Read the hardware configuration area and the user configuration area of the EEPROM into the RAM and try to apply it.
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
bool IsEepromBusy;
|
bool IsEepromBusy;
|
||||||
eeprom_transfer_t CurrentEepromTransfer;
|
eeprom_transfer_t CurrentEepromTransfer;
|
||||||
status_t LastEepromTransferStatus;
|
status_t LastEepromTransferStatus;
|
||||||
|
void (*SuccessCallback)();
|
||||||
|
|
||||||
static i2c_master_handle_t i2cHandle;
|
static i2c_master_handle_t i2cHandle;
|
||||||
static i2c_master_transfer_t i2cTransfer;
|
static i2c_master_transfer_t i2cTransfer;
|
||||||
@@ -59,6 +60,9 @@ static void i2cCallback(I2C_Type *base, i2c_master_handle_t *handle, status_t st
|
|||||||
case EepromTransfer_ReadUserConfiguration:
|
case EepromTransfer_ReadUserConfiguration:
|
||||||
if (isReadSent) {
|
if (isReadSent) {
|
||||||
IsEepromBusy = false;
|
IsEepromBusy = false;
|
||||||
|
if (SuccessCallback) {
|
||||||
|
SuccessCallback();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LastEepromTransferStatus = i2cAsyncRead(
|
LastEepromTransferStatus = i2cAsyncRead(
|
||||||
@@ -75,6 +79,9 @@ static void i2cCallback(I2C_Type *base, i2c_master_handle_t *handle, status_t st
|
|||||||
}
|
}
|
||||||
IsEepromBusy = sourceOffset < sourceLength;
|
IsEepromBusy = sourceOffset < sourceLength;
|
||||||
if (!IsEepromBusy) {
|
if (!IsEepromBusy) {
|
||||||
|
if (SuccessCallback) {
|
||||||
|
SuccessCallback();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LastEepromTransferStatus = writePage();
|
LastEepromTransferStatus = writePage();
|
||||||
@@ -90,13 +97,14 @@ void EEPROM_Init(void)
|
|||||||
I2C_MasterTransferCreateHandle(I2C_EEPROM_BUS_BASEADDR, &i2cHandle, i2cCallback, NULL);
|
I2C_MasterTransferCreateHandle(I2C_EEPROM_BUS_BASEADDR, &i2cHandle, i2cCallback, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t EEPROM_LaunchTransfer(eeprom_transfer_t transferType)
|
status_t EEPROM_LaunchTransfer(eeprom_transfer_t transferType, void (*successCallback))
|
||||||
{
|
{
|
||||||
if (IsEepromBusy) {
|
if (IsEepromBusy) {
|
||||||
return kStatus_I2C_Busy;
|
return kStatus_I2C_Busy;
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentEepromTransfer = transferType;
|
CurrentEepromTransfer = transferType;
|
||||||
|
SuccessCallback = successCallback;
|
||||||
bool isHardwareConfig = CurrentEepromTransfer == EepromTransfer_ReadHardwareConfiguration ||
|
bool isHardwareConfig = CurrentEepromTransfer == EepromTransfer_ReadHardwareConfiguration ||
|
||||||
CurrentEepromTransfer == EepromTransfer_WriteHardwareConfiguration;
|
CurrentEepromTransfer == EepromTransfer_WriteHardwareConfiguration;
|
||||||
eepromStartAddress = isHardwareConfig ? 0 : HARDWARE_CONFIG_SIZE;
|
eepromStartAddress = isHardwareConfig ? 0 : HARDWARE_CONFIG_SIZE;
|
||||||
|
|||||||
@@ -26,6 +26,6 @@
|
|||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
extern void EEPROM_Init(void);
|
extern void EEPROM_Init(void);
|
||||||
extern status_t EEPROM_LaunchTransfer(eeprom_transfer_t transferType);
|
extern status_t EEPROM_LaunchTransfer(eeprom_transfer_t transferType, void (*successCallback));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "bootloader_config.h"
|
#include "bootloader_config.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "wormhole.h"
|
#include "wormhole.h"
|
||||||
|
#include "eeprom.h"
|
||||||
|
|
||||||
key_matrix_t KeyMatrix = {
|
key_matrix_t KeyMatrix = {
|
||||||
.colNum = KEYBOARD_MATRIX_COLS_NUM,
|
.colNum = KEYBOARD_MATRIX_COLS_NUM,
|
||||||
@@ -59,9 +60,23 @@ void UpdateUsbReports()
|
|||||||
IsUsbBasicKeyboardReportSent = false;
|
IsUsbBasicKeyboardReportSent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsEepromInitialized = false;
|
||||||
|
bool IsConfigInitialized = false;
|
||||||
|
|
||||||
|
void userConfigurationReadFinished()
|
||||||
|
{
|
||||||
|
IsEepromInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void hardwareConfigurationReadFinished()
|
||||||
|
{
|
||||||
|
EEPROM_LaunchTransfer(EepromTransfer_ReadUserConfiguration, userConfigurationReadFinished);
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
InitClock();
|
InitClock();
|
||||||
InitPeripherals();
|
InitPeripherals();
|
||||||
|
EEPROM_LaunchTransfer(EepromTransfer_ReadHardwareConfiguration, hardwareConfigurationReadFinished);
|
||||||
|
|
||||||
#ifdef FORCE_BUSPAL
|
#ifdef FORCE_BUSPAL
|
||||||
Wormhole.magicNumber = WORMHOLE_MAGIC_NUMBER;
|
Wormhole.magicNumber = WORMHOLE_MAGIC_NUMBER;
|
||||||
@@ -79,6 +94,10 @@ void main() {
|
|||||||
InitUsb();
|
InitUsb();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
if (!IsConfigInitialized && IsEepromInitialized) {
|
||||||
|
ApplyConfig();
|
||||||
|
IsConfigInitialized = true;
|
||||||
|
}
|
||||||
UpdateUsbReports();
|
UpdateUsbReports();
|
||||||
asm("wfi");
|
asm("wfi");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void *
|
|||||||
case kUSB_DeviceHidEventSendResponse:
|
case kUSB_DeviceHidEventSendResponse:
|
||||||
break;
|
break;
|
||||||
case kUSB_DeviceHidEventRecvResponse:
|
case kUSB_DeviceHidEventRecvResponse:
|
||||||
usbProtocolHandler();
|
UsbProtocolHandler();
|
||||||
|
|
||||||
USB_DeviceHidSend(UsbCompositeDevice.genericHidHandle,
|
USB_DeviceHidSend(UsbCompositeDevice.genericHidHandle,
|
||||||
USB_GENERIC_HID_ENDPOINT_IN_INDEX,
|
USB_GENERIC_HID_ENDPOINT_IN_INDEX,
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ void readMergeSensor(void)
|
|||||||
SetResponseByte(MERGE_SENSOR_IS_MERGED);
|
SetResponseByte(MERGE_SENSOR_IS_MERGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void applyConfig(void)
|
void ApplyConfig(void)
|
||||||
{
|
{
|
||||||
uint8_t *temp;
|
uint8_t *temp;
|
||||||
char oldKeymapAbbreviation[3];
|
char oldKeymapAbbreviation[3];
|
||||||
@@ -149,7 +149,7 @@ void getAdcValue(void)
|
|||||||
void launchEepromTransfer(void)
|
void launchEepromTransfer(void)
|
||||||
{
|
{
|
||||||
eeprom_transfer_t transferType = GenericHidInBuffer[1];
|
eeprom_transfer_t transferType = GenericHidInBuffer[1];
|
||||||
EEPROM_LaunchTransfer(transferType);
|
EEPROM_LaunchTransfer(transferType, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void readConfiguration(bool isHardware)
|
void readConfiguration(bool isHardware)
|
||||||
@@ -162,7 +162,7 @@ void readConfiguration(bool isHardware)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *buffer = isHardware ? HardwareConfigBuffer.buffer : UserConfigBuffer.buffer;
|
uint8_t *buffer = isHardware ? HardwareConfigBuffer.buffer : StagingUserConfigBuffer.buffer;
|
||||||
uint16_t bufferLength = isHardware ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE;
|
uint16_t bufferLength = isHardware ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE;
|
||||||
|
|
||||||
if (offset + length > bufferLength) {
|
if (offset + length > bufferLength) {
|
||||||
@@ -237,7 +237,7 @@ void getDebugInfo(void)
|
|||||||
|
|
||||||
// The main protocol handler function
|
// The main protocol handler function
|
||||||
|
|
||||||
void usbProtocolHandler(void)
|
void UsbProtocolHandler(void)
|
||||||
{
|
{
|
||||||
bzero(GenericHidOutBuffer, USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
bzero(GenericHidOutBuffer, USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
||||||
uint8_t command = GenericHidInBuffer[0];
|
uint8_t command = GenericHidInBuffer[0];
|
||||||
@@ -260,7 +260,7 @@ void usbProtocolHandler(void)
|
|||||||
writeConfiguration(false);
|
writeConfiguration(false);
|
||||||
break;
|
break;
|
||||||
case UsbCommand_ApplyConfig:
|
case UsbCommand_ApplyConfig:
|
||||||
applyConfig();
|
ApplyConfig();
|
||||||
break;
|
break;
|
||||||
case UsbCommand_SetLedPwm:
|
case UsbCommand_SetLedPwm:
|
||||||
setLedPwm();
|
setLedPwm();
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
extern void usbProtocolHandler();
|
extern void UsbProtocolHandler();
|
||||||
|
extern void ApplyConfig(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user