mirror of
git://projects.qi-hardware.com/nn-usb-fpga.git
synced 2025-04-16 07:27:27 +03:00
Enabling Set port and pin in blinker example
This commit is contained in:
parent
5a6f0b5e68
commit
91fdaa29b6
@ -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) {
|
static int jz_gpio_as_output_wrap(lua_State *L) {
|
||||||
JZ_PIO *pio = (JZ_PIO *)lua_touserdata(L,1);
|
JZ_PIO *pio = (JZ_PIO *)lua_touserdata(L,1);
|
||||||
luaL_checkudata(L, 1, metaname); // check argument type
|
luaL_checkudata(L, 1, metaname); // check argument type
|
||||||
int b = luaL_checkint(L, 2);
|
int pin = luaL_checkint(L, 2);
|
||||||
lua_pushnumber(L, (lua_Number)jz_gpio_as_output(pio, b));
|
lua_pushnumber(L, (lua_Number)jz_gpio_as_output(pio, pin));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int jz_gpio_set_pin_wrap(lua_State *L) {
|
static int jz_gpio_set_pin_wrap(lua_State *L) {
|
||||||
JZ_PIO *pio = luaL_checkudata(L, 1, metaname); // check argument type
|
JZ_PIO *pio = luaL_checkudata(L, 1, metaname); // check argument type
|
||||||
int b = luaL_checkint(L, 2);
|
int pin = luaL_checkint(L, 2);
|
||||||
lua_pushnumber(L, (lua_Number)jz_gpio_set_pin(pio, b));
|
lua_pushnumber(L, (lua_Number)jz_gpio_set_pin(pio, pin));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int jz_gpio_clear_pin_wrap(lua_State *L) {
|
static int jz_gpio_clear_pin_wrap(lua_State *L) {
|
||||||
JZ_PIO *pio = luaL_checkudata(L, 1, metaname); // check argument type
|
JZ_PIO *pio = luaL_checkudata(L, 1, metaname); // check argument type
|
||||||
int b = luaL_checkint(L, 2);
|
int pin = luaL_checkint(L, 2);
|
||||||
lua_pushnumber(L, (lua_Number)jz_gpio_clear_pin(pio, b));
|
lua_pushnumber(L, (lua_Number)jz_gpio_clear_pin(pio, pin));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int point_new_wrapper(lua_State *L) { // get Lua to allocate an initialize a Point*
|
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
|
//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);
|
lua_pushlightuserdata(L,pio);
|
||||||
luaL_getmetatable(L, metaname);
|
luaL_getmetatable(L, metaname);
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package.cpath = "./?.so"
|
package.cpath = "./?.so"
|
||||||
require "sram_gpio_lib"
|
require "sram_gpio_lib"
|
||||||
|
|
||||||
|
PORT_A = 0
|
||||||
|
PORT_B = 1
|
||||||
|
PORT_C = 2
|
||||||
|
PORT_D = 3
|
||||||
|
|
||||||
function pulse()
|
function pulse()
|
||||||
sram_gpio_lib.jz_gpio_set_pin(pio,17)
|
sram_gpio_lib.jz_gpio_set_pin(pio,17)
|
||||||
delay_s(1)
|
delay_s(1)
|
||||||
@ -14,7 +19,7 @@ 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()
|
pio=sram_gpio_lib.point_new(PORT_C)
|
||||||
sram_gpio_lib.jz_gpio_as_output(pio,17)
|
sram_gpio_lib.jz_gpio_as_output(pio,17)
|
||||||
|
|
||||||
for i=0,5,1 do
|
for i=0,5,1 do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user