SingingCat 0
application
esp8266_usb_flash.c
1#include "main-header.h"
2#include "loader-api.h"
3#include "addressing.h"
4#include "espressif/esp8266_flash.h"
5#include "proto-esp-usart.h"
6#include "platform-header.h"
7#include "wireless_state_machine.h"
8#include "usb.h"
9// #include "bare-metal.h"
10#include "led.h"
11extern struct ringbuffer esp_ringbuffer;
12
13/********************************************************************************
14* flash wifi via usb (across console) using esptool
15********************************************************************************/
16
17// we add bytes received from usb into the serial port buffer
18void esp8266_usb_byte_received(byte b) {
19 write_serial_char(USART_ESP8266, b);
20 reset_delay_counter(DELAY_ESP2SERIAL);
21}
22
23
24void esp8266_wififlash_usb_bridge() {
25 mculib_usb_set_received_callback(MAIN_MCULIBHANDLE, esp8266_usb_byte_received);
26 print_to_usb(0);
27 printf("Bridging esp2866 & usb...\r\n");
28 int res = espflash_sync();
29
30 if (res) {
31 printf("FAIL: failed to sync to esp8266. Is it connected and powered up?\r\n");
32 print_to_usb(1);
33 return;
34 }
35 int i;
36
37 led_indicate(LED_WIFI_BRIDGE);
38 printf("Entering passthrough mode\r\n");
39 printf("[BRIDGE ACTIVE]\r\n"); // easy parse ;)
40 // esp8266_usart_mode = ESP8266_USART_PASSTHROUGH;
41 reset_delay_counter(DELAY_ESP2SERIAL);
42 reset_delay_counter(DELAY_DEFAULT);
43 avoid_watchdog();
44 int contbridge = 0;
45
46 for (;;) {
47 avoid_watchdog();
48 // deal with chars from esp8266 while bridged
49 if ((i = ringbuffer_get_byte(&esp_ringbuffer)) < 256) {
50 mculib_usb_send(MAIN_MCULIBHANDLE, 1, (uint8_t *)&i);
51 }
52 if ((contbridge == 0) && (get_delay_counter(DELAY_ESP2SERIAL) > 500)) {
53 printf("Leaving passthrough mode.\r\n");
54 // esp8266_usart_mode = ESP8266_USART_PACKET_ONLY;
55 printf("[BRIDGE MODE FINISHED]\r\n"); // easy parse ;)
56 break;
57 }
58 }
59 usb_restore_irq();
60 print_to_usb(1);
61 led_indicate(LED_WIFI_BRIDGE2);
63}
void esp8266_reset()
reset state machine and esp8266
Definition: esp8266.c:387