adc.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright 2023 Dual Tachyon
  2. * https://github.com/DualTachyon
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef DRIVER_ADC_H
  17. #define DRIVER_ADC_H
  18. #include <stdbool.h>
  19. #include <stdint.h>
  20. enum ADC_CH_MASK {
  21. ADC_CH0 = 0x0001U,
  22. ADC_CH1 = 0x0002U,
  23. ADC_CH2 = 0x0004U,
  24. ADC_CH3 = 0x0008U,
  25. ADC_CH4 = 0x0010U,
  26. ADC_CH5 = 0x0020U,
  27. ADC_CH6 = 0x0040U,
  28. ADC_CH7 = 0x0080U,
  29. ADC_CH8 = 0x0100U,
  30. ADC_CH9 = 0x0200U,
  31. ADC_CH10 = 0x0400U,
  32. ADC_CH11 = 0x0800U,
  33. ADC_CH12 = 0x1000U,
  34. ADC_CH13 = 0x2000U,
  35. ADC_CH14 = 0x4000U,
  36. ADC_CH15 = 0x8000U,
  37. };
  38. typedef enum ADC_CH_MASK ADC_CH_MASK;
  39. typedef struct {
  40. uint16_t EXTTRIG_SEL;
  41. uint16_t IE_CHx_EOC;
  42. ADC_CH_MASK CH_SEL;
  43. uint8_t CLK_SEL;
  44. uint8_t AVG;
  45. uint8_t CONT;
  46. uint8_t MEM_MODE;
  47. uint8_t SMPL_CLK;
  48. uint8_t SMPL_SETUP;
  49. uint8_t SMPL_WIN;
  50. uint8_t ADC_TRIG;
  51. uint8_t DMA_EN;
  52. uint8_t IE_FIFO_HFULL;
  53. uint8_t IE_FIFO_FULL;
  54. bool CALIB_OFFSET_VALID;
  55. bool CALIB_KD_VALID;
  56. uint8_t _pad[1];
  57. } ADC_Config_t;
  58. uint8_t ADC_GetChannelNumber(ADC_CH_MASK Mask);
  59. void ADC_Disable(void);
  60. void ADC_Enable(void);
  61. void ADC_SoftReset(void);
  62. uint32_t ADC_GetClockConfig(void);
  63. void ADC_Configure(ADC_Config_t *pAdc);
  64. void ADC_Start(void);
  65. bool ADC_CheckEndOfConversion(ADC_CH_MASK Mask);
  66. uint16_t ADC_GetValue(ADC_CH_MASK Mask);
  67. #endif