fix source files
This commit is contained in:
parent
7008037de9
commit
bd424b78d1
69
prosjekt.X/eeprom.c
Normal file
69
prosjekt.X/eeprom.c
Normal file
@ -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 <len; i++){
|
||||||
|
fanSpeedIterate = eeprom_read_byte(i);
|
||||||
|
printf("Fanspeed nr %u : %u", i, fanSpeedIterate);
|
||||||
|
}
|
||||||
|
}
|
||||||
41
prosjekt.X/eeprom.h
Normal file
41
prosjekt.X/eeprom.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* File: eeprom.h
|
||||||
|
* Author: athamantis
|
||||||
|
*
|
||||||
|
* Created on 06 March 2024, 15:30
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef EEPROM_H
|
||||||
|
#define EEPROM_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <avr/eeprom.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 */
|
||||||
|
|
||||||
@ -10,6 +10,8 @@
|
|||||||
*
|
*
|
||||||
* Created on 01 March 2024, 10:34
|
* Created on 01 March 2024, 10:34
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "eeprom.h"
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -67,79 +69,6 @@ uint8_t USART3_read() {
|
|||||||
* read the memory for the fanspeed
|
* 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 <len; i++){
|
|
||||||
fanSpeedIterate = eeprom_read_byte(i);
|
|
||||||
printf("Fanspeed nr %u : %u", i, fanSpeedIterate);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
USART3_init();
|
USART3_init();
|
||||||
|
|||||||
@ -13,6 +13,8 @@
|
|||||||
displayName="Source Files"
|
displayName="Source Files"
|
||||||
projectFiles="true">
|
projectFiles="true">
|
||||||
<itemPath>main.c</itemPath>
|
<itemPath>main.c</itemPath>
|
||||||
|
<itemPath>eeprom.h</itemPath>
|
||||||
|
<itemPath>eeprom.c</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="ExternalFiles"
|
<logicalFolder name="ExternalFiles"
|
||||||
displayName="Important Files"
|
displayName="Important Files"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user