Skip to content

Commit

Permalink
Merge pull request RIOT-OS#13105 from bergzand/pr/ili9341_add_config
Browse files Browse the repository at this point in the history
ili9341: Add color mode and inversion parameters
  • Loading branch information
aabadie authored Jan 13, 2020
2 parents 3e00430 + 146137e commit cfbab79
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
17 changes: 14 additions & 3 deletions drivers/ili9341/ili9341.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ int ili9341_init(ili9341_t *dev, const ili9341_params_t *params)
_write_cmd(dev, ILI9341_CMD_VMCTRL2, command_params, 1);

/* Memory access CTL */
command_params[0] = ILI9341_MADCTL_HORZ_FLIP | ILI9341_MADCTL_BGR;
command_params[0] = ILI9341_MADCTL_HORZ_FLIP;
command_params[0] |= dev->params->rgb ? 0 : ILI9341_MADCTL_BGR;
_write_cmd(dev, ILI9341_CMD_MADCTL, command_params, 1);

/* Frame control */
Expand Down Expand Up @@ -194,6 +195,10 @@ int ili9341_init(ili9341_t *dev, const ili9341_params_t *params)
sizeof(gamma_neg));

}

if (dev->params->inverted) {
_write_cmd(dev, ILI9341_CMD_DINVON, NULL, 0);
}
/* Sleep out (turn off sleep mode) */
_write_cmd(dev, ILI9341_CMD_SLPOUT, NULL, 0);
/* Display on */
Expand Down Expand Up @@ -290,12 +295,18 @@ void ili9341_pixmap(ili9341_t *dev, uint16_t x1, uint16_t x2,

void ili9341_invert_on(ili9341_t *dev)
{
ili9341_write_cmd(dev, ILI9341_CMD_DINVON, NULL, 0);
uint8_t command = (dev->params->inverted) ? ILI9341_CMD_DINVOFF
: ILI9341_CMD_DINVON;

ili9341_write_cmd(dev, command, NULL, 0);
}

void ili9341_invert_off(ili9341_t *dev)
{
ili9341_write_cmd(dev, ILI9341_CMD_DINVOFF, NULL, 0);
uint8_t command = (dev->params->inverted) ? ILI9341_CMD_DINVON
: ILI9341_CMD_DINVOFF;

ili9341_write_cmd(dev, command, NULL, 0);
}

void ili9341_set_brightness(ili9341_t *dev, uint8_t brightness)
Expand Down
10 changes: 9 additions & 1 deletion drivers/ili9341/include/ili9341_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ extern "C" {
#define ILI9341_PARAM_RST GPIO_UNDEF
#endif
#ifndef ILI9341_PARAM_SPI_MODE
#define ILI9341_PARAM_SPI_MODE SPI_MODE_0
#define ILI9341_PARAM_SPI_MODE SPI_MODE_0
#endif
#ifndef ILI9341_PARAM_RGB
#define ILI9341_PARAM_RGB 0
#endif
#ifndef ILI9341_PARAM_INVERTED
#define ILI9341_PARAM_INVERTED 0
#endif

#ifndef ILI9341_PARAMS
Expand All @@ -56,6 +62,8 @@ extern "C" {
.cs_pin = ILI9341_PARAM_CS, \
.dcx_pin = ILI9341_PARAM_DCX, \
.rst_pin = ILI9341_PARAM_RST, \
.rgb = ILI9341_PARAM_RGB, \
.inverted = ILI9341_PARAM_INVERTED, \
}
#endif
/**@}*/
Expand Down
3 changes: 3 additions & 0 deletions drivers/include/ili9341.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ typedef struct {
gpio_t cs_pin; /**< pin connected to the CHIP SELECT line */
gpio_t dcx_pin; /**< pin connected to the DC line */
gpio_t rst_pin; /**< pin connected to the reset line */
bool rgb; /**< True when display is connected in RGB mode
* False when display is connected in BGR mode */
bool inverted; /**< Display works in inverted color mode */
} ili9341_params_t;

/**
Expand Down

0 comments on commit cfbab79

Please sign in to comment.