Make the left keyboard half send the state of the keys to the right half via I2C and make the right half send the relevant scancodes to the host via USB.
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
#include "usb_composite_device.h"
|
||||
#include "test_led.h"
|
||||
#include "key_matrix.h"
|
||||
#include "fsl_i2c.h"
|
||||
#include "i2c.h"
|
||||
#include "i2c_addresses.h"
|
||||
|
||||
static usb_device_endpoint_struct_t UsbKeyboardEndpoints[USB_KEYBOARD_ENDPOINT_COUNT] = {{
|
||||
USB_KEYBOARD_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
@@ -62,6 +65,9 @@ key_matrix_t keyMatrix = {
|
||||
}
|
||||
};
|
||||
|
||||
#define KEY_STATE_COUNT (5*7)
|
||||
uint8_t leftKeyStates[KEY_STATE_COUNT] = {0};
|
||||
|
||||
static usb_status_t UsbKeyboardAction(void)
|
||||
{
|
||||
UsbKeyboardReport.modifiers = 0;
|
||||
@@ -75,6 +81,16 @@ static usb_status_t UsbKeyboardAction(void)
|
||||
UsbKeyboardReport.scancodes[scancodeIdx] = 0;
|
||||
}
|
||||
|
||||
i2c_master_transfer_t masterXfer;
|
||||
masterXfer.slaveAddress = I2C_ADDRESS_LEFT_KEYBOARD_HALF;
|
||||
masterXfer.direction = kI2C_Read;
|
||||
masterXfer.subaddress = 0;
|
||||
masterXfer.subaddressSize = 0;
|
||||
masterXfer.data = leftKeyStates;
|
||||
masterXfer.dataSize = KEY_STATE_COUNT;
|
||||
masterXfer.flags = kI2C_TransferDefaultFlag;
|
||||
I2C_MasterTransferBlocking(I2C_MAIN_BUS_BASEADDR, &masterXfer);
|
||||
|
||||
scancodeIdx = 0;
|
||||
for (uint8_t keyId=0; keyId<KEYBOARD_MATRIX_COLS_NUM*KEYBOARD_MATRIX_ROWS_NUM; keyId++) {
|
||||
if (keyMatrix.keyStates[keyId] && scancodeIdx<USB_KEYBOARD_MAX_KEYS) {
|
||||
@@ -82,6 +98,12 @@ static usb_status_t UsbKeyboardAction(void)
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t keyId=0; keyId<KEY_STATE_COUNT; keyId++) {
|
||||
if (leftKeyStates[keyId] && scancodeIdx<USB_KEYBOARD_MAX_KEYS) {
|
||||
UsbKeyboardReport.scancodes[scancodeIdx++] = keyId + HID_KEYBOARD_SC_A;
|
||||
}
|
||||
}
|
||||
|
||||
return USB_DeviceHidSend(UsbCompositeDevice.keyboardHandle, USB_KEYBOARD_ENDPOINT_INDEX,
|
||||
(uint8_t*)&UsbKeyboardReport, USB_KEYBOARD_REPORT_LENGTH);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user