diff --git a/prosjekt.X/eeprom.c b/prosjekt.X/eeprom.c new file mode 100644 index 0000000..202da14 --- /dev/null +++ b/prosjekt.X/eeprom.c @@ -0,0 +1,69 @@ +#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 +#include +#include +#include +#include +#include + + + +typedef struct { + uint8_t fanSpeed; +} config_t; + + +void checkEEpromIsReady(); +void WriteStructInEEPROM(config_t writeStruct); +config_t ReadStructInEEPROM(); +void WriteFanSpeedInEEPROM(uint8_t fanSpeed); +void ReadFanSpeedInfo(); + + +#ifdef __cplusplus +} +#endif + +#endif /* EEPROM_H */ + diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index 66887ff..dedbf52 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -10,6 +10,8 @@ * * Created on 01 March 2024, 10:34 */ + +#include "eeprom.h" #include #include #include @@ -67,79 +69,6 @@ uint8_t USART3_read() { * read the memory for the fanspeed */ -uint8_t EEMEM fanControllerStartAddress = 0x00; -bool alreadyWrittenAblock = false;//false - -uint8_t EEMEM fanSpeedStartAddress = 0x30; -uint8_t EEMEM currentFanSpeedAddress = 0x30; - -typedef struct { - uint8_t fanSpeed; -} config_t; - -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(&writeStruct, &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(){ - //read the space as an array or?? - //eeprom_read_block(); - //this write it too or? - uint8_t len = currentFanSpeedAddress - fanSpeedStartAddress; - uint8_t fanSpeedIterate = 0; - - checkEEpromIsReady(); - - for (uint8_t i = 0; i main.c + eeprom.h + eeprom.c