Migrate Oryx code to modules

This commit is contained in:
Drashna Jael're
2025-03-27 20:59:28 -07:00
parent 4acc7c8baf
commit aa09e7ac79
23 changed files with 157 additions and 146 deletions

View File

@@ -1,16 +0,0 @@
// Copyright 2024 ZSA Technology Labs, Inc <@zsa>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#ifdef ORYX_ENABLE
# ifndef SERIAL_NUMBER
# define SERIAL_NUMBER "default/latest"
# endif // SERIAL_NUMBER
# ifndef RAW_USAGE_PAGE
# define RAW_USAGE_PAGE 0xFF60
# endif // RAW_USAGE_PAGE
# ifndef RAW_USAGE_ID
# define RAW_USAGE_ID 0x61
# endif // RAW_USAGE_ID
#endif // ORYX_ENABLE

View File

@@ -1,13 +1 @@
VPATH += keyboards/zsa/common
POST_CONFIG_H += keyboards/zsa/common/keycode_aliases.h
ifeq ($(strip $(ORYX_ENABLE)), yes)
SRC += keyboards/zsa/common/oryx.c
OPT_DEFS += -DORYX_ENABLE -DORYX_CONFIGURATOR
POST_CONFIG_H += keyboards/zsa/common/config.h
RAW_ENABLE := yes
VIA_ENABLE := no
RGB_MATRIX_CUSTOM_KB = yes
else
endif

View File

@@ -22,6 +22,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "bootmagic.h"
#include "gpio.h"
#ifdef COMMUNITY_MODULE_ORYX_ENABLE
# include "oryx.h"
#endif // COMMUNITY_MODULE_ORYX_ENABLE
keyboard_config_t keyboard_config;
__attribute__((weak)) void keyboard_post_init_sub(void) {
@@ -254,14 +258,6 @@ __attribute__((weak)) const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] =
#endif
#ifdef ORYX_ENABLE
layer_state_t layer_state_set_kb(layer_state_t state) {
state = layer_state_set_user(state);
layer_state_set_oryx(state);
return state;
}
#endif
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case LED_LEVEL:

View File

@@ -24,9 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h>
#include <stdbool.h>
#include "i2c_master.h"
#ifdef ORYX_ENABLE
# include "oryx.h"
#endif // ORYX_ENABLE
extern i2c_status_t mcp23018_status;

View File

@@ -0,0 +1,5 @@
{
"modules": [
"zsa/oryx"
]
}

View File

@@ -1 +0,0 @@
ORYX_ENABLE = yes

View File

@@ -1,2 +1 @@
ORYX_ENABLE = yes
LAYER_LOCK_ENABLE = yes

View File

@@ -17,7 +17,10 @@
*/
#include QMK_KEYBOARD_H
#include "moonlander.h"
#ifdef COMMUNITY_MODULE_ORYX_ENABLE
# include "oryx.h"
#endif // COMMUNITY_MODULE_ORYX_ENABLE
keyboard_config_t keyboard_config;
@@ -150,10 +153,11 @@ void keyboard_pre_init_kb(void) {
layer_state_t layer_state_set_kb(layer_state_t state) {
#if !defined(MOONLANDER_USER_LEDS)
state = layer_state_set_user(state);
# ifdef ORYX_ENABLE
layer_state_set_oryx(state);
if (rawhid_state.status_led_control) return state;
# endif
# ifdef COMMUNITY_MODULE_ORYX_ENABLE
if (rawhid_state.status_led_control) {
return state;
}
# endif // COMMUNITY_MODULE_ORYX_ENABLE
if (is_launching || !keyboard_config.led_level) return state;
bool LED_1 = false;
bool LED_2 = false;

View File

@@ -21,9 +21,6 @@
#pragma once
#include "quantum.h"
#ifdef ORYX_ENABLE
# include "oryx.h"
#endif // ORYX_ENABLE
extern bool mcp23018_leds[];

View File

@@ -15,11 +15,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "planck_ez.h"
#include QMK_KEYBOARD_H
#include <ch.h>
#include <hal.h>
#include "keycodes.h"
#ifdef COMMUNITY_MODULE_ORYX_ENABLE
# include "oryx.h"
#endif // COMMUNITY_MODULE_ORYX_ENABLE
keyboard_config_t keyboard_config;
@@ -119,7 +123,7 @@ void keyboard_pre_init_kb(void) {
}
// read kb settings from eeprom
keyboard_config.raw = eeconfig_read_kb();
#if defined(RGB_MATRIX_ENABLE) && defined(ORYX_CONFIGURATOR)
#if defined(RGB_MATRIX_ENABLE)
if (keyboard_config.rgb_matrix_enable) {
rgb_matrix_set_flags(LED_FLAG_ALL);
} else {
@@ -130,7 +134,7 @@ void keyboard_pre_init_kb(void) {
keyboard_pre_init_user();
}
#if defined(RGB_MATRIX_ENABLE) && defined(ORYX_CONFIGURATOR)
#if defined(RGB_MATRIX_ENABLE)
void keyboard_post_init_kb(void) {
rgb_matrix_enable_noeeprom();
keyboard_post_init_user();
@@ -178,9 +182,6 @@ layer_state_t layer_state_set_kb(layer_state_t state) {
default:
break;
}
#ifdef ORYX_ENABLE
layer_state_set_oryx(state);
#endif
return state;
}
#endif

View File

@@ -18,9 +18,6 @@
#pragma once
#include "quantum.h"
#ifdef ORYX_ENABLE
# include "oryx.h"
#endif // ORYX_ENABLE
void planck_ez_right_led_on(void);
void planck_ez_right_led_off(void);

View File

@@ -0,0 +1,5 @@
{
"modules": [
"zsa/oryx"
]
}

View File

@@ -1,3 +1,2 @@
ORYX_ENABLE = yes
TAP_DANCE_ENABLE = yes
LAYER_LOCK_ENABLE = yes

View File

@@ -2,7 +2,11 @@
// Copyright 2023 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
// SPDX-License-Identifier: GPL-2.0-or-later
#include "voyager.h"
#include QMK_KEYBOARD_H
#ifdef COMMUNITY_MODULE_ORYX_ENABLE
# include "oryx.h"
#endif // COMMUNITY_MODULE_ORYX_ENABLE
keyboard_config_t keyboard_config;
@@ -104,9 +108,10 @@ void keyboard_pre_init_kb(void) {
layer_state_t layer_state_set_kb(layer_state_t state) {
state = layer_state_set_user(state);
#if !defined(VOYAGER_USER_LEDS)
# ifdef ORYX_ENABLE
layer_state_set_oryx(state);
if (rawhid_state.status_led_control) return state;
# ifdef COMMUNITY_MODULE_ORYX_ENABLE
if (rawhid_state.status_led_control) {
return state;
}
# endif
if (is_launching || !keyboard_config.led_level) return state;
uint8_t layer = get_highest_layer(state);

View File

@@ -5,9 +5,6 @@
#pragma once
#include "quantum.h"
#ifdef ORYX_ENABLE
# include "oryx.h"
#endif // ORYX_ENABLE
extern bool mcp23018_leds[];

10
modules/zsa/oryx/config.h Normal file
View File

@@ -0,0 +1,10 @@
// Copyright 2024 ZSA Technology Labs, Inc <@zsa>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#define RAW_USAGE_PAGE 0xFF60
#define RAW_USAGE_ID 0x61
#define ORYX_ENABLE
#define ORYX_CONFIGURATOR

View File

@@ -1,22 +1,24 @@
// Copyright 2024 ZSA Technology Labs, Inc <@zsa>
// SPDX-License-Identifier: GPL-2.0-or-later
#include <string.h>
#include QMK_KEYBOARD_H
#include <string.h>
#include "oryx.h"
#include "action_util.h"
ASSERT_COMMUNITY_MODULES_MIN_API_VERSION(1, 1, 0);
uint8_t current_layer = 0;
rawhid_state_t rawhid_state = {
.paired = false,
.rgb_control = false,
.paired = false,
.rgb_control = false,
.status_led_control = false,
};
#if defined(PROTOCOL_LUFA)
bool send_report(uint8_t endpoint, void *report, size_t size);
#include "usb_descriptor.h"
# include "usb_descriptor.h"
# define RAW_EP_NAME RAW_IN_EPNUM
#elif defined(PROTOCOL_CHIBIOS)
# include "usb_endpoints.h"
@@ -33,26 +35,26 @@ void raw_hid_send_oryx(uint8_t *data, uint8_t length) {
return;
}
if (!send_report(RAW_EP_NAME, data, length)) {
#if !defined(PROTOCOL_LUFA)
#if !defined(PROTOCOL_LUFA)
rawhid_state.paired = false;
#endif
#endif
}
}
void oryx_error(uint8_t code) {
uint8_t event[RAW_EPSIZE];
event[0] = ORYX_EVT_ERROR;
event[1] = code;
event[0] = ORYX_EVT_ERROR;
event[1] = code;
raw_hid_send_oryx(event, RAW_EPSIZE);
}
void oryx_layer_event(void) {
uint8_t layer;
uint8_t event[RAW_EPSIZE];
layer = get_highest_layer(layer_state);
event[0] = ORYX_EVT_LAYER;
event[1] = layer;
event[2] = ORYX_STOP_BIT;
layer = get_highest_layer(layer_state);
event[0] = ORYX_EVT_LAYER;
event[1] = layer;
event[2] = ORYX_STOP_BIT;
raw_hid_send_oryx(event, sizeof(event));
}
@@ -74,15 +76,15 @@ void pairing_success_event(void) {
void toggle_smart_layer(void) {
uint8_t event[RAW_EPSIZE];
event[0] = ORYX_EVT_TOGGLE_SMART_LAYER;
event[1] = ORYX_STOP_BIT;
event[0] = ORYX_EVT_TOGGLE_SMART_LAYER;
event[1] = ORYX_STOP_BIT;
raw_hid_send_oryx(event, sizeof(event));
}
void trigger_smart_layer(void) {
uint8_t event[RAW_EPSIZE];
event[0] = ORYX_EVT_TRIGGER_SMART_LAYER;
event[1] = ORYX_STOP_BIT;
event[0] = ORYX_EVT_TRIGGER_SMART_LAYER;
event[1] = ORYX_STOP_BIT;
raw_hid_send_oryx(event, sizeof(event));
}
@@ -109,30 +111,32 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
uint8_t *param = &data[1];
switch (command) {
case ORYX_CMD_GET_FW_VERSION: {
uint8_t event[RAW_EPSIZE];
uint8_t fw_version_size = sizeof(SERIAL_NUMBER);
uint8_t stop[1];
case ORYX_CMD_GET_FW_VERSION:
{
uint8_t event[RAW_EPSIZE];
uint8_t fw_version_size = sizeof(SERIAL_NUMBER);
uint8_t stop[1];
event[0] = ORYX_EVT_GET_FW_VERSION;
stop[0] = ORYX_STOP_BIT;
event[0] = ORYX_EVT_GET_FW_VERSION;
stop[0] = ORYX_STOP_BIT;
memcpy(event + 1, SERIAL_NUMBER, fw_version_size);
memcpy(event + fw_version_size, stop, 1);
memcpy(event + 1, SERIAL_NUMBER, fw_version_size);
memcpy(event + fw_version_size, stop, 1);
raw_hid_send_oryx(event, RAW_EPSIZE);
break;
}
raw_hid_send_oryx(event, RAW_EPSIZE);
break;
}
case ORYX_GET_PROTOCOL_VERSION: {
uint8_t event[RAW_EPSIZE];
event[0] = ORYX_EVT_GET_PROTOCOL_VERSION;
event[1] = ORYX_PROTOCOL_VERSION;
event[2] = ORYX_STOP_BIT;
case ORYX_GET_PROTOCOL_VERSION:
{
uint8_t event[RAW_EPSIZE];
event[0] = ORYX_EVT_GET_PROTOCOL_VERSION;
event[1] = ORYX_PROTOCOL_VERSION;
event[2] = ORYX_STOP_BIT;
raw_hid_send_oryx(event, RAW_EPSIZE);
break;
}
raw_hid_send_oryx(event, RAW_EPSIZE);
break;
}
case ORYX_CMD_PAIRING_INIT:
pairing_success_event();
@@ -160,8 +164,8 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
set_webhid_effect();
}
uint8_t event[RAW_EPSIZE];
event[0] = ORYX_EVT_RGB_CONTROL;
event[1] = rawhid_state.rgb_control;
event[0] = ORYX_EVT_RGB_CONTROL;
event[1] = rawhid_state.rgb_control;
raw_hid_send_oryx(event, RAW_EPSIZE);
#else
oryx_error(ORYX_ERR_RGB_MATRIX_NOT_ENABLED);
@@ -241,79 +245,87 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
break;
}
break;
case ORYX_UPDATE_BRIGHTNESS: {
case ORYX_UPDATE_BRIGHTNESS:
{
#if defined(RGB_MATRIX_ENABLE) && !defined(PROTOCOL_LUFA)
if (param[0]) {
rgb_matrix_increase_val_noeeprom();
} else {
rgb_matrix_decrease_val_noeeprom();
}
if (param[0]) {
rgb_matrix_increase_val_noeeprom();
} else {
rgb_matrix_decrease_val_noeeprom();
}
#else
oryx_error(ORYX_ERR_RGB_MATRIX_NOT_ENABLED);
oryx_error(ORYX_ERR_RGB_MATRIX_NOT_ENABLED);
#endif
break;
}
case ORYX_STATUS_LED_CONTROL: {
rawhid_state.status_led_control = param[0];
if (!param[0]) {
break;
}
case ORYX_STATUS_LED_CONTROL:
{
rawhid_state.status_led_control = param[0];
if (!param[0]) {
#ifdef STATUS_LED_1
STATUS_LED_1(0);
STATUS_LED_1(0);
#endif
#ifdef STATUS_LED_2
STATUS_LED_2(0);
STATUS_LED_2(0);
#endif
#ifdef STATUS_LED_3
STATUS_LED_3(0);
STATUS_LED_3(0);
#endif
#ifdef STATUS_LED_4
STATUS_LED_4(0);
STATUS_LED_4(0);
#endif
#ifdef STATUS_LED_5
STATUS_LED_5(0);
STATUS_LED_5(0);
#endif
#ifdef STATUS_LED_6
STATUS_LED_6(0);
STATUS_LED_6(0);
#endif
}
uint8_t event[RAW_EPSIZE];
event[0] = ORYX_EVT_STATUS_LED_CONTROL;
event[1] = rawhid_state.status_led_control;
raw_hid_send_oryx(event, RAW_EPSIZE);
break;
}
uint8_t event[RAW_EPSIZE];
event[0] = ORYX_EVT_STATUS_LED_CONTROL;
event[1] = rawhid_state.status_led_control;
raw_hid_send_oryx(event, RAW_EPSIZE);
break;
}
default:
oryx_error(ORYX_ERR_UNKNOWN_COMMAND);
}
}
bool pre_process_record_kb(uint16_t keycode, keyrecord_t *record) {
bool pre_process_record_oryx(uint16_t keycode, keyrecord_t *record) {
if (!pre_process_record_oryx_kb(keycode, record)) {
return false;
}
// While paired, the keyboard sends keystrokes positions to the host
if (rawhid_state.paired == true) {
uint8_t event[RAW_EPSIZE];
event[0] = record->event.pressed ? ORYX_EVT_KEYDOWN : ORYX_EVT_KEYUP;
event[1] = record->event.key.col;
event[2] = record->event.key.row;
event[3] = ORYX_STOP_BIT;
event[0] = record->event.pressed ? ORYX_EVT_KEYDOWN : ORYX_EVT_KEYUP;
event[1] = record->event.key.col;
event[2] = record->event.key.row;
event[3] = ORYX_STOP_BIT;
raw_hid_send_oryx(event, sizeof(event));
}
return true;
}
void layer_state_set_oryx(layer_state_t state) {
layer_state_t layer_state_set_oryx(layer_state_t state) {
if (rawhid_state.paired) {
uint8_t layer = get_highest_layer(state);
// Some layer actions (OSL) trigger the layer state change thrice,
// so we need to check if the layer has actually changed
if (current_layer == layer) return;
if (current_layer == layer) {
return layer_state_set_oryx_kb(state);
}
current_layer = layer;
#if defined(PROTOCOL_LUFA)
// Required for Atmel Boards
wait_ms(10);
#endif
uint8_t event[RAW_EPSIZE];
event[0] = ORYX_EVT_LAYER;
event[1] = current_layer;
event[2] = ORYX_STOP_BIT;
event[0] = ORYX_EVT_LAYER;
event[1] = current_layer;
event[2] = ORYX_STOP_BIT;
raw_hid_send_oryx(event, sizeof(event));
}
return layer_state_set_oryx_kb(state);
}

View File

@@ -5,27 +5,27 @@
/*
The Oryx Webhid protocol
Each HID packet is a series of bytes. The first byte is the packet type is the command. The rest of the bytes are the params.
Each HID packet is a series of bytes. The first byte is the packet type is the command. The rest of the bytes are the
params.
Before sending a packet, the host needs to be paired or should request a pairing code.
The pairing code is a sequence of key positions derived from Oryx's firmware version code stored in the FIRMWARE_VERSION define.
The pairing code is a sequence of key positions derived from Oryx's firmware version code stored in the FIRMWARE_VERSION
define.
Once the host has paired, it can freely use the commands define in the Oryx_Command_Code enum for which the board will always respond with a Oryx_Event_Code or a Oryx_Error_Code.
Once the host has paired, it can freely use the commands define in the Oryx_Command_Code enum for which the board will
always respond with a Oryx_Event_Code or a Oryx_Error_Code.
*/
#include "quantum.h"
#include "raw_hid.h"
#ifndef RAW_ENABLE
# error "Raw hid needs to be enabled, please enable it!"
#endif
#ifndef RAW_EPSIZE
# define RAW_EPSIZE 32
#endif
#define ORYX_PROTOCOL_VERSION 0x04
#define ORYX_STOP_BIT -2
#define ORYX_STOP_BIT -2
enum Oryx_Command_Code {
ORYX_CMD_GET_FW_VERSION,
@@ -87,8 +87,6 @@ void trigger_smart_layer(void);
void set_webhid_effect(void);
void oryx_layer_event(void);
void layer_state_set_oryx(layer_state_t state);
#if defined(RGB_MATRIX_ENABLE) && !defined(KEYBOARD_ergodox_ez_glow)
extern RGB webhid_leds[RGB_MATRIX_LED_COUNT];

View File

@@ -0,0 +1,8 @@
// Copyright 2024 ZSA Technology Labs, Inc <@zsa>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#ifndef SERIAL_NUMBER
# define SERIAL_NUMBER "default/latest"
#endif // SERIAL_NUMBER

View File

@@ -0,0 +1,8 @@
{
"maintainer": "drashna",
"module_name": "oryx",
"features": {
"raw": true,
"via": false
}
}

View File

@@ -0,0 +1,2 @@
POST_CONFIG_H += keyboards/zsa/common/keycode_aliases.h
RGB_MATRIX_CUSTOM_KB = yes