So as I’m learning rust so I wanted to write a wrapper for uart in stm32l0xx-hal
as understand it, the error I keep getting is the USART template in impl is different to struct declaration
the code:
pub struct Uart<USART, TX, RX> {
_tx: serial::Tx<USART>,
_rx: serial::Rx<USART>,
_tx_pin: TX,
_rx_pin: RX
}
impl<USART: serial::Serial2Ext<TX,RX>, TX, RX> Uart<USART, TX,RX> {
pub fn new
(usart: USART, mut rcc: rcc::Rcc, tx_pin: TX, rx_pin: RX) -> Self {
let serial = usart
.usart(tx_pin, rx_pin, serial::Config::default(), &mut rcc)
.unwrap();
let (tx, rx) = serial.split();
Uart{
_tx : tx, // <- error
_rx : rx, // <- error
_tx_pin : tx_pin,
_rx_pin : rx_pin
}
}
}
the error:
error[E0308]: mismatched types
--> src/uart.rs:28:19
|
17 | impl<USART: serial::Serial2Ext<TX,RX>, TX, RX> Uart<USART, TX,RX> {
| ----- expected this type parameter
...
28 | _tx : tx,
| ^^ expected `Tx<USART>`, found `Tx<USART2>`
|
= note: expected struct `stm32l0xx_hal::serial::Tx<USART>`
found struct `stm32l0xx_hal::serial::Tx<stm32l0xx_hal::serial::USART2>`
stm32l0xx_hal::serial::USART2
– is the type of usart that I pass to the new function
New contributor
Hugo Balls is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.