70 lines
1.7 KiB
C
70 lines
1.7 KiB
C
|
|
#include "eeprom.h"
|
||
|
|
|
||
|
|
bool alreadyWrittenAblock = false;//false
|
||
|
|
uint8_t EEMEM currentFanSpeedAddress = 0x30;
|
||
|
|
uint8_t EEMEM fanControllerStartAddress = 0x00;
|
||
|
|
|
||
|
|
|
||
|
|
uint8_t EEMEM fanSpeedStartAddress = 0x30;
|
||
|
|
|
||
|
|
|
||
|
|
void checkEEpromIsReady(){
|
||
|
|
printf("checking eeprom");
|
||
|
|
while(1){
|
||
|
|
if (eeprom_is_ready()){
|
||
|
|
break;
|
||
|
|
printf("it is");
|
||
|
|
}else{
|
||
|
|
;
|
||
|
|
printf("its not");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void WriteStructInEEPROM(config_t writeStruct){
|
||
|
|
uint8_t structSize;
|
||
|
|
structSize = sizeof(writeStruct);
|
||
|
|
|
||
|
|
//check if eeprom_is_ready()
|
||
|
|
checkEEpromIsReady();
|
||
|
|
|
||
|
|
if (alreadyWrittenAblock){
|
||
|
|
eeprom_update_block((void*) &writeStruct,(void*) &fanControllerStartAddress, structSize);
|
||
|
|
}else{
|
||
|
|
eeprom_write_block((void*)&writeStruct,(void*) &fanControllerStartAddress, structSize);
|
||
|
|
alreadyWrittenAblock = true;//true
|
||
|
|
//reurn something
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
config_t ReadStructInEEPROM(){
|
||
|
|
//is eeprom ready??
|
||
|
|
config_t readStruct;
|
||
|
|
uint8_t structsize = sizeof(readStruct);
|
||
|
|
|
||
|
|
checkEEpromIsReady();
|
||
|
|
|
||
|
|
eeprom_read_block((void *) &readStruct,(void*) &fanControllerStartAddress, structsize);
|
||
|
|
return readStruct;
|
||
|
|
}
|
||
|
|
|
||
|
|
void WriteFanSpeedInEEPROM(uint8_t fanSpeed){
|
||
|
|
|
||
|
|
checkEEpromIsReady();
|
||
|
|
|
||
|
|
eeprom_write_byte(currentFanSpeedAddress, fanSpeed);
|
||
|
|
currentFanSpeedAddress++;
|
||
|
|
}
|
||
|
|
|
||
|
|
void ReadFanSpeedInfo(){
|
||
|
|
uint8_t len = currentFanSpeedAddress - fanSpeedStartAddress;
|
||
|
|
uint8_t fanSpeedIterate = 0;
|
||
|
|
|
||
|
|
checkEEpromIsReady();
|
||
|
|
|
||
|
|
for (uint8_t i = 0; i <len; i++){
|
||
|
|
fanSpeedIterate = eeprom_read_byte(i);
|
||
|
|
printf("Fanspeed nr %u : %u", i, fanSpeedIterate);
|
||
|
|
}
|
||
|
|
}
|