Skip to content

ADC API does not allow non-unit channels #110

Closed
@chrysn

Description

@chrysn

I'm just implementing the unproven ADC traits for RIOT and found an issue with Channel::channel:

As the channel() function does not even take a &self reference, there can't be implementations of it that are not fully contained in the type (ie. only really works for zero-sized types). Now the zero-sized types are a major plus of embedded Rust, but this signature precludes the use of eg. numeric channels as would be convenient when wrapping an operating system's ADCs.

I suggest adding a &self or &mut self argument to the .channel() function to make it usable as a method.

I don't understand the rationale behind there not being a self argument in or the existence of the channel method at all there in the first place, so I can't tell what it breaks. The example in the OneShot trait would need to say _pin.channel() instead of PIN::channel() -- but also there I don't see the rationale for not doing that in the first place.

(For the RIOT wrappers, until I can publish the code I'd like to point to, things look like this:

pub struct ADCLine(i32); // You'd get that from the OS on the long run; right now the int is pub
impl Channel<ADC> for ADCLine {
    type ID = i32;
    fn channel() -> i32 { unimplemented!() }
}

impl OneShot<ADC, i32, ADCLine> for ADC {
    fn read(&mut self, pin: &mut ADCLine) {
        unsafe { riot_sys::adc_init(pin.0) };
        ...
    }
}

)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions