mirror of
git://projects.qi-hardware.com/nn-usb-fpga.git
synced 2025-01-09 08:20:15 +02:00
Some changes to lua's blink demo
This commit is contained in:
parent
91fdaa29b6
commit
d01e4f4f47
@ -7,7 +7,7 @@ CCFLAGS = ${INCLUDE} ${DEBUG} ${WARNINGS} -std=c99 -fPIC
|
|||||||
LDFLAGS = -L$(OPENWRT_BUILD_DIR)/usr/lib -llua -ldl
|
LDFLAGS = -L$(OPENWRT_BUILD_DIR)/usr/lib -llua -ldl
|
||||||
DEBUG = -O3 -g0
|
DEBUG = -O3 -g0
|
||||||
NANO_PATH = root@192.168.254.101:
|
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_SOURCES = jz47xx_gpio.c jz47xx_mmap.c sram_gpio_wrap.c
|
||||||
COMMON_OBJECTS = $(COMMON_SOURCES:.c=.o)
|
COMMON_OBJECTS = $(COMMON_SOURCES:.c=.o)
|
||||||
|
@ -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);
|
int port = luaL_checkint(L, 1);
|
||||||
//create user data and associate metable with it
|
//create user data and associate metable with it
|
||||||
JZ_PIO *pio = jz_gpio_map (port);
|
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[] = {
|
static const struct luaL_reg functions[] = {
|
||||||
{"jz_gpio_as_output", jz_gpio_as_output_wrap},
|
{"gpio_as_output", jz_gpio_as_output_wrap},
|
||||||
{"jz_gpio_set_pin", jz_gpio_set_pin_wrap},
|
{"set_pin", jz_gpio_set_pin_wrap},
|
||||||
{"jz_gpio_clear_pin", jz_gpio_clear_pin_wrap},
|
{"clear_pin", jz_gpio_clear_pin_wrap},
|
||||||
{"point_new", point_new_wrapper},
|
{"open_port", open_port_wrapper},
|
||||||
{ NULL, NULL}
|
{ NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
//This is the init function that will be called when you require 'mylib'
|
//This is the init function that will be called when you require 'gpio'
|
||||||
|
|
||||||
int luaopen_sram_gpio_lib(lua_State *L) {
|
|
||||||
|
|
||||||
|
|
||||||
|
int luaopen_gpio(lua_State *L) {
|
||||||
luaL_newmetatable(L, metaname);
|
luaL_newmetatable(L, metaname);
|
||||||
//pop 1 elements from the statck .. why?? to pop the newmetatable that is useless.
|
//pop 1 elements from the statck .. why?? to pop the newmetatable that is useless.
|
||||||
//
|
//
|
||||||
//lua_pop(L, 1);
|
//lua_pop(L, 1);
|
||||||
//replace luaL_openlib
|
//replace luaL_openlib
|
||||||
luaL_register(L, "sram_gpio_lib", functions);
|
luaL_register(L, "gpio", functions);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package.cpath = "./?.so"
|
package.cpath = "./?.so"
|
||||||
require "sram_gpio_lib"
|
require "gpio"
|
||||||
|
|
||||||
PORT_A = 0
|
PORT_A = 0
|
||||||
PORT_B = 1
|
PORT_B = 1
|
||||||
@ -7,9 +7,9 @@ require "sram_gpio_lib"
|
|||||||
PORT_D = 3
|
PORT_D = 3
|
||||||
|
|
||||||
function pulse()
|
function pulse()
|
||||||
sram_gpio_lib.jz_gpio_set_pin(pio,17)
|
gpio.set_pin(pio,17)
|
||||||
delay_s(1)
|
delay_s(1)
|
||||||
sram_gpio_lib.jz_gpio_clear_pin(pio,17)
|
gpio.clear_pin(pio,17)
|
||||||
delay_s(1)
|
delay_s(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -19,8 +19,8 @@ require "sram_gpio_lib"
|
|||||||
while os.time() < time_to do end
|
while os.time() < time_to do end
|
||||||
end
|
end
|
||||||
|
|
||||||
pio=sram_gpio_lib.point_new(PORT_C)
|
pio=gpio.open_port(PORT_C)
|
||||||
sram_gpio_lib.jz_gpio_as_output(pio,17)
|
gpio.gpio_as_output(pio,17)
|
||||||
|
|
||||||
for i=0,5,1 do
|
for i=0,5,1 do
|
||||||
pulse()
|
pulse()
|
||||||
|
Loading…
Reference in New Issue
Block a user