mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
add bl24c02 (not test yet)
This commit is contained in:
78
Power_Pico/BSP/BL24C02/BL24C02.c
Normal file
78
Power_Pico/BSP/BL24C02/BL24C02.c
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "BL24C02.h"
|
||||
#include "i2c.h"
|
||||
|
||||
static void BL24C02_Write(uint8_t addr, uint16_t length, uint8_t buff[])
|
||||
{
|
||||
HAL_I2C_Mem_Write(&hi2c1, BL24C02_ADDRESS<<1, addr, I2C_MEMADD_SIZE_8BIT, buff, length, 10);
|
||||
}
|
||||
|
||||
static void BL24C02_Read(uint8_t addr, uint8_t length, uint8_t buff[])
|
||||
{
|
||||
HAL_I2C_Mem_Read(&hi2c1, BL24C02_ADDRESS<<1, addr, I2C_MEMADD_SIZE_8BIT, buff, length, 10);
|
||||
}
|
||||
|
||||
static void delay_ms(uint32_t ms)
|
||||
{
|
||||
HAL_Delay(ms);
|
||||
}
|
||||
|
||||
/******************************************
|
||||
EEPROM Data description:
|
||||
[0x00]:0x55 for check
|
||||
[0x01]:0xAA for check
|
||||
|
||||
[0x10]:user wrist setting, HWInterface.IMU.wrist_is_enabled
|
||||
[0x11]:user ui_APPSy_EN setting
|
||||
|
||||
*******************************************/
|
||||
|
||||
//to check the Data is right and the EEPROM is working
|
||||
uint8_t EEPROM_Check(void)
|
||||
{
|
||||
uint8_t check_buff[2];
|
||||
delay_ms(10);
|
||||
BL24C02_Read(0,2,check_buff);
|
||||
if(check_buff[0] == 0x55 && check_buff[1] == 0xAA)
|
||||
{
|
||||
return 0;//check OK
|
||||
}
|
||||
else
|
||||
{
|
||||
check_buff[0] = 0x55;
|
||||
check_buff[1] = 0xAA;
|
||||
delay_ms(10);
|
||||
BL24C02_Write(0,2,check_buff);
|
||||
memset(check_buff,0,2);
|
||||
delay_ms(10);
|
||||
BL24C02_Read(0,2,check_buff);
|
||||
if(check_buff[0] == 0x55 && check_buff[1] == 0xAA)
|
||||
return 0;//check ok
|
||||
}
|
||||
return 1;//check erro
|
||||
}
|
||||
|
||||
|
||||
//to Save the settings
|
||||
uint8_t SettingSave(uint8_t *buf, uint8_t addr, uint8_t lenth)
|
||||
{
|
||||
if(addr > 1 && !EEPROM_Check())
|
||||
{
|
||||
delay_ms(10);
|
||||
BL24C02_Write(addr,lenth,buf);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
//to Get the settings
|
||||
uint8_t SettingGet(uint8_t *buf, uint8_t addr, uint8_t lenth)
|
||||
{
|
||||
if(addr > 1 && !EEPROM_Check())
|
||||
{
|
||||
delay_ms(10);
|
||||
BL24C02_Read(addr,lenth,buf);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user