Skip to content

Commit

Permalink
Studio support 1
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Sep 20, 2024
1 parent 3d2ddac commit 0789a6e
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 78 deletions.
107 changes: 100 additions & 7 deletions app/boards/arm/stp/stp.dts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <dt-bindings/zmk/matrix_transform.h>

#include "pinctrl.dtsi"
#include <physical_layouts.dtsi>

/ {
model = "STP";
Expand All @@ -22,14 +23,13 @@
zephyr,flash = &flash0;
zmk,kscan = &kscan0;
zmk,backlight = &backlight;
zmk,matrix_transform = &default_transform;
zmk,physical-layout = &physical_layout;
zmk,battery = &vbatt;
zephyr,console = &cdc_acm_uart;
zmk,profileswitch = &profileswitch;
zmk,indicators = &led_strip;
};

default_transform: keymap_transform_0 {
ansi_transform: keymap_transform_0 {
compatible = "zmk,matrix-transform";
columns = <16>;
rows = <6>;
Expand Down Expand Up @@ -99,6 +99,102 @@
compatible = "zmk,profile-switch";
switch-gpios = <&gpio0 29 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>;
};

physical_layout: physical_layout {
compatible = "zmk,physical-layout";
display-name = "ANSI Layout";

kscan = <&kscan0>;
transform = <&ansi_transform>;

keys // w h x y rot rx ry
= <&key_physical_attrs 100 100 0 0 0 0 0>
, <&key_physical_attrs 100 100 100 0 0 0 0>
, <&key_physical_attrs 100 100 200 0 0 0 0>
, <&key_physical_attrs 100 100 300 0 0 0 0>
, <&key_physical_attrs 100 100 400 0 0 0 0>
, <&key_physical_attrs 100 100 500 0 0 0 0>
, <&key_physical_attrs 100 100 600 0 0 0 0>
, <&key_physical_attrs 100 100 1000 0 0 0 0>
, <&key_physical_attrs 100 100 1100 0 0 0 0>
, <&key_physical_attrs 100 100 1200 0 0 0 0>
, <&key_physical_attrs 100 100 1300 0 0 0 0>
, <&key_physical_attrs 100 100 1400 0 0 0 0>
, <&key_physical_attrs 100 100 1500 0 0 0 0>
, <&key_physical_attrs 100 100 1600 0 0 0 0>
, <&key_physical_attrs 100 100 1700 0 0 0 0>
, <&key_physical_attrs 100 100 1800 0 0 0 0>
, <&key_physical_attrs 100 100 0 100 0 0 0>
, <&key_physical_attrs 100 100 100 100 0 0 0>
, <&key_physical_attrs 100 100 200 100 0 0 0>
, <&key_physical_attrs 100 100 300 100 0 0 0>
, <&key_physical_attrs 100 100 400 100 0 0 0>
, <&key_physical_attrs 100 100 500 100 0 0 0>
, <&key_physical_attrs 100 100 600 100 0 0 0>
, <&key_physical_attrs 100 100 1000 100 0 0 0>
, <&key_physical_attrs 100 100 1100 100 0 0 0>
, <&key_physical_attrs 100 100 1200 100 0 0 0>
, <&key_physical_attrs 100 100 1300 100 0 0 0>
, <&key_physical_attrs 100 100 1400 100 0 0 0>
, <&key_physical_attrs 100 100 1500 100 0 0 0>
, <&key_physical_attrs 200 100 1600 100 0 0 0>
, <&key_physical_attrs 100 100 1800 100 0 0 0>
, <&key_physical_attrs 150 100 0 200 0 0 0>
, <&key_physical_attrs 100 100 150 200 0 0 0>
, <&key_physical_attrs 100 100 250 200 0 0 0>
, <&key_physical_attrs 100 100 350 200 0 0 0>
, <&key_physical_attrs 100 100 450 200 0 0 0>
, <&key_physical_attrs 100 100 550 200 0 0 0>
, <&key_physical_attrs 100 100 950 200 0 0 0>
, <&key_physical_attrs 100 100 1050 200 0 0 0>
, <&key_physical_attrs 100 100 1150 200 0 0 0>
, <&key_physical_attrs 100 100 1250 200 0 0 0>
, <&key_physical_attrs 100 100 1350 200 0 0 0>
, <&key_physical_attrs 100 100 1450 200 0 0 0>
, <&key_physical_attrs 100 100 1550 200 0 0 0>
, <&key_physical_attrs 150 100 1650 200 0 0 0>
, <&key_physical_attrs 100 100 1800 200 0 0 0>
, <&key_physical_attrs 175 100 0 300 0 0 0>
, <&key_physical_attrs 100 100 175 300 0 0 0>
, <&key_physical_attrs 100 100 275 300 0 0 0>
, <&key_physical_attrs 100 100 375 300 0 0 0>
, <&key_physical_attrs 100 100 475 300 0 0 0>
, <&key_physical_attrs 100 100 575 300 0 0 0>
, <&key_physical_attrs 100 100 975 300 0 0 0>
, <&key_physical_attrs 100 100 1075 300 0 0 0>
, <&key_physical_attrs 100 100 1175 300 0 0 0>
, <&key_physical_attrs 100 100 1275 300 0 0 0>
, <&key_physical_attrs 100 100 1375 300 0 0 0>
, <&key_physical_attrs 100 100 1475 300 0 0 0>
, <&key_physical_attrs 225 100 1575 300 0 0 0>
, <&key_physical_attrs 100 100 1800 300 0 0 0>
, <&key_physical_attrs 225 100 0 400 0 0 0>
, <&key_physical_attrs 100 100 225 400 0 0 0>
, <&key_physical_attrs 100 100 325 400 0 0 0>
, <&key_physical_attrs 100 100 425 400 0 0 0>
, <&key_physical_attrs 100 100 525 400 0 0 0>
, <&key_physical_attrs 100 100 625 400 0 0 0>
, <&key_physical_attrs 100 100 1025 400 0 0 0>
, <&key_physical_attrs 100 100 1125 400 0 0 0>
, <&key_physical_attrs 100 100 1225 400 0 0 0>
, <&key_physical_attrs 100 100 1325 400 0 0 0>
, <&key_physical_attrs 100 100 1425 400 0 0 0>
, <&key_physical_attrs 175 100 1525 400 0 0 0>
, <&key_physical_attrs 100 100 1700 400 0 0 0>
, <&key_physical_attrs 100 100 1800 400 0 0 0>
, <&key_physical_attrs 125 100 0 500 0 0 0>
, <&key_physical_attrs 125 100 125 500 0 0 0>
, <&key_physical_attrs 125 100 250 500 0 0 0>
, <&key_physical_attrs 300 100 375 500 0 0 0>
, <&key_physical_attrs 300 100 1000 500 0 0 0>
, <&key_physical_attrs 100 100 1300 500 0 0 0>
, <&key_physical_attrs 100 100 1400 500 0 0 0>
, <&key_physical_attrs 100 100 1500 500 0 0 0>
, <&key_physical_attrs 100 100 1600 500 0 0 0>
, <&key_physical_attrs 100 100 1700 500 0 0 0>
, <&key_physical_attrs 100 100 1800 500 0 0 0>
;
};
};

&adc {
Expand All @@ -124,11 +220,8 @@
status = "okay";
};

&usbd {
zephyr_udc0: &usbd {
status = "okay";
cdc_acm_uart: cdc_acm_uart {
compatible = "zephyr,cdc-acm-uart";
};
};


Expand Down
25 changes: 24 additions & 1 deletion app/boards/arm/stp/stp.keymap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
compatible = "zmk,keymap";

default_layer {
display-name = "Base";
// ------------------------------------------------------------------------------------------------------------
// | ESC | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F9 | F9 | F10 | F11 | F12 | 1 | DEL | INS |
// | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | BKSP | HOME |
Expand All @@ -32,14 +33,36 @@
};

raise {
display-name = "Fn";
bindings = <
&none &kp C_MUTE &kp C_VOL_DN &kp C_VOL_UP &kp C_PREV &kp C_PP &kp C_NEXT &bl BL_DEC &bl BL_INC &kp C_BRI_DN &kp C_BRI_UP &bt BT_CLR &stp STP_BAT &trans &none &none
&studio_unlock &kp C_MUTE &kp C_VOL_DN &kp C_VOL_UP &kp C_PREV &kp C_PP &kp C_NEXT &bl BL_DEC &bl BL_INC &kp C_BRI_DN &kp C_BRI_UP &bt BT_CLR &stp STP_BAT &trans &none &none
&none &none &none &none &none &none &none &none &none &none &none &none &none &none &none
&none &none &kp C_MEDIA_WWW &none &none &kp C_MEDIA_TV &none &none &none &none &none &none &none &sys_reset &none
&none &none &none &none &none &none &kp C_AC_HOME &none &none &none &none &none &bootloader &none
&none &none &none &none &none &kp C_AC_BACK &none &none &none &none &none &none &none &none
&none &none &none &none &none &none &none &none &none &none &none
>;
};
extra1 {
status = "reserved";
};

extra2 {
status = "reserved";
};
extra3 {
status = "reserved";
};

extra4 {
status = "reserved";
};
extra5 {
status = "reserved";
};

extra6 {
status = "reserved";
};
};
};
2 changes: 1 addition & 1 deletion app/boards/arm/stp/stp_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ CONFIG_ZMK_PROFILESWITCH=y
CONFIG_ZMK_HID_REPORT_TYPE_NKRO=n
CONFIG_ZMK_HID_CONSUMER_REPORT_USAGES_FULL=y
CONFIG_BUILD_OUTPUT_UF2=y

CONFIG_ZMK_STUDIO=y
65 changes: 0 additions & 65 deletions app/src/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,71 +469,6 @@ bool zmk_hid_is_pressed(uint32_t usage) {
return false;
}

#if IS_ENABLED(CONFIG_ZMK_MOUSE)

// Keep track of how often a button was pressed.
// Only release the button if the count is 0.
static int explicit_button_counts[5] = {0, 0, 0, 0, 0};
static zmk_mod_flags_t explicit_buttons = 0;

#define SET_MOUSE_BUTTONS(btns) \
{ \
mouse_report.body.buttons = btns; \
LOG_DBG("Mouse buttons set to 0x%02X", mouse_report.body.buttons); \
}

int zmk_hid_mouse_button_press(zmk_mouse_button_t button) {
if (button >= ZMK_HID_MOUSE_NUM_BUTTONS) {
return -EINVAL;
}

explicit_button_counts[button]++;
LOG_DBG("Button %d count %d", button, explicit_button_counts[button]);
WRITE_BIT(explicit_buttons, button, true);
SET_MOUSE_BUTTONS(explicit_buttons);
return 0;
}

int zmk_hid_mouse_button_release(zmk_mouse_button_t button) {
if (button >= ZMK_HID_MOUSE_NUM_BUTTONS) {
return -EINVAL;
}

if (explicit_button_counts[button] <= 0) {
LOG_ERR("Tried to release button %d too often", button);
return -EINVAL;
}
explicit_button_counts[button]--;
LOG_DBG("Button %d count: %d", button, explicit_button_counts[button]);
if (explicit_button_counts[button] == 0) {
LOG_DBG("Button %d released", button);
WRITE_BIT(explicit_buttons, button, false);
}
SET_MOUSE_BUTTONS(explicit_buttons);
return 0;
}

int zmk_hid_mouse_buttons_press(zmk_mouse_button_flags_t buttons) {
for (zmk_mouse_button_t i = 0; i < ZMK_HID_MOUSE_NUM_BUTTONS; i++) {
if (buttons & BIT(i)) {
zmk_hid_mouse_button_press(i);
}
}
return 0;
}

int zmk_hid_mouse_buttons_release(zmk_mouse_button_flags_t buttons) {
for (zmk_mouse_button_t i = 0; i < ZMK_HID_MOUSE_NUM_BUTTONS; i++) {
if (buttons & BIT(i)) {
zmk_hid_mouse_button_release(i);
}
}
return 0;
}
void zmk_hid_mouse_clear(void) { memset(&mouse_report.body, 0, sizeof(mouse_report.body)); }

#endif // IS_ENABLED(CONFIG_ZMK_MOUSE)

struct zmk_hid_keyboard_report *zmk_hid_get_keyboard_report(void) { return &keyboard_report; }

struct zmk_hid_consumer_report *zmk_hid_get_consumer_report(void) { return &consumer_report; }
Expand Down
8 changes: 4 additions & 4 deletions app/src/mouse/trackpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ static int trackpad_event_listener(const zmk_event_t *eh) {
return 0;
}

static ZMK_LISTENER(trackpad, trackpad_event_listener);
static ZMK_SUBSCRIPTION(trackpad, zmk_endpoint_changed);
static ZMK_SUBSCRIPTION(trackpad, zmk_usb_conn_state_changed);
static ZMK_SUBSCRIPTION(trackpad, zmk_ble_active_profile_changed);
ZMK_LISTENER(trackpad, trackpad_event_listener);
ZMK_SUBSCRIPTION(trackpad, zmk_endpoint_changed);
ZMK_SUBSCRIPTION(trackpad, zmk_usb_conn_state_changed);
ZMK_SUBSCRIPTION(trackpad, zmk_ble_active_profile_changed);

void zmk_trackpad_set_mode_report(uint8_t *report, struct zmk_endpoint_instance endpoint) {
int profile = zmk_endpoint_instance_to_index(endpoint);
Expand Down

0 comments on commit 0789a6e

Please sign in to comment.