stm32/usart: return error instead of panicking on bad baudrate.
This commit is contained in:
@@ -118,7 +118,7 @@ impl<'d, T: BasicInstance> SetConfig for BufferedUart<'d, T> {
|
||||
type Config = Config;
|
||||
|
||||
fn set_config(&mut self, config: &Self::Config) {
|
||||
self.set_config(config)
|
||||
unwrap!(self.set_config(config))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ impl<'d, T: BasicInstance> SetConfig for BufferedUartRx<'d, T> {
|
||||
type Config = Config;
|
||||
|
||||
fn set_config(&mut self, config: &Self::Config) {
|
||||
self.set_config(config)
|
||||
unwrap!(self.set_config(config))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ impl<'d, T: BasicInstance> SetConfig for BufferedUartTx<'d, T> {
|
||||
type Config = Config;
|
||||
|
||||
fn set_config(&mut self, config: &Self::Config) {
|
||||
self.set_config(config)
|
||||
unwrap!(self.set_config(config))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
|
||||
tx_buffer: &'d mut [u8],
|
||||
rx_buffer: &'d mut [u8],
|
||||
config: Config,
|
||||
) -> BufferedUart<'d, T> {
|
||||
) -> Result<Self, ConfigError> {
|
||||
// UartRx and UartTx have one refcount ea.
|
||||
T::enable();
|
||||
T::enable();
|
||||
@@ -166,7 +166,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
|
||||
tx_buffer: &'d mut [u8],
|
||||
rx_buffer: &'d mut [u8],
|
||||
config: Config,
|
||||
) -> BufferedUart<'d, T> {
|
||||
) -> Result<Self, ConfigError> {
|
||||
into_ref!(cts, rts);
|
||||
|
||||
// UartRx and UartTx have one refcount ea.
|
||||
@@ -194,7 +194,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
|
||||
tx_buffer: &'d mut [u8],
|
||||
rx_buffer: &'d mut [u8],
|
||||
config: Config,
|
||||
) -> BufferedUart<'d, T> {
|
||||
) -> Result<Self, ConfigError> {
|
||||
into_ref!(de);
|
||||
|
||||
// UartRx and UartTx have one refcount ea.
|
||||
@@ -217,7 +217,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
|
||||
tx_buffer: &'d mut [u8],
|
||||
rx_buffer: &'d mut [u8],
|
||||
config: Config,
|
||||
) -> BufferedUart<'d, T> {
|
||||
) -> Result<Self, ConfigError> {
|
||||
into_ref!(_peri, rx, tx);
|
||||
|
||||
let state = T::buffered_state();
|
||||
@@ -230,7 +230,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
|
||||
rx.set_as_af(rx.af_num(), AFType::Input);
|
||||
tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
|
||||
|
||||
configure(r, &config, T::frequency(), T::KIND, true, true);
|
||||
configure(r, &config, T::frequency(), T::KIND, true, true)?;
|
||||
|
||||
r.cr1().modify(|w| {
|
||||
#[cfg(lpuart_v2)]
|
||||
@@ -243,17 +243,17 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
|
||||
T::Interrupt::unpend();
|
||||
unsafe { T::Interrupt::enable() };
|
||||
|
||||
Self {
|
||||
Ok(Self {
|
||||
rx: BufferedUartRx { phantom: PhantomData },
|
||||
tx: BufferedUartTx { phantom: PhantomData },
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn split(self) -> (BufferedUartTx<'d, T>, BufferedUartRx<'d, T>) {
|
||||
(self.tx, self.rx)
|
||||
}
|
||||
|
||||
pub fn set_config(&mut self, config: &Config) {
|
||||
pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
||||
reconfigure::<T>(config)
|
||||
}
|
||||
}
|
||||
@@ -333,7 +333,7 @@ impl<'d, T: BasicInstance> BufferedUartRx<'d, T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_config(&mut self, config: &Config) {
|
||||
pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
||||
reconfigure::<T>(config)
|
||||
}
|
||||
}
|
||||
@@ -407,7 +407,7 @@ impl<'d, T: BasicInstance> BufferedUartTx<'d, T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_config(&mut self, config: &Config) {
|
||||
pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
||||
reconfigure::<T>(config)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user