diff --git a/reform2-keyboard-fw/descriptors.c b/reform2-keyboard-fw/descriptors.c index d82476b19b4163a01c031980e514cd3a9f22fd35..ba94656adc2c9ed6a68a93419109c6d6449a1293 100644 --- a/reform2-keyboard-fw/descriptors.c +++ b/reform2-keyboard-fw/descriptors.c @@ -40,24 +40,19 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM MediaControlReport[] = HID_RI_USAGE_PAGE(8, 0x0C), /* Consumer Page */ HID_RI_USAGE(8, 0x01), /* Consumer Controls */ HID_RI_COLLECTION(8, 0x01), /* Application */ - HID_RI_USAGE(8, 0xB0), /* Play */ - HID_RI_USAGE(8, 0xB1), /* Pause */ - HID_RI_USAGE(8, 0xB3), /* Fast Forward */ - HID_RI_USAGE(8, 0xB4), /* Rewind */ - HID_RI_USAGE(8, 0xB5), /* Next Track */ + HID_RI_USAGE(8, 0x70), /* Display Brightness Decrement */ + HID_RI_USAGE(8, 0x6F), /* Display Brightness Increment */ HID_RI_USAGE(8, 0xB6), /* Previous Track */ - HID_RI_USAGE(8, 0xB7), /* Stop */ HID_RI_USAGE(8, 0xCD), /* Play/Pause (toggle) */ + HID_RI_USAGE(8, 0xB5), /* Next Track */ HID_RI_USAGE(8, 0xE2), /* Mute */ - HID_RI_USAGE(8, 0xE9), /* Volume Up */ HID_RI_USAGE(8, 0xEA), /* Volume Down */ + HID_RI_USAGE(8, 0xE9), /* Volume Up */ HID_RI_REPORT_SIZE(8, 0x01), - HID_RI_REPORT_COUNT(8, 0x0B), + HID_RI_REPORT_COUNT(8, 0x08), HID_RI_LOGICAL_MINIMUM(8, 0), HID_RI_LOGICAL_MAXIMUM(8, 1), HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), - HID_RI_REPORT_COUNT(8, 0x05), - HID_RI_INPUT(8, HID_IOF_CONSTANT), HID_RI_END_COLLECTION(0), }; diff --git a/reform2-keyboard-fw/keyboard.c b/reform2-keyboard-fw/keyboard.c index 0bc82780fcc474f0dc3ae3250ac1cccb82d8126d..63c730b50ca6ec229a5e77ed066be541af0d823d 100644 --- a/reform2-keyboard-fw/keyboard.c +++ b/reform2-keyboard-fw/keyboard.c @@ -102,28 +102,17 @@ inline bool is_media_key(uint8_t keycode) { return (keycode>=HID_KEYBOARD_SC_MEDIA_PLAY); } -bool get_media_keys(uint8_t keycode, USB_MediaReport_Data_t* mcr) { - bool media_key = false; - if (keycode == HID_KEYBOARD_SC_MEDIA_MUTE) { - if (mcr) mcr->Mute = 1; - media_key = true; - } else if (keycode == HID_KEYBOARD_SC_MEDIA_VOLUME_UP) { - if (mcr) mcr->VolumeUp = 1; - media_key = true; - } else if (keycode == HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN) { - if (mcr) mcr->VolumeDown = 1; - media_key = true; - } else if (keycode == HID_KEYBOARD_SC_MEDIA_BACKWARD) { - if (mcr) mcr->PreviousTrack = 1; - media_key = true; - } else if (keycode == HID_KEYBOARD_SC_MEDIA_FORWARD) { - if (mcr) mcr->NextTrack = 1; - media_key = true; - } else if (keycode == HID_KEYBOARD_SC_MEDIA_PLAY) { - if (mcr) mcr->PlayPause = 1; - media_key = true; +void get_media_keys(uint8_t keycode, USB_MediaReport_Data_t* mcr) { + switch (keycode) { + case HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_DOWN: mcr->BrightnessDown = 1; break; + case HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_UP: mcr->BrightnessUp = 1; break; + case HID_KEYBOARD_SC_MEDIA_PREVIOUS_TRACK: mcr->PreviousTrack = 1; break; + case HID_KEYBOARD_SC_MEDIA_PLAY: mcr->PlayPause = 1; break; + case HID_KEYBOARD_SC_MEDIA_NEXT_TRACK: mcr->NextTrack = 1; break; + case HID_KEYBOARD_SC_MEDIA_MUTE: mcr->Mute = 1; break; + case HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN: mcr->VolumeDown = 1; break; + case HID_KEYBOARD_SC_MEDIA_VOLUME_UP: mcr->VolumeUp = 1; break; } - return media_key; } #define MAX_SCANCODES 6 diff --git a/reform2-keyboard-fw/keyboard.h b/reform2-keyboard-fw/keyboard.h index 46ed00c483acc35e5706bdd036fe4f19b871e045..7bbd2be6c34bba49973ed2284a3b84f75249f036 100644 --- a/reform2-keyboard-fw/keyboard.h +++ b/reform2-keyboard-fw/keyboard.h @@ -25,6 +25,10 @@ #define set_input(portdir,pin) portdir &= ~(1<<pin) #define set_output(portdir,pin) portdir |= (1<<pin) +// Reuse existing key codes +#define HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_DOWN HID_KEYBOARD_SC_MEDIA_RELOAD +#define HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_UP HID_KEYBOARD_SC_MEDIA_CALCULATOR + // Top row, left to right #define MATRIX_DEFAULT_ROW_1 \ KEY_ESCAPE,\ @@ -128,18 +132,14 @@ // MediaController USB Report typedef struct { - unsigned Play : 1; - unsigned Pause : 1; - unsigned FForward : 1; - unsigned Rewind : 1; - unsigned NextTrack : 1; + unsigned BrightnessDown : 1; + unsigned BrightnessUp : 1; unsigned PreviousTrack : 1; - unsigned Stop : 1; unsigned PlayPause : 1; + unsigned NextTrack : 1; unsigned Mute : 1; - unsigned VolumeUp : 1; unsigned VolumeDown : 1; - unsigned RESERVED : 5; + unsigned VolumeUp : 1; } ATTR_PACKED USB_MediaReport_Data_t; void setup_hardware(void); diff --git a/reform2-keyboard-fw/matrix.h b/reform2-keyboard-fw/matrix.h index 5647aaab9df1bcb2d64767734f964d517618e129..dc9c0bad2e08285740a9b2650a3e8a6e66c14def 100644 --- a/reform2-keyboard-fw/matrix.h +++ b/reform2-keyboard-fw/matrix.h @@ -24,15 +24,15 @@ uint8_t matrix[KBD_MATRIX_SZ] = { uint8_t matrix_fn[KBD_MATRIX_SZ] = { // Media keys on Hyper + F7-F12 KEY_ESCAPE, - KEY_F1, - KEY_F2, + HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_DOWN, + HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_UP, KEY_F3, KEY_F4, KEY_F5, KEY_F6, - HID_KEYBOARD_SC_MEDIA_BACKWARD, + HID_KEYBOARD_SC_MEDIA_PREVIOUS_TRACK, HID_KEYBOARD_SC_MEDIA_PLAY, - HID_KEYBOARD_SC_MEDIA_FORWARD, + HID_KEYBOARD_SC_MEDIA_NEXT_TRACK, HID_KEYBOARD_SC_MEDIA_MUTE, HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN, HID_KEYBOARD_SC_MEDIA_VOLUME_UP, @@ -49,15 +49,15 @@ uint8_t matrix_fn[KBD_MATRIX_SZ] = { uint8_t matrix_fn_toggled[KBD_MATRIX_SZ] = { // Custom top row KEY_ESCAPE, - KEY_F1, - KEY_F2, + HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_DOWN, + HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_UP, KEY_F3, KEY_F4, KEY_F5, KEY_F6, - HID_KEYBOARD_SC_MEDIA_BACKWARD, + HID_KEYBOARD_SC_MEDIA_PREVIOUS_TRACK, HID_KEYBOARD_SC_MEDIA_PLAY, - HID_KEYBOARD_SC_MEDIA_FORWARD, + HID_KEYBOARD_SC_MEDIA_NEXT_TRACK, HID_KEYBOARD_SC_MEDIA_MUTE, HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN, HID_KEYBOARD_SC_MEDIA_VOLUME_UP, diff --git a/reform2-keyboard-fw/matrix_v.h b/reform2-keyboard-fw/matrix_v.h index 297dd903749eb9fc869cf5c8d349f6bcf266f0a2..99f82311fe99111851b2baac893b6fc899c466d0 100644 --- a/reform2-keyboard-fw/matrix_v.h +++ b/reform2-keyboard-fw/matrix_v.h @@ -37,15 +37,15 @@ uint8_t matrix[KBD_MATRIX_SZ] = { uint8_t matrix_fn[KBD_MATRIX_SZ] = { // Custom top row KEY_ESCAPE, - KEY_F1, - KEY_F2, + HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_DOWN, + HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_UP, KEY_F3, KEY_F4, KEY_F5, KEY_F6, - HID_KEYBOARD_SC_MEDIA_BACKWARD, + HID_KEYBOARD_SC_MEDIA_PREVIOUS_TRACK, HID_KEYBOARD_SC_MEDIA_PLAY, - HID_KEYBOARD_SC_MEDIA_FORWARD, + HID_KEYBOARD_SC_MEDIA_NEXT_TRACK, HID_KEYBOARD_SC_MEDIA_MUTE, HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN, HID_KEYBOARD_SC_MEDIA_VOLUME_UP, @@ -90,15 +90,15 @@ uint8_t matrix_fn[KBD_MATRIX_SZ] = { uint8_t matrix_fn_toggled[KBD_MATRIX_SZ] = { // Custom top row KEY_ESCAPE, - KEY_F1, - KEY_F2, + HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_DOWN, + HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_UP, KEY_F3, KEY_F4, KEY_F5, KEY_F6, - HID_KEYBOARD_SC_MEDIA_BACKWARD, + HID_KEYBOARD_SC_MEDIA_PREVIOUS_TRACK, HID_KEYBOARD_SC_MEDIA_PLAY, - HID_KEYBOARD_SC_MEDIA_FORWARD, + HID_KEYBOARD_SC_MEDIA_NEXT_TRACK, HID_KEYBOARD_SC_MEDIA_MUTE, HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN, HID_KEYBOARD_SC_MEDIA_VOLUME_UP,