Skip to content

Commit cb864f0

Browse files
committed
compiling again
1 parent 0917f35 commit cb864f0

File tree

2 files changed

+53
-76
lines changed

2 files changed

+53
-76
lines changed

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

+10-9
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-
Output::new(peripherals.GPIO35, Level::Low), // Data pin
26-
Output::new(peripherals.GPIO37, Level::Low), // RS pin
27-
Output::new(peripherals.GPIO36, Level::Low), // Clock pin
28-
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
25+
let mut display = hcms_29xx::Hcms29xx::<_, _, _, _, _, _, _, NUM_CHARS>::new(
26+
Output::new(peripherals.GPIO35, Level::Low), // Data pin
27+
Output::new(peripherals.GPIO37, Level::Low), // RS pin
28+
Output::new(peripherals.GPIO36, Level::Low), // Clock pin
29+
Output::new(peripherals.GPIO34, Level::Low), // CE 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

+43-67
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,43 +39,15 @@ 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<
56-
const NUM_CHARS: usize,
5743
DataPin,
5844
RsPin,
5945
ClkPin,
6046
CePin,
61-
BlankPin = UnconfiguredPin,
62-
OscSelPin = UnconfiguredPin,
63-
ResetPin = UnconfiguredPin,
47+
BlankPin,
48+
OscSelPin,
49+
ResetPin,
50+
const NUM_CHARS: usize,
6451
> where
6552
DataPin: OutputPin,
6653
RsPin: OutputPin,
@@ -85,7 +72,6 @@ pub struct Hcms29xx<
8572
}
8673

8774
impl<
88-
const NUM_CHARS: usize,
8975
DataPin,
9076
RsPin,
9177
ClkPin,
@@ -94,7 +80,8 @@ impl<
9480
OscSelPin,
9581
ResetPin,
9682
PinErr,
97-
> Hcms29xx<NUM_CHARS, DataPin, RsPin, ClkPin, CePin, BlankPin, OscSelPin, ResetPin>
83+
const NUM_CHARS: usize,
84+
> Hcms29xx<DataPin, RsPin, ClkPin, CePin, BlankPin, OscSelPin, ResetPin, NUM_CHARS>
9885
where
9986
DataPin: OutputPin + ErrorType<Error = PinErr>,
10087
RsPin: OutputPin + ErrorType<Error = PinErr>,
@@ -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)