Skip to content

Commit 1ce2dc6

Browse files
committed
Apply updates to rp235x-hal-examples
1 parent 249d9b7 commit 1ce2dc6

File tree

5 files changed

+29
-33
lines changed

5 files changed

+29
-33
lines changed

rp235x-hal-examples/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ cortex-m-rtic = "1.1.4"
1818
critical-section = {version = "1.2.0"}
1919
defmt = "0.3"
2020
defmt-rtt = "0.4.0"
21-
dht-sensor = "0.2.1"
21+
dht-sensor = { version = "0.2.1", git = "https://github.com/michaelbeaumont/dht-sensor", rev = "10319bdeae9ace3bb0fc79a15da2869c5bf50f52" }
2222
embedded-alloc = "0.5.1"
2323
embedded-hal = "1.0.0"
2424
embedded-hal-async = "1.0.0"
25+
embedded-hal-bus = {version = "0.3.0", features = ["defmt-03"]}
2526
embedded-io = "0.7.1"
2627
embedded_hal_0_2 = {package = "embedded-hal", version = "0.2.5", features = ["unproven"]}
2728
fugit = "0.3.6"
2829
futures = {version = "0.3.30", default-features = false, features = ["async-await"]}
29-
hd44780-driver = "0.4.0"
30+
hd44780-driver = { version = "0.4.0", git = "https://github.com/JohnDoneth/hd44780-driver", rev = "9009f2c24771ba0a20f8f7534471c9869188f76c" }
3031
heapless = "0.8.0"
3132
nb = "1.0"
3233
panic-halt = "0.2.0"

rp235x-hal-examples/src/bin/dht11.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe();
3131
/// Adjust if your board has a different frequency
3232
const XTAL_FREQ_HZ: u32 = 12_000_000u32;
3333

34-
use dht_sensor::{dht11, DhtReading};
34+
use dht_sensor::dht11;
3535

3636
/// Entry point to our bare-metal application.
3737
///
@@ -71,14 +71,14 @@ fn main() -> ! {
7171
&mut pac.RESETS,
7272
);
7373

74-
let mut delay = hal::Timer::new_timer0(pac.TIMER0, &mut pac.RESETS, &clocks);
74+
let mut timer = hal::Timer::new_timer0(pac.TIMER0, &mut pac.RESETS, &clocks);
7575

7676
// Use GPIO 28 as an InOutPin
7777
let mut pin = hal::gpio::InOutPin::new(pins.gpio28);
7878
let _ = pin.set_high();
7979

8080
// Perform a sensor reading
81-
let _measurement = dht11::Reading::read(&mut delay, &mut pin);
81+
let _measurement = dht11::blocking::read(&mut timer, &mut pin);
8282

8383
// In this case, we just ignore the result. A real application
8484
// would do something with the measurement.

rp235x-hal-examples/src/bin/i2c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use panic_halt as _;
1717
use rp235x_hal as hal;
1818

1919
// Some things we need
20-
use embedded_hal_0_2::blocking::i2c::Write;
20+
use embedded_hal::i2c::I2c;
2121
use hal::fugit::RateExtU32;
2222
use hal::gpio::{FunctionI2C, Pin};
2323

rp235x-hal-examples/src/bin/lcd_display.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ use panic_halt as _;
2020
use rp235x_hal as hal;
2121

2222
// Our LCD driver
23-
use hd44780_driver as hd44780;
23+
use hd44780_driver::{
24+
self as hd44780, bus::FourBitBusPins, memory_map::MemoryMap1602, setup::DisplayOptions4Bit,
25+
};
2426

2527
/// Tell the Boot ROM about our application
2628
#[link_section = ".start_block"]
@@ -74,16 +76,15 @@ fn main() -> ! {
7476
);
7577

7678
// Create the LCD driver from some GPIO pins
77-
let mut lcd = hd44780::HD44780::new_4bit(
78-
pins.gpio16.into_push_pull_output(), // Register Select
79-
pins.gpio17.into_push_pull_output(), // Enable
80-
pins.gpio18.into_push_pull_output(), // d4
81-
pins.gpio19.into_push_pull_output(), // d5
82-
pins.gpio20.into_push_pull_output(), // d6
83-
pins.gpio21.into_push_pull_output(), // d7
84-
&mut delay,
85-
)
86-
.unwrap();
79+
let options = DisplayOptions4Bit::new(MemoryMap1602::new()).with_pins(FourBitBusPins {
80+
rs: pins.gpio16.into_push_pull_output(), // Register Select
81+
en: pins.gpio17.into_push_pull_output(), // Enable
82+
d4: pins.gpio18.into_push_pull_output(), // d4
83+
d5: pins.gpio19.into_push_pull_output(), // d5
84+
d6: pins.gpio20.into_push_pull_output(), // d6
85+
d7: pins.gpio21.into_push_pull_output(), // d7
86+
});
87+
let mut lcd = hd44780::HD44780::new(options, &mut delay).unwrap();
8788

8889
// Clear the screen
8990
lcd.reset(&mut delay).unwrap();

rp235x-hal-examples/src/bin/spi.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#![no_std]
1313
#![no_main]
1414

15+
use embedded_hal::spi::SpiDevice;
16+
use embedded_hal_bus::spi::ExclusiveDevice;
1517
// Ensure we halt the program on panic (if we don't mention this crate it won't
1618
// be linked)
1719
use panic_halt as _;
@@ -20,7 +22,6 @@ use panic_halt as _;
2022
use rp235x_hal as hal;
2123

2224
// Some things we need
23-
use embedded_hal_0_2::prelude::*;
2425
use hal::clocks::Clock;
2526
use hal::fugit::RateExtU32;
2627

@@ -60,6 +61,8 @@ fn main() -> ! {
6061
)
6162
.unwrap();
6263

64+
let mut timer = hal::Timer::new_timer0(pac.TIMER0, &mut pac.RESETS, &clocks);
65+
6366
// The single-cycle I/O block controls our GPIO pins
6467
let sio = hal::Sio::new(pac.SIO);
6568

@@ -78,34 +81,25 @@ fn main() -> ! {
7881
let spi_bus = hal::spi::Spi::<_, _, _, 8>::new(pac.SPI0, (spi_mosi, spi_miso, spi_sclk));
7982

8083
// Exchange the uninitialised SPI driver for an initialised one
81-
let mut spi_bus = spi_bus.init(
84+
let spi_bus = spi_bus.init(
8285
&mut pac.RESETS,
8386
clocks.peripheral_clock.freq(),
8487
16.MHz(),
8588
embedded_hal::spi::MODE_0,
8689
);
8790

91+
let spi_cs = pins.gpio8.into_function::<hal::gpio::FunctionSioOutput>();
92+
let mut spi = ExclusiveDevice::new(spi_bus, spi_cs, &mut timer).unwrap();
93+
8894
// Write out 0, ignore return value
89-
if spi_bus.write(&[0]).is_ok() {
95+
if spi.write(&[0]).is_ok() {
9096
// SPI write was successful
9197
};
9298

93-
// write 50, then check the return
94-
let send_success = spi_bus.send(50);
95-
match send_success {
96-
Ok(_) => {
97-
// We succeeded, check the read value
98-
if let Ok(_x) = spi_bus.read() {
99-
// We got back `x` in exchange for the 0x50 we sent.
100-
};
101-
}
102-
Err(_) => todo!(),
103-
}
104-
10599
// Do a read+write at the same time. Data in `buffer` will be replaced with
106100
// the data read from the SPI device.
107101
let mut buffer: [u8; 4] = [1, 2, 3, 4];
108-
let transfer_success = spi_bus.transfer(&mut buffer);
102+
let transfer_success = spi.transfer_in_place(&mut buffer);
109103
#[allow(clippy::single_match)]
110104
match transfer_success {
111105
Ok(_) => {} // Handle success

0 commit comments

Comments
 (0)