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.

356 lines
8.3 KiB

Keyboard: Helix serial improvements (#3608) * add change_reciver2sender()/change_sender2reciver() This is a change to improve readability. * txled, rxled off in matrix_init() * add serial_send_packet() / serial_recive_packet() This is a change to reduce object size. * add serial_low() at ISR() top * add __attribute__((always_inline)) to some functions * modify serial_send_packet()/serial_recive_packet() A little, object size reduction. A little, speedup. * add debug code to helix/serial.c * Adjust sampling timing of serial signal being received * add split_scomm.c/split_scomm.h and change serial.c/serial.h 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. * add split_scomm.c/split_scomm.h into helix/rev1 * reduce object size helix/rev2/matrix.c * remove checksum check, add parity check * force occur parity error for test * parity test ok. remove test code * change some comment & add skip code when buffer_size == 0 * serial.c: multiple types of transaction support Add 4 bits transaction-type field at packet top. Select Transaction Descriptor Table entry by transaction-type. * helix serial master-slave transaction optimize Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized. * add debug code for retry * add comment into each config.h * fix ISR status drop * add a debug macro 'debug_retry_chg()' * reduce led_test size * remove debug code from helix/serial.c and etc. * helix:five_rows change TAPPING_TERM value 140 * 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
5 years ago
Keyboard: Helix serial improvements (#3608) * add change_reciver2sender()/change_sender2reciver() This is a change to improve readability. * txled, rxled off in matrix_init() * add serial_send_packet() / serial_recive_packet() This is a change to reduce object size. * add serial_low() at ISR() top * add __attribute__((always_inline)) to some functions * modify serial_send_packet()/serial_recive_packet() A little, object size reduction. A little, speedup. * add debug code to helix/serial.c * Adjust sampling timing of serial signal being received * add split_scomm.c/split_scomm.h and change serial.c/serial.h 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. * add split_scomm.c/split_scomm.h into helix/rev1 * reduce object size helix/rev2/matrix.c * remove checksum check, add parity check * force occur parity error for test * parity test ok. remove test code * change some comment & add skip code when buffer_size == 0 * serial.c: multiple types of transaction support Add 4 bits transaction-type field at packet top. Select Transaction Descriptor Table entry by transaction-type. * helix serial master-slave transaction optimize Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized. * add debug code for retry * add comment into each config.h * fix ISR status drop * add a debug macro 'debug_retry_chg()' * reduce led_test size * remove debug code from helix/serial.c and etc. * helix:five_rows change TAPPING_TERM value 140 * 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
5 years ago
Keyboard: Helix serial improvements (#3608) * add change_reciver2sender()/change_sender2reciver() This is a change to improve readability. * txled, rxled off in matrix_init() * add serial_send_packet() / serial_recive_packet() This is a change to reduce object size. * add serial_low() at ISR() top * add __attribute__((always_inline)) to some functions * modify serial_send_packet()/serial_recive_packet() A little, object size reduction. A little, speedup. * add debug code to helix/serial.c * Adjust sampling timing of serial signal being received * add split_scomm.c/split_scomm.h and change serial.c/serial.h 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. * add split_scomm.c/split_scomm.h into helix/rev1 * reduce object size helix/rev2/matrix.c * remove checksum check, add parity check * force occur parity error for test * parity test ok. remove test code * change some comment & add skip code when buffer_size == 0 * serial.c: multiple types of transaction support Add 4 bits transaction-type field at packet top. Select Transaction Descriptor Table entry by transaction-type. * helix serial master-slave transaction optimize Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized. * add debug code for retry * add comment into each config.h * fix ISR status drop * add a debug macro 'debug_retry_chg()' * reduce led_test size * remove debug code from helix/serial.c and etc. * helix:five_rows change TAPPING_TERM value 140 * 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
5 years ago
Keyboard: Helix serial improvements (#3608) * add change_reciver2sender()/change_sender2reciver() This is a change to improve readability. * txled, rxled off in matrix_init() * add serial_send_packet() / serial_recive_packet() This is a change to reduce object size. * add serial_low() at ISR() top * add __attribute__((always_inline)) to some functions * modify serial_send_packet()/serial_recive_packet() A little, object size reduction. A little, speedup. * add debug code to helix/serial.c * Adjust sampling timing of serial signal being received * add split_scomm.c/split_scomm.h and change serial.c/serial.h 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. * add split_scomm.c/split_scomm.h into helix/rev1 * reduce object size helix/rev2/matrix.c * remove checksum check, add parity check * force occur parity error for test * parity test ok. remove test code * change some comment & add skip code when buffer_size == 0 * serial.c: multiple types of transaction support Add 4 bits transaction-type field at packet top. Select Transaction Descriptor Table entry by transaction-type. * helix serial master-slave transaction optimize Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized. * add debug code for retry * add comment into each config.h * fix ISR status drop * add a debug macro 'debug_retry_chg()' * reduce led_test size * remove debug code from helix/serial.c and etc. * helix:five_rows change TAPPING_TERM value 140 * 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
5 years ago
Keyboard: Helix serial improvements (#3608) * add change_reciver2sender()/change_sender2reciver() This is a change to improve readability. * txled, rxled off in matrix_init() * add serial_send_packet() / serial_recive_packet() This is a change to reduce object size. * add serial_low() at ISR() top * add __attribute__((always_inline)) to some functions * modify serial_send_packet()/serial_recive_packet() A little, object size reduction. A little, speedup. * add debug code to helix/serial.c * Adjust sampling timing of serial signal being received * add split_scomm.c/split_scomm.h and change serial.c/serial.h 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. * add split_scomm.c/split_scomm.h into helix/rev1 * reduce object size helix/rev2/matrix.c * remove checksum check, add parity check * force occur parity error for test * parity test ok. remove test code * change some comment & add skip code when buffer_size == 0 * serial.c: multiple types of transaction support Add 4 bits transaction-type field at packet top. Select Transaction Descriptor Table entry by transaction-type. * helix serial master-slave transaction optimize Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized. * add debug code for retry * add comment into each config.h * fix ISR status drop * add a debug macro 'debug_retry_chg()' * reduce led_test size * remove debug code from helix/serial.c and etc. * helix:five_rows change TAPPING_TERM value 140 * 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
5 years ago
Keyboard: Helix serial improvements (#3608) * add change_reciver2sender()/change_sender2reciver() This is a change to improve readability. * txled, rxled off in matrix_init() * add serial_send_packet() / serial_recive_packet() This is a change to reduce object size. * add serial_low() at ISR() top * add __attribute__((always_inline)) to some functions * modify serial_send_packet()/serial_recive_packet() A little, object size reduction. A little, speedup. * add debug code to helix/serial.c * Adjust sampling timing of serial signal being received * add split_scomm.c/split_scomm.h and change serial.c/serial.h 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. * add split_scomm.c/split_scomm.h into helix/rev1 * reduce object size helix/rev2/matrix.c * remove checksum check, add parity check * force occur parity error for test * parity test ok. remove test code * change some comment & add skip code when buffer_size == 0 * serial.c: multiple types of transaction support Add 4 bits transaction-type field at packet top. Select Transaction Descriptor Table entry by transaction-type. * helix serial master-slave transaction optimize Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized. * add debug code for retry * add comment into each config.h * fix ISR status drop * add a debug macro 'debug_retry_chg()' * reduce led_test size * remove debug code from helix/serial.c and etc. * helix:five_rows change TAPPING_TERM value 140 * 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
5 years ago
[Keyboard] Helix add split common option (#7718) * is_master, has_usb() move to rev2.[hc] * Do recent helix/rev2 changes to helix/pico as well. helix/pico/matrix.c: remove 'is_master' helix/pico/pico.c: add 'is_master' helix/pico/pico.h: add 'has_usb()' macro helix/pico/split_util.c: remove 'setup_handedness()' 'has_usb()', add 'is_helix_master()' etc * add HELIX=scan option into {rev2/pico}/local_features.mk Made DEBUG_MATRIX_SCAN_RATE easy to use. * Changed rules.mk to link "helix/local_drivers/ssd1306.c" only when OLED_ENABLE = yes. * Added option to use split_common for helix/rev2, helix/pico keyboard. how to build: ### build helix/pico (HelixPico) with helix current codes $ make helix/pico:KEY_MAP $ make helix/pico/back:KEY_MAP ### build helix/rev2 (Helix or Helix beta) with helix current codes $ make helix:KEY_MAP $ make helix/rev2/back:KEY_MAP $ make helix/rev2/under:KEY_MAP $ make helix/rev2/oled:KEY_MAP $ make helix/rev2/oled/back:KEY_MAP $ make helix/rev2/oled/under:KEY_MAP ### build helix/pico (HelixPico) with split_common codes $ make helix/pico/sc:KEY_MAP $ make helix/pico/sc/back:KEY_MAP $ make helix/pico/sc/under:KEY_MAP ### build helix/rev2 (Helix) with split_common codes $ make helix/rev2/sc:KEY_MAP $ make helix/rev2/sc/back:KEY_MAP $ make helix/rev2/sc/under:KEY_MAP $ make helix/rev2/sc/oled:KEY_MAP $ make helix/rev2/sc/oledback:KEY_MAP $ make helix/rev2/sc/oledunder:KEY_MAP * add matrix_slave_scan_user() to helix/rev2/rev2.c, helix/pico/pico.h * Changed 'helix:xulkal' to always use split_common and removed ad hoc code. Added the following line to 'helix/rev2/keymaps/xulkal/rules.mk': SPLIT_KEYBOARD = yes Removed the following ad hoc code from 'users/xulkal/custom_oled.c': #if KEYBOARD_helix_rev2 extern uint8_t is_master; bool is_keyboard_master(void) { return is_master; } #endif * add '#define DIODE_DIRECTION COL2ROW' into helix/{rev2|pico}/config.h This commit does not change the build result. * update helix readme * keyboards/helix/readme.md * keyboards/helix/pico/keymaps/default/readme.md * keyboards/helix/rev2/keymaps/default/readme.md Co-authored-by: mtei <2170248+mtei@users.noreply.github.com>
4 years ago
Keyboard: Helix serial improvements (#3608) * add change_reciver2sender()/change_sender2reciver() This is a change to improve readability. * txled, rxled off in matrix_init() * add serial_send_packet() / serial_recive_packet() This is a change to reduce object size. * add serial_low() at ISR() top * add __attribute__((always_inline)) to some functions * modify serial_send_packet()/serial_recive_packet() A little, object size reduction. A little, speedup. * add debug code to helix/serial.c * Adjust sampling timing of serial signal being received * add split_scomm.c/split_scomm.h and change serial.c/serial.h 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. * add split_scomm.c/split_scomm.h into helix/rev1 * reduce object size helix/rev2/matrix.c * remove checksum check, add parity check * force occur parity error for test * parity test ok. remove test code * change some comment & add skip code when buffer_size == 0 * serial.c: multiple types of transaction support Add 4 bits transaction-type field at packet top. Select Transaction Descriptor Table entry by transaction-type. * helix serial master-slave transaction optimize Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized. * add debug code for retry * add comment into each config.h * fix ISR status drop * add a debug macro 'debug_retry_chg()' * reduce led_test size * remove debug code from helix/serial.c and etc. * helix:five_rows change TAPPING_TERM value 140 * 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
5 years ago
Keyboard: Helix serial improvements (#3608) * add change_reciver2sender()/change_sender2reciver() This is a change to improve readability. * txled, rxled off in matrix_init() * add serial_send_packet() / serial_recive_packet() This is a change to reduce object size. * add serial_low() at ISR() top * add __attribute__((always_inline)) to some functions * modify serial_send_packet()/serial_recive_packet() A little, object size reduction. A little, speedup. * add debug code to helix/serial.c * Adjust sampling timing of serial signal being received * add split_scomm.c/split_scomm.h and change serial.c/serial.h 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. * add split_scomm.c/split_scomm.h into helix/rev1 * reduce object size helix/rev2/matrix.c * remove checksum check, add parity check * force occur parity error for test * parity test ok. remove test code * change some comment & add skip code when buffer_size == 0 * serial.c: multiple types of transaction support Add 4 bits transaction-type field at packet top. Select Transaction Descriptor Table entry by transaction-type. * helix serial master-slave transaction optimize Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized. * add debug code for retry * add comment into each config.h * fix ISR status drop * add a debug macro 'debug_retry_chg()' * reduce led_test size * remove debug code from helix/serial.c and etc. * helix:five_rows change TAPPING_TERM value 140 * 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
5 years ago
Keyboard: Helix serial improvements (#3608) * add change_reciver2sender()/change_sender2reciver() This is a change to improve readability. * txled, rxled off in matrix_init() * add serial_send_packet() / serial_recive_packet() This is a change to reduce object size. * add serial_low() at ISR() top * add __attribute__((always_inline)) to some functions * modify serial_send_packet()/serial_recive_packet() A little, object size reduction. A little, speedup. * add debug code to helix/serial.c * Adjust sampling timing of serial signal being received * add split_scomm.c/split_scomm.h and change serial.c/serial.h 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. * add split_scomm.c/split_scomm.h into helix/rev1 * reduce object size helix/rev2/matrix.c * remove checksum check, add parity check * force occur parity error for test * parity test ok. remove test code * change some comment & add skip code when buffer_size == 0 * serial.c: multiple types of transaction support Add 4 bits transaction-type field at packet top. Select Transaction Descriptor Table entry by transaction-type. * helix serial master-slave transaction optimize Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized. * add debug code for retry * add comment into each config.h * fix ISR status drop * add a debug macro 'debug_retry_chg()' * reduce led_test size * remove debug code from helix/serial.c and etc. * helix:five_rows change TAPPING_TERM value 140 * 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
5 years ago
Keyboard: Helix serial improvements (#3608) * add change_reciver2sender()/change_sender2reciver() This is a change to improve readability. * txled, rxled off in matrix_init() * add serial_send_packet() / serial_recive_packet() This is a change to reduce object size. * add serial_low() at ISR() top * add __attribute__((always_inline)) to some functions * modify serial_send_packet()/serial_recive_packet() A little, object size reduction. A little, speedup. * add debug code to helix/serial.c * Adjust sampling timing of serial signal being received * add split_scomm.c/split_scomm.h and change serial.c/serial.h 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. * add split_scomm.c/split_scomm.h into helix/rev1 * reduce object size helix/rev2/matrix.c * remove checksum check, add parity check * force occur parity error for test * parity test ok. remove test code * change some comment & add skip code when buffer_size == 0 * serial.c: multiple types of transaction support Add 4 bits transaction-type field at packet top. Select Transaction Descriptor Table entry by transaction-type. * helix serial master-slave transaction optimize Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized. * add debug code for retry * add comment into each config.h * fix ISR status drop * add a debug macro 'debug_retry_chg()' * reduce led_test size * remove debug code from helix/serial.c and etc. * helix:five_rows change TAPPING_TERM value 140 * 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
5 years ago
Keyboard: Helix serial improvements (#3608) * add change_reciver2sender()/change_sender2reciver() This is a change to improve readability. * txled, rxled off in matrix_init() * add serial_send_packet() / serial_recive_packet() This is a change to reduce object size. * add serial_low() at ISR() top * add __attribute__((always_inline)) to some functions * modify serial_send_packet()/serial_recive_packet() A little, object size reduction. A little, speedup. * add debug code to helix/serial.c * Adjust sampling timing of serial signal being received * add split_scomm.c/split_scomm.h and change serial.c/serial.h 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. * add split_scomm.c/split_scomm.h into helix/rev1 * reduce object size helix/rev2/matrix.c * remove checksum check, add parity check * force occur parity error for test * parity test ok. remove test code * change some comment & add skip code when buffer_size == 0 * serial.c: multiple types of transaction support Add 4 bits transaction-type field at packet top. Select Transaction Descriptor Table entry by transaction-type. * helix serial master-slave transaction optimize Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized. * add debug code for retry * add comment into each config.h * fix ISR status drop * add a debug macro 'debug_retry_chg()' * reduce led_test size * remove debug code from helix/serial.c and etc. * helix:five_rows change TAPPING_TERM value 140 * 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
5 years ago
Keyboard: Helix serial improvements (#3608) * add change_reciver2sender()/change_sender2reciver() This is a change to improve readability. * txled, rxled off in matrix_init() * add serial_send_packet() / serial_recive_packet() This is a change to reduce object size. * add serial_low() at ISR() top * add __attribute__((always_inline)) to some functions * modify serial_send_packet()/serial_recive_packet() A little, object size reduction. A little, speedup. * add debug code to helix/serial.c * Adjust sampling timing of serial signal being received * add split_scomm.c/split_scomm.h and change serial.c/serial.h 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. * add split_scomm.c/split_scomm.h into helix/rev1 * reduce object size helix/rev2/matrix.c * remove checksum check, add parity check * force occur parity error for test * parity test ok. remove test code * change some comment & add skip code when buffer_size == 0 * serial.c: multiple types of transaction support Add 4 bits transaction-type field at packet top. Select Transaction Descriptor Table entry by transaction-type. * helix serial master-slave transaction optimize Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized. * add debug code for retry * add comment into each config.h * fix ISR status drop * add a debug macro 'debug_retry_chg()' * reduce led_test size * remove debug code from helix/serial.c and etc. * helix:five_rows change TAPPING_TERM value 140 * 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
5 years ago
Keyboard: Helix serial improvements (#3608) * add change_reciver2sender()/change_sender2reciver() This is a change to improve readability. * txled, rxled off in matrix_init() * add serial_send_packet() / serial_recive_packet() This is a change to reduce object size. * add serial_low() at ISR() top * add __attribute__((always_inline)) to some functions * modify serial_send_packet()/serial_recive_packet() A little, object size reduction. A little, speedup. * add debug code to helix/serial.c * Adjust sampling timing of serial signal being received * add split_scomm.c/split_scomm.h and change serial.c/serial.h 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. * add split_scomm.c/split_scomm.h into helix/rev1 * reduce object size helix/rev2/matrix.c * remove checksum check, add parity check * force occur parity error for test * parity test ok. remove test code * change some comment & add skip code when buffer_size == 0 * serial.c: multiple types of transaction support Add 4 bits transaction-type field at packet top. Select Transaction Descriptor Table entry by transaction-type. * helix serial master-slave transaction optimize Using multi-type transaction feature of serial.c, communication contents between master slaves were optimized. * add debug code for retry * add comment into each config.h * fix ISR status drop * add a debug macro 'debug_retry_chg()' * reduce led_test size * remove debug code from helix/serial.c and etc. * helix:five_rows change TAPPING_TERM value 140 * 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
5 years ago
  1. /*
  2. Copyright 2012 Jun Wako <wakojun@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /*
  15. * scan matrix
  16. */
  17. #include <stdint.h>
  18. #include <stdbool.h>
  19. #include <string.h>
  20. #include <avr/io.h>
  21. #include <avr/wdt.h>
  22. #include <avr/interrupt.h>
  23. #include <util/delay.h>
  24. #include "print.h"
  25. #include "debug.h"
  26. #include "util.h"
  27. #include "matrix.h"
  28. #include "split_util.h"
  29. #include "quantum.h"
  30. #ifdef USE_MATRIX_I2C
  31. # include "i2c.h"
  32. #else // USE_SERIAL
  33. # include "split_scomm.h"
  34. #endif
  35. #ifndef DEBOUNCE
  36. # define DEBOUNCE 5
  37. #endif
  38. #define ERROR_DISCONNECT_COUNT 5
  39. static uint8_t debouncing = DEBOUNCE;
  40. static const int ROWS_PER_HAND = MATRIX_ROWS/2;
  41. static uint8_t error_count = 0;
  42. static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
  43. static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
  44. /* matrix state(1:on, 0:off) */
  45. static matrix_row_t matrix[MATRIX_ROWS];
  46. static matrix_row_t matrix_debouncing[MATRIX_ROWS];
  47. static matrix_row_t read_cols(void);
  48. static void init_cols(void);
  49. static void unselect_rows(void);
  50. static void select_row(uint8_t row);
  51. static uint8_t matrix_master_scan(void);
  52. __attribute__ ((weak))
  53. void matrix_init_kb(void) {
  54. matrix_init_user();
  55. }
  56. __attribute__ ((weak))
  57. void matrix_scan_kb(void) {
  58. matrix_scan_user();
  59. }
  60. __attribute__ ((weak))
  61. void matrix_init_user(void) {
  62. }
  63. __attribute__ ((weak))
  64. void matrix_scan_user(void) {
  65. }
  66. inline
  67. uint8_t matrix_rows(void)
  68. {
  69. return MATRIX_ROWS;
  70. }
  71. inline
  72. uint8_t matrix_cols(void)
  73. {
  74. return MATRIX_COLS;
  75. }
  76. void matrix_init(void)
  77. {
  78. split_keyboard_setup();
  79. // initialize row and col
  80. unselect_rows();
  81. init_cols();
  82. setPinOutput(B0);
  83. setPinOutput(D5);
  84. writePinHigh(B0);
  85. writePinHigh(D5);
  86. // initialize matrix state: all keys off
  87. for (uint8_t i=0; i < MATRIX_ROWS; i++) {
  88. matrix[i] = 0;
  89. matrix_debouncing[i] = 0;
  90. }
  91. matrix_init_quantum();
  92. }
  93. uint8_t _matrix_scan(void)
  94. {
  95. // Right hand is stored after the left in the matirx so, we need to offset it
  96. int offset = isLeftHand ? 0 : (ROWS_PER_HAND);
  97. for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
  98. select_row(i);
  99. _delay_us(30); // without this wait read unstable value.
  100. matrix_row_t cols = read_cols();
  101. if (matrix_debouncing[i+offset] != cols) {
  102. matrix_debouncing[i+offset] = cols;
  103. debouncing = DEBOUNCE;
  104. }
  105. unselect_rows();
  106. }
  107. if (debouncing) {
  108. if (--debouncing) {
  109. _delay_ms(1);
  110. } else {
  111. for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
  112. matrix[i+offset] = matrix_debouncing[i+offset];
  113. }
  114. }
  115. }
  116. return 1;
  117. }
  118. #ifdef USE_MATRIX_I2C
  119. // Get rows from other half over i2c
  120. int i2c_transaction(void) {
  121. int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
  122. int err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE);
  123. if (err) goto i2c_error;
  124. // start of matrix stored at 0x00
  125. err = i2c_master_write(0x00);
  126. if (err) goto i2c_error;
  127. // Start read
  128. err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ);
  129. if (err) goto i2c_error;
  130. if (!err) {
  131. int i;
  132. for (i = 0; i < ROWS_PER_HAND-1; ++i) {
  133. matrix[slaveOffset+i] = i2c_master_read(I2C_ACK);
  134. }
  135. matrix[slaveOffset+i] = i2c_master_read(I2C_NACK);
  136. i2c_master_stop();
  137. } else {
  138. i2c_error: // the cable is disconnceted, or something else went wrong
  139. i2c_reset_state();
  140. return err;
  141. }
  142. return 0;
  143. }
  144. #else // USE_SERIAL
  145. int serial_transaction(int master_changed) {
  146. int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
  147. #ifdef SERIAL_USE_MULTI_TRANSACTION
  148. int ret=serial_update_buffers(master_changed);
  149. #else
  150. int ret=serial_update_buffers();
  151. #endif
  152. if (ret ) {
  153. if(ret==2) writePinLow(B0);
  154. return 1;
  155. }
  156. writePinHigh(B0);
  157. memcpy(&matrix[slaveOffset],
  158. (void *)serial_slave_buffer, sizeof(serial_slave_buffer));
  159. return 0;
  160. }
  161. #endif
  162. uint8_t matrix_scan(void)
  163. {
  164. if (is_helix_master()) {
  165. matrix_master_scan();
  166. }else{
  167. matrix_slave_scan();
  168. int offset = (isLeftHand) ? ROWS_PER_HAND : 0;
  169. memcpy(&matrix[offset],
  170. (void *)serial_master_buffer, sizeof(serial_master_buffer));
  171. matrix_scan_quantum();
  172. }
  173. return 1;
  174. }
  175. uint8_t matrix_master_scan(void) {
  176. int ret = _matrix_scan();
  177. int mchanged = 1;
  178. #ifndef KEYBOARD_helix_rev1
  179. int offset = (isLeftHand) ? 0 : ROWS_PER_HAND;
  180. #ifdef USE_MATRIX_I2C
  181. // for (int i = 0; i < ROWS_PER_HAND; ++i) {
  182. /* i2c_slave_buffer[i] = matrix[offset+i]; */
  183. // i2c_slave_buffer[i] = matrix[offset+i];
  184. // }
  185. #else // USE_SERIAL
  186. #ifdef SERIAL_USE_MULTI_TRANSACTION
  187. mchanged = memcmp((void *)serial_master_buffer,
  188. &matrix[offset], sizeof(serial_master_buffer));
  189. #endif
  190. memcpy((void *)serial_master_buffer,
  191. &matrix[offset], sizeof(serial_master_buffer));
  192. #endif
  193. #endif
  194. #ifdef USE_MATRIX_I2C
  195. if( i2c_transaction() ) {
  196. #else // USE_SERIAL
  197. if( serial_transaction(mchanged) ) {
  198. #endif
  199. // turn on the indicator led when halves are disconnected
  200. writePinLow(D5);
  201. error_count++;
  202. if (error_count > ERROR_DISCONNECT_COUNT) {
  203. // reset other half if disconnected
  204. int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0;
  205. for (int i = 0; i < ROWS_PER_HAND; ++i) {
  206. matrix[slaveOffset+i] = 0;
  207. }
  208. }
  209. } else {
  210. // turn off the indicator led on no error
  211. writePinHigh(D5);
  212. error_count = 0;
  213. }
  214. matrix_scan_quantum();
  215. return ret;
  216. }
  217. void matrix_slave_scan(void) {
  218. _matrix_scan();
  219. int offset = (isLeftHand) ? 0 : ROWS_PER_HAND;
  220. #ifdef USE_MATRIX_I2C
  221. for (int i = 0; i < ROWS_PER_HAND; ++i) {
  222. /* i2c_slave_buffer[i] = matrix[offset+i]; */
  223. i2c_slave_buffer[i] = matrix[offset+i];
  224. }
  225. #else // USE_SERIAL
  226. #ifdef SERIAL_USE_MULTI_TRANSACTION
  227. int change = 0;
  228. #endif
  229. for (int i = 0; i < ROWS_PER_HAND; ++i) {
  230. #ifdef SERIAL_USE_MULTI_TRANSACTION
  231. if( serial_slave_buffer[i] != matrix[offset+i] )
  232. change = 1;
  233. #endif
  234. serial_slave_buffer[i] = matrix[offset+i];
  235. }
  236. #ifdef SERIAL_USE_MULTI_TRANSACTION
  237. slave_buffer_change_count += change;
  238. #endif
  239. #endif
  240. }
  241. bool matrix_is_modified(void)
  242. {
  243. if (debouncing) return false;
  244. return true;
  245. }
  246. inline
  247. bool matrix_is_on(uint8_t row, uint8_t col)
  248. {
  249. return (matrix[row] & ((matrix_row_t)1<<col));
  250. }
  251. inline
  252. matrix_row_t matrix_get_row(uint8_t row)
  253. {
  254. return matrix[row];
  255. }
  256. void matrix_print(void)
  257. {
  258. print("\nr/c 0123456789ABCDEF\n");
  259. for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
  260. print_hex8(row); print(": ");
  261. print_bin_reverse16(matrix_get_row(row));
  262. print("\n");
  263. }
  264. }
  265. uint8_t matrix_key_count(void)
  266. {
  267. uint8_t count = 0;
  268. for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
  269. count += bitpop16(matrix[i]);
  270. }
  271. return count;
  272. }
  273. static void init_cols(void)
  274. {
  275. for(int x = 0; x < MATRIX_COLS; x++) {
  276. _SFR_IO8((col_pins[x] >> 4) + 1) &= ~_BV(col_pins[x] & 0xF);
  277. _SFR_IO8((col_pins[x] >> 4) + 2) |= _BV(col_pins[x] & 0xF);
  278. }
  279. }
  280. static matrix_row_t read_cols(void)
  281. {
  282. matrix_row_t result = 0;
  283. for(int x = 0; x < MATRIX_COLS; x++) {
  284. result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x);
  285. }
  286. return result;
  287. }
  288. static void unselect_rows(void)
  289. {
  290. for(int x = 0; x < ROWS_PER_HAND; x++) {
  291. _SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF);
  292. _SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF);
  293. }
  294. }
  295. static void select_row(uint8_t row)
  296. {
  297. _SFR_IO8((row_pins[row] >> 4) + 1) |= _BV(row_pins[row] & 0xF);
  298. _SFR_IO8((row_pins[row] >> 4) + 2) &= ~_BV(row_pins[row] & 0xF);
  299. }