// ----------------------------------------------------------------------------------------
//
//  packages/s3c2410a/cfax_iic/protocol.h
//    
//  Bob Cook Development, Robotics Library
//  http://www.bobcookdev.com/rl/
//    
//  This file describes an interface (data structures) to the SparkFun CFAX Graphic LCD.
//  Commands will be marshalled into these data structures and transmitted over I2C.
//
//  Copyright (C) 2009 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_S3C2410A_CFAX_IIC_PROTOCOL_H )
#define BCDRL_S3C2410A_CFAX_IIC_PROTOCOL_H


#include <stdint.h>


// ----------------------------------------------------------------------------------------
//  Pack structures tightly - the AVR platform already does this, and doesn't like the
//  compiler pragma
//

#if !defined( __AVR__ )
#pragma pack(push, 1)
#endif


// ----------------------------------------------------------------------------------------
//  All possible commands to send to the CFAX I2C slave
//

const uint8_t CFAXIIC_CMD_CLS   = 0x00;
const uint8_t CFAXIIC_CMD_TEXT  = 0x01;
const uint8_t CFAXIIC_CMD_LINE  = 0x02;
const uint8_t CFAXIIC_CMD_RECT  = 0x03;
const uint8_t CFAXIIC_CMD_FILL  = 0x04;
const uint8_t CFAXIIC_CMD_ERASE = 0x05;
const uint8_t CFAXIIC_CMD_TOUCH = 0x06;

const uint8_t CFAXIIC_RESPONSE_TOUCH = 0x40;

// ----------------------------------------------------------------------------------------
//  Structure containing all possible message parameters; it is likely useful to review
//  the file "packages/avr/lcd/cfax/cfax.h" for some explanations.
//

const uint8_t CFAXIIC_TEXT_BUF_MAX = ( 128 / 6 ); // 6 pixels / character

typedef union
{
    struct  // CFAXIIC_CMD_TEXT
    {
        uint8_t x;
        uint8_t y;
        char    text[ CFAXIIC_TEXT_BUF_MAX + 1 ];
    } text;

    struct  // CFAXIIC_CMD_LINE
    {
        uint8_t x0;
        uint8_t y0;
        uint8_t x1;
        uint8_t y1;
        bool    state; // true = pixels on
    } line;

    struct  // CFAXIIC_CMD_RECT, CFAXIIC_CMD_FILL, CFAXIIC_CMD_ERASE
    {
        uint8_t x;
        uint8_t y;
        uint8_t w;
        uint8_t h;
    } rect;

    struct  // CFAXIIC_RESPONSE_TOUCH
    {
        bool    state; // true = have a touch
        uint8_t x;
        uint8_t y;
    } touch;

} cfaxiic_data_u;

typedef struct
{
    uint8_t         command;
    cfaxiic_data_u  data;

} cfaxiic_cmd_t;


// ----------------------------------------------------------------------------------------

#if !defined( __AVR__ )
#pragma pack(pop)
#endif


#endif  // #if !defined( BCDRL_S3C2410A_CFAX_IIC_PROTOCOL_H )
// ----------------------------------------------------------------------------------------
//  end of protocol.h
// ----------------------------------------------------------------------------------------

