diff options
Diffstat (limited to 'embassy-rp/src/i2c.rs')
| -rw-r--r-- | embassy-rp/src/i2c.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs index a983b7bc3..ffbef63be 100644 --- a/embassy-rp/src/i2c.rs +++ b/embassy-rp/src/i2c.rs | |||
| @@ -64,18 +64,31 @@ pub enum ConfigError { | |||
| 64 | pub struct Config { | 64 | pub struct Config { |
| 65 | /// Frequency. | 65 | /// Frequency. |
| 66 | pub frequency: u32, | 66 | pub frequency: u32, |
| 67 | /// Enable internal pullup on SDA. | ||
| 68 | /// | ||
| 69 | /// Using external pullup resistors is recommended for I2C. If you do | ||
| 70 | /// have external pullups you should not enable this. | ||
| 71 | pub sda_pullup: bool, | ||
| 72 | /// Enable internal pullup on SCL. | ||
| 73 | /// | ||
| 74 | /// Using external pullup resistors is recommended for I2C. If you do | ||
| 75 | /// have external pullups you should not enable this. | ||
| 76 | pub scl_pullup: bool, | ||
| 67 | } | 77 | } |
| 68 | |||
| 69 | impl Default for Config { | 78 | impl Default for Config { |
| 70 | fn default() -> Self { | 79 | fn default() -> Self { |
| 71 | Self { frequency: 100_000 } | 80 | Self { |
| 81 | frequency: 100_000, | ||
| 82 | sda_pullup: true, | ||
| 83 | scl_pullup: true, | ||
| 84 | } | ||
| 72 | } | 85 | } |
| 73 | } | 86 | } |
| 74 | |||
| 75 | /// Size of I2C FIFO. | 87 | /// Size of I2C FIFO. |
| 76 | pub const FIFO_SIZE: u8 = 16; | 88 | pub const FIFO_SIZE: u8 = 16; |
| 77 | 89 | ||
| 78 | /// I2C driver. | 90 | /// I2C driver. |
| 91 | #[derive(Debug)] | ||
| 79 | pub struct I2c<'d, T: Instance, M: Mode> { | 92 | pub struct I2c<'d, T: Instance, M: Mode> { |
| 80 | phantom: PhantomData<(&'d mut T, M)>, | 93 | phantom: PhantomData<(&'d mut T, M)>, |
| 81 | } | 94 | } |
| @@ -358,7 +371,7 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 358 | } | 371 | } |
| 359 | } | 372 | } |
| 360 | 373 | ||
| 361 | pub(crate) fn set_up_i2c_pin<P, T>(pin: &P) | 374 | pub(crate) fn set_up_i2c_pin<P, T>(pin: &P, pullup: bool) |
| 362 | where | 375 | where |
| 363 | P: core::ops::Deref<Target = T>, | 376 | P: core::ops::Deref<Target = T>, |
| 364 | T: crate::gpio::Pin, | 377 | T: crate::gpio::Pin, |
| @@ -371,7 +384,7 @@ where | |||
| 371 | w.set_slewfast(false); | 384 | w.set_slewfast(false); |
| 372 | w.set_ie(true); | 385 | w.set_ie(true); |
| 373 | w.set_od(false); | 386 | w.set_od(false); |
| 374 | w.set_pue(true); | 387 | w.set_pue(pullup); |
| 375 | w.set_pde(false); | 388 | w.set_pde(false); |
| 376 | }); | 389 | }); |
| 377 | } | 390 | } |
| @@ -383,8 +396,8 @@ impl<'d, T: Instance + 'd, M: Mode> I2c<'d, T, M> { | |||
| 383 | crate::reset::unreset_wait(reset); | 396 | crate::reset::unreset_wait(reset); |
| 384 | 397 | ||
| 385 | // Configure SCL & SDA pins | 398 | // Configure SCL & SDA pins |
| 386 | set_up_i2c_pin(&scl); | 399 | set_up_i2c_pin(&scl, config.scl_pullup); |
| 387 | set_up_i2c_pin(&sda); | 400 | set_up_i2c_pin(&sda, config.sda_pullup); |
| 388 | 401 | ||
| 389 | let mut me = Self { phantom: PhantomData }; | 402 | let mut me = Self { phantom: PhantomData }; |
| 390 | 403 | ||
