add bl24c02 (not test yet)

This commit is contained in:
不吃油炸鸡
2025-10-14 16:25:11 +08:00
parent 40439c1800
commit 036eb68b76
2 changed files with 90 additions and 0 deletions

View 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;
}

View File

@@ -0,0 +1,12 @@
#ifndef __BL24C02_H
#define __BL24C02_H
#include <stdint.h>
#define BL24C02_ADDRESS 0x50
uint8_t EEPROM_Check(void);
uint8_t SettingSave(uint8_t *buf, uint8_t addr, uint8_t lenth);
uint8_t SettingGet(uint8_t *buf, uint8_t addr, uint8_t lenth);
#endif