mirror of
https://github.com/fruit-bat/pico-zxspectrum.git
synced 2025-04-19 00:04:01 +03:00
Tidy key handler
This commit is contained in:
parent
66fec82380
commit
cca8562489
@ -104,8 +104,7 @@ ZxSpectrumHidKeyboard::ZxSpectrumHidKeyboard(ZxSpectrumFileLoop *zxSpectrumSnapL
|
||||
sort_keys();
|
||||
}
|
||||
|
||||
void ZxSpectrumHidKeyboard::processHidReport(hid_keyboard_report_t const *report) {
|
||||
static hid_keyboard_report_t prev = { 0, 0, {0} };
|
||||
void ZxSpectrumHidKeyboard::processHidReport(hid_keyboard_report_t const *report, hid_keyboard_report_t const *prev_report) {
|
||||
reset();
|
||||
if (report->keycode[0] == 1) return;
|
||||
const unsigned char m = report->modifier;
|
||||
@ -125,7 +124,7 @@ void ZxSpectrumHidKeyboard::processHidReport(hid_keyboard_report_t const *report
|
||||
const unsigned char fkc = HID_KEY_F1 + fk;
|
||||
if (hidKeyCode == fkc) {
|
||||
fkd |= fkb;
|
||||
if (!isInReport(&prev, fkc)) fkp |= fkb;
|
||||
if (!isInReport(prev_report, fkc)) fkp |= fkb;
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,6 +172,4 @@ void ZxSpectrumHidKeyboard::processHidReport(hid_keyboard_report_t const *report
|
||||
if (fkp & (1 << 6)) _zxSpectrumTapeList->next(_ZxSpectrum);
|
||||
|
||||
}
|
||||
|
||||
prev = *report;
|
||||
}
|
||||
|
@ -13,6 +13,6 @@ class ZxSpectrumHidKeyboard : public ZxSpectrumKeyboard {
|
||||
QuickSave* _quickSave;
|
||||
public:
|
||||
ZxSpectrumHidKeyboard(ZxSpectrumFileLoop* zxSpectrumSnapList, ZxSpectrumFileLoop* zxSpectrumTapeList, QuickSave* quickSave);
|
||||
void processHidReport(hid_keyboard_report_t const *report);
|
||||
void processHidReport(hid_keyboard_report_t const *report, hid_keyboard_report_t const *prev_report);
|
||||
void setZxSpectrum(ZxSpectrum *ZxSpectrum) { _ZxSpectrum = ZxSpectrum; }
|
||||
};
|
||||
|
41
hid_app.c
41
hid_app.c
@ -26,7 +26,7 @@
|
||||
#include "bsp/board.h"
|
||||
#include "tusb.h"
|
||||
|
||||
extern void spectrum_keyboard_handler(hid_keyboard_report_t const *report);
|
||||
extern void process_kbd_report(hid_keyboard_report_t const *report, hid_keyboard_report_t const *prev_report);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
@ -41,7 +41,11 @@ extern void spectrum_keyboard_handler(hid_keyboard_report_t const *report);
|
||||
static uint8_t _report_count[CFG_TUH_HID];
|
||||
static tuh_hid_report_info_t _report_info_arr[CFG_TUH_HID][MAX_REPORT];
|
||||
|
||||
static void process_kbd_report(hid_keyboard_report_t const *report);
|
||||
// Keep a copy of any previous keyboard report.
|
||||
// Currently, only capable of supporting a single keyboard, as
|
||||
// one of these is required each.
|
||||
static hid_keyboard_report_t prev_key_report = { 0, 0, {0} };
|
||||
|
||||
static void process_mouse_report(hid_mouse_report_t const * report);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -61,8 +65,20 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_re
|
||||
|
||||
// Parse report descriptor with built-in parser
|
||||
_report_count[instance] = tuh_hid_parse_report_descriptor(_report_info_arr[instance], MAX_REPORT, desc_report, desc_len);
|
||||
printf("HID has %u reports and interface protocol = %s\r\n", _report_count[instance], protocol_str[interface_protocol]);
|
||||
|
||||
printf(
|
||||
"HID has %u reports and interface protocol %d = %s\r\n",
|
||||
_report_count[instance],
|
||||
interface_protocol,
|
||||
interface_protocol < 3 ? protocol_str[interface_protocol] : "Unknown"
|
||||
);
|
||||
|
||||
// Mounting keyboard
|
||||
if (interface_protocol == 1) {
|
||||
// Clear down previous keyboard report
|
||||
memset(&prev_key_report, 0, sizeof(hid_keyboard_report_t));
|
||||
}
|
||||
|
||||
// request to receive report
|
||||
// tuh_hid_report_received_cb() will be invoked when report is available
|
||||
if ( !tuh_hid_receive_report(dev_addr, instance) )
|
||||
@ -117,12 +133,14 @@ void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t i
|
||||
{
|
||||
switch (rpt_info->usage)
|
||||
{
|
||||
case HID_USAGE_DESKTOP_KEYBOARD:
|
||||
case HID_USAGE_DESKTOP_KEYBOARD: {
|
||||
TU_LOG1("HID receive keyboard report\r\n");
|
||||
// Assume keyboard follow boot report layout
|
||||
process_kbd_report( (hid_keyboard_report_t const*) report );
|
||||
break;
|
||||
|
||||
hid_keyboard_report_t const* key_report = (hid_keyboard_report_t const*) report;
|
||||
process_kbd_report( key_report, &prev_key_report);
|
||||
prev_key_report = *key_report;
|
||||
break;
|
||||
}
|
||||
case HID_USAGE_DESKTOP_MOUSE:
|
||||
TU_LOG1("HID receive mouse report\r\n");
|
||||
// Assume mouse follow boot report layout
|
||||
@ -140,15 +158,6 @@ void __not_in_flash_func(tuh_hid_report_received_cb)(uint8_t dev_addr, uint8_t i
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Keyboard
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static void process_kbd_report(hid_keyboard_report_t const *report)
|
||||
{
|
||||
spectrum_keyboard_handler(report);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Mouse
|
||||
//--------------------------------------------------------------------+
|
||||
|
4
main.cpp
4
main.cpp
@ -143,8 +143,8 @@ void __not_in_flash_func(core1_main)() {
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
extern "C" void spectrum_keyboard_handler(hid_keyboard_report_t const *report) {
|
||||
keyboard.processHidReport(report);
|
||||
extern "C" void process_kbd_report(hid_keyboard_report_t const *report, hid_keyboard_report_t const *prev_report) {
|
||||
keyboard.processHidReport(report, prev_report);
|
||||
}
|
||||
|
||||
extern "C" int __not_in_flash_func(main)() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user