Cleaned up debugging;

Removed newConfig function;
SPI flash clock much faster;
This commit is contained in:
hoogendijkta 2019-09-22 13:35:31 +02:00
parent 30acafe300
commit e9ff7293c5
5 changed files with 135 additions and 575 deletions

View File

@ -21,7 +21,6 @@ void initialiseAll()
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
startstorage();
table3D_setSize(&fuelTable, 16);
table3D_setSize(&fuelTable2, 16);
table3D_setSize(&ignitionTable, 16);
@ -33,6 +32,7 @@ void initialiseAll()
table3D_setSize(&trim2Table, 6);
table3D_setSize(&trim3Table, 6);
table3D_setSize(&trim4Table, 6);
loadConfig();
doUpdates(); //Check if any data items need updating (Occurs with firmware updates)
@ -1021,7 +1021,7 @@ void setPinMapping(byte boardID)
pinCoil3 = 30;
pinO2 = A22;
#elif defined(STM32F4)
//Pin definitions for experimental board Tjeerd
//Pin definitions for experimental board Tjeerd
//Black F407VE wiki.stm32duino.com/index.php?title=STM32F407
//******************************************
@ -1033,7 +1033,7 @@ void setPinMapping(byte boardID)
pinIAT = PA3; //ADC123
pinCLT = PA4; //ADC12
pinO2 = PA5; //ADC12
pinFan = PA6; //ADC12 LED_BUILTIN_1
// = PA6; //ADC12 LED_BUILTIN_1
pinFuelPump = PA7; //ADC12 LED_BUILTIN_2
pinIdle1 = PA8; //
// = PA9 //TXD1
@ -1097,7 +1097,7 @@ void setPinMapping(byte boardID)
pinCoil3 = PD7; //
pinCoil4 = PD8; //
pinCoil5 = PD9;//
// = PD10; //
pinFan = PD10; //
// = PD11; //
// = PD12; //
// = PD13; //
@ -1632,7 +1632,7 @@ void setPinMapping(byte boardID)
#if defined(STM32F4)
case 60:
//Pin definitions for experimental board Tjeerd
//Pin definitions for experimental board Tjeerd
//Black F407VE wiki.stm32duino.com/index.php?title=STM32F407
//******************************************
@ -1644,7 +1644,7 @@ void setPinMapping(byte boardID)
pinIAT = PA3; //ADC123
pinCLT = PA4; //ADC12
pinO2 = PA5; //ADC12
pinFan = PA6; //ADC12 LED_BUILTIN_1
// = PA6; //ADC12 LED_BUILTIN_1
pinFuelPump = PA7; //ADC12 LED_BUILTIN_2
pinIdle1 = PA8; //
// = PA9 //TXD1
@ -1708,7 +1708,7 @@ void setPinMapping(byte boardID)
pinCoil3 = PD7; //
pinCoil4 = PD8; //
pinCoil5 = PD9;//
// = PD10; //
pinFan = PD10; //
// = PD11; //
// = PD12; //
// = PD13; //
@ -1734,10 +1734,45 @@ void setPinMapping(byte boardID)
pinTrigger2 = PE13; //
// = PE14; //
// = PE15; //
break;
#elif defined(CORE_STM32)
//blue pill wiki.stm32duino.com/index.php?title=Blue_Pill
//Maple mini wiki.stm32duino.com/index.php?title=Maple_Mini
//pins PA12, PA11 are used for USB or CAN couldn't be used for GPIO
pinInjector1 = PB7; //Output pin injector 1 is on
pinInjector2 = PB6; //Output pin injector 2 is on
pinInjector3 = PB5; //Output pin injector 3 is on
pinInjector4 = PB4; //Output pin injector 4 is on
pinCoil1 = PB3; //Pin for coil 1
pinCoil2 = PA15; //Pin for coil 2
pinCoil3 = PA14; //Pin for coil 3
pinCoil4 = PA9; //Pin for coil 4
pinCoil5 = PA8; //Pin for coil 5
pinTPS = A0; //TPS input pin
pinMAP = A1; //MAP sensor pin
pinIAT = A2; //IAT sensor pin
pinCLT = A3; //CLS sensor pin
pinO2 = A4; //O2 Sensor pin
pinBat = A5; //Battery reference voltage pin
pinBaro = pinMAP;
pinIdle1 = PB2; //Single wire idle control
pinIdle2 = PA2; //2 wire idle control
pinBoost = PA1; //Boost control
pinVVT_1 = PA0; //Default VVT output
pinStepperDir = PC15; //Direction pin for DRV8825 driver
pinStepperStep = PC14; //Step pin for DRV8825 driver
pinStepperEnable = PC13; //Enable pin for DRV8825
pinDisplayReset = PB2; // OLED reset pin
pinFan = PB1; //Pin for the fan output
pinFuelPump = PB11; //Fuel pump output
pinTachOut = PB10; //Tacho output pin
//external interrupt enabled pins
pinFlex = PB8; // Flex sensor (Must be external interrupt enabled)
pinTrigger = PA10; //The CAS pin
pinTrigger2 = PA13; //The Cam Sensor pin
#endif
break;
default:
#if defined(STM32F4)
//Pin definitions for experimental board Tjeerd

View File

@ -1,17 +1,36 @@
/*
* This file implements a shim layer for the SPIMemory library (https://github.com/Marzogh/SPIMemory) to mimic a minimal
* subset of the standard Arduino EEPROM library
*/
//Working example on BLACK_STM32F407VET6 with official stm32 core from ST
/* Speeduino SPIAsEEPROM Library v.1.0.0
* Copyright (C) 2019 by Tjeerd Hoogendijk
* Created by Tjeerd Hoogendijk - 21/09/2019
*
* This file is part of the Speeduino project. This library is for
* Winbond SPI flash memory modules. In its current form it enables reading
* and writing individual bytes as if it where an AVR EEPROM. It uses some
* wear leveling (256x). When the begin() fuction is called for the first time
* it will "format" the flash chip.
* !!!!THIS DISTROYS ANY EXISTING DATA ON THE SPI FLASH!!!
*
* 1245184 bytes used of the SPI flash resulting in 4228 bytes of usable EEPROM
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License v3.0
* along with the Arduino SPIMemory Library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#if defined(CORE_STM32_OFFICIAL) && defined(SPIFLASH_AS_EEPROM)
#include "SPIAsEEPROM.h"
#include "SPI.h"
//winbondSPIFlash flash(SS1, &SPI); //Use this constructor if using an SPI bus other than the default SPI. Only works with chips with more than one hardware SPI bus
SPIAsEEPROM::SPIAsEEPROM()
{
pinMode(PB0, OUTPUT);
@ -24,13 +43,6 @@ SPIAsEEPROM::SPIAsEEPROM()
uint8_t SPIAsEEPROM::begin() {
uint8_t SpiFlashAvialable = 0;
SpiFlashAvialable = winbondSPIFlash.begin(_W25Q16,SPI,PB0);
// winbondSPIFlash.WE();
// winbondSPIFlash.eraseAll();
// while(winbondSPIFlash.busy());
//Debugging
// if(val){Serial.println("OK");}
uint8_t formatted = 0;
if(SpiFlashAvialable){
//check for magic numbers
@ -39,10 +51,11 @@ SPIAsEEPROM::SPIAsEEPROM()
for(uint16_t i=0; i< FLASHSIZEUSED/SECTORSIZE; i++ ){
winbondSPIFlash.read(sectorNumber*SECTORSIZE, buf, sizeof(buf) - 1);
if(buf[0] != MAGICNUMBER1 | buf[1] != MAGICNUMBER2 | buf[2] != MAGICNUMBER3 ){
//if one of the SECTORS has no magic numbers it is not formatted
formatted = 0;
}
}
//If not formatted format flash. This takes 10 seconds or more!
if(!formatted){
formatFlashForUse();
}
@ -55,31 +68,25 @@ SPIAsEEPROM::SPIAsEEPROM()
formatted = 0;
}
}
// Serial.print("formatted");
// Serial.println(formatted, DEC);
}
if(formatted & SpiFlashAvialable){return true;}else{return false;}
}
int8_t SPIAsEEPROM::write(uint16_t addressEEPROM, uint8_t writeValue){
int8_t SPIAsEEPROM::write(uint16_t addressEEPROM, uint8_t writeValue){
uint8_t ByteBuf[1];
//Check if adress is in the EEPROM space
if (addressEEPROM >= FLASHSIZEUSED/SECTORSIZE * (SECTORSIZE/FLASH_PAGESIZE - 2)){addressEEPROM = FLASHSIZEUSED/SECTORSIZE * (SECTORSIZE/FLASH_PAGESIZE - 2);}
//read the current value
uint8_t readValue = read(addressEEPROM);
// Serial.print("readValue");
// Serial.println(readValue, DEC);
// Serial.print("writeValue");
// Serial.println(writeValue, DEC);
//After reading the byte all global variables containing inforamtion about the address are set correctly.
//After reading the current byte all global variables containing inforamtion about the address are set correctly.
//only write if value is changed.
if (readValue != writeValue){
//Check if buffer is full
//Check if buffer is full and an erase must be performed.
if (nrOfOnes < 1){
//Serial.println("A sector gets erased and hoppfully writen back");
//now the buffer is full and an erase must be done
//First read all the values in this sector that will get distroyed when erasing
uint8_t tempBuf[14];
@ -91,15 +98,12 @@ int8_t SPIAsEEPROM::write(uint16_t addressEEPROM, uint8_t writeValue){
writeMagicNumber(sectorNumber);
//write all the values back
// Serial.println("Start re-writing values");
for(uint8_t i=0; i<14; i++){
write((sectorNumber*14) + i, tempBuf[i]);
}
// Serial.println("End re-writing values");
//also do not forget to write the new value!
write(addressEEPROM, writeValue);
// Serial.println("New value re-writing");
return 0;
}
@ -107,60 +111,21 @@ int8_t SPIAsEEPROM::write(uint16_t addressEEPROM, uint8_t writeValue){
//determine the adress of the byte in the infoblock where one bit must be reset when writing new values
uint8_t RelativeAdressInInfoBlock = (nrOfOnes - 1)/8;
// Serial.print("RelativeAdressInInfoBlock");
// Serial.println(RelativeAdressInInfoBlock, DEC);
//determine value of the infoblock byte after writing one more time.
uint8_t ValueInInfoBlock = 0xFF << (8 - (nrOfOnes - 1 - ((RelativeAdressInInfoBlock) * 8)));
// Serial.print("ValueInInfoBlock");
// Serial.println(ValueInInfoBlock, DEC);
uint8_t ByteBuf[1];
// Serial.print("dataFlashAddress");
// Serial.println(dataFlashAddress, DEC);
// Serial.print("sizeof(ByteBuf)");
// Serial.println(sizeof(ByteBuf), DEC);
//write the new value at the new location
ByteBuf[0] = writeValue;
winbondSPIFlash.WE();
winbondSPIFlash.writePage(dataFlashAddress - 1, ByteBuf, sizeof(ByteBuf));
while(winbondSPIFlash.busy());
// Serial.print("infoFlashAddress");
// Serial.println(infoFlashAddress, DEC);
//write where read can find the new value
ByteBuf[0] = ValueInInfoBlock;
winbondSPIFlash.WE();
winbondSPIFlash.writePage(infoFlashAddress + RelativeAdressInInfoBlock, ByteBuf, sizeof(ByteBuf));
while(winbondSPIFlash.busy());
//read the infoblock and put into the buffer
// uint8_t buf[256];
// winbondSPIFlash.read(infoFlashAddress, buf, sizeof(buf) - 1);
// while(winbondSPIFlash.busy());
// Serial.print("Buffer: ");
// for (uint16_t i = 0; i<sizeof(buf); i++){
// Serial.print(buf[i], HEX);
// }
// Serial.println(" END");
// winbondSPIFlash.read(0, buf, sizeof(buf) - 1);
// while(winbondSPIFlash.busy());
// Serial.print("sizeof(buf)");
// Serial.println(sizeof(buf), DEC);
// Serial.print("Buffer: ");
// for (uint16_t i = 0; i<sizeof(buf); i++){
// Serial.print(buf[i], HEX);
// }
// Serial.println(" END");
return 0;
}else{
@ -169,7 +134,7 @@ int8_t SPIAsEEPROM::write(uint16_t addressEEPROM, uint8_t writeValue){
}
int8_t SPIAsEEPROM::update(uint16_t address, uint8_t val){
//a write statement is already an update statement
//a write function call is already an update.
write(address, val);
return 0;
}
@ -181,45 +146,20 @@ uint8_t SPIAsEEPROM::writeMagicNumber(uint16_t sectorNumber){
if (sectorNumber>=FLASHSIZEUSED/SECTORSIZE){
sectorNumber = (FLASHSIZEUSED/SECTORSIZE - 1);
}
// Serial.print("Sector number to erase");
// Serial.println(sectorNumber);
//First erase the sector (4KiB at the time)
winbondSPIFlash.WE();
winbondSPIFlash.eraseSector(sectorNumber*SECTORSIZE);
while(winbondSPIFlash.busy());
while(winbondSPIFlash.busy()); //if no spi flash present or accessible this hangs forever!
//Write the magic numbers at the start of the sector for identification.
winbondSPIFlash.WE();
winbondSPIFlash.writePage(sectorNumber*SECTORSIZE, magicbuf, MAGICNUMBER_OFFSET);
while(winbondSPIFlash.busy());
// Serial.print("sizeof(magicbuf)");
// Serial.println(sizeof(magicbuf), DEC);
// uint8_t buf[256];
// winbondSPIFlash.read(sectorNumber*SECTORSIZE, buf, sizeof(buf) - 1);
// Serial.print("Buffer: ");
// for (uint16_t i = 0; i<sizeof(buf); i++){
// Serial.print(buf[i], HEX);
// }
// Serial.println(" END");
while(winbondSPIFlash.busy()); //if no spi flash present or accessible this hangs forever!
return 0;
}
// uint8_t SPIAsEEPROM::readInfoBlocks(){
// uint32_t address;
// uint16_t n;
// uint8_t buf[INFOBYTESSECTOROFFSET];
// for (uint16_t i=0; i < FLASHSIZEUSED/SECTORSIZE; i++) {
// n = winbondSPIFlash.read(i*SECTORSIZE,buf,INFOBYTESSECTOROFFSET);
// for (uint16_t j=0; j<36; j++){
// Serial.print(buf[j], HEX);
// }
// Serial.println(" ");
// }
// //winbondSPIFlash.read(address,buf,len);
// return 0;
// }
uint8_t SPIAsEEPROM::formatFlashForUse(){
//Format the flash for use by erasing all sectors used and
//write the magic number at the start of each erased sector
@ -235,60 +175,37 @@ uint8_t SPIAsEEPROM::read(uint16_t addressEEPROM){
//The first 4 bytes of each page must have the magic number
//version 0.1 does not check magic number
uint8_t buf[INFOBYTES_PER_BYTE];
//Check if address is outside of the maximum. limit to get inside maximum and continue as normal.
//Should be changed so that it returns -1 (error)
if (addressEEPROM >= FLASHSIZEUSED/SECTORSIZE * (SECTORSIZE/FLASH_PAGESIZE - 2)){addressEEPROM = FLASHSIZEUSED/SECTORSIZE * (SECTORSIZE/FLASH_PAGESIZE - 2);}
// Serial.print("byte adress");
// Serial.println(addressEEPROM, DEC);
uint8_t buf[INFOBYTES_PER_BYTE];
if (addressEEPROM >= FLASHSIZEUSED/SECTORSIZE * (SECTORSIZE/FLASH_PAGESIZE - 2)){addressEEPROM = FLASHSIZEUSED/SECTORSIZE * (SECTORSIZE/FLASH_PAGESIZE - 2);}
//Check at what sector number the adress resides. 14 bytes per sector
sectorNumber = addressEEPROM/(SECTORSIZE/FLASH_PAGESIZE - 2);
// Serial.print("sectorNumber");
// Serial.println(sectorNumber, DEC);
//Check at what page number in the sector the adress can be found (16 pages per sector, 14 used)
pageNumber = addressEEPROM - (sectorNumber * ((SECTORSIZE/FLASH_PAGESIZE) - 2));
// Serial.print("pageNumber");
// Serial.println(pageNumber, DEC);
//The absulute adress of the infoblock of the byte in flash adress
infoFlashAddress = sectorNumber*SECTORSIZE + pageNumber * INFOBYTES_PER_BYTE + MAGICNUMBER_OFFSET;
//read the infoblock and put into the buffer
//read the infoblock and put into the buffer
winbondSPIFlash.read(infoFlashAddress, buf, sizeof(buf));
// Serial.print("InfoblockBuffer: ");
// for (uint16_t i = 0; i<sizeof(buf); i++){
// Serial.print(buf[i], HEX);
// }
// Serial.println(" END");
while(winbondSPIFlash.busy());
while(winbondSPIFlash.busy()); //if no spi flash present or accessible this hangs forever!
//calculate actual flash address of the data
//Count de number of set bits in the infoblock
nrOfOnes = count(buf);
// Serial.print("nrOfOnes");
// Serial.println(nrOfOnes, DEC);
//Calulate the adress from all previous information.
dataFlashAddress = sectorNumber*SECTORSIZE + (pageNumber * FLASH_PAGESIZE) + INFOBYTESSECTOROFFSET + nrOfOnes - 1;
uint8_t ByteBuf[1];
//read the actual byte
winbondSPIFlash.read(dataFlashAddress, ByteBuf, sizeof(ByteBuf));
while(winbondSPIFlash.busy());
//read the actual byte with information
// Serial.print("values from EEPROM");
// Serial.println(ByteBuf[0], DEC);
winbondSPIFlash.read(dataFlashAddress, ByteBuf, sizeof(ByteBuf));
while(winbondSPIFlash.busy()); //if no spi flash present or accessible this hangs forever!
return ByteBuf[0];
}

View File

@ -1,15 +1,37 @@
/* Speeduino SPIAsEEPROM Library v.1.0.0
* Copyright (C) 2019 by Tjeerd Hoogendijk
* Created by Tjeerd Hoogendijk - 21/09/2019
*
* This file is part of the Speeduino project. This library is for
* Winbond SPI flash memory modules. In its current form it enables reading
* and writing individual bytes as if it where an AVR EEPROM. It uses some
* wear leveling (256x). When the begin() fuction is called for the first time
* it will "format" the flash chip.
* !!!!THIS DISTROYS ANY EXISTING DATA ON THE SPI FLASH!!!
*
* 1757184 bytes used of the SPI flash resulting in 6006 bytes of usable EEPROM
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License v3.0
* along with the Arduino SPIMemory Library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef SPI_AS_EEPROM_H
#define SPI_AS_EEPROM_H
#if defined(CORE_STM32_OFFICIAL) && defined(SPIFLASH_AS_EEPROM)
// //UGLY HACK TO PREVENT EEPROM LIBRARY BEING IMPORTED FIRST!!
// //Use with black_F407VE board
// #ifndef EEPROM_h
// #define EEPROM_h
#define FLASHSIZEUSED 1245184 //must be a multiple of sectorsize //1245184 = 4228 bytes of EEPROM
#define FLASHSIZEUSED 1757184 //must be a multiple of sectorsize //1757184 = 6006 bytes of EEPROM
#define BYTESPERSECTOR 14
#define SECTORSIZE 4096
#define INFOBYTESSECTOROFFSET 512
@ -28,8 +50,6 @@
#include <SPI.h>
#include "winbondflash.h"
// winbondFlashSPI winbondSPIFlash;
class SPIAsEEPROM {
private:
winbondFlashSPI winbondSPIFlash;
@ -53,8 +73,9 @@ class SPIAsEEPROM {
int8_t update(uint16_t address, uint8_t val);
};
#endif
#endif
// #endif
extern SPIAsEEPROM EEPROM;
#endif
#endif

View File

@ -131,39 +131,25 @@ bool winbondFlashClass::checkPartNo(partNumber _partno)
id |= transfer(0x00);
deselect();
//Serial1.print("MANUF=0x");
//Serial1.print(manuf,HEX);
//Serial1.print(",ID=0x");
//Serial1.print(id,HEX);
//Serial1.println();
//Serial1.print("MANUF=0x");
//Serial1.println(WINBOND_MANUF,HEX);
if(manuf != WINBOND_MANUF){
//Serial1.println("MANUF NOT OK");
return false;
}
if(_partno == custom)
return true;
//Serial.println("Not a custom chip type");
if(_partno == autoDetect)
{
//Serial1.print("Autodetect...");
for(int i=0;i<sizeof(pnList)/sizeof(pnList[0]);i++)
{
if(id == pgm_read_word(&(pnList[i].id)))
{
_partno = (partNumber)pgm_read_byte(&(pnList[i].pn));
//Serial1.println("OK");
return true;
}
}
if(_partno == autoDetect)
{
// Serial.println("Failed");
return false;
}
}
@ -179,7 +165,6 @@ bool winbondFlashClass::checkPartNo(partNumber _partno)
return false;
}
}
//Serial1.println("partNumber not found");
return false;//partNo not found
}
@ -256,8 +241,7 @@ bool winbondFlashClass::begin(partNumber _partno)
transfer(RELEASE);
deselect();
delayMicroseconds(15);//>3us
//Serial1.println("Chip Released");
if(!checkPartNo(_partno)) return false;
else return true;
}
@ -307,7 +291,7 @@ void winbondFlashClass::writePage(uint32_t addr_start,uint8_t *buf, uint16_t n)
//do {
// transfer(buf[i]);
// i++;
//}while(i!=sizeof(buf));
//}while(i!=0);
deselect();
}
@ -371,7 +355,7 @@ bool winbondFlashSPI::begin(partNumber _partno,SPIClass &_spi,uint8_t _nss)
// pinMode(MISO,INPUT_PULLUP);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV16);
SPI.setClockDivider(SPI_CLOCK_DIV2);
SPI.setDataMode(SPI_MODE0);
deselect();
// Serial.println("SPI OK");

View File

@ -88,7 +88,6 @@ void writeConfig(byte tableNum)
//That concludes the writing of the VE table
case veSetPage:
EEPROM.read(0);
/*---------------------------------------------------
| Config page 2 (See storage.h for data layout)
| 64 byte long config table
@ -756,399 +755,3 @@ void storeLastBaro(byte newValue) { EEPROM.update(EEPROM_LAST_BARO, newValue); }
void storeCalibrationValue(uint16_t location, byte value) { EEPROM.update(location, value); } //This is essentially just an abstraction for EEPROM.update()
byte readEEPROMVersion() { return EEPROM.read(EEPROM_DATA_VERSION); }
void storeEEPROMVersion(byte newVersion) { EEPROM.update(EEPROM_DATA_VERSION, newVersion); }
void NewWriteConfig(byte tableNum)
{
/*
We only ever write to the EEPROM where the new value is different from the currently stored byte
This is due to the limited write life of the EEPROM (Approximately 100,000 writes)
*/
int offset;
int i, z, y;
int writeCounter = 0;
byte newVal; //Used for tempoerarily storing the new intended value
//Create a pointer to the config page
byte* pnt_configPage;
switch(tableNum)
{
case veMapPage:
/*---------------------------------------------------
| Fuel table (See storage.h for data layout) - Page 1
| 16x16 table itself + the 16 values along each of the axis
-----------------------------------------------------*/
if(EEPROM.read(EEPROM_CONFIG1_XSIZE) != fuelTable.xSize) { EEPROM.write(EEPROM_CONFIG1_XSIZE, fuelTable.xSize); writeCounter++; } //Write the VE Tables RPM dimension size
if(EEPROM.read(EEPROM_CONFIG1_YSIZE) != fuelTable.ySize) { EEPROM.write(EEPROM_CONFIG1_YSIZE, fuelTable.ySize); writeCounter++; } //Write the VE Tables MAP/TPS dimension size
for(int x=EEPROM_CONFIG1_MAP; x<EEPROM_CONFIG1_XBINS; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG1_MAP;
if( EEPROM.read(x) != (fuelTable.values[15-(offset/16)][offset%16]) ) { EEPROM.write(x, fuelTable.values[15-(offset/16)][offset%16]); writeCounter++; } //Write the 16x16 map
}
//RPM bins
for(int x=EEPROM_CONFIG1_XBINS; x<EEPROM_CONFIG1_YBINS; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG1_XBINS;
if( EEPROM.read(x) != (byte(fuelTable.axisX[offset]/TABLE_RPM_MULTIPLIER)) ) { EEPROM.write(x, byte(fuelTable.axisX[offset]/TABLE_RPM_MULTIPLIER)); writeCounter++; } //RPM bins are divided by 100 and converted to a byte
}
//TPS/MAP bins
for(int x=EEPROM_CONFIG1_YBINS; x<EEPROM_CONFIG2_START; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG1_YBINS;
EEPROM.update(x, fuelTable.axisY[offset] / TABLE_LOAD_MULTIPLIER); //Table load is divided by 2 (Allows for MAP up to 511)
}
if(writeCounter > EEPROM_MAX_WRITE_BLOCK) { eepromWritesPending = true; }
else { eepromWritesPending = false; }
break;
//That concludes the writing of the VE table
case veSetPage:
/*---------------------------------------------------
| Config page 2 (See storage.h for data layout)
| 64 byte long config table
-----------------------------------------------------*/
pnt_configPage = (byte *)&configPage2; //Create a pointer to Page 2 in memory
for(int x=EEPROM_CONFIG2_START; x<EEPROM_CONFIG2_END; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
if(EEPROM.read(x) != *(pnt_configPage + byte(x - EEPROM_CONFIG2_START))) { EEPROM.write(x, *(pnt_configPage + byte(x - EEPROM_CONFIG2_START))); writeCounter++; }
}
if(writeCounter > EEPROM_MAX_WRITE_BLOCK) { eepromWritesPending = true; }
else { eepromWritesPending = false; }
break;
case ignMapPage:
/*---------------------------------------------------
| Ignition table (See storage.h for data layout) - Page 1
| 16x16 table itself + the 16 values along each of the axis
-----------------------------------------------------*/
//Begin writing the Ignition table, basically the same thing as above
if(EEPROM.read(EEPROM_CONFIG3_XSIZE) != ignitionTable.xSize) { EEPROM.write(EEPROM_CONFIG3_XSIZE,ignitionTable.xSize); writeCounter++; } //Write the ignition Table RPM dimension size
if(EEPROM.read(EEPROM_CONFIG3_YSIZE) != ignitionTable.ySize) { EEPROM.write(EEPROM_CONFIG3_YSIZE,ignitionTable.ySize); writeCounter++; } //Write the ignition Table MAP/TPS dimension size
for(int x=EEPROM_CONFIG3_MAP; x<EEPROM_CONFIG3_XBINS; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG3_MAP;
newVal = ignitionTable.values[15-(offset/16)][offset%16];
if(EEPROM.read(x) != newVal) { EEPROM.write(x, newVal); writeCounter++; } //Write the 16x16 map with translation
}
//RPM bins
for(int x=EEPROM_CONFIG3_XBINS; x<EEPROM_CONFIG3_YBINS; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG3_XBINS;
newVal = ignitionTable.axisX[offset]/TABLE_RPM_MULTIPLIER;
if(EEPROM.read(x) != newVal) { EEPROM.write(x, newVal); writeCounter++; } //RPM bins are divided by 100 and converted to a byte
}
//TPS/MAP bins
for(int x=EEPROM_CONFIG3_YBINS; x<EEPROM_CONFIG4_START; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG3_YBINS;
newVal = ignitionTable.axisY[offset]/TABLE_LOAD_MULTIPLIER;
if(EEPROM.read(x) != newVal) { EEPROM.write(x, newVal); writeCounter++; } //Table load is divided by 2 (Allows for MAP up to 511)
}
if(writeCounter > EEPROM_MAX_WRITE_BLOCK) { eepromWritesPending = true; }
else { eepromWritesPending = false; }
break;
case ignSetPage:
/*---------------------------------------------------
| Config page 2 (See storage.h for data layout)
| 64 byte long config table
-----------------------------------------------------*/
pnt_configPage = (byte *)&configPage4; //Create a pointer to Page 2 in memory
for(int x=EEPROM_CONFIG4_START; x<EEPROM_CONFIG4_END; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
if(EEPROM.read(x) != *(pnt_configPage + byte(x - EEPROM_CONFIG4_START))) { EEPROM.write(x, *(pnt_configPage + byte(x - EEPROM_CONFIG4_START))); writeCounter++; }
}
if(writeCounter > EEPROM_MAX_WRITE_BLOCK) { eepromWritesPending = true; }
else { eepromWritesPending = false; }
break;
case afrMapPage:
/*---------------------------------------------------
| AFR table (See storage.h for data layout) - Page 5
| 16x16 table itself + the 16 values along each of the axis
-----------------------------------------------------*/
//Begin writing the Ignition table, basically the same thing as above
if(EEPROM.read(EEPROM_CONFIG5_XSIZE) != afrTable.xSize) { EEPROM.write(EEPROM_CONFIG5_XSIZE,afrTable.xSize); writeCounter++; } //Write the ignition Table RPM dimension size
if(EEPROM.read(EEPROM_CONFIG5_YSIZE) != afrTable.ySize) { EEPROM.write(EEPROM_CONFIG5_YSIZE,afrTable.ySize); writeCounter++; } //Write the ignition Table MAP/TPS dimension size
for(int x=EEPROM_CONFIG5_MAP; x<EEPROM_CONFIG5_XBINS; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG5_MAP;
if(EEPROM.read(x) != (afrTable.values[15-(offset/16)][offset%16]) ) { EEPROM.write(x, afrTable.values[15-(offset/16)][offset%16]); writeCounter++; } //Write the 16x16 map
}
//RPM bins
for(int x=EEPROM_CONFIG5_XBINS; x<EEPROM_CONFIG5_YBINS; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG5_XBINS;
if(EEPROM.read(x) != byte(afrTable.axisX[offset]/TABLE_RPM_MULTIPLIER)) { EEPROM.write(x, byte(afrTable.axisX[offset]/TABLE_RPM_MULTIPLIER)); writeCounter++; } //RPM bins are divided by 100 and converted to a byte
}
//TPS/MAP bins
for(int x=EEPROM_CONFIG5_YBINS; x<EEPROM_CONFIG6_START; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG5_YBINS;
EEPROM.update(x, afrTable.axisY[offset]/TABLE_LOAD_MULTIPLIER); //Table load is divided by 2 (Allows for MAP up to 511)
}
if(writeCounter > EEPROM_MAX_WRITE_BLOCK) { eepromWritesPending = true; }
else { eepromWritesPending = false; }
break;
case afrSetPage:
/*---------------------------------------------------
| Config page 3 (See storage.h for data layout)
| 64 byte long config table
-----------------------------------------------------*/
pnt_configPage = (byte *)&configPage6; //Create a pointer to Page 3 in memory
for(int x=EEPROM_CONFIG6_START; x<EEPROM_CONFIG6_END; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
if(EEPROM.read(x) != *(pnt_configPage + byte(x - EEPROM_CONFIG6_START))) { EEPROM.write(x, *(pnt_configPage + byte(x - EEPROM_CONFIG6_START))); writeCounter++; }
}
if(writeCounter > EEPROM_MAX_WRITE_BLOCK) { eepromWritesPending = true; }
else { eepromWritesPending = false; }
break;
case boostvvtPage:
/*---------------------------------------------------
| Boost and vvt tables (See storage.h for data layout) - Page 8
| 8x8 table itself + the 8 values along each of the axis
-----------------------------------------------------*/
//Begin writing the 2 tables, basically the same thing as above but we're doing these 2 together (2 tables per page instead of 1)
if(EEPROM.read(EEPROM_CONFIG7_XSIZE1) != boostTable.xSize) { EEPROM.write(EEPROM_CONFIG7_XSIZE1,boostTable.xSize); writeCounter++; } //Write the boost Table RPM dimension size
if(EEPROM.read(EEPROM_CONFIG7_YSIZE1) != boostTable.ySize) { EEPROM.write(EEPROM_CONFIG7_YSIZE1,boostTable.ySize); writeCounter++; } //Write the boost Table MAP/TPS dimension size
if(EEPROM.read(EEPROM_CONFIG7_XSIZE2) != vvtTable.xSize) { EEPROM.write(EEPROM_CONFIG7_XSIZE2,vvtTable.xSize); writeCounter++; } //Write the vvt Table RPM dimension size
if(EEPROM.read(EEPROM_CONFIG7_YSIZE2) != vvtTable.ySize) { EEPROM.write(EEPROM_CONFIG7_YSIZE2,vvtTable.ySize); writeCounter++; } //Write the vvt Table MAP/TPS dimension size
if(EEPROM.read(EEPROM_CONFIG7_XSIZE3) != stagingTable.xSize) { EEPROM.write(EEPROM_CONFIG7_XSIZE3,stagingTable.xSize); writeCounter++; } //Write the staging Table RPM dimension size
if(EEPROM.read(EEPROM_CONFIG7_YSIZE3) != stagingTable.ySize) { EEPROM.write(EEPROM_CONFIG7_YSIZE3,stagingTable.ySize); writeCounter++; } //Write the staging Table MAP/TPS dimension size
y = EEPROM_CONFIG7_MAP2; //We do the 3 maps together in the same loop
z = EEPROM_CONFIG7_MAP3;
for(int x=EEPROM_CONFIG7_MAP1; x<EEPROM_CONFIG7_XBINS1; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG7_MAP1;
if(EEPROM.read(x) != (boostTable.values[7-(offset/8)][offset%8]) ) { EEPROM.write(x, boostTable.values[7-(offset/8)][offset%8]); writeCounter++; } //Write the 8x8 map
offset = y - EEPROM_CONFIG7_MAP2;
if(EEPROM.read(y) != (vvtTable.values[7-(offset/8)][offset%8]) ) { EEPROM.write(y, vvtTable.values[7-(offset/8)][offset%8]); writeCounter++; } //Write the 8x8 map
offset = z - EEPROM_CONFIG7_MAP3;
if(EEPROM.read(z) != (stagingTable.values[7-(offset/8)][offset%8]) ) { EEPROM.write(z, stagingTable.values[7-(offset/8)][offset%8]); writeCounter++; } //Write the 8x8 map
y++;
z++;
}
//RPM bins
y = EEPROM_CONFIG7_XBINS2;
z = EEPROM_CONFIG7_XBINS3;
for(int x=EEPROM_CONFIG7_XBINS1; x<EEPROM_CONFIG7_YBINS1; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG7_XBINS1;
if(EEPROM.read(x) != byte(boostTable.axisX[offset]/TABLE_RPM_MULTIPLIER)) { EEPROM.write(x, byte(boostTable.axisX[offset]/TABLE_RPM_MULTIPLIER)); writeCounter++; } //RPM bins are divided by 100 and converted to a byte
offset = y - EEPROM_CONFIG7_XBINS2;
if(EEPROM.read(y) != byte(vvtTable.axisX[offset]/TABLE_RPM_MULTIPLIER)) { EEPROM.write(y, byte(vvtTable.axisX[offset]/TABLE_RPM_MULTIPLIER)); writeCounter++; } //RPM bins are divided by 100 and converted to a byte
offset = z - EEPROM_CONFIG7_XBINS3;
if(EEPROM.read(z) != byte(stagingTable.axisX[offset]/TABLE_RPM_MULTIPLIER)) { EEPROM.write(z, byte(stagingTable.axisX[offset]/TABLE_RPM_MULTIPLIER)); writeCounter++; } //RPM bins are divided by 100 and converted to a byte
y++;
z++;
}
//TPS/MAP bins
y=EEPROM_CONFIG7_YBINS2;
z=EEPROM_CONFIG7_YBINS3;
for(int x=EEPROM_CONFIG7_YBINS1; x<EEPROM_CONFIG7_XSIZE2; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG7_YBINS1;
if(EEPROM.read(x) != boostTable.axisY[offset]) { EEPROM.write(x, boostTable.axisY[offset]); writeCounter++; } //TABLE_LOAD_MULTIPLIER is NOT used for boost as it is TPS based (0-100)
offset = y - EEPROM_CONFIG7_YBINS2;
if(EEPROM.read(y) != vvtTable.axisY[offset]) { EEPROM.write(y, vvtTable.axisY[offset]); writeCounter++; } //TABLE_LOAD_MULTIPLIER is NOT used for VVT as it is TPS based (0-100)
offset = z - EEPROM_CONFIG7_YBINS3;
if(EEPROM.read(z) != byte(stagingTable.axisY[offset]/TABLE_LOAD_MULTIPLIER)) { EEPROM.write(z, byte(stagingTable.axisY[offset]/TABLE_LOAD_MULTIPLIER)); writeCounter++; } //RPM bins are divided by 100 and converted to a byte
y++;
z++;
}
if(writeCounter > EEPROM_MAX_WRITE_BLOCK) { eepromWritesPending = true; }
else { eepromWritesPending = false; }
break;
case seqFuelPage:
/*---------------------------------------------------
| Fuel trim tables (See storage.h for data layout) - Page 9
| 6x6 tables itself + the 6 values along each of the axis
-----------------------------------------------------*/
//Begin writing the 2 tables, basically the same thing as above but we're doing these 2 together (2 tables per page instead of 1)
if(EEPROM.read(EEPROM_CONFIG8_XSIZE1) != trim1Table.xSize) { EEPROM.write(EEPROM_CONFIG8_XSIZE1,trim1Table.xSize); writeCounter++; } //Write the boost Table RPM dimension size
if(EEPROM.read(EEPROM_CONFIG8_YSIZE1) != trim1Table.ySize) { EEPROM.write(EEPROM_CONFIG8_YSIZE1,trim1Table.ySize); writeCounter++; } //Write the boost Table MAP/TPS dimension size
if(EEPROM.read(EEPROM_CONFIG8_XSIZE2) != trim2Table.xSize) { EEPROM.write(EEPROM_CONFIG8_XSIZE2,trim2Table.xSize); writeCounter++; } //Write the boost Table RPM dimension size
if(EEPROM.read(EEPROM_CONFIG8_YSIZE2) != trim2Table.ySize) { EEPROM.write(EEPROM_CONFIG8_YSIZE2,trim2Table.ySize); writeCounter++; } //Write the boost Table MAP/TPS dimension size
if(EEPROM.read(EEPROM_CONFIG8_XSIZE3) != trim3Table.xSize) { EEPROM.write(EEPROM_CONFIG8_XSIZE3,trim3Table.xSize); writeCounter++; } //Write the boost Table RPM dimension size
if(EEPROM.read(EEPROM_CONFIG8_YSIZE3) != trim3Table.ySize) { EEPROM.write(EEPROM_CONFIG8_YSIZE3,trim3Table.ySize); writeCounter++; } //Write the boost Table MAP/TPS dimension size
if(EEPROM.read(EEPROM_CONFIG8_XSIZE4) != trim4Table.xSize) { EEPROM.write(EEPROM_CONFIG8_XSIZE4,trim4Table.xSize); writeCounter++; } //Write the boost Table RPM dimension size
if(EEPROM.read(EEPROM_CONFIG8_YSIZE4) != trim4Table.ySize) { EEPROM.write(EEPROM_CONFIG8_YSIZE4,trim4Table.ySize); writeCounter++; } //Write the boost Table MAP/TPS dimension size
y = EEPROM_CONFIG8_MAP2; //We do the 4 maps together in the same loop
z = EEPROM_CONFIG8_MAP3; //We do the 4 maps together in the same loop
i = EEPROM_CONFIG8_MAP4; //We do the 4 maps together in the same loop
for(int x=EEPROM_CONFIG8_MAP1; x<EEPROM_CONFIG8_XBINS1; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG8_MAP1;
newVal = trim1Table.values[5-(offset/6)][offset%6];
if (EEPROM.read(x) != newVal ) { EEPROM.update(x, newVal ); writeCounter++; } //Write the 6x6 map
offset = y - EEPROM_CONFIG8_MAP2;
newVal = trim2Table.values[5-(offset/6)][offset%6];
if (EEPROM.read(y) != newVal ) { EEPROM.update(y, newVal); writeCounter++; } //Write the 6x6 map
offset = z - EEPROM_CONFIG8_MAP3;
newVal = trim3Table.values[5-(offset/6)][offset%6];
if (EEPROM.read(z) != newVal ) { EEPROM.update(z, newVal); writeCounter++; } //Write the 6x6 map
offset = i - EEPROM_CONFIG8_MAP4;
newVal = trim4Table.values[5-(offset/6)][offset%6];
if (EEPROM.read(i) != newVal ) { EEPROM.update(i, newVal); writeCounter++; } //Write the 6x6 map
y++;
z++;
i++;
}
//RPM bins
y = EEPROM_CONFIG8_XBINS2;
z = EEPROM_CONFIG8_XBINS3;
i = EEPROM_CONFIG8_XBINS4;
for(int x=EEPROM_CONFIG8_XBINS1; x<EEPROM_CONFIG8_YBINS1; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { eepromWritesPending = true; break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG8_XBINS1;
EEPROM.update(x, byte(trim1Table.axisX[offset]/TABLE_RPM_MULTIPLIER)); //RPM bins are divided by 100 and converted to a byte
offset = y - EEPROM_CONFIG8_XBINS2;
EEPROM.update(y, byte(trim2Table.axisX[offset]/TABLE_RPM_MULTIPLIER)); //RPM bins are divided by 100 and converted to a byte
offset = z - EEPROM_CONFIG8_XBINS3;
EEPROM.update(z, byte(trim3Table.axisX[offset]/TABLE_RPM_MULTIPLIER)); //RPM bins are divided by 100 and converted to a byte
offset = i - EEPROM_CONFIG8_XBINS4;
EEPROM.update(i, byte(trim4Table.axisX[offset]/TABLE_RPM_MULTIPLIER)); //RPM bins are divided by 100 and converted to a byte
y++;
z++;
i++;
}
//TPS/MAP bins
y=EEPROM_CONFIG8_YBINS2;
z=EEPROM_CONFIG8_YBINS3;
i=EEPROM_CONFIG8_YBINS4;
for(int x=EEPROM_CONFIG8_YBINS1; x<EEPROM_CONFIG8_XSIZE2; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { eepromWritesPending = true; break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG8_YBINS1;
EEPROM.update(x, trim1Table.axisY[offset]/TABLE_LOAD_MULTIPLIER); //Table load is divided by 2 (Allows for MAP up to 511)
offset = y - EEPROM_CONFIG8_YBINS2;
EEPROM.update(y, trim2Table.axisY[offset]/TABLE_LOAD_MULTIPLIER); //Table load is divided by 2 (Allows for MAP up to 511)
offset = z - EEPROM_CONFIG8_YBINS3;
EEPROM.update(z, trim3Table.axisY[offset]/TABLE_LOAD_MULTIPLIER); //Table load is divided by 2 (Allows for MAP up to 511)
offset = i - EEPROM_CONFIG8_YBINS4;
EEPROM.update(i, trim4Table.axisY[offset]/TABLE_LOAD_MULTIPLIER); //Table load is divided by 2 (Allows for MAP up to 511)
y++;
z++;
i++;
}
if(writeCounter > EEPROM_MAX_WRITE_BLOCK) { eepromWritesPending = true; }
else { eepromWritesPending = false; }
break;
case canbusPage:
/*---------------------------------------------------
| Config page 10 (See storage.h for data layout)
| 192 byte long config table
-----------------------------------------------------*/
pnt_configPage = (byte *)&configPage9; //Create a pointer to Page 10 in memory
for(int x=EEPROM_CONFIG9_START; x<EEPROM_CONFIG9_END; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
if(EEPROM.read(x) != *(pnt_configPage + byte(x - EEPROM_CONFIG9_START))) { EEPROM.write(x, *(pnt_configPage + byte(x - EEPROM_CONFIG9_START))); writeCounter++; }
}
if(writeCounter > EEPROM_MAX_WRITE_BLOCK) { eepromWritesPending = true; }
else { eepromWritesPending = false; }
break;
case warmupPage:
/*---------------------------------------------------
| Config page 11 (See storage.h for data layout)
| 192 byte long config table
-----------------------------------------------------*/
pnt_configPage = (byte *)&configPage10; //Create a pointer to Page 11 in memory
//As there are no 3d tables in this page, all 192 bytes can simply be read in
for(int x=EEPROM_CONFIG10_START; x<EEPROM_CONFIG10_END; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
if(EEPROM.read(x) != *(pnt_configPage + byte(x - EEPROM_CONFIG10_START))) { EEPROM.write(x, *(pnt_configPage + byte(x - EEPROM_CONFIG10_START))); writeCounter++; }
}
if(writeCounter > EEPROM_MAX_WRITE_BLOCK) { eepromWritesPending = true; }
else { eepromWritesPending = false; }
break;
case fuelMap2Page:
/*---------------------------------------------------
| Fuel table (See storage.h for data layout) - Page 1
| 16x16 table itself + the 16 values along each of the axis
-----------------------------------------------------*/
EEPROM.update(EEPROM_CONFIG11_XSIZE, fuelTable2.xSize); writeCounter++; //Write the VE Tables RPM dimension size
EEPROM.update(EEPROM_CONFIG11_YSIZE, fuelTable2.ySize); writeCounter++; //Write the VE Tables MAP/TPS dimension size
for(int x=EEPROM_CONFIG11_MAP; x<EEPROM_CONFIG11_XBINS; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG11_MAP;
if( EEPROM.read(x) != (fuelTable2.values[15-(offset/16)][offset%16]) ) { EEPROM.write(x, fuelTable2.values[15-(offset/16)][offset%16]); writeCounter++; } //Write the 16x16 map
}
//RPM bins
for(int x=EEPROM_CONFIG11_XBINS; x<EEPROM_CONFIG11_YBINS; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG11_XBINS;
if( EEPROM.read(x) != (byte(fuelTable2.axisX[offset]/TABLE_RPM_MULTIPLIER)) ) { EEPROM.write(x, byte(fuelTable2.axisX[offset]/TABLE_RPM_MULTIPLIER)); writeCounter++; } //RPM bins are divided by 100 and converted to a byte
}
//TPS/MAP bins
for(int x=EEPROM_CONFIG11_YBINS; x<EEPROM_CONFIG11_END; x++)
{
if( (writeCounter > EEPROM_MAX_WRITE_BLOCK) ) { break; } //This is a safety check to make sure we don't attempt to write too much to the EEPROM at a time.
offset = x - EEPROM_CONFIG11_YBINS;
EEPROM.update(x, fuelTable2.axisY[offset] / TABLE_LOAD_MULTIPLIER); //Table load is divided by 2 (Allows for MAP up to 511)
}
if(writeCounter > EEPROM_MAX_WRITE_BLOCK) { eepromWritesPending = true; }
else { eepromWritesPending = false; }
break;
//That concludes the writing of the 2nd fuel table
default:
break;
}
}