@@ -12,14 +12,6 @@ impl ControlWord0 {
12
12
pub const BRIGHTNESS_MASK : u8 = 0b0000_1111 ;
13
13
pub const BRIGHTNESS_DEFAULT : u8 = 0b0000_1100 ;
14
14
15
- pub fn new ( ) -> Self {
16
- let mut word = ControlWord0 ( Self :: WORD_SELECT_BIT ) ; // MSB is always 0
17
- word. set_brightness_bits ( Self :: BRIGHTNESS_DEFAULT ) ;
18
- word. set_peak_current_bits ( PeakCurrent :: default ( ) ) ;
19
- word. set_wake_bit ( SleepMode :: default ( ) ) ;
20
- word
21
- }
22
-
23
15
pub fn set_brightness_bits ( & mut self , brightness : u8 ) {
24
16
// just truncate the bits rather than enforce or check for a max value
25
17
self . 0 = ( self . 0 & !Self :: BRIGHTNESS_MASK ) | ( brightness & Self :: BRIGHTNESS_MASK ) ;
@@ -38,6 +30,16 @@ impl ControlWord0 {
38
30
}
39
31
}
40
32
33
+ impl Default for ControlWord0 {
34
+ fn default ( ) -> Self {
35
+ let mut control_word = ControlWord0 ( Self :: WORD_SELECT_BIT ) ; // MSB is always 0
36
+ control_word. set_brightness_bits ( Self :: BRIGHTNESS_DEFAULT ) ;
37
+ control_word. set_peak_current_bits ( PeakCurrent :: default ( ) ) ;
38
+ control_word. set_wake_bit ( SleepMode :: default ( ) ) ;
39
+ control_word
40
+ }
41
+ }
42
+
41
43
pub enum SleepMode {
42
44
Sleep = 0b0000_0000 ,
43
45
Normal = 0b0100_0000 ,
@@ -57,12 +59,6 @@ pub enum PeakCurrent {
57
59
Max12_8Ma = 0b0011_0000 ,
58
60
}
59
61
60
- // impl PeakCurrent {
61
- // pub fn bitmask(&self) -> u8 {
62
- // *self as u8
63
- // }
64
- // }
65
-
66
62
impl Default for PeakCurrent {
67
63
fn default ( ) -> Self {
68
64
PeakCurrent :: Max12_8Ma
@@ -77,13 +73,6 @@ impl ControlWord1 {
77
73
pub const DATA_OUT_BIT : u8 = 0b0000_0001 ;
78
74
pub const EXT_OSC_PRESCALER_BIT : u8 = 0b0000_0010 ;
79
75
80
- pub fn new ( ) -> Self {
81
- let mut word = ControlWord1 ( Self :: WORD_SELECT_BIT ) ;
82
- word. set_data_out_mode_bit ( DataOutMode :: default ( ) ) ;
83
- word. set_ext_osc_prescaler_bit ( ExtOscPrescaler :: default ( ) ) ;
84
- word
85
- }
86
-
87
76
pub fn set_data_out_mode_bit ( & mut self , bit : DataOutMode ) {
88
77
self . 0 = ( self . 0 & !Self :: DATA_OUT_BIT ) | ( bit as u8 ) ;
89
78
}
@@ -97,6 +86,15 @@ impl ControlWord1 {
97
86
}
98
87
}
99
88
89
+ impl Default for ControlWord1 {
90
+ fn default ( ) -> Self {
91
+ let mut control_word = ControlWord1 ( Self :: WORD_SELECT_BIT ) ;
92
+ control_word. set_data_out_mode_bit ( DataOutMode :: default ( ) ) ;
93
+ control_word. set_ext_osc_prescaler_bit ( ExtOscPrescaler :: default ( ) ) ;
94
+ control_word
95
+ }
96
+ }
97
+
100
98
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
101
99
pub enum DataOutMode {
102
100
Serial = 0b0000_0000 ,
@@ -111,12 +109,12 @@ impl Default for DataOutMode {
111
109
112
110
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
113
111
pub enum ExtOscPrescaler {
114
- Clock1 = 0b0000_0000 ,
115
- Clock8 = 0b0000_0001 ,
112
+ Direct = 0b0000_0000 ,
113
+ Div8 = 0b0000_0001 ,
116
114
}
117
115
118
116
impl Default for ExtOscPrescaler {
119
117
fn default ( ) -> Self {
120
- ExtOscPrescaler :: Clock1
118
+ ExtOscPrescaler :: Direct
121
119
}
122
120
}
0 commit comments