WMT-GmbH / pn532

no_std implementation of the Pn532 protocol using embedded_hal traits
Apache License 2.0
20 stars 19 forks source link

Documentation examples are using x.ms() methods #1

Closed plaes closed 3 years ago

plaes commented 3 years ago

When attempting to use the examples, code like this: pn532.process(&Request::INLIST_ONE_ISO_A_TARGET, 7, 1000.ms());

Causes errors: can't call methodmson ambiguous numeric type{integer}``

Should these changed to use std::time::Duration::from_millis() instead?

dimpolo commented 3 years ago

Good point.

Most HAL's I've worked with define an extension trait on u32 in their prelude (e.g. stm32f4xx-hal)

The concrete type of the timeout value will depend on the implementation of CountDown.

core::time::Duration would be one possible type but often (especially with no-std) other types are used.

I would like to keep the .ms() call since it doesn't mention a concrete type, but maybe we could provide our own extension trait such as:

use core::time::Duration;

pub trait U64Ext {
    fn ms(self) -> Duration;
}

impl U64Ext for u64 {
    fn ms(self) -> Duration {
        Duration::from_millis(self)
    }
}

Would that work for you?

plaes commented 3 years ago

Yeah, having these would be excellent, as I was trying to use it without HAL (or with basic linux-embedded-hal) and couldn't figure out where to import these definitions (see issue #2 ).