From 13f49ad8d9666c9c6b860075188a93a37f8eb399 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 9 Jun 2018 23:53:26 -0400 Subject: [PATCH] all a's working --- drivers/arm/twi2c.c | 5 ++++ drivers/arm/twi2c.h | 1 + drivers/qwiic/qwiic_keyboard.c | 44 +++++++++++++++++----------------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/drivers/arm/twi2c.c b/drivers/arm/twi2c.c index 61a04d3743..973a822430 100644 --- a/drivers/arm/twi2c.c +++ b/drivers/arm/twi2c.c @@ -157,6 +157,11 @@ uint8_t twi2c_start_listening(uint8_t address, twi2c_message_received callback) return 0; } +uint8_t twi2c_restart_listening(uint8_t address) { + i2cMatchAddress(&I2C_DRIVER, address/2); + return 0; +} + void twi2c_stop(void) { i2cUnmatchAll(&I2C_DRIVER); i2cStop(&I2C_DRIVER); diff --git a/drivers/arm/twi2c.h b/drivers/arm/twi2c.h index 047c28e8b0..daa55fb2d1 100644 --- a/drivers/arm/twi2c.h +++ b/drivers/arm/twi2c.h @@ -43,5 +43,6 @@ void twi2c_stop(void); uint8_t twi2c_reply(I2CDriver * i2cp, uint8_t * data, uint16_t length); uint8_t twi2c_transmit_receive(uint8_t address, uint8_t * tx_body, uint16_t tx_length, uint8_t * rx_body, uint16_t rx_length); uint8_t twi2c_start_listening(uint8_t address, twi2c_message_received callback); +uint8_t twi2c_restart_listening(uint8_t address); #endif diff --git a/drivers/qwiic/qwiic_keyboard.c b/drivers/qwiic/qwiic_keyboard.c index 2b3324021d..088c70f848 100644 --- a/drivers/qwiic/qwiic_keyboard.c +++ b/drivers/qwiic/qwiic_keyboard.c @@ -44,14 +44,13 @@ uint8_t qwiic_keyboard_matrix_message[QWIIC_KEYBOARD_ROWS] = {0}; twi2c_message_received qwiic_keyboard_message_received_ptr = qwiic_keyboard_message_received; uint16_t qwiic_keyboard_keymap[QWIIC_KEYBOARD_LAYERS][QWIIC_KEYBOARD_ROWS][QWIIC_KEYBOARD_COLS] = {0}; -uint8_t qwiic_keyboard_new_listening_address = QWIIC_KEYBOARD_LISTENING_ADDRESS_START; uint8_t qwiic_keyboard_listening_address = QWIIC_KEYBOARD_LISTENING_ADDRESS_START; uint8_t qwiic_keyboard_processing_slave = false; void qwiic_keyboard_init(void) { twi2c_init(); twi2c_start(); - twi2c_start_listening(qwiic_keyboard_listening_address, qwiic_keyboard_message_received_ptr); + twi2c_start_listening(QWIIC_KEYBOARD_HANDSHAKE_ADDRESS, qwiic_keyboard_message_received_ptr); } void qwiic_keyboard_set_master(void) { @@ -79,12 +78,11 @@ void qwiic_keyboard_task(void) { qwiic_matrix_t matrix_row = 0; qwiic_matrix_t matrix_change = 0; qwiic_keyboard_processing_slave = true; - SEND_STRING("K."); for (uint8_t r = 0; r < QWIIC_KEYBOARD_ROWS; r++) { matrix_row = qwiic_keyboard_matrix_message[r]; matrix_change = matrix_row ^ matrix_prev[r]; if (matrix_change) { - for (uint8_t c = 0; c < MATRIX_COLS; c++) { + for (uint8_t c = 0; c < QWIIC_KEYBOARD_COLS; c++) { if (matrix_change & ((qwiic_matrix_t)1<= QMK_KEYS_PER_SCAN) #endif // process a key per task call - goto MATRIX_LOOP_END; + //goto MATRIX_LOOP_END; } } } @@ -109,7 +107,7 @@ void qwiic_keyboard_task(void) { if (!keys_processed) #endif action_exec(TICK); - MATRIX_LOOP_END: + //MATRIX_LOOP_END: qwiic_keyboard_processing_slave = false; } else { // disconnect @@ -118,12 +116,10 @@ void qwiic_keyboard_task(void) { } else { // if not connected // send new address to listen on, expect back keymap if (MSG_OK == twi2c_transmit_receive(QWIIC_KEYBOARD_HANDSHAKE_ADDRESS, - &qwiic_keyboard_new_listening_address, 1, + &qwiic_keyboard_listening_address, 1, qwiic_keyboard_handshake_message, QWIIC_KEYBOARD_HANDSHAKE_MESSAGE_SIZE )) { qwiic_keyboard_connected = true; - // increment address (for future implemenations of supporting multiple devices) - qwiic_keyboard_new_listening_address+=2; // load keymap into memory qwiic_keyboard_read_keymap(qwiic_keyboard_handshake_message); } @@ -131,27 +127,30 @@ void qwiic_keyboard_task(void) { } } -uint8_t qwiic_keyboard_reply[MATRIX_ROWS]; - float song_one_up[][2] = SONG(ONE_UP_SOUND); +bool first_message = true; void qwiic_keyboard_message_received(I2CDriver *i2cp, uint8_t * body, uint16_t size) { if (qwiic_keyboard_connected) { - for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - qwiic_keyboard_reply[row] = matrix_get_row(row); + for (uint8_t row = 0; row < QWIIC_KEYBOARD_ROWS; row++) { + if (row < MATRIX_ROWS) { + qwiic_keyboard_matrix_message[row] = matrix_get_row(row); + } else { + qwiic_keyboard_matrix_message[row] = 0; + } + } + twi2c_reply(i2cp, qwiic_keyboard_matrix_message, QWIIC_KEYBOARD_MATRIX_MESSAGE_SIZE); + if (first_message) { + PLAY_SONG(song_one_up); + first_message = false; } - twi2c_reply(i2cp, qwiic_keyboard_reply, QWIIC_KEYBOARD_MATRIX_MESSAGE_SIZE); } else { qwiic_keyboard_connected = true; qwiic_keyboard_master = false; qwiic_keyboard_listening_address = body[0]; - qwiic_keyboard_write_keymap(qwiic_keyboard_reply); - twi2c_reply(i2cp, qwiic_keyboard_reply, QWIIC_KEYBOARD_HANDSHAKE_MESSAGE_SIZE); - twi2c_stop(); - twi2c_start(); - twi2c_start_listening(qwiic_keyboard_listening_address, qwiic_keyboard_message_received_ptr); - stop_all_notes(); - PLAY_SONG(song_one_up); + twi2c_restart_listening(qwiic_keyboard_listening_address); + qwiic_keyboard_write_keymap(qwiic_keyboard_handshake_message); + twi2c_reply(i2cp, qwiic_keyboard_handshake_message, QWIIC_KEYBOARD_HANDSHAKE_MESSAGE_SIZE); } } @@ -191,7 +190,8 @@ bool is_keyboard_master(void) { uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) { if (qwiic_keyboard_processing_slave) { // trick the built-in handling to accept our replacement keymap - return qwiic_keyboard_keymap[(layer)][(key.row)][(key.col)]; + //return qwiic_keyboard_keymap[(layer)][(key.row)][(key.col)]; + return KC_A; } else { // Read entire word (16bits) return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]);