drivers: display: ssd1306: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h DT_INST macro APIs. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
ac70d4b6ab
commit
b29ff3d4d2
1 changed files with 36 additions and 34 deletions
|
@ -4,6 +4,8 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define DT_DRV_COMPAT solomon_ssd1306fb
|
||||||
|
|
||||||
#include <logging/log.h>
|
#include <logging/log.h>
|
||||||
LOG_MODULE_REGISTER(ssd1306, CONFIG_DISPLAY_LOG_LEVEL);
|
LOG_MODULE_REGISTER(ssd1306, CONFIG_DISPLAY_LOG_LEVEL);
|
||||||
|
|
||||||
|
@ -16,25 +18,25 @@ LOG_MODULE_REGISTER(ssd1306, CONFIG_DISPLAY_LOG_LEVEL);
|
||||||
#include "ssd1306_regs.h"
|
#include "ssd1306_regs.h"
|
||||||
#include <display/cfb.h>
|
#include <display/cfb.h>
|
||||||
|
|
||||||
#if DT_INST_0_SOLOMON_SSD1306FB_SEGMENT_REMAP == 1
|
#if DT_INST_PROP(0, segment_remap) == 1
|
||||||
#define SSD1306_PANEL_SEGMENT_REMAP true
|
#define SSD1306_PANEL_SEGMENT_REMAP true
|
||||||
#else
|
#else
|
||||||
#define SSD1306_PANEL_SEGMENT_REMAP false
|
#define SSD1306_PANEL_SEGMENT_REMAP false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DT_INST_0_SOLOMON_SSD1306FB_COM_INVDIR == 1
|
#if DT_INST_PROP(0, com_invdir) == 1
|
||||||
#define SSD1306_PANEL_COM_INVDIR true
|
#define SSD1306_PANEL_COM_INVDIR true
|
||||||
#else
|
#else
|
||||||
#define SSD1306_PANEL_COM_INVDIR false
|
#define SSD1306_PANEL_COM_INVDIR false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DT_INST_0_SOLOMON_SSD1306FB_COM_SEQUENTIAL == 1
|
#if DT_INST_PROP(0, com_sequential) == 1
|
||||||
#define SSD1306_COM_PINS_HW_CONFIG SSD1306_SET_PADS_HW_SEQUENTIAL
|
#define SSD1306_COM_PINS_HW_CONFIG SSD1306_SET_PADS_HW_SEQUENTIAL
|
||||||
#else
|
#else
|
||||||
#define SSD1306_COM_PINS_HW_CONFIG SSD1306_SET_PADS_HW_ALTERNATIVE
|
#define SSD1306_COM_PINS_HW_CONFIG SSD1306_SET_PADS_HW_ALTERNATIVE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SSD1306_PANEL_NUMOF_PAGES (DT_INST_0_SOLOMON_SSD1306FB_HEIGHT / 8)
|
#define SSD1306_PANEL_NUMOF_PAGES (DT_INST_PROP(0, height) / 8)
|
||||||
#define SSD1306_CLOCK_DIV_RATIO 0x0
|
#define SSD1306_CLOCK_DIV_RATIO 0x0
|
||||||
#define SSD1306_CLOCK_FREQUENCY 0x8
|
#define SSD1306_CLOCK_FREQUENCY 0x8
|
||||||
#define SSD1306_PANEL_VCOM_DESEL_LEVEL 0x20
|
#define SSD1306_PANEL_VCOM_DESEL_LEVEL 0x20
|
||||||
|
@ -55,7 +57,7 @@ static inline int ssd1306_reg_read(struct ssd1306_data *driver,
|
||||||
u8_t reg, u8_t * const val)
|
u8_t reg, u8_t * const val)
|
||||||
{
|
{
|
||||||
return i2c_reg_read_byte(driver->i2c,
|
return i2c_reg_read_byte(driver->i2c,
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS,
|
DT_INST_REG_ADDR(0),
|
||||||
reg, val);
|
reg, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +65,7 @@ static inline int ssd1306_reg_write(struct ssd1306_data *driver,
|
||||||
u8_t reg, u8_t val)
|
u8_t reg, u8_t val)
|
||||||
{
|
{
|
||||||
return i2c_reg_write_byte(driver->i2c,
|
return i2c_reg_write_byte(driver->i2c,
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS,
|
DT_INST_REG_ADDR(0),
|
||||||
reg, val);
|
reg, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ static inline int ssd1306_reg_update(struct ssd1306_data *driver, u8_t reg,
|
||||||
u8_t mask, u8_t val)
|
u8_t mask, u8_t val)
|
||||||
{
|
{
|
||||||
return i2c_reg_update_byte(driver->i2c,
|
return i2c_reg_update_byte(driver->i2c,
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS,
|
DT_INST_REG_ADDR(0),
|
||||||
reg, mask, val);
|
reg, mask, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +92,7 @@ static inline int ssd1306_set_panel_orientation(struct device *dev)
|
||||||
};
|
};
|
||||||
|
|
||||||
return i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
return i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS);
|
DT_INST_REG_ADDR(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ssd1306_set_timing_setting(struct device *dev)
|
static inline int ssd1306_set_timing_setting(struct device *dev)
|
||||||
|
@ -104,7 +106,7 @@ static inline int ssd1306_set_timing_setting(struct device *dev)
|
||||||
SSD1306_CONTROL_BYTE_CMD,
|
SSD1306_CONTROL_BYTE_CMD,
|
||||||
SSD1306_SET_CHARGE_PERIOD,
|
SSD1306_SET_CHARGE_PERIOD,
|
||||||
SSD1306_CONTROL_BYTE_CMD,
|
SSD1306_CONTROL_BYTE_CMD,
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_PRECHARGEP,
|
DT_INST_PROP(0, prechargep),
|
||||||
SSD1306_CONTROL_BYTE_CMD,
|
SSD1306_CONTROL_BYTE_CMD,
|
||||||
SSD1306_SET_VCOM_DESELECT_LEVEL,
|
SSD1306_SET_VCOM_DESELECT_LEVEL,
|
||||||
SSD1306_CONTROL_LAST_BYTE_CMD,
|
SSD1306_CONTROL_LAST_BYTE_CMD,
|
||||||
|
@ -112,7 +114,7 @@ static inline int ssd1306_set_timing_setting(struct device *dev)
|
||||||
};
|
};
|
||||||
|
|
||||||
return i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
return i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS);
|
DT_INST_REG_ADDR(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ssd1306_set_hardware_config(struct device *dev)
|
static inline int ssd1306_set_hardware_config(struct device *dev)
|
||||||
|
@ -124,7 +126,7 @@ static inline int ssd1306_set_hardware_config(struct device *dev)
|
||||||
SSD1306_CONTROL_BYTE_CMD,
|
SSD1306_CONTROL_BYTE_CMD,
|
||||||
SSD1306_SET_DISPLAY_OFFSET,
|
SSD1306_SET_DISPLAY_OFFSET,
|
||||||
SSD1306_CONTROL_BYTE_CMD,
|
SSD1306_CONTROL_BYTE_CMD,
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_DISPLAY_OFFSET,
|
DT_INST_PROP(0, display_offset),
|
||||||
SSD1306_CONTROL_BYTE_CMD,
|
SSD1306_CONTROL_BYTE_CMD,
|
||||||
SSD1306_SET_PADS_HW_CONFIG,
|
SSD1306_SET_PADS_HW_CONFIG,
|
||||||
SSD1306_CONTROL_BYTE_CMD,
|
SSD1306_CONTROL_BYTE_CMD,
|
||||||
|
@ -132,11 +134,11 @@ static inline int ssd1306_set_hardware_config(struct device *dev)
|
||||||
SSD1306_CONTROL_BYTE_CMD,
|
SSD1306_CONTROL_BYTE_CMD,
|
||||||
SSD1306_SET_MULTIPLEX_RATIO,
|
SSD1306_SET_MULTIPLEX_RATIO,
|
||||||
SSD1306_CONTROL_LAST_BYTE_CMD,
|
SSD1306_CONTROL_LAST_BYTE_CMD,
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_MULTIPLEX_RATIO
|
DT_INST_PROP(0, multiplex_ratio)
|
||||||
};
|
};
|
||||||
|
|
||||||
return i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
return i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS);
|
DT_INST_REG_ADDR(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int ssd1306_set_charge_pump(const struct device *dev)
|
static inline int ssd1306_set_charge_pump(const struct device *dev)
|
||||||
|
@ -160,7 +162,7 @@ static inline int ssd1306_set_charge_pump(const struct device *dev)
|
||||||
};
|
};
|
||||||
|
|
||||||
return i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
return i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS);
|
DT_INST_REG_ADDR(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ssd1306_resume(const struct device *dev)
|
static int ssd1306_resume(const struct device *dev)
|
||||||
|
@ -231,18 +233,18 @@ static int ssd1306_write(const struct device *dev, const u16_t x, const u16_t y,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
if (i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS)) {
|
DT_INST_REG_ADDR(0))) {
|
||||||
LOG_ERR("Failed to write command");
|
LOG_ERR("Failed to write command");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i2c_burst_write(driver->i2c,
|
return i2c_burst_write(driver->i2c,
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS,
|
DT_INST_REG_ADDR(0),
|
||||||
SSD1306_CONTROL_LAST_BYTE_DATA,
|
SSD1306_CONTROL_LAST_BYTE_DATA,
|
||||||
(u8_t *)buf, buf_len);
|
(u8_t *)buf, buf_len);
|
||||||
|
|
||||||
#elif defined(CONFIG_SSD1306_SH1106_COMPATIBLE)
|
#elif defined(CONFIG_SSD1306_SH1106_COMPATIBLE)
|
||||||
u8_t x_offset = x + DT_INST_0_SOLOMON_SSD1306FB_SEGMENT_OFFSET;
|
u8_t x_offset = x + DT_INST_PROP(0, segment_offset);
|
||||||
u8_t cmd_buf[] = {
|
u8_t cmd_buf[] = {
|
||||||
SSD1306_CONTROL_BYTE_CMD,
|
SSD1306_CONTROL_BYTE_CMD,
|
||||||
SSD1306_SET_LOWER_COL_ADDRESS |
|
SSD1306_SET_LOWER_COL_ADDRESS |
|
||||||
|
@ -261,12 +263,12 @@ static int ssd1306_write(const struct device *dev, const u16_t x, const u16_t y,
|
||||||
LOG_HEXDUMP_DBG(cmd_buf, sizeof(cmd_buf), "cmd_buf");
|
LOG_HEXDUMP_DBG(cmd_buf, sizeof(cmd_buf), "cmd_buf");
|
||||||
|
|
||||||
if (i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
if (i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS)) {
|
DT_INST_REG_ADDR(0))) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_burst_write(driver->i2c,
|
if (i2c_burst_write(driver->i2c,
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS,
|
DT_INST_REG_ADDR(0),
|
||||||
SSD1306_CONTROL_LAST_BYTE_DATA,
|
SSD1306_CONTROL_LAST_BYTE_DATA,
|
||||||
buf_ptr, desc->width)) {
|
buf_ptr, desc->width)) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -316,15 +318,15 @@ static int ssd1306_set_contrast(const struct device *dev, const u8_t contrast)
|
||||||
};
|
};
|
||||||
|
|
||||||
return i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
return i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS);
|
DT_INST_REG_ADDR(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ssd1306_get_capabilities(const struct device *dev,
|
static void ssd1306_get_capabilities(const struct device *dev,
|
||||||
struct display_capabilities *caps)
|
struct display_capabilities *caps)
|
||||||
{
|
{
|
||||||
memset(caps, 0, sizeof(struct display_capabilities));
|
memset(caps, 0, sizeof(struct display_capabilities));
|
||||||
caps->x_resolution = DT_INST_0_SOLOMON_SSD1306FB_WIDTH;
|
caps->x_resolution = DT_INST_PROP(0, width);
|
||||||
caps->y_resolution = DT_INST_0_SOLOMON_SSD1306FB_HEIGHT;
|
caps->y_resolution = DT_INST_PROP(0, height);
|
||||||
caps->supported_pixel_formats = PIXEL_FORMAT_MONO10;
|
caps->supported_pixel_formats = PIXEL_FORMAT_MONO10;
|
||||||
caps->current_pixel_format = PIXEL_FORMAT_MONO10;
|
caps->current_pixel_format = PIXEL_FORMAT_MONO10;
|
||||||
caps->screen_info = SCREEN_INFO_MONO_VTILED;
|
caps->screen_info = SCREEN_INFO_MONO_VTILED;
|
||||||
|
@ -363,13 +365,13 @@ static int ssd1306_init_device(struct device *dev)
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef DT_INST_0_SOLOMON_SSD1306FB_RESET_GPIOS_CONTROLLER
|
#if DT_INST_NODE_HAS_PROP(0, reset_gpios)
|
||||||
k_sleep(SSD1306_RESET_DELAY);
|
k_sleep(SSD1306_RESET_DELAY);
|
||||||
gpio_pin_set(driver->reset,
|
gpio_pin_set(driver->reset,
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_RESET_GPIOS_PIN, 1);
|
DT_INST_GPIO_PIN(0, reset_gpios), 1);
|
||||||
k_sleep(SSD1306_RESET_DELAY);
|
k_sleep(SSD1306_RESET_DELAY);
|
||||||
gpio_pin_set(driver->reset,
|
gpio_pin_set(driver->reset,
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_RESET_GPIOS_PIN, 0);
|
DT_INST_GPIO_PIN(0, reset_gpios), 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Turn display off */
|
/* Turn display off */
|
||||||
|
@ -395,7 +397,7 @@ static int ssd1306_init_device(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
if (i2c_write(driver->i2c, cmd_buf, sizeof(cmd_buf),
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BASE_ADDRESS)) {
|
DT_INST_REG_ADDR(0))) {
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,26 +416,26 @@ static int ssd1306_init(struct device *dev)
|
||||||
|
|
||||||
LOG_DBG("");
|
LOG_DBG("");
|
||||||
|
|
||||||
driver->i2c = device_get_binding(DT_INST_0_SOLOMON_SSD1306FB_BUS_NAME);
|
driver->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
|
||||||
if (driver->i2c == NULL) {
|
if (driver->i2c == NULL) {
|
||||||
LOG_ERR("Failed to get pointer to %s device!",
|
LOG_ERR("Failed to get pointer to %s device!",
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_BUS_NAME);
|
DT_INST_BUS_LABEL(0));
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DT_INST_0_SOLOMON_SSD1306FB_RESET_GPIOS_CONTROLLER
|
#if DT_INST_NODE_HAS_PROP(0, reset_gpios)
|
||||||
driver->reset = device_get_binding(
|
driver->reset = device_get_binding(
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_RESET_GPIOS_CONTROLLER);
|
DT_INST_GPIO_LABEL(0, reset_gpios));
|
||||||
if (driver->reset == NULL) {
|
if (driver->reset == NULL) {
|
||||||
LOG_ERR("Failed to get pointer to %s device!",
|
LOG_ERR("Failed to get pointer to %s device!",
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_RESET_GPIOS_CONTROLLER);
|
DT_INST_GPIO_LABEL(0, reset_gpios));
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpio_pin_configure(driver->reset,
|
gpio_pin_configure(driver->reset,
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_RESET_GPIOS_PIN,
|
DT_INST_GPIO_PIN(0, reset_gpios),
|
||||||
GPIO_OUTPUT_INACTIVE |
|
GPIO_OUTPUT_INACTIVE |
|
||||||
DT_INST_0_SOLOMON_SSD1306FB_RESET_GPIOS_FLAGS);
|
DT_INST_GPIO_FLAGS(0, reset_gpios));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ssd1306_init_device(dev)) {
|
if (ssd1306_init_device(dev)) {
|
||||||
|
@ -459,7 +461,7 @@ static struct display_driver_api ssd1306_driver_api = {
|
||||||
.set_orientation = ssd1306_set_orientation,
|
.set_orientation = ssd1306_set_orientation,
|
||||||
};
|
};
|
||||||
|
|
||||||
DEVICE_AND_API_INIT(ssd1306, DT_INST_0_SOLOMON_SSD1306FB_LABEL, ssd1306_init,
|
DEVICE_AND_API_INIT(ssd1306, DT_INST_LABEL(0), ssd1306_init,
|
||||||
&ssd1306_driver, NULL,
|
&ssd1306_driver, NULL,
|
||||||
POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY,
|
POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY,
|
||||||
&ssd1306_driver_api);
|
&ssd1306_driver_api);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue