mirror of
https://github.com/goldenfishs/MRobot.git
synced 2026-04-01 05:17:13 +08:00
bsp和component写完了
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
uart,要求开启dma和中断
|
||||
can,要求开启can的中断
|
||||
can,要求开启can的中断要求开启can的中断要求开启can的中断要求开启can的中断要求开启can的中断要求开启can的中断要求开启can的中断要求开启can的中断要求开启can的中断要求开启can的中断要求开启can的中断要求开启can的中断要求开启can的中断
|
||||
gpio,要求设置label开启中断
|
||||
spi,要求开启spi中断
|
||||
i2c,要求开始spi中断
|
||||
i2c,要求开始spi中断
|
||||
mm,这是套了一层的内存
|
||||
|
@@ -18,7 +18,7 @@ extern "C" {
|
||||
/* I2C实体枚举,与设备对应 */
|
||||
typedef enum {
|
||||
/* AUTO GENERATED BSP_I2C_NAME */
|
||||
/* USER BSP_I2C END*/
|
||||
/* USER BSP_I2C BEGIN*/
|
||||
/* USER_I2C_XXX */
|
||||
/* USER BSP_I2C END */
|
||||
BSP_I2C_NUM,
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include "servo_pwm.h"
|
||||
|
||||
#include "main.h"
|
||||
|
||||
|
||||
/* Private define ----------------------------------------------------------- */
|
||||
/* Private macro ------------------------------------------------------------ */
|
||||
/* Private typedef ---------------------------------------------------------- */
|
||||
/* Private variables -------------------------------------------------------- */
|
||||
/* Private function -------------------------------------------------------- */
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
int8_t BSP_PWM_Start(BSP_PWM_Channel_t ch) {
|
||||
|
||||
TIM_HandleTypeDef* htim = pwm_channel_config[ch].htim;
|
||||
uint32_t channel = pwm_channel_config[ch].channel;
|
||||
|
||||
if(HAL_TIM_PWM_Start(htim, channel)!=HAL_OK){
|
||||
return -1;
|
||||
}else return 0;
|
||||
}
|
||||
|
||||
int8_t BSP_PWM_Set(BSP_PWM_Channel_t ch, float duty_cycle) {
|
||||
if (duty_cycle > 1.0f) return -1;
|
||||
|
||||
uint16_t pulse = duty_cycle/CYCLE * PWM_RESOLUTION;
|
||||
|
||||
if(__HAL_TIM_SET_COMPARE(pwm_channel_config[ch].htim, pwm_channel_config[ch].channel, pulse)!=HAL_OK){
|
||||
return -1;
|
||||
}else return 0;
|
||||
}
|
||||
|
||||
int8_t BSP_PWM_Stop(BSP_PWM_Channel_t ch){
|
||||
|
||||
TIM_HandleTypeDef* htim = pwm_channel_config[ch].htim;
|
||||
uint32_t channel = pwm_channel_config[ch].channel;
|
||||
|
||||
if(HAL_TIM_PWM_Stop(htim, channel)!=HAL_OK){
|
||||
return -1;
|
||||
}else return 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include <stdint.h>
|
||||
#include "tim.h"
|
||||
#include "bsp/bsp.h"
|
||||
|
||||
/* Exported constants ------------------------------------------------------- */
|
||||
/* Exported macro ----------------------------------------------------------- */
|
||||
/* Exported types ----------------------------------------------------------- */
|
||||
typedef struct {
|
||||
TIM_HandleTypeDef* htim; // 定时器句柄
|
||||
uint32_t channel; // 定时器通道
|
||||
} PWM_Channel_Config_t;
|
||||
|
||||
#define PWM_RESOLUTION 1000 // ARR change begin
|
||||
#define CYCLE 20 //ms
|
||||
|
||||
typedef enum {
|
||||
BSP_PWM_SERVO = 0,
|
||||
BSP_PWM_IMU_HEAT = 1,
|
||||
} BSP_PWM_Channel_t;
|
||||
|
||||
const PWM_Channel_Config_t pwm_channel_config[] = {
|
||||
[BSP_PWM_SERVO] = { &htim1, TIM_CHANNEL_1 }, // xxx 对应 TIMx 通道x
|
||||
[BSP_PWM_IMU_HEAT] = { &htim1, TIM_CHANNEL_2 }
|
||||
}; //change end
|
||||
|
||||
/* Exported functions prototypes -------------------------------------------- */
|
||||
int8_t BSP_PWM_Start(BSP_PWM_Channel_t ch);
|
||||
int8_t BSP_PWM_Set(BSP_PWM_Channel_t ch, float duty_cycle);
|
||||
int8_t BSP_PWM_Stop(BSP_PWM_Channel_t ch);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user