Date:2010-09-07 04:25:51 (13 years 6 months ago)
Author:Carlos Camargo
Commit:d01e4f4f47bdd2eaf9935e08d04dee4519b5d267
Message:Some changes to lua's blink demo

Files: lua/examples/lua_blink_led/Makefile (1 diff)
lua/examples/lua_blink_led/sram_gpio_wrap.c (2 diffs)
lua/examples/lua_blink_led/test_gpio.lua (3 diffs)

Change Details

lua/examples/lua_blink_led/Makefile
77LDFLAGS = -L$(OPENWRT_BUILD_DIR)/usr/lib -llua -ldl
88DEBUG = -O3 -g0
99NANO_PATH = root@192.168.254.101:
10TARGET = sram_gpio_lib
10TARGET = gpio
1111
1212COMMON_SOURCES = jz47xx_gpio.c jz47xx_mmap.c sram_gpio_wrap.c
1313COMMON_OBJECTS = $(COMMON_SOURCES:.c=.o)
lua/examples/lua_blink_led/sram_gpio_wrap.c
3131
3232
3333
34static int point_new_wrapper(lua_State *L) { // get Lua to allocate an initialize a Point*
34static int open_port_wrapper(lua_State *L) { // get Lua to allocate an initialize a Point*
3535    int port = luaL_checkint(L, 1);
3636    //create user data and associate metable with it
3737    JZ_PIO *pio = jz_gpio_map (port);
...... 
4242}
4343
4444static const struct luaL_reg functions[] = {
45    {"jz_gpio_as_output", jz_gpio_as_output_wrap},
46    {"jz_gpio_set_pin", jz_gpio_set_pin_wrap},
47    {"jz_gpio_clear_pin", jz_gpio_clear_pin_wrap},
48    {"point_new", point_new_wrapper},
45    {"gpio_as_output", jz_gpio_as_output_wrap},
46    {"set_pin", jz_gpio_set_pin_wrap},
47    {"clear_pin", jz_gpio_clear_pin_wrap},
48    {"open_port", open_port_wrapper},
4949    { NULL, NULL}
5050};
5151
52//This is the init function that will be called when you require 'mylib'
53
54int luaopen_sram_gpio_lib(lua_State *L) {
55
52//This is the init function that will be called when you require 'gpio'
5653
54int luaopen_gpio(lua_State *L) {
5755    luaL_newmetatable(L, metaname);
5856    //pop 1 elements from the statck .. why?? to pop the newmetatable that is useless.
5957    //
6058    //lua_pop(L, 1);
6159    //replace luaL_openlib
62    luaL_register(L, "sram_gpio_lib", functions);
60    luaL_register(L, "gpio", functions);
6361    return 1;
6462}
lua/examples/lua_blink_led/test_gpio.lua
11package.cpath = "./?.so"
2require "sram_gpio_lib"
2require "gpio"
33
44  PORT_A = 0
55  PORT_B = 1
...... 
77  PORT_D = 3
88
99  function pulse()
10    sram_gpio_lib.jz_gpio_set_pin(pio,17)
10    gpio.set_pin(pio,17)
1111    delay_s(1)
12    sram_gpio_lib.jz_gpio_clear_pin(pio,17)
12    gpio.clear_pin(pio,17)
1313    delay_s(1)
1414  end
1515
...... 
1919    while os.time() < time_to do end
2020  end
2121
22  pio=sram_gpio_lib.point_new(PORT_C)
23  sram_gpio_lib.jz_gpio_as_output(pio,17)
22  pio=gpio.open_port(PORT_C)
23  gpio.gpio_as_output(pio,17)
2424
2525  for i=0,5,1 do
2626    pulse()

Archive Download the corresponding diff file

Branches:
master



interactive