1
0
mirror of https://github.com/elua/elua.git synced 2025-01-25 01:02:54 +08:00
elua/romfs/tvbgone.lua
Bogdan Marinescu 42ff856578 - the "pio" module is now called "gpio" (Dado will be finally happy :) )
- new addition to the PIO module: now you can use pin ranges in PIO expressions. For example:

  gpio.PA_3_6_DIR = gpio.OUTPUT -- make pins 3-6 from PORTA outputs
  gpio.PB_0_30_PULL = gpio.PULLUP -- activate pullups on all but the last pin of PORTB
  gpio.PB_3_6 = 11 -- set value 10 (1011) to pins 3-6 of PB (so PB.6 == 1, PB.5 == 0, PB.4 == 1, PB.3 == 1 )
  value = gpio.PB_2_9 -- read the value of pins 2-9 of PB into 'value'

  Of course, one can still specify a single pin instead of a range.
  This is still tested, but seems to work fine for now.
- romfs/ samples updated to work with the new module name and syntax
- small fix to buf.c (in the BUF_MOD_INCR macro).
2009-02-16 20:18:48 +00:00

71 lines
1.7 KiB
Lua

-- TVBGone in eLua
-- Adapted from LadyAda's TVBGone project
-- Check codes file
local codes = io.open( "/rom/codes.bin", "rb" )
if codes == nil then
print "Unable to open TVBGone codes file"
return
end
local pwmid, tmrid
if pd.board() == 'EK-LM3S8962' or pd.board() == 'EK-LM3S6965' then
pwmid, tmrid = 2, 1
pwm.setclock( pwmid, 25000000 )
led, startpin, exitpin = "PF_0", "PF_1", "PE_1"
else
print( pd.board() .. " not supported with this example" )
return
end
-- Setup PIO
gpio.dir[ led ] = gpio.OUTPUT
gpio.dir[ startpin ], gpio.dir[ exitpin ] = gpio.INPUT, gpio.INPUT
gpio.pull[ startpin ], gpio.pull[ exitpin ] = gpio.PULLUP, gpio.PULLUP
-- Local variables
local _, fstr, freq, timesstr, ontime, offtime, runme
-- Send all the codes in an infinite loop
collectgarbage( "stop" )
runme = true
while runme do
while gpio[ startpin ] == 1 do
if gpio[ exitpin ] == 0 then
runme = false
break
end
end
if not runme then break end
gpio[ led ] = 1
codes:seek( "set", 0 )
while true do
fstr = codes:read( 4 )
if fstr == nil then break end
_, freq = pack.unpack( fstr, "<L" )
pwm.setup( pwmid, freq, 50 )
while true do
timesstr = codes:read( 4 )
_, ontime = pack.unpack( timesstr, "<H" )
_, offtime = pack.unpack( timesstr, "<H", 3 )
pwm.start( pwmid )
tmr.delay( tmrid, ontime * 10 )
pwm.stop( pwmid )
if offtime == 0 then break end
tmr.delay( tmrid, offtime * 10 )
if gpio[ exitpin ] == 0 then
runme = false
break
end
end
if not runme then break end
tmr.delay( tmrid, 250000 )
end
gpio[ led ] = 0
if not runme then break end
tmr.delay( tmrid, 500000 )
end
codes:close()