1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #ifndef __BSP_ADC_H__
- #define __BSP_ADC_H__
- /*********************************************************************
- * INCLUDES
- */
- #include <stdbool.h>
- #include <stdint.h>
- #include <string.h>
- #include "sdk_common.h"
- #include "SEGGER_RTT.h"
- #include "usr_config.h"
- #include "nrf_gpio.h"
- #include "nrf_pwr_mgmt.h"
- #include "nrf_drv_saadc.h"
- /*********************************************************************
- * DEFINITIONS
- */
- //ERROR CODE
- #define ADC_OP_SUCCESS 0x00 //adc操作成功
- #define ADC_ERR_INIT_PIN 0x01 //该引脚已初始化
- #define ADC_ERR_INIT_CHANNEL 0x02 //该通道已初始化
- #define ADC_ERR_INIT_CONGESTION 0x03 //有效通道已全部初始化
- #define ADC_ERR_REMOVE_PIN_CHANNEL 0x04 //移除通道和引脚失败
- #define ADC_ERR_READ_NO_CHANNEL 0x05 //无配置通道,读取失败
- #define ADC_ERR_READ_TIMEOUT 0x06 //读取adc超时
- #define ADC_ERR_READ_FAIL 0x07 //读取adc失败
- #define ADC_ERR_READ_BUSY 0x08 //BUSY忙碌
- /*********************************************************************
- * STRUCTION
- */
- typedef void (*bsp_adc_read_cb)(int16_t adc_value);
- /*********************************************************************
- * API
- */
-
- //初始化ADC引脚和通道
- uint32_t ADC_SetPinChannel(uint32_t pin, uint32_t channel,nrf_gpio_pin_pull_t pin_pull);
- //移除已初始化ADC引脚和通道
- uint32_t ADC_RemovePinChannel(uint32_t pin, uint32_t channel);
- //ADC初始化
- void ADC_Initialize(void);
- //ADC读取
- uint32_t ADC_Read(uint32_t channel, int16_t *p_adc_value);
- //ADC回调读取
- uint32_t ADC_Read_CallBack_Once(uint32_t channel, bsp_adc_read_cb cb);
- //开启ADC,与初始化没有区别,为了与Disable成对出现
- void ADC_Enable(void);
- //禁用ADC
- void ADC_Disable(void);
- uint32_t ADC_ReadChargePin(uint32_t channel);
- uint8_t bsp_Get_ChargePinADC(int16_t *adc);
- #endif
|