From 036eb68b76c8aaf4ecdeb707387fd2520ca86553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=90=83=E6=B2=B9=E7=82=B8=E9=B8=A1?= <1425962791@qq.com> Date: Tue, 14 Oct 2025 16:25:11 +0800 Subject: [PATCH] add bl24c02 (not test yet) --- Power_Pico/BSP/BL24C02/BL24C02.c | 78 ++++++++++++++++++++++++++++++++ Power_Pico/BSP/BL24C02/BL24C02.h | 12 +++++ 2 files changed, 90 insertions(+) create mode 100644 Power_Pico/BSP/BL24C02/BL24C02.c create mode 100644 Power_Pico/BSP/BL24C02/BL24C02.h diff --git a/Power_Pico/BSP/BL24C02/BL24C02.c b/Power_Pico/BSP/BL24C02/BL24C02.c new file mode 100644 index 0000000..b3174f2 --- /dev/null +++ b/Power_Pico/BSP/BL24C02/BL24C02.c @@ -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; +} diff --git a/Power_Pico/BSP/BL24C02/BL24C02.h b/Power_Pico/BSP/BL24C02/BL24C02.h new file mode 100644 index 0000000..f722e97 --- /dev/null +++ b/Power_Pico/BSP/BL24C02/BL24C02.h @@ -0,0 +1,12 @@ +#ifndef __BL24C02_H +#define __BL24C02_H + +#include + +#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