Some changes to lua's blink demo

This commit is contained in:
Carlos Camargo 2010-09-06 21:25:51 -05:00
parent 91fdaa29b6
commit d01e4f4f47
3 changed files with 14 additions and 16 deletions

View File

@ -7,7 +7,7 @@ CCFLAGS = ${INCLUDE} ${DEBUG} ${WARNINGS} -std=c99 -fPIC
LDFLAGS = -L$(OPENWRT_BUILD_DIR)/usr/lib -llua -ldl
DEBUG = -O3 -g0
NANO_PATH = root@192.168.254.101:
TARGET = sram_gpio_lib
TARGET = gpio
COMMON_SOURCES = jz47xx_gpio.c jz47xx_mmap.c sram_gpio_wrap.c
COMMON_OBJECTS = $(COMMON_SOURCES:.c=.o)

View File

@ -31,7 +31,7 @@ static int jz_gpio_clear_pin_wrap(lua_State *L) {
static int point_new_wrapper(lua_State *L) { // get Lua to allocate an initialize a Point*
static int open_port_wrapper(lua_State *L) { // get Lua to allocate an initialize a Point*
int port = luaL_checkint(L, 1);
//create user data and associate metable with it
JZ_PIO *pio = jz_gpio_map (port);
@ -42,23 +42,21 @@ static int point_new_wrapper(lua_State *L) { // get Lua to allocate an initializ
}
static const struct luaL_reg functions[] = {
{"jz_gpio_as_output", jz_gpio_as_output_wrap},
{"jz_gpio_set_pin", jz_gpio_set_pin_wrap},
{"jz_gpio_clear_pin", jz_gpio_clear_pin_wrap},
{"point_new", point_new_wrapper},
{"gpio_as_output", jz_gpio_as_output_wrap},
{"set_pin", jz_gpio_set_pin_wrap},
{"clear_pin", jz_gpio_clear_pin_wrap},
{"open_port", open_port_wrapper},
{ NULL, NULL}
};
//This is the init function that will be called when you require 'mylib'
int luaopen_sram_gpio_lib(lua_State *L) {
//This is the init function that will be called when you require 'gpio'
int luaopen_gpio(lua_State *L) {
luaL_newmetatable(L, metaname);
//pop 1 elements from the statck .. why?? to pop the newmetatable that is useless.
//
//lua_pop(L, 1);
//replace luaL_openlib
luaL_register(L, "sram_gpio_lib", functions);
luaL_register(L, "gpio", functions);
return 1;
}

View File

@ -1,5 +1,5 @@
package.cpath = "./?.so"
require "sram_gpio_lib"
require "gpio"
PORT_A = 0
PORT_B = 1
@ -7,9 +7,9 @@ require "sram_gpio_lib"
PORT_D = 3
function pulse()
sram_gpio_lib.jz_gpio_set_pin(pio,17)
gpio.set_pin(pio,17)
delay_s(1)
sram_gpio_lib.jz_gpio_clear_pin(pio,17)
gpio.clear_pin(pio,17)
delay_s(1)
end
@ -19,8 +19,8 @@ require "sram_gpio_lib"
while os.time() < time_to do end
end
pio=sram_gpio_lib.point_new(PORT_C)
sram_gpio_lib.jz_gpio_as_output(pio,17)
pio=gpio.open_port(PORT_C)
gpio.gpio_as_output(pio,17)
for i=0,5,1 do
pulse()