Skip to content

ESP32: Cannot use InputOnlyAnalog gpio pins #388

Closed
@Alex-Vining

Description

@Alex-Vining

I'm having trouble trying to setup the read-only analog pins(GPIO34-39) on the esp32. As far as I can tell this is the only implementation of the to_analog() method that you would use to create a AdcPin to interface with an adc. As far as I can tell this trait is only implemented for the IsOutputPin trait which the read-only pins don't have.

Here is example code to reproduce it issue:

#![no_std]
#![no_main]

use esp32_hal::{
    clock::ClockControl, peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, IO
};
use esp_backtrace as _;
#[xtensa_lx_rt::entry]
fn main() -> ! {
    let peripherals = Peripherals::take();
    let system = peripherals.DPORT.split();
    let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

    // Disable the RTC and TIMG watchdog timers
    let mut rtc = Rtc::new(peripherals.RTC_CNTL);
    let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
    let mut wdt0 = timer_group0.wdt;
    let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks);
    let mut wdt1 = timer_group1.wdt;

    rtc.rwdt.disable();
    wdt0.disable();
    wdt1.disable();

    let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);

    io.pins.gpio34.into_analog();
    io.pins.gpio35.into_analog();
    io.pins.gpio36.into_analog();
    io.pins.gpio37.into_analog();
    io.pins.gpio38.into_analog();
    io.pins.gpio39.into_analog();

    loop {
        
    }
}

This is the error message:

the method `into_analog` exists for struct `GpioPin<esp32_hal::gpio::Unknown, Bank1GpioRegisterAccess, DualCoreInteruptStatusRegisterAccessBank1, InputOnlyAnalogPinType, Gpio34Signals, 34>`, but its trait bounds were not satisfied
the following trait bounds were not satisfied:
`InputOnlyAnalogPinType: IsOutputPin`rustcClick for full compiler diagnostic
gpio.rs(554, 1): doesn't satisfy `InputOnlyAnalogPinType: IsOutputPin`

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions