-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RSDK-10188] esp-idf v5 ADC APIs #449
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,8 +34,12 @@ use super::analog::Esp32AnalogReader; | |
// TODO(RSDK-10188): Update to ESP-IDF ADC API | ||
#[cfg(esp32)] | ||
use crate::esp32::esp_idf_svc::hal::adc::{ | ||
attenuation::adc_atten_t_ADC_ATTEN_DB_11 as Atten11dB, config::Config, AdcChannelDriver, | ||
AdcDriver, ADC1, | ||
attenuation::DB_11, | ||
oneshot::{ | ||
config::{AdcChannelConfig, Calibration}, | ||
AdcChannelDriver, AdcDriver, | ||
}, | ||
ADC1, | ||
}; | ||
|
||
use crate::esp32::esp_idf_svc::hal::gpio::InterruptType; | ||
|
@@ -84,104 +88,98 @@ impl EspBoard { | |
let analogs: Result<Vec<AnalogReaderType<u16>>, BoardError> = analogs | ||
.iter() | ||
.map(|v| { | ||
let adc1 = Arc::new(Mutex::new(AdcDriver::new( | ||
unsafe { ADC1::new() }, | ||
&Config::new().calibration(true), | ||
)?)); | ||
let adc1 = AdcDriver::new(unsafe { ADC1::new() })?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure how this would work, you would be configuring the adc for each analog reader so if you have more than one can we actually instantiate more that one ADC? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was porting the same logic from the previous implementation, however we determined a few things:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as a follow-up, we should probably either: |
||
let config = AdcChannelConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's new and cool might be a candidate for config |
||
attenuation: DB_11, | ||
calibration: Calibration::Line, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does that do and why do we set it to line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously we did There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sense 👌 |
||
..Default::default() | ||
}; | ||
let chan: Result<AnalogReaderType<u16>, BoardError> = match v.pin { | ||
32 => { | ||
let p: AnalogReaderType<u16> = | ||
Arc::new(Mutex::new(Esp32AnalogReader::new( | ||
v.name.to_string(), | ||
AdcChannelDriver::<Atten11dB, _>::new(unsafe { | ||
AdcChannelDriver::new(adc1, unsafe { | ||
crate::esp32::esp_idf_svc::hal::gpio::Gpio32::new() | ||
}) | ||
.map_err(BoardError::EspError)?, | ||
adc1, | ||
}, &config) | ||
.map_err(BoardError::EspError)? | ||
))); | ||
Ok(p) | ||
} | ||
33 => { | ||
let p: AnalogReaderType<u16> = | ||
Arc::new(Mutex::new(Esp32AnalogReader::new( | ||
v.name.to_string(), | ||
AdcChannelDriver::<Atten11dB, _>::new(unsafe { | ||
AdcChannelDriver::new(adc1, unsafe { | ||
crate::esp32::esp_idf_svc::hal::gpio::Gpio33::new() | ||
}) | ||
.map_err(BoardError::EspError)?, | ||
adc1, | ||
}, &config) | ||
.map_err(BoardError::EspError)? | ||
))); | ||
Ok(p) | ||
} | ||
34 => { | ||
let p: AnalogReaderType<u16> = | ||
Arc::new(Mutex::new(Esp32AnalogReader::new( | ||
v.name.to_string(), | ||
AdcChannelDriver::<Atten11dB, _>::new(unsafe { | ||
AdcChannelDriver::new(adc1, unsafe { | ||
crate::esp32::esp_idf_svc::hal::gpio::Gpio34::new() | ||
}) | ||
.map_err(BoardError::EspError)?, | ||
adc1, | ||
}, &config) | ||
.map_err(BoardError::EspError)? | ||
))); | ||
Ok(p) | ||
} | ||
35 => { | ||
let p: AnalogReaderType<u16> = | ||
Arc::new(Mutex::new(Esp32AnalogReader::new( | ||
v.name.to_string(), | ||
AdcChannelDriver::<Atten11dB, _>::new(unsafe { | ||
AdcChannelDriver::new(adc1, unsafe { | ||
crate::esp32::esp_idf_svc::hal::gpio::Gpio35::new() | ||
}) | ||
.map_err(BoardError::EspError)?, | ||
adc1, | ||
}, &config) | ||
.map_err(BoardError::EspError)? | ||
))); | ||
Ok(p) | ||
} | ||
36 => { | ||
let p: AnalogReaderType<u16> = | ||
Arc::new(Mutex::new(Esp32AnalogReader::new( | ||
v.name.to_string(), | ||
AdcChannelDriver::<Atten11dB, _>::new(unsafe { | ||
AdcChannelDriver::new(adc1, unsafe { | ||
crate::esp32::esp_idf_svc::hal::gpio::Gpio36::new() | ||
}) | ||
.map_err(BoardError::EspError)?, | ||
adc1, | ||
}, &config) | ||
.map_err(BoardError::EspError)? | ||
))); | ||
Ok(p) | ||
} | ||
37 => { | ||
let p: AnalogReaderType<u16> = | ||
Arc::new(Mutex::new(Esp32AnalogReader::new( | ||
v.name.to_string(), | ||
AdcChannelDriver::<Atten11dB, _>::new(unsafe { | ||
AdcChannelDriver::new(adc1, unsafe { | ||
crate::esp32::esp_idf_svc::hal::gpio::Gpio37::new() | ||
}) | ||
.map_err(BoardError::EspError)?, | ||
adc1, | ||
}, &config) | ||
.map_err(BoardError::EspError)? | ||
))); | ||
Ok(p) | ||
} | ||
38 => { | ||
let p: AnalogReaderType<u16> = | ||
Arc::new(Mutex::new(Esp32AnalogReader::new( | ||
v.name.to_string(), | ||
AdcChannelDriver::<Atten11dB, _>::new(unsafe { | ||
AdcChannelDriver::new(adc1, unsafe { | ||
crate::esp32::esp_idf_svc::hal::gpio::Gpio38::new() | ||
}) | ||
.map_err(BoardError::EspError)?, | ||
adc1, | ||
}, &config) | ||
.map_err(BoardError::EspError)? | ||
))); | ||
Ok(p) | ||
} | ||
39 => { | ||
let p: AnalogReaderType<u16> = | ||
Arc::new(Mutex::new(Esp32AnalogReader::new( | ||
v.name.to_string(), | ||
AdcChannelDriver::<Atten11dB, _>::new(unsafe { | ||
AdcChannelDriver::new(adc1, unsafe { | ||
crate::esp32::esp_idf_svc::hal::gpio::Gpio39::new() | ||
}) | ||
.map_err(BoardError::EspError)?, | ||
adc1, | ||
}, &config) | ||
.map_err(BoardError::EspError)? | ||
))); | ||
Ok(p) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the increase of complexity of types parameters, is there a way we can make it more readable. Like storing only the driver and building the channel on each read? Is building a channel expensive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that may actually make the type even more complex.
At the very least the
new
input parameters would either need to be:(name: String, driver: AdcDriver<'d, T::Adc>, pin: impl Peripheral<P = T> + 'd, config: AdcChannelConfig)
if we want to create theAdcChannelDriver
on-demand(name: String, adc: impl Adc, pin: impl Peripheral<P = T> + 'd, config: AdcChannelConfig)
if we want to handle both theAdcDriver
andAdcChannelDriver
initialization in theEsp32AnalogReader
.with the struct holding the proper generics for whichever route we go (storing the pin, adc, adcdriver, etc)