// ----------------------------------------------------------------------------------------
//
//  avr/lcd/sfe569/sfe569.h
//    
//  Bob Cook Development, Robotics Library
//  http://www.bobcookdev.com/rl/
//    
//  This file implements support for the SparkFun 128x128 Color LCD (#LCD-000569).
//
//  Copyright (C) 2007 Bob Cook
//
//      This program is free software; you can redistribute it and/or modify it
//      under the terms of the GNU General Public License as published by the
//      Free Software Foundation; either version 2 of the License, or (at your
//      option) any later version.
//    
//      This program is distributed in the hope that it will be useful, but 
//      WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
//      or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
//      for more details.
//    
//      You should have received a copy of the GNU General Public License along
//      with this program; if not, write to the Free Software Foundation, Inc., 
//      51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
// ----------------------------------------------------------------------------------------


#if !defined( BCDRL_AVR_SFE569_H )
#define BCDRL_AVR_SFE569_H


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


// ----------------------------------------------------------------------------------------
//  definitions from "project_defs.h"
//
//  enable support for the SFE 128x128 Color LCD with:
//
//      + PRJ_SFE569_ENABLE
//
//  specify the serial clock pin with:
//
//      + PRJ_SFE569_CLOCK_PORT
//      + PRJ_SFE569_CLOCK_PIN
//      + PRJ_SFE569_CLOCK_DDR
//
//  specify the serial data pin with:
//
//      + PRJ_SFE569_DATA_PORT
//      + PRJ_SFE569_DATA_PIN
//      + PRJ_SFE569_DATA_DDR
//
//  specify the chip select pin with:
//
//      + PRJ_SFE569_SELECT_PORT
//      + PRJ_SFE569_SELECT_PIN
//      + PRJ_SFE569_SELECT_DDR
//
//  specify the RESET pin with:
//
//      + PRJ_SFE569_RESET_PORT
//      + PRJ_SFE569_RESET_PIN
//      + PRJ_SFE569_RESET_DDR
//
//  optional features can be enabled with one or more of the following:
//
//      + PRJ_SFE569_INC_WRITE_CHAR
//      + PRJ_SFE569_INC_WRITE_CSTRINGS
//      + PRJ_SFE569_INC_WRITE_PGM_CSTRINGS
//      + PRJ_SFE569_INC_SET_PIXEL
//      + PRJ_SFE569_INC_DRAWING
//      + PRJ_SFE569_INC_IMAGEMASK
//      + PRJ_SFE569_INC_COLORIMAGE
//
// ----------------------------------------------------------------------------------------


// ----------------------------------------------------------------------------------------
//  sfe569_color_t
//
//      The display driver uses 8-bit color values, packed as: RRRGGGBB
//

typedef uint8_t sfe569_color_t;

const sfe569_color_t sfe569_color_black   = 0x00;
const sfe569_color_t sfe569_color_white   = 0xff;
const sfe569_color_t sfe569_color_red     = 0xe0;
const sfe569_color_t sfe569_color_green   = 0x1c;
const sfe569_color_t sfe569_color_blue    = 0x03;
const sfe569_color_t sfe569_color_cyan    = 0x1f;
const sfe569_color_t sfe569_color_magenta = 0xe3;
const sfe569_color_t sfe569_color_yellow  = 0xfc;
const sfe569_color_t sfe569_color_brown   = 0xa5;
const sfe569_color_t sfe569_color_orange  = 0xf4;
const sfe569_color_t sfe569_color_pink    = 0xee;


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

void sfe569_init();


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

void sfe569_fill_screen( sfe569_color_t color );


// ----------------------------------------------------------------------------------------
//  sfe569_write
//
//      Write a character to the display in the *character* row and column. The display
//      can support 16 rows by 21 columns.
//
//      This function is only available if PRJ_SFE569_INC_WRITE_CHAR is defined.
//

void sfe569_write
    (
        char           c, 
        uint8_t        x, 
        uint8_t        y, 
        sfe569_color_t fg_color,
        sfe569_color_t bg_color 
    );


// ----------------------------------------------------------------------------------------
//  sfe569_write
//
//      Write a string to the display in the *character* row and column. The display
//      can support 16 rows by 21 columns.
//
//      This function is only available if PRJ_SFE569_INC_WRITE_CSTRINGS is defined.
//

void sfe569_write
    ( 
        const char*    str, 
        uint8_t        x, 
        uint8_t        y, 
        sfe569_color_t fg_color,
        sfe569_color_t bg_color 
    );


// ----------------------------------------------------------------------------------------
//  sfe569_write_pgm
//
//      Write a string from flash memory to the display in the *character* row and column.
//      The display can support 16 rows by 21 columns.
//
//      This function is only available if PRJ_SFE569_INC_WRITE_PGM_CSTRINGS is defined.
//

void sfe569_write_pgm
    ( 
        const prog_char* str, 
        uint8_t          x, 
        uint8_t          y, 
        sfe569_color_t   fg_color,
        sfe569_color_t   bg_color 
    );


// ----------------------------------------------------------------------------------------
//  sfe569_set_pixel
//
//      Paint a specific pixel. The display supports 128 rows by 128 columns.
//
//      This function is only available if PRJ_SFE569_INC_SET_PIXEL is defined.
//

void sfe569_set_pixel( uint8_t x, uint8_t y, sfe569_color_t color );


// ----------------------------------------------------------------------------------------
//  sfe569_line_h
//
//      Paint a row of pixels.
//
//      This function is only available if PRJ_SFE569_INC_DRAWING is defined.
//

void sfe569_line_h( uint8_t x, uint8_t y, uint8_t len, bool state );


// ----------------------------------------------------------------------------------------
//  sfe569_line_v
//
//      Paint a column of pixels.
//
//      This function is only available if PRJ_SFE569_INC_DRAWING is defined.
//

void sfe569_line_v( uint8_t x, uint8_t y, uint8_t len, bool state );


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

void sfe569_rect( uint8_t x, uint8_t y, uint8_t w, uint8_t h, sfe569_color_t color );


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

void sfe569_fill( uint8_t x, uint8_t y, uint8_t w, uint8_t h, sfe569_color_t color );


// ----------------------------------------------------------------------------------------
//  sfe569_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 (sfe569_line_h, sfe569_line_v) for those cases when possible.
//
//      This function is only available if PRJ_SFE569_INC_DRAWING is defined.
//

void sfe569_line( uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, sfe569_color_t color );


// ----------------------------------------------------------------------------------------
//  sfe569_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_SFE569_INC_IMAGEMASK is defined.
//

void sfe569_imagemask
    (
        uint8_t             x,
        uint8_t             y,
        uint8_t             w,
        uint8_t             h,
        sfe569_color_t      fg_color,
        sfe569_color_t      bg_color,
        const prog_uint8_t* pixels
    );


// ----------------------------------------------------------------------------------------
//  sfe569_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 8-bit format: RRRGGGBB.
//
//      This function is only available if PRJ_SFE569_INC_COLORIMAGE is defined.
//

void sfe569_colorimage
    (
        uint8_t x,
        uint8_t y,
        uint8_t w,
        uint8_t h,
        const prog_uint8_t* pixels
    );


#endif  // #if !defined( BCDRL_AVR_SFE569_H )
// ----------------------------------------------------------------------------------------
//  end of sfe569.h
// ----------------------------------------------------------------------------------------

