Extract the applyConfig USB command into usb_command_apply_config.[ch]
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
#include "right_key_matrix.h"
|
#include "right_key_matrix.h"
|
||||||
#include "key_scanner.h"
|
#include "key_scanner.h"
|
||||||
#include "key_states.h"
|
#include "key_states.h"
|
||||||
|
#include "usb_commands/usb_command_apply_config.h"
|
||||||
|
|
||||||
void updateUsbReports(void)
|
void updateUsbReports(void)
|
||||||
{
|
{
|
||||||
@@ -77,7 +78,7 @@ void main(void)
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!IsConfigInitialized && IsEepromInitialized) {
|
if (!IsConfigInitialized && IsEepromInitialized) {
|
||||||
ApplyConfig();
|
UsbCommand_ApplyConfig();
|
||||||
IsConfigInitialized = true;
|
IsConfigInitialized = true;
|
||||||
}
|
}
|
||||||
updateUsbReports();
|
updateUsbReports();
|
||||||
|
|||||||
58
right/src/usb_commands/usb_command_apply_config.c
Normal file
58
right/src/usb_commands/usb_command_apply_config.c
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#include "fsl_common.h"
|
||||||
|
#include "usb_commands/usb_command_apply_config.h"
|
||||||
|
#include "config_parser/config_globals.h"
|
||||||
|
#include "config_parser/parse_config.h"
|
||||||
|
#include "usb_interfaces/usb_interface_generic_hid.h"
|
||||||
|
#include "usb_protocol_handler.h"
|
||||||
|
#include "keymap.h"
|
||||||
|
|
||||||
|
void UsbCommand_ApplyConfig(void)
|
||||||
|
{
|
||||||
|
// Validate the staging configuration.
|
||||||
|
|
||||||
|
ParserRunDry = true;
|
||||||
|
StagingUserConfigBuffer.offset = 0;
|
||||||
|
GenericHidOutBuffer[0] = ParseConfig(&StagingUserConfigBuffer);
|
||||||
|
*(uint16_t*)(GenericHidOutBuffer+1) = StagingUserConfigBuffer.offset;
|
||||||
|
GenericHidOutBuffer[3] = 0;
|
||||||
|
|
||||||
|
if (GenericHidOutBuffer[0] != UsbResponse_Success) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the staging configuration the current one.
|
||||||
|
|
||||||
|
char oldKeymapAbbreviation[KEYMAP_ABBREVIATION_LENGTH];
|
||||||
|
uint8_t oldKeymapAbbreviationLen;
|
||||||
|
memcpy(oldKeymapAbbreviation, AllKeymaps[CurrentKeymapIndex].abbreviation, KEYMAP_ABBREVIATION_LENGTH);
|
||||||
|
oldKeymapAbbreviationLen = AllKeymaps[CurrentKeymapIndex].abbreviationLen;
|
||||||
|
|
||||||
|
uint8_t *temp = ValidatedUserConfigBuffer.buffer;
|
||||||
|
ValidatedUserConfigBuffer.buffer = StagingUserConfigBuffer.buffer;
|
||||||
|
StagingUserConfigBuffer.buffer = temp;
|
||||||
|
|
||||||
|
ParserRunDry = false;
|
||||||
|
ValidatedUserConfigBuffer.offset = 0;
|
||||||
|
GenericHidOutBuffer[0] = ParseConfig(&ValidatedUserConfigBuffer);
|
||||||
|
*(uint16_t*)(GenericHidOutBuffer+1) = ValidatedUserConfigBuffer.offset;
|
||||||
|
GenericHidOutBuffer[3] = 1;
|
||||||
|
|
||||||
|
if (GenericHidOutBuffer[0] != UsbResponse_Success) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Switch to the keymap of the updated configuration of the same name or the default keymap.
|
||||||
|
|
||||||
|
for (uint8_t keymapId = 0; keymapId < AllKeymapsCount; keymapId++) {
|
||||||
|
if (AllKeymaps[keymapId].abbreviationLen != oldKeymapAbbreviationLen) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (memcmp(oldKeymapAbbreviation, AllKeymaps[keymapId].abbreviation, oldKeymapAbbreviationLen)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
SwitchKeymap(keymapId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SwitchKeymap(DefaultKeymapIndex);
|
||||||
|
}
|
||||||
8
right/src/usb_commands/usb_command_apply_config.h
Normal file
8
right/src/usb_commands/usb_command_apply_config.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef __USB_COMMAND_APPLY_CONFIG_H__
|
||||||
|
#define __USB_COMMAND_APPLY_CONFIG_H__
|
||||||
|
|
||||||
|
// Functions:
|
||||||
|
|
||||||
|
void UsbCommand_ApplyConfig(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "keymap.h"
|
#include "keymap.h"
|
||||||
#include "microseconds/microseconds_pit.c"
|
#include "microseconds/microseconds_pit.c"
|
||||||
#include "i2c_watchdog.h"
|
#include "i2c_watchdog.h"
|
||||||
|
#include "usb_commands/usb_command_apply_config.h"
|
||||||
|
|
||||||
uint8_t UsbDebugInfo[USB_GENERIC_HID_OUT_BUFFER_LENGTH];
|
uint8_t UsbDebugInfo[USB_GENERIC_HID_OUT_BUFFER_LENGTH];
|
||||||
|
|
||||||
@@ -93,57 +94,6 @@ void readMergeSensor(void)
|
|||||||
SetResponseByte(MERGE_SENSOR_IS_MERGED);
|
SetResponseByte(MERGE_SENSOR_IS_MERGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyConfig(void)
|
|
||||||
{
|
|
||||||
// Validate the staging configuration.
|
|
||||||
|
|
||||||
ParserRunDry = true;
|
|
||||||
StagingUserConfigBuffer.offset = 0;
|
|
||||||
GenericHidOutBuffer[0] = ParseConfig(&StagingUserConfigBuffer);
|
|
||||||
*(uint16_t*)(GenericHidOutBuffer+1) = StagingUserConfigBuffer.offset;
|
|
||||||
GenericHidOutBuffer[3] = 0;
|
|
||||||
|
|
||||||
if (GenericHidOutBuffer[0] != UsbResponse_Success) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make the staging configuration the current one.
|
|
||||||
|
|
||||||
char oldKeymapAbbreviation[KEYMAP_ABBREVIATION_LENGTH];
|
|
||||||
uint8_t oldKeymapAbbreviationLen;
|
|
||||||
memcpy(oldKeymapAbbreviation, AllKeymaps[CurrentKeymapIndex].abbreviation, KEYMAP_ABBREVIATION_LENGTH);
|
|
||||||
oldKeymapAbbreviationLen = AllKeymaps[CurrentKeymapIndex].abbreviationLen;
|
|
||||||
|
|
||||||
uint8_t *temp = ValidatedUserConfigBuffer.buffer;
|
|
||||||
ValidatedUserConfigBuffer.buffer = StagingUserConfigBuffer.buffer;
|
|
||||||
StagingUserConfigBuffer.buffer = temp;
|
|
||||||
|
|
||||||
ParserRunDry = false;
|
|
||||||
ValidatedUserConfigBuffer.offset = 0;
|
|
||||||
GenericHidOutBuffer[0] = ParseConfig(&ValidatedUserConfigBuffer);
|
|
||||||
*(uint16_t*)(GenericHidOutBuffer+1) = ValidatedUserConfigBuffer.offset;
|
|
||||||
GenericHidOutBuffer[3] = 1;
|
|
||||||
|
|
||||||
if (GenericHidOutBuffer[0] != UsbResponse_Success) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Switch to the keymap of the updated configuration of the same name or the default keymap.
|
|
||||||
|
|
||||||
for (uint8_t keymapId = 0; keymapId < AllKeymapsCount; keymapId++) {
|
|
||||||
if (AllKeymaps[keymapId].abbreviationLen != oldKeymapAbbreviationLen) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (memcmp(oldKeymapAbbreviation, AllKeymaps[keymapId].abbreviation, oldKeymapAbbreviationLen)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
SwitchKeymap(keymapId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SwitchKeymap(DefaultKeymapIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setLedPwm(void)
|
void setLedPwm(void)
|
||||||
{
|
{
|
||||||
uint8_t brightnessPercent = GenericHidInBuffer[1];
|
uint8_t brightnessPercent = GenericHidInBuffer[1];
|
||||||
@@ -285,8 +235,8 @@ void UsbProtocolHandler(void)
|
|||||||
case UsbCommand_WriteUserConfiguration:
|
case UsbCommand_WriteUserConfiguration:
|
||||||
writeConfiguration(false);
|
writeConfiguration(false);
|
||||||
break;
|
break;
|
||||||
case UsbCommand_ApplyConfig:
|
case UsbCommandId_ApplyConfig:
|
||||||
ApplyConfig();
|
UsbCommand_ApplyConfig();
|
||||||
break;
|
break;
|
||||||
case UsbCommand_SetLedPwm:
|
case UsbCommand_SetLedPwm:
|
||||||
setLedPwm();
|
setLedPwm();
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
UsbCommand_WriteLedDriver = 3,
|
UsbCommand_WriteLedDriver = 3,
|
||||||
UsbCommand_ReadMergeSensor = 7,
|
UsbCommand_ReadMergeSensor = 7,
|
||||||
UsbCommand_WriteUserConfiguration = 8,
|
UsbCommand_WriteUserConfiguration = 8,
|
||||||
UsbCommand_ApplyConfig = 9,
|
UsbCommandId_ApplyConfig = 9,
|
||||||
UsbCommand_SetLedPwm = 10,
|
UsbCommand_SetLedPwm = 10,
|
||||||
UsbCommand_GetAdcValue = 11,
|
UsbCommand_GetAdcValue = 11,
|
||||||
UsbCommand_LaunchEepromTransfer = 12,
|
UsbCommand_LaunchEepromTransfer = 12,
|
||||||
|
|||||||
Reference in New Issue
Block a user