summaryrefslogtreecommitdiff
path: root/hid/src/proto.h
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-11-16 00:43:36 +0300
committerDevaev Maxim <[email protected]>2020-11-16 00:44:14 +0300
commit7efff23ca4da87132169f8f98942cc6290e7cfd8 (patch)
treea0c5c400ced7be3d6ffca414fa0d230c681b7772 /hid/src/proto.h
parentf5250bb0e90b005128bd5025604cc41d3c3f7392 (diff)
refactoring
Diffstat (limited to 'hid/src/proto.h')
-rw-r--r--hid/src/proto.h84
1 files changed, 53 insertions, 31 deletions
diff --git a/hid/src/proto.h b/hid/src/proto.h
index 617711dd..ca9b4f2c 100644
--- a/hid/src/proto.h
+++ b/hid/src/proto.h
@@ -23,41 +23,63 @@
#pragma once
-#define PROTO_MAGIC 0x33
-#define PROTO_CRC_POLINOM 0xA001
+namespace PROTO {
+ const uint8_t MAGIC = 0x33;
+ const uint16_t CRC_POLINOM = 0xA001;
-// #define PROTO_RESP_OK 0x20 // Legacy
-#define PROTO_RESP_NONE 0x24
-#define PROTO_RESP_CRC_ERROR 0x40
-#define PROTO_RESP_INVALID_ERROR 0x45
-#define PROTO_RESP_TIMEOUT_ERROR 0x48
+ namespace RESP { // Plain responses
+ // const uint8_t OK = 0x20; // Legacy
+ const uint8_t NONE = 0x24;
+ const uint8_t CRC_ERROR = 0x40;
+ const uint8_t INVALID_ERROR = 0x45;
+ const uint8_t TIMEOUT_ERROR = 0x48;
+ };
-#define PROTO_RESP_PONG_PREFIX 0x80
-#define PROTO_RESP_PONG_CAPS 0b00000001
-#define PROTO_RESP_PONG_SCROLL 0b00000010
-#define PROTO_RESP_PONG_NUM 0b00000100
-#define PROTO_RESP_PONG_KEYBOARD_OFFLINE 0b00001000
-#define PROTO_RESP_PONG_MOUSE_OFFLINE 0b00010000
+ namespace PONG { // Complex response
+ const uint8_t PREFIX = 0x80;
+ const uint8_t CAPS = 0b00000001;
+ const uint8_t SCROLL = 0b00000010;
+ const uint8_t NUM = 0b00000100;
+ const uint8_t KEYBOARD_OFFLINE = 0b00001000;
+ const uint8_t MOUSE_OFFLINE = 0b00010000;
+ };
-#define PROTO_CMD_PING 0x01
-#define PROTO_CMD_REPEAT 0x02
-#define PROTO_CMD_RESET_HID 0x10
-#define PROTO_CMD_KEY_EVENT 0x11
-#define PROTO_CMD_MOUSE_BUTTON_EVENT 0x13 // Legacy sequence
-#define PROTO_CMD_MOUSE_MOVE_EVENT 0x12
-#define PROTO_CMD_MOUSE_WHEEL_EVENT 0x14
+ namespace CMD {
+ const uint8_t PING = 0x01;
+ const uint8_t REPEAT = 0x02;
+ const uint8_t RESET_HID = 0x10;
-#define PROTO_CMD_MOUSE_BUTTON_LEFT_SELECT 0b10000000
-#define PROTO_CMD_MOUSE_BUTTON_LEFT_STATE 0b00001000
-#define PROTO_CMD_MOUSE_BUTTON_RIGHT_SELECT 0b01000000
-#define PROTO_CMD_MOUSE_BUTTON_RIGHT_STATE 0b00000100
-#define PROTO_CMD_MOUSE_BUTTON_MIDDLE_SELECT 0b00100000
-#define PROTO_CMD_MOUSE_BUTTON_MIDDLE_STATE 0b00000010
+ namespace KEYBOARD {
+ const uint8_t KEY = 0x11;
+ };
-#define PROTO_CMD_MOUSE_BUTTON_EXTRA_UP_SELECT 0b10000000
-#define PROTO_CMD_MOUSE_BUTTON_EXTRA_UP_STATE 0b00001000
-#define PROTO_CMD_MOUSE_BUTTON_EXTRA_DOWN_SELECT 0b01000000
-#define PROTO_CMD_MOUSE_BUTTON_EXTRA_DOWN_STATE 0b00000100
+ namespace MOUSE {
+ const uint8_t MOVE = 0x12;
+ const uint8_t BUTTON = 0x13;
+ const uint8_t WHEEL = 0x14;
+ namespace LEFT {
+ const uint8_t SELECT = 0b10000000;
+ const uint8_t STATE = 0b00001000;
+ };
+ namespace RIGHT {
+ const uint8_t SELECT = 0b01000000;
+ const uint8_t STATE = 0b00000100;
+ };
+ namespace MIDDLE {
+ const uint8_t SELECT = 0b00100000;
+ const uint8_t STATE = 0b00000010;
+ };
+ namespace EXTRA_UP {
+ const uint8_t SELECT = 0b10000000;
+ const uint8_t STATE = 0b00001000;
+ };
+ namespace EXTRA_DOWN {
+ const uint8_t SELECT = 0b01000000;
+ const uint8_t STATE = 0b00000100;
+ };
+ };
+ };
+};
uint16_t protoCrc16(const uint8_t *buffer, unsigned length) {
@@ -70,7 +92,7 @@ uint16_t protoCrc16(const uint8_t *buffer, unsigned length) {
crc = crc >> 1;
} else {
crc = crc >> 1;
- crc = crc ^ PROTO_CRC_POLINOM;
+ crc = crc ^ PROTO::CRC_POLINOM;
}
}
}