Hello. I would like to create a struct / impl which takes two instances of UART peripherals as arguments.
Looking into the source code of the hal, it seems that the trait I need to use is Instance but I have failed to implement this.
To explain further, here is where the instances are created in my main.rs file.
let mut serial0 = Uart::new_with_config(peripherals.UART0, config, Some(sZeroPins), &clocks);
let mut serial1 = Uart::new_with_config(peripherals.UART1, config, Some(sOnePins), &clocks);
The object I would like to create would be instantiated like so:
let mut network = Network::new(serial0, serial1);
When I try to do this, the compiler gives me the following error:
the trait `_esp_hal_uart_Instance` is not implemented for `esp32c3_hal::Uart<'_, esp32c3_hal::peripherals::UART0>
This is the code in the module I am creating:
use esp32c3_hal::uart::*;
pub struct Network<INPUT, OUTPUT>
where
INPUT: Instance,
OUTPUT: Instance
{
input: INPUT,
output: OUTPUT
}
impl<INPUT, OUTPUT> Network<INPUT, OUTPUT>
where
INPUT: Instance,
OUTPUT: Instance
{
pub fn new(input: INPUT, output: OUTPUT) -> Self {
Network {
input,
output
}
}
}
When I try to call functions such as this:
for b in b"Forwarded CMD\n" {
self.input.write(*b).ok
}
I get the following error:
impl<INPUT, OUTPUT> Network<INPUT, OUTPUT>
| ----- method `write` not found for this type parameter
...
41 | self.input.write(*b).ok();
| ^^^^^ method not found in `INPUT`
The Instance trait is defined here: https://github.com/esp-rs/esp-hal/blob/main/esp-hal/src/uart.rs#L930