Simplify code by utilizing type casing on uint8_t arrays.
This commit is contained in:
@@ -100,8 +100,7 @@ void ApplyConfig(void)
|
|||||||
ParserRunDry = true;
|
ParserRunDry = true;
|
||||||
StagingUserConfigBuffer.offset = 0;
|
StagingUserConfigBuffer.offset = 0;
|
||||||
GenericHidOutBuffer[0] = ParseConfig(&StagingUserConfigBuffer);
|
GenericHidOutBuffer[0] = ParseConfig(&StagingUserConfigBuffer);
|
||||||
GenericHidOutBuffer[1] = StagingUserConfigBuffer.offset;
|
*(uint16_t*)(GenericHidOutBuffer+1) = StagingUserConfigBuffer.offset;
|
||||||
GenericHidOutBuffer[2] = StagingUserConfigBuffer.offset >> 8;
|
|
||||||
GenericHidOutBuffer[3] = 0;
|
GenericHidOutBuffer[3] = 0;
|
||||||
|
|
||||||
if (GenericHidOutBuffer[0] != UsbResponse_Success) {
|
if (GenericHidOutBuffer[0] != UsbResponse_Success) {
|
||||||
@@ -115,16 +114,14 @@ void ApplyConfig(void)
|
|||||||
memcpy(oldKeymapAbbreviation, AllKeymaps[CurrentKeymapIndex].abbreviation, KEYMAP_ABBREVIATION_LENGTH);
|
memcpy(oldKeymapAbbreviation, AllKeymaps[CurrentKeymapIndex].abbreviation, KEYMAP_ABBREVIATION_LENGTH);
|
||||||
oldKeymapAbbreviationLen = AllKeymaps[CurrentKeymapIndex].abbreviationLen;
|
oldKeymapAbbreviationLen = AllKeymaps[CurrentKeymapIndex].abbreviationLen;
|
||||||
|
|
||||||
uint8_t *temp;
|
uint8_t *temp = ValidatedUserConfigBuffer.buffer;
|
||||||
temp = ValidatedUserConfigBuffer.buffer;
|
|
||||||
ValidatedUserConfigBuffer.buffer = StagingUserConfigBuffer.buffer;
|
ValidatedUserConfigBuffer.buffer = StagingUserConfigBuffer.buffer;
|
||||||
StagingUserConfigBuffer.buffer = temp;
|
StagingUserConfigBuffer.buffer = temp;
|
||||||
|
|
||||||
ParserRunDry = false;
|
ParserRunDry = false;
|
||||||
ValidatedUserConfigBuffer.offset = 0;
|
ValidatedUserConfigBuffer.offset = 0;
|
||||||
GenericHidOutBuffer[0] = ParseConfig(&ValidatedUserConfigBuffer);
|
GenericHidOutBuffer[0] = ParseConfig(&ValidatedUserConfigBuffer);
|
||||||
GenericHidOutBuffer[1] = ValidatedUserConfigBuffer.offset;
|
*(uint16_t*)(GenericHidOutBuffer+1) = ValidatedUserConfigBuffer.offset;
|
||||||
GenericHidOutBuffer[2] = ValidatedUserConfigBuffer.offset >> 8;
|
|
||||||
GenericHidOutBuffer[3] = 1;
|
GenericHidOutBuffer[3] = 1;
|
||||||
|
|
||||||
if (GenericHidOutBuffer[0] != UsbResponse_Success) {
|
if (GenericHidOutBuffer[0] != UsbResponse_Success) {
|
||||||
@@ -133,14 +130,14 @@ void ApplyConfig(void)
|
|||||||
|
|
||||||
// Switch to the keymap of the updated configuration of the same name or the default keymap.
|
// Switch to the keymap of the updated configuration of the same name or the default keymap.
|
||||||
|
|
||||||
for (uint8_t i = 0; i < AllKeymapsCount; i++) {
|
for (uint8_t keymapId = 0; keymapId < AllKeymapsCount; keymapId++) {
|
||||||
if (AllKeymaps[i].abbreviationLen != oldKeymapAbbreviationLen) {
|
if (AllKeymaps[keymapId].abbreviationLen != oldKeymapAbbreviationLen) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (memcmp(oldKeymapAbbreviation, AllKeymaps[i].abbreviation, oldKeymapAbbreviationLen)) {
|
if (memcmp(oldKeymapAbbreviation, AllKeymaps[keymapId].abbreviation, oldKeymapAbbreviationLen)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SwitchKeymap(i);
|
SwitchKeymap(keymapId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,11 +153,7 @@ void setLedPwm(void)
|
|||||||
|
|
||||||
void getAdcValue(void)
|
void getAdcValue(void)
|
||||||
{
|
{
|
||||||
uint32_t adcValue = ADC_Measure();
|
*(uint32_t*)(GenericHidOutBuffer+0) = ADC_Measure();
|
||||||
GenericHidOutBuffer[0] = adcValue >> 0;
|
|
||||||
GenericHidOutBuffer[1] = adcValue >> 8;
|
|
||||||
GenericHidOutBuffer[2] = adcValue >> 16;
|
|
||||||
GenericHidOutBuffer[3] = adcValue >> 24;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void legacyLaunchEepromTransfer(void)
|
void legacyLaunchEepromTransfer(void)
|
||||||
@@ -185,7 +178,7 @@ void legacyLaunchEepromTransfer(void)
|
|||||||
void readConfiguration(bool isHardware)
|
void readConfiguration(bool isHardware)
|
||||||
{
|
{
|
||||||
uint8_t length = GenericHidInBuffer[1];
|
uint8_t length = GenericHidInBuffer[1];
|
||||||
uint16_t offset = *((uint16_t*)(GenericHidInBuffer+2));
|
uint16_t offset = *(uint16_t*)(GenericHidInBuffer+2);
|
||||||
|
|
||||||
if (length > USB_GENERIC_HID_OUT_BUFFER_LENGTH-1) {
|
if (length > USB_GENERIC_HID_OUT_BUFFER_LENGTH-1) {
|
||||||
setError(ConfigTransferResponse_LengthTooLarge);
|
setError(ConfigTransferResponse_LengthTooLarge);
|
||||||
@@ -235,42 +228,19 @@ void getKeyboardState(void)
|
|||||||
|
|
||||||
void getDebugInfo(void)
|
void getDebugInfo(void)
|
||||||
{
|
{
|
||||||
UsbDebugInfo[0] = I2C_Watchdog >> 0;
|
*(uint32_t*)(UsbDebugInfo+0) = I2C_Watchdog;
|
||||||
UsbDebugInfo[1] = I2C_Watchdog >> 8;
|
*(uint32_t*)(UsbDebugInfo+4) = I2cSchedulerCounter;
|
||||||
UsbDebugInfo[2] = I2C_Watchdog >> 16;
|
*(uint32_t*)(UsbDebugInfo+8) = I2cWatchdog_OuterCounter;
|
||||||
UsbDebugInfo[3] = I2C_Watchdog >> 24;
|
*(uint32_t*)(UsbDebugInfo+12) = I2cWatchdog_InnerCounter;
|
||||||
|
|
||||||
UsbDebugInfo[4] = I2cSchedulerCounter >> 0;
|
|
||||||
UsbDebugInfo[5] = I2cSchedulerCounter >> 8;
|
|
||||||
UsbDebugInfo[6] = I2cSchedulerCounter >> 16;
|
|
||||||
UsbDebugInfo[7] = I2cSchedulerCounter >> 24;
|
|
||||||
|
|
||||||
UsbDebugInfo[8] = I2cWatchdog_OuterCounter >> 0;
|
|
||||||
UsbDebugInfo[9] = I2cWatchdog_OuterCounter >> 8;
|
|
||||||
UsbDebugInfo[10] = I2cWatchdog_OuterCounter >> 16;
|
|
||||||
UsbDebugInfo[11] = I2cWatchdog_OuterCounter >> 24;
|
|
||||||
|
|
||||||
UsbDebugInfo[12] = I2cWatchdog_InnerCounter >> 0;
|
|
||||||
UsbDebugInfo[13] = I2cWatchdog_InnerCounter >> 8;
|
|
||||||
UsbDebugInfo[14] = I2cWatchdog_InnerCounter >> 16;
|
|
||||||
UsbDebugInfo[15] = I2cWatchdog_InnerCounter >> 24;
|
|
||||||
|
|
||||||
memcpy(GenericHidOutBuffer, UsbDebugInfo, USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
memcpy(GenericHidOutBuffer, UsbDebugInfo, USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
||||||
|
|
||||||
/*
|
/* uint64_t ticks = microseconds_get_ticks();
|
||||||
uint64_t ticks = microseconds_get_ticks();
|
|
||||||
uint32_t microseconds = microseconds_convert_to_microseconds(ticks);
|
uint32_t microseconds = microseconds_convert_to_microseconds(ticks);
|
||||||
uint32_t milliseconds = microseconds/1000;
|
uint32_t milliseconds = microseconds/1000;
|
||||||
|
*(uint32_t*)(GenericHidOutBuffer+1) = ticks;
|
||||||
GenericHidOutBuffer[1] = (ticks >> 0) & 0xff;;
|
*/
|
||||||
GenericHidOutBuffer[2] = (ticks >> 8) & 0xff;
|
}
|
||||||
GenericHidOutBuffer[3] = (ticks >> 16) & 0xff;
|
|
||||||
GenericHidOutBuffer[4] = (ticks >> 24) & 0xff;
|
|
||||||
GenericHidOutBuffer[5] = (ticks >> 32) & 0xff;;
|
|
||||||
GenericHidOutBuffer[6] = (ticks >> 40) & 0xff;
|
|
||||||
GenericHidOutBuffer[7] = (ticks >> 48) & 0xff;
|
|
||||||
GenericHidOutBuffer[8] = (ticks >> 56) & 0xff;
|
|
||||||
*/}
|
|
||||||
|
|
||||||
void jumpToSlaveBootloader(void)
|
void jumpToSlaveBootloader(void)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user