eeprom handling works now
This commit is contained in:
parent
cbb8f8d188
commit
404b3f7f7a
@ -28,26 +28,61 @@ static void __EEPROM_CS(GPIO_PinState v) {
|
|||||||
HAL_GPIO_WritePin(EEPROM_CS_GPIO_Port, EEPROM_CS_Pin, v);
|
HAL_GPIO_WritePin(EEPROM_CS_GPIO_Port, EEPROM_CS_Pin, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __HAL_SPI_Transmit_One_ByValue(SPI_HandleTypeDef *hspi, uint8_t c) {
|
|
||||||
HAL_SPI_Transmit(hspi, &c, 1, HAL_MAX_DELAY);
|
uint8_t eepromReadStatus() {
|
||||||
|
struct {
|
||||||
|
uint8_t rdsr;
|
||||||
|
uint8_t data;
|
||||||
|
} txMsg = {
|
||||||
|
.rdsr = EEPROM_RDSR
|
||||||
|
}, rxMsg;
|
||||||
|
|
||||||
|
__EEPROM_CS(LOW);
|
||||||
|
HAL_SPI_TransmitReceive(&hspi1, &txMsg, &rxMsg, 2, HAL_MAX_DELAY);
|
||||||
|
__EEPROM_CS(HIGH);
|
||||||
|
|
||||||
|
return rxMsg.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void eepromWren() {
|
||||||
|
struct {
|
||||||
|
uint8_t wren;
|
||||||
|
} txMsg = {
|
||||||
|
.wren = EEPROM_WREN
|
||||||
|
};
|
||||||
|
|
||||||
|
__EEPROM_CS(LOW);
|
||||||
|
HAL_SPI_Transmit(&hspi1, &txMsg, 1, HAL_MAX_DELAY);
|
||||||
|
__EEPROM_CS(HIGH);
|
||||||
|
}
|
||||||
|
void eepromWrdi() {
|
||||||
|
struct {
|
||||||
|
uint8_t wrdi;
|
||||||
|
} txMsg = {
|
||||||
|
.wrdi = EEPROM_WRDI
|
||||||
|
};
|
||||||
|
|
||||||
|
__EEPROM_CS(LOW);
|
||||||
|
HAL_SPI_Transmit(&hspi1, &txMsg, 1, HAL_MAX_DELAY);
|
||||||
|
__EEPROM_CS(HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len) {
|
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len) {
|
||||||
struct {
|
struct {
|
||||||
uint8_t wren;
|
|
||||||
uint8_t write;
|
uint8_t write;
|
||||||
uint16_t addr;
|
uint16_t addr;
|
||||||
uint8_t data[32];
|
uint8_t data[32];
|
||||||
} msg = {
|
} msg = {
|
||||||
.wren = EEPROM_WREN,
|
|
||||||
.write = EEPROM_WRITE,
|
.write = EEPROM_WRITE,
|
||||||
.addr = addr
|
.addr = addr
|
||||||
};
|
};
|
||||||
memcpy(msg.data, buf, len);
|
memcpy(msg.data, buf, len);
|
||||||
|
|
||||||
|
eepromWren();
|
||||||
|
|
||||||
__EEPROM_CS(LOW);
|
__EEPROM_CS(LOW);
|
||||||
HAL_SPI_Transmit(&hspi1, &msg, ((uint16_t)(len+4)), HAL_MAX_DELAY);
|
HAL_SPI_Transmit(&hspi1, &msg, ((uint16_t)(len+3)), HAL_MAX_DELAY);
|
||||||
__EEPROM_CS(HIGH);
|
__EEPROM_CS(HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,9 +101,5 @@ void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len) {
|
|||||||
HAL_SPI_TransmitReceive(&hspi1, &txMsg, &rxMsg, ((uint16_t)(len+3)), HAL_MAX_DELAY);
|
HAL_SPI_TransmitReceive(&hspi1, &txMsg, &rxMsg, ((uint16_t)(len+3)), HAL_MAX_DELAY);
|
||||||
__EEPROM_CS(HIGH);
|
__EEPROM_CS(HIGH);
|
||||||
|
|
||||||
// __EEPROM_CS(LOW);
|
memcpy(buf, rxMsg.data, len);
|
||||||
// __HAL_SPI_Transmit_One_ByValue(&hspi1, EEPROM_READ);
|
|
||||||
// HAL_SPI_Transmit(&hspi1, &addr, 2, HAL_MAX_DELAY);
|
|
||||||
// HAL_SPI_Receive(&hspi1, buf, ((uint16_t)len), HAL_MAX_DELAY);
|
|
||||||
// __EEPROM_CS(HIGH);
|
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len);
|
void eepromWrite(uint16_t addr, uint8_t *buf, uint8_t len);
|
||||||
void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len);
|
void eepromRead(uint16_t addr, uint8_t *buf, uint8_t len);
|
||||||
|
uint8_t eepromReadStatus();
|
||||||
|
void eepromWren();
|
||||||
|
void eepromWrdi();
|
||||||
|
|
||||||
#endif /* EEPROM_H_ */
|
#endif /* EEPROM_H_ */
|
||||||
|
49
my_src/hmi.c
49
my_src/hmi.c
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const uint32_t STORAGE_MAGIC = 0xaffe0001;
|
const uint32_t STORAGE_MAGIC = 0xaffe0002;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -37,21 +37,6 @@ typedef struct {
|
|||||||
tStorage storage;
|
tStorage storage;
|
||||||
|
|
||||||
void updateDisplay(void *handle) {
|
void updateDisplay(void *handle) {
|
||||||
static uint8_t eetoggle = 0;
|
|
||||||
|
|
||||||
if (eetoggle == 0) {
|
|
||||||
eetoggle = 1;
|
|
||||||
eepromRead(STORAGE_ADDRESS, &storage, sizeof(storage));
|
|
||||||
} else {
|
|
||||||
eetoggle = 0;
|
|
||||||
storage.magic = STORAGE_MAGIC;
|
|
||||||
storage.savedTemperature = 1;
|
|
||||||
storage.savedTime = 2;
|
|
||||||
eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tDisplay *lDisplay = (tDisplay*) handle;
|
tDisplay *lDisplay = (tDisplay*) handle;
|
||||||
lDisplay->toggle ^= 0x01;
|
lDisplay->toggle ^= 0x01;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
@ -73,14 +58,14 @@ void updateDisplay(void *handle) {
|
|||||||
}
|
}
|
||||||
LED_P8x16Str(0, 4, buf);
|
LED_P8x16Str(0, 4, buf);
|
||||||
|
|
||||||
// sprintf(buf, " %5ds", lDisplay->overrunTime);
|
sprintf(buf, " %5ds", lDisplay->overrunTime);
|
||||||
static uint32_t h = 0;
|
// static uint32_t h = 0;
|
||||||
static uint32_t c = 0;
|
// static uint32_t c = 0;
|
||||||
uint32_t i = HAL_GetTick();
|
// uint32_t i = HAL_GetTick();
|
||||||
sprintf(buf, "%d %d %d", c, i, i-h);
|
// sprintf(buf, "%d %d %d", c, i, i-h);
|
||||||
h = i;
|
// h = i;
|
||||||
c++;
|
// c++;
|
||||||
LED_P8x16Str(0, 6, buf);
|
// LED_P8x16Str(0, 6, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -145,16 +130,16 @@ void displayIncValue() {
|
|||||||
reEnableSetModeTimer();
|
reEnableSetModeTimer();
|
||||||
if (display.targetTemperature < 100) {
|
if (display.targetTemperature < 100) {
|
||||||
display.targetTemperature++;
|
display.targetTemperature++;
|
||||||
// storage.savedTemperature = display.targetTemperature;
|
storage.savedTemperature = display.targetTemperature;
|
||||||
// eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (display.setModeTime == 1) {
|
if (display.setModeTime == 1) {
|
||||||
reEnableSetModeTimer();
|
reEnableSetModeTimer();
|
||||||
if (display.targetTime < 999) {
|
if (display.targetTime < 999) {
|
||||||
display.targetTime += 10;
|
display.targetTime += 10;
|
||||||
// storage.savedTime = display.targetTime;
|
storage.savedTime = display.targetTime;
|
||||||
// eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,16 +149,16 @@ void displayDecValue() {
|
|||||||
reEnableSetModeTimer();
|
reEnableSetModeTimer();
|
||||||
if (display.targetTemperature > 0) {
|
if (display.targetTemperature > 0) {
|
||||||
display.targetTemperature--;
|
display.targetTemperature--;
|
||||||
// storage.savedTemperature = display.targetTemperature;
|
storage.savedTemperature = display.targetTemperature;
|
||||||
// eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (display.setModeTime == 1) {
|
if (display.setModeTime == 1) {
|
||||||
reEnableSetModeTimer();
|
reEnableSetModeTimer();
|
||||||
if (display.targetTime >= 10) {
|
if (display.targetTime >= 10) {
|
||||||
display.targetTime -= 10;
|
display.targetTime -= 10;
|
||||||
// storage.savedTime = display.targetTime;
|
storage.savedTime = display.targetTime;
|
||||||
// eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
eepromWrite(STORAGE_ADDRESS, &storage, sizeof(storage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user