Skip to content

Commit 690417f

Browse files
committed
compiling again
1 parent 0917f35 commit 690417f

File tree

3 files changed

+53
-75
lines changed

3 files changed

+53
-75
lines changed

examples/arduino-uno/src/main.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![no_main]
33

44
use arduino_hal::prelude::*;
5+
use hcms_29xx::UnconfiguredPin;
56
use panic_halt as _;
67

78
const MESSAGE: &[u8] = b"Hello from Rust on Arduino!";
@@ -13,15 +14,15 @@ fn main() -> ! {
1314
let pins = arduino_hal::pins!(dp);
1415
let mut serial = arduino_hal::default_serial!(dp, pins, 57600);
1516

16-
let mut display = hcms_29xx::Hcms29xx::<_, _, _, _, _, _, _, NUM_CHARS>::new(
17-
pins.d2.into_output(), // Data pin
18-
pins.d3.into_output(), // RS pin
19-
pins.d4.into_output(), // Clock pin
20-
pins.d5.into_output(), // CE pin
21-
// if optional pins not specified, logic levels should set in elsewhere
22-
None, // Optional: Blank pin
23-
None, // Optional: OscSel pin
24-
None, // Optional: Reset pin
17+
let mut display = hcms_29xx::Hcms29xx::<NUM_CHARS, _, _, _, _>::new(
18+
pins.d2.into_output(), // Data pin
19+
pins.d3.into_output(), // RS pin
20+
pins.d4.into_output(), // Clock pin
21+
pins.d5.into_output(), // CE pin
22+
// if optional pins not specified, logic levels should set elsewhere
23+
UnconfiguredPin, // Optional: Blank pin
24+
UnconfiguredPin, // Optional: OscSel pin
25+
UnconfiguredPin, // Optional: Reset pin
2526
)
2627
.unwrap();
2728

examples/esp32-s3/src/bin/main.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use esp_hal::{
88
gpio::{Level, Output},
99
main,
1010
};
11+
use hcms_29xx::UnconfiguredPin;
1112
use log::info;
1213

1314
const MESSAGE: &[u8] = b"Hello from Rust on ESP32-S3! ";
@@ -21,15 +22,15 @@ fn main() -> ! {
2122
esp_println::logger::init_logger_from_env();
2223

2324
let delay = Delay::new();
24-
let mut display = hcms_29xx::Hcms29xx::<NUM_CHARS, _, _, _, _, _, _, _>::new(
25+
let mut display = hcms_29xx::Hcms29xx::<NUM_CHARS, _, _, _, _, _>::new(
2526
Output::new(peripherals.GPIO35, Level::Low), // Data pin
2627
Output::new(peripherals.GPIO37, Level::Low), // RS pin
2728
Output::new(peripherals.GPIO36, Level::Low), // Clock pin
2829
Output::new(peripherals.GPIO34, Level::Low), // CE pin
29-
// if optional pins not specified, logic levels should set in elsewhere
30-
None, // Optional: Blank pin
31-
None, // Optional: OscSel pin
32-
None, // Optional: Reset pin
30+
// if optional pins not specified, logic levels should set elsewhere
31+
UnconfiguredPin, // Optional: Blank pin
32+
UnconfiguredPin, // Optional: OscSel pin
33+
UnconfiguredPin, // Optional: Reset pin
3334
)
3435
.unwrap();
3536
display.begin().unwrap();

src/lib.rs

+37-61
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
#![no_std]
2-
//#![feature(specialization)]
32

43
mod control_word;
54
mod font5x7;
65

76
pub use control_word::PeakCurrent;
87
use control_word::*;
98
use core::cell::RefCell;
10-
use embedded_hal::digital::{Error, ErrorKind, ErrorType, OutputPin};
9+
use embedded_hal::digital::{ErrorType, OutputPin};
1110

1211
pub const CHAR_WIDTH: usize = 5;
1312
const DEVICE_CHARS: u8 = 4;
1413

14+
pub struct UnconfiguredPin;
15+
16+
impl OutputPin for UnconfiguredPin {
17+
fn set_low(&mut self) -> Result<(), Self::Error> {
18+
Ok(())
19+
}
20+
21+
fn set_high(&mut self) -> Result<(), Self::Error> {
22+
Ok(())
23+
}
24+
}
25+
26+
impl ErrorType for UnconfiguredPin {
27+
type Error = core::convert::Infallible;
28+
}
29+
1530
#[derive(Debug)]
1631
pub enum Hcms29xxError<PinErr> {
1732
PinNotConfigured,
@@ -24,34 +39,6 @@ pub enum Hcms29xxError<PinErr> {
2439
ResetPinError(PinErr),
2540
}
2641

27-
#[derive(Debug)]
28-
pub enum PinError {
29-
PinNotConfigured,
30-
}
31-
32-
impl Error for PinError {
33-
fn kind(&self) -> ErrorKind {
34-
ErrorKind::Other
35-
}
36-
}
37-
38-
// TODO: try specialization when stable soe pin configuration bugs fail to compile
39-
pub struct UnconfiguredPin;
40-
41-
impl ErrorType for UnconfiguredPin {
42-
type Error = PinError;
43-
}
44-
45-
impl OutputPin for UnconfiguredPin {
46-
fn set_high(&mut self) -> Result<(), Self::Error> {
47-
Err(PinError::PinNotConfigured)
48-
}
49-
50-
fn set_low(&mut self) -> Result<(), Self::Error> {
51-
Err(PinError::PinNotConfigured)
52-
}
53-
}
54-
5542
pub struct Hcms29xx<
5643
const NUM_CHARS: usize,
5744
DataPin,
@@ -109,22 +96,17 @@ where
10996
rs: RsPin,
11097
clk: ClkPin,
11198
ce: CePin,
112-
blank: Option<BlankPin>,
113-
osc_sel: Option<OscSelPin>,
114-
reset: Option<ResetPin>,
115-
) -> Result<Self, Hcms29xxError<PinErr>>
116-
where
117-
BlankPin: OutputPin + ErrorType<Error = PinErr>,
118-
OscSelPin: OutputPin + ErrorType<Error = PinErr>,
119-
ResetPin: OutputPin + ErrorType<Error = PinErr>,
120-
{
99+
blank: BlankPin,
100+
osc_sel: OscSelPin,
101+
reset: ResetPin,
102+
) -> Result<Self, Hcms29xxError<PinErr>> {
121103
let data_ref_cell = RefCell::new(data);
122104
let rs_ref_cell = RefCell::new(rs);
123105
let clk_ref_cell = RefCell::new(clk);
124106
let ce_ref_cell = RefCell::new(ce);
125-
let blank_ref_cell = RefCell::new(blank.unwrap());
126-
let osc_sel_ref_cell = RefCell::new(osc_sel.unwrap());
127-
let reset_ref_cell = RefCell::new(reset.unwrap());
107+
let blank_ref_cell = RefCell::new(blank);
108+
let osc_sel_ref_cell = RefCell::new(osc_sel);
109+
let reset_ref_cell = RefCell::new(reset);
128110

129111
data_ref_cell
130112
.borrow_mut()
@@ -134,25 +116,19 @@ where
134116
.borrow_mut()
135117
.set_high()
136118
.map_err(Hcms29xxError::CePinError)?;
137-
// if let Some(ref blank) = blank_ref_cell {
138-
// blank
139-
// .borrow_mut()
140-
// .set_high()
141-
// .map_err(Hcms29xxError::BlankPinError)?;
142-
// }
143-
// // default to internal oscillator, user can set ext osc if needed
144-
// if let Some(ref osc_sel) = osc_sel_ref_cell {
145-
// osc_sel
146-
// .borrow_mut()
147-
// .set_high()
148-
// .map_err(Hcms29xxError::OscSelPinError)?;
149-
// }
150-
// if let Some(ref reset) = reset_ref_cell {
151-
// reset
152-
// .borrow_mut()
153-
// .set_high()
154-
// .map_err(Hcms29xxError::ResetPinError)?;
155-
// }
119+
blank_ref_cell
120+
.borrow_mut()
121+
.set_high()
122+
.map_err(Hcms29xxError::BlankPinError)?;
123+
// default to internal oscillator, user can set ext osc if needed
124+
osc_sel_ref_cell
125+
.borrow_mut()
126+
.set_high()
127+
.map_err(Hcms29xxError::OscSelPinError)?;
128+
reset_ref_cell
129+
.borrow_mut()
130+
.set_high()
131+
.map_err(Hcms29xxError::ResetPinError)?;
156132

157133
Ok(Hcms29xx {
158134
data: data_ref_cell,

0 commit comments

Comments
 (0)