stm32: update set_config
This commit is contained in:
parent
d2a2734752
commit
05218a52e6
@ -91,6 +91,7 @@ fn main() {
|
|||||||
struct SplitFeature {
|
struct SplitFeature {
|
||||||
feature_name: String,
|
feature_name: String,
|
||||||
pin_name_with_c: String,
|
pin_name_with_c: String,
|
||||||
|
#[cfg(feature = "_split-pins-enabled")]
|
||||||
pin_name_without_c: String,
|
pin_name_without_c: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,7 +518,8 @@ impl Timings {
|
|||||||
|
|
||||||
impl<'d, T: Instance> SetConfig for I2c<'d, T> {
|
impl<'d, T: Instance> SetConfig for I2c<'d, T> {
|
||||||
type Config = Hertz;
|
type Config = Hertz;
|
||||||
fn set_config(&mut self, config: &Self::Config) {
|
type ConfigError = ();
|
||||||
|
fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> {
|
||||||
let timings = Timings::new(T::frequency(), *config);
|
let timings = Timings::new(T::frequency(), *config);
|
||||||
T::regs().cr2().modify(|reg| {
|
T::regs().cr2().modify(|reg| {
|
||||||
reg.set_freq(timings.freq);
|
reg.set_freq(timings.freq);
|
||||||
@ -531,5 +532,7 @@ impl<'d, T: Instance> SetConfig for I2c<'d, T> {
|
|||||||
T::regs().trise().modify(|reg| {
|
T::regs().trise().modify(|reg| {
|
||||||
reg.set_trise(timings.trise);
|
reg.set_trise(timings.trise);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1075,7 +1075,8 @@ mod eha {
|
|||||||
|
|
||||||
impl<'d, T: Instance> SetConfig for I2c<'d, T> {
|
impl<'d, T: Instance> SetConfig for I2c<'d, T> {
|
||||||
type Config = Hertz;
|
type Config = Hertz;
|
||||||
fn set_config(&mut self, config: &Self::Config) {
|
type ConfigError = ();
|
||||||
|
fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> {
|
||||||
let timings = Timings::new(T::frequency(), *config);
|
let timings = Timings::new(T::frequency(), *config);
|
||||||
T::regs().timingr().write(|reg| {
|
T::regs().timingr().write(|reg| {
|
||||||
reg.set_presc(timings.prescale);
|
reg.set_presc(timings.prescale);
|
||||||
@ -1084,5 +1085,7 @@ impl<'d, T: Instance> SetConfig for I2c<'d, T> {
|
|||||||
reg.set_sdadel(timings.sdadel);
|
reg.set_sdadel(timings.sdadel);
|
||||||
reg.set_scldel(timings.scldel);
|
reg.set_scldel(timings.scldel);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -982,8 +982,9 @@ impl<'d, T: Instance, C: Channel, W: word::Word> SubBlock<'d, T, C, W> {
|
|||||||
ch.cr2().modify(|w| w.set_mute(value));
|
ch.cr2().modify(|w| w.set_mute(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
/// Reconfigures it with the supplied config.
|
/// Reconfigures it with the supplied config.
|
||||||
pub fn reconfigure(&mut self, _config: Config) {}
|
fn reconfigure(&mut self, _config: Config) {}
|
||||||
|
|
||||||
pub fn get_current_config(&self) -> Config {
|
pub fn get_current_config(&self) -> Config {
|
||||||
Config::default()
|
Config::default()
|
||||||
@ -1056,7 +1057,10 @@ foreach_peripheral!(
|
|||||||
|
|
||||||
impl<'d, T: Instance> SetConfig for Sai<'d, T> {
|
impl<'d, T: Instance> SetConfig for Sai<'d, T> {
|
||||||
type Config = Config;
|
type Config = Config;
|
||||||
fn set_config(&mut self, _config: &Self::Config) {
|
type ConfigError = ();
|
||||||
|
fn set_config(&mut self, _config: &Self::Config) -> Result<(), ()> {
|
||||||
// self.reconfigure(*config);
|
// self.reconfigure(*config);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,7 +323,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reconfigures it with the supplied config.
|
/// Reconfigures it with the supplied config.
|
||||||
pub fn set_config(&mut self, config: Config) {
|
fn set_config(&mut self, config: Config) {
|
||||||
let cpha = config.raw_phase();
|
let cpha = config.raw_phase();
|
||||||
let cpol = config.raw_polarity();
|
let cpol = config.raw_polarity();
|
||||||
|
|
||||||
@ -1061,7 +1061,10 @@ foreach_peripheral!(
|
|||||||
|
|
||||||
impl<'d, T: Instance, Tx, Rx> SetConfig for Spi<'d, T, Tx, Rx> {
|
impl<'d, T: Instance, Tx, Rx> SetConfig for Spi<'d, T, Tx, Rx> {
|
||||||
type Config = Config;
|
type Config = Config;
|
||||||
fn set_config(&mut self, config: &Self::Config) {
|
type ConfigError = ();
|
||||||
|
fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> {
|
||||||
self.set_config(*config);
|
self.set_config(*config);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,25 +116,28 @@ pub struct BufferedUartRx<'d, T: BasicInstance> {
|
|||||||
|
|
||||||
impl<'d, T: BasicInstance> SetConfig for BufferedUart<'d, T> {
|
impl<'d, T: BasicInstance> SetConfig for BufferedUart<'d, T> {
|
||||||
type Config = Config;
|
type Config = Config;
|
||||||
|
type ConfigError = ();
|
||||||
|
|
||||||
fn set_config(&mut self, config: &Self::Config) {
|
fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> {
|
||||||
unwrap!(self.set_config(config))
|
self.set_config(config).map_err(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, T: BasicInstance> SetConfig for BufferedUartRx<'d, T> {
|
impl<'d, T: BasicInstance> SetConfig for BufferedUartRx<'d, T> {
|
||||||
type Config = Config;
|
type Config = Config;
|
||||||
|
type ConfigError = ();
|
||||||
|
|
||||||
fn set_config(&mut self, config: &Self::Config) {
|
fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> {
|
||||||
unwrap!(self.set_config(config))
|
self.set_config(config).map_err(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, T: BasicInstance> SetConfig for BufferedUartTx<'d, T> {
|
impl<'d, T: BasicInstance> SetConfig for BufferedUartTx<'d, T> {
|
||||||
type Config = Config;
|
type Config = Config;
|
||||||
|
type ConfigError = ();
|
||||||
|
|
||||||
fn set_config(&mut self, config: &Self::Config) {
|
fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> {
|
||||||
unwrap!(self.set_config(config))
|
self.set_config(config).map_err(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +256,7 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> {
|
|||||||
(self.tx, self.rx)
|
(self.tx, self.rx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
||||||
reconfigure::<T>(config)
|
reconfigure::<T>(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -333,7 +336,7 @@ impl<'d, T: BasicInstance> BufferedUartRx<'d, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
||||||
reconfigure::<T>(config)
|
reconfigure::<T>(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -407,7 +410,7 @@ impl<'d, T: BasicInstance> BufferedUartTx<'d, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
||||||
reconfigure::<T>(config)
|
reconfigure::<T>(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,10 +181,11 @@ pub struct Uart<'d, T: BasicInstance, TxDma = NoDma, RxDma = NoDma> {
|
|||||||
|
|
||||||
impl<'d, T: BasicInstance, TxDma, RxDma> SetConfig for Uart<'d, T, TxDma, RxDma> {
|
impl<'d, T: BasicInstance, TxDma, RxDma> SetConfig for Uart<'d, T, TxDma, RxDma> {
|
||||||
type Config = Config;
|
type Config = Config;
|
||||||
|
type ConfigError = ();
|
||||||
|
|
||||||
fn set_config(&mut self, config: &Self::Config) {
|
fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> {
|
||||||
unwrap!(self.tx.set_config(config));
|
self.tx.set_config(config).map_err(|_| ())?;
|
||||||
unwrap!(self.rx.set_config(config));
|
self.rx.set_config(config).map_err(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,9 +196,10 @@ pub struct UartTx<'d, T: BasicInstance, TxDma = NoDma> {
|
|||||||
|
|
||||||
impl<'d, T: BasicInstance, TxDma> SetConfig for UartTx<'d, T, TxDma> {
|
impl<'d, T: BasicInstance, TxDma> SetConfig for UartTx<'d, T, TxDma> {
|
||||||
type Config = Config;
|
type Config = Config;
|
||||||
|
type ConfigError = ();
|
||||||
|
|
||||||
fn set_config(&mut self, config: &Self::Config) {
|
fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> {
|
||||||
unwrap!(self.set_config(config));
|
self.set_config(config).map_err(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,9 +213,10 @@ pub struct UartRx<'d, T: BasicInstance, RxDma = NoDma> {
|
|||||||
|
|
||||||
impl<'d, T: BasicInstance, RxDma> SetConfig for UartRx<'d, T, RxDma> {
|
impl<'d, T: BasicInstance, RxDma> SetConfig for UartRx<'d, T, RxDma> {
|
||||||
type Config = Config;
|
type Config = Config;
|
||||||
|
type ConfigError = ();
|
||||||
|
|
||||||
fn set_config(&mut self, config: &Self::Config) {
|
fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> {
|
||||||
unwrap!(self.set_config(config));
|
self.set_config(config).map_err(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +276,7 @@ impl<'d, T: BasicInstance, TxDma> UartTx<'d, T, TxDma> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
||||||
reconfigure::<T>(config)
|
reconfigure::<T>(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,7 +377,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
||||||
reconfigure::<T>(config)
|
reconfigure::<T>(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -803,10 +806,6 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
|
||||||
reconfigure::<T>(config)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error>
|
pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
TxDma: crate::usart::TxDma<T>,
|
TxDma: crate::usart::TxDma<T>,
|
||||||
|
@ -18,9 +18,10 @@ pub struct RingBufferedUartRx<'d, T: BasicInstance, RxDma: super::RxDma<T>> {
|
|||||||
|
|
||||||
impl<'d, T: BasicInstance, RxDma: super::RxDma<T>> SetConfig for RingBufferedUartRx<'d, T, RxDma> {
|
impl<'d, T: BasicInstance, RxDma: super::RxDma<T>> SetConfig for RingBufferedUartRx<'d, T, RxDma> {
|
||||||
type Config = Config;
|
type Config = Config;
|
||||||
|
type ConfigError = ();
|
||||||
|
|
||||||
fn set_config(&mut self, config: &Self::Config) {
|
fn set_config(&mut self, config: &Self::Config) -> Result<(), ()> {
|
||||||
unwrap!(self.set_config(config));
|
self.set_config(config).map_err(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ impl<'d, T: BasicInstance, RxDma: super::RxDma<T>> RingBufferedUartRx<'d, T, RxD
|
|||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
|
||||||
self.teardown_uart();
|
self.teardown_uart();
|
||||||
reconfigure::<T>(config)
|
reconfigure::<T>(config)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user