Skip to content

Commit

Permalink
refactor: Move to zmk_hid_indicators_t type.
Browse files Browse the repository at this point in the history
  • Loading branch information
petejohanson committed Nov 27, 2023
1 parent f14ac2b commit 0b23d07
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/include/zmk/events/hid_indicators_changed.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <zmk/event_manager.h>

struct zmk_hid_indicators_changed {
zmk_hid_indicators indicators;
zmk_hid_indicators_t indicators;
};

ZMK_EVENT_DECLARE(zmk_hid_indicators_changed);
6 changes: 3 additions & 3 deletions app/include/zmk/hid_indicators.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <zmk/hid.h>
#include <zmk/hid_indicators_types.h>

zmk_hid_indicators zmk_hid_indicators_get_current_profile(void);
zmk_hid_indicators zmk_hid_indicators_get_profile(struct zmk_endpoint_instance endpoint);
void zmk_hid_indicators_set_profile(zmk_hid_indicators indicators,
zmk_hid_indicators_t zmk_hid_indicators_get_current_profile(void);
zmk_hid_indicators_t zmk_hid_indicators_get_profile(struct zmk_endpoint_instance endpoint);
void zmk_hid_indicators_set_profile(zmk_hid_indicators_t indicators,
struct zmk_endpoint_instance endpoint);

void zmk_hid_indicators_process_report(struct zmk_hid_led_report_body *report,
Expand Down
2 changes: 1 addition & 1 deletion app/include/zmk/hid_indicators_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

#pragma once

typedef uint8_t zmk_hid_indicators;
typedef uint8_t zmk_hid_indicators_t;
2 changes: 1 addition & 1 deletion app/include/zmk/split/bluetooth/central.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ int zmk_split_bt_invoke_behavior(uint8_t source, struct zmk_behavior_binding *bi

#if IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)

int zmk_split_bt_update_hid_indicator(zmk_hid_indicators indicators);
int zmk_split_bt_update_hid_indicator(zmk_hid_indicators_t indicators);

#endif // IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)
14 changes: 7 additions & 7 deletions app/src/hid_indicators.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

static zmk_hid_indicators hid_indicators[ZMK_ENDPOINT_COUNT];
static zmk_hid_indicators_t hid_indicators[ZMK_ENDPOINT_COUNT];

zmk_hid_indicators zmk_hid_indicators_get_current_profile(void) {
zmk_hid_indicators_t zmk_hid_indicators_get_current_profile(void) {
return zmk_hid_indicators_get_profile(zmk_endpoints_selected());
}

zmk_hid_indicators zmk_hid_indicators_get_profile(struct zmk_endpoint_instance endpoint) {
int profile = zmk_endpoint_instance_to_index(endpoint);
zmk_hid_indicators_t zmk_hid_indicators_get_profile(struct zmk_endpoint_instance endpoint) {
const int profile = zmk_endpoint_instance_to_index(endpoint);
return hid_indicators[profile];
}

static void raise_led_changed_event(struct k_work *_work) {
zmk_hid_indicators indicators = zmk_hid_indicators_get_current_profile();
const zmk_hid_indicators_t indicators = zmk_hid_indicators_get_current_profile();

ZMK_EVENT_RAISE(new_zmk_hid_indicators_changed(
(struct zmk_hid_indicators_changed){.indicators = indicators}));
Expand All @@ -40,7 +40,7 @@ static void raise_led_changed_event(struct k_work *_work) {

static K_WORK_DEFINE(led_changed_work, raise_led_changed_event);

void zmk_hid_indicators_set_profile(zmk_hid_indicators indicators,
void zmk_hid_indicators_set_profile(zmk_hid_indicators_t indicators,
struct zmk_endpoint_instance endpoint) {
int profile = zmk_endpoint_instance_to_index(endpoint);

Expand All @@ -54,7 +54,7 @@ void zmk_hid_indicators_set_profile(zmk_hid_indicators indicators,

void zmk_hid_indicators_process_report(struct zmk_hid_led_report_body *report,
struct zmk_endpoint_instance endpoint) {
uint8_t indicators = report->leds;
const zmk_hid_indicators_t indicators = (zmk_hid_indicators_t)report->leds;
zmk_hid_indicators_set_profile(indicators, endpoint);

LOG_DBG("Update HID indicators: endpoint=%d, indicators=%x", endpoint.transport, indicators);
Expand Down
6 changes: 3 additions & 3 deletions app/src/split/bluetooth/central.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,10 @@ int zmk_split_bt_invoke_behavior(uint8_t source, struct zmk_behavior_binding *bi

#if IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)

static zmk_hid_indicators hid_indicators = 0;
static zmk_hid_indicators_t hid_indicators = 0;

static void split_central_update_indicators_callback(struct k_work *work) {
zmk_hid_indicators indicators = hid_indicators;
zmk_hid_indicators_t indicators = hid_indicators;
for (int i = 0; i < ZMK_SPLIT_BLE_PERIPHERAL_COUNT; i++) {
if (peripherals[i].state != PERIPHERAL_SLOT_STATE_CONNECTED) {
continue;
Expand All @@ -732,7 +732,7 @@ static void split_central_update_indicators_callback(struct k_work *work) {

static K_WORK_DEFINE(split_central_update_indicators, split_central_update_indicators_callback);

int zmk_split_bt_update_hid_indicator(zmk_hid_indicators indicators) {
int zmk_split_bt_update_hid_indicator(zmk_hid_indicators_t indicators) {
hid_indicators = indicators;
return k_work_submit_to_queue(&split_central_split_run_q, &split_central_update_indicators);
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/split/bluetooth/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static void split_svc_pos_state_ccc(const struct bt_gatt_attr *attr, uint16_t va

#if IS_ENABLED(CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS)

static zmk_hid_indicators hid_indicators = 0;
static zmk_hid_indicators_t hid_indicators = 0;

static void split_svc_update_indicators_callback(struct k_work *work) {
LOG_DBG("Raising HID indicators changed event: %x", hid_indicators);
Expand All @@ -125,7 +125,7 @@ static K_WORK_DEFINE(split_svc_update_indicators_work, split_svc_update_indicato
static ssize_t split_svc_update_indicators(struct bt_conn *conn, const struct bt_gatt_attr *attr,
const void *buf, uint16_t len, uint16_t offset,
uint8_t flags) {
if (offset + len > sizeof(zmk_hid_indicators)) {
if (offset + len > sizeof(zmk_hid_indicators_t)) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
}

Expand Down

0 comments on commit 0b23d07

Please sign in to comment.