📄 Ȧ-
字号:
//*****************************************************************************
//
// formike240x320x16_ili9320.c - Display driver for the Formike Electronic
// KWH028Q02-F03 TFT panel with an ILI9320
// controller.
//
// Copyright (c) 2008 Luminary Micro, Inc. All rights reserved.
//
// Software License Agreement
//
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
// exclusively on LMI's microcontroller products.
//
// The software is owned by LMI and/or its suppliers, and is protected under
// applicable copyright laws. All rights are reserved. You may not combine
// this software with "viral" open-source software in order to form a larger
// program. Any use in violation of the foregoing restrictions may subject
// the user to criminal sanctions under applicable laws, as well as to civil
// liability for the breach of the terms and conditions of this license.
//
// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 2293 of the Stellaris Peripheral Driver Library.
//
//*****************************************************************************
#include "formike240x320x16_ili9320.h"
#include "..\Hz16\hz16.h"
//*****************************************************************************
//
// This driver operates in four different screen orientations. They are:
//
// * Portrait - The screen is taller than it is wide, and the flex connector is
// on the bottom of the display. This is selected by defining
// PORTRAIT.
//
// * Landscape - The screen is wider than it is tall, and the flex connector is
// on the right side of the display. This is selected by
// defining LANDSCAPE.
//
// * Portrait flip - The screen is taller than it is wide, and the flex
// connector is on the top of the display. This is selected
// by defining PORTRAIT_FLIP.
//
// * Landscape flip - The screen is wider than it is tall, and the flex
// connector is on the left side of the display. This is
// selected by defining LANDSCAPE_FLIP.
//
// These can also be imagined in terms of screen rotation; if portrait mode is
// 0 degrees of screen rotation, landscape is 90 degrees of counter-clockwise
// rotation, portrait flip is 180 degrees of rotation, and landscape flip is
// 270 degress of counter-clockwise rotation.
//
// If no screen orientation is selected, portrait mode will be used.
//
//*****************************************************************************
#if ! defined(PORTRAIT) && ! defined(PORTRAIT_FLIP) && \
! defined(LANDSCAPE) && ! defined(LANDSCAPE_FLIP)
#define PORTRAIT
#endif
//*****************************************************************************
//
// Defines for the pins that are used to communicate with the ILI9320.
//
//*****************************************************************************
#define LCD_RST_BASE GPIO_PORTG_BASE
#define LCD_RST_PIN GPIO_PIN_0
#define LCD_DATAH_BASE GPIO_PORTA_BASE
#define LCD_DATAL_BASE GPIO_PORTB_BASE
#define LCD_RS_BASE GPIO_PORTF_BASE
#define LCD_RS_PIN GPIO_PIN_2
#define LCD_RD_BASE GPIO_PORTF_BASE
#define LCD_RD_PIN GPIO_PIN_0
#define LCD_WR_BASE GPIO_PORTF_BASE
#define LCD_WR_PIN GPIO_PIN_1
#define LCD_BL_BASE GPIO_PORTC_BASE
#define LCD_BL_PIN GPIO_PIN_6
//*****************************************************************************
//
// Translates a 24-bit RGB color to a display driver-specific color.
//
// \param c is the 24-bit RGB color. The least-significant byte is the blue
// channel, the next byte is the green channel, and the third byte is the red
// channel.
//
// This macro translates a 24-bit RGB color into a value that can be written
// into the display's frame buffer in order to reproduce that color, or the
// closest possible approximation of that color.
//
// \return Returns the display-driver specific color.
//
//*****************************************************************************
#define DPYCOLORTRANSLATE(c) ((((c) & 0x00ff0000) >> 19) | \
((((c) & 0x0000ff00) >> 5) & 0x000007e0) | \
((((c) & 0x000000ff) << 8) & 0x0000f800))
//*****************************************************************************
//
// Writes a data word to the ILI9320.
//
//*****************************************************************************
void WriteData(unsigned short usData)
{
//
// Write the data to the data bus.
//
HWREG(LCD_DATAH_BASE + GPIO_O_DATA + (0xff << 2)) = usData >> 8;
HWREG(LCD_DATAL_BASE + GPIO_O_DATA + (0xff << 2)) = usData;
//
// Assert the write enable signal.
//
HWREG(LCD_WR_BASE + GPIO_O_DATA + (LCD_WR_PIN << 2)) = 0;
//
// Deassert the write enable signal.
//
HWREG(LCD_WR_BASE + GPIO_O_DATA + (LCD_WR_PIN << 2)) = LCD_WR_PIN;
}
//*****************************************************************************
//
// Writes a command to the ILI9320.
//
//*****************************************************************************
void WriteCommand(unsigned char ucData)
{
//
// Write the command to the data bus.
//
HWREG(LCD_DATAH_BASE + GPIO_O_DATA + (0xff << 2)) = 0x00;
HWREG(LCD_DATAL_BASE + GPIO_O_DATA + (0xff << 2)) = ucData;
//
// Set the RS signal low, indicating a command.
//
HWREG(LCD_RS_BASE + GPIO_O_DATA + (LCD_RS_PIN << 2)) = 0;
//
// Assert the write enable signal.
//
HWREG(LCD_WR_BASE + GPIO_O_DATA + (LCD_WR_PIN << 2)) = 0;
//
// Deassert the write enable signal.
//
HWREG(LCD_WR_BASE + GPIO_O_DATA + (LCD_WR_PIN << 2)) = LCD_WR_PIN;
//
// Set the RS signal high, indicating that following writes are data.
//
HWREG(LCD_RS_BASE + GPIO_O_DATA + (LCD_RS_PIN << 2)) = LCD_RS_PIN;
}
//*****************************************************************************
//
//! Initializes the display driver.
//!
//! This function initializes the ILI9320 display controller on the panel,
//! preparing it to display data.
//!
//! \return None.
//
//*****************************************************************************
void Formike240x320x16_ILI9320Init(void)
{
unsigned long ulClockMS, ulCount;
//
// Get the current processor clock frequency.
//
ulClockMS = SysCtlClockGet() / (3 * 1000);
//
// Enable the GPIO peripherals used to interface to the ILI9320.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
//
// Convert the PB7/TRST pin into a GPIO pin. This requires the use of the
// GPIO lock since changing the state of the pin is otherwise disabled.
//
HWREG(GPIO_PORTB_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTB_BASE + GPIO_O_CR) = 0x80;
HWREG(GPIO_PORTB_BASE + GPIO_O_AFSEL) &= ~0x80;
HWREG(GPIO_PORTB_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTB_BASE + GPIO_O_CR) = 0x00;
HWREG(GPIO_PORTB_BASE + GPIO_O_LOCK) = 0;
//
// Configure the pins that connect to the LCD as GPIO outputs.
//
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, 0xff);
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, 0xff);
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, 0x40);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, 0x07);
GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, 0x01);
//
// Set the LCD control pins to their default values. This also asserts the
// LCD reset signal.
//
GPIOPinWrite(GPIO_PORTA_BASE, 0xff, 0x00);
GPIOPinWrite(GPIO_PORTB_BASE, 0xff, 0x00);
GPIOPinWrite(GPIO_PORTC_BASE, 0x40, 0x00);
GPIOPinWrite(GPIO_PORTF_BASE, 0x07, 0x03);
GPIOPinWrite(GPIO_PORTG_BASE, 0x01, 0x00);
//
// Delay for 1ms.
//
SysCtlDelay(ulClockMS);
//
// Deassert the LCD reset signal.
//
GPIOPinWrite(LCD_RST_BASE, LCD_RST_PIN, LCD_RST_PIN);
//
// Delay for 1ms while the LCD comes out of reset.
//
SysCtlDelay(ulClockMS);
//
// Enable the oscillator.
//
WriteCommand(0x00);
WriteData(0x0001);
//
// Delay for 10ms while the oscillator stabilizes.
//
SysCtlDelay(10 * ulClockMS);
//
// Configure and enable the LCD power supply.
//
WriteCommand(0x11);
WriteData(0x0037);
WriteCommand(0x29);
WriteData(0x000F);
WriteCommand(0x13);
WriteData(0x1A00);
WriteCommand(0x10);
WriteData(0x00B0);
WriteCommand(0x12);
WriteData(0x011E);
//
// Delay for 40ms while the power supply stabilizes.
//
SysCtlDelay(40 * ulClockMS);
//
// Finish configuring the LCD power supply.
//
WriteCommand(0x10);
WriteData(0x06B0);
//
// Configure the output drivers.
//
WriteCommand(0x01);
WriteData(0x0100);
//
// Configure the LCD A/C drive waveform.
//
WriteCommand(0x02);
WriteData(0x0700);
//
// Set the number of lines to scan.
//
WriteCommand(0x60);
WriteData(0x2700);
//
// Enable grayscale inversion of the source outputs.
//
WriteCommand(0x61);
WriteData(0x0001);
//
// Clear the contents of the display buffer.
//
WriteCommand(0x22);
for(ulCount = 0; ulCount < (320 * 240); ulCount++)
{
WriteData(0x0000);
}
//
// Enable the source drivers.
//
WriteCommand(0x10);
WriteData(0x16B0);
//
// Enable internal operation of the LCD controller.
//
WriteCommand(0x07);
WriteData(0011);
//
// Delay for 20ms, which is equivalent to two frames.
//
SysCtlDelay(20 * ulClockMS);
//
// Enable the image display.
//
WriteCommand(0x07);
WriteData(0x0133);
//
// Delay for 20ms, which is equivalent to two frames.
//
SysCtlDelay(20 * ulClockMS);
}
//*****************************************************************************
//
//! Turns on the backlight.
//!
//! This function turns on the backlight on the display.
//!
//! \return None.
//
//*****************************************************************************
void Formike240x320x16_ILI9320BacklightOn(void)
{
//
// Assert the signal that turns on the backlight.
//
HWREG(LCD_BL_BASE + GPIO_O_DATA + (LCD_BL_PIN << 2)) = LCD_BL_PIN;
}
//*****************************************************************************
//
//! Turns off the backlight.
//!
//! This function turns off the backlight on the display.
//!
//! \return None.
//
//*****************************************************************************
void Formike240x320x16_ILI9320BacklightOff(void)
{
//
// Deassert the signal that turns on the backlight.
//
HWREG(LCD_BL_BASE + GPIO_O_DATA + (LCD_BL_PIN << 2)) = 0;
}
//*****************************************************************************
//
//! Draws a pixel on the screen.
//!
//! \param pvDisplayData is a pointer to the driver-specific data for this
//! display driver.
//! \param lX is the X coordinate of the pixel.
//! \param lY is the Y coordinate of the pixel.
//! \param ulValue is the color of the pixel.
//!
//! This function sets the given pixel to a particular color. The coordinates
//! of the pixel are assumed to be within the extents of the display.
//!
//! \return None.
//
//*****************************************************************************
void Formike240x320x16_ILI9320PixelDraw(void *pvDisplayData, long lX, long lY,
unsigned long ulValue)
{
//
// Set the X address of the display cursor.
//
WriteCommand(0x20);
#ifdef PORTRAIT
WriteData(lX);
#endif
#ifdef LANDSCAPE
WriteData(239 - lY);
#endif
#ifdef PORTRAIT_FLIP
WriteData(239 - lX);
#endif
#ifdef LANDSCAPE_FLIP
WriteData(lY);
#endif
//
// Set the Y address of the display cursor.
//
WriteCommand(0x21);
#ifdef PORTRAIT
WriteData(lY);
#endif
#ifdef LANDSCAPE
WriteData(lX);
#endif
#ifdef PORTRAIT_FLIP
WriteData(319 - lY);
#endif
#ifdef LANDSCAPE_FLIP
WriteData(319 - lX);
#endif
//
// Write the pixel value.
//
WriteCommand(0x22);
WriteData(ulValue);//发送颜色
}
//*****************************************************************************
//
//! Draws a horizontal sequence of pixels on the screen.
//!
//! \param pvDisplayData is a pointer to the driver-specific data for this
//! display driver.
//! \param lX is the X coordinate of the first pixel.
//! \param lY is the Y coordinate of the first pixel.
//! \param lX0 is sub-pixel offset within the pixel data, which is valid for 1
//! or 4 bit per pixel formats.
//! \param lCount is the number of pixels to draw.
//! \param lBPP is the number of bits per pixel; must be 1, 4, or 8.
//! \param pucData is a pointer to the pixel data. For 1 and 4 bit per pixel
//! formats, the most significant bit(s) represent the left-most pixel.
//! \param pucPalette is a pointer to the palette used to draw the pixels.
//!
//! This function draws a horizontal sequence of pixels on the screen, using
//! the supplied palette. For 1 bit per pixel format, the palette contains
//! pre-translated colors; for 4 and 8 bit per pixel formats, the palette
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -