From a43110f04a5c4d114c095669e4d3b3fab164d88b 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: Mon, 20 Oct 2025 20:15:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99BSP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootloader/BSP/KT6328/KT6328.c | 32 --------- bootloader/BSP/KT6328/KT6328.h | 19 ------ bootloader/BSP/POWER/power.c | 121 --------------------------------- bootloader/BSP/POWER/power.h | 24 ------- 4 files changed, 196 deletions(-) delete mode 100644 bootloader/BSP/KT6328/KT6328.c delete mode 100644 bootloader/BSP/KT6328/KT6328.h delete mode 100644 bootloader/BSP/POWER/power.c delete mode 100644 bootloader/BSP/POWER/power.h diff --git a/bootloader/BSP/KT6328/KT6328.c b/bootloader/BSP/KT6328/KT6328.c deleted file mode 100644 index 56a35ef..0000000 --- a/bootloader/BSP/KT6328/KT6328.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "KT6328.h" - -void KT6328_GPIO_Init(void) -{ - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - - __HAL_RCC_GPIOA_CLK_ENABLE(); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); - - GPIO_InitStruct.Pin = GPIO_PIN_8; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - -} - - -void KT6328_Enable(void) -{ - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); -} - - -void KT6328_Disable(void) -{ - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); -} - diff --git a/bootloader/BSP/KT6328/KT6328.h b/bootloader/BSP/KT6328/KT6328.h deleted file mode 100644 index 2b459da..0000000 --- a/bootloader/BSP/KT6328/KT6328.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __KT6328_H__ -#define __KT6328_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "main.h" - -void KT6328_GPIO_Init(void); -void KT6328_Enable(void); -void KT6328_Disable(void); - - -#ifdef __cplusplus -} -#endif -#endif - diff --git a/bootloader/BSP/POWER/power.c b/bootloader/BSP/POWER/power.c deleted file mode 100644 index 4501376..0000000 --- a/bootloader/BSP/POWER/power.c +++ /dev/null @@ -1,121 +0,0 @@ -#include "power.h" -#include "adc.h" -#include "delay.h" - -#define INTERNAL_RES 0.128 -#define CHARGING_CUR 1 - -void Power_Pins_Init() -{ - GPIO_InitTypeDef GPIO_InitStruct = {0}; - - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOA_CLK_ENABLE(); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(POWER_PORT, POWER_PIN, GPIO_PIN_RESET); - - /*Configure GPIO pin : PA3 */ - GPIO_InitStruct.Pin = POWER_PIN; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(POWER_PORT, &GPIO_InitStruct); - - /*Configure GPIO pin : PA2 */ - GPIO_InitStruct.Pin = CHARGE_PIN; - GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(CHARGE_PORT, &GPIO_InitStruct); - - HAL_NVIC_SetPriority(EXTI2_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(EXTI2_IRQn); - -} - -void Power_Enable() -{ - HAL_GPIO_WritePin(POWER_PORT,POWER_PIN,GPIO_PIN_SET); -} - -void Power_DisEnable() -{ - HAL_GPIO_WritePin(POWER_PORT,POWER_PIN,GPIO_PIN_RESET); -} - -uint8_t ChargeCheck()//1:charging -{ - return HAL_GPIO_ReadPin(CHARGE_PORT,CHARGE_PIN); -} - -float BatCheck() -{ - uint16_t dat; - float BatVoltage; - HAL_ADC_Start(&hadc1); - HAL_ADC_PollForConversion(&hadc1,5); - dat = HAL_ADC_GetValue(&hadc1); - HAL_ADC_Stop(&hadc1); - BatVoltage = dat *2 *3.3 /4096; - return BatVoltage; -} - -float BatCheck_8times() -{ - uint32_t dat=0; - uint8_t i; - float BatVoltage; - for(i=0;i<8;i++) - { - HAL_ADC_Start(&hadc1); - HAL_ADC_PollForConversion(&hadc1,5); - dat += HAL_ADC_GetValue(&hadc1); - HAL_ADC_Stop(&hadc1); - delay_ms(1); - } - dat = dat>>3; - BatVoltage = dat *2 *3.3 /4096; - return BatVoltage; -} - -uint8_t PowerCalculate() -{ - uint8_t power; - float voltage; - voltage = BatCheck_8times(); - - if(ChargeCheck()) - {voltage -= INTERNAL_RES * CHARGING_CUR;} - - if((voltage >= 4.2)) - {power = 100;} - else if(voltage >= 4.06 && voltage <4.2) - {power = 90;} - else if(voltage >= 3.98 && voltage <4.06) - {power = 80;} - else if(voltage >= 3.92 && voltage <3.98) - {power = 70;} - else if(voltage >= 3.87 && voltage <3.92) - {power = 60;} - else if(voltage >= 3.82 && voltage <3.87) - {power = 50;} - else if(voltage >= 3.79 && voltage <3.82) - {power = 40;} - else if(voltage >= 3.77 && voltage <3.79) - {power = 30;} - else if(voltage >= 3.74 && voltage <3.77) - {power = 20;} - else if(voltage >= 3.68 && voltage <3.74) - {power = 10;} - else if(voltage >= 3.45 && voltage <3.68) - {power = 5;} - return power; -} - -void Power_Init(void) -{ - Power_Pins_Init(); - Power_Enable(); -} - - diff --git a/bootloader/BSP/POWER/power.h b/bootloader/BSP/POWER/power.h deleted file mode 100644 index eecd4c2..0000000 --- a/bootloader/BSP/POWER/power.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _POWER_H_ -#define _POWER_H_ - -#include "stm32f4xx_hal.h" - -#define BAT_CHECK_PORT GPIOA -#define BAT_CHECK_PIN GPIO_PIN_1 - -#define CHARGE_PORT GPIOA -#define CHARGE_PIN GPIO_PIN_2 - -#define POWER_PORT GPIOA -#define POWER_PIN GPIO_PIN_3 - -void Power_Pins_Init(void); -void Power_Enable(void); -void Power_DisEnable(void); -float BatCheck(void); -float BatCheck_8times(void); -uint8_t ChargeCheck(void); -uint8_t PowerCalculate(void); -void Power_Init(void); - -#endif