Skip to content

fix: add adc ref to rp channel creation funcs #4559

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions embassy-rp/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct Channel<'p>(Source<'p>);

impl<'p> Channel<'p> {
/// Create a new ADC channel from pin with the provided [Pull] configuration.
pub fn new_pin(pin: Peri<'p, impl AdcPin + 'p>, pull: Pull) -> Self {
pub fn new_pin(_adc: &Adc<'_, impl Mode>, pin: Peri<'p, impl AdcPin + 'p>, pull: Pull) -> Self {
pin.pad_ctrl().modify(|w| {
#[cfg(feature = "_rp235x")]
w.set_iso(false);
Expand All @@ -51,7 +51,7 @@ impl<'p> Channel<'p> {
}

/// Create a new ADC channel for the internal temperature sensor.
pub fn new_temp_sensor(s: Peri<'p, ADC_TEMP_SENSOR>) -> Self {
pub fn new_temp_sensor(_adc: &Adc<'_, impl Mode>, s: Peri<'p, ADC_TEMP_SENSOR>) -> Self {
let r = pac::ADC;
r.cs().write_set(|w| w.set_ts_en(true));
Self(Source::TempSensor(s))
Expand Down
8 changes: 4 additions & 4 deletions examples/rp/src/bin/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ async fn main(_spawner: Spawner) {
let p = embassy_rp::init(Default::default());
let mut adc = Adc::new(p.ADC, Irqs, Config::default());

let mut p26 = Channel::new_pin(p.PIN_26, Pull::None);
let mut p27 = Channel::new_pin(p.PIN_27, Pull::None);
let mut p28 = Channel::new_pin(p.PIN_28, Pull::None);
let mut ts = Channel::new_temp_sensor(p.ADC_TEMP_SENSOR);
let mut p26 = Channel::new_pin(&adc, p.PIN_26, Pull::None);
let mut p27 = Channel::new_pin(&adc, p.PIN_27, Pull::None);
let mut p28 = Channel::new_pin(&adc, p.PIN_28, Pull::None);
let mut ts = Channel::new_temp_sensor(&adc, p.ADC_TEMP_SENSOR);

loop {
let level = adc.read(&mut p26).await.unwrap();
Expand Down
10 changes: 5 additions & 5 deletions examples/rp/src/bin/adc_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ async fn main(_spawner: Spawner) {

let mut adc = Adc::new(p.ADC, Irqs, Config::default());
let mut dma = p.DMA_CH0;
let mut pin = Channel::new_pin(p.PIN_26, Pull::Up);
let mut pin = Channel::new_pin(&adc, p.PIN_26, Pull::Up);
let mut pins = [
Channel::new_pin(p.PIN_27, Pull::Down),
Channel::new_pin(p.PIN_28, Pull::None),
Channel::new_pin(p.PIN_29, Pull::Up),
Channel::new_temp_sensor(p.ADC_TEMP_SENSOR),
Channel::new_pin(&adc, p.PIN_27, Pull::Down),
Channel::new_pin(&adc, p.PIN_28, Pull::None),
Channel::new_pin(&adc, p.PIN_29, Pull::Up),
Channel::new_temp_sensor(&adc, p.ADC_TEMP_SENSOR),
];

const BLOCK_SIZE: usize = 100;
Expand Down
2 changes: 1 addition & 1 deletion examples/rp/src/bin/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn main(spawner: Spawner) {
let p = embassy_rp::init(Default::default());

let adc = Adc::new_blocking(p.ADC, Default::default());
let p26 = adc::Channel::new_pin(p.PIN_26, Pull::None);
let p26 = adc::Channel::new_pin(&adc, p.PIN_26, Pull::None);
ADC.lock(|a| a.borrow_mut().replace((adc, p26)));

let pwm = Pwm::new_output_b(p.PWM_SLICE4, p.PIN_25, Default::default());
Expand Down
2 changes: 1 addition & 1 deletion examples/rp/src/bin/orchestrate_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ pub async fn usb_power(_spawner: Spawner, r: Vbus) {
pub async fn vsys_voltage(_spawner: Spawner, r: Vsys) {
let mut adc = Adc::new(r.adc, Irqs, Config::default());
let vsys_in = r.pin_29;
let mut channel = Channel::new_pin(vsys_in, Pull::None);
let mut channel = Channel::new_pin(&adc, vsys_in, Pull::None);
let sender = EVENT_CHANNEL.sender();

loop {
Expand Down
6 changes: 4 additions & 2 deletions examples/rp/src/bin/zerocopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ async fn main(spawner: Spawner) {
let p = embassy_rp::init(Default::default());
info!("Here we go!");

let adc = Adc::new(p.ADC, Irqs, Config::default());
let pin = adc::Channel::new_pin(&adc, p.PIN_29, Pull::None);
let adc_parts = AdcParts {
adc: Adc::new(p.ADC, Irqs, Config::default()),
pin: adc::Channel::new_pin(p.PIN_29, Pull::None),
adc,
pin,
dma: p.DMA_CH0,
};

Expand Down
Loading