//!/////////////////////////////////////////////////////////////////////////
/// glcd.h                                                                //
///                                                                       //
/// Version:     0.6                                                      //
/// Date:        04/16/2010                                               //
/// Author:      Michael Skutek (michael@skutek.de)                       //
///                                                                       //
/// Description: 8 Bit Interface to GLCD displays with 128x64 dots        //
///              and KS0108 Controller.                                   //
///                                                                       //
/// Platform:    AVR ATmega (tested on ATmega16)                          //
///                                                                       //
/// Include Files:                                                        //
///              avr/io.h:             port accessing (part of avr-gcc)   //
///              util/delay.h:         time delays (part of avr-gcc)      //
///              port_definitions.h:   definition of output ports         //
///              glcd.h:               definitions and display setup      //
///              glcd_characters.h:    definitions for font(s)            //
///              glcd_bitmaps.h:       definitions for bitmaps            //
///                                                                       //
///                                                                       //
/// This program is free software: you can redistribute it and/or modify  //
/// it under the terms of the GNU Lesser General Public License as        //
/// published by the Free Software Foundation, either version 3 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 Lesser General Public License for more details.                   //
///                                                                       //
/// You should have received a copy of the GNU Lesser General Public      //
/// License along with this program. If not, see                          //
/// <http://www.gnu.org/licenses/>.                                       //
//!/////////////////////////////////////////////////////////////////////////


#ifndef GLCD_H_INCLUDED
#define GLCD_H_INCLUDED


///GLCD basic definitions


//Latched I/O on (1) or off(0)?
#define GLCD_LATCHED_IO                      1        //interface mode: 0  - normal mode
                                                      //                1  - latched mode (pins shared)


//values (Do not modify - to be used for mode settings!)
#ifndef TRUE
#define TRUE                                 1
#endif
#ifndef FALSE
#define FALSE                                0
#endif

#define GLCD_X_RESOLUTION                  128        //number of dots in x-direction
#define GLCD_Y_RESOLUTION                   64        //number of dots in y-direction
#define GLCD_LAST_X_POS                    127        //last valid x-position (index)
#define GLCD_LAST_Y_POS                     63        //last valid y-position (index)
#define GLCD_PAGE_WIDTH                     64        //number of dots per page
#define GLCD_PAGE_NUMBER                     8        //number of pages
#define GLCD_PAGE_HEIGHT                     8        //number of page dots (y-direction)

#define GLCD_PAGE_NUMBER_2  GLCD_PAGE_NUMBER/2        //number of pages/2


///timing definitios for read/write access (should be adapted to the display timings (f_osz))

#define GLCD_RESET_WIDTH_MS                 50        //Reset Pulse Width [ms]
#define GLCD_ENABLELOW_WIDTH_US           0.05        //Enable Low Pulse Width [us]
#define GLCD_ENABLEHIGH_WIDTH_US          0.05        //Enable High Pulse Width [us]
#define GLCD_DATAHOLD_US                  0.05        //Address Hold Time [us]


///definitions for values

#define GLCD_DATA_VALUE                    0x1        //Data Flag
#define GLCD_INSTRUCTION_VALUE             0x0        //Instruction Flag

#define GLCD_CONTROLLER_ID1                  1        //ID of Controller 1
#define GLCD_CONTROLLER_ID2                  2        //ID of Controller 2

//some instructions (data bits)
#define GLCD_DISPLAY_ON_VALUE             0x3f        //switch GLCD on
#define GLCD_DISPLAY_OFF_VALUE            0x3e        //switch GLCD off
#define GLCD_SETADDRESS_VALUE             0x40        //set address (y position)
#define GLCD_SETPAGE_VALUE                0xb8        //set page (x position)
#define GLCD_SETSTARTLINE_VALUE           0xc0        //set start line


//modes
#define GLCD_POS_TO_ADDRESS                  0        //conversion from position to GLCD address
#define GLCD_ADDRESS_TO_POS                  1        //conversion from GLCD address to position


//return values
#define GLCD_NO_ERROR                        0        //no error occured
#define GLCD_ERROR                           1        //error occured


///enable or disable some functions (graphical output) to save program memory

#define GLCD_SHOW_XBM_ENABLED                1        //enables [1] or disables [0] "glcd_show_xbm()"
#define GLCD_SHOW_DIAGRAM_ENABLED            1        //enables [1] or disables [0] "glcd_show_diagram()"
#define GLCD_SHOW_COMPLETE_DIAGRAM_ENABLED   1        //enables [1] or disables [0] "glcd_show_complete_diagram()"
#define GLCD_GET_ADDRESS_ENABLED             1        //enables [1] or disables [0] "glcd_get_address()"

///function definitions

void glcd_write_data(uint8_t, uint8_t, uint8_t);
void glcd_delete_line(uint8_t);
void glcd_clear_display(void);
#if GLCD_GET_ADDRESS_ENABLED == 1
uint8_t glcd_get_address(uint8_t *, uint8_t *, uint8_t *, uint8_t *, uint8_t *, uint8_t *, uint8_t);
#endif
#if GLCD_SHOW_XBM_ENABLED == 1
uint8_t glcd_show_xbm(unsigned char *, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t);
#endif
void glcd_set_cursor(uint8_t, uint8_t);
void glcd_send_string(const char *, uint8_t);
void glcd_init(void);
void glcd_pin_init(void);
#if GLCD_SHOW_DIAGRAM_ENABLED == 1
void glcd_show_diagram(char *, uint8_t, char *, uint16_t, uint16_t, uint8_t);
#endif
#if GLCD_SHOW_COMPLETE_DIAGRAM_ENABLED == 1
void glcd_show_complete_diagram(char *, uint8_t, char *, uint16_t *, uint16_t);
#endif



#endif // GLCD_H_INCLUDED
