Skip to content

Commit 6aa9567

Browse files
authored
Add implementation of new Instance type so that I2c works (#157)
1 parent 2a55ace commit 6aa9567

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ default-features = false
3434
version = "1.0.2"
3535

3636
[dev-dependencies]
37+
stm32g0xx-hal = { path = ".", features = ["defmt", "rt"] }
38+
3739
cortex-m-rt = "0.7.5"
3840
cortex-m-semihosting = "0.5.0"
39-
defmt-rtt = "0.4.0"
41+
defmt = "0.3"
42+
defmt-rtt = "0.4"
4043
panic-halt = "1.0.0"
4144
panic-semihosting = "0.6.0"
4245
rtic = { version = "2.1.1", features = ["thumbv6-backend"] }

examples/i2c.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
#![no_main]
44
#![no_std]
55

6-
extern crate cortex_m;
7-
extern crate cortex_m_rt as rt;
8-
extern crate cortex_m_semihosting as sh;
9-
extern crate panic_halt;
10-
extern crate stm32g0xx_hal as hal;
6+
use cortex_m_semihosting as _;
7+
use defmt_rtt as _;
8+
use panic_halt as _;
9+
use stm32g0xx_hal as hal;
1110

11+
use cortex_m_rt::entry;
1212
use hal::i2c::Config;
1313
use hal::prelude::*;
1414
use hal::stm32;
15-
use rt::entry;
16-
use sh::hprintln;
1715

1816
#[entry]
1917
fn main() -> ! {
@@ -31,8 +29,8 @@ fn main() -> ! {
3129
let buf: [u8; 1] = [0];
3230
loop {
3331
match i2c.write(0x3c, &buf) {
34-
Ok(_) => hprintln!("ok"),
35-
Err(err) => hprintln!("error: {:?}", err),
32+
Ok(_) => defmt::println!("ok"),
33+
Err(err) => defmt::println!("error: {:?}", err),
3634
}
3735
}
3836
}

src/i2c/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ pub trait Instance:
8989
{
9090
}
9191

92+
impl Instance for crate::stm32::I2C1 {}
93+
impl Instance for crate::stm32::I2C2 {}
94+
9295
/// I2C SDA pin
9396
pub trait SDAPin<I2C> {
9497
fn setup(&self);

0 commit comments

Comments
 (0)