adc.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-05-07 aozima the first version
  9. * 2018-11-16 Ernest Chen add finsh command and update adc function
  10. * 2022-05-11 Stanley Lwin add finsh voltage conversion command
  11. */
  12. #ifndef __ADC_H__
  13. #define __ADC_H__
  14. #include <rtthread.h>
  15. struct rt_adc_device;
  16. struct rt_adc_ops
  17. {
  18. rt_err_t (*enabled)(struct rt_adc_device *device, rt_uint32_t channel, rt_bool_t enabled);
  19. rt_err_t (*convert)(struct rt_adc_device *device, rt_uint32_t channel, rt_uint32_t *value);
  20. rt_uint8_t (*get_resolution)(struct rt_adc_device *device);
  21. rt_int16_t (*get_vref) (struct rt_adc_device *device);
  22. };
  23. struct rt_adc_device
  24. {
  25. struct rt_device parent;
  26. const struct rt_adc_ops *ops;
  27. };
  28. typedef struct rt_adc_device *rt_adc_device_t;
  29. typedef enum
  30. {
  31. RT_ADC_CMD_ENABLE = RT_DEVICE_CTRL_BASE(ADC) + 1,
  32. RT_ADC_CMD_DISABLE = RT_DEVICE_CTRL_BASE(ADC) + 2,
  33. RT_ADC_CMD_GET_RESOLUTION = RT_DEVICE_CTRL_BASE(ADC) + 3, /* get the resolution in bits */
  34. RT_ADC_CMD_GET_VREF = RT_DEVICE_CTRL_BASE(ADC) + 4, /* get reference voltage */
  35. } rt_adc_cmd_t;
  36. rt_err_t rt_hw_adc_register(rt_adc_device_t adc,const char *name, const struct rt_adc_ops *ops, const void *user_data);
  37. rt_uint32_t rt_adc_read(rt_adc_device_t dev, rt_uint32_t channel);
  38. rt_err_t rt_adc_enable(rt_adc_device_t dev, rt_uint32_t channel);
  39. rt_err_t rt_adc_disable(rt_adc_device_t dev, rt_uint32_t channel);
  40. rt_int16_t rt_adc_voltage(rt_adc_device_t dev, rt_uint32_t channel);
  41. #endif /* __ADC_H__ */