hooked-up keymap/matrix, compiling, not working
This commit is contained in:
parent
53c518f7d4
commit
2fccc1a064
10 changed files with 251 additions and 275 deletions
|
|
@ -20,10 +20,6 @@
|
|||
#include "chprintf.h"
|
||||
#include "memstreams.h"
|
||||
#include "printf.h"
|
||||
#include "matrix.h"
|
||||
|
||||
#ifdef I2C_SLAVE_ENABLE
|
||||
|
||||
#include "hal_i2cslave.h"
|
||||
|
||||
/**
|
||||
|
|
@ -41,8 +37,7 @@
|
|||
// };
|
||||
|
||||
I2CSlaveMsgCB twi2c_incoming_message_process, twi2c_catch_error, twi2c_clear_after_send;
|
||||
|
||||
#endif
|
||||
twi2c_message_received twi2c_message_received_callback;
|
||||
|
||||
static uint8_t twi2c_address;
|
||||
|
||||
|
|
@ -54,68 +49,6 @@ static const I2CConfig i2cconfig = {
|
|||
0
|
||||
};
|
||||
|
||||
char initialReplyBody[50] = "Initial reply"; // 'Status' response if read without preceding write
|
||||
|
||||
|
||||
uint32_t messageCounter = 0; /* Counts number of messages received to return as part of response */
|
||||
|
||||
uint8_t rxBody[2]; /* stores last message master sent us (intentionally a few bytes smaller than txBody) */
|
||||
uint8_t txBody[MATRIX_ROWS/2]; /* Return message buffer for computed replies */
|
||||
|
||||
BaseSequentialStream *chp = NULL; // Used for serial logging
|
||||
|
||||
|
||||
#ifdef I2C_SLAVE_ENABLE
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Handler when something sent to us
|
||||
const I2CSlaveMsg echoRx =
|
||||
{
|
||||
sizeof(rxBody), /* max sizeof received msg body */
|
||||
rxBody, /* body of received msg */
|
||||
NULL, /* do nothing on address match */
|
||||
twi2c_slave_message_process, /* Routine to process received messages */
|
||||
twi2c_catch_error /* Error hook */
|
||||
};
|
||||
|
||||
|
||||
// // 'Empty' reply when nothing to say, and no message received. In RAM, to allow update
|
||||
I2CSlaveMsg initialReply =
|
||||
{
|
||||
sizeof(initialReplyBody), /* trailing zero byte will be repeated as needed */
|
||||
(uint8_t *)initialReplyBody,
|
||||
NULL, /* do nothing on address match */
|
||||
NULL, /* do nothing after reply sent */
|
||||
twi2c_catch_error /* Error hook */
|
||||
};
|
||||
|
||||
// // 'Empty' reply when nothing to say, and no message received. In RAM, to allow update
|
||||
// I2CSlaveMsg initialReply =
|
||||
// {
|
||||
// 0, /* trailing zero byte will be repeated as needed */
|
||||
// NULL,
|
||||
// NULL, /* do nothing on address match */
|
||||
// NULL, /* do nothing after reply sent */
|
||||
// twi2c_catch_error /* Error hook */
|
||||
// };
|
||||
|
||||
|
||||
// Response to received messages
|
||||
I2CSlaveMsg echoReply = { /* this is in RAM so size may be updated */
|
||||
MATRIX_ROWS / 2, /* filled in with the length of the message to send */
|
||||
txBody, /* Response message */
|
||||
NULL, /* do nothing special on address match */
|
||||
twi2c_clear_after_send, /* Clear receive buffer once replied */
|
||||
twi2c_catch_error /* Error hook */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Track I2C errors
|
||||
*/
|
||||
|
|
@ -129,8 +62,6 @@ void noteI2cError(uint32_t flags)
|
|||
gotI2cError = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generic error handler
|
||||
*
|
||||
|
|
@ -141,31 +72,6 @@ void twi2c_catch_error(I2CDriver *i2cp)
|
|||
noteI2cError(i2cp->errors);
|
||||
}
|
||||
|
||||
extern void matrix_copy(matrix_row_t * copy);
|
||||
|
||||
const char hexString[16] = "0123456789abcdef";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Message processor - looks at received message, determines reply as quickly as possible
|
||||
*
|
||||
* Responds with the value of the messageCounter (in hex), followed by the received message in [..]
|
||||
*
|
||||
* Note: Called in interrupt context, so need to be quick!
|
||||
*/
|
||||
void twi2c_slave_message_process(I2CDriver *i2cp) {
|
||||
|
||||
// size_t len = i2cSlaveBytes(i2cp); // Number of bytes received
|
||||
|
||||
// memset(txBody, 0, MATRIX_ROWS / 2 * sizeof(matrix_row_t));
|
||||
matrix_copy(txBody);
|
||||
|
||||
echoReply.size = MATRIX_ROWS / 2;
|
||||
i2cSlaveReplyI(i2cp, &echoReply);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback after sending of response complete - restores default reply in case polled
|
||||
*/
|
||||
|
|
@ -175,49 +81,7 @@ void twi2c_clear_after_send(I2CDriver *i2cp)
|
|||
// i2cSlaveReplyI(i2cp, &initialReply);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start the I2C Slave port to accept comms from master CPU
|
||||
*
|
||||
* We then go into a loop checking for errors, and never return
|
||||
*/
|
||||
|
||||
void twi2c_slave_init(twi2c_message_received * cb, uint8_t address) {
|
||||
|
||||
twi2c_init();
|
||||
|
||||
|
||||
i2cStart(&I2C_DRIVER, &i2cconfig);
|
||||
#if HAL_USE_I2C_SLAVE
|
||||
I2C_DRIVER.slaveTimeout = MS2ST(100); // Time for complete message
|
||||
#endif
|
||||
|
||||
// i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &initialReply);
|
||||
|
||||
memset(txBody, 0, MATRIX_ROWS / 2 * sizeof(matrix_row_t));
|
||||
|
||||
i2cSlaveConfigure(&I2C_DRIVER, &echoRx, &echoReply);
|
||||
|
||||
// Enable match address after everything else set up
|
||||
i2cMatchAddress(&I2C_DRIVER, address/2);
|
||||
// i2cMatchAddress(&I2C_DRIVER, myOtherI2Caddress/2);
|
||||
// i2cMatchAddress(&I2C_DRIVER, 0); /* "all call" */
|
||||
|
||||
printf("Slave I2C started\n\r");
|
||||
|
||||
}
|
||||
|
||||
void twi2c_slave_task(void) {
|
||||
if (gotI2cError) {
|
||||
gotI2cError = 0;
|
||||
printf("I2cError: %04x\r\n", lastI2cErrorFlags);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
uint8_t twi2c_start(uint8_t address) {
|
||||
twi2c_address = address;
|
||||
uint8_t twi2c_start(void) {
|
||||
i2cStart(&I2C_DRIVER, &i2cconfig);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -239,12 +103,15 @@ uint8_t twi2c_write(uint8_t data) {
|
|||
return i2cMasterTransmitTimeout(&I2C_DRIVER, twi2c_address/2, &data, 1, 0, 0, MS2ST(100));
|
||||
}
|
||||
|
||||
uint8_t twi2c_transmit(uint8_t address, uint8_t* data, uint16_t length) {
|
||||
twi2c_address = address;
|
||||
i2cStart(&I2C_DRIVER, &i2cconfig);
|
||||
return i2cMasterTransmitTimeout(&I2C_DRIVER, twi2c_address/2, data, length, 0, 0, MS2ST(100));
|
||||
uint8_t twi2c_transmit(uint8_t address, uint8_t * data, uint16_t length) {
|
||||
return i2cMasterTransmitTimeout(&I2C_DRIVER, address/2, data, length, 0, 0, MS2ST(100));
|
||||
}
|
||||
|
||||
uint8_t twi2c_receive(uint8_t address, uint8_t * data, uint16_t length) {
|
||||
return i2cMasterReceiveTimeout(&I2C_DRIVER, address/2, data, length, MS2ST(100));
|
||||
}
|
||||
|
||||
|
||||
uint8_t twi2c_incoming_body[512];
|
||||
uint8_t twi2c_outgoing_body[512];
|
||||
|
||||
|
|
@ -257,35 +124,40 @@ I2CSlaveMsg twi2c_incoming_message = {
|
|||
twi2c_catch_error /* Error hook */
|
||||
};
|
||||
|
||||
void twi2c_incoming_message_process(I2CDriver *i2cp) {
|
||||
void twi2c_incoming_message_process(I2CDriver * i2cp) {
|
||||
size_t len = i2cSlaveBytes(i2cp);
|
||||
twi2c_message_received_callback(twi2c_incoming_body, len);
|
||||
(*twi2c_message_received_callback)(i2cp, twi2c_incoming_body, len);
|
||||
}
|
||||
|
||||
// Response to received messages
|
||||
I2CSlaveMsg twi2c_outgoing_message = { /* this is in RAM so size may be updated */
|
||||
sizeof(twi2c_outgoing_body), /* filled in with the length of the message to send */
|
||||
I2CSlaveMsg twi2c_outgoing_message = {
|
||||
sizeof(twi2c_outgoing_body),
|
||||
twi2c_outgoing_body,
|
||||
NULL,
|
||||
twi2c_clear_after_send,
|
||||
twi2c_catch_error /* Error hook */
|
||||
twi2c_catch_error
|
||||
};
|
||||
|
||||
uint8_t twi2c_reply(uint8_t * data, uint16_t length) {
|
||||
twi2c_outgoing_body = data;
|
||||
uint8_t twi2c_reply(I2CDriver * i2cp, uint8_t * data, uint16_t length) {
|
||||
memcpy(twi2c_outgoing_body, data, length);
|
||||
twi2c_outgoing_message.size = length;
|
||||
i2cSlaveReplyI(i2cp, &twi2c_outgoing_message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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_transmit_receive(uint8_t address, uint8_t * tx_body, uint16_t tx_length, uint8_t * rx_body, uint16_t rx_length) {
|
||||
return i2cMasterTransmitTimeout(&I2C_DRIVER, address/2, tx_body, tx_length, rx_body, rx_length, MS2ST(100));
|
||||
}
|
||||
|
||||
uint8_t twi2c_start_listening(uint8_t address, twi2c_message_received callback) {
|
||||
twi2c_message_received_callback = callback;
|
||||
i2cStart(&I2C_DRIVER, &i2cconfig);
|
||||
I2C_DRIVER.slaveTimeout = MS2ST(100);
|
||||
i2cSlaveConfigure(&I2C_DRIVER, &twi2c_incoming_message, &twi2c_outgoing_message);
|
||||
i2cMatchAddress(&I2C_DRIVER, address/2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void twi2c_stop(void) {
|
||||
i2cUnmatchAll(&I2C_DRIVER);
|
||||
i2cStop(&I2C_DRIVER);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TWI2C_H
|
||||
#define TWI2C_H
|
||||
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
|
||||
|
|
@ -23,20 +26,11 @@
|
|||
|
||||
#define slaveI2Caddress 0x30 /* Address in our terms - halved by later code */
|
||||
//#define myOtherI2Caddress 0x19
|
||||
|
||||
#ifdef I2C_SLAVE_ENABLE
|
||||
|
||||
typedef void twi2c_message_received(uint8_t * body, uint16_t size);
|
||||
twi2c_message_received twi2c_message_received_callback;
|
||||
|
||||
I2CSlaveMsgCB twi2c_slave_message_process, catchError, clearAfterSend;
|
||||
|
||||
void twi2c_slave_init(void);
|
||||
|
||||
#endif
|
||||
I2CSlaveMsgCB twi2c_incoming_message_process, twi2c_catch_error, twi2c_clear_after_send;
|
||||
typedef void (*twi2c_message_received)(I2CDriver *, uint8_t *, uint16_t);
|
||||
|
||||
void twi2c_init(void);
|
||||
uint8_t twi2c_start(uint8_t address);
|
||||
uint8_t twi2c_start(void);
|
||||
uint8_t twi2c_write(uint8_t data);
|
||||
uint8_t twi2c_read_ack(void);
|
||||
uint8_t twi2c_read_nack(void);
|
||||
|
|
@ -45,6 +39,9 @@ uint8_t twi2c_receive(uint8_t address, uint8_t* data, uint16_t length);
|
|||
uint8_t twi2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length);
|
||||
uint8_t twi2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length);
|
||||
void twi2c_stop(void);
|
||||
uint8_t twi2c_reply(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_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);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -17,82 +17,141 @@
|
|||
#include "qwiic_keyboard.h"
|
||||
#include "keymap.h"
|
||||
#include "matrix.h"
|
||||
#include "keyboard.h"
|
||||
#include "twi2c.h"
|
||||
#include <string.h>
|
||||
#include "usb_main.h"
|
||||
#include "usb_driver.h"
|
||||
|
||||
#define QWIIC_KEYBOARD_LAYERS 16
|
||||
#define QWIIC_KEYBOARD_ROWS 8
|
||||
#define QWIIC_KEYBOARD_COLS 8
|
||||
|
||||
#define QWIIC_KEYBOARD_HANDSHAKE_ADDRESS 0b01010100
|
||||
#define qwiic_matrix_t uint8_t
|
||||
|
||||
#define QWIIC_KEYBOARD_HANDSHAKE_ADDRESS 0b01010100
|
||||
#define QWIIC_KEYBOARD_LISTENING_ADDRESS_START 0b01010110
|
||||
#define QWIIC_KEYBOARD_HANDSHAKE_MESSAGE_SIZE (2 + (QWIIC_KEYBOARD_LAYERS * QWIIC_KEYBOARD_ROWS * QWIIC_KEYBOARD_COLS))
|
||||
#define QWIIC_KEYBOARD_MATRIX_MESSAGE_SIZE MATRIX_ROWS
|
||||
#define QWIIC_KEYBOARD_HANDSHAKE_MESSAGE_SIZE (QWIIC_KEYBOARD_LAYERS * QWIIC_KEYBOARD_ROWS * QWIIC_KEYBOARD_COLS)
|
||||
#define QWIIC_KEYBOARD_MATRIX_MESSAGE_SIZE MATRIX_ROWS
|
||||
|
||||
void qwiic_keyboard_write_keymap(uint8_t * pointer);
|
||||
void qwiic_keyboard_read_keymap(uint8_t * pointer);
|
||||
|
||||
bool qwiic_keyboard_master = false;
|
||||
bool qwiic_keyboard_connected = false;
|
||||
uint8_t * qwiic_keyboard_handshake_message = {0};
|
||||
uint8_t * qwiic_keyboard_matrix_message[QWIIC_KEYBOARD_ROWS] = {0};
|
||||
uint8_t qwiic_keyboard_handshake_message[QWIIC_KEYBOARD_HANDSHAKE_MESSAGE_SIZE] = {0};
|
||||
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_matrix_rows;
|
||||
uint8_t qwiic_keyboard_matrix_cols;
|
||||
uint8_t qwiic_keyboard_processing_slave = false;
|
||||
|
||||
void qwiic_keyboard_setup(void) {
|
||||
twi2c_start_listening(qwiic_keyboard_listening_address, qwiic_keyboard_message_received);
|
||||
void qwiic_keyboard_init(void) {
|
||||
twi2c_init();
|
||||
twi2c_start();
|
||||
twi2c_start_listening(qwiic_keyboard_listening_address, qwiic_keyboard_message_received_ptr);
|
||||
}
|
||||
|
||||
void qwiic_keyboard_set_master() {
|
||||
void qwiic_keyboard_set_master(void) {
|
||||
twi2c_stop();
|
||||
twi2c_start();
|
||||
qwiic_keyboard_master = true;
|
||||
}
|
||||
|
||||
void qwiic_keyboard_task(void) {
|
||||
if (USB_DRIVER.state == USB_ACTIVE)
|
||||
qwiic_keyboard_master = true;
|
||||
else
|
||||
qwiic_keyboard_master = false;
|
||||
if (qwiic_keyboard_master) {
|
||||
if (qwiic_keyboard_connected) {
|
||||
if (MSG_OK == twi2c_transmit_receive(qwiic_keyboard_listening_address,
|
||||
NULL, 0,
|
||||
// send empty message, expecting matrix info
|
||||
twi2c_transmit(qwiic_keyboard_listening_address, NULL, 0);
|
||||
if (MSG_OK == twi2c_receive(qwiic_keyboard_listening_address,
|
||||
qwiic_keyboard_matrix_message, QWIIC_KEYBOARD_MATRIX_MESSAGE_SIZE
|
||||
)) {
|
||||
// process key event
|
||||
// majority of this is pulled from keyboard.c:keyboard_task()
|
||||
static qwiic_matrix_t matrix_prev[QWIIC_KEYBOARD_ROWS];
|
||||
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++) {
|
||||
if (matrix_change & ((qwiic_matrix_t)1<<c)) {
|
||||
action_exec((keyevent_t){
|
||||
.key = (keypos_t){ .row = r, .col = c },
|
||||
.pressed = (matrix_row & ((qwiic_matrix_t)1<<c)),
|
||||
.time = (timer_read() | 1) /* time should not be 0 */
|
||||
});
|
||||
// record a processed key
|
||||
matrix_prev[r] ^= ((qwiic_matrix_t)1<<c);
|
||||
#ifdef QMK_KEYS_PER_SCAN
|
||||
// only jump out if we have processed "enough" keys.
|
||||
if (++keys_processed >= QMK_KEYS_PER_SCAN)
|
||||
#endif
|
||||
// process a key per task call
|
||||
goto MATRIX_LOOP_END;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// call with pseudo tick event when no real key event.
|
||||
#ifdef QMK_KEYS_PER_SCAN
|
||||
// we can get here with some keys processed now.
|
||||
if (!keys_processed)
|
||||
#endif
|
||||
action_exec(TICK);
|
||||
MATRIX_LOOP_END:
|
||||
qwiic_keyboard_processing_slave = false;
|
||||
} else {
|
||||
// disconnect
|
||||
// qwiic_keyboard_connected = false;
|
||||
}
|
||||
} else {
|
||||
// send new address to listen on, expect back keymap
|
||||
twi2c_transmit(QWIIC_KEYBOARD_HANDSHAKE_ADDRESS, &qwiic_keyboard_new_listening_address, 1);
|
||||
if (MSG_OK == twi2c_receive(QWIIC_KEYBOARD_HANDSHAKE_ADDRESS,
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (MSG_OK == twi2c_transmit_receive(QWIIC_KEYBOARD_HANDSHAKE_ADDRESS,
|
||||
qwiic_keyboard_new_listening_address, 1,
|
||||
qwiic_keyboard_handshake_message, QWIIC_KEYBOARD_HANDSHAKE_MESSAGE_SIZE
|
||||
)) {
|
||||
qwiic_keyboard_new_listening_address+=2;
|
||||
uint8_t * message_pointer = qwiic_keyboard_handshake_message;
|
||||
qwiic_keyboard_matrix_rows = *message_pointer++;
|
||||
qwiic_keyboard_matrix_cols = *message_pointer++;
|
||||
qwiic_keyboard_read_keymap(message_pointer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
twi2c_message_received qwiic_keyboard_message_received;
|
||||
extern matrix_row_t matrix[MATRIX_ROWS];
|
||||
uint8_t * qwiic_keyboard_reply;
|
||||
uint8_t qwiic_keyboard_reply[MATRIX_ROWS];
|
||||
|
||||
void qwiic_keyboard_message_received(uint8_t * body, uint16_t size) {
|
||||
void qwiic_keyboard_message_received(I2CDriver *i2cp, uint8_t * body, uint16_t size) {
|
||||
if (qwiic_keyboard_connected) {
|
||||
memcpy(qwiic_keyboard_reply, matrix, QWIIC_KEYBOARD_MATRIX_MESSAGE_SIZE);
|
||||
twi2c_reply(qwiic_keyboard_reply, QWIIC_KEYBOARD_MATRIX_MESSAGE_SIZE);
|
||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||
qwiic_keyboard_reply[row] = matrix_get_row(row);
|
||||
}
|
||||
twi2c_reply(i2cp, qwiic_keyboard_reply, QWIIC_KEYBOARD_MATRIX_MESSAGE_SIZE);
|
||||
} else {
|
||||
qwiic_keyboard_connected = true;
|
||||
qwiic_keyboard_listening_address
|
||||
uint8_t * message_pointer = qwiic_keyboard_reply;
|
||||
*message_pointer++ = MATRIX_ROWS;
|
||||
*message_pointer++ = MATRIX_COLS;
|
||||
qwiic_keyboard_write_keymap(message_pointer);
|
||||
twi2c_reply(qwiic_keyboard_reply, QWIIC_KEYBOARD_HANDSHAKE_MESSAGE_SIZE);
|
||||
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_listening(qwiic_keyboard_listening_address, qwiic_keyboard_message_received);
|
||||
twi2c_start();
|
||||
twi2c_start_listening(qwiic_keyboard_listening_address, qwiic_keyboard_message_received_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
// qwiic_keyboard_message_received_ptr = qwiic_keyboard_message_received;
|
||||
|
||||
__attribute__((optimize("O0")))
|
||||
void qwiic_keyboard_write_keymap(uint8_t * pointer) {
|
||||
for (uint8_t layer = 0; layer < QWIIC_KEYBOARD_LAYERS; layer++) {
|
||||
for (uint8_t row = 0; row < QWIIC_KEYBOARD_ROWS; row++) {
|
||||
|
|
@ -116,3 +175,19 @@ void qwiic_keyboard_read_keymap(uint8_t * pointer) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// overwrite the built-in function - slaves don't need to process keycodes
|
||||
bool is_keyboard_master(void) {
|
||||
return qwiic_keyboard_master;
|
||||
}
|
||||
|
||||
// overwrite the built-in function
|
||||
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)];
|
||||
} else {
|
||||
// Read entire word (16bits)
|
||||
return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,4 +19,8 @@
|
|||
|
||||
#include "quantum.h"
|
||||
|
||||
void qwiic_keyboard_init(void);
|
||||
void qwiic_keyboard_task(void);
|
||||
void qwiic_keyboard_message_received(I2CDriver *i2cp, uint8_t * body, uint16_t size);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue