drivers: display: ili9340: align register names
Align register names with the ones found in the datasheet. It is easier to follow datasheet if names are the same. Some other minor enhancements have also been introduced (comments, use BIT for bit fields...). Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
This commit is contained in:
parent
941322c49e
commit
e807769dce
2 changed files with 57 additions and 67 deletions
|
@ -97,7 +97,7 @@ static int ili9340_exit_sleep(const struct device *dev)
|
|||
{
|
||||
int r;
|
||||
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_EXIT_SLEEP, NULL, 0);
|
||||
r = ili9340_transmit(dev, ILI9340_SLPOUT, NULL, 0);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
@ -131,14 +131,14 @@ static int ili9340_set_mem_area(const struct device *dev, const uint16_t x,
|
|||
|
||||
spi_data[0] = sys_cpu_to_be16(x);
|
||||
spi_data[1] = sys_cpu_to_be16(x + w - 1U);
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_COLUMN_ADDR, &spi_data[0], 4U);
|
||||
r = ili9340_transmit(dev, ILI9340_CASET, &spi_data[0], 4U);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
spi_data[0] = sys_cpu_to_be16(y);
|
||||
spi_data[1] = sys_cpu_to_be16(y + h - 1U);
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_PAGE_ADDR, &spi_data[0], 4U);
|
||||
r = ili9340_transmit(dev, ILI9340_PASET, &spi_data[0], 4U);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
@ -180,8 +180,7 @@ static int ili9340_write(const struct device *dev, const uint16_t x,
|
|||
nbr_of_writes = 1U;
|
||||
}
|
||||
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_MEM_WRITE,
|
||||
write_data_start,
|
||||
r = ili9340_transmit(dev, ILI9340_RAMWR, write_data_start,
|
||||
desc->width * data->bytes_per_pixel * write_h);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
|
@ -224,13 +223,13 @@ static void *ili9340_get_framebuffer(const struct device *dev)
|
|||
static int ili9340_display_blanking_off(const struct device *dev)
|
||||
{
|
||||
LOG_DBG("Turning display blanking off");
|
||||
return ili9340_transmit(dev, ILI9340_CMD_DISPLAY_ON, NULL, 0);
|
||||
return ili9340_transmit(dev, ILI9340_DISPON, NULL, 0);
|
||||
}
|
||||
|
||||
static int ili9340_display_blanking_on(const struct device *dev)
|
||||
{
|
||||
LOG_DBG("Turning display blanking on");
|
||||
return ili9340_transmit(dev, ILI9340_CMD_DISPLAY_OFF, NULL, 0);
|
||||
return ili9340_transmit(dev, ILI9340_DISPOFF, NULL, 0);
|
||||
}
|
||||
|
||||
static int ili9340_set_brightness(const struct device *dev,
|
||||
|
@ -258,18 +257,16 @@ static int ili9340_set_pixel_format(const struct device *dev,
|
|||
|
||||
if (pixel_format == PIXEL_FORMAT_RGB_565) {
|
||||
bytes_per_pixel = 2U;
|
||||
tx_data = ILI9340_DATA_PIXEL_FORMAT_MCU_16_BIT |
|
||||
ILI9340_DATA_PIXEL_FORMAT_RGB_16_BIT;
|
||||
tx_data = ILI9340_PIXSET_MCU_16_BIT | ILI9340_PIXSET_RGB_16_BIT;
|
||||
} else if (pixel_format == PIXEL_FORMAT_RGB_888) {
|
||||
bytes_per_pixel = 3U;
|
||||
tx_data = ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT |
|
||||
ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT;
|
||||
tx_data = ILI9340_PIXSET_MCU_18_BIT | ILI9340_PIXSET_RGB_18_BIT;
|
||||
} else {
|
||||
LOG_ERR("Unsupported pixel format");
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_PIXEL_FORMAT_SET, &tx_data, 1U);
|
||||
r = ili9340_transmit(dev, ILI9340_PIXSET, &tx_data, 1U);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
@ -286,21 +283,19 @@ static int ili9340_set_orientation(const struct device *dev,
|
|||
struct ili9340_data *data = (struct ili9340_data *)dev->data;
|
||||
|
||||
int r;
|
||||
uint8_t tx_data = ILI9340_DATA_MEM_ACCESS_CTRL_BGR;
|
||||
uint8_t tx_data = ILI9340_MADCTL_BGR;
|
||||
|
||||
if (orientation == DISPLAY_ORIENTATION_NORMAL) {
|
||||
tx_data |= ILI9340_DATA_MEM_ACCESS_CTRL_MX;
|
||||
tx_data |= ILI9340_MADCTL_MX;
|
||||
} else if (orientation == DISPLAY_ORIENTATION_ROTATED_90) {
|
||||
tx_data |= ILI9340_DATA_MEM_ACCESS_CTRL_MV;
|
||||
tx_data |= ILI9340_MADCTL_MV;
|
||||
} else if (orientation == DISPLAY_ORIENTATION_ROTATED_180) {
|
||||
tx_data |= ILI9340_DATA_MEM_ACCESS_CTRL_MY;
|
||||
tx_data |= ILI9340_MADCTL_MY;
|
||||
} else if (orientation == DISPLAY_ORIENTATION_ROTATED_270) {
|
||||
tx_data |= ILI9340_DATA_MEM_ACCESS_CTRL_MV |
|
||||
ILI9340_DATA_MEM_ACCESS_CTRL_MX |
|
||||
ILI9340_DATA_MEM_ACCESS_CTRL_MY;
|
||||
tx_data |= ILI9340_MADCTL_MV | ILI9340_MADCTL_MX | ILI9340_MADCTL_MY;
|
||||
}
|
||||
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_MEM_ACCESS_CTRL, &tx_data, 1U);
|
||||
r = ili9340_transmit(dev, ILI9340_MADCTL, &tx_data, 1U);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
@ -372,72 +367,63 @@ static int ili9340_configure(const struct device *dev)
|
|||
|
||||
LOG_HEXDUMP_DBG(config->gamset, ILI9340_GAMSET_LEN, "GAMSET");
|
||||
memcpy(tx_data, config->gamset, ILI9340_GAMSET_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_GAMMA_SET, tx_data,
|
||||
ILI9340_GAMSET_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_GAMSET, tx_data, ILI9340_GAMSET_LEN);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
LOG_HEXDUMP_DBG(config->frmctr1, ILI9340_FRMCTR1_LEN, "FRMCTR1");
|
||||
memcpy(tx_data, config->frmctr1, ILI9340_FRMCTR1_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_FRAME_CTRL_NORMAL_MODE, tx_data,
|
||||
ILI9340_FRMCTR1_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_FRMCTR1, tx_data, ILI9340_FRMCTR1_LEN);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
LOG_HEXDUMP_DBG(config->disctrl, ILI9340_DISCTRL_LEN, "DISCTRL");
|
||||
memcpy(tx_data, config->disctrl, ILI9340_DISCTRL_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_DISPLAY_FUNCTION_CTRL, tx_data,
|
||||
ILI9340_DISCTRL_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_DISCTRL, tx_data, ILI9340_DISCTRL_LEN);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
LOG_HEXDUMP_DBG(config->pwctrl1, ILI9340_PWCTRL1_LEN, "PWCTRL1");
|
||||
memcpy(tx_data, config->pwctrl1, ILI9340_PWCTRL1_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_POWER_CTRL_1, tx_data,
|
||||
ILI9340_PWCTRL1_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_PWCTRL1, tx_data, ILI9340_PWCTRL1_LEN);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
LOG_HEXDUMP_DBG(config->pwctrl2, ILI9340_PWCTRL2_LEN, "PWCTRL2");
|
||||
memcpy(tx_data, config->pwctrl2, ILI9340_PWCTRL2_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_POWER_CTRL_2, tx_data,
|
||||
ILI9340_PWCTRL2_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_PWCTRL2, tx_data, ILI9340_PWCTRL2_LEN);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
LOG_HEXDUMP_DBG(config->vmctrl1, ILI9340_VMCTRL1_LEN, "VMCTRL1");
|
||||
memcpy(tx_data, config->vmctrl1, ILI9340_VMCTRL1_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_VCOM_CTRL_1, tx_data,
|
||||
ILI9340_VMCTRL1_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_VMCTRL1, tx_data, ILI9340_VMCTRL1_LEN);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
LOG_HEXDUMP_DBG(config->vmctrl2, ILI9340_VMCTRL2_LEN, "VMCTRL2");
|
||||
memcpy(tx_data, config->vmctrl2, ILI9340_VMCTRL2_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_VCOM_CTRL_2, tx_data,
|
||||
ILI9340_VMCTRL2_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_VMCTRL2, tx_data, ILI9340_VMCTRL2_LEN);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
LOG_HEXDUMP_DBG(config->pgamctrl, ILI9340_PGAMCTRL_LEN, "PGAMCTRL");
|
||||
memcpy(tx_data, config->pgamctrl, ILI9340_PGAMCTRL_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_POSITIVE_GAMMA_CORRECTION,
|
||||
tx_data, ILI9340_PGAMCTRL_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_PGAMCTRL, tx_data, ILI9340_PGAMCTRL_LEN);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
LOG_HEXDUMP_DBG(config->ngamctrl, ILI9340_NGAMCTRL_LEN, "NGAMCTRL");
|
||||
memcpy(tx_data, config->ngamctrl, ILI9340_NGAMCTRL_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_CMD_NEGATIVE_GAMMA_CORRECTION,
|
||||
tx_data, ILI9340_NGAMCTRL_LEN);
|
||||
r = ili9340_transmit(dev, ILI9340_NGAMCTRL, tx_data, ILI9340_NGAMCTRL_LEN);
|
||||
if (r < 0) {
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -8,26 +8,28 @@
|
|||
#ifndef ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_
|
||||
#define ZEPHYR_DRIVERS_DISPLAY_DISPLAY_ILI9340_H_
|
||||
|
||||
#define ILI9340_CMD_SOFTWARE_RESET 0x01
|
||||
#define ILI9340_CMD_ENTER_SLEEP 0x10
|
||||
#define ILI9340_CMD_EXIT_SLEEP 0x11
|
||||
#define ILI9340_CMD_GAMMA_SET 0x26
|
||||
#define ILI9340_CMD_DISPLAY_OFF 0x28
|
||||
#define ILI9340_CMD_DISPLAY_ON 0x29
|
||||
#define ILI9340_CMD_COLUMN_ADDR 0x2a
|
||||
#define ILI9340_CMD_PAGE_ADDR 0x2b
|
||||
#define ILI9340_CMD_MEM_WRITE 0x2c
|
||||
#define ILI9340_CMD_MEM_ACCESS_CTRL 0x36
|
||||
#define ILI9340_CMD_PIXEL_FORMAT_SET 0x3A
|
||||
#define ILI9340_CMD_FRAME_CTRL_NORMAL_MODE 0xB1
|
||||
#define ILI9340_CMD_DISPLAY_FUNCTION_CTRL 0xB6
|
||||
#define ILI9340_CMD_POWER_CTRL_1 0xC0
|
||||
#define ILI9340_CMD_POWER_CTRL_2 0xC1
|
||||
#define ILI9340_CMD_VCOM_CTRL_1 0xC5
|
||||
#define ILI9340_CMD_VCOM_CTRL_2 0xC7
|
||||
#define ILI9340_CMD_POSITIVE_GAMMA_CORRECTION 0xE0
|
||||
#define ILI9340_CMD_NEGATIVE_GAMMA_CORRECTION 0xE1
|
||||
#include <sys/util.h>
|
||||
|
||||
/* Commands/registers. */
|
||||
#define ILI9340_SLPOUT 0x11
|
||||
#define ILI9340_GAMSET 0x26
|
||||
#define ILI9340_DISPOFF 0x28
|
||||
#define ILI9340_DISPON 0x29
|
||||
#define ILI9340_CASET 0x2a
|
||||
#define ILI9340_PASET 0x2b
|
||||
#define ILI9340_RAMWR 0x2c
|
||||
#define ILI9340_MADCTL 0x36
|
||||
#define ILI9340_PIXSET 0x3A
|
||||
#define ILI9340_FRMCTR1 0xB1
|
||||
#define ILI9340_DISCTRL 0xB6
|
||||
#define ILI9340_PWCTRL1 0xC0
|
||||
#define ILI9340_PWCTRL2 0xC1
|
||||
#define ILI9340_VMCTRL1 0xC5
|
||||
#define ILI9340_VMCTRL2 0xC7
|
||||
#define ILI9340_PGAMCTRL 0xE0
|
||||
#define ILI9340_NGAMCTRL 0xE1
|
||||
|
||||
/* Commands/registers length. */
|
||||
#define ILI9340_GAMSET_LEN 1U
|
||||
#define ILI9340_FRMCTR1_LEN 2U
|
||||
#define ILI9340_DISCTRL_LEN 3U
|
||||
|
@ -38,17 +40,19 @@
|
|||
#define ILI9340_PGAMCTRL_LEN 15U
|
||||
#define ILI9340_NGAMCTRL_LEN 15U
|
||||
|
||||
#define ILI9340_DATA_MEM_ACCESS_CTRL_MY 0x80
|
||||
#define ILI9340_DATA_MEM_ACCESS_CTRL_MX 0x40
|
||||
#define ILI9340_DATA_MEM_ACCESS_CTRL_MV 0x20
|
||||
#define ILI9340_DATA_MEM_ACCESS_CTRL_ML 0x10
|
||||
#define ILI9340_DATA_MEM_ACCESS_CTRL_BGR 0x08
|
||||
#define ILI9340_DATA_MEM_ACCESS_CTRL_MH 0x04
|
||||
/* MADCTL register fields. */
|
||||
#define ILI9340_MADCTL_MY BIT(7U)
|
||||
#define ILI9340_MADCTL_MX BIT(6U)
|
||||
#define ILI9340_MADCTL_MV BIT(5U)
|
||||
#define ILI9340_MADCTL_ML BIT(4U)
|
||||
#define ILI9340_MADCTL_BGR BIT(3U)
|
||||
#define ILI9340_MADCTL_MH BIT(2U)
|
||||
|
||||
#define ILI9340_DATA_PIXEL_FORMAT_RGB_18_BIT 0x60
|
||||
#define ILI9340_DATA_PIXEL_FORMAT_RGB_16_BIT 0x50
|
||||
#define ILI9340_DATA_PIXEL_FORMAT_MCU_18_BIT 0x06
|
||||
#define ILI9340_DATA_PIXEL_FORMAT_MCU_16_BIT 0x05
|
||||
/* PIXSET register fields. */
|
||||
#define ILI9340_PIXSET_RGB_18_BIT 0x60
|
||||
#define ILI9340_PIXSET_RGB_16_BIT 0x50
|
||||
#define ILI9340_PIXSET_MCU_18_BIT 0x06
|
||||
#define ILI9340_PIXSET_MCU_16_BIT 0x05
|
||||
|
||||
/** Command/data GPIO level for commands. */
|
||||
#define ILI9340_CMD 1U
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue