Skip to content

Commit 4093bd8

Browse files
committed
fix i2c
1 parent 29a6237 commit 4093bd8

File tree

4 files changed

+96
-63
lines changed

4 files changed

+96
-63
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,7 @@ required-features = ["rm0433","rt"]
257257
[[example]]
258258
name = "crc"
259259
required-features = ["crc", "rt"]
260+
261+
[[example]]
262+
name = "i2c4_bdma"
263+
required-features = ["rm0433"]

src/gpio/alt.rs

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Alternate, OpenDrain, PinMode};
1+
use super::{Alternate, NoPin, OpenDrain, PinMode};
22
use crate::gpio;
33

44
macro_rules! pin {
@@ -2341,6 +2341,7 @@ pub mod sdmmc2 {
23412341
}
23422342
}
23432343

2344+
#[cfg(any(feature = "gpio-h72", feature = "gpio-h747"))]
23442345
pub mod spdifrx1 {
23452346
use super::*;
23462347
pin! {
@@ -2418,12 +2419,17 @@ pub mod spdifrx {
24182419
pub mod spi1 {
24192420
use super::*;
24202421
pin! {
2421-
<Miso> for [
2422+
<Sck> for no:NoPin, [
2423+
PA5<5>,
2424+
PB3<5>,
2425+
PG11<5>,
2426+
],
2427+
<Miso> for no:NoPin, [
24222428
PA6<5>,
24232429
PB4<5>,
24242430
PG9<5>,
24252431
],
2426-
<Mosi> for [
2432+
<Mosi> for no:NoPin, [
24272433
PA7<5>,
24282434
PB5<5>,
24292435
PD7<5>,
@@ -2433,26 +2439,31 @@ pub mod spi1 {
24332439
PA4<5>,
24342440
PG10<5>,
24352441
],
2436-
<Sck> for [
2437-
PA5<5>,
2438-
PB3<5>,
2439-
PG11<5>,
2440-
],
24412442
}
24422443
}
24432444

24442445
pub mod spi2 {
24452446
use super::*;
24462447
pin! {
2447-
<Miso> for [
2448+
<Sck> for no:NoPin, [
2449+
PA12<5>,
2450+
PA9<5>,
2451+
PB10<5>,
2452+
PB13<5>,
2453+
PD3<5>,
2454+
2455+
#[cfg(any(feature = "gpio-h747", feature = "gpio-h7a2"))]
2456+
PI1<5>,
2457+
],
2458+
<Miso> for no:NoPin, [
24482459
PB14<5>,
24492460

24502461
#[cfg(any(feature = "gpio-h747", feature = "gpio-h7a2"))]
24512462
PC2<5>,
24522463
#[cfg(any(feature = "gpio-h747", feature = "gpio-h7a2"))]
24532464
PI2<5>,
24542465
],
2455-
<Mosi> for [
2466+
<Mosi> for no:NoPin, [
24562467
PB15<5>,
24572468
PC1<5>,
24582469

@@ -2470,27 +2481,21 @@ pub mod spi2 {
24702481
#[cfg(any(feature = "gpio-h747", feature = "gpio-h7a2"))]
24712482
PI0<5>,
24722483
],
2473-
<Sck> for [
2474-
PA12<5>,
2475-
PA9<5>,
2476-
PB10<5>,
2477-
PB13<5>,
2478-
PD3<5>,
2479-
2480-
#[cfg(any(feature = "gpio-h747", feature = "gpio-h7a2"))]
2481-
PI1<5>,
2482-
],
24832484
}
24842485
}
24852486

24862487
pub mod spi3 {
24872488
use super::*;
24882489
pin! {
2489-
<Miso> for [
2490+
<Sck> for no:NoPin, [
2491+
PB3<6>,
2492+
PC10<6>,
2493+
],
2494+
<Miso> for no:NoPin, [
24902495
PB4<6>,
24912496
PC11<6>,
24922497
],
2493-
<Mosi> for [
2498+
<Mosi> for no:NoPin, [
24942499
PB2<7>,
24952500
PB5<7>,
24962501
PC12<6>,
@@ -2500,44 +2505,45 @@ pub mod spi3 {
25002505
PA15<6>,
25012506
PA4<6>,
25022507
],
2503-
<Sck> for [
2504-
PB3<6>,
2505-
PC10<6>,
2506-
],
25072508
}
25082509
}
25092510

25102511
pub mod spi4 {
25112512
use super::*;
25122513
pin! {
2513-
<Miso> for [
2514+
<Sck> for no:NoPin, [
2515+
PE12<5>,
2516+
PE2<5>,
2517+
],
2518+
<Miso> for no:NoPin, [
25142519
PE13<5>,
25152520
PE5<5>,
25162521
],
2517-
<Mosi> for [
2522+
<Mosi> for no:NoPin, [
25182523
PE14<5>,
25192524
PE6<5>,
25202525
],
25212526
<Nss> for [
25222527
PE11<5>,
25232528
PE4<5>,
25242529
],
2525-
<Sck> for [
2526-
PE12<5>,
2527-
PE2<5>,
2528-
],
25292530
}
25302531
}
25312532

25322533
pub mod spi5 {
25332534
use super::*;
25342535
pin! {
2535-
<Miso> for [
2536+
<Sck> for no:NoPin, [
2537+
PF7<5>,
2538+
PH6<5>,
2539+
PK0<5>,
2540+
],
2541+
<Miso> for no:NoPin, [
25362542
PF8<5>,
25372543
PH7<5>,
25382544
PJ11<5>,
25392545
],
2540-
<Mosi> for [
2546+
<Mosi> for no:NoPin, [
25412547
PF11<5>,
25422548
PF9<5>,
25432549
PJ10<5>,
@@ -2547,23 +2553,26 @@ pub mod spi5 {
25472553
PH5<5>,
25482554
PK1<5>,
25492555
],
2550-
<Sck> for [
2551-
PF7<5>,
2552-
PH6<5>,
2553-
PK0<5>,
2554-
],
25552556
}
25562557
}
25572558

25582559
pub mod spi6 {
25592560
use super::*;
25602561
pin! {
2561-
<Miso> for [
2562+
<Sck> for no:NoPin, [
2563+
PA5<8>,
2564+
PB3<8>,
2565+
PG13<5>,
2566+
2567+
#[cfg(any(feature = "gpio-h72", feature = "gpio-h7a2"))]
2568+
PC12<5>,
2569+
],
2570+
<Miso> for no:NoPin, [
25622571
PA6<8>,
25632572
PB4<8>,
25642573
PG12<5>,
25652574
],
2566-
<Mosi> for [
2575+
<Mosi> for no:NoPin, [
25672576
PA7<8>,
25682577
PB5<8>,
25692578
PG14<5>,
@@ -2576,14 +2585,6 @@ pub mod spi6 {
25762585
#[cfg(any(feature = "gpio-h72", feature = "gpio-h7a2"))]
25772586
PA0<5>,
25782587
],
2579-
<Sck> for [
2580-
PA5<8>,
2581-
PB3<8>,
2582-
PG13<5>,
2583-
2584-
#[cfg(any(feature = "gpio-h72", feature = "gpio-h7a2"))]
2585-
PC12<5>,
2586-
],
25872588
}
25882589
}
25892590

src/i2c.rs

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ impl<I2C: Instance> I2c<I2C> {
487487
// `buffer`. The START bit can be set even if the bus
488488
// is BUSY or I2C is in slave mode.
489489
self.i2c.cr2.write(|w| {
490-
w.sadd().bits((addr << 1 | 0) as u16);
490+
w.sadd().bits((addr << 1) as u16);
491491
w.rd_wrn().read();
492492
w.nbytes().bits(length as u8);
493493
w.start().set_bit();
@@ -516,7 +516,7 @@ impl<I2C: Instance> I2c<I2C> {
516516
// I2C is in slave mode.
517517
self.i2c.cr2.write(|w| {
518518
w.start().set_bit();
519-
w.sadd().bits(u16(addr << 1 | 0));
519+
w.sadd().bits(u16(addr << 1));
520520
w.add10().clear_bit();
521521
w.rd_wrn().write();
522522
w.nbytes().bits(length as u8);
@@ -565,7 +565,7 @@ impl<I2C: Instance> Write for I2c<I2C> {
565565

566566
fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Error> {
567567
// TODO support transfers of more than 255 bytes
568-
assert!(bytes.len() < 256 && bytes.len() > 0);
568+
assert!(bytes.len() < 256 && !bytes.is_empty());
569569

570570
// I2C start
571571
//
@@ -605,8 +605,8 @@ impl<I2C: Instance> WriteRead for I2c<I2C> {
605605
buffer: &mut [u8],
606606
) -> Result<(), Error> {
607607
// TODO support transfers of more than 255 bytes
608-
assert!(bytes.len() < 256 && bytes.len() > 0);
609-
assert!(buffer.len() < 256 && buffer.len() > 0);
608+
assert!(bytes.len() < 256 && !bytes.is_empty());
609+
assert!(buffer.len() < 256 && !buffer.is_empty());
610610

611611
// I2C start
612612
//
@@ -647,13 +647,9 @@ impl<I2C: Instance> WriteRead for I2c<I2C> {
647647
impl<I2C: Instance> Read for I2c<I2C> {
648648
type Error = Error;
649649

650-
fn read(
651-
&mut self,
652-
addr: u8,
653-
buffer: &mut [u8],
654-
) -> Result<(), Error> {
650+
fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Error> {
655651
// TODO support transfers of more than 255 bytes
656-
assert!(buffer.len() < 256 && buffer.len() > 0);
652+
assert!(buffer.len() < 256 && !buffer.is_empty());
657653

658654
self.master_read(addr, buffer.len(), Stop::Automatic);
659655

@@ -671,13 +667,45 @@ impl<I2C: Instance> Read for I2c<I2C> {
671667
}
672668
}
673669

670+
#[cfg(not(feature = "rm0455"))]
674671
i2c!(
675672
pac::I2C1: (i2c1, I2c1, pclk1),
676673
pac::I2C2: (i2c2, I2c2, pclk1),
677674
pac::I2C3: (i2c3, I2c3, pclk1),
678675
pac::I2C4: (i2c4, I2c4, pclk4),
679676
);
680677

678+
// TODO: fix derive SPI3 from SPI1 in SVD
679+
#[cfg(feature = "rm0455")]
680+
i2c!(
681+
pac::I2C1: (i2c1, I2c1, pclk1),
682+
pac::I2C2: (i2c2, I2c2, pclk1),
683+
);
684+
#[cfg(feature = "rm0455")]
685+
impl I2c<pac::I2C3> {
686+
/// Returns a reference to the inner peripheral
687+
pub fn inner(&self) -> &pac::I2C3 {
688+
&self.i2c
689+
}
690+
691+
/// Returns a mutable reference to the inner peripheral
692+
pub fn inner_mut(&mut self) -> &mut pac::I2C3 {
693+
&mut self.i2c
694+
}
695+
}
696+
#[cfg(feature = "rm0455")]
697+
impl I2c<pac::I2C4> {
698+
/// Returns a reference to the inner peripheral
699+
pub fn inner(&self) -> &pac::I2C4 {
700+
&self.i2c
701+
}
702+
703+
/// Returns a mutable reference to the inner peripheral
704+
pub fn inner_mut(&mut self) -> &mut pac::I2C4 {
705+
&mut self.i2c
706+
}
707+
}
708+
681709
#[cfg(test)]
682710
mod tests {
683711
use core::cmp;

src/spi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,13 @@ impl HardwareCS {
298298
}
299299

300300
/// A filler type for when the SCK pin is unnecessary
301-
pub struct NoSck;
301+
pub use gpio::NoPin as NoSck;
302302

303303
/// A filler type for when the Miso pin is unnecessary
304-
pub struct NoMiso;
304+
pub use gpio::NoPin as NoMiso;
305305

306306
/// A filler type for when the Mosi pin is unnecessary
307-
pub struct NoMosi;
307+
pub use gpio::NoPin as NoMosi;
308308

309309
macro_rules! pins {
310310
($($SPIX:ty:

0 commit comments

Comments
 (0)