diff --git a/firmware/config/engines/custom_engine.cpp b/firmware/config/engines/custom_engine.cpp index 9d59646ceb..61a8a5c0ae 100644 --- a/firmware/config/engines/custom_engine.cpp +++ b/firmware/config/engines/custom_engine.cpp @@ -302,8 +302,70 @@ void setIssue898() { } #endif /* EFI_UNIT_TEST */ +#if HW_FRANKENSO + +static const I2CConfig i2cfg = { + OPMODE_I2C, + 400000, + FAST_DUTY_CYCLE_2, +}; + +#define EE_PAGE_SIZE 32 + +// todo: page_size + 2 +// todo: CC_SECTION(".nocache") +static uint8_t write_buf[EE_PAGE_SIZE + 10]; + +#define EE_U2CD I2CD3 +#define EEPROM_WRITE_TIME_MS 10 /* time to write one page in ms. Consult datasheet! */ + +/** + * https://www.onsemi.com/pdf/datasheet/cat24c32-d.pdf + * CAT24C32 + */ +static const I2CEepromFileConfig i2cee = { + 0, + 0, + EE_PAGE_SIZE, + 4096, + TIME_MS2I(EEPROM_WRITE_TIME_MS), + &EE_U2CD, + 0x50, + write_buf +}; + +extern EepromDevice eepdev_24xx; +static I2CEepromFileStream ifile; + +/** + * set engine_type 61 + */ void setEepromTestConfiguration() { +// i2cStart(&EE_U2CD, &i2cfg); +// efiSetPadMode("I2C", GPIOA_8, PAL_MODE_ALTERNATE(4)); +// efiSetPadMode("I2C", GPIOC_9, PAL_MODE_ALTERNATE(4)); + + + addConsoleActionI("ee_read", + [](int value) { + EepromFileOpen((EepromFileStream *)&ifile, (EepromFileConfig *)&i2cee, &eepdev_24xx); + + ifile.vmt->setposition(&ifile, 0); +// chFileStreamSeek(&ifile, 0); + int v2; + streamRead(&ifile, (uint8_t *)&v2, 4); + efiPrintf("EE has %d", v2); + + v2 += 3; + ifile.vmt->setposition(&ifile, 0); + streamWrite(&ifile, (uint8_t *)&v2, 4); + + + }); + + } +#endif //HW_FRANKENSO // F407 discovery void setL9779TestConfiguration() {