Improved compatibility with let's split of serial.c. Finish helix/serial.c improvement.

- The difference with the original let's split's serial.c
  - It's high-speed about 4 times.
  - Stable bi-directional data transfer. (Helix need master to slave transfer)
  - serial.h was divided 2 files, serial_config.h and sereial.h
  - With multiple types of transaction support, communication contents can be optimized. (NEW flexible API)

- USE OLD Simple APIs (compatible with let's split serial.c)
  - files :
    - serial_config.h -- hardware configuration (need include by config.h)
    - serial.c/serial.h -- serial communication

- USE NEW flexible APIs. (Support multi-type transaction function.)
  serial.c was divided into 2 layers, split_scom.c and serial.c.
  The upper layer split_scomm.c is called from matrix.c.
  The lower layer serial.c accesses the hardware.
  - files
    - split_scomm.c -- communication buffer is defined in here. call by matrix.c.
    - split_scomm.h -- buffer size is defined in here. include by matrix.c, split_util.c
    - serial_config.h -- hardware configuration (need include by config.h)
      To use the NEW API, specify #define SERIAL_USE_MULTI_TRANSACTION
    - serial.c/serial.h -- serial communication lower layer

- NEW APIs for serial.c / serial.h (The lower layer)
  // Soft Serial Transaction Descriptor
  typedef struct _SSTD_t  {
      uint8_t *status;
      uint8_t initiator2target_buffer_size;
      uint8_t *initiator2target_buffer;
      uint8_t target2initiator_buffer_size;
      uint8_t *target2initiator_buffer;
  } SSTD_t;

  // initiator is transaction start side
  void soft_serial_initiator_init(SSTD_t *sstd_table);
  // target is interrupt accept side
  void soft_serial_target_init(SSTD_t *sstd_table);
  int soft_serial_transaction(int sstd_index);
  int soft_serial_get_and_clean_target_status(int sstd_index);

- NEW APIs for split_scomm.c / split_scomm.h (The upper layer)
   move from old serial.c the following buffer and functions
     serial_slave_buffer[]
     serial_master_buffer[]
     void serial_master_init(void)
     void serial_slave_init(void)
     int serial_update_buffers(void)
   define SERIAL_xxxxx_BUFFER_LENGTH move from serial_config.h to split_scomm.h
pull/3608/head
mtei 7 years ago
parent 7299d961b6
commit 8142a3c740

@ -8,6 +8,9 @@
#define SERIAL_PIN_MASK _BV(PD2)
#define SERIAL_PIN_INTERRUPT INT2_vect
#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
#define SERIAL_MASTER_BUFFER_LENGTH 0
//// #error rev1/keymaps/OLED_sample serial config
#endif /* SOFT_SERIAL_CONFIG_H */

@ -35,7 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef USE_MATRIX_I2C
# include "i2c.h"
#else // USE_SERIAL
# include "split_scomm.h"
# include "serial.h"
#endif
#ifndef DEBOUNCE
@ -178,7 +178,7 @@ i2c_error: // the cable is disconnceted, or something else went wrong
int serial_transaction(void) {
int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
if (serial_update_buffers(1)) {
if (serial_update_buffers()) {
return 1;
}

@ -1,5 +1,4 @@
SRC += rev1/matrix.c
SRC += rev1/split_util.c
SRC += rev1/split_scomm.c
BACKLIGHT_ENABLE = no

@ -8,6 +8,9 @@
#define SERIAL_PIN_MASK _BV(PD0)
#define SERIAL_PIN_INTERRUPT INT0_vect
#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
#define SERIAL_MASTER_BUFFER_LENGTH 0
/// #error rev1 serial config
#endif /* SOFT_SERIAL_CONFIG_H */

@ -1,36 +0,0 @@
#ifdef USE_SERIAL
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <split_scomm.h>
#include "serial.h"
uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
uint8_t volatile status0 = 0;
SSTD_t transactions[] = {
{ (uint8_t *)&status0,
sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
}
};
void serial_master_init(void)
{
soft_serial_initiator_init(transactions);
}
void serial_slave_init(void)
{
soft_serial_target_init(transactions);
}
// 0 => no error
// 1 => slave did not respond
// 2 => checksum error
int serial_update_buffers(int master_update)
{
return soft_serial_transaction();
}
#endif /* USE_SERIAL */

@ -1,15 +0,0 @@
#ifndef SPLIT_COMM_H
#define SPLIT_COMM_H
// Buffers for master - slave communication
#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
#define SERIAL_MASTER_BUFFER_LENGTH 1
extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
void serial_master_init(void);
void serial_slave_init(void);
int serial_update_buffers(int master_changed);
#endif /* SPLIT_COMM_H */

@ -12,7 +12,7 @@
#ifdef USE_MATRIX_I2C
# include "i2c.h"
#else
# include "split_scomm.h"
# include "serial.h"
#endif
volatile bool isLeftHand = true;

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define CONFIG_USER_H
// if you need more program area, try uncomment follow line
//#undef SERIAL_USE_MULTI_TRANSACTION
//#include "serial_config_simpleapi.h"
// place overrides here

@ -2,7 +2,7 @@
#define CONFIG_USER_H
// if you need more program area, try uncomment follow line
//#undef SERIAL_USE_MULTI_TRANSACTION
//#include "serial_config_simpleapi.h"
#undef TAPPING_FORCE_HOLD
#undef TAPPING_TERM

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define CONFIG_USER_H
// if you need more program area, try uncomment follow line
//#undef SERIAL_USE_MULTI_TRANSACTION
//#include "serial_config_simpleapi.h"
#undef TAPPING_TERM
#define TAPPING_TERM 140

@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// place overrides here
// if you need more program area, try uncomment follow line
//#undef SERIAL_USE_MULTI_TRANSACTION
//#include "serial_config_simpleapi.h"
#ifdef MOUSEKEY_ENABLE
#undef MOUSEKEY_INTERVAL

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define CONFIG_USER_H
// if you need more program area, try uncomment follow line
//#undef SERIAL_USE_MULTI_TRANSACTION
//#include "serial_config_simpleapi.h"
#undef TAPPING_TERM
#define TAPPING_TERM 200

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define CONFIG_USER_H
// if you need more program area, try uncomment follow line
#undef SERIAL_USE_MULTI_TRANSACTION
#include "serial_config_simpleapi.h"
// place overrides here

@ -183,7 +183,11 @@ i2c_error: // the cable is disconnceted, or something else went wrong
int serial_transaction(int master_changed) {
int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
#ifdef SERIAL_USE_MULTI_TRANSACTION
int ret=serial_update_buffers(master_changed);
#else
int ret=serial_update_buffers();
#endif
if (ret ) {
if(ret==2) RXLED1;
return 1;

@ -0,0 +1,8 @@
#ifndef SERIAL_CONFIG_SIMPLEAPI_H
#define SERIAL_CONFIG_SIMPLEAPI_H
#undef SERIAL_USE_MULTI_TRANSACTION
#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
#define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2
#endif // SERIAL_CONFIG_SIMPLEAPI_H

@ -1,4 +1,7 @@
#ifdef USE_SERIAL
#ifdef SERIAL_USE_MULTI_TRANSACTION
/* --- USE flexible API (using multi-type transaction function) --- */
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
@ -12,19 +15,8 @@ uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
uint8_t volatile status_com = 0;
uint8_t volatile status1 = 0;
#ifdef SERIAL_USE_MULTI_TRANSACTION
uint8_t slave_buffer_change_count = 0;
uint8_t s_change_old = 0xff;
#endif
#ifndef SERIAL_USE_MULTI_TRANSACTION
SSTD_t transactions[] = {
{ (uint8_t *)&status_com,
sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
}
};
#else
SSTD_t transactions[] = {
#define GET_SLAVE_STATUS 0
@ -46,7 +38,6 @@ SSTD_t transactions[] = {
sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
}
};
#endif
void serial_master_init(void)
{
@ -63,7 +54,6 @@ void serial_slave_init(void)
// 2 => checksum error
int serial_update_buffers(int master_update)
{
#ifdef SERIAL_USE_MULTI_TRANSACTION
int status;
static int need_retry = 0;
if( s_change_old != slave_buffer_change_count ) {
@ -77,10 +67,7 @@ int serial_update_buffers(int master_update)
status = soft_serial_transaction(PUT_MASTER_GET_SLAVE_STATUS);
need_retry = ( status == TRANSACTION_END ) ? 0 : 1;
return status;
#else
int status;
status = soft_serial_transaction();
return status;
#endif
}
#endif // SERIAL_USE_MULTI_TRANSACTION
#endif /* USE_SERIAL */

@ -1,18 +1,24 @@
#ifndef SPLIT_COMM_H
#define SPLIT_COMM_H
#ifndef SERIAL_USE_MULTI_TRANSACTION
/* --- USE Simple API (OLD API, compatible with let's split serial.c) --- */
#include "serial.h"
#else
/* --- USE flexible API (using multi-type transaction function) --- */
// Buffers for master - slave communication
#define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
#define SERIAL_MASTER_BUFFER_LENGTH MATRIX_ROWS/2
extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
#ifdef SERIAL_USE_MULTI_TRANSACTION
extern uint8_t slave_buffer_change_count;
#endif
void serial_master_init(void);
void serial_slave_init(void);
int serial_update_buffers(int master_changed);
#endif
#endif /* SPLIT_COMM_H */

@ -16,6 +16,45 @@
#ifdef USE_SERIAL
#ifndef SERIAL_USE_MULTI_TRANSACTION
/* --- USE Simple API (OLD API, compatible with let's split serial.c) */
#if SERIAL_SLAVE_BUFFER_LENGTH > 0
uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
#endif
#if SERIAL_MASTER_BUFFER_LENGTH > 0
uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
#endif
uint8_t volatile status0 = 0;
SSTD_t transactions[] = {
{ (uint8_t *)&status0,
#if SERIAL_MASTER_BUFFER_LENGTH > 0
sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
#else
0, (uint8_t *)NULL,
#endif
#if SERIAL_SLAVE_BUFFER_LENGTH > 0
sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
#else
0, (uint8_t *)NULL,
#endif
}
};
void serial_master_init(void)
{ soft_serial_initiator_init(transactions); }
void serial_slave_init(void)
{ soft_serial_target_init(transactions); }
// 0 => no error
// 1 => slave did not respond
// 2 => checksum error
int serial_update_buffers()
{ return soft_serial_transaction(); }
#endif // Simple API (OLD API, compatible with let's split serial.c)
#define ALWAYS_INLINE __attribute__((always_inline))
#define NO_INLINE __attribute__((noinline))
#define _delay_sub_us(x) __builtin_avr_delay_cycles(x)

@ -3,9 +3,9 @@
#include <stdbool.h>
// ////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////
// Need Soft Serial defines in serial_config.h
// ////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////
// ex.
// #define SERIAL_PIN_DDR DDRD
// #define SERIAL_PIN_PORT PORTD
@ -13,8 +13,31 @@
// #define SERIAL_PIN_MASK _BV(PD?) ?=0,2
// #define SERIAL_PIN_INTERRUPT INT?_vect ?=0,2
//
// When using multi-type transaction function, define the following macro.
// #define SERIAL_USE_MULTI_TRANSACTION
// //// USE Simple API (OLD API, compatible with let's split serial.c)
// ex.
// #define SERIAL_SLAVE_BUFFER_LENGTH MATRIX_ROWS/2
// #define SERIAL_MASTER_BUFFER_LENGTH 1
//
// //// USE flexible API (using multi-type transaction function)
// #define SERIAL_USE_MULTI_TRANSACTION
//
// /////////////////////////////////////////////////////////////////
#ifndef SERIAL_USE_MULTI_TRANSACTION
/* --- USE Simple API (OLD API, compatible with let's split serial.c) */
#if SERIAL_SLAVE_BUFFER_LENGTH > 0
extern volatile uint8_t serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH];
#endif
#if SERIAL_MASTER_BUFFER_LENGTH > 0
extern volatile uint8_t serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH];
#endif
void serial_master_init(void);
void serial_slave_init(void);
int serial_update_buffers(void);
#endif // USE Simple API
// Soft Serial Transaction Descriptor
typedef struct _SSTD_t {

Loading…
Cancel
Save