fix config saving corrupted

was not waiting for eeprom to be ready before trying to write again, causing failure. was also a bug in the write routine.
This commit is contained in:
true 2024-10-26 20:10:31 -07:00
parent 25dc735560
commit 390528071c
4 changed files with 26 additions and 12 deletions

View File

@ -10,12 +10,12 @@
#include "comm/i2c.h"
uint8_t e16_read_byte(uint16_t addr)
uint8_t eep16_read_byte(uint16_t addr)
{
return 0;
}
void e16_read(uint16_t addr, uint8_t *dat, uint32_t len)
void eep16_read(uint16_t addr, uint8_t *dat, uint32_t len)
{
if (len > EEPROM_SIZE) return;
@ -30,7 +30,7 @@ void e16_read(uint16_t addr, uint8_t *dat, uint32_t len)
i2c_stop();
}
void e16_write(uint16_t addr, uint8_t *dat, uint16_t len)
void eep16_write(uint16_t addr, uint8_t *dat, uint16_t len)
{
uint8_t nack;
@ -45,7 +45,7 @@ void e16_write(uint16_t addr, uint8_t *dat, uint16_t len)
i2c_wr(addr >> 8);
i2c_wr(addr & 0xff);
while (len--) {
while (len--) {
nack = i2c_wr(*dat++);
if (nack) break;
}
@ -53,4 +53,16 @@ void e16_write(uint16_t addr, uint8_t *dat, uint16_t len)
i2c_stop();
}
uint8_t eep16_is_ready()
{
uint8_t ack;
i2c_start();
ack = i2c_wr(EEPROM_I2C_ADDR | 1);
i2c_stop();
if (ack) return 0;
return 1;
}

View File

@ -21,8 +21,9 @@
void e16_read(uint16_t addr, uint8_t *dat, uint32_t len);
void e16_write(uint16_t addr, uint8_t *dat, uint16_t len);
void eep16_read(uint16_t addr, uint8_t *dat, uint32_t len);
void eep16_write(uint16_t addr, uint8_t *dat, uint16_t len);
uint8_t eep16_is_ready();

View File

@ -102,7 +102,7 @@ void uconf_load()
for (i = 0; i < FLASH_RSVD_PAGES; i++) {
// find last page of valid config from flash
uconf_flash_offset = (FLASH_RSVD_PAGES - 1) - i;
e16_read(uconf_flash_offset * FLASH_UCONF_BYTES, (uint8_t *)&uconf, FLASH_UCONF_BYTES);
eep16_read(uconf_flash_offset * FLASH_UCONF_BYTES, (uint8_t *)&uconf, FLASH_UCONF_BYTES);
if (!uconf_validate()) {
// valid data
return;
@ -130,8 +130,8 @@ void uconf_write()
uconf.iter++;
uconf_flash_offset++;
if (uconf_flash_offset >= FLASH_RSVD_PAGES) {
// we need to erase flash and start writing at the beginning
// w25q_erase_sector(0x000000, 1);
// if you need to erase flash, do it here
// we have eeprom so we don't
uconf_flash_offset = 0;
}
@ -145,8 +145,9 @@ void uconf_write()
uaddr = (uint8_t *)&uconf;
while (fsize) {
e16_write(faddr, uaddr, (fsize > 128) ? 128 : fsize);
if (fsize < 128) break;
while (!eep16_is_ready());
eep16_write(faddr, uaddr, (fsize > 128) ? 128 : fsize);
if (fsize <= 128) break;
fsize -= 128;
faddr += 128;
uaddr += 128;

View File

@ -27,7 +27,7 @@
#define SYS_OLED_REVERSE_CHARS (1 << 2) // todo: figure out wtf this is
// user configuration stuff
#define UCONF_VER 0x03
#define UCONF_VER 0x04
#define UCONF_FLAGS_AUTOROTATE_ENA (1 << 0)
#define UCONF_FLAGS_AD_BANNER (1 << 1) // show conference banner text