Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Commit Details
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 | ||
---|---|---|
7 | 7 | LDFLAGS = -L$(OPENWRT_BUILD_DIR)/usr/lib -llua -ldl |
8 | 8 | DEBUG = -O3 -g0 |
9 | 9 | NANO_PATH = root@192.168.254.101: |
10 | TARGET = sram_gpio_lib | |
10 | TARGET = gpio | |
11 | 11 | |
12 | 12 | COMMON_SOURCES = jz47xx_gpio.c jz47xx_mmap.c sram_gpio_wrap.c |
13 | 13 | COMMON_OBJECTS = $(COMMON_SOURCES:.c=.o) |
lua/examples/lua_blink_led/sram_gpio_wrap.c | ||
---|---|---|
31 | 31 | |
32 | 32 | |
33 | 33 | |
34 | static int point_new_wrapper(lua_State *L) { // get Lua to allocate an initialize a Point* | |
34 | static int open_port_wrapper(lua_State *L) { // get Lua to allocate an initialize a Point* | |
35 | 35 | int port = luaL_checkint(L, 1); |
36 | 36 | //create user data and associate metable with it |
37 | 37 | JZ_PIO *pio = jz_gpio_map (port); |
... | ... | |
42 | 42 | } |
43 | 43 | |
44 | 44 | static 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}, | |
49 | 49 | { NULL, NULL} |
50 | 50 | }; |
51 | 51 | |
52 | //This is the init function that will be called when you require 'mylib' | |
53 | ||
54 | int luaopen_sram_gpio_lib(lua_State *L) { | |
55 | ||
52 | //This is the init function that will be called when you require 'gpio' | |
56 | 53 | |
54 | int luaopen_gpio(lua_State *L) { | |
57 | 55 | luaL_newmetatable(L, metaname); |
58 | 56 | //pop 1 elements from the statck .. why?? to pop the newmetatable that is useless. |
59 | 57 | // |
60 | 58 | //lua_pop(L, 1); |
61 | 59 | //replace luaL_openlib |
62 | luaL_register(L, "sram_gpio_lib", functions); | |
60 | luaL_register(L, "gpio", functions); | |
63 | 61 | return 1; |
64 | 62 | } |
lua/examples/lua_blink_led/test_gpio.lua | ||
---|---|---|
1 | 1 | package.cpath = "./?.so" |
2 | require "sram_gpio_lib" | |
2 | require "gpio" | |
3 | 3 | |
4 | 4 | PORT_A = 0 |
5 | 5 | PORT_B = 1 |
... | ... | |
7 | 7 | PORT_D = 3 |
8 | 8 | |
9 | 9 | function pulse() |
10 | sram_gpio_lib.jz_gpio_set_pin(pio,17) | |
10 | gpio.set_pin(pio,17) | |
11 | 11 | delay_s(1) |
12 | sram_gpio_lib.jz_gpio_clear_pin(pio,17) | |
12 | gpio.clear_pin(pio,17) | |
13 | 13 | delay_s(1) |
14 | 14 | end |
15 | 15 | |
... | ... | |
19 | 19 | while os.time() < time_to do end |
20 | 20 | end |
21 | 21 | |
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) | |
24 | 24 | |
25 | 25 | for i=0,5,1 do |
26 | 26 | pulse() |
Branches:
master