Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra keys (system & consumer) for usb and rf #23

Merged
merged 4 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/kb/kb.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

void kb_init();
void kb_send_report(report_keyboard_t *report);
void kb_send_extra(report_extra_t *report);

bool kb_process_record(uint16_t keycode, bool key_pressed);
void kb_update_switches();
void kb_update();
5 changes: 5 additions & 0 deletions src/keyboards/example/kb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ void kb_send_report(report_keyboard_t *report)
{
usb_send_report(report);
}

void kb_send_extra(report_extra_t *report)
{
usb_send_extra(report);
}
5 changes: 5 additions & 0 deletions src/keyboards/eyooso-z11/kb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ void kb_send_report(report_keyboard_t *report)
{
usb_send_report(report);
}

void kb_send_extra(report_extra_t *report)
{
usb_send_extra(report);
}
14 changes: 14 additions & 0 deletions src/keyboards/nuphy-air60/kb.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ void kb_send_report(report_keyboard_t *report)
}
}

void kb_send_extra(report_extra_t *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;

void kb_update()
Expand Down
30 changes: 24 additions & 6 deletions src/keyboards/nuphy-air60/layouts/default/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
// The underscores don't mean anything - you can have a layer called STUFF or any other name.
// Layer names don't all need to be of the same length, obviously, and you can also skip them
// entirely and just use numbers.
#define _BL 0
#define _FL 1
#define _MAC_BL 0
#define _WIN_BL 1
#define _MAC_FL 2
#define _WIN_FL 3

enum custom_keycodes {
SFT_ESC = KB_SAFE_RANGE,
};

const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Keymap _BL: (Base Layer) Default Layer
/* Keymap _WIN_BL: (Base Layer) Default Layer
* ,------------------------------------------------------------.
* |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| Backsp|
* |------------------------------------------------------------|
Expand All @@ -45,12 +47,28 @@ const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* |Ctrl|Alt |Gui | Space |Gui|Fn |Lef|Dow|Rig|
* `------------------------------------------------------------'
*/
[_BL] = LAYOUT_60(
[_MAC_BL] = LAYOUT_60(
SFT_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS,
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_DEL,
KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, KC_LGUI, MO(_FL), KC_LEFT, KC_DOWN, KC_RGHT
KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_LGUI, MO(_MAC_FL), KC_LEFT, KC_DOWN, KC_RGHT
),

[_WIN_BL] = LAYOUT_60(
SFT_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS,
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_DEL,
KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, KC_LGUI, MO(_WIN_FL), KC_LEFT, KC_DOWN, KC_RGHT
),

[_MAC_FL] = LAYOUT_60(
KC_GRV, KC_BRID, KC_BRIU, KC_MCTL, KC_ASST, BL_DOWN, BL_UP, KC_MRWD, KC_MPLY, KC_MFFD, KC_MUTE, KC_VOLD, KC_VOLU, KC_DEL,
_______, LNK_BT1, LNK_BT2, LNK_BT3, LNK_24G, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______
),

/* Keymap _FL: (Base Layer) Function Layer
Expand All @@ -66,7 +84,7 @@ const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* | | | | | | | | | |
* `------------------------------------------------------------'
*/
[_FL] = LAYOUT_60(
[_WIN_FL] = LAYOUT_60(
KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL,
_______, LNK_BT1, LNK_BT2, LNK_BT3, LNK_24G, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
Expand Down
138 changes: 95 additions & 43 deletions src/platform/bk3632/rf_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ 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 consumer, uint16_t system);
void rf_cmd_06(uint8_t param);
void rf_cmd_07(uint8_t param);
void rf_cmd_08(uint8_t type, char *name);
void rf_cmd_0a();
void rf_cmd_0b();
void rf_cmd_0c();
void rf_fetch_4();
uint8_t checksum(uint8_t *data, int len);
Expand All @@ -63,7 +65,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, 0);
delay_ms(30);
rf_send_blank_report();
}
Expand Down Expand Up @@ -107,6 +109,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:
rf_cmd_05(0, report->usage);
break;
case REPORT_ID_CONSUMER:
rf_cmd_05(report->usage, 0);
break;
}
}

void rf_update_keyboard_state(keyboard_state_t *keyboard)
{
__xdata uint8_t status_bytes[2];
Expand Down Expand Up @@ -177,11 +191,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 +218,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 bytes are blanked out until they are implemented
rf_tx_buf[i] = 0x00;
}

Expand All @@ -216,11 +231,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 +249,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 consumer, uint16_t system)
{
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] = consumer & 0xff;
rf_tx_buf[10] = consumer >> 8;
rf_tx_buf[11] = system & 0xff;
rf_tx_buf[12] = system >> 8;

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

bb_spi_xfer(rf_tx_buf, len);
Expand All @@ -264,11 +282,27 @@ 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);
}

void rf_cmd_07(uint8_t param)
{
const uint8_t len = 6;

rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x07;
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 +325,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 +335,27 @@ 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);
}

void rf_cmd_0b()
{
const uint8_t len = 6;

rf_tx_buf[0] = MAGIC_BYTE;
rf_tx_buf[1] = len - 3;
rf_tx_buf[2] = 0x0b;
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 +365,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);
Loading
Loading