Skip to content

Commit

Permalink
drivers: ssd1306: Support GPIO reset function
Browse files Browse the repository at this point in the history
If dts has reset-gpios information, reset it.

Signed-off-by: Kwon Tae-young <tykwon@m2i.co.kr>
  • Loading branch information
KwonTae-young authored and nashif committed Feb 22, 2019
1 parent 0122bac commit e0a8990
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
19 changes: 19 additions & 0 deletions drivers/display/ssd1306.c
Expand Up @@ -47,6 +47,7 @@ LOG_MODULE_REGISTER(ssd1306);
#endif

struct ssd1306_data {
struct device *reset;
struct device *i2c;
u8_t contrast;
u8_t scan_mode;
Expand Down Expand Up @@ -366,6 +367,12 @@ static int ssd1306_init_device(struct device *dev)
SSD1306_SET_NORMAL_DISPLAY,
};

#ifdef DT_SOLOMON_SSD1306FB_0_RESET_GPIOS_CONTROLLER
gpio_pin_write(driver->reset, DT_SOLOMON_SSD1306FB_0_RESET_GPIOS_PIN, 0);
k_sleep(SSD1306_RESET_DELAY);
gpio_pin_write(driver->reset, DT_SOLOMON_SSD1306FB_0_RESET_GPIOS_PIN, 1);
#endif

/* Turn display off */
if (ssd1306_reg_write(driver, SSD1306_CONTROL_LAST_BYTE_CMD,
SSD1306_DISPLAY_OFF)) {
Expand Down Expand Up @@ -415,6 +422,18 @@ static int ssd1306_init(struct device *dev)
return -EINVAL;
}

#ifdef DT_SOLOMON_SSD1306FB_0_RESET_GPIOS_CONTROLLER
driver->reset = device_get_binding(DT_SOLOMON_SSD1306FB_0_RESET_GPIOS_CONTROLLER);
if (driver->reset == NULL) {
LOG_ERR("Failed to get pointer to %s device!",
DT_SOLOMON_SSD1306FB_0_RESET_GPIOS_CONTROLLER);
return -EINVAL;
}

gpio_pin_configure(driver->reset, DT_SOLOMON_SSD1306FB_0_RESET_GPIOS_PIN,
GPIO_DIR_OUT);
#endif

if (ssd1306_init_device(dev)) {
LOG_ERR("Failed to initialize device!");
return -EIO;
Expand Down
3 changes: 3 additions & 0 deletions drivers/display/ssd1306_regs.h
Expand Up @@ -106,4 +106,7 @@
#define SSD1306_READ_MODIFY_WRITE_START 0xe0
#define SSD1306_READ_MODIFY_WRITE_END 0xee

/* time constants in ms */
#define SSD1306_RESET_DELAY 1

#endif

0 comments on commit e0a8990

Please sign in to comment.