From 821c91e4dd3529a48ae588cb48d6e342f71a5baf Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 9 Sep 2020 17:03:32 +1000 Subject: [PATCH 01/12] make USB HID period configurable (and default is now 8ms) --- src/protocol/usbhid.c | 29 +++++++++++++++++++++++++++- src/target/drivers/mcu/emu/stubs.c | 3 +++ src/target/drivers/usb/devo_hid.c | 10 ++++++++-- src/target/tx/opentx/t12/x9d_stubs.c | 3 +++ src/target/tx/opentx/x9d/x9d_stubs.c | 3 +++ 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/protocol/usbhid.c b/src/protocol/usbhid.c index ddf8529b49..d57d5995bd 100644 --- a/src/protocol/usbhid.c +++ b/src/protocol/usbhid.c @@ -18,6 +18,17 @@ #include "mixer.h" #include "config/model.h" +static const char * const usbhid_opts[] = { + _tr_noop("Period (ms)"), "1", "64", NULL, + NULL +}; +enum { + PROTO_OPTS_PERIOD, + LAST_PROTO_OPT, +}; +ctassert(LAST_PROTO_OPT <= NUM_PROTO_OPTS, too_many_protocol_opts); +#define USBHID_FRAME_PERIOD_STD 8 // 8ms default period for 125Hz + //To change USBHID_MAX_CHANNELS you must change the Report_Descriptor in hid_usb_desc.c as well #define USBHID_ANALOG_CHANNELS 8 #define USBHID_DIGITAL_CHANNELS 4 @@ -57,13 +68,23 @@ static void build_data_pkt() packet[USBHID_ANALOG_CHANNELS] = digital; } +// ms suffix to indicate that this is in milliseconds not microseconds like other protocols +static u16 usbhid_period_ms; static u16 usbhid_cb() { + if (usbhid_period_ms != Model.proto_opts[PROTO_OPTS_PERIOD]) { + usbhid_period_ms = Model.proto_opts[PROTO_OPTS_PERIOD]; + // HID should be restarted when period changes + // this lets us update the endpoint descriptor's bInterval field + HID_Disable(); + HID_SetInterval(usbhid_period_ms); + HID_Enable(); + } build_data_pkt(); HID_Write(packet, sizeof(packet)); - return 50000; + return usbhid_period_ms * 1000; } static void deinit() @@ -76,6 +97,8 @@ static void initialize() { CLOCK_StopTimer(); num_channels = Model.num_channels; + usbhid_period_ms = Model.proto_opts[PROTO_OPTS_PERIOD] ? Model.proto_opts[PROTO_OPTS_PERIOD] : USBHID_FRAME_PERIOD_STD; + HID_SetInterval(usbhid_period_ms); HID_Enable(); CLOCK_StartTimer(1000, usbhid_cb); } @@ -91,6 +114,10 @@ uintptr_t USBHID_Cmds(enum ProtoCmds cmd) case PROTOCMD_DEFAULT_NUMCHAN: return 6; case PROTOCMD_CHANNELMAP: return UNCHG; case PROTOCMD_TELEMETRYSTATE: return PROTO_TELEM_UNSUPPORTED; + case PROTOCMD_GETOPTIONS: + if (!Model.proto_opts[PROTO_OPTS_PERIOD]) + Model.proto_opts[PROTO_OPTS_PERIOD] = USBHID_FRAME_PERIOD_STD; + return (uintptr_t)usbhid_opts; default: break; } return 0; diff --git a/src/target/drivers/mcu/emu/stubs.c b/src/target/drivers/mcu/emu/stubs.c index a9cdc2e86d..5100bc2885 100755 --- a/src/target/drivers/mcu/emu/stubs.c +++ b/src/target/drivers/mcu/emu/stubs.c @@ -36,6 +36,9 @@ void TxName(u8 *var, int len) { } void MSC_Enable() {} void MSC_Disable() {} +void HID_SetInterval(u8 interval) { + (void)interval; +} void HID_Enable() {} void HID_Disable() {} void HID_Write(s8 *pkt, u8 size) { diff --git a/src/target/drivers/usb/devo_hid.c b/src/target/drivers/usb/devo_hid.c index 0490c18e75..a8efe03a3a 100644 --- a/src/target/drivers/usb/devo_hid.c +++ b/src/target/drivers/usb/devo_hid.c @@ -72,13 +72,14 @@ static const struct { } }; -static const struct usb_endpoint_descriptor hid_endpoint = { +// this is no longer const so that bInterval can be modified at runtime +static struct usb_endpoint_descriptor hid_endpoint = { .bLength = USB_DT_ENDPOINT_SIZE, .bDescriptorType = USB_DT_ENDPOINT, .bEndpointAddress = 0x81, .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, .wMaxPacketSize = 9, - .bInterval = 0x20, + .bInterval = 8, }; static const struct usb_interface_descriptor hid_iface = { @@ -171,6 +172,11 @@ void HID_Write(s8 *packet, u8 size) } } +void HID_SetInterval(u8 interval) +{ + hid_endpoint.bInterval = interval; +} + void HID_Enable() { usb_preXferComplete = 0; USB_Enable(1); diff --git a/src/target/tx/opentx/t12/x9d_stubs.c b/src/target/tx/opentx/t12/x9d_stubs.c index f1a8825138..42712bf91f 100644 --- a/src/target/tx/opentx/t12/x9d_stubs.c +++ b/src/target/tx/opentx/t12/x9d_stubs.c @@ -24,6 +24,9 @@ void USB_Enable(unsigned use_interrupt) { (void)use_interrupt; } void USB_Disable() {} +void HID_SetInterval(u8 interval) { + (void)interval; +} void HID_Enable() {} void HID_Disable() {} void HID_Write(s8 *pkt, u8 size) { diff --git a/src/target/tx/opentx/x9d/x9d_stubs.c b/src/target/tx/opentx/x9d/x9d_stubs.c index b79e9e1184..bb4a843aec 100644 --- a/src/target/tx/opentx/x9d/x9d_stubs.c +++ b/src/target/tx/opentx/x9d/x9d_stubs.c @@ -20,6 +20,9 @@ #include "common.h" void MSC_Enable() {} void MSC_Disable() {} +void HID_SetInterval(u8 interval) { + (void)interval; +} void HID_Enable() {} void HID_Disable() {} void HID_Write(s8 *pkt, u8 size) { From edb356ac1b3b53805973deed44cb90733f0596e3 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Thu, 10 Sep 2020 14:37:40 +1000 Subject: [PATCH 02/12] add HID_SetInterval to target.h --- src/target.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/target.h b/src/target.h index 5b8ba94aaf..e76a4de600 100644 --- a/src/target.h +++ b/src/target.h @@ -293,6 +293,7 @@ void USB_Disable(); void USB_HandleISR(); void USB_Connect(); +void HID_SetInterval(u8 interval); void HID_Enable(); void HID_Disable(); From e2ca36f914b6772b67719a38386a61003c6f787a Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Thu, 10 Sep 2020 14:38:46 +1000 Subject: [PATCH 03/12] fix lint error (whitespace/comments) --- src/protocol/usbhid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/protocol/usbhid.c b/src/protocol/usbhid.c index d57d5995bd..a45293e63f 100644 --- a/src/protocol/usbhid.c +++ b/src/protocol/usbhid.c @@ -27,7 +27,7 @@ enum { LAST_PROTO_OPT, }; ctassert(LAST_PROTO_OPT <= NUM_PROTO_OPTS, too_many_protocol_opts); -#define USBHID_FRAME_PERIOD_STD 8 // 8ms default period for 125Hz +#define USBHID_FRAME_PERIOD_STD 8 // 8ms default period for 125Hz //To change USBHID_MAX_CHANNELS you must change the Report_Descriptor in hid_usb_desc.c as well #define USBHID_ANALOG_CHANNELS 8 From cb8bce2fe74fdbaac0734204c42ea7525f4cdd66 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Thu, 10 Sep 2020 14:54:14 +1000 Subject: [PATCH 04/12] add HID_SetInterval to test stubs --- src/target/tx/other/test/test_stubs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/target/tx/other/test/test_stubs.c b/src/target/tx/other/test/test_stubs.c index 40b65886a2..d4f7673ce8 100644 --- a/src/target/tx/other/test/test_stubs.c +++ b/src/target/tx/other/test/test_stubs.c @@ -105,6 +105,9 @@ void TxName(u8 *var, int len) { } void MSC_Enable() {} void MSC_Disable() {} +void HID_SetInterval(u8 interval) { + (void)interval; +} void HID_Enable() {} void HID_Disable() {} void HID_Write(s8 *pkt, u8 size) { From bd0587a210fe5cbb49a4589bb649eabf1fa54785 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Fri, 11 Sep 2020 14:41:06 +1000 Subject: [PATCH 05/12] moeder's solution for USB HID compilation on 7e/f7 --- src/protocol/exports.ld | 2 ++ src/protocol/usbhid.c | 1 - src/target.h | 1 + src/target/drivers/usb/devo_hid.c | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/protocol/exports.ld b/src/protocol/exports.ld index 861110109f..43098e88f1 100644 --- a/src/protocol/exports.ld +++ b/src/protocol/exports.ld @@ -21,6 +21,8 @@ EXTERN(TELEMETRY_SetUpdated) EXTERN(USB_Enable) EXTERN(USB_Disable) +EXTERN(HID_SetInterval) +EXTERN(HID_Write) EXTERN(usbd_dev) EXTERN(USB_Product_Name) diff --git a/src/protocol/usbhid.c b/src/protocol/usbhid.c index a45293e63f..99d8ebf168 100644 --- a/src/protocol/usbhid.c +++ b/src/protocol/usbhid.c @@ -40,7 +40,6 @@ ctassert(LAST_PROTO_OPT <= NUM_PROTO_OPTS, too_many_protocol_opts); //if sizeof(packet) changes, must change wMaxPacketSize to match in Joystick_ConfigDescriptor static s8 packet[USBHID_ANALOG_CHANNELS + 1]; static u8 num_channels; -extern void HID_Write(s8 *packet, u8 size); static void build_data_pkt() { diff --git a/src/target.h b/src/target.h index e76a4de600..a7c1daf018 100644 --- a/src/target.h +++ b/src/target.h @@ -296,6 +296,7 @@ void USB_Connect(); void HID_SetInterval(u8 interval); void HID_Enable(); void HID_Disable(); +void HID_Write(s8 *packet, u8 size); void MSC_Enable(); void MSC_Disable(); diff --git a/src/target/drivers/usb/devo_hid.c b/src/target/drivers/usb/devo_hid.c index a8efe03a3a..68a4159a31 100644 --- a/src/target/drivers/usb/devo_hid.c +++ b/src/target/drivers/usb/devo_hid.c @@ -73,7 +73,7 @@ static const struct { }; // this is no longer const so that bInterval can be modified at runtime -static struct usb_endpoint_descriptor hid_endpoint = { +struct usb_endpoint_descriptor hid_endpoint = { .bLength = USB_DT_ENDPOINT_SIZE, .bDescriptorType = USB_DT_ENDPOINT, .bEndpointAddress = 0x81, From 53a989c0a78f3b9d13b0d78e2120a86309a91b7d Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Thu, 17 Sep 2020 21:21:55 +1000 Subject: [PATCH 06/12] usbhid: simplify period selection to 125/250/500/1000 Hz, and make mixer run in-sync with protocol mixer timing code is copied from sbus/sumd --- src/protocol/usbhid.c | 54 +++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/src/protocol/usbhid.c b/src/protocol/usbhid.c index 99d8ebf168..2628c9dd73 100644 --- a/src/protocol/usbhid.c +++ b/src/protocol/usbhid.c @@ -19,7 +19,7 @@ #include "config/model.h" static const char * const usbhid_opts[] = { - _tr_noop("Period (ms)"), "1", "64", NULL, + _tr_noop("Period (Hz)"), "125", "250", "500", "1000", NULL, NULL }; enum { @@ -27,7 +27,18 @@ enum { LAST_PROTO_OPT, }; ctassert(LAST_PROTO_OPT <= NUM_PROTO_OPTS, too_many_protocol_opts); -#define USBHID_FRAME_PERIOD_STD 8 // 8ms default period for 125Hz + +# define USBHID_PERIOD_MAX_INDEX 3 +static u16 period_index_to_ms(s16 idx) +{ + switch (idx) { + case 3: return 1; + case 2: return 2; + case 1: return 4; + default: return 8; + } + return 8; +} //To change USBHID_MAX_CHANNELS you must change the Report_Descriptor in hid_usb_desc.c as well #define USBHID_ANALOG_CHANNELS 8 @@ -67,23 +78,40 @@ static void build_data_pkt() packet[USBHID_ANALOG_CHANNELS] = digital; } -// ms suffix to indicate that this is in milliseconds not microseconds like other protocols +static enum { + ST_DATA1, + ST_DATA2, +} state; + +static u16 mixer_runtime; +// ms suffix on usbhid_period_ms to indicate that it's in milliseconds not microseconds like other protocols static u16 usbhid_period_ms; static u16 usbhid_cb() { - if (usbhid_period_ms != Model.proto_opts[PROTO_OPTS_PERIOD]) { - usbhid_period_ms = Model.proto_opts[PROTO_OPTS_PERIOD]; + u16 protoopts_period = period_index_to_ms(Model.proto_opts[PROTO_OPTS_PERIOD]); + if (usbhid_period_ms != protoopts_period) { + usbhid_period_ms = protoopts_period; // HID should be restarted when period changes // this lets us update the endpoint descriptor's bInterval field HID_Disable(); HID_SetInterval(usbhid_period_ms); HID_Enable(); } - build_data_pkt(); - - HID_Write(packet, sizeof(packet)); + + switch (state) { + case ST_DATA1: + CLOCK_RunMixer(); // clears mixer_sync, which is then set when mixer update complete + state = ST_DATA2; + return mixer_runtime; - return usbhid_period_ms * 1000; + case ST_DATA2: + if (mixer_sync != MIX_DONE && mixer_runtime < 2000) mixer_runtime += 50; + build_data_pkt(); + HID_Write(packet, sizeof(packet)); + state = ST_DATA1; + return usbhid_period_ms * 1000 - mixer_runtime; + } + return usbhid_period_ms * 1000; // avoid compiler warning } static void deinit() @@ -95,8 +123,10 @@ static void deinit() static void initialize() { CLOCK_StopTimer(); + state = ST_DATA1; + mixer_runtime = 50; num_channels = Model.num_channels; - usbhid_period_ms = Model.proto_opts[PROTO_OPTS_PERIOD] ? Model.proto_opts[PROTO_OPTS_PERIOD] : USBHID_FRAME_PERIOD_STD; + usbhid_period_ms = period_index_to_ms(Model.proto_opts[PROTO_OPTS_PERIOD]); HID_SetInterval(usbhid_period_ms); HID_Enable(); CLOCK_StartTimer(1000, usbhid_cb); @@ -114,8 +144,8 @@ uintptr_t USBHID_Cmds(enum ProtoCmds cmd) case PROTOCMD_CHANNELMAP: return UNCHG; case PROTOCMD_TELEMETRYSTATE: return PROTO_TELEM_UNSUPPORTED; case PROTOCMD_GETOPTIONS: - if (!Model.proto_opts[PROTO_OPTS_PERIOD]) - Model.proto_opts[PROTO_OPTS_PERIOD] = USBHID_FRAME_PERIOD_STD; + if (Model.proto_opts[PROTO_OPTS_PERIOD] > USBHID_PERIOD_MAX_INDEX) + Model.proto_opts[PROTO_OPTS_PERIOD] = USBHID_PERIOD_MAX_INDEX; return (uintptr_t)usbhid_opts; default: break; } From 413993a0bf9416a05359a16802333c6865e5408f Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Thu, 17 Sep 2020 21:28:50 +1000 Subject: [PATCH 07/12] fix lint error --- src/protocol/usbhid.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/protocol/usbhid.c b/src/protocol/usbhid.c index 2628c9dd73..fdf2b4f735 100644 --- a/src/protocol/usbhid.c +++ b/src/protocol/usbhid.c @@ -97,7 +97,6 @@ static u16 usbhid_cb() HID_SetInterval(usbhid_period_ms); HID_Enable(); } - switch (state) { case ST_DATA1: CLOCK_RunMixer(); // clears mixer_sync, which is then set when mixer update complete From 5f31b825e41ce6acef94a5a446cfa17689c54c6f Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sat, 19 Sep 2020 16:54:51 +1000 Subject: [PATCH 08/12] USBHID: try to improve synchronisation to host polling --- src/protocol/exports.ld | 1 + src/protocol/usbhid.c | 14 +++++++++++--- src/target.h | 1 + src/target/drivers/mcu/emu/stubs.c | 1 + src/target/drivers/usb/devo_hid.c | 5 +++++ src/target/tx/opentx/t12/x9d_stubs.c | 1 + src/target/tx/opentx/x9d/x9d_stubs.c | 1 + src/target/tx/other/test/test_stubs.c | 1 + 8 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/protocol/exports.ld b/src/protocol/exports.ld index 43098e88f1..46671cbeb7 100644 --- a/src/protocol/exports.ld +++ b/src/protocol/exports.ld @@ -23,6 +23,7 @@ EXTERN(USB_Enable) EXTERN(USB_Disable) EXTERN(HID_SetInterval) EXTERN(HID_Write) +EXTERN(HID_TransferComplete) EXTERN(usbd_dev) EXTERN(USB_Product_Name) diff --git a/src/protocol/usbhid.c b/src/protocol/usbhid.c index fdf2b4f735..e662d47760 100644 --- a/src/protocol/usbhid.c +++ b/src/protocol/usbhid.c @@ -88,6 +88,11 @@ static u16 mixer_runtime; static u16 usbhid_period_ms; static u16 usbhid_cb() { + // wait until endpoint is ready for writing before preparing data + // if the host is polling slower than our clock, this will just delay us a bit + // it does increase the chance of mixers not completing in time for 1ms period though... + if (!HID_TransferComplete()) return 100; + u16 protoopts_period = period_index_to_ms(Model.proto_opts[PROTO_OPTS_PERIOD]); if (usbhid_period_ms != protoopts_period) { usbhid_period_ms = protoopts_period; @@ -108,9 +113,12 @@ static u16 usbhid_cb() build_data_pkt(); HID_Write(packet, sizeof(packet)); state = ST_DATA1; - return usbhid_period_ms * 1000 - mixer_runtime; - } - return usbhid_period_ms * 1000; // avoid compiler warning + // return with - 200 in case host is polling slightly faster than our clock + // this doesn't guarantee perfect timing, but it should be sufficient to + // catch most variations and get us back to waiting for the host + return usbhid_period_ms * 1000 - mixer_runtime - 200; + } + return usbhid_period_ms * 1000 - 200; // avoid compiler warning } static void deinit() diff --git a/src/target.h b/src/target.h index a7c1daf018..96b83310fe 100644 --- a/src/target.h +++ b/src/target.h @@ -297,6 +297,7 @@ void HID_SetInterval(u8 interval); void HID_Enable(); void HID_Disable(); void HID_Write(s8 *packet, u8 size); +u8 HID_TransferComplete(); void MSC_Enable(); void MSC_Disable(); diff --git a/src/target/drivers/mcu/emu/stubs.c b/src/target/drivers/mcu/emu/stubs.c index 5100bc2885..415934bcc0 100755 --- a/src/target/drivers/mcu/emu/stubs.c +++ b/src/target/drivers/mcu/emu/stubs.c @@ -45,6 +45,7 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } +u8 HID_TransferComplete() { return 0;} void Initialize_ButtonMatrix() {} void PWR_Init(void) {} unsigned PWR_ReadVoltage() { return (DEFAULT_BATTERY_ALARM + 1000); } diff --git a/src/target/drivers/usb/devo_hid.c b/src/target/drivers/usb/devo_hid.c index 68a4159a31..52e91a884f 100644 --- a/src/target/drivers/usb/devo_hid.c +++ b/src/target/drivers/usb/devo_hid.c @@ -172,6 +172,11 @@ void HID_Write(s8 *packet, u8 size) } } +u8 HID_TransferComplete() +{ + return usb_preXferComplete; +} + void HID_SetInterval(u8 interval) { hid_endpoint.bInterval = interval; diff --git a/src/target/tx/opentx/t12/x9d_stubs.c b/src/target/tx/opentx/t12/x9d_stubs.c index 42712bf91f..1c3967d9bf 100644 --- a/src/target/tx/opentx/t12/x9d_stubs.c +++ b/src/target/tx/opentx/t12/x9d_stubs.c @@ -33,6 +33,7 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } +u8 HID_TransferComplete() { return 0;} void SOUND_Init() {} void SOUND_SetFrequency(unsigned frequency, unsigned volume) { (void)frequency; diff --git a/src/target/tx/opentx/x9d/x9d_stubs.c b/src/target/tx/opentx/x9d/x9d_stubs.c index bb4a843aec..2f9d82be73 100644 --- a/src/target/tx/opentx/x9d/x9d_stubs.c +++ b/src/target/tx/opentx/x9d/x9d_stubs.c @@ -29,6 +29,7 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } +u8 HID_TransferComplete() { return 0;} void SOUND_Init() {} void SOUND_SetFrequency(unsigned frequency, unsigned volume) { (void)frequency; diff --git a/src/target/tx/other/test/test_stubs.c b/src/target/tx/other/test/test_stubs.c index d4f7673ce8..572e66d9d4 100644 --- a/src/target/tx/other/test/test_stubs.c +++ b/src/target/tx/other/test/test_stubs.c @@ -114,6 +114,7 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } +u8 HID_TransferComplete() { return 0;} void Initialize_ButtonMatrix() {} void PWR_Init(void) {} unsigned PWR_ReadVoltage() { return (DEFAULT_BATTERY_ALARM + 1000); } From 5c0a6bd66de809599cea95e2323b5fae4d97d441 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sat, 19 Sep 2020 22:56:07 +1000 Subject: [PATCH 09/12] usbhid: decrease ROM use (esp. for modular) and hopefully not break anything stubs might not be the right place to declare HID_prevXferComplete on platforms that don't use devo_hid.c, but I'm not sure where else makes sense --- src/protocol/exports.ld | 3 +-- src/protocol/usbhid.c | 2 +- src/target.h | 2 +- src/target/drivers/mcu/emu/stubs.c | 2 +- src/target/drivers/usb/devo_hid.c | 17 ++++++----------- src/target/tx/opentx/t12/x9d_stubs.c | 2 +- src/target/tx/opentx/x9d/x9d_stubs.c | 2 +- src/target/tx/other/test/test_stubs.c | 2 +- 8 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/protocol/exports.ld b/src/protocol/exports.ld index 46671cbeb7..e009011438 100644 --- a/src/protocol/exports.ld +++ b/src/protocol/exports.ld @@ -22,8 +22,7 @@ EXTERN(TELEMETRY_SetUpdated) EXTERN(USB_Enable) EXTERN(USB_Disable) EXTERN(HID_SetInterval) -EXTERN(HID_Write) -EXTERN(HID_TransferComplete) +EXTERN(HID_prevXferComplete) EXTERN(usbd_dev) EXTERN(USB_Product_Name) diff --git a/src/protocol/usbhid.c b/src/protocol/usbhid.c index e662d47760..37c89cc3bc 100644 --- a/src/protocol/usbhid.c +++ b/src/protocol/usbhid.c @@ -91,7 +91,7 @@ static u16 usbhid_cb() // wait until endpoint is ready for writing before preparing data // if the host is polling slower than our clock, this will just delay us a bit // it does increase the chance of mixers not completing in time for 1ms period though... - if (!HID_TransferComplete()) return 100; + if (!HID_prevXferComplete) return 100; u16 protoopts_period = period_index_to_ms(Model.proto_opts[PROTO_OPTS_PERIOD]); if (usbhid_period_ms != protoopts_period) { diff --git a/src/target.h b/src/target.h index 96b83310fe..5aa8af0e68 100644 --- a/src/target.h +++ b/src/target.h @@ -297,7 +297,7 @@ void HID_SetInterval(u8 interval); void HID_Enable(); void HID_Disable(); void HID_Write(s8 *packet, u8 size); -u8 HID_TransferComplete(); +extern volatile u8 HID_prevXferComplete; void MSC_Enable(); void MSC_Disable(); diff --git a/src/target/drivers/mcu/emu/stubs.c b/src/target/drivers/mcu/emu/stubs.c index 415934bcc0..0f06d04dd7 100755 --- a/src/target/drivers/mcu/emu/stubs.c +++ b/src/target/drivers/mcu/emu/stubs.c @@ -45,7 +45,7 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } -u8 HID_TransferComplete() { return 0;} +volatile u8 HID_prevXferComplete; void Initialize_ButtonMatrix() {} void PWR_Init(void) {} unsigned PWR_ReadVoltage() { return (DEFAULT_BATTERY_ALARM + 1000); } diff --git a/src/target/drivers/usb/devo_hid.c b/src/target/drivers/usb/devo_hid.c index 52e91a884f..363db374c4 100644 --- a/src/target/drivers/usb/devo_hid.c +++ b/src/target/drivers/usb/devo_hid.c @@ -10,7 +10,7 @@ static const char * const usb_strings[] = { DeviationVersion }; -static volatile u8 usb_preXferComplete; +volatile u8 HID_prevXferComplete; static const uint8_t hid_report_descriptor[] = { 0x05, 0x01, // USAGE_PAGE (Generic Desktop) @@ -137,7 +137,7 @@ static void hid_callback(usbd_device *usbd_dev, uint8_t ep) (void)usbd_dev; (void)ep; - usb_preXferComplete = 1; + HID_prevXferComplete = 1; } static void hid_set_config(usbd_device *dev, uint16_t wValue) @@ -153,7 +153,7 @@ static void hid_set_config(usbd_device *dev, uint16_t wValue) USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, hid_control_request); - usb_preXferComplete = 1; + HID_prevXferComplete = 1; } static void HID_Init() @@ -166,24 +166,19 @@ static void HID_Init() void HID_Write(s8 *packet, u8 size) { - if (usb_preXferComplete) { - usb_preXferComplete = 0; + if (HID_prevXferComplete) { + HID_prevXferComplete = 0; usbd_ep_write_packet(usbd_dev, 0x81, packet, size); } } -u8 HID_TransferComplete() -{ - return usb_preXferComplete; -} - void HID_SetInterval(u8 interval) { hid_endpoint.bInterval = interval; } void HID_Enable() { - usb_preXferComplete = 0; + HID_prevXferComplete = 0; USB_Enable(1); HID_Init(); } diff --git a/src/target/tx/opentx/t12/x9d_stubs.c b/src/target/tx/opentx/t12/x9d_stubs.c index 1c3967d9bf..e55e163892 100644 --- a/src/target/tx/opentx/t12/x9d_stubs.c +++ b/src/target/tx/opentx/t12/x9d_stubs.c @@ -33,7 +33,7 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } -u8 HID_TransferComplete() { return 0;} +volatile u8 HID_prevXferComplete; void SOUND_Init() {} void SOUND_SetFrequency(unsigned frequency, unsigned volume) { (void)frequency; diff --git a/src/target/tx/opentx/x9d/x9d_stubs.c b/src/target/tx/opentx/x9d/x9d_stubs.c index 2f9d82be73..4bd0e9fcc9 100644 --- a/src/target/tx/opentx/x9d/x9d_stubs.c +++ b/src/target/tx/opentx/x9d/x9d_stubs.c @@ -29,7 +29,7 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } -u8 HID_TransferComplete() { return 0;} +volatile u8 HID_prevXferComplete; void SOUND_Init() {} void SOUND_SetFrequency(unsigned frequency, unsigned volume) { (void)frequency; diff --git a/src/target/tx/other/test/test_stubs.c b/src/target/tx/other/test/test_stubs.c index 572e66d9d4..7d81670a33 100644 --- a/src/target/tx/other/test/test_stubs.c +++ b/src/target/tx/other/test/test_stubs.c @@ -114,7 +114,7 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } -u8 HID_TransferComplete() { return 0;} +volatile u8 HID_prevXferComplete; void Initialize_ButtonMatrix() {} void PWR_Init(void) {} unsigned PWR_ReadVoltage() { return (DEFAULT_BATTERY_ALARM + 1000); } From 99fb44b2007dca98e77f91b8f6979f9c0d7f89db Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sun, 20 Sep 2020 05:07:07 +1000 Subject: [PATCH 10/12] USBHID: try using a callback for better timing --- src/protocol/exports.ld | 1 - src/protocol/usbhid.c | 24 +++++++++-------------- src/target.h | 2 +- src/target/drivers/mcu/emu/stubs.c | 4 +++- src/target/drivers/usb/devo_hid.c | 28 +++++++++++++++++---------- src/target/tx/opentx/t12/x9d_stubs.c | 4 +++- src/target/tx/opentx/x9d/x9d_stubs.c | 4 +++- src/target/tx/other/test/test_stubs.c | 4 +++- 8 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/protocol/exports.ld b/src/protocol/exports.ld index e009011438..1abce35d0b 100644 --- a/src/protocol/exports.ld +++ b/src/protocol/exports.ld @@ -22,7 +22,6 @@ EXTERN(TELEMETRY_SetUpdated) EXTERN(USB_Enable) EXTERN(USB_Disable) EXTERN(HID_SetInterval) -EXTERN(HID_prevXferComplete) EXTERN(usbd_dev) EXTERN(USB_Product_Name) diff --git a/src/protocol/usbhid.c b/src/protocol/usbhid.c index 37c89cc3bc..a92e6859df 100644 --- a/src/protocol/usbhid.c +++ b/src/protocol/usbhid.c @@ -84,15 +84,9 @@ static enum { } state; static u16 mixer_runtime; -// ms suffix on usbhid_period_ms to indicate that it's in milliseconds not microseconds like other protocols static u16 usbhid_period_ms; static u16 usbhid_cb() { - // wait until endpoint is ready for writing before preparing data - // if the host is polling slower than our clock, this will just delay us a bit - // it does increase the chance of mixers not completing in time for 1ms period though... - if (!HID_prevXferComplete) return 100; - u16 protoopts_period = period_index_to_ms(Model.proto_opts[PROTO_OPTS_PERIOD]); if (usbhid_period_ms != protoopts_period) { usbhid_period_ms = protoopts_period; @@ -101,29 +95,29 @@ static u16 usbhid_cb() HID_Disable(); HID_SetInterval(usbhid_period_ms); HID_Enable(); + return 0; } switch (state) { case ST_DATA1: - CLOCK_RunMixer(); // clears mixer_sync, which is then set when mixer update complete + CLOCK_RunMixer(); // clears mixer_sync, which is then set when mixer update complete state = ST_DATA2; return mixer_runtime; case ST_DATA2: - if (mixer_sync != MIX_DONE && mixer_runtime < 2000) mixer_runtime += 50; + if (mixer_sync != MIX_DONE && mixer_runtime < 2000) { + mixer_runtime += 50; + return 50; // wait for mixer instead of forcing a write + } build_data_pkt(); HID_Write(packet, sizeof(packet)); state = ST_DATA1; - // return with - 200 in case host is polling slightly faster than our clock - // this doesn't guarantee perfect timing, but it should be sufficient to - // catch most variations and get us back to waiting for the host - return usbhid_period_ms * 1000 - mixer_runtime - 200; + return 0; // stop the clock and let USB interrupts trigger us instead } - return usbhid_period_ms * 1000 - 200; // avoid compiler warning + return 0; // avoid compiler warning } static void deinit() { - CLOCK_StopTimer(); HID_Disable(); } @@ -135,8 +129,8 @@ static void initialize() num_channels = Model.num_channels; usbhid_period_ms = period_index_to_ms(Model.proto_opts[PROTO_OPTS_PERIOD]); HID_SetInterval(usbhid_period_ms); + HID_SetCallback(usbhid_cb); HID_Enable(); - CLOCK_StartTimer(1000, usbhid_cb); } uintptr_t USBHID_Cmds(enum ProtoCmds cmd) diff --git a/src/target.h b/src/target.h index 5aa8af0e68..425d740181 100644 --- a/src/target.h +++ b/src/target.h @@ -297,7 +297,7 @@ void HID_SetInterval(u8 interval); void HID_Enable(); void HID_Disable(); void HID_Write(s8 *packet, u8 size); -extern volatile u8 HID_prevXferComplete; +void HID_SetCallback(u16 (*callback)(void)); void MSC_Enable(); void MSC_Disable(); diff --git a/src/target/drivers/mcu/emu/stubs.c b/src/target/drivers/mcu/emu/stubs.c index 0f06d04dd7..f161caf6ba 100755 --- a/src/target/drivers/mcu/emu/stubs.c +++ b/src/target/drivers/mcu/emu/stubs.c @@ -45,7 +45,9 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } -volatile u8 HID_prevXferComplete; +void HID_SetCallback(u16 (*callback)(void)) { + (void)callback; +} void Initialize_ButtonMatrix() {} void PWR_Init(void) {} unsigned PWR_ReadVoltage() { return (DEFAULT_BATTERY_ALARM + 1000); } diff --git a/src/target/drivers/usb/devo_hid.c b/src/target/drivers/usb/devo_hid.c index 363db374c4..5b178879bf 100644 --- a/src/target/drivers/usb/devo_hid.c +++ b/src/target/drivers/usb/devo_hid.c @@ -10,8 +10,6 @@ static const char * const usb_strings[] = { DeviationVersion }; -volatile u8 HID_prevXferComplete; - static const uint8_t hid_report_descriptor[] = { 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x15, 0x81, // LOGICAL_MINIMUM (0) @@ -132,12 +130,21 @@ static enum usbd_request_return_codes hid_control_request(usbd_device *dev, stru return USBD_REQ_HANDLED; } +static u16 (*protocol_callback)(void); +static volatile u8 waiting_for_cb; + static void hid_callback(usbd_device *usbd_dev, uint8_t ep) { (void)usbd_dev; (void)ep; - HID_prevXferComplete = 1; + if (protocol_callback && !waiting_for_cb) { + waiting_for_cb = 1; + // call protocol_callback to let it know to prepare new data, + // but use a clock to not delay responding to the USB interrupt + // (USB interrupt seems to be higher priority, so this shouldn't need a time delay) + CLOCK_StartTimer(0, protocol_callback); + } } static void hid_set_config(usbd_device *dev, uint16_t wValue) @@ -152,8 +159,6 @@ static void hid_set_config(usbd_device *dev, uint16_t wValue) USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE, USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, hid_control_request); - - HID_prevXferComplete = 1; } static void HID_Init() @@ -166,10 +171,8 @@ static void HID_Init() void HID_Write(s8 *packet, u8 size) { - if (HID_prevXferComplete) { - HID_prevXferComplete = 0; - usbd_ep_write_packet(usbd_dev, 0x81, packet, size); - } + usbd_ep_write_packet(usbd_dev, 0x81, packet, size); + waiting_for_cb = 0; } void HID_SetInterval(u8 interval) @@ -177,10 +180,15 @@ void HID_SetInterval(u8 interval) hid_endpoint.bInterval = interval; } +void HID_SetCallback(u16 (*callback)(void)) +{ + protocol_callback = callback; +} + void HID_Enable() { - HID_prevXferComplete = 0; USB_Enable(1); HID_Init(); + waiting_for_cb = 0; } void HID_Disable() { diff --git a/src/target/tx/opentx/t12/x9d_stubs.c b/src/target/tx/opentx/t12/x9d_stubs.c index e55e163892..af7003a58d 100644 --- a/src/target/tx/opentx/t12/x9d_stubs.c +++ b/src/target/tx/opentx/t12/x9d_stubs.c @@ -33,7 +33,9 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } -volatile u8 HID_prevXferComplete; +void HID_SetCallback(u16 (*callback)(void)) { + (void)callback; +} void SOUND_Init() {} void SOUND_SetFrequency(unsigned frequency, unsigned volume) { (void)frequency; diff --git a/src/target/tx/opentx/x9d/x9d_stubs.c b/src/target/tx/opentx/x9d/x9d_stubs.c index 4bd0e9fcc9..7df9ece12a 100644 --- a/src/target/tx/opentx/x9d/x9d_stubs.c +++ b/src/target/tx/opentx/x9d/x9d_stubs.c @@ -29,7 +29,9 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } -volatile u8 HID_prevXferComplete; +void HID_SetCallback(u16 (*callback)(void)) { + (void)callback; +} void SOUND_Init() {} void SOUND_SetFrequency(unsigned frequency, unsigned volume) { (void)frequency; diff --git a/src/target/tx/other/test/test_stubs.c b/src/target/tx/other/test/test_stubs.c index 7d81670a33..44e5ac050a 100644 --- a/src/target/tx/other/test/test_stubs.c +++ b/src/target/tx/other/test/test_stubs.c @@ -114,7 +114,9 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } -volatile u8 HID_prevXferComplete; +void HID_SetCallback(u16 (*callback)(void)) { + (void)callback; +} void Initialize_ButtonMatrix() {} void PWR_Init(void) {} unsigned PWR_ReadVoltage() { return (DEFAULT_BATTERY_ALARM + 1000); } From d471725509d0515a9549eb819d62b5e5d8e3ecfc Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sun, 20 Sep 2020 17:47:51 +1000 Subject: [PATCH 11/12] usb hid: ensure clock is stopped after deinit --- src/protocol/usbhid.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/protocol/usbhid.c b/src/protocol/usbhid.c index a92e6859df..1eb095fa1c 100644 --- a/src/protocol/usbhid.c +++ b/src/protocol/usbhid.c @@ -119,6 +119,7 @@ static u16 usbhid_cb() static void deinit() { HID_Disable(); + CLOCK_StopTimer(); // ensure clock is stopped and won't try to call USB functions after unloading } static void initialize() From 541292995fff55e0fd21633c8edb90fcd5a42a76 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Sat, 26 Sep 2020 12:20:40 +1000 Subject: [PATCH 12/12] revert d47172 and 99fb44 --- src/protocol/exports.ld | 1 + src/protocol/usbhid.c | 25 ++++++++++++++---------- src/target.h | 2 +- src/target/drivers/mcu/emu/stubs.c | 4 +--- src/target/drivers/usb/devo_hid.c | 28 ++++++++++----------------- src/target/tx/opentx/t12/x9d_stubs.c | 4 +--- src/target/tx/opentx/x9d/x9d_stubs.c | 4 +--- src/target/tx/other/test/test_stubs.c | 4 +--- 8 files changed, 31 insertions(+), 41 deletions(-) diff --git a/src/protocol/exports.ld b/src/protocol/exports.ld index 1abce35d0b..e009011438 100644 --- a/src/protocol/exports.ld +++ b/src/protocol/exports.ld @@ -22,6 +22,7 @@ EXTERN(TELEMETRY_SetUpdated) EXTERN(USB_Enable) EXTERN(USB_Disable) EXTERN(HID_SetInterval) +EXTERN(HID_prevXferComplete) EXTERN(usbd_dev) EXTERN(USB_Product_Name) diff --git a/src/protocol/usbhid.c b/src/protocol/usbhid.c index 1eb095fa1c..37c89cc3bc 100644 --- a/src/protocol/usbhid.c +++ b/src/protocol/usbhid.c @@ -84,9 +84,15 @@ static enum { } state; static u16 mixer_runtime; +// ms suffix on usbhid_period_ms to indicate that it's in milliseconds not microseconds like other protocols static u16 usbhid_period_ms; static u16 usbhid_cb() { + // wait until endpoint is ready for writing before preparing data + // if the host is polling slower than our clock, this will just delay us a bit + // it does increase the chance of mixers not completing in time for 1ms period though... + if (!HID_prevXferComplete) return 100; + u16 protoopts_period = period_index_to_ms(Model.proto_opts[PROTO_OPTS_PERIOD]); if (usbhid_period_ms != protoopts_period) { usbhid_period_ms = protoopts_period; @@ -95,31 +101,30 @@ static u16 usbhid_cb() HID_Disable(); HID_SetInterval(usbhid_period_ms); HID_Enable(); - return 0; } switch (state) { case ST_DATA1: - CLOCK_RunMixer(); // clears mixer_sync, which is then set when mixer update complete + CLOCK_RunMixer(); // clears mixer_sync, which is then set when mixer update complete state = ST_DATA2; return mixer_runtime; case ST_DATA2: - if (mixer_sync != MIX_DONE && mixer_runtime < 2000) { - mixer_runtime += 50; - return 50; // wait for mixer instead of forcing a write - } + if (mixer_sync != MIX_DONE && mixer_runtime < 2000) mixer_runtime += 50; build_data_pkt(); HID_Write(packet, sizeof(packet)); state = ST_DATA1; - return 0; // stop the clock and let USB interrupts trigger us instead + // return with - 200 in case host is polling slightly faster than our clock + // this doesn't guarantee perfect timing, but it should be sufficient to + // catch most variations and get us back to waiting for the host + return usbhid_period_ms * 1000 - mixer_runtime - 200; } - return 0; // avoid compiler warning + return usbhid_period_ms * 1000 - 200; // avoid compiler warning } static void deinit() { + CLOCK_StopTimer(); HID_Disable(); - CLOCK_StopTimer(); // ensure clock is stopped and won't try to call USB functions after unloading } static void initialize() @@ -130,8 +135,8 @@ static void initialize() num_channels = Model.num_channels; usbhid_period_ms = period_index_to_ms(Model.proto_opts[PROTO_OPTS_PERIOD]); HID_SetInterval(usbhid_period_ms); - HID_SetCallback(usbhid_cb); HID_Enable(); + CLOCK_StartTimer(1000, usbhid_cb); } uintptr_t USBHID_Cmds(enum ProtoCmds cmd) diff --git a/src/target.h b/src/target.h index 425d740181..5aa8af0e68 100644 --- a/src/target.h +++ b/src/target.h @@ -297,7 +297,7 @@ void HID_SetInterval(u8 interval); void HID_Enable(); void HID_Disable(); void HID_Write(s8 *packet, u8 size); -void HID_SetCallback(u16 (*callback)(void)); +extern volatile u8 HID_prevXferComplete; void MSC_Enable(); void MSC_Disable(); diff --git a/src/target/drivers/mcu/emu/stubs.c b/src/target/drivers/mcu/emu/stubs.c index f161caf6ba..0f06d04dd7 100755 --- a/src/target/drivers/mcu/emu/stubs.c +++ b/src/target/drivers/mcu/emu/stubs.c @@ -45,9 +45,7 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } -void HID_SetCallback(u16 (*callback)(void)) { - (void)callback; -} +volatile u8 HID_prevXferComplete; void Initialize_ButtonMatrix() {} void PWR_Init(void) {} unsigned PWR_ReadVoltage() { return (DEFAULT_BATTERY_ALARM + 1000); } diff --git a/src/target/drivers/usb/devo_hid.c b/src/target/drivers/usb/devo_hid.c index 5b178879bf..363db374c4 100644 --- a/src/target/drivers/usb/devo_hid.c +++ b/src/target/drivers/usb/devo_hid.c @@ -10,6 +10,8 @@ static const char * const usb_strings[] = { DeviationVersion }; +volatile u8 HID_prevXferComplete; + static const uint8_t hid_report_descriptor[] = { 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x15, 0x81, // LOGICAL_MINIMUM (0) @@ -130,21 +132,12 @@ static enum usbd_request_return_codes hid_control_request(usbd_device *dev, stru return USBD_REQ_HANDLED; } -static u16 (*protocol_callback)(void); -static volatile u8 waiting_for_cb; - static void hid_callback(usbd_device *usbd_dev, uint8_t ep) { (void)usbd_dev; (void)ep; - if (protocol_callback && !waiting_for_cb) { - waiting_for_cb = 1; - // call protocol_callback to let it know to prepare new data, - // but use a clock to not delay responding to the USB interrupt - // (USB interrupt seems to be higher priority, so this shouldn't need a time delay) - CLOCK_StartTimer(0, protocol_callback); - } + HID_prevXferComplete = 1; } static void hid_set_config(usbd_device *dev, uint16_t wValue) @@ -159,6 +152,8 @@ static void hid_set_config(usbd_device *dev, uint16_t wValue) USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_INTERFACE, USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, hid_control_request); + + HID_prevXferComplete = 1; } static void HID_Init() @@ -171,8 +166,10 @@ static void HID_Init() void HID_Write(s8 *packet, u8 size) { - usbd_ep_write_packet(usbd_dev, 0x81, packet, size); - waiting_for_cb = 0; + if (HID_prevXferComplete) { + HID_prevXferComplete = 0; + usbd_ep_write_packet(usbd_dev, 0x81, packet, size); + } } void HID_SetInterval(u8 interval) @@ -180,15 +177,10 @@ void HID_SetInterval(u8 interval) hid_endpoint.bInterval = interval; } -void HID_SetCallback(u16 (*callback)(void)) -{ - protocol_callback = callback; -} - void HID_Enable() { + HID_prevXferComplete = 0; USB_Enable(1); HID_Init(); - waiting_for_cb = 0; } void HID_Disable() { diff --git a/src/target/tx/opentx/t12/x9d_stubs.c b/src/target/tx/opentx/t12/x9d_stubs.c index af7003a58d..e55e163892 100644 --- a/src/target/tx/opentx/t12/x9d_stubs.c +++ b/src/target/tx/opentx/t12/x9d_stubs.c @@ -33,9 +33,7 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } -void HID_SetCallback(u16 (*callback)(void)) { - (void)callback; -} +volatile u8 HID_prevXferComplete; void SOUND_Init() {} void SOUND_SetFrequency(unsigned frequency, unsigned volume) { (void)frequency; diff --git a/src/target/tx/opentx/x9d/x9d_stubs.c b/src/target/tx/opentx/x9d/x9d_stubs.c index 7df9ece12a..4bd0e9fcc9 100644 --- a/src/target/tx/opentx/x9d/x9d_stubs.c +++ b/src/target/tx/opentx/x9d/x9d_stubs.c @@ -29,9 +29,7 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } -void HID_SetCallback(u16 (*callback)(void)) { - (void)callback; -} +volatile u8 HID_prevXferComplete; void SOUND_Init() {} void SOUND_SetFrequency(unsigned frequency, unsigned volume) { (void)frequency; diff --git a/src/target/tx/other/test/test_stubs.c b/src/target/tx/other/test/test_stubs.c index 44e5ac050a..7d81670a33 100644 --- a/src/target/tx/other/test/test_stubs.c +++ b/src/target/tx/other/test/test_stubs.c @@ -114,9 +114,7 @@ void HID_Write(s8 *pkt, u8 size) { (void)pkt; (void)size; } -void HID_SetCallback(u16 (*callback)(void)) { - (void)callback; -} +volatile u8 HID_prevXferComplete; void Initialize_ButtonMatrix() {} void PWR_Init(void) {} unsigned PWR_ReadVoltage() { return (DEFAULT_BATTERY_ALARM + 1000); }