Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

  1. #ifndef SOFTUART_H_
  2. #define SOFTUART_H_
  3. #include "user_interface.h"
  4. #define SOFTUART_MAX_RX_BUFF 64
  5. #define SOFTUART_GPIO_COUNT 16
  6. typedef struct softuart_pin_t {
  7. uint8_t gpio_id;
  8. uint32_t gpio_mux_name;
  9. uint8_t gpio_func;
  10. } softuart_pin_t;
  11. typedef struct softuart_buffer_t {
  12. char receive_buffer[SOFTUART_MAX_RX_BUFF];
  13. uint8_t receive_buffer_tail;
  14. uint8_t receive_buffer_head;
  15. uint8_t buffer_overflow;
  16. } softuart_buffer_t;
  17. typedef struct {
  18. softuart_pin_t pin_rx;
  19. softuart_pin_t pin_tx;
  20. bool inverse;
  21. //optional rs485 tx enable pin (high -> tx enabled)
  22. uint8_t pin_rs485_tx_enable;
  23. //wether or not this softuart is rs485 and controlls rs485 tx enable pin
  24. uint8_t is_rs485;
  25. volatile softuart_buffer_t buffer;
  26. uint16_t bit_time;
  27. } Softuart;
  28. bool Softuart_Available(Softuart *s);
  29. void Softuart_Intr_Handler(Softuart *s);
  30. void Softuart_SetPinRx(Softuart *s, uint8_t gpio_id);
  31. void Softuart_SetPinTx(Softuart *s, uint8_t gpio_id);
  32. void Softuart_EnableRs485(Softuart *s, uint8_t gpio_id);
  33. void Softuart_Init(Softuart *s, uint32_t baudrate, bool inverse);
  34. void Softuart_Putchar(Softuart *s, char data);
  35. void Softuart_Puts(Softuart *s, const char *c );
  36. uint8_t Softuart_Readline(Softuart *s, char* Buffer, uint8_t MaxLen );
  37. uint8_t Softuart_Read(Softuart *s);
  38. //define mapping from pin to functio mode
  39. typedef struct {
  40. uint32_t gpio_mux_name;
  41. uint8_t gpio_func;
  42. } softuart_reg_t;
  43. #endif /* SOFTUART_H_ */