From 3c0d86eb47b2eb92b8300bc726dc242c8af594f4 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 15 Feb 2018 02:06:06 -0500 Subject: [PATCH] a little progress --- drivers/arm/twi2c.c | 15 ++++----------- keyboards/_qmk_handwire/matrix.c | 29 ++++++++++++++++------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/drivers/arm/twi2c.c b/drivers/arm/twi2c.c index 561a601e..299e52eb 100644 --- a/drivers/arm/twi2c.c +++ b/drivers/arm/twi2c.c @@ -53,7 +53,7 @@ char initialReplyBody[50] = "Initial reply"; // 'Status' response if read uint32_t messageCounter = 0; /* Counts number of messages received to return as part of response */ uint8_t rxBody[240]; /* stores last message master sent us (intentionally a few bytes smaller than txBody) */ -uint8_t txBody[256]; /* Return message buffer for computed replies */ +uint8_t txBody[MATRIX_ROWS/2]; /* Return message buffer for computed replies */ BaseSequentialStream *chp = NULL; // Used for serial logging @@ -126,19 +126,12 @@ const char hexString[16] = "0123456789abcdef"; * Note: Called in interrupt context, so need to be quick! */ void twi2c_slave_message_process(I2CDriver *i2cp) { - uint8_t *txPtr = txBody; - uint8_t txLen; - size_t len = i2cSlaveBytes(i2cp); // Number of bytes received + // size_t len = i2cSlaveBytes(i2cp); // Number of bytes received - if (len >= 2 && rxBody[0] == 0x01 && rxBody[1] == 0x00) { - matrix_row_t matrix[MATRIX_ROWS / 2]; - matrix_copy(matrix); - memcpy(txPtr, matrix, MATRIX_ROWS / 2); - txLen = MATRIX_ROWS / 2; - } + matrix_copy(txBody); - echoReply.size = txLen; + echoReply.size = MATRIX_ROWS / 2; i2cSlaveReplyI(i2cp, &echoReply); } diff --git a/keyboards/_qmk_handwire/matrix.c b/keyboards/_qmk_handwire/matrix.c index 1d67851b..cbf4537b 100644 --- a/keyboards/_qmk_handwire/matrix.c +++ b/keyboards/_qmk_handwire/matrix.c @@ -55,7 +55,8 @@ void matrix_init(void) { right_hand = palReadPad(GPIOC, 13); // if USB is active, this is the master - master = (USB_DRIVER.state == USB_ACTIVE); + // master = usbGetDriverStateI(&USB_DRIVER) == USB_ACTIVE; + master = right_hand; if (master) { twi2c_master_init(); @@ -127,23 +128,25 @@ matrix_row_t matrix_scan_common(uint8_t row) { return data; } -void matrix_scan_master(void) { +const uint8_t command[2] = { 0x01, 0x00 }; +uint8_t other_matrix[MATRIX_ROWS] = { 0 }; - const uint8_t command[2] = { 0x01, 0x00 }; - uint8_t other_matrix[MATRIX_ROWS]; +void matrix_scan_master(void) { msg_t resp; - resp = twi2c_master_send(slaveI2Caddress/2, command, other_matrix, TIME_INFINITE); - printf("%x\n", resp); + resp = twi2c_master_send(slaveI2Caddress/2, command, other_matrix, TIME_IMMEDIATE); + // printf("%x\n", resp); - uint8_t * matrix_pointer; - if (right_hand) { - matrix_pointer = matrix; - } else { - matrix_pointer = matrix + (MATRIX_ROWS / 2); - } + if (resp == MSG_OK) { + uint8_t * matrix_pointer; + if (right_hand) { + matrix_pointer = matrix; + } else { + matrix_pointer = matrix + (MATRIX_ROWS / 2); + } - memcpy(matrix_pointer, other_matrix, MATRIX_ROWS / 2); + memcpy(matrix_pointer, other_matrix, MATRIX_ROWS / 2); + } } uint8_t matrix_scan(void) {