Skip to content

Commit

Permalink
nkro through rf
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossless committed Jan 1, 2025
1 parent edb498d commit 58b0611
Show file tree
Hide file tree
Showing 9 changed files with 480 additions and 49 deletions.
355 changes: 354 additions & 1 deletion docs/keyboards/nuphy-air60.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/kb/kb.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <stdbool.h>

void kb_init();
void kb_send_report(report_keyboard_t *report);
void kb_send_nkro(report_nkro_t *report);
void kb_send_extra(report_extra_t *report);
void kb_send_report(__xdata report_keyboard_t *report);
void kb_send_nkro(__xdata report_nkro_t *report);
void kb_send_extra(__xdata report_extra_t *report);

bool kb_process_record(uint16_t keycode, bool key_pressed);
void kb_update_switches();
Expand Down
8 changes: 4 additions & 4 deletions src/keyboards/nuphy-air60/kb.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool kb_process_record(uint16_t keycode, bool key_pressed)
}
}

void kb_send_report(report_keyboard_t *report)
void kb_send_report(__xdata report_keyboard_t *report)
{
switch (user_keyboard_state.conn_mode) {
case KEYBOARD_CONN_MODE_USB:
Expand All @@ -90,21 +90,21 @@ void kb_send_report(report_keyboard_t *report)
}
}

void kb_send_nkro(report_nkro_t *report)
void kb_send_nkro(__xdata report_nkro_t *report)
{
switch (user_keyboard_state.conn_mode) {
case KEYBOARD_CONN_MODE_USB:
usb_send_nkro(report);
break;
#ifdef RF_ENABLED
case KEYBOARD_CONN_MODE_RF:
// TODO: implement rf
rf_send_nkro(report);
break;
#endif
}
}

void kb_send_extra(report_extra_t *report)
void kb_send_extra(__xdata report_extra_t *report)
{
switch (user_keyboard_state.conn_mode) {
case KEYBOARD_CONN_MODE_USB:
Expand Down
133 changes: 105 additions & 28 deletions src/platform/bk3632/rf_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void rf_send_blank_report();
bool rf_get_status(uint8_t status_bytes[2]);
void rf_cmd_01(uint8_t mode, uint8_t pairing);
void rf_cmd_02(uint8_t *buffer);
void rf_cmd_02_nkro(__xdata uint8_t mods, __xdata uint8_t *nkro_buffer);
void rf_cmd_03(uint8_t param);
void rf_cmd_04();
void rf_cmd_05(uint16_t consumer, uint16_t system);
Expand Down Expand Up @@ -70,46 +71,78 @@ void rf_init()
rf_send_blank_report();
}

void rf_send_report(report_keyboard_t *report)
{
__xdata uint8_t buffer[6];
__xdata uint8_t kro6buffer[6];

buffer[0] = report->raw[0];
buffer[1] = report->raw[2];
buffer[2] = report->raw[3];
buffer[3] = report->raw[4];
buffer[4] = report->raw[5];
buffer[5] = report->raw[6];
void rf_send_report(__xdata report_keyboard_t *report)
{
kro6buffer[0] = report->raw[0];
kro6buffer[1] = report->raw[2];
kro6buffer[2] = report->raw[3];
kro6buffer[3] = report->raw[4];
kro6buffer[4] = report->raw[5];
kro6buffer[5] = report->raw[6];

bool blank = true;
for (int i = 0; i < 6; i++) {
if (buffer[i] != 0) {
for (__xdata int i = 0; i < 6; i++) {
if (kro6buffer[i] != 0) {
blank = false;
}
}

if (blank) {
// blanking sequence
kro6buffer[1] = 0x00;
rf_cmd_02(kro6buffer);
kro6buffer[1] = 0x01;
rf_cmd_02(kro6buffer);
kro6buffer[1] = 0x00;
rf_cmd_02(kro6buffer);
kro6buffer[1] = 0x01;
rf_cmd_02(kro6buffer);
kro6buffer[1] = 0x00;
rf_cmd_02(kro6buffer);
kro6buffer[1] = 0x01;
rf_cmd_02(kro6buffer);
kro6buffer[1] = 0x00;
rf_cmd_02(kro6buffer);
} else {
rf_cmd_02(kro6buffer);
}
}

void rf_send_nkro(__xdata report_nkro_t *report)
{
__xdata bool blank = true;
for (__xdata int i = 1; i < NKRO_REPORT_SIZE - 1; i++) {
if (report->raw[i] != 0) {
blank = false;
}
}

dprintf("is blank: %d\r\n", blank); // FIXME: a delay is necessary here

if (blank) {
// blanking sequence
buffer[1] = 0x00;
rf_cmd_02(buffer);
buffer[1] = 0x01;
rf_cmd_02(buffer);
buffer[1] = 0x00;
rf_cmd_02(buffer);
buffer[1] = 0x01;
rf_cmd_02(buffer);
buffer[1] = 0x00;
rf_cmd_02(buffer);
buffer[1] = 0x01;
rf_cmd_02(buffer);
buffer[1] = 0x00;
rf_cmd_02(buffer);
kro6buffer[1] = 0x00;
rf_cmd_02(kro6buffer);
kro6buffer[1] = 0x01;
rf_cmd_02(kro6buffer);
kro6buffer[1] = 0x00;
rf_cmd_02(kro6buffer);
kro6buffer[1] = 0x01;
rf_cmd_02(kro6buffer);
kro6buffer[1] = 0x00;
rf_cmd_02(kro6buffer);
kro6buffer[1] = 0x01;
rf_cmd_02(kro6buffer);
kro6buffer[1] = 0x00;
rf_cmd_02(kro6buffer);
} else {
rf_cmd_02(buffer);
rf_cmd_02_nkro(report->mods, report->bits);
}
}

void rf_send_extra(report_extra_t *report)
void rf_send_extra(__xdata report_extra_t *report)
{
switch (report->report_id) {
case REPORT_ID_SYSTEM:
Expand Down Expand Up @@ -215,7 +248,6 @@ void rf_cmd_02(uint8_t *buffer)
rf_tx_buf[6] = buffer[3];
rf_tx_buf[7] = buffer[4];
rf_tx_buf[8] = buffer[5];
// FIXME: last keyboard report key is lost
rf_tx_buf[9] = 0x00; // 0x00 or 0x01

for (int i = 10; i < 31; i++) { // FIXME: NKRO bytes are blanked out until they are implemented
Expand All @@ -227,6 +259,51 @@ void rf_cmd_02(uint8_t *buffer)
bb_spi_xfer(rf_tx_buf, len);
}

void rf_cmd_02_nkro(__xdata uint8_t mods, __xdata uint8_t *nkro_buffer)
{
const uint8_t len = 32;

rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = CMD_REPORT;
rf_tx_buf[3] = mods;

rf_tx_buf[4] = 0x00;
rf_tx_buf[5] = 0x00;
rf_tx_buf[6] = 0x00;
rf_tx_buf[7] = 0x00;
rf_tx_buf[8] = 0x00;

rf_tx_buf[9] = 0x00; // 0x00 or 0x01

rf_tx_buf[10] = nkro_buffer[0];
rf_tx_buf[11] = nkro_buffer[1];
rf_tx_buf[12] = nkro_buffer[2];
rf_tx_buf[13] = nkro_buffer[3];
rf_tx_buf[14] = nkro_buffer[4];
rf_tx_buf[15] = nkro_buffer[5];
rf_tx_buf[16] = nkro_buffer[6];
rf_tx_buf[17] = nkro_buffer[7];
rf_tx_buf[18] = nkro_buffer[8];
rf_tx_buf[19] = nkro_buffer[9];
rf_tx_buf[20] = nkro_buffer[10];
rf_tx_buf[21] = nkro_buffer[11];
rf_tx_buf[22] = nkro_buffer[12];
rf_tx_buf[23] = nkro_buffer[13];
rf_tx_buf[24] = nkro_buffer[14];
rf_tx_buf[25] = nkro_buffer[15];
rf_tx_buf[26] = nkro_buffer[16];
rf_tx_buf[27] = nkro_buffer[17];
rf_tx_buf[28] = nkro_buffer[18];
rf_tx_buf[29] = nkro_buffer[19];

rf_tx_buf[30] = 0x00;

rf_tx_buf[31] = checksum(rf_tx_buf, len - 1);

bb_spi_xfer(rf_tx_buf, len);
}

void rf_cmd_03(uint8_t param) // ?? or 0x02
{
const uint8_t len = 6;
Expand Down
5 changes: 3 additions & 2 deletions src/platform/bk3632/rf_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "keyboard.h"

void rf_init();
void rf_send_report(report_keyboard_t *report);
void rf_send_extra(report_extra_t *report);
void rf_send_report(__xdata report_keyboard_t *report);
void rf_send_nkro(__xdata report_nkro_t *report);
void rf_send_extra(__xdata report_extra_t *report);
void rf_update_keyboard_state(keyboard_state_t *keyboard);
12 changes: 6 additions & 6 deletions src/platform/sh68f90a/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ const uint8_t hid_report_desc_extra[] = {

// NKRO
HID_RI_USAGE_PAGE(8, 0x07), // Keyboard/Keypad
HID_RI_USAGE_MINIMUM(8, 0x00), // was 0x04
HID_RI_USAGE_MAXIMUM(8, NKRO_REPORT_BITS * 8 - 1), // was 0x70
HID_RI_USAGE_MINIMUM(8, 0x00),
HID_RI_USAGE_MAXIMUM(8, NKRO_REPORT_BITS * 8 - 1),
HID_RI_LOGICAL_MINIMUM(8, 0x00),
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
HID_RI_REPORT_SIZE(8, 1),
HID_RI_REPORT_COUNT(8, NKRO_REPORT_BITS * 8), // was 120
HID_RI_REPORT_COUNT(8, NKRO_REPORT_BITS * 8),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
HID_RI_END_COLLECTION(0),
#endif // NKRO_ENABLE
Expand Down Expand Up @@ -201,8 +201,8 @@ usb_desc_endpoint_c usb_desc_endpoint_main = {
.bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = 1 | USB_DIR_IN,
.bmAttributes = USB_XFER_INTERRUPT,
.wMaxPacketSize = 8, // 8 bytes
.bInterval = 1, // 1ms
.wMaxPacketSize = 16, // 16 bytes
.bInterval = 1, // 1ms
};

usb_desc_interface_c usb_desc_interface_extra = {
Expand Down Expand Up @@ -232,7 +232,7 @@ usb_desc_endpoint_c usb_desc_endpoint_extra = {
.bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = 2 | USB_DIR_IN,
.bmAttributes = USB_XFER_INTERRUPT,
.wMaxPacketSize = 16, // 16 bytes
.wMaxPacketSize = 64, // 64 bytes
.bInterval = 1, // 1ms
};

Expand Down
4 changes: 2 additions & 2 deletions src/smk/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
static __xdata uint16_t last_system_usage = 0;
static __xdata uint16_t last_consumer_usage = 0;

void host_keyboard_send(report_keyboard_t *report)
void host_keyboard_send(__xdata report_keyboard_t *report)
{
kb_send_report(report);
}

void host_nkro_send(report_nkro_t *report)
void host_nkro_send(__xdata report_nkro_t *report)
{
kb_send_nkro(report);
}
Expand Down
4 changes: 2 additions & 2 deletions src/smk/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdint.h>
#include "report.h"

void host_keyboard_send(report_keyboard_t *report);
void host_nkro_send(report_nkro_t *report);
void host_keyboard_send(__xdata report_keyboard_t *report);
void host_nkro_send(__xdata report_nkro_t *report);
void host_system_send(uint16_t usage);
void host_consumer_send(uint16_t usage);
2 changes: 1 addition & 1 deletion src/smk/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define KEYBOARD_REPORT_SIZE 8
#define KEYBOARD_REPORT_KEYS 6

#define NKRO_REPORT_BITS 13
#define NKRO_REPORT_BITS 20 // limited by wireless dongle hid descriptor
#define NKRO_REPORT_SIZE 2 + NKRO_REPORT_BITS

#define EXTRA_REPORT_SIZE 3
Expand Down

0 comments on commit 58b0611

Please sign in to comment.