Skip to content

Commit 827ff24

Browse files
committed
Adapt embedded-hal v1.0.0-alpha.1
1 parent 735e5dd commit 827ff24

File tree

6 files changed

+22
-28
lines changed

6 files changed

+22
-28
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ edition = "2018"
1313
targets = ["riscv64gc-unknown-none-elf"]
1414

1515
[dependencies]
16-
embedded-hal = { version = "0.2.3", features = ["unproven"] }
16+
embedded-hal = "1.0.0-alpha.1"
1717
nb = "0.1.1"
1818
k210-pac = "0.2.0"
1919
bitflags = "1.2.1"

src/gpio.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::pac;
55
use crate::sysctl::{self, APB0};
66
use crate::fpioa::{IoPin, Pull, Mode};
77
use crate::bit_utils::{u32_set_bit, u32_toggle_bit, u32_bit_is_set, u32_bit_is_clear};
8-
use embedded_hal::digital::v2::{OutputPin, StatefulOutputPin, InputPin, ToggleableOutputPin};
8+
use embedded_hal::digital::{OutputPin, StatefulOutputPin, InputPin, ToggleableOutputPin};
99

1010
/// Extension trait to split a GPIO peripheral into independent pins
1111
pub trait GpioExt {
@@ -169,14 +169,14 @@ impl<GPIO: GpioIndex, PIN: IoPin, MODE: Active> Gpio<GPIO, PIN, MODE> {
169169
impl<GPIO: GpioIndex, PIN, MODE> InputPin for Gpio<GPIO, PIN, Input<MODE>> {
170170
type Error = core::convert::Infallible;
171171

172-
fn is_high(&self) -> Result<bool, Self::Error> {
172+
fn try_is_high(&self) -> Result<bool, Self::Error> {
173173
Ok(unsafe {
174174
let p = &(*pac::GPIO::ptr()).data_input as *const _ as *const _;
175175
u32_bit_is_set(p, GPIO::INDEX as usize)
176176
})
177177
}
178178

179-
fn is_low(&self) -> Result<bool, Self::Error> {
179+
fn try_is_low(&self) -> Result<bool, Self::Error> {
180180
Ok(unsafe {
181181
let p = &(*pac::GPIO::ptr()).data_input as *const _ as *const _;
182182
u32_bit_is_clear(p, GPIO::INDEX as usize)
@@ -187,15 +187,15 @@ impl<GPIO: GpioIndex, PIN, MODE> InputPin for Gpio<GPIO, PIN, Input<MODE>> {
187187
impl<GPIO: GpioIndex, PIN> OutputPin for Gpio<GPIO, PIN, Output> {
188188
type Error = core::convert::Infallible;
189189

190-
fn set_high(&mut self) -> Result<(), Self::Error> {
190+
fn try_set_high(&mut self) -> Result<(), Self::Error> {
191191
unsafe {
192192
let p = &(*pac::GPIO::ptr()).data_output as *const _ as *mut _;
193193
u32_set_bit(p, true, GPIO::INDEX as usize);
194194
}
195195
Ok(())
196196
}
197197

198-
fn set_low(&mut self) -> Result<(), Self::Error> {
198+
fn try_set_low(&mut self) -> Result<(), Self::Error> {
199199
unsafe {
200200
let p = &(*pac::GPIO::ptr()).data_output as *const _ as *mut _;
201201
u32_set_bit(p, false, GPIO::INDEX as usize);
@@ -205,14 +205,14 @@ impl<GPIO: GpioIndex, PIN> OutputPin for Gpio<GPIO, PIN, Output> {
205205
}
206206

207207
impl<GPIO: GpioIndex, PIN> StatefulOutputPin for Gpio<GPIO, PIN, Output> {
208-
fn is_set_high(&self) -> Result<bool, Self::Error> {
208+
fn try_is_set_high(&self) -> Result<bool, Self::Error> {
209209
Ok(unsafe {
210210
let p = &(*pac::GPIO::ptr()).data_output as *const _ as *const _;
211211
u32_bit_is_set(p, GPIO::INDEX as usize)
212212
})
213213
}
214214

215-
fn is_set_low(&self) -> Result<bool, Self::Error> {
215+
fn try_is_set_low(&self) -> Result<bool, Self::Error> {
216216
Ok(unsafe {
217217
let p = &(*pac::GPIO::ptr()).data_output as *const _ as *const _;
218218
u32_bit_is_clear(p, GPIO::INDEX as usize)
@@ -223,7 +223,7 @@ impl<GPIO: GpioIndex, PIN> StatefulOutputPin for Gpio<GPIO, PIN, Output> {
223223
impl<GPIO: GpioIndex, PIN> ToggleableOutputPin for Gpio<GPIO, PIN, Output> {
224224
type Error = core::convert::Infallible;
225225

226-
fn toggle(&mut self) -> Result<(), Self::Error> {
226+
fn try_toggle(&mut self) -> Result<(), Self::Error> {
227227
unsafe {
228228
let p = &(*pac::GPIO::ptr()).data_output as *const _ as *mut _;
229229
u32_toggle_bit(p, GPIO::INDEX as usize);

src/gpiohs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::pac::GPIOHS;
44
use core::marker::PhantomData;
55
use crate::bit_utils::{u32_set_bit, u32_toggle_bit, u32_bit_is_set, u32_bit_is_clear};
6-
use embedded_hal::digital::v2::{InputPin, OutputPin};
6+
use embedded_hal::digital::{InputPin, OutputPin};
77

88
// todo: verify
99

@@ -117,14 +117,14 @@ impl<MODE> Gpiohs0<MODE> {
117117
impl<MODE> InputPin for Gpiohs0<Input<MODE>> {
118118
type Error = core::convert::Infallible;
119119

120-
fn is_high(&self) -> Result<bool, Self::Error> {
120+
fn try_is_high(&self) -> Result<bool, Self::Error> {
121121
Ok(unsafe {
122122
let p = &(*GPIOHS::ptr()).input_val as *const _ as *const _;
123123
u32_bit_is_set(p, 0)
124124
})
125125
}
126126

127-
fn is_low(&self) -> Result<bool, Self::Error> {
127+
fn try_is_low(&self) -> Result<bool, Self::Error> {
128128
Ok(unsafe {
129129
let p = &(*GPIOHS::ptr()).input_val as *const _ as *const _;
130130
u32_bit_is_clear(p, 0)
@@ -135,15 +135,15 @@ impl<MODE> InputPin for Gpiohs0<Input<MODE>> {
135135
impl<MODE> OutputPin for Gpiohs0<Output<MODE>> {
136136
type Error = core::convert::Infallible;
137137

138-
fn set_high(&mut self) -> Result<(), Self::Error> {
138+
fn try_set_high(&mut self) -> Result<(), Self::Error> {
139139
unsafe {
140140
let p = &(*GPIOHS::ptr()).output_val as *const _ as *mut _;
141141
u32_set_bit(p, true, 0);
142142
}
143143
Ok(())
144144
}
145145

146-
fn set_low(&mut self) -> Result<(), Self::Error> {
146+
fn try_set_low(&mut self) -> Result<(), Self::Error> {
147147
unsafe {
148148
let p = &(*GPIOHS::ptr()).output_val as *const _ as *mut _;
149149
u32_set_bit(p, false, 0);

src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ pub mod time;
2727
/// Prelude
2828
pub mod prelude {
2929
pub use embedded_hal::prelude::*;
30-
pub use embedded_hal::digital::v2::{
31-
InputPin as _embedded_hal_digital_v2_InputPin,
32-
OutputPin as _embedded_hal_digital_v2_OutputPin,
33-
StatefulOutputPin as _embedded_hal_digital_v2_StatefulOutputPin,
34-
ToggleableOutputPin as _embedded_hal_digital_v2_ToggleableOutputPin,
35-
};
3630
pub use crate::serial::SerialExt as _k210_hal_serial_SerialExt;
3731
pub use crate::stdout::Write as _k210_hal_stdout_Write;
3832
pub use crate::time::U32Ext as _k210_hal_time_U32Ext;

src/serial.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl Serial<UARTHS> {
100100
impl serial::Read<u8> for Rx<UARTHS> {
101101
type Error = Infallible;
102102

103-
fn read(&mut self) -> nb::Result<u8, Infallible> {
103+
fn try_read(&mut self) -> nb::Result<u8, Infallible> {
104104
let rxdata = self.uart.rxdata.read();
105105

106106
if rxdata.empty().bit_is_set() {
@@ -114,7 +114,7 @@ impl serial::Read<u8> for Rx<UARTHS> {
114114
impl serial::Write<u8> for Tx<UARTHS> {
115115
type Error = Infallible;
116116

117-
fn write(&mut self, byte: u8) -> nb::Result<(), Infallible> {
117+
fn try_write(&mut self, byte: u8) -> nb::Result<(), Infallible> {
118118
let txdata = self.uart.txdata.read();
119119

120120
if txdata.full().bit_is_set() {
@@ -127,7 +127,7 @@ impl serial::Write<u8> for Tx<UARTHS> {
127127
}
128128
}
129129

130-
fn flush(&mut self) -> nb::Result<(), Infallible> {
130+
fn try_flush(&mut self) -> nb::Result<(), Infallible> {
131131
let txdata = self.uart.txdata.read();
132132

133133
if txdata.full().bit_is_set() {
@@ -200,7 +200,7 @@ impl<UART: UartX> Serial<UART> {
200200
impl<UART: UartX> serial::Read<u8> for Rx<UART> {
201201
type Error = Infallible;
202202

203-
fn read(&mut self) -> nb::Result<u8, Infallible> {
203+
fn try_read(&mut self) -> nb::Result<u8, Infallible> {
204204
let lsr = self.uart.lsr.read();
205205

206206
if (lsr.bits() & (1<<0)) == 0 { // Data Ready bit
@@ -215,7 +215,7 @@ impl<UART: UartX> serial::Read<u8> for Rx<UART> {
215215
impl<UART: UartX> serial::Write<u8> for Tx<UART> {
216216
type Error = Infallible;
217217

218-
fn write(&mut self, byte: u8) -> nb::Result<(), Infallible> {
218+
fn try_write(&mut self, byte: u8) -> nb::Result<(), Infallible> {
219219
let lsr = self.uart.lsr.read();
220220

221221
if (lsr.bits() & (1<<5)) != 0 { // Transmit Holding Register Empty bit
@@ -228,7 +228,7 @@ impl<UART: UartX> serial::Write<u8> for Tx<UART> {
228228
}
229229
}
230230

231-
fn flush(&mut self) -> nb::Result<(), Infallible> {
231+
fn try_flush(&mut self) -> nb::Result<(), Infallible> {
232232
// TODO
233233
Ok(())
234234
}

src/stdout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ impl<'p, T> Write for Stdout<'p, T>
1313
fn write_str(&mut self, s: &str) -> core::fmt::Result {
1414
for byte in s.as_bytes() {
1515
if *byte == b'\n' {
16-
let res = block!(self.0.write(b'\r'));
16+
let res = block!(self.0.try_write(b'\r'));
1717

1818
if res.is_err() {
1919
return Err(core::fmt::Error);
2020
}
2121
}
2222

23-
let res = block!(self.0.write(*byte));
23+
let res = block!(self.0.try_write(*byte));
2424

2525
if res.is_err() {
2626
return Err(core::fmt::Error);

0 commit comments

Comments
 (0)