cmd: poll rate switch
This commit is contained in:
+1
-1
@@ -39,7 +39,7 @@ pico_sdk_init()
|
||||
# Add executable. Default name is the project name, version 0.1
|
||||
|
||||
add_executable(ds5-bridge
|
||||
src/usb_descriptors.c
|
||||
src/usb_descriptors.cpp
|
||||
src/main.cpp
|
||||
src/usb.cpp
|
||||
src/audio.cpp
|
||||
|
||||
@@ -38,6 +38,14 @@ volatile bool report_dirty = false;
|
||||
void interrupt_loop() {
|
||||
if (!tud_hid_ready()) return;
|
||||
|
||||
// TODO: Refactor for better code reuse
|
||||
if (get_config().polling_rate_mode != 2) {
|
||||
if (!tud_hid_report(0x01, interrupt_in_data, 63)) {
|
||||
printf("[USBHID] tud_hid_report error\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
bool should_send = false;
|
||||
// Local buffer to hold the report data while we prepare it to send.
|
||||
uint8_t safe_report[63];
|
||||
@@ -72,6 +80,11 @@ void on_bt_data(CHANNEL_TYPE channel, uint8_t *data, uint16_t len) {
|
||||
set_headset(data[56] & 1);
|
||||
}
|
||||
|
||||
if (get_config().polling_rate_mode != 2) {
|
||||
memcpy(interrupt_in_data, data + 3, 63);
|
||||
return;
|
||||
}
|
||||
|
||||
// We add the critical section here to avoid any race conditions when writing to the interrupt_in_data buffer,
|
||||
// which is shared between the main loop and this callback.
|
||||
// The critical section ensures that only one thread can access the buffer at a time,
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "bsp/board_api.h"
|
||||
#include "tusb.h"
|
||||
#include "config.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Device Descriptors
|
||||
@@ -69,7 +70,7 @@ uint8_t const *tud_descriptor_device_cb(void) {
|
||||
//--------------------------------------------------------------------+
|
||||
// Configuration Descriptor
|
||||
//--------------------------------------------------------------------+
|
||||
uint8_t const descriptor_configuration[] = {
|
||||
uint8_t descriptor_configuration[] = {
|
||||
// --- CONFIGURATION DESCRIPTOR ---
|
||||
0x09, // bLength
|
||||
0x02, // bDescriptorType (CONFIGURATION)
|
||||
@@ -330,6 +331,20 @@ uint8_t const descriptor_configuration[] = {
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const *tud_descriptor_configuration_cb(uint8_t index) {
|
||||
(void) index; // for multiple configurations
|
||||
auto bInterval = 0x01;
|
||||
switch (get_config().polling_rate_mode) {
|
||||
case 0:
|
||||
bInterval = 0x04;
|
||||
break;
|
||||
case 1:
|
||||
bInterval = 0x02;
|
||||
break;
|
||||
case 2:
|
||||
bInterval = 0x01;
|
||||
break;
|
||||
}
|
||||
descriptor_configuration[sizeof(descriptor_configuration) - 1] = bInterval;
|
||||
descriptor_configuration[sizeof(descriptor_configuration) - 8] = bInterval;
|
||||
return descriptor_configuration;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user