1
1
#![ no_std]
2
- //#![feature(specialization)]
3
2
4
3
mod control_word;
5
4
mod font5x7;
6
5
7
6
pub use control_word:: PeakCurrent ;
8
7
use control_word:: * ;
9
8
use core:: cell:: RefCell ;
10
- use embedded_hal:: digital:: { Error , ErrorKind , ErrorType , OutputPin } ;
9
+ use embedded_hal:: digital:: { ErrorType , OutputPin } ;
11
10
12
11
pub const CHAR_WIDTH : usize = 5 ;
13
12
const DEVICE_CHARS : u8 = 4 ;
14
13
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
+
15
30
#[ derive( Debug ) ]
16
31
pub enum Hcms29xxError < PinErr > {
17
32
PinNotConfigured ,
@@ -24,43 +39,15 @@ pub enum Hcms29xxError<PinErr> {
24
39
ResetPinError ( PinErr ) ,
25
40
}
26
41
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
-
55
42
pub struct Hcms29xx <
56
- const NUM_CHARS : usize ,
57
43
DataPin ,
58
44
RsPin ,
59
45
ClkPin ,
60
46
CePin ,
61
- BlankPin = UnconfiguredPin ,
62
- OscSelPin = UnconfiguredPin ,
63
- ResetPin = UnconfiguredPin ,
47
+ BlankPin ,
48
+ OscSelPin ,
49
+ ResetPin ,
50
+ const NUM_CHARS : usize ,
64
51
> where
65
52
DataPin : OutputPin ,
66
53
RsPin : OutputPin ,
@@ -85,7 +72,6 @@ pub struct Hcms29xx<
85
72
}
86
73
87
74
impl <
88
- const NUM_CHARS : usize ,
89
75
DataPin ,
90
76
RsPin ,
91
77
ClkPin ,
94
80
OscSelPin ,
95
81
ResetPin ,
96
82
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 >
98
85
where
99
86
DataPin : OutputPin + ErrorType < Error = PinErr > ,
100
87
RsPin : OutputPin + ErrorType < Error = PinErr > ,
@@ -109,22 +96,17 @@ where
109
96
rs : RsPin ,
110
97
clk : ClkPin ,
111
98
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 > > {
121
103
let data_ref_cell = RefCell :: new ( data) ;
122
104
let rs_ref_cell = RefCell :: new ( rs) ;
123
105
let clk_ref_cell = RefCell :: new ( clk) ;
124
106
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) ;
128
110
129
111
data_ref_cell
130
112
. borrow_mut ( )
@@ -134,25 +116,19 @@ where
134
116
. borrow_mut ( )
135
117
. set_high ( )
136
118
. 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 ) ?;
156
132
157
133
Ok ( Hcms29xx {
158
134
data : data_ref_cell,
0 commit comments