Support for the MIO283QT9A LCD from Toby Duckworth

This commit is contained in:
Gregory Nutt 2014-02-10 12:26:08 -06:00
parent 0070815e87
commit a9b01d5824
9 changed files with 1636 additions and 4 deletions

View File

@ -6566,3 +6566,7 @@
cursor (2014-2-10).
* drivers/usbhost/usbhost_hidmouse.c, include/nuttx/input/mouse.h, and
include/nuttx/usb/hid.h: Add support for a mouse wheel (2014-2-10).
* drivers/lcd/mio283qt9a.c and include/nuttx/lcd/mio283qt9a.h: Support
for the MIO283QT9A LCD. From Toby Duckworth (2014-2-10).
* configs/mikroe-stm32f4/src/up_mio283qt9a.c: The Mikroe STM32F4 can
now support the newer MIO283QT9A LCD. From Toby Duckworth (2014-2-10).

View File

@ -94,6 +94,10 @@ ifeq ($(CONFIG_LCD_MIO283QT2),y)
CSRCS += up_mio283qt2.c
endif
ifeq ($(CONFIG_LCD_MIO283QT9A),y)
CSRCS += up_mio283qt9a.c
endif
ifeq ($(CONFIG_VS1053),y)
CSRCS += up_vs1053.c
endif

View File

@ -250,7 +250,7 @@ void weak_function stm32_usbinitialize(void);
*
****************************************************************************************************/
#ifdef CONFIG_LCD_MIO283QT2
#if defined(CONFIG_LCD_MIO283QT2) || defined(CONFIG_LCD_MIO283QT9A)
void stm32_lcdinitialize(void);
#endif
@ -263,7 +263,7 @@ void stm32_lcdinitialize(void);
*
****************************************************************************************************/
#ifdef CONFIG_LCD_MIO283QT2
#if defined(CONFIG_LCD_MIO283QT2) || defined(CONFIG_LCD_MIO283QT9A)
int up_lcdinitialize(void);
#endif

View File

@ -79,7 +79,7 @@ void stm32_boardinitialize(void)
/* Configure GPIOs for controlling the LCD */
#ifdef CONFIG_LCD_MIO283QT2
#if defined(CONFIG_LCD_MIO283QT2) || defined(CONFIG_LCD_MIO283QT9A)
stm32_lcdinitialize();
#endif

View File

@ -0,0 +1,562 @@
/**************************************************************************************
* configs/mikroe-stm32f4/src/up_mio283qt9a.c
*
* Interface definition for the MI0283QT-9A LCD from Multi-Inno Technology Co., Ltd.
* LCD is based on the Ilitek ILI9341 LCD controller.
*
* Copyright (C) 2012-2014 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org>
*
* Modified: 2013-2014 by Ken Pettit to support Mikroe-STM32F4 board.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************************/
/**************************************************************************************
* Included Files
**************************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/lcd/lcd.h>
#include <nuttx/lcd/mio283qt9a.h>
#include <arch/board/board.h>
#include "up_arch.h"
#include "stm32.h"
#include "stm32_gpio.h"
#include "mikroe-stm32f4-internal.h"
#ifdef CONFIG_LCD_MIO283QT9A
/**************************************************************************************
* Pre-processor Definitions
**************************************************************************************/
/* Configuration **********************************************************************/
/* Define CONFIG_DEBUG_LCD to enable detailed LCD debug output. Verbose debug must
* also be enabled.
*/
#ifndef CONFIG_DEBUG
# undef CONFIG_DEBUG_VERBOSE
# undef CONFIG_DEBUG_GRAPHICS
# undef CONFIG_DEBUG_LCD
#endif
#ifndef CONFIG_DEBUG_VERBOSE
# undef CONFIG_DEBUG_LCD
#endif
/* Mikroe-STM32F4 Hardware Definitions ************************************************/
/* --- ---------------------------------- -------------------- ------------------------
* PIN CONFIGURATIONS SIGNAL NAME ON-BOARD CONNECTIONS
* (Family Data Sheet Table 1-1) (PIC32MX7 Schematic)
* --- ---------------------------------- -------------------- ------------------------
* 39 PE8 LCD_RST TFT display
* 46 PE15 LCD-CS# TFT display
* 40 PE9 LCD_BLED LCD backlight LED
* 43 PE12 LCD-RS TFT display
*
*
* 97 RE0 T_D0 TFT display
* 98 RE1 T_D1 TFT display
* 1 RE2 T_D2 TFT display
* 2 RE3 T_D3 TFT display
* 3 RE4 T_D4 TFT display
* 4 RE5 T_D5 TFT display
* 5 RE6 T_D6 TFT display
* 38 RE7 T_D7 TFT display
*
* 41 PE10 PMPRD
* 42 RE11 PMPWR
*
* TOUCHSCREEN PIN CONFIGURATIONS
* PIN CONFIGURATIONS SIGNAL NAME ON-BOARD CONNECTIONS
* --- ---------------------------------- -------------------- ------------------------
* 35 PB0 LCD-YD TFT display
* ? LCD-XR TFT display
* ? LCD-YU TFT display
* 36 PB1 LCD-XL TFT display
* 95 PB8 DRIVEA TFT display
* 96 PB9 DRIVEB TFT display
*/
/* Debug ******************************************************************************/
#ifdef CONFIG_DEBUG_LCD
# define lcddbg dbg
# define lcdvdbg vdbg
#else
# define lcddbg(x...)
# define lcdvdbg(x...)
#endif
/**************************************************************************************
* Private Type Definition
**************************************************************************************/
struct stm32f4_dev_s
{
struct mio283qt9a_lcd_s dev; /* The externally visible part of the driver */
bool grammode; /* true=Writing to GRAM (16-bit write vs 8-bit) */
bool firstread; /* First GRAM read? */
FAR struct lcd_dev_s *drvr; /* The saved instance of the LCD driver */
};
/**************************************************************************************
* Private Function Protototypes
**************************************************************************************/
/* Low Level LCD access */
static void stm32_select(FAR struct mio283qt9a_lcd_s *dev);
static void stm32_deselect(FAR struct mio283qt9a_lcd_s *dev);
static void stm32_index(FAR struct mio283qt9a_lcd_s *dev, uint8_t index);
#if !defined(CONFIG_MIO283QT2_WRONLY) && CONFIG_LCD_NOGETRUN != 1
static uint16_t stm32_read(FAR struct mio283qt9a_lcd_s *dev);
#endif
static void stm32_write(FAR struct mio283qt9a_lcd_s *dev, uint16_t data);
static void stm32_backlight(FAR struct mio283qt9a_lcd_s *dev, int power);
/**************************************************************************************
* Private Data
**************************************************************************************/
/* This is the driver state structure (there is no retained state information) */
static struct stm32f4_dev_s g_stm32f4_lcd =
{
{
.select = stm32_select,
.deselect = stm32_deselect,
.index = stm32_index,
#if !defined(CONFIG_MIO283QT2_WRONLY) && CONFIG_LCD_NOGETRUN != 1
.read = stm32_read,
#endif
.write = stm32_write,
.backlight = stm32_backlight
}
};
static uint32_t * volatile g_portsetreset = (uint32_t *) STM32_GPIOE_BSRR;
/**************************************************************************************
* Private Functions
**************************************************************************************/
/**************************************************************************************
* Name: stm32_tinydelay
*
* Description:
* Delay for a few hundred NS.
*
**************************************************************************************/
static void stm32_tinydelay(void)
{
volatile uint8_t x = 0;
for (x = 1; x > 0; x--)
;
}
/**************************************************************************************
* Name: stm32_command
*
* Description:
* Configure to write an LCD command
*
**************************************************************************************/
static inline void stm32_command(void)
{
uint32_t * volatile portsetreset = (uint32_t *) STM32_GPIOE_BSRR;
/* Low selects command */
*portsetreset = (1 << LCD_RS_PIN) << 16;
}
/**************************************************************************************
* Name: stm32_data
*
* Description:
* Configure to read or write LCD data
*
**************************************************************************************/
static inline void stm32_data(void)
{
/* Hi selects data */
*g_portsetreset = 1 << LCD_RS_PIN;
}
/**************************************************************************************
* Name: stm32_select
*
* Description:
* Select the LCD device
*
**************************************************************************************/
static void stm32_select(FAR struct mio283qt9a_lcd_s *dev)
{
/* CS low selects */
*g_portsetreset = (1 << LCD_CS_PIN) << 16;
}
/**************************************************************************************
* Name: stm32_deselect
*
* Description:
* De-select the LCD device
*
**************************************************************************************/
static void stm32_deselect(FAR struct mio283qt9a_lcd_s *dev)
{
/* CS high de-selects */
*g_portsetreset = 1 << LCD_CS_PIN;
}
/**************************************************************************************
* Name: stm32_index
*
* Description:
* Set the index register
*
**************************************************************************************/
static void stm32_index(FAR struct mio283qt9a_lcd_s *dev, uint8_t index)
{
FAR struct stm32f4_dev_s *priv = (FAR struct stm32f4_dev_s *)dev;
/* Setup to write in command mode (vs data mode) */
stm32_command();
/* Write the index register to the 8-bit GPIO pin bus. We are violating the
* datasheet here a little by driving the WR pin low at the same time as
* the data, but the fact is that all ASIC logic will latch on the rising
* edge of WR anyway, not the falling edge. We are just shaving off a few
* cycles every time this routine is called, which will be fairly often.
*/
*g_portsetreset = index | ((uint8_t) (~index) << 16) |
((1 << LCD_PMPWR_PIN) << 16);
/* Record if we are accessing GRAM or not (16 vs 8 bit accesses)
* NOTE. This also serves as a delay between WR low to WR high
* transition.
*/
priv->grammode = index == 0x2c;
priv->firstread = true;
/* Now raise the WR line */
*g_portsetreset = (1 << LCD_PMPWR_PIN);
/* Back to data mode to read/write the data */
stm32_data();
}
/**************************************************************************************
* Name: stm32_read
*
* Description:
* Read LCD data (GRAM data or register contents)
*
**************************************************************************************/
#if !defined(CONFIG_MIO283QT2_WRONLY) && CONFIG_LCD_NOGETRUN != 1
static uint16_t stm32_read(FAR struct mio283qt9a_lcd_s *dev)
{
FAR struct stm32f4_dev_s *priv = (FAR struct stm32f4_dev_s *)dev;
uint32_t * volatile portsetreset = (uint32_t *) STM32_GPIOE_BSRR;
uint32_t * volatile portmode = (uint32_t *) STM32_GPIOE_MODER;
uint32_t * volatile portinput = (uint32_t *) STM32_GPIOE_IDR;
uint16_t data;
/* Set the I/O Port to input mode. Ugly, but fast. */
*portmode &= 0xFFFF0000;
/* Read the data */
*portsetreset = (1 << LCD_PMPRD_PIN) << 16;
stm32_tinydelay();
data = *portinput & 0x00FF;
*portsetreset = (1 << LCD_PMPRD_PIN);
/* Test if a 16-bit read is needed (GRAM mode) */
if (priv->grammode)
{
/* If this is the 1st GRAM read, then discard the dummy byte */
if (priv->firstread)
{
priv->firstread = false;
*portsetreset = (1 << LCD_PMPRD_PIN) << 16;
stm32_tinydelay();
data = *portinput;
*portsetreset = (1 << LCD_PMPRD_PIN);
}
/* Okay, a 16-bit read is actually a 24-bit read from the LCD.
* this is because the read color format of the MIO283QT-2 is a bit
* different than the 16-bit write color format. During a read,
* the R,G and B samples are read on subsequent bytes, and the
* data is MSB aligned. We must re-construct the 16-bit 565 data.
*/
/* Clip RED sample to 5-bits and shit to MSB */
data = (data & 0xF8) << 8;
/* Now read Green sample */
*portsetreset = (1 << LCD_PMPRD_PIN) << 16;
stm32_tinydelay();
data |= (*portinput & 0x00FC) << 3;
*portsetreset = (1 << LCD_PMPRD_PIN);
/* Now read Blue sample */
*portsetreset = (1 << LCD_PMPRD_PIN) << 16;
stm32_tinydelay();
data |= (*portinput & 0x00F8) >> 3;
*portsetreset = (1 << LCD_PMPRD_PIN);
}
/* Put the port back in output mode. Ugly, but fast. */
*portmode |= 0x00005555;
return data;
}
#endif
/**************************************************************************************
* Name: stm32_write
*
* Description:
* Write LCD data (GRAM data or register contents)
*
**************************************************************************************/
static void stm32_write(FAR struct mio283qt9a_lcd_s *dev, uint16_t data)
{
FAR struct stm32f4_dev_s *priv = (FAR struct stm32f4_dev_s *)dev;
/* Write the data register to the 8-bit GPIO pin bus. We are violating the
* datasheet here a little by driving the WR pin low at the same time as
* the data, but the fact is that all ASIC logic will latch on the rising
* edge of WR anyway, not the falling edge. We are just shaving off a few
* cycles every time this routine is called, which will be fairly often.
*/
if (priv->grammode)
{
/* Need to write 16-bit pixel data (16 BPP). Write the upper pixel data first */
*g_portsetreset = ((data>>8) & 0xFF) | (((~data>>8) & 0xFF) << 16) |
((1 << LCD_PMPWR_PIN) << 16);
stm32_tinydelay();
*g_portsetreset = (1 << LCD_PMPWR_PIN);
}
/* Now write the lower 8-bit of data */
*g_portsetreset = (data & 0xFF) | ((~data & 0xFF) << 16) |
((1 << LCD_PMPWR_PIN) << 16);
stm32_tinydelay();
*g_portsetreset = (1 << LCD_PMPWR_PIN);
}
/**************************************************************************************
* Name: stm32_backlight
*
* Description:
* Set the backlight power level.
*
**************************************************************************************/
static void stm32_backlight(FAR struct mio283qt9a_lcd_s *dev, int power)
{
/* For now, we just control the backlight as a discrete. Pulse width modulation
* would be required to vary the backlight level. A low value turns the backlight
* off.
*/
stm32_gpiowrite(GPIO_LCD_BLED, power > 0);
}
/**************************************************************************************
* Public Functions
**************************************************************************************/
/**************************************************************************************
* Name: stm32_lcdinitialize
*
* Description:
* Initialize the LCD. This function should be called early in the boot
* sequendce -- Even if the LCD is not enabled. In that case we should
* at a minimum at least disable the LCD backlight.
*
**************************************************************************************/
void stm32_lcdinitialize(void)
{
/* Configure all LCD discrete controls. LCD will be left in this state:
* 1. Held in reset,
* 2. Not selected,
* 3. Backlight off,
* 4. Command selected.
*/
#ifdef CONFIG_LCD_MIO283QT9A
stm32_configgpio(GPIO_LCD_RST);
stm32_configgpio(GPIO_LCD_CS);
stm32_configgpio(GPIO_LCD_BLED);
stm32_gpiowrite(GPIO_LCD_BLED, false);
stm32_configgpio(GPIO_LCD_RS);
stm32_configgpio(GPIO_LCD_PMPWR);
stm32_configgpio(GPIO_LCD_PMPRD);
/* Configure PE0-7 for output */
stm32_configgpio(GPIO_LCD_T_D0);
stm32_configgpio(GPIO_LCD_T_D1);
stm32_configgpio(GPIO_LCD_T_D2);
stm32_configgpio(GPIO_LCD_T_D3);
stm32_configgpio(GPIO_LCD_T_D4);
stm32_configgpio(GPIO_LCD_T_D5);
stm32_configgpio(GPIO_LCD_T_D6);
stm32_configgpio(GPIO_LCD_T_D7);
#else
/* Just configure the backlight control as an output and turn off the
* backlight for now.
*/
stm32_configgpio(GPIO_LCD_BLED);
#endif
}
/**************************************************************************************
* Name: up_lcdinitialize
*
* Description:
* Initialize the LCD video hardware. The initial state of the LCD is fully
* initialized, display memory cleared, and the LCD ready to use, but with the power
* setting at 0 (full off).
*
**************************************************************************************/
int up_lcdinitialize(void)
{
/* Only initialize the driver once. NOTE: The LCD GPIOs were already configured
* by stm32_lcdinitialize.
*/
if (!g_stm32f4_lcd.drvr)
{
lcdvdbg("Initializing\n");
/* Hold the LCD in reset (active low) */
stm32_gpiowrite(GPIO_LCD_RST, false);
/* Bring the LCD out of reset */
up_mdelay(5);
stm32_gpiowrite(GPIO_LCD_RST, true);
/* Configure and enable the LCD */
up_mdelay(50);
g_stm32f4_lcd.drvr = mio283qt9a_lcdinitialize(&g_stm32f4_lcd.dev);
if (!g_stm32f4_lcd.drvr)
{
lcddbg("ERROR: mio283qt9a_lcdinitialize failed\n");
return -ENODEV;
}
}
/* Turn the display off */
g_stm32f4_lcd.drvr->setpower(g_stm32f4_lcd.drvr, 0);
return OK;
}
/**************************************************************************************
* Name: up_lcdgetdev
*
* Description:
* Return a a reference to the LCD object for the specified LCD. This allows support
* for multiple LCD devices.
*
**************************************************************************************/
FAR struct lcd_dev_s *up_lcdgetdev(int lcddev)
{
DEBUGASSERT(lcddev == 0);
return g_stm32f4_lcd.drvr;
}
/**************************************************************************************
* Name: up_lcduninitialize
*
* Description:
* Uninitialize the LCD support
*
**************************************************************************************/
void up_lcduninitialize(void)
{
/* Turn the display off */
g_stm32f4_lcd.drvr->setpower(g_stm32f4_lcd.drvr, 0);
}
#endif /* CONFIG_LCD_MIO283QT9A */

View File

@ -356,7 +356,7 @@ int nsh_archinitialize(void)
}
#endif
#ifdef CONFIG_LCD_MIO283QT2
#if defined(CONFIG_LCD_MIO283QT2) || defined(CONFIG_LCD_MIO283QT9A)
/* Configure the TFT LCD module */
message("nsh_archinitialize: Initializing TFT LCD module\n");

View File

@ -67,6 +67,10 @@ ifeq ($(CONFIG_LCD_MIO283QT2),y)
CSRCS += mio283qt2.c
endif
ifeq ($(CONFIG_LCD_MIO283QT9A),y)
CSRCS += mio283qt9a.c
endif
ifeq ($(CONFIG_LCD_ST7567),y)
CSRCS += st7567.c
endif

908
drivers/lcd/mio283qt9a.c Normal file
View File

@ -0,0 +1,908 @@
/**************************************************************************************
* drivers/lcd/mio283qt9a.c
*
* This is a driver for the MI0283QT-9A LCD from Multi-Inno Technology Co., Ltd. This
* LCD is based on the Ilitek ILI9341 LCD controller.
*
* Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************************/
/**************************************************************************************
* Included Files
**************************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/spi/spi.h>
#include <nuttx/lcd/lcd.h>
#include <nuttx/lcd/mio283qt9a.h>
#ifdef CONFIG_LCD_MIO283QT9A
/**************************************************************************************
* Pre-processor Definitions
**************************************************************************************/
/* Configuration **********************************************************************/
/* Check contrast selection */
#if !defined(CONFIG_LCD_MAXCONTRAST)
# define CONFIG_LCD_MAXCONTRAST 1
#endif
/* Check power setting */
#if !defined(CONFIG_LCD_MAXPOWER) || CONFIG_LCD_MAXPOWER < 1
# define CONFIG_LCD_MAXPOWER 1
#endif
#if CONFIG_LCD_MAXPOWER > 255
# error "CONFIG_LCD_MAXPOWER must be less than 256 to fit in uint8_t"
#endif
/* Check orientation */
#if defined(CONFIG_LCD_PORTRAIT)
# if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE) || defined(CONFIG_LCD_RPORTRAIT)
# error "Cannot define both portrait and any other orientations"
# endif
#elif defined(CONFIG_LCD_RPORTRAIT)
# if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE)
# error "Cannot define both rportrait and any other orientations"
# endif
#elif defined(CONFIG_LCD_LANDSCAPE)
# ifdef CONFIG_LCD_RLANDSCAPE
# error "Cannot define both landscape and any other orientations"
# endif
#elif !defined(CONFIG_LCD_RLANDSCAPE)
# define CONFIG_LCD_LANDSCAPE 1
#endif
/* Define CONFIG_DEBUG_LCD to enable detailed LCD debug output. Verbose debug must
* also be enabled.
*/
#ifndef CONFIG_DEBUG
# undef CONFIG_DEBUG_VERBOSE
# undef CONFIG_DEBUG_GRAPHICS
# undef CONFIG_DEBUG_LCD
#endif
#ifndef CONFIG_DEBUG_VERBOSE
# undef CONFIG_DEBUG_LCD
#endif
/* Display/Color Properties ***********************************************************/
/* Display Resolution */
#if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE)
# define MIO283QT9A_XRES 320
# define MIO283QT9A_YRES 240
#else
# define MIO283QT9A_XRES 240
# define MIO283QT9A_YRES 320
#endif
/* Color depth and format */
#define MIO283QT9A_BPP 16
#define MIO283QT9A_COLORFMT FB_FMT_RGB16_565
/* Hardware LCD/LCD controller definitions ********************************************/
/* In this driver, I chose to use all literal constants for register address and
* values. Some recent experiences have shown me that during LCD bringup, it is more
* important to know the binary values rather than nice, people friendly names. Sad,
* but true.
*/
#define ILI9341_ID_1 0x93
#define ILI9341_ID_2 0x41
/* Debug ******************************************************************************/
#ifdef CONFIG_DEBUG_LCD
# define lcddbg dbg
# define lcdvdbg vdbg
#else
# define lcddbg(x...)
# define lcdvdbg(x...)
#endif
/**************************************************************************************
* Private Type Definition
**************************************************************************************/
/* This structure describes the state of this driver */
struct mio283qt9a_dev_s
{
/* Publicly visible device structure */
struct lcd_dev_s dev;
/* Private LCD-specific information follows */
FAR struct mio283qt9a_lcd_s *lcd; /* The contained platform-specific, LCD interface */
uint8_t power; /* Current power setting */
/* This is working memory allocated by the LCD driver for each LCD device
* and for each color plane. This memory will hold one raster line of data.
* The size of the allocated run buffer must therefore be at least
* (bpp * xres / 8). Actual alignment of the buffer must conform to the
* bitwidth of the underlying pixel type.
*
* If there are multiple planes, they may share the same working buffer
* because different planes will not be operate on concurrently. However,
* if there are multiple LCD devices, they must each have unique run buffers.
*/
uint16_t runbuffer[MIO283QT9A_XRES];
};
/**************************************************************************************
* Private Function Prototypes
**************************************************************************************/
/* Low Level LCD access */
static void mio283qt9a_putreg(FAR struct mio283qt9a_lcd_s *lcd, uint8_t regaddr,
uint16_t regval);
#ifndef CONFIG_LCD_NOGETRUN
static uint16_t mio283qt9a_readreg(FAR struct mio283qt9a_lcd_s *lcd, uint8_t regaddr);
#endif
static inline void mio283qt9a_gramwrite(FAR struct mio283qt9a_lcd_s *lcd,
uint16_t rgbcolor);
#ifndef CONFIG_LCD_NOGETRUN
static inline void mio283qt9a_readsetup(FAR struct mio283qt9a_lcd_s *lcd,
FAR uint16_t *accum);
static inline uint16_t mio283qt9a_gramread(FAR struct mio283qt9a_lcd_s *lcd,
FAR uint16_t *accum);
#endif
static void mio283qt9a_setarea(FAR struct mio283qt9a_lcd_s *lcd,
uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
/* LCD Data Transfer Methods */
static int mio283qt9a_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *buffer,
size_t npixels);
static int mio283qt9a_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer,
size_t npixels);
/* LCD Configuration */
static int mio283qt9a_getvideoinfo(FAR struct lcd_dev_s *dev,
FAR struct fb_videoinfo_s *vinfo);
static int mio283qt9a_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno,
FAR struct lcd_planeinfo_s *pinfo);
/* LCD RGB Mapping */
#ifdef CONFIG_FB_CMAP
# error "RGB color mapping not supported by this driver"
#endif
/* Cursor Controls */
#ifdef CONFIG_FB_HWCURSOR
# error "Cursor control not supported by this driver"
#endif
/* LCD Specific Controls */
static int mio283qt9a_getpower(FAR struct lcd_dev_s *dev);
static int mio283qt9a_setpower(FAR struct lcd_dev_s *dev, int power);
static int mio283qt9a_getcontrast(FAR struct lcd_dev_s *dev);
static int mio283qt9a_setcontrast(FAR struct lcd_dev_s *dev, unsigned int contrast);
/* Initialization */
static inline int mio283qt9a_hwinitialize(FAR struct mio283qt9a_dev_s *priv);
/**************************************************************************************
* Private Data
**************************************************************************************/
/* This driver can support only a signal MIO283QT9A device. This is due to an
* unfortunate decision made when the getrun and putrun methods were designed. The
* following is the single MIO283QT9A driver state instance:
*/
static struct mio283qt9a_dev_s g_lcddev;
/**************************************************************************************
* Private Functions
**************************************************************************************/
/**************************************************************************************
* Name: mio283qt9a_putreg
*
* Description:
* Write to an LCD register
*
**************************************************************************************/
static void mio283qt9a_putreg(FAR struct mio283qt9a_lcd_s *lcd,
uint8_t regaddr, uint16_t regval)
{
/* Set the index register to the register address and write the register contents */
lcd->index(lcd, regaddr);
lcd->write(lcd, regval);
}
/**************************************************************************************
* Name: mio283qt9a_readreg
*
* Description:
* Read from an LCD register
*
**************************************************************************************/
#ifndef CONFIG_LCD_NOGETRUN
static uint16_t mio283qt9a_readreg(FAR struct mio283qt9a_lcd_s *lcd, uint8_t regaddr)
{
/* Set the index register to the register address and read the register contents. */
lcd->index(lcd, regaddr);
return lcd->read(lcd);
}
#endif
/**************************************************************************************
* Name: mio283qt9a_gramselect
*
* Description:
* Setup to read or write multiple pixels to the GRAM memory
*
**************************************************************************************/
static inline void mio283qt9a_gramselect(FAR struct mio283qt9a_lcd_s *lcd)
{
lcd->index(lcd, 0x2c);
}
/**************************************************************************************
* Name: mio283qt9a_gramwrite
*
* Description:
* Setup to read or write multiple pixels to the GRAM memory
*
**************************************************************************************/
static inline void mio283qt9a_gramwrite(FAR struct mio283qt9a_lcd_s *lcd, uint16_t data)
{
lcd->write(lcd, data);
}
/**************************************************************************************
* Name: mio283qt9a_readsetup
*
* Description:
* Prime the operation by reading one pixel from the GRAM memory if necessary for
* this LCD type. When reading 16-bit gram data, there may be some shifts in the
* returned data:
*
* - ILI932x: Discard first dummy read; no shift in the return data
*
**************************************************************************************/
#ifndef CONFIG_LCD_NOGETRUN
static inline void mio283qt9a_readsetup(FAR struct mio283qt9a_lcd_s *lcd,
FAR uint16_t *accum)
{
#if 0 /* Probably not necessary... untested */
/* Read-ahead one pixel */
*accum = lcd->read(lcd);
#endif
}
#endif
/**************************************************************************************
* Name: mio283qt9a_gramread
*
* Description:
* Read one correctly aligned pixel from the GRAM memory. Possibly shifting the
* data and possibly swapping red and green components.
*
* - ILI932x: Unknown -- assuming colors are in the color order
*
**************************************************************************************/
#ifndef CONFIG_LCD_NOGETRUN
static inline uint16_t mio283qt9a_gramread(FAR struct mio283qt9a_lcd_s *lcd,
FAR uint16_t *accum)
{
/* Read the value (GRAM register already selected) */
return lcd->read(lcd);
}
#endif
/**************************************************************************************
* Name: mio283qt9a_setarea
*
* Description:
* Set the cursor position. In landscape mode, the "column" is actually the physical
* Y position and the "row" is the physical X position.
*
**************************************************************************************/
static void mio283qt9a_setarea(FAR struct mio283qt9a_lcd_s *lcd,
uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{
//lcddbg("setarea x0=%d, y0=%d, x1=%d, y1=%d\n", x0, y0, x1, y1);
mio283qt9a_putreg(lcd, 0x2a, (x0 >> 8)); /* set column address x0 */
lcd->write(lcd, (x0 & 0xff)); /* set x0 */
lcd->write(lcd, (x1 >> 8)); /* set x1 */
lcd->write(lcd, (x1 & 0xff)); /* set x1 */
mio283qt9a_putreg(lcd, 0x2b, (y0 >> 8)); /* set page address y0 */
lcd->write(lcd, (y0 & 0xff)); /* set y0 */
lcd->write(lcd, (y1 >> 8)); /* set y1 */
lcd->write(lcd, (y1 & 0xff)); /* set y1 */
}
/**************************************************************************************
* Name: mio283qt9a_dumprun
*
* Description:
* Dump the contexts of the run buffer:
*
* run - The buffer in containing the run read to be dumped
* npixels - The number of pixels to dump
*
**************************************************************************************/
#if 0 /* Sometimes useful */
static void mio283qt9a_dumprun(FAR const char *msg, FAR uint16_t *run, size_t npixels)
{
int i;
int j;
syslog("\n%s:\n", msg);
for (i = 0; i < npixels; i += 16)
{
up_putc(' ');
syslog(" ");
for (j = 0; j < 16; j++)
{
syslog(" %04x", *run++);
}
up_putc('\n');
}
}
#endif
/**************************************************************************************
* Name: mio283qt9a_putrun
*
* Description:
* This method can be used to write a partial raster line to the LCD:
*
* row - Starting row to write to (range: 0 <= row < yres)
* col - Starting column to write to (range: 0 <= col <= xres-npixels)
* buffer - The buffer containing the run to be written to the LCD
* npixels - The number of pixels to write to the LCD
* (range: 0 < npixels <= xres-col)
*
**************************************************************************************/
static int mio283qt9a_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *buffer,
size_t npixels)
{
FAR struct mio283qt9a_dev_s *priv = &g_lcddev;
FAR struct mio283qt9a_lcd_s *lcd = priv->lcd;
FAR const uint16_t *src = (FAR const uint16_t*)buffer;
int i;
/* Buffer must be provided and aligned to a 16-bit address boundary */
//lcdvdbg("row: %d col: %d npixels: %d\n", row, col, npixels);
DEBUGASSERT(buffer && ((uintptr_t)buffer & 1) == 0);
/* Select the LCD */
lcd->select(lcd);
/* Write the run to GRAM. */
mio283qt9a_setarea(lcd, col, row, col + npixels - 1, row);
mio283qt9a_gramselect(lcd);
src++;
for (i = 0; i < npixels; i++)
{
mio283qt9a_gramwrite(lcd, *src);
src++;
}
/* De-select the LCD */
lcd->deselect(lcd);
return OK;
}
/**************************************************************************************
* Name: mio283qt9a_getrun
*
* Description:
* This method can be used to read a partial raster line from the LCD:
*
* row - Starting row to read from (range: 0 <= row < yres)
* col - Starting column to read read (range: 0 <= col <= xres-npixels)
* buffer - The buffer in which to return the run read from the LCD
* npixels - The number of pixels to read from the LCD
* (range: 0 < npixels <= xres-col)
*
**************************************************************************************/
static int mio283qt9a_getrun(fb_coord_t row, fb_coord_t col, FAR uint8_t *buffer,
size_t npixels)
{
#ifndef CONFIG_LCD_NOGETRUN
FAR struct mio283qt9a_dev_s *priv = &g_lcddev;
FAR struct mio283qt9a_lcd_s *lcd = priv->lcd;
FAR uint16_t *dest = (FAR uint16_t*)buffer;
uint16_t accum;
int i;
/* Buffer must be provided and aligned to a 16-bit address boundary */
lcdvdbg("row: %d col: %d npixels: %d\n", row, col, npixels);
DEBUGASSERT(buffer && ((uintptr_t)buffer & 1) == 0);
/* Read the run from GRAM. */
/* Select the LCD */
lcd->select(lcd);
/* Red the run fram GRAM. */
mio283qt9a_setarea(lcd, col, row, col + npixels - 1, row);
mio283qt9a_gramselect(lcd);
/* Prime the pump for unaligned read data */
mio283qt9a_readsetup(lcd, &accum);
for (i = 0; i < npixels; i++)
{
*dest++ = mio283qt9a_gramread(lcd, &accum);
}
/* De-select the LCD */
lcd->deselect(lcd);
return OK;
#else
return -ENOSYS;
#endif
}
/**************************************************************************************
* Name: mio283qt9a_getvideoinfo
*
* Description:
* Get information about the LCD video controller configuration.
*
**************************************************************************************/
static int mio283qt9a_getvideoinfo(FAR struct lcd_dev_s *dev,
FAR struct fb_videoinfo_s *vinfo)
{
DEBUGASSERT(dev && vinfo);
lcdvdbg("fmt: %d xres: %d yres: %d nplanes: 1\n",
MIO283QT9A_COLORFMT, MIO283QT9A_XRES, MIO283QT9A_YRES);
vinfo->fmt = MIO283QT9A_COLORFMT; /* Color format: RGB16-565: RRRR RGGG GGGB BBBB */
vinfo->xres = MIO283QT9A_XRES; /* Horizontal resolution in pixel columns */
vinfo->yres = MIO283QT9A_YRES; /* Vertical resolution in pixel rows */
vinfo->nplanes = 1; /* Number of color planes supported */
return OK;
}
/**************************************************************************************
* Name: mio283qt9a_getplaneinfo
*
* Description:
* Get information about the configuration of each LCD color plane.
*
**************************************************************************************/
static int mio283qt9a_getplaneinfo(FAR struct lcd_dev_s *dev, unsigned int planeno,
FAR struct lcd_planeinfo_s *pinfo)
{
FAR struct mio283qt9a_dev_s *priv = (FAR struct mio283qt9a_dev_s *)dev;
DEBUGASSERT(dev && pinfo && planeno == 0);
lcdvdbg("planeno: %d bpp: %d\n", planeno, MIO283QT9A_BPP);
pinfo->putrun = mio283qt9a_putrun; /* Put a run into LCD memory */
pinfo->getrun = mio283qt9a_getrun; /* Get a run from LCD memory */
pinfo->buffer = (uint8_t*)priv->runbuffer; /* Run scratch buffer */
pinfo->bpp = MIO283QT9A_BPP; /* Bits-per-pixel */
return OK;
}
/**************************************************************************************
* Name: mio283qt9a_getpower
*
* Description:
* Get the LCD panel power status (0: full off - CONFIG_LCD_MAXPOWER: full on). On
* backlit LCDs, this setting may correspond to the backlight setting.
*
**************************************************************************************/
static int mio283qt9a_getpower(FAR struct lcd_dev_s *dev)
{
lcdvdbg("getpower: %d\n", 0);
return g_lcddev.power;
}
/**************************************************************************************
* Name: mio283qt9a_poweroff
*
* Description:
* Enable/disable LCD panel power (0: full off - CONFIG_LCD_MAXPOWER: full on). On
* backlit LCDs, this setting may correspond to the backlight setting.
*
**************************************************************************************/
static int mio283qt9a_poweroff(FAR struct mio283qt9a_lcd_s *lcd)
{
/* Select the LCD */
lcdvdbg("mio283qt9a_poweroff\n");
lcd->select(lcd);
/* Set the backlight off */
lcd->backlight(lcd, 0);
/* Turn the display off */
mio283qt9a_putreg(lcd, 0x28, 0x0000); /* GON=0, DTE=0, D=0 */
/* Deselect the LCD */
lcd->deselect(lcd);
/* Remember the power off state */
g_lcddev.power = 0;
return OK;
}
/**************************************************************************************
* Name: mio283qt9a_setpower
*
* Description:
* Enable/disable LCD panel power (0: full off - CONFIG_LCD_MAXPOWER: full on). On
* backlit LCDs, this setting may correspond to the backlight setting.
*
**************************************************************************************/
static int mio283qt9a_setpower(FAR struct lcd_dev_s *dev, int power)
{
FAR struct mio283qt9a_dev_s *priv = (FAR struct mio283qt9a_dev_s *)dev;
FAR struct mio283qt9a_lcd_s *lcd = priv->lcd;
lcdvdbg("setpower: %d\n", power);
DEBUGASSERT((unsigned)power <= CONFIG_LCD_MAXPOWER);
/* Set new power level */
if (power > 0)
{
/* Select the LCD */
lcd->select(lcd);
/* Set the backlight level */
lcd->backlight(lcd, power);
/* Then turn the display on: */
mio283qt9a_putreg(lcd, 0x29, 0x00); /* GON=1, DTE=1, D=2 */
/* Deselect the LCD */
lcd->deselect(lcd);
/* Remember the power on state */
g_lcddev.power = power;
}
else
{
/* Turn the display off */
mio283qt9a_poweroff(lcd);
}
return OK;
}
/**************************************************************************************
* Name: mio283qt9a_getcontrast
*
* Description:
* Get the current contrast setting (0-CONFIG_LCD_MAXCONTRAST).
*
**************************************************************************************/
static int mio283qt9a_getcontrast(FAR struct lcd_dev_s *dev)
{
lcdvdbg("Not implemented\n");
return -ENOSYS;
}
/**************************************************************************************
* Name: mio283qt9a_setcontrast
*
* Description:
* Set LCD panel contrast (0-CONFIG_LCD_MAXCONTRAST).
*
**************************************************************************************/
static int mio283qt9a_setcontrast(FAR struct lcd_dev_s *dev, unsigned int contrast)
{
lcdvdbg("contrast: %d\n", contrast);
return -ENOSYS;
}
/**************************************************************************************
* Name: mio283qt9a_hwinitialize
*
* Description:
* Initialize the LCD hardware.
*
**************************************************************************************/
static inline int mio283qt9a_hwinitialize(FAR struct mio283qt9a_dev_s *priv)
{
FAR struct mio283qt9a_lcd_s *lcd = priv->lcd;
#ifndef CONFIG_LCD_NOGETRUN
uint16_t id_a;
uint16_t id_b;
uint16_t id_c;
uint16_t id_d;
uint16_t id_e;
#endif
int ret;
/* Select the LCD */
lcd->select(lcd);
/* Read the HIMAX ID registger (0x00) */
#ifndef CONFIG_LCD_NOGETRUN
id_a = mio283qt9a_readreg(lcd, 0xd3);
id_b = lcd->read(lcd);
id_c = lcd->read(lcd);
id_d = lcd->read(lcd);
lcdvdbg("LCD ID: %04x %04x %04x %04x\n", id_a, id_b, id_c, id_d);
/* Check if the ID is for the ILI9341 */
if (id_c == ILI9341_ID_1 && id_d == ILI9341_ID_2)
#endif
{
mio283qt9a_putreg(lcd, 0x29, 0); /* Power on */
mio283qt9a_putreg(lcd, 0x13, 0); /* Normal display on */
mio283qt9a_putreg(lcd, 0xc0, 0x28); /* Power control C1 */
mio283qt9a_putreg(lcd, 0xc1, 0x01); /* Power control C2 BT = 1 */
mio283qt9a_putreg(lcd, 0xc5, 0x24); /* VCOM control, VMH = 3.6v */
lcd->write(lcd, 0x25); /* VML = -1.575v */
mio283qt9a_putreg(lcd, 0x26, 0x01); /* Gamma 2.2 */
mio283qt9a_putreg(lcd, 0x3a, 0x55); /* Pixel format set command */
#if defined(CONFIG_LCD_LANDSCAPE)
mio283qt9a_putreg(lcd, 0x36, 0x0028); /* MY=1, MX=0, MV=1, ML=0, BGR=1 */
#elif defined(CONFIG_LCD_PORTRAIT)
mio283qt9a_putreg(lcd, 0x36, 0x0008); /* MY=0, MX=0, MV=0, ML=0, BGR=1 */
#elif defined(CONFIG_LCD_RLANDSCAPE)
mio283qt9a_putreg(lcd, 0x36, 0x0068); /* MY=0, MX=1, MV=1, ML=0, BGR=1 */
#elif defined(CONFIG_LCD_RPORTRAIT)
mio283qt9a_putreg(lcd, 0x36, 0x00c8); /* MY=1, MX=0, MV=1, ML=0, BGR=1 */
#endif
/* Window setting */
mio283qt9a_setarea(lcd, 0, 0, (MIO283QT9A_XRES-1), (MIO283QT9A_YRES-1));
mio283qt9a_putreg(lcd, 0x11, 0); /* Sleep out mode */
up_mdelay(25);
/* Read back some info from the panel */
id_a = mio283qt9a_readreg(lcd, 0x04); /* Read display information */
id_b = lcd->read(lcd);
id_c = lcd->read(lcd);
id_d = lcd->read(lcd);
lcdvdbg("LCD man ID: %02x, version: %02x, driver ID: %02x\n", id_b, id_c, id_d);
id_a = mio283qt9a_readreg(lcd, 0x09); /* Read display status */
id_b = lcd->read(lcd);
id_c = lcd->read(lcd);
id_d = lcd->read(lcd);
id_e = lcd->read(lcd);
lcdvdbg("Display status %02x, %02x, %02x, %02x, %02x\n", id_a, id_b, id_c, id_d, id_e);
id_a = mio283qt9a_readreg(lcd, 0x0a); /* Read power status */
id_b = lcd->read(lcd);
lcdvdbg("Power status %02x, %02x\n", id_a, id_b);
id_a = mio283qt9a_readreg(lcd, 0x0b); /* Read MADCTL */
id_b = lcd->read(lcd);
lcdvdbg("MADCTL %02x, %02x\n", id_a, id_b);
id_a = mio283qt9a_readreg(lcd, 0x0c); /* Read pixel format */
id_b = lcd->read(lcd);
lcdvdbg("Pixel format %02x, %02x\n", id_a, id_b);
id_a = mio283qt9a_readreg(lcd, 0x0d); /* Read image format */
id_b = lcd->read(lcd);
lcdvdbg("Image format %02x, %02x\n", id_a, id_b);
id_a = mio283qt9a_readreg(lcd, 0x0e); /* read signal mode */
id_b = lcd->read(lcd);
lcdvdbg("Signal mode %02x, %02x\n", id_a, id_b);
id_a = mio283qt9a_readreg(lcd, 0x0f); /* read self diag */
id_b = lcd->read(lcd);
lcdvdbg("Self diag %02x, %02x\n", id_a, id_b);
ret = OK;
}
#ifndef CONFIG_LCD_NOGETRUN
else
{
lcddbg("Unsupported LCD type\n");
ret = -ENODEV;
}
#endif
/* De-select the LCD */
lcd->deselect(lcd);
return ret;
}
/*************************************************************************************
* Public Functions
**************************************************************************************/
/**************************************************************************************
* Name: mio283qt9a_lcdinitialize
*
* Description:
* Initialize the LCD video hardware. The initial state of the LCD is fully
* initialized, display memory cleared, and the LCD ready to use, but with the power
* setting at 0 (full off).
*
**************************************************************************************/
FAR struct lcd_dev_s *mio283qt9a_lcdinitialize(FAR struct mio283qt9a_lcd_s *lcd)
{
FAR struct mio283qt9a_dev_s *priv;
int ret;
lcdvdbg("Initializing\n");
/* If we could support multiple MIO283QT9A devices, this is where we would allocate
* a new driver data structure... but we can't. Why not? Because of a bad should
* the form of the getrun() and putrun methods.
*/
priv = &g_lcddev;
/* Initialize the driver data structure */
priv->dev.getvideoinfo = mio283qt9a_getvideoinfo;
priv->dev.getplaneinfo = mio283qt9a_getplaneinfo;
priv->dev.getpower = mio283qt9a_getpower;
priv->dev.setpower = mio283qt9a_setpower;
priv->dev.getcontrast = mio283qt9a_getcontrast;
priv->dev.setcontrast = mio283qt9a_setcontrast;
priv->lcd = lcd;
/* Configure and enable LCD */
ret = mio283qt9a_hwinitialize(priv);
if (ret == OK)
{
/* Clear the display (setting it to the color 0=black) */
mio283qt9a_clear(&priv->dev, 0x0000);
/* Turn the display off */
mio283qt9a_poweroff(lcd);
return &g_lcddev.dev;
}
return NULL;
}
/**************************************************************************************
* Name: mio283qt9a_clear
*
* Description:
* This is a non-standard LCD interface just for the stm3240g-EVAL board. Because
* of the various rotations, clearing the display in the normal way by writing a
* sequences of runs that covers the entire display can be very slow. Here the
* display is cleared by simply setting all GRAM memory to the specified color.
*
**************************************************************************************/
void mio283qt9a_clear(FAR struct lcd_dev_s *dev, uint16_t color)
{
FAR struct mio283qt9a_dev_s *priv = (FAR struct mio283qt9a_dev_s *)dev;
FAR struct mio283qt9a_lcd_s *lcd = priv->lcd;
uint32_t i;
/* Select the LCD and set the drawring area */
lcd->select(lcd);
mio283qt9a_setarea(lcd, 0, 0, (MIO283QT9A_XRES-1), (MIO283QT9A_YRES-1));
/* Prepare to write GRAM data */
mio283qt9a_gramselect(lcd);
/* Copy color into all of GRAM. Orientation does not matter in this case. */
for (i = 0; i < MIO283QT9A_XRES * MIO283QT9A_YRES; i++)
{
mio283qt9a_gramwrite(lcd, color);
}
/* De-select the LCD */
lcd->deselect(lcd);
}
#endif /* CONFIG_LCD_MIO283QT9A */

View File

@ -0,0 +1,150 @@
/**************************************************************************************
* include/nuttx/lcd/mio283qt9a.h
*
* Interface definition for the MI0283QT-9A LCD from Multi-Inno Technology Co., Ltd.
* This LCD is based on the Ilitek ILI9341 LCD controller.
* Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************************/
#ifndef __INCLUDE_NUTTX_LCD_MIO283QT9A_H
#define __INCLUDE_NUTTX_LCD_MIO283QT9A_H
/**************************************************************************************
* Included Files
**************************************************************************************/
#include <nuttx/config.h>
#ifdef CONFIG_LCD_MIO283QT9A
/**************************************************************************************
* Pre-processor Definitions
**************************************************************************************/
/* Configuration **********************************************************************/
/* CONFIG_LCD_MIO283QT9A - Enables support for the MIO283QT2-based LCD.
* CONFIG_LCD_NOGETRUN
* NX components need to know if it can read from the LCD or not. If reading from the
* LCD is supported then some graphic operations can be improved. Default: Supported
* CONFIG_LCD_LANDSCAPE - Define for 320x240 display "landscape" support. Default is
* this 320x240 "landscape" orientation.
* CONFIG_LCD_RLANDSCAPE - Define for 320x240 display "reverse landscape" support.
* Default is this 320x240 "landscape" orientation
* CONFIG_LCD_PORTRAIT - Define for 240x320 display "portrait" orientation support.
* Default is this 320x240 "landscape" orientation
* CONFIG_LCD_RPORTRAIT - Define for 240x320 display "reverse portrait" orientation
* support. Default is this 320x240 "landscape" orientation
*/
/**************************************************************************************
* Public Types
**************************************************************************************/
/* This structure defines the interface to the LCD provided by the platform. The
* nature of this interface is hidden from the MIO283QT2 driver.
*/
struct mio283qt9a_lcd_s
{
/* Interface to write to a MIO283QT2 register.
*
* - select Select the device (as necessary). The meaning of selecting (and
* and deselecting) is not defined. select() will be called before
* starting any sequence of operations. deselect() when that sequence
* of operations is complete.
* - deselect Deselect the device (as necessary)
* - index Set register index
* - read Read data from the LCD (auto-incrementing)
* - write Write data to the LCD (auto-incrementing)
* - backlight Set the backlight power level (0=OFF; CONFIG_LCD_MAXPOWER=MAX)
*/
void (*select)(FAR struct mio283qt9a_lcd_s *dev);
void (*deselect)(FAR struct mio283qt9a_lcd_s *dev);
void (*index)(FAR struct mio283qt9a_lcd_s *dev, uint8_t index);
#ifndef CONFIG_LCD_NOGETRUN
uint16_t (*read)(FAR struct mio283qt9a_lcd_s *dev);
#endif
void (*write)(FAR struct mio283qt9a_lcd_s *dev, uint16_t value);
void (*backlight)(FAR struct mio283qt9a_lcd_s *dev, int power);
/* platform-specific data may follow */
};
/**************************************************************************************
* Public Data
**************************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/**************************************************************************************
* Public Function Prototypes
**************************************************************************************/
/**************************************************************************************
* Name: mio283qt2_lcdinitialize
*
* Description:
* Initialize the LCD video hardware. The initial state of the LCD is fully
* initialized, display memory cleared, and the LCD ready to use, but with the power
* setting at 0 (full off).
*
**************************************************************************************/
FAR struct lcd_dev_s *mio283qt2_lcdinitialize(FAR struct mio283qt9a_lcd_s *lcd);
/**************************************************************************************
* Name: mio283qt2_clear
*
* Description:
* This is a non-standard LCD interface. Because of the various rotations, clearing
* the display in the normal way by writing a sequences of runs that covers the
* entire display can be very slow. Here the display is cleared by simply setting
* all GRAM memory to the specified color.
*
**************************************************************************************/
void mio283qt2_clear(FAR struct lcd_dev_s *dev, uint16_t color);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_LCD_MIO283QT9A */
#endif /* __INCLUDE_NUTTX_LCD_MIO283QT9A_H */