a little progress

This commit is contained in:
Jack Humbert 2018-02-15 02:06:06 -05:00
parent f60166c1a1
commit 3c0d86eb47
2 changed files with 20 additions and 24 deletions

View File

@ -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 */ 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 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 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! * Note: Called in interrupt context, so need to be quick!
*/ */
void twi2c_slave_message_process(I2CDriver *i2cp) { 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_copy(txBody);
matrix_row_t matrix[MATRIX_ROWS / 2];
matrix_copy(matrix);
memcpy(txPtr, matrix, MATRIX_ROWS / 2);
txLen = MATRIX_ROWS / 2;
}
echoReply.size = txLen; echoReply.size = MATRIX_ROWS / 2;
i2cSlaveReplyI(i2cp, &echoReply); i2cSlaveReplyI(i2cp, &echoReply);
} }

View File

@ -55,7 +55,8 @@ void matrix_init(void) {
right_hand = palReadPad(GPIOC, 13); right_hand = palReadPad(GPIOC, 13);
// if USB is active, this is the master // 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) { if (master) {
twi2c_master_init(); twi2c_master_init();
@ -127,15 +128,16 @@ matrix_row_t matrix_scan_common(uint8_t row) {
return data; return data;
} }
const uint8_t command[2] = { 0x01, 0x00 };
uint8_t other_matrix[MATRIX_ROWS] = { 0 };
void matrix_scan_master(void) { void matrix_scan_master(void) {
const uint8_t command[2] = { 0x01, 0x00 };
uint8_t other_matrix[MATRIX_ROWS];
msg_t resp; msg_t resp;
resp = twi2c_master_send(slaveI2Caddress/2, command, other_matrix, TIME_INFINITE); resp = twi2c_master_send(slaveI2Caddress/2, command, other_matrix, TIME_IMMEDIATE);
printf("%x\n", resp); // printf("%x\n", resp);
if (resp == MSG_OK) {
uint8_t * matrix_pointer; uint8_t * matrix_pointer;
if (right_hand) { if (right_hand) {
matrix_pointer = matrix; matrix_pointer = matrix;
@ -145,6 +147,7 @@ void matrix_scan_master(void) {
memcpy(matrix_pointer, other_matrix, MATRIX_ROWS / 2); memcpy(matrix_pointer, other_matrix, MATRIX_ROWS / 2);
} }
}
uint8_t matrix_scan(void) { uint8_t matrix_scan(void) {