adc_continuous_internal.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include "sdkconfig.h"
  10. #include "esp_pm.h"
  11. #include "freertos/FreeRTOS.h"
  12. #include "freertos/ringbuf.h"
  13. #include "hal/adc_types.h"
  14. #include "hal/adc_hal.h"
  15. //For DMA
  16. #if SOC_GDMA_SUPPORTED
  17. #include "esp_private/gdma.h"
  18. #elif CONFIG_IDF_TARGET_ESP32S2
  19. #include "hal/spi_types.h"
  20. #elif CONFIG_IDF_TARGET_ESP32
  21. #include "driver/i2s_types.h"
  22. #endif
  23. #include "esp_adc/adc_filter.h"
  24. #include "esp_adc/adc_monitor.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. typedef enum {
  29. ADC_FSM_INIT,
  30. ADC_FSM_STARTED,
  31. } adc_fsm_t;
  32. typedef enum {
  33. ADC_MONITOR_FSM_INIT,
  34. ADC_MONITOR_FSM_ENABLED,
  35. } adc_monitor_fsm_t;
  36. /*---------------------------------------------------------------
  37. Driver Context
  38. ---------------------------------------------------------------*/
  39. typedef struct adc_iir_filter_t adc_iir_filter_t;
  40. typedef struct adc_monitor_t adc_monitor_t;
  41. typedef struct adc_continuous_ctx_t adc_continuous_ctx_t;
  42. /**
  43. * @brief ADC iir filter context
  44. */
  45. struct adc_iir_filter_t {
  46. adc_digi_iir_filter_t filter_id; // Filter ID
  47. adc_continuous_iir_filter_config_t cfg; //filter configuration
  48. adc_continuous_ctx_t *continuous_ctx; //ADC continuous driver context
  49. };
  50. /**
  51. * @brief ADC digi monitor context
  52. */
  53. struct adc_monitor_t {
  54. adc_monitor_id_t monitor_id; // monitor unit number
  55. adc_monitor_fsm_t fsm; // monitor status indicator
  56. adc_monitor_config_t config; // monitor configuration
  57. adc_monitor_evt_cbs_t cbs; // monitor thresh callbacks
  58. void *user_data; // user data pointer to use in cb
  59. };
  60. /**
  61. * @brief ADC continuous driver context
  62. */
  63. struct adc_continuous_ctx_t {
  64. uint8_t *rx_dma_buf; //dma buffer
  65. adc_hal_dma_ctx_t hal; //hal context
  66. #if SOC_GDMA_SUPPORTED
  67. gdma_channel_handle_t rx_dma_channel; //dma rx channel handle
  68. #elif CONFIG_IDF_TARGET_ESP32S2
  69. spi_host_device_t spi_host; //ADC uses this SPI DMA
  70. #elif CONFIG_IDF_TARGET_ESP32
  71. i2s_port_t i2s_host; //ADC uses this I2S DMA
  72. #endif
  73. intr_handle_t dma_intr_hdl; //DMA Interrupt handler
  74. RingbufHandle_t ringbuf_hdl; //RX ringbuffer handler
  75. void* ringbuf_storage; //Ringbuffer storage buffer
  76. void* ringbuf_struct; //Ringbuffer structure buffer
  77. size_t ringbuf_size; //Ringbuffer size
  78. intptr_t rx_eof_desc_addr; //eof descriptor address of RX channel
  79. adc_fsm_t fsm; //ADC continuous mode driver internal states
  80. bool use_adc1; //1: ADC unit1 will be used; 0: ADC unit1 won't be used.
  81. bool use_adc2; //1: ADC unit2 will be used; 0: ADC unit2 won't be used. This determines whether to acquire sar_adc2_mutex lock or not.
  82. adc_atten_t adc1_atten; //Attenuation for ADC1. On this chip each ADC can only support one attenuation.
  83. adc_atten_t adc2_atten; //Attenuation for ADC2. On this chip each ADC can only support one attenuation.
  84. adc_hal_digi_ctrlr_cfg_t hal_digi_ctrlr_cfg; //Hal digital controller configuration
  85. adc_continuous_evt_cbs_t cbs; //Callbacks
  86. void *user_data; //User context
  87. esp_pm_lock_handle_t pm_lock; //For power management
  88. struct {
  89. uint32_t flush_pool: 1; //Flush the internal pool when the pool is full. With this flag, the `on_pool_ovf` event will not happen.
  90. } flags;
  91. #if SOC_ADC_DIG_IIR_FILTER_SUPPORTED
  92. adc_iir_filter_t *iir_filter[SOC_ADC_DIGI_IIR_FILTER_NUM]; //ADC IIR filter context
  93. #endif
  94. #if SOC_ADC_MONITOR_SUPPORTED
  95. adc_monitor_t *adc_monitor[SOC_ADC_DIGI_MONITOR_NUM]; // adc monitor context
  96. #endif
  97. };
  98. #ifdef __cplusplus
  99. }
  100. #endif