mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-12-16 01:09:57 +00:00
firstTest
This commit is contained in:
67
Core/Src/EEPROM.c
Normal file
67
Core/Src/EEPROM.c
Normal file
@ -0,0 +1,67 @@
|
||||
#include "EEPROM.h"
|
||||
#include "pca9685.h"
|
||||
#include "usbd_cdc_if.h"
|
||||
|
||||
|
||||
void SaveShot(unsigned char number, struct StructShot* shot)
|
||||
{
|
||||
uint16_t blockAddr16 = (uint16_t)(START_ADR_SHOT + (uint16_t)(number*FLASH_BLOCKSIZE));
|
||||
|
||||
uint8_t blockAddr[2] = {HIBYTE(blockAddr16), LOBYTE(blockAddr16)};
|
||||
|
||||
unsigned char Buf[FLASH_BLOCKSIZE];
|
||||
|
||||
for( unsigned char i = 0; i < FLASH_BLOCKSIZE; i++ ) Buf[i] = 0;
|
||||
|
||||
Buf[0] = number;
|
||||
Buf[1] = shot->countRepeatShot;
|
||||
Buf[2] = shot->speedRollerTop;
|
||||
Buf[3] = shot->speedRollerBottom;
|
||||
Buf[4] = shot->speedScrew;
|
||||
Buf[5] = shot->rotationAxial;
|
||||
Buf[6] = shot->rotationHorizontal;
|
||||
Buf[7] = shot->rotationVertical;
|
||||
|
||||
// Writes buffer contents to current block
|
||||
FLASH_WriteBlock(blockAddr, Buf);
|
||||
}
|
||||
|
||||
struct StructShot GetShot( unsigned char number )
|
||||
{
|
||||
struct StructShot shot;
|
||||
|
||||
uint16_t blockAddr16 = (uint16_t)(START_ADR_SHOT + (uint16_t)(number*FLASH_BLOCKSIZE));
|
||||
|
||||
uint8_t blockAddr[2] = {HIBYTE(blockAddr16), LOBYTE(blockAddr16)};
|
||||
|
||||
unsigned char Buf[FLASH_BLOCKSIZE];
|
||||
|
||||
|
||||
HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1), blockAddr, 2, 10);
|
||||
HAL_Delay(1);
|
||||
HAL_I2C_Master_Receive(&hi2c1, (AT24C_ADRESS << 1), Buf, FLASH_BLOCKSIZE, 10);
|
||||
HAL_Delay(1);
|
||||
|
||||
shot.countRepeatShot = Buf[1];
|
||||
shot.speedRollerTop = Buf[2];
|
||||
shot.speedRollerBottom = Buf[3];
|
||||
shot.speedScrew = Buf[4];
|
||||
shot.rotationAxial = Buf[5];
|
||||
shot.rotationHorizontal = Buf[6];
|
||||
shot.rotationVertical = Buf[7];
|
||||
|
||||
return shot;
|
||||
}
|
||||
|
||||
|
||||
void FLASH_WriteBlock(uint8_t *writeAddr, unsigned char *flashWrBufPtr)
|
||||
{
|
||||
unsigned char Buf[FLASH_BLOCKSIZE+2];
|
||||
Buf[0] = writeAddr[0];
|
||||
Buf[1] = writeAddr[1];
|
||||
|
||||
for( unsigned char i = 0; i < (FLASH_BLOCKSIZE); i++ ) Buf[i+2] = flashWrBufPtr[i];
|
||||
|
||||
HAL_I2C_Master_Transmit(&hi2c1, (AT24C_ADRESS << 1), Buf, (FLASH_BLOCKSIZE + 2), 10);
|
||||
HAL_Delay(1);
|
||||
}
|
||||
Reference in New Issue
Block a user