Skip to content

Commit 4e46d4c

Browse files
committed
merged zmkfirmware#547 from upstream (squashed)
1 parent d0cf4de commit 4e46d4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+609
-333
lines changed

app/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ target_sources(app PRIVATE src/events/sensor_event.c)
3939
target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/events/ble_active_profile_changed.c)
4040
target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/events/battery_state_changed.c)
4141
target_sources_ifdef(CONFIG_USB app PRIVATE src/events/usb_conn_state_changed.c)
42+
target_sources(app PRIVATE src/behaviors/behavior_reset.c)
43+
target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c)
4244
if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)
4345
target_sources(app PRIVATE src/behaviors/behavior_key_press.c)
44-
target_sources(app PRIVATE src/behaviors/behavior_reset.c)
4546
target_sources(app PRIVATE src/behaviors/behavior_hold_tap.c)
4647
target_sources(app PRIVATE src/behaviors/behavior_sticky_key.c)
4748
target_sources(app PRIVATE src/behaviors/behavior_momentary_layer.c)
@@ -51,7 +52,6 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)
5152
target_sources(app PRIVATE src/behaviors/behavior_transparent.c)
5253
target_sources(app PRIVATE src/behaviors/behavior_none.c)
5354
target_sources(app PRIVATE src/behaviors/behavior_sensor_rotate_key_press.c)
54-
target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c)
5555
target_sources(app PRIVATE src/combo.c)
5656
target_sources(app PRIVATE src/keymap.c)
5757
endif()

app/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ menuconfig ZMK_SPLIT_BLE_ROLE_CENTRAL
114114
bool "Central"
115115
select BT_CENTRAL
116116
select BT_GATT_CLIENT
117+
select BT_GATT_AUTO_DISCOVER_CCC
117118

118119
if ZMK_SPLIT_BLE_ROLE_CENTRAL
119120

app/boards/shields/jorne/jorne_left.conf

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ CONFIG_WS2812_STRIP=y
33
CONFIG_ZMK_DISPLAY=y
44
CONFIG_ZMK_RGB_UNDERGLOW_ON_START=y
55
CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER=y
6+

app/boards/shields/jorne/jorne_right.conf

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ CONFIG_WS2812_STRIP=y
33
CONFIG_ZMK_DISPLAY=y
44
CONFIG_ZMK_RGB_UNDERGLOW_ON_START=y
55
CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER=y
6+

app/boards/shields/microdox/microdox.dtsi

-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9)
5858
page-offset = <0>;
5959
display-offset = <0>;
6060
multiplex-ratio = <31>;
61-
segment-remap;
62-
com-invdir;
6361
com-sequential;
6462
prechargep = <0x22>;
6563
};

app/boards/shields/microdox/microdox_right.overlay

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
col-offset = <5>;
1111
};
1212

13+
&oled {
14+
segment-remap;
15+
com-invdir;
16+
};
17+
1318
&kscan0 {
1419
col-gpios
1520
= <&pro_micro_d 15 GPIO_ACTIVE_HIGH>

app/dts/behaviors/reset.dtsi

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
bootloader: behavior_reset_dfu {
1818
compatible = "zmk,behavior-reset";
19-
label = "BOOTLOADER_RESET";
19+
label = "BOOTLOAD";
2020
type = <RST_UF2>;
2121
#binding-cells = <0>;
2222
};

app/dts/behaviors/rgb_underglow.dtsi

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
behaviors {
99
rgb_ug: behavior_rgb_underglow {
1010
compatible = "zmk,behavior-rgb-underglow";
11-
label = "RGB_UNDERGLOW";
11+
label = "RGB_UG";
1212
#binding-cells = <2>;
1313
};
1414
};

app/include/drivers/behavior.h

+72
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <zephyr/types.h>
1010
#include <stddef.h>
11+
#include <sys/util.h>
12+
#include <string.h>
1113
#include <device.h>
1214
#include <zmk/keys.h>
1315
#include <zmk/behavior.h>
@@ -26,7 +28,15 @@ typedef int (*behavior_sensor_keymap_binding_callback_t)(struct zmk_behavior_bin
2628
const struct device *sensor,
2729
int64_t timestamp);
2830

31+
enum behavior_locality {
32+
BEHAVIOR_LOCALITY_CENTRAL,
33+
BEHAVIOR_LOCALITY_EVENT_SOURCE,
34+
BEHAVIOR_LOCALITY_GLOBAL
35+
};
36+
2937
__subsystem struct behavior_driver_api {
38+
enum behavior_locality locality;
39+
behavior_keymap_binding_callback_t binding_to_absolute;
3040
behavior_keymap_binding_callback_t binding_pressed;
3141
behavior_keymap_binding_callback_t binding_released;
3242
behavior_sensor_keymap_binding_callback_t sensor_binding_triggered;
@@ -35,6 +45,53 @@ __subsystem struct behavior_driver_api {
3545
* @endcond
3646
*/
3747

48+
/**
49+
* @brief Handle the keymap binding which needs to be converted from relative "toggle" to absolute
50+
* "turn on"
51+
* @param binding Pointer to the details so of the binding
52+
* @param event The event that triggered use of the binding
53+
*
54+
* @retval 0 If successful.
55+
* @retval Negative errno code if failure.
56+
*/
57+
__syscall int behavior_keymap_binding_to_absolute(struct zmk_behavior_binding *binding,
58+
struct zmk_behavior_binding_event event);
59+
60+
static inline int
61+
z_impl_behavior_keymap_binding_to_absolute(struct zmk_behavior_binding *binding,
62+
struct zmk_behavior_binding_event event) {
63+
const struct device *dev = device_get_binding(binding->behavior_dev);
64+
const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->api;
65+
66+
if (api->binding_to_absolute == NULL) {
67+
return 0;
68+
}
69+
70+
return api->binding_to_absolute(binding, event);
71+
}
72+
73+
/**
74+
* @brief Determine where the behavior should be run
75+
* @param behavior Pointer to the device structure for the driver instance.
76+
*
77+
* @retval Zero if successful.
78+
* @retval Negative errno code if failure.
79+
*/
80+
__syscall int behavior_get_locality(const struct device *behavior,
81+
enum behavior_locality *locality);
82+
83+
static inline int z_impl_behavior_get_locality(const struct device *behavior,
84+
enum behavior_locality *locality) {
85+
if (behavior == NULL) {
86+
return -EINVAL;
87+
}
88+
89+
const struct behavior_driver_api *api = (const struct behavior_driver_api *)behavior->api;
90+
*locality = api->locality;
91+
92+
return 0;
93+
}
94+
3895
/**
3996
* @brief Handle the keymap binding being pressed
4097
* @param dev Pointer to the device structure for the driver instance.
@@ -50,6 +107,11 @@ __syscall int behavior_keymap_binding_pressed(struct zmk_behavior_binding *bindi
50107
static inline int z_impl_behavior_keymap_binding_pressed(struct zmk_behavior_binding *binding,
51108
struct zmk_behavior_binding_event event) {
52109
const struct device *dev = device_get_binding(binding->behavior_dev);
110+
111+
if (dev == NULL) {
112+
return -EINVAL;
113+
}
114+
53115
const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->api;
54116

55117
if (api->binding_pressed == NULL) {
@@ -73,6 +135,11 @@ __syscall int behavior_keymap_binding_released(struct zmk_behavior_binding *bind
73135
static inline int z_impl_behavior_keymap_binding_released(struct zmk_behavior_binding *binding,
74136
struct zmk_behavior_binding_event event) {
75137
const struct device *dev = device_get_binding(binding->behavior_dev);
138+
139+
if (dev == NULL) {
140+
return -EINVAL;
141+
}
142+
76143
const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->api;
77144

78145
if (api->binding_released == NULL) {
@@ -100,6 +167,11 @@ static inline int
100167
z_impl_behavior_sensor_keymap_binding_triggered(struct zmk_behavior_binding *binding,
101168
const struct device *sensor, int64_t timestamp) {
102169
const struct device *dev = device_get_binding(binding->behavior_dev);
170+
171+
if (dev == NULL) {
172+
return -EINVAL;
173+
}
174+
103175
const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->api;
104176

105177
if (api->sensor_binding_triggered == NULL) {

app/include/dt-bindings/zmk/rgb.h

+15-11
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
*/
66

77
#define RGB_TOG_CMD 0
8-
#define RGB_HUI_CMD 1
9-
#define RGB_HUD_CMD 2
10-
#define RGB_SAI_CMD 3
11-
#define RGB_SAD_CMD 4
12-
#define RGB_BRI_CMD 5
13-
#define RGB_BRD_CMD 6
14-
#define RGB_SPI_CMD 7
15-
#define RGB_SPD_CMD 8
16-
#define RGB_EFF_CMD 9
17-
#define RGB_EFR_CMD 10
18-
#define RGB_COLOR_HSB_CMD 11
8+
#define RGB_ON_CMD 1
9+
#define RGB_OFF_CMD 2
10+
#define RGB_HUI_CMD 3
11+
#define RGB_HUD_CMD 4
12+
#define RGB_SAI_CMD 5
13+
#define RGB_SAD_CMD 6
14+
#define RGB_BRI_CMD 7
15+
#define RGB_BRD_CMD 8
16+
#define RGB_SPI_CMD 9
17+
#define RGB_SPD_CMD 10
18+
#define RGB_EFF_CMD 11
19+
#define RGB_EFR_CMD 12
20+
#define RGB_COLOR_HSB_CMD 13
1921

2022
#define RGB_TOG RGB_TOG_CMD 0
23+
#define RGB_ON RGB_ON_CMD 0
24+
#define RGB_OFF RGB_OFF_CMD 0
2125
#define RGB_HUI RGB_HUI_CMD 0
2226
#define RGB_HUD RGB_HUD_CMD 0
2327
#define RGB_SAI RGB_SAI_CMD 0

app/include/zmk/event_manager.h

+26-22
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ struct zmk_event_type {
1414
const char *name;
1515
};
1616

17-
struct zmk_event_header {
17+
typedef struct {
1818
const struct zmk_event_type *event;
1919
uint8_t last_listener_index;
20-
};
20+
} zmk_event_t;
2121

2222
#define ZMK_EV_EVENT_BUBBLE 0
2323
#define ZMK_EV_EVENT_HANDLED 1
2424
#define ZMK_EV_EVENT_CAPTURED 2
2525

26-
typedef int (*zmk_listener_callback_t)(const struct zmk_event_header *eh);
26+
typedef int (*zmk_listener_callback_t)(const zmk_event_t *eh);
2727
struct zmk_listener {
2828
zmk_listener_callback_t callback;
2929
};
@@ -34,25 +34,28 @@ struct zmk_event_subscription {
3434
};
3535

3636
#define ZMK_EVENT_DECLARE(event_type) \
37-
struct event_type *new_##event_type(); \
38-
bool is_##event_type(const struct zmk_event_header *eh); \
39-
struct event_type *cast_##event_type(const struct zmk_event_header *eh); \
37+
struct event_type##_event { \
38+
zmk_event_t header; \
39+
struct event_type data; \
40+
}; \
41+
struct event_type##_event *new_##event_type(struct event_type); \
42+
struct event_type *as_##event_type(const zmk_event_t *eh); \
4043
extern const struct zmk_event_type zmk_event_##event_type;
4144

4245
#define ZMK_EVENT_IMPL(event_type) \
4346
const struct zmk_event_type zmk_event_##event_type = {.name = STRINGIFY(event_type)}; \
4447
const struct zmk_event_type *zmk_event_ref_##event_type __used \
4548
__attribute__((__section__(".event_type"))) = &zmk_event_##event_type; \
46-
struct event_type *new_##event_type() { \
47-
struct event_type *ev = (struct event_type *)k_malloc(sizeof(struct event_type)); \
49+
struct event_type##_event *new_##event_type(struct event_type data) { \
50+
struct event_type##_event *ev = \
51+
(struct event_type##_event *)k_malloc(sizeof(struct event_type##_event)); \
4852
ev->header.event = &zmk_event_##event_type; \
53+
ev->data = data; \
4954
return ev; \
5055
}; \
51-
bool is_##event_type(const struct zmk_event_header *eh) { \
52-
return eh->event == &zmk_event_##event_type; \
53-
}; \
54-
struct event_type *cast_##event_type(const struct zmk_event_header *eh) { \
55-
return (struct event_type *)eh; \
56+
struct event_type *as_##event_type(const zmk_event_t *eh) { \
57+
return (eh->event == &zmk_event_##event_type) ? &((struct event_type##_event *)eh)->data \
58+
: NULL; \
5659
};
5760

5861
#define ZMK_LISTENER(mod, cb) const struct zmk_listener zmk_listener_##mod = {.callback = cb};
@@ -65,18 +68,19 @@ struct zmk_event_subscription {
6568
.listener = &zmk_listener_##mod, \
6669
};
6770

68-
#define ZMK_EVENT_RAISE(ev) zmk_event_manager_raise((struct zmk_event_header *)ev);
71+
#define ZMK_EVENT_RAISE(ev) zmk_event_manager_raise((zmk_event_t *)ev);
6972

7073
#define ZMK_EVENT_RAISE_AFTER(ev, mod) \
71-
zmk_event_manager_raise_after((struct zmk_event_header *)ev, &zmk_listener_##mod);
74+
zmk_event_manager_raise_after((zmk_event_t *)ev, &zmk_listener_##mod);
7275

7376
#define ZMK_EVENT_RAISE_AT(ev, mod) \
74-
zmk_event_manager_raise_at((struct zmk_event_header *)ev, &zmk_listener_##mod);
77+
zmk_event_manager_raise_at((zmk_event_t *)ev, &zmk_listener_##mod);
78+
79+
#define ZMK_EVENT_RELEASE(ev) zmk_event_manager_release((zmk_event_t *)ev);
7580

76-
#define ZMK_EVENT_RELEASE(ev) zmk_event_manager_release((struct zmk_event_header *)ev);
81+
#define ZMK_EVENT_FREE(ev) k_free((void *)ev);
7782

78-
int zmk_event_manager_raise(struct zmk_event_header *event);
79-
int zmk_event_manager_raise_after(struct zmk_event_header *event,
80-
const struct zmk_listener *listener);
81-
int zmk_event_manager_raise_at(struct zmk_event_header *event, const struct zmk_listener *listener);
82-
int zmk_event_manager_release(struct zmk_event_header *event);
83+
int zmk_event_manager_raise(zmk_event_t *event);
84+
int zmk_event_manager_raise_after(zmk_event_t *event, const struct zmk_listener *listener);
85+
int zmk_event_manager_raise_at(zmk_event_t *event, const struct zmk_listener *listener);
86+
int zmk_event_manager_release(zmk_event_t *event);

app/include/zmk/events/activity_state_changed.h

+2-11
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,8 @@
1010
#include <zmk/event_manager.h>
1111
#include <zmk/activity.h>
1212

13-
struct activity_state_changed {
14-
struct zmk_event_header header;
13+
struct zmk_activity_state_changed {
1514
enum zmk_activity_state state;
1615
};
1716

18-
ZMK_EVENT_DECLARE(activity_state_changed);
19-
20-
static inline struct activity_state_changed *
21-
create_activity_state_changed(enum zmk_activity_state state) {
22-
struct activity_state_changed *ev = new_activity_state_changed();
23-
ev->state = state;
24-
25-
return ev;
26-
}
17+
ZMK_EVENT_DECLARE(zmk_activity_state_changed);

app/include/zmk/events/battery_state_changed.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
#include <zephyr.h>
1010
#include <zmk/event_manager.h>
1111

12-
struct battery_state_changed {
13-
struct zmk_event_header header;
12+
struct zmk_battery_state_changed {
1413
// TODO: Other battery channels
1514
uint8_t state_of_charge;
1615
};
1716

18-
ZMK_EVENT_DECLARE(battery_state_changed);
17+
ZMK_EVENT_DECLARE(zmk_battery_state_changed);

app/include/zmk/events/ble_active_profile_changed.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212

1313
#include <zmk/ble/profile.h>
1414

15-
struct ble_active_profile_changed {
16-
struct zmk_event_header header;
15+
struct zmk_ble_active_profile_changed {
1716
uint8_t index;
1817
struct zmk_ble_profile *profile;
1918
};
2019

21-
ZMK_EVENT_DECLARE(ble_active_profile_changed);
20+
ZMK_EVENT_DECLARE(zmk_ble_active_profile_changed);

0 commit comments

Comments
 (0)