1
0
mirror of https://github.com/elua/elua.git synced 2025-01-08 20:56:17 +08:00
elua/doc/en/refman.html
2009-02-20 14:48:13 +00:00

756 lines
38 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"><meta http-equiv="Content-Language" content="en-us"><title>Product</title><link rel="stylesheet" type="text/css" href="../style.css"></head>
<body style="background-color: rgb(255, 255, 255);">
<h3>eLua Modules Reference Manual
</h3>
<h2><a name="genericmodules"></a>eLua Generic
Modules</h2>A Generic eLua Module is a module that can be used equally by a Lua program running on any of the <a href="status.html#platforms">supported eLua platforms</a>.<br>Write your code once and it is already automatically ported to the main platforms of the embedded world.<br><br><h3><a name="bitmodule"></a>bit</h3>
Bitwise&nbsp;operations in eLua is implemented thru
the&nbsp;BitLib library, from Reuben Thomas.<br>
BitLib project is hosted at LuaForge on
<a href="http://luaforge.net/projects/bitlib" target="_top">http://luaforge.net/projects/bitlib</a><br>
<p class="MsoNormal" style="font-family: Verdana;"><a name="bit_bnot"></a>Res = bit.bnot( value )</p>
<p class="MsoNormal" style="font-family: Verdana;">
unary negation
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="bit_band"></a> Res = bit.band( v1, v2, ... )</p>
<p class="MsoNormal" style="font-family: Verdana;"><b>bitwise
</b>"and"
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="bit_bor"></a> Res = bit.bor( v1, v2, ... )</p>
<p class="MsoNormal" style="font-family: Verdana;"><span style="font-weight: bold;">&nbsp;</span><b class="info" style="font-weight: bold;">bitwise</b><b class="info" style="font-weight: bold;">
</b><span class="info" style="font-weight: bold;">"or"</span>
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="bit_bxor"></a> Res = bit.bxor( v1, v2, ... )</p>
<p class="MsoNormal" style="font-family: Verdana;">
<b>bitwise</b><b> </b>"exclusive or"
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="bit_lshift"></a> Res = bit.lshift( value, pos )</p>
<p class="MsoNormal" style="font-family: Verdana;">
shift "value" left "pos" positions.
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="bit_rshift"></a> Res = bit.rshift( value, pos )</p>
<p class="MsoNormal" style="font-family: Verdana;">
shift "value" right "pos" positions. The sign is not propagated.
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="bit_arshift"></a> Res = bit.arshift( value, pos )</p>
<p class="MsoNormal" style="font-family: Verdana;">
shift "value" right "pos" positions. The sign is propagated
("arithmetic shift").
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="bit_bit"></a> Res = bit.bit( bitno )</p>
<p class="MsoNormal" style="font-family: Verdana;">
a shortcut for bit.lshift( 1, bitno )
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="bit_set"></a> Res1, Res2, ... = bit.set( bitno, v1,
v2, ... )</p>
<p class="MsoNormal" style="font-family: Verdana;">
set the bit at position "bitno" in v1, v2, ... to 1.
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="bit_clear"></a> Res1, Res2, ... = bit.clear( bitno,
v1, v2, ... )</p>
<p class="MsoNormal" style="font-family: Verdana;">
set the bit at position "bitno"in v1, v2, ... to 0.
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="bit_isset"></a> Res = bit.isset( value, bitno )</p>
<p class="MsoNormal" style="font-family: Verdana;">
returns true if bit at position "bitno" in "value" is 1, false
otherwise.
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="bit_isclear"></a> Res = bit.isclear( value, bitno )</p>
<p class="MsoNormal" style="font-family: Verdana;">
returns true if bit at position "bitno" in "value" is 0, false
otherwise.
</p>
<br style="font-family: Verdana;">
<br style="font-family: Verdana;">
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<h3><a name="cpumodule"></a>cpu</h3>
<p class="MsoNormal" style="font-family: Verdana;"><br>
</p>
<p style="margin-bottom: 0in;"> </p>
<font face="Bitstream Vera Sans Mono, sans-serif"><a name="cpu_write32"></a>write32( address, data ) : write
the 32-bit data at the specified address</font>
<p style="margin-bottom: 0in;"></p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="cpu_write16"></a>write16( address, data ) : write
the 16-bit data at the specified address</font>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="cpu_write8"></a>write8( address, data ) : write the
8-bit data at the specified address</font> <br>
</p>
<p style="margin-bottom: 0in;"><br>
</p>
<br>
<font face="Bitstream Vera Sans Mono, sans-serif"><a name="cpu_read32"></a>Data =&nbsp;read32( address ) :
reads 32-bit data from the specified address</font>
<p style="margin-bottom: 0in;"></p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="cpu_read16"></a>Data = read16( address ) : reads
16-bit data from the specified address</font>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="cpu_read8"></a>Data = read8( address ) : reads 8-bit
data from the specified address</font></p>
<p style="margin-bottom: 0in;"><br>
</p>
<br>
<p style="margin-bottom: 0in;"><a name="cpu_disableinterrupts"></a>
[cpu.disableinterrupts()]&nbsp;&nbsp; <font face="Bitstream Vera Sans Mono, sans-serif">cli(): disable
CPU interrupts</font>
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"><a name="cpu_enableinterrupts"></a>
[cpu.enableinterrupts()]&nbsp;&nbsp; <font face="Bitstream Vera Sans Mono, sans-serif">sei(): enable
CPU interrupts</font>
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><br>
</font></p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="cpu_clockfrequency"></a>[cpu.clockfrequency()]&nbsp;&nbsp;&nbsp;&nbsp;
Clock = clock(): returns the CPU frequency</font>
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">Also, you can
expose as many CPU constants (for example memory mapped registers)</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">as you want to
this module. You might want to use this feature to access some </font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">CPU memory areas
(as defined in the CPU header files from the CPU support </font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">package)
directly from Lua. To do this, you'll need to define the </font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">PLATFORM_CPU_CONSTANTS
macro in the platform's platform_conf.h file </font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">(src/platform/&lt;platform
name&gt;/platform_conf.h). Include all your constants in a </font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">_C(
&lt;constant name&gt; ) definition, and then build your project.</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">For example,
let's suppose that your CPU's interrupt controler has 3 memory</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">mapped
registers: INT_REG_ENABLE, INT_REG_DISABLE and INT_REG_MASK. If you want</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">to access them
from Lua, locate the header that defines the values of these</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">registers (I'll
assume its name is "cpu.h") and add these lines to the</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">platform_conf.h:</font>
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">#include "cpu.h"</font>
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">#define
PLATFORM_CPU_CONSTANTS\</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">_C(
INT_REG_ENABLE ),\</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">_C(
INT_REG_DISABLE ),\</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">_C( INT_REG_MASK
)</font>
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">After this
you'll be able to access the regs directly from Lua, like this:</font>
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">data = cpu.r32(
cpu.INT_REG_ENABLE )</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">cpu.w32(
cpu.INT_REG_ENABLE, data )</font>
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">For a
"real-life" example, see the src/platform/lm3s/platform_conf.h file.</font>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">[uart.sendstring]
uart.sendstr( id, str1, str2, ... ): this is similar to "uart.send",
but its parameters are string.&nbsp;</font>
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> </p>
<h3><a name="gpiomodule">pio</a></h3>
<p class="MsoNormal" style="font-family: Verdana;">
<b>pio</b></p><p class="MsoNormal" style="font-family: Verdana;">Programable Input Output Module</p><p class="MsoNormal" style="font-family: Verdana;">Some notes on PIO:</p><ul><li>pio: only
some platform have internal pullups for the pio pins, while Cortex is
the only platform that also provides pulldowns for its pios. However,
in this case you're safe, as eLua will signal an error if you try to
execute a pullup operatin on a platform that does not support it.</li></ul><p class="MsoNormal" style="font-family: Verdana;">
</p>
<br>
<p class="MsoNormal" style="font-family: Verdana;"><a name="gpio_setpinvalue"></a> [pio.setpinvalue] pio.setpin(
value, Pin1, Pin2 ... ): set the value to all the pins in the list
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp; to "value" (0 or 1).
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="gpio_setpinhigh"></a> [pio.setpinhigh] pio.set(
Pin1, Pin2, ... ): set the value of all the pins in the list to 1.
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="gpio_getpinvalue"></a> [pio.getpinvalue] Val1, Val2,
... = pio.get( Pin1, Pin2, ... ): reads one or more pins and returns
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp; their values (0 or 1).
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="gpio_setpinlow"></a> [pio.setpinlow] pio.clear(
Pin1, Pin2, ... ): set the value of all the pins in the list to 0.
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="gpio_configpin"></a> [pio.configpin(pio.DIR, pio.DIR_INPUT)] pio.input( Pin1, Pin2, ... ): set the specified pin(s)
as input(s).
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;">
[pio.configpin(pio.DIR, pio.DIR_OUTPUT)] pio.output( Pin1, Pin2, ...
): set the specified pin(s) as output(s).
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="gpio_setportvalue"></a> [pio.setportvalue]
pio.setport( value, Port1, Port2, ... ): set the value of all the ports
in the
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp; list to "value".
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="gpio_getportvalue"></a> [pio.getportvalue] Val1,
Val2, ... = pio.getport( Port1, Port2, ... ): reads one or more ports
and
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp; returns their values.
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="gpio_getportname"></a> [pio.getportname]
Port = pio.port( code ): return the physical port number associated
with the given code. For example, "pio.port( pio.P0_20 )" will return
0.
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;"><a name="gpio_getpinnumber"></a> [pio.getpinnumber] Pin =
pio.pin( code ): return the physical pin number associated with the
</p>
<p class="MsoNormal" style="font-family: Verdana;">
given code. For example, "pio.pin( pio.P0_20 )" will return 20.
</p>
<br>
<a name="gpio_togglepin"></a>[pio.togglepin([Pin1],
[Pin2], ...)]<br>
<br>
<a name="gpio_toogleport"></a>[pio.toggleport([Port1],
[Port2], ...)]<br style="font-family: Verdana;">
<br>
Another idea (can be added to the above ?)<br>
[pio.configport(pio.[FUNCTION], pio.MASK, [MASK])]<br>
Ex:<br>
&nbsp; pio.configpin(pio.DIR, pio.DIR_INPUT)&nbsp;&nbsp;&nbsp; (.DIR_OUTPUT)<br>
&nbsp; pio.configpin(pio.PULL, pio.PULL_UP)&nbsp;&nbsp;&nbsp;&nbsp; (.PULL_DOWN,
PULL_NO)<br style="font-family: Verdana;">
<br>
<p class="MsoNormal" style="font-family: Verdana;">
[pio.configport(pio.DIR, pio.DIR_INPUT, [Port1], [Port2], ...)]
pio.port_input( Port1, Port2, ... ): set the specified port(s) as
input(s).
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;">
[pio.configport(pio.DIR, pio.DIR_OUTPUT, [Port1], [Port2], ...)]
pio.port_output( Port1, Port2, ... ): set the specified port(s) as
output(s).
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;">
[pio.configpin(pio.PULL, pio.PULL_UP, [Pin1], [Pin2], ...)]
pio.pullup( Pin1, Pin2, ... ): enable internal pullups on the specified
pins.Note that some CPUs might not provide this feature.
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;">
[pio.configpin(pio.PULL, pio.PULL_DOWN, [Pin1], [Pin2], ...)]
pio.pulldown( Pin1, Pin2, ... ): enable internal pulldowns on the
specified pins. Note that some CPUs might not provide this feature.
</p>
<p class="MsoNormal" style="font-family: Verdana;">
&nbsp;
</p>
<p class="MsoNormal" style="font-family: Verdana;">
[pio.configpin(pio.PULL, pio.PULL_NO, [Pin1], [Pin2], ...)]
pio.nopull( Pin1, Pin2, ... ): disable the pullups/pulldowns on the
specifiedpins. Note that some CPUs might not provide this feature.
</p>
<br>
<h3><a name="netmodule"></a>net</h3>
<br>
<h3><a name="pwmmodule"></a>pwm</h3>
<span style="font-weight: bold;"></span><br>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">It allows Lua to
use the PWM blocks on the target CPU.</font>
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><strike><a name="pwm_setup"></a>[pwm.setup]</strike>(</font><font face="Bitstream Vera Sans Mono, sans-serif">pwm.setup( id,
frequency, Active Cycle ) &nbsp; &nbsp; &nbsp;</font><font face="Bitstream Vera Sans Mono, sans-serif">
Data = pwm.setup( id, frequency, duty ): sets the PWM block 'id' to
generate the specified frequency with the specified duty cycle (duty is
an integer number from 0 to 100, specifying the duty cycle in
percents). It returns the actual frequency set on the PWM block.</font>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> Here there is a bigger
change on the proposal.
</p>
<p style="margin-bottom: 0in;"> The Timer Clock and the
PWM "frame" frequency would be set up in the same function (.setup)
</p>
<p style="margin-bottom: 0in;"> The normal control
function would only set the active cicle (.setcycle)
</p>
<p style="margin-bottom: 0in;"> The original .setup
function would then be replaced by:
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">[pwm.setup( id,
tmrclock, pwm_frequency )</font> ]<br>
</p>
<p style="margin-bottom: 0in;"> <a name="pwm_setcycle"></a>[pwm.setcycle(
id, active_cycle )]</p>
<p style="margin-bottom: 0in;"><font face="Bitstream Vera Sans Mono, sans-serif"><a name="pwm_start"></a>[pwm.start()]&nbsp;&nbsp;
pwm.start( id ): start the PWM block 'id'.</font>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="pwm_stop"></a>[</font><font face="Bitstream Vera Sans Mono, sans-serif">pwm.stop()]&nbsp;&nbsp;&nbsp;
</font><font face="Bitstream Vera Sans Mono, sans-serif">pwm.stop(
id ): stop the PWM block 'id'.</font>
</p>
<br>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="pwm_setclock"></a>Data = pwm.setclock( id, clock ):
set the base clock of the PWM block 'id' to</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">the given clock.
In returns the actual clock set on the PWM block.</font>
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">[</font><font face="Bitstream Vera Sans Mono, sans-serif"><strike>pwm.getclock</strike>]
</font><font face="Bitstream Vera Sans Mono, sans-serif">Data
= pwm.getclock( id ): returns the base clock of the PWM block 'id'.</font>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<h3><a name="spimodule"></a>spi</h3>
<span style="font-weight: bold;"></span><br>
<big><span style="font-family: Helvetica,Arial,sans-serif;"></span><font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big><a name="spi_setup"></a>Actual_clock = spi.setup( id,
spi.MASTER | spi.SLAVE, clock, cpol, cpha,</big></font><span style="font-family: Helvetica,Arial,sans-serif;">
</span><br style="font-family: Helvetica,Arial,sans-serif;">
<span style="font-family: Helvetica,Arial,sans-serif;">
&nbsp; </span><font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>databits):
set the SPI interface with the given parameters, returns the clock</big></font><span style="font-family: Helvetica,Arial,sans-serif;">
</span><br style="font-family: Helvetica,Arial,sans-serif;">
<span style="font-family: Helvetica,Arial,sans-serif;">
&nbsp; </span><font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>that
was set for the interface.</big></font><span style="font-family: Helvetica,Arial,sans-serif;">
</span><br style="font-family: Helvetica,Arial,sans-serif;">
<span style="font-family: Helvetica,Arial,sans-serif;">
&nbsp;
</span><br style="font-family: Helvetica,Arial,sans-serif;">
<font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big><a name="spi_select"></a>spi.select(
</big></font><font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>id</big></font><font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>
): sets the selected spi as active (sets the SS line of the given
interface).</big></font><span style="font-family: Helvetica,Arial,sans-serif;">
</span><br style="font-family: Helvetica,Arial,sans-serif;">
<font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>&nbsp;</big></font><span style="font-family: Helvetica,Arial,sans-serif;">
</span><br style="font-family: Helvetica,Arial,sans-serif;">
<font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big><a name="spi_unselect"></a>spi.unselect(
id ): clears the SS line of the given interface.</big></font><span style="font-family: Helvetica,Arial,sans-serif;">
</span><br style="font-family: Helvetica,Arial,sans-serif;">
<font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>&nbsp;</big></font><span style="font-family: Helvetica,Arial,sans-serif;">
</span><br style="font-family: Helvetica,Arial,sans-serif;">
<font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big><a name="spi_send"></a>spi.send(
id, Data1, Data2, ... ): sends all the data to the specified SPI</big></font><span style="font-family: Helvetica,Arial,sans-serif;">
</span><br style="font-family: Helvetica,Arial,sans-serif;">
<span style="font-family: Helvetica,Arial,sans-serif;">
&nbsp; </span><font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>interface.</big></font><span style="font-family: Helvetica,Arial,sans-serif;">
</span><br style="font-family: Helvetica,Arial,sans-serif;">
<span style="font-family: Helvetica,Arial,sans-serif;">
&nbsp;
</span><br style="font-family: Helvetica,Arial,sans-serif;">
<font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big><a name="spi_sendrecv"></a>[</big></font><font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>spi.sendrecv(</big></font><font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>id,
Out1, Out2, ...</big></font><font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>)]&nbsp;&nbsp;&nbsp;&nbsp;
</big></font><font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>In1,
In2, ... = spi.send_recv( id, Out1, Out2, ... ): sends all the "out"
bytes</big></font><span style="font-family: Helvetica,Arial,sans-serif;"> </span><font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>to
the specified SPI interface and returts the data read after each sent
byte.</big></font><span style="font-family: Helvetica,Arial,sans-serif;">
</span><br style="font-family: Helvetica,Arial,sans-serif;">
<br style="font-family: Helvetica,Arial,sans-serif;">
<font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>Returning
several values in this blocking way would not complicate some queued
send implementations ? (ok, this could be another function :)</big></font><span style="font-family: Helvetica,Arial,sans-serif;">
</span><br style="font-family: Helvetica,Arial,sans-serif;">
<br style="font-family: Helvetica,Arial,sans-serif;">
<font style="font-family: Helvetica,Arial,sans-serif;" size="2"><big>Sending multiple data/chars in a single
call and not in
a table argument does not allow the data to be built in run time
(without some string massage, of course :)</big></font><br>
<br>
<br>
<br>
</big>
<h3><a name="sysmodule"></a>sys</h3>
<br>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="sys_platform"></a>[sys.platform()]&nbsp;&nbsp;&nbsp;
pd.platform(): returns the platform name (f.e. LM3S)</font>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="sys_mcu"></a>[sys.mcu()]&nbsp;&nbsp;&nbsp;
pd.cpu(): returns the CPU name (f.e. LM3S8962)</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="sys_cpu"></a>[sys.cpu()]&nbsp;&nbsp;&nbsp;
would return ARM Cortex M3 in this case.....</font></p>
<p style="margin-bottom: 0in;"><font face="Bitstream Vera Sans Mono, sans-serif"><br>
</font></p>
<font face="Bitstream Vera Sans Mono, sans-serif">&nbsp;&nbsp;<a name="sys_board"></a>[sys.board()]</font><font face="Bitstream Vera Sans Mono, sans-serif">&nbsp;
pd.board(): returns the CPU board (f.e. EK-LM3S8962)</font>
<p style="margin-bottom: 0in;"> <br>
</p>
<h3><a name="term_termmodule">term</a></h3>
&nbsp; &nbsp;Terminal support
<p> <a name="term_clear"></a>[term.clear]
term.clrscr(): clear the screen </p>
<p> &nbsp; <br>
<a name="term_cleareol"></a>[term.cleareol]
term.clreol(): clear from the current cursor position to the end of the
line </p>
<p> &nbsp; </p>
<p><a name="term_moveto"></a> [term.moveto]
term.gotoxy( x, y ): position the cursor at the given coordinates<br>
</p>
<br>
<p><a name="term_moveup"></a> [term.moveup]
term.up( delta ): move the cursor up "delta" lines </p>
<p> &nbsp; </p>
<p><a name="term_movedown"></a> [term.movedown]
term.down( delta ): move the cursor down "delta" lines </p>
<p> &nbsp; </p>
<p><a name="term_moveleft"></a> [term.moveleft]
term.left( delta ): move the cursor left "delta" lines </p>
<p> &nbsp; <br>
<a name="term_moveright"></a>[term.moveright] term.right(
delta ): move the cursor right "delta" lines </p>
<p> &nbsp; </p>
<p><a name="term_getlinecount"></a>
[term.getlinecount] Lines = term.lines(): returns the number of lines </p>
<p> &nbsp; </p>
<p><a name="term_getcolcount"></a>
[term.getcolcount] Cols = term.cols(): returns the number of columns </p>
<p> &nbsp; </p>
<br>
<p><a name="term_printstr"></a> [term.printstr]
term.putstr( s1, s2, ... ): writes the specified string(s) to the
terminal<br>
</p>
<p> </p>
<p> [term.printchar] term.put( c1, c2, ... ): writes the
specified character(s) to the terminal </p>
<p>&nbsp; </p>
<p><a name="term_getx"></a> [term.getx] Cx =
term.cursorx(): return the cursor X position </p>
<p> &nbsp; </p>
<p> <a name="term_gety"></a>[term.gety] Cy =
term.cursory(): return the cursor Y position </p>
<p> &nbsp; </p>
<p> <font size="2"><a name="term_inputchar"></a>[term.inputchar]
c = term.getch( term.WAIT | term.NOWAIT ): returns a char read from the
</font> </p>
<font size="2">&nbsp; terminal.</font>
<br style="font-family: Verdana;">
<br>
<br>
<h3><a name="tmr_tmrmodule"></a>tmr</h3>
<span style="font-weight: bold;"></span><big><br>
</big>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">It allows Lua to
execute timer specific operations (delay, read timer value,</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">start timer, get
time difference).</font></p><p style="margin-bottom: 0in;"><font face="Bitstream Vera Sans Mono, sans-serif">Some notes on timers:</font></p><ul><li>timers: from all the platforms on which eLua runs, only
the Luminary Cortex CPUs has rock solid 32-bit timers. You can do
pretty much everything you need with them. All the other platforms have
16-bit timers, which imposes some limits on the range of delays you can
achieve with them. Make sure to use tmr.mindelay(id) and
tmr.maxdelay(id) to check the actual resolution of your timers, and
adapt your code accordingly. To 'compensate' for this, it's not
possible to change the base timer frequency on the Cortex CPUs, but it
is possible on most other platforms :) So be sure to also check the
result of tmr.setclock(id)</li><li>also, when using timers,
remember that if you're using XMODEM and/or the "term" module, TMR0 is
used by both of them. So, if you change the TMR0 base clock in your
code, be sure to restore the original setting before returning to the
shell. You can change this static timer assignment by modifying
src/main.c. It might also be possible to change it dynamically in the
future, although I see little use for this.</li><li>PWM: the
Cortex CPUs have 6 PWM channels, but channels 0/1, 2/3 and 4/5
respectively share the same base clock setting. So, when you're
changing the base clock for channel 1, you're also changing the base
clock for channel 0; if channel 0 was already running, you won't like
what will happen next. This time no eLua function can save you, you
simply need you know your CPU architecture.</li></ul><p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="tmr_delay"></a>tmr.delay( id, delay ): uses timer
'id' to wait for 'delay' us.</font>
</p>
<p style="margin-bottom: 0in;"> <br>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><span style="font-style: italic;"><a name="tmr_read"></a></span>Data
= tmr.read( id ): reads the value of timer 'id'. The returned value is </font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">platform
dependent.</font>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><span style="font-style: italic;"><a name="tmr_start"></a></span>Data
= tmr.start( id ): start the timer 'id', and also returns its value at</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">the moment of
start. The returned value is platform dependent.</font>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="tmr_diff"></a>diff
= tmr.diff( id, end, start ): returns the time difference (in us)
between</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">the timer values
'end' and 'start' (obtained from calling tmr.start or</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">tmr.read). The
order of end/start is irrelevant. </font>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="tmr_mindelay"></a>Data = tmr.mindelay( id ): returns
the minimum delay (in us ) that can be </font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">achieved by
calling the tmr.delay function. If the return value is 0, the </font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">platform layer
is capable of executing sub-microsecond delays.</font>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="tmr_maxdelay"></a>Data = tmr.maxdelay( id ): returns
the maximum delay (in us) that can be</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">achieved by
calling the tmr.delay function.</font>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="tmr_setclock"></a>Data = tmr.setclock( id, clock ):
sets the clock of the given timer. Returns the</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif">actual clock set
for the timer.</font>
</p>
<p style="margin-bottom: 0in;">
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="tmr_getclock"></a>Data = tmr.getclock( id ): return
the clock of the given timer.</font>
</p>
<br>
<br>
<br>
<br>
<br>
<h3><a name="uartmodule"></a>uart</h3>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="uart_setup"></a><span style="font-weight: bold;">uart.setup(</span></font><font style="font-weight: bold;" face="Bitstream Vera Sans Mono, sans-serif"> id, baud,
databits, </font>
</p><p style="margin-bottom: 0in; font-weight: bold;"> <font face="Bitstream Vera Sans Mono, sans-serif">uart.PARITY_EVEN
| uart.</font><font face="Bitstream Vera Sans Mono, sans-serif">PARITY</font><font face="Bitstream Vera Sans Mono, sans-serif">_ODD | uart.</font><font face="Bitstream Vera Sans Mono, sans-serif">PARITY</font><font face="Bitstream Vera Sans Mono, sans-serif">_NONE, </font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><span style="font-weight: bold;">uart.STOPBITS_1
| uart.STOPBITS_1_5 | uart.STOPBITS_2
)</span></font></p>
<p style="margin-bottom: 0in;"><font face="Bitstream Vera Sans Mono, sans-serif"><span style="font-weight: bold;"></span>&nbsp;&nbsp;&nbsp; Set the UART interface with the&nbsp;given
parameters.</font></p><p style="margin-bottom: 0in;"><font face="Bitstream Vera Sans Mono, sans-serif">&nbsp;&nbsp;&nbsp; Returns the actual baud rate that was set for the UART.</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><br>
</font></p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="uart_send"></a></font><font face="Bitstream Vera Sans Mono, sans-serif"><span style="font-weight: bold;">uart.send( id,
Data1, Data2, ... )</span></font></p><p style="margin-bottom: 0in;"><font face="Bitstream Vera Sans Mono, sans-serif"><span style="font-weight: bold;"></span>&nbsp;&nbsp;&nbsp; Send all the data to the specified UART interface.</font>
</p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><br>
</font></p>
<p style="margin-bottom: 0in;"> <font face="Bitstream Vera Sans Mono, sans-serif"><a name="uart_recv"></a></font><font face="Bitstream Vera Sans Mono, sans-serif">uart.recv(</font><font face="Bitstream Vera Sans Mono, sans-serif"> id,
uart.TIMEOUT_NO | <strike>uart.TIMEOUT_INFINITE</strike> |
timeout )</font><font face="Bitstream Vera Sans Mono, sans-serif">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font face="Bitstream Vera Sans Mono, sans-serif">Data =
uart.recv( id, uart.NO_TIMEOUT | uart.INF_TIMEOUT | timeout )</font></p>
<p style="margin-bottom: 0in;"><font face="Bitstream Vera Sans Mono, sans-serif">&nbsp;&nbsp;&nbsp; Reads a byte from the
specified UART interface.</font></p>
<p style="margin-bottom: 0in;"></p>
<p style="margin-bottom: 0in;">
</p>
<h2><a name="platdepmodules"></a>eLua Platform
Dependent
Modules</h2>A Platform Dependent eLua Module is a module that runs only on one or on a few <a href="status.html#platforms">supported eLua platforms</a>.<br>These
modules make use of specifical devices and features offered by some
kits and allow eLua aplications to make the best use of the external
hardware on your platforms.<br><h3><a name="adcmodule"></a>adc&nbsp; -&nbsp;Analog to Digital Conversion Module</h3><span style="font-weight: bold;">Currently runs on:</span> LM3Sxxxx<br><br>&nbsp;&nbsp;&nbsp; The ADC module handles the Analog to Digital Conversion Peripherals.<br><br><br><a name="adc_sample"></a><span style="font-weight: bold;">adc.sample(channel_id)</span><br>&nbsp;&nbsp;&nbsp; Generate one processed sample.<br><br><a name="adc_getsamples"></a><span style="font-weight: bold;">adc.getsamples(channel_id,
[count])</span><br>&nbsp;&nbsp;&nbsp; Request&nbsp;<span style="font-style: italic;">count</span> samples from the buffer.<br>&nbsp;&nbsp;&nbsp; if singular, an
integer is returned. &nbsp;if multiple, a table of integers is returned. &nbsp;If
<span style="font-style: italic;">count</span> is either zero or omitted, all available samples are returned.<br><br><a name="adc_maxval"></a><span style="font-weight: bold;">adc.maxval(channel_id)</span><br>&nbsp;&nbsp;&nbsp; Returns the largest integer one can expect fromr this channel on a given platform (based on bit depth).<br><br><a name="adc_samplesready"></a><span style="font-weight: bold;">adc.samplesready(channel_id)<br></span>&nbsp;&nbsp;&nbsp; Returns the number of samples waiting in the buffer.<br><br><a name="adc_dataready"></a><span style="font-weight: bold;">adc.dataready(channel_id)<br></span>&nbsp;&nbsp;&nbsp; If running in non-blocking mode, this will indicate if all of the
samples requested from the last sample or <br>burst have been acquired and
are waiting in the buffer.<br><br><a name="adc_setmode"></a><span style="font-weight: bold;">adc.setmode(channel_id,
mode)<br></span>&nbsp;&nbsp;&nbsp; <span style="font-style: italic;">mode</span> 0 sets&nbsp;blocking mode. adc.getsamples will wait for
requested samples to be captured before returning.<br>&nbsp;&nbsp;&nbsp; <span style="font-style: italic;">mode</span> 1 sets non-blocking mode<br><br><a name="adc_setsmoothing"></a><span style="font-weight: bold;">adc.setsmoothing(channel_id, length)<br></span>&nbsp;&nbsp;&nbsp; Set the length of the smoothing filter.<br>&nbsp;&nbsp;&nbsp; This must be a power of 2 (maximum = 128)<br><br><a name="adc_getsmoothing"></a><span style="font-weight: bold;">adc.getsmoothing(channel_id)<br></span>&nbsp;&nbsp;&nbsp; Get the current smoothing length in use.<br><br><a name="adc_burst"></a><span style="font-weight: bold;">adc.burst(
channel_id, count, timer_id, frequency)<br></span>&nbsp;&nbsp;&nbsp; Request that&nbsp;<span style="font-style: italic;">count</span> samples&nbsp;be converted from&nbsp;<span style="font-style: italic;">channel_id</span>, using&nbsp;<span style="font-style: italic;">timer_id</span> at&nbsp;<span style="font-style: italic;">frequency.<br></span>&nbsp;&nbsp;&nbsp; <span style="font-style: italic;">count </span>must be greater than zero and a power of 2<br><br>
<h3><a name="dispmodule"></a>disp</h3>
<span style="font-weight: bold;">Currently runs on:</span> LM3S xxxx<br><br>&nbsp;&nbsp;&nbsp; The disp module handles the RIT OLED display usage on Luminary Micro Cortex-M3 boards<br>
<p class="MsoNormal"><a name="disp_init"></a>
disp.init </p>
<p class="MsoNormal"> <br>
</p>
<p class="MsoNormal"><a name="disp_enable"></a>
disp.enable </p>
<p class="MsoNormal"> <br>
</p>
<p class="MsoNormal"><a name="disp_disable"></a>
disp.disable </p>
<p class="MsoNormal"> <br>
</p>
<p class="MsoNormal"> <a name="disp_on"></a>disp.on
</p>
<p class="MsoNormal"> <br>
</p>
<p class="MsoNormal"><a name="disp_off"></a>
disp.off<br>
</p>
<p class="MsoNormal" style="color: rgb(0, 0, 255);">
<br>
</p>
&nbsp; &nbsp;<a name="disp_print"></a>disp.print<br>
<br>
<p class="MsoNormal"><a name="disp_draw"></a>
disp.draw </p>
</body></html>