Mock up audio routes to match via

This commit is contained in:
zvecr 2022-12-02 22:48:00 +00:00
parent f99f8a2277
commit 0431558da0
8 changed files with 431 additions and 294 deletions

View File

@ -321,5 +321,76 @@
}
}
}
0x07: {
type: router
name: Audio
define: AUDIO
description:
'''
This subsystem allows for control over the audio subsystem.
'''
enable_if_preprocessor: defined(AUDIO_ENABLE)
routes: {
0x01: {
type: command
name: Capabilities Query
define: CAPABILITIES_QUERY
description:
'''
Audio subsystem capabilities query. Each bit should be considered as a "usable" route within this subsystem.
'''
return_type: u32
return_purpose: capabilities
return_constant: XAP_ROUTE_AUDIO_CAPABILITIES
}
0x03: {
type: command
name: Get Config
define: GET_CONFIG
description: Query the current config.
return_type: struct
return_struct_length: 2
return_struct_members: [
{
type: u8
name: enable
},
{
type: u8
name: clicky_enable
},
]
return_execute: get_audio_config
}
0x04: {
type: command
name: Set Config
define: SET_CONFIG
description: Set the current config.
request_type: struct
request_struct_length: 2
request_struct_members: [
{
type: u8
name: enable
},
{
type: u8
name: clicky_enable
},
]
return_execute: set_audio_config
}
0x05: {
type: command
name: Save Config
define: SAVE_CONFIG
description: Save the current config.
return_execute: save_audio_config
}
}
}
}
}

View File

@ -79,3 +79,8 @@ class XAPRoutes():
LIGHTING_RGB_MATRIX_GET_CONFIG = b'\x06\x04\x03'
LIGHTING_RGB_MATRIX_SET_CONFIG = b'\x06\x04\x04'
LIGHTING_RGB_MATRIX_SAVE_CONFIG = b'\x06\x04\x05'
# AUDIO
AUDIO_CAPABILITIES_QUERY = b'\x07\x01'
AUDIO_GET_CONFIG = b'\x07\x03'
AUDIO_SET_CONFIG = b'\x07\x04'
AUDIO_SAVE_CONFIG = b'\x07\x05'

View File

@ -113,6 +113,8 @@ class XAPConfigRgbMatrix(namedtuple('XAPConfigRgbMatrix', 'enable mode hue sat v
# TODO: gen inbound object for set_config
# TODO: gen outbound object for get_config
# TODO: gen inbound object for set_config
# TODO: gen outbound object for get_config
# TODO: gen inbound object for set_config
class XAPSecureStatus(IntEnum):

View File

@ -0,0 +1,39 @@
// Copyright 2022 QMK
// SPDX-License-Identifier: GPL-2.0-or-later
#include "quantum.h"
#include "xap.h"
#if ((defined(AUDIO_ENABLE)))
# include "audio.h"
extern audio_config_t audio_config;
bool xap_respond_get_audio_config(xap_token_t token, const void *data, size_t length) {
xap_route_audio_get_config_t ret;
ret.enable = audio_config.enable;
ret.clicky_enable = audio_config.clicky_enable;
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_set_audio_config(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_audio_set_config_arg_t)) {
return false;
}
xap_route_audio_set_config_arg_t *arg = (xap_route_audio_set_config_arg_t *)data;
audio_config.enable = arg->enable;
audio_config.clicky_enable = arg->clicky_enable;
return xap_respond_success(token);
}
bool xap_respond_save_audio_config(xap_token_t token, const void *data, size_t length) {
eeconfig_update_audio(audio_config.raw);
return xap_respond_success(token);
}
#endif

View File

@ -0,0 +1,67 @@
// Copyright 2022 QMK
// SPDX-License-Identifier: GPL-2.0-or-later
#include "quantum.h"
#include "xap.h"
#include "hardware_id.h"
bool xap_respond_get_config_blob_chunk(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(uint16_t)) {
return false;
}
uint16_t offset;
memcpy(&offset, data, sizeof(uint16_t));
xap_route_qmk_config_blob_chunk_t ret = {0};
bool get_config_blob_chunk(uint16_t offset, uint8_t * data, uint8_t data_len);
if (!get_config_blob_chunk(offset, (uint8_t *)&ret, sizeof(ret))) {
return false;
}
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_secure_status(xap_token_t token, const void *data, size_t length) {
uint8_t ret = secure_get_status();
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_secure_unlock(xap_token_t token, const void *data, size_t length) {
secure_request_unlock();
return xap_respond_success(token);
}
bool xap_respond_secure_lock(xap_token_t token, const void *data, size_t length) {
secure_lock();
return xap_respond_success(token);
}
#ifdef BOOTLOADER_JUMP_SUPPORTED
bool xap_respond_request_bootloader_jump(xap_token_t token, const void *data, size_t length) {
uint8_t ret = secure_is_unlocked();
// TODO: post to deferred queue so this request can return?
bool res = xap_respond_data(token, &ret, sizeof(ret));
reset_keyboard();
return res;
}
#endif
#ifndef NO_RESET
bool xap_respond_request_eeprom_reset(xap_token_t token, const void *data, size_t length) {
uint8_t ret = secure_is_unlocked();
// TODO: post to deferred queue so this request can return?
bool res = xap_respond_data(token, &ret, sizeof(ret));
eeconfig_disable();
soft_reset_keyboard();
return res;
}
#endif
bool xap_respond_get_hardware_id(xap_token_t token, const void *data, size_t length) {
hardware_id_t ret = get_hardware_id();
return xap_respond_data(token, &ret, sizeof(ret));
}

View File

@ -0,0 +1,159 @@
// Copyright 2022 QMK
// SPDX-License-Identifier: GPL-2.0-or-later
#include "quantum.h"
#include "xap.h"
#define INVALID_EFFECT 0xFF
#if ((defined(BACKLIGHT_ENABLE)))
# include "backlight.h"
extern backlight_config_t backlight_config;
bool xap_respond_get_backlight_config(xap_token_t token, const void *data, size_t length) {
xap_route_lighting_backlight_get_config_t ret;
ret.enable = backlight_config.enable;
ret.mode = backlight_config.breathing;
ret.val = backlight_config.level;
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_set_backlight_config(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_lighting_backlight_set_config_arg_t)) {
return false;
}
xap_route_lighting_backlight_set_config_arg_t *arg = (xap_route_lighting_backlight_set_config_arg_t *)data;
if (arg->enable) {
backlight_level_noeeprom(arg->val);
} else {
backlight_level_noeeprom(0);
}
# ifdef BACKLIGHT_BREATHING
if (arg->mode) {
backlight_enable_breathing();
} else {
backlight_disable_breathing();
}
# endif
return xap_respond_success(token);
}
bool xap_respond_save_backlight_config(xap_token_t token, const void *data, size_t length) {
eeconfig_update_backlight_current();
return xap_respond_success(token);
}
#endif
#if ((defined(RGBLIGHT_ENABLE)))
# include "rgblight.h"
extern rgblight_config_t rgblight_config;
uint8_t rgblight2xap(uint8_t val);
uint8_t xap2rgblight(uint8_t val);
void rgblight_enabled_noeeprom(bool val) {
val ? rgblight_enable_noeeprom() : rgblight_disable_noeeprom();
}
bool xap_respond_get_rgblight_config(xap_token_t token, const void *data, size_t length) {
xap_route_lighting_rgblight_get_config_t ret;
ret.enable = rgblight_config.enable;
ret.mode = rgblight2xap(rgblight_config.mode);
ret.hue = rgblight_config.hue;
ret.sat = rgblight_config.sat;
ret.val = rgblight_config.val;
ret.speed = rgblight_config.speed;
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_set_rgblight_config(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_lighting_rgblight_set_config_arg_t)) {
return false;
}
xap_route_lighting_rgblight_set_config_arg_t *arg = (xap_route_lighting_rgblight_set_config_arg_t *)data;
uint8_t mode = xap2rgblight(arg->mode);
if (mode == INVALID_EFFECT) {
return false;
}
rgblight_enabled_noeeprom(arg->enable);
rgblight_mode_noeeprom(mode);
rgblight_sethsv_noeeprom(arg->hue, arg->sat, arg->val);
rgblight_set_speed_noeeprom(arg->speed);
return xap_respond_success(token);
}
bool xap_respond_save_rgblight_config(xap_token_t token, const void *data, size_t length) {
eeconfig_update_rgblight_current();
return xap_respond_success(token);
}
#endif
#if ((defined(RGB_MATRIX_ENABLE)))
# include "rgb_matrix.h"
extern rgb_config_t rgb_matrix_config;
uint8_t rgb_matrix2xap(uint8_t val);
uint8_t xap2rgb_matrix(uint8_t val);
void rgb_matrix_enabled_noeeprom(bool val) {
val ? rgb_matrix_enable_noeeprom() : rgb_matrix_disable_noeeprom();
}
bool xap_respond_get_rgb_matrix_config(xap_token_t token, const void *data, size_t length) {
xap_route_lighting_rgb_matrix_get_config_t ret;
ret.enable = rgb_matrix_config.enable;
ret.mode = rgb_matrix2xap(rgb_matrix_config.mode);
ret.hue = rgb_matrix_config.hsv.h;
ret.sat = rgb_matrix_config.hsv.s;
ret.val = rgb_matrix_config.hsv.v;
ret.speed = rgb_matrix_config.speed;
ret.flags = rgb_matrix_config.flags;
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_set_rgb_matrix_config(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_lighting_rgb_matrix_set_config_arg_t)) {
return false;
}
xap_route_lighting_rgb_matrix_set_config_arg_t *arg = (xap_route_lighting_rgb_matrix_set_config_arg_t *)data;
uint8_t mode = xap2rgb_matrix(arg->mode);
if (mode == INVALID_EFFECT) {
return false;
}
rgb_matrix_enabled_noeeprom(arg->enable);
rgb_matrix_mode_noeeprom(mode);
rgb_matrix_sethsv_noeeprom(arg->hue, arg->sat, arg->val);
rgb_matrix_set_speed_noeeprom(arg->speed);
rgb_matrix_set_flags_noeeprom(arg->flags);
return xap_respond_success(token);
}
bool xap_respond_save_rgb_matrix_config(xap_token_t token, const void *data, size_t length) {
eeconfig_update_rgb_matrix();
return xap_respond_success(token);
}
#endif

View File

@ -0,0 +1,82 @@
// Copyright 2022 QMK
// SPDX-License-Identifier: GPL-2.0-or-later
#include "quantum.h"
#include "xap.h"
#ifdef DYNAMIC_KEYMAP_ENABLE
# define keymap_max_layer_count() DYNAMIC_KEYMAP_LAYER_COUNT
#else
# define keymap_max_layer_count() keymap_layer_count()
#endif
bool xap_respond_keymap_get_layer_count(xap_token_t token, const void *data, size_t length) {
uint8_t ret = keymap_max_layer_count();
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_get_keymap_keycode(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_keymap_get_keymap_keycode_arg_t)) {
return false;
}
xap_route_keymap_get_keymap_keycode_arg_t *arg = (xap_route_keymap_get_keymap_keycode_arg_t *)data;
if (arg->layer >= keymap_max_layer_count()) {
return false;
}
uint16_t keycode = keycode_at_keymap_location(arg->layer, arg->row, arg->column);
return xap_respond_data(token, &keycode, sizeof(keycode));
}
#if ((defined(ENCODER_MAP_ENABLE)))
bool xap_respond_get_encoder_keycode(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_keymap_get_encoder_keycode_arg_t)) {
return false;
}
xap_route_keymap_get_encoder_keycode_arg_t *arg = (xap_route_keymap_get_encoder_keycode_arg_t *)data;
if (arg->layer >= keymap_max_layer_count()) {
return false;
}
uint16_t keycode = keycode_at_encodermap_location(arg->layer, arg->encoder, arg->clockwise);
return xap_respond_data(token, &keycode, sizeof(keycode));
}
#endif
#if ((defined(DYNAMIC_KEYMAP_ENABLE)))
bool xap_respond_dynamic_keymap_set_keycode(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_remapping_set_keymap_keycode_arg_t)) {
return false;
}
xap_route_remapping_set_keymap_keycode_arg_t *arg = (xap_route_remapping_set_keymap_keycode_arg_t *)data;
if (arg->layer >= keymap_max_layer_count()) {
return false;
}
dynamic_keymap_set_keycode(arg->layer, arg->row, arg->column, arg->keycode);
return xap_respond_success(token);
}
#endif
#if ((defined(DYNAMIC_KEYMAP_ENABLE) && defined(ENCODER_MAP_ENABLE)))
bool xap_respond_dynamic_encoder_set_keycode(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_remapping_set_encoder_keycode_arg_t)) {
return false;
}
xap_route_remapping_set_encoder_keycode_arg_t *arg = (xap_route_remapping_set_encoder_keycode_arg_t *)data;
if (arg->layer >= keymap_max_layer_count()) {
return false;
}
dynamic_keymap_set_encoder(arg->layer, arg->encoder, arg->clockwise, arg->keycode);
return xap_respond_success(token);
}
#endif

View File

@ -15,10 +15,9 @@
*/
#include <string.h>
#include <quantum.h>
#include <xap.h>
#include "quantum.h"
#include "xap.h"
#include "hardware_id.h"
#include "secure.h"
#ifndef SECURE_ENABLE
# define secure_get_status() SECURE_UNLOCKED
@ -26,12 +25,6 @@
# define secure_lock()
#endif
#ifdef DYNAMIC_KEYMAP_ENABLE
# define keymap_max_layer_count() DYNAMIC_KEYMAP_LAYER_COUNT
#else
# define keymap_max_layer_count() keymap_layer_count()
#endif
bool xap_respond_success(xap_token_t token) {
xap_send(token, XAP_RESPONSE_FLAG_SUCCESS, NULL, 0);
return true;
@ -57,288 +50,7 @@ bool xap_respond_u32(xap_token_t token, uint32_t value) {
return true;
}
bool xap_respond_get_config_blob_chunk(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(uint16_t)) {
return false;
}
uint16_t offset;
memcpy(&offset, data, sizeof(uint16_t));
xap_route_qmk_config_blob_chunk_t ret = {0};
bool get_config_blob_chunk(uint16_t offset, uint8_t * data, uint8_t data_len);
if (!get_config_blob_chunk(offset, (uint8_t *)&ret, sizeof(ret))) {
return false;
}
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_secure_status(xap_token_t token, const void *data, size_t length) {
uint8_t ret = secure_get_status();
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_secure_unlock(xap_token_t token, const void *data, size_t length) {
secure_request_unlock();
return xap_respond_success(token);
}
bool xap_respond_secure_lock(xap_token_t token, const void *data, size_t length) {
secure_lock();
return xap_respond_success(token);
}
#ifdef BOOTLOADER_JUMP_SUPPORTED
bool xap_respond_request_bootloader_jump(xap_token_t token, const void *data, size_t length) {
uint8_t ret = secure_is_unlocked();
// TODO: post to deferred queue so this request can return?
bool res = xap_respond_data(token, &ret, sizeof(ret));
reset_keyboard();
return res;
}
#endif
#ifndef NO_RESET
bool xap_respond_request_eeprom_reset(xap_token_t token, const void *data, size_t length) {
uint8_t ret = secure_is_unlocked();
// TODO: post to deferred queue so this request can return?
bool res = xap_respond_data(token, &ret, sizeof(ret));
eeconfig_disable();
soft_reset_keyboard();
return res;
}
#endif
bool xap_respond_get_hardware_id(xap_token_t token, const void *data, size_t length) {
hardware_id_t ret = get_hardware_id();
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_keymap_get_layer_count(xap_token_t token, const void *data, size_t length) {
uint8_t ret = keymap_max_layer_count();
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_get_keymap_keycode(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_keymap_get_keymap_keycode_arg_t)) {
return false;
}
xap_route_keymap_get_keymap_keycode_arg_t *arg = (xap_route_keymap_get_keymap_keycode_arg_t *)data;
if (arg->layer >= keymap_max_layer_count()) {
return false;
}
uint16_t keycode = keycode_at_keymap_location(arg->layer, arg->row, arg->column);
return xap_respond_data(token, &keycode, sizeof(keycode));
}
#if ((defined(ENCODER_MAP_ENABLE)))
bool xap_respond_get_encoder_keycode(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_keymap_get_encoder_keycode_arg_t)) {
return false;
}
xap_route_keymap_get_encoder_keycode_arg_t *arg = (xap_route_keymap_get_encoder_keycode_arg_t *)data;
if (arg->layer >= keymap_max_layer_count()) {
return false;
}
uint16_t keycode = keycode_at_encodermap_location(arg->layer, arg->encoder, arg->clockwise);
return xap_respond_data(token, &keycode, sizeof(keycode));
}
#endif
#if ((defined(DYNAMIC_KEYMAP_ENABLE)))
bool xap_respond_dynamic_keymap_set_keycode(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_remapping_set_keymap_keycode_arg_t)) {
return false;
}
xap_route_remapping_set_keymap_keycode_arg_t *arg = (xap_route_remapping_set_keymap_keycode_arg_t *)data;
if (arg->layer >= keymap_max_layer_count()) {
return false;
}
dynamic_keymap_set_keycode(arg->layer, arg->row, arg->column, arg->keycode);
return xap_respond_success(token);
}
#endif
#if ((defined(DYNAMIC_KEYMAP_ENABLE) && defined(ENCODER_MAP_ENABLE)))
bool xap_respond_dynamic_encoder_set_keycode(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_remapping_set_encoder_keycode_arg_t)) {
return false;
}
xap_route_remapping_set_encoder_keycode_arg_t *arg = (xap_route_remapping_set_encoder_keycode_arg_t *)data;
if (arg->layer >= keymap_max_layer_count()) {
return false;
}
dynamic_keymap_set_encoder(arg->layer, arg->encoder, arg->clockwise, arg->keycode);
return xap_respond_success(token);
}
#endif
#define INVALID_EFFECT 0xFF
#if ((defined(BACKLIGHT_ENABLE)))
# include "backlight.h"
extern backlight_config_t backlight_config;
bool xap_respond_get_backlight_config(xap_token_t token, const void *data, size_t length) {
xap_route_lighting_backlight_get_config_t ret;
ret.enable = backlight_config.enable;
ret.mode = backlight_config.breathing;
ret.val = backlight_config.level;
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_set_backlight_config(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_lighting_backlight_set_config_arg_t)) {
return false;
}
xap_route_lighting_backlight_set_config_arg_t *arg = (xap_route_lighting_backlight_set_config_arg_t *)data;
if (arg->enable) {
backlight_level_noeeprom(arg->val);
} else {
backlight_level_noeeprom(0);
}
# ifdef BACKLIGHT_BREATHING
if (arg->mode) {
backlight_enable_breathing();
} else {
backlight_disable_breathing();
}
# endif
return xap_respond_success(token);
}
bool xap_respond_save_backlight_config(xap_token_t token, const void *data, size_t length) {
eeconfig_update_backlight_current();
return xap_respond_success(token);
}
#endif
#if ((defined(RGBLIGHT_ENABLE)))
# include "rgblight.h"
extern rgblight_config_t rgblight_config;
uint8_t rgblight2xap(uint8_t val);
uint8_t xap2rgblight(uint8_t val);
void rgblight_enabled_noeeprom(bool val) {
val ? rgblight_enable_noeeprom() : rgblight_disable_noeeprom();
}
bool xap_respond_get_rgblight_config(xap_token_t token, const void *data, size_t length) {
xap_route_lighting_rgblight_get_config_t ret;
ret.enable = rgblight_config.enable;
ret.mode = rgblight2xap(rgblight_config.mode);
ret.hue = rgblight_config.hue;
ret.sat = rgblight_config.sat;
ret.val = rgblight_config.val;
ret.speed = rgblight_config.speed;
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_set_rgblight_config(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_lighting_rgblight_set_config_arg_t)) {
return false;
}
xap_route_lighting_rgblight_set_config_arg_t *arg = (xap_route_lighting_rgblight_set_config_arg_t *)data;
uint8_t mode = xap2rgblight(arg->mode);
if (mode == INVALID_EFFECT) {
return false;
}
rgblight_enabled_noeeprom(arg->enable);
rgblight_mode_noeeprom(mode);
rgblight_sethsv_noeeprom(arg->hue, arg->sat, arg->val);
rgblight_set_speed_noeeprom(arg->speed);
return xap_respond_success(token);
}
bool xap_respond_save_rgblight_config(xap_token_t token, const void *data, size_t length) {
eeconfig_update_rgblight_current();
return xap_respond_success(token);
}
#endif
#if ((defined(RGB_MATRIX_ENABLE)))
# include "rgb_matrix.h"
extern rgb_config_t rgb_matrix_config;
uint8_t rgb_matrix2xap(uint8_t val);
uint8_t xap2rgb_matrix(uint8_t val);
void rgb_matrix_enabled_noeeprom(bool val) {
val ? rgb_matrix_enable_noeeprom() : rgb_matrix_disable_noeeprom();
}
bool xap_respond_get_rgb_matrix_config(xap_token_t token, const void *data, size_t length) {
xap_route_lighting_rgb_matrix_get_config_t ret;
ret.enable = rgb_matrix_config.enable;
ret.mode = rgb_matrix2xap(rgb_matrix_config.mode);
ret.hue = rgb_matrix_config.hsv.h;
ret.sat = rgb_matrix_config.hsv.s;
ret.val = rgb_matrix_config.hsv.v;
ret.speed = rgb_matrix_config.speed;
ret.flags = rgb_matrix_config.flags;
return xap_respond_data(token, &ret, sizeof(ret));
}
bool xap_respond_set_rgb_matrix_config(xap_token_t token, const void *data, size_t length) {
if (length != sizeof(xap_route_lighting_rgb_matrix_set_config_arg_t)) {
return false;
}
xap_route_lighting_rgb_matrix_set_config_arg_t *arg = (xap_route_lighting_rgb_matrix_set_config_arg_t *)data;
uint8_t mode = xap2rgb_matrix(arg->mode);
if (mode == INVALID_EFFECT) {
return false;
}
rgb_matrix_enabled_noeeprom(arg->enable);
rgb_matrix_mode_noeeprom(mode);
rgb_matrix_sethsv_noeeprom(arg->hue, arg->sat, arg->val);
rgb_matrix_set_speed_noeeprom(arg->speed);
rgb_matrix_set_flags_noeeprom(arg->flags);
return xap_respond_success(token);
}
bool xap_respond_save_rgb_matrix_config(xap_token_t token, const void *data, size_t length) {
eeconfig_update_rgb_matrix();
return xap_respond_success(token);
}
#endif
#include "handlers/core.c"
#include "handlers/remapping.c"
#include "handlers/lighting.c"
#include "handlers/audio.c"