dac.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-06-19 thread-liu the first version
  9. */
  10. #ifndef __DAC_H__
  11. #define __DAC_H__
  12. #include <rtthread.h>
  13. struct rt_dac_device;
  14. struct rt_dac_ops
  15. {
  16. rt_err_t (*disabled)(struct rt_dac_device *device, rt_uint32_t channel);
  17. rt_err_t (*enabled)(struct rt_dac_device *device, rt_uint32_t channel);
  18. rt_err_t (*convert)(struct rt_dac_device *device, rt_uint32_t channel, rt_uint32_t *value);
  19. rt_uint8_t (*get_resolution)(struct rt_dac_device *device);
  20. };
  21. struct rt_dac_device
  22. {
  23. struct rt_device parent;
  24. const struct rt_dac_ops *ops;
  25. };
  26. typedef struct rt_dac_device *rt_dac_device_t;
  27. typedef enum
  28. {
  29. RT_DAC_CMD_ENABLE = RT_DEVICE_CTRL_BASE(DAC) + 0,
  30. RT_DAC_CMD_DISABLE = RT_DEVICE_CTRL_BASE(DAC) + 1,
  31. RT_DAC_CMD_GET_RESOLUTION = RT_DEVICE_CTRL_BASE(DAC) + 2,
  32. } rt_dac_cmd_t;
  33. rt_err_t rt_hw_dac_register(rt_dac_device_t dac,const char *name, const struct rt_dac_ops *ops, const void *user_data);
  34. rt_err_t rt_dac_write(rt_dac_device_t dev, rt_uint32_t channel, rt_uint32_t value);
  35. rt_err_t rt_dac_enable(rt_dac_device_t dev, rt_uint32_t channel);
  36. rt_err_t rt_dac_disable(rt_dac_device_t dev, rt_uint32_t channel);
  37. #endif /* __dac_H__ */