Drivers: ssd1306: Add use_internal_iref DTS option

Necessary for supporting for EastRising 0.42 OLED display/board.

Some boards don't have external Iref set up. This is probably done in an
effort to save on component cost. This command is only documented in the
V1.1 revision of the SSD1306 datasheet.

See issue https://github.com/olikraus/u8g2/issues/1047

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
This commit is contained in:
Théo Battrel 2024-06-24 11:28:38 +02:00 committed by Carles Cufí
parent 77eafac1bf
commit bfb541ccbe
3 changed files with 32 additions and 1 deletions

View file

@ -57,6 +57,7 @@ struct ssd1306_config {
bool color_inversion;
bool sh1106_compatible;
int ready_time_ms;
bool use_internal_iref;
};
struct ssd1306_data {
@ -201,6 +202,22 @@ static inline int ssd1306_set_charge_pump(const struct device *dev)
return ssd1306_write_bus(dev, cmd_buf, sizeof(cmd_buf), true);
}
static inline int ssd1306_set_iref_mode(const struct device *dev)
{
int errno = 0;
const struct ssd1306_config *config = dev->config;
uint8_t cmd_buf[] = {
SSD1306_SET_IREF_MODE,
SSD1306_SET_IREF_MODE_INTERNAL,
};
if (config->use_internal_iref) {
errno = ssd1306_write_bus(dev, cmd_buf, sizeof(cmd_buf), true);
}
return errno;
}
static int ssd1306_resume(const struct device *dev)
{
uint8_t cmd_buf[] = {
@ -413,6 +430,10 @@ static int ssd1306_init_device(const struct device *dev)
return -EIO;
}
if (ssd1306_set_iref_mode(dev)) {
return -EIO;
}
if (ssd1306_write_bus(dev, cmd_buf, sizeof(cmd_buf), true)) {
return -EIO;
}
@ -496,6 +517,7 @@ static const struct display_driver_api ssd1306_driver_api = {
.color_inversion = DT_PROP(node_id, inversion_on), \
.sh1106_compatible = DT_NODE_HAS_COMPAT(node_id, sinowealth_sh1106), \
.ready_time_ms = DT_PROP(node_id, ready_time_ms), \
.use_internal_iref = DT_PROP(node_id, use_internal_iref), \
COND_CODE_1(DT_ON_BUS(node_id, spi), (SSD1306_CONFIG_SPI(node_id)), \
(SSD1306_CONFIG_I2C(node_id))) \
}; \

View file

@ -76,7 +76,11 @@
#define SSD1306_SET_PADS_HW_CONFIG 0xda /* double byte command */
#define SSD1306_SET_PADS_HW_SEQUENTIAL 0x02
#define SSD1306_SET_PADS_HW_ALTERNATIVE 0x12
#define SSD1306_SET_PADS_HW_ALTERNATIVE 0x12
#define SSD1306_SET_IREF_MODE 0xad
#define SSD1306_SET_IREF_MODE_INTERNAL 0x30
#define SSD1306_SET_IREF_MODE_EXTERNAL 0x00
/*

View file

@ -60,3 +60,8 @@ properties:
Time it takes for the device from power up to become responsive and
accepting commands. Defaults to 10ms (found by trial and error) if not
provided.
use-internal-iref:
type: boolean
description: |
Use internal Iref, not common but sometime used to save component cost.