├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── app ├── Makefile ├── pando │ ├── Makefile │ ├── gateway │ │ ├── Makefile │ │ ├── gateway_defs.h │ │ ├── mqtt │ │ │ ├── Makefile │ │ │ ├── debug.h │ │ │ ├── mqtt.c │ │ │ ├── mqtt.h │ │ │ ├── mqtt_msg.c │ │ │ ├── mqtt_msg.h │ │ │ ├── proto.c │ │ │ ├── proto.h │ │ │ ├── queue.c │ │ │ ├── queue.h │ │ │ ├── ringbuf.c │ │ │ ├── ringbuf.h │ │ │ ├── typedef.h │ │ │ ├── utils.c │ │ │ └── utils.h │ │ ├── pando_channel.c │ │ ├── pando_channel.h │ │ ├── pando_cloud_access.c │ │ ├── pando_cloud_access.h │ │ ├── pando_device_login.c │ │ ├── pando_device_login.h │ │ ├── pando_device_register.c │ │ ├── pando_device_register.h │ │ ├── pando_gateway.c │ │ ├── pando_gateway.h │ │ ├── pando_lan_bind.c │ │ ├── pando_lan_bind.h │ │ ├── pando_storage_interface.c │ │ ├── pando_storage_interface.h │ │ ├── pando_system_time.c │ │ ├── pando_system_time.h │ │ ├── pando_zero_device.c │ │ ├── pando_zero_device.h │ │ └── readme.txt │ ├── pando_framework.c │ ├── pando_framework.h │ ├── pando_object.c │ ├── pando_object.h │ ├── pando_subdevice.c │ ├── pando_subdevice.h │ ├── protocol │ │ ├── Makefile │ │ ├── common_functions.c │ │ ├── common_functions.h │ │ ├── pando_endian.c │ │ ├── pando_endian.h │ │ ├── pando_machine.c │ │ ├── pando_machine.h │ │ ├── pando_protocol.c │ │ ├── pando_protocol.h │ │ ├── readme.txt │ │ ├── sub_device_protocol.c │ │ └── sub_device_protocol.h │ └── readme.txt ├── peripheral │ ├── Makefile │ ├── driver │ │ ├── Makefile │ │ ├── adc.c │ │ ├── adc.h │ │ ├── gpio.h │ │ ├── gpio16.c │ │ ├── gpio16.h │ │ ├── i2c.c │ │ ├── i2c.h │ │ ├── key.c │ │ ├── key.h │ │ ├── pwm.c │ │ ├── pwm.h │ │ ├── readme.txt │ │ ├── spi.c │ │ ├── spi.h │ │ ├── spi_register.h │ │ ├── tisan_gpio.c │ │ ├── tisan_gpio.h │ │ ├── tisan_gpio_intr.c │ │ ├── tisan_gpio_intr.h │ │ ├── uart.c │ │ ├── uart.h │ │ └── uart_register.h │ ├── oled_font.h │ ├── peri_dht1122.c │ ├── peri_dht1122.h │ ├── peri_i2c_oled.c │ ├── peri_i2c_oled.h │ ├── peri_iaq.c │ ├── peri_iaq.h │ ├── peri_jdq.c │ ├── peri_jdq.h │ ├── peri_key.c │ ├── peri_key.h │ ├── peri_ldr.c │ ├── peri_ldr.h │ ├── peri_led.c │ ├── peri_led.h │ ├── peri_motor.c │ ├── peri_motor.h │ ├── peri_pm25.c │ ├── peri_pm25.h │ ├── peri_rgb_light.c │ ├── peri_rgb_light.h │ ├── peri_usart_gpu.c │ ├── peri_usart_gpu.h │ └── readme.txt ├── user │ ├── Makefile │ ├── device_config.h │ ├── objects │ │ ├── Makefile │ │ ├── air.c │ │ ├── air.h │ │ ├── humiture.c │ │ ├── humiture.h │ │ ├── led.c │ │ ├── led.h │ │ ├── motor.c │ │ ├── motor.h │ │ ├── plug.c │ │ ├── plug.h │ │ ├── pm25.c │ │ ├── pm25.h │ │ ├── readme.txt │ │ ├── temperature.c │ │ ├── temperature.h │ │ ├── usart_gpu.c │ │ └── usart_gpu.h │ ├── readme.txt │ ├── user_main.c │ ├── wifi_config.c │ └── wifi_config.h └── util │ ├── Makefile │ ├── cert.h │ ├── converter.c │ ├── converter.h │ ├── httpclient.c │ ├── httpclient.h │ ├── pando_json.c │ ├── pando_json.h │ ├── private_key.h │ └── readme.txt ├── bin ├── blank.bin ├── boot_v1.2.bin ├── eagle.flash.bin ├── eagle.irom0text.bin ├── esp_init_data_default.bin └── upgrade │ ├── readme.txt │ └── user1.4096.new.4.bin ├── include ├── c_types.h ├── eagle_soc.h ├── espconn.h ├── espnow.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 ├── queue.h ├── smartconfig.h ├── sntp.h ├── spi_flash.h └── user_interface.h ├── ld ├── eagle.app.v6.app1.ld ├── eagle.app.v6.app2.ld ├── eagle.app.v6.ld ├── eagle.app.v6.new.1024.app1.ld ├── eagle.app.v6.new.1024.app2.ld ├── eagle.app.v6.new.2048.ld ├── eagle.app.v6.new.512.app1.ld ├── eagle.app.v6.new.512.app2.ld ├── eagle.app.v6.old.1024.app1.ld ├── eagle.app.v6.old.1024.app2.ld ├── eagle.app.v6.old.512.app1.ld ├── eagle.app.v6.old.512.app2.ld └── eagle.rom.addr.v6.ld ├── lib ├── libat.a ├── libcrypto.a ├── libespnow.a ├── libjson.a ├── liblwip.a ├── liblwip_536.a ├── libmain.a ├── libnet80211.a ├── libphy.a ├── libpp.a ├── libpwm.a ├── libsmartconfig.a ├── libssl.a ├── libupgrade.a ├── libwpa.a └── libwps.a ├── pic ├── firmware0.jpg ├── firmware1.jpg ├── firmware2.jpg ├── firmware3.jpg ├── show0.jpg ├── show1.jpg ├── show2.jpg ├── show4.png ├── show5.png ├── show6.png ├── show7.png ├── tft-tisan-connect.JPG ├── usart-gpu.JPG ├── webide1.jpg ├── webide2.jpg ├── webide3.jpg └── webide4.jpg ├── reference_doc └── Usart_GPU_Reference.pdf └── tools ├── gen_appbin.py ├── makefile.sh └── xxd.exe /.gitignore: -------------------------------------------------------------------------------- 1 | .cproject 2 | *.S 3 | 4 | *.dump 5 | *.o 6 | *.out 7 | *.a 8 | !/lib/*.a 9 | *.d 10 | *.d.* 11 | *.bin_rep 12 | *.project 13 | .settings/org.eclipse.core.resources.prefs 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 PandoCloud 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/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # Required variables for each makefile 3 | # Discard this section from all parent makefiles 4 | # Expected variables (with automatic defaults): 5 | # CSRCS (all "C" files in the dir) 6 | # SUBDIRS (all subdirs with a Makefile) 7 | # GEN_LIBS - list of libs to be generated () 8 | # GEN_IMAGES - list of object file images to be generated () 9 | # GEN_BINS - list of binaries 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 | TARGET = eagle 15 | FLAVOR = debug 16 | 17 | #EXTRA_CCFLAGS += -u 18 | 19 | ifndef PDIR # { 20 | GEN_IMAGES= eagle.app.v6.out 21 | GEN_BINS= eagle.app.v6.bin 22 | SPECIAL_MKTARGETS=$(APP_MKTARGETS) 23 | SUBDIRS= \ 24 | user \ 25 | util \ 26 | pando \ 27 | peripheral 28 | endif # } PDIR 29 | 30 | APPDIR = . 31 | LDDIR = ../ld 32 | 33 | CCFLAGS += -Os 34 | 35 | TARGET_LDFLAGS = \ 36 | -nostdlib \ 37 | -Wl,-EL \ 38 | --longcalls \ 39 | --text-section-literals 40 | 41 | ifeq ($(FLAVOR),debug) 42 | TARGET_LDFLAGS += -g -O2 43 | endif 44 | 45 | ifeq ($(FLAVOR),release) 46 | TARGET_LDFLAGS += -g -O0 47 | endif 48 | 49 | COMPONENTS_eagle.app.v6 = \ 50 | util/libutil.a \ 51 | user/libuser.a \ 52 | user/objects/libobjects.a \ 53 | pando/libpando.a \ 54 | peripheral/libperipheral.a \ 55 | peripheral/driver/libdriver.a \ 56 | pando/gateway/libgateway.a \ 57 | pando/gateway/mqtt/libmqtt.a \ 58 | pando/protocol/libprotocol.a \ 59 | 60 | LINKFLAGS_eagle.app.v6 = \ 61 | -L../lib \ 62 | -nostdlib \ 63 | -T$(LD_FILE) \ 64 | -Wl,--no-check-sections \ 65 | -u call_user_start \ 66 | -Wl,-static \ 67 | -Wl,--start-group \ 68 | -lc \ 69 | -lgcc \ 70 | -lhal \ 71 | -lphy \ 72 | -lpp \ 73 | -lnet80211 \ 74 | -llwip \ 75 | -lwpa \ 76 | -lmain \ 77 | -ljson \ 78 | -lssl \ 79 | -lsmartconfig \ 80 | $(DEP_LIBS_eagle.app.v6) \ 81 | -Wl,--end-group 82 | 83 | DEPENDS_eagle.app.v6 = \ 84 | $(LD_FILE) \ 85 | $(LDDIR)/eagle.rom.addr.v6.ld 86 | 87 | ############################################################# 88 | # Configuration i.e. compile options etc. 89 | # Target specific stuff (defines etc.) goes in here! 90 | # Generally values applying to a tree are captured in the 91 | # makefile at its root level - these are then overridden 92 | # for a subtree within the makefile rooted therein 93 | # 94 | 95 | #UNIVERSAL_TARGET_DEFINES = \ 96 | 97 | # Other potential configuration flags include: 98 | # -DTXRX_TXBUF_DEBUG 99 | # -DTXRX_RXBUF_DEBUG 100 | # -DWLAN_CONFIG_CCX 101 | ifeq ($(FLAVOR),debug) 102 | CONFIGURATION_DEFINES = -DICACHE_FLASH -DTEST_ENVEROMENT -DDEBUG_MSG -DESP8266_PLANTFORM 103 | endif 104 | 105 | ifeq ($(FLAVOR),release) 106 | CONFIGURATION_DEFINES = -DICACHE_FLASH -DDEBUG_MSG -DESP8266_PLANTFORM 107 | endif 108 | 109 | 110 | ifeq ($(FLAVOR),production) 111 | CONFIGURATION_DEFINES = -DICACHE_FLASH -DESP8266_PLANTFORM 112 | endif 113 | 114 | DEFINES += \ 115 | $(UNIVERSAL_TARGET_DEFINES) \ 116 | $(CONFIGURATION_DEFINES) 117 | 118 | DDEFINES += \ 119 | $(UNIVERSAL_TARGET_DEFINES) \ 120 | $(CONFIGURATION_DEFINES) 121 | 122 | 123 | ############################################################# 124 | # Recursion Magic - Don't touch this!! 125 | # 126 | # Each subtree potentially has an include directory 127 | # corresponding to the common APIs applicable to modules 128 | # rooted at that subtree. Accordingly, the INCLUDE PATH 129 | # of a module can only contain the include directories up 130 | # its parent path, and not its siblings 131 | # 132 | # Required for each makefile to inherit from the parent 133 | # 134 | 135 | INCLUDES := $(INCLUDES) -I $(PDIR)include 136 | PDIR := ../$(PDIR) 137 | sinclude $(PDIR)Makefile 138 | 139 | .PHONY: FORCE 140 | FORCE: 141 | 142 | -------------------------------------------------------------------------------- /app/pando/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 object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = libpando.a 17 | SUBDIRS= \ 18 | gateway \ 19 | gateway/mqtt \ 20 | protocol 21 | endif 22 | 23 | 24 | ############################################################# 25 | # Configuration i.e. compile options etc. 26 | # Target specific stuff (defines etc.) goes in here! 27 | # Generally values applying to a tree are captured in the 28 | # makefile at its root level - these are then overridden 29 | # for a subtree within the makefile rooted therein 30 | # 31 | 32 | #UNIVERSAL_TARGET_DEFINES = \ 33 | 34 | ifndef PDIR 35 | GEN_LIBS = libpando.a 36 | SUBDIRS= \ 37 | gateway \ 38 | protocol 39 | endif 40 | 41 | # Other potential configuration flags include: 42 | # -DTXRX_TXBUF_DEBUG 43 | # -DTXRX_RXBUF_DEBUG 44 | # -DWLAN_CONFIG_CCX 45 | 46 | ############################################################# 47 | # Recursion Magic - Don't touch this!! 48 | # 49 | # Each subtree potentially has an include directory 50 | # corresponding to the common APIs applicable to modules 51 | # rooted at that subtree. Accordingly, the INCLUDE PATH 52 | # of a module can only contain the include directories up 53 | # its parent path, and not its siblings 54 | # 55 | # Required for each makefile to inherit from the parent 56 | # 57 | 58 | INCLUDES := $(INCLUDES) -I $(PDIR)include 59 | PDIR := ../$(PDIR) 60 | sinclude $(PDIR)Makefile 61 | 62 | .PHONY: FORCE 63 | FORCE: 64 | 65 | -------------------------------------------------------------------------------- /app/pando/gateway/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 object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = libgateway.a 17 | SUBDIRS= \ 18 | mqtt 19 | endif 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 | 29 | #UNIVERSAL_TARGET_DEFINES = \ 30 | 31 | # Other potential configuration flags include: 32 | # -DTXRX_TXBUF_DEBUG 33 | # -DTXRX_RXBUF_DEBUG 34 | # -DWLAN_CONFIG_CCX 35 | 36 | 37 | ############################################################# 38 | # Recursion Magic - Don't touch this!! 39 | # 40 | # Each subtree potentially has an include directory 41 | # corresponding to the common APIs applicable to modules 42 | # rooted at that subtree. Accordingly, the INCLUDE PATH 43 | # of a module can only contain the include directories up 44 | # its parent path, and not its siblings 45 | # 46 | # Required for each makefile to inherit from the parent 47 | # 48 | 49 | INCLUDES := $(INCLUDES) -I $(PDIR)include 50 | PDIR := ../$(PDIR) 51 | sinclude $(PDIR)Makefile 52 | 53 | .PHONY: FORCE 54 | FORCE: 55 | 56 | -------------------------------------------------------------------------------- /app/pando/gateway/gateway_defs.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: gateway_defs.h 3 | * Author:Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is to used to define the parameter and structure used in gateway. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __GATEWAY_DEFS_H__ 13 | #define __GATEWAY_DEFS_H__ 14 | 15 | #define PANDO_API_URL "https://api.pandocloud.com" 16 | 17 | #define DATANAME_DEVICE_ID "pando_device_id" 18 | #define DATANAME_DEVICE_SECRET "pando_device_secret" 19 | #define DATANAME_DEVICE_KEY "pando_device_key" 20 | #define DATANAME_ACCESS_TOKEN "pando_access_token" 21 | #define DATANAME_ACCESS_ADDR "pando_access_addr" 22 | 23 | #define PANDO_DEVICE_MODULE "esp8266" 24 | 25 | #define PANDO_SDK_VERSION "1.3.0" 26 | 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /app/pando/gateway/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 = libmqtt.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 | PDIR := ../$(PDIR) 43 | sinclude $(PDIR)Makefile 44 | 45 | -------------------------------------------------------------------------------- /app/pando/gateway/mqtt/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * debug.h 3 | * 4 | * Created on: Dec 4, 2014 5 | * Author: Minh 6 | */ 7 | 8 | #ifndef USER_DEBUG_H_ 9 | #define USER_DEBUG_H_ 10 | 11 | #include "osapi.h" 12 | #ifndef INFO 13 | #define INFO os_printf 14 | #endif 15 | 16 | #endif /* USER_DEBUG_H_ */ 17 | -------------------------------------------------------------------------------- /app/pando/gateway/mqtt/proto.c: -------------------------------------------------------------------------------- 1 | #include "proto.h" 2 | #include "ringbuf.h" 3 | I8 ICACHE_FLASH_ATTR PROTO_Init(PROTO_PARSER *parser, PROTO_PARSE_CALLBACK *completeCallback, U8 *buf, U16 bufSize) 4 | { 5 | parser->buf = buf; 6 | parser->bufSize = bufSize; 7 | parser->dataLen = 0; 8 | parser->callback = completeCallback; 9 | parser->isEsc = 0; 10 | return 0; 11 | } 12 | 13 | I8 ICACHE_FLASH_ATTR PROTO_ParseByte(PROTO_PARSER *parser, U8 value) 14 | { 15 | switch(value){ 16 | case 0x7D: 17 | parser->isEsc = 1; 18 | break; 19 | 20 | case 0x7E: 21 | parser->dataLen = 0; 22 | parser->isEsc = 0; 23 | parser->isBegin = 1; 24 | break; 25 | 26 | case 0x7F: 27 | if (parser->callback != NULL) 28 | parser->callback(); 29 | parser->isBegin = 0; 30 | return 0; 31 | break; 32 | 33 | default: 34 | if(parser->isBegin == 0) break; 35 | 36 | if(parser->isEsc){ 37 | value ^= 0x20; 38 | parser->isEsc = 0; 39 | } 40 | 41 | if(parser->dataLen < parser->bufSize) 42 | parser->buf[parser->dataLen++] = value; 43 | 44 | break; 45 | } 46 | return -1; 47 | } 48 | 49 | I8 ICACHE_FLASH_ATTR PROTO_Parse(PROTO_PARSER *parser, U8 *buf, U16 len) 50 | { 51 | while(len--) 52 | PROTO_ParseByte(parser, *buf++); 53 | 54 | return 0; 55 | } 56 | I16 ICACHE_FLASH_ATTR PROTO_ParseRb(RINGBUF* rb, U8 *bufOut, U16* len, U16 maxBufLen) 57 | { 58 | U8 c; 59 | 60 | PROTO_PARSER proto; 61 | PROTO_Init(&proto, NULL, bufOut, maxBufLen); 62 | while(RINGBUF_Get(rb, &c) == 0){ 63 | if(PROTO_ParseByte(&proto, c) == 0){ 64 | *len = proto.dataLen; 65 | return 0; 66 | } 67 | } 68 | return -1; 69 | } 70 | I16 ICACHE_FLASH_ATTR PROTO_Add(U8 *buf, const U8 *packet, I16 bufSize) 71 | { 72 | U16 i = 2; 73 | U16 len = *(U16*) packet; 74 | 75 | if (bufSize < 1) return -1; 76 | 77 | *buf++ = 0x7E; 78 | bufSize--; 79 | 80 | while (len--) { 81 | switch (*packet) { 82 | case 0x7D: 83 | case 0x7E: 84 | case 0x7F: 85 | if (bufSize < 2) return -1; 86 | *buf++ = 0x7D; 87 | *buf++ = *packet++ ^ 0x20; 88 | i += 2; 89 | bufSize -= 2; 90 | break; 91 | default: 92 | if (bufSize < 1) return -1; 93 | *buf++ = *packet++; 94 | i++; 95 | bufSize--; 96 | break; 97 | } 98 | } 99 | 100 | if (bufSize < 1) return -1; 101 | *buf++ = 0x7F; 102 | 103 | return i; 104 | } 105 | 106 | I16 ICACHE_FLASH_ATTR PROTO_AddRb(RINGBUF *rb, const U8 *packet, I16 len) 107 | { 108 | U16 i = 2; 109 | if(RINGBUF_Put(rb, 0x7E) == -1) return -1; 110 | while (len--) { 111 | switch (*packet) { 112 | case 0x7D: 113 | case 0x7E: 114 | case 0x7F: 115 | if(RINGBUF_Put(rb, 0x7D) == -1) return -1; 116 | if(RINGBUF_Put(rb, *packet++ ^ 0x20) == -1) return -1; 117 | i += 2; 118 | break; 119 | default: 120 | if(RINGBUF_Put(rb, *packet++) == -1) return -1; 121 | i++; 122 | break; 123 | } 124 | } 125 | if(RINGBUF_Put(rb, 0x7F) == -1) return -1; 126 | 127 | return i; 128 | } 129 | 130 | -------------------------------------------------------------------------------- /app/pando/gateway/mqtt/proto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: proto.h 3 | * Author: ThuHien 4 | * 5 | * Created on November 23, 2012, 8:57 AM 6 | */ 7 | 8 | #ifndef _PROTO_H_ 9 | #define _PROTO_H_ 10 | #include 11 | #include "typedef.h" 12 | #include "ringbuf.h" 13 | 14 | typedef void(PROTO_PARSE_CALLBACK)(); 15 | 16 | typedef struct{ 17 | U8 *buf; 18 | U16 bufSize; 19 | U16 dataLen; 20 | U8 isEsc; 21 | U8 isBegin; 22 | PROTO_PARSE_CALLBACK* callback; 23 | }PROTO_PARSER; 24 | 25 | I8 ICACHE_FLASH_ATTR PROTO_Init(PROTO_PARSER *parser, PROTO_PARSE_CALLBACK *completeCallback, U8 *buf, U16 bufSize); 26 | I8 ICACHE_FLASH_ATTR PROTO_Parse(PROTO_PARSER *parser, U8 *buf, U16 len); 27 | I16 ICACHE_FLASH_ATTR PROTO_Add(U8 *buf, const U8 *packet, I16 bufSize); 28 | I16 ICACHE_FLASH_ATTR PROTO_AddRb(RINGBUF *rb, const U8 *packet, I16 len); 29 | I8 ICACHE_FLASH_ATTR PROTO_ParseByte(PROTO_PARSER *parser, U8 value); 30 | I16 ICACHE_FLASH_ATTR PROTO_ParseRb(RINGBUF *rb, U8 *bufOut, U16* len, U16 maxBufLen); 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /app/pando/gateway/mqtt/queue.c: -------------------------------------------------------------------------------- 1 | /* str_queue.c 2 | * 3 | * Copyright (c) 2014-2015, Tuan PM 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #include "queue.h" 31 | 32 | #include "user_interface.h" 33 | #include "osapi.h" 34 | #include "os_type.h" 35 | #include "mem.h" 36 | #include "proto.h" 37 | void ICACHE_FLASH_ATTR QUEUE_Init(QUEUE *queue, int bufferSize) 38 | { 39 | queue->buf = (uint8_t*)os_zalloc(bufferSize); 40 | RINGBUF_Init(&queue->rb, queue->buf, bufferSize); 41 | } 42 | int32_t ICACHE_FLASH_ATTR QUEUE_Puts(QUEUE *queue, uint8_t* buffer, uint16_t len) 43 | { 44 | return PROTO_AddRb(&queue->rb, buffer, len); 45 | } 46 | int32_t ICACHE_FLASH_ATTR QUEUE_Gets(QUEUE *queue, uint8_t* buffer, uint16_t* len, uint16_t maxLen) 47 | { 48 | 49 | return PROTO_ParseRb(&queue->rb, buffer, len, maxLen); 50 | } 51 | 52 | BOOL ICACHE_FLASH_ATTR QUEUE_IsEmpty(QUEUE *queue) 53 | { 54 | if(queue->rb.fill_cnt<=0) 55 | return TRUE; 56 | return FALSE; 57 | } 58 | -------------------------------------------------------------------------------- /app/pando/gateway/mqtt/queue.h: -------------------------------------------------------------------------------- 1 | /* str_queue.h -- 2 | * 3 | * Copyright (c) 2014-2015, Tuan PM 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef USER_QUEUE_H_ 32 | #define USER_QUEUE_H_ 33 | #include "os_type.h" 34 | #include "ringbuf.h" 35 | typedef struct { 36 | uint8_t *buf; 37 | RINGBUF rb; 38 | } QUEUE; 39 | 40 | void ICACHE_FLASH_ATTR QUEUE_Init(QUEUE *queue, int bufferSize); 41 | int32_t ICACHE_FLASH_ATTR QUEUE_Puts(QUEUE *queue, uint8_t* buffer, uint16_t len); 42 | int32_t ICACHE_FLASH_ATTR QUEUE_Gets(QUEUE *queue, uint8_t* buffer, uint16_t* len, uint16_t maxLen); 43 | BOOL ICACHE_FLASH_ATTR QUEUE_IsEmpty(QUEUE *queue); 44 | #endif /* USER_QUEUE_H_ */ 45 | -------------------------------------------------------------------------------- /app/pando/gateway/mqtt/ringbuf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * Ring Buffer library 4 | */ 5 | 6 | #include "ringbuf.h" 7 | 8 | 9 | /** 10 | * \brief init a RINGBUF object 11 | * \param r pointer to a RINGBUF object 12 | * \param buf pointer to a byte array 13 | * \param size size of buf 14 | * \return 0 if successfull, otherwise failed 15 | */ 16 | I16 ICACHE_FLASH_ATTR RINGBUF_Init(RINGBUF *r, U8* buf, I32 size) 17 | { 18 | if(r == NULL || buf == NULL || size < 2) return -1; 19 | 20 | r->p_o = r->p_r = r->p_w = buf; 21 | r->fill_cnt = 0; 22 | r->size = size; 23 | 24 | return 0; 25 | } 26 | /** 27 | * \brief put a character into ring buffer 28 | * \param r pointer to a ringbuf object 29 | * \param c character to be put 30 | * \return 0 if successfull, otherwise failed 31 | */ 32 | I16 ICACHE_FLASH_ATTR RINGBUF_Put(RINGBUF *r, U8 c) 33 | { 34 | if(r->fill_cnt>=r->size)return -1; // ring buffer is full, this should be atomic operation 35 | 36 | 37 | r->fill_cnt++; // increase filled slots count, this should be atomic operation 38 | 39 | 40 | *r->p_w++ = c; // put character into buffer 41 | 42 | if(r->p_w >= r->p_o + r->size) // rollback if write pointer go pass 43 | r->p_w = r->p_o; // the physical boundary 44 | 45 | return 0; 46 | } 47 | /** 48 | * \brief get a character from ring buffer 49 | * \param r pointer to a ringbuf object 50 | * \param c read character 51 | * \return 0 if successfull, otherwise failed 52 | */ 53 | I16 ICACHE_FLASH_ATTR RINGBUF_Get(RINGBUF *r, U8* c) 54 | { 55 | if(r->fill_cnt<=0)return -1; // ring buffer is empty, this should be atomic operation 56 | 57 | 58 | r->fill_cnt--; // decrease filled slots count 59 | 60 | 61 | *c = *r->p_r++; // get the character out 62 | 63 | if(r->p_r >= r->p_o + r->size) // rollback if write pointer go pass 64 | r->p_r = r->p_o; // the physical boundary 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /app/pando/gateway/mqtt/ringbuf.h: -------------------------------------------------------------------------------- 1 | #ifndef _RING_BUF_H_ 2 | #define _RING_BUF_H_ 3 | 4 | #include 5 | #include 6 | #include "typedef.h" 7 | 8 | typedef struct{ 9 | U8* p_o; /**< Original pointer */ 10 | U8* volatile p_r; /**< Read pointer */ 11 | U8* volatile p_w; /**< Write pointer */ 12 | volatile I32 fill_cnt; /**< Number of filled slots */ 13 | I32 size; /**< Buffer size */ 14 | }RINGBUF; 15 | 16 | I16 ICACHE_FLASH_ATTR RINGBUF_Init(RINGBUF *r, U8* buf, I32 size); 17 | I16 ICACHE_FLASH_ATTR RINGBUF_Put(RINGBUF *r, U8 c); 18 | I16 ICACHE_FLASH_ATTR RINGBUF_Get(RINGBUF *r, U8* c); 19 | #endif 20 | -------------------------------------------------------------------------------- /app/pando/gateway/mqtt/typedef.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * Standard Types definition 4 | */ 5 | 6 | #ifndef _TYPE_DEF_H_ 7 | #define _TYPE_DEF_H_ 8 | 9 | typedef char I8; 10 | typedef unsigned char U8; 11 | typedef short I16; 12 | typedef unsigned short U16; 13 | typedef long I32; 14 | typedef unsigned long U32; 15 | typedef unsigned long long U64; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /app/pando/gateway/mqtt/utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Tuan PM 3 | * Email: tuanpm@live.com 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of the copyright holder nor the names of its 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | * POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | */ 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "utils.h" 39 | 40 | 41 | uint8_t ICACHE_FLASH_ATTR UTILS_IsIPV4 (int8_t *str) 42 | { 43 | uint8_t segs = 0; /* Segment count. */ 44 | uint8_t chcnt = 0; /* Character count within segment. */ 45 | uint8_t accum = 0; /* Accumulator for segment. */ 46 | /* Catch NULL pointer. */ 47 | if (str == 0) 48 | return 0; 49 | /* Process every character in string. */ 50 | 51 | while (*str != '\0') { 52 | /* Segment changeover. */ 53 | 54 | if (*str == '.') { 55 | /* Must have some digits in segment. */ 56 | if (chcnt == 0) 57 | return 0; 58 | /* Limit number of segments. */ 59 | if (++segs == 4) 60 | return 0; 61 | /* Reset segment values and restart loop. */ 62 | chcnt = accum = 0; 63 | str++; 64 | continue; 65 | } 66 | 67 | /* Check numeric. */ 68 | if ((*str < '0') || (*str > '9')) 69 | return 0; 70 | 71 | /* Accumulate and check segment. */ 72 | 73 | if ((accum = accum * 10 + *str - '0') > 255) 74 | return 0; 75 | /* Advance other segment specific stuff and continue loop. */ 76 | 77 | chcnt++; 78 | str++; 79 | } 80 | 81 | /* Check enough segments and enough characters in last segment. */ 82 | 83 | if (segs != 3) 84 | return 0; 85 | if (chcnt == 0) 86 | return 0; 87 | /* Address okay. */ 88 | 89 | return 1; 90 | } 91 | uint8_t ICACHE_FLASH_ATTR UTILS_StrToIP(const int8_t* str, void *ip) 92 | { 93 | 94 | /* The count of the number of bytes processed. */ 95 | int i; 96 | /* A pointer to the next digit to process. */ 97 | const char * start; 98 | 99 | start = str; 100 | for (i = 0; i < 4; i++) { 101 | /* The digit being processed. */ 102 | char c; 103 | /* The value of this byte. */ 104 | int n = 0; 105 | while (1) { 106 | c = * start; 107 | start++; 108 | if (c >= '0' && c <= '9') { 109 | n *= 10; 110 | n += c - '0'; 111 | } 112 | /* We insist on stopping at "." if we are still parsing 113 | the first, second, or third numbers. If we have reached 114 | the end of the numbers, we will allow any character. */ 115 | else if ((i < 3 && c == '.') || i == 3) { 116 | break; 117 | } 118 | else { 119 | return 0; 120 | } 121 | } 122 | if (n >= 256) { 123 | return 0; 124 | } 125 | ((uint8_t*)ip)[i] = n; 126 | } 127 | return 1; 128 | 129 | } 130 | uint32_t ICACHE_FLASH_ATTR UTILS_Atoh(const int8_t *s) 131 | { 132 | uint32_t value = 0, digit; 133 | int8_t c; 134 | 135 | while((c = *s++)){ 136 | if('0' <= c && c <= '9') 137 | digit = c - '0'; 138 | else if('A' <= c && c <= 'F') 139 | digit = c - 'A' + 10; 140 | else if('a' <= c && c<= 'f') 141 | digit = c - 'a' + 10; 142 | else break; 143 | 144 | value = (value << 4) | digit; 145 | } 146 | 147 | return value; 148 | } 149 | 150 | -------------------------------------------------------------------------------- /app/pando/gateway/mqtt/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_H_ 2 | #define _UTILS_H_ 3 | 4 | #include "c_types.h" 5 | 6 | uint32_t ICACHE_FLASH_ATTR UTILS_Atoh(const int8_t *s); 7 | uint8_t ICACHE_FLASH_ATTR UTILS_StrToIP(const int8_t* str, void *ip); 8 | uint8_t ICACHE_FLASH_ATTR UTILS_IsIPV4 (int8_t *str); 9 | #endif 10 | -------------------------------------------------------------------------------- /app/pando/gateway/pando_channel.c: -------------------------------------------------------------------------------- 1 | #include "pando_channel.h" 2 | #include "user_interface.h" 3 | 4 | #define MAX_CHAN_LEN 8 5 | 6 | struct pando_channel 7 | { 8 | PANDO_CHANNEL_NAME name; 9 | channel_recv_callback subdevice_cb; 10 | channel_recv_callback device_cb; 11 | }; 12 | 13 | static struct pando_channel channels[MAX_CHAN_LEN]; 14 | 15 | void ICACHE_FLASH_ATTR 16 | on_subdevice_channel_recv(PANDO_CHANNEL_NAME name, channel_recv_callback cb) 17 | { 18 | channels[name].subdevice_cb = cb; 19 | } 20 | 21 | void ICACHE_FLASH_ATTR 22 | on_device_channel_recv(PANDO_CHANNEL_NAME name, channel_recv_callback cb) 23 | { 24 | channels[name].device_cb = cb; 25 | } 26 | 27 | void ICACHE_FLASH_ATTR 28 | channel_send_to_subdevice(PANDO_CHANNEL_NAME name, uint8_t * buffer, uint16_t length) 29 | { 30 | if(channels[name].subdevice_cb != NULL ){ 31 | channels[name].subdevice_cb(buffer, length); 32 | } 33 | } 34 | 35 | void ICACHE_FLASH_ATTR 36 | channel_send_to_device(PANDO_CHANNEL_NAME name, uint8_t * buffer, uint16_t length) 37 | { 38 | PRINTF("send package to device\n"); 39 | if(channels[name].device_cb != NULL ){ 40 | channels[name].device_cb(buffer, length); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /app/pando/gateway/pando_channel.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_channel.h 3 | * Author: ruizeng 4 | * Versions: 1.0 5 | * Description:This module is to used to simulate connection channel (eg. serial port) between device and subdevice. 6 | * History: 7 | * 1.Date: initial code 8 | * Author: ruizeng 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __PANDO_CHANNEL_H__ 13 | #define __PANDO_CHANNEL_H__ 14 | 15 | #include "c_types.h" 16 | 17 | typedef enum { 18 | PANDO_CHANNEL_PORT_0 = 0, 19 | PANDO_CHANNEL_PORT_1, 20 | PANDO_CHANNEL_PORT_2, 21 | PANDO_CHANNEL_PORT_3, 22 | PANDO_CHANNEL_PORT_4, 23 | PANDO_CHANNEL_PORT_5, 24 | PANDO_CHANNEL_PORT_6, 25 | PANDO_CHANNEL_PORT_7 26 | } PANDO_CHANNEL_NAME; 27 | 28 | /* 29 | * "channel_recv_callback" is a callback function invoked when recving buffer from some channel. 30 | */ 31 | typedef void (* channel_recv_callback)(uint8_t * buffer, uint16_t length); 32 | 33 | /****************************************************************************** 34 | * FunctionName : on_subdevice_channel_recv 35 | * Description : regiseter the callback function when subdevice received buffer from some channel. 36 | * Parameters : name: channel name 37 | * cb: callback 38 | * Returns : 39 | *******************************************************************************/ 40 | void on_subdevice_channel_recv(PANDO_CHANNEL_NAME name, channel_recv_callback cb); 41 | 42 | /****************************************************************************** 43 | * FunctionName : on_device_channel_recv 44 | * Description : regiseter the callback function when device received buffer from some channel. 45 | * Parameters : name: channel name 46 | * cb: callback 47 | * Returns : 48 | *******************************************************************************/ 49 | void on_device_channel_recv(PANDO_CHANNEL_NAME name, channel_recv_callback cb); 50 | 51 | /****************************************************************************** 52 | * FunctionName : subdevice_channel_send 53 | * Description : send data to subdevice. 54 | * Parameters : name: channel name 55 | * Returns : 56 | *******************************************************************************/ 57 | void channel_send_to_subdevice(PANDO_CHANNEL_NAME name, uint8_t * buffer, uint16_t length); 58 | 59 | /****************************************************************************** 60 | * FunctionName : device_channel_send 61 | * Description : send data to device. 62 | * Parameters : name: channel name 63 | * Returns : 64 | *******************************************************************************/ 65 | void channel_send_to_device(PANDO_CHANNEL_NAME name, uint8_t * buffer, uint16_t length); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /app/pando/gateway/pando_cloud_access.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_cloud_access.h 3 | * Author: ruizeng 4 | * Versions: 1.0 5 | * Description:This module is to used to access to pando cloud. 6 | * History: 7 | * 1.Date: initial code 8 | * Author: ruizeng 9 | * Modification: 10 | *********************************************************/ 11 | #ifndef __PANDO_CLOUD_ACCESS_H 12 | #define __PANDO_CLOUD_ACCESS_H 13 | 14 | typedef enum { 15 | ACCESS_OK = 0, 16 | ERR_CONNECT, 17 | ERR_RECONNECT, 18 | ERR_DISCONNECT, 19 | ERR_OTHER 20 | } PANDO_ACCESS_ERROR; 21 | 22 | /* 23 | * "access_error_callback" is a callback function invoked when errors occured accessing pando server. 24 | * "result" returns the error code. 25 | */ 26 | typedef void (* access_error_callback)(PANDO_ACCESS_ERROR err); 27 | 28 | /****************************************************************************** 29 | * FunctionName : pando_cloud_access 30 | * Description : pando cloud device access api. 31 | * Parameters : access_error_callback callback:access callback function 32 | * Returns : 33 | *******************************************************************************/ 34 | void pando_cloud_access(access_error_callback callback); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /app/pando/gateway/pando_device_login.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_device_login.h 3 | * Author: ruizeng 4 | * Versions: 1.0 5 | * Description:This module is to used to login device via pando cloud api. 6 | * History: 7 | * 1.Date: initial code 8 | * Author: ruizeng 9 | * Modification: 10 | *********************************************************/ 11 | #ifndef __PANDO_DEVICE_LOGIN_H 12 | #define __PANDO_DEVICE_LOGIN_H 13 | 14 | typedef enum { 15 | LOGIN_OK = 0, 16 | ERR_NOT_REGISTERED, 17 | ERR_LOGIN_FAIL, 18 | } PANDO_LOGIN_RESULT; 19 | 20 | /* 21 | * "login_callback" is a callback function invoked when device login is finished. 22 | * "result" returns the register return code. 23 | */ 24 | typedef void (* login_callback)(PANDO_LOGIN_RESULT result); 25 | 26 | /****************************************************************************** 27 | * FunctionName : pando_device_login 28 | * Description : try login device using pando cloud device register api. 29 | * Parameters : login callback function 30 | * Returns : 31 | *******************************************************************************/ 32 | void pando_device_login(login_callback callback); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /app/pando/gateway/pando_device_register.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_device_register.h 3 | * Author: ruizeng 4 | * Versions: 1.0 5 | * Description:This module is to used to register device via pando cloud api. 6 | * History: 7 | * 1.Date: initial code 8 | * Author: ruizeng 9 | * Modification: 10 | *********************************************************/ 11 | #ifndef __PANDO_DEVICE_REGISTER_H 12 | #define __PANDO_DEVICE_REGISTER_H 13 | 14 | typedef enum { 15 | REGISTER_OK = 0, 16 | ERR_REGISTER_FAIL 17 | } PANDO_REGISTER_RESULT; 18 | 19 | /* 20 | * "register_callback" is a callback function invoked when device register is finished. 21 | * "result" returns the register return code. 22 | */ 23 | typedef void (* register_callback)(PANDO_REGISTER_RESULT result); 24 | 25 | /****************************************************************************** 26 | * FunctionName : pando_device_register 27 | * Description : register pando device using pando cloud device register api. 28 | * Parameters : register callback function 29 | * Returns : 30 | *******************************************************************************/ 31 | void pando_device_register(register_callback callback); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /app/pando/gateway/pando_gateway.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_gateway.h 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is the interface of the pando gateway. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __PANDO_GATEWAY_H__ 13 | #define __PANDO_GATEWAY_H__ 14 | 15 | //if need wifi config without key mode, open it 16 | //#define WIFI_CONFIG_WITHOUT_KEY 17 | 18 | /****************************************************************************** 19 | * FunctionName : pando_gateway_init 20 | * Description : initialize the gateway. 21 | * Parameters : none 22 | * Returns : none 23 | *******************************************************************************/ 24 | void pando_gateway_init(); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /app/pando/gateway/pando_lan_bind.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * File name: pando_lan_bind.h 3 | * Author:Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is to used to send device bind message to mobile phone through lan. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | **********************************************************************************/ 11 | #ifndef __PANDO_LAN_BIND_H__ 12 | #define __PANDO_LAN_BIND_H__ 13 | 14 | /****************************************************************************** 15 | * FunctionName : pando_lan_bind_init 16 | * Description : initialize the lan tcp server. 17 | * Parameters : nonde 18 | * Returns : none 19 | *******************************************************************************/ 20 | void pando_lan_bind_init(); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /app/pando/gateway/pando_storage_interface.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_storage_interface.h 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is the interface used to store the gateway data. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | #ifndef __PANDO_STORAGE_INTERFACE_H__ 12 | #define __PANDO_STORAGE_INTERFACE_H__ 13 | 14 | #include "c_types.h" 15 | 16 | typedef enum { 17 | CHANGE_SAVE_OK = 0, 18 | CREAT_SAVE_OK, 19 | FULL_ERROR, 20 | SAVE_ERROR, 21 | } SET_RESULT; 22 | 23 | /****************************************************************************** 24 | * FunctionName : pando_data_set 25 | * Description : set the vale of the parameter stored, if the parameter is existing. 26 | Else creat the parameter, and save it. 27 | * Parameters : key -- the parameter; 28 | value -- the value of the parameter. 29 | * Returns : the save result 30 | *******************************************************************************/ 31 | 32 | SET_RESULT pando_data_set(char* key, char* value); 33 | 34 | 35 | 36 | /****************************************************************************** 37 | * FunctionName : pando_data_get 38 | * Description : get the value of the key. 39 | * Parameters : key -- the parameter 40 | * Returns : the pointer of the value. NULL if not exist 41 | *******************************************************************************/ 42 | 43 | char * pando_data_get(char* key); 44 | 45 | /****************************************************************************** 46 | * FunctionName : pando_storage_space_left 47 | * Description : get the space left for pando data saved in the storage. 48 | * Parameters : 49 | * Returns : the space left for pando data saving. 50 | *******************************************************************************/ 51 | 52 | uint16 pando_storage_space_left(); 53 | 54 | /****************************************************************************** 55 | * FunctionName : pando_storage_clean. 56 | * Description : clean the pando configuration message. 57 | * Parameters : none 58 | * Returns : none 59 | *******************************************************************************/ 60 | void ICACHE_FLASH_ATTR 61 | pando_storage_clean(); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /app/pando/gateway/pando_system_time.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_system_time.h 3 | * Author: Chongguang Li 4 | * Versions: 1.0 5 | * Description:This module is the interface of system time. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "pando_system_time.h" 13 | #include "osapi.h" 14 | #include "os_type.h" 15 | #include "user_interface.h" 16 | 17 | static uint64 system_time = 0; 18 | 19 | static os_timer_t system_timer; 20 | 21 | /****************************************************************************** 22 | * FunctionName : pando_set_system_time 23 | * Description : configure the system time. 24 | * Parameters : the set value. 25 | * Returns : none 26 | *******************************************************************************/ 27 | 28 | void ICACHE_FLASH_ATTR 29 | pando_set_system_time(uint64 time) 30 | { 31 | system_time = time; 32 | 33 | int i = 0; 34 | for(i = 0; ibuffer = (uint8*)os_malloc(length); 40 | if(device_buffer->buffer == NULL) 41 | { 42 | PRINTF("%s:malloc error!\n", __func__); 43 | return; 44 | } 45 | os_memcpy(device_buffer->buffer, buffer, length); 46 | device_buffer->buffer_length = length; 47 | 48 | struct TLVs *cmd_param = get_sub_device_command(device_buffer, &cmd_body); 49 | if(COMMON_COMMAND_SYN_TIME == cmd_body.command_id ) 50 | { 51 | PRINTF("PANDO: synchronize time\n"); 52 | uint64 time = get_next_uint64(cmd_param); 53 | show_package((uint8*)(&time), sizeof(time)); 54 | pando_set_system_time(time); 55 | } 56 | 57 | } 58 | 59 | /****************************************************************************** 60 | * FunctionName : ipando_zero_device_init 61 | * Description : initialize the zero device(zero device is the gateway itself). 62 | * Parameters : none. 63 | * Returns : none. 64 | *******************************************************************************/ 65 | void ICACHE_FLASH_ATTR 66 | pando_zero_device_init(void) 67 | { 68 | on_subdevice_channel_recv(PANDO_CHANNEL_PORT_0, zero_device_data_process); 69 | } 70 | -------------------------------------------------------------------------------- /app/pando/gateway/pando_zero_device.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_zero_device.h 3 | * Author: Chongguang Li 4 | * Versions: 1.0 5 | * Description:This module is used to process the gateway business. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef APP_PANDO_GATEWAY_PANDO_ZERO_DEVICE_H_ 13 | #define APP_PANDO_GATEWAY_PANDO_ZERO_DEVICE_H_ 14 | 15 | /****************************************************************************** 16 | * FunctionName : ipando_zero_device_init 17 | * Description : initialize the zero device(zero device is the gateway itself). 18 | * Parameters : none. 19 | * Returns : none. 20 | *******************************************************************************/ 21 | 22 | void pando_zero_device_init(void); 23 | 24 | 25 | #endif /* APP_PANDO_GATEWAY_PANDO_ZERO_DEVICE_H_ */ 26 | -------------------------------------------------------------------------------- /app/pando/gateway/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/pando/gateway/readme.txt -------------------------------------------------------------------------------- /app/pando/pando_framework.c: -------------------------------------------------------------------------------- 1 | #include "gateway/pando_channel.h" 2 | #include "pando_subdevice.h" 3 | #include "pando_framework.h" 4 | 5 | void ICACHE_FLASH_ATTR 6 | pando_framework_init() 7 | { 8 | pando_gateway_init(); 9 | 10 | on_subdevice_channel_recv(PANDO_CHANNEL_PORT_1, pando_subdevice_recv); 11 | } 12 | -------------------------------------------------------------------------------- /app/pando/pando_framework.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_subdevice.h 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description: pando iot embeded framework. 6 | * History: 7 | * 1.Date: Sep 11, 2015 8 | * Author: razr 9 | * Modification: initial code 10 | *********************************************************/ 11 | #ifndef PANDO_FRAMEWORK_H_ 12 | #define PANDO_FRAMEWORK_H_ 13 | 14 | void pando_framework_init(); 15 | 16 | #endif /* PANDO_FRAMEWORK_H_ */ 17 | -------------------------------------------------------------------------------- /app/pando/pando_object.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_object.c 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description: 6 | * History: 7 | * 1.Date: Sep 11, 2015 8 | * Author: razr 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "pando_object.h" 13 | 14 | #define MAX_OBJECTS 16 15 | 16 | static pando_object s_pando_object_list[MAX_OBJECTS] = {}; 17 | static int s_pando_object_list_idx = 0; 18 | uint8_t FLASH_SEC_NUM = 0; 19 | 20 | void ICACHE_FLASH_ATTR 21 | register_pando_object(pando_object object) 22 | { 23 | if(s_pando_object_list_idx > MAX_OBJECTS - 1) 24 | { 25 | return; 26 | } 27 | FLASH_SEC_NUM = object.no; 28 | s_pando_object_list[s_pando_object_list_idx++] = object; 29 | } 30 | 31 | pando_object* ICACHE_FLASH_ATTR 32 | find_pando_object(int8 no) 33 | { 34 | int i; 35 | for(i = 0; i < s_pando_object_list_idx; i++) 36 | { 37 | if( s_pando_object_list[i].no == no) 38 | { 39 | return &s_pando_object_list[i]; 40 | } 41 | } 42 | return NULL; 43 | } 44 | 45 | pando_objects_iterator* ICACHE_FLASH_ATTR 46 | create_pando_objects_iterator() 47 | { 48 | pando_objects_iterator* it = (pando_objects_iterator*)os_malloc(sizeof(pando_objects_iterator)); 49 | it->cur = 0; 50 | return it; 51 | } 52 | 53 | void ICACHE_FLASH_ATTR 54 | delete_pando_objects_iterator(pando_objects_iterator* it) 55 | { 56 | if(it) 57 | { 58 | os_free(it); 59 | } 60 | } 61 | 62 | pando_object* ICACHE_FLASH_ATTR 63 | pando_objects_iterator_next(pando_objects_iterator *it) 64 | { 65 | if(it->cur == s_pando_object_list_idx) 66 | { 67 | return NULL; 68 | } 69 | return &s_pando_object_list[it->cur++]; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /app/pando/pando_object.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_object.h 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description: pando object interfaces 6 | * History: 7 | * 1.Date: Sep 11, 2015 8 | * Author: razr 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef PANDO_OBJECTS_H_ 13 | #define PANDO_OBJECTS_H_ 14 | 15 | #include "c_types.h" 16 | #include "protocol/sub_device_protocol.h" 17 | 18 | typedef struct TLVs PARAMS; 19 | 20 | typedef struct { 21 | uint8 no; 22 | void (*pack)(PARAMS*); 23 | void (*unpack)(PARAMS*); 24 | }pando_object; 25 | 26 | typedef struct { 27 | uint8 cur; 28 | }pando_objects_iterator; 29 | 30 | /****************************************************************************** 31 | * FunctionName : register_pando_object. 32 | * Description : register a pando object to framework. 33 | * Parameters : a pando object. 34 | * Returns : none. 35 | *******************************************************************************/ 36 | void register_pando_object(pando_object object); 37 | 38 | /****************************************************************************** 39 | * FunctionName : find_pando_object. 40 | * Description : find a pando object by object no. 41 | * Parameters : the object no. 42 | * Returns : the pando object of specified no, NULL if not found. 43 | *******************************************************************************/ 44 | pando_object* find_pando_object(int8 no); 45 | 46 | /****************************************************************************** 47 | * FunctionName : create_pando_objects_iterator, delete_pando_objects_iterator. 48 | * Description : iterator for pando object list. 49 | * Parameters : . 50 | * Returns : . 51 | *******************************************************************************/ 52 | pando_objects_iterator* create_pando_objects_iterator(); 53 | void delete_pando_objects_iterator(pando_objects_iterator*); 54 | pando_object* pando_objects_iterator_next(pando_objects_iterator*); 55 | 56 | #endif /* PANDO_OBJECTS_H_ */ 57 | -------------------------------------------------------------------------------- /app/pando/pando_subdevice.c: -------------------------------------------------------------------------------- 1 | #include "pando_subdevice.h" 2 | #include "c_types.h" 3 | #include "user_interface.h" 4 | #include "gateway/pando_channel.h" 5 | #include "protocol/common_functions.h" 6 | #include "protocol/sub_device_protocol.h" 7 | #include "pando_object.h" 8 | 9 | #define CMD_QUERY_STATUS (65528) 10 | 11 | 12 | static void ICACHE_FLASH_ATTR 13 | decode_data(struct sub_device_buffer *device_buffer) 14 | { 15 | struct pando_property data_body; 16 | uint8_t *buf_end = device_buffer->buffer + device_buffer->buffer_length; 17 | uint16_t tlv_type, tlv_length; 18 | uint8_t *value = NULL; 19 | 20 | PARAMS *object_param = NULL; 21 | while(object_param = get_sub_device_property(device_buffer, &data_body)){ 22 | pando_object* obj = find_pando_object(data_body.property_num); 23 | if( NULL == obj ) 24 | { 25 | PRINTF("object [%d] not found in list\n", data_body.property_num); 26 | } 27 | 28 | obj->unpack(object_param); 29 | } 30 | 31 | } 32 | 33 | static void ICACHE_FLASH_ATTR 34 | send_current_status() 35 | { 36 | struct sub_device_buffer* data_buffer; 37 | data_buffer = create_data_package(0); 38 | if(NULL == data_buffer) 39 | { 40 | PRINTF("create data package error\n"); 41 | return; 42 | } 43 | 44 | pando_object* obj = NULL; 45 | pando_objects_iterator* it = create_pando_objects_iterator(); 46 | while(obj = pando_objects_iterator_next(it)){ 47 | PARAMS* params = create_params_block(); 48 | if (params == NULL) 49 | { 50 | PRINTF("Create params block failed.\n"); 51 | return ; 52 | } 53 | obj->pack(params); 54 | int ret = add_next_property(data_buffer, obj->no, params); 55 | 56 | if (ret != 0) 57 | { 58 | PRINTF("add_next_property failed."); 59 | } 60 | 61 | 62 | delete_params_block(params); 63 | 64 | } 65 | delete_pando_objects_iterator(it); 66 | 67 | channel_send_to_device(PANDO_CHANNEL_PORT_1, data_buffer->buffer, data_buffer->buffer_length); 68 | show_package(data_buffer->buffer, data_buffer->buffer_length); 69 | delete_device_package(data_buffer); 70 | } 71 | 72 | static void ICACHE_FLASH_ATTR 73 | decode_command(struct sub_device_buffer *device_buffer) 74 | { 75 | struct pando_command cmd_body; 76 | PARAMS *cmd_param = get_sub_device_command(device_buffer, &cmd_body); 77 | if(CMD_QUERY_STATUS == cmd_body.command_id) 78 | { 79 | PRINTF("receive a get request\n"); 80 | send_current_status(); 81 | } 82 | } 83 | 84 | void ICACHE_FLASH_ATTR 85 | pando_subdevice_recv(uint8_t * buffer, uint16_t length) 86 | { 87 | if(NULL == buffer) 88 | { 89 | return; 90 | } 91 | 92 | PRINTF("subdevive receive a package: \n"); 93 | show_package(buffer, length); 94 | 95 | struct sub_device_buffer *device_buffer = (struct sub_device_buffer *)pd_malloc(sizeof(struct sub_device_buffer)); 96 | device_buffer->buffer_length = length; 97 | device_buffer->buffer = (uint8 *)pd_malloc(length); 98 | 99 | pd_memcpy(device_buffer->buffer, buffer, length); 100 | 101 | uint16 payload_type = get_sub_device_payloadtype(device_buffer); 102 | 103 | switch (payload_type) { 104 | case PAYLOAD_TYPE_DATA: 105 | decode_data(device_buffer); 106 | break; 107 | case PAYLOAD_TYPE_COMMAND: 108 | decode_command(device_buffer); 109 | break; 110 | default: 111 | PRINTF("unsuported paload type : %d", payload_type); 112 | break; 113 | } 114 | 115 | delete_device_package(device_buffer); 116 | } 117 | 118 | -------------------------------------------------------------------------------- /app/pando/pando_subdevice.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_subdevice.h 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description:This module is to used to handle subdevice logic. 6 | * History: 7 | * 1.Date: Sep 11, 2015 8 | * Author: razr 9 | * Modification: initial code 10 | *********************************************************/ 11 | #ifndef PANDO_SUBDEVICE_H_ 12 | #define PANDO_SUBDEVICE_H_ 13 | 14 | #include "c_types.h" 15 | 16 | /****************************************************************************** 17 | * FunctionName : pando_subdevice_recv. 18 | * Description : process buffer receive from channel. 19 | * Parameters : the buffer and length from channel. 20 | * Returns : none. 21 | *******************************************************************************/ 22 | void pando_subdevice_recv(uint8_t * buffer, uint16_t length); 23 | 24 | #endif /* PANDO_SUBDEVICE_H_ */ 25 | -------------------------------------------------------------------------------- /app/pando/protocol/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 object file images to be generated () 10 | # GEN_BINS - list of binaries to be generated () 11 | # COMPONENTS_xxx - a list of libs/objs in the form 12 | # subdir/lib to be extracted and rolled up into 13 | # a generated lib/image xxx.a () 14 | # 15 | ifndef PDIR 16 | GEN_LIBS = libprotocol.a 17 | endif 18 | 19 | 20 | ############################################################# 21 | # Configuration i.e. compile options etc. 22 | # Target specific stuff (defines etc.) goes in here! 23 | # Generally values applying to a tree are captured in the 24 | # makefile at its root level - these are then overridden 25 | # for a subtree within the makefile rooted therein 26 | # 27 | 28 | #UNIVERSAL_TARGET_DEFINES = \ 29 | 30 | # Other potential configuration flags include: 31 | # -DTXRX_TXBUF_DEBUG 32 | # -DTXRX_RXBUF_DEBUG 33 | # -DWLAN_CONFIG_CCX 34 | 35 | 36 | ############################################################# 37 | # Recursion Magic - Don't touch this!! 38 | # 39 | # Each subtree potentially has an include directory 40 | # corresponding to the common APIs applicable to modules 41 | # rooted at that subtree. Accordingly, the INCLUDE PATH 42 | # of a module can only contain the include directories up 43 | # its parent path, and not its siblings 44 | # 45 | # Required for each makefile to inherit from the parent 46 | # 47 | 48 | INCLUDES := $(INCLUDES) -I $(PDIR)include 49 | PDIR := ../$(PDIR) 50 | sinclude $(PDIR)Makefile 51 | 52 | .PHONY: FORCE 53 | FORCE: 54 | 55 | -------------------------------------------------------------------------------- /app/pando/protocol/common_functions.c: -------------------------------------------------------------------------------- 1 | #include "common_functions.h" 2 | 3 | void FUNCTION_ATTRIBUTE show_package(uint8_t *buffer, uint16_t length) 4 | { 5 | int i = 0; 6 | pd_printf("Package length: %d\ncontent is: \n", length); 7 | 8 | for (i = 0; i < length; i++) 9 | { 10 | pd_printf("%02x ",(uint8_t)buffer[i]); 11 | } 12 | 13 | pd_printf("\n"); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /app/pando/protocol/common_functions.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Pando. All rights reserved. 2 | // Platform: common_functions.h 3 | // 4 | // Create By ZhaoWenwu On 15/05/17. 5 | 6 | 7 | #ifndef PLATFORM_FUNCTIONS_H 8 | #define PLATFORM_FUNCTIONS_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" 12 | { 13 | #endif 14 | 15 | #ifdef ESP8266_PLANTFORM 16 | 17 | #else 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #endif 25 | 26 | #include "pando_machine.h" 27 | 28 | void show_package(uint8_t *buffer, uint16_t length); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | #endif -------------------------------------------------------------------------------- /app/pando/protocol/pando_endian.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Pando. All rights reserved. 2 | // PtotoBuf: ProtocolBuffer.h 3 | // 4 | // Create By ZhaoWenwu On 15/01/24. 5 | 6 | #include "pando_endian.h" 7 | 8 | int little_endian = -1; 9 | 10 | int FUNCTION_ATTRIBUTE is_little_endian() 11 | { 12 | if(little_endian == -1) 13 | { 14 | union int_char 15 | { 16 | int i; 17 | char c; 18 | }x; 19 | x.i = 1; 20 | little_endian = x.c; 21 | } 22 | 23 | return little_endian; 24 | } 25 | 26 | uint16_t FUNCTION_ATTRIBUTE net16_to_host(uint16_t A) 27 | { 28 | if(is_little_endian()) 29 | { 30 | return ((((A) & 0xff00) >> 8) | (((A) & 0x00ff) << 8)); 31 | } 32 | else 33 | { 34 | return A; 35 | } 36 | } 37 | 38 | uint32_t FUNCTION_ATTRIBUTE net32_to_host(uint32_t A) 39 | { 40 | if(is_little_endian()) 41 | { 42 | return ((((A) & 0xff000000) >> 24) | \ 43 | (((A) & 0x00ff0000) >> 8 ) | \ 44 | (((A) & 0x0000ff00) << 8 ) | \ 45 | (((A) & 0x000000ff) << 24)); 46 | } 47 | else 48 | { 49 | return A; 50 | } 51 | } 52 | 53 | uint64_t FUNCTION_ATTRIBUTE net64_to_host(uint64_t A) 54 | { 55 | uint64_t mask = 0xff; 56 | if(is_little_endian()) 57 | { 58 | return ((((A) & (mask << 56)) >> 56) | \ 59 | (((A) & (mask << 48)) >> 40) | \ 60 | (((A) & (mask << 40)) >> 24) | \ 61 | (((A) & (mask << 32)) >> 8) | \ 62 | (((A) & (mask << 24)) << 8) | \ 63 | (((A) & (mask << 16)) << 24) | \ 64 | (((A) & (mask << 8)) << 40) | \ 65 | (((A) & (mask)) << 56)); 66 | } 67 | else 68 | { 69 | return A; 70 | } 71 | } 72 | 73 | 74 | float FUNCTION_ATTRIBUTE net32f_to_host(float A) 75 | { 76 | if(is_little_endian()) 77 | { 78 | union float_int 79 | { 80 | float f; 81 | uint32_t i; 82 | }x; 83 | x.f = A; 84 | x.i = net32_to_host(x.i); 85 | return x.f; 86 | } 87 | else 88 | { 89 | return A; 90 | } 91 | } 92 | 93 | double FUNCTION_ATTRIBUTE net64f_to_host(double A) 94 | { 95 | if(is_little_endian()) 96 | { 97 | union double_uint64 98 | { 99 | double d; 100 | uint64_t i; 101 | }x; 102 | x.d = A; 103 | x.i = net64_to_host(x.i); 104 | return x.d; 105 | } 106 | else 107 | { 108 | return A; 109 | } 110 | } 111 | 112 | 113 | -------------------------------------------------------------------------------- /app/pando/protocol/pando_endian.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Pando. All rights reserved. 2 | // PtotoBuf: ProtocolBuffer.h 3 | // 4 | // Create By ZhaoWenwu On 15/01/24. 5 | 6 | #ifndef PANDO_ENDIAN_H 7 | #define PANDO_ENDIAN_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | #include "common_functions.h" 15 | 16 | //大小端转换函数 17 | uint16_t net16_to_host(uint16_t A); 18 | uint32_t net32_to_host(uint32_t A); 19 | uint64_t net64_to_host(uint64_t A); 20 | float net32f_to_host(float A); 21 | double net64f_to_host(double A); 22 | 23 | #define host16_to_net net16_to_host 24 | #define host32_to_net net32_to_host 25 | #define host64_to_net net64_to_host 26 | #define host32f_to_net net32f_to_host 27 | #define host64f_to_net net64f_to_host 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | #endif 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/pando/protocol/pando_machine.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | #include "pando_machine.h" 6 | 7 | #ifdef ESP8266_PLANTFORM 8 | 9 | uint64_t FUNCTION_ATTRIBUTE pd_get_timestamp() 10 | { 11 | uint64_t time_now; 12 | time_now = pando_get_system_time(); 13 | return time_now; 14 | } 15 | 16 | #else 17 | uint64_t FUNCTION_ATTRIBUTE pd_get_timestamp() 18 | { 19 | struct timeval now; 20 | gettimeofday(&now, NULL); 21 | return (now.tv_sec * 1000 + now.tv_usec/1000); 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /app/pando/protocol/pando_machine.h: -------------------------------------------------------------------------------- 1 | #ifndef PD_MACHINE_H 2 | #define PD_MACHINE_H 3 | 4 | #ifdef ESP8266_PLANTFORM 5 | 6 | #include "c_types.h" 7 | #include "mem.h" 8 | #include "osapi.h" 9 | #include "../gateway/pando_system_time.h" 10 | 11 | // for #pragma pack(ALIGNED_LENGTH), for example, esp8266 should be 1 12 | #define ALIGNED_LENGTH 1 13 | 14 | // some platform need this prefix between function name and return type 15 | #define FUNCTION_ATTRIBUTE ICACHE_FLASH_ATTR 16 | 17 | 18 | // different platform has its own define of these functions. 19 | 20 | #define pd_malloc os_malloc 21 | #define pd_free os_free 22 | #define pd_memcpy os_memcpy 23 | #define pd_printf os_printf 24 | #define pd_memcmp os_memcmp 25 | #define pd_memset os_memset 26 | 27 | #else 28 | #include 29 | 30 | #define ALIGNED_LENGTH 1 31 | 32 | // some platform need this prefix between function name and return type 33 | #define FUNCTION_ATTRIBUTE 34 | 35 | // different platform has its own define of these functions. 36 | #define pd_malloc malloc 37 | #define pd_free free 38 | #define pd_memcpy memcpy 39 | #define pd_printf printf 40 | #define pd_memcmp memcmp 41 | #define pd_memset memset 42 | 43 | #endif 44 | 45 | uint64_t pd_get_timestamp(); 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /app/pando/protocol/pando_protocol.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Pando. All rights reserved. 2 | // PtotoBuf: ProtocolBuffer.h 3 | // 4 | // Brief: 5 | // 6 | // Create By TangWenhan On 14/12/24. 7 | 8 | #ifndef PANDP_PROTOCOL_TOOL_H 9 | #define PANDP_PROTOCOL_TOOL_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" 13 | { 14 | #endif 15 | 16 | #include "common_functions.h" 17 | #include "sub_device_protocol.h" 18 | #include "pando_endian.h" 19 | 20 | #define MAX_PANDO_TOKEN_SIZE 16 21 | 22 | #define MAGIC_HEAD_PANDO 0x7064 23 | #define BIN_PANDO_TAG 0x0001 24 | #define EMPTY_HEART_BEAT 0xffff 25 | #define FLAG_TCP_XXX //是否现在就要定义具体的flag 26 | 27 | #define GATE_HEADER_LEN (sizeof(struct mqtt_bin_header)) 28 | 29 | #pragma pack(1) 30 | 31 | struct mqtt_bin_header 32 | { 33 | uint8_t flags; 34 | uint64_t timestamp; 35 | uint8_t token[MAX_PANDO_TOKEN_SIZE]; 36 | }; 37 | 38 | 39 | /*载荷数据的开头,必须有子设备ID,以供Gateway转发和聚合*/ 40 | struct pando_payload 41 | { 42 | uint16_t sub_device_id; 43 | }; 44 | 45 | 46 | /* 缓存结构,用于在网关程序内部流转 47 | * buffer总是从pando_header开始的。 48 | * buffer + offset到buffer + buff_len之间的数据,就是decode或者encode要处理的 49 | */ 50 | struct pando_buffer 51 | { 52 | uint16_t buff_len; /* 缓冲区长度 */ 53 | uint16_t offset; /* 有效数据的偏移量 */ 54 | uint8_t *buffer; /* 缓冲区 */ 55 | }; 56 | 57 | /*protocol模块基本数据的结构*/ 58 | struct protocol_base 59 | { 60 | uint64_t device_id; /* 设备ID */ 61 | uint64_t event_sequence; /* 网关的事件序列 */ 62 | uint64_t data_sequence; /* 网关的数据序列 */ 63 | uint64_t command_sequence; /* 网关收到的命令序列 */ 64 | uint32_t sub_device_cmd_seq; /* 保存与子设备交互命令时的序列 */ 65 | uint8_t token[MAX_PANDO_TOKEN_SIZE]; /* token */ 66 | }; 67 | #pragma pack() 68 | 69 | 70 | /*面向网关的接口*/ 71 | 72 | /* 初始化协议基本参数 73 | * 成功返回0,错误返回 -1 */ 74 | int pando_protocol_init(struct protocol_base init_params); 75 | 76 | uint8_t *pando_get_package_begin(struct pando_buffer *buf); 77 | uint16_t pando_get_package_length(struct pando_buffer *buf); 78 | 79 | 80 | /* 动态新建一个空的缓冲区。length为缓冲区长度,offset进行简单地赋值。 81 | * 成功则返回缓冲区,错误则返回NULL。*/ 82 | struct pando_buffer* pando_buffer_create(int length, int offset); 83 | 84 | /* 释放缓冲区动态创建的buffer,释放缓冲区本身 */ 85 | void pando_buffer_delete(struct pando_buffer *pdbuf); 86 | 87 | /* 将网关与子设备交互的包,转换成网关与接入服务器交互的包 88 | * 成功返回0,错误返回 -1 */ 89 | int pando_protocol_encode(struct pando_buffer *pdbuf, uint16_t *payload_type); 90 | 91 | /* 将网关与接入服务器交互的包,转换成网关与子设备交互的包 92 | * 通过command传出command id, command目标子设备id, command priority 93 | * 成功返回0,错误返回 -1 */ 94 | int pando_protocol_decode(struct pando_buffer *pdbuf, uint16_t payload_type); 95 | 96 | /* 网关获取command的序列号,用于反馈机制 97 | * 得到的是最近一次decode的command的序列 98 | */ 99 | uint64_t pando_protocol_get_cmd_sequence(); 100 | 101 | /* 获取或设置子设备ID,必须传入payload的起始位置 102 | */ 103 | int pando_protocol_get_sub_device_id(struct pando_buffer *buf, uint16_t *sub_device_id); 104 | 105 | int pando_protocol_set_sub_device_id(struct pando_buffer *buf, uint16_t sub_device_id); 106 | 107 | 108 | /* get command type after gateway completes decoding the command from server. */ 109 | uint16_t pando_protocol_get_payload_type(struct pando_buffer *pdbuf); 110 | 111 | #ifdef __cplusplus 112 | } 113 | #endif 114 | #endif //PANDP_PROTOCOL_TOOL_H 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /app/pando/protocol/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/pando/protocol/readme.txt -------------------------------------------------------------------------------- /app/pando/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/pando/readme.txt -------------------------------------------------------------------------------- /app/peripheral/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # Required variables for each makefile 3 | # Discard this section from all parent makefiles 4 | # Expected variables (with automatic defaults): 5 | # CSRCS (all "C" files in the dir) 6 | # SUBDIRS (all subdirs with a Makefile) 7 | # GEN_LIBS - list of libs to be generated () 8 | # GEN_IMAGES - list of object file images to be generated () 9 | # GEN_BINS - list of binaries 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 | 15 | ############################################################# 16 | # Configuration i.e. compile options etc. 17 | # Target specific stuff (defines etc.) goes in here! 18 | # Generally values applying to a tree are captured in the 19 | # makefile at its root level - these are then overridden 20 | # for a subtree within the makefile rooted therein 21 | # 22 | 23 | #UNIVERSAL_TARGET_DEFINES = \ 24 | 25 | ifndef PDIR 26 | GEN_LIBS = libperipheral.a 27 | SUBDIRS= \ 28 | driver 29 | endif 30 | 31 | # Other potential configuration flags include: 32 | # -DTXRX_TXBUF_DEBUG 33 | # -DTXRX_RXBUF_DEBUG 34 | # -DWLAN_CONFIG_CCX 35 | 36 | ############################################################# 37 | # Recursion Magic - Don't touch this!! 38 | # 39 | # Each subtree potentially has an include directory 40 | # corresponding to the common APIs applicable to modules 41 | # rooted at that subtree. Accordingly, the INCLUDE PATH 42 | # of a module can only contain the include directories up 43 | # its parent path, and not its siblings 44 | # 45 | # Required for each makefile to inherit from the parent 46 | # 47 | 48 | INCLUDES := $(INCLUDES) -I $(PDIR)include 49 | PDIR := ../$(PDIR) 50 | sinclude $(PDIR)Makefile 51 | 52 | .PHONY: FORCE 53 | FORCE: 54 | 55 | -------------------------------------------------------------------------------- /app/peripheral/driver/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # Required variables for each makefile 3 | # Discard this section from all parent makefiles 4 | # Expected variables (with automatic defaults): 5 | # CSRCS (all "C" files in the dir) 6 | # SUBDIRS (all subdirs with a Makefile) 7 | # GEN_LIBS - list of libs to be generated () 8 | # GEN_IMAGES - list of object file images to be generated () 9 | # GEN_BINS - list of binaries 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 | # Configuration i.e. compile options etc. 19 | # Target specific stuff (defines etc.) goes in here! 20 | # Generally values applying to a tree are captured in the 21 | # makefile at its root level - these are then overridden 22 | # for a subtree within the makefile rooted therein 23 | # 24 | 25 | #UNIVERSAL_TARGET_DEFINES = \ 26 | 27 | # Other potential configuration flags include: 28 | # -DTXRX_TXBUF_DEBUG 29 | # -DTXRX_RXBUF_DEBUG 30 | # -DWLAN_CONFIG_CCX 31 | ############################################################# 32 | # Recursion Magic - Don't touch this!! 33 | # 34 | # Each subtree potentially has an include directory 35 | # corresponding to the common APIs applicable to modules 36 | # rooted at that subtree. Accordingly, the INCLUDE PATH 37 | # of a module can only contain the include directories up 38 | # its parent path, and not its siblings 39 | # 40 | # Required for each makefile to inherit from the parent 41 | # 42 | 43 | INCLUDES := $(INCLUDES) -I $(PDIR)include 44 | PDIR := ../$(PDIR) 45 | sinclude $(PDIR)Makefile 46 | 47 | .PHONY: FORCE 48 | FORCE: 49 | 50 | -------------------------------------------------------------------------------- /app/peripheral/driver/adc.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "osapi.h" 3 | 4 | #include "adc.h" 5 | 6 | #define i2c_bbpll 0x67 7 | #define i2c_bbpll_en_audio_clock_out 4 8 | #define i2c_bbpll_en_audio_clock_out_msb 7 9 | #define i2c_bbpll_en_audio_clock_out_lsb 7 10 | #define i2c_bbpll_hostid 4 11 | #define i2c_saradc 0x6C 12 | #define i2c_saradc_hostid 2 13 | 14 | #define i2c_saradc_en_test 0 15 | #define i2c_saradc_en_test_msb 5 16 | #define i2c_saradc_en_test_lsb 5 17 | 18 | #define i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata) \ 19 | rom_i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata) 20 | 21 | #define i2c_readReg_Mask(block, host_id, reg_add, Msb, Lsb) \ 22 | rom_i2c_readReg_Mask_(block, host_id, reg_add, Msb, Lsb) 23 | 24 | #define i2c_writeReg_Mask_def(block, reg_add, indata) \ 25 | i2c_writeReg_Mask(block, block##_hostid, reg_add, reg_add##_msb, reg_add##_lsb, indata) 26 | 27 | #define i2c_readReg_Mask_def(block, reg_add) \ 28 | i2c_readReg_Mask(block, block##_hostid, reg_add, reg_add##_msb, reg_add##_lsb) 29 | 30 | #ifdef ADC_DEBUG 31 | #define ADC_DBG os_printf 32 | #else 33 | #define ADC_DBG 34 | #endif 35 | 36 | uint16 ICACHE_FLASH_ATTR adc_read(void) 37 | { 38 | uint8 i; 39 | uint16 sar_dout, tout, sardata[8]; 40 | 41 | i2c_writeReg_Mask_def(i2c_saradc, i2c_saradc_en_test, 1); //select test mux 42 | 43 | //PWDET_CAL_EN=0, PKDET_CAL_EN=0 44 | SET_PERI_REG_MASK(0x60000D5C, 0x200000); 45 | 46 | while (GET_PERI_REG_BITS(0x60000D50, 26, 24) > 0); //wait r_state == 0 47 | 48 | sar_dout = 0; 49 | CLEAR_PERI_REG_MASK(0x60000D50, 0x02); //force_en=0 50 | SET_PERI_REG_MASK(0x60000D50, 0x02); //force_en=1 51 | 52 | os_delay_us(2); 53 | 54 | while (GET_PERI_REG_BITS(0x60000D50, 26, 24) > 0); //wait r_state == 0 55 | 56 | read_sar_dout(sardata); 57 | 58 | for (i = 0; i < 8; i++) { 59 | sar_dout += sardata[i]; 60 | ADC_DBG("%d, ", sardata[i]); 61 | } 62 | 63 | tout = (sar_dout + 8) >> 4; //tout is 10 bits fraction 64 | 65 | i2c_writeReg_Mask_def(i2c_saradc, i2c_saradc_en_test, 1); //select test mux 66 | 67 | while (GET_PERI_REG_BITS(0x60000D50, 26, 24) > 0); //wait r_state == 0 68 | 69 | CLEAR_PERI_REG_MASK(0x60000D5C, 0x200000); 70 | SET_PERI_REG_MASK(0x60000D60, 0x1); //force_en=1 71 | CLEAR_PERI_REG_MASK(0x60000D60, 0x1); //force_en=1 72 | 73 | return tout; //tout is 10 bits fraction 74 | } 75 | 76 | -------------------------------------------------------------------------------- /app/peripheral/driver/adc.h: -------------------------------------------------------------------------------- 1 | #ifndef __ADC_H__ 2 | #define __ADC_H__ 3 | 4 | uint16 adc_read(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /app/peripheral/driver/gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) Espressif System 2010 3 | * 4 | */ 5 | 6 | #ifndef _GPIO_H_ 7 | #define _GPIO_H_ 8 | 9 | #include "c_types.h" 10 | 11 | #define GPIO_PIN_ADDR(i) (GPIO_PIN0_ADDRESS + i*4) 12 | 13 | #define GPIO_ID_IS_PIN_REGISTER(reg_id) \ 14 | ((reg_id >= GPIO_ID_PIN0) && (reg_id <= GPIO_ID_PIN(GPIO_PIN_COUNT-1))) 15 | 16 | #define GPIO_REGID_TO_PINIDX(reg_id) ((reg_id) - GPIO_ID_PIN0) 17 | 18 | typedef enum { 19 | GPIO_PIN_INTR_DISABLE = 0, 20 | GPIO_PIN_INTR_POSEDGE = 1, 21 | GPIO_PIN_INTR_NEGEDGE = 2, 22 | GPIO_PIN_INTR_ANYEDGE = 3, 23 | GPIO_PIN_INTR_LOLEVEL = 4, 24 | GPIO_PIN_INTR_HILEVEL = 5 25 | } GPIO_INT_TYPE; 26 | 27 | #define GPIO_OUTPUT_SET(gpio_no, bit_value) \ 28 | gpio_output_set((bit_value)<>gpio_no)&BIT0) 31 | 32 | /* GPIO interrupt handler, registered through gpio_intr_handler_register */ 33 | typedef void (* gpio_intr_handler_fn_t)(uint32 intr_mask, void *arg); 34 | 35 | 36 | /* 37 | * Initialize GPIO. This includes reading the GPIO Configuration DataSet 38 | * to initialize "output enables" and pin configurations for each gpio pin. 39 | * Must be called once during startup. 40 | */ 41 | void gpio_init(void); 42 | 43 | /* 44 | * Change GPIO pin output by setting, clearing, or disabling pins. 45 | * In general, it is expected that a bit will be set in at most one 46 | * of these masks. If a bit is clear in all masks, the output state 47 | * remains unchanged. 48 | * 49 | * There is no particular ordering guaranteed; so if the order of 50 | * writes is significant, calling code should divide a single call 51 | * into multiple calls. 52 | */ 53 | void gpio_output_set(uint32 set_mask, 54 | uint32 clear_mask, 55 | uint32 enable_mask, 56 | uint32 disable_mask); 57 | 58 | /* 59 | * Sample the value of GPIO input pins and returns a bitmask. 60 | */ 61 | uint32 gpio_input_get(void); 62 | 63 | /* 64 | * Set the specified GPIO register to the specified value. 65 | * This is a very general and powerful interface that is not 66 | * expected to be used during normal operation. It is intended 67 | * mainly for debug, or for unusual requirements. 68 | */ 69 | void gpio_register_set(uint32 reg_id, uint32 value); 70 | 71 | /* Get the current value of the specified GPIO register. */ 72 | uint32 gpio_register_get(uint32 reg_id); 73 | 74 | /* 75 | * Register an application-specific interrupt handler for GPIO pin 76 | * interrupts. Once the interrupt handler is called, it will not 77 | * be called again until after a call to gpio_intr_ack. Any GPIO 78 | * interrupts that occur during the interim are masked. 79 | * 80 | * The application-specific handler is called with a mask of 81 | * pending GPIO interrupts. After processing pin interrupts, the 82 | * application-specific handler may wish to use gpio_intr_pending 83 | * to check for any additional pending interrupts before it returns. 84 | */ 85 | void gpio_intr_handler_register(gpio_intr_handler_fn_t fn, void *arg); 86 | 87 | /* Determine which GPIO interrupts are pending. */ 88 | uint32 gpio_intr_pending(void); 89 | 90 | /* 91 | * Acknowledge GPIO interrupts. 92 | * Intended to be called from the gpio_intr_handler_fn. 93 | */ 94 | void gpio_intr_ack(uint32 ack_mask); 95 | 96 | void gpio_pin_wakeup_enable(uint32 i, GPIO_INT_TYPE intr_state); 97 | 98 | void gpio_pin_wakeup_disable(); 99 | 100 | void gpio_pin_intr_state_set(uint32 i, GPIO_INT_TYPE intr_state); 101 | 102 | #endif // _GPIO_H_ 103 | -------------------------------------------------------------------------------- /app/peripheral/driver/gpio16.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "osapi.h" 3 | #include "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/peripheral/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/peripheral/driver/i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_H__ 2 | #define __I2C_H__ 3 | #endif 4 | 5 | /* 6 | I2C driver for the ESP8266 7 | Copyright (C) 2014 Rudy Hardeman (zarya) 8 | 9 | This program is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License as published by 11 | the Free Software Foundation; either version 2 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU General Public License for more details. 18 | 19 | You should have received a copy of the GNU General Public License along 20 | with this program; if not, write to the Free Software Foundation, Inc., 21 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 | */ 23 | 24 | #include "ets_sys.h" 25 | #include "osapi.h" 26 | #include "gpio.h" 27 | 28 | #define I2C_SLEEP_TIME 10 29 | 30 | //SDA on GPIO2 31 | #define I2C_SDA_MUX PERIPHS_IO_MUX_GPIO2_U 32 | #define I2C_SDA_FUNC FUNC_GPIO2 33 | #define I2C_SDA_PIN 2 34 | 35 | //SCK on GPIO14 36 | //#define I2C_SCK_MUX PERIPHS_IO_MUX_MTMS_U 37 | //#define I2C_SCK_FUNC FUNC_GPIO14 38 | //#define I2C_SCK_PIN 14 39 | 40 | //SCK on GPIO0 41 | #define I2C_SCK_MUX PERIPHS_IO_MUX_GPIO0_U 42 | #define I2C_SCK_PIN 0 43 | #define I2C_SCK_FUNC FUNC_GPIO0 44 | 45 | #define i2c_read() GPIO_INPUT_GET(GPIO_ID_PIN(I2C_SDA_PIN)); 46 | 47 | void i2c_init(void); 48 | void i2c_start(void); 49 | void i2c_stop(void); 50 | void i2c_send_ack(uint8 state); 51 | uint8 i2c_check_ack(void); 52 | uint8 i2c_readByte(void); 53 | void i2c_writeByte(uint8 data); 54 | -------------------------------------------------------------------------------- /app/peripheral/driver/key.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * 4 | * FileName: key.c 5 | * 6 | * Description: key driver, now can use different gpio and install different function 7 | * 8 | * Modification history: 9 | * 2014/5/1, v1.0 create this file. 10 | *******************************************************************************/ 11 | #include "ets_sys.h" 12 | #include "os_type.h" 13 | #include "osapi.h" 14 | #include "mem.h" 15 | #include "gpio.h" 16 | #include "user_interface.h" 17 | #include "key.h" 18 | 19 | 20 | /****************************************************************************** 21 | * FunctionName : key_init 22 | * Description : init keys 23 | * Parameters : key_param *keys - keys parameter, which inited by key_init_single 24 | * Returns : none 25 | *******************************************************************************/ 26 | void ICACHE_FLASH_ATTR 27 | key_init(uint32 gpio_name,uint8 gpio_id,uint8 gpio_func) 28 | { 29 | PIN_FUNC_SELECT(gpio_name,gpio_func); 30 | PIN_PULLUP_EN(gpio_name); 31 | gpio_output_set(0, 0, 0, GPIO_ID_PIN(gpio_id)); 32 | 33 | gpio_register_set(GPIO_PIN_ADDR(gpio_id), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE) 34 | | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE) 35 | | GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE)); 36 | 37 | //clear interrupt status 38 | GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(gpio_id)); 39 | 40 | //enable interrupt 41 | gpio_pin_intr_state_set(GPIO_ID_PIN(gpio_id), GPIO_PIN_INTR_NEGEDGE); 42 | } 43 | /****************************************************************************** 44 | * FunctionName : key_5s_cb 45 | * Description : long press 5s timer callback 46 | * Parameters : single_key_param *single_key - single key parameter 47 | * Returns : none 48 | *******************************************************************************/ 49 | void ICACHE_FLASH_ATTR 50 | key_5s_cb(struct key_param *single_key) 51 | { 52 | os_timer_disarm(&single_key->key_5s); 53 | 54 | if (0 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) { 55 | if (single_key->long_press) { 56 | single_key->long_press(); 57 | } 58 | } 59 | } 60 | 61 | /****************************************************************************** 62 | * FunctionName : key_50ms_cb 63 | * Description : 50ms timer callback to check it's a real key push 64 | * Parameters : single_key_param *single_key - single key parameter 65 | * Returns : none 66 | *******************************************************************************/ 67 | void ICACHE_FLASH_ATTR 68 | key_50ms_cb(struct key_param *single_key) 69 | { 70 | os_timer_disarm(&single_key->key_50ms); 71 | 72 | // high, then key is up 73 | if (1 == GPIO_INPUT_GET(GPIO_ID_PIN(single_key->gpio_id))) { 74 | os_timer_disarm(&single_key->key_5s); 75 | single_key->key_level = 1; 76 | gpio_pin_intr_state_set(GPIO_ID_PIN(single_key->gpio_id), GPIO_PIN_INTR_NEGEDGE); 77 | 78 | if (single_key->short_press) { 79 | single_key->short_press(); 80 | } 81 | } else { 82 | gpio_pin_intr_state_set(GPIO_ID_PIN(single_key->gpio_id), GPIO_PIN_INTR_POSEDGE); 83 | } 84 | } 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /app/peripheral/driver/key.h: -------------------------------------------------------------------------------- 1 | #ifndef __KEY_H__ 2 | #define __KEY_H__ 3 | 4 | #include "gpio.h" 5 | #include "../peri_key.h" 6 | 7 | #define LONG_PRESS_COUNT 3000 8 | 9 | void key_init(uint32 gpio_name,uint8 gpio_id,uint8 gpio_func); 10 | void key_intr_handler(struct key_param *key); 11 | void peri_vibrate_tim_start(uint16 delay_ms); 12 | void key_5s_cb(struct key_param *single_key); 13 | void key_50ms_cb(struct key_param *single_key); 14 | 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /app/peripheral/driver/pwm.h: -------------------------------------------------------------------------------- 1 | #ifndef __PWM_H__ 2 | #define __PWM_H__ 3 | 4 | #include "../peri_rgb_light.h" 5 | 6 | #define PWM_CHANNEL_MAX 5 7 | 8 | struct PWM_APP_PARAM 9 | { 10 | uint16 pwm_freq; //100hz typically 11 | uint8 pwm_duty[PWM_CHANNEL_MAX]; // the sequence is red, green, blue. 12 | uint8 pad[1]; // the save data must aligned. 13 | }; 14 | struct PWM_INIT 15 | { 16 | uint8 io_num; //pwm io number 17 | uint8 io_id[PWM_CHANNEL_MAX]; //list pwm io id 18 | }; 19 | 20 | struct pwm_single_param { 21 | uint16 gpio_set; 22 | uint16 gpio_clear; 23 | uint32 h_time; 24 | }; 25 | 26 | struct pwm_param { 27 | uint32 period; 28 | uint16 freq; 29 | uint8 duty[PWM_CHANNEL_MAX]; 30 | }; 31 | 32 | #define PWM_DEPTH 255 33 | 34 | #define PWM_1S 1000000 35 | 36 | #define PWM_0_OUT_IO_MUX PERIPHS_IO_MUX_MTDO_U 37 | #define PWM_0_OUT_IO_NUM 15 38 | #define PWM_0_OUT_IO_FUNC FUNC_GPIO15 39 | 40 | #define PWM_1_OUT_IO_MUX PERIPHS_IO_MUX_MTMS_U 41 | #define PWM_1_OUT_IO_NUM 14 42 | #define PWM_1_OUT_IO_FUNC FUNC_GPIO14 43 | 44 | #define PWM_2_OUT_IO_MUX PERIPHS_IO_MUX_MTCK_U 45 | #define PWM_2_OUT_IO_NUM 13 46 | #define PWM_2_OUT_IO_FUNC FUNC_GPIO13 47 | 48 | #define PERI_0_OUT_IO_MUX PERIPHS_IO_MUX_MTDI_U 49 | #define PERI_0_OUT_IO_NUM 12 50 | #define PERI_0_OUT_IO_FUNC FUNC_GPIO12 51 | 52 | 53 | //void pwm_init(struct LIGHT_PARAM light_param,struct LIGHT_INIT light_init); 54 | 55 | void pwm_start(void); 56 | 57 | void pwm_set_duty(uint8 duty, uint8 channel); 58 | uint8 pwm_get_duty(uint8 channel); 59 | void pwm_set_freq(uint16 freq); 60 | uint16 pwm_get_freq(void); 61 | #endif 62 | 63 | 64 | -------------------------------------------------------------------------------- /app/peripheral/driver/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/peripheral/driver/readme.txt -------------------------------------------------------------------------------- /app/peripheral/driver/spi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 David Ogilvy (MetalPhreak) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #ifndef SPI_APP_H 26 | #define SPI_APP_H 27 | 28 | #include "spi_register.h" 29 | #include "ets_sys.h" 30 | #include "osapi.h" 31 | //#include "uart.h" 32 | #include "os_type.h" 33 | 34 | //Define SPI hardware modules 35 | #define SPI 0 36 | #define HSPI 1 37 | 38 | #define SPI_CLK_USE_DIV 0 39 | #define SPI_CLK_80MHZ_NODIV 1 40 | 41 | #define SPI_BYTE_ORDER_HIGH_TO_LOW 1 42 | #define SPI_BYTE_ORDER_LOW_TO_HIGH 0 43 | 44 | #ifndef CPU_CLK_FREQ //Should already be defined in eagle_soc.h 45 | #define CPU_CLK_FREQ 80*1000000 46 | #endif 47 | 48 | //Define some default SPI clock settings 49 | #define SPI_CLK_PREDIV 10 50 | #define SPI_CLK_CNTDIV 2 51 | #define SPI_CLK_FREQ CPU_CLK_FREQ/(SPI_CLK_PREDIV*SPI_CLK_CNTDIV) // 80 / 20 = 4 MHz 52 | 53 | 54 | 55 | 56 | 57 | void spi_init(uint8 spi_no); 58 | void spi_init_gpio(uint8 spi_no, uint8 sysclk_as_spiclk); 59 | void spi_clock(uint8 spi_no, uint16 prediv, uint8 cntdiv); 60 | void spi_tx_byte_order(uint8 spi_no, uint8 byte_order); 61 | void spi_rx_byte_order(uint8 spi_no, uint8 byte_order); 62 | uint32 spi_transaction(uint8 spi_no, uint8 cmd_bits, uint16 cmd_data, uint32 addr_bits, uint32 addr_data, uint32 dout_bits, uint32 dout_data, uint32 din_bits, uint32 dummy_bits); 63 | 64 | //Expansion Macros 65 | #define spi_busy(spi_no) READ_PERI_REG(SPI_CMD(spi_no))&SPI_USR 66 | 67 | #define spi_txd(spi_no, bits, data) spi_transaction(spi_no, 0, 0, 0, 0, bits, (uint32) data, 0, 0) 68 | #define spi_tx8(spi_no, data) spi_transaction(spi_no, 0, 0, 0, 0, 8, (uint32) data, 0, 0) 69 | #define spi_tx7(spi_no, data) spi_transaction(spi_no, 0, 0, 0, 0, 7, (uint32) data, 0, 0) 70 | #define spi_tx9(spi_no, data) spi_transaction(spi_no, 0, 0, 0, 0, 9, (uint32) data, 0, 0) 71 | #define spi_tx16(spi_no, data) spi_transaction(spi_no, 0, 0, 0, 0, 16, (uint32) data, 0, 0) 72 | #define spi_tx32(spi_no, data) spi_transaction(spi_no, 0, 0, 0, 0, 32, (uint32) data, 0, 0) 73 | 74 | #define spi_rxd(spi_no, bits) spi_transaction(spi_no, 0, 0, 0, 0, 0, 0, bits, 0) 75 | #define spi_rx8(spi_no) spi_transaction(spi_no, 0, 0, 0, 0, 0, 0, 8, 0) 76 | #define spi_rx16(spi_no) spi_transaction(spi_no, 0, 0, 0, 0, 0, 0, 16, 0) 77 | #define spi_rx32(spi_no) spi_transaction(spi_no, 0, 0, 0, 0, 0, 0, 32, 0) 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /app/peripheral/driver/tisan_gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * easygpio.h 3 | * 4 | * Copyright (c) 2015, eadf (https://github.com/eadf) 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * * Neither the name of Redis nor the names of its contributors may be used 16 | * to endorse or promote products derived from this software without 17 | * specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef EASYGPIO_INCLUDE_EASYGPIO_EASYGPIO_H_ 33 | #define EASYGPIO_INCLUDE_EASYGPIO_EASYGPIO_H_ 34 | 35 | #include "c_types.h" 36 | 37 | typedef enum { 38 | EASYGPIO_INPUT=0, 39 | EASYGPIO_OUTPUT=1 40 | } EasyGPIO_PinMode; 41 | 42 | typedef enum { 43 | EASYGPIO_PULLDOWN=2, 44 | EASYGPIO_PULLUP=3, 45 | EASYGPIO_NOPULL=4 46 | } EasyGPIO_PullStatus; 47 | 48 | /** 49 | * Returns the gpio name and func for a specific pin. 50 | */ 51 | bool easygpio_getGPIONameFunc(uint8_t gpio_pin, uint32_t *gpio_name, uint8_t *gpio_func); 52 | 53 | /** 54 | * Sets the 'gpio_pin' pin as a GPIO and sets the interrupt to trigger on that pin. 55 | * The 'interruptArg' is the function argument that will be sent to your interruptHandler 56 | * (this way you can several interrupts with one interruptHandler) 57 | */ 58 | bool easygpio_attachInterrupt(uint8_t gpio_pin, EasyGPIO_PullStatus pullStatus, void (*interruptHandler)(void *arg), void *interruptArg); 59 | 60 | /** 61 | * Deatach the interrupt handler from the 'gpio_pin' pin. 62 | */ 63 | bool easygpio_detachInterrupt(uint8_t gpio_pin); 64 | 65 | /** 66 | * Returns the number of active pins in the gpioMask. 67 | */ 68 | uint8_t easygpio_countBits(uint32_t gpioMask); 69 | 70 | /** 71 | * Sets the 'gpio_pin' pin as a GPIO and sets the pull-up and 72 | * pull-down registers for that pin. 73 | * 'pullStatus' has no effect on output pins or GPIO16 74 | */ 75 | bool easygpio_pinMode(uint8_t gpio_pin, EasyGPIO_PullStatus pullStatus, EasyGPIO_PinMode pinMode); 76 | 77 | /** 78 | * Sets the pull up and pull down registers for a pin. 79 | * This seems to do very little for the actual pull effect 80 | * - it's always pull-up for both EASYGPIO_PULLUP and EASYGPIO_PULLDOWN. 81 | * But that is something the SDK needs to fix. 82 | */ 83 | bool easygpio_pullMode(uint8_t gpio_pin, EasyGPIO_PullStatus pullStatus); 84 | 85 | /** 86 | * Uniform way of getting GPIO input value. Handles GPIO 0-16. 87 | * The pin must be initiated with easygpio_pinMode() so that the pin mux is setup as a gpio in the first place. 88 | * If you know that you won't be using GPIO16 then you'd better off by just using GPIO_INPUT_GET(). 89 | */ 90 | uint8_t easygpio_inputGet(uint8_t gpio_pin); 91 | 92 | /** 93 | * Uniform way of setting GPIO output value. Handles GPIO 0-16. 94 | * 95 | * You can not rely on that this function will switch the gpio to an output like GPIO_OUTPUT_SET does. 96 | * Use easygpio_outputEnable() to change an input gpio to output mode. 97 | */ 98 | void easygpio_outputSet(uint8_t gpio_pin, uint8_t value); 99 | 100 | /** 101 | * Uniform way of turning an output GPIO pin into input mode. Handles GPIO 0-16. 102 | * The pin must be initiated with easygpio_pinMode() so that the pin mux is setup as a gpio in the first place. 103 | * This function does the same thing as GPIO_DIS_OUTPUT, but works on GPIO16 too. 104 | */ 105 | void easygpio_outputDisable(uint8_t gpio_pin); 106 | 107 | /** 108 | * Uniform way of turning an input GPIO pin into output mode. Handles GPIO 0-16. 109 | * The pin must be initiated with easygpio_pinMode() so that the pin mux is setup as a gpio in the first place. 110 | * 111 | * This function: 112 | * - should only be used to convert a input pin into an output pin. 113 | * - is a little bit slower than easygpio_outputSet() so you should use that 114 | * function to just change output value. 115 | * - does the same thing as GPIO_OUTPUT_SET, but works on GPIO16 too. 116 | */ 117 | void easygpio_outputEnable(uint8_t gpio_pin, uint8_t value); 118 | 119 | uint8 tisan_get_gpio_id(uint32 io_name); 120 | uint8 tisan_get_gpio_general_func(uint8 io_id); 121 | uint32 tisan_get_gpio_name(uint8 io_id); 122 | 123 | #endif /* EASYGPIO_INCLUDE_EASYGPIO_EASYGPIO_H_ */ 124 | -------------------------------------------------------------------------------- /app/peripheral/driver/tisan_gpio_intr.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/peripheral/driver/tisan_gpio_intr.c -------------------------------------------------------------------------------- /app/peripheral/driver/tisan_gpio_intr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/peripheral/driver/tisan_gpio_intr.h -------------------------------------------------------------------------------- /app/peripheral/peri_dht1122.h: -------------------------------------------------------------------------------- 1 | /* 2 | Driver for the temperature and humidity sensor DHT11 and DHT22 3 | Official repository: https://github.com/CHERTS/esp8266-dht11_22 4 | 5 | Copyright (C) 2014 Mikhail Grigorev (CHERTS) 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License along 18 | with this program; if not, write to the Free Software Foundation, Inc., 19 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | #ifndef __PERI_DHT11_22_H__ 23 | #define __PERI_DHT11_22_H__ 24 | 25 | #include "ets_sys.h" 26 | #include "osapi.h" 27 | 28 | typedef enum { 29 | DHT11 = 0, 30 | DHT22 31 | } DHTType; 32 | 33 | typedef struct { 34 | float temperature; 35 | float humidity; 36 | } DHT_Sensor_Data; 37 | 38 | typedef struct { 39 | uint8_t pin; 40 | DHTType type; 41 | } DHT_Sensor; 42 | 43 | #define DHT_MAXTIMINGS 10000 44 | #define DHT_BREAKTIME 20 45 | #define DHT_MAXCOUNT 32000 46 | 47 | #define DHT_DATA_IO_MUX PERIPHS_IO_MUX_MTDI_U 48 | #define DHT_DATA_IO_NUM 12 49 | #define DHT_DATA_IO_FUNC FUNC_GPIO12 50 | 51 | //#define DHT_DEBUG true 52 | 53 | void peri_dht_init(DHT_Sensor* sensor); 54 | bool peri_dht_read(DHT_Sensor_Data* output); 55 | char* DHTFloat2String(char* buffer, float value); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /app/peripheral/peri_i2c_oled.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_i2c_oled.h 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is the i2c oled driver. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef APP_PERIPHERAL_PERI_I2C_OLED_H_ 13 | #define APP_PERIPHERAL_PERI_I2C_OLED_H_ 14 | 15 | #include "c_types.h" 16 | 17 | #define OLED_ADDRESS 0x78 // D/C->GND 18 | //#define OLED_ADDRESS 0x7a // D/C->Vcc 19 | 20 | /****************************************************************************** 21 | * FunctionName : peri_i2c_oled_init 22 | * Description : initialize the oled. 23 | * Parameters : none. 24 | * Returns : none. 25 | *******************************************************************************/ 26 | bool ICACHE_FLASH_ATTR 27 | peri_i2c_oled_init(void); 28 | 29 | /****************************************************************************** 30 | * FunctionName : peri_oled_clean_screen. 31 | * Description : clean the screen of the oled. 32 | * Parameters : none. 33 | * Returns : none. 34 | *******************************************************************************/ 35 | void ICACHE_FLASH_ATTR 36 | peri_oled_clean_screen(void); 37 | 38 | /****************************************************************************** 39 | * FunctionName : peri_oled_on. 40 | * Description : turn on the oled. 41 | * Parameters : none. 42 | * Returns : none. 43 | *******************************************************************************/ 44 | void ICACHE_FLASH_ATTR 45 | peri_oled_on(void); 46 | 47 | /****************************************************************************** 48 | * FunctionName : peri_oled_off. 49 | * Description : turn off the oled. 50 | * Parameters : none. 51 | * Returns : none. 52 | *******************************************************************************/ 53 | void ICACHE_FLASH_ATTR 54 | peri_oled_off(void); 55 | 56 | /****************************************************************************** 57 | * FunctionName : peri_oled_show_str. 58 | * Description : print string to the oled. 59 | * Parameters : unsigned char x: the string x position; 60 | * unsigned char y: the string y position; 61 | * unsigned char ch[]: the print string; 62 | * unsigned char len: the length of the string. 63 | * unsigned char text_size: the size of the string. 64 | * Returns : none. 65 | *******************************************************************************/ 66 | void ICACHE_FLASH_ATTR 67 | peri_oled_show_str(unsigned char x, unsigned char y, unsigned char ch[], unsigned char len, unsigned char text_size); 68 | /****************************************************************************** 69 | * FunctionName : peri_oled_draw_bmp. 70 | * Description : print the bmp picture to the oled. 71 | * Parameters : unsigned char x0: the left horizontal position of the bmp picture; 72 | * unsigned char y0: the left vertical position of the bmp picture; 73 | * unsigned char x1: the right horizontal position of the bmp picture; 74 | * unsigned char y1: the left vertical position of the bmp picture; 75 | * unsigned char bmp[]: the bmp picture array; 76 | * Returns : none. 77 | *******************************************************************************/ 78 | void ICACHE_FLASH_ATTR 79 | peri_oled_draw_bmp(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char bmp[]); 80 | #endif /* APP_PERIPHERAL_PERI_I2C_OLED_H_ */ 81 | -------------------------------------------------------------------------------- /app/peripheral/peri_iaq.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_iaq5000.c 3 | * Author: Shasha Liu 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: Indoor air quality detect module. 6 | in this example:GPIO 15: the plug relay driver; 7 | GPIO 12 a blinking led; 8 | GPIO 0 the wifi connect state indicate; 9 | GPIO 13 a press key. 10 | * History: 11 | * 1.Date: 12 | * Author: 13 | * Modification: 14 | *********************************************************/ 15 | 16 | #include "peri_iaq.h" 17 | 18 | #include "ets_sys.h" 19 | #include "osapi.h" 20 | #include "os_type.h" 21 | #include "mem.h" 22 | #include "user_interface.h" 23 | #include "driver/key.h" 24 | #include "driver/i2c.h" 25 | 26 | /* NOTICE---this is for i2c communication. 27 | * 0x84 is the i2c slave device address for 7 bit. */ 28 | #define IAQ5000_ADD 0x84 29 | #define IAQ5000_ADD_W 0x84 30 | #define IAQ5000_ADD_R 0x85 31 | 32 | /****************************************************************************** 33 | * FunctionName : user_mvh3004_burst_read 34 | * Description : burst read mvh3004's internal data 35 | * Parameters : uint8 addr - mvh3004's address 36 | * uint8 *pData - data point to put read data 37 | * uint16 len - read length 38 | * Returns : bool - true or false 39 | *******************************************************************************/ 40 | LOCAL bool ICACHE_FLASH_ATTR 41 | peri_iaq_single_burst_read(uint8 addr, uint8 *pData, uint16 len) 42 | { 43 | uint8 ack; 44 | uint16 i; 45 | 46 | i2c_start(); 47 | i2c_writeByte(addr); 48 | ack = i2c_check_ack(); 49 | PRINTF("the first ack is:%d\n",ack); 50 | if (ack==0) { 51 | os_printf("addr1 not ack when tx write cmd \n"); 52 | i2c_stop(); 53 | return false; 54 | } 55 | 56 | 57 | i2c_writeByte(0x52); 58 | ack = i2c_check_ack(); 59 | PRINTF("the second ack is:%d\n",ack); 60 | 61 | if (ack==0) { 62 | os_printf("not ack when write 0x52 \n"); 63 | i2c_stop(); 64 | return false; 65 | } 66 | 67 | i2c_start(); 68 | i2c_writeByte(addr + 1); 69 | ack = i2c_check_ack(); 70 | PRINTF("the third ack is:%d\n",ack); 71 | if (ack==0) { 72 | os_printf("addr2 not ack when tx write cmd \n"); 73 | i2c_stop(); 74 | return false; 75 | } 76 | os_delay_us(1); 77 | for (i = 0; i < len; i++) { 78 | pData[i] = i2c_readByte(); 79 | if(i==3) 80 | i2c_send_ack(0); 81 | else 82 | i2c_send_ack(1); 83 | 84 | 85 | os_delay_us(1); 86 | PRINTF("bytes_readed:%d\n", pData[i]); 87 | } 88 | 89 | i2c_stop(); 90 | 91 | 92 | return true; 93 | } 94 | /****************************************************************************** 95 | * FunctionName : user_mvh3004_read_th 96 | * Description : read mvh3004's humiture data 97 | * Parameters : uint8 *data - where data to put 98 | * Returns : bool - ture or false 99 | *******************************************************************************/ 100 | uint16 ICACHE_FLASH_ATTR 101 | peri_iaq_read(void) 102 | { 103 | uint8 data[4]; 104 | uint16 iaq_value; 105 | peri_iaq_single_burst_read(IAQ5000_ADD,data, 4); 106 | 107 | if((data[0]!=0xA5)||(data[3]!=0x3C)) 108 | { 109 | os_printf("iaq5000 read data error \n"); 110 | return 0; 111 | } 112 | else 113 | { 114 | iaq_value = data[1]*256+data[2]; 115 | os_printf("iaq5000 read data :%d \n",iaq_value); 116 | return iaq_value; 117 | 118 | } 119 | 120 | } 121 | /****************************************************************************** 122 | * FunctionName : user_iaq5000_init 123 | * Description : init iaq5000, mainly i2c master gpio 124 | * Parameters : none 125 | * Returns : none 126 | *******************************************************************************/ 127 | void ICACHE_FLASH_ATTR 128 | peri_iaq_init(void) 129 | { 130 | i2c_init(); 131 | } 132 | -------------------------------------------------------------------------------- /app/peripheral/peri_iaq.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: user_plug.h 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: plug. 6 | in this example:GPIO 15: the plug relay driver; 7 | GPIO 12 a blinking led; 8 | GPIO 0 the wifi connect state indicate; 9 | GPIO 13 a press key. 10 | * History: 11 | * 1.Date: 12 | * Author: 13 | * Modification: 14 | *********************************************************/ 15 | 16 | #ifndef __PERI_IAQ_H__ 17 | #define __PERI_IAQ_H__ 18 | 19 | #include "ets_sys.h" 20 | 21 | 22 | void peri_iaq_init(void); 23 | uint16 peri_iaq_read(void); 24 | uint8* peri_iaq_get(void); 25 | 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /app/peripheral/peri_jdq.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_jdq.c 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: relay. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "peri_jdq.h" 13 | 14 | #include "user_interface.h" 15 | #include "driver/pwm.h" 16 | #include "c_types.h" 17 | #include "spi_flash.h" 18 | #include "gpio.h" 19 | #include "peri_rgb_light.h" 20 | #include "../pando/pando_object.h" 21 | 22 | extern uint8_t FLASH_SEC_NUM ; 23 | 24 | #define JDQ_FLASH_PRIV_SAVE FLASH_SEC_NUM 25 | uint8 jdq_pin; 26 | /****************************************************************************** 27 | * FunctionName : peri_jdq_get. 28 | * Description : get jdq state. 29 | * Parameters : none 30 | * Returns : jdq state. 31 | *******************************************************************************/ 32 | 33 | uint8 ICACHE_FLASH_ATTR 34 | peri_jdq_get() 35 | { 36 | uint8 jdq_state; 37 | 38 | spi_flash_read((PRIV_PARAM_START_SEC + JDQ_FLASH_PRIV_SAVE) * SPI_FLASH_SEC_SIZE, 39 | (uint32 *)&jdq_state, sizeof(uint8)); 40 | return jdq_state; 41 | } 42 | /****************************************************************************** 43 | * FunctionName : peri_jdq_set 44 | * Description : set jdq on or off 45 | * Parameters : uint8 on_off 46 | * Returns : none 47 | *******************************************************************************/ 48 | void ICACHE_FLASH_ATTR 49 | peri_jdq_set(uint8 on_off) 50 | { 51 | if(on_off==1) 52 | { 53 | GPIO_OUTPUT_SET(jdq_pin, 1); 54 | PRINTF("jdq ON\n"); 55 | } 56 | else 57 | { 58 | GPIO_OUTPUT_SET(jdq_pin, 0); 59 | PRINTF("jdq OFF\n"); 60 | } 61 | spi_flash_erase_sector(PRIV_PARAM_START_SEC + JDQ_FLASH_PRIV_SAVE); 62 | spi_flash_write((PRIV_PARAM_START_SEC + JDQ_FLASH_PRIV_SAVE) * SPI_FLASH_SEC_SIZE, 63 | (uint32 *)&on_off, sizeof(uint8)); 64 | 65 | 66 | } 67 | /****************************************************************************** 68 | * FunctionName : peri_jdq_timer_set 69 | * Description : set jdq on or off by timer 70 | * Parameters : none 71 | * Returns : none 72 | *******************************************************************************/ 73 | void ICACHE_FLASH_ATTR 74 | peri_jdq_timer_set(void) 75 | { 76 | static uint8 i=1; 77 | if(i==1) 78 | { 79 | GPIO_OUTPUT_SET(jdq_pin, i); 80 | PRINTF("jdq ON\n"); 81 | i=0; 82 | } 83 | else 84 | { 85 | GPIO_OUTPUT_SET(jdq_pin, i); 86 | PRINTF("jdq OFF\n"); 87 | i=1; 88 | } 89 | spi_flash_erase_sector(PRIV_PARAM_START_SEC + JDQ_FLASH_PRIV_SAVE); 90 | spi_flash_write((PRIV_PARAM_START_SEC + JDQ_FLASH_PRIV_SAVE) * SPI_FLASH_SEC_SIZE, 91 | (uint32 *)&i, sizeof(uint8)); 92 | 93 | 94 | } 95 | /****************************************************************************** 96 | * FunctionName : peri_jdq_init 97 | * Description : JDQ initialize, mainly initialize pwm mode 98 | * Parameters : uint8 gpio_id 99 | * Returns : none 100 | *******************************************************************************/ 101 | void ICACHE_FLASH_ATTR 102 | peri_jdq_init(uint8 gpio_id) 103 | { 104 | // enum JDQ_STATE jdq_state; 105 | 106 | PRINTF("I am the jdq\n"); 107 | 108 | //PRINTF("jdq_state: %d\n", jdq_state); 109 | PIN_FUNC_SELECT(tisan_get_gpio_name(gpio_id), tisan_get_gpio_general_func(gpio_id)); 110 | PIN_PULLUP_EN(tisan_get_gpio_name(gpio_id)); 111 | jdq_pin=gpio_id; 112 | 113 | } 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /app/peripheral/peri_jdq.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_jdq.h 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: relay. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __PERI_JDQ_H__ 13 | #define __PERI_JDQ_H__ 14 | 15 | #include "c_types.h" 16 | 17 | #pragma pack(1) 18 | 19 | void peri_jdq_init(uint8 gpio_id); 20 | uint8 peri_jdq_get(void); 21 | void peri_jdq_set(uint8 on_off); 22 | void peri_jdq_timer_set(void); 23 | #endif 24 | -------------------------------------------------------------------------------- /app/peripheral/peri_key.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_key.c 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This is the key function module. 6 | 7 | * History: 8 | * 1.Date: 9 | * Author: 10 | * Modification: 11 | *********************************************************/ 12 | #include "peri_key.h" 13 | #include "user_interface.h" 14 | #include "eagle_soc.h" 15 | #include "driver/key.h" 16 | #include "os_type.h" 17 | #include "mem.h" 18 | #include "driver/tisan_gpio_intr.h" 19 | 20 | 21 | /****************************************************************************** 22 | * FunctionName : user_plug_short_press 23 | * Description : key's short press function, needed to be installed 24 | * Parameters : none 25 | * Returns : none 26 | *******************************************************************************/ 27 | void ICACHE_FLASH_ATTR 28 | peri_key_short_press(void) 29 | { 30 | PRINTF("short\n"); 31 | } 32 | 33 | 34 | /****************************************************************************** 35 | * FunctionName : user_plug_long_press 36 | * Description : key's long press function, needed to be installed, preserved function. 37 | * Parameters : none 38 | * Returns : none 39 | *******************************************************************************/ 40 | 41 | void ICACHE_FLASH_ATTR 42 | peri_key_long_press(void) 43 | { 44 | PRINTF("long\n"); 45 | } 46 | /****************************************************************************** 47 | * FunctionName : peri_key_init. 48 | * Description : initialize key device. 49 | * Parameters : none 50 | * Returns : none 51 | *******************************************************************************/ 52 | void ICACHE_FLASH_ATTR 53 | peri_single_key_init(uint8 gpio_id,key_function long_press, key_function short_press) 54 | { 55 | struct key_param *single_key = (struct key_param *)os_zalloc(sizeof(struct key_param)); 56 | uint32 gpio_name=tisan_get_gpio_name(gpio_id); 57 | uint8 gpio_func=tisan_get_gpio_general_func(gpio_id); 58 | single_key->gpio_id = gpio_id; 59 | single_key->key_level = 1; 60 | single_key->long_press = long_press; 61 | single_key->short_press = short_press; 62 | 63 | ETS_GPIO_INTR_ATTACH(gpio_intr_handler, single_key); 64 | ETS_GPIO_INTR_DISABLE(); 65 | 66 | key_init(gpio_name, gpio_id, gpio_func); 67 | 68 | ETS_GPIO_INTR_ENABLE(); 69 | 70 | } 71 | -------------------------------------------------------------------------------- /app/peripheral/peri_key.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_key.h 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is the key function module. 6 | 7 | * History: 8 | * 1.Date: 9 | * Author: 10 | * Modification: 11 | *********************************************************/ 12 | 13 | #ifndef PERI_KEY_H_ 14 | #define PERI_KEY_H_ 15 | 16 | 17 | #include "gpio.h" 18 | #include "../../include/os_type.h" 19 | 20 | #define CONFIG_KEY_0_IO_MUX PERIPHS_IO_MUX_GPIO4_U 21 | 22 | typedef void (* key_function)(void); 23 | 24 | struct key_param { 25 | uint8 key_level; 26 | uint8 gpio_id; 27 | os_timer_t key_5s; 28 | os_timer_t key_50ms; 29 | key_function short_press; 30 | key_function long_press; 31 | }; 32 | 33 | struct keys_param { 34 | uint8 key_num; 35 | struct key_param **single_key; 36 | }; 37 | 38 | void peri_key_short_press(void); 39 | void peri_key_long_press(void); 40 | void peri_single_key_init(uint8 gpio_id,key_function long_press, key_function short_press); 41 | 42 | 43 | #endif /* APP_INCLUDE_USER_USER_KEY_H_ */ 44 | -------------------------------------------------------------------------------- /app/peripheral/peri_ldr.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_ldr.c 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: light dependent resistor. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "peri_ldr.h" 13 | 14 | #include "user_interface.h" 15 | #include "driver/adc.h" 16 | #include "c_types.h" 17 | #include "gpio.h" 18 | /****************************************************************************** 19 | * FunctionName : peri_lsr_read 20 | * Description : read lsr value 21 | * Parameters : none 22 | * Returns : none 23 | *******************************************************************************/ 24 | uint16 ICACHE_FLASH_ATTR 25 | peri_ldr_read(void) 26 | { 27 | return adc_read(); 28 | } 29 | /****************************************************************************** 30 | * FunctionName : peri_lsr_timer_read 31 | * Description : peri_lsr_timer_read 32 | * Parameters : none 33 | * Returns : none 34 | *******************************************************************************/ 35 | void ICACHE_FLASH_ATTR 36 | peri_ldr_timer_read(void) 37 | { 38 | uint16 value; 39 | value = peri_lsr_read(); 40 | PRINTF("lsr_value=%d\n",value); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /app/peripheral/peri_ldr.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_ldr.h 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: light dependent resistor. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __PERI_LDR_H__ 13 | #define __PERI_LDR_H__ 14 | 15 | #include "c_types.h" 16 | 17 | #pragma pack(1) 18 | 19 | uint16 peri_ldr_read(void); 20 | void peri_ldr_timer_read(void); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /app/peripheral/peri_led.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_led.c 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is driver of the led. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "peri_led.h" 13 | #include "eagle_soc.h" 14 | #include "driver/tisan_gpio.h" 15 | #include "os_type.h" 16 | #include "gpio.h" 17 | #include "osapi.h" 18 | 19 | static os_timer_t led_blink_timer; 20 | static uint32 led_pin; 21 | 22 | /****************************************************************************** 23 | * FunctionName : peri_led_init. 24 | * Description : initialize the led. 25 | * Parameters : uint8 gpio_id: the gpio pin drive the led. 26 | * Returns : none 27 | *******************************************************************************/ 28 | void ICACHE_FLASH_ATTR 29 | peri_led_init(uint8 gpio_id) 30 | { 31 | PIN_FUNC_SELECT(tisan_get_gpio_name(gpio_id), tisan_get_gpio_general_func(gpio_id)); 32 | PIN_PULLUP_EN(tisan_get_gpio_name(gpio_id)); 33 | led_pin = gpio_id; 34 | } 35 | 36 | /****************************************************************************** 37 | * FunctionName : led_blink_timer_cb. 38 | * Description : the led_blink_time callback function.. 39 | * Parameters : none. 40 | * Returns : none 41 | *******************************************************************************/ 42 | static void ICACHE_FLASH_ATTR 43 | led_blink_timer_cb(void* arg) 44 | { 45 | static bool state = 0; 46 | if(state == 0) 47 | { 48 | state = 1; 49 | GPIO_OUTPUT_SET(led_pin, state); 50 | } 51 | else 52 | { 53 | state = 0; 54 | GPIO_OUTPUT_SET(led_pin, state); 55 | } 56 | } 57 | 58 | /****************************************************************************** 59 | * FunctionName : peri_led_blink. 60 | * Description : blink the led. 61 | * Parameters : BLINK_SPEED speed: the blink speed. 62 | * Returns : none 63 | *******************************************************************************/ 64 | void ICACHE_FLASH_ATTR 65 | peri_led_blink(BLINK_SPEED speed) 66 | { 67 | os_timer_disarm(&led_blink_timer); 68 | os_timer_setfn(&led_blink_timer, (os_timer_func_t *)led_blink_timer_cb, NULL); 69 | os_timer_arm(&led_blink_timer, speed, 1); 70 | } 71 | 72 | /****************************************************************************** 73 | * FunctionName : peri_led_set. 74 | * Description : set the led state. 75 | * Parameters : bool state: the set state of the led, 1:on ; 0:off. 76 | * Returns : none 77 | *******************************************************************************/ 78 | void ICACHE_FLASH_ATTR 79 | peri_led_set(bool state) 80 | { 81 | os_timer_disarm(&led_blink_timer); 82 | GPIO_OUTPUT_SET(led_pin, state); 83 | } 84 | -------------------------------------------------------------------------------- /app/peripheral/peri_led.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_led.h 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is driver of the led. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef APP_PERIPHERAL_PERI_LED_H_ 13 | #define APP_PERIPHERAL_PERI_LED_H_ 14 | 15 | #include "c_types.h" 16 | 17 | typedef enum { 18 | BLINK_QUICK = 50, 19 | BLINK_SLOW = 1000 20 | }BLINK_SPEED; 21 | 22 | /****************************************************************************** 23 | * FunctionName : peri_led_init. 24 | * Description : initialize the led. 25 | * Parameters : uint8 gpio_id: the gpio pin drive the led. 26 | * Returns : none 27 | *******************************************************************************/ 28 | void peri_led_init(uint8 gpio_id); 29 | 30 | /****************************************************************************** 31 | * FunctionName : peri_led_blink. 32 | * Description : blink the led. 33 | * Parameters : BLINK_SPEED speed: the blink speed. 34 | * Returns : none 35 | *******************************************************************************/ 36 | void peri_led_blink(BLINK_SPEED speed); 37 | 38 | /****************************************************************************** 39 | * FunctionName : peri_led_set. 40 | * Description : set the led state. 41 | * Parameters : bool state: the set state of the led, 1:on ; 0:off. 42 | * Returns : none 43 | *******************************************************************************/ 44 | void peri_led_set(bool state); 45 | 46 | #endif /* APP_PERIPHERAL_PERI_LED_H_ */ 47 | -------------------------------------------------------------------------------- /app/peripheral/peri_motor.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_motor.c 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: motor. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "peri_motor.h" 13 | #include "peri_rgb_light.h" 14 | 15 | #include "user_interface.h" 16 | #include "driver/pwm.h" 17 | #include "c_types.h" 18 | #include "spi_flash.h" 19 | #include "../pando/pando_object.h" 20 | 21 | extern uint8_t FLASH_SEC_NUM ; 22 | 23 | 24 | #define MOTOR_FLASH_PRIV_SAVE FLASH_SEC_NUM 25 | 26 | struct PWM_APP_PARAM motor_forward_param={25000,40,0}; 27 | struct PWM_APP_PARAM motor_backard_param={25000,0,40}; 28 | 29 | /****************************************************************************** 30 | * FunctionName : peri_motor_get. 31 | * Description : get the parameter of the motor status. 32 | * Parameters : none 33 | * Returns : the parameter of the motor status. 34 | *******************************************************************************/ 35 | 36 | struct PWM_APP_PARAM ICACHE_FLASH_ATTR 37 | peri_motor_get(void) 38 | { 39 | struct PWM_APP_PARAM ret; 40 | 41 | spi_flash_read((PRIV_PARAM_START_SEC + MOTOR_FLASH_PRIV_SAVE) * SPI_FLASH_SEC_SIZE, 42 | (uint32 *)&ret, sizeof(struct PWM_APP_PARAM)); 43 | return ret; 44 | } 45 | 46 | 47 | /****************************************************************************** 48 | * FunctionName : peri_motor_set. 49 | * Description : set the parameter of motor status. 50 | * Parameters : struct LIGHT_PARAM motor_param. 51 | * Returns : none 52 | *******************************************************************************/ 53 | 54 | void ICACHE_FLASH_ATTR 55 | peri_motor_set( struct PWM_APP_PARAM motor_param) 56 | { 57 | pwm_set_freq(motor_param.pwm_freq); 58 | pwm_set_duty(motor_param.pwm_duty[0], 0); 59 | pwm_set_duty(motor_param.pwm_duty[1], 1); 60 | pwm_set_duty(motor_param.pwm_duty[2], 2); 61 | 62 | pwm_start(); 63 | 64 | spi_flash_erase_sector(PRIV_PARAM_START_SEC + MOTOR_FLASH_PRIV_SAVE); 65 | spi_flash_write((PRIV_PARAM_START_SEC + MOTOR_FLASH_PRIV_SAVE) * SPI_FLASH_SEC_SIZE, 66 | (uint32 *)&motor_param, sizeof(struct PWM_APP_PARAM)); 67 | } 68 | 69 | /****************************************************************************** 70 | * FunctionName : peri_motor_init 71 | * Description : motor initialize , mainly initialize pwm mode 72 | * Parameters : struct LIGHT_PARAM motor_param,struct LIGHT_INIT motor_init 73 | * Returns : none 74 | *******************************************************************************/ 75 | void ICACHE_FLASH_ATTR 76 | peri_motor_init(struct PWM_APP_PARAM motor_param,struct PWM_INIT motor_init) 77 | { 78 | PRINTF("I am the electronic-motor\n"); 79 | PRINTF("pwm_freq: %d, pwm_duty1: %d, pwm_duty2: %d\n",motor_param.pwm_freq, 80 | (motor_param.pwm_duty)[0], (motor_param.pwm_duty)[1]); 81 | PRINTF("start flash write \n"); 82 | 83 | spi_flash_write((PRIV_PARAM_START_SEC + MOTOR_FLASH_PRIV_SAVE) * SPI_FLASH_SEC_SIZE, 84 | (uint32 *)&motor_param, sizeof(struct PWM_APP_PARAM)); 85 | 86 | PRINTF("finished \n"); 87 | pwm_init(motor_param,motor_init); 88 | pwm_start(); 89 | 90 | } 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /app/peripheral/peri_motor.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: peri_motor.h 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: motor. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __PERI_MOTOR_H__ 13 | #define __PERI_MOTOR_H__ 14 | 15 | #include "c_types.h" 16 | #include "driver/pwm.h" 17 | #include "peri_rgb_light.h" 18 | 19 | #pragma pack(1) 20 | 21 | 22 | void peri_motor_init(struct PWM_APP_PARAM motor_param,struct PWM_INIT motor_init); 23 | struct PWM_APP_PARAM peri_motor_get(void); 24 | void peri_motor_set( struct PWM_APP_PARAM motor_param); 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /app/peripheral/peri_pm25.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: user_plug.c 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: plug. 6 | in this example:GPIO 15: the plug relay driver; 7 | GPIO 12 a blinking led; 8 | GPIO 0 the wifi connect state indicate; 9 | GPIO 13 a press key. 10 | * History: 11 | * 1.Date: 12 | * Author: 13 | * Modification: 14 | *********************************************************/ 15 | 16 | #include "ets_sys.h" 17 | #include "osapi.h" 18 | #include "os_type.h" 19 | #include "mem.h" 20 | #include "user_interface.h" 21 | #include "driver/key.h" 22 | #include "driver/uart.h" 23 | #include "driver/uart_register.h" 24 | #include "peri_pm25.h" 25 | 26 | /* NOTICE---this is for i2c communication. 27 | * 0x84 is the i2c slave device address for 7 bit. */ 28 | 29 | PM25_REV_DATA *PM25_data_buffer; 30 | extern uint8 RcvBuff[128]; 31 | uint16 pm25_data; 32 | void display_PMdevice_data(PM25_REV_DATA *data_buffer) 33 | { 34 | PRINTF("PM device data display\n"); 35 | PRINTF("start_byte1:%x\n", data_buffer->start_byte1); 36 | PRINTF("start_byte2:%x\n", data_buffer->start_byte2); 37 | PRINTF("length:%x\n", data_buffer->length); 38 | PRINTF("pm1.0:%x\n", data_buffer->pm1_0); 39 | PRINTF("pm2.5:%x\n", data_buffer->pm2_5); 40 | PRINTF("pm10:%x\n", data_buffer->pm10_0); 41 | PRINTF("um0.3:%x\n", data_buffer->um0_3); 42 | PRINTF("um0.5:%x\n", data_buffer->um0_5); 43 | PRINTF("um1.0:%x\n", data_buffer->um1_0); 44 | PRINTF("um2.5:%x\n", data_buffer->um2_5); 45 | PRINTF("um5.0:%x\n", data_buffer->um5_0); 46 | PRINTF("um10:%x\n", data_buffer->um10_0); 47 | ETS_UART_INTR_DISABLE(); 48 | } 49 | /****************************************************************************** 50 | * FunctionName : user_mvh3004_read_th 51 | * Description : read mvh3004's humiture data 52 | * Parameters : uint8 *data - where data to put 53 | * Returns : bool - ture or false 54 | ********************************************************************************/ 55 | uint16 ICACHE_FLASH_ATTR 56 | peri_pm_25_get(void) 57 | { 58 | uint8 i,data1,data2; 59 | if(RcvBuff[0]==0x32) 60 | { 61 | data1 = RcvBuff[6]; 62 | data2 = RcvBuff[7]; 63 | pm25_data = data1*256+ data2; 64 | PRINTF("data1=%x , data2=%x\n", data1,data2); 65 | // PM25_data_buffer->pm2_5 = (RcvBuff[6]<<8)&0xff00 + RcvBuff[7] ; 66 | } 67 | 68 | // PRINTF("pm2.5:%x\n", PM25_data_buffer->pm2_5); 69 | PRINTF("pm2.5 : %x\n", pm25_data); 70 | return pm25_data; 71 | } 72 | 73 | -------------------------------------------------------------------------------- /app/peripheral/peri_pm25.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: user_plug.h 3 | * Author: Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: plug. 6 | in this example:GPIO 15: the plug relay driver; 7 | GPIO 12 a blinking led; 8 | GPIO 0 the wifi connect state indicate; 9 | GPIO 13 a press key. 10 | * History: 11 | * 1.Date: 12 | * Author: 13 | * Modification: 14 | *********************************************************/ 15 | 16 | #ifndef __PERI_PM25_H__ 17 | #define __PERI_PM25_H__ 18 | 19 | #define PM_SENT_START1 0x32 20 | #define PM_SENT_START2 0x3d 21 | typedef struct 22 | { 23 | uint8 start_byte1; 24 | uint8 start_byte2; 25 | uint16 length; 26 | uint16 pm1_0; 27 | uint16 pm2_5; 28 | uint16 pm10_0; 29 | uint16 um0_3; 30 | uint16 um0_5; 31 | uint16 um1_0; 32 | uint16 um2_5; 33 | uint16 um5_0; 34 | uint16 um10_0; 35 | uint16 save[4]; 36 | uint16 crc; 37 | }PM25_REV_DATA; 38 | 39 | void display_PMdevice_data(PM25_REV_DATA *data_buffer); 40 | uint16 peri_pm_25_get(void); 41 | 42 | 43 | #endif 44 | 45 | -------------------------------------------------------------------------------- /app/peripheral/peri_rgb_light.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: user_tri_color_light.c 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: tri-colored light. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "peri_rgb_light.h" 13 | 14 | #include "user_interface.h" 15 | #include "driver/pwm.h" 16 | #include "c_types.h" 17 | #include "spi_flash.h" 18 | #include "../pando/pando_object.h" 19 | 20 | extern uint8_t FLASH_SEC_NUM ; 21 | 22 | #define RGB_LIGHT_PRIV_SAVE FLASH_SEC_NUM 23 | 24 | struct PWM_APP_PARAM light_r_param={25000,255,0,255}; 25 | struct PWM_APP_PARAM light_g_param={25000,0,255,255}; 26 | struct PWM_APP_PARAM light_b_param={25000,255,255,0}; 27 | 28 | /****************************************************************************** 29 | * FunctionName : peri_rgb_light_param_get. 30 | * Description : get the parameter of the RGB light. 31 | * Parameters : none 32 | * Returns : the parameter of the RGB light. 33 | *******************************************************************************/ 34 | 35 | struct PWM_APP_PARAM ICACHE_FLASH_ATTR 36 | peri_rgb_light_param_get(void) 37 | { 38 | struct PWM_APP_PARAM ret; 39 | 40 | spi_flash_read((PRIV_PARAM_START_SEC + RGB_LIGHT_PRIV_SAVE) * SPI_FLASH_SEC_SIZE, 41 | (uint32 *)&ret, sizeof(struct PWM_APP_PARAM)); 42 | return ret; 43 | } 44 | 45 | 46 | /****************************************************************************** 47 | * FunctionName : peri_rgb_light_param_set. 48 | * Description : set the parameter of the RGB light. 49 | * Parameters : light_param-- RGB light parameter. 50 | * Returns : none 51 | *******************************************************************************/ 52 | 53 | void ICACHE_FLASH_ATTR 54 | peri_rgb_light_param_set( struct PWM_APP_PARAM light_param) 55 | { 56 | pwm_set_freq(light_param.pwm_freq); 57 | pwm_set_duty(light_param.pwm_duty[0], 0); // red colour. 58 | pwm_set_duty(light_param.pwm_duty[1], 1); // green colour. 59 | pwm_set_duty(light_param.pwm_duty[2], 2); // blue colour. 60 | 61 | pwm_start(); 62 | 63 | spi_flash_erase_sector(PRIV_PARAM_START_SEC + RGB_LIGHT_PRIV_SAVE); 64 | spi_flash_write((PRIV_PARAM_START_SEC + RGB_LIGHT_PRIV_SAVE) * SPI_FLASH_SEC_SIZE, 65 | (uint32 *)&light_param, sizeof(struct PWM_APP_PARAM)); 66 | } 67 | 68 | /****************************************************************************** 69 | * FunctionName : peri_rgb_light_param_timer_set. 70 | * Description : set the parameter of the RGB light by timer. 71 | * Parameters : none. 72 | * Returns : none. 73 | *******************************************************************************/ 74 | 75 | void ICACHE_FLASH_ATTR 76 | peri_rgb_light_param_timer_set(void) 77 | { 78 | static uint8 j=0; 79 | 80 | if(j==0) 81 | { 82 | peri_rgb_light_param_set(light_r_param); 83 | PRINTF("red\n"); 84 | j++; 85 | } 86 | else if(j==1) 87 | { 88 | peri_rgb_light_param_set(light_g_param); 89 | PRINTF("green\n"); 90 | j++; 91 | } 92 | else 93 | { 94 | 95 | peri_rgb_light_param_set(light_b_param); 96 | PRINTF("blue\n"); 97 | j=0; 98 | } 99 | 100 | 101 | } 102 | /****************************************************************************** 103 | * FunctionName : peri_rgb_light_init 104 | * Description : light demo initialize, mainly initialize pwm mode 105 | * Parameters : struct PWM_APP_PARAM light_param,struct PWM_INIT light_init 106 | * Returns : none 107 | *******************************************************************************/ 108 | void ICACHE_FLASH_ATTR 109 | peri_rgb_light_init(struct PWM_APP_PARAM light_param,struct PWM_INIT light_init) 110 | { 111 | 112 | PRINTF("I am the tri-colored light\n"); 113 | PRINTF("pwm_freq: %d, pwm_duty_red: %d, pwm_duty_green: %d, pwm_duty_blue: %d\n", light_param.pwm_freq, 114 | (light_param.pwm_duty)[0], (light_param.pwm_duty)[1], (light_param.pwm_duty)[2]); 115 | 116 | spi_flash_write((PRIV_PARAM_START_SEC + RGB_LIGHT_PRIV_SAVE) * SPI_FLASH_SEC_SIZE, 117 | (uint32 *)&light_param, sizeof(struct PWM_APP_PARAM)); 118 | 119 | pwm_init(light_param,light_init); 120 | pwm_start(); 121 | 122 | } 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /app/peripheral/peri_rgb_light.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: user_tri_color_light.h 3 | * Author: 4 | * Versions:1.0 5 | * Description:This module is driver of the subdevice: tri-colored light. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef ___PERI_RGB_LIGHT_H__ 13 | #define ___PERI_RGB_LIGHT_H__ 14 | 15 | #include "c_types.h" 16 | #include "driver/pwm.h" 17 | 18 | #pragma pack(1) 19 | 20 | #define PRIV_PARAM_START_SEC 0x7C 21 | #define PRIV_PARAM_SAVE 0 22 | 23 | 24 | //void peri_rgb_light_init(struct PWM_APP_PARAM light_param,struct PWM_INIT light_init); 25 | struct PWM_APP_PARAM peri_rgb_light_param_get(void); 26 | void peri_rgb_light_param_set( struct PWM_APP_PARAM light_param); 27 | void peri_rgb_light_param_timer_set(void); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /app/peripheral/peri_usart_gpu.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/peripheral/peri_usart_gpu.c -------------------------------------------------------------------------------- /app/peripheral/peri_usart_gpu.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/peripheral/peri_usart_gpu.h -------------------------------------------------------------------------------- /app/peripheral/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/peripheral/readme.txt -------------------------------------------------------------------------------- /app/user/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # Required variables for each makefile 3 | # Discard this section from all parent makefiles 4 | # Expected variables (with automatic defaults): 5 | # CSRCS (all "C" files in the dir) 6 | # SUBDIRS (all subdirs with a Makefile) 7 | # GEN_LIBS - list of libs to be generated () 8 | # GEN_IMAGES - list of object file images to be generated () 9 | # GEN_BINS - list of binaries 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 | 15 | ############################################################# 16 | # Configuration i.e. compile options etc. 17 | # Target specific stuff (defines etc.) goes in here! 18 | # Generally values applying to a tree are captured in the 19 | # makefile at its root level - these are then overridden 20 | # for a subtree within the makefile rooted therein 21 | # 22 | 23 | #UNIVERSAL_TARGET_DEFINES = \ 24 | 25 | ifndef PDIR 26 | GEN_LIBS = libuser.a 27 | SUBDIRS= \ 28 | objects 29 | endif 30 | 31 | 32 | # Other potential configuration flags include: 33 | # -DTXRX_TXBUF_DEBUG 34 | # -DTXRX_RXBUF_DEBUG 35 | # -DWLAN_CONFIG_CCX 36 | 37 | ############################################################# 38 | # Recursion Magic - Don't touch this!! 39 | # 40 | # Each subtree potentially has an include directory 41 | # corresponding to the common APIs applicable to modules 42 | # rooted at that subtree. Accordingly, the INCLUDE PATH 43 | # of a module can only contain the include directories up 44 | # its parent path, and not its siblings 45 | # 46 | # Required for each makefile to inherit from the parent 47 | # 48 | 49 | INCLUDES := $(INCLUDES) -I $(PDIR)include 50 | PDIR := ../$(PDIR) 51 | sinclude $(PDIR)Makefile 52 | 53 | .PHONY: FORCE 54 | FORCE: 55 | -------------------------------------------------------------------------------- /app/user/device_config.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: device_config.h 3 | * Author:Chongguang Li 4 | * Versions:1.0 5 | * Description: user should add the follow user parameter here: 6 | * 1.PANDO_PRODUCT_KEY. 7 | * History: 8 | * 1.Date: 9 | * Author: 10 | * Modification: 11 | *********************************************************/ 12 | #ifndef __DEVICE_CONFIG_H__ 13 | #define __DEVICE_CONFIG_H__ 14 | 15 | #define PANDO_PRODUCT_KEY "8a98eca69be08eb9007bd165c305b043f29be91a6d34404209a2d98bbeb962ab" 16 | 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /app/user/objects/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # Required variables for each makefile 3 | # Discard this section from all parent makefiles 4 | # Expected variables (with automatic defaults): 5 | # CSRCS (all "C" files in the dir) 6 | # SUBDIRS (all subdirs with a Makefile) 7 | # GEN_LIBS - list of libs to be generated () 8 | # GEN_IMAGES - list of object file images to be generated () 9 | # GEN_BINS - list of binaries 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 | 15 | ############################################################# 16 | # Configuration i.e. compile options etc. 17 | # Target specific stuff (defines etc.) goes in here! 18 | # Generally values applying to a tree are captured in the 19 | # makefile at its root level - these are then overridden 20 | # for a subtree within the makefile rooted therein 21 | # 22 | 23 | #UNIVERSAL_TARGET_DEFINES = \ 24 | 25 | ifndef PDIR 26 | GEN_LIBS = libobjects.a 27 | endif 28 | 29 | # Other potential configuration flags include: 30 | # -DTXRX_TXBUF_DEBUG 31 | # -DTXRX_RXBUF_DEBUG 32 | # -DWLAN_CONFIG_CCX 33 | 34 | 35 | ############################################################# 36 | # Recursion Magic - Don't touch this!! 37 | # 38 | # Each subtree potentially has an include directory 39 | # corresponding to the common APIs applicable to modules 40 | # rooted at that subtree. Accordingly, the INCLUDE PATH 41 | # of a module can only contain the include directories up 42 | # its parent path, and not its siblings 43 | # 44 | # Required for each makefile to inherit from the parent 45 | # 46 | 47 | INCLUDES := $(INCLUDES) -I $(PDIR)include 48 | PDIR := ../$(PDIR) 49 | sinclude $(PDIR)Makefile 50 | 51 | .PHONY: FORCE 52 | FORCE: 53 | 54 | -------------------------------------------------------------------------------- /app/user/objects/air.c: -------------------------------------------------------------------------------- 1 | #include "../../pando/pando_object.h" 2 | #include "c_types.h" 3 | #include "user_interface.h" 4 | #include "air.h" 5 | #include "../../peripheral/peri_iaq.h" 6 | // add your own includes below 7 | 8 | #define AIR_OBJECT_NO 1 9 | struct air { 10 | uint16 quality; 11 | }; 12 | void ICACHE_FLASH_ATTR 13 | air_init() { 14 | // TODO: add your object init code here. 15 | peri_iaq_init(); 16 | 17 | } 18 | void ICACHE_FLASH_ATTR 19 | air_set(struct air* value) { 20 | // TODO: implement object set function here. 21 | // the set function read value and operate the hardware. 22 | 23 | 24 | } 25 | void ICACHE_FLASH_ATTR 26 | air_get(struct air* value) { 27 | // TODO: implement object get function here 28 | // get function retrieve hardware status and assign it to value. 29 | value->quality=peri_iaq_read(); 30 | //PRINTF("Air Quality: %d\n",value->quality); 31 | 32 | } 33 | /* 34 | auto generated code below!! 35 | DO NOT edit unless you know how it works. 36 | */ 37 | struct air* ICACHE_FLASH_ATTR 38 | create_air() { 39 | struct air* air = (struct air*)os_malloc(sizeof(air)); 40 | return air; 41 | } 42 | void ICACHE_FLASH_ATTR 43 | delete_air(struct air* air) { 44 | if(air){ 45 | os_free(air); 46 | } 47 | } 48 | void ICACHE_FLASH_ATTR 49 | air_object_pack(PARAMS * params) { 50 | if(NULL == params){ 51 | PRINTF("Create first tlv param failed.\n"); 52 | return; 53 | } 54 | 55 | struct air* air = create_air(); 56 | air_get(air); 57 | 58 | if (add_next_uint16(params, air->quality)){ 59 | PRINTF("Add next param failed.\n"); 60 | return; 61 | } 62 | 63 | delete_air(air); 64 | } 65 | void ICACHE_FLASH_ATTR 66 | air_object_unpack(PARAMS* params) { 67 | struct air* air = create_air(); 68 | 69 | air->quality = get_next_uint16(params); 70 | 71 | air_set(air); 72 | delete_air(air); 73 | } 74 | void ICACHE_FLASH_ATTR 75 | air_object_init() { 76 | air_init(); 77 | pando_object air_object = { 78 | 1, 79 | air_object_pack, 80 | air_object_unpack, 81 | }; 82 | register_pando_object(air_object); 83 | } 84 | -------------------------------------------------------------------------------- /app/user/objects/air.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_air_H_ 2 | #define OBJECTS_air_H_ 3 | 4 | void air_object_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /app/user/objects/humiture.c: -------------------------------------------------------------------------------- 1 | #include "../../peripheral/peri_dht1122.h" 2 | #include "../../pando/pando_object.h" 3 | #include "c_types.h" 4 | #include "user_interface.h" 5 | #include "humiture.h" 6 | // add your own includes below 7 | #define HUMITURE_OBJECT_NO 1 8 | 9 | struct humiture { 10 | float32 percent; 11 | }; 12 | void ICACHE_FLASH_ATTR 13 | humiture_init() { 14 | // TODO: add your object init code here. 15 | DHT_Sensor dht_sensor; 16 | dht_sensor.pin = 12; 17 | dht_sensor.type = DHT11; 18 | peri_dht_init(&dht_sensor); 19 | 20 | } 21 | void ICACHE_FLASH_ATTR 22 | humiture_set(struct humiture* value) { 23 | // TODO: implement object set function here. 24 | // the set function read value and operate the hardware. 25 | 26 | 27 | } 28 | void ICACHE_FLASH_ATTR 29 | humiture_get(struct humiture* value) { 30 | // TODO: implement object get function here 31 | // get function retrieve hardware status and assign it to value. 32 | DHT_Sensor_Data output; 33 | peri_dht_read(&output); 34 | value->percent = output.humidity; 35 | 36 | } 37 | /* 38 | auto generated code below!! 39 | DO NOT edit unless you know how it works. 40 | */ 41 | struct humiture* ICACHE_FLASH_ATTR 42 | create_humiture() { 43 | struct humiture* humiture = (struct humiture*)os_malloc(sizeof(humiture)); 44 | return humiture; 45 | } 46 | void ICACHE_FLASH_ATTR 47 | delete_humiture(struct humiture* humiture) { 48 | if(humiture){ 49 | os_free(humiture); 50 | } 51 | } 52 | void ICACHE_FLASH_ATTR 53 | humiture_object_pack(PARAMS * params) { 54 | if(NULL == params){ 55 | PRINTF("Create first tlv param failed.\n"); 56 | return; 57 | } 58 | 59 | struct humiture* humiture = create_humiture(); 60 | humiture_get(humiture); 61 | 62 | if (add_next_float32(params, humiture->percent)){ 63 | PRINTF("Add next param failed.\n"); 64 | return; 65 | } 66 | 67 | delete_humiture(humiture); 68 | } 69 | void ICACHE_FLASH_ATTR 70 | humiture_object_unpack(PARAMS* params) { 71 | struct humiture* humiture = create_humiture(); 72 | 73 | humiture->percent = get_next_float32(params); 74 | 75 | humiture_set(humiture); 76 | delete_humiture(humiture); 77 | } 78 | void ICACHE_FLASH_ATTR 79 | humiture_object_init() { 80 | humiture_init(); 81 | pando_object humiture_object = { 82 | 3, 83 | humiture_object_pack, 84 | humiture_object_unpack, 85 | }; 86 | register_pando_object(humiture_object); 87 | } 88 | -------------------------------------------------------------------------------- /app/user/objects/humiture.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_HUMITURE_H_ 2 | #define OBJECTS_HUMITURE_H_ 3 | 4 | void humiture_object_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /app/user/objects/led.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: led.c 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description: the led object 6 | * History: 7 | * 1.Date: Sep 15, 2015 8 | * Author: razr 9 | * Modification: 10 | *********************************************************/ 11 | #include "../../pando/pando_object.h" 12 | #include "c_types.h" 13 | #include "user_interface.h" 14 | #include "../../peripheral/peri_rgb_light.h" 15 | 16 | struct led { 17 | uint8 red; 18 | uint8 green; 19 | uint8 blue; 20 | }; 21 | 22 | void ICACHE_FLASH_ATTR 23 | led_init() 24 | { 25 | struct PWM_APP_PARAM light_param; 26 | struct PWM_INIT light_init; 27 | light_param.pwm_freq=25000; 28 | light_param.pwm_duty[0]=255; 29 | light_param.pwm_duty[1]=255; 30 | light_param.pwm_duty[2]=255; 31 | 32 | light_init.io_num=3; 33 | light_init.io_id[0]=13; 34 | light_init.io_id[1]=14; 35 | light_init.io_id[2]=15; 36 | 37 | peri_rgb_light_init(light_param,light_init); 38 | } 39 | 40 | void ICACHE_FLASH_ATTR 41 | led_set(struct led* value) 42 | { 43 | struct PWM_APP_PARAM light_value; 44 | light_value.pwm_freq=25000; 45 | light_value.pwm_duty[0] = 255-(value->blue); 46 | light_value.pwm_duty[1] = 255-(value->red); 47 | light_value.pwm_duty[2] = 255-(value->green); 48 | peri_rgb_light_param_set(light_value); 49 | 50 | // PRINTF("pwm_freq: %d, pwm_duty_blue: %d, pwm_duty_red: %d, pwm_duty_green: %d\n", light_value.pwm_freq, 51 | // (light_value.pwm_duty)[0], (light_value.pwm_duty)[1], (light_value.pwm_duty)[2]); 52 | } 53 | 54 | void ICACHE_FLASH_ATTR 55 | led_get(struct led* value) 56 | { 57 | struct PWM_APP_PARAM light_value; 58 | light_value = peri_rgb_light_param_get(); 59 | value->red = 255 -light_value.pwm_duty[0]; 60 | value->green =255 - light_value.pwm_duty[1]; 61 | value->blue = 255 -light_value.pwm_duty[2]; 62 | } 63 | 64 | 65 | struct led* ICACHE_FLASH_ATTR 66 | create_led() 67 | { 68 | struct led* led = (struct led*)os_malloc(sizeof(led)); 69 | return led; 70 | } 71 | 72 | void ICACHE_FLASH_ATTR 73 | delete_led(struct led* led) 74 | { 75 | if(led) 76 | { 77 | os_free(led); 78 | } 79 | } 80 | 81 | void ICACHE_FLASH_ATTR 82 | led_object_pack(PARAMS * params) 83 | { 84 | if(NULL == params) 85 | { 86 | PRINTF("Create first tlv param failed.\n"); 87 | return; 88 | } 89 | 90 | struct led* led = create_led(); 91 | led_get(led); 92 | 93 | if (add_next_uint8(params, led->red)) 94 | { 95 | PRINTF("Add next tlv param failed.\n"); 96 | return; 97 | } 98 | 99 | if (add_next_uint8(params, led->green)) 100 | { 101 | PRINTF("Add next tlv param failed.\n"); 102 | return; 103 | } 104 | 105 | if (add_next_uint8(params, led->blue)) 106 | { 107 | PRINTF("Add next tlv param failed.\n"); 108 | return; 109 | } 110 | 111 | delete_led(led); 112 | } 113 | 114 | void ICACHE_FLASH_ATTR 115 | led_object_unpack(PARAMS* params) 116 | { 117 | struct led* led = create_led(); 118 | 119 | led->red = get_next_uint8(params); 120 | led->green = get_next_uint8(params); 121 | led->blue = get_next_uint8(params); 122 | 123 | led_set(led); 124 | 125 | delete_led(led); 126 | 127 | } 128 | 129 | void ICACHE_FLASH_ATTR 130 | led_object_init() 131 | { 132 | // init here... 133 | led_init(); 134 | 135 | // register the object 136 | pando_object led_object = { 137 | 1, 138 | led_object_pack, 139 | led_object_unpack, 140 | }; 141 | register_pando_object(led_object); 142 | } 143 | -------------------------------------------------------------------------------- /app/user/objects/led.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: led.h 3 | * Author: razr 4 | * Versions: 1.0 5 | * Description: 6 | * History: 7 | * 1.Date: Sep 15, 2015 8 | * Author: razr 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef OBJECTS_LED_H_ 13 | #define OBJECTS_LED_H_ 14 | 15 | void led_object_init(); 16 | 17 | #endif /* APP_USER_OBJECTS_LED_H_ */ 18 | -------------------------------------------------------------------------------- /app/user/objects/motor.c: -------------------------------------------------------------------------------- 1 | #include "../../pando/pando_object.h" 2 | #include "../../peripheral/peri_motor.h" 3 | #include "c_types.h" 4 | #include "user_interface.h" 5 | #include "motor.h" 6 | // add your own includes below 7 | 8 | 9 | struct motor { 10 | int8 speed; 11 | }; 12 | void ICACHE_FLASH_ATTR 13 | motor_init() { 14 | // TODO: add your object init code here. 15 | struct PWM_APP_PARAM motor_param; 16 | struct PWM_INIT motor_init; 17 | motor_param.pwm_freq=25000; 18 | motor_param.pwm_duty[0]=0; 19 | motor_param.pwm_duty[1]=0; 20 | 21 | motor_init.io_num=2; 22 | motor_init.io_id[0]=12; 23 | motor_init.io_id[1]=13; 24 | 25 | peri_motor_init(motor_param,motor_init); 26 | 27 | } 28 | void ICACHE_FLASH_ATTR 29 | motor_set(struct motor* value) { 30 | // TODO: implement object set function here. 31 | // the set function read value and operate the hardware. 32 | struct PWM_APP_PARAM motor_param; 33 | motor_param.pwm_freq=25000; 34 | if((value->speed)>=0) //forward 35 | { 36 | motor_param.pwm_duty[0]=value->speed; 37 | motor_param.pwm_duty[1]=0; 38 | 39 | } 40 | else 41 | { 42 | motor_param.pwm_duty[0]=0; 43 | motor_param.pwm_duty[1]=0-(value->speed); 44 | 45 | } 46 | 47 | peri_motor_set(motor_param); 48 | 49 | } 50 | void ICACHE_FLASH_ATTR 51 | motor_get(struct motor* value) { 52 | // TODO: implement object get function here 53 | // get function retrieve hardware status and assign it to value. 54 | struct PWM_APP_PARAM motor_param; 55 | motor_param=peri_motor_get(); 56 | if(motor_param.pwm_duty[0]==0) 57 | { 58 | value->speed=0-(motor_param.pwm_duty[1]); 59 | } 60 | if(motor_param.pwm_duty[1]==0) 61 | { 62 | value->speed=(motor_param.pwm_duty[0]); 63 | } 64 | 65 | } 66 | /* 67 | auto generated code below!! 68 | DO NOT edit unless you know how it works. 69 | */ 70 | struct motor* ICACHE_FLASH_ATTR 71 | create_motor() { 72 | struct motor* motor = (struct motor*)os_malloc(sizeof(motor)); 73 | return motor; 74 | } 75 | void ICACHE_FLASH_ATTR 76 | delete_motor(struct motor* motor) { 77 | if(motor){ 78 | os_free(motor); 79 | } 80 | } 81 | void ICACHE_FLASH_ATTR 82 | motor_object_pack(PARAMS * params) { 83 | if(NULL == params){ 84 | PRINTF("Create first tlv param failed.\n"); 85 | return; 86 | } 87 | 88 | struct motor* motor = create_motor(); 89 | motor_get(motor); 90 | 91 | if (add_next_int8(params, motor->speed)){ 92 | PRINTF("Add next param failed.\n"); 93 | return; 94 | } 95 | 96 | delete_motor(motor); 97 | } 98 | void ICACHE_FLASH_ATTR 99 | motor_object_unpack(PARAMS* params) { 100 | struct motor* motor = create_motor(); 101 | 102 | motor->speed = get_next_int8(params); 103 | 104 | motor_set(motor); 105 | delete_motor(motor); 106 | } 107 | void ICACHE_FLASH_ATTR 108 | motor_object_init() { 109 | motor_init(); 110 | pando_object motor_object = { 111 | 1, 112 | motor_object_pack, 113 | motor_object_unpack, 114 | }; 115 | register_pando_object(motor_object); 116 | } 117 | -------------------------------------------------------------------------------- /app/user/objects/motor.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_motor_H_ 2 | #define OBJECTS_motor_H_ 3 | 4 | void motor_object_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /app/user/objects/plug.c: -------------------------------------------------------------------------------- 1 | #include "../../pando/pando_object.h" 2 | #include "../../peripheral/peri_jdq.h" 3 | #include "c_types.h" 4 | #include "user_interface.h" 5 | #include "plug.h" 6 | // add your own includes below 7 | #define PLUG_OBJECT_NO 1 8 | 9 | struct plug { 10 | uint8 off_on; 11 | }; 12 | void ICACHE_FLASH_ATTR 13 | plug_init() { 14 | // TODO: add your object init code here. 15 | peri_jdq_init(12); 16 | 17 | } 18 | void ICACHE_FLASH_ATTR 19 | plug_set(struct plug* value) { 20 | // TODO: implement object set function here. 21 | // the set function read value and operate the hardware. 22 | peri_jdq_set(value->off_on); 23 | 24 | } 25 | void ICACHE_FLASH_ATTR 26 | plug_get(struct plug* value) { 27 | // TODO: implement object get function here 28 | // get function retrieve hardware status and assign it to value. 29 | value->off_on=peri_jdq_get(); 30 | } 31 | /* 32 | auto generated code below!! 33 | DO NOT edit unless you know how it works. 34 | */ 35 | struct plug* ICACHE_FLASH_ATTR 36 | create_plug() { 37 | struct plug* plug = (struct plug*)os_malloc(sizeof(plug)); 38 | return plug; 39 | } 40 | void ICACHE_FLASH_ATTR 41 | delete_plug(struct plug* plug) { 42 | if(plug){ 43 | os_free(plug); 44 | } 45 | } 46 | void ICACHE_FLASH_ATTR 47 | plug_object_pack(PARAMS * params) { 48 | if(NULL == params){ 49 | PRINTF("Create first tlv param failed.\n"); 50 | return; 51 | } 52 | 53 | struct plug* plug = create_plug(); 54 | plug_get(plug); 55 | 56 | if (add_next_uint8(params, plug->off_on)){ 57 | PRINTF("Add next param failed.\n"); 58 | return; 59 | } 60 | 61 | delete_plug(plug); 62 | } 63 | void ICACHE_FLASH_ATTR 64 | plug_object_unpack(PARAMS* params) { 65 | struct plug* plug = create_plug(); 66 | 67 | plug->off_on = get_next_uint8(params); 68 | 69 | plug_set(plug); 70 | delete_plug(plug); 71 | } 72 | void ICACHE_FLASH_ATTR 73 | plug_object_init() { 74 | plug_init(); 75 | pando_object plug_object = { 76 | 1, 77 | plug_object_pack, 78 | plug_object_unpack, 79 | }; 80 | register_pando_object(plug_object); 81 | } 82 | -------------------------------------------------------------------------------- /app/user/objects/plug.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_PLUG_H_ 2 | #define OBJECTS_PLUG_H_ 3 | 4 | void plug_object_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /app/user/objects/pm25.c: -------------------------------------------------------------------------------- 1 | #include "../../pando/pando_object.h" 2 | #include "../../peripheral/peri_pm25.h" 3 | #include "../../peripheral/driver/uart.h" 4 | #include "c_types.h" 5 | #include "user_interface.h" 6 | #include "pm25.h" 7 | 8 | // add your own includes below 9 | #define PM25_OBJECT_NO 1 10 | 11 | struct pm25 { 12 | uint16 quality; 13 | }; 14 | void ICACHE_FLASH_ATTR 15 | pm25_init() { 16 | // TODO: add your object init code here. 17 | 18 | 19 | } 20 | void ICACHE_FLASH_ATTR 21 | pm25_set(struct pm25* value) { 22 | // TODO: implement object set function here. 23 | // the set function read value and operate the hardware. 24 | 25 | 26 | } 27 | void ICACHE_FLASH_ATTR 28 | pm25_get(struct pm25* value) { 29 | // TODO: implement object get function here 30 | // get function retrieve hardware status and assign it to value. 31 | static os_timer_t read_timer; 32 | uart_rx_intr_enable(UART0); 33 | 34 | os_timer_disarm(&read_timer); 35 | os_timer_setfn(&read_timer, (os_timer_func_t *)peri_pm_25_get,NULL); 36 | os_timer_arm(&read_timer, 1000, 0); 37 | 38 | value->quality=peri_pm_25_get(); 39 | //PRINTF("PM25_VALUE:%d \n",value->quality); 40 | } 41 | /* 42 | auto generated code below!! 43 | DO NOT edit unless you know how it works. 44 | */ 45 | struct pm25* ICACHE_FLASH_ATTR 46 | create_pm25() { 47 | struct pm25* pm25 = (struct pm25*)os_malloc(sizeof(pm25)); 48 | return pm25; 49 | } 50 | void ICACHE_FLASH_ATTR 51 | delete_pm25(struct pm25* pm25) { 52 | if(pm25){ 53 | os_free(pm25); 54 | } 55 | } 56 | void ICACHE_FLASH_ATTR 57 | pm25_object_pack(PARAMS * params) { 58 | if(NULL == params){ 59 | PRINTF("Create first tlv param failed.\n"); 60 | return; 61 | } 62 | 63 | struct pm25* pm25 = create_pm25(); 64 | pm25_get(pm25); 65 | 66 | if (add_next_uint16(params, pm25->quality)){ 67 | PRINTF("Add next param failed.\n"); 68 | return; 69 | } 70 | 71 | delete_pm25(pm25); 72 | } 73 | void ICACHE_FLASH_ATTR 74 | pm25_object_unpack(PARAMS* params) { 75 | struct pm25* pm25 = create_pm25(); 76 | 77 | pm25->quality = get_next_uint16(params); 78 | 79 | pm25_set(pm25); 80 | delete_pm25(pm25); 81 | } 82 | void ICACHE_FLASH_ATTR 83 | pm25_object_init() { 84 | pm25_init(); 85 | pando_object pm25_object = { 86 | 1, 87 | pm25_object_pack, 88 | pm25_object_unpack, 89 | }; 90 | register_pando_object(pm25_object); 91 | } 92 | -------------------------------------------------------------------------------- /app/user/objects/pm25.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_pm25_H_ 2 | #define OBJECTS_pm25_H_ 3 | 4 | void pm25_object_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /app/user/objects/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/user/objects/readme.txt -------------------------------------------------------------------------------- /app/user/objects/temperature.c: -------------------------------------------------------------------------------- 1 | #include "../../peripheral/peri_dht1122.h" 2 | #include "../../pando/pando_object.h" 3 | #include "c_types.h" 4 | #include "user_interface.h" 5 | #include "temperature.h" 6 | // add your own includes below 7 | #define TEMPERATURE_OBJECT_NO 1 8 | 9 | struct temperature { 10 | float32 centigrade; 11 | }; 12 | void ICACHE_FLASH_ATTR 13 | temperature_init() { 14 | // TODO: add your object init code here. 15 | 16 | DHT_Sensor dht_sensor; 17 | dht_sensor.pin = 12; 18 | dht_sensor.type = DHT11; 19 | peri_dht_init(&dht_sensor); 20 | } 21 | void ICACHE_FLASH_ATTR 22 | temperature_set(struct temperature* value) { 23 | // TODO: implement object set function here. 24 | // the set function read value and operate the hardware. 25 | 26 | 27 | } 28 | void ICACHE_FLASH_ATTR 29 | temperature_get(struct temperature* value) { 30 | // TODO: implement object get function here 31 | // get function retrieve hardware status and assign it to value. 32 | 33 | DHT_Sensor_Data output; 34 | peri_dht_read(&output); 35 | value->centigrade = output.temperature; 36 | PRINTF("\ncentigrade:%d\n", (int)(value->centigrade*100)); 37 | } 38 | /* 39 | auto generated code below!! 40 | DO NOT edit unless you know how it works. 41 | */ 42 | struct temperature* ICACHE_FLASH_ATTR 43 | create_temperature() { 44 | struct temperature* temperature = (struct temperature*)os_malloc(sizeof(temperature)); 45 | return temperature; 46 | } 47 | void ICACHE_FLASH_ATTR 48 | delete_temperature(struct temperature* temperature) { 49 | if(temperature){ 50 | os_free(temperature); 51 | } 52 | } 53 | void ICACHE_FLASH_ATTR 54 | temperature_object_pack(PARAMS * params) { 55 | if(NULL == params){ 56 | PRINTF("Create first tlv param failed.\n"); 57 | return; 58 | } 59 | 60 | struct temperature* temperature = create_temperature(); 61 | temperature_get(temperature); 62 | 63 | if (add_next_float32(params, temperature->centigrade)){ 64 | PRINTF("Add next param failed.\n"); 65 | return; 66 | } 67 | 68 | delete_temperature(temperature); 69 | } 70 | void ICACHE_FLASH_ATTR 71 | temperature_object_unpack(PARAMS* params) { 72 | struct temperature* temperature = create_temperature(); 73 | 74 | temperature->centigrade = get_next_float32(params); 75 | 76 | temperature_set(temperature); 77 | delete_temperature(temperature); 78 | } 79 | void ICACHE_FLASH_ATTR 80 | temperature_object_init() { 81 | temperature_init(); 82 | pando_object temperature_object = { 83 | 2, 84 | temperature_object_pack, 85 | temperature_object_unpack, 86 | }; 87 | register_pando_object(temperature_object); 88 | } 89 | -------------------------------------------------------------------------------- /app/user/objects/temperature.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECTS_temperature_H_ 2 | #define OBJECTS_temperature_H_ 3 | 4 | void temperature_object_init(); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /app/user/objects/usart_gpu.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/user/objects/usart_gpu.c -------------------------------------------------------------------------------- /app/user/objects/usart_gpu.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/user/objects/usart_gpu.h -------------------------------------------------------------------------------- /app/user/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/user/readme.txt -------------------------------------------------------------------------------- /app/user/user_main.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | /******************************************************* 3 | * File name: user_main.c 4 | * Author:Chongguang Li 5 | * Versions:1.0 6 | * Description:entry file of user application. 7 | * 8 | * History: 9 | * 1.Date: 10 | * Author: 11 | * Modification: 12 | *******************************************************************************/ 13 | 14 | #include "../peripheral/driver/uart.h" 15 | #include "objects/led.h" 16 | #include "os_type.h" 17 | #include "user_interface.h" 18 | #include "../peripheral/peri_key.h" 19 | #include "wifi_config.h" 20 | #include "../pando/pando_framework.h" 21 | #include "objects/usart_gpu.h" 22 | #include "objects/humiture.h" 23 | #include "objects/temperature.h" 24 | 25 | static void ICACHE_FLASH_ATTR 26 | user_key_long_press_cb() 27 | { 28 | wifi_config(NULL); 29 | } 30 | 31 | /****************************************************************************** 32 | * FunctionName : user_init 33 | * Description : entry of user application, init user function here 34 | * Parameters : none 35 | * Returns : none 36 | *******************************************************************************/ 37 | void user_init(void) 38 | { 39 | uart_init(115200, 115200); // serial bound rate:11520. 40 | 41 | //long press gpio4, enter into wifi config mode. 42 | peri_single_key_init(4, user_key_long_press_cb, NULL); 43 | 44 | // add you object init here. 45 | //led_object_init(); 46 | usart_gpu_object_init(); 47 | temperature_object_init(); 48 | humiture_object_init(); 49 | 50 | pando_framework_init(); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /app/user/wifi_config.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: wifi_config.h 3 | * Author:Chongguang Li 4 | * Versions:1.0 5 | * Description: this module is used to config the wifi ssid and password. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | #ifndef __WIFI_CONFIG_H__ 12 | #define __WIFI_CONFIG_H__ 13 | 14 | typedef enum { 15 | CONFIG_TIMEOUT = -1, 16 | CONFIG_OK 17 | } CONFIG_RESULT; 18 | 19 | 20 | /* 21 | callback function after config. 22 | */ 23 | typedef void (* wifi_config_callback)(CONFIG_RESULT result); 24 | 25 | 26 | /****************************************************************************** 27 | * FunctionName : get_wifi_config_state 28 | * Description : get the wifi config state. 29 | * Parameters : none. 30 | * Returns : 1: the device is in wifi config state. 31 | * 0: the device is not in wifi config state. 32 | *******************************************************************************/ 33 | bool get_wifi_config_state(); 34 | 35 | /****************************************************************************** 36 | * FunctionName : wifi_config 37 | * Description : configure the gateway wifi SSID and password. 38 | * Parameters : config_cb: the call back function after config, can be NULL. 39 | * Returns : none 40 | *******************************************************************************/ 41 | void wifi_config(wifi_config_callback config_cb); 42 | 43 | void auto_check_connect_init(void); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /app/util/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################# 2 | # Required variables for each makefile 3 | # Discard this section from all parent makefiles 4 | # Expected variables (with automatic defaults): 5 | # CSRCS (all "C" files in the dir) 6 | # SUBDIRS (all subdirs with a Makefile) 7 | # GEN_LIBS - list of libs to be generated () 8 | # GEN_IMAGES - list of object file images to be generated () 9 | # GEN_BINS - list of binaries 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 | 15 | ############################################################# 16 | # Configuration i.e. compile options etc. 17 | # Target specific stuff (defines etc.) goes in here! 18 | # Generally values applying to a tree are captured in the 19 | # makefile at its root level - these are then overridden 20 | # for a subtree within the makefile rooted therein 21 | # 22 | 23 | #UNIVERSAL_TARGET_DEFINES = \ 24 | 25 | ifndef PDIR 26 | GEN_LIBS = libutil.a 27 | endif 28 | 29 | # Other potential configuration flags include: 30 | # -DTXRX_TXBUF_DEBUG 31 | # -DTXRX_RXBUF_DEBUG 32 | # -DWLAN_CONFIG_CCX 33 | 34 | ############################################################# 35 | # Recursion Magic - Don't touch this!! 36 | # 37 | # Each subtree potentially has an include directory 38 | # corresponding to the common APIs applicable to modules 39 | # rooted at that subtree. Accordingly, the INCLUDE PATH 40 | # of a module can only contain the include directories up 41 | # its parent path, and not its siblings 42 | # 43 | # Required for each makefile to inherit from the parent 44 | # 45 | 46 | INCLUDES := $(INCLUDES) -I $(PDIR)include 47 | PDIR := ../$(PDIR) 48 | sinclude $(PDIR)Makefile 49 | 50 | .PHONY: FORCE 51 | FORCE: 52 | 53 | -------------------------------------------------------------------------------- /app/util/cert.h: -------------------------------------------------------------------------------- 1 | unsigned char default_certificate[] = { 2 | 0x30, 0x82, 0x01, 0x4d, 0x30, 0x81, 0xf8, 0x02, 0x09, 0x00, 0xba, 0x06, 3 | 0x02, 0x36, 0x28, 0x44, 0xd4, 0x58, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 4 | 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x32, 0x31, 5 | 0x30, 0x30, 0x2e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x27, 0x54, 0x4c, 6 | 0x53, 0x20, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x44, 0x6f, 7 | 0x64, 0x67, 0x79, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 8 | 0x61, 0x74, 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 9 | 0x79, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x35, 0x30, 0x33, 0x33, 0x31, 0x30, 10 | 0x36, 0x32, 0x30, 0x34, 0x32, 0x5a, 0x17, 0x0d, 0x32, 0x38, 0x31, 0x32, 11 | 0x30, 0x37, 0x30, 0x36, 0x32, 0x30, 0x34, 0x32, 0x5a, 0x30, 0x2a, 0x31, 12 | 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0b, 0x54, 0x4c, 13 | 0x53, 0x20, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x31, 0x12, 0x30, 14 | 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x09, 0x31, 0x32, 0x37, 0x2e, 15 | 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 16 | 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 17 | 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, 0xa3, 0x5a, 0x69, 0x68, 0xaf, 0xff, 18 | 0x07, 0x27, 0x46, 0x26, 0x3c, 0xe7, 0x66, 0x90, 0x15, 0x24, 0x8d, 0x2e, 19 | 0x40, 0x22, 0x0d, 0xa5, 0x89, 0x03, 0xd0, 0xc6, 0x5e, 0x45, 0xf5, 0x03, 20 | 0x9b, 0x41, 0x2e, 0xce, 0x95, 0x29, 0x2d, 0x3b, 0x77, 0x92, 0x1b, 0xd8, 21 | 0xf8, 0x73, 0xfd, 0xa9, 0xde, 0xac, 0xee, 0x49, 0x14, 0x3b, 0x2c, 0xd9, 22 | 0x4c, 0x82, 0xad, 0xae, 0x2d, 0xe2, 0x3d, 0xc4, 0xbc, 0xef, 0x02, 0x03, 23 | 0x01, 0x00, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 24 | 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, 0x00, 0x47, 0x53, 0xd3, 25 | 0x8a, 0x21, 0x0d, 0x2f, 0x75, 0xd1, 0x11, 0xbe, 0x42, 0x24, 0xe1, 0x97, 26 | 0xfa, 0xe4, 0xf8, 0x90, 0xa1, 0xe9, 0xb1, 0x2c, 0xe1, 0xc6, 0x4c, 0x3d, 27 | 0x0b, 0x54, 0xe3, 0x4f, 0x79, 0x93, 0x5a, 0x69, 0x91, 0x37, 0x7b, 0x9d, 28 | 0x29, 0x1a, 0x0d, 0x96, 0x86, 0x2f, 0x76, 0xf2, 0xe3, 0xab, 0x27, 0x86, 29 | 0xdc, 0xf5, 0x95, 0x54, 0xe2, 0x3b, 0xc0, 0x8e, 0x1b, 0x2f, 0xc3, 0xc5, 30 | 0xdf 31 | }; 32 | unsigned int default_certificate_len = 337; 33 | -------------------------------------------------------------------------------- /app/util/converter.c: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: converter.c 3 | * Author:Chongguang Li 4 | * Versions:1.0 5 | * Description:This module is to used to covert the data coding. 6 | * History: 7 | * 1.Date: 8 | * Author: 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #include "converter.h" 13 | #include "user_interface.h" 14 | 15 | /****************************************************************************** 16 | * FunctionName : char2bin. 17 | * Description : convert char to bin. 18 | * Parameters : dst -- 19 | * hex_str -- 20 | * Returns : none. 21 | *******************************************************************************/ 22 | static uint8_t ICACHE_FLASH_ATTR 23 | char2bin(char a) 24 | { 25 | uint8_t n; 26 | if(a>='0'&&a<='9') 27 | { 28 | n=a-'0'; 29 | } 30 | else 31 | { 32 | n=a-'a'+10; 33 | } 34 | return n; 35 | } 36 | 37 | /****************************************************************************** 38 | * FunctionName : hex2bin. 39 | * Description : convert string to bin. 40 | * Parameters : dst -- 41 | * hex_str -- 42 | * Returns : none. 43 | *******************************************************************************/ 44 | void ICACHE_FLASH_ATTR 45 | hex2bin(uint8 * dst, char * hex_str) 46 | { 47 | char * p = NULL; 48 | int i=0; 49 | for(p=hex_str; *p; p=p+2) 50 | { 51 | dst[i++] = ((char2bin(*p)) << 4) | (char2bin(*(p+1))); 52 | } 53 | } 54 | 55 | const char* ICACHE_FLASH_ATTR 56 | u32_to_str(unsigned int val) 57 | { 58 | /* Maximum number of decimal digits in u32 is 10 */ 59 | static char num_str[11]; 60 | int pos = 10; 61 | num_str[10] = 0; 62 | 63 | if (val == 0) { 64 | /* If already zero then just return zero */ 65 | return "0"; 66 | } 67 | 68 | while ((val != 0) && (pos > 0)) { 69 | num_str[--pos] = (val % 10) + '0'; 70 | val /= 10; 71 | } 72 | 73 | return &num_str[pos]; 74 | } 75 | -------------------------------------------------------------------------------- /app/util/converter.h: -------------------------------------------------------------------------------- 1 | #ifndef __CONVERTER_H__ 2 | #define __CONVERTER_H__ 3 | 4 | #include "c_types.h" 5 | 6 | /****************************************************************************** 7 | * FunctionName : hex2bin. 8 | * Description : convert. string to bin. 9 | * Parameters : dst -- 10 | * hex_str -- 11 | * Returns : none. 12 | *******************************************************************************/ 13 | 14 | void hex2bin(uint8 * dst, char * hex_str); 15 | 16 | const char *u32_to_str(unsigned int val); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /app/util/httpclient.h: -------------------------------------------------------------------------------- 1 | #ifndef HTTPCLIENT_H 2 | #define HTTPCLIENT_H 3 | 4 | #define BUFFER_SIZE_MAX 5000 5 | 6 | /* 7 | * "full_response" is a string containing all response headers and the response body. 8 | * "response_body and "http_status" are extracted from "full_response" for convenience. 9 | * 10 | * A successful request corresponds to an HTTP status code of 200 (OK). 11 | * More info at http://en.wikipedia.org/wiki/List_of_HTTP_status_codes 12 | */ 13 | typedef void (* http_callback)(char * response_body, int http_status, char * full_response); 14 | 15 | /* 16 | * Download a web page from its URL. 17 | * Try: 18 | * http_get("http://wtfismyip.com/text", http_callback_example); 19 | */ 20 | void http_get(const char * url, http_callback user_callback); 21 | 22 | /* 23 | * Post data to a web form. 24 | * The data should be encoded as application/x-www-form-urlencoded. 25 | * Try: 26 | * http_post("http://httpbin.org/post", "first_word=hello&second_word=world", http_callback_example); 27 | */ 28 | void http_post(const char * url, const char * post_data, http_callback user_callback); 29 | 30 | /* 31 | * Call this function to skip URL parsing if the arguments are already in separate variables. 32 | */ 33 | void http_raw_request(const char * hostname, int port, const char * path, const char * post_data, http_callback user_callback); 34 | 35 | /* 36 | * Output on the UART. 37 | */ 38 | void http_callback_example(char * response, int http_status, char * full_response); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /app/util/pando_json.c: -------------------------------------------------------------------------------- 1 | #include "pando_json.h" 2 | 3 | static char *json_buf; 4 | static int json_buf_len; 5 | static int pos; 6 | 7 | static int ICACHE_FLASH_ATTR 8 | json_putchar(int c) 9 | { 10 | if (json_buf != NULL && pos < json_buf_len) 11 | { 12 | json_buf[pos++] = c; 13 | return c; 14 | } 15 | 16 | return 0; 17 | } 18 | 19 | int ICACHE_FLASH_ATTR 20 | pando_json_print(struct jsontree_value * json_value, char * dst, int len) 21 | { 22 | if( dst == NULL) 23 | { 24 | return -1; 25 | } 26 | json_buf = dst; 27 | json_buf_len = len; 28 | pos = 0; 29 | 30 | struct jsontree_context js_ctx; 31 | js_ctx.values[0] = json_value; 32 | jsontree_reset(&js_ctx); 33 | js_ctx.putchar = json_putchar; 34 | 35 | while (jsontree_print_next(&js_ctx)); 36 | 37 | json_buf[pos] = 0; 38 | 39 | return pos; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /app/util/pando_json.h: -------------------------------------------------------------------------------- 1 | /******************************************************* 2 | * File name: pando_json.h 3 | * Author: ruizeng 4 | * Versions: 1.0 5 | * Description:This module has some json handle utils. 6 | * History: 7 | * 1.Date: initial code 8 | * Author: ruizeng 9 | * Modification: 10 | *********************************************************/ 11 | 12 | #ifndef __PANDO_JSON_H 13 | #define __PANDO_JSON_H 14 | 15 | #include "json/jsontree.h" 16 | 17 | /****************************************************************************** 18 | * FunctionName : pando_json_print 19 | * Description : print json value to a "char *" string. 20 | * Parameters : json_value: the json_value struct ptr. 21 | * dst: the string buffer to print to. 22 | * len: the length of the output buffer. 23 | * Returns : return the length printed, -1 if error 24 | *******************************************************************************/ 25 | 26 | int pando_json_print(struct jsontree_value * json_value, char * dst, int len); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /app/util/private_key.h: -------------------------------------------------------------------------------- 1 | unsigned char default_private_key[] = { 2 | 0x30, 0x82, 0x01, 0x3d, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, 0xa3, 0x5a, 3 | 0x69, 0x68, 0xaf, 0xff, 0x07, 0x27, 0x46, 0x26, 0x3c, 0xe7, 0x66, 0x90, 4 | 0x15, 0x24, 0x8d, 0x2e, 0x40, 0x22, 0x0d, 0xa5, 0x89, 0x03, 0xd0, 0xc6, 5 | 0x5e, 0x45, 0xf5, 0x03, 0x9b, 0x41, 0x2e, 0xce, 0x95, 0x29, 0x2d, 0x3b, 6 | 0x77, 0x92, 0x1b, 0xd8, 0xf8, 0x73, 0xfd, 0xa9, 0xde, 0xac, 0xee, 0x49, 7 | 0x14, 0x3b, 0x2c, 0xd9, 0x4c, 0x82, 0xad, 0xae, 0x2d, 0xe2, 0x3d, 0xc4, 8 | 0xbc, 0xef, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x41, 0x00, 0x95, 0x43, 9 | 0xef, 0x5f, 0xee, 0xba, 0x1d, 0xe2, 0x40, 0x52, 0x7e, 0x82, 0x80, 0x10, 10 | 0x96, 0x91, 0x40, 0xc4, 0x8b, 0x6b, 0xd2, 0x86, 0x79, 0x6d, 0xd8, 0x1e, 11 | 0xfb, 0x53, 0xf7, 0x70, 0x25, 0x33, 0x73, 0x8b, 0x73, 0x2b, 0x99, 0xd2, 12 | 0xf7, 0xa9, 0x1f, 0x9d, 0x14, 0x1e, 0x62, 0x7e, 0x0e, 0xb0, 0x84, 0x2a, 13 | 0xd7, 0x1e, 0x0a, 0x3e, 0xe7, 0x28, 0xc7, 0xa1, 0x0c, 0x8d, 0x83, 0xba, 14 | 0x88, 0x91, 0x02, 0x21, 0x00, 0xd7, 0x15, 0x37, 0x3b, 0x29, 0xe7, 0x8f, 15 | 0x5c, 0x8e, 0x70, 0xb6, 0x49, 0xee, 0x9c, 0x8c, 0x02, 0xc4, 0xe0, 0xfc, 16 | 0x88, 0x20, 0xbb, 0x3a, 0xd8, 0x40, 0xb4, 0xd2, 0xfc, 0x34, 0x60, 0xca, 17 | 0xf9, 0x02, 0x21, 0x00, 0xc2, 0x6d, 0xe6, 0x56, 0x06, 0x4f, 0x26, 0xbe, 18 | 0xe8, 0x1f, 0x8a, 0x3a, 0x57, 0xe9, 0x2e, 0xb5, 0xee, 0x59, 0x0f, 0x9a, 19 | 0x73, 0xd7, 0xc8, 0xc7, 0xdc, 0xff, 0x5b, 0x2f, 0xd6, 0x2f, 0x99, 0x27, 20 | 0x02, 0x21, 0x00, 0xa8, 0x1e, 0x9a, 0x44, 0x71, 0xb5, 0xe1, 0xb6, 0x8c, 21 | 0x54, 0x87, 0xf8, 0x74, 0x3e, 0x03, 0xa6, 0xea, 0x73, 0x9e, 0x91, 0x5d, 22 | 0x5c, 0x5c, 0x5b, 0xcb, 0x00, 0x4c, 0xe6, 0xfc, 0x9e, 0x28, 0x29, 0x02, 23 | 0x21, 0x00, 0x90, 0xc8, 0x09, 0xb7, 0x91, 0x67, 0x2b, 0x71, 0x09, 0xa5, 24 | 0x42, 0xe7, 0x83, 0x43, 0x2e, 0xf7, 0x67, 0x0f, 0x86, 0xe0, 0xfa, 0xd6, 25 | 0x7a, 0xba, 0xe9, 0xc4, 0x75, 0x80, 0xbf, 0xbc, 0x1e, 0x0d, 0x02, 0x21, 26 | 0x00, 0xd6, 0x9b, 0x2c, 0x71, 0xdc, 0xf6, 0x82, 0xd9, 0x49, 0xdc, 0x0c, 27 | 0xe6, 0xe2, 0x99, 0x00, 0x49, 0x9d, 0x6c, 0x89, 0xa3, 0x0c, 0x60, 0x1b, 28 | 0xb4, 0x80, 0x36, 0x69, 0xd0, 0x14, 0xab, 0x2b, 0xfc 29 | }; 30 | unsigned int default_private_key_len = 321; 31 | -------------------------------------------------------------------------------- /app/util/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/app/util/readme.txt -------------------------------------------------------------------------------- /bin/blank.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/bin/blank.bin -------------------------------------------------------------------------------- /bin/boot_v1.2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/bin/boot_v1.2.bin -------------------------------------------------------------------------------- /bin/eagle.flash.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/bin/eagle.flash.bin -------------------------------------------------------------------------------- /bin/eagle.irom0text.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/bin/eagle.irom0text.bin -------------------------------------------------------------------------------- /bin/esp_init_data_default.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/bin/esp_init_data_default.bin -------------------------------------------------------------------------------- /bin/upgrade/readme.txt: -------------------------------------------------------------------------------- 1 | For 512 KB FLASH 2 | download: 3 | boot_v1.2+.bin 0x00000 4 | user1.512.new.bin 0x01000 5 | blank.bin 0x7e000 -------------------------------------------------------------------------------- /bin/upgrade/user1.4096.new.4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/bin/upgrade/user1.4096.new.4.bin -------------------------------------------------------------------------------- /include/c_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 - 2011 Espressif System 3 | * 4 | */ 5 | 6 | #ifndef _C_TYPES_H_ 7 | #define _C_TYPES_H_ 8 | 9 | 10 | typedef unsigned char uint8_t; 11 | typedef signed char sint8_t; 12 | typedef signed char int8_t; 13 | typedef unsigned short uint16_t; 14 | typedef signed short sint16_t; 15 | typedef signed short int16_t; 16 | typedef unsigned long uint32_t; 17 | typedef signed long sint32_t; 18 | typedef signed long int32_t; 19 | typedef signed long long sint64_t; 20 | typedef unsigned long long uint64_t; 21 | typedef signed long long int64; 22 | typedef signed long long int64_t; 23 | typedef unsigned long long u_int64_t; 24 | typedef float real32_t; 25 | typedef double real64_t; 26 | 27 | typedef unsigned char uint8; 28 | typedef unsigned char u8; 29 | typedef signed char sint8; 30 | typedef signed char int8; 31 | typedef signed char s8; 32 | typedef unsigned short uint16; 33 | typedef unsigned short u16; 34 | typedef signed short sint16; 35 | typedef signed short s16; 36 | typedef unsigned int uint32; 37 | typedef unsigned int u_int; 38 | typedef unsigned int u32; 39 | typedef signed int sint32; 40 | typedef signed int s32; 41 | typedef int int32; 42 | typedef signed long long sint64; 43 | typedef unsigned long long uint64; 44 | typedef unsigned long long u64; 45 | typedef float real32; 46 | typedef float float32; 47 | typedef double real64; 48 | typedef double double64; 49 | 50 | #define __le16 u16 51 | 52 | typedef unsigned int size_t; 53 | 54 | #define __packed __attribute__((packed)) 55 | 56 | #define LOCAL static 57 | 58 | #ifndef NULL 59 | #define NULL (void *)0 60 | #endif /* NULL */ 61 | 62 | /* probably should not put STATUS here */ 63 | typedef enum { 64 | OK = 0, 65 | FAIL, 66 | PENDING, 67 | BUSY, 68 | CANCEL, 69 | } STATUS; 70 | 71 | #define BIT(nr) (1UL << (nr)) 72 | 73 | #define REG_SET_BIT(_r, _b) (*(volatile uint32_t*)(_r) |= (_b)) 74 | #define REG_CLR_BIT(_r, _b) (*(volatile uint32_t*)(_r) &= ~(_b)) 75 | 76 | #define DMEM_ATTR __attribute__((section(".bss"))) 77 | #define SHMEM_ATTR 78 | 79 | #ifdef ICACHE_FLASH 80 | #define ICACHE_FLASH_ATTR __attribute__((section(".irom0.text"))) 81 | #define ICACHE_RODATA_ATTR __attribute__((section(".irom.text"))) 82 | #else 83 | #define ICACHE_FLASH_ATTR 84 | #define ICACHE_RODATA_ATTR 85 | #endif /* ICACHE_FLASH */ 86 | 87 | #ifndef __cplusplus 88 | typedef unsigned char bool; 89 | #define BOOL bool 90 | #define true (1) 91 | #define false (0) 92 | #define TRUE true 93 | #define FALSE false 94 | 95 | 96 | #endif /* !__cplusplus */ 97 | 98 | #endif /* _C_TYPES_H_ */ 99 | -------------------------------------------------------------------------------- /include/espnow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 -2018 Espressif System 3 | * 4 | */ 5 | 6 | #ifndef __ESPNOW_H__ 7 | #define __ESPNOW_H__ 8 | 9 | enum esp_now_role { 10 | ESP_NOW_ROLE_IDLE = 0, 11 | ESP_NOW_ROLE_CONTROLLER, 12 | ESP_NOW_ROLE_SLAVE, 13 | ESP_NOW_ROLE_MAX, 14 | }; 15 | 16 | typedef void (*esp_now_recv_cb_t)(u8 *mac_addr, u8 *data, u8 len); 17 | typedef void (*esp_now_send_cb_t)(u8 *mac_addr, u8 status); 18 | 19 | int esp_now_init(void); 20 | int esp_now_deinit(void); 21 | 22 | int esp_now_register_send_cb(esp_now_send_cb_t cb); 23 | int esp_now_unregister_send_cb(void); 24 | 25 | int esp_now_register_recv_cb(esp_now_recv_cb_t cb); 26 | int esp_now_unregister_recv_cb(void); 27 | 28 | int esp_now_send(u8 *da, u8 *data, int len); 29 | 30 | int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len); 31 | int esp_now_del_peer(u8 *mac_addr); 32 | 33 | int esp_now_set_self_role(u8 role); 34 | int esp_now_get_self_role(void); 35 | 36 | int esp_now_set_peer_role(u8 *mac_addr, u8 role); 37 | int esp_now_get_peer_role(u8 *mac_addr); 38 | 39 | int esp_now_set_peer_channel(u8 *mac_addr, u8 channel); 40 | int esp_now_get_peer_channel(u8 *mac_addr); 41 | 42 | int esp_now_set_peer_key(u8 *mac_addr, u8 *key, u8 key_len); 43 | int esp_now_get_peer_key(u8 *mac_addr, u8 *key, u8 *key_len); 44 | 45 | u8 *esp_now_fetch_peer(bool restart); 46 | 47 | int esp_now_is_peer_exist(u8 *mac_addr); 48 | 49 | int esp_now_get_cnt_info(u8 *all_cnt, u8 *encrypt_cnt); 50 | 51 | int esp_now_set_kok(u8 *key, u8 len); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /include/ets_sys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * copyright (c) 2008 - 2011 Espressif System 3 | * 4 | * Define user specified Event signals and Task priorities here 5 | * 6 | */ 7 | 8 | #ifndef _ETS_SYS_H 9 | #define _ETS_SYS_H 10 | 11 | #include "c_types.h" 12 | #include "eagle_soc.h" 13 | 14 | typedef uint32_t ETSSignal; 15 | typedef uint32_t ETSParam; 16 | 17 | typedef struct ETSEventTag ETSEvent; 18 | 19 | struct ETSEventTag { 20 | ETSSignal sig; 21 | ETSParam par; 22 | }; 23 | 24 | typedef void (*ETSTask)(ETSEvent *e); 25 | 26 | /* timer related */ 27 | typedef uint32_t ETSHandle; 28 | typedef void ETSTimerFunc(void *timer_arg); 29 | 30 | typedef struct _ETSTIMER_ { 31 | struct _ETSTIMER_ *timer_next; 32 | uint32_t timer_expire; 33 | uint32_t timer_period; 34 | ETSTimerFunc *timer_func; 35 | void *timer_arg; 36 | } ETSTimer; 37 | 38 | /* interrupt related */ 39 | #define ETS_SPI_INUM 2 40 | #define ETS_GPIO_INUM 4 41 | #define ETS_UART_INUM 5 42 | #define ETS_UART1_INUM 5 43 | #define ETS_FRC_TIMER1_INUM 9 /* use edge*/ 44 | 45 | #define ETS_INTR_LOCK() \ 46 | ets_intr_lock() 47 | 48 | #define ETS_INTR_UNLOCK() \ 49 | ets_intr_unlock() 50 | 51 | #define ETS_FRC_TIMER1_INTR_ATTACH(func, arg) \ 52 | ets_isr_attach(ETS_FRC_TIMER1_INUM, (func), (void *)(arg)) 53 | 54 | #define ETS_FRC_TIMER1_NMI_INTR_ATTACH(func) \ 55 | NmiTimSetFunc(func) 56 | 57 | #define ETS_GPIO_INTR_ATTACH(func, arg) \ 58 | ets_isr_attach(ETS_GPIO_INUM, (func), (void *)(arg)) 59 | 60 | #define ETS_UART_INTR_ATTACH(func, arg) \ 61 | ets_isr_attach(ETS_UART_INUM, (func), (void *)(arg)) 62 | 63 | #define ETS_SPI_INTR_ATTACH(func, arg) \ 64 | ets_isr_attach(ETS_SPI_INUM, (func), (void *)(arg)) 65 | 66 | #define ETS_INTR_ENABLE(inum) \ 67 | ets_isr_unmask((1<= GPIO_ID_PIN0) && (reg_id <= GPIO_ID_PIN(GPIO_PIN_COUNT-1))) 15 | 16 | #define GPIO_REGID_TO_PINIDX(reg_id) ((reg_id) - GPIO_ID_PIN0) 17 | 18 | typedef enum { 19 | GPIO_PIN_INTR_DISABLE = 0, 20 | GPIO_PIN_INTR_POSEDGE = 1, 21 | GPIO_PIN_INTR_NEGEDGE = 2, 22 | GPIO_PIN_INTR_ANYEDGE = 3, 23 | GPIO_PIN_INTR_LOLEVEL = 4, 24 | GPIO_PIN_INTR_HILEVEL = 5 25 | } GPIO_INT_TYPE; 26 | 27 | #define GPIO_OUTPUT_SET(gpio_no, bit_value) \ 28 | gpio_output_set((bit_value)<>gpio_no)&BIT0) 31 | 32 | /* GPIO interrupt handler, registered through gpio_intr_handler_register */ 33 | typedef void (* gpio_intr_handler_fn_t)(uint32 intr_mask, void *arg); 34 | 35 | 36 | /* 37 | * Initialize GPIO. This includes reading the GPIO Configuration DataSet 38 | * to initialize "output enables" and pin configurations for each gpio pin. 39 | * Must be called once during startup. 40 | */ 41 | void gpio_init(void); 42 | 43 | /* 44 | * Change GPIO pin output by setting, clearing, or disabling pins. 45 | * In general, it is expected that a bit will be set in at most one 46 | * of these masks. If a bit is clear in all masks, the output state 47 | * remains unchanged. 48 | * 49 | * There is no particular ordering guaranteed; so if the order of 50 | * writes is significant, calling code should divide a single call 51 | * into multiple calls. 52 | */ 53 | void gpio_output_set(uint32 set_mask, 54 | uint32 clear_mask, 55 | uint32 enable_mask, 56 | uint32 disable_mask); 57 | 58 | /* 59 | * Sample the value of GPIO input pins and returns a bitmask. 60 | */ 61 | uint32 gpio_input_get(void); 62 | 63 | /* 64 | * Set the specified GPIO register to the specified value. 65 | * This is a very general and powerful interface that is not 66 | * expected to be used during normal operation. It is intended 67 | * mainly for debug, or for unusual requirements. 68 | */ 69 | void gpio_register_set(uint32 reg_id, uint32 value); 70 | 71 | /* Get the current value of the specified GPIO register. */ 72 | uint32 gpio_register_get(uint32 reg_id); 73 | 74 | /* 75 | * Register an application-specific interrupt handler for GPIO pin 76 | * interrupts. Once the interrupt handler is called, it will not 77 | * be called again until after a call to gpio_intr_ack. Any GPIO 78 | * interrupts that occur during the interim are masked. 79 | * 80 | * The application-specific handler is called with a mask of 81 | * pending GPIO interrupts. After processing pin interrupts, the 82 | * application-specific handler may wish to use gpio_intr_pending 83 | * to check for any additional pending interrupts before it returns. 84 | */ 85 | void gpio_intr_handler_register(gpio_intr_handler_fn_t fn, void *arg); 86 | 87 | /* Determine which GPIO interrupts are pending. */ 88 | uint32 gpio_intr_pending(void); 89 | 90 | /* 91 | * Acknowledge GPIO interrupts. 92 | * Intended to be called from the gpio_intr_handler_fn. 93 | */ 94 | void gpio_intr_ack(uint32 ack_mask); 95 | 96 | void gpio_pin_wakeup_enable(uint32 i, GPIO_INT_TYPE intr_state); 97 | 98 | void gpio_pin_wakeup_disable(); 99 | 100 | void gpio_pin_intr_state_set(uint32 i, GPIO_INT_TYPE intr_state); 101 | 102 | #endif // _GPIO_H_ 103 | -------------------------------------------------------------------------------- /include/ip_addr.h: -------------------------------------------------------------------------------- 1 | #ifndef __IP_ADDR_H__ 2 | #define __IP_ADDR_H__ 3 | 4 | #include "c_types.h" 5 | 6 | struct ip_addr { 7 | uint32 addr; 8 | }; 9 | 10 | typedef struct ip_addr ip_addr_t; 11 | 12 | struct ip_info { 13 | struct ip_addr ip; 14 | struct ip_addr netmask; 15 | struct ip_addr gw; 16 | }; 17 | 18 | /** 19 | * Determine if two address are on the same network. 20 | * 21 | * @arg addr1 IP address 1 22 | * @arg addr2 IP address 2 23 | * @arg mask network identifier mask 24 | * @return !0 if the network identifiers of both address match 25 | */ 26 | #define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \ 27 | (mask)->addr) == \ 28 | ((addr2)->addr & \ 29 | (mask)->addr)) 30 | 31 | /** Set an IP address given by the four byte-parts. 32 | Little-endian version that prevents the use of htonl. */ 33 | #define IP4_ADDR(ipaddr, a,b,c,d) \ 34 | (ipaddr)->addr = ((uint32)((d) & 0xff) << 24) | \ 35 | ((uint32)((c) & 0xff) << 16) | \ 36 | ((uint32)((b) & 0xff) << 8) | \ 37 | (uint32)((a) & 0xff) 38 | 39 | #define ip4_addr1(ipaddr) (((uint8*)(ipaddr))[0]) 40 | #define ip4_addr2(ipaddr) (((uint8*)(ipaddr))[1]) 41 | #define ip4_addr3(ipaddr) (((uint8*)(ipaddr))[2]) 42 | #define ip4_addr4(ipaddr) (((uint8*)(ipaddr))[3]) 43 | 44 | #define ip4_addr1_16(ipaddr) ((uint16)ip4_addr1(ipaddr)) 45 | #define ip4_addr2_16(ipaddr) ((uint16)ip4_addr2(ipaddr)) 46 | #define ip4_addr3_16(ipaddr) ((uint16)ip4_addr3(ipaddr)) 47 | #define ip4_addr4_16(ipaddr) ((uint16)ip4_addr4(ipaddr)) 48 | 49 | 50 | /** 255.255.255.255 */ 51 | #define IPADDR_NONE ((uint32)0xffffffffUL) 52 | /** 0.0.0.0 */ 53 | #define IPADDR_ANY ((uint32)0x00000000UL) 54 | uint32 ipaddr_addr(const char *cp); 55 | 56 | #define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \ 57 | ip4_addr2_16(ipaddr), \ 58 | ip4_addr3_16(ipaddr), \ 59 | ip4_addr4_16(ipaddr) 60 | 61 | #define IPSTR "%d.%d.%d.%d" 62 | 63 | #endif /* __IP_ADDR_H__ */ 64 | -------------------------------------------------------------------------------- /include/json/json.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2012, 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 Contiki operating system. 30 | */ 31 | 32 | /** 33 | * \file 34 | * A few JSON defines used for parsing and generating JSON. 35 | * \author 36 | * Niclas Finne 37 | * Joakim Eriksson 38 | */ 39 | 40 | #ifndef __JSON_H__ 41 | #define __JSON_H__ 42 | 43 | #define JSON_TYPE_ARRAY '[' 44 | #define JSON_TYPE_OBJECT '{' 45 | #define JSON_TYPE_PAIR ':' 46 | #define JSON_TYPE_PAIR_NAME 'N' /* for N:V pairs */ 47 | #define JSON_TYPE_STRING '"' 48 | #define JSON_TYPE_INT 'I' 49 | #define JSON_TYPE_NUMBER '0' 50 | #define JSON_TYPE_ERROR 0 51 | 52 | /* how should we handle null vs false - both can be 0? */ 53 | #define JSON_TYPE_NULL 'n' 54 | #define JSON_TYPE_TRUE 't' 55 | #define JSON_TYPE_FALSE 'f' 56 | 57 | #define JSON_TYPE_CALLBACK 'C' 58 | 59 | enum { 60 | JSON_ERROR_OK, 61 | JSON_ERROR_SYNTAX, 62 | JSON_ERROR_UNEXPECTED_ARRAY, 63 | JSON_ERROR_UNEXPECTED_END_OF_ARRAY, 64 | JSON_ERROR_UNEXPECTED_OBJECT, 65 | JSON_ERROR_UNEXPECTED_STRING 66 | }; 67 | 68 | #define JSON_CONTENT_TYPE "application/json" 69 | 70 | #endif /* __JSON_H__ */ 71 | -------------------------------------------------------------------------------- /include/json/jsonparse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011-2012, 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 Contiki operating system. 30 | */ 31 | 32 | #ifndef __JSONPARSE_H__ 33 | #define __JSONPARSE_H__ 34 | 35 | #include "c_types.h" 36 | #include "json/json.h" 37 | 38 | #ifdef JSONPARSE_CONF_MAX_DEPTH 39 | #define JSONPARSE_MAX_DEPTH JSONPARSE_CONF_MAX_DEPTH 40 | #else 41 | #define JSONPARSE_MAX_DEPTH 10 42 | #endif 43 | 44 | struct jsonparse_state { 45 | const char *json; 46 | int pos; 47 | int len; 48 | int depth; 49 | /* for handling atomic values */ 50 | int vstart; 51 | int vlen; 52 | char vtype; 53 | char error; 54 | char stack[JSONPARSE_MAX_DEPTH]; 55 | }; 56 | 57 | /** 58 | * \brief Initialize a JSON parser state. 59 | * \param state A pointer to a JSON parser state 60 | * \param json The string to parse as JSON 61 | * \param len The length of the string to parse 62 | * 63 | * This function initializes a JSON parser state for 64 | * parsing a string as JSON. 65 | */ 66 | void jsonparse_setup(struct jsonparse_state *state, const char *json, int len); 67 | 68 | /* move to next JSON element */ 69 | int jsonparse_next(struct jsonparse_state *state); 70 | 71 | /* copy the current JSON value into the specified buffer */ 72 | int jsonparse_copy_value(struct jsonparse_state *state, char *buf, 73 | int buf_size); 74 | 75 | /* get the current JSON value parsed as an int */ 76 | int jsonparse_get_value_as_int(struct jsonparse_state *state); 77 | 78 | /* get the current JSON value parsed as a long */ 79 | long jsonparse_get_value_as_long(struct jsonparse_state *state); 80 | 81 | /* get the length of the current JSON value */ 82 | int jsonparse_get_len(struct jsonparse_state *state); 83 | 84 | /* get the type of the current JSON value */ 85 | int jsonparse_get_type(struct jsonparse_state *state); 86 | 87 | /* compare the JSON value with the specified string */ 88 | int jsonparse_strcmp_value(struct jsonparse_state *state, const char *str); 89 | 90 | #endif /* __JSONPARSE_H__ */ 91 | -------------------------------------------------------------------------------- /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 | 15 | #define os_memcmp ets_memcmp 16 | #define os_memcpy ets_memcpy 17 | #define os_memmove ets_memmove 18 | #define os_memset ets_memset 19 | #define os_strcat strcat 20 | #define os_strchr strchr 21 | #define os_strcmp ets_strcmp 22 | #define os_strcpy ets_strcpy 23 | #define os_strlen ets_strlen 24 | #define os_strncmp ets_strncmp 25 | #define os_strncpy ets_strncpy 26 | #define os_strstr ets_strstr 27 | #ifdef USE_US_TIMER 28 | #define os_timer_arm_us(a, b, c) ets_timer_arm_new(a, b, c, 0) 29 | #endif 30 | #define os_timer_arm(a, b, c) ets_timer_arm_new(a, b, c, 1) 31 | #define os_timer_disarm ets_timer_disarm 32 | #define os_timer_setfn ets_timer_setfn 33 | 34 | #define os_sprintf ets_sprintf 35 | 36 | #ifdef USE_OPTIMIZE_PRINTF 37 | #define os_printf(fmt, ...) do { \ 38 | static const char flash_str[] ICACHE_RODATA_ATTR __attribute__((aligned(4))) = fmt; \ 39 | os_printf_plus(flash_str, ##__VA_ARGS__); \ 40 | } while(0) 41 | #else 42 | #define os_printf os_printf_plus 43 | #endif 44 | 45 | unsigned long os_random(void); 46 | int os_get_random(unsigned char *buf, size_t len); 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /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/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_ESPTOUCH_AIRKISS, 21 | } sc_type; 22 | 23 | typedef void (*sc_callback_t)(sc_status status, void *pdata); 24 | 25 | const char *smartconfig_get_version(void); 26 | bool smartconfig_start(sc_callback_t cb, ...); 27 | bool smartconfig_stop(void); 28 | bool esptouch_set_timeout(uint8 time_s); //15s~255s, offset:45s 29 | bool smartconfig_set_type(sc_type type); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /lib/libat.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libat.a -------------------------------------------------------------------------------- /lib/libcrypto.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libcrypto.a -------------------------------------------------------------------------------- /lib/libespnow.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libespnow.a -------------------------------------------------------------------------------- /lib/libjson.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libjson.a -------------------------------------------------------------------------------- /lib/liblwip.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/liblwip.a -------------------------------------------------------------------------------- /lib/liblwip_536.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/liblwip_536.a -------------------------------------------------------------------------------- /lib/libmain.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libmain.a -------------------------------------------------------------------------------- /lib/libnet80211.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libnet80211.a -------------------------------------------------------------------------------- /lib/libphy.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libphy.a -------------------------------------------------------------------------------- /lib/libpp.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libpp.a -------------------------------------------------------------------------------- /lib/libpwm.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libpwm.a -------------------------------------------------------------------------------- /lib/libsmartconfig.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libsmartconfig.a -------------------------------------------------------------------------------- /lib/libssl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libssl.a -------------------------------------------------------------------------------- /lib/libupgrade.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libupgrade.a -------------------------------------------------------------------------------- /lib/libwpa.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libwpa.a -------------------------------------------------------------------------------- /lib/libwps.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/lib/libwps.a -------------------------------------------------------------------------------- /pic/firmware0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/firmware0.jpg -------------------------------------------------------------------------------- /pic/firmware1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/firmware1.jpg -------------------------------------------------------------------------------- /pic/firmware2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/firmware2.jpg -------------------------------------------------------------------------------- /pic/firmware3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/firmware3.jpg -------------------------------------------------------------------------------- /pic/show0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/show0.jpg -------------------------------------------------------------------------------- /pic/show1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/show1.jpg -------------------------------------------------------------------------------- /pic/show2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/show2.jpg -------------------------------------------------------------------------------- /pic/show4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/show4.png -------------------------------------------------------------------------------- /pic/show5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/show5.png -------------------------------------------------------------------------------- /pic/show6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/show6.png -------------------------------------------------------------------------------- /pic/show7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/show7.png -------------------------------------------------------------------------------- /pic/tft-tisan-connect.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/tft-tisan-connect.JPG -------------------------------------------------------------------------------- /pic/usart-gpu.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/usart-gpu.JPG -------------------------------------------------------------------------------- /pic/webide1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/webide1.jpg -------------------------------------------------------------------------------- /pic/webide2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/webide2.jpg -------------------------------------------------------------------------------- /pic/webide3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/webide3.jpg -------------------------------------------------------------------------------- /pic/webide4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/pic/webide4.jpg -------------------------------------------------------------------------------- /reference_doc/Usart_GPU_Reference.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/reference_doc/Usart_GPU_Reference.pdf -------------------------------------------------------------------------------- /tools/makefile.sh: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # Generate the certificates and keys for encrypt. 4 | # 5 | 6 | # set default cert for use in the client 7 | xxd -i client.cer | sed -e \ 8 | "s/client_cer/default_certificate/" > cert.h 9 | # set default key for use in the server 10 | xxd -i server.key_1024 | sed -e \ 11 | "s/server_key_1024/default_private_key/" > private_key.h 12 | -------------------------------------------------------------------------------- /tools/xxd.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tisan-kit/usart-gpu-tft-demo/9a8988cdb620e66ae7664d495cdcda44bc67d5a9/tools/xxd.exe --------------------------------------------------------------------------------