eLua Modules Reference Manual

Generic Modules


bit

Bitwise operations in eLua is implemented thru the BitLib library, from Reuben Thomas.
BitLib project is hosted at LuaForge on http://luaforge.net/projects/bitlib

Res = bit.bnot( value )

unary negation

 

Res = bit.band( v1, v2, ... )

bitwise "and"

 

Res = bit.bor( v1, v2, ... )

 bitwise "or"

 

Res = bit.bxor( v1, v2, ... )

bitwise "exclusive or"

 

Res = bit.lshift( value, pos )

shift "value" left "pos" positions.

 

Res = bit.rshift( value, pos )

shift "value" right "pos" positions. The sign is not propagated.

 

Res = bit.arshift( value, pos )

shift "value" right "pos" positions. The sign is propagated ("arithmetic shift").

 

Res = bit.bit( bitno )

a shortcut for bit.lshift( 1, bitno )

 

Res1, Res2, ... = bit.set( bitno, v1, v2, ... )

set the bit at position "bitno" in v1, v2, ... to 1.

 

Res1, Res2, ... = bit.clear( bitno, v1, v2, ... )

set the bit at position "bitno"in v1, v2, ... to 0.

 

Res = bit.isset( value, bitno )

returns true if bit at position "bitno" in "value" is 1, false otherwise.

 

Res = bit.isclear( value, bitno )

returns true if bit at position "bitno" in "value" is 0, false otherwise.











cpu


write32( address, data ) : write the 32-bit data at the specified address

write16( address, data ) : write the 16-bit data at the specified address

write8( address, data ) : write the 8-bit data at the specified address



Data = read32( address ) : reads 32-bit data from the specified address

Data = read16( address ) : reads 16-bit data from the specified address

Data = read8( address ) : reads 8-bit data from the specified address



[cpu.disableinterrupts()]   cli(): disable CPU interrupts



[cpu.enableinterrupts()]   sei(): enable CPU interrupts



[cpu.clockfrequency()]     Clock = clock(): returns the CPU frequency


Also, you can expose as many CPU constants (for example memory mapped registers)

as you want to this module. You might want to use this feature to access some

CPU memory areas (as defined in the CPU header files from the CPU support

package) directly from Lua. To do this, you'll need to define the

PLATFORM_CPU_CONSTANTS macro in the platform's platform_conf.h file

(src/platform/<platform name>/platform_conf.h). Include all your constants in a

_C( <constant name> ) definition, and then build your project.

For example, let's suppose that your CPU's interrupt controler has 3 memory

mapped registers: INT_REG_ENABLE, INT_REG_DISABLE and INT_REG_MASK. If you want

to access them from Lua, locate the header that defines the values of these

registers (I'll assume its name is "cpu.h") and add these lines to the

platform_conf.h:


#include "cpu.h"


#define PLATFORM_CPU_CONSTANTS\

_C( INT_REG_ENABLE ),\

_C( INT_REG_DISABLE ),\

_C( INT_REG_MASK )


After this you'll be able to access the regs directly from Lua, like this:


data = cpu.r32( cpu.INT_REG_ENABLE )

cpu.w32( cpu.INT_REG_ENABLE, data )


For a "real-life" example, see the src/platform/lm3s/platform_conf.h file.

[uart.sendstring] uart.sendstr( id, str1, str2, ... ): this is similar to "uart.send", but its parameters are string. 


gpio

[gpio] pio


[gpio.setpinvalue] pio.setpin( value, Pin1, Pin2 ... ): set the value to all the pins in the list

  to "value" (0 or 1).

 

[gpio.setpinhigh] pio.set( Pin1, Pin2, ... ): set the value of all the pins in the list to 1.

 

[gpio.getpinvalue] Val1, Val2, ... = pio.get( Pin1, Pin2, ... ): reads one or more pins and returns

  their values (0 or 1).

 

[gpio.setpinlow] pio.clear( Pin1, Pin2, ... ): set the value of all the pins in the list to 0.

 

[gpio.configpin(gpio.DIR, gpio.DIR_INPUT)] pio.input( Pin1, Pin2, ... ): set the specified pin(s) as input(s).

 

[gpio.configpin(gpio.DIR, gpio.DIR_OUTPUT)] pio.output( Pin1, Pin2, ... ): set the specified pin(s) as output(s).

 

[gpio.setportvalue] pio.setport( value, Port1, Port2, ... ): set the value of all the ports in the

  list to "value".

 

[gpio.getportvalue] Val1, Val2, ... = pio.getport( Port1, Port2, ... ): reads one or more ports and

  returns their values.

 

[gpio.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.

 

[gpio.getpinnumber] Pin = pio.pin( code ): return the physical pin number associated with the

given code. For example, "pio.pin( pio.P0_20 )" will return 20.


[gpio.togglepin([Pin1], [Pin2], ...)]

[gpio.toggleport([Port1], [Port2], ...)]

Another idea (can be added to the above ?)
[gpio.configport(gpio.[FUNCTION], gpio.MASK, [MASK])]
Ex:
  gpio.configpin(gpio.DIR, gpio.DIR_INPUT)    (.DIR_OUTPUT)
  gpio.configpin(gpio.PULL, gpio.PULL_UP)     (.PULL_DOWN, PULL_NO)

[gpio.configport(gpio.DIR, gpio.DIR_INPUT, [Port1], [Port2], ...)] pio.port_input( Port1, Port2, ... ): set the specified port(s) as input(s).

 

[gpio.configport(gpio.DIR, gpio.DIR_OUTPUT, [Port1], [Port2], ...)] pio.port_output( Port1, Port2, ... ): set the specified port(s) as output(s).

 

[gpio.configpin(gpio.PULL, gpio.PULL_UP, [Pin1], [Pin2], ...)] pio.pullup( Pin1, Pin2, ... ): enable internal pullups on the specified pins.Note that some CPUs might not provide this feature.

 

[gpio.configpin(gpio.PULL, gpio.PULL_DOWN, [Pin1], [Pin2], ...)] pio.pulldown( Pin1, Pin2, ... ): enable internal pulldowns on the specified pins. Note that some CPUs might not provide this feature.

 

[gpio.configpin(gpio.PULL, gpio.PULL_NO, [Pin1], [Pin2], ...)] pio.nopull( Pin1, Pin2, ... ): disable the pullups/pulldowns on the specifiedpins. Note that some CPUs might not provide this feature.


net


pwm



It allows Lua to use the PWM blocks on the target CPU.


[pwm.setup](pwm.setup( id, frequency, Active Cycle )       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.


Here there is a bigger change on the proposal.

The Timer Clock and the PWM "frame" frequency would be set up in the same function (.setup)

The normal control function would only set the active cicle (.setcycle)

The original .setup function would then be replaced by:


[pwm.setup( id, tmrclock, pwm_frequency ) ]

[pwm.setcycle( id, active_cycle )]

[pwm.start()]   pwm.start( id ): start the PWM block 'id'.

[pwm.stop()]    pwm.stop( id ): stop the PWM block 'id'.


Data = pwm.setclock( id, clock ): set the base clock of the PWM block 'id' to

the given clock. In returns the actual clock set on the PWM block.


[pwm.getclock] Data = pwm.getclock( id ): returns the base clock of the PWM block 'id'.


spi


Actual_clock = spi.setup( id, spi.MASTER | spi.SLAVE, clock, cpol, cpha,
  databits): set the SPI interface with the given parameters, returns the clock
  that was set for the interface.
 
spi.select( id ): sets the selected spi as active (sets the SS line of the given interface).
 
spi.unselect( id ): clears the SS line of the given interface.
 
spi.send( id, Data1, Data2, ... ): sends all the data to the specified SPI
  interface.
 
[spi.sendrecv(id, Out1, Out2, ...)]     In1, In2, ... = spi.send_recv( id, Out1, Out2, ... ): sends all the "out" bytes to the specified SPI interface and returts the data read after each sent byte.

Returning several values in this blocking way would not complicate some queued send implementations ? (ok, this could be another function :)

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 :)



sys


[sys.platform()]    pd.platform(): returns the platform name (f.e. LM3S)

[sys.mcu()]    pd.cpu(): returns the CPU name (f.e. LM3S8962)

[sys.cpu()]    would return ARM Cortex M3 in this case.....


  [sys.board()]  pd.board(): returns the CPU board (f.e. EK-LM3S8962)


term

   Terminal support

[term.clear] term.clrscr(): clear the screen

 
[term.cleareol] term.clreol(): clear from the current cursor position to the end of the line

 

[term.moveto] term.gotoxy( x, y ): position the cursor at the given coordinates


[term.moveup] term.up( delta ): move the cursor up "delta" lines

 

[term.movedown] term.down( delta ): move the cursor down "delta" lines

 

[term.moveleft] term.left( delta ): move the cursor left "delta" lines

 
[term.moveright] term.right( delta ): move the cursor right "delta" lines

 

[term.getlinecount] Lines = term.lines(): returns the number of lines

 

[term.getcolcount] Cols = term.cols(): returns the number of columns

 


[term.printstr] term.putstr( s1, s2, ... ): writes the specified string(s) to the terminal

[term.printchar] term.put( c1, c2, ... ): writes the specified character(s) to the terminal

 

[term.getx] Cx = term.cursorx(): return the cursor X position

 

[term.gety] Cy = term.cursory(): return the cursor Y position

 

[term.inputchar] c = term.getch( term.WAIT | term.NOWAIT ): returns a char read from the

  terminal.


tmr


It allows Lua to execute timer specific operations (delay, read timer value,

start timer, get time difference).


tmr.delay( id, delay ): uses timer 'id' to wait for 'delay' us.


Data = tmr.read( id ): reads the value of timer 'id'. The returned value is

platform dependent.

Data = tmr.start( id ): start the timer 'id', and also returns its value at

the moment of start. The returned value is platform dependent.

diff = tmr.diff( id, end, start ): returns the time difference (in us) between

the timer values 'end' and 'start' (obtained from calling tmr.start or

tmr.read). The order of end/start is irrelevant.

Data = tmr.mindelay( id ): returns the minimum delay (in us ) that can be

achieved by calling the tmr.delay function. If the return value is 0, the

platform layer is capable of executing sub-microsecond delays.

Data = tmr.maxdelay( id ): returns the maximum delay (in us) that can be

achieved by calling the tmr.delay function.

Data = tmr.setclock( id, clock ): sets the clock of the given timer. Returns the

actual clock set for the timer.

Data = tmr.getclock( id ): return the clock of the given timer.






uart

[uart.setup( id, baud, databits,

uart.PARITY_EVEN |uart.PARITY_ODD | uart.PARITY_NONE,

uart.STOPBITS_1 | uart.STOPBITS_1_5 | uart.STOPBITS_2 )]     Actual_baud = uart.setup( id, baud, databits,

uart.PAR_EVEN |uart.PAR_ODD | uart.PAR_NONE,

uart.STOP_1 | uart.STOP_1_5 | uart.STOP_2 ): set the UART interface with the

given parameters, returns the baud rate that was set for the UART.


[uart.send] uart.send( id, Data1, Data2, ... ): send all the data to the specified UART interface.

#### Data 1 only !?!!


[uart.recv( id, uart.TIMEOUT_NO | uart.TIMEOUT_INFINITE | timeout )        Data = uart.recv( id, uart.NO_TIMEOUT | uart.INF_TIMEOUT | timeout ): reads a

byte from the specified UART interface.

eLua Platform Dependent Modules

adc

Currently runs on: LM3S

adc.sample(channel_id) - generate one processed sample

adc.getsamples(channel_id, count) - request (count) samples from the buffer. if singular, an integer is returned.  if multiple, a table of integers is returned.  If count is either zero or omitted, all available samples are returned.

adc.maxval(channel_id) - returns largest integer one can expect for this channel on a given platform (based on bit depth)

adc.samplesready(channel_id) - returns number of samples waiting in the buffer

adc.dataready(channel_id) - if running in non-blocking mode, this will indicate if all of the samples requested from the last sample or
burst have been acquired and are waiting in the buffer

adc.setmode(channel_id, mode) - mode: 0 sets mode to blocking (getsamples will wait for requested samples to be captured before returning), 1 sets non-blocking

adc.setsmoothing(channel_id, length) - set the length of the smoothing filter, this must be a power of 2 (maximum = 128)

adc.getsmoothing(channel_id) - get the current smoothing length in use

adc.burst( channel_id, count, timer_id, frequency) - request that (count) samples (must be greater than zero and a power of 2) be converted from (channel_id), using (timer_id) at (frequency)

disp

Currently runs on: LM3S

disp.init


disp.enable


disp.disable


disp.on


disp.off


   disp.print

disp.draw