Skip to content

Commit 1fd9cbe

Browse files
committed
add HID_KEYCODE_TO_ASCII decode
1 parent 049a0af commit 1fd9cbe

File tree

2 files changed

+125
-4
lines changed

2 files changed

+125
-4
lines changed

libraries/Bluefruit52Lib/src/services/BLEHidGeneric.cpp

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ BLEHidGeneric::BLEHidGeneric(uint8_t num_input, uint8_t num_output, uint8_t num_
4646
: BLEService(UUID16_SVC_HUMAN_INTERFACE_DEVICE), _chr_control(UUID16_CHR_HID_CONTROL_POINT)
4747
{
4848
_has_keyboard = _has_mouse = false;
49-
_protocol_mode = 1; // report mode
49+
_protocol_mode = HID_PROTOCOL_MODE_REPORT;
5050

5151
_report_map = NULL;
5252
_report_map_len = 0;
@@ -284,7 +284,7 @@ bool BLEHidGeneric::bootMouseReport(void const* data, int len)
284284
}
285285

286286
/*------------------------------------------------------------------*/
287-
/*
287+
/* Ascii to Keycode
288288
*------------------------------------------------------------------*/
289289
const hid_ascii_to_keycode_entry_t HID_ASCII_TO_KEYCODE[128] =
290290
{
@@ -421,3 +421,112 @@ const hid_ascii_to_keycode_entry_t HID_ASCII_TO_KEYCODE[128] =
421421
{0, HID_KEY_DELETE } // 0x7F Delete
422422
};
423423

424+
/*------------------------------------------------------------------*/
425+
/* Keycode to Ascii
426+
*------------------------------------------------------------------*/
427+
const hid_keycode_to_ascii_t HID_KEYCODE_TO_ASCII[128] =
428+
{
429+
{0 , 0 }, // 0x00
430+
{0 , 0 }, // 0x01
431+
{0 , 0 }, // 0x02
432+
{0 , 0 }, // 0x03
433+
{'a' , 'A' }, // 0x04
434+
{'b' , 'B' }, // 0x05
435+
{'c' , 'C' }, // 0x06
436+
{'d' , 'D' }, // 0x07
437+
{'e' , 'E' }, // 0x08
438+
{'f' , 'F' }, // 0x09
439+
{'g' , 'G' }, // 0x0a
440+
{'h' , 'H' }, // 0x0b
441+
{'i' , 'I' }, // 0x0c
442+
{'j' , 'J' }, // 0x0d
443+
{'k' , 'K' }, // 0x0e
444+
{'l' , 'L' }, // 0x0f
445+
{'m' , 'M' }, // 0x10
446+
{'n' , 'N' }, // 0x11
447+
{'o' , 'O' }, // 0x12
448+
{'p' , 'P' }, // 0x13
449+
{'q' , 'Q' }, // 0x14
450+
{'r' , 'R' }, // 0x15
451+
{'s' , 'S' }, // 0x16
452+
{'t' , 'T' }, // 0x17
453+
{'u' , 'U' }, // 0x18
454+
{'v' , 'V' }, // 0x19
455+
{'w' , 'W' }, // 0x1a
456+
{'x' , 'X' }, // 0x1b
457+
{'y' , 'Y' }, // 0x1c
458+
{'z' , 'Z' }, // 0x1d
459+
{'1' , '!' }, // 0x1e
460+
{'2' , '@' }, // 0x1f
461+
{'3' , '#' }, // 0x20
462+
{'4' , '$' }, // 0x21
463+
{'5' , '%' }, // 0x22
464+
{'6' , '^' }, // 0x23
465+
{'7' , '&' }, // 0x24
466+
{'8' , '*' }, // 0x25
467+
{'9' , '(' }, // 0x26
468+
{'0' , ')' }, // 0x27
469+
{'\r' , '\r' }, // 0x28
470+
{'\x1b', '\x1b' }, // 0x29
471+
{'\b' , '\b' }, // 0x2a
472+
{'\t' , '\t' }, // 0x2b
473+
{' ' , ' ' }, // 0x2c
474+
{'-' , '_' }, // 0x2d
475+
{'=' , '+' }, // 0x2e
476+
{'[' , '{' }, // 0x2f
477+
{']' , '}' }, // 0x30
478+
{'\\' , '|' }, // 0x31
479+
{'#' , '~' }, // 0x32
480+
{';' , ':' }, // 0x33
481+
{'\'' , '\"' }, // 0x34
482+
{0 , 0 }, // 0x35
483+
{',' , '<' }, // 0x36
484+
{'.' , '>' }, // 0x37
485+
{'/' , '?' }, // 0x38
486+
487+
{0 , 0 }, // 0x39
488+
{0 , 0 }, // 0x3a
489+
{0 , 0 }, // 0x3b
490+
{0 , 0 }, // 0x3c
491+
{0 , 0 }, // 0x3d
492+
{0 , 0 }, // 0x3e
493+
{0 , 0 }, // 0x3f
494+
{0 , 0 }, // 0x40
495+
{0 , 0 }, // 0x41
496+
{0 , 0 }, // 0x42
497+
{0 , 0 }, // 0x43
498+
{0 , 0 }, // 0x44
499+
{0 , 0 }, // 0x45
500+
{0 , 0 }, // 0x46
501+
{0 , 0 }, // 0x47
502+
{0 , 0 }, // 0x48
503+
{0 , 0 }, // 0x49
504+
{0 , 0 }, // 0x4a
505+
{0 , 0 }, // 0x4b
506+
{0 , 0 }, // 0x4c
507+
{0 , 0 }, // 0x4d
508+
{0 , 0 }, // 0x4e
509+
{0 , 0 }, // 0x4f
510+
{0 , 0 }, // 0x50
511+
{0 , 0 }, // 0x51
512+
{0 , 0 }, // 0x52
513+
{0 , 0 }, // 0x53
514+
515+
{'/' , '/' }, // 0x54
516+
{'*' , '*' }, // 0x55
517+
{'-' , '-' }, // 0x56
518+
{'+' , '+' }, // 0x57
519+
{'\r' , '\r' }, // 0x58
520+
{'1' , 0 }, // 0x59 /* numpad1 & end */ \
521+
{'2' , 0 }, // 0x5a
522+
{'3' , 0 }, // 0x5b
523+
{'4' , 0 }, // 0x5c
524+
{'5' , '5' }, // 0x5d
525+
{'6' , 0 }, // 0x5e
526+
{'7' , 0 }, // 0x5f
527+
{'8' , 0 }, // 0x60
528+
{'9' , 0 }, // 0x61
529+
{'0' , 0 }, // 0x62
530+
{'0' , 0 }, // 0x63
531+
{'=' , '=' }, // 0x67
532+
};

libraries/Bluefruit52Lib/src/services/BLEHidGeneric.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,24 @@
4141
#include "BLECharacteristic.h"
4242
#include "BLEService.h"
4343

44+
enum
45+
{
46+
HID_PROTOCOL_MODE_BOOT = 0,
47+
HID_PROTOCOL_MODE_REPORT = 1
48+
};
49+
4450
typedef struct{
4551
uint8_t shift;
4652
uint8_t keycode;
4753
}hid_ascii_to_keycode_entry_t;
4854
extern const hid_ascii_to_keycode_entry_t HID_ASCII_TO_KEYCODE[128];
4955

56+
typedef struct{
57+
uint8_t ascii;
58+
uint8_t shifted;
59+
}hid_keycode_to_ascii_t;
60+
extern hid_keycode_to_ascii_t const HID_KEYCODE_TO_ASCII[128];
61+
5062
/// Standard HID Boot Protocol Mouse Report.
5163
typedef ATTR_PACKED_STRUCT(struct)
5264
{
@@ -103,7 +115,7 @@ class BLEHidGeneric : public BLEService
103115

104116
virtual err_t begin(void);
105117

106-
bool isBootMode(void) { return _protocol_mode == 0; }
118+
bool isBootMode(void) { return _protocol_mode == HID_PROTOCOL_MODE_BOOT; }
107119

108120
// Report
109121
bool inputReport(uint8_t reportID, void const* data, int len);
@@ -117,7 +129,7 @@ class BLEHidGeneric : public BLEService
117129

118130
bool _has_keyboard;
119131
bool _has_mouse;
120-
bool _protocol_mode; // 0 boot, 1 report (default)
132+
bool _protocol_mode;
121133

122134
uint8_t _hid_info[4];
123135
const uint8_t* _report_map;

0 commit comments

Comments
 (0)