├── LICENSE ├── LuaNode_Esp32 ├── .gitmodules ├── LuaNode32 │ ├── .gitignore │ ├── CMakeLists.txt │ ├── components │ │ ├── lua │ │ │ ├── CMakeLists.txt │ │ │ ├── Kconfig │ │ │ ├── include │ │ │ │ ├── compiler.h │ │ │ │ ├── lapi.h │ │ │ │ ├── lauxlib.h │ │ │ │ ├── lcode.h │ │ │ │ ├── ldebug.h │ │ │ │ ├── ldo.h │ │ │ │ ├── legc.h │ │ │ │ ├── lfunc.h │ │ │ │ ├── lgc.h │ │ │ │ ├── llex.h │ │ │ │ ├── llimits.h │ │ │ │ ├── lmem.h │ │ │ │ ├── lobject.h │ │ │ │ ├── lopcodes.h │ │ │ │ ├── lparser.h │ │ │ │ ├── lrodefs.h │ │ │ │ ├── lrotable.h │ │ │ │ ├── lstate.h │ │ │ │ ├── lstring.h │ │ │ │ ├── ltable.h │ │ │ │ ├── ltm.h │ │ │ │ ├── lua.h │ │ │ │ ├── luac_cross.h │ │ │ │ ├── luaconf.h │ │ │ │ ├── lualib.h │ │ │ │ ├── lundump.h │ │ │ │ ├── lvm.h │ │ │ │ ├── lzio.h │ │ │ │ └── user_modules.h │ │ │ ├── lapi.c │ │ │ ├── lauxlib.c │ │ │ ├── lbaselib.c │ │ │ ├── lcode.c │ │ │ ├── ldblib.c │ │ │ ├── ldebug.c │ │ │ ├── ldo.c │ │ │ ├── ldump.c │ │ │ ├── legc.c │ │ │ ├── lfunc.c │ │ │ ├── lgc.c │ │ │ ├── linit.c │ │ │ ├── liolib.c │ │ │ ├── llex.c │ │ │ ├── lmathlib.c │ │ │ ├── lmem.c │ │ │ ├── loadlib.c │ │ │ ├── lobject.c │ │ │ ├── lopcodes.c │ │ │ ├── lparser.c │ │ │ ├── lrotable.c │ │ │ ├── lstate.c │ │ │ ├── lstring.c │ │ │ ├── lstrlib.c │ │ │ ├── ltable.c │ │ │ ├── ltablib.c │ │ │ ├── ltm.c │ │ │ ├── lua.c │ │ │ ├── lundump.c │ │ │ ├── lvm.c │ │ │ └── lzio.c │ │ ├── modules │ │ │ ├── CMakeLists.txt │ │ │ ├── file.c │ │ │ ├── gpio.c │ │ │ ├── node.c │ │ │ ├── tmr.c │ │ │ └── utils.c │ │ ├── mylibc │ │ │ ├── CMakeLists.txt │ │ │ ├── Kconfig │ │ │ ├── c_ctype.c │ │ │ ├── c_math.c │ │ │ ├── c_stdio.c │ │ │ ├── c_stdlib.c │ │ │ ├── c_string.c │ │ │ └── include │ │ │ │ ├── c_ctype.h │ │ │ │ ├── c_errno.h │ │ │ │ ├── c_fcntl.h │ │ │ │ ├── c_limits.h │ │ │ │ ├── c_locale.h │ │ │ │ ├── c_math.h │ │ │ │ ├── c_stdarg.h │ │ │ │ ├── c_stddef.h │ │ │ │ ├── c_stdint.h │ │ │ │ ├── c_stdio.h │ │ │ │ ├── c_stdlib.h │ │ │ │ ├── c_string.h │ │ │ │ └── c_types.h │ │ └── utils │ │ │ ├── CMakeLists.txt │ │ │ ├── include │ │ │ ├── platform.h │ │ │ └── utils.h │ │ │ ├── platform.c │ │ │ └── utils.c │ ├── examples │ │ ├── README.md │ │ ├── alexa_esp32 │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── components │ │ │ │ ├── alexa │ │ │ │ │ ├── alexa.c │ │ │ │ │ ├── component.mk │ │ │ │ │ └── include │ │ │ │ │ │ └── alexa.h │ │ │ │ └── utils │ │ │ │ │ ├── component.mk │ │ │ │ │ ├── include │ │ │ │ │ └── utils.h │ │ │ │ │ └── utils.c │ │ │ ├── main │ │ │ │ ├── component.mk │ │ │ │ ├── include │ │ │ │ │ └── user_config.h │ │ │ │ └── main.c │ │ │ └── sdkconfig │ │ ├── alexa_multi_esp32 │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── components │ │ │ │ ├── alexa │ │ │ │ │ ├── alexa.c │ │ │ │ │ ├── alexa_device.c │ │ │ │ │ ├── component.mk │ │ │ │ │ ├── include │ │ │ │ │ │ ├── alexa.h │ │ │ │ │ │ ├── alexa_device.h │ │ │ │ │ │ └── upnp_broadcast_responder.h │ │ │ │ │ └── upnp_broadcast_responder.c │ │ │ │ └── utils │ │ │ │ │ ├── component.mk │ │ │ │ │ ├── include │ │ │ │ │ └── utils.h │ │ │ │ │ └── utils.c │ │ │ ├── main │ │ │ │ ├── component.mk │ │ │ │ ├── include │ │ │ │ │ └── user_config.h │ │ │ │ └── main.c │ │ │ └── sdkconfig │ │ ├── ble_led_control │ │ │ ├── README.md │ │ │ ├── client │ │ │ │ ├── Makefile │ │ │ │ ├── main │ │ │ │ │ ├── component.mk │ │ │ │ │ └── gattc_demo.c │ │ │ │ ├── sdkconfig │ │ │ │ └── sdkconfig.defaults │ │ │ └── server │ │ │ │ ├── Makefile │ │ │ │ ├── main │ │ │ │ ├── Kconfig │ │ │ │ ├── component.mk │ │ │ │ └── gatts_demo.c │ │ │ │ ├── sdkconfig │ │ │ │ └── sdkconfig.defaults │ │ ├── ble_notification │ │ │ ├── gatt_client │ │ │ │ ├── Makefile │ │ │ │ ├── README.rst │ │ │ │ ├── main │ │ │ │ │ ├── component.mk │ │ │ │ │ └── gattc_demo.c │ │ │ │ ├── sdkconfig │ │ │ │ └── sdkconfig.defaults │ │ │ └── gatt_server │ │ │ │ ├── Makefile │ │ │ │ ├── README.rst │ │ │ │ ├── main │ │ │ │ ├── component.mk │ │ │ │ └── gatts_demo.c │ │ │ │ ├── sdkconfig │ │ │ │ └── sdkconfig.defaults │ │ ├── ble_to_udp_server │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── components │ │ │ │ ├── ble │ │ │ │ │ ├── ble.c │ │ │ │ │ ├── component.mk │ │ │ │ │ └── include │ │ │ │ │ │ └── ble.h │ │ │ │ ├── uart │ │ │ │ │ ├── component.mk │ │ │ │ │ ├── include │ │ │ │ │ │ └── my_uart.h │ │ │ │ │ └── my_uart.c │ │ │ │ └── utils │ │ │ │ │ ├── component.mk │ │ │ │ │ ├── include │ │ │ │ │ ├── my_list.h │ │ │ │ │ └── utils.h │ │ │ │ │ ├── my_list.c │ │ │ │ │ └── utils.c │ │ │ ├── main │ │ │ │ ├── component.mk │ │ │ │ ├── include │ │ │ │ │ ├── udp_task.h │ │ │ │ │ └── user_config.h │ │ │ │ ├── main.c │ │ │ │ └── udp_task.c │ │ │ └── sdkconfig │ │ ├── bluetooth_scanner │ │ │ ├── Makefile │ │ │ ├── main │ │ │ │ ├── app_main.c │ │ │ │ └── component.mk │ │ │ └── sdkconfig │ │ ├── camera │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── components │ │ │ │ └── camera │ │ │ │ │ ├── Kconfig.projbuild │ │ │ │ │ ├── camera.c │ │ │ │ │ ├── component.mk │ │ │ │ │ ├── include │ │ │ │ │ └── camera.h │ │ │ │ │ ├── ov7725.c │ │ │ │ │ ├── ov7725.h │ │ │ │ │ ├── ov7725_regs.h │ │ │ │ │ ├── sccb.c │ │ │ │ │ ├── sccb.h │ │ │ │ │ ├── sensor.h │ │ │ │ │ ├── twi.c │ │ │ │ │ ├── twi.h │ │ │ │ │ ├── wiring.c │ │ │ │ │ └── wiring.h │ │ │ ├── main │ │ │ │ ├── app_main.c │ │ │ │ └── component.mk │ │ │ ├── schematics │ │ │ │ ├── ov7725-camera-schematic1.pdf │ │ │ │ ├── ov7725-camera-schematic2.pdf │ │ │ │ └── ov7725-dimensions.jpg │ │ │ └── sdkconfig │ │ ├── dns_resolver │ │ │ └── app_main.c │ │ ├── ds1307 │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── components │ │ │ │ └── bsp │ │ │ │ │ ├── component.mk │ │ │ │ │ ├── ds1307.c │ │ │ │ │ └── include │ │ │ │ │ └── ds1307.h │ │ │ ├── main │ │ │ │ ├── component.mk │ │ │ │ └── main.c │ │ │ └── sdkconfig │ │ ├── easy_mem │ │ │ └── app_main.c │ │ ├── esp32_ble_gatt_server_led_control_for_phone │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── main │ │ │ │ ├── Kconfig │ │ │ │ ├── component.mk │ │ │ │ └── gatts_demo.c │ │ │ ├── sdkconfig │ │ │ └── sdkconfig.defaults │ │ ├── esp32_nrf51822_ble_conn │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── main │ │ │ │ ├── component.mk │ │ │ │ └── gattc_demo.c │ │ │ ├── sdkconfig │ │ │ └── sdkconfig.defaults │ │ ├── free80211send │ │ │ └── app_main.c │ │ ├── json │ │ │ ├── Makefile │ │ │ ├── main │ │ │ │ ├── component.mk │ │ │ │ └── main.c │ │ │ └── sdkconfig │ │ ├── lcd_nokia5110_driver │ │ │ ├── Nokia5510LCD_datasheet.pdf │ │ │ └── app_main.c │ │ ├── lwip_raw_api │ │ │ └── app_main.c │ │ ├── ota_tcp_update │ │ │ ├── README.md │ │ │ ├── client │ │ │ │ ├── Makefile │ │ │ │ ├── components │ │ │ │ │ ├── ota │ │ │ │ │ │ ├── component.mk │ │ │ │ │ │ ├── include │ │ │ │ │ │ │ └── ota.h │ │ │ │ │ │ └── ota.c │ │ │ │ │ └── utils │ │ │ │ │ │ ├── component.mk │ │ │ │ │ │ ├── include │ │ │ │ │ │ └── utils.h │ │ │ │ │ │ └── utils.c │ │ │ │ ├── main │ │ │ │ │ ├── component.mk │ │ │ │ │ ├── include │ │ │ │ │ │ └── user_config.h │ │ │ │ │ └── main.c │ │ │ │ └── sdkconfig │ │ │ └── server │ │ │ │ └── ota_server.py │ │ ├── raw_flash_rw │ │ │ └── app_main.c │ │ ├── simple_http_server │ │ │ └── app_main.c │ │ ├── tcp_client_espconn │ │ │ └── app_main.c │ │ ├── tcp_server_espconn │ │ │ └── app_main.c │ │ ├── telnet_server │ │ │ └── app_main.c │ │ ├── test_spiffs │ │ │ └── app_main.c │ │ ├── udp_broadcast │ │ │ └── app_main.c │ │ ├── udp_server_espconn │ │ │ └── app_main.c │ │ └── wifi_scan │ │ │ └── app_main.c │ ├── main │ │ ├── CMakeLists.txt │ │ ├── include │ │ │ ├── lua_def.h │ │ │ └── uart_handler.h │ │ ├── main.c │ │ └── uart_handler.c │ ├── partitions_luanode.csv │ ├── sdkconfig │ └── sdkconfig.ci ├── LuaNode32C6 │ ├── .gitignore │ ├── CMakeLists.txt │ ├── components │ │ ├── lua │ │ │ ├── CMakeLists.txt │ │ │ ├── Kconfig │ │ │ ├── include │ │ │ │ ├── compiler.h │ │ │ │ ├── lapi.h │ │ │ │ ├── lauxlib.h │ │ │ │ ├── lcode.h │ │ │ │ ├── ldebug.h │ │ │ │ ├── ldo.h │ │ │ │ ├── legc.h │ │ │ │ ├── lfunc.h │ │ │ │ ├── lgc.h │ │ │ │ ├── llex.h │ │ │ │ ├── llimits.h │ │ │ │ ├── lmem.h │ │ │ │ ├── lobject.h │ │ │ │ ├── lopcodes.h │ │ │ │ ├── lparser.h │ │ │ │ ├── lrodefs.h │ │ │ │ ├── lrotable.h │ │ │ │ ├── lstate.h │ │ │ │ ├── lstring.h │ │ │ │ ├── ltable.h │ │ │ │ ├── ltm.h │ │ │ │ ├── lua.h │ │ │ │ ├── luac_cross.h │ │ │ │ ├── luaconf.h │ │ │ │ ├── lualib.h │ │ │ │ ├── lundump.h │ │ │ │ ├── lvm.h │ │ │ │ ├── lzio.h │ │ │ │ └── user_modules.h │ │ │ ├── lapi.c │ │ │ ├── lauxlib.c │ │ │ ├── lbaselib.c │ │ │ ├── lcode.c │ │ │ ├── ldblib.c │ │ │ ├── ldebug.c │ │ │ ├── ldo.c │ │ │ ├── ldump.c │ │ │ ├── legc.c │ │ │ ├── lfunc.c │ │ │ ├── lgc.c │ │ │ ├── linit.c │ │ │ ├── liolib.c │ │ │ ├── llex.c │ │ │ ├── lmathlib.c │ │ │ ├── lmem.c │ │ │ ├── loadlib.c │ │ │ ├── lobject.c │ │ │ ├── lopcodes.c │ │ │ ├── lparser.c │ │ │ ├── lrotable.c │ │ │ ├── lstate.c │ │ │ ├── lstring.c │ │ │ ├── lstrlib.c │ │ │ ├── ltable.c │ │ │ ├── ltablib.c │ │ │ ├── ltm.c │ │ │ ├── lua.c │ │ │ ├── lundump.c │ │ │ ├── lvm.c │ │ │ └── lzio.c │ │ ├── modules │ │ │ ├── CMakeLists.txt │ │ │ ├── file.c │ │ │ ├── gpio.c │ │ │ ├── node.c │ │ │ ├── tmr.c │ │ │ ├── utils.c │ │ │ └── zigbee.c │ │ ├── mylibc │ │ │ ├── CMakeLists.txt │ │ │ ├── Kconfig │ │ │ ├── c_ctype.c │ │ │ ├── c_math.c │ │ │ ├── c_stdio.c │ │ │ ├── c_stdlib.c │ │ │ ├── c_string.c │ │ │ └── include │ │ │ │ ├── c_ctype.h │ │ │ │ ├── c_errno.h │ │ │ │ ├── c_fcntl.h │ │ │ │ ├── c_limits.h │ │ │ │ ├── c_locale.h │ │ │ │ ├── c_math.h │ │ │ │ ├── c_stdarg.h │ │ │ │ ├── c_stddef.h │ │ │ │ ├── c_stdint.h │ │ │ │ ├── c_stdio.h │ │ │ │ ├── c_stdlib.h │ │ │ │ ├── c_string.h │ │ │ │ └── c_types.h │ │ └── utils │ │ │ ├── CMakeLists.txt │ │ │ ├── include │ │ │ ├── platform.h │ │ │ └── utils.h │ │ │ ├── platform.c │ │ │ └── utils.c │ ├── main │ │ ├── CMakeLists.txt │ │ ├── include │ │ │ ├── lua_def.h │ │ │ └── uart_handler.h │ │ ├── main.c │ │ └── uart_handler.c │ ├── partitions_luanode.csv │ ├── sdkconfig │ ├── sdkconfig.ci │ └── sdkconfig.defaults ├── LuaNode32_document.docx ├── README.md └── firmware │ ├── LuaNode32C6.bin │ ├── LuaNode_201705040906.bin │ └── README.md ├── LuaNode_Esp8266 ├── CMakeLists.txt ├── Makefile ├── components │ ├── lua │ │ ├── CMakeLists.txt │ │ ├── Kconfig │ │ ├── component.mk │ │ ├── include │ │ │ ├── compiler.h │ │ │ ├── lapi.h │ │ │ ├── lauxlib.h │ │ │ ├── lcode.h │ │ │ ├── ldebug.h │ │ │ ├── ldo.h │ │ │ ├── legc.h │ │ │ ├── lfunc.h │ │ │ ├── lgc.h │ │ │ ├── llex.h │ │ │ ├── llimits.h │ │ │ ├── lmem.h │ │ │ ├── lobject.h │ │ │ ├── lopcodes.h │ │ │ ├── lparser.h │ │ │ ├── lrodefs.h │ │ │ ├── lrotable.h │ │ │ ├── lstate.h │ │ │ ├── lstring.h │ │ │ ├── ltable.h │ │ │ ├── ltm.h │ │ │ ├── lua.h │ │ │ ├── luac_cross.h │ │ │ ├── luaconf.h │ │ │ ├── lualib.h │ │ │ ├── lundump.h │ │ │ ├── lvm.h │ │ │ ├── lzio.h │ │ │ └── user_modules.h │ │ ├── lapi.c │ │ ├── lauxlib.c │ │ ├── lbaselib.c │ │ ├── lcode.c │ │ ├── ldblib.c │ │ ├── ldebug.c │ │ ├── ldo.c │ │ ├── ldump.c │ │ ├── legc.c │ │ ├── lfunc.c │ │ ├── lgc.c │ │ ├── linit.c │ │ ├── liolib.c │ │ ├── llex.c │ │ ├── lmathlib.c │ │ ├── lmem.c │ │ ├── loadlib.c │ │ ├── lobject.c │ │ ├── lopcodes.c │ │ ├── lparser.c │ │ ├── lrotable.c │ │ ├── lstate.c │ │ ├── lstring.c │ │ ├── lstrlib.c │ │ ├── ltable.c │ │ ├── ltablib.c │ │ ├── ltm.c │ │ ├── lua.c │ │ ├── lundump.c │ │ ├── lvm.c │ │ └── lzio.c │ ├── modules │ │ ├── CMakeLists.txt │ │ ├── component.mk │ │ ├── file.c │ │ ├── gpio.c │ │ ├── node.c │ │ ├── tmr.c │ │ ├── utils.c │ │ └── wifi.c │ ├── mylibc │ │ ├── CMakeLists.txt │ │ ├── Kconfig │ │ ├── c_ctype.c │ │ ├── c_math.c │ │ ├── c_stdio.c │ │ ├── c_stdlib.c │ │ ├── c_string.c │ │ ├── component.mk │ │ └── include │ │ │ ├── c_ctype.h │ │ │ ├── c_errno.h │ │ │ ├── c_fcntl.h │ │ │ ├── c_limits.h │ │ │ ├── c_locale.h │ │ │ ├── c_math.h │ │ │ ├── c_stdarg.h │ │ │ ├── c_stddef.h │ │ │ ├── c_stdint.h │ │ │ ├── c_stdio.h │ │ │ ├── c_stdlib.h │ │ │ ├── c_string.h │ │ │ └── c_types.h │ └── utils │ │ ├── CMakeLists.txt │ │ ├── component.mk │ │ ├── include │ │ ├── platform.h │ │ └── utils.h │ │ ├── platform.c │ │ └── utils.c ├── main │ ├── CMakeLists.txt │ ├── component.mk │ ├── include │ │ ├── lua_def.h │ │ └── uart_handler.h │ ├── main.c │ └── uart_handler.c ├── partitions_luanode.csv ├── sdkconfig └── sdkconfig.old ├── LuaNode_Stm32L4 └── README.md ├── README.md ├── images ├── ESP32_dimension.png ├── alexa_esp32.jpg ├── alexa_esp32_dev.png ├── ble_debug_tool.png ├── camera_test.jpg ├── esp32_LCD.jpg ├── esp32_cam.jpg ├── esp32_cam2.jpg ├── esp32_fig.png ├── esp_1.png ├── esp_2.png ├── esp_3.png ├── esp_4.png ├── esp_5.png ├── esp_6.png ├── esp_7.png ├── esplorer_run.png ├── logo.jpg ├── luanode_host.jpg ├── nrf51822_esp32_communication.jpg ├── ota_tcp.jpg ├── partitions.png ├── run_lua_code.png ├── startup.png └── w800.png └── lua_samples ├── base └── base.lua ├── file ├── file.lua ├── file_read.lua ├── file_remove.lua └── file_write.lua ├── gpio ├── gpio_in.lua ├── gpio_intr.lua ├── gpio_out.lua └── led_blink.lua ├── i2c ├── i2c.lua └── i2c_test.lua ├── lpeg └── lpeg.lua ├── mqtt └── mqtt.lua ├── net ├── net_tcp_client.lua └── net_tcp_server.lua ├── node └── node.lua ├── nvs └── nvs.lua ├── pwm └── pwm.lua ├── thread ├── thread.lua └── thread_once.lua ├── timer ├── timer.lua └── timer_callback.lua ├── uart └── uart.lua ├── utils └── utils.lua └── wifi ├── wifi_ap.lua └── wifi_sta.lua /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | it is free of charge, to any person obtaining a copy of this software and associated 3 | documentation files (the "Software"), to deal in the Software without restriction, 4 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 5 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software 6 | is furnished to do so, subject to the following conditions: 7 | 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 10 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 11 | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 12 | FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 13 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 14 | DEALINGS IN THE SOFTWARE. 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /LuaNode_Esp32/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "esp-idf"] 2 | path = esp-idf 3 | url = https://github.com/espressif/esp-idf 4 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | sdkconfig.old 3 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's 2 | # CMakeLists in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.16) 4 | set(EXTRA_COMPONENT_DIRS ./components) 5 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 6 | project(luanode) 7 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "lapi.c" "lcode.c" "ldo.c" "lfunc.c" "llex.c" "loadlib.c" "lparser.c" "lstring.c" "ltablib.c" "lundump.c" "lauxlib.c" "ldblib.c" "ldump.c" "lgc.c" "lmathlib.c" "lobject.c" "lrotable.c" "lstrlib.c" "ltm.c" "lvm.c" "lbaselib.c" "ldebug.c" "legc.c" "liolib.c" "lmem.c" "lopcodes.c" "lstate.c" "ltable.c" "lua.c" "lzio.c" "linit.c" 2 | REQUIRES vfs mylibc 3 | INCLUDE_DIRS "include") 4 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/Kconfig: -------------------------------------------------------------------------------- 1 | menu "LUA" 2 | 3 | config LUA_ENABLE 4 | bool "Enable lua" 5 | default "y" 6 | help 7 | For lua script. 8 | 9 | endmenu 10 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/compiler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * define start/end address of ro data. 3 | */ 4 | 5 | #ifndef __COMPILER_H__ 6 | #define __COMPILER_H__ 7 | 8 | #define __ESP32__ 9 | #if defined(__ESP8266__) 10 | 11 | extern char _irom0_text_start; 12 | extern char _irom0_text_end; 13 | #define RODATA_START_ADDRESS (&_irom0_text_start) 14 | #define RODATA_END_ADDRESS (&_irom0_text_end) 15 | 16 | #elif defined(__ESP32__) 17 | 18 | #define RODATA_START_ADDRESS ((char*)0x3F400000) 19 | #define RODATA_END_ADDRESS ((char*)0x3F800000) 20 | 21 | #else // other compilers 22 | 23 | /* Firstly, modify rodata's start/end address. Then, comment the line below */ 24 | #error "Please modify RODATA_START_ADDRESS and RODATA_END_ADDRESS below." 25 | 26 | /* Perhaps you can use start/end address of flash */ 27 | #define RODATA_START_ADDRESS ((char*)0x40200000) 28 | #define RODATA_END_ADDRESS ((char*)0x40280000) 29 | 30 | #endif 31 | 32 | #endif // __COMPILER_H__ 33 | 34 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #ifdef LUA_OPTIMIZE_DEBUG 17 | # include "lvm.h" 18 | # define getline(f,pc) (((f)->packedlineinfo) ? luaG_getline((f), pc) : 0) 19 | # define INFO_FILL_BYTE 0x7F 20 | # define INFO_DELTA_MASK 0x80 21 | # define INFO_SIGN_MASK 0x40 22 | # define INFO_DELTA_6BITS 0x3F 23 | # define INFO_DELTA_7BITS 0x7F 24 | # define INFO_MAX_LINECNT 126 25 | # define lineInfoTop(fs) ((fs)->f->packedlineinfo + (fs)->lastlineOffset) 26 | #else 27 | # define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 28 | #endif 29 | 30 | #define resethookcount(L) (L->hookcount = L->basehookcount) 31 | 32 | 33 | LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, 34 | const char *opname); 35 | LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 36 | LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, 37 | const TValue *p2); 38 | LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, 39 | const TValue *p2); 40 | LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); 41 | LUAI_FUNC void luaG_errormsg (lua_State *L); 42 | LUAI_FUNC int luaG_checkcode (const Proto *pt); 43 | LUAI_FUNC int luaG_checkopenop (Instruction i); 44 | #ifdef LUA_OPTIMIZE_DEBUG 45 | LUAI_FUNC int luaG_getline (const Proto *f, int pc); 46 | LUAI_FUNC int luaG_stripdebug (lua_State *L, Proto *f, int level, int recv); 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/legc.h: -------------------------------------------------------------------------------- 1 | // Lua EGC (Emergeny Garbage Collector) interface 2 | 3 | #ifndef __LEGC_H__ 4 | #define __LEGC_H__ 5 | 6 | #include "lstate.h" 7 | 8 | // EGC operations modes 9 | #define EGC_NOT_ACTIVE 0 // EGC disabled 10 | #define EGC_ON_ALLOC_FAILURE 1 // run EGC on allocation failure 11 | #define EGC_ON_MEM_LIMIT 2 // run EGC when an upper memory limit is hit 12 | #define EGC_ALWAYS 4 // always run EGC before an allocation 13 | 14 | void legc_set_mode(lua_State *L, int mode, unsigned limit); 15 | 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | #include "lgc.h" 14 | 15 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 16 | cast(int, sizeof(TValue)*((n)-1))) 17 | 18 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 19 | cast(int, sizeof(TValue *)*((n)-1))) 20 | 21 | #define proto_readonly(p) l_setbit((p)->marked, READONLYBIT) 22 | #define proto_is_readonly(p) testbit((p)->marked, READONLYBIT) 23 | 24 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 25 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); 26 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); 27 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 28 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 29 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 30 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 31 | LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); 32 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 33 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 34 | int pc); 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | //#ifdef LUA_CROSS_COMPILER 12 | //#include 13 | //#else 14 | //#include "c_stddef.h" 15 | //#endif 16 | 17 | #include "llimits.h" 18 | #include "lua.h" 19 | 20 | #define MEMERRMSG "not enough memory" 21 | 22 | 23 | #define luaM_reallocv(L,b,on,n,e) \ 24 | ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ 25 | luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ 26 | luaM_toobig(L)) 27 | 28 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 29 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 30 | #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) 31 | 32 | #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) 33 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 34 | #define luaM_newvector(L,n,t) \ 35 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 36 | 37 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 38 | if ((nelems)+1 > (size)) \ 39 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 40 | 41 | #define luaM_reallocvector(L, v,oldn,n,t) \ 42 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 43 | 44 | 45 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 46 | size_t size); 47 | LUAI_FUNC void *luaM_toobig (lua_State *L); 48 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 49 | size_t size_elem, int limit, 50 | const char *errormsg); 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/lrodefs.h: -------------------------------------------------------------------------------- 1 | /* Read-only tables helper */ 2 | 3 | #ifndef lrodefs_h 4 | #define lrodefs_h 5 | 6 | #include "lrotable.h" 7 | 8 | #undef LUA_REG_TYPE 9 | #undef LSTRKEY 10 | #undef LNILKEY 11 | #undef LNUMKEY 12 | #undef LFUNCVAL 13 | #undef LNUMVAL 14 | #undef LROVAL 15 | #undef LNILVAL 16 | #undef LREGISTER 17 | 18 | #if (MIN_OPT_LEVEL > 0) && (LUA_OPTIMIZE_MEMORY >= MIN_OPT_LEVEL) 19 | #define LUA_REG_TYPE luaR_entry 20 | #define LSTRKEY LRO_STRKEY 21 | #define LNUMKEY LRO_NUMKEY 22 | #define LNILKEY LRO_NILKEY 23 | #define LFUNCVAL LRO_FUNCVAL 24 | #define LUDATA LRO_LUDATA 25 | #define LNUMVAL LRO_NUMVAL 26 | #define LROVAL LRO_ROVAL 27 | #define LNILVAL LRO_NILVAL 28 | #define LREGISTER(L, name, table)\ 29 | return 0 30 | #else 31 | #define LUA_REG_TYPE luaL_reg 32 | #define LSTRKEY(x) x 33 | #define LNILKEY NULL 34 | #define LFUNCVAL(x) x 35 | #define LNILVAL NULL 36 | #define LREGISTER(L, name, table)\ 37 | luaL_register(L, name, table);\ 38 | return 1 39 | #endif 40 | 41 | #endif /* lrodefs_h */ 42 | 43 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | 11 | #include "lgc.h" 12 | #include "lobject.h" 13 | #include "lstate.h" 14 | 15 | 16 | #define sizestring(s) (sizeof(union TString)+(luaS_isreadonly(s) ? sizeof(char **) : ((s)->len+1)*sizeof(char))) 17 | 18 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 19 | 20 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) 21 | #define luaS_newro(L, s) (luaS_newrolstr(L, s, strlen(s))) 22 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 23 | (sizeof(s)/sizeof(char))-1)) 24 | 25 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 26 | #define luaS_readonly(s) l_setbit((s)->tsv.marked, READONLYBIT) 27 | #define luaS_isreadonly(s) testbit((s)->marked, READONLYBIT) 28 | 29 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 30 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 31 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 32 | LUAI_FUNC TString *luaS_newrolstr (lua_State *L, const char *str, size_t l); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key.tvk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define key2tval(n) (&(n)->i_key.tvk) 19 | 20 | 21 | LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); 22 | LUAI_FUNC const TValue *luaH_getnum_ro (void *t, int key); 23 | LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); 24 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 25 | LUAI_FUNC const TValue *luaH_getstr_ro (void *t, TString *key); 26 | LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); 27 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 28 | LUAI_FUNC const TValue *luaH_get_ro (void *t, const TValue *key); 29 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 30 | LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); 31 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 32 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 33 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 34 | LUAI_FUNC int luaH_next_ro (lua_State *L, void *t, StkId key); 35 | LUAI_FUNC int luaH_getn (Table *t); 36 | LUAI_FUNC int luaH_getn_ro (void *t); 37 | 38 | #if defined(LUA_DEBUG) 39 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 40 | LUAI_FUNC int luaH_isdummy (Node *n); 41 | #endif 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_EQ, /* last tag method with `fast' access */ 24 | TM_ADD, 25 | TM_SUB, 26 | TM_MUL, 27 | TM_DIV, 28 | TM_MOD, 29 | TM_POW, 30 | TM_UNM, 31 | TM_LEN, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | !luaR_isrotable(et) && ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | LUAI_DATA const char *const luaT_typenames[]; 47 | 48 | 49 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 50 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 51 | TMS event); 52 | LUAI_FUNC void luaT_init (lua_State *L); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/luac_cross.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Header to allow luac.cross compile within NodeMCU 3 | ** See Copyright Notice in lua.h 4 | */ 5 | #ifndef luac_cross_h 6 | #define luac_cross_h 7 | 8 | #define C_HEADER_ASSERT 9 | #define C_HEADER_CTYPE 10 | #define C_HEADER_ERRNO 11 | #define C_HEADER_FCNTL 12 | #define C_HEADER_LOCALE 13 | #define C_HEADER_MATH 14 | #define C_HEADER_STDIO 15 | #define C_HEADER_STDLIB 16 | #define C_HEADER_STRING 17 | #define C_HEADER_TIME 18 | 19 | #ifdef LUA_CROSS_COMPILER 20 | #define ICACHE_RODATA_ATTR 21 | #endif 22 | 23 | #endif /* luac_cross_h */ 24 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include 11 | 12 | #include "lobject.h" 13 | #include "lzio.h" 14 | 15 | typedef uint32_t strsize_t; 16 | 17 | /* info about target machine for cross-compilation */ 18 | typedef struct { 19 | int little_endian; 20 | int sizeof_int; 21 | int sizeof_strsize_t; 22 | int sizeof_lua_Number; 23 | int lua_Number_integral; 24 | int is_arm_fpa; 25 | } DumpTargetInfo; 26 | 27 | /* load one chunk; from lundump.c */ 28 | LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 29 | 30 | /* make header; from lundump.c */ 31 | LUAI_FUNC void luaU_header (char* h); 32 | 33 | /* dump one chunk to a different target; from ldump.c */ 34 | int luaU_dump_crosscompile (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip, DumpTargetInfo target); 35 | 36 | /* dump one chunk; from ldump.c */ 37 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 38 | 39 | #ifdef luac_c 40 | /* print one chunk; from print.c */ 41 | LUAI_FUNC void luaU_print (const Proto* f, int full); 42 | #endif 43 | 44 | /* for header of binary files -- this is Lua 5.1 */ 45 | #define LUAC_VERSION 0x51 46 | 47 | /* for header of binary files -- this is the official format */ 48 | #define LUAC_FORMAT 0 49 | 50 | /* size of header of binary files */ 51 | #define LUAC_HEADERSIZE 12 52 | 53 | /* error codes from cross-compiler */ 54 | /* target integer is too small to hold a value */ 55 | #define LUA_ERR_CC_INTOVERFLOW 101 56 | 57 | /* target lua_Number is integral but a constant is non-integer */ 58 | #define LUA_ERR_CC_NOTINTEGER 102 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ 19 | (((o) = luaV_tonumber(o,n)) != NULL)) 20 | 21 | #define equalobj(L,o1,o2) \ 22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) 23 | 24 | 25 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 26 | LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); 27 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 28 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 29 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 30 | StkId val); 31 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 32 | StkId val); 33 | LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); 34 | LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/include/user_modules.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_MODULES_H__ 2 | #define __USER_MODULES_H__ 3 | 4 | #define LUA_USE_BUILTIN_STRING // for string.xxx() 5 | #define LUA_USE_BUILTIN_TABLE // for table.xxx() 6 | #define LUA_USE_BUILTIN_COROUTINE // for coroutine.xxx() 7 | #define LUA_USE_BUILTIN_MATH // for math.xxx(), partially work 8 | // #define LUA_USE_BUILTIN_IO // for io.xxx(), partially work 9 | 10 | // #define LUA_USE_BUILTIN_OS // for os.xxx(), not work 11 | // #define LUA_USE_BUILTIN_DEBUG 12 | #define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback() 13 | 14 | 15 | #define USE_NODE_MODULE 16 | #define USE_FILE_MODULE 17 | #define USE_GPIO_MODULE 18 | #define USE_UTILS_MODULE 19 | #define USE_TMR_MODULE 20 | /*#define USE_LPEG_MODULE 21 | #define USE_UART_MODULE 22 | #define USE_MQTT_MODULE 23 | #define USE_PWM_MODULE 24 | #define USE_I2C_MODULE 25 | #define USE_WIFI_MODULE 26 | #define USE_NET_MODULE 27 | //#define USE_THREAD_MODULE 28 | #define USE_NVS_MODULE 29 | */ 30 | 31 | 32 | 33 | #endif /* __USER_MODULES_H__ */ 34 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/lua/legc.c: -------------------------------------------------------------------------------- 1 | // Lua EGC (Emergeny Garbage Collector) interface 2 | 3 | #include "legc.h" 4 | #include "lstate.h" 5 | 6 | void legc_set_mode(lua_State *L, int mode, unsigned limit) { 7 | global_State *g = G(L); 8 | 9 | g->egcmode = mode; 10 | g->memlimit = limit; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "node.c" "file.c" "gpio.c" "utils.c" "tmr.c" 2 | REQUIRES lua utils spiffs driver esp_timer esp_event 3 | INCLUDE_DIRS "include") 4 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/mylibc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "c_ctype.c" "c_math.c" "c_stdio.c" "c_stdlib.c" "c_string.c" 2 | INCLUDE_DIRS "include") 3 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/mylibc/Kconfig: -------------------------------------------------------------------------------- 1 | menu "MYLIBC" 2 | 3 | config MYLIBC_ENABLE 4 | bool "Enable mylibc" 5 | default "y" 6 | help 7 | For mylibc. 8 | 9 | endmenu 10 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/mylibc/c_ctype.c: -------------------------------------------------------------------------------- 1 | #include "c_ctype.h" 2 | #include "c_types.h" 3 | 4 | // int isalnum(int c){} 5 | // int isalpha(int c){} 6 | // int iscntrl(int c){} 7 | // int isdigit(int c){} 8 | // // int isgraph(int c){} 9 | // int islower(int c){} 10 | // int isprint(int c){} 11 | // int ispunct(int c){} 12 | // int isspace(int c){} 13 | // int isupper(int c){} 14 | // int isxdigit(int c){} 15 | // int tolower(int c){} 16 | // int toupper(int c){} 17 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/mylibc/c_string.c: -------------------------------------------------------------------------------- 1 | #include "c_string.h" 2 | 3 | // const char *c_strstr(const char * __s1, const char * __s2){ 4 | // } 5 | 6 | // char *c_strncat(char * s1, const char * s2, size_t n){ 7 | // } 8 | 9 | // size_t c_strcspn(const char * s1, const char * s2){ 10 | // } 11 | 12 | // const char *c_strpbrk(const char * s1, const char * s2){ 13 | // } 14 | 15 | // int c_strcoll(const char * s1, const char * s2){ 16 | // } 17 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/mylibc/include/c_ctype.h: -------------------------------------------------------------------------------- 1 | #ifndef _C_CTYPE_H_ 2 | #define _C_CTYPE_H_ 3 | 4 | #if 0 5 | int isalnum(int); 6 | int isalpha(int); 7 | int iscntrl(int); 8 | int isdigit(int); 9 | // int isgraph(int); 10 | int islower(int); 11 | int isprint(int); 12 | int ispunct(int); 13 | int isspace(int); 14 | int isupper(int); 15 | int isxdigit(int); 16 | int tolower(int); 17 | int toupper(int); 18 | 19 | #if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L 20 | // int isblank(int); 21 | #endif 22 | 23 | #ifndef __STRICT_ANSI__ 24 | // int isascii(int); 25 | // int toascii(int); 26 | #define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a') 27 | #define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A') 28 | #endif 29 | 30 | #define _U 01 31 | #define _L 02 32 | #define _N 04 33 | #define _S 010 34 | #define _P 020 35 | #define _C 040 36 | #define _X 0100 37 | #define _B 0200 38 | 39 | /* For C++ backward-compatibility only. */ 40 | // extern char _ctype_[]; 41 | #endif 42 | #endif /* _C_CTYPE_H_ */ 43 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/mylibc/include/c_errno.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_errno_h 2 | #define __c_errno_h 3 | 4 | #include 5 | // #ifndef errno 6 | // extern int errno; 7 | // #endif 8 | 9 | // #define EDOM 1 10 | // #define ERANGE 2 11 | // #define EILSEQ 4 12 | // #define ESIGNUM 3 13 | // #define EINVAL 5 14 | // #define ENOMEM 6 15 | 16 | #endif 17 | 18 | /* end of c_errno.h */ 19 | 20 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/mylibc/include/c_fcntl.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_fcntl_h 2 | #define __c_fcntl_h 3 | 4 | #include 5 | 6 | #endif 7 | 8 | /* end of c_fcntl.h */ 9 | 10 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/mylibc/include/c_locale.h: -------------------------------------------------------------------------------- 1 | /* 2 | c_locale.h 3 | Values appropriate for the formatting of monetary and other 4 | numberic quantities. 5 | */ 6 | 7 | #ifndef _C_LOCALE_H_ 8 | #define _C_LOCALE_H_ 9 | 10 | #include 11 | 12 | #if 0 13 | #ifndef NULL 14 | #define NULL 0 15 | #endif 16 | 17 | #define LC_ALL 0 18 | #define LC_COLLATE 1 19 | #define LC_CTYPE 2 20 | #define LC_MONETARY 3 21 | #define LC_NUMERIC 4 22 | #define LC_TIME 5 23 | #define LC_MESSAGES 6 24 | 25 | struct lconv 26 | { 27 | char *decimal_point; 28 | char *thousands_sep; 29 | char *grouping; 30 | char *int_curr_symbol; 31 | char *currency_symbol; 32 | char *mon_decimal_point; 33 | char *mon_thousands_sep; 34 | char *mon_grouping; 35 | char *positive_sign; 36 | char *negative_sign; 37 | char int_frac_digits; 38 | char frac_digits; 39 | char p_cs_precedes; 40 | char p_sep_by_space; 41 | char n_cs_precedes; 42 | char n_sep_by_space; 43 | char p_sign_posn; 44 | char n_sign_posn; 45 | char int_n_cs_precedes; 46 | char int_n_sep_by_space; 47 | char int_n_sign_posn; 48 | char int_p_cs_precedes; 49 | char int_p_sep_by_space; 50 | char int_p_sign_posn; 51 | }; 52 | 53 | #ifndef _REENT_ONLY 54 | // char *setlocale(int category, const char *locale); 55 | struct lconv *localeconv(void); 56 | #endif 57 | 58 | // struct _reent; 59 | // char *_setlocale_r(struct _reent *, int category, const char *locale); 60 | // struct lconv *_localeconv_r(struct _reent *); 61 | #endif 62 | #endif /* _C_LOCALE_H_ */ 63 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/mylibc/include/c_math.h: -------------------------------------------------------------------------------- 1 | #ifndef _C_MATH_H_ 2 | #define _C_MATH_H_ 3 | #include 4 | 5 | double floor(double); 6 | double pow(double, double); 7 | 8 | #if 0 9 | #ifndef HUGE_VAL 10 | #define HUGE_VAL (1.0e99) 11 | #endif 12 | 13 | #ifndef HUGE_VALF 14 | #define HUGE_VALF (1.0e999999999F) 15 | #endif 16 | 17 | #if !defined(HUGE_VALL) && defined(_HAVE_LONG_DOUBLE) 18 | #define HUGE_VALL (1.0e999999999L) 19 | #endif 20 | 21 | #if !defined(INFINITY) 22 | #define INFINITY (HUGE_VALF) 23 | #endif 24 | 25 | 26 | /* Reentrant ANSI C functions. */ 27 | 28 | #ifndef __math_68881 29 | // double atan(double); 30 | // double cos(double); 31 | // double sin(double); 32 | // double tan(double); 33 | // double tanh(double); 34 | // double frexp(double, int *); 35 | // double modf(double, double *); 36 | // double ceil(double); 37 | // double fabs(double); 38 | // double floor(double); 39 | #endif /* ! defined (__math_68881) */ 40 | 41 | /* Non reentrant ANSI C functions. */ 42 | 43 | #ifndef _REENT_ONLY 44 | #ifndef __math_68881 45 | // double acos(double); 46 | // double asin(double); 47 | // double atan2(double, double); 48 | // double cosh(double); 49 | // double sinh(double); 50 | // double exp(double); 51 | // double ldexp(double, int); 52 | // double log(double); 53 | // double log10(double); 54 | // double pow(double, double); 55 | // double sqrt(double); 56 | // double fmod(double, double); 57 | #endif /* ! defined (__math_68881) */ 58 | #endif /* ! defined (_REENT_ONLY) */ 59 | 60 | #endif 61 | 62 | #endif /* _MATH_H_ */ 63 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/mylibc/include/c_stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_stdarg_h 2 | #define __c_stdarg_h 3 | 4 | #if defined(__GNUC__) 5 | 6 | #include 7 | 8 | #else 9 | 10 | typedef char * va_list; 11 | 12 | #define _INTSIZEOF(n) ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1)) 13 | 14 | #define va_start(ap,v) (ap = (va_list)&v + _INTSIZEOF(v)) 15 | #define va_arg(ap,t) (*(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t))) 16 | #define va_end(ap) (ap = (va_list)0) 17 | 18 | #endif 19 | 20 | #endif 21 | 22 | /* end of c_stdarg.h */ 23 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/mylibc/include/c_stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_stddef_h 2 | #define __c_stddef_h 3 | 4 | typedef signed int ptrdiff_t; 5 | 6 | #if !defined(offsetof) 7 | #define offsetof(s, m) (size_t)&(((s *)0)->m) 8 | #endif 9 | 10 | #if !defined(__size_t) 11 | #define __size_t 1 12 | typedef unsigned int size_t; /* others (e.g. ) also define */ 13 | /* the unsigned integral type of the result of the sizeof operator. */ 14 | #endif 15 | 16 | #undef NULL /* others (e.g. ) also define */ 17 | #define NULL 0 18 | /* null pointer constant. */ 19 | 20 | #endif 21 | 22 | /* end of c_stddef.h */ 23 | 24 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/mylibc/include/c_stdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * c_stdlib.h 3 | * 4 | * Definitions for common types, variables, and functions. 5 | */ 6 | 7 | #ifndef _C_STDLIB_H_ 8 | #define _C_STDLIB_H_ 9 | 10 | #include "c_stddef.h" 11 | //#include "mem.h" 12 | 13 | #include 14 | 15 | #define EXIT_FAILURE 1 16 | #define EXIT_SUCCESS 0 17 | 18 | //#define __INT_MAX__ 2147483647 19 | #undef __RAND_MAX 20 | #if __INT_MAX__ == 32767 21 | #define __RAND_MAX 32767 22 | #else 23 | #define __RAND_MAX 0x7fffffff 24 | #endif 25 | #define RAND_MAX __RAND_MAX 26 | 27 | #ifndef mem_realloc 28 | #define mem_realloc pvPortRealloc 29 | #endif 30 | #ifndef os_realloc 31 | #define os_realloc(p, s) mem_realloc((p), (s)) 32 | #endif 33 | 34 | #define c_free free 35 | #define c_malloc os_malloc 36 | #define c_zalloc os_zalloc 37 | #define c_realloc realloc 38 | 39 | #define c_abs abs 40 | #define c_atoi atoi 41 | //#define c_strtod strtod 42 | #define c_strtol strtol 43 | #define c_strtoul strtoul 44 | 45 | // int c_abs(int); 46 | 47 | // void c_exit(int); 48 | 49 | #define ICACHE_STORE_ATTR __attribute__((aligned(4))) 50 | 51 | // c_getenv() get env "LUA_INIT" string for lua initialization. 52 | const char *c_getenv(const char *__string); 53 | 54 | // void *c_malloc(size_t __size); 55 | // void *c_zalloc(size_t __size); 56 | // void c_free(void *); 57 | 58 | // int c_rand(void); 59 | // void c_srand(unsigned int __seed); 60 | 61 | // int c_atoi(const char *__nptr); 62 | double c_strtod(const char *__n, char **__end_PTR); 63 | // // long c_strtol(const char *__n, char **__end_PTR, int __base); 64 | // unsigned long c_strtoul(const char *__n, char **__end_PTR, int __base); 65 | // // long long c_strtoll(const char *__n, char **__end_PTR, int __base); 66 | 67 | #endif /* _C_STDLIB_H_ */ 68 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/mylibc/include/c_string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * c_string.h 3 | * 4 | * Definitions for memory and string functions. 5 | */ 6 | 7 | #ifndef _C_STRING_H_ 8 | #define _C_STRING_H_ 9 | #include "c_stddef.h" 10 | //#include "osapi.h" 11 | //#include "esp_libc.h" 12 | #include 13 | 14 | #ifndef NULL 15 | #define NULL 0 16 | #endif 17 | 18 | #define c_memcmp memcmp 19 | #define c_memcpy memcpy 20 | #define c_memset memset 21 | 22 | #define os_memcpy ets_memcpy 23 | #define os_memcmp ets_memcmp 24 | #define os_memmove ets_memmove 25 | 26 | #define c_strcat strcat 27 | #define c_strchr strchr 28 | #define c_strcmp strcmp 29 | #define c_strcpy strcpy 30 | #define c_strlen strlen 31 | #define c_strncmp strncmp 32 | #define c_strncpy strncpy 33 | // #define c_strstr os_strstr 34 | #define c_strncasecmp strncmp 35 | 36 | #define c_strstr strstr 37 | #define c_strncat strncat 38 | #define c_strcspn strcspn 39 | #define c_strpbrk strpbrk 40 | #define c_strcoll strcoll 41 | #define c_strrchr strrchr 42 | 43 | //extern unsigned int strlen(char *s); 44 | //extern char *strcat(char *dest, char *src); 45 | //extern char *strchr(const char *s, int c); 46 | //extern char *strcpy(char* des, const char* source); 47 | //extern char *strncpy(char *dest, const char *src, size_t n); 48 | //extern void *memcpy(void *dest, const void *src, size_t n); 49 | extern void *memchr(const void *buf, int ch, size_t count); 50 | extern char *strpbrk(const char *s1, const char *s2); 51 | 52 | // const char *c_strstr(const char * __s1, const char * __s2); 53 | // char *c_strncat(char * __restrict /*s1*/, const char * __restrict /*s2*/, size_t n); 54 | // size_t c_strcspn(const char * s1, const char * s2); 55 | // const char *c_strpbrk(const char * /*s1*/, const char * /*s2*/); 56 | // int c_strcoll(const char * /*s1*/, const char * /*s2*/); 57 | 58 | #endif /* _C_STRING_H_ */ 59 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "utils.c" "platform.c" 2 | REQUIRES driver 3 | INCLUDE_DIRS "include") 4 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/utils/include/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef _PLATFORM_H_ 2 | #define _PLATFORM_H_ 3 | 4 | #define NODE_PLATFORM_ESP32 1001 5 | #define NODE_PLATFORM_ESP8266 1002 6 | #define NODE_PLATFORM_STM32 1003 7 | #define NODE_PLATFORM_W800 1004 8 | 9 | 10 | #define CURRENT_PLATFORM NODE_PLATFORM_ESP32 11 | #define BUILD_SPIFFS 12 | 13 | 14 | #if (CURRENT_PLATFORM == NODE_PLATFORM_ESP32) 15 | #define OUTPUT GPIO_MODE_OUTPUT 16 | #define INPUT GPIO_MODE_INPUT 17 | #define PULLUP GPIO_PULLUP_ONLY 18 | #define FLOAT GPIO_FLOATING 19 | #define INOUT GPIO_MODE_INPUT_OUTPUT 20 | #define PLATFORM_INTERRUPT GPIO_INTR_POSEDGE 21 | #define HIGH 1 22 | #define LOW 0 23 | #define GPIO_PIN_NUM GPIO_NUM_MAX 24 | #else 25 | #define PULLUP PLATFORM_GPIO_PULLUP 26 | #define FLOAT PLATFORM_GPIO_FLOAT 27 | #define OUTPUT PLATFORM_GPIO_OUTPUT 28 | #define INPUT PLATFORM_GPIO_INPUT 29 | #define INOUT PLATFORM_GPIO_INOUT 30 | #define PLATFORM_INTERRUPT PLATFORM_GPIO_INT 31 | #define HIGH PLATFORM_GPIO_HIGH 32 | #define LOW PLATFORM_GPIO_LOW 33 | #endif 34 | 35 | void lua_node_restart(void); 36 | void lua_node_sleep(uint64_t us); 37 | uint32_t lua_node_get_heap_size(void); 38 | void lua_node_system_restore(void); 39 | 40 | int platform_gpio_mode(int pin, int mode, int type); 41 | void platform_gpio_isr_uninstall(void); 42 | uint8_t platform_gpio_read(int pin); 43 | void platform_gpio_write(int pin, int level); 44 | 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/utils/include/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_H_ 2 | #define _UTILS_H_ 3 | 4 | typedef enum { 5 | EMPTY, 6 | UNDER_WRITE, 7 | WRITE_OVER 8 | } RcvMsgBuffState; 9 | 10 | 11 | typedef struct { 12 | uint32_t RcvBuffSize; 13 | uint8_t *pRcvMsgBuff; 14 | uint8_t *pWritePos; 15 | uint8_t *pReadPos; 16 | uint8_t TrigLvl; //JLU: may need to pad 17 | RcvMsgBuffState BuffState; 18 | } RcvMsgBuff; 19 | 20 | void print_info(void); 21 | //char *basename(char *path); 22 | char * get_partition_label(void); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/components/utils/utils.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "utils.h" 4 | 5 | void print_info(void) 6 | { 7 | printf(" _ _ _ _ \n\ 8 | | | | \\ | | | | \n\ 9 | | | _ _ __ _ | \\| | ___ __| | ___ \n\ 10 | | | | | | | / _` || . ` | / _ \\ / _` | / _ \\\n\ 11 | | |____| |_| || (_| || |\\ || (_) || (_| || __/\n\ 12 | \\_____/ \\__,_| \\__,_|\\_| \\_/ \\___/ \\__,_| \\___|\n\ 13 | \n\ 14 | For ESP32 \n\ 15 | Version 2.0.0\n\ 16 | \n\ 17 | ------------------------------------------------\n\ 18 | \n"); 19 | } 20 | 21 | /*char *basename(char *path) 22 | { 23 | int num = strlen(path); 24 | for (int i = num-1; i >= 0; i++) { 25 | if (path[i] == '/') { 26 | return path+i+1; 27 | } 28 | } 29 | return path; 30 | }*/ 31 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_esp32/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := alexa_esp32 2 | 3 | include $(IDF_PATH)/make/project.mk 4 | 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_esp32/README.md: -------------------------------------------------------------------------------- 1 | ## ESP32 voice control via Amazon Echo Dot (Alexa) 2 | 3 | This is an awesome application that using Amazon Echo Dot to turn on/off the blue LED on DOIT ESP32 dev-board via voice 4 | control service. You can find the source code, named `alexa_esp32`, within the `examples` directory. 5 | 6 | ![github](https://github.com/Nicholas3388/LuaNode/raw/master/images/alexa_esp32.jpg "Amazon Echo Dot & ESP32 board") 7 | 8 | When you build the `alexa_esp32` within the examples folder and flash the firmware to ESP32 board, then you can ask 9 | Echo Dot to discover device by telling her "Alexa, discover device". She will answer you "Discovery starting...". After about 10 | 20 seconds, if She does find device, she will answer you "I found 1 device...". Plus, you can search device via Alexa App or 11 | via this page: `alexa.amazon.com`. When Echo Dot find ESP32, you will see the found device named "esp" on `alexa.amazon.com`, show 12 | as the following figure: 13 | 14 | ![github](https://github.com/Nicholas3388/LuaNode/raw/master/images/alexa_esp32_dev.png "Alexa found ESP32 device") 15 | 16 | When Alexa find ESP32 device successfully, you can ask Echo Dot "Alexa, turn on ESP" to turn on the blue LED on ESP32 borad. Ask 17 | "Alexa, turn off ESP" to turn off the LED. The following link is a video to show the ESP32 voice control via Amazon Echo Dot: https://youtu.be/Eg1dApUHIBc 18 | 19 | 20 | ## How to build 21 | 22 | export your esp-idf path first, input `export IDF_PATH=/your_idf_path` on terminal. Then input `make` to build this project. 23 | 24 | ## How to config 25 | 26 | * The Amazon Echo Dot will find the ESP32 device as `esp`, the name will show on Alexa server. You can change the name by 27 | changing the string named `device_name` in `alexa.c` 28 | * Config Wifi SSID and Password in `user_config.h` 29 | * Macro `GPIO_TEST` is the pin for the blue LED 30 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_esp32/components/alexa/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_esp32/components/alexa/include/alexa.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __ALEXA_H__ 16 | #define __ALEXA_H__ 17 | 18 | void alexa_init(void); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_esp32/components/utils/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_esp32/components/utils/include/utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __UTILS_H__ 16 | #define __UTILS_H__ 17 | 18 | #include "lwip/ip_addr.h" 19 | 20 | void printHex(char c); 21 | void delay_ms(int ms); 22 | void ip_addr_to_num(unsigned char *res, ip_addr_t *addr); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_esp32/components/utils/utils.c: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "utils.h" 18 | #include "esp_log.h" 19 | 20 | #include "freertos/FreeRTOS.h" 21 | #include "freertos/task.h" 22 | 23 | static const char *TAG = "utils"; 24 | 25 | void printHex(char c) 26 | { 27 | char buff[3] = {0x0}; 28 | sprintf(buff, "%02X ", c); 29 | ESP_LOGI(TAG, "%s", buff); 30 | } 31 | 32 | void delay_ms(int ms) 33 | { 34 | vTaskDelay(ms / portTICK_RATE_MS); 35 | } 36 | 37 | void ip_addr_to_num(unsigned char *res, ip_addr_t *addr) 38 | { 39 | unsigned int ip = (addr->u_addr).ip4.addr; 40 | res[0] = (unsigned char)(ip & 0xFF); 41 | res[1] = (unsigned char)((ip >> 8) & 0xFF); 42 | res[2] = (unsigned char)((ip >> 16) & 0xFF); 43 | res[3] = (unsigned char)((ip >> 24) & 0xFF); 44 | } -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_esp32/main/component.mk: -------------------------------------------------------------------------------- 1 | # do nothing 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_esp32/main/include/user_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #define TMP_TASK_STACK_SIZE 2048 16 | #define TMP_TASK_PRIO 9 17 | #define ALEXA_TASK_STACK_SIZE 4096 18 | #define ALEXA_TASK_PRIO 4 19 | #define ALEXA_UDP_TASK_STACK_SIZE 4096 20 | #define ALEXA_UDP_TASK_PRIO 4 21 | 22 | #define MY_WIFI_SSID "doit_newifi" 23 | #define MY_WIFI_PASS "doit3305" 24 | 25 | #define HTTP_SRV_PORT 80 26 | 27 | #define GPIO_TEST 2 -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_multi_esp32/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := alexa_esp32 2 | 3 | include $(IDF_PATH)/make/project.mk 4 | 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_multi_esp32/README.md: -------------------------------------------------------------------------------- 1 | ## How to use 2 | 3 | In the function `alexa_init` function defined in `alexa.c`, you can call `create_new_device` 4 | to add a new device to be controlled by Alexa. As for the parameters of `create_new_device`, 5 | the first parameter is the device name, the second one is the TCP server port, each device need 6 | a TCP server to communicate with Alexa Echo device, the third one is a callback when user ask "Alexa, 7 | turn on `device_name`", the last one is a callback when user ask "Alexa, turn off `device_name`", where 8 | `device_name` refer to the first parameter. 9 | 10 | 11 | In this app, when you ask Alexa device "Alexa, turn on receptacle", it will require ESP32 to invoke 12 | the function `turn_on_relay` defined in `alexa.c`. When you ask "Alexa, turn off backlight", Alexa 13 | will require ESP32 to invoke funtion named `turn_off_backlight`. 14 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_multi_esp32/components/alexa/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_multi_esp32/components/alexa/include/alexa.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __ALEXA_H__ 16 | #define __ALEXA_H__ 17 | 18 | void alexa_init(void); 19 | void alexa_suspend(void); 20 | void alexa_resume(void); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_multi_esp32/components/alexa/include/alexa_device.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __ALEXA_DEVICE_H__ 16 | #define __ALEXA_DEVICE_H__ 17 | 18 | #include "freertos/FreeRTOS.h" 19 | #include "freertos/task.h" 20 | #include "lwip/api.h" 21 | 22 | typedef struct alexa_dev { 23 | char dev_name[20]; 24 | int index; 25 | int sock_id; 26 | int local_port; 27 | void (*turn_on_cb)(void); 28 | void (*turn_off_cb)(void); 29 | TaskHandle_t task_handle; 30 | struct alexa_dev *next; 31 | } alexa_dev_t; 32 | 33 | alexa_dev_t *create_new_device(const char *name, int port, void (*on_cb)(void), void (*off_cb)(void)); 34 | void alexa_device_add(alexa_dev_t *dev); 35 | void alexa_device_remove(alexa_dev_t *dev); 36 | void alexa_device_list_init(void); 37 | alexa_dev_t *alexa_device_get_dev_by_index(int index); 38 | int alexa_device_get_num(void); 39 | void alexa_device_list_destroy(void); 40 | void alexa_device_list_traverse(void (*cb)(alexa_dev_t *dev)); 41 | void response_to_search(struct netconn *udpconn, unsigned char *addr, int port); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_multi_esp32/components/alexa/include/upnp_broadcast_responder.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __UPNP_BROADCAST_RESPONDER_H__ 16 | #define __UPNP_BROADCAST_RESPONDER_H__ 17 | 18 | void upnp_broadcast_responder_init(void); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_multi_esp32/components/utils/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_multi_esp32/components/utils/include/utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __UTILS_H__ 16 | #define __UTILS_H__ 17 | 18 | #include "lwip/ip_addr.h" 19 | 20 | void printHex(char c); 21 | void delay_ms(int ms); 22 | void ip_addr_to_num(unsigned char *res, ip_addr_t *addr); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_multi_esp32/components/utils/utils.c: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "utils.h" 18 | #include "esp_log.h" 19 | 20 | #include "freertos/FreeRTOS.h" 21 | #include "freertos/task.h" 22 | 23 | static const char *TAG = "utils"; 24 | 25 | void printHex(char c) 26 | { 27 | char buff[3] = {0x0}; 28 | sprintf(buff, "%02X ", c); 29 | ESP_LOGI(TAG, "%s", buff); 30 | } 31 | 32 | void delay_ms(int ms) 33 | { 34 | vTaskDelay(ms / portTICK_RATE_MS); 35 | } 36 | 37 | void ip_addr_to_num(unsigned char *res, ip_addr_t *addr) 38 | { 39 | unsigned int ip = (addr->u_addr).ip4.addr; 40 | res[0] = (unsigned char)(ip & 0xFF); 41 | res[1] = (unsigned char)((ip >> 8) & 0xFF); 42 | res[2] = (unsigned char)((ip >> 16) & 0xFF); 43 | res[3] = (unsigned char)((ip >> 24) & 0xFF); 44 | } -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_multi_esp32/main/component.mk: -------------------------------------------------------------------------------- 1 | # do nothing 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/alexa_multi_esp32/main/include/user_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #define TMP_TASK_STACK_SIZE 2048 16 | #define TMP_TASK_PRIO 9 17 | #define ALEXA_TASK_STACK_SIZE 4096 18 | #define ALEXA_TASK_PRIO 4 19 | #define ALEXA_UDP_TASK_STACK_SIZE 4096 20 | #define ALEXA_UDP_TASK_PRIO 4 21 | 22 | #define MY_WIFI_SSID "MERCURY_CA7C" 23 | #define MY_WIFI_PASS "wang11113388" 24 | 25 | #define HTTP_SRV_PORT 80 26 | 27 | #define GPIO_TEST 2 28 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_led_control/README.md: -------------------------------------------------------------------------------- 1 | # HOW TO BUILD 2 | 3 | To build this sample, setup IDF_PATH by the following command `export IDF_PATH=/your_idf_path`. 4 | And setup your toolchain path by the following comman `export PATH=/your_tool_chain_path:$PATH`. 5 | Then change your directory to `client` or `server` and execute `make` to generate firmware. 6 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_led_control/client/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := my_gattc 7 | 8 | COMPONENT_ADD_INCLUDEDIRS := components/include 9 | 10 | include $(IDF_PATH)/make/project.mk 11 | 12 | # Copy some defaults into the sdkconfig by default 13 | # so BT stack is enabled 14 | sdkconfig: sdkconfig.defaults 15 | $(Q) cp $< $@ 16 | 17 | menuconfig: sdkconfig 18 | defconfig: sdkconfig 19 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_led_control/client/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 5 | # this will take the sources in the src/ directory, compile them and link them into 6 | # lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | 10 | #include $(IDF_PATH)/make/component_common.mk 11 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_led_control/client/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # Override some defaults so BT stack is enabled 2 | # in this example 3 | 4 | # 5 | # BT config 6 | # 7 | CONFIG_BT_ENABLED=y 8 | 9 | # 10 | # ESP32-specific config 11 | # 12 | CONFIG_ESP32_ENABLE_STACK_BT=y 13 | # CONFIG_ESP32_ENABLE_STACK_NONE is not set 14 | CONFIG_MEMMAP_BT=y 15 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_led_control/server/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := gatt_server_demos 7 | 8 | COMPONENT_ADD_INCLUDEDIRS := components/include 9 | 10 | include $(IDF_PATH)/make/project.mk 11 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_led_control/server/main/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Example 'GATT SERVER' Config" 2 | 3 | config SET_RAW_ADV_DATA 4 | bool "Use raw data for advertising packets and scan response data" 5 | help 6 | If this config item is set, raw binary data will be used to generate advertising & scan response data. 7 | This option uses the esp_ble_gap_config_adv_data_raw() and esp_ble_gap_config_scan_rsp_data_raw() functions. 8 | 9 | If this config item is unset, advertising & scan response data is provided via a higher-level esp_ble_adv_data_t structure. 10 | The lower layer will generate the BLE packets. This option has higher overhead at runtime. 11 | 12 | endmenu 13 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_led_control/server/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 5 | # this will take the sources in the src/ directory, compile them and link them into 6 | # lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_led_control/server/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # Override some defaults so BT stack is enabled 2 | # and WiFi disabled by default in this example 3 | CONFIG_BT_ENABLED=y 4 | CONFIG_WIFI_ENABLED=n 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_notification/gatt_client/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := gatt_client_demo 7 | 8 | COMPONENT_ADD_INCLUDEDIRS := components/include 9 | 10 | include $(IDF_PATH)/make/project.mk 11 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_notification/gatt_client/README.rst: -------------------------------------------------------------------------------- 1 | ESP-IDF GATT CLIENT demo 2 | ======================== 3 | 4 | This is the demo for user to use ESP_APIs to create a GATT Client. 5 | 6 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_notification/gatt_client/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_notification/gatt_client/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # Override some defaults so BT stack is enabled 2 | # and WiFi disabled by default in this example 3 | CONFIG_BT_ENABLED=y 4 | CONFIG_WIFI_ENABLED=n 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_notification/gatt_server/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := gatt_server_demo 7 | 8 | COMPONENT_ADD_INCLUDEDIRS := components/include 9 | 10 | include $(IDF_PATH)/make/project.mk 11 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_notification/gatt_server/README.rst: -------------------------------------------------------------------------------- 1 | ESP-IDF GATT CLIENT demo 2 | ======================== 3 | 4 | This is the demo for user to use ESP_APIs to create a GATT Client. 5 | 6 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_notification/gatt_server/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_notification/gatt_server/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # Override some defaults so BT stack is enabled 2 | # and WiFi disabled by default in this example 3 | CONFIG_BT_ENABLED=y 4 | CONFIG_WIFI_ENABLED=n 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := beacon_send 2 | 3 | include $(IDF_PATH)/make/project.mk 4 | 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/README.md: -------------------------------------------------------------------------------- 1 | # BLE scan results send to UDP server 2 | 3 | In this example, ESP32 scan BLE devices and then send the scan results to UDP server. User can 4 | setup SSID, password, server IP and server port via uart. Run a uart debug tool, the following 5 | commands can send to ESP32 via uart0. 6 | 7 | * ssid: after input `ssid`, ESP32 will require user to input AP's SSID which ESP32 will connect to 8 | * pass: after input `pass`, ESP32 will require user to input AP's password 9 | * ip: the UDP server's IP 10 | * port: the UDP server's port 11 | * help: show help info 12 | * wifi: start BLE scanning and then send scan results via WiFi. Before input this command, you have to setup `ssid`, `pass`, `ip` and `port`. 13 | 14 | To test this example, you can use UDP debug tool to create a UDP server, and then run this example on 15 | ESP32, it will send the scan result to the server. 16 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/components/ble/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/components/ble/include/ble.h: -------------------------------------------------------------------------------- 1 | #ifndef __BLE_H__ 2 | #define __BLE_H__ 3 | 4 | // prototype 5 | void ble_init(void); 6 | void ble_client_app_register(void); 7 | void ble_start_scanning(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/components/uart/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/components/uart/include/my_uart.h: -------------------------------------------------------------------------------- 1 | #ifndef __MY_UART_H__ 2 | #define __MY_UART_H__ 3 | 4 | #include 5 | 6 | typedef enum { 7 | NONE, 8 | INPUT_SSID, 9 | INPUT_PASS, 10 | INPUT_IP, 11 | INPUT_PORT, 12 | } inputStatus; 13 | 14 | typedef enum { 15 | EMPTY, 16 | UNDER_WRITE, 17 | WRITE_OVER 18 | } RcvMsgBuffState; 19 | 20 | typedef struct { 21 | uint32_t RcvBuffSize; 22 | uint8_t *pRcvMsgBuff; 23 | uint8_t *pWritePos; 24 | uint8_t *pReadPos; 25 | uint8_t TrigLvl; //JLU: may need to pad 26 | RcvMsgBuffState BuffState; 27 | } RcvMsgBuff; 28 | 29 | 30 | // prototype 31 | void uart_init(void); 32 | void show_help_info(); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/components/utils/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/components/utils/include/my_list.h: -------------------------------------------------------------------------------- 1 | #ifndef __MY_LIST_H__ 2 | #define __MY_LIST_H_ 3 | 4 | typedef struct scan_list { 5 | char *bda; 6 | char *uuid; 7 | int rssi; 8 | struct scan_list *pNext; 9 | } scan_list_t; 10 | 11 | // prototype 12 | void list_init(void); 13 | scan_list_t *list_new_item(void); 14 | void list_insert_to_head(scan_list_t *item); 15 | void list_destroy(void); 16 | scan_list_t *list_get_head(void); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/components/utils/include/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef __UTILS_H__ 2 | #define __UTILS_H__ 3 | 4 | int str2num(const char *str, int len); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/components/utils/my_list.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "my_list.h" 4 | #include "esp_log.h" 5 | #include "user_config.h" 6 | 7 | static const char *TAG = "my_list"; 8 | 9 | static scan_list_t head; 10 | 11 | void list_init(void) 12 | { 13 | head.bda = NULL; 14 | head.uuid = NULL; 15 | head.rssi = 0; 16 | head.pNext = NULL; 17 | } 18 | 19 | scan_list_t *list_new_item(void) 20 | { 21 | scan_list_t *newItem = (scan_list_t *) malloc(sizeof(scan_list_t)); 22 | if (newItem == NULL) { 23 | ESP_LOGE(TAG, "malloc list item failed!"); 24 | return NULL; 25 | } 26 | memset(newItem, 0, sizeof(scan_list_t)); 27 | newItem->bda = (char *) malloc(BDA_SIZE); 28 | 29 | if (newItem->bda == NULL) { 30 | ESP_LOGE(TAG, "alloc for BDA failed!"); 31 | free(newItem); 32 | return NULL; 33 | } 34 | 35 | newItem->uuid = (char *)malloc(UUID_SIZE); 36 | if (newItem->uuid == NULL) { 37 | ESP_LOGE(TAG, "alloc for UUID failed!"); 38 | free(newItem->bda); 39 | free(newItem); 40 | return NULL; 41 | } 42 | 43 | return newItem; 44 | } 45 | 46 | void list_insert_to_head(scan_list_t *item) 47 | { 48 | scan_list_t *next = NULL; 49 | next = head.pNext; 50 | head.pNext = item; 51 | item->pNext = next; 52 | } 53 | 54 | void list_destroy(void) 55 | { 56 | scan_list_t *next = NULL; 57 | while (head.pNext != NULL) { 58 | next = (head.pNext)->pNext; 59 | free((head.pNext)->bda); 60 | free((head.pNext)->uuid); 61 | free(head.pNext); 62 | head.pNext = next; 63 | } 64 | } 65 | 66 | scan_list_t *list_get_head(void) 67 | { 68 | return &head; 69 | } -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/components/utils/utils.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "utils.h" 4 | 5 | int str2num(const char *str, int len) 6 | { 7 | int res; 8 | unsigned char *temp = (unsigned char *) malloc(len+1); 9 | memcpy(temp, str, len); 10 | temp[len] = 0; 11 | res = atoi((const char *)temp); 12 | free(temp); 13 | return res; 14 | } -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 5 | # this will take the sources in the src/ directory, compile them and link them into 6 | # lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | 10 | #include $(IDF_PATH)/make/component_common.mk 11 | COMPONENT_ADD_INCLUDEDIRS := include 12 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/main/include/udp_task.h: -------------------------------------------------------------------------------- 1 | #ifndef __UDP_TASK_H__ 2 | #define __UDP_TASK_H__ 3 | 4 | void connect_server(const char *ip, int port); 5 | void send_data(const char *data, int len); 6 | void disconnect_server(); 7 | void send_all_data(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ble_to_udp_server/main/include/user_config.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_CONFIG_H__ 2 | #define __USER_CONFIG_H__ 3 | 4 | #define UDP_TASK_STACK_SIZE 2048 5 | #define UDP_TASK_PRIO 12 6 | #define UART_TASK_STACK_SIZE 2048 7 | #define UART_TASK_PRIO 11 8 | #define UART_EVT_TASK_STACK_SIZE 2048 9 | #define UART_EVT_TASK_PRIO 10 10 | #define TMP_TASK_STACK_SIZE 2048 11 | #define TMP_TASK_PRIO 9 12 | #define LED_TASK_STACK_SIZE 2048 13 | #define LED_TASK_PRIO 13 14 | #define BUF_SIZE 1024 15 | #define RECV_BUF_SIZE 128 16 | #define WIFI_SSID_MAX_LEN 32 17 | #define WIFI_PASS_MAX_LEN 32 18 | #define SRV_IP_MAX_LEN 16 19 | 20 | #define BDA_SIZE 16 21 | #define UUID_SIZE 64 22 | #define WIFI_CHECK_TIMEOUT 15 23 | 24 | // user commands 25 | #define CMD_SSID "ssid" 26 | #define CMD_PASS "pass" 27 | #define CMD_IP "ip" 28 | #define CMD_PORT "port" 29 | #define CMD_HELP "help" 30 | #define CMD_WIFI "wifi" 31 | #define CMD_QUIT "quit" 32 | 33 | 34 | #define PROMPT "\r\n" 35 | #define PROMPT_LEN 2 36 | 37 | //#define ENABLE_SCAN_OUTPUT 1 38 | 39 | 40 | extern void set_panic(void); 41 | extern void clear_panic(void); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/bluetooth_scanner/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := bt_scanner 2 | 3 | include $(IDF_PATH)/make/project.mk 4 | 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/bluetooth_scanner/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/camera/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := esp32-cam-demo 2 | 3 | include $(IDF_PATH)/make/project.mk 4 | 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/camera/README.md: -------------------------------------------------------------------------------- 1 | # Pin connections 2 | 3 | | Interface | Camera Pin | DOIT ESP32 board Pin | 4 | | --- | --- | --- | 5 | | SCCB Clock | SCL | D27 | 6 | | SCCB Data | SDA | D26 | 7 | | FIFO Read Reset | RRST | D2 | 8 | | Vertical Sync | VS | D25 | 9 | | Read Clock | RCLK | D21 | 10 | | FIFO Write Reset | WRST | D22 | 11 | | WEN | WEN | D23 | 12 | | Pixel Data Bit 0 | D0 | D4 | 13 | | Pixel Data Bit 1 | D1 | D5 | 14 | | Pixel Data Bit 2 | D2 | D18 | 15 | | Pixel Data Bit 3 | D3 | D19 | 16 | | Pixel Data Bit 4 | D4 | VP | 17 | | Pixel Data Bit 5 | D5 | VN | 18 | | Pixel Data Bit 6 | D6 | D34 | 19 | | Pixel Data Bit 7 | D7 | D35 | 20 | | OE | OE | D12 | 21 | | Power Supply 3.3V | 3V3 | 3V3 | 22 | | Ground | GND | GND | 23 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/camera/components/camera/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Example Configuration" 2 | 3 | config ENABLE_TEST_PATTERN 4 | bool "Enable test pattern on camera output" 5 | default n 6 | help 7 | Configure the camera module to output test pattern instead of live image. 8 | 9 | Use this option to troubleshoot image issues like noise, 10 | distortion, not legible and missing live image. 11 | Instead, module will generate regular vertical bars 12 | in shades from dark to white. 13 | 14 | endmenu 15 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/camera/components/camera/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | 3 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/camera/components/camera/ov7725.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the OpenMV project. 3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader 4 | * This work is licensed under the MIT license, see the file LICENSE for details. 5 | * 6 | * OV7725 driver. 7 | * 8 | */ 9 | #ifndef __OV7725_H__ 10 | #define __OV7725_H__ 11 | #include "sensor.h" 12 | 13 | int ov7725_init(sensor_t *sensor); 14 | #endif // __OV7725_H__ 15 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/camera/components/camera/sccb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the OpenMV project. 3 | * Copyright (c) 2013/2014 Ibrahim Abdelkader 4 | * This work is licensed under the MIT license, see the file LICENSE for details. 5 | * 6 | * SCCB (I2C like) driver. 7 | * 8 | */ 9 | #ifndef __SCCB_H__ 10 | #define __SCCB_H__ 11 | #include 12 | int SCCB_Init(int pin_sda, int pin_scl); 13 | uint8_t SCCB_Probe(); 14 | uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg); 15 | uint8_t SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data); 16 | #endif // __SCCB_H__ 17 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/camera/components/camera/twi.h: -------------------------------------------------------------------------------- 1 | /* 2 | twi.h - Software I2C library for ESP31B 3 | 4 | Copyright (c) 2015 Hristo Gochkov. All rights reserved. 5 | This file is part of the ESP31B core for Arduino environment. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | #ifndef SI2C_h 22 | #define SI2C_h 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | void twi_init(unsigned char sda, unsigned char scl); 29 | void twi_stop(void); 30 | void twi_setClock(unsigned int freq); 31 | uint8_t twi_writeTo(unsigned char address, unsigned char * buf, unsigned int len, unsigned char sendStop); 32 | uint8_t twi_readFrom(unsigned char address, unsigned char * buf, unsigned int len, unsigned char sendStop); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/camera/components/camera/wiring.c: -------------------------------------------------------------------------------- 1 | #include "wiring.h" 2 | #include "soc/gpio_reg.h" 3 | #include "soc/io_mux_reg.h" 4 | #include "driver/gpio.h" 5 | 6 | void pinMode(int pin, int mode) { 7 | 8 | gpio_config_t conf = {0}; 9 | conf.pin_bit_mask = 1LL << pin; 10 | if (mode == OUTPUT) { 11 | conf.mode = GPIO_MODE_OUTPUT; 12 | } 13 | if (mode == INPUT || mode == INPUT_PULLUP) { 14 | conf.mode = GPIO_MODE_INPUT; 15 | } 16 | if (mode == INPUT) { 17 | conf.pull_down_en = GPIO_PULLDOWN_DISABLE; 18 | conf.pull_up_en = GPIO_PULLUP_DISABLE; 19 | } 20 | else if (mode == INPUT_PULLUP) { 21 | conf.pull_down_en = GPIO_PULLDOWN_DISABLE; 22 | conf.pull_up_en = GPIO_PULLUP_ENABLE; 23 | } 24 | gpio_config(&conf); 25 | } 26 | 27 | void digitalWrite(int pin, int value) { 28 | gpio_set_level(pin, (value)?1:0); 29 | } 30 | 31 | void delay(int millis) { 32 | vTaskDelay(millis / portTICK_PERIOD_MS); 33 | } 34 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/camera/components/camera/wiring.h: -------------------------------------------------------------------------------- 1 | #ifndef __OMV_PORT_H__ 2 | #define __OMV_PORT_H__ 3 | 4 | #include 5 | #include 6 | 7 | 8 | // Some functions from Arduino/Wiring 9 | void pinMode(int pin, int mode); 10 | void digitalWrite(int pin, int value); 11 | void delay(int millis); 12 | 13 | #define OUTPUT 0 14 | #define INPUT 1 15 | #define INPUT_PULLUP 2 16 | 17 | // Some functions to make OpenMV happy 18 | #define systick_sleep(t) delay(t) 19 | #define __disable_irq() 20 | #define __enable_irq() 21 | 22 | 23 | 24 | #endif //__OMV_PORT_H__ 25 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/camera/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # This Makefile should, at the very least, just include $(SDK_PATH)/make/component.mk. By default, 5 | # this will take the sources in the src/ directory, compile them and link them into 6 | # lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, 7 | # please read the SDK documents if you need to do this. 8 | # 9 | 10 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/camera/schematics/ov7725-camera-schematic1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/LuaNode_Esp32/LuaNode32/examples/camera/schematics/ov7725-camera-schematic1.pdf -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/camera/schematics/ov7725-camera-schematic2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/LuaNode_Esp32/LuaNode32/examples/camera/schematics/ov7725-camera-schematic2.pdf -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/camera/schematics/ov7725-dimensions.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/LuaNode_Esp32/LuaNode32/examples/camera/schematics/ov7725-dimensions.jpg -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ds1307/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := ds1307 2 | 3 | include $(IDF_PATH)/make/project.mk 4 | 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ds1307/README.md: -------------------------------------------------------------------------------- 1 | ## DS1307 2 | 3 | DS1307 is an RTC module. This example is modified from Kolban's example. 4 | 5 | ## How to use 6 | 7 | To use DS1307 module, please remove R2 and R3 on the module. 8 | 9 | Pin connections: 10 | 11 | 12 | -------- 13 | | DS1307 | ESP32 | 14 | | --- | --- | 15 | | SCL | GPIO19 | 16 | | SDA | GPIO18 | 17 | | Vcc | 3v3 | 18 | | GND | GND | 19 | 20 | 21 | Modified the SSID and password defined in `main.c` 22 | 23 | Compile and run the example on ESP32, then you can see the time is output each second. 24 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ds1307/components/bsp/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ds1307/components/bsp/include/ds1307.h: -------------------------------------------------------------------------------- 1 | #ifndef __DS1307_H__ 2 | #define __DS1307_H__ 3 | 4 | #include 5 | 6 | #define SDA_PIN 18 7 | #define SCL_PIN 19 8 | #define DS1307_ADDRESS 0x68 9 | 10 | void initDS1307(void); 11 | void writeValue(time_t newTime); 12 | time_t readValue(); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ds1307/main/component.mk: -------------------------------------------------------------------------------- 1 | # do nothing 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/easy_mem/app_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "esp_log.h" 4 | #include "esp_system.h" 5 | #include "easy_heap.h" 6 | #include "easy_mem.h" 7 | 8 | #define BUF_SIZE 10 9 | 10 | static const char *TAG = "main"; 11 | 12 | void app_main() 13 | { 14 | easy_heap_init(); 15 | easy_mem_init(); 16 | 17 | unsigned char *addr1 = (unsigned char*)easy_heap_alloc(BUF_SIZE); 18 | memset(addr1, 0, BUF_SIZE); 19 | memcpy(addr1, "hello", 5); 20 | printf("%s\n", addr1); 21 | easy_heap_free(addr1); 22 | 23 | unsigned char *addr2 = (unsigned char*)easy_mem_alloc(BUF_SIZE); 24 | memset(addr2, 0, BUF_SIZE); 25 | memcpy(addr2, "world", 5); 26 | printf("%s\n", addr2); 27 | easy_mem_free(addr2); 28 | 29 | // print statistics 30 | easy_heap_statistics(); 31 | easy_mem_statistics(); 32 | } 33 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/esp32_ble_gatt_server_led_control_for_phone/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := gatt_server_demos 7 | 8 | COMPONENT_ADD_INCLUDEDIRS := components/include 9 | 10 | include $(IDF_PATH)/make/project.mk 11 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/esp32_ble_gatt_server_led_control_for_phone/README.md: -------------------------------------------------------------------------------- 1 | Download the APP from the following project: https://github.com/Nicholas3388/LuaNode_BLE_Client 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/esp32_ble_gatt_server_led_control_for_phone/main/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Example 'GATT SERVER' Config" 2 | 3 | config SET_RAW_ADV_DATA 4 | bool "Use raw data for advertising packets and scan response data" 5 | help 6 | If this config item is set, raw binary data will be used to generate advertising & scan response data. 7 | This option uses the esp_ble_gap_config_adv_data_raw() and esp_ble_gap_config_scan_rsp_data_raw() functions. 8 | 9 | If this config item is unset, advertising & scan response data is provided via a higher-level esp_ble_adv_data_t structure. 10 | The lower layer will generate the BLE packets. This option has higher overhead at runtime. 11 | 12 | endmenu 13 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/esp32_ble_gatt_server_led_control_for_phone/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 5 | # this will take the sources in the src/ directory, compile them and link them into 6 | # lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/esp32_ble_gatt_server_led_control_for_phone/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # Override some defaults so BT stack is enabled 2 | # and WiFi disabled by default in this example 3 | CONFIG_BT_ENABLED=y 4 | CONFIG_WIFI_ENABLED=n 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/esp32_nrf51822_ble_conn/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := esp32_nrf51_led_ctrl 7 | 8 | COMPONENT_ADD_INCLUDEDIRS := components/include 9 | 10 | include $(IDF_PATH)/make/project.mk 11 | 12 | # Copy some defaults into the sdkconfig by default 13 | # so BT stack is enabled 14 | sdkconfig: sdkconfig.defaults 15 | $(Q) cp $< $@ 16 | 17 | menuconfig: sdkconfig 18 | defconfig: sdkconfig 19 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/esp32_nrf51822_ble_conn/README.md: -------------------------------------------------------------------------------- 1 | # Build 2 | 3 | * Setup IDF_PATH by the following command: `export IDF_PATH=/your_esp_idf_path` 4 | * Setup toolchain by: `export PATH=/your_esp32_toolchain_path:$PATH` 5 | * Execute `make` 6 | 7 | You can download the nRF51822 sources from the following 8 | link: https://github.com/Nicholas3388/nRF51822_ESP32_communicate 9 | 10 | Build the nRF51822 project within `Keil uVersion4`. 11 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/esp32_nrf51822_ble_conn/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # This Makefile should, at the very least, just include $(SDK_PATH)/make/component_common.mk. By default, 5 | # this will take the sources in the src/ directory, compile them and link them into 6 | # lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | 10 | #include $(IDF_PATH)/make/component_common.mk 11 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/esp32_nrf51822_ble_conn/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # Override some defaults so BT stack is enabled 2 | # in this example 3 | 4 | # 5 | # BT config 6 | # 7 | CONFIG_BT_ENABLED=y 8 | 9 | # 10 | # ESP32-specific config 11 | # 12 | CONFIG_ESP32_ENABLE_STACK_BT=y 13 | # CONFIG_ESP32_ENABLE_STACK_NONE is not set 14 | CONFIG_MEMMAP_BT=y 15 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/json/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := json 2 | 3 | include $(IDF_PATH)/make/project.mk 4 | 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/json/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main component makefile. 3 | # 4 | # This Makefile can be left empty. By default, it will take the sources in the 5 | # src/ directory, compile them and link them into lib(subdirectory_name).a 6 | # in the build directory. This behaviour is entirely configurable, 7 | # please read the ESP-IDF documents if you need to do this. 8 | # 9 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/lcd_nokia5110_driver/Nokia5510LCD_datasheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/LuaNode_Esp32/LuaNode32/examples/lcd_nokia5110_driver/Nokia5510LCD_datasheet.pdf -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ota_tcp_update/README.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | 3 | ![github](https://github.com/Nicholas3388/LuaNode/raw/master/images/ota_tcp.jpg "OTA TCP update") 4 | 5 | Although there is an OTA example provided by esp-idf, the new firmware download from http server, I found 6 | that some times the connection is failed when firmware updating. In this sample, we provide a TCP method to 7 | update firmware via TCP server. If a package is sent failed, the client (ESP32) will request the server to 8 | send package again. 9 | 10 | * The request sent by client will have a string format like this: `req0\r\n\r\n` or `req1\r\n\r\n`, where "req0" 11 | means client request server send next package, "req1" means there are some errors occur when client receive 12 | package, request server to send previous package again. 13 | 14 | * The package sent by server will have the following format: `total: 123456\r\nlength: 321\r\n\r\n$#&*@#$......`, 15 | where "total: 123456\r\nlength: 321\r\n\r\n" is package header, there are two key and value. 16 | the key "total" refers to the total length of this firmware, the other key "length" refers to current package 17 | length. With these information, we can show update progress to user. The package header end with "\r\n\r\n", 18 | and then follow by firmware data. 512 bytes of firmware data for each package. 19 | 20 | ## How to use 21 | 22 | * Modify the SSID and password in `user_config.h` in client source. Then build client and 23 | flash the generated firmware to your ESP32 device 24 | 25 | * Store your new firmware, which used for updating and the `ota_server.py` on your laptop, 26 | the two file must in the same folder, 27 | then run the server on your laptop (You must install python on you laptop first), note that 28 | the laptop and ESP32 must connect to the same AP. 29 | 30 | * when ESP32 powerup, it will connect to the python server run on your laptop and download 31 | the new firmware. 32 | 33 | You can run the `ota_server.py` on remote server and store your new firmware on the remote 34 | server for updating. Just change the server IP and PORT defined in `user_config.h` 35 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ota_tcp_update/client/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME := my_ota 2 | 3 | include $(IDF_PATH)/make/project.mk 4 | 5 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ota_tcp_update/client/components/ota/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ota_tcp_update/client/components/ota/include/ota.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __OTA_H__ 16 | #define __OTA_H__ 17 | 18 | void ota_init(void); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ota_tcp_update/client/components/utils/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ota_tcp_update/client/components/utils/include/utils.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __UTILS_H__ 16 | #define __UTILS_H__ 17 | 18 | #include "lwip/ip_addr.h" 19 | 20 | void printHex(char c); 21 | void delay_ms(int ms); 22 | void ip_addr_to_num(unsigned char *res, ip_addr_t *addr); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ota_tcp_update/client/components/utils/utils.c: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "utils.h" 18 | #include "esp_log.h" 19 | 20 | #include "freertos/FreeRTOS.h" 21 | #include "freertos/task.h" 22 | 23 | static const char *TAG = "utils"; 24 | 25 | void printHex(char c) 26 | { 27 | char buff[3] = {0x0}; 28 | sprintf(buff, "%02X ", c); 29 | ESP_LOGI(TAG, "%s", buff); 30 | } 31 | 32 | void delay_ms(int ms) 33 | { 34 | vTaskDelay(ms / portTICK_RATE_MS); 35 | } 36 | 37 | void ip_addr_to_num(unsigned char *res, ip_addr_t *addr) 38 | { 39 | unsigned int ip = (addr->u_addr).ip4.addr; 40 | res[0] = (unsigned char)(ip & 0xFF); 41 | res[1] = (unsigned char)((ip >> 8) & 0xFF); 42 | res[2] = (unsigned char)((ip >> 16) & 0xFF); 43 | res[3] = (unsigned char)((ip >> 24) & 0xFF); 44 | } -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ota_tcp_update/client/main/component.mk: -------------------------------------------------------------------------------- 1 | # do nothing 2 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ota_tcp_update/client/main/include/user_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Doctors of Intelligence & Technology (Shenzhen) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __USER_CONFIG_H__ 16 | #define __USER_CONFIG_H__ 17 | 18 | #define WIFI_SSID "Doit" 19 | #define WIFI_PASS "doit3305" 20 | 21 | #define LOCAL_PORT 7001 22 | #define REMOTE_PORT 8070 23 | 24 | #define TMP_TASK_STACK_SIZE 2048 25 | #define TMP_TASK_PRIO 5 26 | #define OTA_TASK_STACK_SIZE 8192 27 | #define OTA_TASK_PRIO 6 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/ota_tcp_update/server/ota_server.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import os 3 | import time 4 | 5 | ################################################ 6 | ## change firmware and port to yours 7 | firmware_name = 'hello-world.bin' 8 | server_ip = 8070 9 | ################################################ 10 | 11 | 12 | ip_port = ('0.0.0.0', server_ip) 13 | 14 | file_size = os.path.getsize(firmware_name) 15 | 16 | # open binary file 17 | reopen = True; 18 | while reopen: 19 | try: 20 | fd = open(firmware_name, 'rb') 21 | reopen = False 22 | except: 23 | print 'open file failed' 24 | time.sleep(1) 25 | 26 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 27 | sock.bind(ip_port) 28 | sock.listen(5) 29 | 30 | last_package = None 31 | send_count = 0 32 | 33 | while True: 34 | print 'wait for client' 35 | conn, addr = sock.accept() 36 | print addr 37 | while True: 38 | client_data = conn.recv(1024) 39 | if client_data == "req0\r\n\r\n": 40 | send_fail_retry = True 41 | is_over = False 42 | while send_fail_retry: 43 | try: 44 | dat = fd.read(512) 45 | send_data = 'total: ' + str(file_size) + '\r\nlength: ' + str(len(dat)) + '\r\n\r\n' + dat 46 | last_package = send_data 47 | conn.send(send_data) 48 | send_fail_retry = False 49 | send_count += len(dat) 50 | print ('send progress: %%%d' %(send_count*100/file_size)) 51 | if send_count >= file_size: 52 | print 'file send end' 53 | last_package = None 54 | send_count = 0 55 | is_over = True 56 | except: 57 | print 'read file error, try again later' 58 | time.sleep(1) 59 | if is_over: 60 | fd.seek(0) 61 | break 62 | elif client_data == "req1\r\n\r\n": 63 | retry = True 64 | while retry: 65 | try: 66 | conn.send(last_package) 67 | retry = False 68 | print 'resend OK' 69 | except: 70 | print 'resend data failed' 71 | time.sleep(1) 72 | 73 | print 'something went wrong' -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/raw_flash_rw/app_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "esp_system.h" 4 | #include "nvs_flash.h" 5 | #include "platform.h" 6 | #include "flash.h" 7 | #include "tmr.h" 8 | 9 | #define START_ADDR 0x110000 10 | #define USED_FLASH_SIZE 2048 11 | #define BUFF_SIZE 12 12 | 13 | void led_blink(void) 14 | { 15 | int res = platform_gpio_mode(2, 2); // pin mode: OUTPUT 16 | if(res < 0) { 17 | printf("Led lightup failed\n"); 18 | return; 19 | } 20 | platform_gpio_write(2, 1); // led on 21 | tmr_delay_msec(250); 22 | platform_gpio_write(2, 0); // led off 23 | tmr_delay_msec(250); 24 | platform_gpio_write(2, 1); 25 | tmr_delay_msec(250); 26 | platform_gpio_write(2, 0); 27 | tmr_delay_msec(250); 28 | platform_gpio_write(2, 1); 29 | } 30 | 31 | void app_main() 32 | { 33 | nvs_flash_init(); 34 | flash_init(); 35 | led_blink(); 36 | 37 | flash_config *fc = flash_get_config(); 38 | fc->hal_erase_f(START_ADDR, USED_FLASH_SIZE); 39 | uint8_t str[10] = "helloworld"; 40 | fc->hal_write_f(START_ADDR, strlen(str), str); 41 | 42 | tmr_delay_msec(1000); 43 | uint8_t buff[BUFF_SIZE]; 44 | memset(buff, 0, BUFF_SIZE); 45 | fc->hal_read_f(START_ADDR, strlen(str), buff); 46 | printf("==> Read content: %s\n", buff); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/examples/test_spiffs/app_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "esp_log.h" 4 | #include "esp_system.h" 5 | #include "spiffs.h" 6 | #include "vfs.h" 7 | #include "platform.h" 8 | #include "freertos/FreeRTOS.h" 9 | #include "freertos/task.h" 10 | #include "flash_api.h" 11 | 12 | static const char *TAG = "main"; 13 | static spiffs fs; 14 | 15 | void app_main() 16 | { 17 | char buf[12] = {0}; 18 | 19 | if(flash_safe_get_size_byte() != flash_rom_get_size_byte()) { 20 | ESP_LOGI(TAG, "Incorrect flash size reported, adjusting..."); 21 | flash_rom_set_size_byte(flash_safe_get_size_byte()); 22 | system_restart(); 23 | return; 24 | } 25 | 26 | ESP_LOGI (TAG, "Mounting flash filesystem..."); 27 | if (!vfs_mount("/FLASH", 0)) { 28 | // Failed to mount -- try reformat 29 | ESP_LOGI(TAG, "Formatting file system. Please wait..."); 30 | if (!vfs_format()) { 31 | ESP_LOGI(TAG, "*** ERROR ***: unable to format. FS might be compromised." ); 32 | ESP_LOGI(TAG, "It is advised to re-flash the NodeMCU image." ); 33 | } 34 | // Note that fs_format leaves the file system mounted 35 | } 36 | 37 | spiffs_file fd = SPIFFS_open(&fs, "test_file", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0); 38 | ESP_LOGI(TAG, "fd=%d", fd); 39 | if (SPIFFS_write(&fs, fd, (u8_t *)"Hello SPIFFS", 12) < 0) { 40 | ESP_LOGI(TAG, "write errno %i", SPIFFS_errno(&fs)); 41 | } 42 | SPIFFS_close(&fs, fd); 43 | 44 | vTaskDelay(1000 / portTICK_RATE_MS); 45 | 46 | fd = SPIFFS_open(&fs, "test_file", SPIFFS_RDWR, 0); 47 | ESP_LOGI(TAG, "fd=%d", fd); 48 | if (SPIFFS_read(&fs, fd, (u8_t *)buf, 12) < 0) { 49 | ESP_LOGI(TAG, "read errno %i", SPIFFS_errno(&fs)); 50 | } 51 | SPIFFS_close(&fs, fd); 52 | 53 | ESP_LOGI(TAG, "--> %s <--", buf); 54 | } 55 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "main.c" "uart_handler.c" 2 | INCLUDE_DIRS "include") 3 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/main/include/lua_def.h: -------------------------------------------------------------------------------- 1 | #ifndef _LUA_DEF_H_ 2 | #define _LUA_DEF_H_ 3 | 4 | 5 | /* 6 | @@ LUA_MAXINPUT is the maximum length for an input line in the 7 | @* stand-alone interpreter. 8 | ** CHANGE it if you need longer lines. 9 | */ 10 | #define LUA_MAXINPUT 256 11 | 12 | /* 13 | @@ LUA_PROMPT is the default prompt used by stand-alone Lua. 14 | @@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua. 15 | ** CHANGE them if you want different prompts. (You can also change the 16 | ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) 17 | */ 18 | #define LUA_PROMPT "> " 19 | #define LUA_PROMPT2 ">> " 20 | 21 | // EGC operations modes 22 | #define EGC_NOT_ACTIVE 0 // EGC disabled 23 | #define EGC_ON_ALLOC_FAILURE 1 // run EGC on allocation failure 24 | #define EGC_ON_MEM_LIMIT 2 // run EGC when an upper memory limit is hit 25 | #define EGC_ALWAYS 4 // always run EGC before an allocation 26 | 27 | /* 28 | ** pseudo-indices 29 | */ 30 | #define LUA_REGISTRYINDEX (-10000) 31 | #define LUA_ENVIRONINDEX (-10001) 32 | #define LUA_GLOBALSINDEX (-10002) 33 | 34 | 35 | #define GCSpause 0 36 | 37 | #define GCSTEPSIZE 1024u 38 | 39 | typedef LUAI_UMEM lu_mem; 40 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) 41 | 42 | #define G(L) (L->l_G) 43 | 44 | 45 | typedef struct __lua_load{ 46 | lua_State *L; 47 | int firstline; 48 | char *line; 49 | int line_position; 50 | size_t len; 51 | int done; 52 | const char *prmt; 53 | }lua_Load; 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/main/include/uart_handler.h: -------------------------------------------------------------------------------- 1 | #ifndef _UART_HANDLER_H_ 2 | #define _UART_HANDLER_H_ 3 | 4 | 5 | void my_uart_init(void); 6 | bool uart_getc(char *c); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/partitions_luanode.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap 3 | nvs, data, nvs, 0x9000, 0x6000, 4 | phy_init, data, phy, 0xf000, 0x1000, 5 | factory, app, factory, 0x10000, 1M, 6 | storage, data, spiffs, , 0xF0000, 7 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32/sdkconfig.ci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/LuaNode_Esp32/LuaNode32/sdkconfig.ci -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | sdkconfig.old 3 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's 2 | # CMakeLists in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.16) 4 | set(EXTRA_COMPONENT_DIRS ./components) 5 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 6 | project(luanode) 7 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "lapi.c" "lcode.c" "ldo.c" "lfunc.c" "llex.c" "loadlib.c" "lparser.c" "lstring.c" "ltablib.c" "lundump.c" "lauxlib.c" "ldblib.c" "ldump.c" "lgc.c" "lmathlib.c" "lobject.c" "lrotable.c" "lstrlib.c" "ltm.c" "lvm.c" "lbaselib.c" "ldebug.c" "legc.c" "liolib.c" "lmem.c" "lopcodes.c" "lstate.c" "ltable.c" "lua.c" "lzio.c" "linit.c" 2 | REQUIRES vfs mylibc 3 | INCLUDE_DIRS "include") 4 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/Kconfig: -------------------------------------------------------------------------------- 1 | menu "LUA" 2 | 3 | config LUA_ENABLE 4 | bool "Enable lua" 5 | default "y" 6 | help 7 | For lua script. 8 | 9 | endmenu 10 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/compiler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * define start/end address of ro data. 3 | */ 4 | 5 | #ifndef __COMPILER_H__ 6 | #define __COMPILER_H__ 7 | 8 | #define __ESP32__ 9 | #if defined(__ESP8266__) 10 | 11 | extern char _irom0_text_start; 12 | extern char _irom0_text_end; 13 | #define RODATA_START_ADDRESS (&_irom0_text_start) 14 | #define RODATA_END_ADDRESS (&_irom0_text_end) 15 | 16 | #elif defined(__ESP32__) 17 | 18 | #define RODATA_START_ADDRESS ((char*)0x3F400000) 19 | #define RODATA_END_ADDRESS ((char*)0x3F800000) 20 | 21 | #else // other compilers 22 | 23 | /* Firstly, modify rodata's start/end address. Then, comment the line below */ 24 | #error "Please modify RODATA_START_ADDRESS and RODATA_END_ADDRESS below." 25 | 26 | /* Perhaps you can use start/end address of flash */ 27 | #define RODATA_START_ADDRESS ((char*)0x40200000) 28 | #define RODATA_END_ADDRESS ((char*)0x40280000) 29 | 30 | #endif 31 | 32 | #endif // __COMPILER_H__ 33 | 34 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #ifdef LUA_OPTIMIZE_DEBUG 17 | # include "lvm.h" 18 | # define getline(f,pc) (((f)->packedlineinfo) ? luaG_getline((f), pc) : 0) 19 | # define INFO_FILL_BYTE 0x7F 20 | # define INFO_DELTA_MASK 0x80 21 | # define INFO_SIGN_MASK 0x40 22 | # define INFO_DELTA_6BITS 0x3F 23 | # define INFO_DELTA_7BITS 0x7F 24 | # define INFO_MAX_LINECNT 126 25 | # define lineInfoTop(fs) ((fs)->f->packedlineinfo + (fs)->lastlineOffset) 26 | #else 27 | # define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 28 | #endif 29 | 30 | #define resethookcount(L) (L->hookcount = L->basehookcount) 31 | 32 | 33 | LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, 34 | const char *opname); 35 | LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 36 | LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, 37 | const TValue *p2); 38 | LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, 39 | const TValue *p2); 40 | LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); 41 | LUAI_FUNC void luaG_errormsg (lua_State *L); 42 | LUAI_FUNC int luaG_checkcode (const Proto *pt); 43 | LUAI_FUNC int luaG_checkopenop (Instruction i); 44 | #ifdef LUA_OPTIMIZE_DEBUG 45 | LUAI_FUNC int luaG_getline (const Proto *f, int pc); 46 | LUAI_FUNC int luaG_stripdebug (lua_State *L, Proto *f, int level, int recv); 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/legc.h: -------------------------------------------------------------------------------- 1 | // Lua EGC (Emergeny Garbage Collector) interface 2 | 3 | #ifndef __LEGC_H__ 4 | #define __LEGC_H__ 5 | 6 | #include "lstate.h" 7 | 8 | // EGC operations modes 9 | #define EGC_NOT_ACTIVE 0 // EGC disabled 10 | #define EGC_ON_ALLOC_FAILURE 1 // run EGC on allocation failure 11 | #define EGC_ON_MEM_LIMIT 2 // run EGC when an upper memory limit is hit 12 | #define EGC_ALWAYS 4 // always run EGC before an allocation 13 | 14 | void legc_set_mode(lua_State *L, int mode, unsigned limit); 15 | 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | #include "lgc.h" 14 | 15 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 16 | cast(int, sizeof(TValue)*((n)-1))) 17 | 18 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 19 | cast(int, sizeof(TValue *)*((n)-1))) 20 | 21 | #define proto_readonly(p) l_setbit((p)->marked, READONLYBIT) 22 | #define proto_is_readonly(p) testbit((p)->marked, READONLYBIT) 23 | 24 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 25 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); 26 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); 27 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 28 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 29 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 30 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 31 | LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); 32 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 33 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 34 | int pc); 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | //#ifdef LUA_CROSS_COMPILER 12 | //#include 13 | //#else 14 | //#include "c_stddef.h" 15 | //#endif 16 | 17 | #include "llimits.h" 18 | #include "lua.h" 19 | 20 | #define MEMERRMSG "not enough memory" 21 | 22 | 23 | #define luaM_reallocv(L,b,on,n,e) \ 24 | ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ 25 | luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ 26 | luaM_toobig(L)) 27 | 28 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 29 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 30 | #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) 31 | 32 | #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) 33 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 34 | #define luaM_newvector(L,n,t) \ 35 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 36 | 37 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 38 | if ((nelems)+1 > (size)) \ 39 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 40 | 41 | #define luaM_reallocvector(L, v,oldn,n,t) \ 42 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 43 | 44 | 45 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 46 | size_t size); 47 | LUAI_FUNC void *luaM_toobig (lua_State *L); 48 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 49 | size_t size_elem, int limit, 50 | const char *errormsg); 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/lrodefs.h: -------------------------------------------------------------------------------- 1 | /* Read-only tables helper */ 2 | 3 | #ifndef lrodefs_h 4 | #define lrodefs_h 5 | 6 | #include "lrotable.h" 7 | 8 | #undef LUA_REG_TYPE 9 | #undef LSTRKEY 10 | #undef LNILKEY 11 | #undef LNUMKEY 12 | #undef LFUNCVAL 13 | #undef LNUMVAL 14 | #undef LROVAL 15 | #undef LNILVAL 16 | #undef LREGISTER 17 | 18 | #if (MIN_OPT_LEVEL > 0) && (LUA_OPTIMIZE_MEMORY >= MIN_OPT_LEVEL) 19 | #define LUA_REG_TYPE luaR_entry 20 | #define LSTRKEY LRO_STRKEY 21 | #define LNUMKEY LRO_NUMKEY 22 | #define LNILKEY LRO_NILKEY 23 | #define LFUNCVAL LRO_FUNCVAL 24 | #define LUDATA LRO_LUDATA 25 | #define LNUMVAL LRO_NUMVAL 26 | #define LROVAL LRO_ROVAL 27 | #define LNILVAL LRO_NILVAL 28 | #define LREGISTER(L, name, table)\ 29 | return 0 30 | #else 31 | #define LUA_REG_TYPE luaL_reg 32 | #define LSTRKEY(x) x 33 | #define LNILKEY NULL 34 | #define LFUNCVAL(x) x 35 | #define LNILVAL NULL 36 | #define LREGISTER(L, name, table)\ 37 | luaL_register(L, name, table);\ 38 | return 1 39 | #endif 40 | 41 | #endif /* lrodefs_h */ 42 | 43 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | 11 | #include "lgc.h" 12 | #include "lobject.h" 13 | #include "lstate.h" 14 | 15 | 16 | #define sizestring(s) (sizeof(union TString)+(luaS_isreadonly(s) ? sizeof(char **) : ((s)->len+1)*sizeof(char))) 17 | 18 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 19 | 20 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) 21 | #define luaS_newro(L, s) (luaS_newrolstr(L, s, strlen(s))) 22 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 23 | (sizeof(s)/sizeof(char))-1)) 24 | 25 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 26 | #define luaS_readonly(s) l_setbit((s)->tsv.marked, READONLYBIT) 27 | #define luaS_isreadonly(s) testbit((s)->marked, READONLYBIT) 28 | 29 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 30 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 31 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 32 | LUAI_FUNC TString *luaS_newrolstr (lua_State *L, const char *str, size_t l); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key.tvk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define key2tval(n) (&(n)->i_key.tvk) 19 | 20 | 21 | LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); 22 | LUAI_FUNC const TValue *luaH_getnum_ro (void *t, int key); 23 | LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); 24 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 25 | LUAI_FUNC const TValue *luaH_getstr_ro (void *t, TString *key); 26 | LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); 27 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 28 | LUAI_FUNC const TValue *luaH_get_ro (void *t, const TValue *key); 29 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 30 | LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); 31 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 32 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 33 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 34 | LUAI_FUNC int luaH_next_ro (lua_State *L, void *t, StkId key); 35 | LUAI_FUNC int luaH_getn (Table *t); 36 | LUAI_FUNC int luaH_getn_ro (void *t); 37 | 38 | #if defined(LUA_DEBUG) 39 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 40 | LUAI_FUNC int luaH_isdummy (Node *n); 41 | #endif 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_EQ, /* last tag method with `fast' access */ 24 | TM_ADD, 25 | TM_SUB, 26 | TM_MUL, 27 | TM_DIV, 28 | TM_MOD, 29 | TM_POW, 30 | TM_UNM, 31 | TM_LEN, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | !luaR_isrotable(et) && ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | LUAI_DATA const char *const luaT_typenames[]; 47 | 48 | 49 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 50 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 51 | TMS event); 52 | LUAI_FUNC void luaT_init (lua_State *L); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/luac_cross.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Header to allow luac.cross compile within NodeMCU 3 | ** See Copyright Notice in lua.h 4 | */ 5 | #ifndef luac_cross_h 6 | #define luac_cross_h 7 | 8 | #define C_HEADER_ASSERT 9 | #define C_HEADER_CTYPE 10 | #define C_HEADER_ERRNO 11 | #define C_HEADER_FCNTL 12 | #define C_HEADER_LOCALE 13 | #define C_HEADER_MATH 14 | #define C_HEADER_STDIO 15 | #define C_HEADER_STDLIB 16 | #define C_HEADER_STRING 17 | #define C_HEADER_TIME 18 | 19 | #ifdef LUA_CROSS_COMPILER 20 | #define ICACHE_RODATA_ATTR 21 | #endif 22 | 23 | #endif /* luac_cross_h */ 24 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include 11 | 12 | #include "lobject.h" 13 | #include "lzio.h" 14 | 15 | typedef uint32_t strsize_t; 16 | 17 | /* info about target machine for cross-compilation */ 18 | typedef struct { 19 | int little_endian; 20 | int sizeof_int; 21 | int sizeof_strsize_t; 22 | int sizeof_lua_Number; 23 | int lua_Number_integral; 24 | int is_arm_fpa; 25 | } DumpTargetInfo; 26 | 27 | /* load one chunk; from lundump.c */ 28 | LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 29 | 30 | /* make header; from lundump.c */ 31 | LUAI_FUNC void luaU_header (char* h); 32 | 33 | /* dump one chunk to a different target; from ldump.c */ 34 | int luaU_dump_crosscompile (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip, DumpTargetInfo target); 35 | 36 | /* dump one chunk; from ldump.c */ 37 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 38 | 39 | #ifdef luac_c 40 | /* print one chunk; from print.c */ 41 | LUAI_FUNC void luaU_print (const Proto* f, int full); 42 | #endif 43 | 44 | /* for header of binary files -- this is Lua 5.1 */ 45 | #define LUAC_VERSION 0x51 46 | 47 | /* for header of binary files -- this is the official format */ 48 | #define LUAC_FORMAT 0 49 | 50 | /* size of header of binary files */ 51 | #define LUAC_HEADERSIZE 12 52 | 53 | /* error codes from cross-compiler */ 54 | /* target integer is too small to hold a value */ 55 | #define LUA_ERR_CC_INTOVERFLOW 101 56 | 57 | /* target lua_Number is integral but a constant is non-integer */ 58 | #define LUA_ERR_CC_NOTINTEGER 102 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ 19 | (((o) = luaV_tonumber(o,n)) != NULL)) 20 | 21 | #define equalobj(L,o1,o2) \ 22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) 23 | 24 | 25 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 26 | LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); 27 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 28 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 29 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 30 | StkId val); 31 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 32 | StkId val); 33 | LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); 34 | LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/include/user_modules.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_MODULES_H__ 2 | #define __USER_MODULES_H__ 3 | 4 | #define LUA_USE_BUILTIN_STRING // for string.xxx() 5 | #define LUA_USE_BUILTIN_TABLE // for table.xxx() 6 | #define LUA_USE_BUILTIN_COROUTINE // for coroutine.xxx() 7 | #define LUA_USE_BUILTIN_MATH // for math.xxx(), partially work 8 | // #define LUA_USE_BUILTIN_IO // for io.xxx(), partially work 9 | 10 | // #define LUA_USE_BUILTIN_OS // for os.xxx(), not work 11 | // #define LUA_USE_BUILTIN_DEBUG 12 | #define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback() 13 | 14 | 15 | #define USE_NODE_MODULE 16 | #define USE_FILE_MODULE 17 | #define USE_GPIO_MODULE 18 | #define USE_UTILS_MODULE 19 | #define USE_TMR_MODULE 20 | #define USE_ZIGBEE_MODULE 21 | /*#define USE_LPEG_MODULE 22 | #define USE_UART_MODULE 23 | #define USE_MQTT_MODULE 24 | #define USE_PWM_MODULE 25 | #define USE_I2C_MODULE 26 | #define USE_WIFI_MODULE 27 | #define USE_NET_MODULE 28 | //#define USE_THREAD_MODULE 29 | #define USE_NVS_MODULE 30 | */ 31 | 32 | 33 | 34 | #endif /* __USER_MODULES_H__ */ 35 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/lua/legc.c: -------------------------------------------------------------------------------- 1 | // Lua EGC (Emergeny Garbage Collector) interface 2 | 3 | #include "legc.h" 4 | #include "lstate.h" 5 | 6 | void legc_set_mode(lua_State *L, int mode, unsigned limit) { 7 | global_State *g = G(L); 8 | 9 | g->egcmode = mode; 10 | g->memlimit = limit; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "node.c" "file.c" "gpio.c" "utils.c" "tmr.c" "zigbee" 2 | REQUIRES lua utils spiffs driver esp_timer esp_event 3 | INCLUDE_DIRS "include") 4 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/modules/zigbee.c: -------------------------------------------------------------------------------- 1 | #include 2 | //#include "modules.h" 3 | #include "lauxlib.h" 4 | #include "ldebug.h" 5 | #include "ldo.h" 6 | #include "lfunc.h" 7 | #include "lmem.h" 8 | #include "lobject.h" 9 | #include "lstate.h" 10 | #include "lualib.h" 11 | 12 | #include "lopcodes.h" 13 | #include "lstring.h" 14 | #include "lundump.h" 15 | 16 | #include "platform.h" 17 | #include "lrotable.h" 18 | #include "lrodefs.h" 19 | 20 | #define TAG "zb" 21 | 22 | // Module function map 23 | const LUA_REG_TYPE zigbee_map[] = 24 | { 25 | { LNILKEY, LNILVAL } 26 | }; 27 | 28 | LUALIB_API int luaopen_zigbee(lua_State *L) 29 | { 30 | luaL_register( L, LUA_ZIGBEELIBNAME, zigbee_map ); 31 | return 1; 32 | } 33 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/mylibc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "c_ctype.c" "c_math.c" "c_stdio.c" "c_stdlib.c" "c_string.c" 2 | INCLUDE_DIRS "include") 3 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/mylibc/Kconfig: -------------------------------------------------------------------------------- 1 | menu "MYLIBC" 2 | 3 | config MYLIBC_ENABLE 4 | bool "Enable mylibc" 5 | default "y" 6 | help 7 | For mylibc. 8 | 9 | endmenu 10 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/mylibc/c_ctype.c: -------------------------------------------------------------------------------- 1 | #include "c_ctype.h" 2 | #include "c_types.h" 3 | 4 | // int isalnum(int c){} 5 | // int isalpha(int c){} 6 | // int iscntrl(int c){} 7 | // int isdigit(int c){} 8 | // // int isgraph(int c){} 9 | // int islower(int c){} 10 | // int isprint(int c){} 11 | // int ispunct(int c){} 12 | // int isspace(int c){} 13 | // int isupper(int c){} 14 | // int isxdigit(int c){} 15 | // int tolower(int c){} 16 | // int toupper(int c){} 17 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/mylibc/c_string.c: -------------------------------------------------------------------------------- 1 | #include "c_string.h" 2 | 3 | // const char *c_strstr(const char * __s1, const char * __s2){ 4 | // } 5 | 6 | // char *c_strncat(char * s1, const char * s2, size_t n){ 7 | // } 8 | 9 | // size_t c_strcspn(const char * s1, const char * s2){ 10 | // } 11 | 12 | // const char *c_strpbrk(const char * s1, const char * s2){ 13 | // } 14 | 15 | // int c_strcoll(const char * s1, const char * s2){ 16 | // } 17 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/mylibc/include/c_ctype.h: -------------------------------------------------------------------------------- 1 | #ifndef _C_CTYPE_H_ 2 | #define _C_CTYPE_H_ 3 | 4 | #if 0 5 | int isalnum(int); 6 | int isalpha(int); 7 | int iscntrl(int); 8 | int isdigit(int); 9 | // int isgraph(int); 10 | int islower(int); 11 | int isprint(int); 12 | int ispunct(int); 13 | int isspace(int); 14 | int isupper(int); 15 | int isxdigit(int); 16 | int tolower(int); 17 | int toupper(int); 18 | 19 | #if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L 20 | // int isblank(int); 21 | #endif 22 | 23 | #ifndef __STRICT_ANSI__ 24 | // int isascii(int); 25 | // int toascii(int); 26 | #define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a') 27 | #define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A') 28 | #endif 29 | 30 | #define _U 01 31 | #define _L 02 32 | #define _N 04 33 | #define _S 010 34 | #define _P 020 35 | #define _C 040 36 | #define _X 0100 37 | #define _B 0200 38 | 39 | /* For C++ backward-compatibility only. */ 40 | // extern char _ctype_[]; 41 | #endif 42 | #endif /* _C_CTYPE_H_ */ 43 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/mylibc/include/c_errno.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_errno_h 2 | #define __c_errno_h 3 | 4 | #include 5 | // #ifndef errno 6 | // extern int errno; 7 | // #endif 8 | 9 | // #define EDOM 1 10 | // #define ERANGE 2 11 | // #define EILSEQ 4 12 | // #define ESIGNUM 3 13 | // #define EINVAL 5 14 | // #define ENOMEM 6 15 | 16 | #endif 17 | 18 | /* end of c_errno.h */ 19 | 20 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/mylibc/include/c_fcntl.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_fcntl_h 2 | #define __c_fcntl_h 3 | 4 | #include 5 | 6 | #endif 7 | 8 | /* end of c_fcntl.h */ 9 | 10 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/mylibc/include/c_locale.h: -------------------------------------------------------------------------------- 1 | /* 2 | c_locale.h 3 | Values appropriate for the formatting of monetary and other 4 | numberic quantities. 5 | */ 6 | 7 | #ifndef _C_LOCALE_H_ 8 | #define _C_LOCALE_H_ 9 | 10 | #include 11 | 12 | #if 0 13 | #ifndef NULL 14 | #define NULL 0 15 | #endif 16 | 17 | #define LC_ALL 0 18 | #define LC_COLLATE 1 19 | #define LC_CTYPE 2 20 | #define LC_MONETARY 3 21 | #define LC_NUMERIC 4 22 | #define LC_TIME 5 23 | #define LC_MESSAGES 6 24 | 25 | struct lconv 26 | { 27 | char *decimal_point; 28 | char *thousands_sep; 29 | char *grouping; 30 | char *int_curr_symbol; 31 | char *currency_symbol; 32 | char *mon_decimal_point; 33 | char *mon_thousands_sep; 34 | char *mon_grouping; 35 | char *positive_sign; 36 | char *negative_sign; 37 | char int_frac_digits; 38 | char frac_digits; 39 | char p_cs_precedes; 40 | char p_sep_by_space; 41 | char n_cs_precedes; 42 | char n_sep_by_space; 43 | char p_sign_posn; 44 | char n_sign_posn; 45 | char int_n_cs_precedes; 46 | char int_n_sep_by_space; 47 | char int_n_sign_posn; 48 | char int_p_cs_precedes; 49 | char int_p_sep_by_space; 50 | char int_p_sign_posn; 51 | }; 52 | 53 | #ifndef _REENT_ONLY 54 | // char *setlocale(int category, const char *locale); 55 | struct lconv *localeconv(void); 56 | #endif 57 | 58 | // struct _reent; 59 | // char *_setlocale_r(struct _reent *, int category, const char *locale); 60 | // struct lconv *_localeconv_r(struct _reent *); 61 | #endif 62 | #endif /* _C_LOCALE_H_ */ 63 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/mylibc/include/c_math.h: -------------------------------------------------------------------------------- 1 | #ifndef _C_MATH_H_ 2 | #define _C_MATH_H_ 3 | #include 4 | 5 | double floor(double); 6 | double pow(double, double); 7 | 8 | #if 0 9 | #ifndef HUGE_VAL 10 | #define HUGE_VAL (1.0e99) 11 | #endif 12 | 13 | #ifndef HUGE_VALF 14 | #define HUGE_VALF (1.0e999999999F) 15 | #endif 16 | 17 | #if !defined(HUGE_VALL) && defined(_HAVE_LONG_DOUBLE) 18 | #define HUGE_VALL (1.0e999999999L) 19 | #endif 20 | 21 | #if !defined(INFINITY) 22 | #define INFINITY (HUGE_VALF) 23 | #endif 24 | 25 | 26 | /* Reentrant ANSI C functions. */ 27 | 28 | #ifndef __math_68881 29 | // double atan(double); 30 | // double cos(double); 31 | // double sin(double); 32 | // double tan(double); 33 | // double tanh(double); 34 | // double frexp(double, int *); 35 | // double modf(double, double *); 36 | // double ceil(double); 37 | // double fabs(double); 38 | // double floor(double); 39 | #endif /* ! defined (__math_68881) */ 40 | 41 | /* Non reentrant ANSI C functions. */ 42 | 43 | #ifndef _REENT_ONLY 44 | #ifndef __math_68881 45 | // double acos(double); 46 | // double asin(double); 47 | // double atan2(double, double); 48 | // double cosh(double); 49 | // double sinh(double); 50 | // double exp(double); 51 | // double ldexp(double, int); 52 | // double log(double); 53 | // double log10(double); 54 | // double pow(double, double); 55 | // double sqrt(double); 56 | // double fmod(double, double); 57 | #endif /* ! defined (__math_68881) */ 58 | #endif /* ! defined (_REENT_ONLY) */ 59 | 60 | #endif 61 | 62 | #endif /* _MATH_H_ */ 63 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/mylibc/include/c_stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_stdarg_h 2 | #define __c_stdarg_h 3 | 4 | #if defined(__GNUC__) 5 | 6 | #include 7 | 8 | #else 9 | 10 | typedef char * va_list; 11 | 12 | #define _INTSIZEOF(n) ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1)) 13 | 14 | #define va_start(ap,v) (ap = (va_list)&v + _INTSIZEOF(v)) 15 | #define va_arg(ap,t) (*(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t))) 16 | #define va_end(ap) (ap = (va_list)0) 17 | 18 | #endif 19 | 20 | #endif 21 | 22 | /* end of c_stdarg.h */ 23 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/mylibc/include/c_stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_stddef_h 2 | #define __c_stddef_h 3 | 4 | typedef signed int ptrdiff_t; 5 | 6 | #if !defined(offsetof) 7 | #define offsetof(s, m) (size_t)&(((s *)0)->m) 8 | #endif 9 | 10 | #if !defined(__size_t) 11 | #define __size_t 1 12 | typedef unsigned int size_t; /* others (e.g. ) also define */ 13 | /* the unsigned integral type of the result of the sizeof operator. */ 14 | #endif 15 | 16 | #undef NULL /* others (e.g. ) also define */ 17 | #define NULL 0 18 | /* null pointer constant. */ 19 | 20 | #endif 21 | 22 | /* end of c_stddef.h */ 23 | 24 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/mylibc/include/c_stdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * c_stdlib.h 3 | * 4 | * Definitions for common types, variables, and functions. 5 | */ 6 | 7 | #ifndef _C_STDLIB_H_ 8 | #define _C_STDLIB_H_ 9 | 10 | #include "c_stddef.h" 11 | //#include "mem.h" 12 | 13 | #include 14 | 15 | #define EXIT_FAILURE 1 16 | #define EXIT_SUCCESS 0 17 | 18 | //#define __INT_MAX__ 2147483647 19 | #undef __RAND_MAX 20 | #if __INT_MAX__ == 32767 21 | #define __RAND_MAX 32767 22 | #else 23 | #define __RAND_MAX 0x7fffffff 24 | #endif 25 | #define RAND_MAX __RAND_MAX 26 | 27 | #ifndef mem_realloc 28 | #define mem_realloc pvPortRealloc 29 | #endif 30 | #ifndef os_realloc 31 | #define os_realloc(p, s) mem_realloc((p), (s)) 32 | #endif 33 | 34 | #define c_free free 35 | #define c_malloc os_malloc 36 | #define c_zalloc os_zalloc 37 | #define c_realloc realloc 38 | 39 | #define c_abs abs 40 | #define c_atoi atoi 41 | //#define c_strtod strtod 42 | #define c_strtol strtol 43 | #define c_strtoul strtoul 44 | 45 | // int c_abs(int); 46 | 47 | // void c_exit(int); 48 | 49 | #define ICACHE_STORE_ATTR __attribute__((aligned(4))) 50 | 51 | // c_getenv() get env "LUA_INIT" string for lua initialization. 52 | const char *c_getenv(const char *__string); 53 | 54 | // void *c_malloc(size_t __size); 55 | // void *c_zalloc(size_t __size); 56 | // void c_free(void *); 57 | 58 | // int c_rand(void); 59 | // void c_srand(unsigned int __seed); 60 | 61 | // int c_atoi(const char *__nptr); 62 | double c_strtod(const char *__n, char **__end_PTR); 63 | // // long c_strtol(const char *__n, char **__end_PTR, int __base); 64 | // unsigned long c_strtoul(const char *__n, char **__end_PTR, int __base); 65 | // // long long c_strtoll(const char *__n, char **__end_PTR, int __base); 66 | 67 | #endif /* _C_STDLIB_H_ */ 68 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/mylibc/include/c_string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * c_string.h 3 | * 4 | * Definitions for memory and string functions. 5 | */ 6 | 7 | #ifndef _C_STRING_H_ 8 | #define _C_STRING_H_ 9 | #include "c_stddef.h" 10 | //#include "osapi.h" 11 | //#include "esp_libc.h" 12 | #include 13 | 14 | #ifndef NULL 15 | #define NULL 0 16 | #endif 17 | 18 | #define c_memcmp memcmp 19 | #define c_memcpy memcpy 20 | #define c_memset memset 21 | 22 | #define os_memcpy ets_memcpy 23 | #define os_memcmp ets_memcmp 24 | #define os_memmove ets_memmove 25 | 26 | #define c_strcat strcat 27 | #define c_strchr strchr 28 | #define c_strcmp strcmp 29 | #define c_strcpy strcpy 30 | #define c_strlen strlen 31 | #define c_strncmp strncmp 32 | #define c_strncpy strncpy 33 | // #define c_strstr os_strstr 34 | #define c_strncasecmp strncmp 35 | 36 | #define c_strstr strstr 37 | #define c_strncat strncat 38 | #define c_strcspn strcspn 39 | #define c_strpbrk strpbrk 40 | #define c_strcoll strcoll 41 | #define c_strrchr strrchr 42 | 43 | //extern unsigned int strlen(char *s); 44 | //extern char *strcat(char *dest, char *src); 45 | //extern char *strchr(const char *s, int c); 46 | //extern char *strcpy(char* des, const char* source); 47 | //extern char *strncpy(char *dest, const char *src, size_t n); 48 | //extern void *memcpy(void *dest, const void *src, size_t n); 49 | extern void *memchr(const void *buf, int ch, size_t count); 50 | extern char *strpbrk(const char *s1, const char *s2); 51 | 52 | // const char *c_strstr(const char * __s1, const char * __s2); 53 | // char *c_strncat(char * __restrict /*s1*/, const char * __restrict /*s2*/, size_t n); 54 | // size_t c_strcspn(const char * s1, const char * s2); 55 | // const char *c_strpbrk(const char * /*s1*/, const char * /*s2*/); 56 | // int c_strcoll(const char * /*s1*/, const char * /*s2*/); 57 | 58 | #endif /* _C_STRING_H_ */ 59 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "utils.c" "platform.c" 2 | REQUIRES driver 3 | INCLUDE_DIRS "include") 4 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/utils/include/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef _PLATFORM_H_ 2 | #define _PLATFORM_H_ 3 | 4 | #define NODE_PLATFORM_ESP32 1001 5 | #define NODE_PLATFORM_ESP8266 1002 6 | #define NODE_PLATFORM_STM32 1003 7 | #define NODE_PLATFORM_W800 1004 8 | 9 | 10 | #define CURRENT_PLATFORM NODE_PLATFORM_ESP32 11 | #define BUILD_SPIFFS 12 | 13 | 14 | #if (CURRENT_PLATFORM == NODE_PLATFORM_ESP32) 15 | #define OUTPUT GPIO_MODE_OUTPUT 16 | #define INPUT GPIO_MODE_INPUT 17 | #define PULLUP GPIO_PULLUP_ONLY 18 | #define FLOAT GPIO_FLOATING 19 | #define INOUT GPIO_MODE_INPUT_OUTPUT 20 | #define PLATFORM_INTERRUPT GPIO_INTR_POSEDGE 21 | #define HIGH 1 22 | #define LOW 0 23 | #define GPIO_PIN_NUM GPIO_NUM_MAX 24 | #else 25 | #define PULLUP PLATFORM_GPIO_PULLUP 26 | #define FLOAT PLATFORM_GPIO_FLOAT 27 | #define OUTPUT PLATFORM_GPIO_OUTPUT 28 | #define INPUT PLATFORM_GPIO_INPUT 29 | #define INOUT PLATFORM_GPIO_INOUT 30 | #define PLATFORM_INTERRUPT PLATFORM_GPIO_INT 31 | #define HIGH PLATFORM_GPIO_HIGH 32 | #define LOW PLATFORM_GPIO_LOW 33 | #endif 34 | 35 | void lua_node_restart(void); 36 | void lua_node_sleep(uint64_t us); 37 | uint32_t lua_node_get_heap_size(void); 38 | void lua_node_system_restore(void); 39 | 40 | int platform_gpio_mode(int pin, int mode, int type); 41 | void platform_gpio_isr_uninstall(void); 42 | uint8_t platform_gpio_read(int pin); 43 | void platform_gpio_write(int pin, int level); 44 | 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/utils/include/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_H_ 2 | #define _UTILS_H_ 3 | 4 | typedef enum { 5 | EMPTY, 6 | UNDER_WRITE, 7 | WRITE_OVER 8 | } RcvMsgBuffState; 9 | 10 | 11 | typedef struct { 12 | uint32_t RcvBuffSize; 13 | uint8_t *pRcvMsgBuff; 14 | uint8_t *pWritePos; 15 | uint8_t *pReadPos; 16 | uint8_t TrigLvl; //JLU: may need to pad 17 | RcvMsgBuffState BuffState; 18 | } RcvMsgBuff; 19 | 20 | void print_info(void); 21 | //char *basename(char *path); 22 | char * get_partition_label(void); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/components/utils/utils.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "utils.h" 4 | 5 | void print_info(void) 6 | { 7 | printf(" _ _ _ _ \n\ 8 | | | | \\ | | | | \n\ 9 | | | _ _ __ _ | \\| | ___ __| | ___ \n\ 10 | | | | | | | / _` || . ` | / _ \\ / _` | / _ \\\n\ 11 | | |____| |_| || (_| || |\\ || (_) || (_| || __/\n\ 12 | \\_____/ \\__,_| \\__,_|\\_| \\_/ \\___/ \\__,_| \\___|\n\ 13 | \n\ 14 | For " CONFIG_IDF_TARGET " \n\ 15 | Version 2.0.0\n\ 16 | \n\ 17 | ------------------------------------------------\n\ 18 | \n"); 19 | } 20 | 21 | /*char *basename(char *path) 22 | { 23 | int num = strlen(path); 24 | for (int i = num-1; i >= 0; i++) { 25 | if (path[i] == '/') { 26 | return path+i+1; 27 | } 28 | } 29 | return path; 30 | }*/ 31 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "main.c" "uart_handler.c" 2 | INCLUDE_DIRS "include") 3 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/main/include/lua_def.h: -------------------------------------------------------------------------------- 1 | #ifndef _LUA_DEF_H_ 2 | #define _LUA_DEF_H_ 3 | 4 | 5 | /* 6 | @@ LUA_MAXINPUT is the maximum length for an input line in the 7 | @* stand-alone interpreter. 8 | ** CHANGE it if you need longer lines. 9 | */ 10 | #define LUA_MAXINPUT 256 11 | 12 | /* 13 | @@ LUA_PROMPT is the default prompt used by stand-alone Lua. 14 | @@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua. 15 | ** CHANGE them if you want different prompts. (You can also change the 16 | ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) 17 | */ 18 | #define LUA_PROMPT "> " 19 | #define LUA_PROMPT2 ">> " 20 | 21 | // EGC operations modes 22 | #define EGC_NOT_ACTIVE 0 // EGC disabled 23 | #define EGC_ON_ALLOC_FAILURE 1 // run EGC on allocation failure 24 | #define EGC_ON_MEM_LIMIT 2 // run EGC when an upper memory limit is hit 25 | #define EGC_ALWAYS 4 // always run EGC before an allocation 26 | 27 | /* 28 | ** pseudo-indices 29 | */ 30 | #define LUA_REGISTRYINDEX (-10000) 31 | #define LUA_ENVIRONINDEX (-10001) 32 | #define LUA_GLOBALSINDEX (-10002) 33 | 34 | 35 | #define GCSpause 0 36 | 37 | #define GCSTEPSIZE 1024u 38 | 39 | typedef LUAI_UMEM lu_mem; 40 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) 41 | 42 | #define G(L) (L->l_G) 43 | 44 | 45 | typedef struct __lua_load{ 46 | lua_State *L; 47 | int firstline; 48 | char *line; 49 | int line_position; 50 | size_t len; 51 | int done; 52 | const char *prmt; 53 | }lua_Load; 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/main/include/uart_handler.h: -------------------------------------------------------------------------------- 1 | #ifndef _UART_HANDLER_H_ 2 | #define _UART_HANDLER_H_ 3 | 4 | 5 | void my_uart_init(void); 6 | bool uart_getc(char *c); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/partitions_luanode.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap 3 | nvs, data, nvs, 0x9000, 0x6000, 4 | phy_init, data, phy, 0xf000, 0x1000, 5 | factory, app, factory, 0x10000, 1M, 6 | storage, data, spiffs, , 0xF0000, 7 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/sdkconfig.ci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/LuaNode_Esp32/LuaNode32C6/sdkconfig.ci -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32C6/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_IDF_TARGET="esp32c6" 2 | 3 | -------------------------------------------------------------------------------- /LuaNode_Esp32/LuaNode32_document.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/LuaNode_Esp32/LuaNode32_document.docx -------------------------------------------------------------------------------- /LuaNode_Esp32/firmware/LuaNode32C6.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/LuaNode_Esp32/firmware/LuaNode32C6.bin -------------------------------------------------------------------------------- /LuaNode_Esp32/firmware/LuaNode_201705040906.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/LuaNode_Esp32/firmware/LuaNode_201705040906.bin -------------------------------------------------------------------------------- /LuaNode_Esp32/firmware/README.md: -------------------------------------------------------------------------------- 1 | ## HOW TO FLASH 2 | 3 | Use either the Espressif flash_download_tools or esptool.py to flash the firmware. 4 | 5 | The start address is 0x1000 6 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's 2 | # CMakeLists in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.5) 4 | set(EXTRA_COMPONENT_DIRS ./components) 5 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 6 | project(luanode) 7 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := luanode 7 | 8 | include $(IDF_PATH)/make/project.mk 9 | 10 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "lapi.c" "lcode.c" "ldo.c" "lfunc.c" "llex.c" "loadlib.c" "lparser.c" "lstring.c" "ltablib.c" "lundump.c" "lauxlib.c" "ldblib.c" "ldump.c" "lgc.c" "lmathlib.c" "lobject.c" "lrotable.c" "lstrlib.c" "ltm.c" "lvm.c" "lbaselib.c" "ldebug.c" "legc.c" "liolib.c" "lmem.c" "lopcodes.c" "lstate.c" "ltable.c" "lua.c" "lzio.c" "linit.c" 2 | REQUIRES vfs mylibc 3 | INCLUDE_DIRS "include") 4 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/Kconfig: -------------------------------------------------------------------------------- 1 | menu "LUA" 2 | 3 | config LUA_ENABLE 4 | bool "Enable lua" 5 | default "y" 6 | help 7 | For lua script. 8 | 9 | endmenu 10 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/compiler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * define start/end address of ro data. 3 | */ 4 | 5 | #ifndef __COMPILER_H__ 6 | #define __COMPILER_H__ 7 | 8 | #define __ESP32__ 9 | #if defined(__ESP8266__) 10 | 11 | extern char _irom0_text_start; 12 | extern char _irom0_text_end; 13 | #define RODATA_START_ADDRESS (&_irom0_text_start) 14 | #define RODATA_END_ADDRESS (&_irom0_text_end) 15 | 16 | #elif defined(__ESP32__) 17 | 18 | #define RODATA_START_ADDRESS ((char*)0x3F400000) 19 | #define RODATA_END_ADDRESS ((char*)0x3F800000) 20 | 21 | #else // other compilers 22 | 23 | /* Firstly, modify rodata's start/end address. Then, comment the line below */ 24 | #error "Please modify RODATA_START_ADDRESS and RODATA_END_ADDRESS below." 25 | 26 | /* Perhaps you can use start/end address of flash */ 27 | #define RODATA_START_ADDRESS ((char*)0x40200000) 28 | #define RODATA_END_ADDRESS ((char*)0x40280000) 29 | 30 | #endif 31 | 32 | #endif // __COMPILER_H__ 33 | 34 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #ifdef LUA_OPTIMIZE_DEBUG 17 | # include "lvm.h" 18 | # define getline(f,pc) (((f)->packedlineinfo) ? luaG_getline((f), pc) : 0) 19 | # define INFO_FILL_BYTE 0x7F 20 | # define INFO_DELTA_MASK 0x80 21 | # define INFO_SIGN_MASK 0x40 22 | # define INFO_DELTA_6BITS 0x3F 23 | # define INFO_DELTA_7BITS 0x7F 24 | # define INFO_MAX_LINECNT 126 25 | # define lineInfoTop(fs) ((fs)->f->packedlineinfo + (fs)->lastlineOffset) 26 | #else 27 | # define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 28 | #endif 29 | 30 | #define resethookcount(L) (L->hookcount = L->basehookcount) 31 | 32 | 33 | LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, 34 | const char *opname); 35 | LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 36 | LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, 37 | const TValue *p2); 38 | LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, 39 | const TValue *p2); 40 | LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); 41 | LUAI_FUNC void luaG_errormsg (lua_State *L); 42 | LUAI_FUNC int luaG_checkcode (const Proto *pt); 43 | LUAI_FUNC int luaG_checkopenop (Instruction i); 44 | #ifdef LUA_OPTIMIZE_DEBUG 45 | LUAI_FUNC int luaG_getline (const Proto *f, int pc); 46 | LUAI_FUNC int luaG_stripdebug (lua_State *L, Proto *f, int level, int recv); 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/legc.h: -------------------------------------------------------------------------------- 1 | // Lua EGC (Emergeny Garbage Collector) interface 2 | 3 | #ifndef __LEGC_H__ 4 | #define __LEGC_H__ 5 | 6 | #include "lstate.h" 7 | 8 | // EGC operations modes 9 | #define EGC_NOT_ACTIVE 0 // EGC disabled 10 | #define EGC_ON_ALLOC_FAILURE 1 // run EGC on allocation failure 11 | #define EGC_ON_MEM_LIMIT 2 // run EGC when an upper memory limit is hit 12 | #define EGC_ALWAYS 4 // always run EGC before an allocation 13 | 14 | void legc_set_mode(lua_State *L, int mode, unsigned limit); 15 | 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | #include "lgc.h" 14 | 15 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 16 | cast(int, sizeof(TValue)*((n)-1))) 17 | 18 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 19 | cast(int, sizeof(TValue *)*((n)-1))) 20 | 21 | #define proto_readonly(p) l_setbit((p)->marked, READONLYBIT) 22 | #define proto_is_readonly(p) testbit((p)->marked, READONLYBIT) 23 | 24 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 25 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); 26 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); 27 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 28 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 29 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 30 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 31 | LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); 32 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 33 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 34 | int pc); 35 | 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | //#ifdef LUA_CROSS_COMPILER 12 | //#include 13 | //#else 14 | //#include "c_stddef.h" 15 | //#endif 16 | 17 | #include "llimits.h" 18 | #include "lua.h" 19 | 20 | #define MEMERRMSG "not enough memory" 21 | 22 | 23 | #define luaM_reallocv(L,b,on,n,e) \ 24 | ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ 25 | luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ 26 | luaM_toobig(L)) 27 | 28 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 29 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 30 | #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) 31 | 32 | #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) 33 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 34 | #define luaM_newvector(L,n,t) \ 35 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 36 | 37 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 38 | if ((nelems)+1 > (size)) \ 39 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 40 | 41 | #define luaM_reallocvector(L, v,oldn,n,t) \ 42 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 43 | 44 | 45 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 46 | size_t size); 47 | LUAI_FUNC void *luaM_toobig (lua_State *L); 48 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 49 | size_t size_elem, int limit, 50 | const char *errormsg); 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/lrodefs.h: -------------------------------------------------------------------------------- 1 | /* Read-only tables helper */ 2 | 3 | #ifndef lrodefs_h 4 | #define lrodefs_h 5 | 6 | #include "lrotable.h" 7 | 8 | #undef LUA_REG_TYPE 9 | #undef LSTRKEY 10 | #undef LNILKEY 11 | #undef LNUMKEY 12 | #undef LFUNCVAL 13 | #undef LNUMVAL 14 | #undef LROVAL 15 | #undef LNILVAL 16 | #undef LREGISTER 17 | 18 | #if (MIN_OPT_LEVEL > 0) && (LUA_OPTIMIZE_MEMORY >= MIN_OPT_LEVEL) 19 | #define LUA_REG_TYPE luaR_entry 20 | #define LSTRKEY LRO_STRKEY 21 | #define LNUMKEY LRO_NUMKEY 22 | #define LNILKEY LRO_NILKEY 23 | #define LFUNCVAL LRO_FUNCVAL 24 | #define LUDATA LRO_LUDATA 25 | #define LNUMVAL LRO_NUMVAL 26 | #define LROVAL LRO_ROVAL 27 | #define LNILVAL LRO_NILVAL 28 | #define LREGISTER(L, name, table)\ 29 | return 0 30 | #else 31 | #define LUA_REG_TYPE luaL_reg 32 | #define LSTRKEY(x) x 33 | #define LNILKEY NULL 34 | #define LFUNCVAL(x) x 35 | #define LNILVAL NULL 36 | #define LREGISTER(L, name, table)\ 37 | luaL_register(L, name, table);\ 38 | return 1 39 | #endif 40 | 41 | #endif /* lrodefs_h */ 42 | 43 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | 11 | #include "lgc.h" 12 | #include "lobject.h" 13 | #include "lstate.h" 14 | 15 | 16 | #define sizestring(s) (sizeof(union TString)+(luaS_isreadonly(s) ? sizeof(char **) : ((s)->len+1)*sizeof(char))) 17 | 18 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 19 | 20 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) 21 | #define luaS_newro(L, s) (luaS_newrolstr(L, s, strlen(s))) 22 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 23 | (sizeof(s)/sizeof(char))-1)) 24 | 25 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 26 | #define luaS_readonly(s) l_setbit((s)->tsv.marked, READONLYBIT) 27 | #define luaS_isreadonly(s) testbit((s)->marked, READONLYBIT) 28 | 29 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 30 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 31 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 32 | LUAI_FUNC TString *luaS_newrolstr (lua_State *L, const char *str, size_t l); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key.tvk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define key2tval(n) (&(n)->i_key.tvk) 19 | 20 | 21 | LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); 22 | LUAI_FUNC const TValue *luaH_getnum_ro (void *t, int key); 23 | LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); 24 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 25 | LUAI_FUNC const TValue *luaH_getstr_ro (void *t, TString *key); 26 | LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); 27 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 28 | LUAI_FUNC const TValue *luaH_get_ro (void *t, const TValue *key); 29 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 30 | LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); 31 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 32 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 33 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 34 | LUAI_FUNC int luaH_next_ro (lua_State *L, void *t, StkId key); 35 | LUAI_FUNC int luaH_getn (Table *t); 36 | LUAI_FUNC int luaH_getn_ro (void *t); 37 | 38 | #if defined(LUA_DEBUG) 39 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 40 | LUAI_FUNC int luaH_isdummy (Node *n); 41 | #endif 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_EQ, /* last tag method with `fast' access */ 24 | TM_ADD, 25 | TM_SUB, 26 | TM_MUL, 27 | TM_DIV, 28 | TM_MOD, 29 | TM_POW, 30 | TM_UNM, 31 | TM_LEN, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | !luaR_isrotable(et) && ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | LUAI_DATA const char *const luaT_typenames[]; 47 | 48 | 49 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 50 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 51 | TMS event); 52 | LUAI_FUNC void luaT_init (lua_State *L); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/luac_cross.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Header to allow luac.cross compile within NodeMCU 3 | ** See Copyright Notice in lua.h 4 | */ 5 | #ifndef luac_cross_h 6 | #define luac_cross_h 7 | 8 | #define C_HEADER_ASSERT 9 | #define C_HEADER_CTYPE 10 | #define C_HEADER_ERRNO 11 | #define C_HEADER_FCNTL 12 | #define C_HEADER_LOCALE 13 | #define C_HEADER_MATH 14 | #define C_HEADER_STDIO 15 | #define C_HEADER_STDLIB 16 | #define C_HEADER_STRING 17 | #define C_HEADER_TIME 18 | 19 | #ifdef LUA_CROSS_COMPILER 20 | #define ICACHE_RODATA_ATTR 21 | #endif 22 | 23 | #endif /* luac_cross_h */ 24 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include 11 | 12 | #include "lobject.h" 13 | #include "lzio.h" 14 | 15 | typedef uint32_t strsize_t; 16 | 17 | /* info about target machine for cross-compilation */ 18 | typedef struct { 19 | int little_endian; 20 | int sizeof_int; 21 | int sizeof_strsize_t; 22 | int sizeof_lua_Number; 23 | int lua_Number_integral; 24 | int is_arm_fpa; 25 | } DumpTargetInfo; 26 | 27 | /* load one chunk; from lundump.c */ 28 | LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 29 | 30 | /* make header; from lundump.c */ 31 | LUAI_FUNC void luaU_header (char* h); 32 | 33 | /* dump one chunk to a different target; from ldump.c */ 34 | int luaU_dump_crosscompile (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip, DumpTargetInfo target); 35 | 36 | /* dump one chunk; from ldump.c */ 37 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 38 | 39 | #ifdef luac_c 40 | /* print one chunk; from print.c */ 41 | LUAI_FUNC void luaU_print (const Proto* f, int full); 42 | #endif 43 | 44 | /* for header of binary files -- this is Lua 5.1 */ 45 | #define LUAC_VERSION 0x51 46 | 47 | /* for header of binary files -- this is the official format */ 48 | #define LUAC_FORMAT 0 49 | 50 | /* size of header of binary files */ 51 | #define LUAC_HEADERSIZE 12 52 | 53 | /* error codes from cross-compiler */ 54 | /* target integer is too small to hold a value */ 55 | #define LUA_ERR_CC_INTOVERFLOW 101 56 | 57 | /* target lua_Number is integral but a constant is non-integer */ 58 | #define LUA_ERR_CC_NOTINTEGER 102 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ 19 | (((o) = luaV_tonumber(o,n)) != NULL)) 20 | 21 | #define equalobj(L,o1,o2) \ 22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) 23 | 24 | 25 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 26 | LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); 27 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 28 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 29 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 30 | StkId val); 31 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 32 | StkId val); 33 | LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); 34 | LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/include/user_modules.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_MODULES_H__ 2 | #define __USER_MODULES_H__ 3 | 4 | #define LUA_USE_BUILTIN_STRING // for string.xxx() 5 | #define LUA_USE_BUILTIN_TABLE // for table.xxx() 6 | #define LUA_USE_BUILTIN_COROUTINE // for coroutine.xxx() 7 | #define LUA_USE_BUILTIN_MATH // for math.xxx(), partially work 8 | // #define LUA_USE_BUILTIN_IO // for io.xxx(), partially work 9 | 10 | // #define LUA_USE_BUILTIN_OS // for os.xxx(), not work 11 | // #define LUA_USE_BUILTIN_DEBUG 12 | #define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback() 13 | 14 | 15 | #define USE_NODE_MODULE 16 | #define USE_FILE_MODULE 17 | #define USE_GPIO_MODULE 18 | #define USE_UTILS_MODULE 19 | #define USE_TMR_MODULE 20 | #define USE_WIFI_MODULE 21 | /*#define USE_LPEG_MODULE 22 | #define USE_UART_MODULE 23 | #define USE_MQTT_MODULE 24 | #define USE_PWM_MODULE 25 | #define USE_I2C_MODULE 26 | #define USE_NET_MODULE 27 | //#define USE_THREAD_MODULE 28 | #define USE_NVS_MODULE 29 | */ 30 | 31 | 32 | 33 | #endif /* __USER_MODULES_H__ */ 34 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/legc.c: -------------------------------------------------------------------------------- 1 | // Lua EGC (Emergeny Garbage Collector) interface 2 | 3 | #include "legc.h" 4 | #include "lstate.h" 5 | 6 | void legc_set_mode(lua_State *L, int mode, unsigned limit) { 7 | global_State *g = G(L); 8 | 9 | g->egcmode = mode; 10 | g->memlimit = limit; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/lua/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** a generic input stream interface 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define lzio_c 9 | #define LUA_CORE 10 | #define LUAC_CROSS_FILE 11 | 12 | #include "lua.h" 13 | #include C_HEADER_STRING 14 | 15 | #include "llimits.h" 16 | #include "lmem.h" 17 | #include "lstate.h" 18 | #include "lzio.h" 19 | 20 | 21 | int luaZ_fill (ZIO *z) { 22 | size_t size; 23 | lua_State *L = z->L; 24 | const char *buff; 25 | lua_unlock(L); 26 | buff = z->reader(L, z->data, &size); 27 | lua_lock(L); 28 | if (buff == NULL || size == 0) return EOZ; 29 | z->n = size - 1; 30 | z->p = buff; 31 | return char2int(*(z->p++)); 32 | } 33 | 34 | 35 | int luaZ_lookahead (ZIO *z) { 36 | if (z->n == 0) { 37 | if (luaZ_fill(z) == EOZ) 38 | return EOZ; 39 | else { 40 | z->n++; /* luaZ_fill removed first byte; put back it */ 41 | z->p--; 42 | } 43 | } 44 | return char2int(*z->p); 45 | } 46 | 47 | 48 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 49 | z->L = L; 50 | z->reader = reader; 51 | z->data = data; 52 | z->n = z->i = 0; 53 | z->p = NULL; 54 | } 55 | 56 | 57 | /* --------------------------------------------------------------- read --- */ 58 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 59 | while (n) { 60 | size_t m; 61 | if (luaZ_lookahead(z) == EOZ) 62 | return n; /* return number of missing bytes */ 63 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 64 | if (b) 65 | memcpy(b, z->p, m); 66 | z->n -= m; 67 | z->i += m; 68 | z->p += m; 69 | if (b) 70 | b = (char *)b + m; 71 | n -= m; 72 | } 73 | return 0; 74 | } 75 | 76 | /* ------------------------------------------------------------------------ */ 77 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 78 | if (n > buff->buffsize) { 79 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 80 | luaZ_resizebuffer(L, buff, n); 81 | } 82 | return buff->buffer; 83 | } 84 | 85 | 86 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "node.c" "file.c" "gpio.c" "utils.c" 2 | REQUIRES lua utils spiffs driver 3 | INCLUDE_DIRS "include") 4 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/modules/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "c_ctype.c" "c_math.c" "c_stdio.c" "c_stdlib.c" "c_string.c" 2 | INCLUDE_DIRS "include") 3 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/Kconfig: -------------------------------------------------------------------------------- 1 | menu "MYLIBC" 2 | 3 | config MYLIBC_ENABLE 4 | bool "Enable mylibc" 5 | default "y" 6 | help 7 | For mylibc. 8 | 9 | endmenu 10 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/c_ctype.c: -------------------------------------------------------------------------------- 1 | #include "c_ctype.h" 2 | #include "c_types.h" 3 | 4 | // int isalnum(int c){} 5 | // int isalpha(int c){} 6 | // int iscntrl(int c){} 7 | // int isdigit(int c){} 8 | // // int isgraph(int c){} 9 | // int islower(int c){} 10 | // int isprint(int c){} 11 | // int ispunct(int c){} 12 | // int isspace(int c){} 13 | // int isupper(int c){} 14 | // int isxdigit(int c){} 15 | // int tolower(int c){} 16 | // int toupper(int c){} 17 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/c_string.c: -------------------------------------------------------------------------------- 1 | #include "c_string.h" 2 | 3 | // const char *c_strstr(const char * __s1, const char * __s2){ 4 | // } 5 | 6 | // char *c_strncat(char * s1, const char * s2, size_t n){ 7 | // } 8 | 9 | // size_t c_strcspn(const char * s1, const char * s2){ 10 | // } 11 | 12 | // const char *c_strpbrk(const char * s1, const char * s2){ 13 | // } 14 | 15 | // int c_strcoll(const char * s1, const char * s2){ 16 | // } 17 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/include/c_ctype.h: -------------------------------------------------------------------------------- 1 | #ifndef _C_CTYPE_H_ 2 | #define _C_CTYPE_H_ 3 | 4 | #if 0 5 | int isalnum(int); 6 | int isalpha(int); 7 | int iscntrl(int); 8 | int isdigit(int); 9 | // int isgraph(int); 10 | int islower(int); 11 | int isprint(int); 12 | int ispunct(int); 13 | int isspace(int); 14 | int isupper(int); 15 | int isxdigit(int); 16 | int tolower(int); 17 | int toupper(int); 18 | 19 | #if !defined(__STRICT_ANSI__) || defined(__cplusplus) || __STDC_VERSION__ >= 199901L 20 | // int isblank(int); 21 | #endif 22 | 23 | #ifndef __STRICT_ANSI__ 24 | // int isascii(int); 25 | // int toascii(int); 26 | #define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a') 27 | #define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A') 28 | #endif 29 | 30 | #define _U 01 31 | #define _L 02 32 | #define _N 04 33 | #define _S 010 34 | #define _P 020 35 | #define _C 040 36 | #define _X 0100 37 | #define _B 0200 38 | 39 | /* For C++ backward-compatibility only. */ 40 | // extern char _ctype_[]; 41 | #endif 42 | #endif /* _C_CTYPE_H_ */ 43 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/include/c_errno.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_errno_h 2 | #define __c_errno_h 3 | 4 | #include 5 | // #ifndef errno 6 | // extern int errno; 7 | // #endif 8 | 9 | // #define EDOM 1 10 | // #define ERANGE 2 11 | // #define EILSEQ 4 12 | // #define ESIGNUM 3 13 | // #define EINVAL 5 14 | // #define ENOMEM 6 15 | 16 | #endif 17 | 18 | /* end of c_errno.h */ 19 | 20 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/include/c_fcntl.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_fcntl_h 2 | #define __c_fcntl_h 3 | 4 | #include 5 | 6 | #endif 7 | 8 | /* end of c_fcntl.h */ 9 | 10 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/include/c_locale.h: -------------------------------------------------------------------------------- 1 | /* 2 | c_locale.h 3 | Values appropriate for the formatting of monetary and other 4 | numberic quantities. 5 | */ 6 | 7 | #ifndef _C_LOCALE_H_ 8 | #define _C_LOCALE_H_ 9 | 10 | #include 11 | 12 | #if 0 13 | #ifndef NULL 14 | #define NULL 0 15 | #endif 16 | 17 | #define LC_ALL 0 18 | #define LC_COLLATE 1 19 | #define LC_CTYPE 2 20 | #define LC_MONETARY 3 21 | #define LC_NUMERIC 4 22 | #define LC_TIME 5 23 | #define LC_MESSAGES 6 24 | 25 | struct lconv 26 | { 27 | char *decimal_point; 28 | char *thousands_sep; 29 | char *grouping; 30 | char *int_curr_symbol; 31 | char *currency_symbol; 32 | char *mon_decimal_point; 33 | char *mon_thousands_sep; 34 | char *mon_grouping; 35 | char *positive_sign; 36 | char *negative_sign; 37 | char int_frac_digits; 38 | char frac_digits; 39 | char p_cs_precedes; 40 | char p_sep_by_space; 41 | char n_cs_precedes; 42 | char n_sep_by_space; 43 | char p_sign_posn; 44 | char n_sign_posn; 45 | char int_n_cs_precedes; 46 | char int_n_sep_by_space; 47 | char int_n_sign_posn; 48 | char int_p_cs_precedes; 49 | char int_p_sep_by_space; 50 | char int_p_sign_posn; 51 | }; 52 | 53 | #ifndef _REENT_ONLY 54 | // char *setlocale(int category, const char *locale); 55 | struct lconv *localeconv(void); 56 | #endif 57 | 58 | // struct _reent; 59 | // char *_setlocale_r(struct _reent *, int category, const char *locale); 60 | // struct lconv *_localeconv_r(struct _reent *); 61 | #endif 62 | #endif /* _C_LOCALE_H_ */ 63 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/include/c_math.h: -------------------------------------------------------------------------------- 1 | #ifndef _C_MATH_H_ 2 | #define _C_MATH_H_ 3 | #include 4 | 5 | double floor(double); 6 | double pow(double, double); 7 | 8 | #if 0 9 | #ifndef HUGE_VAL 10 | #define HUGE_VAL (1.0e99) 11 | #endif 12 | 13 | #ifndef HUGE_VALF 14 | #define HUGE_VALF (1.0e999999999F) 15 | #endif 16 | 17 | #if !defined(HUGE_VALL) && defined(_HAVE_LONG_DOUBLE) 18 | #define HUGE_VALL (1.0e999999999L) 19 | #endif 20 | 21 | #if !defined(INFINITY) 22 | #define INFINITY (HUGE_VALF) 23 | #endif 24 | 25 | 26 | /* Reentrant ANSI C functions. */ 27 | 28 | #ifndef __math_68881 29 | // double atan(double); 30 | // double cos(double); 31 | // double sin(double); 32 | // double tan(double); 33 | // double tanh(double); 34 | // double frexp(double, int *); 35 | // double modf(double, double *); 36 | // double ceil(double); 37 | // double fabs(double); 38 | // double floor(double); 39 | #endif /* ! defined (__math_68881) */ 40 | 41 | /* Non reentrant ANSI C functions. */ 42 | 43 | #ifndef _REENT_ONLY 44 | #ifndef __math_68881 45 | // double acos(double); 46 | // double asin(double); 47 | // double atan2(double, double); 48 | // double cosh(double); 49 | // double sinh(double); 50 | // double exp(double); 51 | // double ldexp(double, int); 52 | // double log(double); 53 | // double log10(double); 54 | // double pow(double, double); 55 | // double sqrt(double); 56 | // double fmod(double, double); 57 | #endif /* ! defined (__math_68881) */ 58 | #endif /* ! defined (_REENT_ONLY) */ 59 | 60 | #endif 61 | 62 | #endif /* _MATH_H_ */ 63 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/include/c_stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_stdarg_h 2 | #define __c_stdarg_h 3 | 4 | #if defined(__GNUC__) 5 | 6 | #include 7 | 8 | #else 9 | 10 | typedef char * va_list; 11 | 12 | #define _INTSIZEOF(n) ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1)) 13 | 14 | #define va_start(ap,v) (ap = (va_list)&v + _INTSIZEOF(v)) 15 | #define va_arg(ap,t) (*(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t))) 16 | #define va_end(ap) (ap = (va_list)0) 17 | 18 | #endif 19 | 20 | #endif 21 | 22 | /* end of c_stdarg.h */ 23 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/include/c_stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef __c_stddef_h 2 | #define __c_stddef_h 3 | 4 | typedef signed int ptrdiff_t; 5 | 6 | #if !defined(offsetof) 7 | #define offsetof(s, m) (size_t)&(((s *)0)->m) 8 | #endif 9 | 10 | #if !defined(__size_t) 11 | #define __size_t 1 12 | typedef unsigned int size_t; /* others (e.g. ) also define */ 13 | /* the unsigned integral type of the result of the sizeof operator. */ 14 | #endif 15 | 16 | #undef NULL /* others (e.g. ) also define */ 17 | #define NULL 0 18 | /* null pointer constant. */ 19 | 20 | #endif 21 | 22 | /* end of c_stddef.h */ 23 | 24 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/include/c_stdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * c_stdlib.h 3 | * 4 | * Definitions for common types, variables, and functions. 5 | */ 6 | 7 | #ifndef _C_STDLIB_H_ 8 | #define _C_STDLIB_H_ 9 | 10 | #include "c_stddef.h" 11 | //#include "mem.h" 12 | 13 | #include 14 | 15 | #define EXIT_FAILURE 1 16 | #define EXIT_SUCCESS 0 17 | 18 | //#define __INT_MAX__ 2147483647 19 | #undef __RAND_MAX 20 | #if __INT_MAX__ == 32767 21 | #define __RAND_MAX 32767 22 | #else 23 | #define __RAND_MAX 0x7fffffff 24 | #endif 25 | #define RAND_MAX __RAND_MAX 26 | 27 | #ifndef mem_realloc 28 | #define mem_realloc pvPortRealloc 29 | #endif 30 | #ifndef os_realloc 31 | #define os_realloc(p, s) mem_realloc((p), (s)) 32 | #endif 33 | 34 | #define c_free free 35 | #define c_malloc os_malloc 36 | #define c_zalloc os_zalloc 37 | #define c_realloc realloc 38 | 39 | #define c_abs abs 40 | #define c_atoi atoi 41 | //#define c_strtod strtod 42 | #define c_strtol strtol 43 | #define c_strtoul strtoul 44 | 45 | // int c_abs(int); 46 | 47 | // void c_exit(int); 48 | 49 | #define ICACHE_STORE_ATTR __attribute__((aligned(4))) 50 | 51 | // c_getenv() get env "LUA_INIT" string for lua initialization. 52 | const char *c_getenv(const char *__string); 53 | 54 | // void *c_malloc(size_t __size); 55 | // void *c_zalloc(size_t __size); 56 | // void c_free(void *); 57 | 58 | // int c_rand(void); 59 | // void c_srand(unsigned int __seed); 60 | 61 | // int c_atoi(const char *__nptr); 62 | double c_strtod(const char *__n, char **__end_PTR); 63 | // // long c_strtol(const char *__n, char **__end_PTR, int __base); 64 | // unsigned long c_strtoul(const char *__n, char **__end_PTR, int __base); 65 | // // long long c_strtoll(const char *__n, char **__end_PTR, int __base); 66 | 67 | #endif /* _C_STDLIB_H_ */ 68 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/mylibc/include/c_string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * c_string.h 3 | * 4 | * Definitions for memory and string functions. 5 | */ 6 | 7 | #ifndef _C_STRING_H_ 8 | #define _C_STRING_H_ 9 | #include "c_stddef.h" 10 | //#include "osapi.h" 11 | //#include "esp_libc.h" 12 | #include 13 | 14 | #ifndef NULL 15 | #define NULL 0 16 | #endif 17 | 18 | #define c_memcmp memcmp 19 | #define c_memcpy memcpy 20 | #define c_memset memset 21 | 22 | #define os_memcpy ets_memcpy 23 | #define os_memcmp ets_memcmp 24 | #define os_memmove ets_memmove 25 | 26 | #define c_strcat strcat 27 | #define c_strchr strchr 28 | #define c_strcmp strcmp 29 | #define c_strcpy strcpy 30 | #define c_strlen strlen 31 | #define c_strncmp strncmp 32 | #define c_strncpy strncpy 33 | // #define c_strstr os_strstr 34 | #define c_strncasecmp strncmp 35 | 36 | #define c_strstr strstr 37 | #define c_strncat strncat 38 | #define c_strcspn strcspn 39 | #define c_strpbrk strpbrk 40 | #define c_strcoll strcoll 41 | #define c_strrchr strrchr 42 | 43 | //extern unsigned int strlen(char *s); 44 | //extern char *strcat(char *dest, char *src); 45 | //extern char *strchr(const char *s, int c); 46 | //extern char *strcpy(char* des, const char* source); 47 | //extern char *strncpy(char *dest, const char *src, size_t n); 48 | //extern void *memcpy(void *dest, const void *src, size_t n); 49 | extern void *memchr(const void *buf, int ch, size_t count); 50 | extern char *strpbrk(const char *s1, const char *s2); 51 | 52 | // const char *c_strstr(const char * __s1, const char * __s2); 53 | // char *c_strncat(char * __restrict /*s1*/, const char * __restrict /*s2*/, size_t n); 54 | // size_t c_strcspn(const char * s1, const char * s2); 55 | // const char *c_strpbrk(const char * /*s1*/, const char * /*s2*/); 56 | // int c_strcoll(const char * /*s1*/, const char * /*s2*/); 57 | 58 | #endif /* _C_STRING_H_ */ 59 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "utils.c" "platform.c" 2 | REQUIRES driver 3 | INCLUDE_DIRS "include") 4 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/utils/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/utils/include/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef _PLATFORM_H_ 2 | #define _PLATFORM_H_ 3 | 4 | #define NODE_PLATFORM_ESP32 1001 5 | #define NODE_PLATFORM_ESP8266 1002 6 | #define NODE_PLATFORM_STM32 1003 7 | #define NODE_PLATFORM_W800 1004 8 | 9 | 10 | #define CURRENT_PLATFORM NODE_PLATFORM_ESP8266 11 | #define BUILD_SPIFFS 12 | 13 | 14 | #if (CURRENT_PLATFORM == NODE_PLATFORM_ESP32) 15 | #define OUTPUT GPIO_MODE_OUTPUT 16 | #define INPUT GPIO_MODE_INPUT 17 | #define PULLUP GPIO_PULLUP_ONLY 18 | #define FLOAT GPIO_FLOATING 19 | #define INOUT GPIO_MODE_INPUT_OUTPUT 20 | #define PLATFORM_INTERRUPT GPIO_INTR_POSEDGE 21 | #define HIGH 1 22 | #define LOW 0 23 | #define GPIO_PIN_NUM GPIO_NUM_MAX 24 | #elif (CURRENT_PLATFORM == NODE_PLATFORM_ESP8266) 25 | #define OUTPUT GPIO_MODE_OUTPUT 26 | #define INPUT GPIO_MODE_INPUT 27 | #define PULLUP GPIO_PULLUP_ONLY 28 | #define FLOAT GPIO_FLOATING 29 | //#define INOUT GPIO_MODE_INPUT_OUTPUT 30 | #define PLATFORM_INTERRUPT GPIO_INTR_POSEDGE 31 | #define HIGH 1 32 | #define LOW 0 33 | #define GPIO_PIN_NUM GPIO_NUM_MAX 34 | #else 35 | #define PULLUP PLATFORM_GPIO_PULLUP 36 | #define FLOAT PLATFORM_GPIO_FLOAT 37 | #define OUTPUT PLATFORM_GPIO_OUTPUT 38 | #define INPUT PLATFORM_GPIO_INPUT 39 | #define INOUT PLATFORM_GPIO_INOUT 40 | #define PLATFORM_INTERRUPT PLATFORM_GPIO_INT 41 | #define HIGH PLATFORM_GPIO_HIGH 42 | #define LOW PLATFORM_GPIO_LOW 43 | #endif 44 | 45 | void lua_node_restart(void); 46 | void lua_node_sleep(uint64_t us); 47 | uint32_t lua_node_get_heap_size(void); 48 | void lua_node_system_restore(void); 49 | 50 | int platform_gpio_mode(int pin, int mode, int type); 51 | void platform_gpio_isr_uninstall(void); 52 | int platform_gpio_read(int pin); 53 | void platform_gpio_write(int pin, int level); 54 | 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/utils/include/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_H_ 2 | #define _UTILS_H_ 3 | 4 | typedef enum { 5 | EMPTY, 6 | UNDER_WRITE, 7 | WRITE_OVER 8 | } RcvMsgBuffState; 9 | 10 | 11 | typedef struct { 12 | uint32_t RcvBuffSize; 13 | uint8_t *pRcvMsgBuff; 14 | uint8_t *pWritePos; 15 | uint8_t *pReadPos; 16 | uint8_t TrigLvl; //JLU: may need to pad 17 | RcvMsgBuffState BuffState; 18 | } RcvMsgBuff; 19 | 20 | void print_info(void); 21 | //char *basename(char *path); 22 | char * get_partition_label(void); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/components/utils/utils.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "utils.h" 4 | 5 | void print_info(void) 6 | { 7 | printf(" _ _ _ _ \n\ 8 | | | | \\ | | | | \n\ 9 | | | _ _ __ _ | \\| | ___ __| | ___ \n\ 10 | | | | | | | / _` || . ` | / _ \\ / _` | / _ \\\n\ 11 | | |____| |_| || (_| || |\\ || (_) || (_| || __/\n\ 12 | \\_____/ \\__,_| \\__,_|\\_| \\_/ \\___/ \\__,_| \\___|\n\ 13 | \n\ 14 | For ESP8266 \n\ 15 | Version 2.0.0\n\ 16 | \n\ 17 | ------------------------------------------------\n\ 18 | \n"); 19 | } 20 | 21 | /*char *basename(char *path) 22 | { 23 | int num = strlen(path); 24 | for (int i = num-1; i >= 0; i++) { 25 | if (path[i] == '/') { 26 | return path+i+1; 27 | } 28 | } 29 | return path; 30 | }*/ 31 | 32 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "main.c" "uart_handler.c" 2 | INCLUDE_DIRS "include") 3 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/main/include/lua_def.h: -------------------------------------------------------------------------------- 1 | #ifndef _LUA_DEF_H_ 2 | #define _LUA_DEF_H_ 3 | 4 | 5 | /* 6 | @@ LUA_MAXINPUT is the maximum length for an input line in the 7 | @* stand-alone interpreter. 8 | ** CHANGE it if you need longer lines. 9 | */ 10 | #define LUA_MAXINPUT 256 11 | 12 | /* 13 | @@ LUA_PROMPT is the default prompt used by stand-alone Lua. 14 | @@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua. 15 | ** CHANGE them if you want different prompts. (You can also change the 16 | ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) 17 | */ 18 | #define LUA_PROMPT "> " 19 | #define LUA_PROMPT2 ">> " 20 | 21 | // EGC operations modes 22 | #define EGC_NOT_ACTIVE 0 // EGC disabled 23 | #define EGC_ON_ALLOC_FAILURE 1 // run EGC on allocation failure 24 | #define EGC_ON_MEM_LIMIT 2 // run EGC when an upper memory limit is hit 25 | #define EGC_ALWAYS 4 // always run EGC before an allocation 26 | 27 | /* 28 | ** pseudo-indices 29 | */ 30 | #define LUA_REGISTRYINDEX (-10000) 31 | #define LUA_ENVIRONINDEX (-10001) 32 | #define LUA_GLOBALSINDEX (-10002) 33 | 34 | 35 | #define GCSpause 0 36 | 37 | #define GCSTEPSIZE 1024u 38 | 39 | typedef LUAI_UMEM lu_mem; 40 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) 41 | 42 | #define G(L) (L->l_G) 43 | 44 | 45 | typedef struct __lua_load{ 46 | lua_State *L; 47 | int firstline; 48 | char *line; 49 | int line_position; 50 | size_t len; 51 | int done; 52 | const char *prmt; 53 | }lua_Load; 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/main/include/uart_handler.h: -------------------------------------------------------------------------------- 1 | #ifndef _UART_HANDLER_H_ 2 | #define _UART_HANDLER_H_ 3 | 4 | 5 | void my_uart_init(void); 6 | bool uart_getc(char *c); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /LuaNode_Esp8266/partitions_luanode.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap 3 | nvs, data, nvs, 0x9000, 0x6000, 4 | phy_init, data, phy, 0xf000, 0x1000, 5 | factory, app, factory, 0x10000, 1M, 6 | storage, data, spiffs, , 0xF0000, 7 | -------------------------------------------------------------------------------- /LuaNode_Stm32L4/README.md: -------------------------------------------------------------------------------- 1 | # LuaNode for STM32L4 serial chip 2 | --------------------------------------- 3 | 4 | This part is ongoing, coming soon! 5 | -------------------------------------------------------------------------------- /images/ESP32_dimension.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/ESP32_dimension.png -------------------------------------------------------------------------------- /images/alexa_esp32.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/alexa_esp32.jpg -------------------------------------------------------------------------------- /images/alexa_esp32_dev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/alexa_esp32_dev.png -------------------------------------------------------------------------------- /images/ble_debug_tool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/ble_debug_tool.png -------------------------------------------------------------------------------- /images/camera_test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/camera_test.jpg -------------------------------------------------------------------------------- /images/esp32_LCD.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/esp32_LCD.jpg -------------------------------------------------------------------------------- /images/esp32_cam.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/esp32_cam.jpg -------------------------------------------------------------------------------- /images/esp32_cam2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/esp32_cam2.jpg -------------------------------------------------------------------------------- /images/esp32_fig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/esp32_fig.png -------------------------------------------------------------------------------- /images/esp_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/esp_1.png -------------------------------------------------------------------------------- /images/esp_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/esp_2.png -------------------------------------------------------------------------------- /images/esp_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/esp_3.png -------------------------------------------------------------------------------- /images/esp_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/esp_4.png -------------------------------------------------------------------------------- /images/esp_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/esp_5.png -------------------------------------------------------------------------------- /images/esp_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/esp_6.png -------------------------------------------------------------------------------- /images/esp_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/esp_7.png -------------------------------------------------------------------------------- /images/esplorer_run.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/esplorer_run.png -------------------------------------------------------------------------------- /images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/logo.jpg -------------------------------------------------------------------------------- /images/luanode_host.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/luanode_host.jpg -------------------------------------------------------------------------------- /images/nrf51822_esp32_communication.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/nrf51822_esp32_communication.jpg -------------------------------------------------------------------------------- /images/ota_tcp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/ota_tcp.jpg -------------------------------------------------------------------------------- /images/partitions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/partitions.png -------------------------------------------------------------------------------- /images/run_lua_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/run_lua_code.png -------------------------------------------------------------------------------- /images/startup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/startup.png -------------------------------------------------------------------------------- /images/w800.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nicholas3388/LuaNode/db50f474f6016d183bf22992f9ee91346937ec97/images/w800.png -------------------------------------------------------------------------------- /lua_samples/base/base.lua: -------------------------------------------------------------------------------- 1 | -- test lua base module 2 | -- such as sting, table 3 | 4 | print("Hello world") 5 | 6 | str="test"; 7 | print(string.len(str)); -- lua string module 8 | print(string.sub(str, 1, 2)); 9 | 10 | t={11,22,33,44,55}; 11 | for k,v in pairs(t) do print(k,v); end 12 | table.remove(t, 3); -- use table module to remove the third element from table t 13 | for k,v in pairs(t) do print(k,v); end 14 | table.insert(t, 2, 99); -- insert 99 to t at index 2 15 | 16 | 17 | foo = function() 18 | print("This is a function"); 19 | end 20 | foo(); -- function test 21 | -------------------------------------------------------------------------------- /lua_samples/file/file.lua: -------------------------------------------------------------------------------- 1 | -- FS information, format operation 2 | 3 | size = file.fsinfo(); 4 | print(size); -- print total size of the FS 5 | 6 | -- print FS detail 7 | detail = file.list(); 8 | for k,v in pairs(detail) do 9 | print(k, v); 10 | end 11 | 12 | 13 | -- format FS, remove all content in FS 14 | file.format(); 15 | detail = file.list(); 16 | for k,v in pairs(detail) do 17 | print(k, v); -- nothing to print 18 | end 19 | -------------------------------------------------------------------------------- /lua_samples/file/file_read.lua: -------------------------------------------------------------------------------- 1 | -- Read an existing file 2 | 3 | res = file.open("test.lua", "r"); 4 | 5 | while true do 6 | if(res == false) then 7 | print("Open file failed"); 8 | break; 9 | end 10 | 11 | -- read 64 character from the file 12 | content = file.read(64); 13 | print(content); 14 | file.close(); 15 | 16 | break; 17 | end 18 | -------------------------------------------------------------------------------- /lua_samples/file/file_remove.lua: -------------------------------------------------------------------------------- 1 | -- Remove file 2 | 3 | res = file.open("test.lua", "w"); 4 | 5 | while true do 6 | if(res == false) then 7 | print("Open file failed"); 8 | break; 9 | end 10 | 11 | file.close(); 12 | file.remove("test.lua"); -- remove file 13 | 14 | break; 15 | end 16 | -------------------------------------------------------------------------------- /lua_samples/file/file_write.lua: -------------------------------------------------------------------------------- 1 | -- file create and write 2 | -- To read a file, you should open it first 3 | 4 | res = file.open("myfile.lua","w") -- Open file myfile.lua. If it doesn't exist, create it, otherwise, overwrite the file 5 | while true do 6 | if(res == false) then 7 | print("open file failed"); 8 | break; 9 | end 10 | 11 | file.write("hello"); 12 | file.close(); 13 | 14 | break; 15 | end 16 | 17 | --[[ 18 | file.open("myfile.lua","w+") -- Open and append content to myfile.lua 19 | file.write("hello"); 20 | file.close(); 21 | ]] 22 | -------------------------------------------------------------------------------- /lua_samples/gpio/gpio_in.lua: -------------------------------------------------------------------------------- 1 | -- Read gpio pin 2 | 3 | gpio.mode(3, gpio.INPUT); 4 | level = gpio.read(3); -- read gpio level 5 | print(level); 6 | -------------------------------------------------------------------------------- /lua_samples/gpio/gpio_intr.lua: -------------------------------------------------------------------------------- 1 | -- connect GPIO5 to GPIO4 2 | -- GPIO4 will be triggered when GPIO5 output different level 3 | 4 | -- gpio.mode(pin, pin_type, intr_type, callback) 5 | -- pin: pin to set 6 | -- pin_type: the value can be: gpio.INPUT/gpio.OUTPUT/gpio.INT/gpio.INOUT 7 | -- intr_type: how to trigger, the value is string, can be: "up"/"down"/"both"/"low"/"high" 8 | -- callback: callback function 9 | 10 | -- to remove a callback call: gpio.remove(pin) 11 | -- to remove all GPIO ISR call: gpio.uninstall() 12 | 13 | pin_intr = 4; 14 | pin_out = 5; 15 | callback = function() 16 | print("run callback"); 17 | end 18 | gpio.mode(pin_intr, gpio.INT, "both", callback); 19 | gpio.mode(pin_out, gpio.OUTPUT); 20 | tmr.delay(2); 21 | gpio.write(pin_out, 1); 22 | tmr.delay(1); 23 | gpio.write(pin_out, 0); 24 | -------------------------------------------------------------------------------- /lua_samples/gpio/gpio_out.lua: -------------------------------------------------------------------------------- 1 | -- GPIO sample 2 | -- The pin gpio2 connect to a led. when the pin output high level, the led will be light up 3 | -- gpio.mode(pin, mode) 4 | -- mode = 1(INPUT), 2(OUTPUT),4(PULLUP),5(INPUT_PULLUP),8(PULLDOWN),9(INPUT_PULLDOWN)...... 5 | -- gpio.write(pin, level) 6 | -- level = gpio.read(pin) 7 | 8 | gpio.mode(2,gpio.OUTPUT); 9 | gpio.write(2,1); -- led on 10 | gpio.write(2,0); -- led off 11 | 12 | -------------------------------------------------------------------------------- /lua_samples/gpio/led_blink.lua: -------------------------------------------------------------------------------- 1 | -- LED blink 2 | -- The pin 2 connect to a LED. When the pin output high level, the LED will be light up, 3 | -- otherwise, the LED will be turned off 4 | 5 | isOff = false 6 | 7 | led_blink = function() 8 | if(isOff) then 9 | gpio.write(2, 1); -- turn on 10 | isOff = false 11 | else 12 | gpio.write(2, 0); -- turn off 13 | isOff = true 14 | end 15 | end 16 | 17 | --gpio.mode(2,gpio.OUTPUT); 18 | 19 | period = 1000; 20 | tmr.register(1, period, tmr.ALARM_AUTO, led_blink); 21 | tmr.start(1); 22 | -------------------------------------------------------------------------------- /lua_samples/i2c/i2c.lua: -------------------------------------------------------------------------------- 1 | -- Since there are two i2c on esp32, I setup one i2c as master and the other one as slave, and read/write them on the esp32 2 | -- slave : 3 | -- GPIO25 is assigned as the data signal of i2c slave port 4 | -- GPIO26 is assigned as the clock signal of i2c slave port 5 | -- master: 6 | -- GPIO18 is assigned as the data signal of i2c master port 7 | -- GPIO19 is assigned as the clock signal of i2c master port 8 | -- connect GPIO18 with GPIO25 9 | -- connect GPIO19 with GPIO26 10 | i2c.setup(i2c.SLAVE,i2c.I2C_0,26,25,40) 11 | i2c.setup(i2c.MASTER,i2c.I2C_1,19,18) 12 | -- slave write something, master read 13 | i2c.write(i2c.SLAVE,i2c.I2C_0,40,"helloworld") 14 | c=i2c.read(i2c.MASTER,i2c.I2C_1,40,10) 15 | print(c) 16 | 17 | tmr.delay(5) 18 | -- master write something, slave read 19 | i2c.write(i2c.MASTER,i2c.I2C_1,40,"test") 20 | c=i2c.read(i2c.SLAVE,i2c.I2C_0,40,4) 21 | print(c) 22 | 23 | -- i2c uninstall 24 | i2c.uninstall(i2c.I2C_0) 25 | i2c.uninstall(i2c.I2C_1) 26 | -------------------------------------------------------------------------------- /lua_samples/i2c/i2c_test.lua: -------------------------------------------------------------------------------- 1 | -- ESP32 Lua I2c bus scanner 2 | -- vslinuxdotnet@github - 11/02/2017 3 | 4 | sda=18 5 | scl=19 6 | 7 | function find_dev(dev_addr) 8 | c=i2c.read(i2c.MASTER, i2c.I2C_1, dev_addr, 4) 9 | if c == "" then 10 | return false 11 | else 12 | return true 13 | end 14 | end 15 | 16 | i2c.setup(i2c.MASTER, i2c.I2C_1, scl, sda) 17 | print("Scanning I2C Bus...") 18 | for i=0,127 do 19 | if find_dev(i)==true then 20 | print("Device found at address 0x"..string.format("%02X",i).."!") 21 | end 22 | end 23 | print("Done!") -------------------------------------------------------------------------------- /lua_samples/lpeg/lpeg.lua: -------------------------------------------------------------------------------- 1 | -- Lpeg test 2 | -- match string 3 | -- For more details of lpeg, visit the lpeg homepage show bellow: 4 | -- http://www.inf.pub-rio.br/~roberto/lpeg/ 5 | 6 | match = lpeg.match; 7 | P = lpeg.P; 8 | 9 | res = match(P'a', 'aaa'); -- return the index behind first match 'a' 10 | print(res); 11 | 12 | res = match(P'a', '123'); 13 | print(res); -- output nil, since match nothing 14 | -------------------------------------------------------------------------------- /lua_samples/mqtt/mqtt.lua: -------------------------------------------------------------------------------- 1 | -- mqtt.new(host, client_id, keepalive, connected_callback, [username], [password], [encrypt]) 2 | -- host: the mqtt host IP 3 | -- client_id: client id 4 | -- keepalive: keep alive seconds 5 | -- connected_callback: a callback when connection established 6 | -- username: optional argument, mqtt user name 7 | -- password: 8 | -- encrypt: not support encrypt now 9 | 10 | -- mqtt.on(handle, event, callback): the method is used to register callback to monitor the following event: 'data'/'publish'/'subscribe'/'disconnect' 11 | 12 | -- mqtt.unsubscribe(handle, topic): unsubscribe a topic 13 | 14 | -- mqtt.close(handle): use this method to close an mqtt connection 15 | 16 | -- Note: 17 | -- 1. the mqtt.new retern a handle, which is used for subscribe/publish, remember to save the handle. 18 | -- 2. you can create 3 mqtt connections at most. You will fail to create more than 3 mqtt connections. 19 | 20 | ccb=function() print("mqtt connected\n"); end 21 | dcb=function(t,d) print(t);print(d); end 22 | wifi.setmode(1); 23 | wifi.start(); 24 | wifi.sta.config({ssid="Doit",pwd="doit3305"}); 25 | tmr.delay(15); 26 | handle=mqtt.new('test.mosquitto.org','c1',600,ccb); -- if you don't need connect callback, write like this: mqtt.new('test.mosquitto.org','c1',600,nil) 27 | tmr.delay(8); 28 | mqtt.subscribe(handle,'/chann1',mqtt.QOS0); 29 | tmr.delay(3); 30 | mqtt.on(handle,'data',dcb); 31 | mqtt.publish(handle,'/chann1','test'); -------------------------------------------------------------------------------- /lua_samples/net/net_tcp_client.lua: -------------------------------------------------------------------------------- 1 | -- Wifi station test 2 | -- Suppose you have a TCP server, whose IP is 192.168.99.218, 3 | -- and it listens the PORT 8181, then you can run the following 4 | -- source to create a client to connect to the server. 5 | 6 | PORT = 8181 7 | ADDR = "192.168.99.218" 8 | 9 | recv_cb = function(sock, c) 10 | print(c); 11 | end 12 | 13 | wifi.setmode(wifi.STATION); 14 | wifi.start(); 15 | wifi.sta.config({ssid="newifi_doit3305", pwd="doit3305"}); 16 | tmr.delay(10); 17 | info = wifi.sta.getconfig(); 18 | count = 0; 19 | timeout = false; 20 | while(string.len(info.ssid) == 0) do -- wait for connection established 21 | tmr.delay(1); 22 | info = wifi.sta.getconfig(); 23 | count = count + 1; 24 | if(count == 3) then 25 | print("Connect timeout"); 26 | timeout = true; 27 | break; 28 | end 29 | end 30 | 31 | if(timeout ~= true) then 32 | conn = net.createConnection(net.TCP, 0); 33 | conn:on("receive", recv_cb); 34 | conn:connect(PORT, ADDR); 35 | print("Connect to server"); 36 | end -------------------------------------------------------------------------------- /lua_samples/net/net_tcp_server.lua: -------------------------------------------------------------------------------- 1 | -- Create a TCP server 2 | 3 | PORT = 8181; 4 | ADDR = "192.168.4.1"; 5 | 6 | wifi.setmode(wifi.SOFTAP); 7 | wifi.start(); 8 | 9 | tmr.delay(2); 10 | srv = net.createServer(net.TCP, 30); 11 | srv:listen(PORT, ADDR, function(sock) 12 | sock:on("receive", function(sock, c) 13 | print(c); 14 | end) 15 | end) 16 | -------------------------------------------------------------------------------- /lua_samples/node/node.lua: -------------------------------------------------------------------------------- 1 | -- methods same as nodemcu 2 | 3 | node.heap(); -- print heap 4 | 5 | node.restart(); -- restart chip 6 | -------------------------------------------------------------------------------- /lua_samples/nvs/nvs.lua: -------------------------------------------------------------------------------- 1 | -- NVS: Non-volatile storage, the data store in NVS will not be cleaned when power off 2 | -- This is a Lua module. User can use it to access NVS from Lua. 3 | -- The following methods are provided by this module: 4 | -- nvs.open() 5 | -- nvs.close() 6 | -- nvs.put(key, value) 7 | -- nvs.get(key) 8 | -- nvs.exist(key) 9 | -- nvs.remove(key) 10 | -- nvs.clearall() 11 | 12 | nvs.open(); 13 | nvs.put("k","hello"); 14 | v=nvs.get("k"); 15 | print(v); -- this will print out "hello" 16 | print(nvs.exist("k")); -- will output "1", if key exists nvs.exist return 1, otherwise, return 0 17 | nvs.remove("k"); -- if remove successfully, nvs.remove return 0, otherwise, return 1 18 | print(nvs.exist("k")); -- will output "0" 19 | nvs.close(); 20 | 21 | -------------------------------------------------------------------------------- /lua_samples/pwm/pwm.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------------- 2 | -- The following methods are provided by PWM module: 3 | -- 4 | -- 1. pwm.setup(pin, freqency, duty, channel) 5 | -- pin: pin to set 6 | -- frequency: frequency to set 7 | -- duty: duty to set. range from 0 to 8192 8 | -- channel: used channel, valid channel range from 0 to 7 9 | -- 2. pwm.stop(channel) 10 | -- 3. pwm.getduty(channel) 11 | -- 4. pwm.setduty(channel, duty) 12 | -- 5. pwm.getfreq() 13 | -- 6. pwm.setfreq(frequency) 14 | -- 15 | -- Note: once pwm.setup is called, your device start to generate PWM. 16 | ----------------------------------------------------------------------------------- 17 | 18 | -- The following example is to make the blue LED on DOIT ESP32 dev-board blink per seconds. 19 | -- There is a blue LED connect to GPIO2 on DOIT ESP32 dev-board. 20 | 21 | pwm.setup(2, 1, 4096, 0); -- blink per seconds 22 | duty=pwm.getduty(0); 23 | print(duty); 24 | freq = pwm.getfreq(); 25 | print(freq); 26 | tmr.delay(10); 27 | pwm.setfreq(2); -- blink twice per seconds 28 | tmr.delay(10); 29 | pwm.stop(0); -------------------------------------------------------------------------------- /lua_samples/thread/thread.lua: -------------------------------------------------------------------------------- 1 | -- Thread test 2 | -- Start a thread for LED blinking 3 | -- Print status of the thread 4 | 5 | f1=function() 6 | while true do 7 | gpio.write(2,0); 8 | tmr.delay(1); 9 | gpio.write(2,1); 10 | tmr.delay(1); 11 | end 12 | end 13 | 14 | th1=thread.start(f1); 15 | --status = thread.status(th1); -- get thread status, and then print it 16 | --print(status); -- this will output running 17 | -------------------------------------------------------------------------------- /lua_samples/thread/thread_once.lua: -------------------------------------------------------------------------------- 1 | -- Thread run only once 2 | -- The thread will exit when it run once 3 | 4 | f1 = function() 5 | print("thread start"); 6 | tmr.delay(1); -- do somthing 7 | print("thread end"); 8 | end 9 | 10 | thread.start(f1); 11 | -------------------------------------------------------------------------------- /lua_samples/timer/timer.lua: -------------------------------------------------------------------------------- 1 | -- timer 2 | -- tmr.delay(us) 3 | 4 | tmr.delay_us(1000000); -- Delay 1000000us, and then output hello 5 | print("hello"); 6 | 7 | tmr.delay_ms(1000); -- delay 1000ms 8 | print("hello"); 9 | 10 | tmr.delay(1); -- delay 1s 11 | print("hello"); 12 | 13 | tmr.now(); -- Output timestamp 14 | 15 | -------------------------------------------------------------------------------- /lua_samples/timer/timer_callback.lua: -------------------------------------------------------------------------------- 1 | -- Register call back for a timer 2 | -- Timer trigger each period, change parameter to tmr.ALARM_SINGLE to trigger once 3 | 4 | callback = function(id) 5 | print("times up!"); 6 | end 7 | 8 | -- set timer id and callback period 9 | tmrId = 1; 10 | period = 1000000; -- call callback each 1s, unit is microsecond 11 | 12 | tmr.register(tmrId, period, tmr.ALARM_SINGLE, callback); -- to setup a loop timer, used tmr.ALARM_PERIODIC as 3th parameter 13 | tmr.start(tmrId); -- start timer 14 | 15 | -- to stop the timer, run the following command 16 | -- tmr.stop(tmrId); 17 | 18 | 19 | -- to make the timer trigger only once, modify the third parameter of tmr.register as below 20 | -- tmr.register(tmrId, period, tmr.ALARM_SINGLE, callback); 21 | 22 | -------------------------------------------------------------------------------- /lua_samples/uart/uart.lua: -------------------------------------------------------------------------------- 1 | -- The uart module provide the following method 2 | -- 3 | -- 1. uart.setup(id, baud, databits, parity, stopbits, flow_ctrl, [txd], [rxd], [rts], [cts]) 4 | -- id: the uart number 5 | -- baud: the uart baud rate 6 | -- databits: can be the following constants: uart.DATA_8_BITS/uart.DATA_7_BITS/uart.DATA_6_BITS/uart.DATA_5_BITS 7 | -- parity: can be uart.PARITY_NONE/uart.PARITY_ODD/uart.PARITY_EVEN 8 | -- stopbits: can be uart.STOPBITS_1/uart.STOPBITS_1_5/uart.STOPBITS_2 9 | -- flow_ctrl: flow control enable. normally set to uart.FLOWCTRL_DISABLE 10 | -- txd: pin of txd, optional, default pin is GPIO4 11 | -- rxd: pin of rxd, optional, default pin is GPIO5 12 | -- rts: pin of rts, optional, default pin is GPIO18 13 | -- cts: pin of cts, optional, default is GPIO19 14 | -- 2. uart.write(id, string1, [string2], ..., [stringn]) 15 | -- 3. uart.uninstall(id) 16 | 17 | uart.setup(uart.UART_1, 115200, uart.DATA_8_BITS, uart.PARITY_NONE, uart.STOPBITS_1, uart.FLOWCTRL_DISABLE); 18 | while true do 19 | tmr.delay(2); 20 | uart.write(1, "hello"); 21 | end 22 | 23 | -- uart.uninstall(uart.UART_1) -------------------------------------------------------------------------------- /lua_samples/utils/utils.lua: -------------------------------------------------------------------------------- 1 | -- utils module 2 | print(utils.leapyear(2016)) -- is the input year leap year? 3 | 4 | str = "hello" 5 | encodeStr = utils.base64_encode(str) 6 | decodeStr = utils.base64_decode(encodeStr) -------------------------------------------------------------------------------- /lua_samples/wifi/wifi_ap.lua: -------------------------------------------------------------------------------- 1 | -- set wifi softap mode 2 | 3 | wifi.setmode(wifi.SOFTAP); 4 | wifi.start(); 5 | 6 | -------------------------------------------------------------------------------- /lua_samples/wifi/wifi_sta.lua: -------------------------------------------------------------------------------- 1 | -- Wifi station test 2 | -- Suppose you have a TCP server, whose IP is 192.168.99.218, 3 | -- and it listens the PORT 8181, then you can run the following 4 | -- source to create a client to connect to the server. 5 | 6 | PORT = 8181 7 | ADDR = "192.168.99.218" 8 | 9 | recv_cb = function(sock, c) 10 | print(c); 11 | end 12 | 13 | wifi.setmode(wifi.STATION); 14 | wifi.start(); 15 | wifi.sta.config({ssid="newifi_doit3305", pwd="doit3305"}); 16 | tmr.delay(10); 17 | info = wifi.sta.getconfig(); 18 | count = 0; 19 | timeout = false; 20 | while(string.len(info.ssid) == 0) do -- wait for connection established 21 | tmr.delay(1); 22 | info = wifi.sta.getconfig(); 23 | count = count + 1; 24 | if(count == 3) then 25 | print("Connect timeout"); 26 | timeout = true; 27 | break; 28 | end 29 | end 30 | 31 | if(timeout ~= true) then 32 | conn = net.createConnection(net.TCP, 0); 33 | conn:on("receive", recv_cb); 34 | conn:connect(PORT, ADDR); 35 | print("Connect to server"); 36 | end --------------------------------------------------------------------------------