diff --git a/device/src/usb/command_app.cpp b/device/src/usb/command_app.cpp index f286f1f9..899dec92 100644 --- a/device/src/usb/command_app.cpp +++ b/device/src/usb/command_app.cpp @@ -3,18 +3,21 @@ #include "hid/report_protocol.hpp" #include "zephyr/sys/printk.h" -extern "C" bool CommandProtocolTx(const uint8_t *data, size_t size) +extern "C" void UsbProtocolHandler(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); + +command_app &command_app::usb_handle() { - return command_app::handle().send(std::span(data, size)); + static command_app app{}; + return app; } -extern "C" void CommandProtocolRxHandler(const uint8_t *data, size_t size); - +#if DEVICE_IS_UHK80_RIGHT command_app &command_app::handle() { - static command_app app{}; - return app; + static command_app ble_app{}; + return ble_app; } +#endif void command_app::start(hid::protocol prot) { @@ -32,7 +35,15 @@ void command_app::set_report(hid::report::type type, const std::span(data.data()); - CommandProtocolRxHandler(out.payload.data(), data.size() - (report_out::has_id() ? 1 : 0)); + auto buf_idx = in_buffer_.active_side(); + auto &in = in_buffer_[buf_idx]; + UsbProtocolHandler(out.payload.data(), in.payload.data()); + auto err = send_report(&in); + if (err == hid::result::OK) { + in_buffer_.compare_swap(buf_idx); + } else { + printk("Command app failed to send report with: %d\n", (int)err); + } } void command_app::get_report(hid::report::selector select, const std::span &buffer) @@ -47,24 +58,6 @@ void command_app::get_report(hid::report::selector select, const std::span buffer) -{ - auto buf_idx = in_buffer_.active_side(); - auto &report = in_buffer_[buf_idx]; - if (buffer.size() > report.payload.max_size()) { - printk("Usb payload exceeded maximum size!\n"); - return false; - } - std::copy(buffer.begin(), buffer.end(), report.payload.begin()); - c2usb::result err = send_report(&in_buffer_[buf_idx]); - if (err == hid::result::OK) { - in_buffer_.compare_swap(buf_idx); - return true; - } - printk("Command app failed to send report with: %i\n", (int)err); - return false; -} - void command_app::in_report_sent(const std::span &data) { if (data.front() != report_ids::IN_COMMAND) { diff --git a/device/src/usb/command_app.hpp b/device/src/usb/command_app.hpp index e9166a0e..d9099b85 100644 --- a/device/src/usb/command_app.hpp +++ b/device/src/usb/command_app.hpp @@ -6,6 +6,7 @@ #include "hid/rdf/descriptor.hpp" #include "hid/report_protocol.hpp" #include "report_ids.h" +#include "../device.h" namespace hid::page { enum class ugl : uint8_t; @@ -61,9 +62,10 @@ class command_app : public hid::application { using report_in = report_base; using report_out = report_base; + static command_app& usb_handle(); +#if DEVICE_IS_UHK80_RIGHT static command_app& handle(); - - bool send(std::span buffer); +#endif void start(hid::protocol prot) override; void set_report(hid::report::type type, const std::span& data) override; diff --git a/device/src/usb/usb.cpp b/device/src/usb/usb.cpp index 2ae622cc..22fe34cc 100644 --- a/device/src/usb/usb.cpp +++ b/device/src/usb/usb.cpp @@ -113,7 +113,7 @@ struct usb_manager { static usb::df::hid::function usb_kb{ keyboard_app::handle(), usb::hid::boot_protocol_mode::KEYBOARD}; static usb::df::hid::function usb_mouse{mouse_app::handle()}; - static usb::df::hid::function usb_command{command_app::handle()}; + static usb::df::hid::function usb_command{command_app::usb_handle()}; static usb::df::hid::function usb_controls{controls_app::handle()}; static usb::df::hid::function usb_gamepad{gamepad_app::handle()}; static usb::df::microsoft::xfunction usb_xpad{gamepad_app::handle()}; @@ -128,17 +128,19 @@ struct usb_manager { usb::df::hid::config(usb_mouse, speed, usb::endpoint::address(0x82), 1), usb::df::hid::config(usb_command, speed, usb::endpoint::address(0x83), 10), usb::df::hid::config(usb_controls, speed, usb::endpoint::address(0x84), 1) -#if !DEVICE_HAS_BATTERY - ); -#else +#if DEVICE_HAS_BATTERY , usb::df::hid::config(usb_battery, speed, usb::endpoint::address(0x86), 1) // not very useful at the moment +#endif ); - - static const auto battery_config = usb::df::config::make_config(config_header, - usb::df::hid::config(usb_battery, speed, usb::endpoint::address(0x86), 1)); + static const auto inactive_config = usb::df::config::make_config(config_header, + usb::df::hid::config(usb_command, speed, usb::endpoint::address(0x83), 10) +#if DEVICE_HAS_BATTERY + , + usb::df::hid::config(usb_battery, speed, usb::endpoint::address(0x86), 1) #endif + ); static const auto base_config = usb::df::config::make_config(config_header, shared_config_elems); @@ -155,12 +157,8 @@ struct usb_manager { printk("USB config changing to %s\n", magic_enum::enum_name(conf).data()); switch (conf) { case Hid_Empty: -#if DEVICE_HAS_BATTERY ms_enum_.set_config({}); - device_.set_config(battery_config); -#else - assert(false); -#endif + device_.set_config(inactive_config); break; case Hid_NoGamepad: ms_enum_.set_config({}); diff --git a/right/src/usb_commands/usb_command_apply_config.c b/right/src/usb_commands/usb_command_apply_config.c index eb78e105..03055fcb 100644 --- a/right/src/usb_commands/usb_command_apply_config.c +++ b/right/src/usb_commands/usb_command_apply_config.c @@ -19,25 +19,26 @@ #include "main.h" #endif -void updateUsbBuffer(uint8_t usbStatusCode, uint16_t parserOffset, parser_stage_t parserStage) +void updateUsbBuffer(uint8_t *GenericHidInBuffer, uint8_t usbStatusCode, uint16_t parserOffset, parser_stage_t parserStage) { SetUsbTxBufferUint8(0, usbStatusCode); SetUsbTxBufferUint16(1, parserOffset); SetUsbTxBufferUint8(3, parserStage); } -static uint8_t validateConfig() { +static uint8_t validateConfig(uint8_t *GenericHidInBuffer) { // Validate the staging configuration. ParserRunDry = true; StagingUserConfigBuffer.offset = 0; uint8_t parseConfigStatus = ParseConfig(&StagingUserConfigBuffer); - updateUsbBuffer(UsbStatusCode_Success, StagingUserConfigBuffer.offset, ParsingStage_Validate); - + if (GenericHidInBuffer) { + updateUsbBuffer(GenericHidInBuffer, UsbStatusCode_Success, StagingUserConfigBuffer.offset, ParsingStage_Validate); + } return parseConfigStatus; } -void UsbCommand_ApplyConfigAsync(void) { - if (validateConfig() == UsbStatusCode_Success) { +void UsbCommand_ApplyConfigAsync(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { + if (validateConfig(GenericHidInBuffer) == UsbStatusCode_Success) { EventVector_Set(EventVector_ApplyConfig); #ifdef __ZEPHYR__ Main_Wake(); @@ -45,7 +46,7 @@ void UsbCommand_ApplyConfigAsync(void) { } } -void UsbCommand_ApplyFactory(void) +void UsbCommand_ApplyFactory(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { EventVector_Unset(EventVector_ApplyConfig); @@ -63,12 +64,12 @@ void UsbCommand_ApplyFactory(void) LedManager_FullUpdate(); } -uint8_t UsbCommand_ApplyConfig(void) +uint8_t UsbCommand_ApplyConfig(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { static bool isBoot = true; EventVector_Unset(EventVector_ApplyConfig); - uint8_t parseConfigStatus = validateConfig(); + uint8_t parseConfigStatus = validateConfig(GenericHidInBuffer); if (parseConfigStatus != UsbStatusCode_Success) { return parseConfigStatus; diff --git a/right/src/usb_commands/usb_command_apply_config.h b/right/src/usb_commands/usb_command_apply_config.h index cdd09ae2..2527156f 100644 --- a/right/src/usb_commands/usb_command_apply_config.h +++ b/right/src/usb_commands/usb_command_apply_config.h @@ -15,8 +15,8 @@ // Functions: - uint8_t UsbCommand_ApplyConfig(void); - void UsbCommand_ApplyFactory(void); - void UsbCommand_ApplyConfigAsync(void); + uint8_t UsbCommand_ApplyConfig(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); + void UsbCommand_ApplyFactory(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); + void UsbCommand_ApplyConfigAsync(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_draw_oled.c b/right/src/usb_commands/usb_command_draw_oled.c index 74be314f..fab8e885 100644 --- a/right/src/usb_commands/usb_command_draw_oled.c +++ b/right/src/usb_commands/usb_command_draw_oled.c @@ -15,7 +15,7 @@ #include "debug.h" #include -void UsbCommand_DrawOled() +void UsbCommand_DrawOled(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { #if defined(__ZEPHYR__) && DEVICE_HAS_OLED uint8_t x = GetUsbRxBufferUint8(1); diff --git a/right/src/usb_commands/usb_command_draw_oled.h b/right/src/usb_commands/usb_command_draw_oled.h index a3a1371a..7d57c742 100644 --- a/right/src/usb_commands/usb_command_draw_oled.h +++ b/right/src/usb_commands/usb_command_draw_oled.h @@ -11,6 +11,6 @@ // Functions: - void UsbCommand_DrawOled(); + void UsbCommand_DrawOled(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_exec_macro_command.c b/right/src/usb_commands/usb_command_exec_macro_command.c index 7bfcade4..f1c81cfd 100644 --- a/right/src/usb_commands/usb_command_exec_macro_command.c +++ b/right/src/usb_commands/usb_command_exec_macro_command.c @@ -14,7 +14,7 @@ char UsbMacroCommand[USB_GENERIC_HID_OUT_BUFFER_LENGTH+1]; uint8_t UsbMacroCommandLength = 0; key_state_t dummyState; -static void requestExecution() +static void requestExecution(const uint8_t *GenericHidOutBuffer) { Utils_SafeStrCopy(UsbMacroCommand, ((char*)GenericHidOutBuffer) + 1, sizeof(GenericHidOutBuffer)-1); UsbMacroCommandLength = strlen(UsbMacroCommand); @@ -41,9 +41,9 @@ void UsbMacroCommand_ExecuteSynchronously() EventVector_Unset(EventVector_UsbMacroCommandWaitingForExecution); } -void UsbCommand_ExecMacroCommand() +void UsbCommand_ExecMacroCommand(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { if (canExecute()) { - requestExecution(); + requestExecution(GenericHidOutBuffer); } } diff --git a/right/src/usb_commands/usb_command_exec_macro_command.h b/right/src/usb_commands/usb_command_exec_macro_command.h index 0a6ef294..f87dc430 100644 --- a/right/src/usb_commands/usb_command_exec_macro_command.h +++ b/right/src/usb_commands/usb_command_exec_macro_command.h @@ -16,6 +16,6 @@ // Functions: void UsbMacroCommand_ExecuteSynchronously(); - void UsbCommand_ExecMacroCommand(); + void UsbCommand_ExecMacroCommand(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_get_adc_value.c b/right/src/usb_commands/usb_command_get_adc_value.c index 852ea0f4..b191a4c2 100644 --- a/right/src/usb_commands/usb_command_get_adc_value.c +++ b/right/src/usb_commands/usb_command_get_adc_value.c @@ -2,7 +2,7 @@ #include "usb_commands/usb_command_get_adc_value.h" #include "peripherals/adc.h" -void UsbCommand_GetAdcValue(void) +void UsbCommand_GetAdcValue(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { SetUsbTxBufferUint32(1, ADC_Measure()); } diff --git a/right/src/usb_commands/usb_command_get_adc_value.h b/right/src/usb_commands/usb_command_get_adc_value.h index b699602e..b8830ce8 100644 --- a/right/src/usb_commands/usb_command_get_adc_value.h +++ b/right/src/usb_commands/usb_command_get_adc_value.h @@ -1,8 +1,12 @@ #ifndef __USB_COMMAND_GET_ADC_VALUE_H__ #define __USB_COMMAND_GET_ADC_VALUE_H__ +// Includes: + + #include + // Functions: - void UsbCommand_GetAdcValue(void); + void UsbCommand_GetAdcValue(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_get_debug_buffer.c b/right/src/usb_commands/usb_command_get_debug_buffer.c index e280dcdc..f8065bce 100644 --- a/right/src/usb_commands/usb_command_get_debug_buffer.c +++ b/right/src/usb_commands/usb_command_get_debug_buffer.c @@ -19,7 +19,7 @@ uint8_t DebugBuffer[USB_GENERIC_HID_IN_BUFFER_LENGTH]; -void UsbCommand_GetDebugBuffer(void) +void UsbCommand_GetDebugBuffer(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { #ifndef __ZEPHYR__ SetDebugBufferUint32(1, I2C_Watchdog); diff --git a/right/src/usb_commands/usb_command_get_debug_buffer.h b/right/src/usb_commands/usb_command_get_debug_buffer.h index 06619b40..d726e315 100644 --- a/right/src/usb_commands/usb_command_get_debug_buffer.h +++ b/right/src/usb_commands/usb_command_get_debug_buffer.h @@ -11,7 +11,7 @@ // Functions: - void UsbCommand_GetDebugBuffer(void); + void UsbCommand_GetDebugBuffer(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); void SetDebugBufferUint8(uint32_t offset, uint8_t value); void SetDebugBufferUint16(uint32_t offset, uint16_t value); diff --git a/right/src/usb_commands/usb_command_get_device_property.c b/right/src/usb_commands/usb_command_get_device_property.c index efd76ae3..f45c7fd1 100644 --- a/right/src/usb_commands/usb_command_get_device_property.c +++ b/right/src/usb_commands/usb_command_get_device_property.c @@ -25,7 +25,7 @@ uint16_t configSizes[] = {HARDWARE_CONFIG_SIZE, USER_CONFIG_SIZE}; -void UsbCommand_GetDeviceProperty(void) +void UsbCommand_GetDeviceProperty(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { uint8_t propertyId = GetUsbRxBufferUint8(1); uint8_t *dest = GenericHidInBuffer + 1; @@ -105,7 +105,7 @@ void UsbCommand_GetDeviceProperty(void) } break; case DevicePropertyId_NewPairings: #ifdef __ZEPHYR__ - UsbCommand_GetNewPairings(); + UsbCommand_GetNewPairings(GenericHidOutBuffer, GenericHidInBuffer); #endif break; default: diff --git a/right/src/usb_commands/usb_command_get_device_property.h b/right/src/usb_commands/usb_command_get_device_property.h index cce6ca49..517490f2 100644 --- a/right/src/usb_commands/usb_command_get_device_property.h +++ b/right/src/usb_commands/usb_command_get_device_property.h @@ -1,6 +1,10 @@ #ifndef __USB_COMMAND_GET_DEVICE_PROPERTY_H__ #define __USB_COMMAND_GET_DEVICE_PROPERTY_H__ +// Includes: + + #include + // Typedefs: typedef enum { @@ -31,6 +35,6 @@ // Functions: - void UsbCommand_GetDeviceProperty(void); + void UsbCommand_GetDeviceProperty(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_get_device_state.c b/right/src/usb_commands/usb_command_get_device_state.c index 63ab15f1..6b06339e 100644 --- a/right/src/usb_commands/usb_command_get_device_state.c +++ b/right/src/usb_commands/usb_command_get_device_state.c @@ -29,7 +29,7 @@ #define Bt_NewPairedDevice 0 #endif -void UsbCommand_GetKeyboardState(void) +void UsbCommand_GetKeyboardState(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { #ifdef __ZEPHYR__ diff --git a/right/src/usb_commands/usb_command_get_device_state.h b/right/src/usb_commands/usb_command_get_device_state.h index 4b14970e..1b1b20f9 100644 --- a/right/src/usb_commands/usb_command_get_device_state.h +++ b/right/src/usb_commands/usb_command_get_device_state.h @@ -1,6 +1,10 @@ #ifndef __USB_COMMAND_GET_KEYBOARD_STATE_H__ #define __USB_COMMAND_GET_KEYBOARD_STATE_H__ +// Includes: + + #include + // Typedefs: typedef enum { @@ -18,6 +22,6 @@ typedef enum { // Functions: - void UsbCommand_GetKeyboardState(void); + void UsbCommand_GetKeyboardState(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_get_module_property.c b/right/src/usb_commands/usb_command_get_module_property.c index a7eda47b..5b5efdaa 100644 --- a/right/src/usb_commands/usb_command_get_module_property.c +++ b/right/src/usb_commands/usb_command_get_module_property.c @@ -10,7 +10,7 @@ #include "utils.h" #include "versioning.h" -void UsbCommand_GetModuleProperty() +void UsbCommand_GetModuleProperty(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { slot_t slotId = GetUsbRxBufferUint8(1); diff --git a/right/src/usb_commands/usb_command_get_module_property.h b/right/src/usb_commands/usb_command_get_module_property.h index 2237aaf2..101574cb 100644 --- a/right/src/usb_commands/usb_command_get_module_property.h +++ b/right/src/usb_commands/usb_command_get_module_property.h @@ -1,9 +1,13 @@ #ifndef __USB_COMMAND_GET_MODULE_PROPERTY_H__ #define __USB_COMMAND_GET_MODULE_PROPERTY_H__ +// Includes: + + #include + // Functions: - void UsbCommand_GetModuleProperty(); + void UsbCommand_GetModuleProperty(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); // Typedefs: diff --git a/right/src/usb_commands/usb_command_get_new_pairings.c b/right/src/usb_commands/usb_command_get_new_pairings.c index d86d030d..168f319b 100644 --- a/right/src/usb_commands/usb_command_get_new_pairings.c +++ b/right/src/usb_commands/usb_command_get_new_pairings.c @@ -7,12 +7,20 @@ #include #include "host_connection.h" -static uint8_t idx; -static uint8_t count; +typedef struct { + const uint8_t *OutBuffer; + uint8_t *InBuffer; + uint8_t idx; + uint8_t count; +} CommandUserData; + static void bt_foreach_bond_cb(const struct bt_bond_info *info, void *user_data) { - if (idx + BLE_ADDR_LEN+1 >= USB_GENERIC_HID_IN_BUFFER_LENGTH) { + CommandUserData *data = (CommandUserData *)user_data; + uint8_t *GenericHidInBuffer = data->InBuffer; + + if ((data->idx + BLE_ADDR_LEN + 1) >= USB_GENERIC_HID_IN_BUFFER_LENGTH) { return; } @@ -20,22 +28,26 @@ static void bt_foreach_bond_cb(const struct bt_bond_info *info, void *user_data) return; } - count++; + data->count++; - SetUsbTxBufferBleAddress(idx, &info->addr); - idx += BLE_ADDR_LEN; + SetUsbTxBufferBleAddress(data->idx, &info->addr); + data->idx += BLE_ADDR_LEN; // Name placeholder - SetUsbTxBufferUint8(idx++, 0); + SetUsbTxBufferUint8(data->idx++, 0); } -void UsbCommand_GetNewPairings(void) { - count = 0; - idx = 2; +void UsbCommand_GetNewPairings(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { + CommandUserData data = { + .OutBuffer = GenericHidOutBuffer, + .InBuffer = GenericHidInBuffer, + .idx = 2, + .count = 0 + }; - bt_foreach_bond(BT_ID_DEFAULT, bt_foreach_bond_cb, NULL); + bt_foreach_bond(BT_ID_DEFAULT, bt_foreach_bond_cb, &data); - SetUsbTxBufferUint8(1, count); + SetUsbTxBufferUint8(1, data.count); Bt_NewPairedDevice = false; } diff --git a/right/src/usb_commands/usb_command_get_new_pairings.h b/right/src/usb_commands/usb_command_get_new_pairings.h index a62b0cb4..726e1206 100644 --- a/right/src/usb_commands/usb_command_get_new_pairings.h +++ b/right/src/usb_commands/usb_command_get_new_pairings.h @@ -1,13 +1,17 @@ #ifndef __USB_COMMAND_GET_NEW_PAIRINGS_H__ #define __USB_COMMAND_GET_NEW_PAIRINGS_H__ +// Includes: + + #include + #ifdef __ZEPHYR__ // Typedefs: // Functions: - void UsbCommand_GetNewPairings(void); + void UsbCommand_GetNewPairings(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_get_slave_i2c_errors.c b/right/src/usb_commands/usb_command_get_slave_i2c_errors.c index 0843a330..3e62cad9 100644 --- a/right/src/usb_commands/usb_command_get_slave_i2c_errors.c +++ b/right/src/usb_commands/usb_command_get_slave_i2c_errors.c @@ -4,7 +4,7 @@ #include "slave_scheduler.h" #include "i2c_error_logger.h" -void UsbCommand_GetSlaveI2cErrors() +void UsbCommand_GetSlaveI2cErrors(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { uint8_t slaveId = GetUsbRxBufferUint8(1); diff --git a/right/src/usb_commands/usb_command_get_slave_i2c_errors.h b/right/src/usb_commands/usb_command_get_slave_i2c_errors.h index d62d459a..f06357d6 100644 --- a/right/src/usb_commands/usb_command_get_slave_i2c_errors.h +++ b/right/src/usb_commands/usb_command_get_slave_i2c_errors.h @@ -1,9 +1,13 @@ #ifndef __USB_COMMAND_GET_SLAVE_I2C_ERRORS_H__ #define __USB_COMMAND_GET_SLAVE_I2C_ERRORS_H__ +// Includes: + + #include + // Functions: - void UsbCommand_GetSlaveI2cErrors(); + void UsbCommand_GetSlaveI2cErrors(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); // Typedefs: diff --git a/right/src/usb_commands/usb_command_get_variable.c b/right/src/usb_commands/usb_command_get_variable.c index c96cddb0..95391bd9 100644 --- a/right/src/usb_commands/usb_command_get_variable.c +++ b/right/src/usb_commands/usb_command_get_variable.c @@ -6,7 +6,7 @@ #include "macros/core.h" #include "config_manager.h" -void UsbCommand_GetVariable(void) +void UsbCommand_GetVariable(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { usb_variable_id_t variableId = GetUsbRxBufferUint8(1); diff --git a/right/src/usb_commands/usb_command_get_variable.h b/right/src/usb_commands/usb_command_get_variable.h index 5e5992ae..88bf2498 100644 --- a/right/src/usb_commands/usb_command_get_variable.h +++ b/right/src/usb_commands/usb_command_get_variable.h @@ -1,8 +1,12 @@ #ifndef __USB_COMMAND_GET_VARIABLE_H__ #define __USB_COMMAND_GET_VARIABLE_H__ +// Includes: + + #include + // Functions: - void UsbCommand_GetVariable(void); + void UsbCommand_GetVariable(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_jump_to_module_bootloader.c b/right/src/usb_commands/usb_command_jump_to_module_bootloader.c index 5cff7e00..e93a4541 100644 --- a/right/src/usb_commands/usb_command_jump_to_module_bootloader.c +++ b/right/src/usb_commands/usb_command_jump_to_module_bootloader.c @@ -3,7 +3,7 @@ #include "slot.h" #include "slave_drivers/uhk_module_driver.h" -void UsbCommand_JumpToModuleBootloader(void) +void UsbCommand_JumpToModuleBootloader(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { uint8_t slotId = GetUsbRxBufferUint8(1); diff --git a/right/src/usb_commands/usb_command_jump_to_module_bootloader.h b/right/src/usb_commands/usb_command_jump_to_module_bootloader.h index e004f3ae..1d5b2877 100644 --- a/right/src/usb_commands/usb_command_jump_to_module_bootloader.h +++ b/right/src/usb_commands/usb_command_jump_to_module_bootloader.h @@ -1,9 +1,13 @@ #ifndef __USB_COMMAND_JUMP_TO_MODULE_BOOTLOADER_H__ #define __USB_COMMAND_JUMP_TO_MODULE_BOOTLOADER_H__ +// Includes: + + #include + // Functions: - void UsbCommand_JumpToModuleBootloader(void); + void UsbCommand_JumpToModuleBootloader(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); // Typedefs: diff --git a/right/src/usb_commands/usb_command_launch_storage_transfer.c b/right/src/usb_commands/usb_command_launch_storage_transfer.c index c6a25881..259b1494 100644 --- a/right/src/usb_commands/usb_command_launch_storage_transfer.c +++ b/right/src/usb_commands/usb_command_launch_storage_transfer.c @@ -20,7 +20,7 @@ enum _generic_status #include "eeprom.h" #endif -void UsbCommand_LaunchStorageTransfer(void) +void UsbCommand_LaunchStorageTransfer(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { storage_operation_t storageOperation = GetUsbRxBufferUint8(1); config_buffer_id_t configBufferId = GetUsbRxBufferUint8(2); diff --git a/right/src/usb_commands/usb_command_launch_storage_transfer.h b/right/src/usb_commands/usb_command_launch_storage_transfer.h index e2b7796d..2c7aae96 100644 --- a/right/src/usb_commands/usb_command_launch_storage_transfer.h +++ b/right/src/usb_commands/usb_command_launch_storage_transfer.h @@ -1,6 +1,10 @@ #ifndef __USB_COMMAND_LAUNCH_STORAGE_TRANSFER_H__ #define __USB_COMMAND_LAUNCH_STORAGE_TRANSFER_H__ +// Includes: + + #include + // Typedef typedef enum { @@ -11,6 +15,6 @@ // Functions: - void UsbCommand_LaunchStorageTransfer(void); + void UsbCommand_LaunchStorageTransfer(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_pairing.c b/right/src/usb_commands/usb_command_pairing.c index e4d42a7f..b1a1bee2 100644 --- a/right/src/usb_commands/usb_command_pairing.c +++ b/right/src/usb_commands/usb_command_pairing.c @@ -15,7 +15,7 @@ #define BUF_KEY_R_POS 7 #define BUF_KEY_C_POS 23 -void UsbCommand_GetPairingData(void) { +void UsbCommand_GetPairingData(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { struct bt_le_oob* oob = BtPair_GetLocalOob(); SetUsbTxBufferBleAddress(BUF_ADR_POS, &oob->addr); @@ -23,7 +23,7 @@ void UsbCommand_GetPairingData(void) { memcpy(GenericHidInBuffer + BUF_KEY_C_POS, oob->le_sc_data.c, BLE_KEY_LEN); } -void UsbCommand_SetPairingData(void) { +void UsbCommand_SetPairingData(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { struct bt_le_oob oob; uint8_t peerId = GenericHidOutBuffer[BUF_PEER_POS]; @@ -53,31 +53,31 @@ void UsbCommand_SetPairingData(void) { } } -void UsbCommand_PairCentral(void) { +void UsbCommand_PairCentral(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { #ifdef CONFIG_BT_CENTRAL BtPair_PairCentral(); #endif } -void UsbCommand_PairPeripheral(void) { +void UsbCommand_PairPeripheral(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { #ifdef CONFIG_BT_PERIPHERAL BtPair_PairPeripheral(); #endif } // If zero address is provided, all existing bonds will be deleted -void UsbCommand_Unpair(void) { +void UsbCommand_Unpair(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { bt_addr_le_t addr = GetUsbRxBufferBleAddress(1); BtPair_Unpair(addr); } -void UsbCommand_IsPaired(void) { +void UsbCommand_IsPaired(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { bt_addr_le_t addr = GetUsbRxBufferBleAddress(1); bool isPaired = BtPair_IsDeviceBonded(&addr); SetUsbTxBufferUint8(1, isPaired); } -void UsbCommand_EnterPairingMode(void) { +void UsbCommand_EnterPairingMode(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { BtManager_EnterPairingMode(); } diff --git a/right/src/usb_commands/usb_command_pairing.h b/right/src/usb_commands/usb_command_pairing.h index b6312f0d..64bb6b1f 100644 --- a/right/src/usb_commands/usb_command_pairing.h +++ b/right/src/usb_commands/usb_command_pairing.h @@ -1,15 +1,19 @@ #ifndef __USB_COMMAND_PAIRING_H__ #define __USB_COMMAND_PAIRING_H__ +// Includes: + + #include + // Functions: - void UsbCommand_GetPairingData(void); - void UsbCommand_SetPairingData(void); - void UsbCommand_PairCentral(void); - void UsbCommand_PairPeripheral(void); - void UsbCommand_Unpair(void); - void UsbCommand_IsPaired(void); - void UsbCommand_EnterPairingMode(void); + void UsbCommand_GetPairingData(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); + void UsbCommand_SetPairingData(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); + void UsbCommand_PairCentral(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); + void UsbCommand_PairPeripheral(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); + void UsbCommand_Unpair(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); + void UsbCommand_IsPaired(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); + void UsbCommand_EnterPairingMode(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); // Typedefs: diff --git a/right/src/usb_commands/usb_command_read_config.c b/right/src/usb_commands/usb_command_read_config.c index 7dd09de2..99212d2f 100644 --- a/right/src/usb_commands/usb_command_read_config.c +++ b/right/src/usb_commands/usb_command_read_config.c @@ -11,7 +11,7 @@ #include "usb_protocol_handler.h" #include "eeprom.h" -void UsbCommand_ReadConfig() +void UsbCommand_ReadConfig(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { config_buffer_id_t configBufferId = GetUsbRxBufferUint8(1); uint8_t length = GetUsbRxBufferUint8(2); diff --git a/right/src/usb_commands/usb_command_read_config.h b/right/src/usb_commands/usb_command_read_config.h index 889d3ec6..f2be164d 100644 --- a/right/src/usb_commands/usb_command_read_config.h +++ b/right/src/usb_commands/usb_command_read_config.h @@ -1,9 +1,13 @@ #ifndef __USB_COMMAND_READ_CONFIG_H__ #define __USB_COMMAND_READ_CONFIG_H__ +// Includes: + + #include + // Functions: - void UsbCommand_ReadConfig(); + void UsbCommand_ReadConfig(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); // Typedefs: diff --git a/right/src/usb_commands/usb_command_reenumerate.c b/right/src/usb_commands/usb_command_reenumerate.c index 86ba1cdf..256b32e9 100644 --- a/right/src/usb_commands/usb_command_reenumerate.c +++ b/right/src/usb_commands/usb_command_reenumerate.c @@ -9,7 +9,7 @@ #include "usb_commands/usb_command_reenumerate.h" #include "usb_protocol_handler.h" -void UsbCommand_Reenumerate(void) +void UsbCommand_Reenumerate(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { #ifdef __ZEPHYR__ bootmode_set(BOOT_MODE_TYPE_BOOTLOADER); diff --git a/right/src/usb_commands/usb_command_reenumerate.h b/right/src/usb_commands/usb_command_reenumerate.h index fccefd32..d4dcd716 100644 --- a/right/src/usb_commands/usb_command_reenumerate.h +++ b/right/src/usb_commands/usb_command_reenumerate.h @@ -1,8 +1,12 @@ #ifndef __USB_COMMAND_REENUMERATE_H__ #define __USB_COMMAND_REENUMERATE_H__ +// Includes: + + #include + // Functions: - void UsbCommand_Reenumerate(void); + void UsbCommand_Reenumerate(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_send_kboot_command_to_module.c b/right/src/usb_commands/usb_command_send_kboot_command_to_module.c index 08397fbf..c96817df 100644 --- a/right/src/usb_commands/usb_command_send_kboot_command_to_module.c +++ b/right/src/usb_commands/usb_command_send_kboot_command_to_module.c @@ -2,7 +2,7 @@ #include "usb_commands/usb_command_send_kboot_command_to_module.h" #include "slave_drivers/kboot_driver.h" -void UsbCommand_SendKbootCommandToModule(void) +void UsbCommand_SendKbootCommandToModule(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { KbootDriverState.phase = 0; KbootDriverState.i2cAddress = GetUsbRxBufferUint8(2); diff --git a/right/src/usb_commands/usb_command_send_kboot_command_to_module.h b/right/src/usb_commands/usb_command_send_kboot_command_to_module.h index e1b3b090..b67dfd10 100644 --- a/right/src/usb_commands/usb_command_send_kboot_command_to_module.h +++ b/right/src/usb_commands/usb_command_send_kboot_command_to_module.h @@ -1,8 +1,12 @@ #ifndef __USB_COMMAND_SEND_KBOOT_COMMAND_TO_MODULE_H__ #define __USB_COMMAND_SEND_KBOOT_COMMAND_TO_MODULE_H__ +// Includes: + + #include + // Functions: - void UsbCommand_SendKbootCommandToModule(void); + void UsbCommand_SendKbootCommandToModule(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_set_i2c_baud_rate.c b/right/src/usb_commands/usb_command_set_i2c_baud_rate.c index 90b12133..c294fee7 100644 --- a/right/src/usb_commands/usb_command_set_i2c_baud_rate.c +++ b/right/src/usb_commands/usb_command_set_i2c_baud_rate.c @@ -3,7 +3,7 @@ #include "init_peripherals.h" #include "fsl_i2c.h" -void UsbCommand_SetI2cBaudRate(void) +void UsbCommand_SetI2cBaudRate(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { uint32_t i2cBaudRate = GetUsbRxBufferUint32(1); ChangeI2cBaudRate(i2cBaudRate); diff --git a/right/src/usb_commands/usb_command_set_i2c_baud_rate.h b/right/src/usb_commands/usb_command_set_i2c_baud_rate.h index c95c4d32..22881e24 100644 --- a/right/src/usb_commands/usb_command_set_i2c_baud_rate.h +++ b/right/src/usb_commands/usb_command_set_i2c_baud_rate.h @@ -1,8 +1,12 @@ #ifndef __USB_COMMAND_SET_I2C_BAUD_RATE__ #define __USB_COMMAND_SET_I2C_BAUD_RATE__ +// Includes: + + #include + // Functions: - void UsbCommand_SetI2cBaudRate(void); + void UsbCommand_SetI2cBaudRate(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_set_led_pwm_brightness.c b/right/src/usb_commands/usb_command_set_led_pwm_brightness.c index 3cb465a3..035f38bc 100644 --- a/right/src/usb_commands/usb_command_set_led_pwm_brightness.c +++ b/right/src/usb_commands/usb_command_set_led_pwm_brightness.c @@ -3,7 +3,7 @@ #include "slave_drivers/uhk_module_driver.h" #include "led_pwm.h" -void UsbCommand_SetLedPwmBrightness(void) +void UsbCommand_SetLedPwmBrightness(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { uint8_t brightnessPercent = GetUsbRxBufferUint8(1); LedPwm_SetBrightness(brightnessPercent); diff --git a/right/src/usb_commands/usb_command_set_led_pwm_brightness.h b/right/src/usb_commands/usb_command_set_led_pwm_brightness.h index 48a9ac14..73daafb2 100644 --- a/right/src/usb_commands/usb_command_set_led_pwm_brightness.h +++ b/right/src/usb_commands/usb_command_set_led_pwm_brightness.h @@ -1,8 +1,12 @@ #ifndef __USB_COMMAND_SET_LED_PWM_BRIGHTNESS_H__ #define __USB_COMMAND_SET_LED_PWM_BRIGHTNESS_H__ +// Includes: + + #include + // Functions: - void UsbCommand_SetLedPwmBrightness(void); + void UsbCommand_SetLedPwmBrightness(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_set_test_led.c b/right/src/usb_commands/usb_command_set_test_led.c index 0104270e..82dfd346 100644 --- a/right/src/usb_commands/usb_command_set_test_led.c +++ b/right/src/usb_commands/usb_command_set_test_led.c @@ -3,7 +3,7 @@ #include "peripherals/test_led.h" #include "slave_drivers/uhk_module_driver.h" -void UsbCommand_SetTestLed(void) +void UsbCommand_SetTestLed(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { bool isTestLedOn = GetUsbRxBufferUint8(1); TestLed_Set(isTestLedOn); diff --git a/right/src/usb_commands/usb_command_set_test_led.h b/right/src/usb_commands/usb_command_set_test_led.h index 718e8fe1..413616e7 100644 --- a/right/src/usb_commands/usb_command_set_test_led.h +++ b/right/src/usb_commands/usb_command_set_test_led.h @@ -1,8 +1,12 @@ #ifndef __USB_COMMAND_SET_TEST_LED_H__ #define __USB_COMMAND_SET_TEST_LED_H__ +// Includes: + + #include + // Functions: - void UsbCommand_SetTestLed(void); + void UsbCommand_SetTestLed(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_set_variable.c b/right/src/usb_commands/usb_command_set_variable.c index f04f5a5a..729413e8 100644 --- a/right/src/usb_commands/usb_command_set_variable.c +++ b/right/src/usb_commands/usb_command_set_variable.c @@ -8,7 +8,7 @@ #include "config_manager.h" #include "ledmap.h" -void UsbCommand_SetVariable(void) +void UsbCommand_SetVariable(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { usb_variable_id_t variableId = GetUsbRxBufferUint8(1); diff --git a/right/src/usb_commands/usb_command_set_variable.h b/right/src/usb_commands/usb_command_set_variable.h index e9b61218..2f3148a7 100644 --- a/right/src/usb_commands/usb_command_set_variable.h +++ b/right/src/usb_commands/usb_command_set_variable.h @@ -1,8 +1,12 @@ #ifndef __USB_COMMAND_SET_VARIABLE_H__ #define __USB_COMMAND_SET_VARIABLE_H__ +// Includes: + + #include + // Functions: - void UsbCommand_SetVariable(void); + void UsbCommand_SetVariable(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_commands/usb_command_switch_keymap.c b/right/src/usb_commands/usb_command_switch_keymap.c index 2a822c77..60ef2a9a 100644 --- a/right/src/usb_commands/usb_command_switch_keymap.c +++ b/right/src/usb_commands/usb_command_switch_keymap.c @@ -3,7 +3,7 @@ #include "keymap.h" #include "layer_stack.h" -void UsbCommand_SwitchKeymap(void) +void UsbCommand_SwitchKeymap(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { uint32_t keymapLength = GetUsbRxBufferUint8(1); char *keymapAbbrev = (char*)GenericHidOutBuffer + 2; diff --git a/right/src/usb_commands/usb_command_switch_keymap.h b/right/src/usb_commands/usb_command_switch_keymap.h index be22c771..58e13480 100644 --- a/right/src/usb_commands/usb_command_switch_keymap.h +++ b/right/src/usb_commands/usb_command_switch_keymap.h @@ -1,9 +1,13 @@ #ifndef __USB_COMMAND_SWITCH_KEYMAP_H__ #define __USB_COMMAND_SWITCH_KEYMAP_H__ +// Includes: + + #include + // Functions: - void UsbCommand_SwitchKeymap(void); + void UsbCommand_SwitchKeymap(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); // Typedefs: diff --git a/right/src/usb_commands/usb_command_write_config.c b/right/src/usb_commands/usb_command_write_config.c index 29879241..9c147e94 100644 --- a/right/src/usb_commands/usb_command_write_config.c +++ b/right/src/usb_commands/usb_command_write_config.c @@ -6,7 +6,7 @@ #include "usb_protocol_handler.h" #include "eeprom.h" -void UsbCommand_WriteConfig(config_buffer_id_t configBufferId) +void UsbCommand_WriteConfig(config_buffer_id_t configBufferId, const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { uint8_t length = GetUsbRxBufferUint8(1); uint16_t offset = GetUsbRxBufferUint16(2); diff --git a/right/src/usb_commands/usb_command_write_config.h b/right/src/usb_commands/usb_command_write_config.h index 7fde91bd..c8dcbc2a 100644 --- a/right/src/usb_commands/usb_command_write_config.h +++ b/right/src/usb_commands/usb_command_write_config.h @@ -14,6 +14,6 @@ // Functions: - void UsbCommand_WriteConfig(config_buffer_id_t configBufferId); + void UsbCommand_WriteConfig(config_buffer_id_t configBufferId, const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/usb_interfaces/usb_interface_generic_hid.c b/right/src/usb_interfaces/usb_interface_generic_hid.c index 9ff60cea..a0e44b32 100644 --- a/right/src/usb_interfaces/usb_interface_generic_hid.c +++ b/right/src/usb_interfaces/usb_interface_generic_hid.c @@ -1,22 +1,10 @@ -#ifndef __ZEPHYR__ #include "usb_composite_device.h" -#endif - #include "usb_protocol_handler.h" -#ifndef __ZEPHYR__ uint32_t UsbGenericHidActionCounter; -#endif - -uint8_t GenericHidInBuffer[USB_GENERIC_HID_IN_BUFFER_LENGTH]; - -#ifdef __ZEPHYR__ -const uint8_t *GenericHidOutBuffer; -#else -uint8_t GenericHidOutBuffer[USB_GENERIC_HID_OUT_BUFFER_LENGTH]; -#endif +uint8_t GenericHidIn[USB_GENERIC_HID_IN_BUFFER_LENGTH]; +uint8_t GenericHidOut[USB_GENERIC_HID_OUT_BUFFER_LENGTH]; -#ifndef __ZEPHYR__ static usb_status_t UsbReceiveData(void) { if (!UsbCompositeDevice.attach) { @@ -62,11 +50,11 @@ usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void * break; case kUSB_DeviceHidEventRecvResponse: - UsbProtocolHandler(); + UsbProtocolHandler(GenericHidOut, GenericHidIn); USB_DeviceHidSend(UsbCompositeDevice.genericHidHandle, USB_GENERIC_HID_ENDPOINT_IN_INDEX, - GenericHidInBuffer, + GenericHidIn, USB_GENERIC_HID_IN_BUFFER_LENGTH); UsbGenericHidActionCounter++; error = UsbReceiveData(); @@ -75,7 +63,7 @@ usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void * case kUSB_DeviceHidEventGetReport: { usb_device_hid_report_struct_t *report = (usb_device_hid_report_struct_t*)param; if (report->reportType == USB_DEVICE_HID_REQUEST_GET_REPORT_TYPE_INPUT && report->reportId == 0 && report->reportLength <= USB_GENERIC_HID_IN_BUFFER_LENGTH) { - report->reportBuffer = GenericHidInBuffer; + report->reportBuffer = GenericHidIn; UsbGenericHidActionCounter++; error = kStatus_USB_Success; } else { @@ -90,4 +78,3 @@ usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void * return error; } -#endif diff --git a/right/src/usb_interfaces/usb_interface_generic_hid.h b/right/src/usb_interfaces/usb_interface_generic_hid.h index 07c8a10c..bbd51b2e 100644 --- a/right/src/usb_interfaces/usb_interface_generic_hid.h +++ b/right/src/usb_interfaces/usb_interface_generic_hid.h @@ -28,13 +28,6 @@ // Variables: extern uint32_t UsbGenericHidActionCounter; - extern uint8_t GenericHidInBuffer[USB_GENERIC_HID_IN_BUFFER_LENGTH]; - -#ifdef __ZEPHYR__ - extern const uint8_t *GenericHidOutBuffer; -#else - extern uint8_t GenericHidOutBuffer[USB_GENERIC_HID_OUT_BUFFER_LENGTH]; -#endif // Functions: diff --git a/right/src/usb_protocol_handler.c b/right/src/usb_protocol_handler.c index 37de9288..0c761943 100644 --- a/right/src/usb_protocol_handler.c +++ b/right/src/usb_protocol_handler.c @@ -1,7 +1,6 @@ #include #include "macros/status_buffer.h" #include "usb_protocol_handler.h" -#include "buffer.h" #include "usb_commands/usb_command_get_device_state.h" #include "usb_commands/usb_command_read_config.h" #include "usb_commands/usb_command_reenumerate.h" @@ -30,114 +29,104 @@ #include "usb_commands/usb_command_set_i2c_baud_rate.h" #endif -#ifdef __ZEPHYR__ -void CommandProtocolRxHandler(const uint8_t* data, size_t size) -{ - GenericHidOutBuffer = data; - // printk("CommandProtocolRxHandler: data[0]:%u size:%d\n", data[0], size); - UsbProtocolHandler(); - CommandProtocolTx(GenericHidInBuffer, USB_GENERIC_HID_OUT_BUFFER_LENGTH); -} -#endif - -void UsbProtocolHandler(void) +void UsbProtocolHandler(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) { bzero(GenericHidInBuffer, USB_GENERIC_HID_IN_BUFFER_LENGTH); uint8_t command = GetUsbRxBufferUint8(0); switch (command) { case UsbCommandId_GetDeviceProperty: - UsbCommand_GetDeviceProperty(); + UsbCommand_GetDeviceProperty(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_Reenumerate: - UsbCommand_Reenumerate(); + UsbCommand_Reenumerate(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_ReadConfig: - UsbCommand_ReadConfig(); + UsbCommand_ReadConfig(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_WriteHardwareConfig: - UsbCommand_WriteConfig(ConfigBufferId_HardwareConfig); + UsbCommand_WriteConfig(ConfigBufferId_HardwareConfig, GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_WriteStagingUserConfig: - UsbCommand_WriteConfig(ConfigBufferId_StagingUserConfig); + UsbCommand_WriteConfig(ConfigBufferId_StagingUserConfig, GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_ApplyConfig: #ifdef __ZEPHYR__ - UsbCommand_ApplyConfigAsync(); + UsbCommand_ApplyConfigAsync(GenericHidOutBuffer, GenericHidInBuffer); #else - UsbCommand_ApplyConfig(); + UsbCommand_ApplyConfig(GenericHidOutBuffer, GenericHidInBuffer); #endif break; case UsbCommandId_GetDeviceState: - UsbCommand_GetKeyboardState(); + UsbCommand_GetKeyboardState(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_GetDebugBuffer: - UsbCommand_GetDebugBuffer(); + UsbCommand_GetDebugBuffer(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_SwitchKeymap: - UsbCommand_SwitchKeymap(); + UsbCommand_SwitchKeymap(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_GetVariable: - UsbCommand_GetVariable(); + UsbCommand_GetVariable(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_SetVariable: - UsbCommand_SetVariable(); + UsbCommand_SetVariable(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_ExecMacroCommand: - UsbCommand_ExecMacroCommand(); + UsbCommand_ExecMacroCommand(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_LaunchStorageTransfer: - UsbCommand_LaunchStorageTransfer(); + UsbCommand_LaunchStorageTransfer(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_GetModuleProperty: - UsbCommand_GetModuleProperty(); + UsbCommand_GetModuleProperty(GenericHidOutBuffer, GenericHidInBuffer); break; #ifdef __ZEPHYR__ case UsbCommandId_DrawOled: - UsbCommand_DrawOled(); + UsbCommand_DrawOled(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_GetPairingData: - UsbCommand_GetPairingData(); + UsbCommand_GetPairingData(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_SetPairingData: - UsbCommand_SetPairingData(); + UsbCommand_SetPairingData(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_PairCentral: - UsbCommand_PairCentral(); + UsbCommand_PairCentral(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_PairPeripheral: - UsbCommand_PairPeripheral(); + UsbCommand_PairPeripheral(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_UnpairAll: - UsbCommand_Unpair(); + UsbCommand_Unpair(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_IsPaired: - UsbCommand_IsPaired(); + UsbCommand_IsPaired(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_EnterPairingMode: - UsbCommand_EnterPairingMode(); + UsbCommand_EnterPairingMode(GenericHidOutBuffer, GenericHidInBuffer); break; #else case UsbCommandId_JumpToModuleBootloader: - UsbCommand_JumpToModuleBootloader(); + UsbCommand_JumpToModuleBootloader(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_SendKbootCommandToModule: - UsbCommand_SendKbootCommandToModule(); + UsbCommand_SendKbootCommandToModule(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_SetTestLed: - UsbCommand_SetTestLed(); + UsbCommand_SetTestLed(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_GetAdcValue: - UsbCommand_GetAdcValue(); + UsbCommand_GetAdcValue(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_SetLedPwmBrightness: - UsbCommand_SetLedPwmBrightness(); + UsbCommand_SetLedPwmBrightness(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_GetSlaveI2cErrors: - UsbCommand_GetSlaveI2cErrors(); + UsbCommand_GetSlaveI2cErrors(GenericHidOutBuffer, GenericHidInBuffer); break; case UsbCommandId_SetI2cBaudRate: - UsbCommand_SetI2cBaudRate(); + UsbCommand_SetI2cBaudRate(GenericHidOutBuffer, GenericHidInBuffer); break; #endif default: @@ -149,38 +138,8 @@ void UsbProtocolHandler(void) } } -uint8_t GetUsbRxBufferUint8(uint32_t offset) -{ - return GetBufferUint8(GenericHidOutBuffer, offset); -} - -uint16_t GetUsbRxBufferUint16(uint32_t offset) -{ - return GetBufferUint16(GenericHidOutBuffer, offset); -} - -uint32_t GetUsbRxBufferUint32(uint32_t offset) -{ - return GetBufferUint32(GenericHidOutBuffer, offset); -} - -void SetUsbTxBufferUint8(uint32_t offset, uint8_t value) -{ - SetBufferUint8(GenericHidInBuffer, offset, value); -} - -void SetUsbTxBufferUint16(uint32_t offset, uint16_t value) -{ - SetBufferUint16(GenericHidInBuffer, offset, value); -} - -void SetUsbTxBufferUint32(uint32_t offset, uint32_t value) -{ - SetBufferUint32(GenericHidInBuffer, offset, value); -} - #ifdef __ZEPHYR__ -bt_addr_le_t GetUsbRxBufferBleAddress(uint32_t offset) { +bt_addr_le_t GetBufferBleAddress(const uint8_t *GenericHidOutBuffer, uint32_t offset) { bt_addr_le_t addr; addr.type = 1; for (uint8_t i = 0; i < BLE_ADDR_LEN; i++) { @@ -189,7 +148,7 @@ bt_addr_le_t GetUsbRxBufferBleAddress(uint32_t offset) { return addr; } -void SetUsbTxBufferBleAddress(uint32_t offset, const bt_addr_le_t* addr) { +void SetBufferBleAddress(uint8_t *GenericHidInBuffer, uint32_t offset, const bt_addr_le_t* addr) { for (uint8_t i = 0; i < BLE_ADDR_LEN; i++) { GenericHidInBuffer[offset + i] = addr->a.val[i]; } diff --git a/right/src/usb_protocol_handler.h b/right/src/usb_protocol_handler.h index e8cacfc9..96a30e36 100644 --- a/right/src/usb_protocol_handler.h +++ b/right/src/usb_protocol_handler.h @@ -7,6 +7,7 @@ #include #include #include "usb_interfaces/usb_interface_generic_hid.h" + #include "buffer.h" #ifdef __ZEPHYR__ #include #else @@ -17,6 +18,17 @@ #define USB_STATUS_CODE_SIZE 1 + #define GetUsbRxBufferUint8(OFFSET) (GetBufferUint8(GenericHidOutBuffer, OFFSET)) + #define GetUsbRxBufferUint16(OFFSET) (GetBufferUint16(GenericHidOutBuffer, OFFSET)) + #define GetUsbRxBufferUint32(OFFSET) (GetBufferUint32(GenericHidOutBuffer, OFFSET)) + + #define SetUsbTxBufferUint8(OFFSET, VALUE) (SetBufferUint8(GenericHidInBuffer, OFFSET, VALUE)) + #define SetUsbTxBufferUint16(OFFSET, VALUE) (SetBufferUint16(GenericHidInBuffer, OFFSET, VALUE)) + #define SetUsbTxBufferUint32(OFFSET, VALUE) (SetBufferUint32(GenericHidInBuffer, OFFSET, VALUE)) + + #define GetUsbRxBufferBleAddress(OFFSET) (GetBufferBleAddress(GenericHidOutBuffer, OFFSET)) + #define SetUsbTxBufferBleAddress(OFFSET, VALUE) (SetBufferBleAddress(GenericHidInBuffer, OFFSET, VALUE)) + // Typedefs: typedef enum { @@ -77,19 +89,9 @@ // Functions: #ifdef __ZEPHYR__ - extern bool CommandProtocolTx(const uint8_t* data, size_t size); - - void SetUsbTxBufferBleAddress(uint32_t offset, const bt_addr_le_t* addr); - extern bt_addr_le_t GetUsbRxBufferBleAddress(uint32_t offset); + bt_addr_le_t GetBufferBleAddress(const uint8_t *GenericHidOutBuffer, uint32_t offset); + void SetBufferBleAddress(uint8_t *GenericHidInBuffer, uint32_t offset, const bt_addr_le_t* addr); #endif - void UsbProtocolHandler(void); - - uint8_t GetUsbRxBufferUint8(uint32_t offset); - uint16_t GetUsbRxBufferUint16(uint32_t offset); - uint32_t GetUsbRxBufferUint32(uint32_t offset); - - void SetUsbTxBufferUint8(uint32_t offset, uint8_t value); - void SetUsbTxBufferUint16(uint32_t offset, uint16_t value); - void SetUsbTxBufferUint32(uint32_t offset, uint32_t value); + void UsbProtocolHandler(const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer); #endif diff --git a/right/src/user_logic.c b/right/src/user_logic.c index 438343b6..1e4cfe17 100644 --- a/right/src/user_logic.c +++ b/right/src/user_logic.c @@ -15,7 +15,7 @@ void RunUserLogic(void) { if (EventVector_IsSet(EventVector_ApplyConfig)) { - UsbCommand_ApplyConfig(); + UsbCommand_ApplyConfig(NULL, NULL); } if (EventVector_IsSet(EventVector_KeymapReloadNeeded)) { SwitchKeymapById(CurrentKeymapIndex);