|
12 | 12 | //! |
13 | 13 | //! let mut i2c = I2C::i2c1( |
14 | 14 | //! peripherals.I2C1, |
15 | | -//! pins.gpio18.into_pull_up_input().into_function(), // sda |
16 | | -//! pins.gpio19.into_pull_up_input().into_function(), // scl |
| 15 | +//! pins.gpio18.reconfigure(), // sda |
| 16 | +//! pins.gpio19.reconfigure(), // scl |
17 | 17 | //! 400.kHz(), |
18 | 18 | //! &mut peripherals.RESETS, |
19 | 19 | //! 125_000_000.Hz(), |
@@ -47,7 +47,7 @@ use core::{marker::PhantomData, ops::Deref}; |
47 | 47 | use fugit::HertzU32; |
48 | 48 |
|
49 | 49 | use crate::{ |
50 | | - gpio::{bank0::*, pin::pin_sealed::TypeLevelPinId, AnyPin, FunctionI2c}, |
| 50 | + gpio::{bank0::*, pin::pin_sealed::TypeLevelPinId, AnyPin, FunctionI2c, PullUp}, |
51 | 51 | pac::{self, i2c0::RegisterBlock as I2CBlock, I2C0, I2C1, RESETS}, |
52 | 52 | resets::SubsystemReset, |
53 | 53 | typelevel::Sealed, |
@@ -327,12 +327,34 @@ macro_rules! hal { |
327 | 327 | system_clock: SystemF) -> Self |
328 | 328 | where |
329 | 329 | F: Into<HertzU32>, |
330 | | - Sda: ValidPinSda<$I2CX>, |
331 | | - Scl: ValidPinScl<$I2CX>, |
| 330 | + Sda: ValidPinSda<$I2CX> + AnyPin<Pull = PullUp>, |
| 331 | + Scl: ValidPinScl<$I2CX> + AnyPin<Pull = PullUp>, |
332 | 332 | SystemF: Into<HertzU32>, |
333 | 333 | { |
334 | 334 | Self::new_controller(i2c, sda_pin, scl_pin, freq.into(), resets, system_clock.into()) |
335 | 335 | } |
| 336 | + |
| 337 | + $crate::paste::paste! { |
| 338 | + /// Configures the I2C peripheral to work in master mode |
| 339 | + /// |
| 340 | + /// This function can be called without activating internal pull-ups on the I2C pins. |
| 341 | + /// It should only be used if external pull-ups are provided. |
| 342 | + pub fn [<$i2cX _with_external_pull_up>]<F, SystemF>( |
| 343 | + i2c: $I2CX, |
| 344 | + sda_pin: Sda, |
| 345 | + scl_pin: Scl, |
| 346 | + freq: F, |
| 347 | + resets: &mut RESETS, |
| 348 | + system_clock: SystemF) -> Self |
| 349 | + where |
| 350 | + F: Into<HertzU32>, |
| 351 | + Sda: ValidPinSda<$I2CX>, |
| 352 | + Scl: ValidPinScl<$I2CX>, |
| 353 | + SystemF: Into<HertzU32>, |
| 354 | + { |
| 355 | + Self::new_controller(i2c, sda_pin, scl_pin, freq.into(), resets, system_clock.into()) |
| 356 | + } |
| 357 | + } |
336 | 358 | } |
337 | 359 | )+ |
338 | 360 | } |
|
0 commit comments