This repository has been archived on 2025-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
torsion/User/system/bsp/adcs.h

107 lines
2.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/***
* @Author: xxx
* @Date: 2023-08-01 15:15:53
* @LastEditors: xxx
* @LastEditTime: 2023-08-10 16:00:46
* @Description: LL库ADC驱动
* @email:
* @Copyright (c) 2023 by xxx, All Rights Reserved.
*/
/**
* 使用教程
#include "adcs.h"
void adc_convert_callback(adc_t handle)
{
// 在这里处理ADC转换完成时的逻辑例如更新UI、发送通知等
}
void adc_init(adc_t handle)
{
// 初始化ADC包括停止转换、开始校准、使能ADC和启用DMA等
}
void adc_start(adc_t handle)
{
// 启动ADC转换
}
void adc_completed_state_change(BOOL state)
{
// 设置ADC转换完成状态变化回调函数
}
BOOL adc_completed(void)
{
// 获取ADC转换完成状态
}
uint16_t adc_get_result0(uint8_t in_num)
{
// 获取ADC第0个通道的读取结果
}
uint16_t adc_get_result_average(uint8_t adc_num)
{
// 获取ADC所有通道的读取结果平均值
}
int32_t compute_temperature(uint16_t measure)
{
// 计算内部温度
}
int32_t compute_value_local(uint16_t measure)
{
// 计算内部电压
}
*/
#ifndef __ADCS_H__
#define __ADCS_H__
#include "lib.h"
#include "main.h"
typedef enum
{
// IN0 = 0,
// IN1,
// IN2,
// IN3,
// IN4,
// IN5,
// IN6,
IN7,
IN8,
IN9,
IN10,
// IN11,
// IN12,
IN13,
// IN14,
// IN15,
// INVREF,
// INTEMP,
INMAX,
} adc_num_t; // ADC通道号根据cubemax配置的通道数量而定
typedef struct
{
ADC_TypeDef *adc; // ADC外设
DMA_TypeDef *dma; // DMA外设
uint32_t dma_channel; // DMA通道
} adc_t;
extern void adc_init(adc_t handle); // ADC初始化
extern void adc_start(adc_t handle); // 启动ADC转换
extern void adc_completed_state_change(BOOL state); // ADC转换完成状态改变
extern BOOL adc_completed(void); // ADC转换完成
extern uint16_t adc_get_result_average(uint8_t adc_num); // 获取ADC转换结果
extern uint16_t adc_get_result0(uint8_t in_num); // 获取ADC转换结果
extern int32_t compute_temperature(uint16_t measure); // 计算内部温度
extern int32_t compute_value_local(uint16_t measure); // 计算内部电压
extern void adc_convert_callback(adc_t handle); // ADC转换完成回调函数
#endif // __ADCS_H__