1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-01-05 16:10:31 +02:00

Use micro:bit v2 for PAC and HAL examples too.

This commit is contained in:
Andrew Walbran 2023-02-16 01:56:46 +00:00
parent 5ad0a593f8
commit 2c8eb761c4
7 changed files with 59 additions and 105 deletions

View File

@ -1,7 +1,2 @@
[target.thumbv7m-none-eabi]
rustflags = [
"-C", "link-arg=-Tmemory.x",
]
[build]
target = "thumbv7m-none-eabi" # Cortex-M3
target = "thumbv7em-none-eabihf" # Cortex-M4F

View File

@ -29,24 +29,6 @@ version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bxcan"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40ac3d0c0a542d0ab5521211f873f62706a7136df415676f676d347e5a41dd80"
dependencies = [
"bitflags",
"embedded-hal",
"nb 1.0.0",
"vcell",
]
[[package]]
name = "bytemuck"
version = "1.13.0"
@ -128,15 +110,6 @@ dependencies = [
"stable_deref_trait",
]
[[package]]
name = "embedded-dma"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "994f7e5b5cb23521c22304927195f236813053eb9c065dd2226a32ba64695446"
dependencies = [
"stable_deref_trait",
]
[[package]]
name = "embedded-hal"
version = "0.2.7"
@ -165,34 +138,6 @@ dependencies = [
"typenum",
]
[[package]]
name = "gd32f1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f484ed96a7b3129d72792c31eb9d22e8e3164d668dcbfd05ce8e5786799a946"
dependencies = [
"cortex-m",
"cortex-m-rt",
"vcell",
]
[[package]]
name = "gd32f1x0-hal"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e94f33a60f7c7a4a38010bf4801b182cf294a8f1236e3cf528bb1f0fe995571"
dependencies = [
"bxcan",
"cast",
"cortex-m",
"cortex-m-rt",
"embedded-dma 0.2.0",
"embedded-hal",
"gd32f1",
"nb 1.0.0",
"void",
]
[[package]]
name = "half"
version = "2.2.1"
@ -228,9 +173,9 @@ version = "0.1.0"
dependencies = [
"cortex-m-rt",
"embedded-hal",
"gd32f1",
"gd32f1x0-hal",
"microbit-v2",
"nrf52833-hal",
"nrf52833-pac",
"panic-halt",
]
@ -258,7 +203,7 @@ dependencies = [
"cast",
"cfg-if",
"cortex-m",
"embedded-dma 0.1.2",
"embedded-dma",
"embedded-hal",
"embedded-storage",
"fixed",

View File

@ -8,9 +8,9 @@ edition = "2021"
[dependencies]
cortex-m-rt = "0.7.0"
embedded-hal = "0.2.6"
gd32f1 = { version = "0.6.0", features = ["gd32f130", "rt"] }
gd32f1x0-hal = { version = "0.7.1", features = ["rt", "gd32f130x8"] }
microbit-v2 = "0.13.0"
nrf52833-hal = "0.14.1"
nrf52833-pac = { version = "0.10.1", features = ["rt"] }
panic-halt = "0.2.0"
[[bin]]

View File

@ -1,6 +0,0 @@
MEMORY
{
/* Memory layout for GD32F130C8T. */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 8K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 64K
}

View File

@ -19,21 +19,26 @@
extern crate panic_halt as _;
use cortex_m_rt::entry;
use gd32f1x0_hal::{pac::Peripherals, prelude::*};
use nrf52833_hal::{
gpio::{p0, Level},
pac::Peripherals,
prelude::*,
};
#[entry]
fn main() -> ! {
let p = Peripherals::take().unwrap();
let mut rcu = p.RCU.constrain();
// Enable GPIOC.
let mut gpioc = p.GPIOC.split(&mut rcu.ahb);
// GPIO port 0.
let gpio0 = p0::Parts::new(p.P0);
// Configure PC9 as a push-pull output.
let mut led = gpioc.pc9.into_push_pull_output(&mut gpioc.config);
// Configure GPIO 0 pins 21 and 28 as push-pull outputs.
let mut col1 = gpio0.p0_28.into_push_pull_output(Level::High);
let mut row1 = gpio0.p0_21.into_push_pull_output(Level::Low);
// Set PC9 high to turn the LED on.
led.set_high().unwrap();
// Set pin 28 low and pin 21 high to turn the LED on.
col1.set_low().unwrap();
row1.set_high().unwrap();
loop {}
}

View File

@ -19,23 +19,34 @@
extern crate panic_halt as _;
use cortex_m_rt::entry;
use gd32f1::gd32f130::Peripherals;
use nrf52833_pac::Peripherals;
#[entry]
fn main() -> ! {
let p = Peripherals::take().unwrap();
let gpioc = p.GPIOC;
let gpio0 = p.P0;
// Enable GPIOC.
p.RCU.ahben.modify(|_, w| w.pcen().enabled());
// Configure GPIO 0 pins 21 and 28 as push-pull outputs.
gpio0.pin_cnf[21].write(|w| {
w.dir().output();
w.input().disconnect();
w.pull().disabled();
w.drive().s0s1();
w.sense().disabled();
w
});
gpio0.pin_cnf[28].write(|w| {
w.dir().output();
w.input().disconnect();
w.pull().disabled();
w.drive().s0s1();
w.sense().disabled();
w
});
// Configure PC9 as a push-pull output.
gpioc.pud.modify(|_, w| w.pud9().floating());
gpioc.omode.modify(|_, w| w.om9().push_pull());
gpioc.ctl.modify(|_, w| w.ctl9().output());
// Set PC9 high to turn the LED on.
gpioc.bop.write(|w| w.bop9().set());
// Set pin 28 low and pin 21 high to turn the LED on.
gpio0.outclr.write(|w| w.pin28().clear());
gpio0.outset.write(|w| w.pin21().set());
loop {}
}

View File

@ -18,10 +18,10 @@
extern crate panic_halt as _;
use cortex_m_rt::entry;
use gd32f1x0_hal::{
use nrf52833_hal::{
gpio::{
gpioc::{PC1, PC2, PC9},
Floating, Input, OpenDrain, Output, PushPull,
p0::{self, P0_01, P0_02, P0_03},
Disconnected, Floating, Input, Level, OpenDrain, OpenDrainConfig, Output, PushPull,
},
pac::Peripherals,
prelude::*,
@ -31,20 +31,24 @@ use gd32f1x0_hal::{
#[entry]
fn main() -> ! {
let p = Peripherals::take().unwrap();
let mut rcu = p.RCU.constrain();
let mut gpioc = p.GPIOC.split(&mut rcu.ahb);
let pc9: PC9<Input<Floating>> = gpioc.pc9;
// let pc9_again = gpioc.pc9; // Error, moved.
if pc9.is_high().unwrap() {
let gpio0 = p0::Parts::new(p.P0);
let pin: P0_01<Disconnected> = gpio0.p0_01;
// let gpio0_01_again = gpio0.p0_01; // Error, moved.
let pin_input: P0_01<Input<Floating>> = pin.into_floating_input();
if pin_input.is_high().unwrap() {
// ...
}
let mut pc9_output: PC9<Output<OpenDrain>> =
pc9.into_open_drain_output(&mut gpioc.config);
pc9_output.set_high().unwrap();
// pc9.is_high(); // Error, moved.
let mut pin_output: P0_01<Output<OpenDrain>> =
pin_input.into_open_drain_output(OpenDrainConfig::Disconnect0Standard1, Level::Low);
pin_output.set_high().unwrap();
// pin_input.is_high(); // Error, moved.
let _pc1: PC1<Output<OpenDrain>> = gpioc.pc1.into_open_drain_output(&mut gpioc.config);
let _pc2: PC2<Output<PushPull>> = gpioc.pc2.into_push_pull_output(&mut gpioc.config);
let _pin2: P0_02<Output<OpenDrain>> = gpio0
.p0_02
.into_open_drain_output(OpenDrainConfig::Disconnect0Standard1, Level::Low);
let _pin3: P0_03<Output<PushPull>> = gpio0.p0_03.into_push_pull_output(Level::Low);
loop {}
}