drv_adc.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright (c) 2023, Canaan Bright Sight Co., Ltd
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are met:
  5. * 1. Redistributions of source code must retain the above copyright
  6. * notice, this list of conditions and the following disclaimer.
  7. * 2. Redistributions in binary form must reproduce the above copyright
  8. * notice, this list of conditions and the following disclaimer in the
  9. * documentation and/or other materials provided with the distribution.
  10. *
  11. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  12. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  13. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  15. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  16. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  21. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. /*
  26. * Copyright (c) 2006-2025 RT-Thread Development Team
  27. *
  28. * SPDX-License-Identifier: Apache-2.0
  29. */
  30. #ifndef __DRV_ADC__
  31. #define __DRV_ADC__
  32. #include "board.h"
  33. #define K230_ADC_NAME "adc"
  34. #define ADC_MAX_CHANNEL 6
  35. #define ADC_MAX_DMA_CHN 3
  36. struct k230_adc_regs
  37. {
  38. rt_uint32_t trim_reg; /**< 0x00 */
  39. rt_uint32_t cfg_reg; /**< 0x04 */
  40. rt_uint32_t mode_reg; /**< 0x08 */
  41. rt_uint32_t thsd_reg; /**< 0x0c */
  42. rt_uint32_t dma_intr_reg; /**< 0x10 */
  43. rt_uint32_t data_reg[ADC_MAX_CHANNEL]; /**< 0x14~0x28 */
  44. rt_uint32_t data_dma[ADC_MAX_DMA_CHN]; /**< 0x2c~0x34 */
  45. };
  46. struct k230_adc_chan
  47. {
  48. rt_uint32_t chn_num;
  49. rt_int8_t enabled;
  50. };
  51. struct k230_adc
  52. {
  53. struct rt_adc_device dev;
  54. struct k230_adc_regs *adc_regs;
  55. struct k230_adc_chan chn[ADC_MAX_CHANNEL];
  56. };
  57. #endif /*__DRV_ADC__*/