Skip to content

Commit 645215a

Browse files
authored
Merge pull request #547 from stm32-rs/blocking_reset
fixed example and added reset
2 parents 7f7e1f6 + 12e9481 commit 645215a

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4545

4646
### Added
4747

48+
- reset methods for I2C and BlockingI2C interfaces
4849
- `Serial` support for UART4/5
4950
- Allow to set HSE bypass bit in `RCC` clock configuration register to use an external clock input on the `OSC_IN` pin [#485]
5051
- initial support of `embedded-hal-1.0` [#416]

examples/i2c-bme280/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use panic_semihosting as _;
2424
use bme280::i2c::BME280;
2525
use cortex_m_rt::entry;
2626
use stm32f1xx_hal::{
27-
i2c::{BlockingI2c, DutyCycle, Mode},
27+
i2c::{DutyCycle, Mode},
2828
pac,
2929
prelude::*,
3030
rcc,
@@ -54,10 +54,10 @@ fn main() -> ! {
5454
&mut flash.acr,
5555
);
5656

57-
let mut afio = dp.AFIO.constrain(&mut rcc);
57+
//let mut afio = dp.AFIO.constrain(&mut rcc); // add this if want to use PB8, PB9 instead
5858

5959
// Acquire the GPIOB peripheral
60-
let mut gpiob = dp.GPIOB.split(&mut rcc);
60+
let gpiob = dp.GPIOB.split(&mut rcc);
6161

6262
let scl = gpiob.pb6;
6363
let sda = gpiob.pb7;
@@ -71,7 +71,7 @@ fn main() -> ! {
7171
frequency: 400.kHz(),
7272
duty_cycle: DutyCycle::Ratio16to9,
7373
},
74-
&clocks,
74+
&mut rcc,
7575
1000,
7676
10,
7777
1000,
@@ -80,7 +80,7 @@ fn main() -> ! {
8080

8181
// The Adafruit boards have address 0x77 without closing the jumper on the back, the BME280 lib connects to 0x77 with `new_secondary`, use
8282
// `new_primary` for 0x76 if you close the jumper/solder bridge.
83-
let mut bme280 = BME280::new_secondary(i2c, cp.SYST.delay(&clocks));
83+
let mut bme280 = BME280::new_secondary(i2c, cp.SYST.delay(&rcc.clocks));
8484
bme280
8585
.init()
8686
.map_err(|error| {

src/i2c/blocking.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ impl<I2C: Instance> BlockingI2c<I2C> {
212212
Ok(())
213213
}
214214

215+
pub fn reset(&mut self) {
216+
self.nb.reset();
217+
}
218+
215219
pub fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Error> {
216220
self.send_start_and_wait()?;
217221
self.send_addr_and_wait(addr, true)?;

0 commit comments

Comments
 (0)