2024-03-06 14:49:48 +00:00
|
|
|
#include "eeprom.h"
|
|
|
|
|
|
2024-03-06 19:05:52 +00:00
|
|
|
// The start address for the controller data
|
|
|
|
|
uint8_t EEMEM startAddressController = 0x00;
|
2024-03-06 14:49:48 +00:00
|
|
|
|
2024-03-06 19:05:52 +00:00
|
|
|
// Where the writing of the fans points start
|
|
|
|
|
uint8_t EEMEM startAddressFan1 = 0x30;
|
|
|
|
|
uint8_t EEMEM startAddressFan2 = 0x60;
|
2024-03-06 14:49:48 +00:00
|
|
|
|
2024-03-06 19:05:52 +00:00
|
|
|
// The placement for the next datapoint form the fans.
|
|
|
|
|
uint8_t EEMEM currentAddressFan1 = 0x30;
|
|
|
|
|
uint8_t EEMEM currentAddressFan2 = 0x60;
|
2024-03-06 14:49:48 +00:00
|
|
|
|
2024-03-06 19:05:52 +00:00
|
|
|
// Checks if its written a struct in the memmory space.
|
|
|
|
|
bool alreadyWrittenABlock = false;
|
2024-03-06 14:49:48 +00:00
|
|
|
|
2024-03-06 19:05:52 +00:00
|
|
|
// Checks if the EEPROM memory is ready to be written in.
|
2024-03-06 14:49:48 +00:00
|
|
|
void checkEEpromIsReady(){
|
|
|
|
|
while(1){
|
|
|
|
|
if (eeprom_is_ready()){
|
|
|
|
|
break;
|
|
|
|
|
printf("it is");
|
|
|
|
|
}else{
|
|
|
|
|
;
|
|
|
|
|
printf("its not");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 19:05:52 +00:00
|
|
|
|
|
|
|
|
// Takes inn a struct by the form of config_t
|
|
|
|
|
// Checks if the eeprom is ready to be written in
|
|
|
|
|
// Checks if it has been written information at the address
|
|
|
|
|
// If true, the infromation is replaced with the intaken struct
|
|
|
|
|
// else the intaken struct is written at the address.
|
2024-03-06 14:49:48 +00:00
|
|
|
void WriteStructInEEPROM(config_t writeStruct){
|
|
|
|
|
uint8_t structSize;
|
|
|
|
|
structSize = sizeof(writeStruct);
|
|
|
|
|
|
|
|
|
|
checkEEpromIsReady();
|
|
|
|
|
|
2024-03-06 19:05:52 +00:00
|
|
|
if (alreadyWrittenABlock){
|
|
|
|
|
eeprom_update_block((void*) &writeStruct,(void*) &startAddressController, structSize);
|
2024-03-06 14:49:48 +00:00
|
|
|
}else{
|
2024-03-06 19:05:52 +00:00
|
|
|
eeprom_write_block((void*)&writeStruct,(void*) &startAddressController, structSize);
|
|
|
|
|
alreadyWrittenABlock = true;
|
2024-03-06 14:49:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 19:05:52 +00:00
|
|
|
// Reads the memory block at the address 0x00
|
|
|
|
|
// returns a struct in form of config_t
|
2024-03-06 14:49:48 +00:00
|
|
|
config_t ReadStructInEEPROM(){
|
|
|
|
|
//is eeprom ready??
|
|
|
|
|
config_t readStruct;
|
|
|
|
|
uint8_t structsize = sizeof(readStruct);
|
|
|
|
|
|
|
|
|
|
checkEEpromIsReady();
|
|
|
|
|
|
2024-03-06 19:05:52 +00:00
|
|
|
eeprom_read_block((void *) &readStruct,(void*) &startAddressController, structsize);
|
2024-03-06 14:49:48 +00:00
|
|
|
return readStruct;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 19:05:52 +00:00
|
|
|
// Takes inn a dataPoint and what data set it belongs to
|
|
|
|
|
// checks if EEPROM is ready
|
|
|
|
|
// If the dataset is 1, the datapoint is written at the address.
|
|
|
|
|
// If the dataset is 2 its written at another point.
|
|
|
|
|
void WriteDataPointInEEPROM(uint8_t dataPoint, uint8_t data){
|
2024-03-06 14:49:48 +00:00
|
|
|
|
|
|
|
|
checkEEpromIsReady();
|
2024-03-06 19:05:52 +00:00
|
|
|
if (data == 1){
|
|
|
|
|
eeprom_write_byte(currentAddressFan1, dataPoint);
|
|
|
|
|
currentAddressFan1++;
|
|
|
|
|
} else if (data == 2){
|
|
|
|
|
eeprom_write_byte(currentAddressFan2, dataPoint);
|
|
|
|
|
currentAddressFan2++;
|
|
|
|
|
} else{
|
|
|
|
|
// error???
|
|
|
|
|
;
|
|
|
|
|
}
|
2024-03-06 14:49:48 +00:00
|
|
|
}
|
|
|
|
|
|
2024-03-06 19:05:52 +00:00
|
|
|
// Reads all the datapoints to the choosen data.
|
|
|
|
|
// it writes the data points in the USART stream.
|
|
|
|
|
void ReadDataPointSpeedInfo(uint8_t data){
|
|
|
|
|
uint8_t dataPoint = 0;
|
2024-03-06 14:49:48 +00:00
|
|
|
|
2024-03-06 19:05:52 +00:00
|
|
|
if (data == 1){
|
|
|
|
|
uint8_t len = currentAddressFan1 - startAddressFan1;
|
|
|
|
|
|
|
|
|
|
checkEEpromIsReady();
|
|
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i <len; i++){
|
|
|
|
|
dataPoint = eeprom_read_byte(i);
|
|
|
|
|
printf("Fanspeed nr %u : %u", i, dataPoint);
|
|
|
|
|
}
|
|
|
|
|
} else if (data == 2){
|
|
|
|
|
uint8_t len = currentAddressFan2 - startAddressFan2;
|
|
|
|
|
checkEEpromIsReady();
|
|
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i <len; i++){
|
|
|
|
|
dataPoint = eeprom_read_byte(i);
|
|
|
|
|
printf("Fanspeed nr %u : %u", i, dataPoint);
|
|
|
|
|
}
|
2024-03-06 14:49:48 +00:00
|
|
|
}
|
|
|
|
|
}
|