@@ -77,6 +77,7 @@ struct auxdisplay_hd44780_config {
77
77
78
78
static void auxdisplay_hd44780_set_entry_mode (const struct device * dev );
79
79
static void auxdisplay_hd44780_set_display_mode (const struct device * dev , bool enabled );
80
+ static int auxdisplay_hd44780_clear (const struct device * dev );
80
81
81
82
static void hd44780_pulse_enable_line (const struct device * dev )
82
83
{
@@ -109,13 +110,53 @@ static void auxdisplay_hd44780_command(const struct device *dev, bool rs, uint8_
109
110
}
110
111
}
111
112
113
+ static void hd44780_ic_initialize (const struct device * dev )
114
+ {
115
+ const struct auxdisplay_hd44780_config * config = dev -> config ;
116
+ uint8_t cmd ;
117
+
118
+ /*
119
+ * If proper power supply is used to power the HD44780, it initializes correctly
120
+ * on a reset condition all by itself. However, if the power supply is below
121
+ * its expectations (e.g. supplying it with some 3.3V Nucleo board),
122
+ * it won't initialize properly on its own, and the MCU has to carry out
123
+ * the initialization as listed in the reference manual.
124
+ * Since we cannot determine it properly in the runtime,
125
+ * always carry out the initialization procedure.
126
+ */
127
+ cmd = AUXDISPLAY_HD44780_CMD_SETUP | AUXDISPLAY_HD44780_8_BIT_CONFIG ;
128
+ auxdisplay_hd44780_command (dev , false, cmd , AUXDISPLAY_HD44780_MODE_4_BIT_ONCE );
129
+ k_sleep (K_USEC (4100 ));
130
+ auxdisplay_hd44780_command (dev , false, cmd , AUXDISPLAY_HD44780_MODE_4_BIT_ONCE );
131
+ k_sleep (K_USEC (100 ));
132
+ auxdisplay_hd44780_command (dev , false, cmd , AUXDISPLAY_HD44780_MODE_4_BIT_ONCE );
133
+ k_sleep (K_USEC (100 ));
134
+
135
+ if (config -> capabilities .mode == AUXDISPLAY_HD44780_MODE_4_BIT ) {
136
+ /* Put display into 4-bit mode */
137
+ cmd = AUXDISPLAY_HD44780_CMD_SETUP ;
138
+ auxdisplay_hd44780_command (dev , false, cmd , AUXDISPLAY_HD44780_MODE_4_BIT_ONCE );
139
+ }
140
+
141
+ /* Configure display */
142
+ if (config -> capabilities .rows > 1 ) {
143
+ cmd |= AUXDISPLAY_HD44780_2_LINE_CONFIG ;
144
+ }
145
+ auxdisplay_hd44780_command (dev , false, cmd , config -> capabilities .mode );
146
+
147
+ auxdisplay_hd44780_set_display_mode (dev , false);
148
+ auxdisplay_hd44780_clear (dev );
149
+ auxdisplay_hd44780_set_entry_mode (dev );
150
+
151
+ auxdisplay_hd44780_set_display_mode (dev , true);
152
+ }
153
+
112
154
static int auxdisplay_hd44780_init (const struct device * dev )
113
155
{
114
156
const struct auxdisplay_hd44780_config * config = dev -> config ;
115
157
struct auxdisplay_hd44780_data * data = dev -> data ;
116
158
int rc ;
117
159
uint8_t i = 0 ;
118
- uint8_t cmd = AUXDISPLAY_HD44780_CMD_SETUP | AUXDISPLAY_HD44780_8_BIT_CONFIG ;
119
160
120
161
if (config -> capabilities .mode > AUXDISPLAY_HD44780_MODE_8_BIT ) {
121
162
/* This index is reserved for internal driver usage */
@@ -199,28 +240,7 @@ static int auxdisplay_hd44780_init(const struct device *dev)
199
240
k_sleep (K_MSEC (config -> boot_delay ));
200
241
}
201
242
202
- if (config -> capabilities .mode == AUXDISPLAY_HD44780_MODE_4_BIT ) {
203
- /* Reset display to known state in 8-bit mode */
204
- auxdisplay_hd44780_command (dev , false, cmd , AUXDISPLAY_HD44780_MODE_4_BIT_ONCE );
205
- auxdisplay_hd44780_command (dev , false, cmd , AUXDISPLAY_HD44780_MODE_4_BIT_ONCE );
206
-
207
- /* Put display into 4-bit mode */
208
- cmd = AUXDISPLAY_HD44780_CMD_SETUP ;
209
- auxdisplay_hd44780_command (dev , false, cmd , AUXDISPLAY_HD44780_MODE_4_BIT_ONCE );
210
- }
211
-
212
- if (config -> capabilities .rows > 1 ) {
213
- cmd |= AUXDISPLAY_HD44780_2_LINE_CONFIG ;
214
- }
215
-
216
- /* Configure display */
217
- auxdisplay_hd44780_command (dev , false, cmd , config -> capabilities .mode );
218
- auxdisplay_hd44780_set_display_mode (dev , true);
219
- auxdisplay_hd44780_set_entry_mode (dev );
220
- auxdisplay_hd44780_command (dev , false, AUXDISPLAY_HD44780_CMD_CLEAR ,
221
- config -> capabilities .mode );
222
-
223
- k_sleep (K_USEC (config -> clear_delay ));
243
+ hd44780_ic_initialize (dev );
224
244
225
245
return 0 ;
226
246
}
0 commit comments