diff --git a/drivers/ili9341/ili9341.c b/drivers/ili9341/ili9341.c index e6f6206737..fdcbafbf34 100644 --- a/drivers/ili9341/ili9341.c +++ b/drivers/ili9341/ili9341.c @@ -131,7 +131,7 @@ 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; + command_params[0] = dev->params->rotation; command_params[0] |= dev->params->rgb ? 0 : ILI9341_MADCTL_BGR; _write_cmd(dev, ILI9341_CMD_MADCTL, command_params, 1); diff --git a/drivers/ili9341/include/ili9341_internal.h b/drivers/ili9341/include/ili9341_internal.h index 3a65e63b6d..d04499c078 100644 --- a/drivers/ili9341/include/ili9341_internal.h +++ b/drivers/ili9341/include/ili9341_internal.h @@ -65,30 +65,6 @@ extern "C" { #define ILI9341_CMD_IFCTL 0xf6 /**< Interface control */ /** @} */ -/** - * @name Memory access control bits - * @{ - */ -#define ILI9341_MADCTL_MY 0x80 /**< Row address order */ -#define ILI9341_MADCTL_MX 0x40 /**< Column access order */ -#define ILI9341_MADCTL_MV 0x20 /**< Row column exchange */ -#define ILI9341_MADCTL_ML 0x10 /**< Vertical refresh order */ -#define ILI9341_MADCTL_BGR 0x08 /**< Color selector switch control */ -#define ILI9341_MADCTL_MH 0x04 /**< Horizontal refresh direction */ -/** @} */ - -/** - * @name Display rotation modes - * @{ - */ -#define ILI9341_MADCTL_VERT ILI9341_MADCTL_MX /**< Vertical mode */ -#define ILI9341_MADCTL_VERT_FLIP ILI9341_MADCTL_MY /**< Flipped vertical */ -#define ILI9341_MADCTL_HORZ ILI9341_MADCTL_MV /**< Horizontal mode */ -#define ILI9341_MADCTL_HORZ_FLIP ILI9341_MADCTL_MV | \ - ILI9341_MADCTL_MY | \ - ILI9341_MADCTL_MX /**< Horizontal flipped */ -/** @} */ - #define ILI9341_PIXSET_16BIT 0x55 /**< MCU and RGB 16 bit interface */ #define ILI9341_PIXSET_18BIT 0x66 /**< MCU and RGB 18 bit interface (not implemented) */ diff --git a/drivers/ili9341/include/ili9341_params.h b/drivers/ili9341/include/ili9341_params.h index ddc627fb8b..6096195ef3 100644 --- a/drivers/ili9341/include/ili9341_params.h +++ b/drivers/ili9341/include/ili9341_params.h @@ -59,6 +59,10 @@ extern "C" { #define ILI9341_PARAM_NUM_LINES 320U #endif +#ifndef ILI9341_PARAM_ROTATION +#define ILI9341_PARAM_ROTATION ILI9341_ROTATION_HORZ_FLIP +#endif + #ifndef ILI9341_PARAMS #define ILI9341_PARAMS { .spi = ILI9341_PARAM_SPI, \ .spi_clk = ILI9341_PARAM_SPI_CLK, \ @@ -69,6 +73,7 @@ extern "C" { .rgb = ILI9341_PARAM_RGB, \ .inverted = ILI9341_PARAM_INVERTED, \ .lines = ILI9341_PARAM_NUM_LINES, \ + .rotation = ILI9341_PARAM_ROTATION, \ } #endif /**@}*/ diff --git a/drivers/include/ili9341.h b/drivers/include/ili9341.h index 561c73f6ed..8c41c0cd33 100644 --- a/drivers/include/ili9341.h +++ b/drivers/include/ili9341.h @@ -93,20 +93,55 @@ extern "C" { #endif /** @} */ +/** + * @name Memory access control bits + * @{ + */ +#define ILI9341_MADCTL_MY 0x80 /**< Row address order */ +#define ILI9341_MADCTL_MX 0x40 /**< Column access order */ +#define ILI9341_MADCTL_MV 0x20 /**< Row column exchange */ +#define ILI9341_MADCTL_ML 0x10 /**< Vertical refresh order */ +#define ILI9341_MADCTL_BGR 0x08 /**< Color selector switch control */ +#define ILI9341_MADCTL_MH 0x04 /**< Horizontal refresh direction */ +/** @} */ + +/** + * @name Display rotation modes + * @{ + */ +#define ILI9341_MADCTL_VERT ILI9341_MADCTL_MX /**< Vertical mode */ +#define ILI9341_MADCTL_VERT_FLIP ILI9341_MADCTL_MY /**< Flipped vertical */ +#define ILI9341_MADCTL_HORZ ILI9341_MADCTL_MV /**< Horizontal mode */ +#define ILI9341_MADCTL_HORZ_FLIP ILI9341_MADCTL_MV | \ + ILI9341_MADCTL_MY | \ + ILI9341_MADCTL_MX /**< Horizontal flipped */ +/** @} */ + +/** + * @brief Display rotation mode + */ +typedef enum { + ILI9341_ROTATION_VERT = ILI9341_MADCTL_VERT, /**< Vertical mode */ + ILI9341_ROTATION_VERT_FLIP = ILI9341_MADCTL_VERT_FLIP, /**< Vertical flipped mode */ + ILI9341_ROTATION_HORZ = ILI9341_MADCTL_HORZ, /**< Horizontal mode */ + ILI9341_ROTATION_HORZ_FLIP = ILI9341_MADCTL_HORZ_FLIP, /**< Horizontal flipped mode */ +} ili9341_rotation_t; + /** * @brief Device initialization parameters */ typedef struct { - spi_t spi; /**< SPI device that the display is connected to */ - spi_clk_t spi_clk; /**< SPI clock speed to use */ - spi_mode_t spi_mode;/**< SPI mode */ - 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 */ - uint16_t lines; /**< Number of lines, from 16 to 320 in 8 line steps */ + spi_t spi; /**< SPI device that the display is connected to */ + spi_clk_t spi_clk; /**< SPI clock speed to use */ + spi_mode_t spi_mode; /**< SPI mode */ + 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 */ + uint16_t lines; /**< Number of lines, from 16 to 320 in 8 line steps */ + ili9341_rotation_t rotation; /**< Display rotation mode */ } ili9341_params_t; /**