Skip to content

Commit

Permalink
consumer keys on rf
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossless committed Dec 22, 2024
1 parent 4673fef commit 8345ee9
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 51 deletions.
11 changes: 10 additions & 1 deletion src/keyboards/nuphy-air60/kb.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ void kb_send_report(report_keyboard_t *report)

void kb_send_extra(report_extra_t *report)
{
usb_send_extra(report);
switch (user_keyboard_state.conn_mode) {
case KEYBOARD_CONN_MODE_USB:
usb_send_extra(report);
break;
#ifdef RF_ENABLED
case KEYBOARD_CONN_MODE_RF:
rf_send_extra(report);
break;
#endif
}
}

uint16_t ticks = 0;
Expand Down
106 changes: 63 additions & 43 deletions src/platform/bk3632/rf_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void rf_cmd_01(uint8_t mode, uint8_t pairing);
void rf_cmd_02(uint8_t *buffer);
void rf_cmd_03(uint8_t param);
void rf_cmd_04();
void rf_cmd_05();
void rf_cmd_05(uint16_t data);
void rf_cmd_06(uint8_t param);
void rf_cmd_08(uint8_t type, char *name);
void rf_cmd_0a();
Expand Down Expand Up @@ -63,7 +63,7 @@ void rf_init()
delay_ms(20);
rf_cmd_01(RF_MODE_2_4G, RF_PAIRING_OFF);
delay_ms(15);
rf_cmd_05();
rf_cmd_05(0);
delay_ms(30);
rf_send_blank_report();
}
Expand Down Expand Up @@ -107,6 +107,18 @@ void rf_send_report(report_keyboard_t *report)
}
}

void rf_send_extra(report_extra_t *report)
{
switch (report->report_id) {
case REPORT_ID_SYSTEM:
// TODO: implement
break;
case REPORT_ID_CONSUMER:
rf_cmd_05(report->usage);
break;
}
}

void rf_update_keyboard_state(keyboard_state_t *keyboard)
{
__xdata uint8_t status_bytes[2];
Expand Down Expand Up @@ -177,11 +189,12 @@ void rf_cmd_01(uint8_t mode, uint8_t pairing)
{
const uint8_t len = 6;

rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x01;
rf_tx_buf[3] = mode;
rf_tx_buf[4] = pairing;
rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x01;
rf_tx_buf[3] = mode;
rf_tx_buf[4] = pairing;

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

bb_spi_xfer(rf_tx_buf, 6);
Expand All @@ -203,7 +216,7 @@ void rf_cmd_02(uint8_t *buffer)
// FIXME: last keyboard report key is lost
rf_tx_buf[9] = 0x00; // 0x00 or 0x01

for (int i = 10; i < 31; i++) { // FIXME: NKRO / Media Keys bytes are blanked out until they are implemented
for (int i = 10; i < 31; i++) { // FIXME: NKRO / Extra Keys bytes are blanked out until they are implemented
rf_tx_buf[i] = 0x00;
}

Expand All @@ -216,11 +229,12 @@ void rf_cmd_03(uint8_t param) // ?? or 0x02
{
const uint8_t len = 6;

rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x03;
rf_tx_buf[3] = param;
rf_tx_buf[4] = 0x00;
rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x03;
rf_tx_buf[3] = param;
rf_tx_buf[4] = 0x00;

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

bb_spi_xfer(rf_tx_buf, 6);
Expand All @@ -233,28 +247,30 @@ void rf_cmd_04()
rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x04;
rf_tx_buf[3] = checksum(rf_tx_buf, 3);

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

bb_spi_xfer(rf_tx_buf, 4);
}

void rf_cmd_05()
void rf_cmd_05(uint16_t data) // Consumer Keys
{
const uint8_t len = 14;

rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x05;
rf_tx_buf[3] = 0x00;
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;
rf_tx_buf[10] = 0x00;
rf_tx_buf[11] = 0x00;
rf_tx_buf[12] = 0x00;
rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x05;
rf_tx_buf[3] = 0x00;
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] = data & 0xff;
rf_tx_buf[10] = data >> 8;
rf_tx_buf[11] = 0x00;
rf_tx_buf[12] = 0x00;

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

bb_spi_xfer(rf_tx_buf, len);
Expand All @@ -264,11 +280,12 @@ void rf_cmd_06(uint8_t param) // 0x00 or 0x01
{
const uint8_t len = 6;

rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x06;
rf_tx_buf[3] = param;
rf_tx_buf[4] = 0x00;
rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x06;
rf_tx_buf[3] = param;
rf_tx_buf[4] = 0x00;

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

bb_spi_xfer(rf_tx_buf, len);
Expand All @@ -291,6 +308,7 @@ void rf_cmd_08(uint8_t type, char *name)
for (int j = i; j < (len - 1); j++) {
rf_tx_buf[j] = 0x00;
}

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

bb_spi_xfer(rf_tx_buf, len);
Expand All @@ -300,11 +318,12 @@ void rf_cmd_0a()
{
const uint8_t len = 6;

rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x0a;
rf_tx_buf[3] = 0x00;
rf_tx_buf[4] = 0x00;
rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x0a;
rf_tx_buf[3] = 0x00;
rf_tx_buf[4] = 0x00;

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

bb_spi_xfer(rf_tx_buf, len);
Expand All @@ -314,11 +333,12 @@ void rf_cmd_0c()
{
const uint8_t len = 6;

rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x0c;
rf_tx_buf[3] = 0x00;
rf_tx_buf[4] = 0x00;
rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x0c;
rf_tx_buf[3] = 0x00;
rf_tx_buf[4] = 0x00;

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

bb_spi_xfer(rf_tx_buf, len);
Expand Down
1 change: 1 addition & 0 deletions src/platform/bk3632/rf_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

void rf_init();
void rf_send_report(report_keyboard_t *report);
void rf_send_extra(report_extra_t *report);
void rf_update_keyboard_state(keyboard_state_t *keyboard);
7 changes: 0 additions & 7 deletions src/platform/sh68f90a/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
#include "report.h"
#include <stdint.h>

enum usb_report_id {
REPORT_ID_SYSTEM = 1,
REPORT_ID_CONSUMER = 2,
REPORT_ID_ISP = 5,
REPORT_ID_NKRO = 6,
};

void usb_init();
void usb_send_report(report_keyboard_t *report);
void usb_send_extra(report_extra_t *report);
Expand Down
7 changes: 7 additions & 0 deletions src/smk/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
#define KEYBOARD_REPORT_SIZE 8
#define KEYBOARD_REPORT_KEYS 6

enum report_id {
REPORT_ID_SYSTEM = 1,
REPORT_ID_CONSUMER = 2,
REPORT_ID_ISP = 5,
REPORT_ID_NKRO = 6,
};

/*
* keyboard report is 8-byte array retains state of 8 modifiers and 6 keys.
*
Expand Down

0 comments on commit 8345ee9

Please sign in to comment.