view main/packages/avr/lcd/ili9340/ili9340.h @ 220:74381e5dd204 main

Demo for the Adafruit LCD product number 1480.
author Bob Cook <bob@bobcookdev.com>
date Mon, 07 Jul 2014 18:42:15 -0700
parents 8245c6f136b5
children
line wrap: on
line source

// ----------------------------------------------------------------------------------------
//
//  avr/lcd/ili9340/ili9340.h
//    
//  Bob Cook Development, Robotics Library
//  http://www.bobcookdev.com/rl/
//    
//  This file implements support for the ILI9340 240x320 RGB LCD driver.
//
//  Copyright (C) 2014 Bob Cook
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//  
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//  
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//
// ----------------------------------------------------------------------------------------

#if !defined( BCDRL_AVR_LCD_ILI9340_H )
#define BCDRL_AVR_LCD_ILI9340_H

#include <stdint.h>
#include <avr/pgmspace.h>

// ----------------------------------------------------------------------------------------
//  definitions from "project_defs.h"
//
//  enable support for the ILI9340 240x320 RGB LCD driver with:
//
//      + PRJ_ILI9340_ENABLE
//
//  specify the SELECT pin for SPI communications with:
//
//      + PRJ_ILI9340_SELECT_PORT
//      + PRJ_ILI9340_SELECT_PIN
//      + PRJ_ILI9340_SELECT_DDR
//
//  specify the MODE pin (for setting either command or data) with:
//
//      + PRJ_ILI9340_COMMAND_PORT
//      + PRJ_ILI9340_COMMAND_PIN
//      + PRJ_ILI9340_COMMAND_DDR
//
//  specify the (optional) RESET pin with:
//
//      + PRJ_ILI9340_USE_HW_RESET
//      + PRJ_ILI9340_RESET_PORT
//      + PRJ_ILI9340_RESET_PIN
//      + PRJ_ILI9340_RESET_DDR
//
//  specify the orientation with one (and only one) of the following:
//
//      + PRJ_ILI9340_DISPLAY_ORIENTATION_0
//      + PRJ_ILI9340_DISPLAY_ORIENTATION_90
//      + PRJ_ILI9340_DISPLAY_ORIENTATION_180
//      + PRJ_ILI9340_DISPLAY_ORIENTATION_270
//
//  optional features can be enabled with one or more of the following:
//
//      + PRJ_ILI9340_INC_WRITE_CHAR
//      + PRJ_ILI9340_INC_WRITE_CSTRINGS
//      + PRJ_ILI9340_INC_WRITE_PGM_CSTRINGS
//      + PRJ_ILI9340_INC_SET_PIXEL
//      + PRJ_ILI9340_INC_DRAWING
//      + PRJ_ILI9340_INC_IMAGEMASK
//      + PRJ_ILI9340_INC_COLORIMAGE
//
// ----------------------------------------------------------------------------------------

// ----------------------------------------------------------------------------------------
//  ili9340_color_t
//
//      The display driver uses 16-bit color values, packed as: RRRRRGGGGGGBBBBB (5-6-5)
//

typedef uint16_t ili9340_color_t;

const ili9340_color_t ili9340_color_black   = 0x0000;
const ili9340_color_t ili9340_color_white   = 0xffff;
const ili9340_color_t ili9340_color_red     = 0xf800;
const ili9340_color_t ili9340_color_green   = 0x07e0;
const ili9340_color_t ili9340_color_blue    = 0x001f;
const ili9340_color_t ili9340_color_cyan    = 0x07ff;
const ili9340_color_t ili9340_color_magenta = 0xf81f;
const ili9340_color_t ili9340_color_yellow  = 0xffe0;

// ----------------------------------------------------------------------------------------
//  ili9340_init
//
//      Initialize the ILI9340 LCD driver package, setting up the hardware and clearing
//      the display. Call this function prior to any other.
//

void ili9340_init();

// ----------------------------------------------------------------------------------------
//  ili9340_reset
//
//      Reset the display, using the hardware reset line if available. Otherwise uses
//      the software reset command.
//

void ili9340_reset();

// ----------------------------------------------------------------------------------------
//  ili9340_fill_screen
//
//      Fill the entire screen with the specified color. Use this function to erase the
//      screen by filling it with "ili9340_color_black".
//

void ili9340_fill_screen( ili9340_color_t color );

// ----------------------------------------------------------------------------------------
//  ili9340_write
//
//      Write a character to the display in the *character* row and column. The maximum
//      number of characters depends on the orientation:
//      
//          horizontal: 40 characters wide x 20 characters high
//          vertical:   30 characters wide x 26 characters high
//
//      This function is only available if PRJ_ILI9340_INC_WRITE_CHAR is defined.
//

void ili9340_write
    (
        char           c, 
        uint8_t        x, 
        uint8_t        y, 
        ili9340_color_t fg_color,
        ili9340_color_t bg_color 
    );

// ----------------------------------------------------------------------------------------
//  ili9340_write
//
//      Write a string to the display in the *character* row and column.
//
//      This function is only available if PRJ_ILI9340_INC_WRITE_CSTRINGS is defined.
//

void ili9340_write
    ( 
        const char*    str, 
        uint8_t        x, 
        uint8_t        y, 
        ili9340_color_t fg_color,
        ili9340_color_t bg_color 
    );

// ----------------------------------------------------------------------------------------
//  ili9340_write_pgm
//
//      Write a string from flash memory to the display in the *character* row and column.
//
//      This function is only available if PRJ_ILI9340_INC_WRITE_PGM_CSTRINGS is defined.
//

void ili9340_write_pgm
    ( 
        const prog_char* str, 
        uint8_t          x, 
        uint8_t          y, 
        ili9340_color_t   fg_color,
        ili9340_color_t   bg_color 
    );

// ----------------------------------------------------------------------------------------
//  ili9340_set_pixel
//
//      Paint a specific pixel.
//
//      This function is only available if PRJ_ILI9340_INC_SET_PIXEL is defined.
//

void ili9340_set_pixel( uint16_t x, uint16_t y, ili9340_color_t color );

// ----------------------------------------------------------------------------------------
//  ili9340_line_h
//
//      Paint a row of pixels.
//
//      This function is only available if PRJ_ILI9340_INC_DRAWING is defined.
//

void ili9340_line_h( uint16_t x, uint16_t y, uint16_t len, ili9340_color_t color );

// ----------------------------------------------------------------------------------------
//  ili9340_line_v
//
//      Paint a column of pixels.
//
//      This function is only available if PRJ_ILI9340_INC_DRAWING is defined.
//

void ili9340_line_v( uint16_t x, uint16_t y, uint16_t len, ili9340_color_t color );

// ----------------------------------------------------------------------------------------
//  ili9340_rect
//
//      Paint the frame (edge) pixels of a rectangular region.
//
//      This function is only available if PRJ_ILI9340_INC_DRAWING is defined.
//

void ili9340_rect( uint16_t x, uint16_t y, uint16_t w, uint16_t h, ili9340_color_t color );

// ----------------------------------------------------------------------------------------
//  ili9340_fill
//
//      Turn on all the pixels inside of a rectangular region.
//
//      This function is only available if PRJ_ILI9340_INC_DRAWING is defined.
//

void ili9340_fill( uint16_t x, uint16_t y, uint16_t w, uint16_t h, ili9340_color_t color );

// ----------------------------------------------------------------------------------------
//  ili9340_line
//
//      Turn on or off the pixels in a line between two points. This is much more
//      expensive for horizontal or vertical lines; prefer to use the optimized
//      functions (ili9340_line_h, ili9340_line_v) for those cases when possible.
//
//      This function is only available if PRJ_ILI9340_INC_DRAWING is defined.
//

void ili9340_line( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, ili9340_color_t color );

// ----------------------------------------------------------------------------------------
//  ili9340_imagemask
//
//      Paint pixels with the specified color using the 1-bit image as a mask, at the
//      specified pixel location. The pixel data must be stored in flash memory and be 
//      organized by rows, padded to whole bytes per row.
//
//      This function is only available if PRJ_ILI9340_INC_IMAGEMASK is defined.
//

void ili9340_imagemask
    (
        uint16_t            x,
        uint16_t            y,
        uint16_t            w,
        uint16_t            h,
        ili9340_color_t     fg_color,
        ili9340_color_t     bg_color,
        const prog_uint8_t* pixels
    );

// ----------------------------------------------------------------------------------------
//  ili9340_colorimage
//
//      Paint an image at the specified pixel location. The pixel data must be stored in
//      flash memory and be organized by rows, padded to an even number of bytes per row.
//      Each pixel must the 16-bit format: RRRRRGGGGGGBBBBB (5-6-5).
//
//      This function is only available if PRJ_ILI9340_INC_COLORIMAGE is defined.
//

void ili9340_colorimage
    (
        uint16_t            x,
        uint16_t            y,
        uint16_t            w,
        uint16_t            h,
        const prog_uint8_t* pixels
    );

#endif  // #if !defined( BCDRL_AVR_LCD_ILI9340_H )
// ----------------------------------------------------------------------------------------