Move slave constructor to v2 module

This commit is contained in:
jrmoulton 2024-06-17 21:15:26 -06:00
parent 967fa1b2a2
commit 49357709ed
No known key found for this signature in database
2 changed files with 21 additions and 20 deletions

View File

@ -268,26 +268,6 @@ impl<'d, M: Mode, IM: MasterMode> I2c<'d, M, IM> {
}
}
}
impl<'d, M: Mode> I2c<'d, M, Master> {
/// Configure the I2C driver for slave operations, allowing for the driver to be used as a slave and a master (multimaster)
pub fn into_slave_multimaster(mut self, slave_addr_config: SlaveAddrConfig) -> I2c<'d, M, MultiMaster> {
let mut slave = I2c {
info: self.info,
state: self.state,
kernel_clock: self.kernel_clock,
scl: self.scl.take(),
sda: self.sda.take(),
tx_dma: self.tx_dma.take(),
rx_dma: self.rx_dma.take(),
#[cfg(feature = "time")]
timeout: self.timeout,
_phantom: PhantomData,
_phantom2: PhantomData,
};
slave.init_slave(slave_addr_config);
slave
}
}
impl<'d, M: Mode, IM: MasterMode> Drop for I2c<'d, M, IM> {
fn drop(&mut self) {

View File

@ -694,6 +694,27 @@ impl<'d, IM: MasterMode> I2c<'d, Async, IM> {
}
}
impl<'d, M: Mode> I2c<'d, M, Master> {
/// Configure the I2C driver for slave operations, allowing for the driver to be used as a slave and a master (multimaster)
pub fn into_slave_multimaster(mut self, slave_addr_config: SlaveAddrConfig) -> I2c<'d, M, MultiMaster> {
let mut slave = I2c {
info: self.info,
state: self.state,
kernel_clock: self.kernel_clock,
scl: self.scl.take(),
sda: self.sda.take(),
tx_dma: self.tx_dma.take(),
rx_dma: self.rx_dma.take(),
#[cfg(feature = "time")]
timeout: self.timeout,
_phantom: PhantomData,
_phantom2: PhantomData,
};
slave.init_slave(slave_addr_config);
slave
}
}
impl<'d, M: Mode> I2c<'d, M, MultiMaster> {
pub(crate) fn init_slave(&mut self, config: SlaveAddrConfig) {
self.info.regs.cr1().modify(|reg| {