Skip to content

Commit

Permalink
merged zmkfirmware#547 from upstream (squashed)
Browse files Browse the repository at this point in the history
  • Loading branch information
joric committed Jan 30, 2021
1 parent d0cf4de commit 4e46d4c
Show file tree
Hide file tree
Showing 59 changed files with 609 additions and 333 deletions.
4 changes: 2 additions & 2 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ target_sources(app PRIVATE src/events/sensor_event.c)
target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/events/ble_active_profile_changed.c)
target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/events/battery_state_changed.c)
target_sources_ifdef(CONFIG_USB app PRIVATE src/events/usb_conn_state_changed.c)
target_sources(app PRIVATE src/behaviors/behavior_reset.c)
target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c)
if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)
target_sources(app PRIVATE src/behaviors/behavior_key_press.c)
target_sources(app PRIVATE src/behaviors/behavior_reset.c)
target_sources(app PRIVATE src/behaviors/behavior_hold_tap.c)
target_sources(app PRIVATE src/behaviors/behavior_sticky_key.c)
target_sources(app PRIVATE src/behaviors/behavior_momentary_layer.c)
Expand All @@ -51,7 +52,6 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)
target_sources(app PRIVATE src/behaviors/behavior_transparent.c)
target_sources(app PRIVATE src/behaviors/behavior_none.c)
target_sources(app PRIVATE src/behaviors/behavior_sensor_rotate_key_press.c)
target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c)
target_sources(app PRIVATE src/combo.c)
target_sources(app PRIVATE src/keymap.c)
endif()
Expand Down
1 change: 1 addition & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ menuconfig ZMK_SPLIT_BLE_ROLE_CENTRAL
bool "Central"
select BT_CENTRAL
select BT_GATT_CLIENT
select BT_GATT_AUTO_DISCOVER_CCC

if ZMK_SPLIT_BLE_ROLE_CENTRAL

Expand Down
1 change: 1 addition & 0 deletions app/boards/shields/jorne/jorne_left.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ CONFIG_WS2812_STRIP=y
CONFIG_ZMK_DISPLAY=y
CONFIG_ZMK_RGB_UNDERGLOW_ON_START=y
CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER=y

1 change: 1 addition & 0 deletions app/boards/shields/jorne/jorne_right.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ CONFIG_WS2812_STRIP=y
CONFIG_ZMK_DISPLAY=y
CONFIG_ZMK_RGB_UNDERGLOW_ON_START=y
CONFIG_ZMK_RGB_UNDERGLOW_EXT_POWER=y

2 changes: 0 additions & 2 deletions app/boards/shields/microdox/microdox.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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)
page-offset = <0>;
display-offset = <0>;
multiplex-ratio = <31>;
segment-remap;
com-invdir;
com-sequential;
prechargep = <0x22>;
};
Expand Down
5 changes: 5 additions & 0 deletions app/boards/shields/microdox/microdox_right.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
col-offset = <5>;
};

&oled {
segment-remap;
com-invdir;
};

&kscan0 {
col-gpios
= <&pro_micro_d 15 GPIO_ACTIVE_HIGH>
Expand Down
2 changes: 1 addition & 1 deletion app/dts/behaviors/reset.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

bootloader: behavior_reset_dfu {
compatible = "zmk,behavior-reset";
label = "BOOTLOADER_RESET";
label = "BOOTLOAD";
type = <RST_UF2>;
#binding-cells = <0>;
};
Expand Down
2 changes: 1 addition & 1 deletion app/dts/behaviors/rgb_underglow.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
behaviors {
rgb_ug: behavior_rgb_underglow {
compatible = "zmk,behavior-rgb-underglow";
label = "RGB_UNDERGLOW";
label = "RGB_UG";
#binding-cells = <2>;
};
};
Expand Down
72 changes: 72 additions & 0 deletions app/include/drivers/behavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <zephyr/types.h>
#include <stddef.h>
#include <sys/util.h>
#include <string.h>
#include <device.h>
#include <zmk/keys.h>
#include <zmk/behavior.h>
Expand All @@ -26,7 +28,15 @@ typedef int (*behavior_sensor_keymap_binding_callback_t)(struct zmk_behavior_bin
const struct device *sensor,
int64_t timestamp);

enum behavior_locality {
BEHAVIOR_LOCALITY_CENTRAL,
BEHAVIOR_LOCALITY_EVENT_SOURCE,
BEHAVIOR_LOCALITY_GLOBAL
};

__subsystem struct behavior_driver_api {
enum behavior_locality locality;
behavior_keymap_binding_callback_t binding_to_absolute;
behavior_keymap_binding_callback_t binding_pressed;
behavior_keymap_binding_callback_t binding_released;
behavior_sensor_keymap_binding_callback_t sensor_binding_triggered;
Expand All @@ -35,6 +45,53 @@ __subsystem struct behavior_driver_api {
* @endcond
*/

/**
* @brief Handle the keymap binding which needs to be converted from relative "toggle" to absolute
* "turn on"
* @param binding Pointer to the details so of the binding
* @param event The event that triggered use of the binding
*
* @retval 0 If successful.
* @retval Negative errno code if failure.
*/
__syscall int behavior_keymap_binding_to_absolute(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event);

static inline int
z_impl_behavior_keymap_binding_to_absolute(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
const struct device *dev = device_get_binding(binding->behavior_dev);
const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->api;

if (api->binding_to_absolute == NULL) {
return 0;
}

return api->binding_to_absolute(binding, event);
}

/**
* @brief Determine where the behavior should be run
* @param behavior Pointer to the device structure for the driver instance.
*
* @retval Zero if successful.
* @retval Negative errno code if failure.
*/
__syscall int behavior_get_locality(const struct device *behavior,
enum behavior_locality *locality);

static inline int z_impl_behavior_get_locality(const struct device *behavior,
enum behavior_locality *locality) {
if (behavior == NULL) {
return -EINVAL;
}

const struct behavior_driver_api *api = (const struct behavior_driver_api *)behavior->api;
*locality = api->locality;

return 0;
}

/**
* @brief Handle the keymap binding being pressed
* @param dev Pointer to the device structure for the driver instance.
Expand All @@ -50,6 +107,11 @@ __syscall int behavior_keymap_binding_pressed(struct zmk_behavior_binding *bindi
static inline int z_impl_behavior_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
const struct device *dev = device_get_binding(binding->behavior_dev);

if (dev == NULL) {
return -EINVAL;
}

const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->api;

if (api->binding_pressed == NULL) {
Expand All @@ -73,6 +135,11 @@ __syscall int behavior_keymap_binding_released(struct zmk_behavior_binding *bind
static inline int z_impl_behavior_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
const struct device *dev = device_get_binding(binding->behavior_dev);

if (dev == NULL) {
return -EINVAL;
}

const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->api;

if (api->binding_released == NULL) {
Expand Down Expand Up @@ -100,6 +167,11 @@ static inline int
z_impl_behavior_sensor_keymap_binding_triggered(struct zmk_behavior_binding *binding,
const struct device *sensor, int64_t timestamp) {
const struct device *dev = device_get_binding(binding->behavior_dev);

if (dev == NULL) {
return -EINVAL;
}

const struct behavior_driver_api *api = (const struct behavior_driver_api *)dev->api;

if (api->sensor_binding_triggered == NULL) {
Expand Down
26 changes: 15 additions & 11 deletions app/include/dt-bindings/zmk/rgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
*/

#define RGB_TOG_CMD 0
#define RGB_HUI_CMD 1
#define RGB_HUD_CMD 2
#define RGB_SAI_CMD 3
#define RGB_SAD_CMD 4
#define RGB_BRI_CMD 5
#define RGB_BRD_CMD 6
#define RGB_SPI_CMD 7
#define RGB_SPD_CMD 8
#define RGB_EFF_CMD 9
#define RGB_EFR_CMD 10
#define RGB_COLOR_HSB_CMD 11
#define RGB_ON_CMD 1
#define RGB_OFF_CMD 2
#define RGB_HUI_CMD 3
#define RGB_HUD_CMD 4
#define RGB_SAI_CMD 5
#define RGB_SAD_CMD 6
#define RGB_BRI_CMD 7
#define RGB_BRD_CMD 8
#define RGB_SPI_CMD 9
#define RGB_SPD_CMD 10
#define RGB_EFF_CMD 11
#define RGB_EFR_CMD 12
#define RGB_COLOR_HSB_CMD 13

#define RGB_TOG RGB_TOG_CMD 0
#define RGB_ON RGB_ON_CMD 0
#define RGB_OFF RGB_OFF_CMD 0
#define RGB_HUI RGB_HUI_CMD 0
#define RGB_HUD RGB_HUD_CMD 0
#define RGB_SAI RGB_SAI_CMD 0
Expand Down
48 changes: 26 additions & 22 deletions app/include/zmk/event_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ struct zmk_event_type {
const char *name;
};

struct zmk_event_header {
typedef struct {
const struct zmk_event_type *event;
uint8_t last_listener_index;
};
} zmk_event_t;

#define ZMK_EV_EVENT_BUBBLE 0
#define ZMK_EV_EVENT_HANDLED 1
#define ZMK_EV_EVENT_CAPTURED 2

typedef int (*zmk_listener_callback_t)(const struct zmk_event_header *eh);
typedef int (*zmk_listener_callback_t)(const zmk_event_t *eh);
struct zmk_listener {
zmk_listener_callback_t callback;
};
Expand All @@ -34,25 +34,28 @@ struct zmk_event_subscription {
};

#define ZMK_EVENT_DECLARE(event_type) \
struct event_type *new_##event_type(); \
bool is_##event_type(const struct zmk_event_header *eh); \
struct event_type *cast_##event_type(const struct zmk_event_header *eh); \
struct event_type##_event { \
zmk_event_t header; \
struct event_type data; \
}; \
struct event_type##_event *new_##event_type(struct event_type); \
struct event_type *as_##event_type(const zmk_event_t *eh); \
extern const struct zmk_event_type zmk_event_##event_type;

#define ZMK_EVENT_IMPL(event_type) \
const struct zmk_event_type zmk_event_##event_type = {.name = STRINGIFY(event_type)}; \
const struct zmk_event_type *zmk_event_ref_##event_type __used \
__attribute__((__section__(".event_type"))) = &zmk_event_##event_type; \
struct event_type *new_##event_type() { \
struct event_type *ev = (struct event_type *)k_malloc(sizeof(struct event_type)); \
struct event_type##_event *new_##event_type(struct event_type data) { \
struct event_type##_event *ev = \
(struct event_type##_event *)k_malloc(sizeof(struct event_type##_event)); \
ev->header.event = &zmk_event_##event_type; \
ev->data = data; \
return ev; \
}; \
bool is_##event_type(const struct zmk_event_header *eh) { \
return eh->event == &zmk_event_##event_type; \
}; \
struct event_type *cast_##event_type(const struct zmk_event_header *eh) { \
return (struct event_type *)eh; \
struct event_type *as_##event_type(const zmk_event_t *eh) { \
return (eh->event == &zmk_event_##event_type) ? &((struct event_type##_event *)eh)->data \
: NULL; \
};

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

#define ZMK_EVENT_RAISE(ev) zmk_event_manager_raise((struct zmk_event_header *)ev);
#define ZMK_EVENT_RAISE(ev) zmk_event_manager_raise((zmk_event_t *)ev);

#define ZMK_EVENT_RAISE_AFTER(ev, mod) \
zmk_event_manager_raise_after((struct zmk_event_header *)ev, &zmk_listener_##mod);
zmk_event_manager_raise_after((zmk_event_t *)ev, &zmk_listener_##mod);

#define ZMK_EVENT_RAISE_AT(ev, mod) \
zmk_event_manager_raise_at((struct zmk_event_header *)ev, &zmk_listener_##mod);
zmk_event_manager_raise_at((zmk_event_t *)ev, &zmk_listener_##mod);

#define ZMK_EVENT_RELEASE(ev) zmk_event_manager_release((zmk_event_t *)ev);

#define ZMK_EVENT_RELEASE(ev) zmk_event_manager_release((struct zmk_event_header *)ev);
#define ZMK_EVENT_FREE(ev) k_free((void *)ev);

int zmk_event_manager_raise(struct zmk_event_header *event);
int zmk_event_manager_raise_after(struct zmk_event_header *event,
const struct zmk_listener *listener);
int zmk_event_manager_raise_at(struct zmk_event_header *event, const struct zmk_listener *listener);
int zmk_event_manager_release(struct zmk_event_header *event);
int zmk_event_manager_raise(zmk_event_t *event);
int zmk_event_manager_raise_after(zmk_event_t *event, const struct zmk_listener *listener);
int zmk_event_manager_raise_at(zmk_event_t *event, const struct zmk_listener *listener);
int zmk_event_manager_release(zmk_event_t *event);
13 changes: 2 additions & 11 deletions app/include/zmk/events/activity_state_changed.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,8 @@
#include <zmk/event_manager.h>
#include <zmk/activity.h>

struct activity_state_changed {
struct zmk_event_header header;
struct zmk_activity_state_changed {
enum zmk_activity_state state;
};

ZMK_EVENT_DECLARE(activity_state_changed);

static inline struct activity_state_changed *
create_activity_state_changed(enum zmk_activity_state state) {
struct activity_state_changed *ev = new_activity_state_changed();
ev->state = state;

return ev;
}
ZMK_EVENT_DECLARE(zmk_activity_state_changed);
5 changes: 2 additions & 3 deletions app/include/zmk/events/battery_state_changed.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#include <zephyr.h>
#include <zmk/event_manager.h>

struct battery_state_changed {
struct zmk_event_header header;
struct zmk_battery_state_changed {
// TODO: Other battery channels
uint8_t state_of_charge;
};

ZMK_EVENT_DECLARE(battery_state_changed);
ZMK_EVENT_DECLARE(zmk_battery_state_changed);
5 changes: 2 additions & 3 deletions app/include/zmk/events/ble_active_profile_changed.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@

#include <zmk/ble/profile.h>

struct ble_active_profile_changed {
struct zmk_event_header header;
struct zmk_ble_active_profile_changed {
uint8_t index;
struct zmk_ble_profile *profile;
};

ZMK_EVENT_DECLARE(ble_active_profile_changed);
ZMK_EVENT_DECLARE(zmk_ble_active_profile_changed);
Loading

0 comments on commit 4e46d4c

Please sign in to comment.