serbridge.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef __SER_BRIDGE_H__
  2. #define __SER_BRIDGE_H__
  3. #include <ip_addr.h>
  4. #include <c_types.h>
  5. #include <espconn.h>
  6. #define MAX_CONN 4
  7. #define SER_BRIDGE_TIMEOUT 300 // 300 seconds = 5 minutes
  8. // Send buffer size
  9. #define MAX_TXBUFFER (2*1460)
  10. enum connModes {
  11. cmInit = 0, // initialization mode: nothing received yet
  12. cmPGMInit, // initialization mode for programming
  13. cmTransparent, // transparent mode
  14. cmPGM, // Arduino/AVR/ARM programming mode
  15. cmTelnet, // use telnet escape sequences for programming mode
  16. };
  17. typedef struct serbridgeConnData {
  18. struct espconn *conn;
  19. enum connModes conn_mode; // connection mode
  20. uint8_t telnet_state;
  21. uint16 txbufferlen; // length of data in txbuffer
  22. char *txbuffer; // buffer for the data to send
  23. char *sentbuffer; // buffer sent, awaiting callback to get freed
  24. uint32_t txoverflow_at; // when the transmitter started to overflow
  25. bool readytosend; // true, if txbuffer can be sent by espconn_sent
  26. } serbridgeConnData;
  27. // port1 is transparent&programming, second port is programming only
  28. void ICACHE_FLASH_ATTR serbridgeInit(int port1, int port2);
  29. void ICACHE_FLASH_ATTR serbridgeInitPins(void);
  30. void ICACHE_FLASH_ATTR serbridgeUartCb(char *buf, short len);
  31. void ICACHE_FLASH_ATTR serbridgeReset();
  32. int ICACHE_FLASH_ATTR serbridgeInMCUFlashing();
  33. // callback when receiving UART chars when in programming mode
  34. extern void (*programmingCB)(char *buffer, short length);
  35. #endif /* __SER_BRIDGE_H__ */