serial.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef SOFT_SERIAL_H
  2. #define SOFT_SERIAL_H
  3. #include <stdbool.h>
  4. // /////////////////////////////////////////////////////////////////
  5. // Need Soft Serial defines in serial_config.h
  6. // /////////////////////////////////////////////////////////////////
  7. // ex.
  8. // #define SERIAL_PIN_DDR DDRD
  9. // #define SERIAL_PIN_PORT PORTD
  10. // #define SERIAL_PIN_INPUT PIND
  11. // #define SERIAL_PIN_MASK _BV(PD?) ?=0,2
  12. // #define SERIAL_PIN_INTERRUPT INT?_vect ?=0,2
  13. //
  14. // //// USE Simple API (OLD API, compatible with let's split serial.c)
  15. // ex.
  16. // #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
  17. // #define SERIAL_MASTER_BUFFER_LENGTH 1
  18. //
  19. // //// USE flexible API (using multi-type transaction function)
  20. // #define SERIAL_USE_MULTI_TRANSACTION
  21. //
  22. // /////////////////////////////////////////////////////////////////
  23. #ifndef SERIAL_USE_MULTI_TRANSACTION
  24. /* --- USE Simple API (OLD API, compatible with let's split serial.c) */
  25. #if SERIAL_SLAVE_BUFFER_LENGTH > 0
  26. extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
  27. #endif
  28. #if SERIAL_MASTER_BUFFER_LENGTH > 0
  29. extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
  30. #endif
  31. void serial_master_init(void);
  32. void serial_slave_init(void);
  33. int serial_update_buffers(void);
  34. #endif // USE Simple API
  35. // Soft Serial Transaction Descriptor
  36. typedef struct _SSTD_t {
  37. uint8_t *status;
  38. uint8_t initiator2target_buffer_size;
  39. uint8_t *initiator2target_buffer;
  40. uint8_t target2initiator_buffer_size;
  41. uint8_t *target2initiator_buffer;
  42. } SSTD_t;
  43. // initiator is transaction start side
  44. void soft_serial_initiator_init(SSTD_t *sstd_table);
  45. // target is interrupt accept side
  46. void soft_serial_target_init(SSTD_t *sstd_table);
  47. // initiator resullt
  48. #define TRANSACTION_END 0
  49. #define TRANSACTION_NO_RESPONSE 0x1
  50. #define TRANSACTION_DATA_ERROR 0x2
  51. #ifndef SERIAL_USE_MULTI_TRANSACTION
  52. int soft_serial_transaction(void);
  53. #else
  54. int soft_serial_transaction(int sstd_index);
  55. #endif
  56. // target status
  57. // *SSTD_t.status has
  58. // initiator:
  59. // TRANSACTION_END
  60. // or TRANSACTION_NO_RESPONSE
  61. // or TRANSACTION_DATA_ERROR
  62. // target:
  63. // TRANSACTION_DATA_ERROR
  64. // or TRANSACTION_ACCEPTED
  65. #define TRANSACTION_ACCEPTED 0x4
  66. #ifdef SERIAL_USE_MULTI_TRANSACTION
  67. int soft_serial_get_and_clean_status(int sstd_index);
  68. #endif
  69. #endif /* SOFT_SERIAL_H */