qmk

QMK Firmware
git clone git://git.z3bra.org/qmk.git
Log | Files | Refs | Submodules | LICENSE

serial.h (2757B)


      1 #ifndef SOFT_SERIAL_H
      2 #define SOFT_SERIAL_H
      3 
      4 #include <stdbool.h>
      5 
      6 // /////////////////////////////////////////////////////////////////
      7 // Need Soft Serial defines in config.h
      8 // /////////////////////////////////////////////////////////////////
      9 // ex.
     10 //  #define SOFT_SERIAL_PIN ??   // ?? = D0,D1,D2,D3,E6
     11 //  OPTIONAL: #define SELECT_SOFT_SERIAL_SPEED ? // ? = 1,2,3,4,5
     12 //                                               //  1: about 137kbps (default)
     13 //                                               //  2: about 75kbps
     14 //                                               //  3: about 39kbps
     15 //                                               //  4: about 26kbps
     16 //                                               //  5: about 20kbps
     17 //
     18 // //// USE Simple API (OLD API, compatible with let's split serial.c)
     19 // ex.
     20 //  #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
     21 //  #define SERIAL_MASTER_BUFFER_LENGTH 1
     22 //
     23 // //// USE flexible API (using multi-type transaction function)
     24 //  #define SERIAL_USE_MULTI_TRANSACTION
     25 //
     26 // /////////////////////////////////////////////////////////////////
     27 
     28 
     29 #ifndef SERIAL_USE_MULTI_TRANSACTION
     30 /* --- USE Simple API (OLD API, compatible with let's split serial.c) */
     31 #if SERIAL_SLAVE_BUFFER_LENGTH > 0
     32 extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
     33 #endif
     34 #if SERIAL_MASTER_BUFFER_LENGTH > 0
     35 extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
     36 #endif
     37 
     38 void serial_master_init(void);
     39 void serial_slave_init(void);
     40 int serial_update_buffers(void);
     41 
     42 #endif // USE Simple API
     43 
     44 // Soft Serial Transaction Descriptor
     45 typedef struct _SSTD_t  {
     46     uint8_t *status;
     47     uint8_t initiator2target_buffer_size;
     48     uint8_t *initiator2target_buffer;
     49     uint8_t target2initiator_buffer_size;
     50     uint8_t *target2initiator_buffer;
     51 } SSTD_t;
     52 #define TID_LIMIT( table ) (sizeof(table) / sizeof(SSTD_t))
     53 
     54 // initiator is transaction start side
     55 void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size);
     56 // target is interrupt accept side
     57 void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size);
     58 
     59 // initiator resullt
     60 #define TRANSACTION_END 0
     61 #define TRANSACTION_NO_RESPONSE 0x1
     62 #define TRANSACTION_DATA_ERROR  0x2
     63 #define TRANSACTION_TYPE_ERROR  0x4
     64 #ifndef SERIAL_USE_MULTI_TRANSACTION
     65 int  soft_serial_transaction(void);
     66 #else
     67 int  soft_serial_transaction(int sstd_index);
     68 #endif
     69 
     70 // target status
     71 // *SSTD_t.status has
     72 //   initiator:
     73 //       TRANSACTION_END
     74 //    or TRANSACTION_NO_RESPONSE
     75 //    or TRANSACTION_DATA_ERROR
     76 //   target:
     77 //       TRANSACTION_DATA_ERROR
     78 //    or TRANSACTION_ACCEPTED
     79 #define TRANSACTION_ACCEPTED 0x8
     80 #ifdef SERIAL_USE_MULTI_TRANSACTION
     81 int  soft_serial_get_and_clean_status(int sstd_index);
     82 #endif
     83 
     84 #endif /* SOFT_SERIAL_H */