1
0
mirror of git://projects.qi-hardware.com/nn-usb-fpga.git synced 2024-12-05 04:31:52 +02:00

Enabling Set port and pin in blinker example

This commit is contained in:
Carlos Camargo 2010-09-06 20:49:11 -05:00
parent 5a6f0b5e68
commit 91fdaa29b6
2 changed files with 14 additions and 8 deletions

View File

@ -10,30 +10,31 @@ const char *metaname = "mine.JZ_PIO"; // associated with userdata of type Point*
static int jz_gpio_as_output_wrap(lua_State *L) {
JZ_PIO *pio = (JZ_PIO *)lua_touserdata(L,1);
luaL_checkudata(L, 1, metaname); // check argument type
int b = luaL_checkint(L, 2);
lua_pushnumber(L, (lua_Number)jz_gpio_as_output(pio, b));
int pin = luaL_checkint(L, 2);
lua_pushnumber(L, (lua_Number)jz_gpio_as_output(pio, pin));
return 1;
}
static int jz_gpio_set_pin_wrap(lua_State *L) {
JZ_PIO *pio = luaL_checkudata(L, 1, metaname); // check argument type
int b = luaL_checkint(L, 2);
lua_pushnumber(L, (lua_Number)jz_gpio_set_pin(pio, b));
int pin = luaL_checkint(L, 2);
lua_pushnumber(L, (lua_Number)jz_gpio_set_pin(pio, pin));
return 1;
}
static int jz_gpio_clear_pin_wrap(lua_State *L) {
JZ_PIO *pio = luaL_checkudata(L, 1, metaname); // check argument type
int b = luaL_checkint(L, 2);
lua_pushnumber(L, (lua_Number)jz_gpio_clear_pin(pio, b));
int pin = luaL_checkint(L, 2);
lua_pushnumber(L, (lua_Number)jz_gpio_clear_pin(pio, pin));
return 1;
}
static int point_new_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 (JZ_GPIO_PORT_C);
JZ_PIO *pio = jz_gpio_map (port);
lua_pushlightuserdata(L,pio);
luaL_getmetatable(L, metaname);
lua_setmetatable(L, -2);

View File

@ -1,6 +1,11 @@
package.cpath = "./?.so"
require "sram_gpio_lib"
PORT_A = 0
PORT_B = 1
PORT_C = 2
PORT_D = 3
function pulse()
sram_gpio_lib.jz_gpio_set_pin(pio,17)
delay_s(1)
@ -14,7 +19,7 @@ require "sram_gpio_lib"
while os.time() < time_to do end
end
pio=sram_gpio_lib.point_new()
pio=sram_gpio_lib.point_new(PORT_C)
sram_gpio_lib.jz_gpio_as_output(pio,17)
for i=0,5,1 do