Initial commit of base code
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
#include "tusb.h"
|
||||
|
||||
#include "parse_keys.h"
|
||||
#include "usb_descriptors.h"
|
||||
|
||||
void parse_key_list(char * keys) {
|
||||
uint8_t keypos = 2;
|
||||
uint8_t code = 0x00;
|
||||
static unsigned char boot_report[8];
|
||||
memset(boot_report, 0x00, 8);
|
||||
|
||||
char * token = strtok(keys, ",");
|
||||
while (token != NULL) {
|
||||
code = parse_key_single(token);
|
||||
if (code && keypos < 9) {
|
||||
boot_report[keypos] = code;
|
||||
keypos++;
|
||||
}
|
||||
if (code == 0x00) {
|
||||
code = parse_mod(token);
|
||||
if (code) {
|
||||
boot_report[0] = boot_report[0] | code;
|
||||
}
|
||||
}
|
||||
token = strtok(NULL, ",");
|
||||
}
|
||||
|
||||
printf("HID report: ");
|
||||
for(int i=0; i<8; i++){
|
||||
printf("%02X ",boot_report[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
tud_hid_report(REPORT_ID_KEYBOARD, boot_report, 8);
|
||||
}
|
||||
|
||||
uint8_t parse_key_single(char * key) {
|
||||
//printf("single key: %s\n", key);
|
||||
|
||||
for (int i=0; i < NKEYS; i++) {
|
||||
keycode_dict * keycode = &keytable[i];
|
||||
if (strcmp(keycode->key, key) == 0){
|
||||
//printf("key found");
|
||||
return keycode->val;
|
||||
}
|
||||
}
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
uint8_t parse_mod(char * key) {
|
||||
for (int i=0; i < NMODS; i++) {
|
||||
keycode_dict * modcode = &modtable[i];
|
||||
if (strcmp(modcode->key, key) == 0){
|
||||
//printf("key found");
|
||||
return modcode->val;
|
||||
}
|
||||
}
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user