@@ -43,6 +43,7 @@ struct ssd1306_config {
4343 union ssd1306_bus bus ;
4444 struct gpio_dt_spec data_cmd ;
4545 struct gpio_dt_spec reset ;
46+ struct gpio_dt_spec supply ;
4647 ssd1306_bus_ready_fn bus_ready ;
4748 ssd1306_write_bus_fn write_bus ;
4849 ssd1306_bus_name_fn bus_name ;
@@ -226,19 +227,33 @@ static inline int ssd1306_set_iref_mode(const struct device *dev)
226227
227228static int ssd1306_resume (const struct device * dev )
228229{
230+ const struct ssd1306_config * config = dev -> config ;
229231 uint8_t cmd_buf [] = {
230232 SSD1306_DISPLAY_ON ,
231233 };
232234
235+ /* Turn on supply if pin connected */
236+ if (config -> supply .port ) {
237+ gpio_pin_set_dt (& config -> supply , 1 );
238+ k_sleep (K_MSEC (SSD1306_SUPPLY_DELAY ));
239+ }
240+
233241 return ssd1306_write_bus (dev , cmd_buf , sizeof (cmd_buf ), true);
234242}
235243
236244static int ssd1306_suspend (const struct device * dev )
237245{
246+ const struct ssd1306_config * config = dev -> config ;
238247 uint8_t cmd_buf [] = {
239248 SSD1306_DISPLAY_OFF ,
240249 };
241250
251+ /* Turn off supply if pin connected */
252+ if (config -> supply .port ) {
253+ gpio_pin_set_dt (& config -> supply , 0 );
254+ k_sleep (K_MSEC (SSD1306_SUPPLY_DELAY ));
255+ }
256+
242257 return ssd1306_write_bus (dev , cmd_buf , sizeof (cmd_buf ), true);
243258}
244259
@@ -408,6 +423,11 @@ static int ssd1306_init_device(const struct device *dev)
408423 };
409424
410425 data -> pf = config -> color_inversion ? PIXEL_FORMAT_MONO10 : PIXEL_FORMAT_MONO01 ;
426+ /* Turn on supply if pin connected */
427+ if (config -> supply .port ) {
428+ gpio_pin_set_dt (& config -> supply , 1 );
429+ k_sleep (K_MSEC (SSD1306_SUPPLY_DELAY ));
430+ }
411431
412432 /* Reset if pin connected */
413433 if (config -> reset .port ) {
@@ -460,6 +480,7 @@ static int ssd1306_init_device(const struct device *dev)
460480static int ssd1306_init (const struct device * dev )
461481{
462482 const struct ssd1306_config * config = dev -> config ;
483+ int ret ;
463484
464485 k_sleep (K_TIMEOUT_ABS_MS (config -> ready_time_ms ));
465486
@@ -468,14 +489,28 @@ static int ssd1306_init(const struct device *dev)
468489 return - EINVAL ;
469490 }
470491
471- if (config -> reset .port ) {
472- int ret ;
492+ if (config -> supply .port ) {
493+ ret = gpio_pin_configure_dt (& config -> supply ,
494+ GPIO_OUTPUT_INACTIVE );
495+ if (ret < 0 ) {
496+ return ret ;
497+ }
498+ if (!gpio_is_ready_dt (& config -> supply )) {
499+ LOG_ERR ("Supply GPIO device not ready" );
500+ return - ENODEV ;
501+ }
502+ }
473503
504+ if (config -> reset .port ) {
474505 ret = gpio_pin_configure_dt (& config -> reset ,
475506 GPIO_OUTPUT_INACTIVE );
476507 if (ret < 0 ) {
477508 return ret ;
478509 }
510+ if (!gpio_is_ready_dt (& config -> reset )) {
511+ LOG_ERR ("Reset GPIO device not ready" );
512+ return - ENODEV ;
513+ }
479514 }
480515
481516 if (ssd1306_init_device (dev )) {
@@ -514,6 +549,7 @@ static DEVICE_API(display, ssd1306_driver_api) = {
514549 static struct ssd1306_data data##node_id; \
515550 static const struct ssd1306_config config##node_id = { \
516551 .reset = GPIO_DT_SPEC_GET_OR(node_id, reset_gpios, {0}), \
552+ .supply = GPIO_DT_SPEC_GET_OR(node_id, supply_gpios, {0}), \
517553 .height = DT_PROP(node_id, height), \
518554 .width = DT_PROP(node_id, width), \
519555 .segment_offset = DT_PROP(node_id, segment_offset), \
0 commit comments