Skip to content

Commit dab45ae

Browse files
committed
add SparkFun RED-V board support
1 parent 997743b commit dab45ae

File tree

8 files changed

+96
-3
lines changed

8 files changed

+96
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ nb = "0.1.2"
1818
[features]
1919
board-hifive1 = []
2020
board-hifive1-revb = ["e310x-hal/g002"]
21+
board-redv = ["e310x-hal/g002"]
2122
board-lofive = []
2223
board-lofive-r1 = ["e310x-hal/g002"]
2324

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
> Board support crate for HiFive1 and LoFive boards
88
9+
## Supported Boards
10+
11+
`hifive1` - use feature `board-hifive1`
12+
`hifive1-revb` - use feature `board-hifive1-revb`
13+
`redv` - use feature `board-redv`
14+
`lofive` - use feature `board-lofive`
15+
`lofive-r1` - use feature `board-lofive-r1`
16+
917
## [Documentation](https://docs.rs/crate/hifive1)
1018

1119
## License

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() {
2828
fs::copy("memory-hifive1.x", out_dir.join("hifive1-memory.x")).unwrap();
2929
println!("cargo:rerun-if-changed=memory-hifive1.x");
3030
}
31-
"hifive1_revb" => {
31+
"hifive1_revb" | "redv" => {
3232
fs::copy("memory-hifive1-revb.x", out_dir.join("hifive1-memory.x")).unwrap();
3333
println!("cargo:rerun-if-changed=memory-hifive1-revb.x");
3434
}

ci/script.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ set -euxo pipefail
44

55
cargo check --target $TARGET --features 'board-hifive1'
66
cargo check --target $TARGET --features 'board-hifive1-revb'
7+
cargo check --target $TARGET --features 'board-redv'
78
cargo check --target $TARGET --features 'board-lofive'
89
cargo check --target $TARGET --features 'board-lofive-r1'

src/clock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use e310x_hal::{
66
time::Hertz,
77
};
88

9-
#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb"))]
9+
#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb", feature = "board-redv"))]
1010
/// Configures clock generation system.
1111
///
1212
/// For HiFive1 and HiFive1 Rev B boards external oscillators are enabled for

src/gpio.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb"))]
12
///
23
/// Returns single pin for given gpio object mapped accordingly
34
///
@@ -58,7 +59,69 @@ macro_rules! pin {
5859
($gpio:ident, led_red) => { $gpio.pin22 };
5960
($gpio:ident, led_green) => { $gpio.pin19 };
6061
($gpio:ident, led_blue) => { $gpio.pin21 };
62+
// #[cfg(feature = "redv")]
63+
// ($gpio:ident, led_blue) => { $gpio.pin4 };
64+
}
6165

66+
#[cfg(feature = "board-redv")]
67+
///
68+
/// Returns single pin for given gpio object mapped accordingly
69+
///
70+
/// # Mappings
71+
///
72+
/// - `spi0_<x>` — SPI pins where `<x>` is one of (`sck`, `mosi`, `miso`, `ss0`, `ss2`, `ss3`)
73+
/// - `i2c0_<x>` — I2C pins where `<x>` is one of (`sda`, `scl`)
74+
/// - `uart0_<x>` — UART pins where `<x>` is one of (`tx`, `rx`)
75+
/// - `dig#` — Digital/physical pins on the board where `#` is from range 0..19
76+
/// - `led_<x>` - Internal LED light pins where `<x>` is one of (`red`, `green`, `blue`)
77+
///
78+
/// # Example
79+
///
80+
/// ```
81+
/// let mosi = pin!(gpio, spi0_mosi); // gpio.pin3
82+
/// ```
83+
///
84+
#[macro_export]
85+
macro_rules! pin {
86+
// empty
87+
($gpio:ident, none) => { () };
88+
// spi
89+
($gpio:ident, spi0_sck) => { $gpio.pin5 };
90+
($gpio:ident, spi0_mosi) => { $gpio.pin3 };
91+
($gpio:ident, spi0_miso) => { $gpio.pin4 };
92+
($gpio:ident, spi0_ss0) => { $gpio.pin2 };
93+
// spi_ss1 is not documented
94+
($gpio:ident, spi0_ss2) => { $gpio.pin9 };
95+
($gpio:ident, spi0_ss3) => { $gpio.pin10 };
96+
// i2c
97+
($gpio:ident, i2c0_sda) => { $gpio.pin12 };
98+
($gpio:ident, i2c0_scl) => { $gpio.pin13 };
99+
// serial
100+
($gpio:ident, uart0_tx) => { $gpio.pin17 };
101+
($gpio:ident, uart0_rx) => { $gpio.pin16 };
102+
// digital/physical
103+
($gpio:ident, dig0) => { $gpio.pin16 };
104+
($gpio:ident, dig1) => { $gpio.pin17 };
105+
($gpio:ident, dig2) => { $gpio.pin18 };
106+
($gpio:ident, dig3) => { $gpio.pin19 };
107+
($gpio:ident, dig4) => { $gpio.pin20 };
108+
($gpio:ident, dig5) => { $gpio.pin21 };
109+
($gpio:ident, dig6) => { $gpio.pin22 };
110+
($gpio:ident, dig7) => { $gpio.pin23 };
111+
($gpio:ident, dig8) => { $gpio.pin0 };
112+
($gpio:ident, dig9) => { $gpio.pin1 };
113+
($gpio:ident, dig10) => { $gpio.pin2 };
114+
($gpio:ident, dig11) => { $gpio.pin3 };
115+
($gpio:ident, dig12) => { $gpio.pin4 };
116+
($gpio:ident, dig13) => { $gpio.pin5 };
117+
($gpio:ident, dig14) => { $gpio.pin8 }; // tested
118+
($gpio:ident, dig15) => { $gpio.pin9 };
119+
($gpio:ident, dig16) => { $gpio.pin10 };
120+
($gpio:ident, dig17) => { $gpio.pin11 };
121+
($gpio:ident, dig18) => { $gpio.pin12 };
122+
($gpio:ident, dig19) => { $gpio.pin13 };
123+
// onboard LEDs
124+
($gpio:ident, led_blue) => { $gpio.pin4 };
62125
}
63126

64127
///

src/led.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
//! On-board user LEDs
22
//!
3+
//! Hifive1 (+ revB)
34
//! - Red = Pin 22
45
//! - Green = Pin 19
56
//! - Blue = Pin 21
7+
//!
8+
//! RedV
9+
//! - Blue = Pin 4
10+
611
use embedded_hal::digital::v2::OutputPin;
12+
#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb"))]
713
use e310x_hal::gpio::gpio0::{Pin19, Pin21, Pin22};
14+
#[cfg(feature = "board-redv")]
15+
use e310x_hal::gpio::gpio0::{Pin4};
816
use e310x_hal::gpio::{Output, Regular, Invert};
917

18+
#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb"))]
1019
/// Red LED
1120
pub type RED = Pin22<Output<Regular<Invert>>>;
1221

22+
#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb"))]
1323
/// Green LED
1424
pub type GREEN = Pin19<Output<Regular<Invert>>>;
1525

26+
#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb"))]
1627
/// Blue LED
1728
pub type BLUE = Pin21<Output<Regular<Invert>>>;
1829

30+
#[cfg(feature = "board-redv")]
31+
/// Blue LED
32+
pub type BLUE = Pin4<Output<Regular<Invert>>>;
33+
34+
#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb"))]
1935
/// Returns RED, GREEN and BLUE LEDs.
2036
pub fn rgb<X, Y, Z>(
2137
red: Pin22<X>, green: Pin19<Y>, blue: Pin21<Z>
@@ -36,6 +52,7 @@ pub trait Led {
3652
fn on(&mut self);
3753
}
3854

55+
#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb"))]
3956
impl Led for RED {
4057
fn off(&mut self) {
4158
self.set_low().unwrap();
@@ -46,6 +63,7 @@ impl Led for RED {
4663
}
4764
}
4865

66+
#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb"))]
4967
impl Led for GREEN {
5068
fn off(&mut self) {
5169
self.set_low().unwrap();

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ pub use clock::configure as configure_clocks;
1010

1111
pub mod flash;
1212

13-
#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb"))]
13+
#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb", feature = "board-redv"))]
1414
pub mod led;
1515
#[cfg(any(feature = "board-hifive1", feature = "board-hifive1-revb"))]
1616
pub use led::{RED, GREEN, BLUE, rgb, Led};
17+
#[cfg(feature = "board-redv")]
18+
pub use led::{BLUE, Led};
1719

1820
pub mod stdout;
1921
pub use stdout::configure as configure_stdout;

0 commit comments

Comments
 (0)