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:
László Monda
2017-09-14 09:55:29 +02:00
parent 3c40b21ced
commit e6b5b3b3a5
6 changed files with 37 additions and 9 deletions

View File

@@ -7,6 +7,7 @@
bool IsEepromBusy;
eeprom_transfer_t CurrentEepromTransfer;
status_t LastEepromTransferStatus;
void (*SuccessCallback)();
static i2c_master_handle_t i2cHandle;
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:
if (isReadSent) {
IsEepromBusy = false;
if (SuccessCallback) {
SuccessCallback();
}
return;
}
LastEepromTransferStatus = i2cAsyncRead(
@@ -75,6 +79,9 @@ static void i2cCallback(I2C_Type *base, i2c_master_handle_t *handle, status_t st
}
IsEepromBusy = sourceOffset < sourceLength;
if (!IsEepromBusy) {
if (SuccessCallback) {
SuccessCallback();
}
return;
}
LastEepromTransferStatus = writePage();
@@ -90,13 +97,14 @@ void EEPROM_Init(void)
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) {
return kStatus_I2C_Busy;
}
CurrentEepromTransfer = transferType;
SuccessCallback = successCallback;
bool isHardwareConfig = CurrentEepromTransfer == EepromTransfer_ReadHardwareConfiguration ||
CurrentEepromTransfer == EepromTransfer_WriteHardwareConfiguration;
eepromStartAddress = isHardwareConfig ? 0 : HARDWARE_CONFIG_SIZE;

View File

@@ -26,6 +26,6 @@
// Functions:
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

View File

@@ -13,6 +13,7 @@
#include "bootloader_config.h"
#include "command.h"
#include "wormhole.h"
#include "eeprom.h"
key_matrix_t KeyMatrix = {
.colNum = KEYBOARD_MATRIX_COLS_NUM,
@@ -59,9 +60,23 @@ void UpdateUsbReports()
IsUsbBasicKeyboardReportSent = false;
}
bool IsEepromInitialized = false;
bool IsConfigInitialized = false;
void userConfigurationReadFinished()
{
IsEepromInitialized = true;
}
void hardwareConfigurationReadFinished()
{
EEPROM_LaunchTransfer(EepromTransfer_ReadUserConfiguration, userConfigurationReadFinished);
}
void main() {
InitClock();
InitPeripherals();
EEPROM_LaunchTransfer(EepromTransfer_ReadHardwareConfiguration, hardwareConfigurationReadFinished);
#ifdef FORCE_BUSPAL
Wormhole.magicNumber = WORMHOLE_MAGIC_NUMBER;
@@ -79,6 +94,10 @@ void main() {
InitUsb();
while (1) {
if (!IsConfigInitialized && IsEepromInitialized) {
ApplyConfig();
IsConfigInitialized = true;
}
UpdateUsbReports();
asm("wfi");
}

View File

@@ -60,7 +60,7 @@ usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void *
case kUSB_DeviceHidEventSendResponse:
break;
case kUSB_DeviceHidEventRecvResponse:
usbProtocolHandler();
UsbProtocolHandler();
USB_DeviceHidSend(UsbCompositeDevice.genericHidHandle,
USB_GENERIC_HID_ENDPOINT_IN_INDEX,

View File

@@ -88,7 +88,7 @@ void readMergeSensor(void)
SetResponseByte(MERGE_SENSOR_IS_MERGED);
}
void applyConfig(void)
void ApplyConfig(void)
{
uint8_t *temp;
char oldKeymapAbbreviation[3];
@@ -149,7 +149,7 @@ void getAdcValue(void)
void launchEepromTransfer(void)
{
eeprom_transfer_t transferType = GenericHidInBuffer[1];
EEPROM_LaunchTransfer(transferType);
EEPROM_LaunchTransfer(transferType, NULL);
}
void readConfiguration(bool isHardware)
@@ -162,7 +162,7 @@ void readConfiguration(bool isHardware)
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;
if (offset + length > bufferLength) {
@@ -237,7 +237,7 @@ void getDebugInfo(void)
// The main protocol handler function
void usbProtocolHandler(void)
void UsbProtocolHandler(void)
{
bzero(GenericHidOutBuffer, USB_GENERIC_HID_OUT_BUFFER_LENGTH);
uint8_t command = GenericHidInBuffer[0];
@@ -260,7 +260,7 @@ void usbProtocolHandler(void)
writeConfiguration(false);
break;
case UsbCommand_ApplyConfig:
applyConfig();
ApplyConfig();
break;
case UsbCommand_SetLedPwm:
setLedPwm();

View File

@@ -37,6 +37,7 @@
// Functions:
extern void usbProtocolHandler();
extern void UsbProtocolHandler();
extern void ApplyConfig(void);
#endif