6#ifdef CYW43_USES_VSYS_PIN
7#include "pico/cyw43_arch.h"
9#include <hardware/adc.h>
15#define PICO_VSYS_PIN 29
20static const char *
const TAG =
"adc";
32#if defined(PICO_RP2350) && !defined(PICO_RP2350A)
33#error "PICO_RP2350A is not defined, so the RP2350 die is unknown and the temperature ADC channel cannot be chosen"
35#if defined(PICO_RP2350) && !PICO_RP2350A
36static constexpr uint8_t TEMPERATURE_ADC_INPUT = 8;
38static constexpr uint8_t TEMPERATURE_ADC_INPUT = 4;
42 static bool initialized =
false;
50 LOG_SENSOR(
"",
"ADC Sensor",
this);
52 ESP_LOGCONFIG(TAG,
" Pin: Temperature");
54#ifdef USE_ADC_SENSOR_VCC
55 ESP_LOGCONFIG(TAG,
" Pin: VCC");
57 LOG_PIN(
" Pin: ", this->
pin_);
64 LOG_UPDATE_INTERVAL(
this);
72 adc_set_temp_sensor_enabled(
true);
74 adc_select_input(TEMPERATURE_ADC_INPUT);
80 adc_set_temp_sensor_enabled(
false);
82 return aggr.aggregate();
84 return aggr.aggregate() * 3.3f / 4096.0f;
88#if defined(CYW43_USES_VSYS_PIN) && defined(USE_WIFI)
89 if (pin == PICO_VSYS_PIN) {
102 adc_select_input(pin - 26);
106 aggr.add_sample(
raw);
109#if defined(CYW43_USES_VSYS_PIN) && defined(USE_WIFI)
110 if (pin == PICO_VSYS_PIN) {
116 return aggr.aggregate();
118 float coeff = pin == PICO_VSYS_PIN ? 3.0f : 1.0f;
119 return aggr.aggregate() * 3.3f / 4096.0f * coeff;
virtual uint8_t get_pin() const =0
float sample() override
Perform a single ADC sampling operation and return the measured value.
void setup() override
Set up the ADC sensor by initializing hardware and calibration parameters.
void dump_config() override
Output the configuration details of the ADC sensor for debugging purposes.
SamplingMode sampling_mode_
const LogString * sampling_mode_to_str(SamplingMode mode)
void HOT delay(uint32_t ms)