]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - tmk_core/common/report.h
[Keyboard] Snagpad Configurator bugfix and readme refactor (#6381)
[qmk_firmware.git] / tmk_core / common / report.h
index 0c799eca39af5581cb22912f24ea749524afc11a..e7c31bd376a08fa4263bddef15a18abb4ebb7bb6 100644 (file)
@@ -23,9 +23,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
 /* report id */
-#define REPORT_ID_MOUSE     1
-#define REPORT_ID_SYSTEM    2
-#define REPORT_ID_CONSUMER  3
+#define REPORT_ID_KEYBOARD  1
+#define REPORT_ID_MOUSE     2
+#define REPORT_ID_SYSTEM    3
+#define REPORT_ID_CONSUMER  4
+#define REPORT_ID_NKRO      5
 
 /* mouse buttons */
 #define MOUSE_BTN1 (1<<0)
@@ -36,6 +38,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 /* Consumer Page(0x0C)
  * following are supported by Windows: http://msdn.microsoft.com/en-us/windows/hardware/gg463372.aspx
+ * see also https://docs.microsoft.com/en-us/windows-hardware/drivers/hid/display-brightness-control
  */
 #define AUDIO_MUTE              0x00E2
 #define AUDIO_VOL_UP            0x00E9
@@ -45,6 +48,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define TRANSPORT_STOP          0x00B7
 #define TRANSPORT_STOP_EJECT    0x00CC
 #define TRANSPORT_PLAY_PAUSE    0x00CD
+#define BRIGHTNESS_UP           0x006F
+#define BRIGHTNESS_DOWN         0x0070
 /* application launch */
 #define AL_CC_CONFIG            0x0183
 #define AL_EMAIL                0x018A
@@ -72,29 +77,35 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define SYSTEM_WAKE_UP          0x0083
 
 
+#define NKRO_SHARED_EP
 /* key report size(NKRO or boot mode) */
-#if defined(PROTOCOL_PJRC) && defined(NKRO_ENABLE)
-#   include "usb.h"
-#   define KEYBOARD_REPORT_SIZE KBD2_SIZE
-#   define KEYBOARD_REPORT_KEYS (KBD2_SIZE - 2)
-#   define KEYBOARD_REPORT_BITS (KBD2_SIZE - 1)
-
-#elif defined(PROTOCOL_LUFA) && defined(NKRO_ENABLE)
-#   include "protocol/lufa/descriptor.h"
-#   define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
-#   define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
-#   define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
-#elif defined(PROTOCOL_CHIBIOS) && defined(NKRO_ENABLE)
-#   include "protocol/chibios/usb_main.h"
-#   define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
-#   define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
-#   define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
+#if defined(NKRO_ENABLE)
+  #if defined(PROTOCOL_LUFA) || defined(PROTOCOL_CHIBIOS)
+    #include "protocol/usb_descriptor.h"
+    #define KEYBOARD_REPORT_BITS (SHARED_EPSIZE - 2)
+  #elif defined(PROTOCOL_ARM_ATSAM)
+    #include "protocol/arm_atsam/usb/udi_device_epsize.h"
+    #define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
+    #undef NKRO_SHARED_EP
+    #undef MOUSE_SHARED_EP
+  #else
+    #error "NKRO not supported with this protocol"
+  #endif
+#endif
 
+#ifdef KEYBOARD_SHARED_EP
+#   define KEYBOARD_REPORT_SIZE 9
 #else
 #   define KEYBOARD_REPORT_SIZE 8
-#   define KEYBOARD_REPORT_KEYS 6
 #endif
 
+#define KEYBOARD_REPORT_KEYS 6
+
+/* VUSB hardcodes keyboard and mouse+extrakey only */
+#if defined(PROTOCOL_VUSB)
+  #undef KEYBOARD_SHARED_EP
+  #undef MOUSE_SHARED_EP
+#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -123,26 +134,28 @@ extern "C" {
 typedef union {
     uint8_t raw[KEYBOARD_REPORT_SIZE];
     struct {
+#ifdef KEYBOARD_SHARED_EP
+        uint8_t report_id;
+#endif
         uint8_t mods;
         uint8_t reserved;
         uint8_t keys[KEYBOARD_REPORT_KEYS];
     };
 #ifdef NKRO_ENABLE
-    struct {
+    struct nkro_report {
+#ifdef NKRO_SHARED_EP
+        uint8_t report_id;
+#endif
         uint8_t mods;
         uint8_t bits[KEYBOARD_REPORT_BITS];
     } nkro;
 #endif
 } __attribute__ ((packed)) report_keyboard_t;
-/*
-typedef struct {
-    uint8_t mods;
-    uint8_t reserved;
-    uint8_t keys[REPORT_KEYS];
-} __attribute__ ((packed)) report_keyboard_t;
-*/
 
 typedef struct {
+#ifdef MOUSE_SHARED_EP
+    uint8_t report_id;
+#endif
     uint8_t buttons;
     int8_t x;
     int8_t y;
@@ -179,7 +192,23 @@ typedef struct {
     (key == KC_WWW_FORWARD      ?  AC_FORWARD : \
     (key == KC_WWW_STOP         ?  AC_STOP : \
     (key == KC_WWW_REFRESH      ?  AC_REFRESH : \
-    (key == KC_WWW_FAVORITES    ?  AC_BOOKMARKS : 0)))))))))))))))))))))
+    (key == KC_BRIGHTNESS_UP    ?  BRIGHTNESS_UP : \
+    (key == KC_BRIGHTNESS_DOWN  ?  BRIGHTNESS_DOWN : \
+    (key == KC_WWW_FAVORITES    ?  AC_BOOKMARKS : 0)))))))))))))))))))))))
+
+uint8_t has_anykey(report_keyboard_t* keyboard_report);
+uint8_t get_first_key(report_keyboard_t* keyboard_report);
+
+void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code);
+void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code);
+#ifdef NKRO_ENABLE
+void add_key_bit(report_keyboard_t* keyboard_report, uint8_t code);
+void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code);
+#endif
+
+void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key);
+void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key);
+void clear_keys_from_report(report_keyboard_t* keyboard_report);
 
 #ifdef __cplusplus
 }