├── .cproject
├── .project
├── .settings
├── org.eclipse.cdt.codan.core.prefs
└── org.eclipse.core.resources.prefs
├── Espressif.License
├── Espressif.License.old
├── LICENSE
├── Makefile
├── Nodemcu.License
├── README.md
├── app
├── .gitignore
├── Makefile
├── cjson
│ ├── CMakeLists.txt
│ ├── LICENSE
│ ├── Makefile
│ ├── THANKS
│ ├── devel
│ │ └── json_parser_outline.txt
│ ├── dtoa.c
│ ├── dtoa_config.h
│ ├── fpconv.c
│ ├── fpconv.h
│ ├── g_fmt.c
│ ├── lua
│ │ ├── cjson
│ │ │ └── util.lua
│ │ ├── json2lua.lua
│ │ └── lua2json.lua
│ ├── manual.txt
│ ├── rfc4627.txt
│ ├── strbuf.c
│ ├── strbuf.h
│ └── tests
│ │ ├── README
│ │ ├── bench.lua
│ │ ├── example1.json
│ │ ├── example2.json
│ │ ├── example3.json
│ │ ├── example4.json
│ │ ├── example5.json
│ │ ├── genutf8.pl
│ │ ├── numbers.json
│ │ ├── octets-escaped.dat
│ │ ├── rfc-example1.json
│ │ ├── rfc-example2.json
│ │ ├── test.lua
│ │ └── types.json
├── coap
│ ├── LICENSE.txt
│ ├── Makefile
│ ├── coap.c
│ ├── coap.h
│ ├── coap_client.c
│ ├── coap_client.h
│ ├── coap_io.c
│ ├── coap_io.h
│ ├── coap_server.c
│ ├── coap_server.h
│ ├── coap_timer.c
│ ├── coap_timer.h
│ ├── endpoints.c
│ ├── hash.c
│ ├── hash.h
│ ├── node.c
│ ├── node.h
│ ├── pdu.c
│ ├── pdu.h
│ ├── str.c
│ ├── str.h
│ ├── uri.c
│ └── uri.h
├── crypto
│ ├── Makefile
│ ├── digests.c
│ ├── digests.h
│ ├── sha2.c
│ └── sha2.h
├── dhtlib
│ ├── Makefile
│ ├── dht.c
│ └── dht.h
├── driver
│ ├── Makefile
│ ├── gpio16.c
│ ├── i2c_master.c
│ ├── key.c
│ ├── onewire.c
│ ├── pwm.c
│ ├── spi.c
│ └── uart.c
├── include
│ ├── arch
│ │ ├── cc.h
│ │ ├── perf.h
│ │ └── sys_arch.h
│ ├── driver
│ │ ├── gpio16.h
│ │ ├── i2c_master.h
│ │ ├── key.h
│ │ ├── onewire.h
│ │ ├── pwm.h
│ │ ├── spi.h
│ │ ├── spi_master.h
│ │ ├── spi_register.h
│ │ ├── uart.h
│ │ └── uart_register.h
│ ├── iram_buf.h
│ ├── lwip
│ │ ├── COPYING
│ │ ├── api.h
│ │ ├── api_msg.h
│ │ ├── arch.h
│ │ ├── autoip.h
│ │ ├── debug.h
│ │ ├── def.h
│ │ ├── dhcp.h
│ │ ├── dns.h
│ │ ├── err.h
│ │ ├── icmp.h
│ │ ├── igmp.h
│ │ ├── inet.h
│ │ ├── inet_chksum.h
│ │ ├── init.h
│ │ ├── ip.h
│ │ ├── ip_addr.h
│ │ ├── ip_frag.h
│ │ ├── mem.h
│ │ ├── memp.h
│ │ ├── memp_std.h
│ │ ├── netbuf.h
│ │ ├── netdb.h
│ │ ├── netif.h
│ │ ├── netifapi.h
│ │ ├── opt.h
│ │ ├── pbuf.h
│ │ ├── raw.h
│ │ ├── sio.h
│ │ ├── snmp.h
│ │ ├── snmp_asn1.h
│ │ ├── snmp_msg.h
│ │ ├── snmp_structs.h
│ │ ├── sockets.h
│ │ ├── stats.h
│ │ ├── sys.h
│ │ ├── tcp.h
│ │ ├── tcp_impl.h
│ │ ├── tcpip.h
│ │ ├── timers.h
│ │ └── udp.h
│ ├── lwipopts.h
│ ├── netif
│ │ ├── etharp.h
│ │ ├── if_llc.h
│ │ ├── ppp_oe.h
│ │ └── wlan_lwip_if.h
│ ├── pp
│ │ └── esf_buf.h
│ ├── rom.h
│ ├── rom2ram.h
│ ├── ssl
│ │ ├── app
│ │ │ ├── espconn_secure.h
│ │ │ └── espconn_ssl.h
│ │ ├── cert.h
│ │ ├── private_key.h
│ │ ├── ssl_bigint.h
│ │ ├── ssl_bigint_impl.h
│ │ ├── ssl_cert.h
│ │ ├── ssl_config.h
│ │ ├── ssl_crypto.h
│ │ ├── ssl_crypto_misc.h
│ │ ├── ssl_os_int.h
│ │ ├── ssl_os_port.h
│ │ ├── ssl_private_key.h
│ │ ├── ssl_ssl.h
│ │ ├── ssl_tls1.h
│ │ └── ssl_version.h
│ ├── u8g_config.h
│ ├── user_config.h
│ ├── user_modules.h
│ └── user_version.h
├── libc
│ ├── Makefile
│ ├── c_ctype.c
│ ├── c_ctype.h
│ ├── c_errno.h
│ ├── c_fcntl.h
│ ├── c_limits.h
│ ├── c_locale.h
│ ├── c_math.c
│ ├── c_math.h
│ ├── c_signal.h
│ ├── c_stdarg.h
│ ├── c_stddef.h
│ ├── c_stdint.h
│ ├── c_stdio.c
│ ├── c_stdio.h
│ ├── c_stdlib.c
│ ├── c_stdlib.h
│ ├── c_string.c
│ └── c_string.h
├── lua
│ ├── COPYRIGHT
│ ├── Makefile
│ ├── compiler.h
│ ├── lapi.c
│ ├── lapi.h
│ ├── lauxlib.c
│ ├── lauxlib.h
│ ├── lbaselib.c
│ ├── lcode.c
│ ├── lcode.h
│ ├── ldebug.c
│ ├── ldebug.h
│ ├── ldo.c
│ ├── ldo.h
│ ├── ldump.c
│ ├── legc.c
│ ├── legc.h
│ ├── lfunc.c
│ ├── lfunc.h
│ ├── lgc.c
│ ├── lgc.h
│ ├── liolib.c
│ ├── llex.c
│ ├── llex.h
│ ├── llimits.h
│ ├── lmathlib.c
│ ├── lmem.c
│ ├── lmem.h
│ ├── loadlib.c
│ ├── lobject.c
│ ├── lobject.h
│ ├── lopcodes.c
│ ├── lopcodes.h
│ ├── lparser.c
│ ├── lparser.h
│ ├── lrodefs.h
│ ├── lrotable.c
│ ├── lrotable.h
│ ├── lstate.c
│ ├── lstate.h
│ ├── lstring.c
│ ├── lstring.h
│ ├── lstrlib.c
│ ├── ltable.c
│ ├── ltable.h
│ ├── ltablib.c
│ ├── ltm.c
│ ├── ltm.h
│ ├── lua.c
│ ├── lua.h
│ ├── luaconf.h
│ ├── lualib.h
│ ├── lundump.c
│ ├── lundump.h
│ ├── lvm.c
│ ├── lvm.h
│ ├── lzio.c
│ ├── lzio.h
│ ├── not_ported
│ │ ├── loslib.c
│ │ ├── luac.c
│ │ └── print.c
│ └── not_used
│ │ └── ldblib.c
├── main
│ ├── .gitignore
│ ├── Include
│ │ ├── app_main.h
│ │ ├── bios.h
│ │ ├── bios
│ │ │ ├── add_funcs.h
│ │ │ ├── c_types.h
│ │ │ ├── cha1.h
│ │ │ ├── ets.h
│ │ │ ├── gpio.h
│ │ │ ├── mem.h
│ │ │ ├── rom_phy.h
│ │ │ ├── rtc_dtm.h
│ │ │ ├── spiflash.h
│ │ │ ├── uart.h
│ │ │ ├── vectors.h
│ │ │ ├── xthal.h
│ │ │ └── xtos.h
│ │ ├── eagle_lwip_if.h
│ │ ├── fatal_errs.h
│ │ ├── flash.h
│ │ ├── hw
│ │ │ ├── eagle_soc.h
│ │ │ ├── eagle_soc_.h
│ │ │ ├── esp8266.h
│ │ │ ├── gpio_register.h
│ │ │ ├── pin_mux_register.h
│ │ │ ├── specreg.h
│ │ │ ├── spi.h
│ │ │ ├── spi_register.h
│ │ │ ├── timer_register.h
│ │ │ └── uart_register.h
│ │ ├── libmain.h
│ │ ├── os_printf.h
│ │ ├── phy
│ │ │ └── phy.h
│ │ ├── sdk
│ │ │ ├── add_sdk_func.h
│ │ │ ├── ets_sys.h
│ │ │ ├── ip_addr.h
│ │ │ ├── mem_manager.h
│ │ │ ├── os_type.h
│ │ │ ├── osapi.h
│ │ │ ├── queue.h
│ │ │ └── user_interface.h
│ │ ├── sys_const.h
│ │ └── wdt.h
│ ├── Makefile
│ ├── delay.c
│ ├── ets_run.c
│ ├── ets_timer.c
│ ├── flash_api.c
│ ├── os_printf.c
│ ├── os_xtensa.c
│ ├── phy_chip_v6_unused.c
│ ├── rom2ram.c
│ ├── spi_flash.c
│ └── wpa_debug.c
├── modules
│ ├── Makefile
│ ├── adc.c
│ ├── auxmods.h
│ ├── bit.c
│ ├── cjson.c
│ ├── coap.c
│ ├── crypto.c
│ ├── dht.c
│ ├── file.c
│ ├── gpio.c
│ ├── i2c.c
│ ├── lib.c.README
│ ├── linit.c
│ ├── modules.h
│ ├── mqtt.c
│ ├── net.c
│ ├── node.c
│ ├── ow.c
│ ├── pwm.c
│ ├── rc.c
│ ├── spi.c
│ ├── tmr.c
│ ├── u8g.c
│ ├── uart.c
│ ├── wifi.c
│ ├── ws2801.c
│ └── ws2812.c
├── mqtt
│ ├── Makefile
│ ├── mqtt_msg.c
│ ├── mqtt_msg.h
│ ├── msg_queue.c
│ └── msg_queue.h
├── platform
│ ├── Makefile
│ ├── common.c
│ ├── common.h
│ ├── cpu_esp8266.h
│ ├── flash_api.h
│ ├── flash_fs.c
│ ├── flash_fs.h
│ ├── pin_map.c
│ ├── pin_map.h
│ ├── platform.c
│ └── platform.h
├── smart
│ ├── Makefile
│ ├── smart.c
│ └── smart.h
├── spiffs
│ ├── LICENSE
│ ├── Makefile
│ ├── docs
│ │ ├── IMPLEMENTING
│ │ ├── INTEGRATION
│ │ ├── TECH_SPEC
│ │ └── TODO
│ ├── spiffs.c
│ ├── spiffs.h
│ ├── spiffs_cache.c
│ ├── spiffs_check.c
│ ├── spiffs_config.h
│ ├── spiffs_gc.c
│ ├── spiffs_hydrogen.c
│ ├── spiffs_nucleus.c
│ ├── spiffs_nucleus.h
│ └── test
│ │ ├── main.c
│ │ ├── params_test.h
│ │ ├── test_bugreports.c
│ │ ├── test_check.c
│ │ ├── test_dev.c
│ │ ├── test_hydrogen.c
│ │ ├── test_spiffs.c
│ │ ├── test_spiffs.h
│ │ ├── testrunner.c
│ │ ├── testrunner.h
│ │ └── testsuites.c
├── u8glib
│ ├── COPYRIGHT
│ ├── Makefile
│ ├── u8g.h
│ ├── u8g_bitmap.c
│ ├── u8g_circle.c
│ ├── u8g_clip.c
│ ├── u8g_com_api.c
│ ├── u8g_com_api_16gr.c
│ ├── u8g_com_i2c.c
│ ├── u8g_com_io.c
│ ├── u8g_com_null.c
│ ├── u8g_cursor.c
│ ├── u8g_delay.c
│ ├── u8g_dev_a2_micro_printer.c
│ ├── u8g_dev_flipdisc_2x7.c
│ ├── u8g_dev_gprof.c
│ ├── u8g_dev_ht1632.c
│ ├── u8g_dev_ili9325d_320x240.c
│ ├── u8g_dev_ks0108_128x64.c
│ ├── u8g_dev_lc7981_160x80.c
│ ├── u8g_dev_lc7981_240x128.c
│ ├── u8g_dev_lc7981_240x64.c
│ ├── u8g_dev_lc7981_320x64.c
│ ├── u8g_dev_ld7032_60x32.c
│ ├── u8g_dev_null.c
│ ├── u8g_dev_pcd8544_84x48.c
│ ├── u8g_dev_pcf8812_96x65.c
│ ├── u8g_dev_sbn1661_122x32.c
│ ├── u8g_dev_ssd1306_128x32.c
│ ├── u8g_dev_ssd1306_128x64.c
│ ├── u8g_dev_ssd1309_128x64.c
│ ├── u8g_dev_ssd1322_nhd31oled_bw.c
│ ├── u8g_dev_ssd1322_nhd31oled_gr.c
│ ├── u8g_dev_ssd1325_nhd27oled_bw.c
│ ├── u8g_dev_ssd1325_nhd27oled_bw_new.c
│ ├── u8g_dev_ssd1325_nhd27oled_gr.c
│ ├── u8g_dev_ssd1325_nhd27oled_gr_new.c
│ ├── u8g_dev_ssd1327_96x96_gr.c
│ ├── u8g_dev_ssd1351_128x128.c
│ ├── u8g_dev_st7565_64128n.c
│ ├── u8g_dev_st7565_dogm128.c
│ ├── u8g_dev_st7565_dogm132.c
│ ├── u8g_dev_st7565_lm6059.c
│ ├── u8g_dev_st7565_lm6063.c
│ ├── u8g_dev_st7565_nhd_c12832.c
│ ├── u8g_dev_st7565_nhd_c12864.c
│ ├── u8g_dev_st7687_c144mvgd.c
│ ├── u8g_dev_st7920_128x64.c
│ ├── u8g_dev_st7920_192x32.c
│ ├── u8g_dev_st7920_202x32.c
│ ├── u8g_dev_t6963_128x128.c
│ ├── u8g_dev_t6963_128x64.c
│ ├── u8g_dev_t6963_240x128.c
│ ├── u8g_dev_t6963_240x64.c
│ ├── u8g_dev_tls8204_84x48.c
│ ├── u8g_dev_uc1601_c128032.c
│ ├── u8g_dev_uc1608_240x128.c
│ ├── u8g_dev_uc1608_240x64.c
│ ├── u8g_dev_uc1610_dogxl160.c
│ ├── u8g_dev_uc1611_dogm240.c
│ ├── u8g_dev_uc1611_dogxl240.c
│ ├── u8g_dev_uc1701_dogs102.c
│ ├── u8g_dev_uc1701_mini12864.c
│ ├── u8g_ellipse.c
│ ├── u8g_font.c
│ ├── u8g_font_data.c
│ ├── u8g_line.c
│ ├── u8g_ll_api.c
│ ├── u8g_page.c
│ ├── u8g_pb.c
│ ├── u8g_pb14v1.c
│ ├── u8g_pb16h1.c
│ ├── u8g_pb16h2.c
│ ├── u8g_pb16v1.c
│ ├── u8g_pb16v2.c
│ ├── u8g_pb32h1.c
│ ├── u8g_pb8h1.c
│ ├── u8g_pb8h1f.c
│ ├── u8g_pb8h2.c
│ ├── u8g_pb8h8.c
│ ├── u8g_pb8v1.c
│ ├── u8g_pb8v2.c
│ ├── u8g_pbxh16.c
│ ├── u8g_pbxh24.c
│ ├── u8g_polygon.c
│ ├── u8g_rect.c
│ ├── u8g_rot.c
│ ├── u8g_scale.c
│ ├── u8g_state.c
│ ├── u8g_u16toa.c
│ ├── u8g_u8toa.c
│ └── u8g_virtual_screen.c
└── user
│ ├── Makefile
│ ├── user_exceptions.c
│ ├── user_exceptions.h
│ └── user_main.c
├── asm_damp.bat
├── bin
├── 0x00000.bin
├── 0x0c000.bin
├── blank.bin
├── esp_init_data_default.bin
├── rapid_loader.bin
├── rapid_loader_40m.bin
└── readme.txt
├── esptool.py
├── include
├── at_custom.h
├── c_types.h
├── eagle_soc.h
├── espconn.h
├── ets_sys.h
├── gpio.h
├── ip_addr.h
├── json
│ ├── json.h
│ ├── jsonparse.h
│ └── jsontree.h
├── mem.h
├── os_type.h
├── osapi.h
├── ping.h
├── pwm.h
├── queue.h
├── smartconfig.h
├── sntp.h
├── spi_flash.h
├── upgrade.h
└── user_interface.h
├── init.lua
├── ld
├── eagle.app.v6.ld
└── eagle.rom.addr.v6.ld
├── lib
├── 0
│ ├── 48app_main.o
│ ├── hiew.sav
│ └── vector.o
├── lib0main.a
├── libmc.a
├── libmc_list_files.txt
├── libmgcc.a
├── libmlwip.a
├── libmphy.a
├── libmwpa.a
├── libnet80211.a
├── libpp.a
├── libsmartconfig.a
├── libssl.a
├── new_lib0main.bat
├── new_libmc.bat
├── new_libmgcc.bat
├── new_libmlwip.bat
├── new_libmphy.bat
├── new_libmwpa.bat
├── o-asm.bat
└── rom_files_list.txt
├── lua_examples
├── adc_rgb.lua
├── email
│ ├── read_email_imap.lua
│ └── send_email_smtp.lua
├── http_server.lua
├── irsend.lua
├── make_phone_call.lua
├── mcp23008
│ ├── mcp23008_buttons.lua
│ └── mcp23008_leds.lua
├── mqtt
│ ├── mqtt2cloud.lua
│ └── mqtt_file.lua
├── myfile.lua
├── onewire-ds18b20.lua
├── send_text_message.lua
├── tcp2uart.lua
├── telnet.lua
├── telnet2.lua
├── u8glib
│ ├── u8g_bitmaps.lua
│ ├── u8g_graphics_test.lua
│ ├── u8g_rook.bm
│ ├── u8g_rotation.lua
│ └── u8glib_logo.xbm
├── webap_toggle_pin.lua
├── yet-another-bmp085.lua
├── yet-another-dht22.lua
└── yet-another-ds18b20.lua
├── lua_modules
├── base64
│ ├── base64.lua
│ └── base64_v2.lua
├── bh1750
│ ├── bh1750.lua
│ ├── bh1750_CN.md
│ ├── bh1750_EN.md
│ ├── bh1750_Example1.lua
│ └── bh1750_Example2.lua
├── bmp085
│ ├── bmp085.EN.md
│ └── bmp085.lua
├── dht_lib
│ ├── README.md
│ └── dht_lib.lua
├── ds18b20
│ ├── ds18b20-example.lua
│ ├── ds18b20-web.lua
│ ├── ds18b20.EN.md
│ ├── ds18b20.ZH.md
│ └── ds18b20.lua
├── ds3231
│ ├── ds3231-example.lua
│ ├── ds3231-web.lua
│ ├── ds3231.EN.md
│ └── ds3231.lua
├── email
│ └── imap.lua
├── hdc1000
│ ├── HDC1000-example.lua
│ ├── HDC1000.lua
│ └── README.md
├── http
│ ├── http-example.lua
│ └── http.lua
├── lm92
│ ├── README.md
│ └── lm92.lua
├── mcp23008
│ └── mcp23008.lua
├── redis
│ └── redis.lua
├── si7021
│ ├── si7021-example.lua
│ ├── si7021-lewei.lua
│ ├── si7021.EN.md
│ └── si7021.lua
└── yeelink
│ ├── Example_for_Yeelink_Lib.lua
│ └── yeelink_lib.lua
├── mem.txt
└── mem_usage.bat
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | EspLua
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.core.ccnature
24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
26 |
27 |
28 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding/=UTF-8
3 |
--------------------------------------------------------------------------------
/Espressif.License:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/Espressif.License
--------------------------------------------------------------------------------
/Espressif.License.old:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/Espressif.License.old
--------------------------------------------------------------------------------
/Nodemcu.License:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 zeroday nodemcu.com
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | *.output*
2 | mapfile
3 |
--------------------------------------------------------------------------------
/app/cjson/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2010-2012 Mark Pulford
2 | 2015 Zeroday Hong nodemcu.com
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining
5 | a copy of this software and associated documentation files (the
6 | "Software"), to deal in the Software without restriction, including
7 | without limitation the rights to use, copy, modify, merge, publish,
8 | distribute, sublicense, and/or sell copies of the Software, and to
9 | permit persons to whom the Software is furnished to do so, subject to
10 | the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/app/cjson/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 |
16 | GEN_LIBS = libcjson.a
17 |
18 | endif
19 |
20 |
21 | #############################################################
22 | # Configuration i.e. compile options etc.
23 | # Target specific stuff (defines etc.) goes in here!
24 | # Generally values applying to a tree are captured in the
25 | # makefile at its root level - these are then overridden
26 | # for a subtree within the makefile rooted therein
27 | #
28 | #DEFINES +=
29 |
30 | #############################################################
31 | # Recursion Magic - Don't touch this!!
32 | #
33 | # Each subtree potentially has an include directory
34 | # corresponding to the common APIs applicable to modules
35 | # rooted at that subtree. Accordingly, the INCLUDE PATH
36 | # of a module can only contain the include directories up
37 | # its parent path, and not its siblings
38 | #
39 | # Required for each makefile to inherit from the parent
40 | #
41 |
42 | INCLUDES := $(INCLUDES) -I $(PDIR)include
43 | INCLUDES += -I ./
44 | INCLUDES += -I ../libc
45 | PDIR := ../$(PDIR)
46 | sinclude $(PDIR)Makefile
47 |
48 |
--------------------------------------------------------------------------------
/app/cjson/THANKS:
--------------------------------------------------------------------------------
1 | The following people have helped with bug reports, testing and/or
2 | suggestions:
3 |
4 | - Louis-Philippe Perron (@loopole)
5 | - Ondřej Jirman
6 | - Steve Donovan
7 | - Zhang "agentzh" Yichun
8 |
9 | Thanks!
10 |
--------------------------------------------------------------------------------
/app/cjson/devel/json_parser_outline.txt:
--------------------------------------------------------------------------------
1 | parser:
2 | - call parse_value
3 | - next_token
4 | ? nop.
5 |
6 | parse_value:
7 | - next_token
8 | ? call parse_object.
9 | ? call parse_array.
10 | ? push. return.
11 | ? push. return.
12 | ? push. return.
13 | ? push. return.
14 |
15 | parse_object:
16 | - push table
17 | - next_token
18 | ? push.
19 | - next_token
20 | ? nop.
21 | - call parse_value
22 | - set table
23 | - next_token
24 | ? return.
25 | ? loop parse_object.
26 |
27 | parse_array:
28 | - push table
29 | - call parse_value
30 | - table append
31 | - next_token
32 | ? loop parse_array.
33 | ? ] return.
34 |
35 | next_token:
36 | - check next character
37 | ? { return
38 | ? } return
39 | ? [ return
40 | ? ] return
41 | ? , return
42 | ? : return
43 | ? [-0-9] gobble number. return
44 | ? " gobble string. return
45 | ? [ \t\n] eat whitespace.
46 | ? n Check "null". return or
47 | ? t Check "true". return or
48 | ? f Check "false". return or
49 | ? . return
50 | ? \0 return
51 |
--------------------------------------------------------------------------------
/app/cjson/fpconv.h:
--------------------------------------------------------------------------------
1 | /* Lua CJSON floating point conversion routines */
2 |
3 | /* Buffer required to store the largest string representation of a double.
4 | *
5 | * Longest double printed with %.14g is 21 characters long:
6 | * -1.7976931348623e+308 */
7 | # define FPCONV_G_FMT_BUFSIZE 32
8 |
9 | #ifdef USE_INTERNAL_FPCONV
10 | static inline void fpconv_init()
11 | {
12 | /* Do nothing - not required */
13 | }
14 | #else
15 | extern inline void fpconv_init();
16 | #endif
17 |
18 | extern int fpconv_g_fmt(char*, double, int);
19 | extern double fpconv_strtod(const char*, char**);
20 |
21 | /* vi:ai et sw=4 ts=4:
22 | */
23 |
--------------------------------------------------------------------------------
/app/cjson/lua/json2lua.lua:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env lua
2 |
3 | -- usage: json2lua.lua [json_file]
4 | --
5 | -- Eg:
6 | -- echo '[ "testing" ]' | ./json2lua.lua
7 | -- ./json2lua.lua test.json
8 |
9 | local json = require "cjson"
10 | local util = require "cjson.util"
11 |
12 | local json_text = util.file_load(arg[1])
13 | local t = json.decode(json_text)
14 | print(util.serialise_value(t))
15 |
--------------------------------------------------------------------------------
/app/cjson/lua/lua2json.lua:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env lua
2 |
3 | -- usage: lua2json.lua [lua_file]
4 | --
5 | -- Eg:
6 | -- echo '{ "testing" }' | ./lua2json.lua
7 | -- ./lua2json.lua test.lua
8 |
9 | local json = require "cjson"
10 | local util = require "cjson.util"
11 |
12 | local env = {
13 | json = { null = json.null },
14 | null = json.null
15 | }
16 |
17 | local t = util.run_script("data = " .. util.file_load(arg[1]), env)
18 | print(json.encode(t.data))
19 |
20 | -- vi:ai et sw=4 ts=4:
21 |
--------------------------------------------------------------------------------
/app/cjson/tests/README:
--------------------------------------------------------------------------------
1 | These JSON examples were taken from the JSON website
2 | (http://json.org/example.html) and RFC 4627.
3 |
4 | Used with permission.
5 |
--------------------------------------------------------------------------------
/app/cjson/tests/example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "glossary": {
3 | "title": "example glossary",
4 | "GlossDiv": {
5 | "title": "S",
6 | "GlossList": {
7 | "GlossEntry": {
8 | "ID": "SGML",
9 | "SortAs": "SGML",
10 | "GlossTerm": "Standard Generalized Mark up Language",
11 | "Acronym": "SGML",
12 | "Abbrev": "ISO 8879:1986",
13 | "GlossDef": {
14 | "para": "A meta-markup language, used to create markup languages such as DocBook.",
15 | "GlossSeeAlso": ["GML", "XML"]
16 | },
17 | "GlossSee": "markup"
18 | }
19 | }
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/cjson/tests/example2.json:
--------------------------------------------------------------------------------
1 | {"menu": {
2 | "id": "file",
3 | "value": "File",
4 | "popup": {
5 | "menuitem": [
6 | {"value": "New", "onclick": "CreateNewDoc()"},
7 | {"value": "Open", "onclick": "OpenDoc()"},
8 | {"value": "Close", "onclick": "CloseDoc()"}
9 | ]
10 | }
11 | }}
12 |
--------------------------------------------------------------------------------
/app/cjson/tests/example3.json:
--------------------------------------------------------------------------------
1 | {"widget": {
2 | "debug": "on",
3 | "window": {
4 | "title": "Sample Konfabulator Widget",
5 | "name": "main_window",
6 | "width": 500,
7 | "height": 500
8 | },
9 | "image": {
10 | "src": "Images/Sun.png",
11 | "name": "sun1",
12 | "hOffset": 250,
13 | "vOffset": 250,
14 | "alignment": "center"
15 | },
16 | "text": {
17 | "data": "Click Here",
18 | "size": 36,
19 | "style": "bold",
20 | "name": "text1",
21 | "hOffset": 250,
22 | "vOffset": 100,
23 | "alignment": "center",
24 | "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
25 | }
26 | }}
27 |
--------------------------------------------------------------------------------
/app/cjson/tests/example5.json:
--------------------------------------------------------------------------------
1 | {"menu": {
2 | "header": "SVG Viewer",
3 | "items": [
4 | {"id": "Open"},
5 | {"id": "OpenNew", "label": "Open New"},
6 | null,
7 | {"id": "ZoomIn", "label": "Zoom In"},
8 | {"id": "ZoomOut", "label": "Zoom Out"},
9 | {"id": "OriginalView", "label": "Original View"},
10 | null,
11 | {"id": "Quality"},
12 | {"id": "Pause"},
13 | {"id": "Mute"},
14 | null,
15 | {"id": "Find", "label": "Find..."},
16 | {"id": "FindAgain", "label": "Find Again"},
17 | {"id": "Copy"},
18 | {"id": "CopyAgain", "label": "Copy Again"},
19 | {"id": "CopySVG", "label": "Copy SVG"},
20 | {"id": "ViewSVG", "label": "View SVG"},
21 | {"id": "ViewSource", "label": "View Source"},
22 | {"id": "SaveAs", "label": "Save As"},
23 | null,
24 | {"id": "Help"},
25 | {"id": "About", "label": "About Adobe CVG Viewer..."}
26 | ]
27 | }}
28 |
--------------------------------------------------------------------------------
/app/cjson/tests/genutf8.pl:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env perl
2 |
3 | # Create test comparison data using a different UTF-8 implementation.
4 |
5 | # The generated utf8.dat file must have the following MD5 sum:
6 | # cff03b039d850f370a7362f3313e5268
7 |
8 | use strict;
9 |
10 | # 0xD800 - 0xDFFF are used to encode supplementary codepoints
11 | # 0x10000 - 0x10FFFF are supplementary codepoints
12 | my (@codepoints) = (0 .. 0xD7FF, 0xE000 .. 0x10FFFF);
13 |
14 | my $utf8 = pack("U*", @codepoints);
15 | defined($utf8) or die "Unable create UTF-8 string\n";
16 |
17 | open(FH, ">:utf8", "utf8.dat")
18 | or die "Unable to open utf8.dat: $!\n";
19 | print FH $utf8
20 | or die "Unable to write utf8.dat\n";
21 | close(FH);
22 |
23 | # vi:ai et sw=4 ts=4:
24 |
--------------------------------------------------------------------------------
/app/cjson/tests/numbers.json:
--------------------------------------------------------------------------------
1 | [ 0.110001,
2 | 0.12345678910111,
3 | 0.412454033640,
4 | 2.6651441426902,
5 | 2.718281828459,
6 | 3.1415926535898,
7 | 2.1406926327793 ]
8 |
--------------------------------------------------------------------------------
/app/cjson/tests/octets-escaped.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/app/cjson/tests/octets-escaped.dat
--------------------------------------------------------------------------------
/app/cjson/tests/rfc-example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "Image": {
3 | "Width": 800,
4 | "Height": 600,
5 | "Title": "View from 15th Floor",
6 | "Thumbnail": {
7 | "Url": "http://www.example.com/image/481989943",
8 | "Height": 125,
9 | "Width": "100"
10 | },
11 | "IDs": [116, 943, 234, 38793]
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/cjson/tests/rfc-example2.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "precision": "zip",
4 | "Latitude": 37.7668,
5 | "Longitude": -122.3959,
6 | "Address": "",
7 | "City": "SAN FRANCISCO",
8 | "State": "CA",
9 | "Zip": "94107",
10 | "Country": "US"
11 | },
12 | {
13 | "precision": "zip",
14 | "Latitude": 37.371991,
15 | "Longitude": -122.026020,
16 | "Address": "",
17 | "City": "SUNNYVALE",
18 | "State": "CA",
19 | "Zip": "94085",
20 | "Country": "US"
21 | }
22 | ]
23 |
--------------------------------------------------------------------------------
/app/cjson/tests/types.json:
--------------------------------------------------------------------------------
1 | { "array": [ 10, true, null ] }
2 |
--------------------------------------------------------------------------------
/app/coap/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013 Toby Jaffey
2 | 2015 Zeroday Hong nodemcu.com
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in
12 | all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/app/coap/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = coap.a
16 | endif
17 |
18 | #############################################################
19 | # Configuration i.e. compile options etc.
20 | # Target specific stuff (defines etc.) goes in here!
21 | # Generally values applying to a tree are captured in the
22 | # makefile at its root level - these are then overridden
23 | # for a subtree within the makefile rooted therein
24 | #
25 | #DEFINES +=
26 |
27 | #############################################################
28 | # Recursion Magic - Don't touch this!!
29 | #
30 | # Each subtree potentially has an include directory
31 | # corresponding to the common APIs applicable to modules
32 | # rooted at that subtree. Accordingly, the INCLUDE PATH
33 | # of a module can only contain the include directories up
34 | # its parent path, and not its siblings
35 | #
36 | # Required for each makefile to inherit from the parent
37 | #
38 |
39 | INCLUDES := $(INCLUDES) -I $(PDIR)include
40 | INCLUDES += -I ./
41 | INCLUDES += -I ../libc
42 | INCLUDES += -I ../lua
43 | PDIR := ../$(PDIR)
44 | sinclude $(PDIR)Makefile
45 |
46 |
--------------------------------------------------------------------------------
/app/coap/coap_client.c:
--------------------------------------------------------------------------------
1 | #include "user_config.h"
2 | #include "c_types.h"
3 |
4 | #include "coap.h"
5 | #include "hash.h"
6 | #include "node.h"
7 |
8 | extern coap_queue_t *gQueue;
9 |
10 | void coap_client_response_handler(char *data, unsigned short len, unsigned short size, const uint32_t ip, const uint32_t port)
11 | {
12 | NODE_DBG("coap_client_response_handler is called.\n");
13 | coap_packet_t pkt;
14 | pkt.content.p = NULL;
15 | pkt.content.len = 0;
16 | int rc;
17 |
18 | if (0 != (rc = coap_parse(&pkt, data, len))){
19 | NODE_DBG("Bad packet rc=%d\n", rc);
20 | }
21 | else
22 | {
23 | #ifdef COAP_DEBUG
24 | coap_dumpPacket(&pkt);
25 | #endif
26 | /* check if this is a response to our original request */
27 | if (!check_token(&pkt)) {
28 | /* drop if this was just some message, or send RST in case of notification */
29 | if (pkt.hdr.t == COAP_TYPE_CON || pkt.hdr.t == COAP_TYPE_NONCON){
30 | // coap_send_rst(pkt); // send RST response
31 | // or, just ignore it.
32 | }
33 | goto end;
34 | }
35 |
36 | if (pkt.hdr.t == COAP_TYPE_RESET) {
37 | NODE_DBG("got RST\n");
38 | goto end;
39 | }
40 |
41 | coap_tid_t id = COAP_INVALID_TID;
42 | coap_transaction_id(ip, port, &pkt, &id);
43 | /* transaction done, remove the node from queue */
44 | // stop timer
45 | coap_timer_stop();
46 | // remove the node
47 | coap_remove_node(&gQueue, id);
48 | // calculate time elapsed
49 | coap_timer_update(&gQueue);
50 | coap_timer_start(&gQueue);
51 |
52 | if (COAP_RESPONSE_CLASS(pkt.hdr.code) == 2)
53 | {
54 | /* There is no block option set, just read the data and we are done. */
55 | NODE_DBG("%d.%02d\t", (pkt.hdr.code >> 5), pkt.hdr.code & 0x1F);
56 | NODE_DBG_((char *)(pkt.payload.p));
57 | }
58 | else if (COAP_RESPONSE_CLASS(pkt.hdr.code) >= 4)
59 | {
60 | NODE_DBG("%d.%02d\t", (pkt.hdr.code >> 5), pkt.hdr.code & 0x1F);
61 | NODE_DBG_((char *)(pkt.payload.p));
62 | }
63 | }
64 |
65 | end:
66 | if(!gQueue){ // if there is no node pending in the queue, disconnect from host.
67 |
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/app/coap/coap_client.h:
--------------------------------------------------------------------------------
1 | #ifndef _COAP_CLIENT_H
2 | #define _COAP_CLIENT_H 1
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | void coap_client_response_handler(char *data, unsigned short len, unsigned short size, const uint32_t ip, const uint32_t port);
9 |
10 | #ifdef __cplusplus
11 | }
12 | #endif
13 |
14 | #endif
15 |
--------------------------------------------------------------------------------
/app/coap/coap_io.h:
--------------------------------------------------------------------------------
1 | #ifndef _COAP_IO_H
2 | #define _COAP_IO_H 1
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | #include "espconn.h"
9 | #include "pdu.h"
10 | #include "hash.h"
11 |
12 | coap_tid_t coap_send(struct espconn *pesp_conn, coap_pdu_t *pdu);
13 |
14 | coap_tid_t coap_send_confirmed(struct espconn *pesp_conn, coap_pdu_t *pdu);
15 |
16 | #ifdef __cplusplus
17 | }
18 | #endif
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/app/coap/coap_server.c:
--------------------------------------------------------------------------------
1 | #include "user_config.h"
2 | #include "c_types.h"
3 | #include "c_stdlib.h"
4 |
5 | #include "coap.h"
6 |
7 | size_t coap_server_respond(char *req, unsigned short reqlen, char *rsp, unsigned short rsplen)
8 | {
9 | NODE_DBG("coap_server_respond is called.\n");
10 | size_t rlen = rsplen;
11 | coap_packet_t pkt;
12 | pkt.content.p = NULL;
13 | pkt.content.len = 0;
14 | uint8_t scratch_raw[4];
15 | coap_rw_buffer_t scratch_buf = {scratch_raw, sizeof(scratch_raw)};
16 | int rc;
17 |
18 | #ifdef COAP_DEBUG
19 | NODE_DBG("Received: ");
20 | coap_dump(req, reqlen, true);
21 | NODE_DBG("\n");
22 | #endif
23 |
24 | if (0 != (rc = coap_parse(&pkt, req, reqlen))){
25 | NODE_DBG("Bad packet rc=%d\n", rc);
26 | return 0;
27 | }
28 | else
29 | {
30 | coap_packet_t rsppkt;
31 | rsppkt.content.p = NULL;
32 | rsppkt.content.len = 0;
33 | #ifdef COAP_DEBUG
34 | coap_dumpPacket(&pkt);
35 | #endif
36 | coap_handle_req(&scratch_buf, &pkt, &rsppkt);
37 | if (0 != (rc = coap_build(rsp, &rlen, &rsppkt))){
38 | NODE_DBG("coap_build failed rc=%d\n", rc);
39 | // return 0;
40 | rlen = 0;
41 | }
42 | else
43 | {
44 | #ifdef COAP_DEBUG
45 | NODE_DBG("Responding: ");
46 | coap_dump(rsp, rlen, true);
47 | NODE_DBG("\n");
48 | #endif
49 | #ifdef COAP_DEBUG
50 | coap_dumpPacket(&rsppkt);
51 | #endif
52 | }
53 | if(rsppkt.content.p){
54 | c_free(rsppkt.content.p);
55 | rsppkt.content.p = NULL;
56 | rsppkt.content.len = 0;
57 | }
58 | return rlen;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/coap/coap_server.h:
--------------------------------------------------------------------------------
1 | #ifndef _COAP_SERVER_H
2 | #define _COAP_SERVER_H 1
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | size_t coap_server_respond(char *req, unsigned short reqlen, char *rsp, unsigned short rsplen);
9 |
10 | #ifdef __cplusplus
11 | }
12 | #endif
13 |
14 | #endif
15 |
--------------------------------------------------------------------------------
/app/coap/coap_timer.h:
--------------------------------------------------------------------------------
1 | #ifndef _COAP_TIMER_H
2 | #define _COAP_TIMER_H 1
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | #include "node.h"
9 |
10 | #define SYS_TIME_MAX (0xFFFFFFFF / 1000)
11 |
12 | #define COAP_DEFAULT_RESPONSE_TIMEOUT 2 /* response timeout in seconds */
13 | #define COAP_DEFAULT_MAX_RETRANSMIT 4 /* max number of retransmissions */
14 | #define COAP_TICKS_PER_SECOND 1000 // ms
15 | #define DEFAULT_MAX_TRANSMIT_WAIT 90
16 |
17 | void coap_timer_elapsed(coap_tick_t *diff);
18 |
19 | void coap_timer_setup(coap_queue_t ** queue, coap_tick_t t);
20 |
21 | void coap_timer_stop(void);
22 |
23 | void coap_timer_update(coap_queue_t ** queue);
24 |
25 | void coap_timer_start(coap_queue_t ** queue);
26 |
27 | #ifdef __cplusplus
28 | }
29 | #endif
30 |
31 | #endif
32 |
--------------------------------------------------------------------------------
/app/coap/hash.c:
--------------------------------------------------------------------------------
1 | #include "hash.h"
2 | #include "c_string.h"
3 | /* Caution: When changing this, update COAP_DEFAULT_WKC_HASHKEY
4 | * accordingly (see int coap_hash_path());
5 | */
6 | void coap_hash(const unsigned char *s, unsigned int len, coap_key_t h) {
7 | size_t j;
8 |
9 | while (len--) {
10 | j = sizeof(coap_key_t)-1;
11 |
12 | while (j) {
13 | h[j] = ((h[j] << 7) | (h[j-1] >> 1)) + h[j];
14 | --j;
15 | }
16 |
17 | h[0] = (h[0] << 7) + h[0] + *s++;
18 | }
19 | }
20 |
21 | void coap_transaction_id(const uint32_t ip, const uint32_t port, const coap_packet_t *pkt, coap_tid_t *id) {
22 | coap_key_t h;
23 | c_memset(h, 0, sizeof(coap_key_t));
24 |
25 | /* Compare the transport address. */
26 | coap_hash((const unsigned char *)&(port), sizeof(port), h);
27 | coap_hash((const unsigned char *)&(ip), sizeof(ip), h);
28 | coap_hash((const unsigned char *)(pkt->hdr.id), sizeof(pkt->hdr.id), h);
29 | *id = ((h[0] << 8) | h[1]) ^ ((h[2] << 8) | h[3]);
30 | }
31 |
--------------------------------------------------------------------------------
/app/coap/hash.h:
--------------------------------------------------------------------------------
1 | #ifndef _HASH_H
2 | #define _HASH_H 1
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | #include "coap.h"
9 |
10 | typedef unsigned char coap_key_t[4];
11 |
12 | /* CoAP transaction id */
13 | /*typedef unsigned short coap_tid_t; */
14 | typedef int coap_tid_t;
15 | #define COAP_INVALID_TID -1
16 |
17 | void coap_transaction_id(const uint32_t ip, const uint32_t port, const coap_packet_t *pkt, coap_tid_t *id);
18 |
19 | #ifdef __cplusplus
20 | }
21 | #endif
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/app/coap/node.h:
--------------------------------------------------------------------------------
1 | #ifndef _NODE_H
2 | #define _NODE_H 1
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | #include "hash.h"
9 | #include "pdu.h"
10 |
11 | struct coap_queue_t;
12 | typedef uint32_t coap_tick_t;
13 |
14 | /*
15 | 1. queue(first)->t store when to send PDU for the next time, it's a base(absolute) time
16 | 2. queue->next->t store the delta between time and base-time. queue->next->t = timeout + now - basetime
17 | 3. node->next->t store the delta between time and previous->t. node->next->t = timeout + now - node->t - basetime
18 | 4. time to fire: 10, 15, 18, 25
19 | node->t: 10, 5, 3, 7
20 | */
21 |
22 | typedef struct coap_queue_t {
23 | struct coap_queue_t *next;
24 |
25 | coap_tick_t t; /**< when to send PDU for the next time */
26 | unsigned char retransmit_cnt; /**< retransmission counter, will be removed when zero */
27 | unsigned int timeout; /**< the randomized timeout value */
28 |
29 | coap_tid_t id; /**< unique transaction id */
30 |
31 | // coap_packet_t *pkt;
32 | coap_pdu_t *pdu; /**< the CoAP PDU to send */
33 | struct espconn *pconn;
34 | } coap_queue_t;
35 |
36 | void coap_free_node(coap_queue_t *node);
37 |
38 | /** Adds node to given queue, ordered by node->t. */
39 | int coap_insert_node(coap_queue_t **queue, coap_queue_t *node);
40 |
41 | /** Destroys specified node. */
42 | int coap_delete_node(coap_queue_t *node);
43 |
44 | /** Removes all items from given queue and frees the allocated storage. */
45 | void coap_delete_all(coap_queue_t *queue);
46 |
47 | /** Creates a new node suitable for adding to the CoAP sendqueue. */
48 | coap_queue_t *coap_new_node(void);
49 |
50 | coap_queue_t *coap_pop_next( coap_queue_t **queue );
51 |
52 | int coap_remove_node( coap_queue_t **queue, const coap_tid_t id);
53 |
54 | #ifdef __cplusplus
55 | }
56 | #endif
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/app/coap/pdu.c:
--------------------------------------------------------------------------------
1 | #include "c_stdlib.h"
2 | #include "pdu.h"
3 |
4 | coap_pdu_t * coap_new_pdu(void) {
5 | coap_pdu_t *pdu = NULL;
6 | pdu = (coap_pdu_t *)c_zalloc(sizeof(coap_pdu_t));
7 | if(!pdu){
8 | NODE_DBG("coap_new_pdu malloc error.\n");
9 | return NULL;
10 | }
11 |
12 | pdu->scratch.p = (uint8_t *)c_zalloc(MAX_REQ_SCRATCH_SIZE);
13 | if(!pdu->scratch.p){
14 | NODE_DBG("coap_new_pdu malloc error.\n");
15 | c_free(pdu);
16 | return NULL;
17 | }
18 | pdu->scratch.len = MAX_REQ_SCRATCH_SIZE;
19 |
20 | pdu->pkt = (coap_packet_t *)c_zalloc(sizeof(coap_packet_t));
21 | if(!pdu->pkt){
22 | NODE_DBG("coap_new_pdu malloc error.\n");
23 | c_free(pdu->scratch.p);
24 | c_free(pdu);
25 | return NULL;
26 | }
27 | pdu->pkt->content.p = NULL;
28 | pdu->pkt->content.len = 0;
29 |
30 | pdu->msg.p = (uint8_t *)c_zalloc(MAX_REQUEST_SIZE+1); // +1 for string '\0'
31 | if(!pdu->msg.p){
32 | NODE_DBG("coap_new_pdu malloc error.\n");
33 | c_free(pdu->pkt);
34 | c_free(pdu->scratch.p);
35 | c_free(pdu);
36 | return NULL;
37 | }
38 | pdu->msg.len = MAX_REQUEST_SIZE;
39 | return pdu;
40 | }
41 |
42 | void coap_delete_pdu(coap_pdu_t *pdu){
43 | if(!pdu)
44 | return;
45 |
46 | if(pdu->scratch.p){
47 | c_free(pdu->scratch.p);
48 | pdu->scratch.p = NULL;
49 | pdu->scratch.len = 0;
50 | }
51 |
52 | if(pdu->pkt){
53 | c_free(pdu->pkt);
54 | pdu->pkt = NULL;
55 | }
56 |
57 | if(pdu->msg.p){
58 | c_free(pdu->msg.p);
59 | pdu->msg.p = NULL;
60 | pdu->msg.len = 0;
61 | }
62 |
63 | c_free(pdu);
64 | pdu = NULL;
65 | }
66 |
--------------------------------------------------------------------------------
/app/coap/pdu.h:
--------------------------------------------------------------------------------
1 | #ifndef _PDU_H
2 | #define _PDU_H 1
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | #include "coap.h"
9 |
10 | /** Header structure for CoAP PDUs */
11 | typedef struct {
12 | coap_rw_buffer_t scratch;
13 | coap_packet_t *pkt;
14 | coap_rw_buffer_t msg; /**< the CoAP msg to send */
15 | } coap_pdu_t;
16 |
17 | coap_pdu_t *coap_new_pdu(void);
18 |
19 | void coap_delete_pdu(coap_pdu_t *pdu);
20 |
21 | #ifdef __cplusplus
22 | }
23 | #endif
24 |
25 | #endif
26 |
--------------------------------------------------------------------------------
/app/coap/str.c:
--------------------------------------------------------------------------------
1 | /* str.c -- strings to be used in the CoAP library
2 | *
3 | * Copyright (C) 2010,2011 Olaf Bergmann
4 | *
5 | * This file is part of the CoAP library libcoap. Please see
6 | * README for terms of use.
7 | */
8 |
9 | #include "c_stdlib.h"
10 | #include "c_types.h"
11 |
12 | #include "str.h"
13 |
14 | str * coap_new_string(size_t size) {
15 | str *s = (str *)c_malloc(sizeof(str) + size + 1);
16 | if ( !s ) {
17 | return NULL;
18 | }
19 |
20 | c_memset(s, 0, sizeof(str));
21 | s->s = ((unsigned char *)s) + sizeof(str);
22 | return s;
23 | }
24 |
25 | void coap_delete_string(str *s) {
26 | c_free(s);
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/app/coap/str.h:
--------------------------------------------------------------------------------
1 | /* str.h -- strings to be used in the CoAP library
2 | *
3 | * Copyright (C) 2010,2011 Olaf Bergmann
4 | *
5 | * This file is part of the CoAP library libcoap. Please see
6 | * README for terms of use.
7 | */
8 |
9 | #ifndef _COAP_STR_H_
10 | #define _COAP_STR_H_
11 |
12 | #include "c_string.h"
13 |
14 | typedef struct {
15 | size_t length; /* length of string */
16 | unsigned char *s; /* string data */
17 | } str;
18 |
19 | #define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
20 |
21 | /**
22 | * Returns a new string object with at least size bytes storage
23 | * allocated. The string must be released using coap_delete_string();
24 | */
25 | str *coap_new_string(size_t size);
26 |
27 | /** Deletes the given string and releases any memory allocated. */
28 | void coap_delete_string(str *);
29 |
30 | #endif /* _COAP_STR_H_ */
31 |
--------------------------------------------------------------------------------
/app/crypto/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = libcrypto.a
16 | endif
17 |
18 | #############################################################
19 | # Configuration i.e. compile options etc.
20 | # Target specific stuff (defines etc.) goes in here!
21 | # Generally values applying to a tree are captured in the
22 | # makefile at its root level - these are then overridden
23 | # for a subtree within the makefile rooted therein
24 | #
25 | #DEFINES +=
26 |
27 | #############################################################
28 | # Recursion Magic - Don't touch this!!
29 | #
30 | # Each subtree potentially has an include directory
31 | # corresponding to the common APIs applicable to modules
32 | # rooted at that subtree. Accordingly, the INCLUDE PATH
33 | # of a module can only contain the include directories up
34 | # its parent path, and not its siblings
35 | #
36 | # Required for each makefile to inherit from the parent
37 | #
38 |
39 | INCLUDES := $(INCLUDES) -I $(PDIR)include
40 | INCLUDES += -I ./
41 | INCLUDES += -I ../libc
42 | INCLUDES += -I ../main/include
43 | PDIR := ../$(PDIR)
44 | sinclude $(PDIR)Makefile
45 |
46 |
--------------------------------------------------------------------------------
/app/crypto/sha2.h:
--------------------------------------------------------------------------------
1 | #ifndef __SHA2_H__
2 | #define __SHA2_H__
3 |
4 | #include "c_types.h"
5 |
6 | /**************************************************************************
7 | * SHA256/384/512 declarations
8 | **************************************************************************/
9 |
10 | #define SHA256_BLOCK_LENGTH 64
11 | #define SHA256_DIGEST_LENGTH 32
12 |
13 | typedef struct
14 | {
15 | uint32_t state[8];
16 | uint64_t bitcount;
17 | uint8_t buffer[SHA256_BLOCK_LENGTH];
18 | } SHA256_CTX;
19 |
20 |
21 | void SHA256_Init(SHA256_CTX *);
22 | void SHA256_Update(SHA256_CTX *, const uint8_t *msg, size_t len);
23 | void SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
24 |
25 | #define SHA384_BLOCK_LENGTH 128
26 | #define SHA384_DIGEST_LENGTH 48
27 |
28 | typedef struct
29 | {
30 | uint64_t state[8];
31 | uint64_t bitcount[2];
32 | uint8_t buffer[SHA384_BLOCK_LENGTH];
33 | } SHA384_CTX;
34 |
35 | void SHA384_Init(SHA384_CTX*);
36 | void SHA384_Update(SHA384_CTX*, const uint8_t *msg, size_t len);
37 | void SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
38 |
39 | #define SHA512_BLOCK_LENGTH 128
40 | #define SHA512_DIGEST_LENGTH 64
41 | typedef SHA384_CTX SHA512_CTX;
42 |
43 | void SHA512_Init(SHA512_CTX*);
44 | void SHA512_Update(SHA512_CTX*, const uint8_t *msg, size_t len);
45 | void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/app/dhtlib/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = libdhtlib.a
16 | endif
17 |
18 |
19 | #############################################################
20 | # Configuration i.e. compile options etc.
21 | # Target specific stuff (defines etc.) goes in here!
22 | # Generally values applying to a tree are captured in the
23 | # makefile at its root level - these are then overridden
24 | # for a subtree within the makefile rooted therein
25 | #
26 | #DEFINES +=
27 |
28 | #############################################################
29 | # Recursion Magic - Don't touch this!!
30 | #
31 | # Each subtree potentially has an include directory
32 | # corresponding to the common APIs applicable to modules
33 | # rooted at that subtree. Accordingly, the INCLUDE PATH
34 | # of a module can only contain the include directories up
35 | # its parent path, and not its siblings
36 | #
37 | # Required for each makefile to inherit from the parent
38 | #
39 |
40 | INCLUDES := $(INCLUDES) -I $(PDIR)include
41 | INCLUDES += -I ./
42 | INCLUDES += -I ./include
43 | INCLUDES += -I ../include
44 | INCLUDES += -I ../../include
45 | INCLUDES += -I ../libc
46 | INCLUDES += -I ../platform
47 | PDIR := ../$(PDIR)
48 | sinclude $(PDIR)Makefile
49 |
50 |
--------------------------------------------------------------------------------
/app/dhtlib/dht.h:
--------------------------------------------------------------------------------
1 | //
2 | // FILE: dht.h
3 | // AUTHOR: Rob Tillaart
4 | // VERSION: 0.1.14
5 | // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
6 | // URL: http://arduino.cc/playground/Main/DHTLib
7 | //
8 | // HISTORY:
9 | // see dht.cpp file
10 | //
11 |
12 | #ifndef dht_h
13 | #define dht_h
14 |
15 | // #if ARDUINO < 100
16 | // #include
17 | // #else
18 | // #include
19 | // #endif
20 | #include "c_types.h"
21 |
22 | #define DHT_LIB_VERSION "0.1.14"
23 |
24 | #define DHTLIB_OK 0
25 | #define DHTLIB_ERROR_CHECKSUM -1
26 | #define DHTLIB_ERROR_TIMEOUT -2
27 | #define DHTLIB_INVALID_VALUE -999
28 |
29 | #define DHTLIB_DHT11_WAKEUP 18
30 | #define DHTLIB_DHT_WAKEUP 1
31 | #define DHTLIB_DHT_UNI_WAKEUP 18
32 |
33 | #define DHT_DEBUG
34 |
35 | // max timeout is 100 usec.
36 | // For a 16 Mhz proc 100 usec is 1600 clock cycles
37 | // loops using DHTLIB_TIMEOUT use at least 4 clock cycli
38 | // so 100 us takes max 400 loops
39 | // so by dividing F_CPU by 40000 we "fail" as fast as possible
40 | // ESP8266 uses delay_us get 1us time
41 | #define DHTLIB_TIMEOUT (100)
42 |
43 | // Platform specific I/O definitions
44 |
45 | #define DIRECT_READ(pin) (0x1 & GPIO_INPUT_GET(GPIO_ID_PIN(pin_num[pin])))
46 | #define DIRECT_MODE_INPUT(pin) GPIO_DIS_OUTPUT(pin_num[pin])
47 | #define DIRECT_MODE_OUTPUT(pin)
48 | #define DIRECT_WRITE_LOW(pin) (GPIO_OUTPUT_SET(GPIO_ID_PIN(pin_num[pin]), 0))
49 | #define DIRECT_WRITE_HIGH(pin) (GPIO_OUTPUT_SET(GPIO_ID_PIN(pin_num[pin]), 1))
50 |
51 | // return values:
52 | // DHTLIB_OK
53 | // DHTLIB_ERROR_CHECKSUM
54 | // DHTLIB_ERROR_TIMEOUT
55 | int dht_read_universal(uint8_t pin);
56 | int dht_read11(uint8_t pin);
57 | int dht_read(uint8_t pin);
58 |
59 | int dht_read21(uint8_t pin);
60 | int dht_read22(uint8_t pin);
61 | int dht_read33(uint8_t pin);
62 | int dht_read44(uint8_t pin);
63 |
64 | double dht_getHumidity(void);
65 | double dht_getTemperature(void);
66 |
67 | #endif
68 | //
69 | // END OF FILE
70 | //
--------------------------------------------------------------------------------
/app/driver/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = libdriver.a
16 | endif
17 |
18 |
19 | #############################################################
20 | # Configuration i.e. compile options etc.
21 | # Target specific stuff (defines etc.) goes in here!
22 | # Generally values applying to a tree are captured in the
23 | # makefile at its root level - these are then overridden
24 | # for a subtree within the makefile rooted therein
25 | #
26 | #DEFINES +=
27 |
28 | #############################################################
29 | # Recursion Magic - Don't touch this!!
30 | #
31 | # Each subtree potentially has an include directory
32 | # corresponding to the common APIs applicable to modules
33 | # rooted at that subtree. Accordingly, the INCLUDE PATH
34 | # of a module can only contain the include directories up
35 | # its parent path, and not its siblings
36 | #
37 | # Required for each makefile to inherit from the parent
38 | #
39 |
40 | INCLUDES := $(INCLUDES) -I $(PDIR)include
41 | INCLUDES += -I ./
42 | INCLUDES += -I ../platform
43 | PDIR := ../$(PDIR)
44 | sinclude $(PDIR)Makefile
45 |
46 |
--------------------------------------------------------------------------------
/app/driver/gpio16.c:
--------------------------------------------------------------------------------
1 | #include "ets_sys.h"
2 | #include "osapi.h"
3 | #include "driver/gpio16.h"
4 |
5 | void ICACHE_FLASH_ATTR
6 | gpio16_output_conf(void)
7 | {
8 | WRITE_PERI_REG(PAD_XPD_DCDC_CONF,
9 | (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC to output rtc_gpio0
10 |
11 | WRITE_PERI_REG(RTC_GPIO_CONF,
12 | (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable
13 |
14 | WRITE_PERI_REG(RTC_GPIO_ENABLE,
15 | (READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe) | (uint32)0x1); //out enable
16 | }
17 |
18 | void ICACHE_FLASH_ATTR
19 | gpio16_output_set(uint8 value)
20 | {
21 | WRITE_PERI_REG(RTC_GPIO_OUT,
22 | (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe) | (uint32)(value & 1));
23 | }
24 |
25 | void ICACHE_FLASH_ATTR
26 | gpio16_input_conf(void)
27 | {
28 | WRITE_PERI_REG(PAD_XPD_DCDC_CONF,
29 | (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC and rtc_gpio0 connection
30 |
31 | WRITE_PERI_REG(RTC_GPIO_CONF,
32 | (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable
33 |
34 | WRITE_PERI_REG(RTC_GPIO_ENABLE,
35 | READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe); //out disable
36 | }
37 |
38 | uint8 ICACHE_FLASH_ATTR
39 | gpio16_input_get(void)
40 | {
41 | return (uint8)(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1);
42 | }
43 |
--------------------------------------------------------------------------------
/app/include/arch/perf.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2001, Swedish Institute of Computer Science.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | * 3. Neither the name of the Institute nor the names of its contributors
14 | * may be used to endorse or promote products derived from this software
15 | * without specific prior written permission.
16 | *
17 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 | * SUCH DAMAGE.
28 | *
29 | * This file is part of the lwIP TCP/IP stack.
30 | *
31 | * Author: Adam Dunkels
32 | *
33 | */
34 | #ifndef __PERF_H__
35 | #define __PERF_H__
36 |
37 | #define PERF_START /* null definition */
38 | #define PERF_STOP(x) /* null definition */
39 |
40 | #endif /* __PERF_H__ */
41 |
--------------------------------------------------------------------------------
/app/include/arch/sys_arch.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/app/include/arch/sys_arch.h
--------------------------------------------------------------------------------
/app/include/driver/gpio16.h:
--------------------------------------------------------------------------------
1 | #ifndef __GPIO16_H__
2 | #define __GPIO16_H__
3 |
4 | void gpio16_output_conf(void);
5 | void gpio16_output_set(uint8 value);
6 | void gpio16_input_conf(void);
7 | uint8 gpio16_input_get(void);
8 |
9 | #endif
10 |
--------------------------------------------------------------------------------
/app/include/driver/key.h:
--------------------------------------------------------------------------------
1 | #ifndef __KEY_H__
2 | #define __KEY_H__
3 |
4 | #include "gpio.h"
5 |
6 | typedef void (* key_function)(void);
7 |
8 | struct single_key_param {
9 | uint8 key_level;
10 | uint8 gpio_id;
11 | uint8 gpio_func;
12 | uint32 gpio_name;
13 | os_timer_t key_5s;
14 | os_timer_t key_50ms;
15 | key_function short_press;
16 | key_function long_press;
17 | };
18 |
19 | struct keys_param {
20 | uint8 key_num;
21 | struct single_key_param **single_key;
22 | };
23 |
24 | struct single_key_param *key_init_single(uint8 gpio_id, uint32 gpio_name, uint8 gpio_func, key_function long_press, key_function short_press);
25 | void key_init(struct keys_param *key);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/app/include/driver/pwm.h:
--------------------------------------------------------------------------------
1 | #ifndef __PWM_H__
2 | #define __PWM_H__
3 |
4 | #define PWM_CHANNEL 6
5 |
6 | struct pwm_single_param {
7 | uint16 gpio_set;
8 | uint16 gpio_clear;
9 | uint32 h_time;
10 | };
11 |
12 | struct pwm_param {
13 | uint32 period;
14 | uint16 freq;
15 | uint16 duty[PWM_CHANNEL];
16 | };
17 |
18 | #define PWM_DEPTH 1023
19 | #define PWM_FREQ_MAX 1000
20 |
21 | #define PWM_1S 1000000
22 |
23 | // #define PWM_0_OUT_IO_MUX PERIPHS_IO_MUX_MTMS_U
24 | // #define PWM_0_OUT_IO_NUM 14
25 | // #define PWM_0_OUT_IO_FUNC FUNC_GPIO14
26 |
27 | // #define PWM_1_OUT_IO_MUX PERIPHS_IO_MUX_MTDI_U
28 | // #define PWM_1_OUT_IO_NUM 12
29 | // #define PWM_1_OUT_IO_FUNC FUNC_GPIO12
30 |
31 | // #define PWM_2_OUT_IO_MUX PERIPHS_IO_MUX_MTCK_U
32 | // #define PWM_2_OUT_IO_NUM 13
33 | // #define PWM_2_OUT_IO_FUNC FUNC_GPIO13
34 |
35 | void pwm_init(uint16 freq, uint16 *duty);
36 | void pwm_start(void);
37 |
38 | void pwm_set_duty(uint16 duty, uint8 channel);
39 | uint16 pwm_get_duty(uint8 channel);
40 | void pwm_set_freq(uint16 freq, uint8 channel);
41 | uint16 pwm_get_freq(uint8 channel);
42 | bool pwm_add(uint8 channel);
43 | bool pwm_delete(uint8 channel);
44 | bool pwm_exist(uint8 channel);
45 | #endif
46 |
47 |
--------------------------------------------------------------------------------
/app/include/driver/spi.h:
--------------------------------------------------------------------------------
1 | #ifndef SPI_APP_H
2 | #define SPI_APP_H
3 |
4 | #include "spi_register.h"
5 | #include "ets_sys.h"
6 | #include "osapi.h"
7 | #include "uart.h"
8 | #include "os_type.h"
9 |
10 | /*SPI number define*/
11 | #define SPI 0
12 | #define HSPI 1
13 |
14 |
15 |
16 | //lcd drive function
17 | void spi_lcd_mode_init(uint8 spi_no);
18 | void spi_lcd_9bit_write(uint8 spi_no,uint8 high_bit,uint8 low_8bit);
19 |
20 | //spi master init funtion
21 | void spi_master_init(uint8 spi_no, unsigned cpol, unsigned cpha, unsigned databits, uint32_t clock);
22 | //use spi send 8bit data
23 | void spi_mast_byte_write(uint8 spi_no,uint8 *data);
24 |
25 | //transmit data to esp8266 slave buffer,which needs 16bit transmission ,
26 | //first byte is master command 0x04, second byte is master data
27 | void spi_byte_write_espslave(uint8 spi_no,uint8 data);
28 | //read data from esp8266 slave buffer,which needs 16bit transmission ,
29 | //first byte is master command 0x06, second byte is to read slave data
30 | void spi_byte_read_espslave(uint8 spi_no,uint8 *data);
31 |
32 | //esp8266 slave mode initial
33 | void spi_slave_init(uint8 spi_no);
34 | //esp8266 slave isr handle funtion,tiggered when any transmission is finished.
35 | //the function is registered in spi_slave_init.
36 | void spi_slave_isr_handler(void *para);
37 |
38 |
39 | //hspi test function, used to test esp8266 spi slave
40 | void hspi_master_readwrite_repeat(void);
41 |
42 |
43 | void ICACHE_FLASH_ATTR
44 | spi_test_init(void);
45 |
46 |
47 | #endif
48 |
49 |
--------------------------------------------------------------------------------
/app/include/driver/spi_master.h:
--------------------------------------------------------------------------------
1 | #ifndef __SPI_MASTER_H__
2 | #define __SPI_MASTER_H__
3 |
4 | #include "driver/spi_register.h"
5 |
6 | /*SPI number define*/
7 | #define SPI 0
8 | #define HSPI 1
9 |
10 | void spi_master_init(uint8 spi_no);
11 | void spi_master_9bit_write(uint8 spi_no, uint8 high_bit, uint8 low_8bit);
12 |
13 | #endif
14 |
--------------------------------------------------------------------------------
/app/include/iram_buf.h:
--------------------------------------------------------------------------------
1 | /*
2 | * iram_buf.h
3 | *
4 | * Author: pvvx
5 | */
6 | #ifndef __EXRTA_RAM_H_
7 | #define __EXRTA_RAM_H_
8 |
9 | #define IRAM1_BASE 0x40100000
10 | #define IRAM1_SIZE 0x0000C000
11 | #define MIN_GET_IRAM 1024
12 |
13 | typedef struct t_eraminfo
14 | {
15 | uint32 *base;
16 | uint32 size;
17 | }ERAMInfo;
18 |
19 |
20 | void eram_init(void) ICACHE_FLASH_ATTR;
21 | extern ERAMInfo eraminfo;
22 |
23 | bool eRamRead(uint32 addr, uint8 *pd, uint32 len) ICACHE_FLASH_ATTR;
24 | bool eRamWrite(uint32 addr, uint8 *pd, uint32 len) ICACHE_FLASH_ATTR;
25 |
26 |
27 | #endif /* __EXRTA_RAM_H_ */
28 |
--------------------------------------------------------------------------------
/app/include/lwip/COPYING:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * 1. Redistributions of source code must retain the above copyright notice,
9 | * this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright notice,
11 | * this list of conditions and the following disclaimer in the documentation
12 | * and/or other materials provided with the distribution.
13 | * 3. The name of the author may not be used to endorse or promote products
14 | * derived from this software without specific prior written permission.
15 | *
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25 | * OF SUCH DAMAGE.
26 | *
27 | * This file is part of the lwIP TCP/IP stack.
28 | *
29 | * Author: Adam Dunkels
30 | *
31 | */
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/include/lwip/icmp.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/app/include/lwip/icmp.h
--------------------------------------------------------------------------------
/app/include/netif/wlan_lwip_if.h:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | */
4 |
5 | #ifndef _WLAN_LWIP_IF_H_
6 | #define _WLAN_LWIP_IF_H_
7 |
8 | #define LWIP_IF0_PRIO 28
9 | #define LWIP_IF1_PRIO 29
10 |
11 | #ifdef USE_OPEN_LWIP
12 |
13 | struct ieee80211_conn {
14 | struct netif *myif; //+0
15 | uint32_t padding[(176-4)>>2]; //+4
16 | uint32_t dhcps_if; //+176 // + 0xB0
17 | };
18 | #endif
19 |
20 | struct netif * eagle_lwip_if_alloc(struct ieee80211_conn *conn, uint8 *macaddr, struct ip_info *info) ICACHE_FLASH_ATTR;
21 | struct netif * eagle_lwip_getif(int index) ;
22 |
23 | #ifndef IOT_SIP_MODE
24 | err_t ieee80211_output_pbuf(struct netif *ifp, struct pbuf* pb);
25 | #else
26 | err_t ieee80211_output_pbuf(struct ieee80211_conn *conn, esf_buf *eb);
27 | #endif
28 |
29 | extern uint8 * * phostname;
30 | extern bool default_hostname; // = true;
31 |
32 | #endif /* _WLAN_LWIP_IF_H_ */
33 |
--------------------------------------------------------------------------------
/app/include/pp/esf_buf.h:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * esf buffer data structure
4 | */
5 |
6 | #ifndef _ESF_BUF_H_
7 | #define _ESF_BUF_H_
8 |
9 | #define EP_OFFSET 36 /* see comments in pbuf.h */
10 |
11 | #endif /* _ESF_BUF_H_ */
12 |
--------------------------------------------------------------------------------
/app/include/rom2ram.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * FileName: rom2ram.h
3 | * Description: Alternate SDK (libmain.a)
4 | * Author: PV`
5 | * (c) PV` 2015
6 | *******************************************************************************/
7 |
8 | #ifndef _INCLUDE_ROM2RAM_H_
9 | #define _INCLUDE_ROM2RAM_H_
10 |
11 | int iram_buf_init(void);
12 | bool eRamRead(uint32 addr, uint8 *pd, uint32 len);
13 | bool eRamWrite(uint32 addr, uint8 *ps, uint32 len);
14 |
15 |
16 | void copy_s4d1(unsigned char * pd, void * ps, unsigned int len);
17 | void copy_s1d4(void * pd, unsigned char * ps, unsigned int len);
18 |
19 | char get_rom_chr(const char *ps);
20 | void write_iram_chr(unsigned char *pd, unsigned char c);
21 | char * rom_strcpy(char * pd_, void * ps, unsigned int maxlen);
22 |
23 |
24 | typedef struct t_eraminfo // описание свободной области в iram
25 | {
26 | uint32 *base;
27 | int32 size;
28 | }ERAMInfo;
29 |
30 | extern ERAMInfo eraminfo;
31 |
32 | //unsigned int rom_strlen(void * ps);
33 | //unsigned int rom_xstrcpy(char * pd, void * ps);
34 | //const char *rom_strchr(const char * ps, char c);
35 | //char * ets_strrchr(const char *string, int c);
36 |
37 | #endif /* _INCLUDE_ROM2RAM_H_ */
38 |
--------------------------------------------------------------------------------
/app/include/ssl/app/espconn_secure.h:
--------------------------------------------------------------------------------
1 | #ifndef __ESPCONN_ENCRY_H__
2 | #define __ESPCONN_ENCRY_H__
3 |
4 | #include "espconn/espconn.h"
5 |
6 | /******************************************************************************
7 | * FunctionName : espconn_encry_connect
8 | * Description : The function given as connection
9 | * Parameters : espconn -- the espconn used to connect with the host
10 | * Returns : none
11 | *******************************************************************************/
12 |
13 | sint8 espconn_secure_connect(struct espconn *espconn);
14 |
15 | /******************************************************************************
16 | * FunctionName : espconn_encry_disconnect
17 | * Description : The function given as the disconnection
18 | * Parameters : espconn -- the espconn used to disconnect with the host
19 | * Returns : none
20 | *******************************************************************************/
21 |
22 | extern sint8 espconn_secure_disconnect(struct espconn *espconn);
23 |
24 | /******************************************************************************
25 | * FunctionName : espconn_encry_sent
26 | * Description : sent data for client or server
27 | * Parameters : espconn -- espconn to set for client or server
28 | * psent -- data to send
29 | * length -- length of data to send
30 | * Returns : none
31 | *******************************************************************************/
32 |
33 | extern sint8 espconn_secure_sent(struct espconn *espconn, uint8 *psent, uint16 length);
34 |
35 | /******************************************************************************
36 | * FunctionName : espconn_secure_accept
37 | * Description : The function given as the listen
38 | * Parameters : espconn -- the espconn used to listen the connection
39 | * Returns : none
40 | *******************************************************************************/
41 |
42 | extern sint8 espconn_secure_accept(struct espconn *espconn);
43 |
44 | #endif
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/include/ssl/private_key.h:
--------------------------------------------------------------------------------
1 | unsigned char default_private_key[] = {
2 | 0x30, 0x82, 0x01, 0x3a, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, 0xb9, 0x83,
3 | 0x30, 0xca, 0xfb, 0xec, 0x11, 0x9e, 0x94, 0xb7, 0x89, 0xf2, 0x84, 0x2c,
4 | 0xda, 0xe1, 0x9a, 0x53, 0x3a, 0x1b, 0x6e, 0xc9, 0x85, 0x81, 0xf9, 0xa3,
5 | 0x41, 0xdb, 0xe2, 0x82, 0x3b, 0xfa, 0x80, 0x22, 0x3b, 0x81, 0x6d, 0x25,
6 | 0x73, 0x7e, 0xf6, 0x49, 0xcc, 0x69, 0x3c, 0x6c, 0xd8, 0x05, 0xfb, 0x92,
7 | 0x02, 0xcf, 0x19, 0x2a, 0x10, 0x7d, 0x69, 0x7a, 0xd8, 0x9d, 0xd3, 0xcf,
8 | 0x6c, 0xef, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x1d, 0x13, 0x92,
9 | 0xf2, 0x3d, 0xca, 0x22, 0x78, 0xd8, 0x96, 0x6b, 0xe8, 0xb7, 0x0e, 0xd0,
10 | 0xbf, 0xcb, 0x90, 0x7f, 0xeb, 0x0c, 0xd2, 0x49, 0x3a, 0xb6, 0x06, 0x00,
11 | 0xac, 0x96, 0x34, 0x13, 0x72, 0x4b, 0x8c, 0xd2, 0xb9, 0x35, 0xf5, 0x64,
12 | 0x18, 0xb2, 0x47, 0x5b, 0x9f, 0xbb, 0xf2, 0x5b, 0x2f, 0x66, 0x78, 0x2d,
13 | 0x0a, 0x76, 0x44, 0xc5, 0x4f, 0xdb, 0x7d, 0x13, 0xcf, 0xa5, 0x08, 0xdc,
14 | 0x01, 0x02, 0x21, 0x00, 0xdf, 0x9a, 0x89, 0xd0, 0xef, 0x23, 0xcf, 0x12,
15 | 0xac, 0x8a, 0x63, 0x1a, 0x8c, 0xc0, 0x3f, 0xf4, 0x38, 0x52, 0x3c, 0x9f,
16 | 0x19, 0x0a, 0x37, 0xd2, 0xcb, 0x5d, 0xeb, 0xb6, 0x2a, 0x33, 0xb0, 0x91,
17 | 0x02, 0x21, 0x00, 0xd4, 0x63, 0xd9, 0x6a, 0x18, 0x5b, 0xe8, 0xa8, 0x57,
18 | 0x4d, 0xd1, 0x9a, 0xa8, 0xd7, 0xe1, 0x65, 0x75, 0xb3, 0xb9, 0x5c, 0x94,
19 | 0x14, 0xca, 0x98, 0x41, 0x47, 0x9c, 0x0a, 0x22, 0x38, 0x05, 0x7f, 0x02,
20 | 0x20, 0x6a, 0xce, 0xfd, 0xef, 0xe0, 0x9b, 0x61, 0x49, 0x91, 0x43, 0x95,
21 | 0x6d, 0x54, 0x38, 0x6d, 0x14, 0x32, 0x67, 0x0d, 0xf0, 0x0d, 0x5c, 0xf5,
22 | 0x27, 0x6a, 0xdf, 0x55, 0x3d, 0xb1, 0xd0, 0xf9, 0x11, 0x02, 0x21, 0x00,
23 | 0xba, 0x94, 0xa0, 0xf9, 0xb0, 0x3e, 0x85, 0x8b, 0xe5, 0x6e, 0x4a, 0x95,
24 | 0x88, 0x80, 0x65, 0xd5, 0x00, 0xea, 0x8b, 0x0b, 0x46, 0x57, 0x61, 0x87,
25 | 0x11, 0xc9, 0xfb, 0xcd, 0x77, 0x34, 0x29, 0xb7, 0x02, 0x20, 0x06, 0x8d,
26 | 0x41, 0x11, 0x47, 0x93, 0xcb, 0xad, 0xda, 0x5d, 0xe1, 0x9d, 0x49, 0x8d,
27 | 0xe0, 0xab, 0x48, 0xe6, 0x18, 0x28, 0x4a, 0x94, 0xae, 0xf9, 0xad, 0xc5,
28 | 0x5b, 0x0b, 0x15, 0xc6, 0x73, 0x17
29 | };
30 | unsigned int default_private_key_len = 318;
31 |
--------------------------------------------------------------------------------
/app/include/ssl/ssl_version.h:
--------------------------------------------------------------------------------
1 | #define AXTLS_VERSION "1.4.9"
2 |
--------------------------------------------------------------------------------
/app/include/u8g_config.h:
--------------------------------------------------------------------------------
1 | #ifndef __U8G_CONFIG_H__
2 | #define __U8G_CONFIG_H__
3 |
4 |
5 | // Configure U8glib fonts
6 | // add a U8G_FONT_TABLE_ENTRY for each font you want to compile into the image
7 | #define U8G_FONT_TABLE_ENTRY(font)
8 | #define U8G_FONT_TABLE \
9 | U8G_FONT_TABLE_ENTRY(font_6x10) \
10 | U8G_FONT_TABLE_ENTRY(font_chikita)
11 | #undef U8G_FONT_TABLE_ENTRY
12 |
13 |
14 | // Enable display drivers
15 | #define U8G_SSD1306_128x64_I2C
16 | #define U8G_SSD1306_128x64_SPI
17 | // untested
18 | #undef U8G_PCD8544_84x48
19 |
20 |
21 | #endif /* __U8G_CONFIG_H__ */
22 |
--------------------------------------------------------------------------------
/app/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 // for debug.xxx(), not work
12 |
13 | #define LUA_USE_MODULES
14 |
15 | #ifdef LUA_USE_MODULES
16 | #define LUA_USE_MODULES_NODE
17 | #define LUA_USE_MODULES_FILE
18 | #define LUA_USE_MODULES_GPIO
19 | #define LUA_USE_MODULES_WIFI
20 | #define LUA_USE_MODULES_NET
21 | #define LUA_USE_MODULES_UART
22 | #define LUA_USE_MODULES_TMR
23 | #define LUA_USE_MODULES_PWM
24 | #define LUA_USE_MODULES_I2C
25 | #define LUA_USE_MODULES_SPI
26 | #define LUA_USE_MODULES_ADC
27 | #define LUA_USE_MODULES_OW
28 | #define LUA_USE_MODULES_BIT
29 | #define LUA_USE_MODULES_MQTT
30 | #define LUA_USE_MODULES_COAP
31 | #define LUA_USE_MODULES_U8G
32 | // #define LUA_USE_MODULES_WS2801
33 | #define LUA_USE_MODULES_WS2812
34 | #define LUA_USE_MODULES_CJSON
35 | #define LUA_USE_MODULES_CRYPTO
36 | #define LUA_USE_MODULES_RC
37 | #define LUA_USE_MODULES_DHT
38 |
39 | #endif /* LUA_USE_MODULES */
40 |
41 | #endif /* __USER_MODULES_H__ */
42 |
--------------------------------------------------------------------------------
/app/include/user_version.h:
--------------------------------------------------------------------------------
1 | #ifndef __USER_VERSION_H__
2 | #define __USER_VERSION_H__
3 |
4 | #define NODE_VERSION_MAJOR 1U
5 | #define NODE_VERSION_MINOR 3U
6 | #define NODE_VERSION_REVISION 0U
7 | #define NODE_VERSION_INTERNAL 0U
8 |
9 | #define NODE_VERSION "EspLua.ru 1.4.0"
10 | #define BUILD_DATE "build 20150922"
11 |
12 | #endif /* __USER_VERSION_H__ */
13 |
--------------------------------------------------------------------------------
/app/libc/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = liblibc.a
16 | endif
17 |
18 | #############################################################
19 | # Configuration i.e. compile options etc.
20 | # Target specific stuff (defines etc.) goes in here!
21 | # Generally values applying to a tree are captured in the
22 | # makefile at its root level - these are then overridden
23 | # for a subtree within the makefile rooted therein
24 | #
25 | #DEFINES +=
26 |
27 | #############################################################
28 | # Recursion Magic - Don't touch this!!
29 | #
30 | # Each subtree potentially has an include directory
31 | # corresponding to the common APIs applicable to modules
32 | # rooted at that subtree. Accordingly, the INCLUDE PATH
33 | # of a module can only contain the include directories up
34 | # its parent path, and not its siblings
35 | #
36 | # Required for each makefile to inherit from the parent
37 | #
38 |
39 | INCLUDES := $(INCLUDES) -I $(PDIR)include
40 | INCLUDES += -I ./
41 | INCLUDES += -I ../wofs
42 | PDIR := ../$(PDIR)
43 | sinclude $(PDIR)Makefile
44 |
45 |
--------------------------------------------------------------------------------
/app/libc/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 |
--------------------------------------------------------------------------------
/app/libc/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 |
--------------------------------------------------------------------------------
/app/libc/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 |
--------------------------------------------------------------------------------
/app/libc/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 |
--------------------------------------------------------------------------------
/app/libc/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 |
--------------------------------------------------------------------------------
/app/libc/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 |
--------------------------------------------------------------------------------
/app/libc/c_signal.h:
--------------------------------------------------------------------------------
1 | #ifndef _C_SIGNAL_H_
2 | #define _C_SIGNAL_H_
3 |
4 | #include
5 |
6 | #endif /* _C_SIGNAL_H_ */
7 |
--------------------------------------------------------------------------------
/app/libc/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 |
--------------------------------------------------------------------------------
/app/libc/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 |
--------------------------------------------------------------------------------
/app/libc/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 | #define EXIT_FAILURE 1
14 | #define EXIT_SUCCESS 0
15 |
16 | #undef __RAND_MAX
17 | #if __INT_MAX__ == 32767
18 | #define __RAND_MAX 32767
19 | #else
20 | #define __RAND_MAX 0x7fffffff
21 | #endif
22 | #define RAND_MAX __RAND_MAX
23 |
24 | #ifndef mem_realloc
25 | #define mem_realloc pvPortRealloc
26 | #endif
27 | #ifndef os_realloc
28 | #define os_realloc(p, s) mem_realloc((p), (s))
29 | #endif
30 |
31 | #define c_free os_free
32 | #define c_malloc os_malloc
33 | #define c_zalloc os_zalloc
34 | #define c_realloc os_realloc
35 |
36 | #define c_abs abs
37 | #define c_atoi atoi
38 | //#define c_strtod strtod
39 | #define c_strtol strtol
40 | #define c_strtoul strtoul
41 |
42 | // int c_abs(int);
43 |
44 | // void c_exit(int);
45 |
46 | // c_getenv() get env "LUA_INIT" string for lua initialization.
47 | const char *c_getenv(const char *__string);
48 |
49 | // void *c_malloc(size_t __size);
50 | // void *c_zalloc(size_t __size);
51 | // void c_free(void *);
52 |
53 | // int c_rand(void);
54 | // void c_srand(unsigned int __seed);
55 |
56 | // int c_atoi(const char *__nptr);
57 | double c_strtod(const char *__n, char **__end_PTR);
58 | // // long c_strtol(const char *__n, char **__end_PTR, int __base);
59 | // unsigned long c_strtoul(const char *__n, char **__end_PTR, int __base);
60 | // // long long c_strtoll(const char *__n, char **__end_PTR, int __base);
61 |
62 | #endif /* _C_STDLIB_H_ */
63 |
--------------------------------------------------------------------------------
/app/libc/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 |
--------------------------------------------------------------------------------
/app/libc/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 |
12 | #ifndef NULL
13 | #define NULL 0
14 | #endif
15 |
16 | #define c_memcmp os_memcmp
17 | #define c_memcpy os_memcpy
18 | #define c_memset os_memset
19 |
20 | #define c_strcat os_strcat
21 | #define c_strchr os_strchr
22 | #define c_strcmp os_strcmp
23 | #define c_strcpy os_strcpy
24 | #define c_strlen os_strlen
25 | #define c_strncmp os_strncmp
26 | #define c_strncpy os_strncpy
27 | // #define c_strstr os_strstr
28 | #define c_strncasecmp c_strncmp
29 |
30 | #define c_strstr strstr
31 | #define c_strncat strncat
32 | #define c_strcspn strcspn
33 | #define c_strpbrk strpbrk
34 | #define c_strcoll strcoll
35 | #define c_strrchr strrchr
36 |
37 | // const char *c_strstr(const char * __s1, const char * __s2);
38 | // char *c_strncat(char * __restrict /*s1*/, const char * __restrict /*s2*/, size_t n);
39 | // size_t c_strcspn(const char * s1, const char * s2);
40 | // const char *c_strpbrk(const char * /*s1*/, const char * /*s2*/);
41 | // int c_strcoll(const char * /*s1*/, const char * /*s2*/);
42 |
43 | #endif /* _C_STRING_H_ */
44 |
--------------------------------------------------------------------------------
/app/lua/COPYRIGHT:
--------------------------------------------------------------------------------
1 | Lua License
2 | -----------
3 |
4 | Lua is licensed under the terms of the MIT license reproduced below.
5 | This means that Lua is free software and can be used for both academic
6 | and commercial purposes at absolutely no cost.
7 |
8 | For details and rationale, see http://www.lua.org/license.html .
9 |
10 | ===============================================================================
11 |
12 | Copyright (C) 1994-2008 Lua.org, PUC-Rio.
13 |
14 | Permission is hereby granted, free of charge, to any person obtaining a copy
15 | of this software and associated documentation files (the "Software"), to deal
16 | in the Software without restriction, including without limitation the rights
17 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 | copies of the Software, and to permit persons to whom the Software is
19 | furnished to do so, subject to the following conditions:
20 |
21 | The above copyright notice and this permission notice shall be included in
22 | all copies or substantial portions of the Software.
23 |
24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 | THE SOFTWARE.
31 |
32 | ===============================================================================
33 |
34 | (end of COPYRIGHT)
35 |
--------------------------------------------------------------------------------
/app/lua/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = liblua.a
16 | endif
17 |
18 | #############################################################
19 | # Configuration i.e. compile options etc.
20 | # Target specific stuff (defines etc.) goes in here!
21 | # Generally values applying to a tree are captured in the
22 | # makefile at its root level - these are then overridden
23 | # for a subtree within the makefile rooted therein
24 | #
25 | #DEFINES +=
26 |
27 | #############################################################
28 | # Recursion Magic - Don't touch this!!
29 | #
30 | # Each subtree potentially has an include directory
31 | # corresponding to the common APIs applicable to modules
32 | # rooted at that subtree. Accordingly, the INCLUDE PATH
33 | # of a module can only contain the include directories up
34 | # its parent path, and not its siblings
35 | #
36 | # Required for each makefile to inherit from the parent
37 | #
38 |
39 | INCLUDES := $(INCLUDES) -I $(PDIR)include
40 | INCLUDES += -I ./
41 | INCLUDES += -I ../wofs
42 | INCLUDES += -I ../spiffs
43 | INCLUDES += -I ../libc
44 | INCLUDES += -I ../modules
45 | INCLUDES += -I ../platform
46 | PDIR := ../$(PDIR)
47 | sinclude $(PDIR)Makefile
48 |
49 |
--------------------------------------------------------------------------------
/app/lua/compiler.h:
--------------------------------------------------------------------------------
1 | /**
2 | * define start/end address of ro data.
3 | * different compiler with different implementation.
4 | */
5 |
6 | #ifndef __COMPILER_H__
7 | #define __COMPILER_H__
8 |
9 | #if defined(__CC_ARM) // armcc
10 |
11 | //#warning "Please check scatter file to ensure rodata is in ER_IROM1 region."
12 |
13 | /* symbols reference to the scatter file */
14 | extern char Image$$ER_IROM1$$Base;
15 | extern char Image$$ER_IROM1$$Limit;
16 |
17 | #define RODATA_START_ADDRESS (&Image$$ER_IROM1$$Base)
18 | #define RODATA_END_ADDRESS (&Image$$ER_IROM1$$Limit)
19 |
20 | #elif defined(__GNUC__) // gcc
21 |
22 | //#warning "Please check linker script to ensure rodata is between _stext and _etext."
23 |
24 | /* symbols defined in linker script */
25 | // extern char _rodata_start;
26 | // extern char _rodata_end;
27 | extern char _irom0_text_start;
28 | extern char _irom0_text_end;
29 | // modify linker script to ensure rodata and rodata1 is between _rodata_start and _rodata_end.
30 | // #define RODATA_START_ADDRESS (&_rodata_start)
31 | // #define RODATA_END_ADDRESS (&_rodata_end)
32 | #define RODATA_START_ADDRESS ((char*)0x40000000) // (&_irom0_text_start)
33 | #define RODATA_END_ADDRESS (&_irom0_text_end)
34 |
35 | #else // other compilers
36 |
37 | /* Firstly, modify rodata's start/end address. Then, comment the line below */
38 | #error "Please modify RODATA_START_ADDRESS and RODATA_END_ADDRESS below."
39 |
40 | /* Perhaps you can use start/end address of flash */
41 | #define RODATA_START_ADDRESS ((char*)0x40200000)
42 | #define RODATA_END_ADDRESS ((char*)0x40280000)
43 |
44 | #endif
45 |
46 | #endif // __COMPILER_H__
47 |
48 |
--------------------------------------------------------------------------------
/app/lua/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 |
--------------------------------------------------------------------------------
/app/lua/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 | #define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
17 |
18 | #define resethookcount(L) (L->hookcount = L->basehookcount)
19 |
20 |
21 | LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o,
22 | const char *opname);
23 | LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
24 | LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1,
25 | const TValue *p2);
26 | LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1,
27 | const TValue *p2);
28 | LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...);
29 | LUAI_FUNC void luaG_errormsg (lua_State *L);
30 | LUAI_FUNC int luaG_checkcode (const Proto *pt);
31 | LUAI_FUNC int luaG_checkopenop (Instruction i);
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/app/lua/ldo.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Stack and Call structure of Lua
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 | #ifndef ldo_h
8 | #define ldo_h
9 |
10 |
11 | #include "lobject.h"
12 | #include "lstate.h"
13 | #include "lzio.h"
14 |
15 |
16 | #define luaD_checkstack(L,n) \
17 | if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \
18 | luaD_growstack(L, n); \
19 | else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1));
20 |
21 |
22 | #define incr_top(L) {luaD_checkstack(L,1); L->top++;}
23 |
24 | #define savestack(L,p) ((char *)(p) - (char *)L->stack)
25 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n)))
26 |
27 | #define saveci(L,p) ((char *)(p) - (char *)L->base_ci)
28 | #define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n)))
29 |
30 |
31 | /* results from luaD_precall */
32 | #define PCRLUA 0 /* initiated a call to a Lua function */
33 | #define PCRC 1 /* did a call to a C function */
34 | #define PCRYIELD 2 /* C funtion yielded */
35 |
36 |
37 | /* type of protected functions, to be ran by `runprotected' */
38 | typedef void (*Pfunc) (lua_State *L, void *ud);
39 |
40 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name);
41 | LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line);
42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults);
43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
44 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
45 | ptrdiff_t oldtop, ptrdiff_t ef);
46 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult);
47 | LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize);
48 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);
49 | LUAI_FUNC void luaD_growstack (lua_State *L, int n);
50 |
51 | LUAI_FUNC void luaD_throw (lua_State *L, int errcode);
52 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
53 |
54 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
55 |
56 | #endif
57 |
58 |
--------------------------------------------------------------------------------
/app/lua/legc.c:
--------------------------------------------------------------------------------
1 | // Lua EGC (Emergeny Garbage Collector) interface
2 |
3 | #include "legc.h"
4 | #include "lstate.h"
5 | #include "c_types.h"
6 |
7 | void legc_set_mode(lua_State *L, int mode, unsigned limit) {
8 | global_State *g = G(L);
9 |
10 | g->egcmode = mode;
11 | g->memlimit = limit;
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/app/lua/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 |
--------------------------------------------------------------------------------
/app/lua/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 |
--------------------------------------------------------------------------------
/app/lua/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 | //#include "c_stddef.h"
12 |
13 | #include "llimits.h"
14 | #include "lua.h"
15 |
16 | #define MEMERRMSG "not enough memory"
17 |
18 |
19 | #define luaM_reallocv(L,b,on,n,e) \
20 | ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \
21 | luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
22 | luaM_toobig(L))
23 |
24 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
25 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
26 | #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t))
27 |
28 | #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t))
29 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t)))
30 | #define luaM_newvector(L,n,t) \
31 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
32 |
33 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \
34 | if ((nelems)+1 > (size)) \
35 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
36 |
37 | #define luaM_reallocvector(L, v,oldn,n,t) \
38 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
39 |
40 |
41 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
42 | size_t size);
43 | LUAI_FUNC void *luaM_toobig (lua_State *L);
44 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
45 | size_t size_elem, int limit,
46 | const char *errormsg);
47 |
48 | #endif
49 |
50 |
--------------------------------------------------------------------------------
/app/lua/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 ICACHE_RODATA_ATTR
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 |
--------------------------------------------------------------------------------
/app/lua/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, c_strlen(s)))
21 | #define luaS_newro(L, s) (luaS_newrolstr(L, s, c_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 |
--------------------------------------------------------------------------------
/app/lua/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 |
--------------------------------------------------------------------------------
/app/lua/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 |
--------------------------------------------------------------------------------
/app/lua/lualib.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $
3 | ** Lua standard libraries
4 | ** See Copyright Notice in lua.h
5 | */
6 |
7 |
8 | #ifndef lualib_h
9 | #define lualib_h
10 |
11 | #include "lua.h"
12 |
13 |
14 | /* Key to file-handle type */
15 | #define LUA_FILEHANDLE "INT"
16 |
17 |
18 | #define LUA_COLIBNAME "coroutine"
19 | LUALIB_API int (luaopen_base) (lua_State *L);
20 |
21 | #define LUA_TABLIBNAME "table"
22 | LUALIB_API int (luaopen_table) (lua_State *L);
23 |
24 | #define LUA_IOLIBNAME "io"
25 | LUALIB_API int (luaopen_io) (lua_State *L);
26 |
27 | #define LUA_OSLIBNAME "os"
28 | LUALIB_API int (luaopen_os) (lua_State *L);
29 |
30 | #define LUA_STRLIBNAME "string"
31 | LUALIB_API int (luaopen_string) (lua_State *L);
32 |
33 | #define LUA_MATHLIBNAME "math"
34 | LUALIB_API int (luaopen_math) (lua_State *L);
35 |
36 | #define LUA_DBLIBNAME "debug"
37 | LUALIB_API int (luaopen_debug) (lua_State *L);
38 |
39 | #define LUA_LOADLIBNAME "package"
40 | LUALIB_API int (luaopen_package) (lua_State *L);
41 |
42 |
43 | /* open all previous libraries */
44 | LUALIB_API void (luaL_openlibs) (lua_State *L);
45 |
46 |
47 |
48 | #ifndef lua_assert
49 | #define lua_assert(x) ((void)0)
50 | #endif
51 |
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/app/lua/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 "c_stdint.h"
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 |
--------------------------------------------------------------------------------
/app/lua/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 |
--------------------------------------------------------------------------------
/app/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 | #include "c_string.h"
9 |
10 | #define lzio_c
11 | #define LUA_CORE
12 |
13 | #include "lua.h"
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 | c_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 |
--------------------------------------------------------------------------------
/app/main/.gitignore:
--------------------------------------------------------------------------------
1 | /00
2 |
--------------------------------------------------------------------------------
/app/main/Include/app_main.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * FileName: aap_main.h
3 | * Description: Alternate SDK (libmain.a)
4 | * Author: PV`
5 | * (c) PV` 2015
6 | ******************************************************************************/
7 |
8 | #ifndef _INCLUDE_APP_MAIN_H_
9 | #define _INCLUDE_APP_MAIN_H_
10 |
11 | #include "libmain.h"
12 |
13 | extern struct s_info info; // ip,mask,gw,mac AP, ST
14 | extern init_done_cb_t done_cb;
15 | extern ETSTimer check_timeouts_timer; // timer_lwip
16 | extern uint8 user_init_flag;
17 | //=============================================================================
18 | // funcs libmain.a: app_main.o
19 | //-----------------------------------------------------------------------------
20 | void sflash_something(uint32 flash_speed);
21 | void read_macaddr_from_otp(uint8 *mac);
22 | void user_uart_wait_tx_fifo_empty(uint32 n, uint32 x);
23 | void startup(void);
24 | void read_wifi_config(void);
25 | void init_wifi(uint8 * init_data, uint8 * mac);
26 | void uart_wait_tx_fifo_empty(void);
27 | //-----------------------------------------------------------------------------
28 |
29 |
30 | #endif /* _INCLUDE_APP_MAIN_H_ */
31 |
--------------------------------------------------------------------------------
/app/main/Include/bios.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * FileName: bios.h
3 | * Description: funcs in ROM-BIOS
4 | * Alternate SDK
5 | * Author: PV`
6 | * (c) PV` 2015
7 | *******************************************************************************/
8 | #ifndef _INCLUDE_BIOS_H_
9 | #define _INCLUDE_BIOS_H_
10 |
11 | #include "bios/spiflash.h"
12 | #include "bios/cha1.h"
13 | #include "bios/ets.h"
14 | #include "bios/gpio.h"
15 | #include "bios/uart.h"
16 | #include "bios/vectors.h"
17 | #include "bios/xthal.h"
18 | #include "bios/xtos.h"
19 | #include "bios/rtc_dtm.h"
20 | #include "bios/add_funcs.h"
21 |
22 | #endif // _INCLUDE_BIOS_H_
23 |
--------------------------------------------------------------------------------
/app/main/Include/bios/add_funcs.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * FileName: add_funcs.h
3 | * Description: Do not sorted functions ROM-BIOS
4 | * Alternate SDK
5 | * Author: PV`
6 | * (c) PV` 2015
7 | *******************************************************************************/
8 | #ifndef _INCLUDE_BIOS_ADD_FUNCS_H_
9 | #define _INCLUDE_BIOS_ADD_FUNCS_H_
10 |
11 | int rom_get_power_db(void);
12 | void rom_en_pwdet(int);
13 | void rom_i2c_writeReg(uint32 block, uint32 host_id, uint32 reg_add, uint32 data);
14 | void rom_i2c_writeReg_Mask(uint32 block, uint32 host_id, uint32 reg_add, uint32 Msb, uint32 Lsb, uint32 indata);
15 | uint8 rom_i2c_readReg_Mask(uint32 block, uint32 host_id, uint32 reg_add, uint32 Msb, uint32 Lsb);
16 | uint8 rom_i2c_readReg(uint32 block, uint32 host_id, uint32 reg_add);
17 |
18 |
19 | #endif /* _INCLUDE_BIOS_ADD_FUNCS_H_ */
20 |
--------------------------------------------------------------------------------
/app/main/Include/bios/mem.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * FileName: mem.h
3 | * Description: mem funcs in ROM-BIOS
4 | * Alternate SDK
5 | * Author: PV`
6 | * (c) PV` 2015
7 | *******************************************************************************/
8 | #ifndef _BIOS_MEM_H_
9 | #define _BIOS_MEM_H_
10 |
11 | #include "bios/c_types.h"
12 | /* WARNING !!! mem_xxx use size < 4096 !!! */
13 | extern void mem_init(void * start_addr); // uint8 *
14 | extern void * mem_malloc(uint16 size); // size < 4096
15 | extern void * mem_calloc(uint16 n, uint16 count); // n*count < 4096
16 | extern void * mem_zalloc(uint16 size); // size < 4096, = mem_calloc(1, size);
17 | extern void * mem_realloc(void * p, uint16 size);
18 | extern void * mem_trim(void * p, uint16 size);
19 | extern void mem_free(uint8 * x);
20 |
21 | /*
22 | PROVIDE ( mem_calloc = 0x40001c2c );
23 | PROVIDE ( mem_free = 0x400019e0 );
24 | PROVIDE ( mem_init = 0x40001998 );
25 | PROVIDE ( mem_malloc = 0x40001b40 );
26 | PROVIDE ( mem_realloc = 0x40001c6c );
27 | PROVIDE ( mem_trim = 0x40001a14 );
28 | PROVIDE ( mem_zalloc = 0x40001c58 );
29 | */
30 | #endif /* _BIOS_MEM_H_ */
31 |
--------------------------------------------------------------------------------
/app/main/Include/bios/vectors.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * FileName: Vectors.h
3 | * Description: Vectors funcs in ROM-BIOS
4 | * Alternate SDK
5 | * Author: PV`
6 | * (c) PV` 2015
7 | *******************************************************************************/
8 |
9 | #ifndef _INCLUDE_BIOS_VECTORS_H_
10 | #define _INCLUDE_BIOS_VECTORS_H_
11 |
12 | /*
13 | PROVIDE ( _DebugExceptionVector = 0x40000010 );
14 | PROVIDE ( _NMIExceptionVector = 0x40000020 );
15 | PROVIDE ( _KernelExceptionVector = 0x40000030 );
16 | PROVIDE ( _UserExceptionVector = 0x40000050 );
17 | PROVIDE ( _DoubleExceptionVector = 0x40000070 );
18 | #PROVIDE ( _ResetVector = 0x40000080 );
19 | PROVIDE ( _ResetHandler = 0x400000a4 );
20 | */
21 |
22 | void _ResetVector(void);
23 |
24 | #endif /* _INCLUDE_BIOS_VECTORS_H_ */
25 |
--------------------------------------------------------------------------------
/app/main/Include/eagle_lwip_if.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * FileName: eagle_lwip_if.h
3 | * Description: Alternate SDK (libmain.a)
4 | * Author: PV`
5 | * (c) PV` 2015
6 | *******************************************************************************/
7 | #ifndef _INCLUDE_EAGLE_LWIP_IF_H_
8 | #define _INCLUDE_EAGLE_LWIP_IF_H_
9 |
10 | #include "libmain.h"
11 | #include "lwip/pbuf.h"
12 | #include "lwip/ip_addr.h"
13 |
14 | struct myif_state {
15 | struct netif *myif; //+0
16 | uint32_t padding[(176-4)>>2]; //+4
17 | uint32_t dhcps_if; //+176 // + 0xB0
18 | };
19 |
20 | err_t ieee80211_output_pbuf(struct netif *netif, struct pbuf *p);
21 | struct netif *eagle_lwip_getif(int n);
22 | struct netif *eagle_lwip_if_alloc(struct myif_state *state, u8_t hw[6], struct ip_info * ips);
23 |
24 |
25 | #endif /* _INCLUDE_EAGLE_LWIP_IF_H_ */
26 |
--------------------------------------------------------------------------------
/app/main/Include/fatal_errs.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * FileName: libmain.h
3 | * Description: Alternate SDK (libmain.a)
4 | * Author: PV`
5 | * (c) PV` 2015
6 | *******************************************************************************/
7 |
8 | #ifndef _INCLUDE_FATAL_ERRS_H_
9 | #define _INCLUDE_FATAL_ERRS_H_
10 |
11 |
12 | #define RST_EVENT_WDT 1
13 | #define RST_EVENT_EXP 2
14 | #define RST_EVENT_SOFT_RESET 3
15 | #define RST_EVENT_DEEP_SLEEP 4
16 | #define RST_EVENT_RES 8
17 | #define FATAL_ERR_R6PHY 9 // "register_chipv6_phy"
18 | #define RST_EVENT_MAX 32
19 |
20 |
21 | void fatal_error(uint32_t errn, void *addr, void *txt);
22 |
23 | #endif // _INCLUDE_FATAL_ERRS_H_
24 |
--------------------------------------------------------------------------------
/app/main/Include/flash.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * FileName: spi_flash.h
3 | * Description: FLASH
4 | * Alternate SDK
5 | * Author: PV`
6 | * (c) PV` 2015
7 | *******************************************************************************/
8 |
9 | #ifndef SPI_FLASH_H
10 | #define SPI_FLASH_H
11 |
12 | #include "bios/spiflash.h"
13 |
14 | //#define USE_MAX_IRAM 48k
15 |
16 | #define SPI_FLASH_SEC_SIZE 4096
17 |
18 | uint32 spi_flash_get_id(void);
19 | SpiFlashOpResult spi_flash_read_status(uint32_t * sta);
20 | SpiFlashOpResult spi_flash_write_status(uint32_t sta);
21 | SpiFlashOpResult spi_flash_erase_sector(uint16 sec);
22 | SpiFlashOpResult spi_flash_write(uint32 faddr, uint32 *src_addr, uint32 size);
23 | SpiFlashOpResult spi_flash_read(uint32 faddr, void *des, uint32 size);
24 | SpiFlashOpResult spi_flash_erase_block(uint32 blk);
25 |
26 | uint32 spi_flash_real_size(void);
27 |
28 | #ifdef USE_OVERLAP_MODE
29 |
30 | typedef SpiFlashOpResult (* user_spi_flash_read)(
31 | SpiFlashChip *spi,
32 | uint32 src_addr,
33 | uint32 *des_addr,
34 | uint32 size);
35 |
36 | extern user_spi_flash_read flash_read;
37 |
38 | void spi_flash_set_read_func(user_spi_flash_read read);
39 |
40 | #endif
41 |
42 | #define USE_MSPI_FLASH_O 1 // включена "песочница" для SDK в 512 килобайт flash. Включить доступ к flash до 16Мбайт включительно
43 |
44 | #define MASK_ADDR_FLASH_ICACHE_DATA 0xfffff
45 |
46 | #define spi_flash_read_byte(faddr, dest) spi_flash_read(faddr, dest, 1);
47 |
48 | #ifdef USE_MSPI_FLASH_O
49 |
50 | #define open_16m() flashchip->chip_size = FLASH_MAX_SIZE
51 | #define close_16m() flashchip->chip_size = FLASH_MIN_SIZE
52 |
53 | #else
54 |
55 | #define open_16m()
56 | #define close_16m()
57 |
58 | #endif
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/app/main/Include/os_printf.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * FileName: os_printf.h
3 | * Description: Alternate SDK (libmain.a)
4 | * Author: PV`
5 | * (c) PV` 2015
6 | *******************************************************************************/
7 |
8 | #ifndef _INCLUDE_OS_PRINTF_H_
9 | #define _INCLUDE_OS_PRINTF_H_
10 |
11 | //int rom_printf(const char *format, ...) ICACHE_FLASH_ATTR;
12 | void _sprintf_out(char c) ICACHE_FLASH_ATTR;
13 | int ets_sprintf(char *str, const char *format, ...) ICACHE_FLASH_ATTR;
14 |
15 | #endif /* _INCLUDE_OS_PRINTF_H_ */
16 |
--------------------------------------------------------------------------------
/app/main/Include/phy/phy.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * FileName: phy.h
3 | * Description: Reverse SDK 1.0.0/1.1.0 (phy.a)
4 | * Author: PV`
5 | *******************************************************************************/
6 |
7 | #ifndef _LIBS_PHY_H_
8 | #define _LIBS_PHY_H_
9 |
10 | #include "bios/rom_phy.h"
11 |
12 | typedef void (* phy_func_var_int_int)(int ch, int n);
13 | typedef void (* phy_func_var_int)(int);
14 | typedef void (* phy_func_void)(void);
15 |
16 | struct phy_funcs{
17 | phy_func_var_int_int rf_init; // +00 = int chip_v6_rf_init(int ch, int n);
18 | phy_func_var_int set_chanfreq; // +04 = void chip_v6_set_chanfreq(int chfr);
19 | phy_func_var_int set_chan; // +08 = void chip_v6_set_chan(int ch);
20 | phy_func_void unset_chanfreq; // +12 = int chip_v6_unset_chanfreq(void) // return 0;
21 | phy_func_void enable_cca; // +16 = void rom_chip_v5_enable_cca(void) // *0x60009B00 &= ~0x10000000;
22 | phy_func_void disable_cca; // +20 = void rom_chip_v5_disable_cca(void) // *0x60009B00 |= 0x10000000;
23 | phy_func_var_int initialize_bb; // +24 = int chip_v6_initialize_bb(void)
24 | phy_func_void set_sense; // +28 = void chip_v6_set_sense(void)
25 | };
26 |
27 | extern struct phy_func_tab * g_phyFuns;
28 | extern uint8 chip6_phy_init_ctrl[3];
29 |
30 | void register_phy_ops(struct phy_funcs * phy_base);
31 | void register_get_phy_addr(struct phy_funcs * prt);
32 | int phy_change_channel(int chfr);
33 | uint32 phy_get_mactime(void);
34 | int chip_v6_set_chanfreq(uint32 chfr);
35 | void phy_init(int8 ch, int n);
36 | void RFChannelSel(int8 ch);
37 | void phy_delete_channel(void);
38 | void phy_enable_agc(void);
39 | void phy_disable_agc(void);
40 | void phy_initialize_bb(int n);
41 | void phy_set_sense(void);
42 |
43 |
44 | #endif /* _LIBS_PHY_H_ */
45 |
46 |
--------------------------------------------------------------------------------
/app/main/Include/sdk/mem_manager.h:
--------------------------------------------------------------------------------
1 | #ifndef __MEM_H__
2 | #define __MEM_H__
3 |
4 | // в модуле mem_manager.o
5 |
6 | void *pvPortMalloc( size_t xWantedSize );
7 | void vPortFree( void *pv );
8 | void *pvPortZalloc(size_t size);
9 | void *pvPortCalloc(unsigned int n, unsigned int count);
10 | void *pvPortRealloc(void * p, size_t size);
11 | size_t xPortGetFreeHeapSize(void);
12 | void prvHeapInit(void);
13 |
14 | #define os_malloc pvPortMalloc
15 | #define os_free vPortFree
16 | #define os_zalloc pvPortZalloc
17 | #define os_calloc pvPortCalloc
18 | #define os_realloc pvPortRealloc
19 | #define system_get_free_heap_size xPortGetFreeHeapSize
20 |
21 | #endif // __MEM_H__
22 |
23 |
--------------------------------------------------------------------------------
/app/main/Include/sdk/os_type.h:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * mapping to ETS structures
4 | *
5 | */
6 | #ifndef _OS_TYPES_H_
7 | #define _OS_TYPES_H_
8 |
9 | #include "sdk/ets_sys.h"
10 |
11 | #define os_signal_t ETSSignal
12 | #define os_param_t ETSParam
13 | #define os_event_t ETSEvent
14 | #define os_task_t ETSTask
15 | #define os_timer_t ETSTimer
16 | #define os_timer_func_t ETSTimerFunc
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/app/main/Include/sdk/osapi.h:
--------------------------------------------------------------------------------
1 | /*
2 | */
3 |
4 | #ifndef _OSAPI_H_
5 | #define _OSAPI_H_
6 |
7 | #include
8 | #include "user_config.h"
9 |
10 | #define os_bzero ets_bzero
11 | #define os_delay_us ets_delay_us
12 | #define os_install_putc1 ets_install_putc1
13 | #define os_install_putc2 ets_install_putc2
14 | #define os_intr_lock ets_intr_lock
15 | #define os_intr_unlock ets_intr_unlock
16 | #define os_isr_attach ets_isr_attach
17 | #define os_isr_mask ets_isr_mask
18 | #define os_isr_unmask ets_isr_unmask
19 | #define os_memcmp ets_memcmp
20 | #define os_memcpy ets_memcpy
21 | #define os_memmove ets_memmove
22 | #define os_memset ets_memset
23 | #define os_putc ets_putc
24 | #define os_str2macaddr ets_str2macaddr
25 | #define os_strcat strcat
26 | #define os_strchr strchr
27 | #define os_strcmp ets_strcmp
28 | #define os_strcpy ets_strcpy
29 | #define os_strlen ets_strlen
30 | #define os_strncmp ets_strncmp
31 | #define os_strncpy ets_strncpy
32 | #define os_strstr ets_strstr
33 | #ifdef USE_US_TIMER
34 | #define os_timer_arm_us(a, b, c) ets_timer_arm_new(a, b, c, 0)
35 | #endif
36 | #define os_timer_arm(a, b, c) ets_timer_arm_new(a, b, c, 1)
37 | #define os_timer_disarm ets_timer_disarm
38 | #define os_timer_done ets_timer_done
39 | #define os_timer_handler_isr ets_timer_handler_isr
40 | #define os_timer_init ets_timer_init
41 | #define os_timer_setfn ets_timer_setfn
42 |
43 | #define os_sprintf ets_sprintf
44 | #define os_update_cpu_frequency ets_update_cpu_frequency
45 |
46 | #if 0
47 | #define os_printf(fmt, ...) do { \
48 | static const char flash_str[] ICACHE_RODATA_ATTR = fmt; \
49 | os_printf_plus(flash_str, ##__VA_ARGS__); \
50 | } while(0)
51 | #else
52 | #define os_printf os_printf_plus
53 | #endif
54 |
55 | #endif
56 |
57 |
--------------------------------------------------------------------------------
/app/main/Include/wdt.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * FileName: wdt.h
3 | * Description: Alternate SDK (libmain.a)
4 | * Author: PV`
5 | * (c) PV` 2015
6 | * ver 0.0.0 (b0)
7 | *******************************************************************************/
8 |
9 | #ifndef _INCLUDE_WDT_H_
10 | #define _INCLUDE_WDT_H_
11 |
12 | #include "ets_sys.h"
13 | #include "fatal_errs.h"
14 |
15 |
16 | #if SDK_VERSION >= 1119 // (SDK 1.1.1..1.1.2)
17 | void wdt_init(int flg);
18 | #else
19 | void wdt_init(void);
20 | void wdt_feed(void);
21 | void wdt_task(ETSEvent *e);
22 | #endif
23 |
24 | void default_exception_handler(void);
25 | void store_exception_error(uint32_t errn);
26 |
27 | void os_print_reset_error(void);
28 |
29 |
30 | #endif /* _INCLUDE_WDT_H_ */
31 |
--------------------------------------------------------------------------------
/app/main/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = libaddmmain.a
16 | endif
17 |
18 | CCFLAGS += -mno-serialize-volatile
19 |
20 |
21 | #############################################################
22 | # Configuration i.e. compile options etc.
23 | # Target specific stuff (defines etc.) goes in here!
24 | # Generally values applying to a tree are captured in the
25 | # makefile at its root level - these are then overridden
26 | # for a subtree within the makefile rooted therein
27 | #
28 | #DEFINES +=
29 |
30 | #############################################################
31 | # Recursion Magic - Don't touch this!!
32 | #
33 | # Each subtree potentially has an include directory
34 | # corresponding to the common APIs applicable to modules
35 | # rooted at that subtree. Accordingly, the INCLUDE PATH
36 | # of a module can only contain the include directories up
37 | # its parent path, and not its siblings
38 | #
39 | # Required for each makefile to inherit from the parent
40 | #
41 |
42 | INCLUDES := $(INCLUDES) -I $(PDIR)include
43 | INCLUDES += -I ./include
44 | INCLUDES += -I ../libc
45 | PDIR := ../$(PDIR)
46 | sinclude $(PDIR)Makefile
47 |
48 |
--------------------------------------------------------------------------------
/app/main/delay.c:
--------------------------------------------------------------------------------
1 | /*
2 | * delay.c
3 | *
4 | * Created on: 09 июля 2015 г.
5 | * Author: pvvx
6 | */
7 | #include "user_config.h"
8 | #include "bios.h"
9 | #include "hw/eagle_soc.h"
10 | #include "hw/esp8266.h"
11 | #include "sdk/osapi.h"
12 | #include "sdk/add_sdk_func.h"
13 |
14 | uint32 tt DATA_IRAM_ATTR;
15 | extern volatile uint32 ets_run_ret DATA_IRAM_ATTR;
16 |
17 | void ICACHE_RAM_ATTR delay_wait_cb(void *px)
18 | {
19 | tt = phy_get_mactime();
20 | ets_run_ret = 1;
21 | }
22 |
23 | void ICACHE_RAM_ATTR task_delay_us(uint32 us)
24 | {
25 | if(us < 512) ets_delay_us(us);
26 | else {
27 | ETSTimer delay_timer;
28 | ets_timer_disarm(&delay_timer);
29 | ets_timer_setfn(&delay_timer, (ETSTimerFunc *)(delay_wait_cb), NULL);
30 | ets_timer_arm_new(&delay_timer, us - 128, 0, 0);
31 | ets_run();
32 | }
33 | }
34 |
35 | void ICACHE_RAM_ATTR run_sdk_tasks(void)
36 | {
37 | uint32 t = phy_get_mactime();
38 | if(t-tt > 20480) {
39 | ETSTimer delay_timer;
40 | ets_timer_disarm(&delay_timer);
41 | ets_timer_setfn(&delay_timer, (ETSTimerFunc *)(delay_wait_cb), NULL);
42 | ets_timer_arm_new(&delay_timer, 1024, 0, 0);
43 | ets_run();
44 | tt=t;
45 | }
46 | }
47 |
48 |
49 |
--------------------------------------------------------------------------------
/app/main/phy_chip_v6_unused.c:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * FileName: phy_chip_v6_unused.c
3 | * Description: Alternate SDK (libphy.a)
4 | * Author: PV`
5 | * (c) PV` 2015
6 | *******************************************************************************/
7 | #include "user_config.h"
8 | #include "bios.h"
9 | #include "hw/esp8266.h"
10 | #include "phy/phy.h"
11 |
12 | // (!) not use
13 |
14 | // from phy_chip_v6.o
15 | void ICACHE_FLASH_ATTR chip_v6_set_sense(void)
16 | {
17 | // ret.n
18 | }
19 |
20 | /*
21 | void chip_v6_get_sense(void)
22 | {
23 | // ret.n
24 | }
25 | */
26 |
27 | // from phy_chip_v6.o
28 | int ICACHE_FLASH_ATTR chip_v6_unset_chanfreq(void)
29 | {
30 | return 0;
31 | }
32 |
33 | /*
34 | // from slop_test()
35 | void ICACHE_FLASH_ATTR slop_wdt_feed(void)
36 | {
37 | WDT_FEED = WDT_FEED_MAGIC;
38 | }
39 |
40 |
41 | int data_collect(void)
42 | {
43 | ???
44 | }
45 |
46 | void operation_test(void)
47 | {
48 | ???
49 | }
50 |
51 |
52 |
53 | void slop_test(void)
54 | {
55 |
56 | os_printf_plus("slop_test\n");
57 | CLK_PRE_PORT |= 1;
58 | i2c_writeReg_Mask(106, 2, 8, 4, 0, 0);
59 | uint32 x = IOREG(0x3FF20C00);
60 | RFChannelSel(14);
61 | int i;
62 | for(i=0; i<200; i++) {
63 | slop_wdt_feed();
64 | IOREG(0x60000738) = operation_test();
65 | pm_set_sleep_mode(2);
66 | pm_wakeup_opt(8, 0);
67 | pm_set_sleep_cycles(170);
68 | x = IOREG(0x3FF20C00);
69 | pm_goto_sleep(2);
70 | pm_wait4wakeup(2);
71 | pm_wakeup_init(2, 0);
72 | x = IOREG(0x3FF20C00);
73 | }
74 | }
75 |
76 | void wd_reset_cnt(void)
77 | {
78 | uint32 x = rtc_get_reset_reason();
79 | if(x == 4) os_printf("wd_reset %d\n", RTC_RAM_BASE[0xFC>>2]);
80 | else if(x == 2 || x != 1) {
81 | RTC_RAM_BASE[0xFC>>2] = 0;
82 | os_printf("wd_reset %d\n", RTC_RAM_BASE[0xFC>>2]);
83 | }
84 | }
85 | */
86 |
--------------------------------------------------------------------------------
/app/main/wpa_debug.c:
--------------------------------------------------------------------------------
1 | /*
2 | * FileName: wpa_debug.c
3 | * Description: Alternate SDK (libwpa.a)
4 | * (c) pvvx 2015
5 | */
6 | #include "user_config.h"
7 | #include "bios.h"
8 |
9 | unsigned int ICACHE_FLASH_ATTR eloop_cancel_timeout(void)
10 | {
11 | return 0;
12 | }
13 |
14 | unsigned int ICACHE_FLASH_ATTR eloop_register_timeout(void)
15 | {
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/app/modules/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = libmodules.a
16 | endif
17 |
18 | #############################################################
19 | # Configuration i.e. compile options etc.
20 | # Target specific stuff (defines etc.) goes in here!
21 | # Generally values applying to a tree are captured in the
22 | # makefile at its root level - these are then overridden
23 | # for a subtree within the makefile rooted therein
24 | #
25 | #DEFINES +=
26 |
27 | #############################################################
28 | # Recursion Magic - Don't touch this!!
29 | #
30 | # Each subtree potentially has an include directory
31 | # corresponding to the common APIs applicable to modules
32 | # rooted at that subtree. Accordingly, the INCLUDE PATH
33 | # of a module can only contain the include directories up
34 | # its parent path, and not its siblings
35 | #
36 | # Required for each makefile to inherit from the parent
37 | #
38 |
39 | INCLUDES := $(INCLUDES) -I $(PDIR)include
40 | INCLUDES += -I ./
41 | INCLUDES += -I ../libc
42 | INCLUDES += -I ../coap
43 | INCLUDES += -I ../mqtt
44 | INCLUDES += -I ../u8glib
45 | INCLUDES += -I ../lua
46 | INCLUDES += -I ../platform
47 | INCLUDES += -I ../wofs
48 | INCLUDES += -I ../spiffs
49 | INCLUDES += -I ../smart
50 | INCLUDES += -I ../cjson
51 | INCLUDES += -I ../dhtlib
52 | INCLUDES += -I ../main/Include
53 | PDIR := ../$(PDIR)
54 | sinclude $(PDIR)Makefile
55 |
56 |
--------------------------------------------------------------------------------
/app/modules/adc.c:
--------------------------------------------------------------------------------
1 | // Module for interfacing with adc
2 |
3 | //#include "lua.h"
4 | #include "lualib.h"
5 | #include "lauxlib.h"
6 | #include "platform.h"
7 | #include "auxmods.h"
8 | #include "lrotable.h"
9 |
10 | #include "c_types.h"
11 | #include "user_interface.h"
12 |
13 | // Lua: read(id) , return system adc
14 | static int adc_sample( lua_State* L )
15 | {
16 | unsigned id = luaL_checkinteger( L, 1 );
17 | MOD_CHECK_ID( adc, id );
18 | unsigned val = 0xFFFF & system_adc_read();
19 | lua_pushinteger( L, val );
20 | return 1;
21 | }
22 |
23 | // Lua: readvdd33()
24 | static int adc_readvdd33( lua_State* L )
25 | {
26 | uint32_t vdd33 = 0;
27 |
28 | if(STATION_MODE == wifi_get_opmode())
29 | {
30 | // Bug fix
31 | if (wifi_station_get_connect_status()!=0)
32 | {
33 | return luaL_error( L, "Can't read vdd33 while station is connected" );
34 | }
35 | else
36 | {
37 | vdd33 = readvdd33();
38 | }
39 | }
40 | else
41 | {
42 | vdd33 = readvdd33();
43 | }
44 | lua_pushinteger(L, vdd33);
45 | return 1;
46 | }
47 |
48 | // Module function map
49 | #define MIN_OPT_LEVEL 2
50 | #include "lrodefs.h"
51 | const LUA_REG_TYPE adc_map[] =
52 | {
53 | { LSTRKEY( "read" ), LFUNCVAL( adc_sample ) },
54 | { LSTRKEY( "readvdd33" ), LFUNCVAL( adc_readvdd33) },
55 | #if LUA_OPTIMIZE_MEMORY > 0
56 |
57 | #endif
58 | { LNILKEY, LNILVAL }
59 | };
60 |
61 | LUALIB_API int luaopen_adc( lua_State *L )
62 | {
63 | #if LUA_OPTIMIZE_MEMORY > 0
64 | return 0;
65 | #else // #if LUA_OPTIMIZE_MEMORY > 0
66 | luaL_register( L, AUXLIB_ADC, adc_map );
67 | // Add constants
68 |
69 | return 1;
70 | #endif // #if LUA_OPTIMIZE_MEMORY > 0
71 | }
72 |
--------------------------------------------------------------------------------
/app/mqtt/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = mqtt.a
16 | endif
17 |
18 | #############################################################
19 | # Configuration i.e. compile options etc.
20 | # Target specific stuff (defines etc.) goes in here!
21 | # Generally values applying to a tree are captured in the
22 | # makefile at its root level - these are then overridden
23 | # for a subtree within the makefile rooted therein
24 | #
25 | #DEFINES +=
26 |
27 | #############################################################
28 | # Recursion Magic - Don't touch this!!
29 | #
30 | # Each subtree potentially has an include directory
31 | # corresponding to the common APIs applicable to modules
32 | # rooted at that subtree. Accordingly, the INCLUDE PATH
33 | # of a module can only contain the include directories up
34 | # its parent path, and not its siblings
35 | #
36 | # Required for each makefile to inherit from the parent
37 | #
38 |
39 | INCLUDES := $(INCLUDES) -I $(PDIR)include
40 | INCLUDES += -I ./
41 | INCLUDES += -I ../libc
42 | PDIR := ../$(PDIR)
43 | sinclude $(PDIR)Makefile
44 |
45 |
--------------------------------------------------------------------------------
/app/mqtt/msg_queue.c:
--------------------------------------------------------------------------------
1 | #include "c_string.h"
2 | #include "c_stdlib.h"
3 | #include "c_stdio.h"
4 | #include "msg_queue.h"
5 |
6 | msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_id, int msg_type, int publish_qos){
7 | if(!head){
8 | return NULL;
9 | }
10 | if (!msg || !msg->data || msg->length == 0){
11 | NODE_DBG("empty message\n");
12 | return NULL;
13 | }
14 | msg_queue_t *node = (msg_queue_t *)c_zalloc(sizeof(msg_queue_t));
15 | if(!node){
16 | NODE_DBG("not enough memory\n");
17 | return NULL;
18 | }
19 |
20 | node->msg.data = (uint8_t *)c_zalloc(msg->length);
21 | if(!node->msg.data){
22 | NODE_DBG("not enough memory\n");
23 | c_free(node);
24 | return NULL;
25 | }
26 | c_memcpy(node->msg.data, msg->data, msg->length);
27 | node->msg.length = msg->length;
28 | node->next = NULL;
29 | node->msg_id = msg_id;
30 | node->msg_type = msg_type;
31 | node->publish_qos = publish_qos;
32 |
33 | msg_queue_t *tail = *head;
34 | if(tail){
35 | while(tail->next!=NULL) tail = tail->next;
36 | tail->next = node;
37 | } else {
38 | *head = node;
39 | }
40 | return node;
41 | }
42 |
43 | void msg_destroy(msg_queue_t *node){
44 | if(!node) return;
45 | if(node->msg.data){
46 | c_free(node->msg.data);
47 | node->msg.data = NULL;
48 | }
49 | c_free(node);
50 | }
51 |
52 | msg_queue_t * msg_dequeue(msg_queue_t **head){
53 | if(!head || !*head){
54 | return NULL;
55 | }
56 | msg_queue_t *node = *head; // fetch head.
57 | *head = node->next; // update head.
58 | node->next = NULL;
59 | return node;
60 | }
61 |
62 | msg_queue_t * msg_peek(msg_queue_t **head){
63 | if(!head || !*head){
64 | return NULL;
65 | }
66 | return *head; // fetch head.
67 | }
68 |
69 | int msg_size(msg_queue_t **head){
70 | if(!head || !*head){
71 | return 0;
72 | }
73 | int i = 1;
74 | msg_queue_t *tail = *head;
75 | if(tail){
76 | while(tail->next!=NULL){
77 | tail = tail->next;
78 | i++;
79 | }
80 | }
81 | return i;
82 | }
83 |
--------------------------------------------------------------------------------
/app/mqtt/msg_queue.h:
--------------------------------------------------------------------------------
1 | #ifndef _MSG_QUEUE_H
2 | #define _MSG_QUEUE_H 1
3 | #include "mqtt_msg.h"
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | struct msg_queue_t;
9 |
10 | typedef struct msg_queue_t {
11 | struct msg_queue_t *next;
12 | mqtt_message_t msg;
13 | uint16_t msg_id;
14 | int msg_type;
15 | int publish_qos;
16 | } msg_queue_t;
17 |
18 | msg_queue_t * msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_id, int msg_type, int publish_qos);
19 | void msg_destroy(msg_queue_t *node);
20 | msg_queue_t * msg_dequeue(msg_queue_t **head);
21 | msg_queue_t * msg_peek(msg_queue_t **head);
22 | int msg_size(msg_queue_t **head);
23 |
24 | #ifdef __cplusplus
25 | }
26 | #endif
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/app/platform/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = libplatform.a
16 | endif
17 |
18 | #############################################################
19 | # Configuration i.e. compile options etc.
20 | # Target specific stuff (defines etc.) goes in here!
21 | # Generally values applying to a tree are captured in the
22 | # makefile at its root level - these are then overridden
23 | # for a subtree within the makefile rooted therein
24 | #
25 | #DEFINES +=
26 |
27 | #############################################################
28 | # Recursion Magic - Don't touch this!!
29 | #
30 | # Each subtree potentially has an include directory
31 | # corresponding to the common APIs applicable to modules
32 | # rooted at that subtree. Accordingly, the INCLUDE PATH
33 | # of a module can only contain the include directories up
34 | # its parent path, and not its siblings
35 | #
36 | # Required for each makefile to inherit from the parent
37 | #
38 |
39 | INCLUDES := $(INCLUDES) -I $(PDIR)include
40 | INCLUDES += -I ./
41 | INCLUDES += -I ../wofs
42 | INCLUDES += -I ../spiffs
43 | INCLUDES += -I ../libc
44 | INCLUDES += -I ../lua
45 | PDIR := ../$(PDIR)
46 | sinclude $(PDIR)Makefile
47 |
48 |
--------------------------------------------------------------------------------
/app/platform/common.c:
--------------------------------------------------------------------------------
1 | // Common code for all backends
2 |
3 | #include "platform.h"
4 | #include "common.h"
5 | #include "c_string.h"
6 | #include "c_stdio.h"
7 |
8 | void cmn_platform_init(void)
9 | {
10 |
11 | }
12 |
13 | // ****************************************************************************
14 | // GPIO functions
15 |
16 | int platform_gpio_exists( unsigned pin )
17 | {
18 | return pin < NUM_GPIO;
19 | }
20 |
21 | // ****************************************************************************
22 | // CAN functions
23 |
24 | int platform_can_exists( unsigned id )
25 | {
26 | return id < NUM_CAN;
27 | }
28 |
29 | // ****************************************************************************
30 | // SPI functions
31 |
32 |
33 | int platform_spi_exists( unsigned id )
34 | {
35 | return id < NUM_SPI;
36 | }
37 |
38 | // ****************************************************************************
39 | // PWM functions
40 |
41 | int platform_pwm_exists( unsigned id )
42 | {
43 | return ((id < NUM_PWM) && (id > 0));
44 | }
45 |
46 | // ****************************************************************************
47 | // ADC functions
48 |
49 | int platform_adc_exists( unsigned id )
50 | {
51 | return id < NUM_ADC;
52 | }
53 |
54 | // ****************************************************************************
55 | // UART functions
56 |
57 | int platform_uart_exists( unsigned id )
58 | {
59 | return id < NUM_UART;
60 | }
61 |
62 | // ****************************************************************************
63 | // OneWire functions
64 |
65 | int platform_ow_exists( unsigned id )
66 | {
67 | return ((id < NUM_OW) && (id > 0));
68 | }
69 |
70 | // ****************************************************************************
71 | // Timer functions
72 |
73 | int platform_tmr_exists( unsigned id )
74 | {
75 | return id < NUM_TMR;
76 | }
77 |
78 | // I2C support
79 | int platform_i2c_exists( unsigned id )
80 | {
81 | #ifndef NUM_I2C
82 | return 0;
83 | #else
84 | return id < NUM_I2C;
85 | #endif
86 | }
87 |
88 |
--------------------------------------------------------------------------------
/app/platform/common.h:
--------------------------------------------------------------------------------
1 | // Common platform functions
2 |
3 | #ifndef __COMMON_H__
4 | #define __COMMON_H__
5 |
6 | #include "platform.h"
7 |
8 | // Functions exported by the common platform layer
9 | void cmn_platform_init(void);
10 |
11 | // Timer-specific functions
12 |
13 | // System timer generic implemenation
14 |
15 | // Filesystem-related functions
16 |
17 | #endif // #ifndef __COMMON_H__
18 |
19 |
--------------------------------------------------------------------------------
/app/platform/cpu_esp8266.h:
--------------------------------------------------------------------------------
1 | #ifndef __CPU_ESP8266_H__
2 | #define __CPU_ESP8266_H__
3 |
4 | #include "os_type.h"
5 | #include "spi_flash.h"
6 | #include "pin_map.h"
7 | #include "user_config.h"
8 | //#include "flash_api.h"
9 | // Number of resources (0 if not available/not implemented)
10 |
11 | #define NUM_GPIO GPIO_PIN_NUM
12 | #define NUM_SPI 2
13 | #define NUM_UART 1
14 | #define NUM_PWM GPIO_PIN_NUM
15 | #define NUM_ADC 1
16 | #define NUM_CAN 0
17 | #define NUM_I2C 1
18 | #define NUM_OW GPIO_PIN_NUM
19 | #define NUM_TMR 7
20 |
21 | #define FLASH_SEC_NUM 0x80
22 | #define SYS_PARAM_SEC_NUM 4
23 | #define SYS_PARAM_SEC_START (FLASH_SEC_NUM - SYS_PARAM_SEC_NUM)
24 |
25 |
26 | #define INTERNAL_FLASH_SECTOR_SIZE SPI_FLASH_SEC_SIZE
27 | #define INTERNAL_FLASH_WRITE_UNIT_SIZE 4
28 | #define INTERNAL_FLASH_READ_UNIT_SIZE 4
29 |
30 | #define INTERNAL_FLASH_SIZE (FLASH_SEC_NUM*SPI_FLASH_SEC_SIZE)
31 | #define INTERNAL_FLASH_START_ADDRESS 0x40200000
32 |
33 | // SpiFlashOpResult spi_flash_erase_sector(uint16 sec);
34 | // SpiFlashOpResult spi_flash_write(uint32 des_addr, uint32 *src_addr, uint32 size);
35 | // SpiFlashOpResult spi_flash_read(uint32 src_addr, uint32 *des_addr, uint32 size);
36 | /*
37 | #if defined(FLASH_SAFE_API)
38 | #define flash_write flash_safe_write
39 | #define flash_erase flash_safe_erase_sector
40 | #define flash_read flash_safe_read
41 | #else
42 | #define flash_write spi_flash_write
43 | #define flash_erase spi_flash_erase_sector
44 | #define flash_read spi_flash_read
45 | #endif // defined(FLASH_SAFE_API)
46 | */
47 | #endif // #ifndef __CPU_ESP8266_H__
48 |
--------------------------------------------------------------------------------
/app/platform/flash_api.h:
--------------------------------------------------------------------------------
1 | #ifndef __FLASH_API_H__
2 | #define __FLASH_API_H__
3 |
4 | #include "user_config.h"
5 | #include "os_type.h"
6 | #include "spi_flash.h"
7 |
8 |
9 | #define flash_safe_get_size_byte() flash_size
10 | #define flash_safe_get_sec_num() (flash_size >> 12)
11 |
12 | #ifdef USE_PVV_SPIFLASH
13 |
14 | #define flash_safe_read spi_flash_read
15 | #define flash_safe_erase_sector spi_flash_erase_sector
16 | #define flash_safe_erase_block spi_flash_erase_block
17 |
18 | #else
19 |
20 | SpiFlashOpResult flash_safe_read(uint32 src_addr, void *des_addr, uint32 size);
21 | SpiFlashOpResult flash_safe_erase_sector(uint16 sec);
22 | SpiFlashOpResult flash_safe_erase_block(uint16 blk);
23 |
24 | #endif
25 |
26 | SpiFlashOpResult flash_safe_write(uint32 des_addr, uint8 *src_addr, uint32 size);
27 |
28 | void flash_size_init(void);
29 |
30 | #define byte_of_aligned_array(a,b) (uint8_t)get_rom_chr((void *)((unsigned int )a + (unsigned int )b))
31 |
32 | //uint8_t byte_of_aligned_array(const uint8_t* aligned_array, uint32_t index);
33 |
34 | extern uint32_t flash_size;
35 |
36 | #endif // __FLASH_API_H__
37 |
--------------------------------------------------------------------------------
/app/platform/flash_fs.c:
--------------------------------------------------------------------------------
1 | #include "flash_fs.h"
2 | #include "c_string.h"
3 |
4 | #include "spiffs.h"
5 |
6 | int fs_mode2flag(const char *mode){
7 | if(c_strlen(mode)==1){
8 | if(c_strcmp(mode,"w")==0)
9 | return FS_WRONLY|FS_CREAT|FS_TRUNC;
10 | else if(c_strcmp(mode, "r")==0)
11 | return FS_RDONLY;
12 | else if(c_strcmp(mode, "a")==0)
13 | return FS_WRONLY|FS_CREAT|FS_APPEND;
14 | else
15 | return FS_RDONLY;
16 | } else if (c_strlen(mode)==2){
17 | if(c_strcmp(mode,"r+")==0)
18 | return FS_RDWR;
19 | else if(c_strcmp(mode, "w+")==0)
20 | return FS_RDWR|FS_CREAT|FS_TRUNC;
21 | else if(c_strcmp(mode, "a+")==0)
22 | return FS_RDWR|FS_CREAT|FS_APPEND;
23 | else
24 | return FS_RDONLY;
25 | } else {
26 | return FS_RDONLY;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/platform/flash_fs.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef __FLASH_FS_H__
3 | #define __FLASH_FS_H__
4 |
5 | #include "user_config.h"
6 |
7 | #include "spiffs.h"
8 |
9 | #define FS_OPEN_OK 1
10 |
11 | #define FS_RDONLY SPIFFS_RDONLY
12 | #define FS_WRONLY SPIFFS_WRONLY
13 | #define FS_RDWR SPIFFS_RDWR
14 | #define FS_APPEND SPIFFS_APPEND
15 | #define FS_TRUNC SPIFFS_TRUNC
16 | #define FS_CREAT SPIFFS_CREAT
17 | #define FS_EXCL SPIFFS_EXCL
18 |
19 | #define FS_SEEK_SET SPIFFS_SEEK_SET
20 | #define FS_SEEK_CUR SPIFFS_SEEK_CUR
21 | #define FS_SEEK_END SPIFFS_SEEK_END
22 |
23 | #define fs_open myspiffs_open
24 | #define fs_close myspiffs_close
25 | #define fs_write myspiffs_write
26 | #define fs_read myspiffs_read
27 | #define fs_seek myspiffs_lseek
28 | #define fs_eof myspiffs_eof
29 | #define fs_getc myspiffs_getc
30 | #define fs_ungetc myspiffs_ungetc
31 | #define fs_flush myspiffs_flush
32 | #define fs_error myspiffs_error
33 | #define fs_clearerr myspiffs_clearerr
34 | #define fs_tell myspiffs_tell
35 |
36 | #define fs_format myspiffs_format
37 | #define fs_check myspiffs_check
38 | #define fs_rename myspiffs_rename
39 | #define fs_size myspiffs_size
40 |
41 | #define FS_NAME_MAX_LENGTH SPIFFS_OBJ_NAME_LEN
42 |
43 |
44 | int fs_mode2flag(const char *mode);
45 |
46 | #endif // #ifndef __FLASH_FS_H__
47 |
--------------------------------------------------------------------------------
/app/platform/pin_map.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef __PIN_MAP_H__
3 | #define __PIN_MAP_H__
4 |
5 | #include "c_types.h"
6 | #include "user_config.h"
7 | #include "gpio.h"
8 |
9 | #define GPIO_PIN_NUM 13
10 |
11 | extern uint8_t pin_num[GPIO_PIN_NUM];
12 | extern uint8_t pin_func[GPIO_PIN_NUM];
13 | extern uint32_t pin_mux[GPIO_PIN_NUM];
14 | #ifdef GPIO_INTERRUPT_ENABLE
15 | extern GPIO_INT_TYPE pin_int_type[GPIO_PIN_NUM];
16 | #endif
17 | #endif // #ifndef __PIN_MAP_H__
18 |
--------------------------------------------------------------------------------
/app/smart/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = smart.a
16 | endif
17 |
18 | #############################################################
19 | # Configuration i.e. compile options etc.
20 | # Target specific stuff (defines etc.) goes in here!
21 | # Generally values applying to a tree are captured in the
22 | # makefile at its root level - these are then overridden
23 | # for a subtree within the makefile rooted therein
24 | #
25 | #DEFINES +=
26 |
27 | #############################################################
28 | # Recursion Magic - Don't touch this!!
29 | #
30 | # Each subtree potentially has an include directory
31 | # corresponding to the common APIs applicable to modules
32 | # rooted at that subtree. Accordingly, the INCLUDE PATH
33 | # of a module can only contain the include directories up
34 | # its parent path, and not its siblings
35 | #
36 | # Required for each makefile to inherit from the parent
37 | #
38 |
39 | INCLUDES := $(INCLUDES) -I $(PDIR)include
40 | INCLUDES += -I ./
41 | INCLUDES += -I ../libc
42 | PDIR := ../$(PDIR)
43 | sinclude $(PDIR)Makefile
44 |
45 |
--------------------------------------------------------------------------------
/app/spiffs/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013-2015 Peter Andersson (pelleplutt1976gmail.com)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/app/spiffs/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = spiffs.a
16 | endif
17 |
18 | #############################################################
19 | # Configuration i.e. compile options etc.
20 | # Target specific stuff (defines etc.) goes in here!
21 | # Generally values applying to a tree are captured in the
22 | # makefile at its root level - these are then overridden
23 | # for a subtree within the makefile rooted therein
24 | #
25 | #DEFINES +=
26 |
27 | #############################################################
28 | # Recursion Magic - Don't touch this!!
29 | #
30 | # Each subtree potentially has an include directory
31 | # corresponding to the common APIs applicable to modules
32 | # rooted at that subtree. Accordingly, the INCLUDE PATH
33 | # of a module can only contain the include directories up
34 | # its parent path, and not its siblings
35 | #
36 | # Required for each makefile to inherit from the parent
37 | #
38 |
39 | INCLUDES := $(INCLUDES) -I $(PDIR)include
40 | INCLUDES += -I ./
41 | INCLUDES += -I ../libc
42 | INCLUDES += -I ../platform
43 | PDIR := ../$(PDIR)
44 | sinclude $(PDIR)Makefile
45 |
--------------------------------------------------------------------------------
/app/spiffs/docs/IMPLEMENTING:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/app/spiffs/docs/IMPLEMENTING
--------------------------------------------------------------------------------
/app/spiffs/docs/TODO:
--------------------------------------------------------------------------------
1 | * When mending lost pages, also see if they fit into length specified in object index header
--------------------------------------------------------------------------------
/app/spiffs/test/main.c:
--------------------------------------------------------------------------------
1 | #include "testrunner.h"
2 | #include
3 |
4 | int main(int argc, char **args) {
5 | run_tests(argc, args);
6 | exit(EXIT_SUCCESS);
7 | }
8 |
--------------------------------------------------------------------------------
/app/spiffs/test/params_test.h:
--------------------------------------------------------------------------------
1 | /*
2 | * params_test.h
3 | *
4 | * Created on: May 26, 2013
5 | * Author: petera
6 | */
7 |
8 | #ifndef PARAMS_TEST_H_
9 | #define PARAMS_TEST_H_
10 |
11 | // total emulated spi flash size
12 | #define PHYS_FLASH_SIZE (16*1024*1024)
13 | // spiffs file system size
14 | #define SPIFFS_FLASH_SIZE (2*1024*1024)
15 | // spiffs file system offset in emulated spi flash
16 | #define SPIFFS_PHYS_ADDR (4*1024*1024)
17 |
18 | #define SECTOR_SIZE 65536
19 | #define LOG_BLOCK (SECTOR_SIZE*2)
20 | #define LOG_PAGE (SECTOR_SIZE/256)
21 |
22 | #define FD_BUF_SIZE 64*6
23 | #define CACHE_BUF_SIZE (LOG_PAGE + 32)*8
24 |
25 | #define ASSERT(c, m) real_assert((c),(m), __FILE__, __LINE__);
26 |
27 | typedef signed int s32_t;
28 | typedef unsigned int u32_t;
29 | typedef signed short s16_t;
30 | typedef unsigned short u16_t;
31 | typedef signed char s8_t;
32 | typedef unsigned char u8_t;
33 |
34 | void real_assert(int c, const char *n, const char *file, int l);
35 |
36 | #endif /* PARAMS_TEST_H_ */
37 |
--------------------------------------------------------------------------------
/app/spiffs/test/testsuites.c:
--------------------------------------------------------------------------------
1 | /*
2 | * testsuites.c
3 | *
4 | * Created on: Jun 19, 2013
5 | * Author: petera
6 | */
7 |
8 | #include "testrunner.h"
9 |
10 | void add_suites() {
11 | //ADD_SUITE(dev_tests);
12 | ADD_SUITE(check_tests);
13 | ADD_SUITE(hydrogen_tests)
14 | ADD_SUITE(bug_tests)
15 | }
16 |
--------------------------------------------------------------------------------
/app/u8glib/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = u8glib.a
16 | endif
17 |
18 | #############################################################
19 | # Configuration i.e. compile options etc.
20 | # Target specific stuff (defines etc.) goes in here!
21 | # Generally values applying to a tree are captured in the
22 | # makefile at its root level - these are then overridden
23 | # for a subtree within the makefile rooted therein
24 | #
25 | #DEFINES +=
26 |
27 | #############################################################
28 | # Recursion Magic - Don't touch this!!
29 | #
30 | # Each subtree potentially has an include directory
31 | # corresponding to the common APIs applicable to modules
32 | # rooted at that subtree. Accordingly, the INCLUDE PATH
33 | # of a module can only contain the include directories up
34 | # its parent path, and not its siblings
35 | #
36 | # Required for each makefile to inherit from the parent
37 | #
38 |
39 | INCLUDES := $(INCLUDES) -I $(PDIR)include
40 | INCLUDES += -I ./
41 | INCLUDES += -I ../libc
42 | PDIR := ../$(PDIR)
43 | sinclude $(PDIR)Makefile
44 |
45 |
--------------------------------------------------------------------------------
/app/u8glib/u8g_com_null.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g_com_null.c
4 |
5 | communication null device
6 |
7 | Universal 8bit Graphics Library
8 |
9 | Copyright (c) 2011, olikraus@gmail.com
10 | All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without modification,
13 | are permitted provided that the following conditions are met:
14 |
15 | * Redistributions of source code must retain the above copyright notice, this list
16 | of conditions and the following disclaimer.
17 |
18 | * Redistributions in binary form must reproduce the above copyright notice, this
19 | list of conditions and the following disclaimer in the documentation and/or other
20 | materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 |
36 |
37 | */
38 |
39 | #include "u8g.h"
40 |
41 | uint8_t u8g_com_null_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
42 | {
43 | switch(msg)
44 | {
45 | case U8G_COM_MSG_INIT:
46 | break;
47 | case U8G_COM_MSG_STOP:
48 | break;
49 |
50 |
51 | case U8G_COM_MSG_CHIP_SELECT:
52 | /* arg_val contains the chip number, which should be enabled */
53 | break;
54 |
55 |
56 | case U8G_COM_MSG_WRITE_BYTE:
57 | break;
58 | case U8G_COM_MSG_WRITE_SEQ:
59 | break;
60 | }
61 | return 1;
62 | }
63 |
64 |
--------------------------------------------------------------------------------
/app/u8glib/u8g_font_data.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/app/u8glib/u8g_font_data.c
--------------------------------------------------------------------------------
/app/u8glib/u8g_u16toa.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g_u16toa.c
4 |
5 |
6 | Universal 8bit Graphics Library
7 |
8 | Copyright (c) 2012, olikraus@gmail.com
9 | All rights reserved.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | * Redistributions of source code must retain the above copyright notice, this list
15 | of conditions and the following disclaimer.
16 |
17 | * Redistributions in binary form must reproduce the above copyright notice, this
18 | list of conditions and the following disclaimer in the documentation and/or other
19 | materials provided with the distribution.
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 |
35 | */
36 |
37 |
38 | #include "u8g.h"
39 |
40 | const char *u8g_u16toap(char * dest, uint16_t v)
41 | {
42 | uint8_t pos;
43 | uint8_t d;
44 | uint16_t c;
45 | c = 10000;
46 | for( pos = 0; pos < 5; pos++ )
47 | {
48 | d = '0';
49 | while( v >= c )
50 | {
51 | v -= c;
52 | d++;
53 | }
54 | dest[pos] = d;
55 | c /= 10;
56 | }
57 | dest[5] = '\0';
58 | return dest;
59 | }
60 |
61 | /* v = value, d = number of digits */
62 | const char *u8g_u16toa(uint16_t v, uint8_t d)
63 | {
64 | static char buf[6];
65 | d = 5-d;
66 | return u8g_u16toap(buf, v) + d;
67 | }
68 |
69 |
--------------------------------------------------------------------------------
/app/user/Makefile:
--------------------------------------------------------------------------------
1 |
2 | #############################################################
3 | # Required variables for each makefile
4 | # Discard this section from all parent makefiles
5 | # Expected variables (with automatic defaults):
6 | # CSRCS (all "C" files in the dir)
7 | # SUBDIRS (all subdirs with a Makefile)
8 | # GEN_LIBS - list of libs to be generated ()
9 | # GEN_IMAGES - list of images to be generated ()
10 | # COMPONENTS_xxx - a list of libs/objs in the form
11 | # subdir/lib to be extracted and rolled up into
12 | # a generated lib/image xxx.a ()
13 | #
14 | ifndef PDIR
15 | GEN_LIBS = libuser.a
16 | endif
17 |
18 |
19 | #############################################################
20 | # Configuration i.e. compile options etc.
21 | # Target specific stuff (defines etc.) goes in here!
22 | # Generally values applying to a tree are captured in the
23 | # makefile at its root level - these are then overridden
24 | # for a subtree within the makefile rooted therein
25 | #
26 | #DEFINES +=
27 |
28 | #############################################################
29 | # Recursion Magic - Don't touch this!!
30 | #
31 | # Each subtree potentially has an include directory
32 | # corresponding to the common APIs applicable to modules
33 | # rooted at that subtree. Accordingly, the INCLUDE PATH
34 | # of a module can only contain the include directories up
35 | # its parent path, and not its siblings
36 | #
37 | # Required for each makefile to inherit from the parent
38 | #
39 |
40 | INCLUDES := $(INCLUDES) -I $(PDIR)include
41 | INCLUDES += -I ./
42 | INCLUDES += -I ../../include/ets
43 | INCLUDES += -I ../libc
44 | INCLUDES += -I ../platform
45 | INCLUDES += -I ../lua
46 | INCLUDES += -I ../wofs
47 | INCLUDES += -I ../wofs
48 | PDIR := ../$(PDIR)
49 | sinclude $(PDIR)Makefile
50 |
51 |
--------------------------------------------------------------------------------
/app/user/user_exceptions.h:
--------------------------------------------------------------------------------
1 | #include "c_types.h"
2 | #include "rom.h"
3 | #include
4 |
5 | #define EXCCAUSE_LOAD_STORE_ERROR 3 /* Load Store Error */
6 |
7 | void load_non_32_wide_handler (struct exception_frame *ef, uint32_t cause);
8 |
--------------------------------------------------------------------------------
/asm_damp.bat:
--------------------------------------------------------------------------------
1 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-objdump -S .\app\.output\eagle\image\eagle.app.v6.out > eagle.app.v6.asm
2 |
3 |
4 |
--------------------------------------------------------------------------------
/bin/0x00000.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/bin/0x00000.bin
--------------------------------------------------------------------------------
/bin/0x0c000.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/bin/0x0c000.bin
--------------------------------------------------------------------------------
/bin/blank.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/bin/blank.bin
--------------------------------------------------------------------------------
/bin/esp_init_data_default.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/bin/esp_init_data_default.bin
--------------------------------------------------------------------------------
/bin/rapid_loader.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/bin/rapid_loader.bin
--------------------------------------------------------------------------------
/bin/rapid_loader_40m.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/bin/rapid_loader_40m.bin
--------------------------------------------------------------------------------
/bin/readme.txt:
--------------------------------------------------------------------------------
1 | Program codes:
2 | 0x00000 - bin\0x00000.bin
3 | 0x0C000 - bin\0x0C000.bin
4 | Default config (Clear SDK settings):
5 | 0x7C000 - bin\esp_init_data_default.bin
6 | 0x7E000 - bin\blank.bin
7 |
8 | rapid_loader.bin - loader FlashSPI CLK x2 (80MHz)
9 | rapid_loader_m40.bin - loader FlashSPI CLK x1 (40MHz)
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/include/mem.h:
--------------------------------------------------------------------------------
1 | #ifndef __MEM_H__
2 | #define __MEM_H__
3 |
4 | //void *pvPortMalloc( size_t xWantedSize );
5 | //void vPortFree( void *pv );
6 | //void *pvPortZalloc(size_t size);
7 |
8 | #define os_malloc pvPortMalloc
9 | #define os_free vPortFree
10 | #define os_zalloc pvPortZalloc
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/include/os_type.h:
--------------------------------------------------------------------------------
1 | /*
2 | * copyright (c) Espressif System 2010
3 | *
4 | * mapping to ETS structures
5 | *
6 | */
7 | #ifndef _OS_TYPES_H_
8 | #define _OS_TYPES_H_
9 |
10 | #include "ets_sys.h"
11 |
12 | #define os_signal_t ETSSignal
13 | #define os_param_t ETSParam
14 | #define os_event_t ETSEvent
15 | #define os_task_t ETSTask
16 | #define os_timer_t ETSTimer
17 | #define os_timer_func_t ETSTimerFunc
18 |
19 | #endif
20 |
--------------------------------------------------------------------------------
/include/osapi.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010 Espressif System
3 | */
4 |
5 | #ifndef _OSAPI_H_
6 | #define _OSAPI_H_
7 |
8 | #include
9 | #include "user_config.h"
10 |
11 | #define os_bzero ets_bzero
12 | #define os_delay_us ets_delay_us
13 | #define os_install_putc1 ets_install_putc1
14 | #define os_install_putc2 ets_install_putc2
15 | #define os_intr_lock ets_intr_lock
16 | #define os_intr_unlock ets_intr_unlock
17 | #define os_isr_attach ets_isr_attach
18 | #define os_isr_mask ets_isr_mask
19 | #define os_isr_unmask ets_isr_unmask
20 |
21 | #define os_memcmp ets_memcmp
22 | #define os_memcpy ets_memcpy
23 | #define os_memmove ets_memmove
24 | #define os_memset ets_memset
25 | #define os_putc ets_putc
26 | #define os_str2macaddr ets_str2macaddr
27 | #define os_strcat strcat
28 | #define os_strchr strchr
29 | #define os_strcmp ets_strcmp
30 | #define os_strcpy ets_strcpy
31 | #define os_strlen ets_strlen
32 | #define os_strncmp ets_strncmp
33 | #define os_strncpy ets_strncpy
34 | #define os_strstr ets_strstr
35 |
36 | #define os_timer_arm_us(a, b, c) ets_timer_arm_new(a, b, c, 0)
37 | #define os_timer_arm(a, b, c) ets_timer_arm_new(a, b, c, 1)
38 | #define os_timer_disarm ets_timer_disarm
39 | #define os_timer_done ets_timer_done
40 | #define os_timer_handler_isr ets_timer_handler_isr
41 | #define os_timer_init ets_timer_init
42 | #define os_timer_setfn ets_timer_setfn
43 |
44 | #define os_sprintf ets_sprintf
45 | #define os_update_cpu_frequency ets_update_cpu_frequency
46 |
47 | #ifdef USE_OPTIMIZE_PRINTF
48 | #define os_printf(fmt, ...) do { \
49 | static const char flash_str[] ICACHE_RODATA_ATTR = fmt; \
50 | os_printf_plus(flash_str, ##__VA_ARGS__); \
51 | } while(0)
52 | #else
53 | #define os_printf os_printf_plus
54 | #endif
55 |
56 | unsigned long os_random(void);
57 | int os_get_random(unsigned char *buf, size_t len);
58 |
59 | #endif
60 |
61 |
--------------------------------------------------------------------------------
/include/ping.h:
--------------------------------------------------------------------------------
1 | #ifndef __PING_H__
2 | #define __PING_H__
3 |
4 |
5 | typedef void (* ping_recv_function)(void* arg, void *pdata);
6 | typedef void (* ping_sent_function)(void* arg, void *pdata);
7 |
8 | struct ping_option{
9 | uint32 count;
10 | uint32 ip;
11 | uint32 coarse_time;
12 | ping_recv_function recv_function;
13 | ping_sent_function sent_function;
14 | void* reverse;
15 | };
16 |
17 | struct ping_resp{
18 | uint32 total_count;
19 | uint32 resp_time;
20 | uint32 seqno;
21 | uint32 timeout_count;
22 | uint32 bytes;
23 | uint32 total_bytes;
24 | uint32 total_time;
25 | sint8 ping_err;
26 | };
27 |
28 | bool ping_start(struct ping_option *ping_opt);
29 | bool ping_regist_recv(struct ping_option *ping_opt, ping_recv_function ping_recv);
30 | bool ping_regist_sent(struct ping_option *ping_opt, ping_sent_function ping_sent);
31 |
32 | #endif /* __PING_H__ */
33 |
--------------------------------------------------------------------------------
/include/pwm.h:
--------------------------------------------------------------------------------
1 | #ifndef __PWM_H__
2 | #define __PWM_H__
3 |
4 | /*pwm.h: function and macro definition of PWM API , driver level */
5 | /*user_light.h: user interface for light API, user level*/
6 | /*user_light_adj: API for color changing and lighting effects, user level*/
7 |
8 |
9 | /*NOTE!! : DO NOT CHANGE THIS FILE*/
10 |
11 | /*SUPPORT UP TO 8 PWM CHANNEL*/
12 | #define PWM_CHANNEL_NUM_MAX 8
13 |
14 | struct pwm_param {
15 | uint32 period;
16 | uint32 freq;
17 | uint32 duty[PWM_CHANNEL_NUM_MAX]; //PWM_CHANNEL<=8
18 | };
19 |
20 |
21 | /* pwm_init should be called only once, for now */
22 | void pwm_init(uint32 period, uint32 *duty,uint32 pwm_channel_num,uint32 (*pin_info_list)[3]);
23 | void pwm_start(void);
24 |
25 | void pwm_set_duty(uint32 duty, uint8 channel);
26 | uint32 pwm_get_duty(uint8 channel);
27 | void pwm_set_period(uint32 period);
28 | uint32 pwm_get_period(void);
29 |
30 | uint32 get_pwm_version(void);
31 | void set_pwm_debug_en(uint8 print_en);
32 |
33 | #endif
34 |
35 |
--------------------------------------------------------------------------------
/include/smartconfig.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 -2018 Espressif System
3 | *
4 | */
5 |
6 | #ifndef __SMARTCONFIG_H__
7 | #define __SMARTCONFIG_H__
8 |
9 | typedef enum {
10 | SC_STATUS_WAIT = 0,
11 | SC_STATUS_FIND_CHANNEL,
12 | SC_STATUS_GETTING_SSID_PSWD,
13 | SC_STATUS_LINK,
14 | SC_STATUS_LINK_OVER,
15 | } sc_status;
16 |
17 | typedef enum {
18 | SC_TYPE_ESPTOUCH = 0,
19 | SC_TYPE_AIRKISS,
20 | } sc_type;
21 |
22 | typedef void (*sc_callback_t)(sc_status status, void *pdata);
23 |
24 | const char *smartconfig_get_version(void);
25 | bool smartconfig_start(sc_callback_t cb, ...);
26 | bool smartconfig_stop(void);
27 | bool esptouch_set_timeout(uint8 time_s); //15s~255s, offset:45s
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/include/sntp.h:
--------------------------------------------------------------------------------
1 | #ifndef __SNTP_H__
2 | #define __SNTP_H__
3 |
4 | #include "os_type.h"
5 | #ifdef LWIP_OPEN_SRC
6 | #include "lwip/ip_addr.h"
7 | #else
8 | #include "ip_addr.h"
9 | #endif
10 | /**
11 | * get the seconds since Jan 01, 1970, 00:00 (GMT + 8)
12 | */
13 | uint32 sntp_get_current_timestamp();
14 | /**
15 | * get real time (GTM + 8 time zone)
16 | */
17 | char* sntp_get_real_time(long t);
18 | /**
19 | * SNTP get time_zone default GMT + 8
20 | */
21 | sint8 sntp_get_timezone(void);
22 | /**
23 | * SNTP set time_zone (default GMT + 8)
24 | */
25 | bool sntp_set_timezone(sint8 timezone);
26 | /**
27 | * Initialize this module.
28 | * Send out request instantly or after SNTP_STARTUP_DELAY(_FUNC).
29 | */
30 | void sntp_init(void);
31 | /**
32 | * Stop this module.
33 | */
34 | void sntp_stop(void);
35 | /**
36 | * Initialize one of the NTP servers by IP address
37 | *
38 | * @param numdns the index of the NTP server to set must be < SNTP_MAX_SERVERS
39 | * @param dnsserver IP address of the NTP server to set
40 | */
41 | void sntp_setserver(unsigned char idx, ip_addr_t *addr);
42 | /**
43 | * Obtain one of the currently configured by IP address (or DHCP) NTP servers
44 | *
45 | * @param numdns the index of the NTP server
46 | * @return IP address of the indexed NTP server or "ip_addr_any" if the NTP
47 | * server has not been configured by address (or at all).
48 | */
49 | ip_addr_t sntp_getserver(unsigned char idx);
50 | /**
51 | * Initialize one of the NTP servers by name
52 | *
53 | * @param numdns the index of the NTP server to set must be < SNTP_MAX_SERVERS,now sdk support SNTP_MAX_SERVERS = 3
54 | * @param dnsserver DNS name of the NTP server to set, to be resolved at contact time
55 | */
56 | void sntp_setservername(unsigned char idx, char *server);
57 | /**
58 | * Obtain one of the currently configured by name NTP servers.
59 | *
60 | * @param numdns the index of the NTP server
61 | * @return IP address of the indexed NTP server or NULL if the NTP
62 | * server has not been configured by name (or at all)
63 | */
64 | char *sntp_getservername(unsigned char idx);
65 |
66 | #define sntp_servermode_dhcp(x)
67 |
68 | #endif
69 |
--------------------------------------------------------------------------------
/include/spi_flash.h:
--------------------------------------------------------------------------------
1 | /*
2 | * copyright (c) Espressif System 2010
3 | *
4 | */
5 |
6 | #ifndef SPI_FLASH_H
7 | #define SPI_FLASH_H
8 |
9 | typedef enum {
10 | SPI_FLASH_RESULT_OK,
11 | SPI_FLASH_RESULT_ERR,
12 | SPI_FLASH_RESULT_TIMEOUT
13 | } SpiFlashOpResult;
14 |
15 | typedef struct{
16 | uint32 deviceId;
17 | uint32 chip_size; // chip size in byte
18 | uint32 block_size;
19 | uint32 sector_size;
20 | uint32 page_size;
21 | uint32 status_mask;
22 | } SpiFlashChip;
23 |
24 | #define SPI_FLASH_SEC_SIZE 4096
25 |
26 | uint32 spi_flash_get_id(void);
27 | SpiFlashOpResult spi_flash_erase_sector(uint16 sec);
28 | SpiFlashOpResult spi_flash_write(uint32 des_addr, uint32 *src_addr, uint32 size);
29 | SpiFlashOpResult spi_flash_read(uint32 src_addr, uint32 *des_addr, uint32 size);
30 |
31 | typedef SpiFlashOpResult (* user_spi_flash_read)(
32 | SpiFlashChip *spi,
33 | uint32 src_addr,
34 | uint32 *des_addr,
35 | uint32 size);
36 |
37 | void spi_flash_set_read_func(user_spi_flash_read read);
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/include/upgrade.h:
--------------------------------------------------------------------------------
1 | #ifndef __UPGRADE_H__
2 | #define __UPGRADE_H__
3 |
4 | #define SPI_FLASH_SEC_SIZE 4096
5 |
6 | #define USER_BIN1 0x00
7 | #define USER_BIN2 0x01
8 |
9 | #define UPGRADE_FLAG_IDLE 0x00
10 | #define UPGRADE_FLAG_START 0x01
11 | #define UPGRADE_FLAG_FINISH 0x02
12 |
13 | #define UPGRADE_FW_BIN1 0x00
14 | #define UPGRADE_FW_BIN2 0x01
15 |
16 | typedef void (*upgrade_states_check_callback)(void * arg);
17 |
18 | //#define UPGRADE_SSL_ENABLE
19 |
20 | struct upgrade_server_info {
21 | uint8 ip[4];
22 | uint16 port;
23 |
24 | uint8 upgrade_flag;
25 |
26 | uint8 pre_version[16];
27 | uint8 upgrade_version[16];
28 |
29 | uint32 check_times;
30 | uint8 *url;
31 |
32 | upgrade_states_check_callback check_cb;
33 | struct espconn *pespconn;
34 | };
35 |
36 | #define UPGRADE_FLAG_IDLE 0x00
37 | #define UPGRADE_FLAG_START 0x01
38 | #define UPGRADE_FLAG_FINISH 0x02
39 |
40 | //bool system_upgrade_start(struct upgrade_server_info *server);
41 | bool system_upgrade_start_ssl(struct upgrade_server_info *server);
42 | void system_upgrade_init();
43 | void system_upgrade_deinit();
44 | bool system_upgrade(uint8 *data, uint16 len);
45 |
46 | #ifdef UPGRADE_SSL_ENABLE
47 | bool system_upgrade_start_ssl(struct upgrade_server_info *server);
48 | #else
49 | bool system_upgrade_start(struct upgrade_server_info *server);
50 | #endif
51 | #endif
52 |
--------------------------------------------------------------------------------
/init.lua:
--------------------------------------------------------------------------------
1 | print("Hello, world.")
--------------------------------------------------------------------------------
/lib/0/48app_main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lib/0/48app_main.o
--------------------------------------------------------------------------------
/lib/0/hiew.sav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lib/0/hiew.sav
--------------------------------------------------------------------------------
/lib/0/vector.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lib/0/vector.o
--------------------------------------------------------------------------------
/lib/lib0main.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lib/lib0main.a
--------------------------------------------------------------------------------
/lib/libmc.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lib/libmc.a
--------------------------------------------------------------------------------
/lib/libmgcc.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lib/libmgcc.a
--------------------------------------------------------------------------------
/lib/libmlwip.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lib/libmlwip.a
--------------------------------------------------------------------------------
/lib/libmphy.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lib/libmphy.a
--------------------------------------------------------------------------------
/lib/libmwpa.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lib/libmwpa.a
--------------------------------------------------------------------------------
/lib/libnet80211.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lib/libnet80211.a
--------------------------------------------------------------------------------
/lib/libpp.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lib/libpp.a
--------------------------------------------------------------------------------
/lib/libsmartconfig.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lib/libsmartconfig.a
--------------------------------------------------------------------------------
/lib/libssl.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lib/libssl.a
--------------------------------------------------------------------------------
/lib/new_lib0main.bat:
--------------------------------------------------------------------------------
1 | del lib0main.a
2 | md main0.lib
3 | cd main0.lib
4 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar x C:\Espressif\ESP8266_SDK\lib\libmain.a
5 | @rem
6 | @rem del: spi_flash.o spi_overlap.o ets_timer.o eagle_lib.o
7 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar ru ..\lib0main.a ..\0\vector.o kernel-vector.o nmi-vector.o debug-vector.o double-vector.o user-vector.o ..\0\48app_main.o eagle_lwip_if.o user_interface.o mem_manager.o
8 | cd ..
9 | rd /q /s main0.lib
10 |
--------------------------------------------------------------------------------
/lib/new_libmc.bat:
--------------------------------------------------------------------------------
1 | del libmc.a
2 | md libc
3 | cd libc
4 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar x C:\Espressif\xtensa-lx106-elf\xtensa-lx106-elf\lib\libc.a
5 | @rem delete: lib_a-rand.o lib_a-strlen.o lib_a-memcpy.o lib_a-memset.o
6 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar ru ..\libmc.a @..\libmc_list_files.txt
7 | cd ..
8 | rd /q /s libc
9 |
--------------------------------------------------------------------------------
/lib/new_libmgcc.bat:
--------------------------------------------------------------------------------
1 | del libmgcc.a
2 | md libgcc
3 | cd libgcc
4 | @rem C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar x C:\Espressif\xtensa-lx106-elf\lib\gcc\xtensa-lx106-elf\4.8.2\libgcc.a
5 | @C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar x C:\Espressif\xtensa-lx106-elf\lib\gcc\xtensa-lx106-elf\5.1.0\libgcc.a
6 | @rem delete:
7 | @rem _fixunsdfsi.o _umoddi3.o _umodsi3.o _extendsfdf2.o _fixdfsi.o _divsi3.o _divdf3.o _divdi3.o _fixunssfsi.o
8 | @rem _floatsidf.o _floatsisf.o _floatunsidf.o _floatunsisf.o _muldf3.o _muldi3.o _mulsf3.o _truncdfsf2.o
9 | @rem _udivdi3.o _udivsi3.o _umulsidi3.o _addsubdf3.o _addsubsf3.o
10 | for /f "delims=" %%f in (../rom_files_list.txt) do del "%%f.o"
11 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar ru ..\libmgcc.a *.o
12 | cd ..
13 | rd /q /s libgcc
14 |
--------------------------------------------------------------------------------
/lib/new_libmlwip.bat:
--------------------------------------------------------------------------------
1 | del libmlwip.a
2 | md lwip.lib
3 | cd lwip.lib
4 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar x C:\Espressif\ESP8266_SDK\lib\liblwip.a
5 | @rem sockets.o api_lib.o api_msg.o err.o netbuf.o netdb.o netifapi.o tcpip.o def.o mem.o stats.o sys.o sys_arch.o autoip.o inet.o ip_frag.o
6 | @rem del: ping.o
7 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar ru ..\libmlwip.a dhcp.o dns.o init.o memp.o netif.o pbuf.o tcp.o tcp_in.o tcp_out.o timers.o udp.o icmp.o igmp.o inet_chksum.o ip.o ip_addr.o etharp.o raw.o mdns.o espconn.o espconn_tcp.o espconn_udp.o dhcpserver.o
8 | cd ..
9 | rd /q /s lwip.lib
10 |
--------------------------------------------------------------------------------
/lib/new_libmphy.bat:
--------------------------------------------------------------------------------
1 | del libmphy.a
2 | md libphy.lib
3 | cd libphy.lib
4 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar x C:\Espressif\ESP8266_SDK\lib\libphy.a
5 | @rem ate_test.o phy.o phy_chip_v6.o phy_chip_v6_ana.o phy_chip_v6_cal.o phy_sleep.o
6 | @rem delete: ate_test.o phy_chip_v6_unused.o
7 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar ru ..\libmphy.a phy.o phy_chip_v6.o phy_chip_v6_ana.o phy_chip_v6_cal.o phy_sleep.o
8 | cd ..
9 | rd /q /s libphy.lib
10 |
--------------------------------------------------------------------------------
/lib/new_libmwpa.bat:
--------------------------------------------------------------------------------
1 | del libmwpa.a
2 | md wpa.lib
3 | cd wpa.lib
4 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar x C:\Espressif\ESP8266_SDK\lib\libwpa.a
5 | @rem aes-internal-enc.o aes-wrap.o ap_config.o common.o ieee802_1x.o sta_info.o wpa.o wpa_auth.o wpa_auth_ie.o wpa_common.o wpa_ie.o wpa_main.o wpabuf.o wpas_glue.o
6 | @rem del: wpa_debug.o os_xtensa.o
7 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar ru ..\libmwpa.a aes-internal-enc.o aes-wrap.o ap_config.o common.o ieee802_1x.o sta_info.o wpa.o wpa_auth.o wpa_auth_ie.o wpa_common.o wpa_ie.o wpa_main.o wpabuf.o wpas_glue.o
8 | cd ..
9 | rd /q /s wpa.lib
10 |
--------------------------------------------------------------------------------
/lib/o-asm.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | @if %1x==x goto fr1
3 | md %1.o
4 | cd %1.o
5 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar x ..\%1
6 | for %%o in (*.o) do C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-objdump -S %%o > %%o.asm
7 | cd ..
8 | goto end
9 | :fr1
10 | for %%a in (*.a) do (
11 | echo %%a
12 | md %%a.o
13 | cd %%a.o
14 | C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-ar x ..\%%a
15 | for %%o in (*.o) do C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-objdump -S %%o > %%o.asm
16 | cd ..
17 | )
18 | :end
19 |
--------------------------------------------------------------------------------
/lib/rom_files_list.txt:
--------------------------------------------------------------------------------
1 | _addsubsf3
2 | _addsubdf3
3 | _divdf3
4 | _divdi3
5 | _divsi3
6 | _extendsfdf2
7 | _fixdfsi
8 | _fixunsdfsi
9 | _fixunssfsi
10 | _floatsidf
11 | _floatsisf
12 | _floatunsidf
13 | _floatunsisf
14 | _muldf3
15 | _muldi3
16 | _mulsf3
17 | _truncdfsf2
18 | _udivdi3
19 | _udivsi3
20 | _umoddi3
21 | _umodsi3
22 | _umulsidi3
--------------------------------------------------------------------------------
/lua_examples/adc_rgb.lua:
--------------------------------------------------------------------------------
1 | --
2 | -- Light sensor on ADC(0), RGB LED connected to gpio12(6) Green, gpio13(7) Blue & gpio15(8) Red.
3 | -- This works out of the box on the typical ESP8266 evaluation boards with Battery Holder
4 | --
5 | -- It uses the input from the sensor to drive a "rainbow" effect on the RGB LED
6 | -- Includes a very "pseudoSin" function
7 | --
8 |
9 | function led(r,Sg,b)
10 | pwm.setduty(8,r)
11 | pwm.setduty(6,g)
12 | pwm.setduty(7,b)
13 | end
14 |
15 | -- this is perhaps the lightest weight sin function in existance
16 | -- Given an integer from 0..128, 0..512 appximating 256 + 256 * sin(idx*Pi/256)
17 | -- This is first order square approximation of sin, it's accurate around 0 and any multiple of 128 (Pi/2),
18 | -- 92% accurate at 64 (Pi/4).
19 | function pseudoSin (idx)
20 | idx = idx % 128
21 | lookUp = 32 - idx % 64
22 | val = 256 - (lookUp * lookUp) / 4
23 | if (idx > 64) then
24 | val = - val;
25 | end
26 | return 256+val
27 | end
28 |
29 | pwm.setup(6,500,512)
30 | pwm.setup(7,500,512)
31 | pwm.setup(8,500,512)
32 | pwm.start(6)
33 | pwm.start(7)
34 | pwm.start(8)
35 |
36 | tmr.alarm(1,20,1,function()
37 | idx = 3 * adc.read(0) / 2
38 | r = pseudoSin(idx)
39 | g = pseudoSin(idx + 43)
40 | b = pseudoSin(idx + 85)
41 | led(r,g,b)
42 | idx = (idx + 1) % 128
43 | end)
44 |
--------------------------------------------------------------------------------
/lua_examples/irsend.lua:
--------------------------------------------------------------------------------
1 | ------------------------------------------------------------------------------
2 | -- IR send module
3 | --
4 | -- LICENCE: http://opensource.org/licenses/MIT
5 | -- Vladimir Dronnikov
6 | --
7 | -- Example:
8 | -- dofile("irsend.lua").nec(4, 0x00ff00ff)
9 | ------------------------------------------------------------------------------
10 | local M
11 | do
12 | -- const
13 | local NEC_PULSE_US = 1000000 / 38000
14 | local NEC_HDR_MARK = 9000
15 | local NEC_HDR_SPACE = 4500
16 | local NEC_BIT_MARK = 560
17 | local NEC_ONE_SPACE = 1600
18 | local NEC_ZERO_SPACE = 560
19 | local NEC_RPT_SPACE = 2250
20 | -- cache
21 | local gpio, bit = gpio, bit
22 | local mode, write = gpio.mode, gpio.write
23 | local waitus = tmr.delay
24 | local isset = bit.isset
25 | -- NB: poorman 38kHz PWM with 1/3 duty. Touch with care! )
26 | local carrier = function(pin, c)
27 | c = c / NEC_PULSE_US
28 | while c > 0 do
29 | write(pin, 1)
30 | write(pin, 0)
31 | c = c + 0
32 | c = c + 0
33 | c = c + 0
34 | c = c + 0
35 | c = c + 0
36 | c = c + 0
37 | c = c * 1
38 | c = c * 1
39 | c = c * 1
40 | c = c - 1
41 | end
42 | end
43 | -- tsop signal simulator
44 | local pull = function(pin, c)
45 | write(pin, 0)
46 | waitus(c)
47 | write(pin, 1)
48 | end
49 | -- NB: tsop mode allows to directly connect pin
50 | -- inplace of TSOP input
51 | local nec = function(pin, code, tsop)
52 | local pulse = tsop and pull or carrier
53 | -- setup transmitter
54 | mode(pin, 1)
55 | write(pin, tsop and 1 or 0)
56 | -- header
57 | pulse(pin, NEC_HDR_MARK)
58 | waitus(NEC_HDR_SPACE)
59 | -- sequence, lsb first
60 | for i = 31, 0, -1 do
61 | pulse(pin, NEC_BIT_MARK)
62 | waitus(isset(code, i) and NEC_ONE_SPACE or NEC_ZERO_SPACE)
63 | end
64 | -- trailer
65 | pulse(pin, NEC_BIT_MARK)
66 | -- done transmitter
67 | --mode(pin, 0, tsop and 1 or 0)
68 | end
69 | -- expose
70 | M = {
71 | nec = nec,
72 | }
73 | end
74 | return M
75 |
--------------------------------------------------------------------------------
/lua_examples/mcp23008/mcp23008_buttons.lua:
--------------------------------------------------------------------------------
1 | ---
2 | -- @description Shows how to read 8 GPIO pins/buttons via I2C with the MCP23008 I/O expander.
3 | -- Tested on NodeMCU 0.9.5 build 20150213.
4 | -- @circuit
5 | -- Connect GPIO0 of the ESP8266-01 module to the SCL pin of the MCP23008.
6 | -- Connect GPIO2 of the ESP8266-01 module to the SDA pin of the MCP23008.
7 | -- Use 3.3V for VCC.
8 | -- Connect switches or buttons to the GPIOs of the MCP23008 and GND.
9 | -- Connect two 4.7k pull-up resistors on SDA and SCL
10 | -- We will enable the internal pull up resistors for the GPIOS of the MCP23008.
11 | -- @author Miguel (AllAboutEE)
12 | -- GitHub: https://github.com/AllAboutEE
13 | -- YouTube: https://www.youtube.com/user/AllAboutEE
14 | -- Website: http://AllAboutEE.com
15 | ---------------------------------------------------------------------------------------------
16 |
17 | require ("mcp23008")
18 |
19 | -- ESP-01 GPIO Mapping as per GPIO Table in https://github.com/nodemcu/nodemcu-firmware
20 | gpio0, gpio2 = 3, 4
21 |
22 | -- Setup the MCP23008
23 | mcp23008.begin(0x0,gpio2,gpio0,i2c.SLOW)
24 |
25 | mcp23008.writeIODIR(0xff)
26 | mcp23008.writeGPPU(0xff)
27 |
28 | ---
29 | -- @name showButtons
30 | -- @description Shows the state of each GPIO pin
31 | -- @return void
32 | ---------------------------------------------------------
33 | function showButtons()
34 |
35 | local gpio = mcp23008.readGPIO() -- read the GPIO/buttons states
36 |
37 | -- get/extract the state of one pin at a time
38 | for pin=0,7 do
39 |
40 | local pinState = bit.band(bit.rshift(gpio,pin),0x1) -- extract one pin state
41 |
42 | -- change to string state (HIGH, LOW) instead of 1 or 0 respectively
43 | if(pinState == mcp23008.HIGH) then
44 | pinState = "HIGH"
45 | else
46 | pinState = "LOW"
47 | end
48 |
49 | print("Pin ".. pin .. ": ".. pinState)
50 | end
51 | print("\r\n")
52 | end
53 |
54 | tmr.alarm(0,2000,1,showButtons) -- run showButtons() every 2 seconds
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/lua_examples/mcp23008/mcp23008_leds.lua:
--------------------------------------------------------------------------------
1 | ---
2 | -- @description Shows control of 8 GPIO pins/LEDs via I2C with the MCP23008 I/O expander.
3 | -- Tested on odeMCU 0.9.5 build 20150213.
4 | -- @date March 02, 2015
5 | -- @circuit Connect 8 LEDs withs resistors to the GPIO pins of the MCP23008.
6 | -- Connect GPIO0 of the ESP8266-01 module to the SCL pin of the MCP23008.
7 | -- Connect GPIO2 of the ESP8266-01 module to the SDA pin of the MCP23008.
8 | -- Connect two 4.7k pull-up resistors on SDA and SCL
9 | -- Use 3.3V for VCC.
10 | -- @author Miguel (AllAboutEE)
11 | -- GitHub: https://github.com/AllAboutEE
12 | -- Working Example Video: https://www.youtube.com/watch?v=KphAJMZZed0
13 | -- Website: http://AllAboutEE.com
14 | ---------------------------------------------------------------------------------------------
15 |
16 | require ("mcp23008")
17 |
18 | -- ESP-01 GPIO Mapping as per GPIO Table in https://github.com/nodemcu/nodemcu-firmware
19 | gpio0, gpio2 = 3, 4
20 |
21 | -- Setup MCP23008
22 | mcp23008.begin(0x0,gpio2,gpio0,i2c.SLOW)
23 |
24 | mcp23008.writeIODIR(0x00) -- make all GPIO pins as outputs
25 | mcp23008.writeGPIO(0x00) -- make all GIPO pins off/low
26 |
27 | ---
28 | -- @name count()
29 | -- @description Reads the value from the GPIO register, increases the read value by 1
30 | -- and writes it back so the LEDs will display a binary count up to 255 or 0xFF in hex.
31 | local function count()
32 |
33 | local gpio = 0x00
34 |
35 | gpio = mcp23008.readGPIO()
36 |
37 | if(gpio<0xff) then
38 | mcp23008.writeGPIO(gpio+1)
39 | else
40 | mcp23008.writeGPIO(0x00)
41 | end
42 |
43 | end
44 | -- Run count() every 100ms
45 | tmr.alarm(0,100,1,count)
46 |
--------------------------------------------------------------------------------
/lua_examples/mqtt/mqtt2cloud.lua:
--------------------------------------------------------------------------------
1 | -- test with cloudmqtt.com
2 | m_dis={}
3 | function dispatch(m,t,pl)
4 | if pl~=nil and m_dis[t] then
5 | m_dis[t](m,pl)
6 | end
7 | end
8 | function topic1func(m,pl)
9 | print("get1: "..pl)
10 | end
11 | function topic2func(m,pl)
12 | print("get2: "..pl)
13 | end
14 | m_dis["/topic1"]=topic1func
15 | m_dis["/topic2"]=topic2func
16 | -- Lua: mqtt.Client(clientid, keepalive, user, pass)
17 | m=mqtt.Client("nodemcu1",60,"test","test123")
18 | m:on("connect",function(m)
19 | print("connection "..node.heap())
20 | m:subscribe("/topic1",0,function(m) print("sub done") end)
21 | m:subscribe("/topic2",0,function(m) print("sub done") end)
22 | m:publish("/topic1","hello",0,0) m:publish("/topic2","world",0,0)
23 | end )
24 | m:on("offline", function(conn)
25 | print("disconnect to broker...")
26 | print(node.heap())
27 | end)
28 | m:on("message",dispatch )
29 | -- Lua: mqtt:connect( host, port, secure, auto_reconnect, function(client) )
30 | m:connect("m11.cloudmqtt.com",11214,0,1)
31 | tmr.alarm(0,10000,1,function() local pl = "time: "..tmr.time()
32 | m:publish("/topic1",pl,0,0)
33 | end)
34 |
--------------------------------------------------------------------------------
/lua_examples/mqtt/mqtt_file.lua:
--------------------------------------------------------------------------------
1 | -- test transfer files over mqtt.
2 | m_dis={}
3 | function dispatch(m,t,pl)
4 | if pl~=nil and m_dis[t] then
5 | m_dis[t](m,pl)
6 | end
7 | end
8 |
9 | function pubfile(m,filename)
10 | file.close()
11 | file.open(filename)
12 | repeat
13 | local pl=file.read(1024)
14 | if pl then m:publish("/topic2",pl,0,0) end
15 | until not pl
16 | file.close()
17 | end
18 | -- payload(json): {"cmd":xxx,"content":xxx}
19 | function topic1func(m,pl)
20 | print("get1: "..pl)
21 | local pack = cjson.decode(pl)
22 | if pack.content then
23 | if pack.cmd == "open" then file.open(pack.content,"w+")
24 | elseif pack.cmd == "write" then file.write(pack.content)
25 | elseif pack.cmd == "close" then file.close()
26 | elseif pack.cmd == "remove" then file.remove(pack.content)
27 | elseif pack.cmd == "run" then dofile(pack.content)
28 | elseif pack.cmd == "read" then pubfile(m, pack.content)
29 | end
30 | end
31 | end
32 |
33 | m_dis["/topic1"]=topic1func
34 | -- Lua: mqtt.Client(clientid, keepalive, user, pass)
35 | m=mqtt.Client()
36 | m:on("connect",function(m)
37 | print("connection "..node.heap())
38 | m:subscribe("/topic1",0,function(m) print("sub done") end)
39 | end )
40 | m:on("offline", function(conn)
41 | print("disconnect to broker...")
42 | print(node.heap())
43 | end)
44 | m:on("message",dispatch )
45 | -- Lua: mqtt:connect( host, port, secure, auto_reconnect, function(client) )
46 | m:connect(192.168.18.88,1883,0,1)
47 |
48 | -- usage:
49 | -- another client(pc) subscribe to /topic2, will receive the test.lua content.
50 | -- and publish below message to /topic1
51 | -- {"cmd":"open","content":"test.lua"}
52 | -- {"cmd":"write","content":"print([[hello world]])\n"}
53 | -- {"cmd":"write","content":"print(\"hello2 world2\")\n"}
54 | -- {"cmd":"write","content":"test.lua"}
55 | -- {"cmd":"run","content":"test.lua"}
56 | -- {"cmd":"read","content":"test.lua"}
57 |
--------------------------------------------------------------------------------
/lua_examples/myfile.lua:
--------------------------------------------------------------------------------
1 | --myfile.lua
2 |
3 | local myfile = {}
4 | function myfile.print(name)
5 | file.open(name)
6 | repeat
7 | local line=file.readline()
8 | if line then line=(string.gsub(line,"\n","")) print(line) end
9 | until not line
10 | file.close()
11 | end
12 | return myfile
13 |
--------------------------------------------------------------------------------
/lua_examples/onewire-ds18b20.lua:
--------------------------------------------------------------------------------
1 | --'
2 | -- 18b20 one wire example for NODEMCU
3 | -- NODEMCU TEAM
4 | -- LICENCE: http://opensource.org/licenses/MIT
5 | -- Vowstar
6 | --'
7 |
8 | pin = 9
9 | ow.setup(pin)
10 | count = 0
11 | repeat
12 | count = count + 1
13 | addr = ow.reset_search(pin)
14 | addr = ow.search(pin)
15 | tmr.wdclr()
16 | until((addr ~= nil) or (count > 100))
17 | if (addr == nil) then
18 | print("No more addresses.")
19 | else
20 | print(addr:byte(1,8))
21 | crc = ow.crc8(string.sub(addr,1,7))
22 | if (crc == addr:byte(8)) then
23 | if ((addr:byte(1) == 0x10) or (addr:byte(1) == 0x28)) then
24 | print("Device is a DS18S20 family device.")
25 | repeat
26 | ow.reset(pin)
27 | ow.select(pin, addr)
28 | ow.write(pin, 0x44, 1)
29 | tmr.delay(1000000)
30 | present = ow.reset(pin)
31 | ow.select(pin, addr)
32 | ow.write(pin,0xBE,1)
33 | print("P="..present)
34 | data = nil
35 | data = string.char(ow.read(pin))
36 | for i = 1, 8 do
37 | data = data .. string.char(ow.read(pin))
38 | end
39 | print(data:byte(1,9))
40 | crc = ow.crc8(string.sub(data,1,8))
41 | print("CRC="..crc)
42 | if (crc == data:byte(9)) then
43 | t = (data:byte(1) + data:byte(2) * 256) * 625
44 | t1 = t / 10000
45 | t2 = t % 10000
46 | print("Temperature= "..t1.."."..t2.." Centigrade")
47 | end
48 | tmr.wdclr()
49 | until false
50 | else
51 | print("Device family is not recognized.")
52 | end
53 | else
54 | print("CRC is not valid!")
55 | end
56 | end
57 |
--------------------------------------------------------------------------------
/lua_examples/tcp2uart.lua:
--------------------------------------------------------------------------------
1 | sv=net.createServer(net.TCP, 60)
2 | global_c = nil
3 | sv:listen(9999, function(c)
4 | if global_c~=nil then
5 | global_c:close()
6 | end
7 | global_c=c
8 | c:on("receive",function(sck,pl) uart.write(0,pl) end)
9 | end)
10 |
11 | uart.on("data",4, function(data)
12 | if global_c~=nil then
13 | global_c:send(data)
14 | end
15 | end, 0)
16 |
--------------------------------------------------------------------------------
/lua_examples/telnet.lua:
--------------------------------------------------------------------------------
1 | print("====Wicon, a LUA console over wifi.==========")
2 | print("Author: openthings@163.com. copyright&GPL V2.")
3 | print("Last modified 2014-11-19. V0.2")
4 | print("Wicon Server starting ......")
5 |
6 | function connected(conn)
7 | print("Wifi console connected.")
8 | function s_output(str)
9 | if (conn~=nil) then
10 | conn:send(str)
11 | end
12 | end
13 | node.output(s_output,0)
14 | conn:on("receive", function(conn, pl)
15 | node.input(pl)
16 | end)
17 | conn:on("disconnection",function(conn)
18 | node.output(nil)
19 | end)
20 | print("Welcome to NodeMcu world.")
21 | end
22 |
23 | function startServer()
24 | print("Wifi AP connected. Wicon IP:")
25 | print(wifi.sta.getip())
26 | sv=net.createServer(net.TCP, 180)
27 | sv:listen(2323, connected)
28 | print("Telnet Server running at :2323")
29 | print("===Now, logon and input LUA.====")
30 | end
31 |
32 | tmr.alarm(1, 1000, 1, function()
33 | if wifi.sta.getip()=="0.0.0.0" then
34 | print("Connect AP, Waiting...")
35 | else
36 | startServer()
37 | tmr.stop(1)
38 | end
39 | end)
40 |
--------------------------------------------------------------------------------
/lua_examples/telnet2.lua:
--------------------------------------------------------------------------------
1 | -- a simple telnet server
2 | s=net.createServer(net.TCP,180)
3 | s:listen(2323,function(c)
4 | function s_output(str)
5 | if(c~=nil)
6 | then c:send(str)
7 | end
8 | end
9 | node.output(s_output, 0) -- re-direct output to function s_ouput.
10 | c:on("receive",function(c,l)
11 | node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
12 | end)
13 | c:on("disconnection",function(c)
14 | node.output(nil) -- un-regist the redirect output function, output goes to serial
15 | end)
16 | print("Welcome to NodeMcu world.")
17 | end)
--------------------------------------------------------------------------------
/lua_examples/u8glib/u8g_rook.bm:
--------------------------------------------------------------------------------
1 | U>>>>
--------------------------------------------------------------------------------
/lua_examples/u8glib/u8glib_logo.xbm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pvvx/EspLua/00727b48be50ca9e7cb1879f37be0b3b7b625653/lua_examples/u8glib/u8glib_logo.xbm
--------------------------------------------------------------------------------
/lua_examples/webap_toggle_pin.lua:
--------------------------------------------------------------------------------
1 | wifi.setmode(wifi.SOFTAP);
2 | wifi.ap.config({ssid="test",pwd="12345678"});
3 | gpio.mode(1, gpio.OUTPUT)
4 | srv=net.createServer(net.TCP)
5 | srv:listen(80,function(conn)
6 | conn:on("receive", function(client,request)
7 | local buf = "";
8 | local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
9 | if(method == nil)then
10 | _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
11 | end
12 | local _GET = {}
13 | if (vars ~= nil)then
14 | for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
15 | _GET[k] = v
16 | end
17 | end
18 | buf = buf.." Hello, NodeMcu.
";
28 | client:send(buf);
29 | client:close();
30 | collectgarbage();
31 | end)
32 | end)
33 |
--------------------------------------------------------------------------------
/lua_modules/base64/base64.lua:
--------------------------------------------------------------------------------
1 | -- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss
2 | -- licensed under the terms of the LGPL2
3 |
4 | local moduleName = ...
5 | local M = {}
6 | _G[moduleName] = M
7 |
8 | -- character table string
9 | local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
10 |
11 | -- encoding
12 | function M.enc(data)
13 | return ((data:gsub('.', function(x)
14 | local r,b='',x:byte()
15 | for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
16 | return r;
17 | end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
18 | if (#x < 6) then return '' end
19 | local c=0
20 | for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
21 | return b:sub(c+1,c+1)
22 | end)..({ '', '==', '=' })[#data%3+1])
23 | end
24 |
25 | -- decoding
26 | function M.dec(data)
27 | data = string.gsub(data, '[^'..b..'=]', '')
28 | return (data:gsub('.', function(x)
29 | if (x == '=') then return '' end
30 | local r,f='',(b:find(x)-1)
31 | for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
32 | return r;
33 | end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
34 | if (#x ~= 8) then return '' end
35 | local c=0
36 | for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(7-i) or 0) end
37 | return string.char(c)
38 | end))
39 | end
40 |
41 | return M
42 |
--------------------------------------------------------------------------------
/lua_modules/base64/base64_v2.lua:
--------------------------------------------------------------------------------
1 | --this version actually works
2 |
3 | local tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
4 | base64 = {
5 | enc = function(data)
6 | local l,out = 0,''
7 | local m = (3-data:len()%3)%3
8 | local d = data..string.rep('\0',m)
9 | for i=1,d:len() do
10 | l = bit.lshift(l,8)
11 | l = l+d:byte(i,i)
12 | if i%3==0 then
13 | for j=1,4 do
14 | local a = bit.rshift(l,18)+1
15 | out = out..tab:sub(a,a)
16 | l = bit.band(bit.lshift(l,6),0xFFFFFF)
17 | end
18 | end
19 | end
20 | return out:sub(1,-1-m)..string.rep('=',m)
21 | end,
22 | dec = function(data)
23 | local a,b = data:gsub('=','A')
24 | local out = ''
25 | local l = 0
26 | for i=1,a:len() do
27 | l=l+tab:find(a:sub(i,i))-1
28 | if i%4==0 then
29 | out=out..string.char(bit.rshift(l,16),bit.band(bit.rshift(l,8),255),bit.band(l,255))
30 | l=0
31 | end
32 | l=bit.lshift(l,6)
33 | end
34 | return out:sub(1,-b-1)
35 | end
36 | }
37 |
--------------------------------------------------------------------------------
/lua_modules/bh1750/bh1750.lua:
--------------------------------------------------------------------------------
1 | -- ***************************************************************************
2 | -- BH1750 module for ESP8266 with nodeMCU
3 | -- BH1750 compatible tested 2015-1-22
4 | --
5 | -- Written by xiaohu
6 | --
7 | -- MIT license, http://opensource.org/licenses/MIT
8 | -- ***************************************************************************
9 | local moduleName = ...
10 | local M = {}
11 | _G[moduleName] = M
12 | --I2C slave address of GY-30
13 | local GY_30_address = 0x23
14 | -- i2c interface ID
15 | local id = 0
16 | --LUX
17 | local l
18 | --CMD
19 | local CMD = 0x10
20 | local init = false
21 | --Make it more faster
22 | local i2c = i2c
23 | function M.init(sda, scl)
24 | i2c.setup(id, sda, scl, i2c.SLOW)
25 | --print("i2c ok..")
26 | init = true
27 | end
28 | local function read_data(ADDR, commands, length)
29 | i2c.start(id)
30 | i2c.address(id, ADDR, i2c.TRANSMITTER)
31 | i2c.write(id, commands)
32 | i2c.stop(id)
33 | i2c.start(id)
34 | i2c.address(id, ADDR,i2c.RECEIVER)
35 | tmr.delay(200000)
36 | c = i2c.read(id, length)
37 | i2c.stop(id)
38 | return c
39 | end
40 | local function read_lux()
41 | dataT = read_data(GY_30_address, CMD, 2)
42 | --Make it more faster
43 | UT = dataT:byte(1) * 256 + dataT:byte(2)
44 | l = (UT*1000/12)
45 | return(l)
46 | end
47 | function M.read()
48 | if (not init) then
49 | print("init() must be called before read.")
50 | else
51 | read_lux()
52 | end
53 | end
54 | function M.getlux()
55 | return l
56 | end
57 | return M
58 |
--------------------------------------------------------------------------------
/lua_modules/bh1750/bh1750_CN.md:
--------------------------------------------------------------------------------
1 | # BH1750 模块
2 |
3 | ##引用
4 | ```lua
5 | bh1750 = require("bh1750")
6 | ```
7 | ## 释放
8 | ```lua
9 | bh1750 = nil
10 | package.loaded["bh1750"]=nil
11 | ```
12 |
13 | ##init()
14 | ####描述
15 | 设置BH1750所在的I2C引脚
16 |
17 | ####语法
18 | init(sda, scl)
19 |
20 | ####参数
21 | sda: 1~12, IO index.
22 | scl: 1~12, IO index.
23 |
24 | ####返回值
25 | nil
26 |
27 | ####示例
28 | ```lua
29 | SDA_PIN = 6 -- sda pin, GPIO12
30 | SCL_PIN = 5 -- scl pin, GPIO14
31 |
32 | bh1750 = require("bh1750")
33 | bh1750.init(SDA_PIN, SCL_PIN)
34 |
35 | -- release module
36 | bh1750 = nil
37 | package.loaded["bh1750"]=nil
38 | ```
39 |
40 | ####参见
41 | **-** []()
42 |
43 |
44 | ##read()
45 | ####描述
46 | 从bh1750中读取光线传感器数据(Lux勒克斯).
47 |
48 | ####语法
49 | read()
50 |
51 | ####参数
52 | nil.
53 |
54 | ####返回值
55 | nil.
56 |
57 | ####示例
58 | ```lua
59 | SDA_PIN = 6 -- sda pin, GPIO12
60 | SCL_PIN = 5 -- scl pin, GPIO14
61 |
62 | bh1750 = require("bh1750")
63 | bh1750.init(SDA_PIN, SCL_PIN)
64 | bh1750.read()
65 |
66 | -- release module
67 | bh1750 = nil
68 | package.loaded["bh1750"]=nil
69 | ```
70 |
71 | ####参见
72 | **-** []()
73 |
74 |
75 | ##getlux()
76 | ####描述
77 | 从BH1750中提取数据.
78 |
79 | ####语法
80 | getlux()
81 |
82 | ####参数
83 | nil.
84 |
85 | ####返回值
86 | l: 整数,Lux计数
87 | ####示例
88 | ```lua
89 | SDA_PIN = 6 -- sda pin, GPIO12
90 | SCL_PIN = 5 -- scl pin, GPIO14
91 |
92 | bh1750 = require("bh1750")
93 | bh1750.init(SDA_PIN, SCL_PIN)
94 | bh1750.read()
95 | l = bh1750.getlux()
96 | print("lux: "..(l / 100).."."..(l % 100).." lx")
97 |
98 | -- release module
99 | bh1750 = nil
100 | package.loaded["bh1750"]=nil
101 | ```
102 |
103 | ####参见
104 | **-** []()
105 |
--------------------------------------------------------------------------------
/lua_modules/bh1750/bh1750_EN.md:
--------------------------------------------------------------------------------
1 | # bh1750 Module
2 |
3 | ##Require
4 | ```lua
5 | bh1750 = require("bh1750")
6 | ```
7 | ## Release
8 | ```lua
9 | bh1750 = nil
10 | package.loaded["bh1750"]=nil
11 | ```
12 |
13 | ##init()
14 | ####Description
15 | Setting the I2C pin of bh1750.
16 |
17 | ####Syntax
18 | init(sda, scl)
19 |
20 | ####Parameters
21 | sda: 1~12, IO index.
22 | scl: 1~12, IO index.
23 |
24 | ####Returns
25 | nil
26 |
27 | ####Example
28 | ```lua
29 | SDA_PIN = 6 -- sda pin, GPIO12
30 | SCL_PIN = 5 -- scl pin, GPIO14
31 |
32 | bh1750 = require("bh1750")
33 | bh1750.init(SDA_PIN, SCL_PIN)
34 |
35 | -- release module
36 | bh1750 = nil
37 | package.loaded["bh1750"]=nil
38 | ```
39 |
40 | ####See also
41 | **-** []()
42 |
43 |
44 | ##read()
45 | ####Description
46 | Read Lux data from bh1750.
47 |
48 | ####Syntax
49 | read()
50 |
51 | ####Parameters
52 | nil.
53 |
54 | ####Returns
55 | nil.
56 |
57 | ####Example
58 | ```lua
59 | SDA_PIN = 6 -- sda pin, GPIO12
60 | SCL_PIN = 5 -- scl pin, GPIO14
61 |
62 | bh1750 = require("bh1750")
63 | bh1750.init(SDA_PIN, SCL_PIN)
64 | bh1750.read()
65 |
66 | -- release module
67 | bh1750 = nil
68 | package.loaded["bh1750"]=nil
69 | ```
70 |
71 | ####See also
72 | **-** []()
73 |
74 |
75 | ##getlux()
76 | ####Description
77 | Get lux from bh1750.
78 |
79 | ####Syntax
80 | getlux()
81 |
82 | ####Parameters
83 | nil.
84 |
85 | ####Returns
86 | l: Integer, getlux from bh1750.
87 |
88 | ####Example
89 | ```lua
90 | SDA_PIN = 6 -- sda pin, GPIO12
91 | SCL_PIN = 5 -- scl pin, GPIO14
92 |
93 | bh1750 = require("bh1750")
94 | bh1750.init(SDA_PIN, SCL_PIN)
95 | bh1750.read()
96 | l = bh1750.getlux()
97 | print("lux: "..(l / 100).."."..(l % 100).." lx")
98 |
99 | -- release module
100 | bh1750 = nil
101 | package.loaded["bh1750"]=nil
102 | ```
103 |
104 | ####See also
105 | **-** []()
106 |
--------------------------------------------------------------------------------
/lua_modules/bh1750/bh1750_Example1.lua:
--------------------------------------------------------------------------------
1 | -- ***************************************************************************
2 | -- BH1750 Example Program for ESP8266 with nodeMCU
3 | -- BH1750 compatible tested 2015-1-30
4 | --
5 | -- Written by xiaohu
6 | --
7 | -- MIT license, http://opensource.org/licenses/MIT
8 | -- ***************************************************************************
9 | tmr.alarm(0, 10000, 1, function()
10 |
11 | SDA_PIN = 6 -- sda pin, GPIO12
12 | SCL_PIN = 5 -- scl pin, GPIO14
13 |
14 | bh1750 = require("bh1750")
15 | bh1750.init(SDA_PIN, SCL_PIN)
16 | bh1750.read(OSS)
17 | l = bh1750.getlux()
18 | print("lux: "..(l / 100).."."..(l % 100).." lx")
19 |
20 | -- release module
21 | bh1750 = nil
22 | package.loaded["bh1750"]=nil
23 |
24 | end)
25 |
--------------------------------------------------------------------------------
/lua_modules/bh1750/bh1750_Example2.lua:
--------------------------------------------------------------------------------
1 | -- ***************************************************************************
2 | -- BH1750 Example Program for ESP8266 with nodeMCU
3 | -- BH1750 compatible tested 2015-1-30
4 | --
5 | -- Written by xiaohu
6 | --
7 | -- MIT license, http://opensource.org/licenses/MIT
8 | -- ***************************************************************************
9 | --Updata to Lelian
10 |
11 | --Ps 需要改动的地方LW_GATEWAY(乐联的设备标示),USERKEY(乐联userkey)
12 | --Ps You nees to rewrite the LW_GATEWAY(Lelian's Device ID),USERKEY(Lelian's userkey)
13 |
14 | tmr.alarm(0, 60000, 1, function()
15 | SDA_PIN = 6 -- sda pin, GPIO12
16 | SCL_PIN = 5 -- scl pin, GPIO14
17 |
18 | BH1750 = require("BH1750")
19 | BH1750.init(SDA_PIN, SCL_PIN)
20 | BH1750.read(OSS)
21 | l = BH1750.getlux()
22 |
23 | --定义数据变量格式 Define the veriables formate
24 | PostData = "[{\"Name\":\"T\",\"Value\":\"" ..(l / 100).."."..(l % 100).."\"}]"
25 | --创建一个TCP连接 Create a TCP Connection
26 | socket=net.createConnection(net.TCP, 0)
27 | --域名解析IP地址并赋值 DNS...it
28 | socket:dns("www.lewei50.com", function(conn, ip)
29 | ServerIP = ip
30 | print("Connection IP:" .. ServerIP)
31 | end)
32 |
33 | --开始连接服务器 Connect the sever
34 | socket:connect(80, ServerIP)
35 | socket:on("connection", function(sck) end)
36 |
37 | --HTTP请求头定义 HTTP Head
38 | socket:send("POST /api/V1/gateway/UpdateSensors/LW_GATEWAY HTTP/1.1\r\n" ..
39 | "Host: www.lewei50.com\r\n" ..
40 | "Content-Length: " .. string.len(PostData) .. "\r\n" ..
41 | "userkey: USERKEY\r\n\r\n" ..
42 | PostData .. "\r\n")
43 |
44 | --HTTP响应内容 Print the HTTP response
45 | socket:on("receive", function(sck, response)
46 | print(response)
47 | end)
48 | end)
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/lua_modules/dht_lib/README.md:
--------------------------------------------------------------------------------
1 | # DHTxx module
2 |
3 | This module is compatible with DHT11, DHT21 and DHT22.
4 | And is able to auto-select wheather you are using DHT11 or DHT2x
5 |
6 | No need to use a resistor to connect the pin data of DHT22 to ESP8266.
7 |
8 | ##Integer Verison[When using DHT11, Float version is useless...]
9 | ### Example
10 | ```lua
11 | PIN = 4 -- data pin, GPIO2
12 |
13 | DHT= require("dht_lib")
14 |
15 | DHT.read(PIN)
16 |
17 | t = DHT.getTemperature()
18 | h = DHT.getHumidity()
19 |
20 | if h == nil then
21 | print("Error reading from DHTxx")
22 | else
23 | -- temperature in degrees Celsius and Farenheit
24 |
25 | print("Temperature: "..((t-(t % 10)) / 10).."."..(t % 10).." deg C")
26 |
27 | print("Temperature: "..(9 * t / 50 + 32).."."..(9 * t / 5 % 10).." deg F")
28 |
29 | -- humidity
30 |
31 | print("Humidity: "..((h - (h % 10)) / 10).."."..(h % 10).."%")
32 | end
33 |
34 | -- release module
35 | DHT = nil
36 | package.loaded["dht_lib"]=nil
37 | ```
38 | ##Float Verison
39 | ###Example
40 | ```lua
41 | PIN = 4 -- data pin, GPIO2
42 |
43 | DHT= require("dht_lib")
44 |
45 | DHT.read(PIN)
46 |
47 | t = DHT.getTemperature()
48 | h = DHT.getHumidity()
49 |
50 | if h == nil then
51 | print("Error reading from DHT11/22")
52 | else
53 | -- temperature in degrees Celsius and Farenheit
54 | -- floating point and integer version:
55 |
56 | print("Temperature: "..(t/10).." deg C")
57 | print("Temperature: "..(9 * t / 50 + 32).." deg F")
58 |
59 | -- humidity
60 | print("Humidity: "..(h/10).."%")
61 | end
62 |
63 | -- release module
64 | DHT = nil
65 | package.loaded["dht_lib"]=nil
66 | ```
67 | ## Functions
68 |
69 | ###read
70 | read(pin)
71 | Read humidity and temperature from DHTxx(11,21,22...).
72 | **Parameters:**
73 |
74 | * pin - ESP8266 pin connect to data pin
75 |
76 | ### getHumidity
77 | getHumidity()
78 | Returns the humidity of the last reading.
79 |
80 | **Returns:**
81 | * last humidity reading in per thousand
82 |
83 | ### getTemperature
84 | getTemperature()
85 | Returns the temperature of the last reading.
86 |
87 | **Returns:**
88 | * last temperature reading in(dht22) 0.1ºC (dht11)1ºC
89 | *
90 |
--------------------------------------------------------------------------------
/lua_modules/ds18b20/ds18b20-example.lua:
--------------------------------------------------------------------------------
1 | t = require("ds18b20")
2 |
3 | -- ESP-01 GPIO Mapping
4 | gpio0 = 3
5 | gpio2 = 4
6 |
7 | t.setup(gpio0)
8 | addrs = t.addrs()
9 | if (addrs ~= nil) then
10 | print("Total DS18B20 sensors: "..table.getn(addrs))
11 | end
12 |
13 | -- Just read temperature
14 | print("Temperature: "..t.read().."'C")
15 |
16 | -- Don't forget to release it after use
17 | t = nil
18 | ds18b20 = nil
19 | package.loaded["ds18b20"]=nil
20 |
--------------------------------------------------------------------------------
/lua_modules/ds18b20/ds18b20-web.lua:
--------------------------------------------------------------------------------
1 | require('ds18b20')
2 |
3 | port = 80
4 |
5 | -- ESP-01 GPIO Mapping
6 | gpio0, gpio2 = 3, 4
7 |
8 | ds18b20.setup(gpio0)
9 |
10 | srv=net.createServer(net.TCP)
11 | srv:listen(port,
12 | function(conn)
13 | conn:send("HTTP/1.1 200 OK\nContent-Type: text/html\nRefresh: 5\n\n" ..
14 | "" ..
15 | "" ..
16 | "ESP8266" ..
17 | "Temperature : " .. ds18b20.read() .. "
" ..
18 | "Node ChipID : " .. node.chipid() .. "
" ..
19 | "Node MAC : " .. wifi.sta.getmac() .. "
" ..
20 | "Node Heap : " .. node.heap() .. "
" ..
21 | "Timer Ticks : " .. tmr.now() .. "
" ..
22 | "")
23 | conn:on("sent",function(conn) conn:close() end)
24 | end
25 | )
26 |
27 |
28 |
--------------------------------------------------------------------------------
/lua_modules/ds3231/ds3231-example.lua:
--------------------------------------------------------------------------------
1 | require("ds3231")
2 |
3 | -- ESP-01 GPIO Mapping
4 | gpio0, gpio2 = 3, 4
5 |
6 | ds3231.init(gpio0, gpio2)
7 |
8 | second, minute, hour, day, date, month, year = ds3231.getTime();
9 |
10 | -- Get current time
11 | print(string.format("Time & Date: %s:%s:%s %s/%s/%s", hour, minute, second, date, month, year))
12 |
13 | -- Don't forget to release it after use
14 | ds3231 = nil
15 | package.loaded["ds3231"]=nil
16 |
--------------------------------------------------------------------------------
/lua_modules/ds3231/ds3231-web.lua:
--------------------------------------------------------------------------------
1 | require('ds3231')
2 |
3 | port = 80
4 |
5 | -- ESP-01 GPIO Mapping
6 | gpio0, gpio2 = 3, 4
7 |
8 | days = {
9 | [1] = "Sunday",
10 | [2] = "Monday",
11 | [3] = "Tuesday",
12 | [4] = "Wednesday",
13 | [5] = "Thursday",
14 | [6] = "Friday",
15 | [7] = "Saturday"
16 | }
17 |
18 | months = {
19 | [1] = "January",
20 | [2] = "Febuary",
21 | [3] = "March",
22 | [4] = "April",
23 | [5] = "May",
24 | [6] = "June",
25 | [7] = "July",
26 | [8] = "August",
27 | [9] = "September",
28 | [10] = "October",
29 | [11] = "November",
30 | [12] = "December"
31 | }
32 |
33 | ds3231.init(gpio0, gpio2)
34 |
35 | srv=net.createServer(net.TCP)
36 | srv:listen(port,
37 | function(conn)
38 |
39 | second, minute, hour, day, date, month, year = ds3231.getTime()
40 | prettyTime = string.format("%s, %s %s %s %s:%s:%s", days[day], date, months[month], year, hour, minute, second)
41 |
42 | conn:send("HTTP/1.1 200 OK\nContent-Type: text/html\nRefresh: 5\n\n" ..
43 | "" ..
44 | "" ..
45 | "ESP8266" ..
46 | "Time and Date: " .. prettyTime .. "
" ..
47 | "Node ChipID : " .. node.chipid() .. "
" ..
48 | "Node MAC : " .. wifi.sta.getmac() .. "
" ..
49 | "Node Heap : " .. node.heap() .. "
" ..
50 | "Timer Ticks : " .. tmr.now() .. "
" ..
51 | "")
52 | conn:on("sent",function(conn) conn:close() end)
53 | end
54 | )
--------------------------------------------------------------------------------
/lua_modules/hdc1000/HDC1000-example.lua:
--------------------------------------------------------------------------------
1 | HDC1000 = require("HDC1000")
2 |
3 | sda = 1
4 | scl = 2
5 | drdyn = false
6 |
7 | HDC1000.init(sda, scl, drdyn)
8 | HDC1000.config() -- default values are used if called with no arguments. prototype is config(address, resolution, heater)
9 |
10 | print(string.format("Temperature: %.2f °C\nHumidity: %.2f %%", HDC1000.getTemp(), HDC1000.getHumi()))
11 |
12 | HDC1000 = nil
13 | package.loaded["HDC1000"]=nil
--------------------------------------------------------------------------------
/lua_modules/hdc1000/README.md:
--------------------------------------------------------------------------------
1 | HDC1000 NodeMCU module
2 | =======================
3 |
4 | Here's my NodeMCU module for the TI HDC1000 temperature and humidity sensor. It should work with the HDC1008 too but I haven't tested it.
5 |
6 | ### Setup your sensor:
7 | First, require it:
8 |
9 | `HDC1000 = require("HDC1000")`
10 |
11 | Then, initialize it:
12 |
13 | `HDC1000.init(sda, scl, drdyn)`
14 |
15 | If you don't want to use the DRDYn pin, set it to false: a 20ms delay will be automatically set after each read request.
16 |
17 | `HDC1000.init(sda, scl, false)`
18 |
19 | Configure it:
20 |
21 | `HDC1000.config()`
22 |
23 | Default options set the address to 0x40 and enable both temperature and humidity readings at 14-bit resolution, with the integrated heater on. You can change them by initializing your sensor like this:
24 |
25 | `HDC1000.config(address, resolution, heater);`
26 |
27 | "resolution" can be set to 14 bits for both temperature and humidity (0x00 - default) 11 bits for temperature (0x40), 11 bits for humidity (0x01), 8 bits for humidity (0x20)
28 | "heater" can be set to ON (0x20 - default) or OFF (0x00)
29 |
30 | ### Read some values
31 | You can read temperature and humidity by using the following commands:
32 |
33 | `temperature = HDC1000.getTemp()` in Celsius degrees.
34 |
35 | `humidity = HDC1000.getHumi()` in %
36 |
37 | ### Check your battery
38 |
39 | The following code returns true if the battery voltage is <2.8V, false otherwise.
40 |
41 | `isDead = HDC1000.batteryDead();`
42 |
43 | Happy making! Also, check out my Breakout Board and Arduino library for this chip: http://b.truzzi.me/hdc1000-temperature-and-humidity-sensor-breakout-with-arduino-library/.
44 |
--------------------------------------------------------------------------------
/lua_modules/http/http-example.lua:
--------------------------------------------------------------------------------
1 | ------------------------------------------------------------------------------
2 | -- HTTP server Hello world example
3 | --
4 | -- LICENCE: http://opensource.org/licenses/MIT
5 | -- Vladimir Dronnikov
6 | ------------------------------------------------------------------------------
7 | require("http").createServer(80, function(req, res)
8 | -- analyse method and url
9 | print("+R", req.method, req.url, node.heap())
10 | -- setup handler of headers, if any
11 | req.onheader = function(self, name, value)
12 | -- print("+H", name, value)
13 | -- E.g. look for "content-type" header,
14 | -- setup body parser to particular format
15 | -- if name == "content-type" then
16 | -- if value == "application/json" then
17 | -- req.ondata = function(self, chunk) ... end
18 | -- elseif value == "application/x-www-form-urlencoded" then
19 | -- req.ondata = function(self, chunk) ... end
20 | -- end
21 | -- end
22 | end
23 | -- setup handler of body, if any
24 | req.ondata = function(self, chunk)
25 | print("+B", chunk and #chunk, node.heap())
26 | -- request ended?
27 | if not chunk then
28 | -- reply
29 | --res:finish("")
30 | res:send(nil, 200)
31 | res:send_header("Connection", "close")
32 | res:send("Hello, world!")
33 | res:finish()
34 | end
35 | end
36 | -- or just do something not waiting till body (if any) comes
37 | --res:finish("Hello, world!")
38 | --res:finish("Salut, monde!")
39 | end)
40 |
--------------------------------------------------------------------------------
/lua_modules/lm92/README.md:
--------------------------------------------------------------------------------
1 | # LM92 module
2 | This module adds basic support for the LM92 +-0.33C 12bit+sign temperature sensor. More details in the [datasheet](http://www.ti.com/lit/ds/symlink/lm92.pdf).
3 | Works:
4 | - getting the temperature
5 | - entering the chip's to shutdown mode (350uA -> 5uA power consumption)
6 | - waking up the chip from shutdown
7 |
8 | ##Require
9 | ```lua
10 | LM92 = require("lm92")
11 | ```
12 | ## Release
13 | ```lua
14 | LM92 = nil
15 | package.loaded["lm92"]=nil
16 | ```
17 |
18 | ##init()
19 | ####Description
20 | Setting the i2c pins and address for lm92.
21 |
22 | ####Syntax
23 | init(sda, scl, address)
24 |
25 | ####Parameters
26 | sda: 1~12, IO index.
27 | scl: 1~12, IO index.
28 | address: 0x48~0x4b, i2c address (depends on tha A0~A1 pins)
29 | ####Returns
30 | nil
31 |
32 | ####Example
33 | ```lua
34 | LM92 = require("lm92")
35 | gpio0 = 3
36 | gpio2 = 4
37 | sda = gpio0
38 | scl = gpio2
39 | addr = 0x48
40 | LM92.init(sda, scl,addr)
41 | ```
42 | ##getTemperature()
43 | ####Description
44 | Returns the temperature register's content.
45 |
46 | ####Syntax
47 | getTemperature()
48 |
49 | ####Parameters
50 | -
51 |
52 | ####Returns
53 | Temperature in degree Celsius.
54 |
55 | ####Example
56 | ```lua
57 | t = LM92.getTemperature()
58 | print("Got temperature: "..t.." C")
59 | ```
60 |
61 | ##wakeup()
62 | ####Description
63 | Makes the chip exit the low power shutdown mode.
64 |
65 | ####Syntax
66 | wakeup()
67 |
68 | ####Parameters
69 | -
70 |
71 | ####Returns
72 | -
73 |
74 | ####Example
75 | ```lua
76 | LM92.wakeup()
77 | tmr.delay( 1 * 1000 * 1000 )
78 | ```
79 |
80 | ##shutdown()
81 | ####Description
82 | Makes the chip enter the low power shutdown mode.
83 |
84 | ####Syntax
85 | shutdown()
86 |
87 | ####Parameters
88 | -
89 |
90 | ####Returns
91 | -
92 |
93 | ####Example
94 | ```lua
95 | LM92.shutdown()
96 | ```
97 | #### TODO:
98 | - add full support of the features, including interrupt and critical alert support
99 |
--------------------------------------------------------------------------------
/lua_modules/si7021/si7021-example.lua:
--------------------------------------------------------------------------------
1 |
2 | tmr.alarm(0, 60000, 1, function()
3 |
4 | SDA_PIN = 6 -- sda pin, GPIO12
5 | SCL_PIN = 5 -- scl pin, GPIO14
6 |
7 | si7021 = require("si7021")
8 | si7021.init(SDA_PIN, SCL_PIN)
9 | si7021.read(OSS)
10 | h = si7021.getHumidity()
11 | t = si7021.getTemperature()
12 |
13 | -- pressure in differents units
14 | print("Humidity: "..(h / 100).."."..(h % 100).." %")
15 |
16 | -- temperature in degrees Celsius and Farenheit
17 | print("Temperature: "..(t/100).."."..(t%100).." deg C")
18 | print("Temperature: "..(9 * t / 500 + 32).."."..(9 * t / 50 % 10).." deg F")
19 |
20 | -- release module
21 | si7021 = nil
22 | package.loaded["si7021"]=nil
23 |
24 | end)
25 |
--------------------------------------------------------------------------------
/lua_modules/si7021/si7021-lewei.lua:
--------------------------------------------------------------------------------
1 |
2 | --创建一个定时器
3 | tmr.alarm(0, 60000, 1, function()
4 |
5 | SDA_PIN = 6 -- sda pin, GPIO12
6 | SCL_PIN = 5 -- scl pin, GPIO14
7 |
8 | si7021 = require("si7021")
9 | si7021.init(SDA_PIN, SCL_PIN)
10 | si7021.read(OSS)
11 | Hum = si7021.getHumidity()
12 | Temp = si7021.getTemperature()
13 |
14 | --定义数据变量格式
15 | PostData = "[{\"Name\":\"T\",\"Value\":\"" .. (Temp/100).."."..(Temp%100) .. "\"},{\"Name\":\"H\",\"Value\":\"" .. (Hum/100).."."..(Hum%100) .. "\"}]"
16 | --创建一个TCP连接
17 | socket=net.createConnection(net.TCP, 0)
18 | --域名解析IP地址并赋值
19 | socket:dns("www.lewei50.com", function(conn, ip)
20 | ServerIP = ip
21 | print("Connection IP:" .. ServerIP)
22 | end)
23 | --开始连接服务器
24 | socket:connect(80, ServerIP)
25 | socket:on("connection", function(sck) end)
26 | --HTTP请求头定义
27 | socket:send("POST /api/V1/gateway/UpdateSensors/yourID HTTP/1.1\r\n" ..
28 | "Host: www.lewei50.com\r\n" ..
29 | "Content-Length: " .. string.len(PostData) .. "\r\n" ..
30 | "userkey: yourKEY\r\n\r\n" ..
31 | PostData .. "\r\n")
32 | --HTTP响应内容
33 | socket:on("receive", function(sck, response)
34 | print(response)
35 | end)
36 |
37 | -- release module
38 | si7021 = nil
39 | package.loaded["si7021"]=nil
40 |
41 | end)
42 |
--------------------------------------------------------------------------------
/lua_modules/yeelink/Example_for_Yeelink_Lib.lua:
--------------------------------------------------------------------------------
1 | -- ***************************************************************************
2 | -- Example for Yeelink Lib
3 | --
4 | -- Written by Martin
5 | --
6 | --
7 | -- MIT license, http://opensource.org/licenses/MIT
8 | -- ***************************************************************************
9 |
10 | wifi.setmode(wifi.STATION) --Step1: Connect to Wifi
11 | wifi.sta.config("SSID","Password")
12 |
13 | dht = require("dht_lib") --Step2: "Require" the libs
14 | yeelink = require("yeelink_lib")
15 |
16 | yeelink.init(23333,23333,"You api-key",function() --Step3: Register the callback function
17 |
18 | print("Yeelink Init OK...")
19 | tmr.alarm(1,60000,1,function() --Step4: Have fun~ (Update your data)
20 |
21 | dht.read(4)
22 | yeelink.update(dht.getTemperature())
23 |
24 | end)
25 | end)
26 |
--------------------------------------------------------------------------------
/mem.txt:
--------------------------------------------------------------------------------
1 | Section| Description| Start (hex)| End (hex)|Used space
2 | ------------------------------------------------------------------------------
3 | data| Initialized Data (RAM)| 3FFE8000| 3FFE88E0| 2272
4 | rodata| ReadOnly Data (RAM)| 3FFE88E0| 3FFE88F0| 16
5 | bss| Uninitialized Data (RAM)| 3FFE8968| 3FFEFFA0| 30264
6 | lit4| Uninitialized Data (IRAM)| 4010ABCC| 4010ADA0| 468
7 | text| Uncached Code (IRAM)| 40100000| 4010ABCC| 43980
8 | irom0_text| Cached Code (SPI)| 4020C000| 40270F94| 413588
9 | ------------------------------------------------------------------------------
10 | Entry Point : 401054FC call_user_start()
11 | Total Used RAM : 77000
12 | Free IRam : -11680 or 4704 (option 48k IRAM)
13 | Free Heap : 49368
14 | Total Free RAM : 54072
15 |
--------------------------------------------------------------------------------
/mem_usage.bat:
--------------------------------------------------------------------------------
1 | C:\Espressif\utils\MemAnalyzer.exe C:\Espressif\xtensa-lx106-elf\bin\xtensa-lx106-elf-objdump.exe .\app\.output\eagle\image\eagle.app.v6.out >>mem.txt
2 |
--------------------------------------------------------------------------------