Skip to content

Commit df544aa

Browse files
committed
SPI working
1 parent b16cfc1 commit df544aa

File tree

7 files changed

+94
-25
lines changed

7 files changed

+94
-25
lines changed

e310x-hal/src/pwm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ pub struct Channel<'a, PWM, PIN> {
198198
pin: PIN,
199199
}
200200

201-
impl<'a, PWM, PIN> Channel<'a, PWM, PIN> {
201+
impl<PWM, PIN> Channel<'_, PWM, PIN> {
202202
/// Frees the PWM channel
203203
pub fn free(self) -> PIN {
204204
self.pin
205205
}
206206
}
207207

208-
impl<'a, PWM: PwmX, PIN: Pin<PWM>> Channel<'a, PWM, PIN> {
208+
impl<PWM: PwmX, PIN: Pin<PWM>> Channel<'_, PWM, PIN> {
209209
/// Returns the period of the PWM
210210
pub fn get_period(&self) -> PWM::CmpWidth {
211211
self.pwm.get_period()
@@ -237,11 +237,11 @@ impl<'a, PWM: PwmX, PIN: Pin<PWM>> Channel<'a, PWM, PIN> {
237237
}
238238
}
239239

240-
impl<'a, PWM: PwmX, PIN: Pin<PWM>> ErrorType for Channel<'a, PWM, PIN> {
240+
impl<PWM: PwmX, PIN: Pin<PWM>> ErrorType for Channel<'_, PWM, PIN> {
241241
type Error = ErrorKind;
242242
}
243243

244-
impl<'a, PWM: PwmX, PIN: Pin<PWM>> SetDutyCycle for Channel<'a, PWM, PIN> {
244+
impl<PWM: PwmX, PIN: Pin<PWM>> SetDutyCycle for Channel<'_, PWM, PIN> {
245245
fn max_duty_cycle(&self) -> u16 {
246246
PWM::bits_from_cmp_width(self.max_duty()) as _
247247
}

e310x-hal/src/spi/shared_device.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct SpiSharedDevice<'bus, SPI, PINS, CS> {
1010
config: SpiConfig,
1111
}
1212

13-
impl<'bus, SPI, PINS, CS> SpiSharedDevice<'bus, SPI, PINS, CS> {
13+
impl<SPI, PINS, CS> SpiSharedDevice<'_, SPI, PINS, CS> {
1414
/// Releases the CS pin back
1515
pub fn release(self) -> CS {
1616
self.cs
@@ -34,7 +34,7 @@ where
3434
}
3535
}
3636

37-
impl<'bus, SPI, PINS, CS> ErrorType for SpiSharedDevice<'bus, SPI, PINS, CS>
37+
impl<SPI, PINS, CS> ErrorType for SpiSharedDevice<'_, SPI, PINS, CS>
3838
where
3939
SPI: SpiX,
4040
PINS: PinsNoCS<SPI>,
@@ -43,7 +43,7 @@ where
4343
type Error = ErrorKind;
4444
}
4545

46-
impl<'bus, SPI, PINS, CS> SpiDevice for SpiSharedDevice<'bus, SPI, PINS, CS>
46+
impl<SPI, PINS, CS> SpiDevice for SpiSharedDevice<'_, SPI, PINS, CS>
4747
where
4848
SPI: SpiX,
4949
PINS: PinsNoCS<SPI> + PinsFull<SPI>,

e310x-hal/src/stdout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use nb::block;
77
/// implementations.
88
pub struct Stdout<'p, T: 'p>(pub &'p mut T);
99

10-
impl<'p, T: serial::Write> Write for Stdout<'p, T> {
10+
impl<T: serial::Write> Write for Stdout<'_, T> {
1111
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
1212
for byte in s.as_bytes() {
1313
if *byte == b'\n' {

hifive1-examples/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ riscv-rt = { version = "0.13.0", features = ["single-hart"] }
2020
panic-halt = "1.0.0"
2121
semihosting = { version = "0.1", features = ["stdio", "panic-handler"] }
2222
# max3010x = "0.2.0" # TODO uncomment when the driver is published
23-
max3010x = { git = "https://github.com/romancardenas/max3010x-rs.git" }
23+
max3010x = { git = "https://github.com/eldruin/max3010x-rs.git" }
24+
mfrc522 = "0.8.0"
2425

2526
[features]
2627
v-trap = ["hifive1/v-trap"]

hifive1-examples/examples/i2c_max3010x.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//! Basic blinking LEDs example using mtime/mtimecmp registers for "sleep" in a loop.
2-
//! Blinks each led once and goes to the next one.
1+
//! Sample example for the MAX3010x pulse oximeter and heart rate sensor
2+
//! using the I2C interface.
33
44
#![no_std]
55
#![no_main]
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//! Basic example of the RC522 RFID reader using the SPI interface.
2+
3+
#![no_std]
4+
#![no_main]
5+
6+
use hifive1::{
7+
clock,
8+
hal::{
9+
e310x::CLINT,
10+
prelude::*,
11+
spi::{SpiBus, SpiConfig, SpiExclusiveDevice, MODE_0},
12+
DeviceResources,
13+
},
14+
pin, sprintln,
15+
};
16+
use mfrc522::{comm::blocking::spi::SpiInterface, Mfrc522};
17+
extern crate panic_halt;
18+
19+
#[riscv_rt::entry]
20+
fn main() -> ! {
21+
let dr = DeviceResources::take().unwrap();
22+
let p = dr.peripherals;
23+
let pins = dr.pins;
24+
25+
// Configure clocks
26+
let clocks = clock::configure(p.PRCI, p.AONCLK, 320.mhz().into());
27+
28+
// Configure UART for stdout
29+
hifive1::stdout::configure(
30+
p.UART0,
31+
pin!(pins, uart0_tx),
32+
pin!(pins, uart0_rx),
33+
115_200.bps(),
34+
clocks,
35+
);
36+
37+
let sck = pin!(pins, spi1_sck).into_iof0();
38+
let miso = pin!(pins, spi1_miso).into_iof0();
39+
let mosi = pin!(pins, spi1_mosi).into_iof0();
40+
let cs = pin!(pins, spi1_ss0).into_iof0();
41+
42+
let spi_bus = SpiBus::new(p.QSPI1, (mosi, miso, sck, cs));
43+
let spi_cfg = SpiConfig::new(MODE_0, 1_000_000.hz(), &clocks);
44+
let spi_device = SpiExclusiveDevice::new(spi_bus, &spi_cfg);
45+
let spi_itf = SpiInterface::new(spi_device);
46+
47+
let mut mfrc522 = match Mfrc522::new(spi_itf).init() {
48+
Ok(mfrc522) => mfrc522,
49+
Err(e) => {
50+
sprintln!("Error initializing sensor: {:?}", e);
51+
loop {}
52+
}
53+
};
54+
// The reported version is expected to be 0x91 or 0x92
55+
let version = mfrc522.version().unwrap();
56+
sprintln!("Version: {:x}", version);
57+
58+
// Get the sleep struct from CLINT
59+
let mut sleep = CLINT::delay();
60+
const STEP: u32 = 1000; // 1s
61+
loop {
62+
sleep.delay_ms(STEP);
63+
}
64+
}

hifive1/src/gpio.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,25 @@ macro_rules! pin {
2424
()
2525
};
2626
// spi
27-
($gpio:ident, spi0_sck) => {
27+
($gpio:ident, spi1_sck) => {
2828
$gpio.pin5
2929
};
30-
($gpio:ident, spi0_mosi) => {
30+
($gpio:ident, spi1_mosi) => {
3131
$gpio.pin3
3232
};
33-
($gpio:ident, spi0_miso) => {
33+
($gpio:ident, spi1_miso) => {
3434
$gpio.pin4
3535
};
36-
($gpio:ident, spi0_ss0) => {
36+
($gpio:ident, spi1_ss0) => {
3737
$gpio.pin2
3838
};
39-
// spi_ss1 is not documented
40-
($gpio:ident, spi0_ss2) => {
39+
($gpio:ident, spi1_ss1) => {
40+
$gpio.pin8
41+
};
42+
($gpio:ident, spi1_ss2) => {
4143
$gpio.pin9
4244
};
43-
($gpio:ident, spi0_ss3) => {
45+
($gpio:ident, spi1_ss3) => {
4446
$gpio.pin10
4547
};
4648
// i2c
@@ -184,23 +186,25 @@ macro_rules! pin {
184186
()
185187
};
186188
// spi
187-
($gpio:ident, spi0_sck) => {
189+
($gpio:ident, spi1_sck) => {
188190
$gpio.pin5
189191
};
190-
($gpio:ident, spi0_mosi) => {
192+
($gpio:ident, spi1_mosi) => {
191193
$gpio.pin3
192194
};
193-
($gpio:ident, spi0_miso) => {
195+
($gpio:ident, spi1_miso) => {
194196
$gpio.pin4
195197
};
196-
($gpio:ident, spi0_ss0) => {
198+
($gpio:ident, spi1_ss0) => {
197199
$gpio.pin2
198200
};
199-
// spi_ss1 is not documented
200-
($gpio:ident, spi0_ss2) => {
201+
($gpio:ident, spi1_ss1) => {
202+
$gpio.pin8
203+
};
204+
($gpio:ident, spi1_ss2) => {
201205
$gpio.pin9
202206
};
203-
($gpio:ident, spi0_ss3) => {
207+
($gpio:ident, spi1_ss3) => {
204208
$gpio.pin10
205209
};
206210
// i2c

0 commit comments

Comments
 (0)