bsp_adc.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef __BSP_ADC_H__
  2. #define __BSP_ADC_H__
  3. /*********************************************************************
  4. * INCLUDES
  5. */
  6. #include <stdbool.h>
  7. #include <stdint.h>
  8. #include <string.h>
  9. #include "sdk_common.h"
  10. #include "SEGGER_RTT.h"
  11. #include "usr_config.h"
  12. #include "nrf_gpio.h"
  13. #include "nrf_pwr_mgmt.h"
  14. #include "nrf_drv_saadc.h"
  15. /*********************************************************************
  16. * DEFINITIONS
  17. */
  18. //ERROR CODE
  19. #define ADC_OP_SUCCESS 0x00 //adc操作成功
  20. #define ADC_ERR_INIT_PIN 0x01 //该引脚已初始化
  21. #define ADC_ERR_INIT_CHANNEL 0x02 //该通道已初始化
  22. #define ADC_ERR_INIT_CONGESTION 0x03 //有效通道已全部初始化
  23. #define ADC_ERR_REMOVE_PIN_CHANNEL 0x04 //移除通道和引脚失败
  24. #define ADC_ERR_READ_NO_CHANNEL 0x05 //无配置通道,读取失败
  25. #define ADC_ERR_READ_TIMEOUT 0x06 //读取adc超时
  26. #define ADC_ERR_READ_FAIL 0x07 //读取adc失败
  27. #define ADC_ERR_READ_BUSY 0x08 //BUSY忙碌
  28. /*********************************************************************
  29. * STRUCTION
  30. */
  31. typedef void (*bsp_adc_read_cb)(int16_t adc_value);
  32. /*********************************************************************
  33. * API
  34. */
  35. //初始化ADC引脚和通道
  36. uint32_t ADC_SetPinChannel(uint32_t pin, uint32_t channel,nrf_gpio_pin_pull_t pin_pull);
  37. //移除已初始化ADC引脚和通道
  38. uint32_t ADC_RemovePinChannel(uint32_t pin, uint32_t channel);
  39. //ADC初始化
  40. void ADC_Initialize(void);
  41. //ADC读取
  42. uint32_t ADC_Read(uint32_t channel, int16_t *p_adc_value);
  43. //ADC回调读取
  44. uint32_t ADC_Read_CallBack_Once(uint32_t channel, bsp_adc_read_cb cb);
  45. //开启ADC,与初始化没有区别,为了与Disable成对出现
  46. void ADC_Enable(void);
  47. //禁用ADC
  48. void ADC_Disable(void);
  49. uint32_t ADC_ReadChargePin(uint32_t channel);
  50. uint8_t bsp_Get_ChargePinADC(int16_t *adc);
  51. #endif