├── 0x00000.bin ├── 0x40000.bin ├── LICENSE ├── Makefile ├── PCB └── Shift-32 │ ├── ESP12 Controller-cache.lib │ ├── ESP12 Controller.bak │ ├── ESP12 Controller.kicad_pcb │ ├── ESP12 Controller.kicad_pcb-bak │ ├── ESP12 Controller.net │ ├── ESP12 Controller.pro │ ├── ESP12 Controller.sch │ ├── Esquema e placa.pdf │ └── GERBER │ ├── ESP12 Controller-B.Cu.gbr │ ├── ESP12 Controller-B.SilkS.gbr │ ├── ESP12 Controller-Edge.Cuts.gbr │ ├── ESP12 Controller-F.Cu.gbr │ ├── ESP12 Controller-F.SilkS.gbr │ └── ESP12 Controller.drl ├── README.md ├── common ├── commonservices.c ├── commonservices.h ├── esp8266_rom.h ├── flash_rewriter.c ├── flash_rewriter.h ├── http.c ├── http.h ├── http_custom.c ├── mdns.c ├── mdns.h ├── mfs.c ├── mfs.h ├── mystuff.c └── mystuff.h ├── driver └── uart.c ├── image.elf ├── images └── Counter - Word_clock and 3LSBs.png ├── include ├── driver │ ├── uart.h │ └── uart_register.h ├── pin_mux_register.h ├── string.h └── user_config.h ├── top ├── Makefile ├── README.md ├── top └── top.c ├── user ├── custom_commands.c ├── slc_register.h ├── user_main.c ├── ws2812_i2s.c └── ws2812_i2s.h └── web ├── Makefile ├── execute_reflash.c ├── md5.c ├── md5.h ├── mfsmaker.c ├── page.mpfs ├── page ├── index.html ├── jquery-2.1.4.min.js.gz ├── main.js └── menuinterface.js └── pushtodev.c /0x00000.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhartmann/esp8266_reprap/46653d8ec498c8fa382bd2c672f4d8cea946bc49/0x00000.bin -------------------------------------------------------------------------------- /0x40000.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhartmann/esp8266_reprap/46653d8ec498c8fa382bd2c672f4d8cea946bc49/0x40000.bin -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ESPRSSIF MIT License 2 | 3 | Copyright (c) 2015 4 | Portions Copyright (c) 2015 <>< Charles Lohr 5 | 6 | Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, 7 | in which case, it is free of charge, to any person obtaining a copy of this 8 | software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | 25 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | FW_FILE_1:=0x00000.bin 2 | FW_FILE_2:=0x40000.bin 3 | TARGET_OUT:=image.elf 4 | all : $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) 5 | 6 | 7 | SRCS:=driver/uart.c \ 8 | common/mystuff.c \ 9 | common/flash_rewriter.c \ 10 | common/http.c \ 11 | common/commonservices.c \ 12 | common/http_custom.c \ 13 | common/mdns.c \ 14 | common/mfs.c \ 15 | user/custom_commands.c \ 16 | user/ws2812_i2s.c \ 17 | user/user_main.c 18 | 19 | ESPOPENSDK:=~/.bin/esp-open-sdk 20 | GCC_FOLDER:=$(ESPOPENSDK)/xtensa-lx106-elf 21 | ESPTOOL_PY:=$(ESPOPENSDK)/esptool/esptool.py 22 | FW_TOOL:=$(ESPOPENSDK)/esptool-ck/esptool 23 | SDK:=$(ESPOPENSDK)/sdk/ 24 | PORT:=/dev/ttyUSB0 25 | #PORT:=/dev/ttyACM0 26 | 27 | XTLIB:=$(SDK)/lib 28 | XTGCCLIB:=$(GCC_FOLDER)/lib/gcc/xtensa-lx106-elf/4.8.2/libgcc.a 29 | FOLDERPREFIX:=$(GCC_FOLDER)/bin 30 | PREFIX:=$(FOLDERPREFIX)/xtensa-lx106-elf- 31 | CC:=$(PREFIX)gcc 32 | 33 | CFLAGS:=-mlongcalls -I$(SDK)/include -Imyclib -Iinclude -Iuser -Os -I$(SDK)/include/ -Icommon -DICACHE_FLASH 34 | 35 | # \ 36 | # 37 | 38 | LDFLAGS_CORE:=\ 39 | -nostdlib \ 40 | -Wl,--relax -Wl,--gc-sections \ 41 | -L$(XTLIB) \ 42 | -L$(XTGCCLIB) \ 43 | $(SDK)/lib/liblwip.a \ 44 | $(SDK)/lib/libssl.a \ 45 | $(SDK)/lib/libupgrade.a \ 46 | $(SDK)/lib/libnet80211.a \ 47 | $(SDK)/lib/liblwip.a \ 48 | $(SDK)/lib/libwpa.a \ 49 | $(SDK)/lib/libnet80211.a \ 50 | $(SDK)/lib/libphy.a \ 51 | $(SDK)/lib/libmain.a \ 52 | $(SDK)/lib/libpp.a \ 53 | $(XTGCCLIB) \ 54 | -T $(SDK)/ld/eagle.app.v6.ld 55 | 56 | LINKFLAGS:= \ 57 | $(LDFLAGS_CORE) \ 58 | -B$(XTLIB) 59 | 60 | #image.elf : $(OBJS) 61 | # $(PREFIX)ld $^ $(LDFLAGS) -o $@ 62 | 63 | $(TARGET_OUT) : $(SRCS) 64 | $(PREFIX)gcc $(CFLAGS) $^ -flto $(LINKFLAGS) -o $@ 65 | 66 | 67 | 68 | $(FW_FILE_1): $(TARGET_OUT) 69 | @echo "FW $@" 70 | $(FW_TOOL) -eo $(TARGET_OUT) -bo $@ -bs .text -bs .data -bs .rodata -bc -ec 71 | 72 | $(FW_FILE_2): $(TARGET_OUT) 73 | @echo "FW $@" 74 | $(FW_TOOL) -eo $(TARGET_OUT) -es .irom0.text $@ -ec 75 | 76 | burn : $(FW_FILE_1) $(FW_FILE_2) 77 | ($(ESPTOOL_PY) --port $(PORT) --baud 460800 write_flash 0x00000 0x00000.bin 0x40000 0x40000.bin)||(true) 78 | 79 | #If you have space, MFS should live at 0x100000, if you don't it can also live at 80 | #0x10000. But, then it is limited to 180kB. You might need to do this if you have a 512kB 81 | #ESP variant. 82 | 83 | burnweb : web/page.mpfs 84 | ($(ESPTOOL_PY) --port $(PORT) write_flash 0x10000 web/page.mpfs)||(true) 85 | 86 | 87 | IP?=192.168.4.1 88 | 89 | netburn : image.elf $(FW_FILE_1) $(FW_FILE_2) 90 | web/execute_reflash $(IP) 0x00000.bin 0x40000.bin 91 | 92 | clean : 93 | rm -rf user/*.o driver/*.o $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2) 94 | 95 | 96 | -------------------------------------------------------------------------------- /PCB/Shift-32/ESP12 Controller-cache.lib: -------------------------------------------------------------------------------- 1 | EESchema-LIBRARY Version 2.3 2 | #encoding utf-8 3 | # 4 | # 74HC595 5 | # 6 | DEF 74HC595 U 0 40 Y Y 1 F N 7 | F0 "U" 150 600 70 H V C CNN 8 | F1 "74HC595" 0 -600 70 H V C CNN 9 | F2 "" 0 0 60 H V C CNN 10 | F3 "" 0 0 60 H V C CNN 11 | ALIAS 74LS596 74LS595 12 | DRAW 13 | S -400 -550 400 550 0 1 0 N 14 | X QB 1 700 350 300 L 60 60 1 1 T 15 | X QC 2 700 250 300 L 60 60 1 1 T 16 | X QD 3 700 150 300 L 60 60 1 1 T 17 | X QE 4 700 50 300 L 60 60 1 1 T 18 | X QF 5 700 -50 300 L 60 60 1 1 T 19 | X QG 6 700 -150 300 L 60 60 1 1 T 20 | X QH 7 700 -250 300 L 60 60 1 1 T 21 | X GND 8 -300 -550 0 U 60 60 1 1 W N 22 | X ~QH 9 700 -450 300 L 60 60 1 1 O 23 | X SRCLR 10 -700 150 300 R 60 60 1 1 I I 24 | X SRCLK 11 -700 250 300 R 60 60 1 1 I C 25 | X RCLK 12 -700 -50 300 R 60 60 1 1 I C 26 | X G 13 -700 -150 300 R 60 60 1 1 I I 27 | X SER 14 -700 450 300 R 60 60 1 1 I 28 | X QA 15 700 450 300 L 60 60 1 1 T 29 | X VCC 16 -300 550 0 D 60 60 1 1 W N 30 | ENDDRAW 31 | ENDDEF 32 | # 33 | # C 34 | # 35 | DEF C C 0 10 N Y 1 F N 36 | F0 "C" 25 100 50 H V L CNN 37 | F1 "C" 25 -100 50 H V L CNN 38 | F2 "" 38 -150 30 H V C CNN 39 | F3 "" 0 0 60 H V C CNN 40 | $FPLIST 41 | C? 42 | C_????_* 43 | C_???? 44 | SMD*_c 45 | Capacitor* 46 | $ENDFPLIST 47 | DRAW 48 | P 2 0 1 20 -80 -30 80 -30 N 49 | P 2 0 1 20 -80 30 80 30 N 50 | X ~ 1 0 150 110 D 40 40 1 1 P 51 | X ~ 2 0 -150 110 U 40 40 1 1 P 52 | ENDDRAW 53 | ENDDEF 54 | # 55 | # CONN_01X02 56 | # 57 | DEF CONN_01X02 P 0 40 Y N 1 F N 58 | F0 "P" 0 150 50 H V C CNN 59 | F1 "CONN_01X02" 100 0 50 V V C CNN 60 | F2 "" 0 0 60 H V C CNN 61 | F3 "" 0 0 60 H V C CNN 62 | $FPLIST 63 | Pin_Header_Straight_1X02 64 | Pin_Header_Angled_1X02 65 | Socket_Strip_Straight_1X02 66 | Socket_Strip_Angled_1X02 67 | $ENDFPLIST 68 | DRAW 69 | S -50 -45 10 -55 0 1 0 N 70 | S -50 55 10 45 0 1 0 N 71 | S -50 100 50 -100 0 1 0 N 72 | X P1 1 -200 50 150 R 50 50 1 1 P 73 | X P2 2 -200 -50 150 R 50 50 1 1 P 74 | ENDDRAW 75 | ENDDEF 76 | # 77 | # CONN_01X05 78 | # 79 | DEF CONN_01X05 P 0 40 Y N 1 F N 80 | F0 "P" 0 300 50 H V C CNN 81 | F1 "CONN_01X05" 100 0 50 V V C CNN 82 | F2 "" 0 0 60 H V C CNN 83 | F3 "" 0 0 60 H V C CNN 84 | $FPLIST 85 | Pin_Header_Straight_1X05 86 | Pin_Header_Angled_1X05 87 | Socket_Strip_Straight_1X05 88 | Socket_Strip_Angled_1X05 89 | $ENDFPLIST 90 | DRAW 91 | S -50 -195 10 -205 0 1 0 N 92 | S -50 -95 10 -105 0 1 0 N 93 | S -50 5 10 -5 0 1 0 N 94 | S -50 105 10 95 0 1 0 N 95 | S -50 205 10 195 0 1 0 N 96 | S -50 250 50 -250 0 1 0 N 97 | X P1 1 -200 200 150 R 50 50 1 1 P 98 | X P2 2 -200 100 150 R 50 50 1 1 P 99 | X P3 3 -200 0 150 R 50 50 1 1 P 100 | X P4 4 -200 -100 150 R 50 50 1 1 P 101 | X P5 5 -200 -200 150 R 50 50 1 1 P 102 | ENDDRAW 103 | ENDDEF 104 | # 105 | # CONN_01X08 106 | # 107 | DEF CONN_01X08 P 0 40 Y N 1 F N 108 | F0 "P" 0 450 50 H V C CNN 109 | F1 "CONN_01X08" 100 0 50 V V C CNN 110 | F2 "" 0 0 60 H V C CNN 111 | F3 "" 0 0 60 H V C CNN 112 | $FPLIST 113 | Pin_Header_Straight_1X08 114 | Pin_Header_Angled_1X08 115 | Socket_Strip_Straight_1X08 116 | Socket_Strip_Angled_1X08 117 | $ENDFPLIST 118 | DRAW 119 | S -50 -400 50 400 0 1 0 N 120 | S -50 -345 10 -355 0 1 0 N 121 | S -50 -245 10 -255 0 1 0 N 122 | S -50 -145 10 -155 0 1 0 N 123 | S -50 -45 10 -55 0 1 0 N 124 | S -50 55 10 45 0 1 0 N 125 | S -50 155 10 145 0 1 0 N 126 | S -50 255 10 245 0 1 0 N 127 | S -50 355 10 345 0 1 0 N 128 | X P1 1 -200 350 150 R 50 50 1 1 P 129 | X P2 2 -200 250 150 R 50 50 1 1 P 130 | X P3 3 -200 150 150 R 50 50 1 1 P 131 | X P4 4 -200 50 150 R 50 50 1 1 P 132 | X P5 5 -200 -50 150 R 50 50 1 1 P 133 | X P6 6 -200 -150 150 R 50 50 1 1 P 134 | X P7 7 -200 -250 150 R 50 50 1 1 P 135 | X P8 8 -200 -350 150 R 50 50 1 1 P 136 | ENDDRAW 137 | ENDDEF 138 | # 139 | # CONN_02X08 140 | # 141 | DEF CONN_02X08 P 0 1 Y N 1 F N 142 | F0 "P" 0 450 50 H V C CNN 143 | F1 "CONN_02X08" 0 0 50 V V C CNN 144 | F2 "" 0 -1200 60 H V C CNN 145 | F3 "" 0 -1200 60 H V C CNN 146 | $FPLIST 147 | Pin_Header_Straight_2X08 148 | Pin_Header_Angled_2X08 149 | Socket_Strip_Straight_2X08 150 | Socket_Strip_Angled_2X08 151 | $ENDFPLIST 152 | DRAW 153 | S -100 -345 -50 -355 0 1 0 N 154 | S -100 -245 -50 -255 0 1 0 N 155 | S -100 -145 -50 -155 0 1 0 N 156 | S -100 -45 -50 -55 0 1 0 N 157 | S -100 55 -50 45 0 1 0 N 158 | S -100 155 -50 145 0 1 0 N 159 | S -100 255 -50 245 0 1 0 N 160 | S -100 355 -50 345 0 1 0 N 161 | S -100 400 100 -400 0 1 0 N 162 | S 50 -345 100 -355 0 1 0 N 163 | S 50 -245 100 -255 0 1 0 N 164 | S 50 -145 100 -155 0 1 0 N 165 | S 50 -45 100 -55 0 1 0 N 166 | S 50 55 100 45 0 1 0 N 167 | S 50 155 100 145 0 1 0 N 168 | S 50 255 100 245 0 1 0 N 169 | S 50 355 100 345 0 1 0 N 170 | X P1 1 -250 350 150 R 50 50 1 1 P 171 | X P2 2 250 350 150 L 50 50 1 1 P 172 | X P3 3 -250 250 150 R 50 50 1 1 P 173 | X P4 4 250 250 150 L 50 50 1 1 P 174 | X P5 5 -250 150 150 R 50 50 1 1 P 175 | X P6 6 250 150 150 L 50 50 1 1 P 176 | X P7 7 -250 50 150 R 50 50 1 1 P 177 | X P8 8 250 50 150 L 50 50 1 1 P 178 | X P9 9 -250 -50 150 R 50 50 1 1 P 179 | X P10 10 250 -50 150 L 50 50 1 1 P 180 | X P11 11 -250 -150 150 R 50 50 1 1 P 181 | X P12 12 250 -150 150 L 50 50 1 1 P 182 | X P13 13 -250 -250 150 R 50 50 1 1 P 183 | X P14 14 250 -250 150 L 50 50 1 1 P 184 | X P15 15 -250 -350 150 R 50 50 1 1 P 185 | X P16 16 250 -350 150 L 50 50 1 1 P 186 | ENDDRAW 187 | ENDDEF 188 | # 189 | # GND 190 | # 191 | DEF GND #PWR 0 0 Y Y 1 F P 192 | F0 "#PWR" 0 -250 50 H I C CNN 193 | F1 "GND" 0 -150 50 H V C CNN 194 | F2 "" 0 0 60 H V C CNN 195 | F3 "" 0 0 60 H V C CNN 196 | DRAW 197 | P 6 0 1 0 0 0 0 -50 50 -50 0 -100 -50 -50 0 -50 N 198 | X GND 1 0 0 0 D 50 50 1 1 W N 199 | ENDDRAW 200 | ENDDEF 201 | # 202 | # VCC 203 | # 204 | DEF VCC #PWR 0 0 Y Y 1 F P 205 | F0 "#PWR" 0 -150 50 H I C CNN 206 | F1 "VCC" 0 150 50 H V C CNN 207 | F2 "" 0 0 60 H V C CNN 208 | F3 "" 0 0 60 H V C CNN 209 | DRAW 210 | C 0 75 25 0 1 0 N 211 | P 2 0 1 0 0 0 0 50 N 212 | X VCC 1 0 0 0 U 50 50 1 1 W N 213 | ENDDRAW 214 | ENDDEF 215 | # 216 | # VPP 217 | # 218 | DEF VPP #PWR 0 0 Y Y 1 F P 219 | F0 "#PWR" 0 -150 50 H I C CNN 220 | F1 "VPP" 0 150 50 H V C CNN 221 | F2 "" 0 0 60 H V C CNN 222 | F3 "" 0 0 60 H V C CNN 223 | DRAW 224 | P 2 0 1 0 -30 50 0 100 N 225 | P 2 0 1 0 0 0 0 100 N 226 | P 2 0 1 0 0 100 30 50 N 227 | X VPP 1 0 0 0 U 50 50 1 1 W N 228 | ENDDRAW 229 | ENDDEF 230 | # 231 | #End Library 232 | -------------------------------------------------------------------------------- /PCB/Shift-32/ESP12 Controller.net: -------------------------------------------------------------------------------- 1 | (export (version D) 2 | (design 3 | (source "/home/lucas.hartmann/Documentos/Projetos/CNCs/Shift-32/ESP12 Controller.sch") 4 | (date "Tue 17 Nov 2015 13:48:28 BRT") 5 | (tool "Eeschema 4.0.0-rc2-stable") 6 | (sheet (number 1) (name /) (tstamps /) 7 | (title_block 8 | (title) 9 | (company) 10 | (rev) 11 | (date) 12 | (source "ESP12 Controller.sch") 13 | (comment (number 1) (value "")) 14 | (comment (number 2) (value "")) 15 | (comment (number 3) (value "")) 16 | (comment (number 4) (value ""))))) 17 | (components 18 | (comp (ref U1) 19 | (value 74HC595) 20 | (footprint SMD_Packages:SO-16-N) 21 | (libsource (lib 74xx) (part 74HC595)) 22 | (sheetpath (names /) (tstamps /)) 23 | (tstamp 564A450E)) 24 | (comp (ref U2) 25 | (value 74HC595) 26 | (footprint SMD_Packages:SO-16-N) 27 | (libsource (lib 74xx) (part 74HC595)) 28 | (sheetpath (names /) (tstamps /)) 29 | (tstamp 564A4AF6)) 30 | (comp (ref U3) 31 | (value 74HC595) 32 | (footprint SMD_Packages:SO-16-N) 33 | (libsource (lib 74xx) (part 74HC595)) 34 | (sheetpath (names /) (tstamps /)) 35 | (tstamp 564A4B89)) 36 | (comp (ref U4) 37 | (value 74HC595) 38 | (footprint SMD_Packages:SO-16-N) 39 | (libsource (lib 74xx) (part 74HC595)) 40 | (sheetpath (names /) (tstamps /)) 41 | (tstamp 564A4BAA)) 42 | (comp (ref P7) 43 | (value EXPANSION) 44 | (footprint Socket_Strips:Socket_Strip_Straight_1x05) 45 | (libsource (lib conn) (part CONN_01X05)) 46 | (sheetpath (names /) (tstamps /)) 47 | (tstamp 564A5E7D)) 48 | (comp (ref P5) 49 | (value INPUT) 50 | (footprint Socket_Strips:Socket_Strip_Straight_1x05) 51 | (libsource (lib conn) (part CONN_01X05)) 52 | (sheetpath (names /) (tstamps /)) 53 | (tstamp 564B4C2F)) 54 | (comp (ref P1) 55 | (value CONN_02X08) 56 | (footprint Socket_Strips:Socket_Strip_Straight_2x08) 57 | (libsource (lib conn) (part CONN_02X08)) 58 | (sheetpath (names /) (tstamps /)) 59 | (tstamp 564B4E7E)) 60 | (comp (ref P3) 61 | (value CONN_02X08) 62 | (footprint Socket_Strips:Socket_Strip_Straight_2x08) 63 | (libsource (lib conn) (part CONN_02X08)) 64 | (sheetpath (names /) (tstamps /)) 65 | (tstamp 564B538D)) 66 | (comp (ref P6) 67 | (value CONN_02X08) 68 | (footprint Socket_Strips:Socket_Strip_Straight_2x08) 69 | (libsource (lib conn) (part CONN_02X08)) 70 | (sheetpath (names /) (tstamps /)) 71 | (tstamp 564B54A0)) 72 | (comp (ref P9) 73 | (value CONN_02X08) 74 | (footprint Socket_Strips:Socket_Strip_Straight_2x08) 75 | (libsource (lib conn) (part CONN_02X08)) 76 | (sheetpath (names /) (tstamps /)) 77 | (tstamp 564B5640)) 78 | (comp (ref P2) 79 | (value CONN_01X08) 80 | (footprint Socket_Strips:Socket_Strip_Straight_1x08) 81 | (libsource (lib conn) (part CONN_01X08)) 82 | (sheetpath (names /) (tstamps /)) 83 | (tstamp 564B57F1)) 84 | (comp (ref P4) 85 | (value CONN_01X08) 86 | (footprint Socket_Strips:Socket_Strip_Straight_1x08) 87 | (libsource (lib conn) (part CONN_01X08)) 88 | (sheetpath (names /) (tstamps /)) 89 | (tstamp 564B5EDC)) 90 | (comp (ref P8) 91 | (value CONN_01X08) 92 | (footprint Socket_Strips:Socket_Strip_Straight_1x08) 93 | (libsource (lib conn) (part CONN_01X08)) 94 | (sheetpath (names /) (tstamps /)) 95 | (tstamp 564B5F8D)) 96 | (comp (ref P10) 97 | (value CONN_01X08) 98 | (footprint Socket_Strips:Socket_Strip_Straight_1x08) 99 | (libsource (lib conn) (part CONN_01X08)) 100 | (sheetpath (names /) (tstamps /)) 101 | (tstamp 564B600B)) 102 | (comp (ref C1) 103 | (value 1uF) 104 | (footprint Capacitors_SMD:C_0805_HandSoldering) 105 | (libsource (lib device) (part C)) 106 | (sheetpath (names /) (tstamps /)) 107 | (tstamp 564B60FB)) 108 | (comp (ref C2) 109 | (value 1uF) 110 | (footprint Capacitors_SMD:C_0805_HandSoldering) 111 | (libsource (lib device) (part C)) 112 | (sheetpath (names /) (tstamps /)) 113 | (tstamp 564B616C)) 114 | (comp (ref C3) 115 | (value 1uF) 116 | (footprint Capacitors_SMD:C_0805_HandSoldering) 117 | (libsource (lib device) (part C)) 118 | (sheetpath (names /) (tstamps /)) 119 | (tstamp 564B61A9)) 120 | (comp (ref C4) 121 | (value 1uF) 122 | (footprint Capacitors_SMD:C_0805_HandSoldering) 123 | (libsource (lib device) (part C)) 124 | (sheetpath (names /) (tstamps /)) 125 | (tstamp 564B61EC)) 126 | (comp (ref C5) 127 | (value 1uF) 128 | (footprint Capacitors_SMD:C_0805_HandSoldering) 129 | (libsource (lib device) (part C)) 130 | (sheetpath (names /) (tstamps /)) 131 | (tstamp 564B6E07)) 132 | (comp (ref C6) 133 | (value 1uF) 134 | (footprint Capacitors_SMD:C_0805_HandSoldering) 135 | (libsource (lib device) (part C)) 136 | (sheetpath (names /) (tstamps /)) 137 | (tstamp 564B6E0E)) 138 | (comp (ref C7) 139 | (value 1uF) 140 | (footprint Capacitors_SMD:C_0805_HandSoldering) 141 | (libsource (lib device) (part C)) 142 | (sheetpath (names /) (tstamps /)) 143 | (tstamp 564B6E15)) 144 | (comp (ref C8) 145 | (value 1uF) 146 | (footprint Capacitors_SMD:C_0805_HandSoldering) 147 | (libsource (lib device) (part C)) 148 | (sheetpath (names /) (tstamps /)) 149 | (tstamp 564B6E1C)) 150 | (comp (ref P11) 151 | (value CONN_01X02) 152 | (footprint Socket_Strips:Socket_Strip_Straight_1x02) 153 | (libsource (lib conn) (part CONN_01X02)) 154 | (sheetpath (names /) (tstamps /)) 155 | (tstamp 564B75C0))) 156 | (libparts 157 | (libpart (lib 74xx) (part 74HC595) 158 | (aliases 159 | (alias 74LS596) 160 | (alias 74LS595)) 161 | (description "8 bits serial in // out Shift Register 3 State Out") 162 | (docs 74xx/74HC595.pdf) 163 | (fields 164 | (field (name Reference) U) 165 | (field (name Value) 74HC595)) 166 | (pins 167 | (pin (num 1) (name QB) (type 3state)) 168 | (pin (num 2) (name QC) (type 3state)) 169 | (pin (num 3) (name QD) (type 3state)) 170 | (pin (num 4) (name QE) (type 3state)) 171 | (pin (num 5) (name QF) (type 3state)) 172 | (pin (num 6) (name QG) (type 3state)) 173 | (pin (num 7) (name QH) (type 3state)) 174 | (pin (num 8) (name GND) (type power_in)) 175 | (pin (num 9) (name ~QH) (type output)) 176 | (pin (num 10) (name SRCLR) (type input)) 177 | (pin (num 11) (name SRCLK) (type input)) 178 | (pin (num 12) (name RCLK) (type input)) 179 | (pin (num 13) (name G) (type input)) 180 | (pin (num 14) (name SER) (type input)) 181 | (pin (num 15) (name QA) (type 3state)) 182 | (pin (num 16) (name VCC) (type power_in)))) 183 | (libpart (lib device) (part C) 184 | (description "Unpolarized capacitor") 185 | (footprints 186 | (fp C?) 187 | (fp C_????_*) 188 | (fp C_????) 189 | (fp SMD*_c) 190 | (fp Capacitor*)) 191 | (fields 192 | (field (name Reference) C) 193 | (field (name Value) C)) 194 | (pins 195 | (pin (num 1) (name ~) (type passive)) 196 | (pin (num 2) (name ~) (type passive)))) 197 | (libpart (lib conn) (part CONN_01X02) 198 | (footprints 199 | (fp Pin_Header_Straight_1X02) 200 | (fp Pin_Header_Angled_1X02) 201 | (fp Socket_Strip_Straight_1X02) 202 | (fp Socket_Strip_Angled_1X02)) 203 | (fields 204 | (field (name Reference) P) 205 | (field (name Value) CONN_01X02)) 206 | (pins 207 | (pin (num 1) (name P1) (type passive)) 208 | (pin (num 2) (name P2) (type passive)))) 209 | (libpart (lib conn) (part CONN_01X05) 210 | (footprints 211 | (fp Pin_Header_Straight_1X05) 212 | (fp Pin_Header_Angled_1X05) 213 | (fp Socket_Strip_Straight_1X05) 214 | (fp Socket_Strip_Angled_1X05)) 215 | (fields 216 | (field (name Reference) P) 217 | (field (name Value) CONN_01X05)) 218 | (pins 219 | (pin (num 1) (name P1) (type passive)) 220 | (pin (num 2) (name P2) (type passive)) 221 | (pin (num 3) (name P3) (type passive)) 222 | (pin (num 4) (name P4) (type passive)) 223 | (pin (num 5) (name P5) (type passive)))) 224 | (libpart (lib conn) (part CONN_01X08) 225 | (footprints 226 | (fp Pin_Header_Straight_1X08) 227 | (fp Pin_Header_Angled_1X08) 228 | (fp Socket_Strip_Straight_1X08) 229 | (fp Socket_Strip_Angled_1X08)) 230 | (fields 231 | (field (name Reference) P) 232 | (field (name Value) CONN_01X08)) 233 | (pins 234 | (pin (num 1) (name P1) (type passive)) 235 | (pin (num 2) (name P2) (type passive)) 236 | (pin (num 3) (name P3) (type passive)) 237 | (pin (num 4) (name P4) (type passive)) 238 | (pin (num 5) (name P5) (type passive)) 239 | (pin (num 6) (name P6) (type passive)) 240 | (pin (num 7) (name P7) (type passive)) 241 | (pin (num 8) (name P8) (type passive)))) 242 | (libpart (lib conn) (part CONN_02X08) 243 | (footprints 244 | (fp Pin_Header_Straight_2X08) 245 | (fp Pin_Header_Angled_2X08) 246 | (fp Socket_Strip_Straight_2X08) 247 | (fp Socket_Strip_Angled_2X08)) 248 | (fields 249 | (field (name Reference) P) 250 | (field (name Value) CONN_02X08)) 251 | (pins 252 | (pin (num 1) (name P1) (type passive)) 253 | (pin (num 2) (name P2) (type passive)) 254 | (pin (num 3) (name P3) (type passive)) 255 | (pin (num 4) (name P4) (type passive)) 256 | (pin (num 5) (name P5) (type passive)) 257 | (pin (num 6) (name P6) (type passive)) 258 | (pin (num 7) (name P7) (type passive)) 259 | (pin (num 8) (name P8) (type passive)) 260 | (pin (num 9) (name P9) (type passive)) 261 | (pin (num 10) (name P10) (type passive)) 262 | (pin (num 11) (name P11) (type passive)) 263 | (pin (num 12) (name P12) (type passive)) 264 | (pin (num 13) (name P13) (type passive)) 265 | (pin (num 14) (name P14) (type passive)) 266 | (pin (num 15) (name P15) (type passive)) 267 | (pin (num 16) (name P16) (type passive))))) 268 | (libraries 269 | (library (logical device) 270 | (uri /usr/share/kicad/library/device.lib)) 271 | (library (logical conn) 272 | (uri /usr/share/kicad/library/conn.lib)) 273 | (library (logical 74xx) 274 | (uri /usr/share/kicad/library/74xx.lib))) 275 | (nets 276 | (net (code 1) (name /Q19) 277 | (node (ref P6) (pin 7)) 278 | (node (ref U3) (pin 3))) 279 | (net (code 2) (name /Q14) 280 | (node (ref P3) (pin 13)) 281 | (node (ref U2) (pin 6))) 282 | (net (code 3) (name /Q15) 283 | (node (ref U2) (pin 7)) 284 | (node (ref P3) (pin 15))) 285 | (net (code 4) (name /Q18) 286 | (node (ref U3) (pin 2)) 287 | (node (ref P6) (pin 5))) 288 | (net (code 5) (name /Q20) 289 | (node (ref U3) (pin 4)) 290 | (node (ref P6) (pin 9))) 291 | (net (code 6) (name /Q21) 292 | (node (ref P6) (pin 11)) 293 | (node (ref U3) (pin 5))) 294 | (net (code 7) (name /Q22) 295 | (node (ref P6) (pin 13)) 296 | (node (ref U3) (pin 6))) 297 | (net (code 8) (name /Q23) 298 | (node (ref P6) (pin 15)) 299 | (node (ref U3) (pin 7))) 300 | (net (code 9) (name /Q24) 301 | (node (ref P9) (pin 1)) 302 | (node (ref U4) (pin 15))) 303 | (net (code 10) (name /Q25) 304 | (node (ref P9) (pin 3)) 305 | (node (ref U4) (pin 1))) 306 | (net (code 11) (name /Q26) 307 | (node (ref U4) (pin 2)) 308 | (node (ref P9) (pin 5))) 309 | (net (code 12) (name /Q27) 310 | (node (ref P9) (pin 7)) 311 | (node (ref U4) (pin 3))) 312 | (net (code 13) (name /Q0) 313 | (node (ref U1) (pin 15)) 314 | (node (ref P1) (pin 1))) 315 | (net (code 14) (name /Q28) 316 | (node (ref U4) (pin 4)) 317 | (node (ref P9) (pin 9))) 318 | (net (code 15) (name /Q1) 319 | (node (ref P1) (pin 3)) 320 | (node (ref U1) (pin 1))) 321 | (net (code 16) (name /Q2) 322 | (node (ref P1) (pin 5)) 323 | (node (ref U1) (pin 2))) 324 | (net (code 17) (name /Q3) 325 | (node (ref U1) (pin 3)) 326 | (node (ref P1) (pin 7))) 327 | (net (code 18) (name /Q4) 328 | (node (ref U1) (pin 4)) 329 | (node (ref P1) (pin 9))) 330 | (net (code 19) (name /Q29) 331 | (node (ref P9) (pin 11)) 332 | (node (ref U4) (pin 5))) 333 | (net (code 20) (name /Q30) 334 | (node (ref P9) (pin 13)) 335 | (node (ref U4) (pin 6))) 336 | (net (code 21) (name /Q31) 337 | (node (ref U4) (pin 7)) 338 | (node (ref P9) (pin 15))) 339 | (net (code 22) (name VPP) 340 | (node (ref P8) (pin 3)) 341 | (node (ref P8) (pin 1)) 342 | (node (ref P8) (pin 2)) 343 | (node (ref P8) (pin 4)) 344 | (node (ref P8) (pin 5)) 345 | (node (ref P8) (pin 6)) 346 | (node (ref P8) (pin 7)) 347 | (node (ref P8) (pin 8)) 348 | (node (ref P10) (pin 2)) 349 | (node (ref P10) (pin 1)) 350 | (node (ref P10) (pin 3)) 351 | (node (ref P10) (pin 5)) 352 | (node (ref P10) (pin 6)) 353 | (node (ref P10) (pin 7)) 354 | (node (ref P10) (pin 8)) 355 | (node (ref P10) (pin 4)) 356 | (node (ref C6) (pin 1)) 357 | (node (ref P4) (pin 6)) 358 | (node (ref P4) (pin 7)) 359 | (node (ref P2) (pin 6)) 360 | (node (ref P4) (pin 8)) 361 | (node (ref P2) (pin 4)) 362 | (node (ref C5) (pin 1)) 363 | (node (ref P2) (pin 8)) 364 | (node (ref C7) (pin 1)) 365 | (node (ref C8) (pin 1)) 366 | (node (ref P2) (pin 1)) 367 | (node (ref P2) (pin 7)) 368 | (node (ref P4) (pin 3)) 369 | (node (ref P4) (pin 2)) 370 | (node (ref P2) (pin 2)) 371 | (node (ref P2) (pin 3)) 372 | (node (ref P4) (pin 1)) 373 | (node (ref P11) (pin 1)) 374 | (node (ref P4) (pin 4)) 375 | (node (ref P2) (pin 5)) 376 | (node (ref P4) (pin 5))) 377 | (net (code 23) (name /Q16) 378 | (node (ref U3) (pin 15)) 379 | (node (ref P6) (pin 1))) 380 | (net (code 24) (name /Q17) 381 | (node (ref P6) (pin 3)) 382 | (node (ref U3) (pin 1))) 383 | (net (code 25) (name GND) 384 | (node (ref U1) (pin 13)) 385 | (node (ref U1) (pin 8)) 386 | (node (ref U2) (pin 13)) 387 | (node (ref P3) (pin 16)) 388 | (node (ref P6) (pin 10)) 389 | (node (ref P3) (pin 12)) 390 | (node (ref P5) (pin 5)) 391 | (node (ref P3) (pin 10)) 392 | (node (ref P3) (pin 8)) 393 | (node (ref P3) (pin 6)) 394 | (node (ref U2) (pin 8)) 395 | (node (ref P3) (pin 14)) 396 | (node (ref P7) (pin 5)) 397 | (node (ref P3) (pin 2)) 398 | (node (ref P3) (pin 4)) 399 | (node (ref P1) (pin 10)) 400 | (node (ref P1) (pin 16)) 401 | (node (ref P1) (pin 14)) 402 | (node (ref P1) (pin 12)) 403 | (node (ref U4) (pin 8)) 404 | (node (ref U4) (pin 13)) 405 | (node (ref U3) (pin 8)) 406 | (node (ref U3) (pin 13)) 407 | (node (ref P9) (pin 12)) 408 | (node (ref P9) (pin 10)) 409 | (node (ref C1) (pin 2)) 410 | (node (ref P9) (pin 8)) 411 | (node (ref P9) (pin 6)) 412 | (node (ref P9) (pin 4)) 413 | (node (ref P9) (pin 2)) 414 | (node (ref P6) (pin 2)) 415 | (node (ref P1) (pin 8)) 416 | (node (ref P11) (pin 2)) 417 | (node (ref C2) (pin 2)) 418 | (node (ref C4) (pin 2)) 419 | (node (ref C3) (pin 2)) 420 | (node (ref C8) (pin 2)) 421 | (node (ref C7) (pin 2)) 422 | (node (ref C6) (pin 2)) 423 | (node (ref C5) (pin 2)) 424 | (node (ref P9) (pin 16)) 425 | (node (ref P6) (pin 14)) 426 | (node (ref P9) (pin 14)) 427 | (node (ref P1) (pin 6)) 428 | (node (ref P6) (pin 12)) 429 | (node (ref P1) (pin 4)) 430 | (node (ref P1) (pin 2)) 431 | (node (ref P6) (pin 4)) 432 | (node (ref P6) (pin 6)) 433 | (node (ref P6) (pin 8)) 434 | (node (ref P6) (pin 16))) 435 | (net (code 26) (name VCC) 436 | (node (ref C3) (pin 1)) 437 | (node (ref C4) (pin 1)) 438 | (node (ref U2) (pin 10)) 439 | (node (ref P5) (pin 1)) 440 | (node (ref U3) (pin 10)) 441 | (node (ref P7) (pin 1)) 442 | (node (ref U1) (pin 16)) 443 | (node (ref U4) (pin 16)) 444 | (node (ref U3) (pin 16)) 445 | (node (ref U1) (pin 10)) 446 | (node (ref C2) (pin 1)) 447 | (node (ref C1) (pin 1)) 448 | (node (ref U2) (pin 16)) 449 | (node (ref U4) (pin 10))) 450 | (net (code 27) (name "Net-(U2-Pad9)") 451 | (node (ref U2) (pin 9)) 452 | (node (ref U3) (pin 14))) 453 | (net (code 28) (name "Net-(U1-Pad9)") 454 | (node (ref U2) (pin 14)) 455 | (node (ref U1) (pin 9))) 456 | (net (code 29) (name "Net-(U3-Pad9)") 457 | (node (ref U3) (pin 9)) 458 | (node (ref U4) (pin 14))) 459 | (net (code 30) (name /SDI) 460 | (node (ref U1) (pin 14)) 461 | (node (ref P5) (pin 4))) 462 | (net (code 31) (name /WCK) 463 | (node (ref P5) (pin 3)) 464 | (node (ref U2) (pin 12)) 465 | (node (ref U4) (pin 12)) 466 | (node (ref P7) (pin 3)) 467 | (node (ref U1) (pin 12)) 468 | (node (ref U3) (pin 12))) 469 | (net (code 32) (name /BCK) 470 | (node (ref P7) (pin 2)) 471 | (node (ref P5) (pin 2)) 472 | (node (ref U2) (pin 11)) 473 | (node (ref U1) (pin 11)) 474 | (node (ref U4) (pin 11)) 475 | (node (ref U3) (pin 11))) 476 | (net (code 33) (name /Q8) 477 | (node (ref U2) (pin 15)) 478 | (node (ref P3) (pin 1))) 479 | (net (code 34) (name /Q9) 480 | (node (ref P3) (pin 3)) 481 | (node (ref U2) (pin 1))) 482 | (net (code 35) (name /Q5) 483 | (node (ref P1) (pin 11)) 484 | (node (ref U1) (pin 5))) 485 | (net (code 36) (name /Q6) 486 | (node (ref U1) (pin 6)) 487 | (node (ref P1) (pin 13))) 488 | (net (code 37) (name /Q7) 489 | (node (ref U1) (pin 7)) 490 | (node (ref P1) (pin 15))) 491 | (net (code 38) (name /Q10) 492 | (node (ref U2) (pin 2)) 493 | (node (ref P3) (pin 5))) 494 | (net (code 39) (name /Q11) 495 | (node (ref P3) (pin 7)) 496 | (node (ref U2) (pin 3))) 497 | (net (code 40) (name /Q12) 498 | (node (ref U2) (pin 4)) 499 | (node (ref P3) (pin 9))) 500 | (net (code 41) (name /Q13) 501 | (node (ref P3) (pin 11)) 502 | (node (ref U2) (pin 5))) 503 | (net (code 42) (name /SDO) 504 | (node (ref P7) (pin 4)) 505 | (node (ref U4) (pin 9))))) -------------------------------------------------------------------------------- /PCB/Shift-32/ESP12 Controller.pro: -------------------------------------------------------------------------------- 1 | update=Wed 09 Dec 2015 22:38:34 BRT 2 | version=1 3 | last_client=kicad 4 | [pcbnew] 5 | version=1 6 | LastNetListRead= 7 | UseCmpFile=1 8 | PadDrill=0.600000000000 9 | PadDrillOvalY=0.600000000000 10 | PadSizeH=1.500000000000 11 | PadSizeV=1.500000000000 12 | PcbTextSizeV=1.500000000000 13 | PcbTextSizeH=1.500000000000 14 | PcbTextThickness=0.300000000000 15 | ModuleTextSizeV=1.000000000000 16 | ModuleTextSizeH=1.000000000000 17 | ModuleTextSizeThickness=0.150000000000 18 | SolderMaskClearance=0.000000000000 19 | SolderMaskMinWidth=0.000000000000 20 | DrawSegmentWidth=0.200000000000 21 | BoardOutlineThickness=0.100000000000 22 | ModuleOutlineThickness=0.150000000000 23 | [cvpcb] 24 | version=1 25 | NetIExt=net 26 | [general] 27 | version=1 28 | [eeschema] 29 | version=1 30 | LibDir=../../lib/KiCAD/ESP8266;../../lib/KiCAD/ESP8266 31 | [eeschema/libraries] 32 | LibName1=power 33 | LibName2=device 34 | LibName3=transistors 35 | LibName4=conn 36 | LibName5=linear 37 | LibName6=regul 38 | LibName7=74xx 39 | LibName8=cmos4000 40 | LibName9=adc-dac 41 | LibName10=memory 42 | LibName11=xilinx 43 | LibName12=microcontrollers 44 | LibName13=dsp 45 | LibName14=microchip 46 | LibName15=analog_switches 47 | LibName16=motorola 48 | LibName17=texas 49 | LibName18=intel 50 | LibName19=audio 51 | LibName20=interface 52 | LibName21=digital-audio 53 | LibName22=philips 54 | LibName23=display 55 | LibName24=cypress 56 | LibName25=siliconi 57 | LibName26=opto 58 | LibName27=atmel 59 | LibName28=contrib 60 | LibName29=valves 61 | LibName30=/home/lucas.hartmann/Documentos/Projetos/lib/KiCAD/componentes 62 | LibName31=/home/lucas.hartmann/Documentos/Projetos/lib/KiCAD/ESP8266/ESP8266 63 | [schematic_editor] 64 | version=1 65 | PageLayoutDescrFile= 66 | PlotDirectoryName= 67 | SubpartIdSeparator=0 68 | SubpartFirstId=65 69 | NetFmtName= 70 | SpiceForceRefPrefix=0 71 | SpiceUseNetNumbers=0 72 | LabSize=60 73 | -------------------------------------------------------------------------------- /PCB/Shift-32/Esquema e placa.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhartmann/esp8266_reprap/46653d8ec498c8fa382bd2c672f4d8cea946bc49/PCB/Shift-32/Esquema e placa.pdf -------------------------------------------------------------------------------- /PCB/Shift-32/GERBER/ESP12 Controller-B.Cu.gbr: -------------------------------------------------------------------------------- 1 | G04 #@! TF.FileFunction,Copper,L2,Bot,Signal* 2 | %FSLAX46Y46*% 3 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 4 | G04 Created by KiCad (PCBNEW 4.0.0-rc2-stable) date Tue 17 Nov 2015 13:54:05 BRT* 5 | %MOMM*% 6 | G01* 7 | G04 APERTURE LIST* 8 | %ADD10C,0.100000*% 9 | %ADD11R,1.727200X1.727200*% 10 | %ADD12O,1.727200X1.727200*% 11 | %ADD13R,1.727200X2.032000*% 12 | %ADD14O,1.727200X2.032000*% 13 | %ADD15R,2.032000X1.727200*% 14 | %ADD16O,2.032000X1.727200*% 15 | %ADD17R,2.032000X2.032000*% 16 | %ADD18O,2.032000X2.032000*% 17 | %ADD19C,1.300000*% 18 | %ADD20C,1.000000*% 19 | %ADD21C,0.350000*% 20 | G04 APERTURE END LIST* 21 | D10* 22 | D11* 23 | X157480000Y-53340000D03* 24 | D12* 25 | X157480000Y-55880000D03* 26 | X160020000Y-53340000D03* 27 | X160020000Y-55880000D03* 28 | X162560000Y-53340000D03* 29 | X162560000Y-55880000D03* 30 | X165100000Y-53340000D03* 31 | X165100000Y-55880000D03* 32 | X167640000Y-53340000D03* 33 | X167640000Y-55880000D03* 34 | X170180000Y-53340000D03* 35 | X170180000Y-55880000D03* 36 | X172720000Y-53340000D03* 37 | X172720000Y-55880000D03* 38 | X175260000Y-53340000D03* 39 | X175260000Y-55880000D03* 40 | D13* 41 | X157480000Y-58420000D03* 42 | D14* 43 | X160020000Y-58420000D03* 44 | X162560000Y-58420000D03* 45 | X165100000Y-58420000D03* 46 | X167640000Y-58420000D03* 47 | X170180000Y-58420000D03* 48 | X172720000Y-58420000D03* 49 | X175260000Y-58420000D03* 50 | D11* 51 | X185420000Y-53340000D03* 52 | D12* 53 | X185420000Y-55880000D03* 54 | X187960000Y-53340000D03* 55 | X187960000Y-55880000D03* 56 | X190500000Y-53340000D03* 57 | X190500000Y-55880000D03* 58 | X193040000Y-53340000D03* 59 | X193040000Y-55880000D03* 60 | X195580000Y-53340000D03* 61 | X195580000Y-55880000D03* 62 | X198120000Y-53340000D03* 63 | X198120000Y-55880000D03* 64 | X200660000Y-53340000D03* 65 | X200660000Y-55880000D03* 66 | X203200000Y-53340000D03* 67 | X203200000Y-55880000D03* 68 | D13* 69 | X185420000Y-58420000D03* 70 | D14* 71 | X187960000Y-58420000D03* 72 | X190500000Y-58420000D03* 73 | X193040000Y-58420000D03* 74 | X195580000Y-58420000D03* 75 | X198120000Y-58420000D03* 76 | X200660000Y-58420000D03* 77 | X203200000Y-58420000D03* 78 | D15* 79 | X152400000Y-30480000D03* 80 | D16* 81 | X152400000Y-33020000D03* 82 | X152400000Y-35560000D03* 83 | X152400000Y-38100000D03* 84 | X152400000Y-40640000D03* 85 | D11* 86 | X213360000Y-53340000D03* 87 | D12* 88 | X213360000Y-55880000D03* 89 | X215900000Y-53340000D03* 90 | X215900000Y-55880000D03* 91 | X218440000Y-53340000D03* 92 | X218440000Y-55880000D03* 93 | X220980000Y-53340000D03* 94 | X220980000Y-55880000D03* 95 | X223520000Y-53340000D03* 96 | X223520000Y-55880000D03* 97 | X226060000Y-53340000D03* 98 | X226060000Y-55880000D03* 99 | X228600000Y-53340000D03* 100 | X228600000Y-55880000D03* 101 | X231140000Y-53340000D03* 102 | X231140000Y-55880000D03* 103 | D15* 104 | X264160000Y-30480000D03* 105 | D16* 106 | X264160000Y-33020000D03* 107 | X264160000Y-35560000D03* 108 | X264160000Y-38100000D03* 109 | X264160000Y-40640000D03* 110 | D13* 111 | X213360000Y-58420000D03* 112 | D14* 113 | X215900000Y-58420000D03* 114 | X218440000Y-58420000D03* 115 | X220980000Y-58420000D03* 116 | X223520000Y-58420000D03* 117 | X226060000Y-58420000D03* 118 | X228600000Y-58420000D03* 119 | X231140000Y-58420000D03* 120 | D11* 121 | X241300000Y-53340000D03* 122 | D12* 123 | X241300000Y-55880000D03* 124 | X243840000Y-53340000D03* 125 | X243840000Y-55880000D03* 126 | X246380000Y-53340000D03* 127 | X246380000Y-55880000D03* 128 | X248920000Y-53340000D03* 129 | X248920000Y-55880000D03* 130 | X251460000Y-53340000D03* 131 | X251460000Y-55880000D03* 132 | X254000000Y-53340000D03* 133 | X254000000Y-55880000D03* 134 | X256540000Y-53340000D03* 135 | X256540000Y-55880000D03* 136 | X259080000Y-53340000D03* 137 | X259080000Y-55880000D03* 138 | D13* 139 | X241300000Y-58420000D03* 140 | D14* 141 | X243840000Y-58420000D03* 142 | X246380000Y-58420000D03* 143 | X248920000Y-58420000D03* 144 | X251460000Y-58420000D03* 145 | X254000000Y-58420000D03* 146 | X256540000Y-58420000D03* 147 | X259080000Y-58420000D03* 148 | D17* 149 | X264160000Y-55880000D03* 150 | D18* 151 | X264160000Y-53340000D03* 152 | D19* 153 | X242570000Y-30480000D03* 154 | X242570000Y-39370000D03* 155 | X214630000Y-30480000D03* 156 | X214630000Y-39370000D03* 157 | X186690000Y-30480000D03* 158 | X186690000Y-39370000D03* 159 | X158750000Y-30480000D03* 160 | X158750000Y-39370000D03* 161 | X259080000Y-36830000D03* 162 | X261739658Y-39489658D03* 163 | X193040000Y-31980010D03* 164 | X193040000Y-36830000D03* 165 | X220980000Y-31980010D03* 166 | X220980000Y-36830000D03* 167 | X248920000Y-31980010D03* 168 | X248920000Y-36830000D03* 169 | D20* 170 | X242570000Y-39370000D02* 171 | X242570000Y-30480000D01* 172 | X214630000Y-39370000D02* 173 | X214630000Y-30480000D01* 174 | X186690000Y-39370000D02* 175 | X186690000Y-30480000D01* 176 | X158750000Y-39370000D02* 177 | X158750000Y-30480000D01* 178 | D21* 179 | X261739658Y-39489658D02* 180 | X259080000Y-36830000D01* 181 | X193040000Y-36830000D02* 182 | X193040000Y-31980010D01* 183 | X220980000Y-36830000D02* 184 | X220980000Y-31980010D01* 185 | X248920000Y-36830000D02* 186 | X248920000Y-31980010D01* 187 | M02* 188 | -------------------------------------------------------------------------------- /PCB/Shift-32/GERBER/ESP12 Controller-B.SilkS.gbr: -------------------------------------------------------------------------------- 1 | G04 #@! TF.FileFunction,Legend,Bot* 2 | %FSLAX46Y46*% 3 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 4 | G04 Created by KiCad (PCBNEW 4.0.0-rc2-stable) date Tue 17 Nov 2015 13:49:37 BRT* 5 | %MOMM*% 6 | G01* 7 | G04 APERTURE LIST* 8 | %ADD10C,0.100000*% 9 | G04 APERTURE END LIST* 10 | D10* 11 | M02* 12 | -------------------------------------------------------------------------------- /PCB/Shift-32/GERBER/ESP12 Controller-Edge.Cuts.gbr: -------------------------------------------------------------------------------- 1 | G04 #@! TF.FileFunction,Profile,NP* 2 | %FSLAX46Y46*% 3 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 4 | G04 Created by KiCad (PCBNEW 4.0.0-rc2-stable) date Tue 17 Nov 2015 13:54:05 BRT* 5 | %MOMM*% 6 | G01* 7 | G04 APERTURE LIST* 8 | %ADD10C,0.100000*% 9 | %ADD11C,0.150000*% 10 | G04 APERTURE END LIST* 11 | D10* 12 | D11* 13 | X149860000Y-27940000D02* 14 | X266700000Y-27940000D01* 15 | X149860000Y-60960000D02* 16 | X149860000Y-27940000D01* 17 | X266700000Y-60960000D02* 18 | X149860000Y-60960000D01* 19 | X266700000Y-27940000D02* 20 | X266700000Y-60960000D01* 21 | M02* 22 | -------------------------------------------------------------------------------- /PCB/Shift-32/GERBER/ESP12 Controller-F.SilkS.gbr: -------------------------------------------------------------------------------- 1 | G04 #@! TF.FileFunction,Legend,Top* 2 | %FSLAX46Y46*% 3 | G04 Gerber Fmt 4.6, Leading zero omitted, Abs format (unit mm)* 4 | G04 Created by KiCad (PCBNEW 4.0.0-rc2-stable) date Tue 17 Nov 2015 13:49:37 BRT* 5 | %MOMM*% 6 | G01* 7 | G04 APERTURE LIST* 8 | %ADD10C,0.100000*% 9 | %ADD11C,0.150000*% 10 | G04 APERTURE END LIST* 11 | D10* 12 | D11* 13 | X215400000Y-37680000D02* 14 | X216400000Y-37680000D01* 15 | X216400000Y-35980000D02* 16 | X215400000Y-35980000D01* 17 | X159540000Y-37680000D02* 18 | X160540000Y-37680000D01* 19 | X160540000Y-35980000D02* 20 | X159540000Y-35980000D01* 21 | X187440000Y-37680000D02* 22 | X188440000Y-37680000D01* 23 | X188440000Y-35980000D02* 24 | X187440000Y-35980000D01* 25 | X243340000Y-37680000D02* 26 | X244340000Y-37680000D01* 27 | X244340000Y-35980000D02* 28 | X243340000Y-35980000D01* 29 | X207430000Y-56650000D02* 30 | X207430000Y-57650000D01* 31 | X209130000Y-57650000D02* 32 | X209130000Y-56650000D01* 33 | X152820000Y-56630000D02* 34 | X152820000Y-57630000D01* 35 | X154520000Y-57630000D02* 36 | X154520000Y-56630000D01* 37 | X179490000Y-56650000D02* 38 | X179490000Y-57650000D01* 39 | X181190000Y-57650000D02* 40 | X181190000Y-56650000D01* 41 | X235370000Y-56650000D02* 42 | X235370000Y-57650000D01* 43 | X237070000Y-57650000D02* 44 | X237070000Y-56650000D01* 45 | X176530000Y-57150000D02* 46 | X156210000Y-57150000D01* 47 | X158750000Y-52070000D02* 48 | X176530000Y-52070000D01* 49 | X176530000Y-57150000D02* 50 | X176530000Y-52070000D01* 51 | X156210000Y-57150000D02* 52 | X156210000Y-54610000D01* 53 | X157480000Y-51790000D02* 54 | X155930000Y-51790000D01* 55 | X156210000Y-54610000D02* 56 | X158750000Y-54610000D01* 57 | X158750000Y-54610000D02* 58 | X158750000Y-52070000D01* 59 | X155930000Y-51790000D02* 60 | X155930000Y-53340000D01* 61 | X158750000Y-59690000D02* 62 | X176530000Y-59690000D01* 63 | X176530000Y-59690000D02* 64 | X176530000Y-57150000D01* 65 | X176530000Y-57150000D02* 66 | X158750000Y-57150000D01* 67 | X155930000Y-59970000D02* 68 | X157480000Y-59970000D01* 69 | X158750000Y-59690000D02* 70 | X158750000Y-57150000D01* 71 | X157480000Y-56870000D02* 72 | X155930000Y-56870000D01* 73 | X155930000Y-56870000D02* 74 | X155930000Y-59970000D01* 75 | X204470000Y-57150000D02* 76 | X184150000Y-57150000D01* 77 | X186690000Y-52070000D02* 78 | X204470000Y-52070000D01* 79 | X204470000Y-57150000D02* 80 | X204470000Y-52070000D01* 81 | X184150000Y-57150000D02* 82 | X184150000Y-54610000D01* 83 | X185420000Y-51790000D02* 84 | X183870000Y-51790000D01* 85 | X184150000Y-54610000D02* 86 | X186690000Y-54610000D01* 87 | X186690000Y-54610000D02* 88 | X186690000Y-52070000D01* 89 | X183870000Y-51790000D02* 90 | X183870000Y-53340000D01* 91 | X186690000Y-59690000D02* 92 | X204470000Y-59690000D01* 93 | X204470000Y-59690000D02* 94 | X204470000Y-57150000D01* 95 | X204470000Y-57150000D02* 96 | X186690000Y-57150000D01* 97 | X183870000Y-59970000D02* 98 | X185420000Y-59970000D01* 99 | X186690000Y-59690000D02* 100 | X186690000Y-57150000D01* 101 | X185420000Y-56870000D02* 102 | X183870000Y-56870000D01* 103 | X183870000Y-56870000D02* 104 | X183870000Y-59970000D01* 105 | X151130000Y-31750000D02* 106 | X151130000Y-41910000D01* 107 | X151130000Y-41910000D02* 108 | X153670000Y-41910000D01* 109 | X153670000Y-41910000D02* 110 | X153670000Y-31750000D01* 111 | X150850000Y-28930000D02* 112 | X150850000Y-30480000D01* 113 | X151130000Y-31750000D02* 114 | X153670000Y-31750000D01* 115 | X153950000Y-30480000D02* 116 | X153950000Y-28930000D01* 117 | X153950000Y-28930000D02* 118 | X150850000Y-28930000D01* 119 | X232410000Y-57150000D02* 120 | X212090000Y-57150000D01* 121 | X214630000Y-52070000D02* 122 | X232410000Y-52070000D01* 123 | X232410000Y-57150000D02* 124 | X232410000Y-52070000D01* 125 | X212090000Y-57150000D02* 126 | X212090000Y-54610000D01* 127 | X213360000Y-51790000D02* 128 | X211810000Y-51790000D01* 129 | X212090000Y-54610000D02* 130 | X214630000Y-54610000D01* 131 | X214630000Y-54610000D02* 132 | X214630000Y-52070000D01* 133 | X211810000Y-51790000D02* 134 | X211810000Y-53340000D01* 135 | X262890000Y-31750000D02* 136 | X262890000Y-41910000D01* 137 | X262890000Y-41910000D02* 138 | X265430000Y-41910000D01* 139 | X265430000Y-41910000D02* 140 | X265430000Y-31750000D01* 141 | X262610000Y-28930000D02* 142 | X262610000Y-30480000D01* 143 | X262890000Y-31750000D02* 144 | X265430000Y-31750000D01* 145 | X265710000Y-30480000D02* 146 | X265710000Y-28930000D01* 147 | X265710000Y-28930000D02* 148 | X262610000Y-28930000D01* 149 | X214630000Y-59690000D02* 150 | X232410000Y-59690000D01* 151 | X232410000Y-59690000D02* 152 | X232410000Y-57150000D01* 153 | X232410000Y-57150000D02* 154 | X214630000Y-57150000D01* 155 | X211810000Y-59970000D02* 156 | X213360000Y-59970000D01* 157 | X214630000Y-59690000D02* 158 | X214630000Y-57150000D01* 159 | X213360000Y-56870000D02* 160 | X211810000Y-56870000D01* 161 | X211810000Y-56870000D02* 162 | X211810000Y-59970000D01* 163 | X260350000Y-57150000D02* 164 | X240030000Y-57150000D01* 165 | X242570000Y-52070000D02* 166 | X260350000Y-52070000D01* 167 | X260350000Y-57150000D02* 168 | X260350000Y-52070000D01* 169 | X240030000Y-57150000D02* 170 | X240030000Y-54610000D01* 171 | X241300000Y-51790000D02* 172 | X239750000Y-51790000D01* 173 | X240030000Y-54610000D02* 174 | X242570000Y-54610000D01* 175 | X242570000Y-54610000D02* 176 | X242570000Y-52070000D01* 177 | X239750000Y-51790000D02* 178 | X239750000Y-53340000D01* 179 | X242570000Y-59690000D02* 180 | X260350000Y-59690000D01* 181 | X260350000Y-59690000D02* 182 | X260350000Y-57150000D01* 183 | X260350000Y-57150000D02* 184 | X242570000Y-57150000D01* 185 | X239750000Y-59970000D02* 186 | X241300000Y-59970000D01* 187 | X242570000Y-59690000D02* 188 | X242570000Y-57150000D01* 189 | X241300000Y-56870000D02* 190 | X239750000Y-56870000D01* 191 | X239750000Y-56870000D02* 192 | X239750000Y-59970000D01* 193 | X161417000Y-41783000D02* 194 | X162179000Y-41783000D01* 195 | X162179000Y-41783000D02* 196 | X162179000Y-43307000D01* 197 | X162179000Y-43307000D02* 198 | X161417000Y-43307000D01* 199 | X172593000Y-40259000D02* 200 | X172593000Y-44831000D01* 201 | X172593000Y-44831000D02* 202 | X161417000Y-44831000D01* 203 | X161417000Y-44831000D02* 204 | X161417000Y-40259000D01* 205 | X161417000Y-40259000D02* 206 | X172593000Y-40259000D01* 207 | X189357000Y-41783000D02* 208 | X190119000Y-41783000D01* 209 | X190119000Y-41783000D02* 210 | X190119000Y-43307000D01* 211 | X190119000Y-43307000D02* 212 | X189357000Y-43307000D01* 213 | X200533000Y-40259000D02* 214 | X200533000Y-44831000D01* 215 | X200533000Y-44831000D02* 216 | X189357000Y-44831000D01* 217 | X189357000Y-44831000D02* 218 | X189357000Y-40259000D01* 219 | X189357000Y-40259000D02* 220 | X200533000Y-40259000D01* 221 | X217297000Y-41783000D02* 222 | X218059000Y-41783000D01* 223 | X218059000Y-41783000D02* 224 | X218059000Y-43307000D01* 225 | X218059000Y-43307000D02* 226 | X217297000Y-43307000D01* 227 | X228473000Y-40259000D02* 228 | X228473000Y-44831000D01* 229 | X228473000Y-44831000D02* 230 | X217297000Y-44831000D01* 231 | X217297000Y-44831000D02* 232 | X217297000Y-40259000D01* 233 | X217297000Y-40259000D02* 234 | X228473000Y-40259000D01* 235 | X245237000Y-41783000D02* 236 | X245999000Y-41783000D01* 237 | X245999000Y-41783000D02* 238 | X245999000Y-43307000D01* 239 | X245999000Y-43307000D02* 240 | X245237000Y-43307000D01* 241 | X256413000Y-40259000D02* 242 | X256413000Y-44831000D01* 243 | X256413000Y-44831000D02* 244 | X245237000Y-44831000D01* 245 | X245237000Y-44831000D02* 246 | X245237000Y-40259000D01* 247 | X245237000Y-40259000D02* 248 | X256413000Y-40259000D01* 249 | X265710000Y-57430000D02* 250 | X265710000Y-55880000D01* 251 | X265430000Y-52070000D02* 252 | X265430000Y-54610000D01* 253 | X265430000Y-54610000D02* 254 | X262890000Y-54610000D01* 255 | X262610000Y-55880000D02* 256 | X262610000Y-57430000D01* 257 | X262610000Y-57430000D02* 258 | X265710000Y-57430000D01* 259 | X262890000Y-54610000D02* 260 | X262890000Y-52070000D01* 261 | X262890000Y-52070000D02* 262 | X265430000Y-52070000D01* 263 | X215733334Y-39287143D02* 264 | X215685715Y-39334762D01* 265 | X215542858Y-39382381D01* 266 | X215447620Y-39382381D01* 267 | X215304762Y-39334762D01* 268 | X215209524Y-39239524D01* 269 | X215161905Y-39144286D01* 270 | X215114286Y-38953810D01* 271 | X215114286Y-38810952D01* 272 | X215161905Y-38620476D01* 273 | X215209524Y-38525238D01* 274 | X215304762Y-38430000D01* 275 | X215447620Y-38382381D01* 276 | X215542858Y-38382381D01* 277 | X215685715Y-38430000D01* 278 | X215733334Y-38477619D01* 279 | X216685715Y-39382381D02* 280 | X216114286Y-39382381D01* 281 | X216400000Y-39382381D02* 282 | X216400000Y-38382381D01* 283 | X216304762Y-38525238D01* 284 | X216209524Y-38620476D01* 285 | X216114286Y-38668095D01* 286 | X159873334Y-39287143D02* 287 | X159825715Y-39334762D01* 288 | X159682858Y-39382381D01* 289 | X159587620Y-39382381D01* 290 | X159444762Y-39334762D01* 291 | X159349524Y-39239524D01* 292 | X159301905Y-39144286D01* 293 | X159254286Y-38953810D01* 294 | X159254286Y-38810952D01* 295 | X159301905Y-38620476D01* 296 | X159349524Y-38525238D01* 297 | X159444762Y-38430000D01* 298 | X159587620Y-38382381D01* 299 | X159682858Y-38382381D01* 300 | X159825715Y-38430000D01* 301 | X159873334Y-38477619D01* 302 | X160254286Y-38477619D02* 303 | X160301905Y-38430000D01* 304 | X160397143Y-38382381D01* 305 | X160635239Y-38382381D01* 306 | X160730477Y-38430000D01* 307 | X160778096Y-38477619D01* 308 | X160825715Y-38572857D01* 309 | X160825715Y-38668095D01* 310 | X160778096Y-38810952D01* 311 | X160206667Y-39382381D01* 312 | X160825715Y-39382381D01* 313 | X187773334Y-39287143D02* 314 | X187725715Y-39334762D01* 315 | X187582858Y-39382381D01* 316 | X187487620Y-39382381D01* 317 | X187344762Y-39334762D01* 318 | X187249524Y-39239524D01* 319 | X187201905Y-39144286D01* 320 | X187154286Y-38953810D01* 321 | X187154286Y-38810952D01* 322 | X187201905Y-38620476D01* 323 | X187249524Y-38525238D01* 324 | X187344762Y-38430000D01* 325 | X187487620Y-38382381D01* 326 | X187582858Y-38382381D01* 327 | X187725715Y-38430000D01* 328 | X187773334Y-38477619D01* 329 | X188106667Y-38382381D02* 330 | X188725715Y-38382381D01* 331 | X188392381Y-38763333D01* 332 | X188535239Y-38763333D01* 333 | X188630477Y-38810952D01* 334 | X188678096Y-38858571D01* 335 | X188725715Y-38953810D01* 336 | X188725715Y-39191905D01* 337 | X188678096Y-39287143D01* 338 | X188630477Y-39334762D01* 339 | X188535239Y-39382381D01* 340 | X188249524Y-39382381D01* 341 | X188154286Y-39334762D01* 342 | X188106667Y-39287143D01* 343 | X243673334Y-39287143D02* 344 | X243625715Y-39334762D01* 345 | X243482858Y-39382381D01* 346 | X243387620Y-39382381D01* 347 | X243244762Y-39334762D01* 348 | X243149524Y-39239524D01* 349 | X243101905Y-39144286D01* 350 | X243054286Y-38953810D01* 351 | X243054286Y-38810952D01* 352 | X243101905Y-38620476D01* 353 | X243149524Y-38525238D01* 354 | X243244762Y-38430000D01* 355 | X243387620Y-38382381D01* 356 | X243482858Y-38382381D01* 357 | X243625715Y-38430000D01* 358 | X243673334Y-38477619D01* 359 | X244530477Y-38715714D02* 360 | X244530477Y-39382381D01* 361 | X244292381Y-38334762D02* 362 | X244054286Y-39049048D01* 363 | X244673334Y-39049048D01* 364 | X206537143Y-57316666D02* 365 | X206584762Y-57364285D01* 366 | X206632381Y-57507142D01* 367 | X206632381Y-57602380D01* 368 | X206584762Y-57745238D01* 369 | X206489524Y-57840476D01* 370 | X206394286Y-57888095D01* 371 | X206203810Y-57935714D01* 372 | X206060952Y-57935714D01* 373 | X205870476Y-57888095D01* 374 | X205775238Y-57840476D01* 375 | X205680000Y-57745238D01* 376 | X205632381Y-57602380D01* 377 | X205632381Y-57507142D01* 378 | X205680000Y-57364285D01* 379 | X205727619Y-57316666D01* 380 | X205632381Y-56411904D02* 381 | X205632381Y-56888095D01* 382 | X206108571Y-56935714D01* 383 | X206060952Y-56888095D01* 384 | X206013333Y-56792857D01* 385 | X206013333Y-56554761D01* 386 | X206060952Y-56459523D01* 387 | X206108571Y-56411904D01* 388 | X206203810Y-56364285D01* 389 | X206441905Y-56364285D01* 390 | X206537143Y-56411904D01* 391 | X206584762Y-56459523D01* 392 | X206632381Y-56554761D01* 393 | X206632381Y-56792857D01* 394 | X206584762Y-56888095D01* 395 | X206537143Y-56935714D01* 396 | X151927143Y-57296666D02* 397 | X151974762Y-57344285D01* 398 | X152022381Y-57487142D01* 399 | X152022381Y-57582380D01* 400 | X151974762Y-57725238D01* 401 | X151879524Y-57820476D01* 402 | X151784286Y-57868095D01* 403 | X151593810Y-57915714D01* 404 | X151450952Y-57915714D01* 405 | X151260476Y-57868095D01* 406 | X151165238Y-57820476D01* 407 | X151070000Y-57725238D01* 408 | X151022381Y-57582380D01* 409 | X151022381Y-57487142D01* 410 | X151070000Y-57344285D01* 411 | X151117619Y-57296666D01* 412 | X151022381Y-56439523D02* 413 | X151022381Y-56630000D01* 414 | X151070000Y-56725238D01* 415 | X151117619Y-56772857D01* 416 | X151260476Y-56868095D01* 417 | X151450952Y-56915714D01* 418 | X151831905Y-56915714D01* 419 | X151927143Y-56868095D01* 420 | X151974762Y-56820476D01* 421 | X152022381Y-56725238D01* 422 | X152022381Y-56534761D01* 423 | X151974762Y-56439523D01* 424 | X151927143Y-56391904D01* 425 | X151831905Y-56344285D01* 426 | X151593810Y-56344285D01* 427 | X151498571Y-56391904D01* 428 | X151450952Y-56439523D01* 429 | X151403333Y-56534761D01* 430 | X151403333Y-56725238D01* 431 | X151450952Y-56820476D01* 432 | X151498571Y-56868095D01* 433 | X151593810Y-56915714D01* 434 | X178597143Y-57316666D02* 435 | X178644762Y-57364285D01* 436 | X178692381Y-57507142D01* 437 | X178692381Y-57602380D01* 438 | X178644762Y-57745238D01* 439 | X178549524Y-57840476D01* 440 | X178454286Y-57888095D01* 441 | X178263810Y-57935714D01* 442 | X178120952Y-57935714D01* 443 | X177930476Y-57888095D01* 444 | X177835238Y-57840476D01* 445 | X177740000Y-57745238D01* 446 | X177692381Y-57602380D01* 447 | X177692381Y-57507142D01* 448 | X177740000Y-57364285D01* 449 | X177787619Y-57316666D01* 450 | X177692381Y-56983333D02* 451 | X177692381Y-56316666D01* 452 | X178692381Y-56745238D01* 453 | X234477143Y-57316666D02* 454 | X234524762Y-57364285D01* 455 | X234572381Y-57507142D01* 456 | X234572381Y-57602380D01* 457 | X234524762Y-57745238D01* 458 | X234429524Y-57840476D01* 459 | X234334286Y-57888095D01* 460 | X234143810Y-57935714D01* 461 | X234000952Y-57935714D01* 462 | X233810476Y-57888095D01* 463 | X233715238Y-57840476D01* 464 | X233620000Y-57745238D01* 465 | X233572381Y-57602380D01* 466 | X233572381Y-57507142D01* 467 | X233620000Y-57364285D01* 468 | X233667619Y-57316666D01* 469 | X234000952Y-56745238D02* 470 | X233953333Y-56840476D01* 471 | X233905714Y-56888095D01* 472 | X233810476Y-56935714D01* 473 | X233762857Y-56935714D01* 474 | X233667619Y-56888095D01* 475 | X233620000Y-56840476D01* 476 | X233572381Y-56745238D01* 477 | X233572381Y-56554761D01* 478 | X233620000Y-56459523D01* 479 | X233667619Y-56411904D01* 480 | X233762857Y-56364285D01* 481 | X233810476Y-56364285D01* 482 | X233905714Y-56411904D01* 483 | X233953333Y-56459523D01* 484 | X234000952Y-56554761D01* 485 | X234000952Y-56745238D01* 486 | X234048571Y-56840476D01* 487 | X234096190Y-56888095D01* 488 | X234191429Y-56935714D01* 489 | X234381905Y-56935714D01* 490 | X234477143Y-56888095D01* 491 | X234524762Y-56840476D01* 492 | X234572381Y-56745238D01* 493 | X234572381Y-56554761D01* 494 | X234524762Y-56459523D01* 495 | X234477143Y-56411904D01* 496 | X234381905Y-56364285D01* 497 | X234191429Y-56364285D01* 498 | X234096190Y-56411904D01* 499 | X234048571Y-56459523D01* 500 | X234000952Y-56554761D01* 501 | X156741905Y-48692381D02* 502 | X156741905Y-47692381D01* 503 | X157122858Y-47692381D01* 504 | X157218096Y-47740000D01* 505 | X157265715Y-47787619D01* 506 | X157313334Y-47882857D01* 507 | X157313334Y-48025714D01* 508 | X157265715Y-48120952D01* 509 | X157218096Y-48168571D01* 510 | X157122858Y-48216190D01* 511 | X156741905Y-48216190D01* 512 | X158265715Y-48692381D02* 513 | X157694286Y-48692381D01* 514 | X157980000Y-48692381D02* 515 | X157980000Y-47692381D01* 516 | X157884762Y-47835238D01* 517 | X157789524Y-47930476D01* 518 | X157694286Y-47978095D01* 519 | X156741905Y-53772381D02* 520 | X156741905Y-52772381D01* 521 | X157122858Y-52772381D01* 522 | X157218096Y-52820000D01* 523 | X157265715Y-52867619D01* 524 | X157313334Y-52962857D01* 525 | X157313334Y-53105714D01* 526 | X157265715Y-53200952D01* 527 | X157218096Y-53248571D01* 528 | X157122858Y-53296190D01* 529 | X156741905Y-53296190D01* 530 | X157694286Y-52867619D02* 531 | X157741905Y-52820000D01* 532 | X157837143Y-52772381D01* 533 | X158075239Y-52772381D01* 534 | X158170477Y-52820000D01* 535 | X158218096Y-52867619D01* 536 | X158265715Y-52962857D01* 537 | X158265715Y-53058095D01* 538 | X158218096Y-53200952D01* 539 | X157646667Y-53772381D01* 540 | X158265715Y-53772381D01* 541 | X184681905Y-48692381D02* 542 | X184681905Y-47692381D01* 543 | X185062858Y-47692381D01* 544 | X185158096Y-47740000D01* 545 | X185205715Y-47787619D01* 546 | X185253334Y-47882857D01* 547 | X185253334Y-48025714D01* 548 | X185205715Y-48120952D01* 549 | X185158096Y-48168571D01* 550 | X185062858Y-48216190D01* 551 | X184681905Y-48216190D01* 552 | X185586667Y-47692381D02* 553 | X186205715Y-47692381D01* 554 | X185872381Y-48073333D01* 555 | X186015239Y-48073333D01* 556 | X186110477Y-48120952D01* 557 | X186158096Y-48168571D01* 558 | X186205715Y-48263810D01* 559 | X186205715Y-48501905D01* 560 | X186158096Y-48597143D01* 561 | X186110477Y-48644762D01* 562 | X186015239Y-48692381D01* 563 | X185729524Y-48692381D01* 564 | X185634286Y-48644762D01* 565 | X185586667Y-48597143D01* 566 | X184681905Y-53772381D02* 567 | X184681905Y-52772381D01* 568 | X185062858Y-52772381D01* 569 | X185158096Y-52820000D01* 570 | X185205715Y-52867619D01* 571 | X185253334Y-52962857D01* 572 | X185253334Y-53105714D01* 573 | X185205715Y-53200952D01* 574 | X185158096Y-53248571D01* 575 | X185062858Y-53296190D01* 576 | X184681905Y-53296190D01* 577 | X186110477Y-53105714D02* 578 | X186110477Y-53772381D01* 579 | X185872381Y-52724762D02* 580 | X185634286Y-53439048D01* 581 | X186253334Y-53439048D01* 582 | X157952381Y-31218095D02* 583 | X156952381Y-31218095D01* 584 | X156952381Y-30837142D01* 585 | X157000000Y-30741904D01* 586 | X157047619Y-30694285D01* 587 | X157142857Y-30646666D01* 588 | X157285714Y-30646666D01* 589 | X157380952Y-30694285D01* 590 | X157428571Y-30741904D01* 591 | X157476190Y-30837142D01* 592 | X157476190Y-31218095D01* 593 | X156952381Y-29741904D02* 594 | X156952381Y-30218095D01* 595 | X157428571Y-30265714D01* 596 | X157380952Y-30218095D01* 597 | X157333333Y-30122857D01* 598 | X157333333Y-29884761D01* 599 | X157380952Y-29789523D01* 600 | X157428571Y-29741904D01* 601 | X157523810Y-29694285D01* 602 | X157761905Y-29694285D01* 603 | X157857143Y-29741904D01* 604 | X157904762Y-29789523D01* 605 | X157952381Y-29884761D01* 606 | X157952381Y-30122857D01* 607 | X157904762Y-30218095D01* 608 | X157857143Y-30265714D01* 609 | X212621905Y-48692381D02* 610 | X212621905Y-47692381D01* 611 | X213002858Y-47692381D01* 612 | X213098096Y-47740000D01* 613 | X213145715Y-47787619D01* 614 | X213193334Y-47882857D01* 615 | X213193334Y-48025714D01* 616 | X213145715Y-48120952D01* 617 | X213098096Y-48168571D01* 618 | X213002858Y-48216190D01* 619 | X212621905Y-48216190D01* 620 | X214050477Y-47692381D02* 621 | X213860000Y-47692381D01* 622 | X213764762Y-47740000D01* 623 | X213717143Y-47787619D01* 624 | X213621905Y-47930476D01* 625 | X213574286Y-48120952D01* 626 | X213574286Y-48501905D01* 627 | X213621905Y-48597143D01* 628 | X213669524Y-48644762D01* 629 | X213764762Y-48692381D01* 630 | X213955239Y-48692381D01* 631 | X214050477Y-48644762D01* 632 | X214098096Y-48597143D01* 633 | X214145715Y-48501905D01* 634 | X214145715Y-48263810D01* 635 | X214098096Y-48168571D01* 636 | X214050477Y-48120952D01* 637 | X213955239Y-48073333D01* 638 | X213764762Y-48073333D01* 639 | X213669524Y-48120952D01* 640 | X213621905Y-48168571D01* 641 | X213574286Y-48263810D01* 642 | X269712381Y-31218095D02* 643 | X268712381Y-31218095D01* 644 | X268712381Y-30837142D01* 645 | X268760000Y-30741904D01* 646 | X268807619Y-30694285D01* 647 | X268902857Y-30646666D01* 648 | X269045714Y-30646666D01* 649 | X269140952Y-30694285D01* 650 | X269188571Y-30741904D01* 651 | X269236190Y-30837142D01* 652 | X269236190Y-31218095D01* 653 | X268712381Y-30313333D02* 654 | X268712381Y-29646666D01* 655 | X269712381Y-30075238D01* 656 | X212621905Y-53772381D02* 657 | X212621905Y-52772381D01* 658 | X213002858Y-52772381D01* 659 | X213098096Y-52820000D01* 660 | X213145715Y-52867619D01* 661 | X213193334Y-52962857D01* 662 | X213193334Y-53105714D01* 663 | X213145715Y-53200952D01* 664 | X213098096Y-53248571D01* 665 | X213002858Y-53296190D01* 666 | X212621905Y-53296190D01* 667 | X213764762Y-53200952D02* 668 | X213669524Y-53153333D01* 669 | X213621905Y-53105714D01* 670 | X213574286Y-53010476D01* 671 | X213574286Y-52962857D01* 672 | X213621905Y-52867619D01* 673 | X213669524Y-52820000D01* 674 | X213764762Y-52772381D01* 675 | X213955239Y-52772381D01* 676 | X214050477Y-52820000D01* 677 | X214098096Y-52867619D01* 678 | X214145715Y-52962857D01* 679 | X214145715Y-53010476D01* 680 | X214098096Y-53105714D01* 681 | X214050477Y-53153333D01* 682 | X213955239Y-53200952D01* 683 | X213764762Y-53200952D01* 684 | X213669524Y-53248571D01* 685 | X213621905Y-53296190D01* 686 | X213574286Y-53391429D01* 687 | X213574286Y-53581905D01* 688 | X213621905Y-53677143D01* 689 | X213669524Y-53724762D01* 690 | X213764762Y-53772381D01* 691 | X213955239Y-53772381D01* 692 | X214050477Y-53724762D01* 693 | X214098096Y-53677143D01* 694 | X214145715Y-53581905D01* 695 | X214145715Y-53391429D01* 696 | X214098096Y-53296190D01* 697 | X214050477Y-53248571D01* 698 | X213955239Y-53200952D01* 699 | X240561905Y-48692381D02* 700 | X240561905Y-47692381D01* 701 | X240942858Y-47692381D01* 702 | X241038096Y-47740000D01* 703 | X241085715Y-47787619D01* 704 | X241133334Y-47882857D01* 705 | X241133334Y-48025714D01* 706 | X241085715Y-48120952D01* 707 | X241038096Y-48168571D01* 708 | X240942858Y-48216190D01* 709 | X240561905Y-48216190D01* 710 | X241609524Y-48692381D02* 711 | X241800000Y-48692381D01* 712 | X241895239Y-48644762D01* 713 | X241942858Y-48597143D01* 714 | X242038096Y-48454286D01* 715 | X242085715Y-48263810D01* 716 | X242085715Y-47882857D01* 717 | X242038096Y-47787619D01* 718 | X241990477Y-47740000D01* 719 | X241895239Y-47692381D01* 720 | X241704762Y-47692381D01* 721 | X241609524Y-47740000D01* 722 | X241561905Y-47787619D01* 723 | X241514286Y-47882857D01* 724 | X241514286Y-48120952D01* 725 | X241561905Y-48216190D01* 726 | X241609524Y-48263810D01* 727 | X241704762Y-48311429D01* 728 | X241895239Y-48311429D01* 729 | X241990477Y-48263810D01* 730 | X242038096Y-48216190D01* 731 | X242085715Y-48120952D01* 732 | X240085714Y-53772381D02* 733 | X240085714Y-52772381D01* 734 | X240466667Y-52772381D01* 735 | X240561905Y-52820000D01* 736 | X240609524Y-52867619D01* 737 | X240657143Y-52962857D01* 738 | X240657143Y-53105714D01* 739 | X240609524Y-53200952D01* 740 | X240561905Y-53248571D01* 741 | X240466667Y-53296190D01* 742 | X240085714Y-53296190D01* 743 | X241609524Y-53772381D02* 744 | X241038095Y-53772381D01* 745 | X241323809Y-53772381D02* 746 | X241323809Y-52772381D01* 747 | X241228571Y-52915238D01* 748 | X241133333Y-53010476D01* 749 | X241038095Y-53058095D01* 750 | X242228571Y-52772381D02* 751 | X242323810Y-52772381D01* 752 | X242419048Y-52820000D01* 753 | X242466667Y-52867619D01* 754 | X242514286Y-52962857D01* 755 | X242561905Y-53153333D01* 756 | X242561905Y-53391429D01* 757 | X242514286Y-53581905D01* 758 | X242466667Y-53677143D01* 759 | X242419048Y-53724762D01* 760 | X242323810Y-53772381D01* 761 | X242228571Y-53772381D01* 762 | X242133333Y-53724762D01* 763 | X242085714Y-53677143D01* 764 | X242038095Y-53581905D01* 765 | X241990476Y-53391429D01* 766 | X241990476Y-53153333D01* 767 | X242038095Y-52962857D01* 768 | X242085714Y-52867619D01* 769 | X242133333Y-52820000D01* 770 | X242228571Y-52772381D01* 771 | X166370095Y-40727381D02* 772 | X166370095Y-41536905D01* 773 | X166417714Y-41632143D01* 774 | X166465333Y-41679762D01* 775 | X166560571Y-41727381D01* 776 | X166751048Y-41727381D01* 777 | X166846286Y-41679762D01* 778 | X166893905Y-41632143D01* 779 | X166941524Y-41536905D01* 780 | X166941524Y-40727381D01* 781 | X167941524Y-41727381D02* 782 | X167370095Y-41727381D01* 783 | X167655809Y-41727381D02* 784 | X167655809Y-40727381D01* 785 | X167560571Y-40870238D01* 786 | X167465333Y-40965476D01* 787 | X167370095Y-41013095D01* 788 | X194310095Y-40727381D02* 789 | X194310095Y-41536905D01* 790 | X194357714Y-41632143D01* 791 | X194405333Y-41679762D01* 792 | X194500571Y-41727381D01* 793 | X194691048Y-41727381D01* 794 | X194786286Y-41679762D01* 795 | X194833905Y-41632143D01* 796 | X194881524Y-41536905D01* 797 | X194881524Y-40727381D01* 798 | X195310095Y-40822619D02* 799 | X195357714Y-40775000D01* 800 | X195452952Y-40727381D01* 801 | X195691048Y-40727381D01* 802 | X195786286Y-40775000D01* 803 | X195833905Y-40822619D01* 804 | X195881524Y-40917857D01* 805 | X195881524Y-41013095D01* 806 | X195833905Y-41155952D01* 807 | X195262476Y-41727381D01* 808 | X195881524Y-41727381D01* 809 | X222250095Y-40727381D02* 810 | X222250095Y-41536905D01* 811 | X222297714Y-41632143D01* 812 | X222345333Y-41679762D01* 813 | X222440571Y-41727381D01* 814 | X222631048Y-41727381D01* 815 | X222726286Y-41679762D01* 816 | X222773905Y-41632143D01* 817 | X222821524Y-41536905D01* 818 | X222821524Y-40727381D01* 819 | X223202476Y-40727381D02* 820 | X223821524Y-40727381D01* 821 | X223488190Y-41108333D01* 822 | X223631048Y-41108333D01* 823 | X223726286Y-41155952D01* 824 | X223773905Y-41203571D01* 825 | X223821524Y-41298810D01* 826 | X223821524Y-41536905D01* 827 | X223773905Y-41632143D01* 828 | X223726286Y-41679762D01* 829 | X223631048Y-41727381D01* 830 | X223345333Y-41727381D01* 831 | X223250095Y-41679762D01* 832 | X223202476Y-41632143D01* 833 | X250190095Y-40727381D02* 834 | X250190095Y-41536905D01* 835 | X250237714Y-41632143D01* 836 | X250285333Y-41679762D01* 837 | X250380571Y-41727381D01* 838 | X250571048Y-41727381D01* 839 | X250666286Y-41679762D01* 840 | X250713905Y-41632143D01* 841 | X250761524Y-41536905D01* 842 | X250761524Y-40727381D01* 843 | X251666286Y-41060714D02* 844 | X251666286Y-41727381D01* 845 | X251428190Y-40679762D02* 846 | X251190095Y-41394048D01* 847 | X251809143Y-41394048D01* 848 | X259512381Y-57094286D02* 849 | X258512381Y-57094286D01* 850 | X258512381Y-56713333D01* 851 | X258560000Y-56618095D01* 852 | X258607619Y-56570476D01* 853 | X258702857Y-56522857D01* 854 | X258845714Y-56522857D01* 855 | X258940952Y-56570476D01* 856 | X258988571Y-56618095D01* 857 | X259036190Y-56713333D01* 858 | X259036190Y-57094286D01* 859 | X259512381Y-55570476D02* 860 | X259512381Y-56141905D01* 861 | X259512381Y-55856191D02* 862 | X258512381Y-55856191D01* 863 | X258655238Y-55951429D01* 864 | X258750476Y-56046667D01* 865 | X258798095Y-56141905D01* 866 | X259512381Y-54618095D02* 867 | X259512381Y-55189524D01* 868 | X259512381Y-54903810D02* 869 | X258512381Y-54903810D01* 870 | X258655238Y-54999048D01* 871 | X258750476Y-55094286D01* 872 | X258798095Y-55189524D01* 873 | M02* 874 | -------------------------------------------------------------------------------- /PCB/Shift-32/GERBER/ESP12 Controller.drl: -------------------------------------------------------------------------------- 1 | M48 2 | ;DRILL file {KiCad 4.0.0-rc2-stable} date Tue 17 Nov 2015 13:54:08 BRT 3 | ;FORMAT={3:3/ absolute / metric / keep zeros} 4 | FMAT,2 5 | METRIC,TZ 6 | T1C0.700 7 | T2C1.016 8 | % 9 | G90 10 | G05 11 | M71 12 | T1 13 | X158750Y-030480 14 | X158750Y-039370 15 | X186690Y-030480 16 | X186690Y-039370 17 | X193040Y-031980 18 | X193040Y-036830 19 | X214630Y-030480 20 | X214630Y-039370 21 | X220980Y-031980 22 | X220980Y-036830 23 | X242570Y-030480 24 | X242570Y-039370 25 | X248920Y-031980 26 | X248920Y-036830 27 | X259080Y-036830 28 | X261740Y-039490 29 | T2 30 | X152400Y-030480 31 | X152400Y-033020 32 | X152400Y-035560 33 | X152400Y-038100 34 | X152400Y-040640 35 | X157480Y-053340 36 | X157480Y-055880 37 | X157480Y-058420 38 | X160020Y-053340 39 | X160020Y-055880 40 | X160020Y-058420 41 | X162560Y-053340 42 | X162560Y-055880 43 | X162560Y-058420 44 | X165100Y-053340 45 | X165100Y-055880 46 | X165100Y-058420 47 | X167640Y-053340 48 | X167640Y-055880 49 | X167640Y-058420 50 | X170180Y-053340 51 | X170180Y-055880 52 | X170180Y-058420 53 | X172720Y-053340 54 | X172720Y-055880 55 | X172720Y-058420 56 | X175260Y-053340 57 | X175260Y-055880 58 | X175260Y-058420 59 | X185420Y-053340 60 | X185420Y-055880 61 | X185420Y-058420 62 | X187960Y-053340 63 | X187960Y-055880 64 | X187960Y-058420 65 | X190500Y-053340 66 | X190500Y-055880 67 | X190500Y-058420 68 | X193040Y-053340 69 | X193040Y-055880 70 | X193040Y-058420 71 | X195580Y-053340 72 | X195580Y-055880 73 | X195580Y-058420 74 | X198120Y-053340 75 | X198120Y-055880 76 | X198120Y-058420 77 | X200660Y-053340 78 | X200660Y-055880 79 | X200660Y-058420 80 | X203200Y-053340 81 | X203200Y-055880 82 | X203200Y-058420 83 | X213360Y-053340 84 | X213360Y-055880 85 | X213360Y-058420 86 | X215900Y-053340 87 | X215900Y-055880 88 | X215900Y-058420 89 | X218440Y-053340 90 | X218440Y-055880 91 | X218440Y-058420 92 | X220980Y-053340 93 | X220980Y-055880 94 | X220980Y-058420 95 | X223520Y-053340 96 | X223520Y-055880 97 | X223520Y-058420 98 | X226060Y-053340 99 | X226060Y-055880 100 | X226060Y-058420 101 | X228600Y-053340 102 | X228600Y-055880 103 | X228600Y-058420 104 | X231140Y-053340 105 | X231140Y-055880 106 | X231140Y-058420 107 | X241300Y-053340 108 | X241300Y-055880 109 | X241300Y-058420 110 | X243840Y-053340 111 | X243840Y-055880 112 | X243840Y-058420 113 | X246380Y-053340 114 | X246380Y-055880 115 | X246380Y-058420 116 | X248920Y-053340 117 | X248920Y-055880 118 | X248920Y-058420 119 | X251460Y-053340 120 | X251460Y-055880 121 | X251460Y-058420 122 | X254000Y-053340 123 | X254000Y-055880 124 | X254000Y-058420 125 | X256540Y-053340 126 | X256540Y-055880 127 | X256540Y-058420 128 | X259080Y-053340 129 | X259080Y-055880 130 | X259080Y-058420 131 | X264160Y-030480 132 | X264160Y-033020 133 | X264160Y-035560 134 | X264160Y-038100 135 | X264160Y-040640 136 | X264160Y-053340 137 | X264160Y-055880 138 | T0 139 | M30 140 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #ESP8266 I2S 32bit Realtime Shift Register Driver 2 | 3 | I believe I found a way to use just an ESP8266 module to control a set of 3D printer stepper drivers directly. This code demonstrates how. 4 | 5 | Background: 6 | 7 | 1. Other projects show how to use ESP01 as a wifi-serial bridge to the arduinos, but serial is still a bottleneck and wifi uploads are impractical. 8 | 2. Altough ESP8266 does 160MHz at 32bits processing (versus 16MHZ 8-bit from most Arduinos) it has insufficient realtime GPIO for controlling printers. 9 | 3. Raspberry pi shared the realtime gpio limitation, but wallacoloo still did reprap control using DMA. Nice! https://www.youtube.com/watch?v=g4UD5MRas3E 10 | 4. CNLohr did a really cool WS2812 led driver (weird one-wire serial protocol) using ESP8266 I2S audio output and DMA. https://www.youtube.com/watch?v=6zqGwxqJQnw 11 | 5. I2S and SPI look very much alike, and SPI can control shift registers. Hey! Opportunity! 12 | 13 | I got the code from CNLohr on github, modified it to output a 32 bit counter (16 bit left + 16 bit right channels) via a circular DMA buffer, and created a small PCB with four cascaded 74HC595 shift registers. wiring is simple: 14 | - I2S Data to '595 input data 15 | - I2S Bitclock to '595 shift clock 16 | - I2s word clock (left/right) to '595 buffer clock. 17 | 18 | This is what RAW I2S output signals for the counter look like: word-clock (yellow), bit clock (cyan), data (purple). Notice how LSB of data is output after the word clock rising edge. 19 | 20 | [![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/Fhat7x_vPLw/0.jpg)](http://www.youtube.com/watch?v=Fhat7x_vPLw) 21 | 22 | Fixed the offset (software shifing) to match the parallel outputs, raised the frequency a bit (just cause), plugged in the shifter board. Now this is what word-clock (yellow) and the 3LSBs (cyan=1, purple=2, blue=4) look like: 23 | ![image of osciloscope](https://github.com/lhartmann/esp8266_reprap/blob/master/images/Counter%20-%20Word_clock%20and%203LSBs.png?raw=true) 24 | 25 | The code and the PCB: (https://github.com/lhartmann/esp8266_reprap) 26 | 27 | What this does: 28 | 29 | - Allows realtime bitbanging of 32 data bits via I2S and DMA. 30 | - Demo code just outputs a 32bit counter at 185kHz sample rate. 31 | - Reference shifter board is provided. 32 | 33 | Limitations: 34 | 35 | - 1MSB is actually delayed by 1 sample due to I2S signaling standard. This delay is constant so it could be compensated, but I didn't bother. 36 | 37 | Hopes for the future: RepRap 3D Printing. 38 | 39 | - No extra arduino necessary, ESP would control the drivers directly. 40 | - SDcard uploads over wifi would be feasible for large files, no more serial connection bottleneck with wifi-serial bridging. 41 | - Browser-side slicing with slic3r and (http://www.skulpt.org). No software install required on the client! 42 | -------------------------------------------------------------------------------- /common/commonservices.h: -------------------------------------------------------------------------------- 1 | //Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or 2 | // ColorChord License. You Choose. 3 | 4 | #ifndef _COMMON_H 5 | #define _COMMON_H 6 | 7 | #include "c_types.h" 8 | 9 | #define FLASH_PROTECTION_BOUNDARY 524288 10 | #define MAX_DEVICE_NAME 32 11 | #define USERDATA_SIZE 256 12 | 13 | //Returns nr bytes to return. You must allocate retdata. 14 | //It MUST be at least 1,300 bytes large and it MUST be 32-bit aligned. 15 | //NOTE: It is SAFE to use pusrdata and retdata as the same buffer. 16 | int ICACHE_FLASH_ATTR issue_command(char * retdata, int retsize, char *pusrdata, unsigned short len); 17 | 18 | //Includes UDP Control + HTTP Interfaces 19 | void ICACHE_FLASH_ATTR CSPreInit(); 20 | void ICACHE_FLASH_ATTR CSInit(); 21 | void ICACHE_FLASH_ATTR CSTick( int slowtick ); 22 | void ICACHE_FLASH_ATTR CSConnectionChange(); 23 | 24 | void ICACHE_FLASH_ATTR CSSettingsLoad(int force_reinit); 25 | void ICACHE_FLASH_ATTR CSSettingsSave(); 26 | 27 | struct CommonSettings 28 | { 29 | uint8_t settings_key; //Needs to be 0xAF 30 | char DeviceName[MAX_DEVICE_NAME]; 31 | char DeviceDescription[MAX_DEVICE_NAME]; 32 | char UserData[USERDATA_SIZE]; 33 | }; 34 | 35 | extern struct CommonSettings SETTINGS; 36 | 37 | 38 | //You must provide: 39 | //Critical should not lock interrupts, just disable services that have problems 40 | //with double-interrupt faults. I.e. turn off/on any really fast timer interrupts. 41 | //These generally only get called when doing serious operations like reflashing. 42 | void EnterCritical(); 43 | void ExitCritical(); 44 | 45 | //If we receive a command that's not F, E or W (Flash Echo Wifi) 46 | int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata, unsigned short len); 47 | 48 | //Other utility stuff 49 | extern int need_to_switch_opmode; //0 = no, 1 = will need to after a scan. 2 = do it now. 3 = need to go back into station mode. 50 | 51 | 52 | 53 | //Browse mechanism. 54 | #define BROWSE_CLIENTS_LIST_SIZE 20 55 | 56 | struct BrowseClient 57 | { 58 | uint32_t ip; 59 | char service[11]; 60 | char devicename[11]; 61 | char description[17]; 62 | }; 63 | 64 | extern struct BrowseClient FoundBrowseClients[BROWSE_CLIENTS_LIST_SIZE]; 65 | 66 | //Service name can be the title of the service, or can be "esp8266" to list all ESP8266's. 67 | void ICACHE_FLASH_ATTR BrowseForService( const char * servicename ); 68 | 69 | //Set the service name for this device. No more than 10 chars allowed. 70 | void ICACHE_FLASH_ATTR SetServiceName( const char * myservice ); 71 | 72 | #endif 73 | 74 | -------------------------------------------------------------------------------- /common/esp8266_rom.h: -------------------------------------------------------------------------------- 1 | #ifndef _ESP8266_ROM_FUNCTS 2 | #define _ESP8266_ROM_FUNCTS 3 | 4 | //This is my best guess at some of the ROM functions for the ESP8266. 5 | //I have no idea if this stuff is correct! 6 | 7 | #include 8 | #include 9 | 10 | void Cache_Read_Disable(); //Can't seem to operate... 11 | void Cache_Read_Enable(); 12 | 13 | //PROVIDE ( Cache_Read_Disable = 0x400047f0 ); 14 | //PROVIDE ( Cache_Read_Enable = 0x40004678 ); 15 | 16 | typedef struct { 17 | uint32_t i[2]; 18 | uint32_t buf[4]; 19 | unsigned char in[64]; 20 | unsigned char digest[16]; 21 | } MD5_CTX; 22 | 23 | void MD5Init ( MD5_CTX *mdContext); 24 | void MD5Update( MD5_CTX *mdContext, const unsigned char *inBuf, unsigned int inLen); 25 | void MD5Final ( unsigned char hash[], MD5_CTX *mdContext); 26 | 27 | 28 | //SHA Stuff from: https://github.com/pvvx/esp8266web/blob/master/app/include/bios/cha1.h 29 | #define SHA1_HASH_LEN 20 30 | typedef struct { 31 | uint32 state[5]; 32 | uint32 count[2]; 33 | uint8 buffer[64]; 34 | uint8 extra[40]; 35 | } SHA1_CTX; 36 | 37 | void SHA1Init(SHA1_CTX* context); 38 | void SHA1Update(SHA1_CTX* context, 39 | const uint8 *data, 40 | size_t len); 41 | void SHA1Final(uint8 digest[SHA1_HASH_LEN], SHA1_CTX* context); 42 | void SHA1Transform(uint32 state[5], const uint8 buffer[64]); 43 | 44 | 45 | 46 | //SPI_FLASH_SEC_SIZE 4096 47 | 48 | void SPIEraseSector(uint16 sec); 49 | void SPIEraseArea(uint32 start,uint32 len); //Doesn't work? 50 | void SPIEraseBlock(uint16 blk); 51 | void SPIWrite(uint32 des_addr, uint32_t *src_addr, uint32_t size); 52 | void SPIRead(uint32 src_addr, uint32_t *des_addr, uint16_t size); 53 | void SPILock( uint16_t sec ); //??? I don't use this? 54 | void SPIUnlock( ); //??? I don't use this? -> Seems to crash. 55 | 56 | extern SpiFlashChip * flashchip; //don't forget: flashchip->chip_size = 0x01000000; 57 | 58 | 59 | /* 60 | flashchip->chip_size = 0x01000000; 61 | 62 | { 63 | uint32_t __attribute__ ((aligned (16))) t[1024]; 64 | t[0] = 0xAABBCCDD; 65 | t[1] = 0xEEFF0011; 66 | for( i = 0; i < 10000; i++ ) uart0_sendStr("A\n"); 67 | SPIEraseSector( 1000000/4096 ); 68 | for( i = 0; i < 10000; i++ ) uart0_sendStr("B\n"); 69 | SPIWrite( 1000000, t, 8 ); 70 | } 71 | 72 | for( i = 0; i < 10000; i++ ) uart0_sendStr("C\n"); 73 | 74 | while(1) 75 | { 76 | char ct[32]; 77 | uint32_t __attribute__ ((aligned (16))) ret = 0x12345678; 78 | // SPIRead( 1000000, &ret, 4 ); 79 | ret = *(uint32_t*)(0x40200000+1000004); 80 | ets_sprintf( ct, "%08x\n", ret ); 81 | printf( ct ); 82 | } 83 | */ 84 | 85 | 86 | void software_reset(); 87 | 88 | 89 | 90 | #endif 91 | 92 | 93 | -------------------------------------------------------------------------------- /common/flash_rewriter.c: -------------------------------------------------------------------------------- 1 | //Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or 2 | // ColorChord License. You Choose. 3 | 4 | #include "flash_rewriter.h" 5 | #include 6 | #include 7 | #include 8 | 9 | #define SRCSIZE 4096 10 | #define BLKSIZE 65536 11 | 12 | static const char * key = ""; 13 | static int keylen = 0; 14 | 15 | 16 | static int MyRewriteFlash( char * command, int commandlen ) 17 | { 18 | MD5_CTX md5ctx; 19 | char __attribute__ ((aligned (32))) buffer[512]; 20 | char * colons[8]; 21 | int i, ipl = 0; 22 | int p; 23 | //[from_address]\t[to_address]\t[size]\t[MD5(key+data)]\t[from_address]\t[to_address]\t[size]\t[MD5(key+data)] 24 | command[commandlen] = 0; 25 | 26 | flashchip->chip_size = 0x01000000; 27 | 28 | ets_wdt_disable(); 29 | 30 | colons[ipl++] = &command[0]; 31 | for( i = 0; i < commandlen; i++ ) 32 | { 33 | if( command[i] == 0 ) break; 34 | if( command[i] == '\t' ) 35 | { 36 | if( ipl >= 8 ) break; 37 | command[i] = 0; 38 | colons[ipl++] = &command[i+1]; 39 | } 40 | } 41 | if( ipl != 8 ) 42 | { 43 | return 1; 44 | } 45 | uint32_t from1 = my_atoi( colons[0] ); 46 | uint32_t to1 = my_atoi( colons[1] ); 47 | int32_t size1 = my_atoi( colons[2] ); 48 | char * md51 = colons[3]; 49 | char md5h1raw[48]; 50 | char md5h1[48]; 51 | uint32_t from2 = my_atoi( colons[4] ); 52 | uint32_t to2 = my_atoi( colons[5] ); 53 | int32_t size2 = my_atoi( colons[6] ); 54 | char * md52 = colons[7]; 55 | char md5h2raw[48]; 56 | char md5h2[48]; 57 | 58 | if( from1 == 0 || from2 == 0 || size1 == 0 ) 59 | { 60 | return 2; 61 | } 62 | 63 | if( ( from1 & 0xfff ) || ( from2 & 0xfff ) || ( to1 & 0xfff ) || ( to2 & 0xfff ) ) 64 | { 65 | return 3; 66 | } 67 | 68 | 69 | /////////////////////////////// 70 | char st[400]; 71 | /* 72 | ets_sprintf( st, "!!%08x", (((uint32_t*)(0x40200000 + from1))) ); 73 | uart0_sendStr( st ); 74 | 75 | for( i = 0; i < 200; i++ ) 76 | { 77 | ets_sprintf( st, "%08x", (uint32_t)(((uint32_t*)(0x40200000 + from1))[i]) ); 78 | uart0_sendStr( st ); 79 | } 80 | uart0_sendStr( "+\n" ); 81 | 82 | /* 83 | 84 | 85 | uint32_t __attribute__ ((aligned (32))) readr = 0xAAAAAAAA; 86 | SPIRead( from1, &readr, 4 ); 87 | ets_sprintf( st, ":%08x\n", readr ); 88 | uart0_sendStr( st ); 89 | readr = 0x12345678; 90 | 91 | SPIRead( from1+4, &readr, 4 ); 92 | ets_sprintf( st, ":%08x\n", readr ); 93 | uart0_sendStr( st ); 94 | uart0_sendStr( "\n" ); 95 | 96 | ets_sprintf( st, "TT: %08x ADDY: %08x\n", from1, &readr ); 97 | uart0_sendStr( st ); 98 | 99 | 100 | 101 | 102 | readr = 0xAAAAAAAA; 103 | spi_flash_read( from1, &readr, 4 ); 104 | ets_sprintf( st, "+%08x\n", readr ); 105 | uart0_sendStr( st ); 106 | 107 | readr = 0xbbbbbbbb; 108 | spi_flash_read( from1+4, &readr, 4 ); 109 | ets_sprintf( st, "+%08x\n", readr ); 110 | uart0_sendStr( st ); 111 | 112 | */ 113 | 114 | /* 115 | MD5Init( &md5ctx ); 116 | MD5Update( &md5ctx, (uint8_t*)0x40200000 + from1, 4 ); 117 | MD5Final( md5h1raw, &md5ctx ); 118 | for( i = 0; i < 16; i++ ) 119 | { 120 | ets_sprintf( md5h1+i*2, "%02x", md5h1raw[i] ); 121 | } 122 | uart0_sendStr( "Hash 1:" ); 123 | uart0_sendStr( md5h1 ); 124 | uart0_sendStr( "!\n" ); 125 | */ 126 | 127 | ////////////////////////////// 128 | 129 | ets_sprintf( st, "Computing Hash 1: %08x size %d\n", from1, size1 ); 130 | uart0_sendStr( st ); 131 | 132 | MD5Init( &md5ctx ); 133 | if( keylen ) 134 | MD5Update( &md5ctx, key, keylen ); 135 | // MD5Update( &md5ctx, (uint8_t*)0x40200000 + from1, size1 ); 136 | SafeMD5Update( &md5ctx, (uint8_t*)0x40200000 + from1, size1 ); 137 | MD5Final( md5h1raw, &md5ctx ); 138 | for( i = 0; i < 16; i++ ) 139 | { 140 | ets_sprintf( md5h1+i*2, "%02x", md5h1raw[i] ); 141 | } 142 | 143 | uart0_sendStr( "Hash 1:" ); 144 | uart0_sendStr( md5h1 ); 145 | uart0_sendStr( "\n" ); 146 | 147 | for( i = 0; i < 32; i++ ) 148 | { 149 | if( md5h1[i] != md51[i] ) 150 | { 151 | //printf( "%s != %s", md5h1, md51 ); 152 | uart0_sendStr( "File 1 MD5 mismatch\nActual:" ); 153 | uart0_sendStr( md5h1 ); 154 | uart0_sendStr( "\nExpected:" ); 155 | uart0_sendStr( md51 ); 156 | uart0_sendStr( "\n" ); 157 | return 4; 158 | } 159 | } 160 | 161 | ets_sprintf( st, "Computing Hash 2: %08x size %d\n", from2, size2 ); 162 | uart0_sendStr( st ); 163 | 164 | MD5Init( &md5ctx ); 165 | if( keylen ) 166 | MD5Update( &md5ctx, key, keylen ); 167 | SafeMD5Update( &md5ctx, (uint8_t*)0x40200000 + from2, size2 ); 168 | MD5Final( md5h2raw, &md5ctx ); 169 | for( i = 0; i < 16; i++ ) 170 | { 171 | ets_sprintf( md5h2+i*2, "%02x", md5h2raw[i] ); 172 | } 173 | 174 | uart0_sendStr( "Hash 2:" ); 175 | uart0_sendStr( md5h2 ); 176 | uart0_sendStr( "\n" ); 177 | 178 | /* for( i = 0; i <= size2/4; i++ ) 179 | { 180 | uint32_t j = ((uint32_t*)(0x40200000 + from2))[i]; 181 | ets_sprintf( st, "%02x%02x%02x%02x\n", (uint8_t)(j>>0), (uint8_t)(j>>8), (uint8_t)(j>>16), (uint8_t)(j>>24) ); 182 | uart0_sendStr( st ); 183 | }*/ 184 | 185 | for( i = 0; i < 32; i++ ) 186 | { 187 | if( md5h2[i] != md52[i] ) 188 | { 189 | uart0_sendStr( "File 2 MD5 mismatch\nActual:" ); 190 | uart0_sendStr( md5h2 ); 191 | uart0_sendStr( "\nExpected:" ); 192 | uart0_sendStr( md52 ); 193 | uart0_sendStr( "\n" ); 194 | return 5; 195 | } 196 | } 197 | 198 | //Need to round sizes up. 199 | size1 = ((size1-1)&(~0xfff))+1; 200 | size2 = ((size2-1)&(~0xfff))+1; 201 | 202 | ets_sprintf( st, "Copy 1: %08x to %08x, size %d\n", from1, to1, size1 ); 203 | uart0_sendStr( st ); 204 | ets_sprintf( st, "Copy 2: %08x to %08x, size %d\n", from2, to2, size2 ); 205 | uart0_sendStr( st ); 206 | 207 | //Everything checked out... Need to move the flashes. 208 | 209 | ets_delay_us( 1000 ); 210 | 211 | //Disable all interrupts. 212 | ets_intr_lock(); 213 | 214 | uart_tx_one_char( 'A' ); 215 | 216 | int j; 217 | ipl = (size1/BLKSIZE)+1; 218 | p = to1/BLKSIZE; 219 | for( i = 0; i < ipl; i++ ) 220 | { 221 | SPIEraseBlock( p++ ); 222 | 223 | for( j = 0; j < BLKSIZE/SRCSIZE; j++ ) 224 | { 225 | SPIWrite( to1, (uint32_t*)(0x40200000 + from1), SRCSIZE ); 226 | to1 += SRCSIZE; 227 | from1 += SRCSIZE; 228 | } 229 | } 230 | 231 | uart_tx_one_char( 'B' ); 232 | 233 | ipl = (size2/BLKSIZE)+1; 234 | p = to2/BLKSIZE; 235 | for( i = 0; i < ipl; i++ ) 236 | { 237 | SPIEraseBlock( p++ ); 238 | for( j = 0; j < BLKSIZE/SRCSIZE; j++ ) 239 | { 240 | SPIWrite( to2, (uint32_t*)(0x40200000 + from2), SRCSIZE ); 241 | to2 += SRCSIZE; 242 | from2 += SRCSIZE; 243 | } 244 | } 245 | 246 | uart_tx_one_char( 'C' ); 247 | 248 | 249 | void(*rebootme)() = (void(*)())0x40000080; 250 | rebootme(); 251 | 252 | 253 | // system_upgrade_reboot(); 254 | // software_reset(); //Doesn't seem to boot back in. 255 | 256 | 257 | //Destinations are erased. Copy over the other part. 258 | // for( i = 0; i < ; i++ ) 259 | 260 | /*Things I know: 261 | flashchip->chip_size = 0x01000000; 262 | SPIEraseSector( 1000000/4096 ); 263 | SPIWrite( 1000000, &t, 4 ); << Charles Lohr Under the MIT/x11 License, NewBSD License or 2 | // ColorChord License. You Choose. 3 | 4 | #ifndef _FLASH_REWRITER_H 5 | #define _FLASH_REWRITER_H 6 | 7 | //Unusual, but guarentees that the code resides in IRAM. 8 | /* 9 | Usage: 10 | [from_address]:[to_address]:[size]:[MD5(key+data)]:[from_address]:[to_address]:[size]:[MD5(key+data)][extra byte required] 11 | 12 | NOTE: YOU MUST USE 4096-byte-aligned boundaries. 13 | 14 | Note: this will modify the text in "command" 15 | */ 16 | 17 | 18 | extern int (*GlobalRewriteFlash)( char * command, int commandlen ); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /common/http.c: -------------------------------------------------------------------------------- 1 | //Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or 2 | // ColorChord License. You Choose. 3 | 4 | #include "http.h" 5 | #include "mystuff.h" 6 | #include "esp8266_rom.h" 7 | 8 | #define HTDEBUG( x... ) printf( x ) 9 | 10 | //#define ISKEEPALIVE "keep-alive" 11 | #define ISKEEPALIVE "close" 12 | 13 | struct HTTPConnection HTTPConnections[HTTP_CONNECTIONS]; 14 | struct HTTPConnection * curhttp; 15 | uint8 * curdata; 16 | uint16 curlen; 17 | uint8 wsmask[4]; 18 | uint8 wsmaskplace; 19 | 20 | 21 | ICACHE_FLASH_ATTR void InternalStartHTTP( ); 22 | ICACHE_FLASH_ATTR void HTTPHandleInternalCallback( ); 23 | 24 | ICACHE_FLASH_ATTR void HTTPClose( ) 25 | { 26 | //This is dead code, but it is a testament to Charles. 27 | //Do not do this here. Wait for the ESP to tell us the 28 | //socket is successfully closed. 29 | //curhttp->state = HTTP_STATE_NONE; 30 | curhttp->state = HTTP_WAIT_CLOSE; 31 | espconn_disconnect( curhttp->socket ); 32 | } 33 | 34 | 35 | void ICACHE_FLASH_ATTR HTTPGotData( ) 36 | { 37 | uint8 c; 38 | curhttp->timeout = 0; 39 | while( curlen-- ) 40 | { 41 | c = HTTPPOP; 42 | // sendhex2( h->state ); sendchr( ' ' ); 43 | 44 | switch( curhttp->state ) 45 | { 46 | case HTTP_STATE_WAIT_METHOD: 47 | if( c == ' ' ) 48 | { 49 | curhttp->state = HTTP_STATE_WAIT_PATH; 50 | curhttp->state_deets = 0; 51 | } 52 | break; 53 | case HTTP_STATE_WAIT_PATH: 54 | curhttp->pathbuffer[curhttp->state_deets++] = c; 55 | if( curhttp->state_deets == MAX_PATHLEN ) 56 | { 57 | curhttp->state_deets--; 58 | } 59 | 60 | if( c == ' ' ) 61 | { 62 | //Tricky: If we're a websocket, we need the whole header. 63 | curhttp->pathbuffer[curhttp->state_deets-1] = 0; 64 | curhttp->state_deets = 0; 65 | 66 | if( strncmp( (const char*)curhttp->pathbuffer, "/d/ws", 5 ) == 0 ) 67 | { 68 | curhttp->state = HTTP_STATE_DATA_WEBSOCKET; 69 | curhttp->state_deets = 0; 70 | } 71 | else 72 | { 73 | curhttp->state = HTTP_STATE_WAIT_PROTO; 74 | } 75 | } 76 | break; 77 | case HTTP_STATE_WAIT_PROTO: 78 | if( c == '\n' ) 79 | { 80 | curhttp->state = HTTP_STATE_WAIT_FLAG; 81 | } 82 | break; 83 | case HTTP_STATE_WAIT_FLAG: 84 | if( c == '\n' ) 85 | { 86 | curhttp->state = HTTP_STATE_DATA_XFER; 87 | InternalStartHTTP( ); 88 | } 89 | else if( c != '\r' ) 90 | { 91 | curhttp->state = HTTP_STATE_WAIT_INFLAG; 92 | } 93 | break; 94 | case HTTP_STATE_WAIT_INFLAG: 95 | if( c == '\n' ) 96 | { 97 | curhttp->state = HTTP_STATE_WAIT_FLAG; 98 | curhttp->state_deets = 0; 99 | } 100 | break; 101 | case HTTP_STATE_DATA_XFER: 102 | //Ignore any further data? 103 | curlen = 0; 104 | break; 105 | case HTTP_STATE_DATA_WEBSOCKET: 106 | WebSocketGotData( c ); 107 | break; 108 | case HTTP_WAIT_CLOSE: 109 | if( curhttp->keep_alive ) 110 | { 111 | curhttp->state = HTTP_STATE_WAIT_METHOD; 112 | } 113 | else 114 | { 115 | HTTPClose( ); 116 | } 117 | break; 118 | default: 119 | break; 120 | }; 121 | } 122 | 123 | } 124 | 125 | 126 | static void DoHTTP( uint8_t timed ) 127 | { 128 | switch( curhttp->state ) 129 | { 130 | case HTTP_STATE_NONE: //do nothing if no state. 131 | break; 132 | case HTTP_STATE_DATA_XFER: 133 | if( TCPCanSend( curhttp->socket, 1024 ) ) //TCPDoneSend 134 | { 135 | if( curhttp->is_dynamic ) 136 | { 137 | HTTPCustomCallback( ); 138 | } 139 | else 140 | { 141 | HTTPHandleInternalCallback( ); 142 | } 143 | } 144 | break; 145 | case HTTP_WAIT_CLOSE: 146 | if( TCPDoneSend( curhttp->socket ) ) 147 | { 148 | if( curhttp->keep_alive ) 149 | { 150 | curhttp->state = HTTP_STATE_WAIT_METHOD; 151 | } 152 | else 153 | { 154 | HTTPClose( ); 155 | } 156 | } 157 | break; 158 | case HTTP_STATE_DATA_WEBSOCKET: 159 | if( TCPCanSend( curhttp->socket, 1024 ) ) //TCPDoneSend 160 | { 161 | WebSocketTickInternal(); 162 | } 163 | break; 164 | default: 165 | if( timed ) 166 | { 167 | if( curhttp->timeout++ > HTTP_SERVER_TIMEOUT ) 168 | { 169 | HTTPClose( ); 170 | } 171 | } 172 | } 173 | } 174 | 175 | void HTTPTick( uint8_t timed ) 176 | { 177 | uint8_t i; 178 | for( i = 0; i < HTTP_CONNECTIONS; i++ ) 179 | { 180 | if( curhttp ) { printf( "Unexpected Race Condition\n" );} 181 | curhttp = &HTTPConnections[i]; 182 | DoHTTP( timed ); 183 | curhttp = 0; 184 | } 185 | } 186 | 187 | void ICACHE_FLASH_ATTR HTTPHandleInternalCallback( ) 188 | { 189 | uint16_t i, bytestoread; 190 | 191 | if( curhttp->isdone ) 192 | { 193 | HTTPClose( ); 194 | return; 195 | } 196 | if( curhttp->is404 ) 197 | { 198 | START_PACK 199 | PushString("HTTP/1.1 404 Not Found\r\nConnection: close\r\n\r\nFile not found."); 200 | EndTCPWrite( curhttp->socket ); 201 | curhttp->isdone = 1; 202 | return; 203 | } 204 | if( curhttp->isfirst ) 205 | { 206 | char stto[10]; 207 | uint8_t slen = os_strlen( curhttp->pathbuffer ); 208 | const char * k; 209 | 210 | START_PACK; 211 | //TODO: Content Length? MIME-Type? 212 | PushString("HTTP/1.1 200 Ok\r\n"); 213 | 214 | if( curhttp->bytesleft < 0xfffffffe ) 215 | { 216 | PushString("Connection: "ISKEEPALIVE"\r\nContent-Length: "); 217 | Uint32To10Str( stto, curhttp->bytesleft ); 218 | PushBlob( stto, os_strlen( stto ) ); 219 | curhttp->keep_alive = 1; 220 | } 221 | else 222 | { 223 | PushString("Connection: close\r\n"); 224 | curhttp->keep_alive = 0; 225 | } 226 | 227 | PushString( "\r\nContent-Type: " ); 228 | //Content-Type? 229 | while( slen && ( curhttp->pathbuffer[--slen] != '.' ) ); 230 | k = &curhttp->pathbuffer[slen+1]; 231 | if( strcmp( k, "mp3" ) == 0 ) 232 | { 233 | PushString( "audio/mpeg3" ); 234 | } 235 | else if( strcmp( k, "gz" ) == 0 ) 236 | { 237 | PushString( "text/plain\r\nContent-Encoding: gzip\r\nCache-Control: public, max-age=3600" ); 238 | } 239 | else if( curhttp->bytesleft == 0xfffffffe ) 240 | { 241 | PushString( "text/plain" ); 242 | } 243 | else 244 | { 245 | PushString( "text/html" ); 246 | } 247 | 248 | PushString( "\r\n\r\n" ); 249 | EndTCPWrite( curhttp->socket ); 250 | curhttp->isfirst = 0; 251 | 252 | return; 253 | } 254 | 255 | START_PACK 256 | 257 | for( i = 0; i < 4 && curhttp->bytesleft; i++ ) 258 | { 259 | int bpt = curhttp->bytesleft; 260 | if( bpt > MFS_SECTOR ) bpt = MFS_SECTOR; 261 | curhttp->bytesleft = MFSReadSector( generic_ptr, &curhttp->data.filedescriptor ); 262 | generic_ptr += bpt; 263 | } 264 | 265 | EndTCPWrite( curhttp->socket ); 266 | 267 | if( !curhttp->bytesleft ) 268 | curhttp->isdone = 1; 269 | } 270 | 271 | void InternalStartHTTP( ) 272 | { 273 | int32_t clusterno; 274 | int8_t i; 275 | const char * path = &curhttp->pathbuffer[0]; 276 | 277 | if( curhttp->pathbuffer[0] == '/' ) 278 | path++; 279 | 280 | if( path[0] == 'd' && path[1] == '/' ) 281 | { 282 | curhttp->is_dynamic = 1; 283 | curhttp->isfirst = 1; 284 | curhttp->isdone = 0; 285 | curhttp->is404 = 0; 286 | HTTPCustomStart(); 287 | return; 288 | } 289 | 290 | if( !path[0] ) 291 | { 292 | path = "index.html"; 293 | } 294 | 295 | i = MFSOpenFile( path, &curhttp->data.filedescriptor ); 296 | curhttp->bytessofar = 0; 297 | 298 | if( i < 0 ) 299 | { 300 | HTDEBUG( "404(%s)\n", path ); 301 | curhttp->is404 = 1; 302 | curhttp->isfirst = 1; 303 | curhttp->isdone = 0; 304 | curhttp->is_dynamic = 0; 305 | } 306 | else 307 | { 308 | curhttp->isfirst = 1; 309 | curhttp->isdone = 0; 310 | curhttp->is404 = 0; 311 | curhttp->is_dynamic = 0; 312 | curhttp->bytesleft = curhttp->data.filedescriptor.filelen; 313 | } 314 | 315 | } 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | LOCAL void ICACHE_FLASH_ATTR 325 | http_disconnetcb(void *arg) { 326 | struct espconn *pespconn = (struct espconn *) arg; 327 | ((struct HTTPConnection * )pespconn->reverse)->state = 0; 328 | } 329 | 330 | LOCAL void ICACHE_FLASH_ATTR 331 | http_recvcb(void *arg, char *pusrdata, unsigned short length) 332 | { 333 | struct espconn *pespconn = (struct espconn *) arg; 334 | 335 | //Though it might be possible for this to interrupt the other 336 | //tick task, I don't know if this is actually a probelem. 337 | //I'm adding this back-up-the-register just in case. 338 | if( curhttp ) { printf( "Unexpected Race Condition\n" );} 339 | 340 | curhttp = (struct HTTPConnection * )pespconn->reverse; 341 | curdata = (uint8*)pusrdata; 342 | curlen = length; 343 | HTTPGotData(); 344 | curhttp = 0 ; 345 | 346 | } 347 | 348 | void ICACHE_FLASH_ATTR 349 | httpserver_connectcb(void *arg) 350 | { 351 | int i; 352 | struct espconn *pespconn = (struct espconn *)arg; 353 | 354 | for( i = 0; i < HTTP_CONNECTIONS; i++ ) 355 | { 356 | if( HTTPConnections[i].state == 0 ) 357 | { 358 | pespconn->reverse = &HTTPConnections[i]; 359 | HTTPConnections[i].socket = pespconn; 360 | HTTPConnections[i].state = HTTP_STATE_WAIT_METHOD; 361 | break; 362 | } 363 | } 364 | if( i == HTTP_CONNECTIONS ) 365 | { 366 | espconn_disconnect( pespconn ); 367 | return; 368 | } 369 | 370 | // espconn_set_opt(pespconn, ESPCONN_NODELAY); 371 | // espconn_set_opt(pespconn, ESPCONN_COPY); 372 | 373 | espconn_regist_recvcb( pespconn, http_recvcb ); 374 | espconn_regist_disconcb( pespconn, http_disconnetcb ); 375 | 376 | } 377 | 378 | 379 | int ICACHE_FLASH_ATTR URLDecode( char * decodeinto, int maxlen, const char * buf ) 380 | { 381 | int i = 0; 382 | 383 | for( ; buf && *buf; buf++ ) 384 | { 385 | char c = *buf; 386 | if( c == '+' ) 387 | { 388 | decodeinto[i++] = ' '; 389 | } 390 | else if( c == '?' || c == '&' ) 391 | { 392 | break; 393 | } 394 | else if( c == '%' ) 395 | { 396 | if( *(buf+1) && *(buf+2) ) 397 | { 398 | decodeinto[i++] = hex2byte( buf+1 ); 399 | buf += 2; 400 | } 401 | } 402 | else 403 | { 404 | decodeinto[i++] = c; 405 | } 406 | if( i >= maxlen -1 ) break; 407 | 408 | } 409 | decodeinto[i] = 0; 410 | return i; 411 | } 412 | 413 | 414 | 415 | void ICACHE_FLASH_ATTR WebSocketGotData( uint8_t c ) 416 | { 417 | switch( curhttp->state_deets ) 418 | { 419 | case 0: 420 | { 421 | int i = 0; 422 | char inkey[120]; 423 | unsigned char hash[SHA1_HASH_LEN]; 424 | SHA1_CTX c; 425 | int inkeylen = 0; 426 | 427 | curhttp->is_dynamic = 1; 428 | while( curlen > 20 ) 429 | { 430 | curdata++; curlen--; 431 | if( strncmp( curdata, "Sec-WebSocket-Key: ", 19 ) == 0 ) 432 | { 433 | break; 434 | } 435 | } 436 | 437 | if( curlen <= 21 ) 438 | { 439 | HTDEBUG( "No websocket key found.\n" ); 440 | curhttp->state = HTTP_WAIT_CLOSE; 441 | return; 442 | } 443 | 444 | curdata+= 19; 445 | curlen -= 19; 446 | 447 | 448 | #define WS_KEY_LEN 36 449 | #define WS_KEY "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" 450 | #define WS_RETKEY_SIZEM1 32 451 | 452 | while( curlen > 1 ) 453 | { 454 | uint8_t lc = *(curdata++); 455 | inkey[i] = lc; 456 | curlen--; 457 | if( lc == '\r' ) 458 | { 459 | inkey[i] = 0; 460 | break; 461 | } 462 | i++; 463 | if( i >= sizeof( inkey ) - WS_KEY_LEN - 5 ) 464 | { 465 | HTDEBUG( "Websocket key too big.\n" ); 466 | curhttp->state = HTTP_WAIT_CLOSE; 467 | return; 468 | } 469 | } 470 | if( curlen <= 1 ) 471 | { 472 | HTDEBUG( "Invalid websocket key found.\n" ); 473 | curhttp->state = HTTP_WAIT_CLOSE; 474 | return; 475 | } 476 | 477 | if( i + WS_KEY_LEN + 1 >= sizeof( inkey ) ) 478 | { 479 | HTDEBUG( "WSKEY Too Big.\n" ); 480 | curhttp->state = HTTP_WAIT_CLOSE; 481 | return; 482 | } 483 | 484 | ets_memcpy( &inkey[i], WS_KEY, WS_KEY_LEN + 1 ); 485 | i += WS_KEY_LEN; 486 | SHA1_Init( &c ); 487 | SHA1_Update( &c, inkey, i ); 488 | SHA1_Final( hash, &c ); 489 | 490 | #if (WS_RETKEY_SIZE > MAX_PATHLEN - 10 ) 491 | #error MAX_PATHLEN too short. 492 | #endif 493 | 494 | my_base64_encode( hash, SHA1_HASH_LEN, curhttp->pathbuffer + (MAX_PATHLEN-WS_RETKEY_SIZEM1) ); 495 | 496 | curhttp->bytessofar = 0; 497 | curhttp->bytesleft = 0; 498 | 499 | NewWebSocket(); 500 | 501 | //Respond... 502 | curhttp->state_deets = 1; 503 | break; 504 | } 505 | case 1: 506 | if( c == '\n' ) curhttp->state_deets = 2; 507 | break; 508 | case 2: 509 | if( c == '\r' ) curhttp->state_deets = 3; 510 | else curhttp->state_deets = 1; 511 | break; 512 | case 3: 513 | if( c == '\n' ) curhttp->state_deets = 4; 514 | else curhttp->state_deets = 1; 515 | break; 516 | case 5: //Established connection. 517 | { 518 | //XXX TODO: Seems to malfunction on large-ish packets. I know it has problems with 140-byte payloads. 519 | 520 | if( curlen < 5 ) //Can't interpret packet. 521 | break; 522 | 523 | uint8_t fin = c & 1; 524 | uint8_t opcode = c << 4; 525 | uint16_t payloadlen = *(curdata++); 526 | curlen--; 527 | if( !(payloadlen & 0x80) ) 528 | { 529 | HTDEBUG( "Unmasked packet.\n" ); 530 | curhttp->state = HTTP_WAIT_CLOSE; 531 | break; 532 | } 533 | 534 | payloadlen &= 0x7f; 535 | 536 | if( payloadlen == 127 ) 537 | { 538 | //Very long payload. 539 | //Not supported. 540 | HTDEBUG( "Unsupported payload packet.\n" ); 541 | curhttp->state = HTTP_WAIT_CLOSE; 542 | break; 543 | } 544 | else if( payloadlen == 126 ) 545 | { 546 | payloadlen = (curdata[0] << 8) | curdata[1]; 547 | curdata += 2; 548 | curlen -= 2; 549 | } 550 | 551 | wsmask[0] = curdata[0]; 552 | wsmask[1] = curdata[1]; 553 | wsmask[2] = curdata[2]; 554 | wsmask[3] = curdata[3]; 555 | curdata += 4; 556 | curlen -= 4; 557 | wsmaskplace = 0; 558 | 559 | //XXX Warning: When packets get larger, they may split the 560 | //websockets packets into multiple parts. We could handle this 561 | //but at the cost of prescious RAM. I am chosing to just drop those 562 | //packets on the floor, and restarting the connection. 563 | if( curlen < payloadlen ) 564 | { 565 | HTDEBUG( "Websocket Fragmented. %d %d\n", curlen, payloadlen ); 566 | curhttp->state = HTTP_WAIT_CLOSE; 567 | return; 568 | } 569 | 570 | WebSocketData( payloadlen ); 571 | curlen -= payloadlen; 572 | curdata += payloadlen; 573 | 574 | break; 575 | } 576 | default: 577 | break; 578 | } 579 | } 580 | 581 | void ICACHE_FLASH_ATTR WebSocketTickInternal() 582 | { 583 | switch( curhttp->state_deets ) 584 | { 585 | case 4: //Has key full HTTP header, etc. wants response. 586 | START_PACK; 587 | PushString( "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: " ); 588 | PushString( curhttp->pathbuffer + (MAX_PATHLEN-WS_RETKEY_SIZEM1) ); 589 | PushString( "\r\n\r\n" ); 590 | EndTCPWrite( curhttp->socket ); 591 | curhttp->state_deets = 5; 592 | curhttp->keep_alive = 0; 593 | break; 594 | case 5: 595 | WebSocketTick(); 596 | break; 597 | } 598 | } 599 | 600 | void ICACHE_FLASH_ATTR WebSocketSend( uint8_t * data, int size ) 601 | { 602 | START_PACK; 603 | PushByte( 0x81 ); 604 | if( size > 126 ) 605 | { 606 | PushByte( 0x00 | 126 ); 607 | PushByte( size>>8 ); 608 | PushByte( size&0xff ); 609 | } 610 | else 611 | { 612 | PushByte( 0x00 | size ); 613 | } 614 | PushBlob( data, size ); 615 | EndTCPWrite( curhttp->socket ); 616 | } 617 | 618 | uint8_t WSPOPMASK() 619 | { 620 | uint8_t mask = wsmask[wsmaskplace]; 621 | wsmaskplace = (wsmaskplace+1)&3; 622 | return (*curdata++)^(mask); 623 | } 624 | 625 | 626 | -------------------------------------------------------------------------------- /common/http.h: -------------------------------------------------------------------------------- 1 | //Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or 2 | // ColorChord License. You Choose. 3 | 4 | #ifndef _HTTP_H 5 | #define _HTTP_H 6 | 7 | #include "mem.h" 8 | #include "c_types.h" 9 | #include "user_interface.h" 10 | #include "ets_sys.h" 11 | #include "driver/uart.h" 12 | #include "osapi.h" 13 | #include "espconn.h" 14 | #include "mfs.h" 15 | #include "mystuff.h" 16 | 17 | #define HTTP_SERVER_TIMEOUT 500 18 | #define HTTP_CONNECTIONS 8 19 | #define MAX_PATHLEN 80 20 | 21 | //You must provide: 22 | void ICACHE_FLASH_ATTR HTTPCustomStart( ); 23 | void ICACHE_FLASH_ATTR HTTPCustomCallback( ); //called when we can send more data 24 | 25 | void ICACHE_FLASH_ATTR WebSocketData( int len ); 26 | void ICACHE_FLASH_ATTR WebSocketTick( ); 27 | void ICACHE_FLASH_ATTR WebSocketNew(); 28 | 29 | extern struct HTTPConnection * curhttp; 30 | extern uint8 * curdata; 31 | extern uint16 curlen; 32 | extern uint8 wsmask[4]; 33 | extern uint8 wsmaskplace; 34 | 35 | uint8_t WSPOPMASK(); 36 | #define HTTPPOP (*curdata++) 37 | 38 | #define HTTP_STATE_NONE 0 39 | #define HTTP_STATE_WAIT_METHOD 1 40 | #define HTTP_STATE_WAIT_PATH 2 41 | #define HTTP_STATE_WAIT_PROTO 3 42 | 43 | #define HTTP_STATE_WAIT_FLAG 4 44 | #define HTTP_STATE_WAIT_INFLAG 5 45 | #define HTTP_STATE_DATA_XFER 7 46 | #define HTTP_STATE_DATA_WEBSOCKET 8 47 | 48 | #define HTTP_WAIT_CLOSE 15 49 | 50 | 51 | struct HTTPConnection 52 | { 53 | uint8_t state:4; 54 | uint8_t state_deets; 55 | 56 | //Provides path, i.e. "/index.html" but, for websockets, the last 57 | //32 bytes of the buffer are used for the websockets key. 58 | uint8_t pathbuffer[MAX_PATHLEN]; 59 | uint8_t is_dynamic:1; 60 | uint16_t timeout; 61 | 62 | union data_t 63 | { 64 | struct MFSFileInfo filedescriptor; 65 | struct UserData { uint16_t a, b, c; } user; 66 | } data; 67 | 68 | void * rcb; 69 | void * rcbDat; //For websockets primarily. 70 | 71 | uint32_t bytesleft; 72 | uint32_t bytessofar; 73 | 74 | uint8_t is404:1; 75 | uint8_t isdone:1; 76 | uint8_t isfirst:1; 77 | uint8_t keep_alive:1; 78 | uint8_t need_resend:1; 79 | 80 | struct espconn * socket; 81 | } HTTPConnections[HTTP_CONNECTIONS]; 82 | 83 | 84 | 85 | void ICACHE_FLASH_ATTR httpserver_connectcb(void *arg); 86 | 87 | void HTTPTick( uint8_t timedtick ); 88 | //you can call this a LOT if you want fast transfers, but be sure only to call it with a 1 at the update tick rate. 89 | 90 | int ICACHE_FLASH_ATTR URLDecode( char * decodeinto, int maxlen, const char * buf ); 91 | 92 | void ICACHE_FLASH_ATTR WebSocketGotData( uint8_t c ); 93 | void ICACHE_FLASH_ATTR WebSocketTickInternal(); 94 | 95 | void ICACHE_FLASH_ATTR WebSocketSend( uint8_t * data, int size ); 96 | 97 | 98 | #endif 99 | 100 | -------------------------------------------------------------------------------- /common/http_custom.c: -------------------------------------------------------------------------------- 1 | //Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or 2 | // ColorChord License. You Choose. 3 | 4 | #include "http.h" 5 | #include "mystuff.h" 6 | #include "commonservices.h" 7 | 8 | static ICACHE_FLASH_ATTR void huge() 9 | { 10 | uint8_t i = 0; 11 | 12 | START_PACK; 13 | do 14 | { 15 | PushByte( 0 ); 16 | PushByte( i ); 17 | } while( ++i ); //Tricky: this will roll-over to 0, and thus only execute 256 times. 18 | 19 | EndTCPWrite( curhttp->socket ); 20 | } 21 | 22 | 23 | static ICACHE_FLASH_ATTR void echo() 24 | { 25 | char mydat[128]; 26 | int len = URLDecode( mydat, 128, curhttp->pathbuffer+8 ); 27 | 28 | START_PACK; 29 | PushBlob( mydat, len ); 30 | EndTCPWrite( curhttp->socket ); 31 | 32 | curhttp->state = HTTP_WAIT_CLOSE; 33 | } 34 | 35 | static ICACHE_FLASH_ATTR void issue() 36 | { 37 | uint8_t __attribute__ ((aligned (32))) buf[1300]; 38 | int len = URLDecode( buf, 1300, curhttp->pathbuffer+9 ); 39 | 40 | int r = issue_command(buf, 1300, buf, len ); 41 | if( r > 0 ) 42 | { 43 | START_PACK; 44 | PushBlob( buf, r ); 45 | EndTCPWrite( curhttp->socket ); 46 | } 47 | curhttp->state = HTTP_WAIT_CLOSE; 48 | } 49 | 50 | 51 | void ICACHE_FLASH_ATTR HTTPCustomStart( ) 52 | { 53 | if( strncmp( (const char*)curhttp->pathbuffer, "/d/huge", 7 ) == 0 ) 54 | { 55 | curhttp->rcb = (void(*)())&huge; 56 | curhttp->bytesleft = 0xffffffff; 57 | } 58 | else 59 | if( strncmp( (const char*)curhttp->pathbuffer, "/d/echo?", 8 ) == 0 ) 60 | { 61 | curhttp->rcb = (void(*)())&echo; 62 | curhttp->bytesleft = 0xfffffffe; 63 | } 64 | else 65 | if( strncmp( (const char*)curhttp->pathbuffer, "/d/issue?", 9 ) == 0 ) 66 | { 67 | curhttp->rcb = (void(*)())&issue; 68 | curhttp->bytesleft = 0xfffffffe; 69 | } 70 | else 71 | { 72 | curhttp->rcb = 0; 73 | curhttp->bytesleft = 0; 74 | } 75 | curhttp->isfirst = 1; 76 | HTTPHandleInternalCallback(); 77 | } 78 | 79 | 80 | 81 | void ICACHE_FLASH_ATTR HTTPCustomCallback( ) 82 | { 83 | if( curhttp->rcb ) 84 | ((void(*)())curhttp->rcb)(); 85 | else 86 | curhttp->isdone = 1; 87 | } 88 | 89 | 90 | 91 | 92 | static void ICACHE_FLASH_ATTR WSEchoData( int len ) 93 | { 94 | char cbo[len]; 95 | int i; 96 | for( i = 0; i < len; i++ ) 97 | { 98 | cbo[i] = WSPOPMASK(); 99 | } 100 | WebSocketSend( cbo, len ); 101 | } 102 | 103 | 104 | static void ICACHE_FLASH_ATTR WSEvalData( int len ) 105 | { 106 | char cbo[128]; 107 | int l = ets_sprintf( cbo, "output.innerHTML = %d; doSend('x' );", curhttp->bytessofar++ ); 108 | 109 | WebSocketSend( cbo, l ); 110 | } 111 | 112 | 113 | static void ICACHE_FLASH_ATTR WSCommandData( int len ) 114 | { 115 | uint8_t __attribute__ ((aligned (32))) buf[1300]; 116 | int i; 117 | 118 | for( i = 0; i < len; i++ ) 119 | { 120 | buf[i] = WSPOPMASK(); 121 | } 122 | 123 | i = issue_command(buf, 1300, buf, len ); 124 | 125 | if( i < 0 ) i = 0; 126 | 127 | WebSocketSend( buf, i ); 128 | } 129 | 130 | 131 | // output.innerHTML = msg++ + " " + lasthz; 132 | // doSend('x' ); 133 | 134 | 135 | 136 | void ICACHE_FLASH_ATTR NewWebSocket() 137 | { 138 | if( strcmp( (const char*)curhttp->pathbuffer, "/d/ws/echo" ) == 0 ) 139 | { 140 | curhttp->rcb = 0; 141 | curhttp->rcbDat = (void*)&WSEchoData; 142 | } 143 | else if( strcmp( (const char*)curhttp->pathbuffer, "/d/ws/evaltest" ) == 0 ) 144 | { 145 | curhttp->rcb = 0; 146 | curhttp->rcbDat = (void*)&WSEvalData; 147 | } 148 | else if( strncmp( (const char*)curhttp->pathbuffer, "/d/ws/issue", 11 ) == 0 ) 149 | { 150 | curhttp->rcb = 0; 151 | curhttp->rcbDat = (void*)&WSCommandData; 152 | } 153 | else 154 | { 155 | curhttp->is404 = 1; 156 | } 157 | } 158 | 159 | 160 | 161 | 162 | void ICACHE_FLASH_ATTR WebSocketTick() 163 | { 164 | if( curhttp->rcb ) 165 | { 166 | ((void(*)())curhttp->rcb)(); 167 | } 168 | } 169 | 170 | void ICACHE_FLASH_ATTR WebSocketData( int len ) 171 | { 172 | if( curhttp->rcbDat ) 173 | { 174 | ((void(*)( int ))curhttp->rcbDat)( len ); 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /common/mdns.c: -------------------------------------------------------------------------------- 1 | #include "mdns.h" 2 | #include "commonservices.h" 3 | #include "mem.h" 4 | #include "c_types.h" 5 | #include "user_interface.h" 6 | #include "ets_sys.h" 7 | #include "osapi.h" 8 | #include "espconn.h" 9 | #include "mystuff.h" 10 | #include "ip_addr.h" 11 | 12 | #define MDNS_BRD 0xfb0000e0 13 | 14 | static char * MDNSNames[MAX_MDNS_NAMES]; 15 | static struct espconn *pMDNSServer; 16 | static uint8_t igmp_bound[4]; 17 | static char MyLocalName[MAX_MDNS_PATH+7]; 18 | 19 | static int nr_services = 0; 20 | static char * MDNSServices[MAX_MDNS_SERVICES]; 21 | static char * MDNSServiceTexts[MAX_MDNS_SERVICES]; 22 | static uint16_t MDNSServicePorts[MAX_MDNS_SERVICES]; 23 | 24 | static char MDNSSearchName[MAX_MDNS_PATH]; 25 | 26 | 27 | void ICACHE_FLASH_ATTR AddMDNSService( const char * ServiceName, const char * Text, int port ) 28 | { 29 | int i; 30 | for( i = 0; i < MAX_MDNS_SERVICES; i++ ) 31 | { 32 | if( !MDNSServices[i] ) 33 | { 34 | MDNSServices[i] = strdupcaselower( ServiceName ); 35 | MDNSServiceTexts[i] = strdup( Text ); 36 | MDNSServicePorts[i] = port; 37 | nr_services++; 38 | break; 39 | } 40 | } 41 | } 42 | 43 | void ICACHE_FLASH_ATTR AddMDNSName( const char * ToDup ) 44 | { 45 | int i; 46 | for( i = 1; i < MAX_MDNS_NAMES; i++ ) 47 | { 48 | if( !MDNSNames[i] ) 49 | { 50 | if( i == 0 ) 51 | { 52 | int sl = ets_strlen( ToDup ); 53 | ets_memcpy( MyLocalName, ToDup, sl ); 54 | ets_memcpy( MyLocalName + sl, ".local", 7 ); 55 | } 56 | MDNSNames[i] = strdupcaselower( ToDup ); 57 | break; 58 | } 59 | } 60 | } 61 | 62 | void ICACHE_FLASH_ATTR ClearMDNSNames() 63 | { 64 | int i; 65 | for( i = 0; i < MAX_MDNS_NAMES; i++ ) 66 | { 67 | if( MDNSNames[i] ) 68 | { 69 | os_zfree( MDNSNames[i] ); 70 | MDNSNames[i] = 0; 71 | } 72 | } 73 | for( i = 0; i < MAX_MDNS_SERVICES; i++ ) 74 | { 75 | if( MDNSServices[i] ) 76 | { 77 | os_zfree( MDNSServices[i] ); MDNSServices[i] = 0; 78 | os_zfree( MDNSServiceTexts[i] ); MDNSServiceTexts[i] = 0; 79 | MDNSServicePorts[i] = 0; 80 | } 81 | } 82 | nr_services = 0; 83 | ets_memset( MyLocalName, 0, sizeof( MyLocalName ) ); 84 | MDNSNames[0] = strdupcaselower( &SETTINGS.DeviceName[0] ); 85 | } 86 | 87 | uint8_t * ICACHE_FLASH_ATTR ParseMDNSPath( uint8_t * dat, char * topop, int * len ) 88 | { 89 | int l; 90 | int j; 91 | *len = 0; 92 | do 93 | { 94 | l = *(dat++); 95 | if( l == 0 ) 96 | { 97 | *topop = 0; 98 | return dat; 99 | } 100 | if( *len + l >= MAX_MDNS_PATH ) return 0; 101 | 102 | //If not our first time through, add a '.' 103 | if( *len != 0 ) 104 | { 105 | *(topop++) = '.'; 106 | (*len)++; 107 | } 108 | 109 | for( j = 0; j < l; j++ ) 110 | { 111 | if( dat[j] >= 'A' && dat[j] <= 'Z' ) 112 | topop[j] = dat[j] - 'A' + 'a'; 113 | else 114 | topop[j] = dat[j]; 115 | } 116 | topop += l; 117 | dat += l; 118 | *topop = 0; //Null terminate. 119 | *len += l; 120 | } while( 1 ); 121 | } 122 | 123 | uint8_t * ICACHE_FLASH_ATTR SendPathSegment( uint8_t * dat, const char * path ) 124 | { 125 | char c; 126 | int i; 127 | do 128 | { 129 | const char * pathstart = path; 130 | int this_seg_length = 0; 131 | while( c = *(path++) ) 132 | { 133 | if( c == '.' ) break; 134 | this_seg_length++; 135 | } 136 | if( !this_seg_length ) return dat; 137 | 138 | *(dat++) = this_seg_length; 139 | for( i = 0; i < this_seg_length; i++ ) 140 | { 141 | *(dat++) = *(pathstart++); 142 | } 143 | } while( c != 0 ); 144 | return dat; 145 | } 146 | 147 | uint8_t * ICACHE_FLASH_ATTR TackTemp( uint8_t * obptr ) 148 | { 149 | *(obptr++) = ets_strlen( MDNSNames[0] ); 150 | ets_memcpy( obptr, MDNSNames[0], ets_strlen( MDNSNames[0] ) ); 151 | obptr+=ets_strlen( MDNSNames[0] ); 152 | *(obptr++) = 0xc0; *(obptr++) = 0x0c; //continue the name. 153 | return obptr; 154 | } 155 | 156 | static void ICACHE_FLASH_ATTR SendOurARecord( uint8_t * namestartptr, int xactionid, int stlen ) 157 | { 158 | //Found match with us. 159 | //Send a response. 160 | 161 | uint8_t outbuff[MAX_MDNS_PATH+32]; 162 | uint8_t * obptr = outbuff; 163 | uint16_t * obb = (uint16_t*)outbuff; 164 | *(obb++) = xactionid; 165 | *(obb++) = HTONS(0x8400); //Authortative response. 166 | *(obb++) = 0; 167 | *(obb++) = HTONS(1); //1 answer. 168 | *(obb++) = 0; 169 | *(obb++) = 0; 170 | 171 | obptr = (uint8_t*)obb; 172 | ets_memcpy( obptr, namestartptr, stlen+1 ); //Hack: Copy the name in. 173 | obptr += stlen+1; 174 | *(obptr++) = 0; 175 | *(obptr++) = 0x00; *(obptr++) = 0x01; //A record 176 | *(obptr++) = 0x80; *(obptr++) = 0x01; //Flush cache + in ptr. 177 | *(obptr++) = 0x00; *(obptr++) = 0x00; //TTL 178 | *(obptr++) = 0x00; *(obptr++) = 120; //very short. (120 seconds) 179 | *(obptr++) = 0x00; *(obptr++) = 0x04; //Size 4 (IP) 180 | ets_memcpy( obptr, pMDNSServer->proto.udp->local_ip, 4 ); 181 | obptr+=4; 182 | uint32_t md = MDNS_BRD; 183 | ets_memcpy( pMDNSServer->proto.udp->remote_ip, &md, 4 ); 184 | espconn_sent( pMDNSServer, outbuff, obptr - outbuff ); 185 | } 186 | 187 | static void ICACHE_FLASH_ATTR SendAvailableServices( uint8_t * namestartptr, int xactionid, int stlen ) 188 | { 189 | int i; 190 | if( nr_services == 0 ) return; 191 | uint8_t outbuff[(MAX_MDNS_PATH+14)*MAX_MDNS_SERVICES+32]; 192 | uint8_t * obptr = outbuff; 193 | uint16_t * obb = (uint16_t*)outbuff; 194 | *(obb++) = xactionid; 195 | *(obb++) = HTONS(0x8400); //Authortative response. 196 | *(obb++) = 0; 197 | *(obb++) = HTONS(nr_services); //Answers 198 | *(obb++) = 0; 199 | *(obb++) = 0; 200 | 201 | obptr = (uint8_t*)obb; 202 | 203 | for( i = 0; i < nr_services; i++ ) 204 | { 205 | char localservicename[MAX_MDNS_PATH+8]; 206 | 207 | ets_memcpy( obptr, namestartptr, stlen+1 ); //Hack: Copy the name in. 208 | obptr += stlen+1; 209 | *(obptr++) = 0; 210 | *(obptr++) = 0x00; *(obptr++) = 0x0c; //PTR record 211 | *(obptr++) = 0x00; *(obptr++) = 0x01; //Don't flush cache + ptr 212 | *(obptr++) = 0x00; *(obptr++) = 0x00; //TTL 213 | *(obptr++) = 0x00; *(obptr++) = 0xf0; //4 minute TTL. 214 | 215 | int sl = ets_strlen( MDNSServices[i] ); 216 | ets_memcpy( localservicename, MDNSServices[i], sl ); 217 | ets_memcpy( localservicename+sl, ".local", 7 ); 218 | *(obptr++) = 0x00; *(obptr++) = sl+8; 219 | obptr = SendPathSegment( obptr, localservicename ); 220 | *(obptr++) = 0x00; 221 | } 222 | 223 | //Send to broadcast. 224 | uint32_t md = MDNS_BRD; 225 | ets_memcpy( pMDNSServer->proto.udp->remote_ip, &md, 4 ); 226 | espconn_sent( pMDNSServer, outbuff, obptr - outbuff ); 227 | } 228 | 229 | 230 | 231 | static void ICACHE_FLASH_ATTR SendSpecificService( int sid, uint8_t*namestartptr, int xactionid, int stlen, int is_prefix ) 232 | { 233 | uint8_t outbuff[256]; 234 | uint8_t * obptr = outbuff; 235 | uint16_t * obb = (uint16_t*)outbuff; 236 | 237 | const char *sn = MDNSServices[sid]; 238 | const char *st = MDNSServiceTexts[sid]; int stl = ets_strlen( st ); 239 | int sp = MDNSServicePorts[sid]; 240 | 241 | *(obb++) = xactionid; 242 | *(obb++) = HTONS(0x8400); //We are authoratative. And this is a response. 243 | *(obb++) = 0; 244 | *(obb++) = HTONS(sp?4:3); //4 answers. (or 3 if we don't have a port) 245 | *(obb++) = 0; 246 | *(obb++) = 0; 247 | 248 | 249 | if( !sn || !st ) return; 250 | 251 | obptr = (uint8_t*)obb; 252 | // ets_memcpy( obptr, namestartptr, stlen+1 ); //Hack: Copy the name in. 253 | // obptr += stlen+1; 254 | obptr = SendPathSegment( obptr, sn ); 255 | obptr = SendPathSegment( obptr, "local" ); 256 | *(obptr++) = 0; 257 | 258 | *(obptr++) = 0x00; *(obptr++) = 0x0c; //PTR record 259 | *(obptr++) = 0x00; *(obptr++) = 0x01; //No Flush cache + in ptr. 260 | *(obptr++) = 0x00; *(obptr++) = 0x00; //TTL 261 | *(obptr++) = 0x00; *(obptr++) = 100; //very short. (100 seconds) 262 | 263 | if( !is_prefix ) 264 | { 265 | *(obptr++) = 0x00; *(obptr++) = ets_strlen( MDNSNames[0] ) + 3; //Service... 266 | obptr = TackTemp( obptr ); 267 | } 268 | else 269 | { 270 | *(obptr++) = 0x00; *(obptr++) = 2; 271 | *(obptr++) = 0xc0; *(obptr++) = 0x0c; //continue the name. 272 | } 273 | 274 | 275 | if( !is_prefix ) 276 | { 277 | obptr = TackTemp( obptr ); 278 | } 279 | else 280 | { 281 | *(obptr++) = 0xc0; *(obptr++) = 0x0c; //continue the name. 282 | } 283 | 284 | *(obptr++) = 0x00; *(obptr++) = 0x10; //TXT record 285 | *(obptr++) = 0x80; *(obptr++) = 0x01; //Flush cache + in ptr. 286 | *(obptr++) = 0x00; *(obptr++) = 0x00; //TTL 287 | *(obptr++) = 0x00; *(obptr++) = 100; //very short. (100 seconds) 288 | *(obptr++) = 0x00; *(obptr++) = stl + 1; //Service... 289 | *(obptr++) = stl; //Service length 290 | ets_memcpy( obptr, st, stl ); 291 | obptr += stl; 292 | 293 | //Service record 294 | if( sp ) 295 | { 296 | int localnamelen = ets_strlen( MyLocalName ); 297 | 298 | 299 | if( !is_prefix ) 300 | { 301 | obptr = TackTemp( obptr ); 302 | } 303 | else 304 | { 305 | *(obptr++) = 0xc0; *(obptr++) = 0x0c; //continue the name. 306 | } 307 | 308 | //obptr = TackTemp( obptr ); 309 | //*(obptr++) = 0xc0; *(obptr++) = 0x2f; //continue the name. 310 | *(obptr++) = 0x00; *(obptr++) = 0x21; //SRV record 311 | *(obptr++) = 0x80; *(obptr++) = 0x01; //Don't Flush cache + in ptr. 312 | *(obptr++) = 0x00; *(obptr++) = 0x00; //TTL 313 | *(obptr++) = 0x00; *(obptr++) = 100; //very short. (100 seconds) 314 | *(obptr++) = 0x00; *(obptr++) = localnamelen + 7 + 1; //Service? 315 | *(obptr++) = 0x00; *(obptr++) = 0x00; //Priority 316 | *(obptr++) = 0x00; *(obptr++) = 0x00; //Weight 317 | *(obptr++) = sp>>8; *(obptr++) = sp&0xff; //Port# 318 | obptr = SendPathSegment( obptr, MyLocalName ); 319 | *(obptr++) = 0; 320 | } 321 | 322 | //A Record 323 | obptr = SendPathSegment( obptr, MyLocalName ); 324 | *(obptr++) = 0; 325 | *(obptr++) = 0x00; *(obptr++) = 0x01; //A record 326 | *(obptr++) = 0x80; *(obptr++) = 0x01; //Flush cache + in ptr. 327 | *(obptr++) = 0x00; *(obptr++) = 0x00; //TTL 328 | *(obptr++) = 0x00; *(obptr++) = 30; //very short. (30 seconds) 329 | *(obptr++) = 0x00; *(obptr++) = 0x04; //Size 4 (IP) 330 | ets_memcpy( obptr, pMDNSServer->proto.udp->local_ip, 4 ); 331 | obptr+=4; 332 | 333 | //Send to broadcast. 334 | uint32_t md = MDNS_BRD; 335 | ets_memcpy( pMDNSServer->proto.udp->remote_ip, &md, 4 ); 336 | espconn_sent( pMDNSServer, outbuff, obptr - outbuff ); 337 | } 338 | 339 | 340 | static void ICACHE_FLASH_ATTR got_mdns_packet(void *arg, char *pusrdata, unsigned short len) 341 | { 342 | int i, j, stlen; 343 | char path[MAX_MDNS_PATH]; 344 | 345 | uint16_t * psr = (uint16_t*)pusrdata; 346 | uint16_t xactionid = HTONS( psr[0] ); 347 | uint16_t flags = HTONS( psr[1] ); 348 | uint16_t questions = HTONS( psr[2] ); 349 | uint16_t answers = HTONS( psr[3] ); 350 | 351 | uint8_t * dataptr = (uint8_t*)pusrdata + 12; 352 | uint8_t * dataend = dataptr + len; 353 | 354 | if( flags & 0x8000 ) 355 | { 356 | //Response 357 | 358 | //Unused; MDNS does not fit the browse model we want to use. 359 | } 360 | else 361 | { 362 | //Query 363 | for( i = 0; i < questions; i++ ) 364 | { 365 | uint8_t * namestartptr = dataptr; 366 | //Work our way through. 367 | dataptr = ParseMDNSPath( dataptr, path, &stlen ); 368 | 369 | if( dataend - dataptr < 10 ) return; 370 | 371 | if( !dataptr ) 372 | { 373 | return; 374 | } 375 | 376 | int pathlen = ets_strlen( path ); 377 | if( pathlen < 6 ) 378 | { 379 | continue; 380 | } 381 | if( strcmp( path + pathlen - 6, ".local" ) != 0 ) 382 | { 383 | continue; 384 | } 385 | uint16_t record_type = ( dataptr[0] << 8 ) | dataptr[1]; 386 | uint16_t record_class = ( dataptr[2] << 8 ) | dataptr[3]; 387 | 388 | const char * path_first_dot = path; 389 | const char * cpp = path; 390 | while( *cpp && *cpp != '.' ) cpp++; 391 | int dotlen = 0; 392 | if( *cpp == '.' ) 393 | { 394 | path_first_dot = cpp+1; 395 | dotlen = path_first_dot - path - 1; 396 | } 397 | else 398 | path_first_dot = 0; 399 | 400 | int found = 0; 401 | for( i = 0; i < MAX_MDNS_NAMES; i++ ) 402 | { 403 | //Handle [hostname].local, or [hostname].[service].local 404 | if( MDNSNames[i] && dotlen && ets_strncmp( MDNSNames[i], path, dotlen ) == 0 && dotlen == ets_strlen( MDNSNames[i] )) 405 | { 406 | found = 1; 407 | if( record_type == 0x0001 ) //A Name Lookup. 408 | SendOurARecord( namestartptr, xactionid, stlen ); 409 | else 410 | SendSpecificService( i, namestartptr, xactionid, stlen, 1 ); 411 | } 412 | } 413 | 414 | if( !found ) //Not a specific entry lookup... 415 | { 416 | //Is this a browse? 417 | if( ets_strcmp( path, "_services._dns-sd._udp.local" ) == 0 ) 418 | { 419 | SendAvailableServices( namestartptr, xactionid, stlen ); 420 | } 421 | else 422 | { 423 | //A specific service? 424 | for( i = 0; i < MAX_MDNS_SERVICES; i++ ) 425 | { 426 | const char * srv = MDNSServices[i]; 427 | if( !srv ) continue; 428 | int sl = ets_strlen( srv ); 429 | if( strncmp( path, srv, sl ) == 0 ) 430 | { 431 | SendSpecificService( i, namestartptr, xactionid, stlen, 0 ); 432 | } 433 | } 434 | } 435 | } 436 | } 437 | } 438 | } 439 | 440 | void ICACHE_FLASH_ATTR SetupMDNS() 441 | { 442 | MDNSNames[0] = strdupcaselower( &SETTINGS.DeviceName[0] ); 443 | 444 | pMDNSServer = (struct espconn *)os_zalloc(sizeof(struct espconn)); 445 | ets_memset( pMDNSServer, 0, sizeof( struct espconn ) ); 446 | pMDNSServer->type = ESPCONN_UDP; 447 | pMDNSServer->proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp)); 448 | pMDNSServer->proto.udp->local_port = 5353; 449 | espconn_regist_recvcb(pMDNSServer, got_mdns_packet); 450 | espconn_create( pMDNSServer ); 451 | } 452 | 453 | int ICACHE_FLASH_ATTR JoinGropMDNS() 454 | { 455 | uint32_t ip = GetCurrentIP(); 456 | if( ip ) 457 | { 458 | struct ip_addr grpip; 459 | grpip.addr = MDNS_BRD; 460 | printf( "IGMP Joining: %08x %08x\n", ip, grpip.addr ); 461 | ets_memcpy( igmp_bound, &grpip.addr, 4 ); 462 | espconn_igmp_join( (ip_addr_t *)&ip, &grpip); 463 | return 0; 464 | } 465 | return 1; 466 | } 467 | 468 | 469 | -------------------------------------------------------------------------------- /common/mdns.h: -------------------------------------------------------------------------------- 1 | #ifndef _MDNS_H 2 | #define _MDNS_H 3 | 4 | #include "c_types.h" 5 | 6 | #define MAX_MDNS_NAMES 5 7 | #define MAX_MDNS_SERVICES 5 8 | #define MAX_MDNS_PATH 32 9 | 10 | void ICACHE_FLASH_ATTR SetupMDNS(); 11 | int ICACHE_FLASH_ATTR JoinGropMDNS(); //returns nonzero on failure. 12 | 13 | //This _does_ dup the data. Don't worry about keeping the data around. 14 | //Matching name, to respond with full suite of what-I-have 15 | //The first name is automatically inserted to be the device name. 16 | void ICACHE_FLASH_ATTR MDNSAddName( const char * ToDup ); 17 | 18 | //Add service names here, I.e. _http._tcp. or "esp8266" this will make us respond when we get 19 | //those kinds of requests. 20 | // 21 | //All data is dupped 22 | void ICACHE_FLASH_ATTR AddMDNSService( const char * ServiceName, const char * Text, int port ); 23 | 24 | //Reset all services and matches. 25 | void ICACHE_FLASH_ATTR ClearMDNS(); 26 | 27 | uint8_t * ICACHE_FLASH_ATTR ParseMDNSPath( uint8_t * dat, char * topop, int * len ); 28 | //Sends part of a path, but, does not terminate, so you an concatinate paths. 29 | uint8_t * ICACHE_FLASH_ATTR SendPathSegment( uint8_t * dat, const char * path ); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /common/mfs.c: -------------------------------------------------------------------------------- 1 | //Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or 2 | // ColorChord License. You Choose. 3 | 4 | #include "mystuff.h" 5 | #include "mfs.h" 6 | #include "spi_flash.h" 7 | #include "ets_sys.h" 8 | 9 | uint32 mfs_at = 0; 10 | 11 | void FindMPFS() 12 | { 13 | uint32 mfs_check[2]; 14 | EnterCritical(); 15 | flashchip->chip_size = 0x01000000; 16 | 17 | spi_flash_read( MFS_START, mfs_check, sizeof( mfs_check ) ); 18 | if( strncmp( "MPFSPFS", mfs_check ) == 0 ) { mfs_at = MFS_START; goto done; } 19 | 20 | spi_flash_read( MFS_ALTERNATIVE_START, mfs_check, sizeof( mfs_check ) ); 21 | if( strncmp( "MPFSPFS", mfs_check ) == 0 ) { mfs_at = MFS_ALTERNATIVE_START; goto done; } 22 | 23 | 24 | done: 25 | flashchip->chip_size = 0x00080000; 26 | ExitCritical(); 27 | } 28 | 29 | extern SpiFlashChip * flashchip; 30 | 31 | //Returns 0 on succses. 32 | //Returns size of file if non-empty 33 | //If positive, populates mfi. 34 | //Returns -1 if can't find file or reached end of file list. 35 | int8_t MFSOpenFile( const char * fname, struct MFSFileInfo * mfi ) 36 | { 37 | if( mfs_at == 0 ) 38 | { 39 | FindMPFS(); 40 | } 41 | if( mfs_at == 0 ) 42 | { 43 | return -1; 44 | } 45 | 46 | EnterCritical(); 47 | flashchip->chip_size = 0x01000000; 48 | uint32 ptr = mfs_at; 49 | struct MFSFileEntry e; 50 | while(1) 51 | { 52 | spi_flash_read( ptr, (uint32*)&e, sizeof( e ) ); 53 | ptr += sizeof(e); 54 | if( e.name[0] == 0xff || ets_strlen( e.name ) == 0 ) break; 55 | 56 | if( ets_strcmp( e.name, fname ) == 0 ) 57 | { 58 | mfi->offset = e.start; 59 | mfi->filelen = e.len; 60 | flashchip->chip_size = 0x00080000; 61 | ExitCritical(); 62 | return 0; 63 | } 64 | } 65 | flashchip->chip_size = 0x00080000; 66 | ExitCritical(); 67 | return -1; 68 | } 69 | 70 | int32_t MFSReadSector( uint8_t* data, struct MFSFileInfo * mfi ) 71 | { 72 | //returns # of bytes left tin file. 73 | if( !mfi->filelen ) 74 | { 75 | return 0; 76 | } 77 | 78 | int toread = mfi->filelen; 79 | if( toread > MFS_SECTOR ) toread = MFS_SECTOR; 80 | 81 | EnterCritical(); 82 | flashchip->chip_size = 0x01000000; 83 | spi_flash_read( mfs_at+mfi->offset, (uint32*)data, MFS_SECTOR ); 84 | flashchip->chip_size = 0x00080000; 85 | ExitCritical(); 86 | 87 | mfi->offset += toread; 88 | mfi->filelen -= toread; 89 | return mfi->filelen; 90 | } 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /common/mfs.h: -------------------------------------------------------------------------------- 1 | //Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or 2 | // ColorChord License. You Choose. 3 | 4 | //Not to be confused with MFS for the AVR. 5 | 6 | #ifndef _MFS_H 7 | #define _MFS_H 8 | 9 | #include "mem.h" 10 | #include "c_types.h" 11 | #include "mystuff.h" 12 | 13 | //SPI_FLASH_SEC_SIZE 4096 14 | 15 | //If you are on a chip with limited space, MFS can alternatively live here, with a max size of 180kB. 16 | #define MFS_ALTERNATIVE_START 0x10000 17 | 18 | #define MFS_STARTFLASHSECTOR 0x100 19 | #define MFS_START (MFS_STARTFLASHSECTOR*SPI_FLASH_SEC_SIZE) 20 | #define MFS_SECTOR 256 21 | 22 | 23 | #define MFS_FILENAMELEN 32-8 24 | 25 | //Format: 26 | // [FILE NAME (24)] [Start (4)] [Len (4)] 27 | // NOTE: Filename must be null-terminated within the 24. 28 | struct MFSFileEntry 29 | { 30 | char name[MFS_FILENAMELEN]; 31 | uint32 start; //From beginning of mfs thing. 32 | uint32 len; 33 | }; 34 | 35 | 36 | struct MFSFileInfo 37 | { 38 | uint32 offset; 39 | uint32 filelen; 40 | }; 41 | 42 | 43 | 44 | //Returns 0 on succses. 45 | //Returns size of file if non-empty 46 | //If positive, populates mfi. 47 | //Returns -1 if can't find file or reached end of file list. 48 | ICACHE_FLASH_ATTR int8_t MFSOpenFile( const char * fname, struct MFSFileInfo * mfi ); 49 | ICACHE_FLASH_ATTR int32_t MFSReadSector( uint8_t* data, struct MFSFileInfo * mfi ); //returns # of bytes left in file. 50 | 51 | 52 | 53 | #endif 54 | 55 | 56 | -------------------------------------------------------------------------------- /common/mystuff.c: -------------------------------------------------------------------------------- 1 | //Unless what else is individually marked, all code in this file is 2 | //Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or 3 | // ColorChord License. You Choose. 4 | 5 | #include "mystuff.h" 6 | #include 7 | #include 8 | 9 | const char * enctypes[6] = { "open", "wep", "wpa", "wpa2", "wpa_wpa2", 0 }; 10 | 11 | char generic_print_buffer[384]; 12 | char generic_buffer[1500]; 13 | char * generic_ptr; 14 | 15 | int32 my_atoi( const char * in ) 16 | { 17 | int positive = 1; //1 if negative. 18 | int hit = 0; 19 | int val = 0; 20 | while( *in && hit < 11 ) 21 | { 22 | if( *in == '-' ) 23 | { 24 | if( positive == -1 ) return val*positive; 25 | positive = -1; 26 | } else if( *in >= '0' && *in <= '9' ) 27 | { 28 | val *= 10; 29 | val += *in - '0'; 30 | hit++; 31 | } else if (!hit && ( *in == ' ' || *in == '\t' ) ) 32 | { 33 | //okay 34 | } else 35 | { 36 | //bad. 37 | return val*positive; 38 | } 39 | in++; 40 | } 41 | return val*positive; 42 | } 43 | 44 | void Uint32To10Str( char * out, uint32 dat ) 45 | { 46 | int tens = 1000000000; 47 | int val; 48 | int place = 0; 49 | 50 | while( tens > 1 ) 51 | { 52 | if( dat/tens ) break; 53 | tens/=10; 54 | } 55 | 56 | while( tens ) 57 | { 58 | val = dat/tens; 59 | dat -= val*tens; 60 | tens /= 10; 61 | out[place++] = val + '0'; 62 | } 63 | 64 | out[place] = 0; 65 | } 66 | 67 | char tohex1( uint8_t i ) 68 | { 69 | i = i&0x0f; 70 | return (i<10)?('0'+i):('a'-10+i); 71 | } 72 | 73 | int8_t fromhex1( char c ) 74 | { 75 | if( c >= '0' && c <= '9' ) 76 | return c - '0'; 77 | else if( c >= 'a' && c <= 'f' ) 78 | return c - 'a' + 10; 79 | else if( c >= 'A' && c <= 'F' ) 80 | return c - 'A' + 10; 81 | else 82 | return -1; 83 | } 84 | 85 | void NixNewline( char * str ) 86 | { 87 | if( !str ) return; 88 | int sl = ets_strlen( str ); 89 | if( sl > 1 && str[sl-1] == '\n' ) str[sl-1] = 0; 90 | if( sl > 2 && str[sl-2] == '\r' ) str[sl-2] = 0; 91 | } 92 | 93 | 94 | 95 | void ICACHE_FLASH_ATTR EndTCPWrite( struct espconn * conn ) 96 | { 97 | if(generic_ptr!=generic_buffer) 98 | { 99 | int r = espconn_sent(conn,generic_buffer,generic_ptr-generic_buffer); 100 | } 101 | } 102 | 103 | 104 | void PushString( const char * buffer ) 105 | { 106 | char c; 107 | while( c = *(buffer++) ) 108 | PushByte( c ); 109 | } 110 | 111 | void PushBlob( const uint8 * buffer, int len ) 112 | { 113 | int i; 114 | for( i = 0; i < len; i++ ) 115 | PushByte( buffer[i] ); 116 | } 117 | 118 | 119 | int8_t TCPCanSend( struct espconn * conn, int size ) 120 | { 121 | #ifdef SAFESEND 122 | return TCPDoneSend( conn ); 123 | #else 124 | struct espconn_packet infoarg; 125 | sint8 r = espconn_get_packet_info(conn, &infoarg); 126 | 127 | if( infoarg.snd_buf_size >= size && infoarg.snd_queuelen > 0 ) 128 | return 1; 129 | else 130 | return 0; 131 | #endif 132 | } 133 | 134 | int8_t ICACHE_FLASH_ATTR TCPDoneSend( struct espconn * conn ) 135 | { 136 | return conn->state == ESPCONN_CONNECT; 137 | } 138 | 139 | const char * ICACHE_FLASH_ATTR my_strchr( const char * st, char c ) 140 | { 141 | while( *st && *st != c ) st++; 142 | if( !*st ) return 0; 143 | return st; 144 | } 145 | 146 | int ICACHE_FLASH_ATTR ColonsToInts( const char * str, int32_t * vals, int max_quantity ) 147 | { 148 | int i; 149 | for( i = 0; i < max_quantity; i++ ) 150 | { 151 | const char * colon = my_strchr( str, ':' ); 152 | vals[i] = my_atoi( str ); 153 | if( !colon ) break; 154 | str = colon+1; 155 | } 156 | return i+1; 157 | } 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | //from http://stackoverflow.com/questions/342409/how-do-i-base64-encode-decode-in-c 166 | static const char encoding_table[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 167 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 168 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 169 | 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 170 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 171 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 172 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', 173 | '4', '5', '6', '7', '8', '9', '+', '/'}; 174 | 175 | static const int mod_table[] = {0, 2, 1}; 176 | 177 | void ICACHE_FLASH_ATTR my_base64_encode(const unsigned char *data, size_t input_length, uint8_t * encoded_data ) 178 | { 179 | 180 | int i, j; 181 | int output_length = 4 * ((input_length + 2) / 3); 182 | 183 | if( !encoded_data ) return; 184 | if( !data ) { encoded_data[0] = '='; encoded_data[1] = 0; return; } 185 | 186 | for (i = 0, j = 0; i < input_length; ) { 187 | 188 | uint32_t octet_a = i < input_length ? (unsigned char)data[i++] : 0; 189 | uint32_t octet_b = i < input_length ? (unsigned char)data[i++] : 0; 190 | uint32_t octet_c = i < input_length ? (unsigned char)data[i++] : 0; 191 | 192 | uint32_t triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c; 193 | 194 | encoded_data[j++] = encoding_table[(triple >> 3 * 6) & 0x3F]; 195 | encoded_data[j++] = encoding_table[(triple >> 2 * 6) & 0x3F]; 196 | encoded_data[j++] = encoding_table[(triple >> 1 * 6) & 0x3F]; 197 | encoded_data[j++] = encoding_table[(triple >> 0 * 6) & 0x3F]; 198 | } 199 | 200 | for (i = 0; i < mod_table[input_length % 3]; i++) 201 | encoded_data[output_length - 1 - i] = '='; 202 | 203 | encoded_data[j] = 0; 204 | } 205 | 206 | 207 | 208 | void ICACHE_FLASH_ATTR SafeMD5Update( MD5_CTX * md5ctx, uint8_t*from, uint32_t size1 ) 209 | { 210 | char __attribute__ ((aligned (32))) buffer[32]; 211 | 212 | while( size1 > 32 ) 213 | { 214 | ets_memcpy( buffer, from, 32 ); 215 | MD5Update( md5ctx, buffer, 32 ); 216 | size1-=32; 217 | from+=32; 218 | } 219 | ets_memcpy( buffer, from, 32 ); 220 | MD5Update( md5ctx, buffer, size1 ); 221 | } 222 | 223 | char * ICACHE_FLASH_ATTR strdup( const char * src ) 224 | { 225 | int len = ets_strlen( src ); 226 | char * ret = (char*)os_malloc( len+1 ); 227 | ets_memcpy( ret, src, len+1 ); 228 | return ret; 229 | } 230 | 231 | char * ICACHE_FLASH_ATTR strdupcaselower( const char * src ) 232 | { 233 | int i; 234 | int len = ets_strlen( src ); 235 | char * ret = (char*)os_malloc( len+1 ); 236 | for( i = 0; i < len+1; i++ ) 237 | { 238 | if( src[i] >= 'A' && src[i] <= 'Z' ) 239 | ret[i] = src[i] - 'A' + 'a'; 240 | else 241 | ret[i] = src[i]; 242 | } 243 | return ret; 244 | } 245 | 246 | uint32_t ICACHE_FLASH_ATTR GetCurrentIP( ) 247 | { 248 | struct ip_info sta_ip; 249 | wifi_get_ip_info(STATION_IF, &sta_ip); 250 | if( sta_ip.ip.addr == 0 ) 251 | { 252 | wifi_get_ip_info(SOFTAP_IF, &sta_ip); 253 | } 254 | if( sta_ip.ip.addr != 0 ) 255 | return sta_ip.ip.addr; 256 | else 257 | return 0; 258 | } 259 | 260 | -------------------------------------------------------------------------------- /common/mystuff.h: -------------------------------------------------------------------------------- 1 | //Unless what else is individually marked, all code in this file is 2 | //Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or 3 | // ColorChord License. You Choose. 4 | 5 | #ifndef _MYSTUFF_H 6 | #define _MYSTUFF_H 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | //XXX WARNING As of 1.3.0, "cansend" doesn't work. 18 | //the SDK seems to misbehave when trying to send without a full 19 | //response packet. 20 | #define SAFESEND 21 | 22 | 23 | #define HTONS(x) ((((uint16_t)(x))>>8)|(((x)&0xff)<<8)) 24 | 25 | #define IP4_to_uint32(x) (((uint32_t)x[3]<<24)|((uint32_t)x[2]<<16)|((uint32_t)x[1]<<8)|x[0]) 26 | #define uint32_to_IP4(x,y) {y[0] = (uint8_t)(x); y[1] = (uint8_t)((x)>>8); y[2] = (uint8_t)((x)>>16); y[3] = (uint8_t)((x)>>24);} 27 | 28 | extern char generic_print_buffer[384]; 29 | 30 | extern const char * enctypes[6];// = { "open", "wep", "wpa", "wpa2", "wpa_wpa2", 0 }; 31 | 32 | #define printf( ... ) { ets_sprintf( generic_print_buffer, __VA_ARGS__ ); uart0_sendStr( generic_print_buffer ); } 33 | 34 | char tohex1( uint8_t i ); 35 | int8_t fromhex1( char c ); //returns -1 if not hex char. 36 | 37 | int32 my_atoi( const char * in ); 38 | void Uint32To10Str( char * out, uint32 dat ); 39 | 40 | void NixNewline( char * str ); //If there's a newline at the end of this string, make it null. 41 | 42 | //For holding TX packet buffers 43 | extern char generic_buffer[1500]; 44 | extern char * generic_ptr; 45 | int8_t ICACHE_FLASH_ATTR TCPCanSend( struct espconn * conn, int size ); 46 | int8_t ICACHE_FLASH_ATTR TCPDoneSend( struct espconn * conn ); 47 | void ICACHE_FLASH_ATTR EndTCPWrite( struct espconn * conn ); 48 | 49 | 50 | #define PushByte( c ) { *(generic_ptr++) = c; } 51 | 52 | void PushString( const char * buffer ); 53 | void PushBlob( const uint8 * buffer, int len ); 54 | #define START_PACK {generic_ptr=generic_buffer;} 55 | #define PACK_LENGTH (generic_ptr-&generic_buffer[0]} 56 | 57 | int ICACHE_FLASH_ATTR ColonsToInts( const char * str, int32_t * vals, int max_quantity ); 58 | 59 | //As much as it pains me, we shouldn't be using the esp8266's base64_encode() function 60 | //as it does stuff with dynamic memory. 61 | void ICACHE_FLASH_ATTR my_base64_encode(const unsigned char *data, size_t input_length, uint8_t * encoded_data ); 62 | 63 | 64 | void ICACHE_FLASH_ATTR SafeMD5Update( MD5_CTX * md5ctx, uint8_t*from, uint32_t size1 ); 65 | 66 | char * ICACHE_FLASH_ATTR strdup( const char * src ); 67 | char * ICACHE_FLASH_ATTR strdupcaselower( const char * src ); 68 | 69 | 70 | uint32_t ICACHE_FLASH_ATTR GetCurrentIP( ); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /driver/uart.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2014 Espressif Systems (Wuxi) 3 | * Copyright 2015 <>< Charles Lohr 4 | * 5 | * FileName: uart.c 6 | * 7 | * Description: Two UART mode configration and interrupt handler. 8 | * Check your hardware connection while use this mode. 9 | * 10 | * Modification history: 11 | * 2014/3/12, v1.0 create this file. 12 | * 2015/1/29, Various changes to the way in which bytes are received. 13 | *******************************************************************************/ 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | //#include "ssc.h" 21 | //#include "at.h" 22 | 23 | // UartDev is defined and initialized in rom code. 24 | extern UartDevice UartDev; 25 | //extern os_event_t at_recvTaskQueue[at_recvTaskQueueLen]; 26 | 27 | LOCAL void uart0_rx_intr_handler(void *para); 28 | 29 | /****************************************************************************** 30 | * FunctionName : uart_config 31 | * Description : Internal used function 32 | * UART0 used for data TX/RX, RX buffer size is 0x100, interrupt enabled 33 | * UART1 just used for debug output 34 | * Parameters : uart_no, use UART0 or UART1 defined ahead 35 | * Returns : NONE 36 | *******************************************************************************/ 37 | LOCAL void ICACHE_FLASH_ATTR 38 | uart_config(uint8 uart_no) 39 | { 40 | if (uart_no == UART1) 41 | { 42 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK); 43 | } 44 | else 45 | { 46 | /* rcv_buff size if 0x100 */ 47 | ETS_UART_INTR_ATTACH(uart0_rx_intr_handler, &(UartDev.rcv_buff)); 48 | PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U); 49 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD); 50 | // PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_U0RTS); 51 | } 52 | 53 | uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate)); 54 | 55 | WRITE_PERI_REG(UART_CONF0(uart_no), UartDev.exist_parity 56 | | UartDev.parity 57 | | (UartDev.stop_bits << UART_STOP_BIT_NUM_S) 58 | | (UartDev.data_bits << UART_BIT_NUM_S)); 59 | 60 | //clear rx and tx fifo,not ready 61 | SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST); 62 | CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST); 63 | 64 | //set rx fifo trigger 65 | // WRITE_PERI_REG(UART_CONF1(uart_no), 66 | // ((UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) | 67 | // ((96 & UART_TXFIFO_EMPTY_THRHD) << UART_TXFIFO_EMPTY_THRHD_S) | 68 | // UART_RX_FLOW_EN); 69 | if (uart_no == UART0) 70 | { 71 | //set rx fifo trigger 72 | WRITE_PERI_REG(UART_CONF1(uart_no), 73 | ((0x01 & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S) | 74 | ((0x01 & UART_RX_FLOW_THRHD) << UART_RX_FLOW_THRHD_S) | 75 | UART_RX_FLOW_EN); 76 | } 77 | else 78 | { 79 | WRITE_PERI_REG(UART_CONF1(uart_no), 80 | ((UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S)); 81 | } 82 | 83 | //clear all interrupt 84 | WRITE_PERI_REG(UART_INT_CLR(uart_no), 0xffff); 85 | //enable rx_interrupt 86 | SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_FULL_INT_ENA); 87 | } 88 | 89 | /****************************************************************************** 90 | * FunctionName : uart1_tx_one_char 91 | * Description : Internal used function 92 | * Use uart1 interface to transfer one char 93 | * Parameters : uint8 TxChar - character to tx 94 | * Returns : OK 95 | *******************************************************************************/ 96 | LOCAL STATUS 97 | uart_tx_one_char(uint8 uart, uint8 TxChar) 98 | { 99 | while (true) 100 | { 101 | uint32 fifo_cnt = READ_PERI_REG(UART_STATUS(uart)) & (UART_TXFIFO_CNT<> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) < 126) { 103 | break; 104 | } 105 | } 106 | 107 | WRITE_PERI_REG(UART_FIFO(uart) , TxChar); 108 | return OK; 109 | } 110 | 111 | /****************************************************************************** 112 | * FunctionName : uart1_write_char 113 | * Description : Internal used function 114 | * Do some special deal while tx char is '\r' or '\n' 115 | * Parameters : char c - character to tx 116 | * Returns : NONE 117 | *******************************************************************************/ 118 | LOCAL void ICACHE_FLASH_ATTR 119 | uart1_write_char(char c) 120 | { 121 | if (c == '\n') 122 | { 123 | uart_tx_one_char(UART1, '\r'); 124 | uart_tx_one_char(UART1, '\n'); 125 | } 126 | else if (c == '\r') 127 | { 128 | } 129 | else 130 | { 131 | uart_tx_one_char(UART1, c); 132 | } 133 | } 134 | /****************************************************************************** 135 | * FunctionName : uart0_tx_buffer 136 | * Description : use uart0 to transfer buffer 137 | * Parameters : uint8 *buf - point to send buffer 138 | * uint16 len - buffer len 139 | * Returns : 140 | *******************************************************************************/ 141 | void ICACHE_FLASH_ATTR 142 | uart0_tx_buffer(uint8 *buf, uint16 len) 143 | { 144 | uint16 i; 145 | 146 | for (i = 0; i < len; i++) 147 | { 148 | uart_tx_one_char(UART0, buf[i]); 149 | } 150 | } 151 | 152 | /****************************************************************************** 153 | * FunctionName : uart0_sendStr 154 | * Description : use uart0 to transfer buffer 155 | * Parameters : uint8 *buf - point to send buffer 156 | * uint16 len - buffer len 157 | * Returns : 158 | *******************************************************************************/ 159 | void ICACHE_FLASH_ATTR 160 | uart0_sendStr(const char *str) 161 | { 162 | while(*str) 163 | { 164 | uart_tx_one_char(UART0, *str++); 165 | } 166 | } 167 | 168 | /****************************************************************************** 169 | * FunctionName : uart0_rx_intr_handler 170 | * Description : Internal used function 171 | * UART0 interrupt handler, add self handle code inside 172 | * Parameters : void *para - point to ETS_UART_INTR_ATTACH's arg 173 | * Returns : NONE 174 | *******************************************************************************/ 175 | 176 | extern void charrx( uint8_t c ); 177 | 178 | LOCAL void 179 | uart0_rx_intr_handler(void *para) 180 | { 181 | static uint8_t history[4]; 182 | static uint8_t hhead; 183 | 184 | uint8 uart_no = UART0;//UartDev.buff_uart_no; 185 | volatile uint8_t v = READ_PERI_REG(UART_FIFO(uart_no)) & 0xFF; 186 | WRITE_PERI_REG(UART_INT_CLR(uart_no), UART_RXFIFO_FULL_INT_CLR); 187 | 188 | history[hhead++] = v; 189 | if( hhead > 3 ) hhead = 0; 190 | 191 | //Detect a request to reboot into bootloader. 192 | if( history[hhead&3] == 0xc2 && history[(hhead+1)&3] == 0x42 && history[(hhead+2)&3] == 0x56 && history[(hhead+3)&3] == 0xff ) 193 | { 194 | system_restart(); 195 | } 196 | 197 | charrx( v ); 198 | 199 | } 200 | 201 | /****************************************************************************** 202 | * FunctionName : uart_init 203 | * Description : user interface for init uart 204 | * Parameters : UartBautRate uart0_br - uart0 bautrate 205 | * UartBautRate uart1_br - uart1 bautrate 206 | * Returns : NONE 207 | *******************************************************************************/ 208 | void ICACHE_FLASH_ATTR 209 | uart_init(UartBautRate uart0_br, UartBautRate uart1_br) 210 | { 211 | // rom use 74880 baut_rate, here reinitialize 212 | UartDev.baut_rate = uart0_br; 213 | uart_config(UART0); 214 | UartDev.baut_rate = uart1_br; 215 | uart_config(UART1); 216 | ETS_UART_INTR_ENABLE(); 217 | 218 | // install uart1 putc callback 219 | os_install_putc1((void *)uart1_write_char); 220 | } 221 | 222 | void ICACHE_FLASH_ATTR 223 | uart_reattach() 224 | { 225 | uart_init(BIT_RATE_74880, BIT_RATE_74880); 226 | } 227 | -------------------------------------------------------------------------------- /image.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhartmann/esp8266_reprap/46653d8ec498c8fa382bd2c672f4d8cea946bc49/image.elf -------------------------------------------------------------------------------- /images/Counter - Word_clock and 3LSBs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhartmann/esp8266_reprap/46653d8ec498c8fa382bd2c672f4d8cea946bc49/images/Counter - Word_clock and 3LSBs.png -------------------------------------------------------------------------------- /include/driver/uart.h: -------------------------------------------------------------------------------- 1 | #ifndef UART_APP_H 2 | #define UART_APP_H 3 | 4 | #include "uart_register.h" 5 | #include "eagle_soc.h" 6 | #include "c_types.h" 7 | 8 | #define RX_BUFF_SIZE 256 9 | #define TX_BUFF_SIZE 100 10 | #define UART0 0 11 | #define UART1 1 12 | 13 | typedef enum { 14 | FIVE_BITS = 0x0, 15 | SIX_BITS = 0x1, 16 | SEVEN_BITS = 0x2, 17 | EIGHT_BITS = 0x3 18 | } UartBitsNum4Char; 19 | 20 | typedef enum { 21 | ONE_STOP_BIT = 0, 22 | ONE_HALF_STOP_BIT = BIT2, 23 | TWO_STOP_BIT = BIT2 24 | } UartStopBitsNum; 25 | 26 | typedef enum { 27 | NONE_BITS = 0, 28 | ODD_BITS = 0, 29 | EVEN_BITS = BIT4 30 | } UartParityMode; 31 | 32 | typedef enum { 33 | STICK_PARITY_DIS = 0, 34 | STICK_PARITY_EN = BIT3 | BIT5 35 | } UartExistParity; 36 | 37 | typedef enum { 38 | BIT_RATE_9600 = 9600, 39 | BIT_RATE_19200 = 19200, 40 | BIT_RATE_38400 = 38400, 41 | BIT_RATE_57600 = 57600, 42 | BIT_RATE_74880 = 74880, 43 | BIT_RATE_115200 = 115200, 44 | BIT_RATE_230400 = 230400, 45 | BIT_RATE_460800 = 460800, 46 | BIT_RATE_921600 = 921600 47 | } UartBautRate; 48 | 49 | typedef enum { 50 | NONE_CTRL, 51 | HARDWARE_CTRL, 52 | XON_XOFF_CTRL 53 | } UartFlowCtrl; 54 | 55 | typedef enum { 56 | EMPTY, 57 | UNDER_WRITE, 58 | WRITE_OVER 59 | } RcvMsgBuffState; 60 | 61 | typedef struct { 62 | uint32 RcvBuffSize; 63 | uint8 *pRcvMsgBuff; 64 | uint8 *pWritePos; 65 | uint8 *pReadPos; 66 | uint8 TrigLvl; //JLU: may need to pad 67 | RcvMsgBuffState BuffState; 68 | } RcvMsgBuff; 69 | 70 | typedef struct { 71 | uint32 TrxBuffSize; 72 | uint8 *pTrxBuff; 73 | } TrxMsgBuff; 74 | 75 | typedef enum { 76 | BAUD_RATE_DET, 77 | WAIT_SYNC_FRM, 78 | SRCH_MSG_HEAD, 79 | RCV_MSG_BODY, 80 | RCV_ESC_CHAR, 81 | } RcvMsgState; 82 | 83 | typedef struct { 84 | UartBautRate baut_rate; 85 | UartBitsNum4Char data_bits; 86 | UartExistParity exist_parity; 87 | UartParityMode parity; // chip size in byte 88 | UartStopBitsNum stop_bits; 89 | UartFlowCtrl flow_ctrl; 90 | RcvMsgBuff rcv_buff; 91 | TrxMsgBuff trx_buff; 92 | RcvMsgState rcv_state; 93 | int received; 94 | int buff_uart_no; //indicate which uart use tx/rx buffer 95 | } UartDevice; 96 | 97 | void uart_init(UartBautRate uart0_br, UartBautRate uart1_br); 98 | void uart0_sendStr(const char *str); 99 | 100 | #endif 101 | 102 | -------------------------------------------------------------------------------- /include/driver/uart_register.h: -------------------------------------------------------------------------------- 1 | //Generated at 2012-07-03 18:44:06 2 | /* 3 | * Copyright (c) 2010 - 2011 Espressif System 4 | * 5 | */ 6 | 7 | #ifndef UART_REGISTER_H_INCLUDED 8 | #define UART_REGISTER_H_INCLUDED 9 | #define REG_UART_BASE( i ) (0x60000000+(i)*0xf00) 10 | //version value:32'h062000 11 | 12 | #define UART_FIFO( i ) (REG_UART_BASE( i ) + 0x0) 13 | #define UART_RXFIFO_RD_BYTE 0x000000FF 14 | #define UART_RXFIFO_RD_BYTE_S 0 15 | 16 | #define UART_INT_RAW( i ) (REG_UART_BASE( i ) + 0x4) 17 | #define UART_RXFIFO_TOUT_INT_RAW (BIT(8)) 18 | #define UART_BRK_DET_INT_RAW (BIT(7)) 19 | #define UART_CTS_CHG_INT_RAW (BIT(6)) 20 | #define UART_DSR_CHG_INT_RAW (BIT(5)) 21 | #define UART_RXFIFO_OVF_INT_RAW (BIT(4)) 22 | #define UART_FRM_ERR_INT_RAW (BIT(3)) 23 | #define UART_PARITY_ERR_INT_RAW (BIT(2)) 24 | #define UART_TXFIFO_EMPTY_INT_RAW (BIT(1)) 25 | #define UART_RXFIFO_FULL_INT_RAW (BIT(0)) 26 | 27 | #define UART_INT_ST( i ) (REG_UART_BASE( i ) + 0x8) 28 | #define UART_RXFIFO_TOUT_INT_ST (BIT(8)) 29 | #define UART_BRK_DET_INT_ST (BIT(7)) 30 | #define UART_CTS_CHG_INT_ST (BIT(6)) 31 | #define UART_DSR_CHG_INT_ST (BIT(5)) 32 | #define UART_RXFIFO_OVF_INT_ST (BIT(4)) 33 | #define UART_FRM_ERR_INT_ST (BIT(3)) 34 | #define UART_PARITY_ERR_INT_ST (BIT(2)) 35 | #define UART_TXFIFO_EMPTY_INT_ST (BIT(1)) 36 | #define UART_RXFIFO_FULL_INT_ST (BIT(0)) 37 | 38 | #define UART_INT_ENA( i ) (REG_UART_BASE( i ) + 0xC) 39 | #define UART_RXFIFO_TOUT_INT_ENA (BIT(8)) 40 | #define UART_BRK_DET_INT_ENA (BIT(7)) 41 | #define UART_CTS_CHG_INT_ENA (BIT(6)) 42 | #define UART_DSR_CHG_INT_ENA (BIT(5)) 43 | #define UART_RXFIFO_OVF_INT_ENA (BIT(4)) 44 | #define UART_FRM_ERR_INT_ENA (BIT(3)) 45 | #define UART_PARITY_ERR_INT_ENA (BIT(2)) 46 | #define UART_TXFIFO_EMPTY_INT_ENA (BIT(1)) 47 | #define UART_RXFIFO_FULL_INT_ENA (BIT(0)) 48 | 49 | #define UART_INT_CLR( i ) (REG_UART_BASE( i ) + 0x10) 50 | #define UART_RXFIFO_TOUT_INT_CLR (BIT(8)) 51 | #define UART_BRK_DET_INT_CLR (BIT(7)) 52 | #define UART_CTS_CHG_INT_CLR (BIT(6)) 53 | #define UART_DSR_CHG_INT_CLR (BIT(5)) 54 | #define UART_RXFIFO_OVF_INT_CLR (BIT(4)) 55 | #define UART_FRM_ERR_INT_CLR (BIT(3)) 56 | #define UART_PARITY_ERR_INT_CLR (BIT(2)) 57 | #define UART_TXFIFO_EMPTY_INT_CLR (BIT(1)) 58 | #define UART_RXFIFO_FULL_INT_CLR (BIT(0)) 59 | 60 | #define UART_CLKDIV( i ) (REG_UART_BASE( i ) + 0x14) 61 | #define UART_CLKDIV_CNT 0x000FFFFF 62 | #define UART_CLKDIV_S 0 63 | 64 | #define UART_AUTOBAUD( i ) (REG_UART_BASE( i ) + 0x18) 65 | #define UART_GLITCH_FILT 0x000000FF 66 | #define UART_GLITCH_FILT_S 8 67 | #define UART_AUTOBAUD_EN (BIT(0)) 68 | 69 | #define UART_STATUS( i ) (REG_UART_BASE( i ) + 0x1C) 70 | #define UART_TXD (BIT(31)) 71 | #define UART_RTSN (BIT(30)) 72 | #define UART_DTRN (BIT(29)) 73 | #define UART_TXFIFO_CNT 0x000000FF 74 | #define UART_TXFIFO_CNT_S 16 75 | #define UART_RXD (BIT(15)) 76 | #define UART_CTSN (BIT(14)) 77 | #define UART_DSRN (BIT(13)) 78 | #define UART_RXFIFO_CNT 0x000000FF 79 | #define UART_RXFIFO_CNT_S 0 80 | 81 | #define UART_CONF0( i ) (REG_UART_BASE( i ) + 0x20) 82 | #define UART_TXFIFO_RST (BIT(18)) 83 | #define UART_RXFIFO_RST (BIT(17)) 84 | #define UART_IRDA_EN (BIT(16)) 85 | #define UART_TX_FLOW_EN (BIT(15)) 86 | #define UART_LOOPBACK (BIT(14)) 87 | #define UART_IRDA_RX_INV (BIT(13)) 88 | #define UART_IRDA_TX_INV (BIT(12)) 89 | #define UART_IRDA_WCTL (BIT(11)) 90 | #define UART_IRDA_TX_EN (BIT(10)) 91 | #define UART_IRDA_DPLX (BIT(9)) 92 | #define UART_TXD_BRK (BIT(8)) 93 | #define UART_SW_DTR (BIT(7)) 94 | #define UART_SW_RTS (BIT(6)) 95 | #define UART_STOP_BIT_NUM 0x00000003 96 | #define UART_STOP_BIT_NUM_S 4 97 | #define UART_BIT_NUM 0x00000003 98 | #define UART_BIT_NUM_S 2 99 | #define UART_PARITY_EN (BIT(1)) 100 | #define UART_PARITY (BIT(0)) 101 | 102 | #define UART_CONF1( i ) (REG_UART_BASE( i ) + 0x24) 103 | #define UART_RX_TOUT_EN (BIT(31)) 104 | #define UART_RX_TOUT_THRHD 0x0000007F 105 | #define UART_RX_TOUT_THRHD_S 24 106 | #define UART_RX_FLOW_EN (BIT(23)) 107 | #define UART_RX_FLOW_THRHD 0x0000007F 108 | #define UART_RX_FLOW_THRHD_S 16 109 | #define UART_TXFIFO_EMPTY_THRHD 0x0000007F 110 | #define UART_TXFIFO_EMPTY_THRHD_S 8 111 | #define UART_RXFIFO_FULL_THRHD 0x0000007F 112 | #define UART_RXFIFO_FULL_THRHD_S 0 113 | 114 | #define UART_LOWPULSE( i ) (REG_UART_BASE( i ) + 0x28) 115 | #define UART_LOWPULSE_MIN_CNT 0x000FFFFF 116 | #define UART_LOWPULSE_MIN_CNT_S 0 117 | 118 | #define UART_HIGHPULSE( i ) (REG_UART_BASE( i ) + 0x2C) 119 | #define UART_HIGHPULSE_MIN_CNT 0x000FFFFF 120 | #define UART_HIGHPULSE_MIN_CNT_S 0 121 | 122 | #define UART_PULSE_NUM( i ) (REG_UART_BASE( i ) + 0x30) 123 | #define UART_PULSE_NUM_CNT 0x0003FF 124 | #define UART_PULSE_NUM_CNT_S 0 125 | 126 | #define UART_DATE( i ) (REG_UART_BASE( i ) + 0x78) 127 | #define UART_ID( i ) (REG_UART_BASE( i ) + 0x7C) 128 | #endif // UART_REGISTER_H_INCLUDED 129 | -------------------------------------------------------------------------------- /include/pin_mux_register.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Espressif System 2010 - 2012 3 | * 4 | */ 5 | 6 | #ifndef _PIN_MUX_H_ 7 | #define _PIN_MUX_H_ 8 | 9 | #define PERIPHS_IO_MUX 0x60000800 10 | 11 | #define PERIPHS_IO_MUX_FUNC 0x13 12 | #define PERIPHS_IO_MUX_FUNC_S 4 13 | #define PERIPHS_IO_MUX_PULLUP BIT7 14 | #define PERIPHS_IO_MUX_PULLDWN BIT6 15 | #define PERIPHS_IO_MUX_SLEEP_PULLUP BIT3 16 | #define PERIPHS_IO_MUX_SLEEP_PULLDWN BIT2 17 | #define PERIPHS_IO_MUX_SLEEP_OE BIT1 18 | #define PERIPHS_IO_MUX_OE BIT0 19 | 20 | #define PERIPHS_IO_MUX_CONF_U (PERIPHS_IO_MUX + 0x00) 21 | #define SPI0_CLK_EQU_SYS_CLK BIT8 22 | #define SPI1_CLK_EQU_SYS_CLK BIT9 23 | 24 | #define PERIPHS_IO_MUX_MTDI_U (PERIPHS_IO_MUX + 0x04) 25 | #define FUNC_MTDI 0 26 | #define FUNC_I2SI_DATA 1 27 | #define FUNC_HSPIQ_MISO 2 28 | #define FUNC_GPIO12 3 29 | #define FUNC_UART0_DTR 4 30 | 31 | #define PERIPHS_IO_MUX_MTCK_U (PERIPHS_IO_MUX + 0x08) 32 | #define FUNC_MTCK 0 33 | #define FUNC_I2SI_BCK 1 34 | #define FUNC_HSPID_MOSI 2 35 | #define FUNC_GPIO13 3 36 | #define FUNC_UART0_CTS 4 37 | 38 | #define PERIPHS_IO_MUX_MTMS_U (PERIPHS_IO_MUX + 0x0C) 39 | #define FUNC_MTMS 0 40 | #define FUNC_I2SI_WS 1 41 | #define FUNC_HSPI_CLK 2 42 | #define FUNC_GPIO14 3 43 | #define FUNC_UART0_DSR 4 44 | 45 | #define PERIPHS_IO_MUX_MTDO_U (PERIPHS_IO_MUX + 0x10) 46 | #define FUNC_MTDO 0 47 | #define FUNC_I2SO_BCK 1 48 | #define FUNC_HSPI_CS0 2 49 | #define FUNC_GPIO15 3 50 | #define FUNC_U0RTS 4 51 | #define FUNC_UART0_RTS 4 52 | 53 | #define PERIPHS_IO_MUX_U0RXD_U (PERIPHS_IO_MUX + 0x14) 54 | #define FUNC_U0RXD 0 55 | #define FUNC_I2SO_DATA 1 56 | #define FUNC_GPIO3 3 57 | #define FUNC_CLK_XTAL_BK 4 58 | 59 | #define PERIPHS_IO_MUX_U0TXD_U (PERIPHS_IO_MUX + 0x18) 60 | #define FUNC_U0TXD 0 61 | #define FUNC_SPICS1 1 62 | #define FUNC_GPIO1 3 63 | #define FUNC_CLK_RTC_BK 4 64 | 65 | #define PERIPHS_IO_MUX_SD_CLK_U (PERIPHS_IO_MUX + 0x1c) 66 | #define FUNC_SDCLK 0 67 | #define FUNC_SPICLK 1 68 | #define FUNC_GPIO6 3 69 | #define UART1_CTS 4 70 | 71 | #define PERIPHS_IO_MUX_SD_DATA0_U (PERIPHS_IO_MUX + 0x20) 72 | #define FUNC_SDDATA0 0 73 | #define FUNC_SPIQ_MISO 1 74 | #define FUNC_GPIO7 3 75 | #define FUNC_U1TXD 4 76 | #define FUNC_UART1_TXD 4 77 | 78 | #define PERIPHS_IO_MUX_SD_DATA1_U (PERIPHS_IO_MUX + 0x24) 79 | #define FUNC_SDDATA1 0 80 | #define FUNC_SPID_MOSI 1 81 | #define FUNC_GPIO8 3 82 | #define FUNC_U1RXD 4 83 | #define FUNC_UART1_RXD 4 84 | 85 | #define PERIPHS_IO_MUX_SD_DATA2_U (PERIPHS_IO_MUX + 0x28) 86 | #define FUNC_SDDATA2 0 87 | #define FUNC_SPIHD 1 88 | #define FUNC_GPIO9 3 89 | #define UFNC_HSPIHD 4 90 | 91 | #define PERIPHS_IO_MUX_SD_DATA3_U (PERIPHS_IO_MUX + 0x2c) 92 | #define FUNC_SDDATA3 0 93 | #define FUNC_SPIWP 1 94 | #define FUNC_GPIO10 3 95 | #define FUNC_HSPIWP 4 96 | 97 | #define PERIPHS_IO_MUX_SD_CMD_U (PERIPHS_IO_MUX + 0x30) 98 | #define FUNC_SDCMD 0 99 | #define FUNC_SPICS0 1 100 | #define FUNC_GPIO11 3 101 | #define U1RTS 4 102 | #define UART1_RTS 4 103 | 104 | #define PERIPHS_IO_MUX_GPIO0_U (PERIPHS_IO_MUX + 0x34) 105 | #define FUNC_GPIO0 0 106 | #define FUNC_SPICS2 1 107 | #define FUNC_CLK_OUT 4 108 | 109 | #define PERIPHS_IO_MUX_GPIO2_U (PERIPHS_IO_MUX + 0x38) 110 | #define FUNC_GPIO2 0 111 | #define FUNC_I2SO_WS 1 112 | #define FUNC_U1TXD_BK 2 113 | #define FUNC_UART1_TXD_BK 2 114 | #define FUNC_U0TXD_BK 4 115 | #define FUNC_UART0_TXD_BK 4 116 | 117 | #define PERIPHS_IO_MUX_GPIO4_U (PERIPHS_IO_MUX + 0x3C) 118 | #define FUNC_GPIO4 0 119 | #define FUNC_CLK_XTAL 1 120 | 121 | #define PERIPHS_IO_MUX_GPIO5_U (PERIPHS_IO_MUX + 0x40) 122 | #define FUNC_GPIO5 0 123 | #define FUNC_CLK_RTC 1 124 | 125 | #define PIN_PULLUP_DIS(PIN_NAME) CLEAR_PERI_REG_MASK(PIN_NAME, PERIPHS_IO_MUX_PULLUP) 126 | #define PIN_PULLUP_EN(PIN_NAME) SET_PERI_REG_MASK(PIN_NAME, PERIPHS_IO_MUX_PULLUP) 127 | 128 | //XXX THIS LOOKS WRONG. 129 | 130 | #undef PIN_FUNC_SELECT 131 | 132 | #define PIN_FUNC_SELECT(PIN_NAME, FUNC) do { \ 133 | CLEAR_PERI_REG_MASK(PIN_NAME, (PERIPHS_IO_MUX_FUNC< 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int sockfd; 8 | struct sockaddr_in servaddr; 9 | 10 | 11 | unsigned long HSVtoHEX( float hue, float sat, float value ) 12 | { 13 | 14 | float pr = 0; 15 | float pg = 0; 16 | float pb = 0; 17 | 18 | short ora = 0; 19 | short og = 0; 20 | short ob = 0; 21 | 22 | float ro = fmod( hue * 6, 6. ); 23 | 24 | float avg = 0; 25 | 26 | ro = fmod( ro + 6 + 1, 6 ); //Hue was 60* off... 27 | 28 | if( ro < 1 ) //yellow->red 29 | { 30 | pr = 1; 31 | pg = 1. - ro; 32 | } else if( ro < 2 ) 33 | { 34 | pr = 1; 35 | pb = ro - 1.; 36 | } else if( ro < 3 ) 37 | { 38 | pr = 3. - ro; 39 | pb = 1; 40 | } else if( ro < 4 ) 41 | { 42 | pb = 1; 43 | pg = ro - 3; 44 | } else if( ro < 5 ) 45 | { 46 | pb = 5 - ro; 47 | pg = 1; 48 | } else 49 | { 50 | pg = 1; 51 | pr = ro - 5; 52 | } 53 | 54 | //Actually, above math is backwards, oops! 55 | pr *= value; 56 | pg *= value; 57 | pb *= value; 58 | 59 | avg += pr; 60 | avg += pg; 61 | avg += pb; 62 | 63 | pr = pr * sat + avg * (1.-sat); 64 | pg = pg * sat + avg * (1.-sat); 65 | pb = pb * sat + avg * (1.-sat); 66 | 67 | ora = pr * 255; 68 | og = pb * 255; 69 | ob = pg * 255; 70 | 71 | if( ora < 0 ) ora = 0; 72 | if( ora > 255 ) ora = 255; 73 | if( og < 0 ) og = 0; 74 | if( og > 255 ) og = 255; 75 | if( ob < 0 ) ob = 0; 76 | if( ob > 255 ) ob = 255; 77 | 78 | return (ob<<16) | (og<<8) | ora; 79 | } 80 | 81 | int main( int argc, char ** argv ) 82 | { 83 | int firstoverride = -1; 84 | if( argc < 2 ) 85 | { 86 | fprintf( stderr, "Error: usage: [tool] [ip address] [optional: no of lights] [optional (if present, first override (i.e. white on some systems))]\n" ); 87 | return -1; 88 | } 89 | uint32_t frame = 0; 90 | sockfd=socket(AF_INET,SOCK_DGRAM,0); 91 | 92 | bzero(&servaddr,sizeof(servaddr)); 93 | servaddr.sin_family = AF_INET; 94 | servaddr.sin_addr.s_addr=inet_addr(argv[1]); 95 | servaddr.sin_port=htons(7777); 96 | 97 | int lights = 186; 98 | 99 | if( argc >= 3 ) 100 | { 101 | lights = atoi( argv[2] ); 102 | } 103 | if( argc >= 4 ) 104 | { 105 | firstoverride = atoi( argv[3] ); 106 | } 107 | 108 | printf( "Lights: %d\n", lights ); 109 | 110 | while(1) 111 | { 112 | //#define lights 186 113 | uint8_t buffer[lights*3]; 114 | int i; 115 | for( i = 0; i < lights; i++ ) 116 | { 117 | 118 | //#define BEAT 119 | uint32_t hex; 120 | //For button 121 | // hex = (i == (frame % lights))?0xFFFFFF:0x000000; 122 | // hex=0xffffff; 123 | // hex = HSVtoHEX( i*(1/12.) + frame*(1./48.), 1, 1.0 ); 124 | // hex = (((frame+i)%lights)>(lights-2))?0xffffff:0; //The worm. 125 | hex = HSVtoHEX( i*.03 - frame*.04, 1, (((((-i<<3)%256) - ((frame<<3)%256)+256)%256) ) /256.0*0.9-0.1); //Long, smooth, transitioning. 1.0 126 | 127 | 128 | //For wall art. 129 | 130 | // hex = 0x404040; 131 | 132 | hex = HSVtoHEX( i*.05 + frame*.01, 1, 1.0 ); //0.50 = overload. 0.45 = overheat? =0.40 = HOT 133 | 134 | // hex = (((frame+i)%186)>160)?0xff8f8f:0; //The worm. 135 | // hex = (((frame+i)%186)>130)?0x0000ff:0; //The red worm. 136 | // hex = HSVtoHEX( i*.005 - frame*.001, 1, ((((-i%256) - ((frame>>1)%256)+256)%256) ) /256.0*1.2-0.1); 137 | // hex = HSVtoHEX( i*.00500 + ((int)(frame*0.42))*.17, 1, 0.40 ); //Fiesta 138 | 139 | //and my favorite: 140 | // hex = HSVtoHEX( i*.001 - frame*.001, 1, ((((i%256) - ((frame>>1)%256)+256)%256) ) /256.0*1.5-0.1); //Long, smooth, transitioning. 1.0 overloads. Trying 0.9. If 0.9 works, should back off. 141 | 142 | // hex = HSVtoHEX( i*0.005376344 - frame*.001, 1.3, 1.0); //Long, smooth, transitioning. full-brigth 143 | 144 | 145 | //Chaser 146 | // hex = HSVtoHEX( i*.002 + frame*.002, 4, 1.0 ); //0.50 = overload. 0.45 = overheat? =0.40 = HOT 147 | // hex = HSVtoHEX( frame*.001, 1.0, 1.0); //Long, smooth, transitioning. full-brigth 148 | 149 | // hex = 0x0000ff; 150 | 151 | // hex = HSVtoHEX( i * 0.0002+.3333, 1, 1.0 ); 152 | 153 | 154 | buffer[0+i*3] = (hex>>8); 155 | buffer[1+i*3] = (hex); 156 | buffer[2+i*3] = (hex>>16); 157 | 158 | } 159 | 160 | if( firstoverride >= 0 ) 161 | buffer[0] = firstoverride; 162 | 163 | #ifdef BEAT 164 | for( i = 0; i < 4;i ++ ) 165 | { 166 | uint32_t hex = ((-frame % 48)+48)*256/48;//((frame %48) == 0)?0xffffff:0x000000; 167 | hex |= hex<<8 | hex<<16; 168 | buffer[0+i*3] = (hex>>8); 169 | buffer[1+i*3] = (hex); 170 | buffer[2+i*3] = (hex>>16); 171 | } 172 | #endif 173 | 174 | sendto(sockfd,buffer,sizeof(buffer),0, 175 | (struct sockaddr *)&servaddr,sizeof(servaddr)); 176 | frame++; 177 | printf( "." ); 178 | fflush( stdout ); 179 | usleep(14000); 180 | } 181 | } 182 | 183 | -------------------------------------------------------------------------------- /user/custom_commands.c: -------------------------------------------------------------------------------- 1 | //Copyright 2015 <>< Charles Lohr, see LICENSE file. 2 | 3 | #include 4 | 5 | extern uint8_t last_leds[512*3]; 6 | extern int last_led_count; 7 | 8 | 9 | int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata, unsigned short len) 10 | { 11 | char * buffend = buffer; 12 | 13 | switch( pusrdata[1] ) 14 | { 15 | case 'C': case 'c': //Custom command test 16 | { 17 | buffend += ets_sprintf( buffend, "CC" ); 18 | return buffend-buffer; 19 | } 20 | 21 | case 'l': case 'L': //LEDs 22 | { 23 | int i, it = 0; 24 | buffend += ets_sprintf( buffend, "CL:%d:", last_led_count ); 25 | uint16_t toledsvals = last_led_count*3; 26 | if( toledsvals > 600 ) toledsvals = 600; 27 | for( i = 0; i < toledsvals; i++ ) 28 | { 29 | uint8_t samp = last_leds[it++]; 30 | *(buffend++) = tohex1( samp>>4 ); 31 | *(buffend++) = tohex1( samp&0x0f ); 32 | } 33 | return buffend-buffer; 34 | } 35 | 36 | 37 | } 38 | return -1; 39 | } 40 | -------------------------------------------------------------------------------- /user/slc_register.h: -------------------------------------------------------------------------------- 1 | //Generated at 2012-10-23 19:55:03 2 | /* 3 | * Copyright (c) 2010 - 2011 Espressif System 4 | * 5 | */ 6 | 7 | #ifndef SLC_REGISTER_H_ 8 | #define SLC_REGISTER_H_ 9 | 10 | #define REG_SLC_BASE 0x60000B00 11 | //version value:32'h091700 12 | 13 | #define SLC_CONF0 (REG_SLC_BASE + 0x0) 14 | #ifndef ESP_MAC_5 15 | #define SLC_MODE 0x00000003 16 | #define SLC_MODE_S 12 17 | #endif 18 | #define SLC_DATA_BURST_EN (BIT(9)) 19 | #define SLC_DSCR_BURST_EN (BIT(8)) 20 | #define SLC_RX_NO_RESTART_CLR (BIT(7)) 21 | #define SLC_RX_AUTO_WRBACK (BIT(6)) 22 | #define SLC_RX_LOOP_TEST (BIT(5)) 23 | #define SLC_TX_LOOP_TEST (BIT(4)) 24 | #define SLC_AHBM_RST (BIT(3)) 25 | #define SLC_AHBM_FIFO_RST (BIT(2)) 26 | #define SLC_RXLINK_RST (BIT(1)) 27 | #define SLC_TXLINK_RST (BIT(0)) 28 | 29 | #define SLC_INT_RAW (REG_SLC_BASE + 0x4) 30 | #define SLC_TX_DSCR_EMPTY_INT_RAW (BIT(21)) 31 | #define SLC_RX_DSCR_ERR_INT_RAW (BIT(20)) 32 | #define SLC_TX_DSCR_ERR_INT_RAW (BIT(19)) 33 | #define SLC_TOHOST_INT_RAW (BIT(18)) 34 | #define SLC_RX_EOF_INT_RAW (BIT(17)) 35 | #define SLC_RX_DONE_INT_RAW (BIT(16)) 36 | #define SLC_TX_EOF_INT_RAW (BIT(15)) 37 | #define SLC_TX_DONE_INT_RAW (BIT(14)) 38 | #define SLC_TOKEN1_1TO0_INT_RAW (BIT(13)) 39 | #define SLC_TOKEN0_1TO0_INT_RAW (BIT(12)) 40 | #define SLC_TX_OVF_INT_RAW (BIT(11)) 41 | #define SLC_RX_UDF_INT_RAW (BIT(10)) 42 | #define SLC_TX_START_INT_RAW (BIT(9)) 43 | #define SLC_RX_START_INT_RAW (BIT(8)) 44 | #define SLC_FRHOST_BIT7_INT_RAW (BIT(7)) 45 | #define SLC_FRHOST_BIT6_INT_RAW (BIT(6)) 46 | #define SLC_FRHOST_BIT5_INT_RAW (BIT(5)) 47 | #define SLC_FRHOST_BIT4_INT_RAW (BIT(4)) 48 | #define SLC_FRHOST_BIT3_INT_RAW (BIT(3)) 49 | #define SLC_FRHOST_BIT2_INT_RAW (BIT(2)) 50 | #define SLC_FRHOST_BIT1_INT_RAW (BIT(1)) 51 | #define SLC_FRHOST_BIT0_INT_RAW (BIT(0)) 52 | 53 | #define SLC_INT_STATUS (REG_SLC_BASE + 0x8) 54 | #define SLC_TX_DSCR_EMPTY_INT_ST (BIT(21)) 55 | #define SLC_RX_DSCR_ERR_INT_ST (BIT(20)) 56 | #define SLC_TX_DSCR_ERR_INT_ST (BIT(19)) 57 | #define SLC_TOHOST_INT_ST (BIT(18)) 58 | #define SLC_RX_EOF_INT_ST (BIT(17)) 59 | #define SLC_RX_DONE_INT_ST (BIT(16)) 60 | #define SLC_TX_EOF_INT_ST (BIT(15)) 61 | #define SLC_TX_DONE_INT_ST (BIT(14)) 62 | #define SLC_TOKEN1_1TO0_INT_ST (BIT(13)) 63 | #define SLC_TOKEN0_1TO0_INT_ST (BIT(12)) 64 | #define SLC_TX_OVF_INT_ST (BIT(11)) 65 | #define SLC_RX_UDF_INT_ST (BIT(10)) 66 | #define SLC_TX_START_INT_ST (BIT(9)) 67 | #define SLC_RX_START_INT_ST (BIT(8)) 68 | #define SLC_FRHOST_BIT7_INT_ST (BIT(7)) 69 | #define SLC_FRHOST_BIT6_INT_ST (BIT(6)) 70 | #define SLC_FRHOST_BIT5_INT_ST (BIT(5)) 71 | #define SLC_FRHOST_BIT4_INT_ST (BIT(4)) 72 | #define SLC_FRHOST_BIT3_INT_ST (BIT(3)) 73 | #define SLC_FRHOST_BIT2_INT_ST (BIT(2)) 74 | #define SLC_FRHOST_BIT1_INT_ST (BIT(1)) 75 | #define SLC_FRHOST_BIT0_INT_ST (BIT(0)) 76 | 77 | #define SLC_INT_ENA (REG_SLC_BASE + 0xC) 78 | #define SLC_TX_DSCR_EMPTY_INT_ENA (BIT(21)) 79 | #define SLC_RX_DSCR_ERR_INT_ENA (BIT(20)) 80 | #define SLC_TX_DSCR_ERR_INT_ENA (BIT(19)) 81 | #define SLC_TOHOST_INT_ENA (BIT(18)) 82 | #define SLC_RX_EOF_INT_ENA (BIT(17)) 83 | #define SLC_RX_DONE_INT_ENA (BIT(16)) 84 | #define SLC_TX_EOF_INT_ENA (BIT(15)) 85 | #define SLC_TX_DONE_INT_ENA (BIT(14)) 86 | #define SLC_TOKEN1_1TO0_INT_ENA (BIT(13)) 87 | #define SLC_TOKEN0_1TO0_INT_ENA (BIT(12)) 88 | #define SLC_TX_OVF_INT_ENA (BIT(11)) 89 | #define SLC_RX_UDF_INT_ENA (BIT(10)) 90 | #define SLC_TX_START_INT_ENA (BIT(9)) 91 | #define SLC_RX_START_INT_ENA (BIT(8)) 92 | #define SLC_FRHOST_BIT7_INT_ENA (BIT(7)) 93 | #define SLC_FRHOST_BIT6_INT_ENA (BIT(6)) 94 | #define SLC_FRHOST_BIT5_INT_ENA (BIT(5)) 95 | #define SLC_FRHOST_BIT4_INT_ENA (BIT(4)) 96 | #define SLC_FRHOST_BIT3_INT_ENA (BIT(3)) 97 | #define SLC_FRHOST_BIT2_INT_ENA (BIT(2)) 98 | #define SLC_FRHOST_BIT1_INT_ENA (BIT(1)) 99 | #define SLC_FRHOST_BIT0_INT_ENA (BIT(0)) 100 | 101 | #define SLC_FRHOST_BIT_INT_ENA_ALL 0xff 102 | 103 | #define SLC_INT_CLR (REG_SLC_BASE + 0x10) 104 | #define SLC_TX_DSCR_EMPTY_INT_CLR (BIT(21)) 105 | #define SLC_RX_DSCR_ERR_INT_CLR (BIT(20)) 106 | #define SLC_TX_DSCR_ERR_INT_CLR (BIT(19)) 107 | #define SLC_TOHOST_INT_CLR (BIT(18)) 108 | #define SLC_RX_EOF_INT_CLR (BIT(17)) 109 | #define SLC_RX_DONE_INT_CLR (BIT(16)) 110 | #define SLC_TX_EOF_INT_CLR (BIT(15)) 111 | #define SLC_TX_DONE_INT_CLR (BIT(14)) 112 | #define SLC_TOKEN1_1TO0_INT_CLR (BIT(13)) 113 | #define SLC_TOKEN0_1TO0_INT_CLR (BIT(12)) 114 | #define SLC_TX_OVF_INT_CLR (BIT(11)) 115 | #define SLC_RX_UDF_INT_CLR (BIT(10)) 116 | #define SLC_TX_START_INT_CLR (BIT(9)) 117 | #define SLC_RX_START_INT_CLR (BIT(8)) 118 | #define SLC_FRHOST_BIT7_INT_CLR (BIT(7)) 119 | #define SLC_FRHOST_BIT6_INT_CLR (BIT(6)) 120 | #define SLC_FRHOST_BIT5_INT_CLR (BIT(5)) 121 | #define SLC_FRHOST_BIT4_INT_CLR (BIT(4)) 122 | #define SLC_FRHOST_BIT3_INT_CLR (BIT(3)) 123 | #define SLC_FRHOST_BIT2_INT_CLR (BIT(2)) 124 | #define SLC_FRHOST_BIT1_INT_CLR (BIT(1)) 125 | #define SLC_FRHOST_BIT0_INT_CLR (BIT(0)) 126 | 127 | #define SLC_RX_STATUS (REG_SLC_BASE + 0x14) 128 | #define SLC_RX_EMPTY (BIT(1)) 129 | #define SLC_RX_FULL (BIT(0)) 130 | 131 | #define SLC_RX_FIFO_PUSH (REG_SLC_BASE + 0x18) 132 | #define SLC_RXFIFO_PUSH (BIT(16)) 133 | #define SLC_RXFIFO_WDATA 0x000001FF 134 | #define SLC_RXFIFO_WDATA_S 0 135 | 136 | #define SLC_TX_STATUS (REG_SLC_BASE + 0x1C) 137 | #define SLC_TX_EMPTY (BIT(1)) 138 | #define SLC_TX_FULL (BIT(0)) 139 | 140 | #define SLC_TX_FIFO_POP (REG_SLC_BASE + 0x20) 141 | #define SLC_TXFIFO_POP (BIT(16)) 142 | #define SLC_TXFIFO_RDATA 0x000007FF 143 | #define SLC_TXFIFO_RDATA_S 0 144 | 145 | #define SLC_RX_LINK (REG_SLC_BASE + 0x24) 146 | #define SLC_RXLINK_PARK (BIT(31)) 147 | #define SLC_RXLINK_RESTART (BIT(30)) 148 | #define SLC_RXLINK_START (BIT(29)) 149 | #define SLC_RXLINK_STOP (BIT(28)) 150 | #define SLC_RXLINK_DESCADDR_MASK 0x000FFFFF 151 | #define SLC_RXLINK_ADDR_S 0 152 | 153 | #define SLC_TX_LINK (REG_SLC_BASE + 0x28) 154 | #define SLC_TXLINK_PARK (BIT(31)) 155 | #define SLC_TXLINK_RESTART (BIT(30)) 156 | #define SLC_TXLINK_START (BIT(29)) 157 | #define SLC_TXLINK_STOP (BIT(28)) 158 | #define SLC_TXLINK_DESCADDR_MASK 0x000FFFFF 159 | #define SLC_TXLINK_ADDR_S 0 160 | 161 | #define SLC_INTVEC_TOHOST (REG_SLC_BASE + 0x2C) 162 | #define SLC_TOHOST_INTVEC 0x000000FF 163 | #define SLC_TOHOST_INTVEC_S 0 164 | 165 | #define SLC_TOKEN0 (REG_SLC_BASE + 0x30) 166 | #define SLC_TOKEN0_MASK 0x00000FFF 167 | #define SLC_TOKEN0_S 16 168 | #define SLC_TOKEN0_LOCAL_INC_MORE (BIT(14)) 169 | #define SLC_TOKEN0_LOCAL_INC (BIT(13)) 170 | #define SLC_TOKEN0_LOCAL_WR (BIT(12)) 171 | #define SLC_TOKEN0_LOCAL_WDATA_MASK 0x00000FFF 172 | #define SLC_TOKEN0_LOCAL_WDATA_S 0 173 | 174 | #define SLC_TOKEN1 (REG_SLC_BASE + 0x34) 175 | #define SLC_TOKEN1_MASK 0x00000FFF 176 | #define SLC_TOKEN1_S 16 177 | #define SLC_TOKEN1_LOCAL_INC_MORE (BIT(14)) 178 | #define SLC_TOKEN1_LOCAL_INC (BIT(13)) 179 | #define SLC_TOKEN1_LOCAL_WR (BIT(12)) 180 | #define SLC_TOKEN1_LOCAL_WDATA 0x00000FFF 181 | #define SLC_TOKEN1_LOCAL_WDATA_S 0 182 | 183 | #define SLC_CONF1 (REG_SLC_BASE + 0x38) 184 | #define SLC_STATE0 (REG_SLC_BASE + 0x3C) 185 | #define SLC_STATE1 (REG_SLC_BASE + 0x40) 186 | 187 | #define SLC_BRIDGE_CONF (REG_SLC_BASE + 0x44) 188 | #ifndef ESP_MAC_5 189 | #define SLC_TX_PUSH_IDLE_NUM 0x0000FFFF 190 | #define SLC_TX_PUSH_IDLE_NUM_S 16 191 | #define SLC_TX_DUMMY_MODE (BIT(12)) 192 | #endif 193 | #define SLC_FIFO_MAP_ENA 0x0000000F 194 | #define SLC_FIFO_MAP_ENA_S 8 195 | #define SLC_TXEOF_ENA 0x0000003F 196 | #define SLC_TXEOF_ENA_S 0 197 | 198 | #define SLC_RX_EOF_DES_ADDR (REG_SLC_BASE + 0x48) 199 | #define SLC_TX_EOF_DES_ADDR (REG_SLC_BASE + 0x4C) 200 | #define SLC_FROM_HOST_LAST_DESC SLC_TX_EOF_DES_ADDR 201 | #define SLC_TO_HOST_LAST_DESC SLC_RX_EOF_DES_ADDR 202 | 203 | #define SLC_RX_EOF_BFR_DES_ADDR (REG_SLC_BASE + 0x50) 204 | #define SLC_AHB_TEST (REG_SLC_BASE + 0x54) 205 | #define SLC_AHB_TESTADDR 0x00000003 206 | #define SLC_AHB_TESTADDR_S 4 207 | #define SLC_AHB_TESTMODE 0x00000007 208 | #define SLC_AHB_TESTMODE_S 0 209 | 210 | #define SLC_SDIO_ST (REG_SLC_BASE + 0x58) 211 | #define SLC_BUS_ST 0x00000007 212 | #define SLC_BUS_ST_S 12 213 | #define SLC_SDIO_WAKEUP (BIT(8)) 214 | #define SLC_FUNC_ST 0x0000000F 215 | #define SLC_FUNC_ST_S 4 216 | #define SLC_CMD_ST 0x00000007 217 | #define SLC_CMD_ST_S 0 218 | 219 | #define SLC_RX_DSCR_CONF (REG_SLC_BASE + 0x5C) 220 | #ifdef ESP_MAC_5 221 | #define SLC_INFOR_NO_REPLACE (BIT(9)) 222 | #define SLC_TOKEN_NO_REPLACE (BIT(8)) 223 | #define SLC_POP_IDLE_CNT 0x000000FF 224 | #else 225 | #define SLC_RX_FILL_EN (BIT(20)) 226 | #define SLC_RX_EOF_MODE (BIT(19)) 227 | #define SLC_RX_FILL_MODE (BIT(18)) 228 | #define SLC_INFOR_NO_REPLACE (BIT(17)) 229 | #define SLC_TOKEN_NO_REPLACE (BIT(16)) 230 | #define SLC_POP_IDLE_CNT 0x0000FFFF 231 | #endif 232 | #define SLC_POP_IDLE_CNT_S 0 233 | 234 | #define SLC_TXLINK_DSCR (REG_SLC_BASE + 0x60) 235 | #define SLC_TXLINK_DSCR_BF0 (REG_SLC_BASE + 0x64) 236 | #define SLC_TXLINK_DSCR_BF1 (REG_SLC_BASE + 0x68) 237 | #define SLC_RXLINK_DSCR (REG_SLC_BASE + 0x6C) 238 | #define SLC_RXLINK_DSCR_BF0 (REG_SLC_BASE + 0x70) 239 | #define SLC_RXLINK_DSCR_BF1 (REG_SLC_BASE + 0x74) 240 | #define SLC_DATE (REG_SLC_BASE + 0x78) 241 | #define SLC_ID (REG_SLC_BASE + 0x7C) 242 | 243 | #define SLC_HOST_CONF_W0 (REG_SLC_BASE + 0x80 + 0x14) 244 | #define SLC_HOST_CONF_W1 (REG_SLC_BASE + 0x80 + 0x18) 245 | #define SLC_HOST_CONF_W2 (REG_SLC_BASE + 0x80 + 0x20) 246 | #define SLC_HOST_CONF_W3 (REG_SLC_BASE + 0x80 + 0x24) 247 | #define SLC_HOST_CONF_W4 (REG_SLC_BASE + 0x80 + 0x28) 248 | 249 | #define SLC_HOST_INTR_ST (REG_SLC_BASE + 0x80 + 0x1c) 250 | #define SLC_HOST_INTR_CLR (REG_SLC_BASE + 0x80 + 0x30) 251 | #define SLC_HOST_INTR_SOF_BIT (BIT(12)) 252 | 253 | #define SLC_HOST_INTR_ENA (REG_SLC_BASE + 0x80 + 0x34) 254 | #define SLC_RX_NEW_PACKET_INT_ENA (BIT23) 255 | #define SLC_HOST_TOHOST_BIT0_INT_ENA (BIT0) 256 | #define SLC_HOST_CONF_W5 (REG_SLC_BASE + 0x80 + 0x3C) 257 | #define SLC_HOST_INTR_RAW (REG_SLC_BASE + 0x80 + 0x8) 258 | #define SLC_HOST_INTR_ENA_BIT (BIT(23)) 259 | //[15:12]: 0x3ff9xxxx -- 0b01 from_host 260 | // 0x3ffaxxxx -- 0b10 general 261 | // 0x3ffbxxxx -- 0b11 to_host 262 | #define SLC_DATA_ADDR_CLEAR_MASK (~(0xf<<12)) 263 | #define SLC_FROM_HOST_ADDR_MASK (0x1<<12) 264 | #define SLC_TO_HOST_ADDR_MASK (0x3<<12) 265 | 266 | #define SLC_SET_FROM_HOST_ADDR_MASK(v) do { \ 267 | (v) &= SLC_DATA_ADDR_CLEAR_MASK; \ 268 | (v) |= SLC_FROM_HOST_ADDR_MASK; \ 269 | } while(0); 270 | 271 | #define SLC_SET_TO_HOST_ADDR_MASK(v) do { \ 272 | (v) &= SLC_DATA_ADDR_CLEAR_MASK; \ 273 | (v) |= SLC_TO_HOST_ADDR_MASK; \ 274 | } while(0); 275 | 276 | 277 | #define SLC_TX_DESC_DEBUG_REG 0x3ff0002c //[15:0] set to 0xcccc 278 | 279 | 280 | #endif // SLC_REGISTER_H_INCLUDED 281 | 282 | -------------------------------------------------------------------------------- /user/user_main.c: -------------------------------------------------------------------------------- 1 | //Copyright 2015 <>< Charles Lohr, see LICENSE file. 2 | 3 | #include "mem.h" 4 | #include "c_types.h" 5 | #include "user_interface.h" 6 | #include "ets_sys.h" 7 | #include "driver/uart.h" 8 | #include "osapi.h" 9 | #include "espconn.h" 10 | #include "mystuff.h" 11 | #include "ws2812_i2s.h" 12 | #include "commonservices.h" 13 | #include 14 | 15 | #define PORT 7777 16 | 17 | #define procTaskPrio 0 18 | #define procTaskQueueLen 1 19 | 20 | static volatile os_timer_t some_timer; 21 | static struct espconn *pUdpServer; 22 | uint8_t last_leds[512*3]; 23 | int last_led_count; 24 | 25 | 26 | //int ICACHE_FLASH_ATTR StartMDNS(); 27 | 28 | void user_rf_pre_init(void) 29 | { 30 | //nothing. 31 | } 32 | 33 | 34 | char * strcat( char * dest, char * src ) 35 | { 36 | return strcat(dest, src ); 37 | } 38 | 39 | 40 | 41 | //Tasks that happen all the time. 42 | 43 | os_event_t procTaskQueue[procTaskQueueLen]; 44 | 45 | static void ICACHE_FLASH_ATTR procTask(os_event_t *events) 46 | { 47 | CSTick( 0 ); 48 | system_os_post(procTaskPrio, 0, 0 ); 49 | } 50 | 51 | //Timer event. 52 | static void ICACHE_FLASH_ATTR myTimer(void *arg) 53 | { 54 | CSTick( 1 ); 55 | } 56 | 57 | 58 | //Called when new packet comes in. 59 | static void ICACHE_FLASH_ATTR 60 | udpserver_recv(void *arg, char *pusrdata, unsigned short len) 61 | { 62 | struct espconn *pespconn = (struct espconn *)arg; 63 | 64 | uart0_sendStr("X"); 65 | 66 | 67 | len -= 3; 68 | if( len > sizeof(last_leds) + 3 ) 69 | { 70 | len = sizeof(last_leds) + 3; 71 | } 72 | ets_memcpy( last_leds, pusrdata+3, len ); 73 | last_led_count = len / 3; 74 | } 75 | 76 | void ICACHE_FLASH_ATTR charrx( uint8_t c ) 77 | { 78 | //Called from UART. 79 | } 80 | 81 | void user_init(void) 82 | { 83 | uart_init(BIT_RATE_115200, BIT_RATE_115200); 84 | 85 | uart0_sendStr("\r\nesp8266 ws2812 driver\r\n"); 86 | 87 | // int opm = wifi_get_opmode(); 88 | // if( opm == 1 ) need_to_switch_opmode = 120; 89 | // wifi_set_opmode_current(2); 90 | //Uncomment this to force a system restore. 91 | // system_restore(); 92 | 93 | CSSettingsLoad( 0 ); 94 | CSPreInit(); 95 | 96 | pUdpServer = (struct espconn *)os_zalloc(sizeof(struct espconn)); 97 | ets_memset( pUdpServer, 0, sizeof( struct espconn ) ); 98 | espconn_create( pUdpServer ); 99 | pUdpServer->type = ESPCONN_UDP; 100 | pUdpServer->proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp)); 101 | pUdpServer->proto.udp->local_port = 7777; 102 | espconn_regist_recvcb(pUdpServer, udpserver_recv); 103 | 104 | if( espconn_create( pUdpServer ) ) 105 | { 106 | while(1) { uart0_sendStr( "\r\nFAULT\r\n" ); } 107 | } 108 | 109 | CSInit(); 110 | 111 | SetServiceName( "ws2812" ); 112 | AddMDNSName( "cn8266" ); 113 | AddMDNSName( "ws2812" ); 114 | AddMDNSService( "_http._tcp", "An ESP8266 Webserver", 80 ); 115 | AddMDNSService( "_ws2812._udp", "WS2812 Driver", 7777 ); 116 | AddMDNSService( "_cn8266._udp", "ESP8266 Backend", 7878 ); 117 | 118 | //Add a process 119 | system_os_task(procTask, procTaskPrio, procTaskQueue, procTaskQueueLen); 120 | 121 | //Timer example 122 | os_timer_disarm(&some_timer); 123 | os_timer_setfn(&some_timer, (os_timer_func_t *)myTimer, NULL); 124 | os_timer_arm(&some_timer, 100, 1); 125 | 126 | reprap_dmaio_init(); 127 | 128 | system_os_post(procTaskPrio, 0, 0 ); 129 | } 130 | 131 | 132 | //There is no code in this project that will cause reboots if interrupts are disabled. 133 | void EnterCritical() 134 | { 135 | } 136 | 137 | void ExitCritical() 138 | { 139 | } 140 | 141 | 142 | -------------------------------------------------------------------------------- /user/ws2812_i2s.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright 2013-2015 Espressif Systems 3 | * 2015 <>< Charles Lohr 4 | * 5 | * FileName: i2s_freertos.c 6 | * 7 | * Description: I2S output routines for a FreeRTOS system. Uses DMA and a queue 8 | * to abstract away the nitty-gritty details. 9 | * 10 | * Modification history: 11 | * 2015/06/01, v1.0 File created. 12 | * 2015/07/23, Switch to making it a WS2812 output device. 13 | ******************************************************************************* 14 | 15 | Notes: 16 | 17 | This is pretty badly hacked together from the MP3 example. 18 | I spent some time trying to strip it down to avoid a lot of the TX_ stuff. 19 | That seems to work. 20 | 21 | Major suggestions that I couldn't figure out: 22 | * Use interrupts to disable DMA, so it isn't running nonstop. 23 | * Use interrupts to flag when new data can be sent. 24 | 25 | When I try using interrupts, it seems to work for a bit but things fall apart 26 | rather quickly and the engine just refuses to send anymore until reboot. 27 | 28 | The way it works right now is to keep the DMA running forever and just update 29 | the data in the buffer so it continues sending the frame. 30 | 31 | Extra copyright info: 32 | Actually not much of this file is Copyright Espressif, comparativly little 33 | mostly just the stuff to make the I2S bus go. 34 | 35 | *******************************************************************************/ 36 | 37 | 38 | #include "slc_register.h" 39 | #include "mystuff.h" 40 | #include 41 | #include "ws2812_i2s.h" 42 | #include "user_interface.h" 43 | #include "pin_mux_register.h" 44 | 45 | //Creates an I2S SR of 93,750 Hz, or 3 MHz Bitclock (.333us/sample) 46 | // 12000000L/(div*bestbck*2) 47 | //It is likely you could speed this up a little. 48 | 49 | #define WS_I2S_BCK 10 //Seems to work as low as 14, shoddy at 13. 50 | #define WS_I2S_DIV 4 51 | 52 | #ifndef i2c_bbpll 53 | #define i2c_bbpll 0x67 54 | #define i2c_bbpll_en_audio_clock_out 4 55 | #define i2c_bbpll_en_audio_clock_out_msb 7 56 | #define i2c_bbpll_en_audio_clock_out_lsb 7 57 | #define i2c_bbpll_hostid 4 58 | 59 | #define i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata) rom_i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata) 60 | #define i2c_readReg_Mask(block, host_id, reg_add, Msb, Lsb) rom_i2c_readReg_Mask(block, host_id, reg_add, Msb, Lsb) 61 | #define i2c_writeReg_Mask_def(block, reg_add, indata) \ 62 | i2c_writeReg_Mask(block, block##_hostid, reg_add, reg_add##_msb, reg_add##_lsb, indata) 63 | #define i2c_readReg_Mask_def(block, reg_add) \ 64 | i2c_readReg_Mask(block, block##_hostid, reg_add, reg_add##_msb, reg_add##_lsb) 65 | #endif 66 | #ifndef ETS_SLC_INUM 67 | #define ETS_SLC_INUM 1 68 | #endif 69 | 70 | 71 | 72 | //From i2s_reg.h 73 | #define DR_REG_I2S_BASE (0x60000e00) 74 | 75 | #define I2STXFIFO (DR_REG_I2S_BASE + 0x0000) 76 | #define I2SRXFIFO (DR_REG_I2S_BASE + 0x0004) 77 | #define I2SCONF (DR_REG_I2S_BASE + 0x0008) 78 | #define I2S_BCK_DIV_NUM 0x0000003F 79 | #define I2S_BCK_DIV_NUM_S 22 80 | #define I2S_CLKM_DIV_NUM 0x0000003F 81 | #define I2S_CLKM_DIV_NUM_S 16 82 | #define I2S_BITS_MOD 0x0000000F 83 | #define I2S_BITS_MOD_S 12 84 | #define I2S_RECE_MSB_SHIFT (BIT(11)) 85 | #define I2S_TRANS_MSB_SHIFT (BIT(10)) 86 | #define I2S_I2S_RX_START (BIT(9)) 87 | #define I2S_I2S_TX_START (BIT(8)) 88 | #define I2S_MSB_RIGHT (BIT(7)) 89 | #define I2S_RIGHT_FIRST (BIT(6)) 90 | #define I2S_RECE_SLAVE_MOD (BIT(5)) 91 | #define I2S_TRANS_SLAVE_MOD (BIT(4)) 92 | #define I2S_I2S_RX_FIFO_RESET (BIT(3)) 93 | #define I2S_I2S_TX_FIFO_RESET (BIT(2)) 94 | #define I2S_I2S_RX_RESET (BIT(1)) 95 | #define I2S_I2S_TX_RESET (BIT(0)) 96 | #define I2S_I2S_RESET_MASK 0xf 97 | 98 | #define I2SINT_RAW (DR_REG_I2S_BASE + 0x000c) 99 | #define I2S_I2S_TX_REMPTY_INT_RAW (BIT(5)) 100 | #define I2S_I2S_TX_WFULL_INT_RAW (BIT(4)) 101 | #define I2S_I2S_RX_REMPTY_INT_RAW (BIT(3)) 102 | #define I2S_I2S_RX_WFULL_INT_RAW (BIT(2)) 103 | #define I2S_I2S_TX_PUT_DATA_INT_RAW (BIT(1)) 104 | #define I2S_I2S_RX_TAKE_DATA_INT_RAW (BIT(0)) 105 | 106 | 107 | #define I2SINT_ST (DR_REG_I2S_BASE + 0x0010) 108 | #define I2S_I2S_TX_REMPTY_INT_ST (BIT(5)) 109 | #define I2S_I2S_TX_WFULL_INT_ST (BIT(4)) 110 | #define I2S_I2S_RX_REMPTY_INT_ST (BIT(3)) 111 | #define I2S_I2S_RX_WFULL_INT_ST (BIT(2)) 112 | #define I2S_I2S_TX_PUT_DATA_INT_ST (BIT(1)) 113 | #define I2S_I2S_RX_TAKE_DATA_INT_ST (BIT(0)) 114 | 115 | #define I2SINT_ENA (DR_REG_I2S_BASE + 0x0014) 116 | #define I2S_I2S_TX_REMPTY_INT_ENA (BIT(5)) 117 | #define I2S_I2S_TX_WFULL_INT_ENA (BIT(4)) 118 | #define I2S_I2S_RX_REMPTY_INT_ENA (BIT(3)) 119 | #define I2S_I2S_RX_WFULL_INT_ENA (BIT(2)) 120 | #define I2S_I2S_TX_PUT_DATA_INT_ENA (BIT(1)) 121 | #define I2S_I2S_RX_TAKE_DATA_INT_ENA (BIT(0)) 122 | 123 | #define I2SINT_CLR (DR_REG_I2S_BASE + 0x0018) 124 | #define I2S_I2S_TX_REMPTY_INT_CLR (BIT(5)) 125 | #define I2S_I2S_TX_WFULL_INT_CLR (BIT(4)) 126 | #define I2S_I2S_RX_REMPTY_INT_CLR (BIT(3)) 127 | #define I2S_I2S_RX_WFULL_INT_CLR (BIT(2)) 128 | #define I2S_I2S_PUT_DATA_INT_CLR (BIT(1)) 129 | #define I2S_I2S_TAKE_DATA_INT_CLR (BIT(0)) 130 | 131 | #define I2STIMING (DR_REG_I2S_BASE + 0x001c) 132 | #define I2S_TRANS_BCK_IN_INV (BIT(22)) 133 | #define I2S_RECE_DSYNC_SW (BIT(21)) 134 | #define I2S_TRANS_DSYNC_SW (BIT(20)) 135 | #define I2S_RECE_BCK_OUT_DELAY 0x00000003 136 | #define I2S_RECE_BCK_OUT_DELAY_S 18 137 | #define I2S_RECE_WS_OUT_DELAY 0x00000003 138 | #define I2S_RECE_WS_OUT_DELAY_S 16 139 | #define I2S_TRANS_SD_OUT_DELAY 0x00000003 140 | #define I2S_TRANS_SD_OUT_DELAY_S 14 141 | #define I2S_TRANS_WS_OUT_DELAY 0x00000003 142 | #define I2S_TRANS_WS_OUT_DELAY_S 12 143 | #define I2S_TRANS_BCK_OUT_DELAY 0x00000003 144 | #define I2S_TRANS_BCK_OUT_DELAY_S 10 145 | #define I2S_RECE_SD_IN_DELAY 0x00000003 146 | #define I2S_RECE_SD_IN_DELAY_S 8 147 | #define I2S_RECE_WS_IN_DELAY 0x00000003 148 | #define I2S_RECE_WS_IN_DELAY_S 6 149 | #define I2S_RECE_BCK_IN_DELAY 0x00000003 150 | #define I2S_RECE_BCK_IN_DELAY_S 4 151 | #define I2S_TRANS_WS_IN_DELAY 0x00000003 152 | #define I2S_TRANS_WS_IN_DELAY_S 2 153 | #define I2S_TRANS_BCK_IN_DELAY 0x00000003 154 | #define I2S_TRANS_BCK_IN_DELAY_S 0 155 | 156 | #define I2S_FIFO_CONF (DR_REG_I2S_BASE + 0x0020) 157 | #define I2S_I2S_RX_FIFO_MOD 0x00000007 158 | #define I2S_I2S_RX_FIFO_MOD_S 16 159 | #define I2S_I2S_TX_FIFO_MOD 0x00000007 160 | #define I2S_I2S_TX_FIFO_MOD_S 13 161 | #define I2S_I2S_DSCR_EN (BIT(12)) 162 | #define I2S_I2S_TX_DATA_NUM 0x0000003F 163 | #define I2S_I2S_TX_DATA_NUM_S 6 164 | #define I2S_I2S_RX_DATA_NUM 0x0000003F 165 | #define I2S_I2S_RX_DATA_NUM_S 0 166 | 167 | 168 | #define I2SRXEOF_NUM (DR_REG_I2S_BASE + 0x0024) 169 | #define I2S_I2S_RX_EOF_NUM 0xFFFFFFFF 170 | #define I2S_I2S_RX_EOF_NUM_S 0 171 | 172 | #define I2SCONF_SIGLE_DATA (DR_REG_I2S_BASE + 0x0028) 173 | #define I2S_I2S_SIGLE_DATA 0xFFFFFFFF 174 | #define I2S_I2S_SIGLE_DATA_S 0 175 | 176 | #define I2SCONF_CHAN (DR_REG_I2S_BASE + 0x002c) 177 | #define I2S_RX_CHAN_MOD 0x00000003 178 | #define I2S_RX_CHAN_MOD_S 3 179 | #define I2S_TX_CHAN_MOD 0x00000007 180 | #define I2S_TX_CHAN_MOD_S 0 181 | 182 | //From sdio_slv.h 183 | 184 | struct sdio_queue 185 | { 186 | uint32 blocksize:12; 187 | uint32 datalen:12; 188 | uint32 unused:5; 189 | uint32 sub_sof:1; 190 | uint32 eof:1; 191 | uint32 owner:1; 192 | 193 | uint32 buf_ptr; 194 | uint32 next_link_ptr; 195 | }; 196 | 197 | struct sdio_slave_status_element 198 | { 199 | uint32 wr_busy:1; 200 | uint32 rd_empty :1; 201 | uint32 comm_cnt :3; 202 | uint32 intr_no :3; 203 | uint32 rx_length:16; 204 | uint32 res:8; 205 | }; 206 | 207 | union sdio_slave_status 208 | { 209 | struct sdio_slave_status_element elm_value; 210 | uint32 word_value; 211 | }; 212 | 213 | #define RX_AVAILIBLE 2 214 | #define TX_AVAILIBLE 1 215 | #define INIT_STAGE 0 216 | 217 | #define SDIO_QUEUE_LEN 8 218 | #define MOSI 0 219 | #define MISO 1 220 | #define SDIO_DATA_ERROR 6 221 | 222 | #define SLC_INTEREST_EVENT (SLC_TX_EOF_INT_ENA | SLC_RX_EOF_INT_ENA | SLC_RX_UDF_INT_ENA | SLC_TX_DSCR_ERR_INT_ENA) 223 | #define TRIG_TOHOST_INT() SET_PERI_REG_MASK(SLC_INTVEC_TOHOST , BIT0);\ 224 | CLEAR_PERI_REG_MASK(SLC_INTVEC_TOHOST , BIT0) 225 | 226 | ///Rest of program... 227 | 228 | //Pointer to the I2S DMA buffer data 229 | static unsigned int i2sBuf[I2SDMABUFCNT][I2SDMABUFLEN]; 230 | //I2S DMA buffer descriptors 231 | static int sdio_queue_pos = 0; 232 | static struct sdio_queue i2sBufDesc[I2SDMABUFCNT]; 233 | 234 | //Queue which contains empty DMA buffers 235 | //DMA underrun counter 236 | 237 | 238 | #ifdef USE_REPRAP_DMAIO_INTERRUPTS 239 | 240 | volatile uint8_t ws2812_dma_complete; 241 | 242 | //This routine is called as soon as the DMA routine has something to tell us. All we 243 | //handle here is the RX_EOF_INT status, which indicate the DMA has sent a buffer whose 244 | //descriptor has the 'EOF' field set to 1. 245 | LOCAL void slc_isr(void) { 246 | int i; 247 | 248 | //clear all intr flags 249 | WRITE_PERI_REG(SLC_INT_CLR, 0xffffffff);//slc_intr_status); 250 | 251 | // Iterate buffers 252 | // p will point to the recently emptied buffer 253 | unsigned int *p = i2sBuf[sdio_queue_pos++]; 254 | if (sdio_queue_pos == I2SDMABUFCNT) sdio_queue_pos = 0; 255 | 256 | // 257 | for (i=0; i> 31) | (counter << 1); 262 | counter++; 263 | } 264 | } 265 | 266 | #endif 267 | 268 | //Initialize I2S subsystem for DMA circular buffer use 269 | void ICACHE_FLASH_ATTR reprap_dmaio_init() 270 | { 271 | int x, y; 272 | 273 | //Reset DMA 274 | SET_PERI_REG_MASK(SLC_CONF0, SLC_RXLINK_RST);//|SLC_TXLINK_RST); 275 | CLEAR_PERI_REG_MASK(SLC_CONF0, SLC_RXLINK_RST);//|SLC_TXLINK_RST); 276 | 277 | //Clear DMA int flags 278 | SET_PERI_REG_MASK(SLC_INT_CLR, 0xffffffff); 279 | CLEAR_PERI_REG_MASK(SLC_INT_CLR, 0xffffffff); 280 | 281 | //Enable and configure DMA 282 | CLEAR_PERI_REG_MASK(SLC_CONF0, (SLC_MODE<< Charles Lohr, See LICENSE file. 2 | //WS2812 sender that abuses the I2S interface on the WS2812. 3 | 4 | #ifndef REPRAP_DMAIO_H 5 | #define REPRAP_DMAIO_H 6 | 7 | //Stuff that should be for the header: 8 | 9 | #include 10 | 11 | //Parameters for the I2S DMA behaviour 12 | #define I2SDMABUFCNT ( 2) //Number of buffers in the I2S circular buffer 13 | #define I2SDMABUFLEN (192*5) //Length of one buffer, in 32-bit words. 14 | #define USE_REPRAP_DMAIO_INTERRUPTS 15 | 16 | void ICACHE_FLASH_ATTR reprap_dmaio_init(); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /web/Makefile: -------------------------------------------------------------------------------- 1 | all : execute_reflash page.mpfs push 2 | 3 | IP?=192.168.4.1 4 | 5 | mfsmaker : mfsmaker.c 6 | gcc -o $@ $^ 7 | 8 | page.mpfs : mfsmaker page 9 | # cat to_compress/*.js | gzip -9 > page/compressed.js.gz 10 | ./mfsmaker page page.mpfs 11 | 12 | pushtodev : pushtodev.c 13 | gcc -o $@ $^ 14 | 15 | execute_reflash : execute_reflash.c md5.c 16 | gcc -o $@ $^ 17 | 18 | push : pushtodev page.mpfs 19 | ./pushtodev $(IP) 1048576 page.mpfs 20 | 21 | clean : 22 | rm -rf mfsmaker page.mpfs pushtodev execute_reflash 23 | -------------------------------------------------------------------------------- /web/execute_reflash.c: -------------------------------------------------------------------------------- 1 | //Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or 2 | // ColorChord License. You Choose. 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "md5.h" 13 | 14 | #define BLOCK_SIZE 65536 15 | #define SECTOR_SIZE 4096 16 | #define PADDING 1024 17 | int sockfd; 18 | struct sockaddr_in servaddr,cliaddr; 19 | 20 | int PushMatch( const char * match ) 21 | { 22 | struct timeval tva, tvb; 23 | gettimeofday( &tva, 0 ); 24 | gettimeofday( &tvb, 0 ); 25 | while( tvb.tv_sec - tva.tv_sec < 3 ) 26 | { 27 | struct pollfd ufds; 28 | ufds.fd = sockfd; 29 | ufds.events = POLLIN; 30 | int rv = poll(&ufds, 1, 100); 31 | if( rv > 0 ) 32 | { 33 | char recvline[10000]; 34 | int n=recvfrom(sockfd,recvline,10000,0,NULL,NULL); 35 | // printf( "%s === %s\n", recvline, match ); 36 | if( strncmp( recvline, match, strlen( match ) ) == 0 ) 37 | { 38 | printf( "Ok - " ); fflush( stdout ); 39 | return 0; 40 | } 41 | } 42 | gettimeofday( &tvb, 0 ); 43 | } 44 | return 1; 45 | } 46 | 47 | uint32_t Push( uint32_t offset, const char * file ) 48 | { 49 | char sendline[1000]; 50 | char recvline[1000]; 51 | 52 | if( offset <= 0 ) 53 | { 54 | fprintf( stderr, "Error: Cannot write to address 0 or before.\n" ); 55 | exit(-2); 56 | } 57 | 58 | FILE * f = fopen( file, "rb" ); 59 | if( !f || feof( f ) ) 60 | { 61 | fprintf( stderr, "Error: cannot open file.\n" ); 62 | exit(-3); 63 | } 64 | 65 | 66 | 67 | int devo = 0; 68 | int lastblock = -1; 69 | 70 | while( !feof( f ) ) 71 | { 72 | int tries; 73 | int thissuccess; 74 | char buffer[PADDING]; 75 | char bufferout[2000]; 76 | 77 | int reads = fread( buffer, 1, PADDING, f ); 78 | int sendplace = offset + devo; 79 | int sendsize = PADDING;//reads; 80 | int block = sendplace / BLOCK_SIZE; 81 | 82 | memset( buffer + reads, 0, sendsize-reads ); 83 | 84 | if( block != lastblock ) 85 | { 86 | char se[64]; 87 | int sel = sprintf( se, "FB%d\r\n", block ); 88 | 89 | thissuccess = 0; 90 | for( tries = 0; tries < 10; tries++ ) 91 | { 92 | char match[75]; 93 | printf( "Erase: %d\n", block ); 94 | sendto( sockfd, se, sel, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr)); 95 | sprintf( match, "FB%d", block ); 96 | 97 | if( PushMatch(match) == 0 ) { thissuccess = 1; break; } 98 | printf( "Retry.\n" ); 99 | } 100 | if( !thissuccess ) 101 | { 102 | fprintf( stderr, "Error: Timeout in communications.\n" ); 103 | exit( -6 ); 104 | } 105 | 106 | lastblock = block; 107 | } 108 | 109 | 110 | int r = sprintf( bufferout, "FW%d\t%d\t", sendplace, sendsize ); 111 | memcpy( bufferout + r, buffer, sendsize ); 112 | 113 | printf( "bufferout: %d %d\n", sendplace, sendsize ); 114 | 115 | thissuccess = 0; 116 | for( tries = 0; tries < 10; tries++ ) 117 | { 118 | char match[75]; 119 | sendto( sockfd, bufferout, sendsize + r, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr)); 120 | sprintf( match, "FW%d", sendplace ); 121 | 122 | if( PushMatch(match) == 0 ) { thissuccess = 1; break; } 123 | printf( "Retry.\n" ); 124 | } 125 | if( !thissuccess ) 126 | { 127 | fprintf( stderr, "Error: Timeout in communications.\n" ); 128 | exit( -6 ); 129 | } 130 | if( reads != 0 ) 131 | devo += sendsize; 132 | } 133 | 134 | return devo; 135 | } 136 | 137 | void ComputeMD5WithKey( char * md5retText, const char * filename, const char * key ) 138 | { 139 | uint8_t retmd5[16]; 140 | MD5_CTX ctx; 141 | FILE * f = fopen( filename, "rb" ); 142 | if( !f ) 143 | { 144 | fprintf( stderr, "Error opening %s\n", filename ); 145 | exit( -9 ); 146 | } 147 | 148 | fseek( f, 0, SEEK_END ); 149 | int l = ftell( f ); 150 | printf("MD5 Size: %d\n", l ); 151 | int padl = ((l-1) / PADDING)*PADDING+PADDING; 152 | printf("MD5 Pad: %d\n", padl ); 153 | fseek( f, 0, SEEK_SET ); 154 | uint8_t data[padl]; 155 | fread( data, l, 1, f ); 156 | fclose( f ); 157 | 158 | memset( data+l, 0, padl-l ); 159 | MD5_Init( &ctx ); 160 | if( !strlen(key) ) 161 | MD5_Update( &ctx, key, strlen( key ) ); 162 | MD5_Update( &ctx, data, padl ); 163 | MD5_Final( retmd5, &ctx ); 164 | 165 | for( l = 0; l < 16; l++ ) 166 | { 167 | sprintf( md5retText + l*2, "%02x", retmd5[l] ); 168 | } 169 | 170 | return; 171 | } 172 | 173 | uint32_t roundup( uint32_t r ) 174 | { 175 | return ((r-1)&(~0xFFF))+0x1000; 176 | } 177 | 178 | 179 | int main(int argc, char**argv) 180 | { 181 | int n; 182 | 183 | char sendline[1000]; 184 | char recvline[1000]; 185 | 186 | char md5_f1[48]; 187 | char md5_f2[48]; 188 | 189 | if (argc < 4 ) 190 | { 191 | printf("usage: pushtodev [IP address] [file_lower] [file_upper] [key (optional)]\n"); 192 | exit(-1); 193 | } 194 | 195 | const char * file1 = argv[2]; 196 | const char * file2 = argv[3]; 197 | 198 | 199 | 200 | sockfd=socket(AF_INET,SOCK_DGRAM,0); 201 | 202 | bzero(&servaddr,sizeof(servaddr)); 203 | servaddr.sin_family = AF_INET; 204 | servaddr.sin_addr.s_addr=inet_addr(argv[1]); 205 | servaddr.sin_port=htons(7878); 206 | 207 | uint32_t fs1 = Push( 0x080000, file1 ); 208 | uint32_t fs2 = Push( 0x0c0000, file2 ); 209 | 210 | if( !fs1 || !fs2 ) 211 | { 212 | fprintf( stderr, "Error: File size not acceptable.\n" ); 213 | return 0; 214 | } 215 | 216 | const char * dat = ""; 217 | if( argc == 5 ) 218 | { 219 | dat = argv[4]; 220 | } 221 | 222 | ComputeMD5WithKey( md5_f1, file1, dat ); 223 | ComputeMD5WithKey( md5_f2, file2, dat ); 224 | 225 | printf( "%s %s\n", md5_f1, md5_f2 ); 226 | 227 | //FM[from_address]\t[to_address]\t[size]\t[MD5(key+data)]\t[from_address]\t[to_address]\t[size]\t[MD5(key+data)] 228 | 229 | char cmd[1024]; 230 | 231 | sprintf( cmd, "FM%d\t%d\t%d\t%s\t%d\t%d\t%d\t%s\n", 232 | 0x080000, 233 | 0x000000, 234 | fs1, //roundup( fs1 ), 235 | md5_f1, 236 | 0x0C0000, 237 | 0x040000, 238 | fs2, //roundup( fs2 ), 239 | md5_f2 ); 240 | 241 | printf( "Issuing: %s\n", cmd ); 242 | sendto( sockfd, cmd, strlen(cmd), MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr)); 243 | usleep(10000); 244 | sendto( sockfd, cmd, strlen(cmd), MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr)); 245 | 246 | struct pollfd ufds; 247 | ufds.fd = sockfd; 248 | ufds.events = POLLIN; 249 | int rv = poll(&ufds, 1, 100); 250 | if( rv > 0 ) 251 | { 252 | char recvline[10000]; 253 | int n=recvfrom(sockfd,recvline,10000,0,NULL,NULL); 254 | 255 | printf( "Response: %s\n",recvline ); 256 | return 0; 257 | } 258 | else 259 | { 260 | printf( "Timeout. Good? Maybe?\n" ); 261 | return 0; 262 | } 263 | 264 | return 0; 265 | } 266 | 267 | 268 | -------------------------------------------------------------------------------- /web/md5.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 3 | * MD5 Message-Digest Algorithm (RFC 1321). 4 | * 5 | * Homepage: 6 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 7 | * 8 | * Author: 9 | * Alexander Peslyak, better known as Solar Designer 10 | * 11 | * This software was written by Alexander Peslyak in 2001. No copyright is 12 | * claimed, and the software is hereby placed in the public domain. 13 | * In case this attempt to disclaim copyright and place the software in the 14 | * public domain is deemed null and void, then the software is 15 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 16 | * general public under the following terms: 17 | * 18 | * Redistribution and use in source and binary forms, with or without 19 | * modification, are permitted. 20 | * 21 | * There's ABSOLUTELY NO WARRANTY, express or implied. 22 | * 23 | * (This is a heavily cut-down "BSD license".) 24 | * 25 | * This differs from Colin Plumb's older public domain implementation in that 26 | * no exactly 32-bit integer data type is required (any 32-bit or wider 27 | * unsigned integer data type will do), there's no compile-time endianness 28 | * configuration, and the function prototypes match OpenSSL's. No code from 29 | * Colin Plumb's implementation has been reused; this comment merely compares 30 | * the properties of the two independent implementations. 31 | * 32 | * The primary goals of this implementation are portability and ease of use. 33 | * It is meant to be fast, but not as fast as possible. Some known 34 | * optimizations are not included to reduce source code size and avoid 35 | * compile-time configuration. 36 | */ 37 | 38 | #ifndef HAVE_OPENSSL 39 | 40 | #include 41 | 42 | #include "md5.h" 43 | 44 | /* 45 | * The basic MD5 functions. 46 | * 47 | * F and G are optimized compared to their RFC 1321 definitions for 48 | * architectures that lack an AND-NOT instruction, just like in Colin Plumb's 49 | * implementation. 50 | */ 51 | #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) 52 | #define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y)))) 53 | #define H(x, y, z) (((x) ^ (y)) ^ (z)) 54 | #define H2(x, y, z) ((x) ^ ((y) ^ (z))) 55 | #define I(x, y, z) ((y) ^ ((x) | ~(z))) 56 | 57 | /* 58 | * The MD5 transformation for all four rounds. 59 | */ 60 | #define STEP(f, a, b, c, d, x, t, s) \ 61 | (a) += f((b), (c), (d)) + (x) + (t); \ 62 | (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \ 63 | (a) += (b); 64 | 65 | /* 66 | * SET reads 4 input bytes in little-endian byte order and stores them 67 | * in a properly aligned word in host byte order. 68 | * 69 | * The check for little-endian architectures that tolerate unaligned 70 | * memory accesses is just an optimization. Nothing will break if it 71 | * doesn't work. 72 | */ 73 | #if defined(__i386__) || defined(__x86_64__) || defined(__vax__) 74 | #define SET(n) \ 75 | (*(MD5_u32plus *)&ptr[(n) * 4]) 76 | #define GET(n) \ 77 | SET(n) 78 | #else 79 | #define SET(n) \ 80 | (ctx->block[(n)] = \ 81 | (MD5_u32plus)ptr[(n) * 4] | \ 82 | ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \ 83 | ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \ 84 | ((MD5_u32plus)ptr[(n) * 4 + 3] << 24)) 85 | #define GET(n) \ 86 | (ctx->block[(n)]) 87 | #endif 88 | 89 | /* 90 | * This processes one or more 64-byte data blocks, but does NOT update 91 | * the bit counters. There are no alignment requirements. 92 | */ 93 | static const void *body(MD5_CTX *ctx, const void *data, unsigned long size) 94 | { 95 | const unsigned char *ptr; 96 | MD5_u32plus a, b, c, d; 97 | MD5_u32plus saved_a, saved_b, saved_c, saved_d; 98 | 99 | ptr = (const unsigned char *)data; 100 | 101 | a = ctx->a; 102 | b = ctx->b; 103 | c = ctx->c; 104 | d = ctx->d; 105 | 106 | do { 107 | saved_a = a; 108 | saved_b = b; 109 | saved_c = c; 110 | saved_d = d; 111 | 112 | /* Round 1 */ 113 | STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7) 114 | STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12) 115 | STEP(F, c, d, a, b, SET(2), 0x242070db, 17) 116 | STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22) 117 | STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7) 118 | STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12) 119 | STEP(F, c, d, a, b, SET(6), 0xa8304613, 17) 120 | STEP(F, b, c, d, a, SET(7), 0xfd469501, 22) 121 | STEP(F, a, b, c, d, SET(8), 0x698098d8, 7) 122 | STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12) 123 | STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17) 124 | STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22) 125 | STEP(F, a, b, c, d, SET(12), 0x6b901122, 7) 126 | STEP(F, d, a, b, c, SET(13), 0xfd987193, 12) 127 | STEP(F, c, d, a, b, SET(14), 0xa679438e, 17) 128 | STEP(F, b, c, d, a, SET(15), 0x49b40821, 22) 129 | 130 | /* Round 2 */ 131 | STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5) 132 | STEP(G, d, a, b, c, GET(6), 0xc040b340, 9) 133 | STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14) 134 | STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20) 135 | STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5) 136 | STEP(G, d, a, b, c, GET(10), 0x02441453, 9) 137 | STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14) 138 | STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20) 139 | STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5) 140 | STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9) 141 | STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14) 142 | STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20) 143 | STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5) 144 | STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9) 145 | STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14) 146 | STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20) 147 | 148 | /* Round 3 */ 149 | STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4) 150 | STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11) 151 | STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16) 152 | STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23) 153 | STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4) 154 | STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11) 155 | STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16) 156 | STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23) 157 | STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4) 158 | STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11) 159 | STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16) 160 | STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23) 161 | STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4) 162 | STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11) 163 | STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16) 164 | STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23) 165 | 166 | /* Round 4 */ 167 | STEP(I, a, b, c, d, GET(0), 0xf4292244, 6) 168 | STEP(I, d, a, b, c, GET(7), 0x432aff97, 10) 169 | STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15) 170 | STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21) 171 | STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6) 172 | STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10) 173 | STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15) 174 | STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21) 175 | STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6) 176 | STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10) 177 | STEP(I, c, d, a, b, GET(6), 0xa3014314, 15) 178 | STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21) 179 | STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6) 180 | STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10) 181 | STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15) 182 | STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21) 183 | 184 | a += saved_a; 185 | b += saved_b; 186 | c += saved_c; 187 | d += saved_d; 188 | 189 | ptr += 64; 190 | } while (size -= 64); 191 | 192 | ctx->a = a; 193 | ctx->b = b; 194 | ctx->c = c; 195 | ctx->d = d; 196 | 197 | return ptr; 198 | } 199 | 200 | void MD5_Init(MD5_CTX *ctx) 201 | { 202 | ctx->a = 0x67452301; 203 | ctx->b = 0xefcdab89; 204 | ctx->c = 0x98badcfe; 205 | ctx->d = 0x10325476; 206 | 207 | ctx->lo = 0; 208 | ctx->hi = 0; 209 | } 210 | 211 | void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size) 212 | { 213 | MD5_u32plus saved_lo; 214 | unsigned long used, available; 215 | 216 | saved_lo = ctx->lo; 217 | if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo) 218 | ctx->hi++; 219 | ctx->hi += size >> 29; 220 | 221 | used = saved_lo & 0x3f; 222 | 223 | if (used) { 224 | available = 64 - used; 225 | 226 | if (size < available) { 227 | memcpy(&ctx->buffer[used], data, size); 228 | return; 229 | } 230 | 231 | memcpy(&ctx->buffer[used], data, available); 232 | data = (const unsigned char *)data + available; 233 | size -= available; 234 | body(ctx, ctx->buffer, 64); 235 | } 236 | 237 | if (size >= 64) { 238 | data = body(ctx, data, size & ~(unsigned long)0x3f); 239 | size &= 0x3f; 240 | } 241 | 242 | memcpy(ctx->buffer, data, size); 243 | } 244 | 245 | void MD5_Final(unsigned char *result, MD5_CTX *ctx) 246 | { 247 | unsigned long used, available; 248 | 249 | used = ctx->lo & 0x3f; 250 | 251 | ctx->buffer[used++] = 0x80; 252 | 253 | available = 64 - used; 254 | 255 | if (available < 8) { 256 | memset(&ctx->buffer[used], 0, available); 257 | body(ctx, ctx->buffer, 64); 258 | used = 0; 259 | available = 64; 260 | } 261 | 262 | memset(&ctx->buffer[used], 0, available - 8); 263 | 264 | ctx->lo <<= 3; 265 | ctx->buffer[56] = ctx->lo; 266 | ctx->buffer[57] = ctx->lo >> 8; 267 | ctx->buffer[58] = ctx->lo >> 16; 268 | ctx->buffer[59] = ctx->lo >> 24; 269 | ctx->buffer[60] = ctx->hi; 270 | ctx->buffer[61] = ctx->hi >> 8; 271 | ctx->buffer[62] = ctx->hi >> 16; 272 | ctx->buffer[63] = ctx->hi >> 24; 273 | 274 | body(ctx, ctx->buffer, 64); 275 | 276 | result[0] = ctx->a; 277 | result[1] = ctx->a >> 8; 278 | result[2] = ctx->a >> 16; 279 | result[3] = ctx->a >> 24; 280 | result[4] = ctx->b; 281 | result[5] = ctx->b >> 8; 282 | result[6] = ctx->b >> 16; 283 | result[7] = ctx->b >> 24; 284 | result[8] = ctx->c; 285 | result[9] = ctx->c >> 8; 286 | result[10] = ctx->c >> 16; 287 | result[11] = ctx->c >> 24; 288 | result[12] = ctx->d; 289 | result[13] = ctx->d >> 8; 290 | result[14] = ctx->d >> 16; 291 | result[15] = ctx->d >> 24; 292 | 293 | memset(ctx, 0, sizeof(*ctx)); 294 | } 295 | 296 | #endif 297 | -------------------------------------------------------------------------------- /web/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 3 | * MD5 Message-Digest Algorithm (RFC 1321). 4 | * 5 | * Homepage: 6 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 7 | * 8 | * Author: 9 | * Alexander Peslyak, better known as Solar Designer 10 | * 11 | * This software was written by Alexander Peslyak in 2001. No copyright is 12 | * claimed, and the software is hereby placed in the public domain. 13 | * In case this attempt to disclaim copyright and place the software in the 14 | * public domain is deemed null and void, then the software is 15 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 16 | * general public under the following terms: 17 | * 18 | * Redistribution and use in source and binary forms, with or without 19 | * modification, are permitted. 20 | * 21 | * There's ABSOLUTELY NO WARRANTY, express or implied. 22 | * 23 | * See md5.c for more information. 24 | */ 25 | 26 | #ifdef HAVE_OPENSSL 27 | #include 28 | #elif !defined(_MD5_H) 29 | #define _MD5_H 30 | 31 | /* Any 32-bit or wider unsigned integer data type will do */ 32 | typedef unsigned int MD5_u32plus; 33 | 34 | typedef struct { 35 | MD5_u32plus lo, hi; 36 | MD5_u32plus a, b, c, d; 37 | unsigned char buffer[64]; 38 | MD5_u32plus block[16]; 39 | } MD5_CTX; 40 | 41 | extern void MD5_Init(MD5_CTX *ctx); 42 | extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size); 43 | extern void MD5_Final(unsigned char *result, MD5_CTX *ctx); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /web/mfsmaker.c: -------------------------------------------------------------------------------- 1 | 2 | //Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or 3 | // ColorChord License. You Choose. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define SPI_FLASH_SEC_SIZE 4096 12 | #define MFS_STARTFLASHSECTOR 0x100 13 | #define MFS_START (MFS_STARTFLASHSECTOR*SPI_FLASH_SEC_SIZE) 14 | #define MFS_SECTOR 256 15 | #define MFS_FILENAMELEN 32-8 16 | #define ENTRIES 8192 17 | 18 | #define ENDIAN(x) x//htonl 19 | 20 | struct MFSFileEntry 21 | { 22 | char name[MFS_FILENAMELEN]; 23 | uint32_t start; //From beginning of mfs thing. 24 | uint32_t len; 25 | } mfsfat[ENTRIES]; 26 | 27 | unsigned char mfsdata[131072*8]; 28 | 29 | unsigned long fatpointer = 0; 30 | unsigned long datapointer = 0; 31 | 32 | int main( int argc, char ** argv ) 33 | { 34 | int i; 35 | DIR *d; 36 | struct dirent *dir; 37 | 38 | if( argc != 3 ) 39 | { 40 | fprintf( stderr, "Error: [tool] [directory to pack] [output packed .dat file]\n" ); 41 | return -1; 42 | } 43 | 44 | d = opendir( argv[1] ); 45 | 46 | if (!d) 47 | { 48 | fprintf( stderr, "Error: cannot open folder for packing.\n" ); 49 | return -2; 50 | } 51 | 52 | 53 | memcpy( mfsfat[fatpointer].name, "MPFSMPFS", 8 ); 54 | mfsfat[fatpointer].start = 0; 55 | mfsfat[fatpointer].len = 0; 56 | fatpointer++; 57 | 58 | 59 | while ((dir = readdir(d)) != NULL) 60 | { 61 | if( dir->d_type & DT_REG ) 62 | { 63 | char thisfile[1024]; 64 | struct stat buf; 65 | int dlen = strlen( dir->d_name ); 66 | int sprret = snprintf( thisfile, 1023, "%s/%s", argv[1], dir->d_name ); 67 | 68 | if( sprret > 1023 || sprret < 1 ) 69 | { 70 | fprintf( stderr, "Error processing \"%s\" (snprintf)\n", dir->d_name ); 71 | continue; 72 | } 73 | 74 | int statret = stat( thisfile, &buf ); 75 | 76 | if( statret ) 77 | { 78 | fprintf( stderr, "Error processing \"%s\" (stat)\n", dir->d_name ); 79 | continue; 80 | } 81 | 82 | if( dlen >= MFS_FILENAMELEN ) 83 | { 84 | fprintf( stderr, "Warning: Fle \"%s\" too long.\n", dir->d_name ); 85 | continue; 86 | } 87 | if( fatpointer > ENTRIES ) 88 | { 89 | fprintf( stderr, "Warning: Not enough entries to fit \"%s\".\n", dir->d_name ); 90 | continue; 91 | } 92 | 93 | if( buf.st_size + datapointer > sizeof( mfsdata ) ) 94 | { 95 | fprintf( stderr, "Error: no space left.\n" ); 96 | return -1; 97 | } 98 | 99 | memcpy( mfsfat[fatpointer].name, dir->d_name, dlen ); 100 | mfsfat[fatpointer].start = datapointer; 101 | mfsfat[fatpointer].len = ENDIAN( buf.st_size ); 102 | fatpointer++; 103 | 104 | if( buf.st_size ) 105 | { 106 | FILE * f = fopen( thisfile, "rb" ); 107 | if( !f ) 108 | { 109 | fprintf( stderr, "Error: cannot open \"%s\" for reading.\n", dir->d_name ); 110 | return -9; 111 | } 112 | fread( &mfsdata[datapointer], 1, buf.st_size, f ); 113 | fclose( f ); 114 | int rs = buf.st_size; 115 | rs = (rs+1+MFS_SECTOR)&(~(MFS_SECTOR-1)); 116 | datapointer += rs; 117 | printf( "%s: %d (%ld)\n", thisfile, rs, datapointer ); 118 | } 119 | } 120 | } 121 | 122 | closedir(d); 123 | 124 | int rs = (fatpointer+1)*sizeof(struct MFSFileEntry); 125 | rs = (rs+1+MFS_SECTOR)&(~(MFS_SECTOR-1)); 126 | for( i = 0; i < fatpointer; i++ ) 127 | { 128 | mfsfat[i].start = ENDIAN(mfsfat[i].start + rs ); 129 | } 130 | 131 | printf( "%d %ld\n", rs, datapointer ); 132 | 133 | FILE * f = fopen( argv[2], "w" ); 134 | 135 | if( !f || ferror( f ) ) 136 | { 137 | fprintf( stderr, "Error: cannot open \"%s\" for writing.\n", argv[2] ); 138 | } 139 | fwrite( mfsfat, rs, 1, f ); 140 | fwrite( mfsdata, datapointer, 1, f ); 141 | fclose( f ); 142 | 143 | return 0; 144 | } 145 | 146 | 147 | -------------------------------------------------------------------------------- /web/page.mpfs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhartmann/esp8266_reprap/46653d8ec498c8fa382bd2c672f4d8cea946bc49/web/page.mpfs -------------------------------------------------------------------------------- /web/page/index.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | esp8266 ws2812 i2s controller 6 | 7 | 8 | 9 | 10 | 19 | 20 | 21 |

esp8266 ws2812 i2s controller

22 |
23 | 24 | 25 | 26 | 27 | 28 | 37 | 38 | 39 | 40 | 46 | 47 | 48 | 49 | 50 | 51 |

Copyright (C) 2015 <>< Charles Lohr, See LICENSE file for more info.

52 |
...
53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /web/page/jquery-2.1.4.min.js.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lhartmann/esp8266_reprap/46653d8ec498c8fa382bd2c672f4d8cea946bc49/web/page/jquery-2.1.4.min.js.gz -------------------------------------------------------------------------------- /web/page/main.js: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2015 <>< Charles Lohr, see LICENSE file for more info. 2 | // 3 | //This particular file may be licensed under the MIT/x11, New BSD or ColorChord Licenses. 4 | 5 | 6 | is_leds_running = false; 7 | pause_led = false; 8 | 9 | function KickLEDs() 10 | { 11 | $( "#LEDPauseButton" ).css( "background-color", (is_leds_running&&!pause_led)?"green":"red" ); 12 | 13 | if( !is_leds_running && !pause_led ) 14 | LEDDataTicker(); 15 | 16 | } 17 | 18 | window.addEventListener("load", KickLEDs, false); 19 | 20 | function ToggleLEDPause() 21 | { 22 | pause_led = !pause_led; 23 | KickLEDs(); 24 | } 25 | 26 | 27 | function GotLED(req,data) 28 | { 29 | var ls = document.getElementById('LEDCanvasHolder'); 30 | var canvas = document.getElementById('LEDCanvas'); 31 | var ctx = canvas.getContext('2d'); 32 | var h = ls.height; 33 | var w = ls.width; 34 | if( canvas.width != ls.clientWidth-10 ) canvas.width = ls.clientWidth-10; 35 | if( ctx.canvas.width != canvas.clientWidth ) ctx.canvas.width = canvas.clientWidth; 36 | 37 | var secs = data.split( ":" ); 38 | 39 | $( "#LEDPauseButton" ).css( "background-color", "green" ); 40 | 41 | var samps = Number( secs[1] ); 42 | var data = secs[2]; 43 | var lastsamp = parseInt( data.substr(0,4),16 ); 44 | ctx.clearRect( 0, 0, canvas.width, canvas.height ); 45 | 46 | for( var i = 0; i < samps; i++ ) 47 | { 48 | var x2 = i * canvas.clientWidth / samps; 49 | var samp = data.substr(i*6,6); 50 | var y2 = ( 1.-samp / 2047 ) * canvas.clientHeight; 51 | 52 | ctx.fillStyle = "#" + samp.substr( 2, 2 ) + samp.substr( 0, 2 ) + samp.substr( 4, 2 ); 53 | ctx.lineWidth = 0; 54 | ctx.fillRect( x2, 0, canvas.clientWidth / samps+1, canvas.clientHeight ); 55 | } 56 | 57 | var samp = parseInt( data.substr(i*2,2),16 ); 58 | 59 | LEDDataTicker(); 60 | } 61 | 62 | function LEDDataTicker() 63 | { 64 | if( IsTabOpen('LEDs') && !pause_led ) 65 | { 66 | is_leds_running = true; 67 | QueueOperation( "CL", GotLED ); 68 | } 69 | else 70 | { 71 | is_leds_running = 0; 72 | } 73 | $( "#LEDPauseButton" ).css( "background-color", (is_leds_running&&!pause_led)?"green":"red" ); 74 | 75 | } 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /web/pushtodev.c: -------------------------------------------------------------------------------- 1 | //Unless what else is individually marked, all code in this file is 2 | //Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or 3 | // ColorChord License. You Choose. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define sector_SIZE 4096 15 | int sockfd; 16 | char recvline[10000]; 17 | 18 | 19 | int PushMatch( const char * match ) 20 | { 21 | struct timeval tva, tvb; 22 | gettimeofday( &tva, 0 ); 23 | gettimeofday( &tvb, 0 ); 24 | while( tvb.tv_sec - tva.tv_sec < 3 ) //3 second timeout. 25 | { 26 | struct pollfd ufds; 27 | ufds.fd = sockfd; 28 | ufds.events = POLLIN; 29 | int rv = poll(&ufds, 1, 500); 30 | if( rv > 0 ) 31 | { 32 | // tbuf = recvline; 33 | int n=recvfrom(sockfd,recvline,10000,0,NULL,NULL); 34 | // printf( "!!%d ->%s\n", n,recvline ); 35 | // printf( "%s === %s\n", recvline, match ); 36 | if( strncmp( recvline, match, strlen( match ) ) == 0 ) 37 | { 38 | // printf( "Ok\n" ); fflush( stdout ); 39 | return 0; 40 | } 41 | } 42 | gettimeofday( &tvb, 0 ); 43 | } 44 | return 1; 45 | } 46 | 47 | 48 | int main(int argc, char**argv) 49 | { 50 | int n; 51 | struct sockaddr_in servaddr,cliaddr; 52 | char sendline[1000]; 53 | // char recvline[1000]; 54 | 55 | if (argc != 4) 56 | { 57 | printf("usage: pushtodev [IP address] [address offset] [file]\n"); 58 | exit(-1); 59 | } 60 | 61 | int offset = atoi( argv[2] ); 62 | const char * file = argv[3]; 63 | 64 | if( offset <= 0 ) 65 | { 66 | fprintf( stderr, "Error: Cannot write to address 0 or before.\n" ); 67 | exit(-2); 68 | } 69 | 70 | FILE * f = fopen( file, "rb" ); 71 | if( !f || feof( f ) ) 72 | { 73 | fprintf( stderr, "Error: cannot open file.\n" ); 74 | exit(-3); 75 | } 76 | 77 | 78 | 79 | sockfd=socket(AF_INET,SOCK_DGRAM,0); 80 | 81 | bzero(&servaddr,sizeof(servaddr)); 82 | servaddr.sin_family = AF_INET; 83 | servaddr.sin_addr.s_addr=inet_addr(argv[1]); 84 | servaddr.sin_port=htons(7878); 85 | 86 | int devo = 0; 87 | int lastsector_block = -1; 88 | int resend_times = 0; 89 | int r; 90 | while( !feof( f ) ) 91 | { 92 | int tries; 93 | int thissuccess; 94 | char buffer[1024]; 95 | char bufferout[1600]; 96 | int reads = fread( buffer, 1, 1024, f ); 97 | int sendplace = offset + devo; 98 | int sendsize = reads; 99 | 100 | #ifdef SECTOR 101 | int sector = sendplace / sector_SIZE; 102 | if( sector != lastsector_block ) 103 | { 104 | char se[64]; 105 | int sel = sprintf( se, "FE%d\r\n", sector ); 106 | 107 | thissuccess = 0; 108 | for( tries = 0; tries < 10; tries++ ) 109 | { 110 | char match[75]; 111 | printf( "Erase: %d\n", sector ); 112 | sendto( sockfd, se, sel, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr)); 113 | sprintf( match, "FE%d", sector ); 114 | 115 | if( PushMatch(match) == 0 ) { thissuccess = 1; break; } 116 | printf( "Retry.\n" ); 117 | } 118 | if( !thissuccess ) 119 | { 120 | fprintf( stderr, "Error: Timeout in communications.\n" ); 121 | exit( -6 ); 122 | } 123 | 124 | lastsector_block = sector; 125 | } 126 | #else //block 127 | 128 | int block = sendplace / 65536; 129 | if( block != lastsector_block ) 130 | { 131 | char se[64]; 132 | int sel = sprintf( se, "FB%d\r\n", block ); 133 | 134 | thissuccess = 0; 135 | for( tries = 0; tries < 10; tries++ ) 136 | { 137 | char match[75]; 138 | printf( "Erase: %d\n", block ); 139 | sendto( sockfd, se, sel, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr)); 140 | sprintf( match, "FB%d", block ); 141 | 142 | if( PushMatch(match) == 0 ) { thissuccess = 1; break; } 143 | printf( "Retry.\n" ); 144 | } 145 | if( !thissuccess ) 146 | { 147 | fprintf( stderr, "Error: Timeout in communications.\n" ); 148 | exit( -6 ); 149 | } 150 | 151 | lastsector_block = block; 152 | } 153 | #endif 154 | resend_times = 0; 155 | resend: 156 | r = sprintf( bufferout, "FW%d\t%d\t", sendplace, sendsize ); 157 | printf( "bufferout: %d %d %s\n", sendplace, sendsize, bufferout ); 158 | memcpy( bufferout + r, buffer, sendsize ); 159 | 160 | 161 | thissuccess = 0; 162 | for( tries = 0; tries < 10; tries++ ) 163 | { 164 | char match[75]; 165 | sendto( sockfd, bufferout, reads + r, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr)); 166 | 167 | sprintf( match, "FW%d", sendplace ); 168 | 169 | if( PushMatch(match) == 0 ) { thissuccess = 1; break; } 170 | printf( "Retry.\n" ); 171 | } 172 | if( !thissuccess ) 173 | { 174 | fprintf( stderr, "Error: Timeout in communications.\n" ); 175 | exit( -6 ); 176 | } 177 | 178 | /* 179 | printf( "Verifying..." ); 180 | fflush( stdout ); 181 | 182 | int r = sprintf( bufferout, "FR%d:%d", sendplace, sendsize ); 183 | bufferout[r] = 0; 184 | 185 | thissuccess = 0; 186 | for( tries = 0; tries < 10; tries++ ) 187 | { 188 | char match[1600]; 189 | sendto( sockfd, bufferout, r, MSG_NOSIGNAL, (struct sockaddr *)&servaddr,sizeof(servaddr)); 190 | devo += reads; 191 | sprintf( match, "FR%08d", sendplace ); 192 | 193 | if( PushMatch(match) == 0 ) { 194 | 195 | //Check data... 196 | //printf( "RR:%s\n", recvline ); 197 | char * colon1 = strchr( recvline, ':' ); 198 | char * colon2 = (colon1)?strchr( colon1+1, ':' ):0; 199 | //printf( "::%p %p \"%s\"\n", colon1, colon2,recvline ); 200 | if( colon2 ) 201 | { 202 | if( memcmp( colon2+1, buffer, sendsize ) == 0 ) 203 | thissuccess = 1; 204 | } 205 | 206 | if( !thissuccess ) 207 | { 208 | if( resend_times > 2 ) 209 | { 210 | break; 211 | } 212 | resend_times++; 213 | goto resend; 214 | } 215 | break; 216 | } 217 | printf( "Retry.\n" ); 218 | } 219 | if( !thissuccess ) 220 | { 221 | fprintf( stderr, "Error: Fault verifying.\n" ); 222 | exit( -6 ); 223 | } 224 | */ 225 | devo += reads; 226 | 227 | } 228 | 229 | return 0; 230 | } 231 | --------------------------------------------------------------------------------