Changeset - 6982c8ddef15
Libraries/u8glib/chessengine.c
Show inline comments
 
new file 100644
 
/*
 
  chessengine.c
 
  
 
  "Little Rook Chess" (lrc)
 

	
 
  Port to u8g library
 

	
 
  chess for embedded 8-Bit controllers
 

	
 
  Copyright (c) 2012, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 

	
 
  Note:
 
    UNIX_MAIN --> unix console executable
 

	
 
  Current Rule Limitation
 
    - no minor promotion, only "Queening" of the pawn
 
    - threefold repetition is not detected (same board situation appears three times)
 
	Note: Could be implemented, but requires tracking of the complete game
 
    - Fifty-move rule is not checked (no pawn move, no capture within last 50 moves)
 
	
 
  Words
 
    Ply		a half move
 
    
 
  General Links
 
    http://chessprogramming.wikispaces.com/
 

	
 
  Arduino specific
 
    http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1260055596
 
    
 
  Prefixes  
 
    chess_		Generic Chess Application Interface
 
    ce_		Chess engine, used internally, these function should not be called directly
 
    cu_		Chess utility function
 
    stack_		Internal function for stack handling
 

	
 
  Issues
 
    10.01.2011
 
      - castling to the right does not move the rook
 
	  --> done
 
      - castling to the left: King can only move two squares
 
	  --> done
 
      
 
    11.01.2011	
 
      Next Steps:
 
	- replace stack_NextCurrentPos with cu_NextPos, cleanup code according to the loop variable
 
	    --> done
 
	- Castling: Need to check for fields under attack
 
	    --> done
 
	
 
	- Check for WIN / LOOSE situation, perhaps call ce_Eval() once on the top-level board setup
 
	    just after the real move
 
	- cleanup cu_Move
 
	    --> almost done
 
	- add some heuristics to the eval procedure
 
	- add right side menu
 
	  --> done
 
	- clean up chess_ManualMove
 
	  --> done
 
	- finish menu (consider is_game_end, undo move)
 
        - end condition: if KING is under attack and if KING can not move to a field which is under attack...
 
	      then the game is lost. What will be returned by the Eval procedure? is it -INF?
 
	    --> finished
 
	    
 
	- reduce the use of variable color, all should be reduced to board_orientation and ply&1
 
	
 
	- chess_GetNextMarked shoud make use of cu_NextPos
 
	    --> done
 
	- chess_ManualMove: again cleanup, solve draw issue (KING is not in check and no legal moves are available)
 
	    --> done
 
    22.01.2011
 
	- simplify eval_t ce_Eval(void)
 
	- position eval does not work, still moves side pawn :-(
 
	      maybe because all pieces are considered
 
	    --> done
 

	
 
*/
 

	
 
#include "u8g.h"
 

	
 
//#ifndef __unix__
 
//#else
 
//#include <assert.h>
 
//#define U8G_NOINLINE
 
//#endif
 

	
 
/*
 
SAN identifies each piece by a single upper case letter.  The standard English
 
values: pawn = "P", knight = "N", bishop = "B", rook = "R", queen = "Q", and
 
king = "K".
 
*/
 

	
 
/* numbers for the various pieces */
 
#define PIECE_NONE	0
 
#define PIECE_PAWN 	1
 
#define PIECE_KNIGHT  	2
 
#define PIECE_BISHOP 	3
 
#define PIECE_ROOK	4
 
#define PIECE_QUEEN 	5
 
#define PIECE_KING		6
 

	
 
/* color definitions */
 
#define COLOR_WHITE	0
 
#define COLOR_BLACK	1
 

	
 
/* a mask, which includes COLOR and PIECE number */
 
#define COLOR_PIECE_MASK 0x01f
 

	
 
#define CP_MARK_MASK 0x20
 

	
 
#define ILLEGAL_POSITION 255
 

	
 
/* This is the build in upper limit of the search stack */
 
/* This value defines the amount of memory allocated for the search stack */
 
/* The search depth of this chess engine can never exceed this value */
 
#define STACK_MAX_SIZE 5
 

	
 
/* chess half move stack: twice the number of undo's, a user can do */ 
 
#define CHM_USER_SIZE 6
 

	
 
/* the CHM_LIST_SIZE must be larger than the maximum search depth */
 
/* the overall size of ste half move stack */
 
#define CHM_LIST_SIZE (STACK_MAX_SIZE+CHM_USER_SIZE+2)
 

	
 
typedef int16_t eval_t;	/* a variable type to store results from the evaluation */ 
 
//#define EVAL_T_LOST -32768
 
#define EVAL_T_MIN -32767
 
#define EVAL_T_MAX 32767
 
//#define EVAL_T_WIN 32767
 

	
 
/* for maintainance of our own stack: this is the definition of one element on the stack */
 
struct _stack_element_struct
 
{
 
  /* the current source position which is investigated */
 
  uint8_t current_pos;
 
  uint8_t current_cp;
 
  uint8_t current_color;	/* COLOR_WHITE or COLOR_BLACK: must be predefines */
 
  
 
  /* the move which belongs to that value, both values are game positions */
 
  uint8_t best_from_pos;
 
  uint8_t best_to_pos;
 
  /* the best value, which has been dicovered so far */
 
  eval_t best_eval;
 
};
 
typedef struct _stack_element_struct stack_element_t;
 
typedef struct _stack_element_struct *stack_element_p;
 

	
 
/* chess half move history */
 
struct _chm_struct
 
{
 
  uint8_t main_cp;		/* the main piece, which is moved */
 
  uint8_t main_src;		/* the source position of the main piece */
 
  uint8_t main_dest; 	/* the destination of the main piece */
 
  
 
  uint8_t other_cp;		/* another piece: the captured one, the ROOK in case of castling or PIECE_NONE */
 
  uint8_t other_src;		/* the delete position of other_cp. Often identical to main_dest except for e.p. and castling */
 
  uint8_t other_dest;		/* only used for castling: ROOK destination pos */
 
  
 
  /* the position of the last pawn, which did a double move forward */
 
  /* this is required to check en passant conditions */
 
  /* this array can be indexed by the color of the current player */
 
  /* this is the condition BEFORE the move was done */
 
  uint8_t pawn_dbl_move[2];
 
  
 
  /* flags for the movement of rook and king; required for castling */
 
  /* a 1 means: castling is (still) possible */
 
  /* a 0 means: castling not possible */
 
  /*  bit 0 left side white */
 
  /*  bit 1 right side white */
 
  /*  bit 2 left side black */
 
  /*  bit 3 right side black */
 
  /* this is the condition BEFORE the move was done */
 
  uint8_t castling_possible;   
 
};
 

	
 
typedef struct _chm_struct chm_t;
 
typedef struct _chm_struct *chm_p;
 

	
 
/* little rook chess, main structure */
 
struct _lrc_struct
 
{  
 
  /* half-move (ply) counter: Counts the number of half-moves so far. Starts with 0 */
 
  /* the lowest bit is used to derive the color of the current player */
 
  /* will be set to zero in chess_SetupBoard() */
 
  uint8_t ply_count;
 
  
 
  /* the half move stack position counter, counts the number of elements in chm_list */
 
  uint8_t chm_pos;
 
  
 
  /* each element contains a colored piece, empty fields have value 0 */
 
  /* the field with index 0 is black (lower left) */
 
  uint8_t board[64];	
 
  /* the position of the last pawn, which did a double move forward */
 
  /* this is required to check en passant conditions */
 
  /* this array can be indexed by the color of the current player */
 
  uint8_t pawn_dbl_move[2]; 
 
  
 
  /* flags for the movement of rook and king; required for castling */
 
  /* a 1 means: castling is (still) possible */
 
  /* a 0 means: castling not possible */
 
  /*  bit 0 left side white */
 
  /*  bit 1 right side white */
 
  /*  bit 2 left side black */
 
  /*  bit 3 right side black */
 
  uint8_t castling_possible; 
 
  
 
  /* board orientation */
 
  /* 0: white is below COLOR_WHITE */
 
  /* 1: black is below COLOR_BLACK */
 
  /* bascially, this can be used as a color */
 
  uint8_t orientation;
 
  
 
  /* exchange colors of the pieces */
 
  /* 0: white has an empty body, use this for bright background color */
 
  /* 1: black has an empty body, use this for dark backround color */
 
  uint8_t strike_out_color;
 
  
 
  /* 0, when the game is ongoing */
 
  /* 1, when the game is stopped (lost or draw) */
 
  uint8_t is_game_end;
 
  /* the color of the side which lost the game */
 
  /* this value is only valid, when is_game_end is not 0 */
 
  /* values 0 and 1 represent WHITE and BLACK, 2 means a draw */
 
  uint8_t lost_side_color;
 
  
 
  
 
  
 
  /* checks are executed in ce_LoopRecur */
 
  /* these checks will put some marks on the board */
 
  /* this will be used by the interface to find out */
 
  /* legal moves */
 
  uint8_t check_src_pos;
 
  uint8_t check_mode;		/* CHECK_MODE_NONE, CHECK_MODE_MOVEABLE, CHECK_MODE_TARGET_MOVE */
 
  
 
  
 
  /* count of the attacking pieces, indexed by color */
 
  uint8_t find_piece_cnt[2];
 

	
 
  /* sum of the attacking pieces, indexed by color */
 
  uint8_t find_piece_weight[2];
 

	
 
  /* points to the current element of the search stack */
 
  /* this stack is NEVER empty. The value 0 points to the first element of the stack */
 
  /* actually "curr_depth" represent half-moves (plies) */
 
  uint8_t curr_depth;
 
  uint8_t max_depth;
 
  stack_element_p curr_element;
 
  
 
  /* allocated memory for the search stack */
 
  stack_element_t stack_memory[STACK_MAX_SIZE];
 

	
 
  /* the half move stack, used for move undo and depth search, size is stored in chm_pos */
 
  chm_t chm_list[CHM_LIST_SIZE];
 
};
 
typedef struct _lrc_struct lrc_t;
 

	
 
#define CHECK_MODE_NONE 0
 
#define CHECK_MODE_MOVEABLE 1
 
#define CHECK_MODE_TARGET_MOVE 2
 

	
 

	
 

	
 
/*==============================================================*/
 
/* global variables */
 
/*==============================================================*/
 

	
 
u8g_t *lrc_u8g;
 

	
 
lrc_t lrc_obj;
 

	
 

	
 
/*==============================================================*/
 
/* forward declarations */
 
/*==============================================================*/
 

	
 
/* 
 
  apply no inline to some of the functions:
 
  avr-gcc very often inlines functions, however not inline saves a lot of program memory!
 
  On the other hand there are some really short procedures which should be inlined (like cp_GetColor)
 
  These procedures are marked static to prevent the generation of the expanded procedure, which
 
  also saves space.
 
*/
 

	
 
uint8_t stack_Push(uint8_t color) U8G_NOINLINE;
 
void stack_Pop(void) U8G_NOINLINE;
 
void stack_InitCurrElement(void) U8G_NOINLINE;
 
void stack_Init(uint8_t max) U8G_NOINLINE;
 
void stack_SetMove(eval_t val, uint8_t to_pos) U8G_NOINLINE;
 
uint8_t cu_NextPos(uint8_t pos) U8G_NOINLINE;
 
static uint8_t cu_gpos2bpos(uint8_t gpos);
 
static uint8_t cp_Construct(uint8_t color, uint8_t piece);
 
static uint8_t cp_GetPiece(uint8_t cp);
 
static uint8_t cp_GetColor(uint8_t cp);
 
uint8_t cp_GetFromBoard(uint8_t pos) U8G_NOINLINE;
 
void cp_SetOnBoard(uint8_t pos, uint8_t cp) U8G_NOINLINE;
 

	
 
void cu_ClearBoard(void) U8G_NOINLINE;
 
void chess_SetupBoard(void) U8G_NOINLINE;
 
eval_t ce_Eval(void);
 

	
 
void cu_ClearMoveHistory(void) U8G_NOINLINE;
 
void cu_ReduceHistoryByFullMove(void) U8G_NOINLINE;
 
void cu_UndoHalfMove(void) U8G_NOINLINE;
 
chm_p cu_PushHalfMove(void) U8G_NOINLINE;
 

	
 

	
 
void ce_CalculatePositionWeight(uint8_t pos);
 
uint8_t ce_GetPositionAttackWeight(uint8_t pos, uint8_t color);
 

	
 
void chess_Thinking(void);
 
void ce_LoopPieces(void);
 

	
 

	
 
/*==============================================================*/
 
/* search stack */
 
/*==============================================================*/
 

	
 
/* get current element from stack */
 
stack_element_p stack_GetCurrElement(void)
 
{
 
  return lrc_obj.curr_element;
 
}
 

	
 
uint8_t stack_Push(uint8_t color)
 
{
 
  if ( lrc_obj.curr_depth == lrc_obj.max_depth )
 
    return 0;
 
  lrc_obj.curr_depth++;
 
  lrc_obj.curr_element = lrc_obj.stack_memory+lrc_obj.curr_depth;
 
  
 
  /* change view for the evaluation */
 
  color ^= 1;
 
  stack_GetCurrElement()->current_color = color;
 

	
 
  return 1;
 
}
 

	
 
void stack_Pop(void)
 
{
 
  lrc_obj.curr_depth--;
 
  lrc_obj.curr_element = lrc_obj.stack_memory+lrc_obj.curr_depth;
 
}
 

	
 
/* reset the current element on the stack */
 
void stack_InitCurrElement(void)
 
{
 
  stack_element_p e = stack_GetCurrElement();
 
  e->best_eval = EVAL_T_MIN;
 
  e->best_from_pos = ILLEGAL_POSITION;
 
  e->best_to_pos = ILLEGAL_POSITION;
 
}
 

	
 
/* resets the search stack (and the check mode) */
 
void stack_Init(uint8_t max)
 
{
 
  lrc_obj.curr_depth = 0;
 
  lrc_obj.curr_element = lrc_obj.stack_memory;
 
  lrc_obj.max_depth = max;
 
  lrc_obj.check_mode = CHECK_MODE_NONE;
 
  stack_InitCurrElement();
 
  stack_GetCurrElement()->current_color = lrc_obj.ply_count;
 
  stack_GetCurrElement()->current_color &= 1;
 
}
 

	
 
/* assign evaluation value and store the move, if this is the best move */
 
/* assumes, that current_pos contains the source position */
 
void stack_SetMove(eval_t val, uint8_t to_pos)
 
{
 
  stack_element_p e = stack_GetCurrElement();
 
  if ( e->best_eval < val )
 
  {
 
    e->best_eval = val;
 
    e->best_from_pos = e->current_pos;
 
    e->best_to_pos = to_pos;
 
  }
 
}
 

	
 
/* 
 
  calculate next position on a 0x88 board 
 
  loop is constructed in this way:
 
  i = 0;
 
  do
 
  {
 
    ...
 
    i = cu_NextPos(i);
 
  } while( i != 0 );
 

	
 
  next pos might be started with an illegal position like 255
 
*/
 
uint8_t cu_NextPos(uint8_t pos)
 
{
 
  /* calculate next gpos */
 
  pos++;
 
  if ( ( pos & 0x08 ) != 0 )
 
  {
 
    pos+= 0x10;
 
    pos&= 0xf0; 
 
  }
 
  if ( ( pos & 0x80 ) != 0 )
 
    pos = 0;
 
  return pos;
 
}
 

	
 
uint8_t cu_PrevPos(uint8_t pos)
 
{
 
  /* calculate prev gpos */
 
  pos--;
 
  if ( ( pos & 0x80 ) != 0 )
 
    pos = 0x077;
 
  else if ( ( pos & 0x08 ) != 0 )
 
  {
 
    pos &= 0xf0; 
 
    pos |= 0x07;
 
  }
 
  return pos;
 
}
 

	
 

	
 
/*==============================================================*/
 
/* position transltion */
 
/*==============================================================*/
 
/*
 
  there are two positions
 
    1. game position (gpos): BCD encoded x-y values
 
    2. board position (bpos): a number between 0 and 63, only used to access the board.
 
*/
 
/*
 
  gpos:	game position value
 
  returns:	board position
 
  note:	does not do any checks
 
*/
 
static uint8_t cu_gpos2bpos(uint8_t gpos)
 
{
 
  uint8_t bpos = gpos;
 
  bpos &= 0xf0;
 
  bpos >>= 1;
 
  gpos &= 0x0f;
 
  bpos |= gpos;
 
  return bpos;
 
}
 

	
 
#define gpos_IsIllegal(gpos) ((gpos) & 0x088)
 

	
 

	
 
/*==============================================================*/
 
/* colored piece handling */
 
/*==============================================================*/
 

	
 
#define cp_IsMarked(cp)  ((cp) & CP_MARK_MASK)
 

	
 

	
 
/*
 
  piece: one of PIECE_xxx
 
  color: COLOR_WHITE or COLOR_BLACK
 

	
 
  returns: A colored piece
 
*/
 
static uint8_t cp_Construct(uint8_t color, uint8_t piece)
 
{
 
  color <<= 4;
 
  color |= piece;
 
  return color;
 
}
 

	
 
/* inline is better than a macro */
 
static uint8_t cp_GetPiece(uint8_t cp)
 
{
 
  cp &= 0x0f;
 
  return cp;
 
}
 

	
 
/*
 
  we could use a macro:
 
  #define cp_GetColor(cp)	(((cp) >> 4)&1)
 
  however, inlined functions are sometimes much better
 
*/
 
static uint8_t cp_GetColor(uint8_t cp)
 
{
 
  cp >>= 4;
 
  cp &= 1;
 
  return cp;
 
}
 

	
 
/*
 
  pos: game position
 
  returns the colored piece at the given position
 
*/
 
uint8_t cp_GetFromBoard(uint8_t pos)
 
{
 
  return lrc_obj.board[cu_gpos2bpos(pos)];
 
}
 

	
 
/*
 
  pos: game position
 
  cp: colored piece
 
*/
 
void cp_SetOnBoard(uint8_t pos, uint8_t cp)
 
{
 
  /*printf("cp_SetOnBoard gpos:%02x cp:%02x\n", pos, cp);*/
 
  lrc_obj.board[cu_gpos2bpos(pos)] = cp;
 
}
 

	
 
/*==============================================================*/
 
/* global board access */
 
/*==============================================================*/
 

	
 
void cu_ClearBoard(void)
 
{
 
  uint8_t i;
 
  /* clear the board */
 
  for( i = 0; i < 64; i++ )
 
    lrc_obj.board[i] = PIECE_NONE;
 
  
 
  lrc_obj.ply_count = 0;
 
  lrc_obj.orientation = COLOR_WHITE;
 
  
 
  lrc_obj.pawn_dbl_move[0] = ILLEGAL_POSITION;
 
  lrc_obj.pawn_dbl_move[1] = ILLEGAL_POSITION;
 
  
 
  lrc_obj.castling_possible = 0x0f;
 
  
 
  lrc_obj.is_game_end = 0;
 
  lrc_obj.lost_side_color = 0;
 

	
 
  /* clear half move history */
 
  cu_ClearMoveHistory();
 

	
 
}
 

	
 
/*
 
  test setup
 
  white wins in one move
 
*/
 
void chess_SetupBoardTest01(void)
 
{
 
  cu_ClearBoard();
 
  lrc_obj.board[7+7*8] = cp_Construct(COLOR_BLACK, PIECE_KING);
 
  lrc_obj.board[7+5*8] = cp_Construct(COLOR_WHITE, PIECE_PAWN);
 
  lrc_obj.board[3] = cp_Construct(COLOR_WHITE, PIECE_KING);
 
  lrc_obj.board[0+7*8] = cp_Construct(COLOR_BLACK, PIECE_ROOK);
 
  lrc_obj.board[6] = cp_Construct(COLOR_WHITE, PIECE_QUEEN);
 
} 
 

	
 
/* setup the global board */
 
void chess_SetupBoard(void)
 
{
 
  uint8_t i;
 
  register uint8_t bp, wp;
 
  
 
  /* clear the board */
 
  cu_ClearBoard();
 
  
 
  /* precronstruct pawns */
 
  wp = cp_Construct(COLOR_WHITE, PIECE_PAWN);
 
  bp = cp_Construct(COLOR_BLACK, PIECE_PAWN);
 
  
 
  /* setup pawn */
 
  for( i = 0; i < 8; i++ )
 
  {
 
    lrc_obj.board[i+8] = wp;
 
    lrc_obj.board[i+6*8] = bp;
 
  }
 
  
 
  /* assign remaining pieces */
 
  
 
  lrc_obj.board[0] = cp_Construct(COLOR_WHITE, PIECE_ROOK);
 
  lrc_obj.board[1] = cp_Construct(COLOR_WHITE, PIECE_KNIGHT);
 
  lrc_obj.board[2] = cp_Construct(COLOR_WHITE, PIECE_BISHOP);
 
  lrc_obj.board[3] = cp_Construct(COLOR_WHITE, PIECE_QUEEN);
 
  lrc_obj.board[4] = cp_Construct(COLOR_WHITE, PIECE_KING);
 
  lrc_obj.board[5] = cp_Construct(COLOR_WHITE, PIECE_BISHOP);
 
  lrc_obj.board[6] = cp_Construct(COLOR_WHITE, PIECE_KNIGHT);
 
  lrc_obj.board[7] = cp_Construct(COLOR_WHITE, PIECE_ROOK);
 

	
 
  lrc_obj.board[0+7*8] = cp_Construct(COLOR_BLACK, PIECE_ROOK);
 
  lrc_obj.board[1+7*8] = cp_Construct(COLOR_BLACK, PIECE_KNIGHT);
 
  lrc_obj.board[2+7*8] = cp_Construct(COLOR_BLACK, PIECE_BISHOP);
 
  lrc_obj.board[3+7*8] = cp_Construct(COLOR_BLACK, PIECE_QUEEN);
 
  lrc_obj.board[4+7*8] = cp_Construct(COLOR_BLACK, PIECE_KING);
 
  lrc_obj.board[5+7*8] = cp_Construct(COLOR_BLACK, PIECE_BISHOP);
 
  lrc_obj.board[6+7*8] = cp_Construct(COLOR_BLACK, PIECE_KNIGHT);
 
  lrc_obj.board[7+7*8] = cp_Construct(COLOR_BLACK, PIECE_ROOK);
 

	
 
  //chess_SetupBoardTest01();
 

	
 
}
 

	
 

	
 

	
 
/*==============================================================*/
 
/* checks */
 
/*==============================================================*/
 

	
 
/*
 
  checks if the position is somehow illegal
 
*/
 
uint8_t cu_IsIllegalPosition(uint8_t pos, uint8_t my_color)
 
{
 
  uint8_t board_cp;
 
  /* check, if the position is offboard */
 
  if ( gpos_IsIllegal(pos) != 0 )
 
    return 1;
 
  /* get the piece from the board */
 
  board_cp = cp_GetFromBoard(pos);
 
  /* check if hit our own pieces */
 
  if ( board_cp != 0 ) 
 
    if ( cp_GetColor(board_cp) == my_color )
 
      return 1;
 
  /* all ok, we could go to this position */
 
  return 0;
 
}
 

	
 
/*==============================================================*/
 
/* evaluation procedure */
 
/*==============================================================*/
 

	
 
/*
 
  basic idea is to return a value between EVAL_T_MIN and EVAL_T_MAX
 
*/
 

	
 
/*
 
  the weight table uses the PIECE number as index:
 
      #define PIECE_NONE	0
 
      #define PIECE_PAWN 	1
 
      #define PIECE_KNIGHT  	2
 
      #define PIECE_BISHOP 	3
 
      #define PIECE_ROOK	4
 
      #define PIECE_QUEEN 	5
 
      #define PIECE_KING		6
 
  the king itself is not counted
 
*/
 
uint8_t ce_piece_weight[] = { 0, 1, 3, 3, 5, 9, 0 };
 
uint8_t ce_pos_weight[] = { 0, 1, 1, 2, 2, 1, 1, 0};
 
/*
 
  evaluate the current situation on the global board
 
*/
 
eval_t ce_Eval(void)
 
{
 
  uint8_t cp;
 
  uint8_t is_my_king_present = 0;
 
  uint8_t is_opposit_king_present = 0;
 
  eval_t material_my_color = 0;
 
  eval_t material_opposit_color = 0;
 
  eval_t position_my_color = 0;
 
  eval_t position_opposit_color = 0;
 
  eval_t result;
 
  uint8_t pos;
 
  
 
  pos = 0;
 
  do
 
  {
 
    /* get colored piece from the board */
 
    cp = cp_GetFromBoard(pos);
 
    
 
    if ( cp_GetPiece(cp) != PIECE_NONE )
 
    {
 
      if ( stack_GetCurrElement()->current_color == cp_GetColor(cp) )
 
      {
 
	/* this is our color */
 
	/* check if we found our king */
 
	if ( cp_GetPiece(cp) == PIECE_KING  )
 
	  is_my_king_present = 1;
 
	material_my_color += ce_piece_weight[cp_GetPiece(cp)];
 
	if ( cp_GetPiece(cp) == PIECE_PAWN || cp_GetPiece(cp) == PIECE_KNIGHT  )
 
	{
 
	  position_my_color += ce_pos_weight[pos&7]*ce_pos_weight[(pos>>4)&7];
 
	}
 
      }
 
      else
 
      {
 
	/* this is the opposit color */
 
	if ( cp_GetPiece(cp) == PIECE_KING  )
 
	  is_opposit_king_present = 1;
 
	material_opposit_color += ce_piece_weight[cp_GetPiece(cp)];
 
	if ( cp_GetPiece(cp) == PIECE_PAWN || cp_GetPiece(cp) == PIECE_KNIGHT )
 
	{
 
	  position_opposit_color += ce_pos_weight[pos&7]*ce_pos_weight[(pos>>4)&7];
 
	}
 
      }
 
    }
 
    pos = cu_NextPos(pos);
 
  } while( pos != 0 );
 

	
 
    
 
  /* decide if we lost or won the game */
 
  if ( is_my_king_present == 0 )
 
    return EVAL_T_MIN;	/*_LOST*/
 
  if ( is_opposit_king_present == 0 )
 
    return EVAL_T_MAX;	/*_WIN*/
 
  
 
  /* here is the evaluation function */
 
  
 
  result = material_my_color - material_opposit_color;
 
  result <<= 3;
 
  result += position_my_color - position_opposit_color;
 
  return result;
 
}
 

	
 
/*==============================================================*/
 
/* move backup and restore */
 
/*==============================================================*/
 

	
 

	
 
/* this procedure must be called to keep the size as low as possible */
 
/* if the chm_list is large enough, it could hold the complete history */
 
/* but for an embedded controler... it is deleted for every engine search */
 
void cu_ClearMoveHistory(void)
 
{
 
  lrc_obj.chm_pos = 0;
 
}
 

	
 
void cu_ReduceHistoryByFullMove(void)
 
{
 
  uint8_t i;
 
  while( lrc_obj.chm_pos > CHM_USER_SIZE )
 
  {
 
    i = 0;
 
    for(;;)
 
    {
 
      if ( i+2 >= lrc_obj.chm_pos )
 
	break;
 
      lrc_obj.chm_list[i] = lrc_obj.chm_list[i+2];
 
      i++;
 
    }
 
    lrc_obj.chm_pos -= 2;
 
  }
 
}
 

	
 
void cu_UndoHalfMove(void)
 
{
 
  chm_p chm;
 
  
 
  if ( lrc_obj.chm_pos == 0 )
 
    return;
 
  
 
  lrc_obj.chm_pos--;
 

	
 
  chm = lrc_obj.chm_list+lrc_obj.chm_pos;
 
  
 
  lrc_obj.pawn_dbl_move[0] = chm->pawn_dbl_move[0];
 
  lrc_obj.pawn_dbl_move[1] = chm->pawn_dbl_move[1];
 
  lrc_obj.castling_possible = chm->castling_possible;
 
  
 
  cp_SetOnBoard(chm->main_src, chm->main_cp);
 
  cp_SetOnBoard(chm->main_dest, PIECE_NONE);
 
  
 
  if ( chm->other_src != ILLEGAL_POSITION )
 
    cp_SetOnBoard(chm->other_src, chm->other_cp);
 
  if ( chm->other_dest != ILLEGAL_POSITION )
 
    cp_SetOnBoard(chm->other_dest, PIECE_NONE);
 

	
 
}
 

	
 
/*
 
  assumes, that the following members of the returned chm structure are filled 
 
  uint8_t main_cp;		the main piece, which is moved
 
  uint8_t main_src;		the source position of the main piece
 
  uint8_t main_dest; 	the destination of the main piece
 
  
 
  uint8_t other_cp;		another piece: the captured one, the ROOK in case of castling or PIECE_NONE
 
  uint8_t other_src;		the delete position of other_cp. Often identical to main_dest except for e.p. and castling
 
  uint8_t other_dest;		only used for castling: ROOK destination pos
 

	
 
*/
 
chm_p cu_PushHalfMove(void)
 
{
 
  chm_p chm;
 
  
 
  chm = lrc_obj.chm_list+lrc_obj.chm_pos;
 
  if ( lrc_obj.chm_pos < CHM_LIST_SIZE-1)
 
    lrc_obj.chm_pos++;
 

	
 
  chm->pawn_dbl_move[0] = lrc_obj.pawn_dbl_move[0];
 
  chm->pawn_dbl_move[1] = lrc_obj.pawn_dbl_move[1];
 
  chm->castling_possible = lrc_obj.castling_possible;
 
  return chm;
 
}
 

	
 

	
 
char chess_piece_to_char[] = "NBRQK";
 

	
 
/*
 
  simple moves on empty field: 	Ka1-b2
 
  capture moves:				Ka1xb2
 
  castling:						0-0 or 0-0-0
 
*/
 

	
 
static void cu_add_pos(char *s, uint8_t pos) U8G_NOINLINE;
 

	
 
static void cu_add_pos(char *s, uint8_t pos)
 
{
 
  *s = pos;
 
  *s >>= 4;
 
  *s += 'a';
 
  s++;
 
  *s = pos;
 
  *s &= 15;
 
  *s += '1';
 
}
 

	
 
const char *cu_GetHalfMoveStr(uint8_t idx)
 
{
 
  chm_p chm;
 
  static char buf[7];		/*Ka1-b2*/
 
  char *p = buf;
 
  chm = lrc_obj.chm_list+idx;
 
  
 
  if ( cp_GetPiece(chm->main_cp) != PIECE_NONE )
 
  {
 
    if ( cp_GetPiece(chm->main_cp) > PIECE_PAWN )
 
    {
 
      *p++ = chess_piece_to_char[cp_GetPiece(chm->main_cp)-2];
 
    }
 
    cu_add_pos(p, chm->main_src);
 
    p+=2;
 
    if ( cp_GetPiece(chm->other_cp) == PIECE_NONE )
 
      *p++ = '-';
 
    else
 
      *p++ = 'x';
 
    cu_add_pos(p, chm->main_dest);
 
    p+=2;
 
  }
 
  *p = '\0';
 
  return buf;
 
}
 

	
 

	
 

	
 

	
 

	
 
/*==============================================================*/
 
/* move */
 
/*==============================================================*/
 

	
 
/*
 
  Move a piece from source position to a destination on the board
 
  This function
 
    - does not perform any checking
 
    - however it processes "en passant" and casteling
 
    - backup the move and allow 1x undo
 
  
 
  2011-02-05: 
 
    - fill pawn_dbl_move[] for double pawn moves
 
	--> done
 
    - Implement casteling 
 
	--> done
 
    - en passant
 
	--> done
 
    - pawn conversion/promotion
 
	--> done
 
    - half-move backup 
 
	--> done
 
    - cleanup everything, minimize variables
 
	--> done
 
*/
 

	
 
void cu_Move(uint8_t src, uint8_t dest)
 
{  
 
  /* start backup structure */
 
  chm_p chm = cu_PushHalfMove();
 

	
 
  /* these are the values from the board at the positions, provided as arguments to this function */
 
  uint8_t cp_src, cp_dest;
 
  
 
  /* Maybe a second position is cleared and one additional location is set */
 
  uint8_t clr_pos2;
 
  uint8_t set_pos2;
 
  uint8_t set_cp2;
 
  
 
  /* get values from board */
 
  cp_src = cp_GetFromBoard(src);
 
  cp_dest = cp_GetFromBoard(dest);
 

	
 
  /* fill backup structure */
 
  
 
  chm->main_cp = cp_src;
 
  chm->main_src = src;
 
  chm->main_dest = dest;
 
  
 
  chm->other_cp = cp_dest;		/* prepace capture backup */
 
  chm->other_src = dest;
 
  chm->other_dest = ILLEGAL_POSITION;
 
  
 
  /* setup results as far as possible with some suitable values */
 
  
 
  clr_pos2 = ILLEGAL_POSITION;	/* for en passant and castling, two positions might be cleared */
 
  set_pos2 = ILLEGAL_POSITION;	/* only used for castling */
 
  set_cp2 = PIECE_NONE;			/* ROOK for castling */
 
  
 
  /* check for PAWN */
 
  if ( cp_GetPiece(cp_src) == PIECE_PAWN )
 
  {
 
    
 
    /* double step: is the distance 2 rows */
 
    if ( (src - dest == 32) || ( dest - src == 32 ) )
 
    {
 
      /* remember the destination position */
 
      lrc_obj.pawn_dbl_move[cp_GetColor(cp_src)] = dest;
 
    }
 
    
 
    /* check if the PAWN is able to promote */
 
    else if ( (dest>>4) == 0 || (dest>>4) == 7 )
 
    {
 
      /* do simple "queening" */
 
      cp_src &= ~PIECE_PAWN;
 
      cp_src |= PIECE_QUEEN;
 
    }
 
    
 
    /* is it en passant capture? */
 
    /* check for side move */
 
    else if ( ((src + dest) & 1) != 0 )
 
    {
 
      /* check, if target field is empty */
 
      if (  cp_GetPiece(cp_dest) == PIECE_NONE )
 
      {
 
	/* this is en passant */
 
	/* no further checking required, because legal moves are assumed here */
 
	/* however... the captured pawn position must be valid */
 
	clr_pos2 = lrc_obj.pawn_dbl_move[cp_GetColor(cp_src) ^ 1];
 
	chm->other_src = clr_pos2;
 
	chm->other_cp = cp_GetFromBoard(clr_pos2);
 
      }
 
    }    
 
  }
 
  
 
  /* check for the KING */
 
  else if ( cp_GetPiece(cp_src) == PIECE_KING )
 
  {
 
    /* disallow castling, if the KING has moved */
 
    if ( cp_GetColor(cp_src) == COLOR_WHITE )
 
    {
 
      /* if white KING has moved, disallow castling for white */
 
      lrc_obj.castling_possible &= 0x0c;
 
    }
 
    else
 
    {
 
      /* if black KING has moved, disallow castling for black */
 
      lrc_obj.castling_possible &= 0x03;
 
    }
 
    
 
    /* has it been castling to the left? */
 
    if ( src - dest == 2 )
 
    {
 
      /* let the ROOK move to pos2 */
 
      set_pos2 = src-1;
 
      set_cp2 = cp_GetFromBoard(src-4);
 
      
 
      /* the ROOK must be cleared from the original position */
 
      clr_pos2 = src-4;
 
      
 
      chm->other_cp = set_cp2;
 
      chm->other_src = clr_pos2;
 
      chm->other_dest = set_pos2;
 
    }
 
    
 
    /* has it been castling to the right? */
 
    else if ( dest - src == 2 )
 
    {
 
      /* let the ROOK move to pos2 */
 
      set_pos2 = src+1;
 
      set_cp2 = cp_GetFromBoard(src+3);
 
      
 
      /* the ROOK must be cleared from the original position */
 
      clr_pos2 = src+3;
 
      
 
      chm->other_cp = set_cp2;
 
      chm->other_src = clr_pos2;
 
      chm->other_dest = set_pos2;
 
      
 
    }
 
    
 
  }
 
  
 
  /* check for the ROOK */
 
  else if ( cp_GetPiece(cp_src) == PIECE_ROOK )
 
  {
 
    /* disallow white left castling */
 
    if ( src == 0x00 )
 
      lrc_obj.castling_possible &= ~0x01;
 
    /* disallow white right castling */
 
    if ( src == 0x07 )
 
      lrc_obj.castling_possible &= ~0x02;
 
    /* disallow black left castling */
 
    if ( src == 0x70 )
 
      lrc_obj.castling_possible &= ~0x04;
 
    /* disallow black right castling */
 
    if ( src == 0x77 )
 
      lrc_obj.castling_possible &= ~0x08;
 
  }
 
  
 
  
 
  /* apply new board situation */
 
  
 
  cp_SetOnBoard(dest, cp_src);
 
  
 
  if ( set_pos2 != ILLEGAL_POSITION )
 
    cp_SetOnBoard(set_pos2, set_cp2);
 
  
 
  cp_SetOnBoard(src, PIECE_NONE);
 
  
 
  if ( clr_pos2 != ILLEGAL_POSITION )
 
    cp_SetOnBoard(clr_pos2, PIECE_NONE);
 
  
 
  
 
}
 

	
 
/*
 
  this subprocedure decides for evaluation of the current board situation or further (deeper) investigation
 
  Argument pos is the new target position if the current piece 
 

	
 
*/
 
uint8_t ce_LoopRecur(uint8_t pos)
 
{
 
  eval_t eval;
 
  
 
  /* 1. check if target position is occupied by the same player (my_color) */
 
  /*     of if pos is somehow illegal or not valid */
 
  if ( cu_IsIllegalPosition(pos, stack_GetCurrElement()->current_color) != 0 )
 
    return 0;
 

	
 
  /* 2. move piece to the specified position, capture opponent piece if required */
 
  cu_Move(stack_GetCurrElement()->current_pos, pos);
 

	
 
  
 
  /* 3. */
 
  /* if depth reached: evaluate */
 
  /* else: go down next level */
 
  /* no eval if there had been any valid half-moves, so the default value (MIN) will be returned. */
 
  if ( stack_Push(stack_GetCurrElement()->current_color) == 0 )
 
  {
 
    eval = ce_Eval();
 
  }
 
  else
 
  {
 
    /* init the element, which has been pushed */
 
    stack_InitCurrElement();
 
    /* start over with ntext level */
 
    ce_LoopPieces();
 
    /* get the best move from opponents view, so invert the result */
 
    eval = -stack_GetCurrElement()->best_eval;
 
    stack_Pop();
 
  }
 
  
 
  /* 4. store result */
 
  stack_SetMove(eval, pos);
 
  
 
  /* 5. undo the move */
 
  cu_UndoHalfMove();
 
  
 
  /* 6. check special modes */
 
  /* the purpose of these checks is to mark special pieces and positions on the board */
 
  /* these marks can be checked by the user interface to highlight special positions */
 
  if ( lrc_obj.check_mode != 0 )
 
  {
 
    stack_element_p e = stack_GetCurrElement();
 
    if ( lrc_obj.check_mode == CHECK_MODE_MOVEABLE )
 
    {
 
      cp_SetOnBoard(e->current_pos, e->current_cp | CP_MARK_MASK );
 
    }
 
    else if ( lrc_obj.check_mode == CHECK_MODE_TARGET_MOVE )
 
    {
 
      if ( e->current_pos == lrc_obj.check_src_pos )
 
      {
 
	cp_SetOnBoard(pos, cp_GetFromBoard(pos)  | CP_MARK_MASK );
 
      }
 
    }
 
  }
 
  return 1;
 
}
 

	
 
/*==============================================================*/
 
/* move pieces which can move one or more steps into a direction */
 
/*==============================================================*/
 

	
 
/*
 
  subprocedure to generate various target positions for some pieces
 
  special cases are handled in the piece specific sub-procedure
 

	
 
  Arguments:
 
    d: a list of potential directions
 
    is_multi_step: if the piece can only do one step (zero for KING and KNIGHT)
 
*/
 
static const uint8_t ce_dir_offset_rook[] PROGMEM = { 1, 16, -16, -1, 0 };
 
static const uint8_t ce_dir_offset_bishop[] PROGMEM = { 15, 17, -17, -15, 0 };
 
static const uint8_t ce_dir_offset_queen[] PROGMEM = { 1, 16, -16, -1, 15, 17, -17, -15, 0 };
 
static const uint8_t ce_dir_offset_knight[] PROGMEM = {14, -14, 18, -18, 31, -31, 33, -33, 0};
 

	
 
void ce_LoopDirsSingleMultiStep(const uint8_t *d, uint8_t is_multi_step)
 
{
 
  uint8_t loop_pos;
 
  
 
  /* with all directions */
 
  for(;;)
 
  {
 
    if ( u8g_pgm_read(d) == 0 )
 
      break;
 
    
 
    /* start again from the initial position */
 
    loop_pos = stack_GetCurrElement()->current_pos;
 
    
 
    /* check direction */
 
    do
 
    {
 
      /* check next position into one direction */
 
      loop_pos += u8g_pgm_read(d);
 
      
 
      /*
 
	go further to ce_LoopRecur()
 
	0 will be returned if the target position is illegal or a piece of the own color
 
	this is used to stop walking into one direction
 
      */
 
      if ( ce_LoopRecur(loop_pos) == 0 )
 
	break;
 
      
 
      /* stop if we had hit another piece */
 
      if ( cp_GetPiece(cp_GetFromBoard(loop_pos)) != PIECE_NONE )
 
	break;
 
    } while( is_multi_step );
 
    d++;
 
  }
 
}
 

	
 
void ce_LoopRook(void)
 
{
 
  ce_LoopDirsSingleMultiStep(ce_dir_offset_rook, 1);
 
}
 

	
 
void ce_LoopBishop(void)
 
{
 
  ce_LoopDirsSingleMultiStep(ce_dir_offset_bishop, 1);
 
}
 

	
 
void ce_LoopQueen(void)
 
{
 
  ce_LoopDirsSingleMultiStep(ce_dir_offset_queen, 1);
 
}
 

	
 
void ce_LoopKnight(void)
 
{
 
  ce_LoopDirsSingleMultiStep(ce_dir_offset_knight, 0);
 
}
 

	
 

	
 

	
 
/*==============================================================*/
 
/* move king */
 
/*==============================================================*/
 

	
 
uint8_t cu_IsKingCastling(uint8_t mask, int8_t direction, uint8_t cnt) U8G_NOINLINE;
 

	
 
/*
 
  checks, if the king can do castling
 

	
 
  Arguments:
 
    mask:		the bit-mask for the global "castling possible" flag
 
    direction:	left castling: -1, right castling 1
 
    cnt:		number of fields to be checked: 3 or 2
 
*/
 
uint8_t cu_IsKingCastling(uint8_t mask, int8_t direction, uint8_t cnt)
 
{
 
  uint8_t pos;
 
  uint8_t opponent_color;
 
  
 
  /* check if the current board state allows castling */
 
  if ( (lrc_obj.castling_possible & mask) == 0 )
 
    return 0; 	/* castling not allowed */
 
  
 
  /* get the position of the KING, could be white or black king */
 
  pos = stack_GetCurrElement()->current_pos;
 
  
 
  /* calculate the color of the opponent */
 
  opponent_color = 1;
 
  opponent_color -= stack_GetCurrElement()->current_color;
 
  
 
  /* if the KING itself is given check... */
 
  if ( ce_GetPositionAttackWeight(pos, opponent_color) > 0 )
 
    return 0;
 

	
 
  
 
  /* check if fields in the desired direction are emtpy */
 
  for(;;)
 
  {
 
    /* go to the next field */
 
    pos += direction;
 
    /* check for a piece */
 
    if ( cp_GetPiece(cp_GetFromBoard(pos)) != PIECE_NONE )
 
      return 0;		/* castling not allowed */
 

	
 
    /* if some of the fields are under attack */
 
    if ( ce_GetPositionAttackWeight(pos, opponent_color) > 0 )
 
      return 0;
 
    
 
    cnt--;
 
    if ( cnt == 0 )
 
      break;
 
  }
 
  return 1; /* castling allowed */
 
}
 

	
 
void ce_LoopKing(void)
 
{
 
  /*
 
    there is an interessting timing problem in this procedure
 
    it must be checked for castling first and as second step the normal
 
    KING movement. If we would first check for normal moves, than
 
    any marks might be overwritten by the ROOK in the case of castling.
 
  */
 
  
 
  /* castling (this must be done before checking normal moves (see above) */
 
  if ( stack_GetCurrElement()->current_color == COLOR_WHITE )
 
  {
 
    /* white left castling */
 
    if ( cu_IsKingCastling(1, -1, 3) != 0 )
 
    {
 
      /* check for attacked fields */
 
      ce_LoopRecur(stack_GetCurrElement()->current_pos-2);
 
    }
 
    /* white right castling */
 
    if ( cu_IsKingCastling(2, 1, 2) != 0 )
 
    {
 
      /* check for attacked fields */
 
      ce_LoopRecur(stack_GetCurrElement()->current_pos+2);
 
    }
 
  }
 
  else
 
  {
 
    /* black left castling */
 
    if ( cu_IsKingCastling(4, -1, 3) != 0 )
 
    {
 
      /* check for attacked fields */
 
      ce_LoopRecur(stack_GetCurrElement()->current_pos-2);
 
    }
 
    /* black right castling */
 
    if ( cu_IsKingCastling(8, 1, 2) != 0 )
 
    {
 
      /* check for attacked fields */
 
      ce_LoopRecur(stack_GetCurrElement()->current_pos+2);
 
    }
 
  }
 
  
 
  /* reuse queen directions */
 
  ce_LoopDirsSingleMultiStep(ce_dir_offset_queen, 0);
 
}
 

	
 

	
 
/*==============================================================*/
 
/* move pawn */
 
/*==============================================================*/
 

	
 
/*
 
  doppelschritt: nur von der grundlinie aus, beide (!) felder vor dem bauern müssen frei sein
 
  en passant: nur unmittelbar nachdem ein doppelschritt ausgeführt wurde.
 
*/
 
void ce_LoopPawnSideCapture(uint8_t loop_pos)
 
{
 
  if ( gpos_IsIllegal(loop_pos) == 0 )
 
  {
 
    /* get the piece from the board */
 
    /* if the field is NOT empty */
 
    if ( cp_GetPiece(cp_GetFromBoard(loop_pos)) != PIECE_NONE )
 
    {
 
      /* normal capture */
 
      ce_LoopRecur(loop_pos);
 
      /* TODO: check for pawn conversion/promotion */
 
    }
 
    else
 
    {
 
      /* check conditions for en passant capture */
 
      if ( stack_GetCurrElement()->current_color == COLOR_WHITE )
 
      {
 
	if ( lrc_obj.pawn_dbl_move[COLOR_BLACK]+16 == loop_pos )
 
	{
 
	  ce_LoopRecur(loop_pos);
 
	  /* note: pawn conversion/promotion can not occur */
 
	}
 
      }
 
      else
 
      {
 
	if ( lrc_obj.pawn_dbl_move[COLOR_WHITE] == loop_pos+16 )
 
	{
 
	  ce_LoopRecur(loop_pos);
 
	  /* note: pawn conversion/promotion can not occur */
 
	}
 
      }
 
    }
 
  }
 
}
 

	
 
void ce_LoopPawn(void)
 
{
 
  uint8_t initial_pos = stack_GetCurrElement()->current_pos; 
 
  uint8_t my_color = stack_GetCurrElement()->current_color;
 
  
 
  uint8_t loop_pos;
 
  uint8_t line;
 
  
 
  /* one step forward */
 
  
 
  loop_pos = initial_pos;
 
  line = initial_pos;
 
  line >>= 4;
 
  if ( my_color == COLOR_WHITE )
 
    loop_pos += 16;
 
  else
 
    loop_pos -= 16;
 
  if ( gpos_IsIllegal(loop_pos) == 0 )
 
  {
 
    /* if the field is empty */
 
    if ( cp_GetPiece(cp_GetFromBoard(loop_pos)) == PIECE_NONE )
 
    {
 
      /* TODO: check for and loop through piece conversion/promotion */
 
      ce_LoopRecur(loop_pos);      
 

	
 
      /* second step forward */
 
      
 
      /* if pawn is on his starting line */
 
      if ( (my_color == COLOR_WHITE && line == 1) || (my_color == COLOR_BLACK && line == 6 ) )
 
      {
 
	/* the place before the pawn is not occupied, so we can do double moves, see above */
 
	
 
	if ( my_color == COLOR_WHITE )
 
	  loop_pos += 16;
 
	else
 
	  loop_pos -= 16;
 
	if ( cp_GetPiece(cp_GetFromBoard(loop_pos)) == PIECE_NONE )
 
	{
 
	  /* this is a special case, other promotions of the pawn can not occur */
 
	  ce_LoopRecur(loop_pos);
 
	}
 
      }
 
    }
 
  }
 

	
 
  /* capture */
 
  
 
  loop_pos = initial_pos;
 
  if ( my_color == COLOR_WHITE )
 
    loop_pos += 15;
 
  else
 
    loop_pos -= 15;
 
  ce_LoopPawnSideCapture(loop_pos);
 

	
 

	
 
  loop_pos = initial_pos;
 
  if ( my_color == COLOR_WHITE )
 
    loop_pos += 17;
 
  else
 
    loop_pos -= 17;
 
  ce_LoopPawnSideCapture(loop_pos);
 
}
 

	
 
/*==============================================================*/
 
/* attacked */
 
/*==============================================================*/
 

	
 
/*
 
  from a starting position, search for a piece, that might jump to that postion.
 
  return:
 
    the two global variables
 
      lrc_obj.find_piece_weight[0];
 
      lrc_obj.find_piece_weight[1];
 
  will be increased by the weight of the attacked pieces of that color.
 
  it is usually required to reset these global variables to zero, before using
 
  this function.
 
*/
 

	
 
void ce_FindPieceByStep(uint8_t start_pos, uint8_t piece, const uint8_t *d, uint8_t is_multi_step)
 
{
 
  uint8_t loop_pos, cp;
 
  
 
  /* with all directions */
 
  for(;;)
 
  {
 
    if ( u8g_pgm_read(d) == 0 )
 
      break;
 
    
 
    /* start again from the initial position */
 
    loop_pos = start_pos;
 
    
 
    /* check direction */
 
    do
 
    {
 
      /* check next position into one direction */
 
      loop_pos += u8g_pgm_read(d);
 
      
 
      /* check if the board boundary has been crossed */
 
      if ( (loop_pos & 0x088) != 0 )
 
	break;
 
      
 
      /* get the colored piece from the board */
 
      cp = cp_GetFromBoard(loop_pos);
 
      
 
      /* stop if we had hit another piece */
 
      if ( cp_GetPiece(cp) != PIECE_NONE )
 
      {
 
	/* if it is the piece we are looking for, then add the weight */
 
	if ( cp_GetPiece(cp) == piece )
 
	{
 
	  lrc_obj.find_piece_weight[cp_GetColor(cp)] += ce_piece_weight[piece];
 
	  lrc_obj.find_piece_cnt[cp_GetColor(cp)]++;
 
	}
 
	/* in any case, break out of the inner loop */
 
	break;
 
      }
 
    } while( is_multi_step );
 
    d++;
 
  }
 
}
 

	
 
void ce_FindPawnPiece(uint8_t dest_pos, uint8_t color)
 
{
 
  uint8_t cp;
 
  /* check if the board boundary has been crossed */
 
  if ( (dest_pos & 0x088) == 0 )
 
  {
 
    /* get the colored piece from the board */
 
    cp = cp_GetFromBoard(dest_pos);
 
    /* only if there is a pawn of the matching color */
 
    if ( cp_GetPiece(cp) == PIECE_PAWN )
 
    {
 
      if ( cp_GetColor(cp) == color )
 
      {
 
	/* the weight of the PAWN */
 
	lrc_obj.find_piece_weight[color] += 1;
 
	lrc_obj.find_piece_cnt[color]++;
 
      }
 
    }
 
  }
 
}
 

	
 

	
 
/*
 
  find out, which pieces do attack a specified field
 
  used to
 
  - check if the KING can do castling
 
  - check if the KING must move
 

	
 
  may be used in the eval procedure ... once...
 

	
 
  the result is stored in the global array
 
    uint8_t lrc_obj.find_piece_weight[2];
 
  which is indexed with the color.
 
  lrc_obj.find_piece_weight[COLOR_WHITE] is the sum of all white pieces
 
  which can directly move to this field.
 

	
 
  example:
 
    if the black KING is at "pos" and lrc_obj.find_piece_weight[COLOR_WHITE] is not zero 
 
    (after executing ce_CalculatePositionWeight(pos)) then the KING must be protected or moveed, because 
 
    the KING was given check.
 
*/
 

	
 
void ce_CalculatePositionWeight(uint8_t pos)
 
{
 
  
 
  lrc_obj.find_piece_weight[0] = 0;
 
  lrc_obj.find_piece_weight[1] = 0;
 
  lrc_obj.find_piece_cnt[0] = 0;
 
  lrc_obj.find_piece_cnt[1] = 0;
 
  
 
  if ( (pos & 0x088) != 0 )
 
    return;
 

	
 
  ce_FindPieceByStep(pos, PIECE_ROOK, ce_dir_offset_rook, 1);
 
  ce_FindPieceByStep(pos, PIECE_BISHOP, ce_dir_offset_bishop, 1);
 
  ce_FindPieceByStep(pos, PIECE_QUEEN, ce_dir_offset_queen, 1);
 
  ce_FindPieceByStep(pos, PIECE_KNIGHT, ce_dir_offset_knight, 0);
 
  ce_FindPieceByStep(pos, PIECE_KING, ce_dir_offset_queen, 0);
 

	
 
  ce_FindPawnPiece(pos+17, COLOR_BLACK);
 
  ce_FindPawnPiece(pos+15, COLOR_BLACK);
 
  ce_FindPawnPiece(pos-17, COLOR_WHITE);
 
  ce_FindPawnPiece(pos-15, COLOR_WHITE);
 
}
 

	
 
/*
 
  calculate the summed weight of pieces with specified color which can move to a specified position
 

	
 
  argument:
 
    pos: 	the position which should be analysed
 
    color: 	the color of those pieces which should be analysed
 
		e.g. if a black piece is at 'pos' and 'color' is white then this procedure returns the white atting count
 
*/
 
uint8_t ce_GetPositionAttackWeight(uint8_t pos, uint8_t color)
 
{
 
  ce_CalculatePositionWeight(pos);
 
  return lrc_obj.find_piece_weight[color];
 
}
 

	
 
uint8_t ce_GetPositionAttackCount(uint8_t pos, uint8_t color)
 
{
 
  ce_CalculatePositionWeight(pos);
 
  return lrc_obj.find_piece_cnt[color];
 
}
 

	
 

	
 
/*==============================================================*/
 
/* depth search starts here: loop over all pieces of the current color on the board */
 
/*==============================================================*/
 

	
 
void ce_LoopPieces(void)
 
{
 
  stack_element_p e = stack_GetCurrElement();
 
  /* start with lower left position (A1) */
 
  e->current_pos = 0;
 
  do
 
  {
 
    e->current_cp = cp_GetFromBoard(e->current_pos);
 
    /* check if the position on the board is empty */
 
    if ( e->current_cp != 0 )
 
    {
 
      /* only generate moves for the current color */
 
      if ( e->current_color == cp_GetColor(e->current_cp) )
 
      {
 
	chess_Thinking();
 
	
 
	/* find out which piece is used */
 
	switch(cp_GetPiece(e->current_cp))
 
	{
 
	  case PIECE_NONE:
 
	    break;
 
	  case PIECE_PAWN:
 
	    ce_LoopPawn();
 
	    break;
 
	  case PIECE_KNIGHT:
 
	    ce_LoopKnight();
 
	    break;
 
	  case PIECE_BISHOP:
 
	    ce_LoopBishop();
 
	    break;
 
	  case PIECE_ROOK:
 
	    ce_LoopRook();
 
	    break;
 
	  case PIECE_QUEEN:
 
	    ce_LoopQueen();
 
	    break;
 
	  case PIECE_KING:
 
	    ce_LoopKing();
 
	    break;
 
	}
 
      }
 
    }    
 
    e->current_pos = cu_NextPos(e->current_pos);
 
  } while( e->current_pos != 0 );
 
}
 

	
 
/*==============================================================*/
 
/* user interface */
 
/*==============================================================*/
 

	
 
/*
 
eval_t chess_EvalCurrBoard(uint8_t color)
 
{
 
  stack_Init(0);
 
  stack_GetCurrElement()->current_color = color;
 
  ce_LoopPieces();
 
  return stack_GetCurrElement()->best_eval;
 
}
 
*/
 

	
 
/* clear any marks on the board */
 
void chess_ClearMarks(void)
 
{
 
  uint8_t i;
 
  for( i = 0; i < 64; i++ )
 
     lrc_obj.board[i] &= ~CP_MARK_MASK;
 
}
 

	
 
/*
 
  Mark all pieces which can do moves. This is done by setting flags on the global board
 
*/
 
void chess_MarkMovable(void)
 
{
 
  stack_Init(0);
 
  //stack_GetCurrElement()->current_color = color;
 
  lrc_obj.check_mode = CHECK_MODE_MOVEABLE;
 
  ce_LoopPieces();
 
}
 

	
 
/*
 
  Checks, if the piece can move from src_pos to dest_pos
 

	
 
  src_pos: The game position of a piece on the chess board
 
*/
 
void chess_MarkTargetMoves(uint8_t src_pos)
 
{
 
  stack_Init(0);
 
  stack_GetCurrElement()->current_color = cp_GetColor(cp_GetFromBoard(src_pos));
 
  lrc_obj.check_src_pos = src_pos;
 
  lrc_obj.check_mode = CHECK_MODE_TARGET_MOVE;  
 
  ce_LoopPieces();
 
}
 

	
 
/*
 
  first call should start with 255
 
  this procedure will return 255 if 
 
      - there are no marks at all
 
      - it has looped over all marks once
 
*/
 
uint8_t chess_GetNextMarked(uint8_t arg, uint8_t is_prev)
 
{
 
  uint8_t i;
 
  uint8_t pos = arg;
 
  for(i = 0; i < 64; i++)
 
  {
 
    if ( is_prev != 0 )
 
      pos = cu_PrevPos(pos);
 
    else
 
      pos = cu_NextPos(pos);
 
    if ( arg != 255 && pos == 0 )
 
      return 255;
 
    if ( cp_IsMarked(cp_GetFromBoard(pos)) )
 
      return pos;
 
  }
 
  return 255;
 
}
 

	
 

	
 
/* make a manual move: this is a little bit more than cu_Move() */
 
void chess_ManualMove(uint8_t src, uint8_t dest)
 
{
 
  uint8_t cp;
 
  
 
  /* printf("chess_ManualMove %02x -> %02x\n", src, dest); */
 
  
 
  /* if all other things fail, this is the place where the game is to be decided: */
 
  /* ... if the KING is captured */
 
  cp = cp_GetFromBoard(dest);
 
  if ( cp_GetPiece(cp) == PIECE_KING )
 
  {
 
    lrc_obj.is_game_end = 1;
 
    lrc_obj.lost_side_color = cp_GetColor(cp);    
 
  }
 

	
 
  /* clear ply history here, to avoid memory overflow */
 
  /* may be the last X moves can be kept here */
 
  cu_ReduceHistoryByFullMove();
 
  /* perform the move on the board */
 
  cu_Move(src, dest);
 
  
 
  /* update en passant double move positions: en passant position is removed after two half moves  */
 
  lrc_obj.pawn_dbl_move[lrc_obj.ply_count&1]  = ILLEGAL_POSITION;
 
  
 
  /* update the global half move counter */
 
  lrc_obj.ply_count++;
 

	
 

	
 
  /* make a small check about the end of the game */
 
  /* use at least depth 1, because we must know if the king can still move */
 
  /* this is: King moves at level 0 and will be captured at level 1 */
 
  /* so we check if the king can move and will not be captured at search level 1 */
 
  
 
  stack_Init(1);
 
  ce_LoopPieces(); 
 

	
 
  /* printf("chess_ManualMove/analysis best_from_pos %02x -> best_to_pos %02x\n", stack_GetCurrElement()->best_from_pos, stack_GetCurrElement()->best_to_pos); */
 

	
 
  /* analyse the eval result */
 
  
 
  /* check if the other player has any moves left */
 
  if ( stack_GetCurrElement()->best_from_pos == ILLEGAL_POSITION )
 
  {
 
    uint8_t color;
 
    /* conditions: */
 
    /* 1. no King, should never happen, opposite color has won */
 
    /*		this is already checked above at the beginning if this procedure */
 
    /* 2. King is under attack, opposite color has won */
 
    /* 3. King is not under attack, game is a draw */
 

	
 
    uint8_t i = 0;
 
    color = lrc_obj.ply_count;
 
    color &= 1;
 
    do
 
    {
 
      cp = cp_GetFromBoard(i);
 
      /* look for the King */
 
      if ( cp_GetPiece(cp) == PIECE_KING )
 
      {
 
	if ( cp_GetColor(cp) == color )
 
	{
 
	  /* check if  KING is attacked */
 
	  if ( ce_GetPositionAttackCount(i, color^1) != 0 )
 
	  {
 
	    /* KING is under attack (check) and can not move: Game is lost */
 
	    lrc_obj.is_game_end = 1;
 
	    lrc_obj.lost_side_color = color; 
 
	  }
 
	  else
 
	  {
 
	    /* KING is NOT under attack (check) but can not move: Game is a draw */
 
	    lrc_obj.is_game_end = 1;
 
	    lrc_obj.lost_side_color = 2; 
 
	  }
 
	  /* break out of the loop */
 
	  break;	  
 
	}
 
      }
 
      i = cu_NextPos(i);
 
    } while( i != 0 );
 
  }
 
}
 

	
 
/* let the computer do a move */
 
void chess_ComputerMove(uint8_t depth)
 
{
 
  stack_Init(depth);
 
  
 
  //stack_GetCurrElement()->current_color = lrc_obj.ply_count;
 
  //stack_GetCurrElement()->current_color &= 1;
 
  
 
  cu_ReduceHistoryByFullMove();
 
  ce_LoopPieces();
 

	
 
  chess_ManualMove(stack_GetCurrElement()->best_from_pos, stack_GetCurrElement()->best_to_pos);
 
}
 

	
 

	
 
/*==============================================================*/
 
/* unix code */
 
/*==============================================================*/
 

	
 
#ifdef UNIX_MAIN
 

	
 
#include <stdio.h>
 
#include <string.h>
 

	
 
char *piece_str[] = {
 
  /* 0x00 */
 
  "  ", 
 
  "wP", 
 
  "wN", 
 
  "wB", 
 
  
 
  /* 0x04 */
 
  "wR", 
 
  "wQ", 
 
  "wK", 
 
  "w?", 
 

	
 
  /* 0x08 */
 
  "w?", 
 
  "w?", 
 
  "w?", 
 
  "w?", 
 
  
 
  /* 0x0c */
 
  "w?", 
 
  "w?", 
 
  "w?", 
 
  "w?", 
 

	
 
  /* 0x10 */
 
  "b ",
 
  "bP", 
 
  "bN", 
 
  "bB", 
 
  "bR", 
 
  "bQ", 
 
  "bK", 
 
  "b?", 
 

	
 
  "b?", 
 
  "b?", 
 
  "b?", 
 
  "b?", 
 
  "b?", 
 
  "b?", 
 
  "b?", 
 
  "b?"
 
};
 

	
 
void chess_Thinking(void)
 
{
 
  uint8_t i;
 
  uint8_t cp = cp_GetPiece(stack_GetCurrElement()->current_cp);
 
  
 
  printf("Thinking:  ", piece_str[cp], stack_GetCurrElement()->current_pos);
 
  
 
  for( i = 0; i <= lrc_obj.curr_depth; i++ )
 
    printf("%s ", piece_str[(lrc_obj.stack_memory+i)->current_cp]);
 
  
 
  printf("    \r");
 
}
 

	
 
void board_Show(void)
 
{
 
  uint8_t i, j, cp;
 
  char buf[10];
 
  for ( i = 0; i < 8; i++ )
 
  {
 
    printf("%1d ", 7-i);
 
    for ( j = 0; j < 8; j++ )
 
    {
 
      /* get piece from global board */
 
      cp = lrc_obj.board[(7-i)*8+j];
 
      strcpy(buf, piece_str[cp&COLOR_PIECE_MASK]);
 
      
 
      if ( (cp & CP_MARK_MASK) != 0 )
 
      {
 
	buf[0] = '#';
 
      }
 
      
 
      /* mask out any bits except color and piece index */
 
      cp &= COLOR_PIECE_MASK;
 
      printf("%s %02x ", buf, cp);
 
      
 
    }
 
    printf("\n");
 
  }
 
}
 

	
 
int main(void)
 
{
 
  uint8_t depth = 3;
 
  chess_SetupBoard();
 
  board_Show();
 
  puts("");
 
    
 
 
 
 /* 
 
  chess_ClearMarks();
 
  chess_MarkMovable(COLOR_WHITE);
 
  board_Show();
 
  */
 
  
 
  chess_ManualMove(0x006, 0x066);
 
  
 
  printf("lrc_obj.is_game_end: %d\n" , lrc_obj.is_game_end);
 
  printf("lrc_obj.lost_side_color: %d\n" , lrc_obj.lost_side_color);
 

	
 
  chess_ComputerMove(2);
 

	
 
  printf("lrc_obj.is_game_end: %d\n" , lrc_obj.is_game_end);
 
  printf("lrc_obj.lost_side_color: %d\n" , lrc_obj.lost_side_color);
 
  
 
  board_Show();
 

	
 
}
 

	
 

	
 

	
 
#else
 

	
 
/*==============================================================*/
 
/* display menu */
 
/*==============================================================*/
 

	
 
//#define MNU_FONT font_5x7
 
#define MNU_FONT u8g_font_5x8r
 
//#define MNU_FONT font_6x9
 
#define MNU_ENTRY_HEIGHT 9
 

	
 
char *mnu_title = "Little Rook Chess";
 
char *mnu_list[] = { "New Game (White)", "New Game (Black)", "Undo Move", "Return" };
 
uint8_t mnu_pos = 0;
 
uint8_t mnu_max = 4;
 

	
 
void mnu_DrawHome(uint8_t is_highlight)
 
{
 
  uint8_t x = lrc_u8g->width - 35;  
 
  uint8_t y = (lrc_u8g->height-1);
 
  uint8_t t;
 
  
 
  u8g_SetFont(lrc_u8g, u8g_font_5x7r);
 
  u8g_SetDefaultForegroundColor(lrc_u8g);
 
  t = u8g_DrawStrP(lrc_u8g, x, y -1, U8G_PSTR("Options"));
 
    
 
  if ( is_highlight )
 
    u8g_DrawFrame(lrc_u8g, x-1, y - MNU_ENTRY_HEIGHT +1, t, MNU_ENTRY_HEIGHT);  
 
}
 

	
 
void mnu_DrawEntry(uint8_t y, char *str, uint8_t is_clr_background, uint8_t is_highlight)
 
{
 
  uint8_t t, x;
 
  u8g_SetFont(lrc_u8g, MNU_FONT);
 
  t = u8g_GetStrWidth(lrc_u8g, str);
 
  x = u8g_GetWidth(lrc_u8g);
 
  x -= t;
 
  x >>= 1;
 
  
 
  if ( is_clr_background )
 
  {
 
    u8g_SetDefaultBackgroundColor(lrc_u8g);
 
    u8g_DrawBox(lrc_u8g, x-3, (lrc_u8g->height-1) - (y+MNU_ENTRY_HEIGHT-1+2), t+5, MNU_ENTRY_HEIGHT+4);
 
  }
 
  
 
  u8g_SetDefaultForegroundColor(lrc_u8g);
 
  u8g_DrawStr(lrc_u8g, x, (lrc_u8g->height-1) - y, str);
 
  
 
  if ( is_highlight )
 
  {
 
    u8g_DrawFrame(lrc_u8g, x-1, (lrc_u8g->height-1) - y -MNU_ENTRY_HEIGHT +1, t, MNU_ENTRY_HEIGHT);
 
  }
 
}
 

	
 
void mnu_Draw(void)
 
{
 
  uint8_t i;
 
  uint8_t t,y;
 
  /* calculate hight of the complete menu */
 
  y = mnu_max;
 
  y++; 					/* consider also some space for the title */
 
  y++; 					/* consider also some space for the title */
 
  y *= MNU_ENTRY_HEIGHT;
 
  
 
  /* calculate how much space will be left */
 
  t = u8g_GetHeight(lrc_u8g);			
 
  t -= y;
 
  
 
  /* topmost pos start half of that empty space from the top */
 
  t >>= 1;
 
  y = u8g_GetHeight(lrc_u8g);
 
  y -= t;
 
  
 
  y -= MNU_ENTRY_HEIGHT;
 
  mnu_DrawEntry(y, mnu_title, 0, 0);
 
  
 
  y -= MNU_ENTRY_HEIGHT;
 
  
 
  
 
  for( i = 0; i < mnu_max; i++ )
 
  {
 
    y -= MNU_ENTRY_HEIGHT;
 
    mnu_DrawEntry(y, mnu_list[i], 0, i == mnu_pos);
 
  }
 
}
 

	
 
void mnu_Step(uint8_t key_cmd)
 
{
 
    if ( key_cmd == CHESS_KEY_NEXT )
 
    {
 
      if ( mnu_pos+1 < mnu_max )
 
	mnu_pos++;
 
    }
 
    else if ( key_cmd == CHESS_KEY_PREV )
 
    {
 
      if ( mnu_pos > 0 )
 
	mnu_pos--;
 
    }
 
}
 

	
 

	
 

	
 

	
 
uint8_t chess_key_code = 0;
 
uint8_t chess_key_cmd = 0;
 
#define CHESS_STATE_MENU 0
 
#define CHESS_STATE_SELECT_START 1
 
#define CHESS_STATE_SELECT_PIECE 2
 
#define CHESS_STATE_SELECT_TARGET_POS 3
 
#define CHESS_STATE_THINKING 4
 
#define CHESS_STATE_GAME_END 5
 
uint8_t chess_state = CHESS_STATE_MENU;
 
uint8_t chess_source_pos = 255;
 
uint8_t chess_target_pos = 255;
 

	
 
const uint8_t chess_pieces_body_bm[] PROGMEM = 
 
{
 
  /* PAWN */ 		0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, /* 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x00, 0x00, 0x00, */ 
 
  /* KNIGHT */		0x00, 0x00, 0x1c, 0x2c, 0x04, 0x04, 0x0e, 0x00,
 
  /* BISHOP */		0x00, 0x00, 0x1c, 0x1c, 0x1c, 0x08, 0x00, 0x00, /* 0x00, 0x00, 0x08, 0x1c, 0x1c, 0x08, 0x00, 0x00, */
 
  /* ROOK */		0x00, 0x00, 0x00, 0x1c, 0x1c, 0x1c, 0x1c, 0x00,
 
  /* QUEEN */		0x00, 0x00, 0x14, 0x1c, 0x08, 0x1c, 0x08, 0x00,
 
  /* KING */		0x00, 0x00, 0x00, 0x08, 0x3e, 0x1c, 0x08, 0x00,
 
};
 

	
 
#ifdef NOT_REQUIRED
 
/* white pieces are constructed by painting black pieces and cutting out the white area */
 
const uint8_t chess_white_pieces_bm[] PROGMEM = 
 
{
 
  /* PAWN */ 		0x00, 0x00, 0x0c, 0x12, 0x12, 0x0c, 0x1e, 0x00, 
 
  /* KNIGHT */		0x00, 0x1c, 0x22, 0x52, 0x6a, 0x0a, 0x11, 0x1f,
 
  /* BISHOP */		0x00, 0x08, 0x14, 0x22, 0x22, 0x14, 0x08, 0x7f,
 
  /* ROOK */		0x00, 0x55, 0x7f, 0x22, 0x22, 0x22, 0x22, 0x7f,
 
  /* QUEEN */		0x00, 0x55, 0x2a, 0x22, 0x14, 0x22, 0x14, 0x7f,
 
  /* KING */		0x08, 0x1c, 0x49, 0x77, 0x41, 0x22, 0x14, 0x7f,
 
};
 
#endif
 

	
 
const uint8_t chess_black_pieces_bm[] PROGMEM = 
 
{
 
  /* PAWN */ 		0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x3c, 0x00, /* 0x00, 0x00, 0x0c, 0x1e, 0x1e, 0x0c, 0x1e, 0x00, */ 
 
  /* KNIGHT */		0x00, 0x1c, 0x3e, 0x7e, 0x6e, 0x0e, 0x1f, 0x1f,
 
  /* BISHOP */		0x00, 0x1c, 0x2e, 0x3e, 0x3e, 0x1c, 0x08, 0x7f,  /*0x00, 0x08, 0x1c, 0x3e, 0x3e, 0x1c, 0x08, 0x7f,*/
 
  /* ROOK */		0x00, 0x55, 0x7f, 0x3e, 0x3e, 0x3e, 0x3e, 0x7f,
 
  /* QUEEN */		0x00, 0x55, 0x3e, 0x3e, 0x1c, 0x3e, 0x1c, 0x7f,
 
  /* KING -*/		0x08, 0x1c, 0x49, 0x7f, 0x7f, 0x3e, 0x1c, 0x7f,
 
};
 

	
 

	
 
#if defined(DOGXL160_HW_GR)
 
#define BOXSIZE 13
 
#define BOXOFFSET 3
 
#else
 
#define BOXSIZE 8
 
#define BOXOFFSET 1
 
#endif
 

	
 
u8g_uint_t chess_low_edge;
 
uint8_t chess_boxsize = 8;
 
uint8_t chess_boxoffset = 1;
 

	
 

	
 
void chess_DrawFrame(uint8_t pos, uint8_t is_bold)
 
{
 
  u8g_uint_t x0, y0;
 

	
 
  x0 = pos;
 
  x0 &= 15;
 
  if ( lrc_obj.orientation != COLOR_WHITE )
 
    x0 ^= 7;
 

	
 
  y0 = pos;
 
  y0>>= 4;
 
  if ( lrc_obj.orientation != COLOR_WHITE )
 
    y0 ^= 7;
 
  
 
  x0 *= chess_boxsize;
 
  y0 *= chess_boxsize;
 
  
 
  u8g_SetDefaultForegroundColor(lrc_u8g);
 
  u8g_DrawFrame(lrc_u8g, x0, chess_low_edge - y0 - chess_boxsize+1, chess_boxsize, chess_boxsize);
 
  
 
  
 
  if ( is_bold )
 
  {
 
      x0--;
 
      y0++;
 
  
 
    u8g_DrawFrame(lrc_u8g, x0, chess_low_edge - y0 - chess_boxsize +1, chess_boxsize+2, chess_boxsize+2);
 
  }
 
}
 

	
 

	
 
void chess_DrawBoard(void)
 
{
 
  uint8_t i, j, cp;
 
  const uint8_t *ptr;  /* pointer into PROGMEM */
 
  
 
  if ( U8G_MODE_GET_BITS_PER_PIXEL(u8g_GetMode(lrc_u8g)) > 1 )
 
  {
 
    for( i = 0; i < 8; i++ )
 
      for( j = 0; j < 8; j++ )
 
      {
 
        uint8_t x,y;
 
        x = i;
 
        x*=chess_boxsize;
 
        y = j;
 
        y*=chess_boxsize;
 
        if ( ((i^j) & 1)  == 0 )
 
          u8g_SetDefaultMidColor(lrc_u8g);  
 
        else
 
          u8g_SetDefaultBackgroundColor(lrc_u8g);  
 
        u8g_DrawBox(lrc_u8g, x,chess_low_edge-y-chess_boxsize+1,chess_boxsize,chess_boxsize);
 
      }
 
    //u8g_SetDefaultForegroundColor(lrc_u8g);  
 
  }
 
  else
 
  {
 
    uint8_t x_offset = 1;
 
    u8g_SetDefaultForegroundColor(lrc_u8g);  
 
    for( i = 0; i < 8*8; i+=8 )
 
    {
 
      for( j = 0; j < 8*8; j+=8 )
 
      {
 
        if ( ((i^j) & 8)  == 0 )
 
        {
 
          u8g_DrawPixel(lrc_u8g, j+0+x_offset, chess_low_edge - i-0);
 
          u8g_DrawPixel(lrc_u8g, j+0+x_offset, chess_low_edge - i-2);
 
          u8g_DrawPixel(lrc_u8g, j+0+x_offset, chess_low_edge - i-4);
 
          u8g_DrawPixel(lrc_u8g, j+0+x_offset, chess_low_edge - i-6);
 
          u8g_DrawPixel(lrc_u8g, j+2+x_offset, chess_low_edge - i-0);
 
          u8g_DrawPixel(lrc_u8g, j+2+x_offset, chess_low_edge - i-6);
 
          u8g_DrawPixel(lrc_u8g, j+4+x_offset, chess_low_edge - i-0);
 
          u8g_DrawPixel(lrc_u8g, j+4+x_offset, chess_low_edge - i-6);
 
          u8g_DrawPixel(lrc_u8g, j+6+x_offset, chess_low_edge - i-0);
 
          u8g_DrawPixel(lrc_u8g, j+6+x_offset, chess_low_edge - i-2);
 
          u8g_DrawPixel(lrc_u8g, j+6+x_offset, chess_low_edge - i-4);
 
          u8g_DrawPixel(lrc_u8g, j+6+x_offset, chess_low_edge - i-6);
 
        }
 
      }
 
    }
 
  }
 
  
 
  for ( i = 0; i < 8; i++ )
 
  {
 
    for ( j = 0; j < 8; j++ )
 
    {
 
      /* get piece from global board */
 
      if ( lrc_obj.orientation == COLOR_WHITE )
 
      {
 
	cp =  lrc_obj.board[i*8+j];
 
      }
 
      else
 
      {
 
	cp =  lrc_obj.board[(7-i)*8+7-j];
 
      }
 
      if ( cp_GetPiece(cp) != PIECE_NONE )
 
      {
 
	ptr = chess_black_pieces_bm;
 
	ptr += (cp_GetPiece(cp)-1)*8;
 
        u8g_SetDefaultForegroundColor(lrc_u8g);
 
        u8g_DrawBitmapP(lrc_u8g, j*chess_boxsize+chess_boxoffset-1, chess_low_edge - (i*chess_boxsize+chess_boxsize-chess_boxoffset), 1, 8, ptr);
 
        
 
	if ( cp_GetColor(cp) == lrc_obj.strike_out_color ) 
 
	{
 
	  ptr = chess_pieces_body_bm;
 
	  ptr += (cp_GetPiece(cp)-1)*8;
 
          u8g_SetDefaultBackgroundColor(lrc_u8g);
 
          u8g_DrawBitmapP(lrc_u8g, j*chess_boxsize+chess_boxoffset-1, chess_low_edge - (i*chess_boxsize+chess_boxsize-chess_boxoffset), 1, 8, ptr);
 
	}
 
      }
 
    }
 
  }
 
  
 
  if ( (chess_source_pos & 0x88) == 0 )
 
  {
 
    chess_DrawFrame(chess_source_pos, 1);
 
  }
 

	
 
  if ( (chess_target_pos & 0x88) == 0 )
 
  {
 
    chess_DrawFrame(chess_target_pos, 0);
 
  }
 
  
 
}
 

	
 

	
 
void chess_Thinking(void)
 
{
 
}
 

	
 
void chess_Init(u8g_t *u8g, uint8_t body_color)
 
{
 
  lrc_u8g = u8g;
 

	
 
  chess_low_edge = u8g_GetHeight(lrc_u8g);
 
  chess_low_edge--;
 
  
 

	
 
  if ( U8G_MODE_GET_BITS_PER_PIXEL(u8g_GetMode(lrc_u8g)) == 1 )
 
  {
 
  
 
    chess_boxsize = 8;
 
    chess_boxoffset = 1;
 
  }
 
  else
 
  {
 

	
 
    /*    
 
    if ( u8g_GetHeight(lrc_u8g) >= 12*8 )
 
    {
 
      chess_boxsize = 12;
 
      chess_boxoffset = 3;
 
    }
 
    else */ if ( u8g_GetHeight(lrc_u8g) >= 11*8 )
 
    {
 
      chess_boxsize = 10;
 
      chess_boxoffset = 2;
 
    }
 
    else
 
    {
 
      chess_boxsize = 8;
 
      chess_boxoffset = 1;      
 
    }
 
    
 
    if ( u8g_GetHeight(lrc_u8g) > 64 )
 
      chess_low_edge -= (u8g_GetHeight(lrc_u8g)-chess_boxsize*8) / 2;
 
    
 
  }
 
    
 
  lrc_obj.strike_out_color = body_color;
 
  chess_SetupBoard();
 
}
 

	
 

	
 

	
 
void chess_Draw(void)
 
{
 
  if ( chess_state == CHESS_STATE_MENU )
 
  {
 
    if ( lrc_obj.ply_count == 0)
 
      mnu_max = 2;
 
    else
 
      mnu_max = 4;
 
    mnu_Draw();
 
  }
 
  else
 
  {
 
    chess_DrawBoard();
 
    
 
    {
 
      uint8_t i;
 
      uint8_t entries = lrc_obj.chm_pos;
 
      if ( entries > 4 )
 
	entries = 4;
 
      
 
      u8g_SetFont(lrc_u8g, u8g_font_5x7);
 
      u8g_SetDefaultForegroundColor(lrc_u8g);
 
      for( i = 0; i < entries; i++ )
 
      {
 
        
 
#if defined(DOGXL160_HW_GR) || defined(DOGXL160_HW_BW)
 
	dog_DrawStr(u8g_GetWidth(lrc_u8g)-35, u8g_GetHeight(lrc_u8g)-8*(i+1), font_5x7, cu_GetHalfMoveStr(lrc_obj.chm_pos-entries+i));
 
#else
 
        u8g_DrawStr(lrc_u8g, u8g_GetWidth(lrc_u8g)-35, 8*(i+1), cu_GetHalfMoveStr(lrc_obj.chm_pos-entries+i));
 
#endif
 

	
 
      }
 
      
 
    }
 
    
 
    if ( chess_state == CHESS_STATE_SELECT_PIECE )
 
      mnu_DrawHome(chess_source_pos == 255);
 
    else if ( chess_state == CHESS_STATE_SELECT_TARGET_POS )
 
      mnu_DrawHome(chess_target_pos == 255);
 
    else
 
      mnu_DrawHome(0);
 
      
 
    if ( chess_state == CHESS_STATE_GAME_END )
 
    {
 
      switch( lrc_obj.lost_side_color )
 
      {
 
	case COLOR_WHITE:
 
	  mnu_DrawEntry(u8g_GetHeight(lrc_u8g) / 2-2, "Black wins", 1, 1);
 
	  break;
 
	case COLOR_BLACK:
 
	  mnu_DrawEntry(u8g_GetHeight(lrc_u8g) / 2-2, "White wins", 1, 1);
 
	  break;
 
	default:
 
	  mnu_DrawEntry(u8g_GetHeight(lrc_u8g) / 2-2, "Stalemate", 1, 1);
 
	  break;
 
      }  
 
    }
 
  }
 
}
 

	
 

	
 
void chess_Step(uint8_t keycode)
 
{
 
  if ( keycode == CHESS_KEY_NONE )
 
  {
 
    chess_key_cmd = chess_key_code;
 
    chess_key_code = CHESS_KEY_NONE;
 
  }
 
  else
 
  {
 
    chess_key_cmd = CHESS_KEY_NONE;
 
    chess_key_code = keycode;
 
  }
 
  //chess_ComputerMove(2);
 
  switch(chess_state)
 
  {
 
    case CHESS_STATE_MENU:
 
      mnu_Step(chess_key_cmd);
 
      if ( chess_key_cmd == CHESS_KEY_SELECT )
 
      {
 
	if ( mnu_pos == 0 )
 
	{
 
          chess_SetupBoard();
 
	  lrc_obj.orientation = 0;
 
	  chess_state = CHESS_STATE_SELECT_START;
 
	}
 
	else if ( mnu_pos == 1 )
 
	{
 
          chess_SetupBoard();
 
	  lrc_obj.orientation = 1;
 
	  chess_state = CHESS_STATE_THINKING;
 
	}
 
	else if ( mnu_pos == 2 )
 
	{
 
	  if ( lrc_obj.ply_count >= 2 )
 
	  {
 
	    cu_UndoHalfMove();
 
	    cu_UndoHalfMove();
 
	    lrc_obj.ply_count-=2;
 
	    if ( lrc_obj.ply_count == 0 )
 
	      mnu_pos = 0;
 
	  }
 
	  chess_state = CHESS_STATE_SELECT_START;
 
	}
 
	else if ( mnu_pos == 3 )
 
	{
 
	  chess_state = CHESS_STATE_SELECT_START;
 
	}
 
      }
 
      break;
 
    case CHESS_STATE_SELECT_START:
 
      chess_ClearMarks();
 
      chess_MarkMovable();
 
      chess_source_pos = chess_GetNextMarked(255, 0);
 
      chess_target_pos = ILLEGAL_POSITION;
 
      chess_state = CHESS_STATE_SELECT_PIECE;
 
      break;
 
      
 
    case CHESS_STATE_SELECT_PIECE:
 
      if ( chess_key_cmd == CHESS_KEY_NEXT )
 
      {
 
	chess_source_pos = chess_GetNextMarked(chess_source_pos, 0);
 
      }
 
      else if ( chess_key_cmd == CHESS_KEY_PREV )
 
      {
 
	chess_source_pos = chess_GetNextMarked(chess_source_pos, 1);
 
      }
 
      else if ( chess_key_cmd == CHESS_KEY_SELECT )
 
      {
 
	if ( chess_source_pos == 255 )
 
	{
 
	  chess_state = CHESS_STATE_MENU;
 
	}
 
	else
 
	{
 
	  chess_ClearMarks();
 
	  chess_MarkTargetMoves(chess_source_pos);
 
	  chess_target_pos = chess_GetNextMarked(255, 0);
 
	  chess_state = CHESS_STATE_SELECT_TARGET_POS;      
 
	}
 
      }
 
      break;
 
    case CHESS_STATE_SELECT_TARGET_POS:
 
      if ( chess_key_cmd == CHESS_KEY_NEXT )
 
      {
 
	chess_target_pos = chess_GetNextMarked(chess_target_pos, 0);
 
      }
 
      else if ( chess_key_cmd == CHESS_KEY_PREV )
 
      {
 
	chess_target_pos = chess_GetNextMarked(chess_target_pos, 1);
 
      }
 
      else if ( chess_key_cmd == CHESS_KEY_BACK )
 
      {
 
	chess_ClearMarks();
 
	chess_MarkMovable();
 
	chess_target_pos = ILLEGAL_POSITION;
 
	chess_state = CHESS_STATE_SELECT_PIECE;
 
      }
 
      else if ( chess_key_cmd == CHESS_KEY_SELECT )
 
      {
 
	chess_ManualMove(chess_source_pos, chess_target_pos);
 
	if ( lrc_obj.is_game_end != 0 )
 
	  chess_state = CHESS_STATE_GAME_END;
 
	else
 
	  chess_state = CHESS_STATE_THINKING;
 
	/* clear marks as some kind of feedback to the user... it simply looks better */
 
	chess_source_pos = ILLEGAL_POSITION;
 
	chess_target_pos = ILLEGAL_POSITION;
 
	chess_ClearMarks();
 
      }
 
      break;
 
    case CHESS_STATE_THINKING:
 
      chess_ComputerMove(2);
 
      if ( lrc_obj.is_game_end != 0 )
 
	chess_state = CHESS_STATE_GAME_END;
 
      else
 
	chess_state = CHESS_STATE_SELECT_START;
 
      break;
 
    case CHESS_STATE_GAME_END:
 
      if ( chess_key_cmd != CHESS_KEY_NONE )
 
      {
 
	chess_state = CHESS_STATE_MENU;  
 
	chess_SetupBoard();
 
      }	
 
      break;
 
  }
 
  
 
}
 

	
 
#endif
 

	
 

	
Libraries/u8glib/u8g.h
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g.h
 
  
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2011, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
  
 
*/
 

	
 
#ifndef _U8G_H
 
#define _U8G_H
 

	
 
/* uncomment the following line to support displays larger than 240x240 */
 
//#define U8G_16BIT 1
 

	
 
/* comment the following line to generate more compact but interrupt unsafe code */
 
#define U8G_INTERRUPT_SAFE 1
 

	
 

	
 
#include <stddef.h>
 

	
 
#ifdef __18CXX
 
typedef unsigned char uint8_t;
 
typedef signed char int8_t;
 
typedef unsigned short uint16_t;
 
typedef signed short int16_t;
 
#else
 
#include <stdint.h>
 
#endif
 

	
 
#if defined(__AVR__)
 
#include <avr/pgmspace.h>
 
#endif 
 

	
 
/* 
 
  use the com interface directly on any systems which are not AVR or ARDUINO 
 
*/
 
#if defined(__AVR__) || defined(ARDUINO)
 
#define U8G_WITH_PINLIST
 
#endif
 

	
 

	
 
#ifdef __cplusplus
 
extern "C" {
 
#endif
 

	
 
  
 
/*===============================================================*/
 
#ifdef __GNUC__
 
#  define U8G_NOINLINE __attribute__((noinline))
 
#  define U8G_PURE  __attribute__ ((pure))
 
#  define U8G_NOCOMMON __attribute__ ((nocommon))
 
#  define U8G_SECTION(name) __attribute__ ((section (name)))
 
#  if defined(__MSPGCC__)
 
/* mspgcc does not have .progmem sections. Use -fdata-sections. */
 
#    define U8G_FONT_SECTION(name)
 
#  endif
 
#  if defined(__AVR__)
 
#    define U8G_FONT_SECTION(name) U8G_SECTION(".progmem." name)
 
#  endif
 
#else
 
#  define U8G_NOINLINE
 
#  define U8G_PURE
 
#  define U8G_NOCOMMON
 
#  define U8G_SECTION(name)
 
#  define U8G_FONT_SECTION(name)
 
#endif
 

	
 
#ifndef U8G_FONT_SECTION
 
#  define U8G_FONT_SECTION(name)
 
#endif
 

	
 

	
 
/*===============================================================*/
 
/* flash memory access */
 

	
 
#if defined(__AVR__)
 
/* U8G_PROGMEM is used by the XBM example */
 
#define U8G_PROGMEM U8G_SECTION(".progmem.data")
 
typedef uint8_t PROGMEM u8g_pgm_uint8_t;
 
typedef uint8_t u8g_fntpgm_uint8_t;
 
#define u8g_pgm_read(adr) pgm_read_byte_near(adr)
 
#define U8G_PSTR(s) ((u8g_pgm_uint8_t *)PSTR(s))
 

	
 
#else
 

	
 
#define U8G_PROGMEM
 
#define PROGMEM
 
typedef uint8_t u8g_pgm_uint8_t;
 
typedef uint8_t u8g_fntpgm_uint8_t;
 
#define u8g_pgm_read(adr) (*(const u8g_pgm_uint8_t *)(adr)) 
 
#define U8G_PSTR(s) ((u8g_pgm_uint8_t *)(s))
 

	
 
#endif
 
  
 
/*===============================================================*/
 
/* interrupt safe code */
 
#if defined(U8G_INTERRUPT_SAFE)
 
#  if defined(__AVR__)
 
extern uint8_t global_SREG_backup;	/* u8g_state.c */
 
#    define U8G_ATOMIC_START()		do { global_SREG_backup = SREG; cli(); } while(0)
 
#    define U8G_ATOMIC_END()			SREG = global_SREG_backup
 
#    define U8G_ATOMIC_OR(ptr, val) 	do { uint8_t tmpSREG = SREG; cli(); (*(ptr) |= (val)); SREG = tmpSREG; } while(0)
 
#    define U8G_ATOMIC_AND(ptr, val) 	do { uint8_t tmpSREG = SREG; cli(); (*(ptr) &= (val)); SREG = tmpSREG; } while(0)
 
#  else
 
#    define U8G_ATOMIC_OR(ptr, val) (*(ptr) |= (val))
 
#    define U8G_ATOMIC_AND(ptr, val) (*(ptr) &= (val))
 
#    define U8G_ATOMIC_START()
 
#    define U8G_ATOMIC_END()
 
#  endif /* __AVR__ */
 
#else
 
#  define U8G_ATOMIC_OR(ptr, val) (*(ptr) |= (val))
 
#  define U8G_ATOMIC_AND(ptr, val) (*(ptr) &= (val))
 
#  define U8G_ATOMIC_START()
 
#  define U8G_ATOMIC_END()
 
#endif /* U8G_INTERRUPT_SAFE */
 
  
 
  
 
/*===============================================================*/
 
/* forward */
 
typedef struct _u8g_t u8g_t;
 
typedef struct _u8g_dev_t u8g_dev_t;
 

	
 
typedef struct _u8g_dev_arg_pixel_t u8g_dev_arg_pixel_t;
 
typedef struct _u8g_dev_arg_bbx_t u8g_dev_arg_bbx_t;
 
typedef struct _u8g_box_t u8g_box_t;
 
typedef struct _u8g_dev_arg_irgb_t u8g_dev_arg_irgb_t;
 

	
 

	
 
/*===============================================================*/
 
/* generic */
 
#if defined(U8G_16BIT)
 
typedef uint16_t u8g_uint_t;
 
typedef int16_t u8g_int_t;
 
#else
 
typedef uint8_t u8g_uint_t;
 
typedef int8_t u8g_int_t;
 
#endif
 

	
 
#ifdef OBSOLETE
 
struct _u8g_box_t
 
{
 
  u8g_uint_t x0, y0, x1, y1;  
 
};
 
typedef struct _u8g_box_t u8g_box_t;
 
#endif /* OBSOLETE */
 

	
 

	
 
/*===============================================================*/
 
/* device structure */
 

	
 
#ifdef __XC8
 
/* device prototype */
 
typedef uint8_t (*u8g_dev_fnptr)(void *u8g, void *dev, uint8_t msg, void *arg);
 

	
 
/* com prototype */
 
typedef uint8_t (*u8g_com_fnptr)(void *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
 
#else
 
/* device prototype */
 
typedef uint8_t (*u8g_dev_fnptr)(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 
/* com prototype */
 
typedef uint8_t (*u8g_com_fnptr)(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
 
#endif
 

	
 

	
 

	
 
struct _u8g_dev_t
 
{
 
  u8g_dev_fnptr dev_fn;         /* device procedure */
 
  void *dev_mem;                /* device memory */
 
  u8g_com_fnptr com_fn;         /* communication procedure */
 
};
 

	
 

	
 
/*===============================================================*/
 
/* device list */
 

	
 
/* Size: 128x64 SDL, u8g_dev_sdl.c */
 
extern u8g_dev_t u8g_dev_sdl_1bit;
 
extern u8g_dev_t u8g_dev_sdl_1bit_h;
 
extern u8g_dev_t u8g_dev_sdl_2bit;
 
extern u8g_dev_t u8g_dev_sdl_2bit_double_mem;
 
extern u8g_dev_t u8g_dev_sdl_8bit;
 
extern u8g_dev_t u8g_dev_sdl_hicolor;
 
extern u8g_dev_t u8g_dev_sdl_fullcolor;
 
int u8g_sdl_get_key(void);
 

	
 
/* Size: 70x30 monochrom, stdout */
 
extern u8g_dev_t u8g_dev_stdout;
 

	
 
/* Size: monochrom, writes "u8g.pbm" */
 
extern u8g_dev_t u8g_dev_pbm;
 
extern u8g_dev_t u8g_dev_pbm_8h1;
 
extern u8g_dev_t u8g_dev_pbm_8h2;	/* grayscale simulation */
 

	
 
/* Size: 128x64 monochrom, no output, used for performance measure */
 
extern u8g_dev_t u8g_dev_gprof;
 

	
 
/* Display: EA DOGS102, Size: 102x64 monochrom */
 
extern u8g_dev_t u8g_dev_uc1701_dogs102_sw_spi;
 
extern u8g_dev_t u8g_dev_uc1701_dogs102_hw_spi;
 

	
 
extern u8g_dev_t u8g_dev_uc1701_dogs102_2x_sw_spi;
 
extern u8g_dev_t u8g_dev_uc1701_dogs102_2x_hw_spi;
 

	
 
/* Display: Mini12864 (dealextreme), Size: 128x64 monochrom */
 
extern u8g_dev_t u8g_dev_uc1701_mini12864_sw_spi;
 
extern u8g_dev_t u8g_dev_uc1701_mini12864_hw_spi;
 

	
 
extern u8g_dev_t u8g_dev_uc1701_mini12864_2x_sw_spi;
 
extern u8g_dev_t u8g_dev_uc1701_mini12864_2x_hw_spi;
 

	
 
/* Display: EA DOGM132, Size: 128x32 monochrom */
 
extern u8g_dev_t u8g_dev_st7565_dogm132_sw_spi;
 
extern u8g_dev_t u8g_dev_st7565_dogm132_hw_spi;
 

	
 
/* Display: EA DOGM128, Size: 128x64 monochrom */
 
extern u8g_dev_t u8g_dev_st7565_dogm128_sw_spi;
 
extern u8g_dev_t u8g_dev_st7565_dogm128_hw_spi;
 
extern u8g_dev_t u8g_dev_st7565_dogm128_parallel;
 

	
 
extern u8g_dev_t u8g_dev_st7565_dogm128_2x_sw_spi;
 
extern u8g_dev_t u8g_dev_st7565_dogm128_2x_hw_spi;
 
extern u8g_dev_t u8g_dev_st7565_dogm128_2x_parallel;
 

	
 
/* Display: Topway LM6059 128x64 (Adafruit) */
 
extern u8g_dev_t u8g_dev_st7565_lm6059_sw_spi;
 
extern u8g_dev_t u8g_dev_st7565_lm6059_hw_spi;
 
extern u8g_dev_t u8g_dev_st7565_lm6059_2x_sw_spi;
 
extern u8g_dev_t u8g_dev_st7565_lm6059_2x_hw_spi;
 
/* Display: Topway LM6063 128x64 */
 
extern u8g_dev_t u8g_dev_st7565_lm6063_sw_spi;
 
extern u8g_dev_t u8g_dev_st7565_lm6063_hw_spi;
 
extern u8g_dev_t u8g_dev_st7565_lm6063_2x_sw_spi;
 
extern u8g_dev_t u8g_dev_st7565_lm6063_2x_hw_spi;
 
/* Display: Newhaven NHD-C12864 */
 
extern u8g_dev_t u8g_dev_st7565_nhd_c12864_sw_spi;
 
extern u8g_dev_t u8g_dev_st7565_nhd_c12864_hw_spi;
 
extern u8g_dev_t u8g_dev_st7565_nhd_c12864_2x_sw_spi;
 
extern u8g_dev_t u8g_dev_st7565_nhd_c12864_2x_hw_spi;
 

	
 
/* Display: Newhaven NHD-C12832 */
 
extern u8g_dev_t u8g_dev_st7565_nhd_c12832_sw_spi;
 
extern u8g_dev_t u8g_dev_st7565_nhd_c12832_hw_spi;
 
extern u8g_dev_t u8g_dev_st7565_nhd_c12832_parallel;
 
extern u8g_dev_t u8g_dev_st7565_nhd_c12832_hw_usart_spi;
 

	
 
/* Display: Displaytech 64128N */
 
extern u8g_dev_t u8g_dev_st7565_64128n_sw_spi;
 
extern u8g_dev_t u8g_dev_st7565_64128n_hw_spi;
 
extern u8g_dev_t u8g_dev_st7565_64128n_parallel;
 

	
 
extern u8g_dev_t u8g_dev_st7565_64128n_2x_sw_spi;
 
extern u8g_dev_t u8g_dev_st7565_64128n_2x_hw_spi;
 
extern u8g_dev_t u8g_dev_st7565_64128n_2x_parallel;
 

	
 
/* Display: LCD-AG-C128032R-DIW W/KK E6 PBF */
 
extern u8g_dev_t u8g_dev_uc1601_c128032_sw_spi;
 
extern u8g_dev_t u8g_dev_uc1601_c128032_hw_spi;
 

	
 
extern u8g_dev_t u8g_dev_uc1601_c128032_2x_sw_spi;
 
extern u8g_dev_t u8g_dev_uc1601_c128032_2x_hw_spi;
 

	
 
/* East Rising/buy-display.com ERC24064-1 */
 
extern u8g_dev_t u8g_dev_uc1608_240x64_sw_spi;
 
extern u8g_dev_t u8g_dev_uc1608_240x64_hw_spi;
 

	
 
extern u8g_dev_t u8g_dev_uc1608_240x64_2x_sw_spi;
 
extern u8g_dev_t u8g_dev_uc1608_240x64_2x_hw_spi;
 

	
 
/* dfrobot 128x64 Graphic LCD (SKU:FIT0021) */
 
extern u8g_dev_t u8g_dev_st7920_128x64_sw_spi;
 
extern u8g_dev_t u8g_dev_st7920_128x64_hw_spi;
 
extern u8g_dev_t u8g_dev_st7920_128x64_8bit;
 
extern u8g_dev_t u8g_dev_st7920_128x64_custom;
 

	
 
extern u8g_dev_t u8g_dev_st7920_128x64_4x_sw_spi;
 
extern u8g_dev_t u8g_dev_st7920_128x64_4x_hw_spi;
 
extern u8g_dev_t u8g_dev_st7920_128x64_4x_8bit;
 
extern u8g_dev_t u8g_dev_st7920_128x64_4x_custom;
 

	
 
/* NHD-19232WG */
 
extern u8g_dev_t u8g_dev_st7920_192x32_sw_spi;
 
extern u8g_dev_t u8g_dev_st7920_192x32_hw_spi;
 
extern u8g_dev_t u8g_dev_st7920_192x32_8bit;
 

	
 
extern u8g_dev_t u8g_dev_st7920_192x32_4x_sw_spi;
 
extern u8g_dev_t u8g_dev_st7920_192x32_4x_hw_spi;
 
extern u8g_dev_t u8g_dev_st7920_192x32_4x_8bit;
 

	
 
/* CrystalFontz CFAG20232 */
 
extern u8g_dev_t u8g_dev_st7920_202x32_sw_spi;
 
extern u8g_dev_t u8g_dev_st7920_202x32_hw_spi;
 
extern u8g_dev_t u8g_dev_st7920_202x32_8bit;
 

	
 
extern u8g_dev_t u8g_dev_st7920_202x32_4x_sw_spi;
 
extern u8g_dev_t u8g_dev_st7920_202x32_4x_hw_spi;
 
extern u8g_dev_t u8g_dev_st7920_202x32_4x_8bit;
 

	
 
/* LC7981 160x80 display */
 
extern u8g_dev_t u8g_dev_lc7981_160x80_8bit;
 
/* LC7981 240x64 display */
 
extern u8g_dev_t u8g_dev_lc7981_240x64_8bit;
 
/* LC7981 240x128 display */
 
extern u8g_dev_t u8g_dev_lc7981_240x128_8bit;
 
/* LC7981 320x64 display */
 
extern u8g_dev_t u8g_dev_lc7981_320x64_8bit;
 

	
 
/* T6963, all t6963 devices have double page (2x) */
 
extern u8g_dev_t u8g_dev_t6963_240x128_8bit;
 
extern u8g_dev_t u8g_dev_t6963_240x64_8bit;
 
extern u8g_dev_t u8g_dev_t6963_128x64_8bit;
 

	
 
/* Display: EA DOGXL160, Size: 160x104 monochrom & gray level */
 
extern u8g_dev_t u8g_dev_uc1610_dogxl160_bw_sw_spi;
 
extern u8g_dev_t u8g_dev_uc1610_dogxl160_bw_hw_spi;
 
extern u8g_dev_t u8g_dev_uc1610_dogxl160_gr_sw_spi;
 
extern u8g_dev_t u8g_dev_uc1610_dogxl160_gr_hw_spi;
 

	
 
extern u8g_dev_t u8g_dev_uc1610_dogxl160_2x_bw_sw_spi;
 
extern u8g_dev_t u8g_dev_uc1610_dogxl160_2x_bw_hw_spi;
 
extern u8g_dev_t u8g_dev_uc1610_dogxl160_2x_gr_sw_spi;
 
extern u8g_dev_t u8g_dev_uc1610_dogxl160_2x_gr_hw_spi;
 

	
 
/* Display: Generic KS0108b, Size: 128x64 monochrom */
 
extern u8g_dev_t u8g_dev_ks0108_128x64;         /* official Arduino Library interface */
 
extern u8g_dev_t u8g_dev_ks0108_128x64_fast;    /* faster, but uses private tables from the Arduino Library */
 

	
 
/* Nokia 84x48 Display with PCD8544 */
 
extern u8g_dev_t u8g_dev_pcd8544_84x48_sw_spi;
 
extern u8g_dev_t u8g_dev_pcd8544_84x48_hw_spi;
 
extern u8g_dev_t u8g_dev_tls8204_84x48_sw_spi;
 

	
 
/* Nokia 96x65 Display with PCF8812 */
 
extern u8g_dev_t u8g_dev_pcf8812_96x65_sw_spi;
 
extern u8g_dev_t u8g_dev_pcf8812_96x65_hw_spi;
 

	
 
/* NHD-2.7-12864UCY3 OLED Display with SSD1325 Controller */
 
extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_bw_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_bw_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_bw_parallel;
 
extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_gr_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_gr_hw_spi;
 

	
 
extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_bw_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_bw_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_bw_parallel;
 
extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_gr_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1325_nhd27oled_2x_gr_hw_spi;
 

	
 
/* LY120 OLED with SSD1327 Controller (tested with Seeedstudio module) */
 
extern u8g_dev_t u8g_dev_ssd1327_96x96_gr_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1327_96x96_gr_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1327_96x96_gr_i2c;
 

	
 
extern u8g_dev_t u8g_dev_ssd1327_96x96_2x_gr_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1327_96x96_2x_gr_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1327_96x96_2x_gr_i2c;
 

	
 
/* NHD-3.12-25664 OLED Display with SSD1322 Controller */
 
extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_bw_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_bw_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_bw_parallel;
 
extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_bw_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_bw_hw_spi;
 

	
 
extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_gr_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_gr_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_gr_parallel;
 
extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_gr_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1322_nhd31oled_2x_gr_hw_spi;
 

	
 
/* OLED 128x64 Display with SSD1306 Controller */
 
extern u8g_dev_t u8g_dev_ssd1306_128x64_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1306_128x64_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1306_128x64_i2c;
 

	
 
extern u8g_dev_t u8g_dev_ssd1306_128x64_2x_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1306_128x64_2x_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1306_128x64_2x_i2c;
 

	
 
/* OLED 128x64 Display with SSD1309 Controller */
 
extern u8g_dev_t u8g_dev_ssd1309_128x64_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1309_128x64_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1309_128x64_i2c;
 

	
 
/* OLED 128x32 Display with SSD1306 Controller */
 
extern u8g_dev_t u8g_dev_ssd1306_128x32_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1306_128x32_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1306_128x32_i2c;
 

	
 
extern u8g_dev_t u8g_dev_ssd1306_128x32_2x_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1306_128x32_2x_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1306_128x32_2x_i2c;
 

	
 
/* experimental 65K TFT with st7687 controller */
 
extern u8g_dev_t u8g_dev_st7687_c144mvgd_sw_spi;
 
extern u8g_dev_t u8g_dev_st7687_c144mvgd_8bit;
 

	
 
/* SBN1661/SED1520 display with 122x32 */
 
extern u8g_dev_t u8g_dev_sbn1661_122x32;
 

	
 
/* flip disc matrix */
 
extern u8g_dev_t u8g_dev_flipdisc_2x7;
 
void u8g_SetFlipDiscCallback(u8g_t *u8g, void (*cb)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2));
 

	
 
/* ILI9325D based TFT */
 
extern u8g_dev_t u8g_dev_ili9325d_320x240_8bit;
 

	
 

	
 
/* SSD1351 OLED (breakout board from http://www.kickstarter.com/projects/ilsoftltd/colour-oled-breakout-board) */
 
extern u8g_dev_t u8g_dev_ssd1351_128x128_332_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128_332_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128_4x_332_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128_4x_332_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128_idx_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128_idx_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128_hicolor_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128_hicolor_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128_4x_hicolor_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128_4x_hicolor_hw_spi;
 

	
 
/* SSD1351 OLED (Freetronics, GPIOs set to high level) */
 
extern u8g_dev_t u8g_dev_ssd1351_128x128gh_332_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128gh_332_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_332_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_332_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128gh_hicolor_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128gh_hicolor_hw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_hicolor_sw_spi;
 
extern u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_hicolor_hw_spi;
 

	
 
/* HT1632 */
 
extern u8g_dev_t u8g_dev_ht1632_24x16;
 

	
 
/* A2 Micro Printer */
 
extern u8g_dev_t u8g_dev_a2_micro_printer_384x240;
 
extern u8g_dev_t u8g_dev_a2_micro_printer_192x120_ds;
 
extern u8g_dev_t u8g_dev_a2_micro_printer_192x360_ds;
 
extern u8g_dev_t u8g_dev_a2_micro_printer_192x720_ds;
 

	
 
/* u8g_virtual_screen.c  */
 
extern u8g_dev_t u8g_dev_vs;
 

	
 

	
 
/*===============================================================*/
 
/* device messages */
 

	
 
struct _u8g_dev_arg_pixel_t
 
{
 
  u8g_uint_t x, y;              /* will be modified */
 
  uint8_t pixel;                  /* will be modified, pixel sequence or transparency value */
 
  uint8_t dir;
 
  uint8_t color;			/* color or index value, red value for true color mode */
 
  uint8_t hi_color;		/* high byte for 64K color mode, low byte is in "color", green value for true color mode */
 
  uint8_t blue;			/* blue value in true color mode */
 
};
 
/* typedef struct _u8g_dev_arg_pixel_t u8g_dev_arg_pixel_t; */ /* forward decl */
 

	
 
/* range for r,g,b: 0..255 */
 
#define U8G_GET_HICOLOR_BY_RGB(r,g,b) (((uint16_t)((r)&0x0f8))<<8)|(((uint16_t)((g)&0x0fc))<<3)|(((uint16_t)((b)>>3)))
 

	
 
struct _u8g_dev_arg_bbx_t
 
{
 
  u8g_uint_t x, y, w, h;
 
};
 
/* typedef struct _u8g_dev_arg_bbx_t u8g_dev_arg_bbx_t; */ /* forward decl */
 

	
 
struct _u8g_box_t
 
{
 
  u8g_uint_t x0, y0, x1, y1;
 
};
 
/* typedef struct _u8g_box_t u8g_box_t; */ /* forward decl */
 

	
 
struct _u8g_dev_arg_irgb_t
 
{
 
  u8g_uint_t idx, r, g, b;		/* index with rgb value */
 
};
 
/* typedef struct _u8g_dev_arg_irgb_t u8g_dev_arg_irgb_t; */ /* forward decl */
 

	
 

	
 

	
 
#define U8G_DEV_MSG_INIT                10
 
#define U8G_DEV_MSG_STOP                  11
 

	
 
/* arg: pointer to uint8_t, contranst value between 0 and 255 */
 
#define U8G_DEV_MSG_CONTRAST            15
 

	
 
#define U8G_DEV_MSG_SLEEP_ON            16
 
#define U8G_DEV_MSG_SLEEP_OFF            17
 

	
 
#define U8G_DEV_MSG_PAGE_FIRST                  20
 
#define U8G_DEV_MSG_PAGE_NEXT                    21
 

	
 
/* arg: u8g_dev_arg_bbx_t * */
 
/* new algorithm with U8G_DEV_MSG_GET_PAGE_BOX makes this msg obsolete */
 
/* #define U8G_DEV_MSG_IS_BBX_INTERSECTION 22 */
 

	
 
/* arg: u8g_box_t *, fill structure with current page properties */
 
#define U8G_DEV_MSG_GET_PAGE_BOX 23
 

	
 
/*
 
#define U8G_DEV_MSG_PRIMITIVE_START             30
 
#define U8G_DEV_MSG_PRIMITIVE_END               31
 
*/
 

	
 
/* arg: u8g_dev_arg_pixel_t * */
 
#define U8G_DEV_MSG_SET_TPIXEL				44
 
#define U8G_DEV_MSG_SET_4TPIXEL			45
 

	
 
#define U8G_DEV_MSG_SET_PIXEL                           50
 
#define U8G_DEV_MSG_SET_8PIXEL                          59
 

	
 
#define U8G_DEV_MSG_SET_COLOR_ENTRY                60
 

	
 
#define U8G_DEV_MSG_SET_XY_CB                           61
 

	
 
#define U8G_DEV_MSG_GET_WIDTH                           70
 
#define U8G_DEV_MSG_GET_HEIGHT                           71
 
#define U8G_DEV_MSG_GET_MODE                  72
 

	
 
/*===============================================================*/
 
/* device modes */
 
#define U8G_MODE(is_index_mode, is_color, bits_per_pixel) (((is_index_mode)<<6) | ((is_color)<<5)|(bits_per_pixel))
 

	
 
#define U8G_MODE_UNKNOWN     0
 
#define U8G_MODE_BW     U8G_MODE(0, 0, 1)
 
#define U8G_MODE_GRAY2BIT     U8G_MODE(0, 0, 2)
 
#define U8G_MODE_R3G3B2  U8G_MODE(0, 1, 8)
 
#define U8G_MODE_INDEX  U8G_MODE(1, 1, 8)
 
/* hicolor is R5G6B5 */
 
#define U8G_MODE_HICOLOR  U8G_MODE(0, 1, 16)
 
/* truecolor  */
 
#define U8G_MODE_TRUECOLOR  U8G_MODE(0, 1, 24)
 

	
 

	
 
#define U8G_MODE_GET_BITS_PER_PIXEL(mode) ((mode)&31)
 
#define U8G_MODE_IS_COLOR(mode) (((mode)&32)==0?0:1)
 
#define U8G_MODE_IS_INDEX_MODE(mode) (((mode)&64)==0?0:1)
 

	
 

	
 
/*===============================================================*/
 
/* com options */
 

	
 
/* uncomment the following line for Atmega HW SPI double speed, issue 89 */
 
/* #define U8G_HW_SPI_2X 1 */
 

	
 
/* com messages */
 

	
 
#define U8G_COM_MSG_STOP        0
 
#define U8G_COM_MSG_INIT        1
 

	
 
#define U8G_COM_MSG_ADDRESS 2
 

	
 
/* CHIP_SELECT argument: number of the chip which needs to be activated, so this is more like high active */
 
#define U8G_COM_MSG_CHIP_SELECT 3
 

	
 
#define U8G_COM_MSG_RESET 4
 

	
 
#define U8G_COM_MSG_WRITE_BYTE 5
 
#define U8G_COM_MSG_WRITE_SEQ 6
 
#define U8G_COM_MSG_WRITE_SEQ_P 7
 

	
 

	
 
/* com driver */
 
uint8_t u8g_com_null_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);               /* u8g_com_null.c */
 
uint8_t u8g_com_arduino_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);        /* u8g_com_arduino_std_sw_spi.c */
 
uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);      /* u8g_com_atmega_hw_usart_spi.c */
 
uint8_t u8g_com_arduino_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);        /* u8g_com_arduino_sw_spi.c */
 
uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);          /* u8g_com_arduino_hw_spi.c */
 
uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);          /* u8g_arduino_ATTiny85_std_hw_spi.c */
 
uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);  /* u8g_com_arduino_st7920_spi.c */
 
uint8_t u8g_com_arduino_st7920_custom_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); /* u8g_com_arduino_st7920_custom.c */
 
uint8_t u8g_com_arduino_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);  /* u8g_com_arduino_st7920_hw_spi.c */
 
uint8_t u8g_com_arduino_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);           /* u8g_com_arduino_parallel.c */
 
uint8_t u8g_com_arduino_fast_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);      /* u8g_com_arduino_fast_parallel.c */
 
uint8_t u8g_com_arduino_port_d_wr_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);       /* u8g_com_arduino_port_d_wr.c */
 
uint8_t u8g_com_arduino_no_en_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);	/* u8g_com_arduino_no_en_parallel.c */		
 
uint8_t u8g_com_arduino_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);		/* u8g_com_arduino_ssd_i2c.c */
 
uint8_t u8g_com_arduino_t6963_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);			/* u8g_com_arduino_t6963.c */
 

	
 

	
 
uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);      /* u8g_com_atmega_hw_spi.c */
 
uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);      /* u8g_com_atmega_sw_spi.c */
 
uint8_t u8g_com_atmega_st7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);	/* u8g_com_atmega_st7920_spi.c */
 
uint8_t u8g_com_atmega_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
 
uint8_t u8g_com_atmega_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);    /* u8g_com_atmega_parallel.c */
 

	
 

	
 
/* 
 
  Translation of system specific com drives to generic com names
 
  At the moment, the following generic com drives are available
 
  U8G_COM_HW_SPI
 
  U8G_COM_SW_SPI
 
  U8G_COM_PARALLEL
 
  U8G_COM_T6963
 
  U8G_COM_FAST_PARALLEL
 
  U8G_COM_SSD_I2C
 
  
 
defined(__18CXX) || defined(__PIC32MX)  
 

	
 
*/
 
/* ==== HW SPI, Arduino ====*/
 
#if defined(ARDUINO)
 
#if defined(__AVR__)
 

	
 
#if defined(__AVR_ATtiny85__)
 
#define U8G_COM_HW_SPI u8g_com_arduino_ATtiny85_std_hw_spi_fn
 
#define U8G_COM_ST7920_HW_SPI u8g_com_null_fn
 
#else
 

	
 
#define U8G_COM_HW_SPI u8g_com_arduino_hw_spi_fn
 
#if defined(__AVR_ATmega32U4__)
 
#define U8G_COM_HW_USART_SPI u8g_com_arduino_hw_usart_spi_fn
 
#endif /* __AVR_ATmega32U4__ */
 
#define U8G_COM_ST7920_HW_SPI u8g_com_arduino_st7920_hw_spi_fn
 
#endif /* __AVR_ATtiny85__ */
 

	
 
#elif defined(__18CXX) || defined(__PIC32MX)
 
#define U8G_COM_HW_SPI u8g_com_null_fn
 
#define U8G_COM_ST7920_HW_SPI u8g_com_null_fn
 
#elif defined(__SAM3X8E__)   /* Arduino Due */
 
#define U8G_COM_HW_SPI u8g_com_arduino_hw_spi_fn
 
#define U8G_COM_ST7920_HW_SPI u8g_com_null_fn
 
#endif
 
#endif
 
/* ==== HW SPI, not Arduino ====*/
 
#ifndef U8G_COM_HW_SPI
 
#if defined(__AVR__)
 
#define U8G_COM_HW_SPI u8g_com_atmega_hw_spi_fn
 
#define U8G_COM_ST7920_HW_SPI u8g_com_atmega_st7920_hw_spi_fn
 
#endif
 
#endif
 
#ifndef U8G_COM_HW_SPI
 
#define U8G_COM_HW_SPI u8g_com_null_fn
 
#define U8G_COM_ST7920_HW_SPI u8g_com_null_fn
 
#endif
 

	
 
#ifndef U8G_COM_HW_USART_SPI
 
#define U8G_COM_HW_USART_SPI u8g_com_null_fn
 
#endif
 

	
 

	
 
/* ==== SW SPI, Arduino ====*/
 
#if defined(ARDUINO)
 
#if defined(__AVR__)
 
#define U8G_COM_SW_SPI u8g_com_arduino_sw_spi_fn
 
#define U8G_COM_ST7920_SW_SPI u8g_com_arduino_st7920_spi_fn
 
#elif defined(__18CXX) || defined(__PIC32MX)
 
#define U8G_COM_SW_SPI u8g_com_arduino_sw_spi_fn
 
#define U8G_COM_ST7920_SW_SPI u8g_com_arduino_st7920_spi_fn
 
#elif defined(__SAM3X8E__)   /* Arduino Due */
 
//#define U8G_COM_SW_SPI u8g_com_arduino_std_sw_spi_fn
 
#define U8G_COM_SW_SPI u8g_com_arduino_sw_spi_fn
 
#define U8G_COM_ST7920_SW_SPI u8g_com_arduino_st7920_spi_fn
 
#elif defined(__arm__)   /* Teensy */
 
#define U8G_COM_SW_SPI u8g_com_arduino_std_sw_spi_fn
 
#define U8G_COM_ST7920_SW_SPI u8g_com_arduino_st7920_spi_fn
 
#endif
 
#endif
 

	
 
#ifndef U8G_COM_SW_SPI
 
/* ==== SW SPI, not Arduino ====*/
 
#if defined(__AVR__)
 
#define U8G_COM_SW_SPI u8g_com_atmega_sw_spi_fn
 
#define U8G_COM_ST7920_SW_SPI u8g_com_atmega_st7920_sw_spi_fn
 
#endif
 
#endif
 
#ifndef U8G_COM_SW_SPI
 
#define U8G_COM_SW_SPI u8g_com_null_fn
 
#define U8G_COM_ST7920_SW_SPI u8g_com_null_fn
 
#endif
 

	
 
/* ==== Parallel iinterface, Arduino ====*/
 
#if defined(ARDUINO)
 
#if defined(__AVR__)
 
#define U8G_COM_PARALLEL u8g_com_arduino_parallel_fn
 
#define U8G_COM_FAST_PARALLEL u8g_com_arduino_fast_parallel_fn
 
#define U8G_COM_T6963  u8g_com_arduino_t6963_fn
 
#else /* Arduino Due, Chipkit PIC32 */
 
#define U8G_COM_PARALLEL u8g_com_arduino_parallel_fn
 
#define U8G_COM_FAST_PARALLEL u8g_com_arduino_parallel_fn
 
#define U8G_COM_T6963  u8g_com_null_fn
 
#endif
 
#endif
 
#ifndef U8G_COM_PARALLEL
 
#if defined(__AVR__)
 
#define U8G_COM_PARALLEL u8g_com_atmega_parallel_fn
 
#define U8G_COM_FAST_PARALLEL u8g_com_atmega_parallel_fn
 
#define U8G_COM_T6963  u8g_com_null_fn
 
#endif
 
#endif
 
#ifndef U8G_COM_PARALLEL
 
#define U8G_COM_PARALLEL u8g_com_null_fn
 
#define U8G_COM_FAST_PARALLEL u8g_com_null_fn
 
#define U8G_COM_T6963  u8g_com_null_fn
 
#endif
 

	
 
#if defined(ARDUINO)
 
#if defined(__AVR__)
 
#define U8G_COM_SSD_I2C u8g_com_arduino_ssd_i2c_fn
 
#endif
 
#endif
 

	
 
#ifndef U8G_COM_SSD_I2C
 
#if defined(__AVR__)
 
/* AVR variant can use the arduino version at the moment */
 
#define U8G_COM_SSD_I2C u8g_com_arduino_ssd_i2c_fn
 
#endif
 
#endif
 
#ifndef U8G_COM_SSD_I2C
 
#define U8G_COM_SSD_I2C u8g_com_null_fn
 
#endif
 

	
 

	
 

	
 
/*===============================================================*/
 
/* com api */
 

	
 
#define U8G_SPI_CLK_CYCLE_50NS 1
 
#define U8G_SPI_CLK_CYCLE_300NS 2
 
#define U8G_SPI_CLK_CYCLE_400NS 3
 
#define U8G_SPI_CLK_CYCLE_NONE 255
 

	
 
uint8_t u8g_InitCom(u8g_t *u8g, u8g_dev_t *dev, uint8_t clk_cycle_time);
 
void u8g_StopCom(u8g_t *u8g, u8g_dev_t *dev);
 
void u8g_EnableCom(u8g_t *u8g, u8g_dev_t *dev);         /* obsolete */
 
void u8g_DisableCom(u8g_t *u8g, u8g_dev_t *dev);        /* obsolete */
 
void u8g_SetChipSelect(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs);
 
void u8g_SetResetLow(u8g_t *u8g, u8g_dev_t *dev);
 
void u8g_SetResetHigh(u8g_t *u8g, u8g_dev_t *dev);
 
void u8g_SetAddress(u8g_t *u8g, u8g_dev_t *dev, uint8_t address);
 
uint8_t u8g_WriteByte(u8g_t *u8g, u8g_dev_t *dev, uint8_t val);
 
uint8_t u8g_WriteSequence(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *seq);
 
uint8_t u8g_WriteSequenceP(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, const uint8_t *seq);
 

	
 

	
 

	
 
#define U8G_ESC_DLY(x) 255, ((x) & 0x7f)
 
#define U8G_ESC_CS(x) 255, (0xd0 | ((x)&0x0f))
 
#define U8G_ESC_ADR(x) 255, (0xe0 | ((x)&0x0f))
 
#define U8G_ESC_RST(x) 255, (0xc0 | ((x)&0x0f))
 
#define U8G_ESC_VCC(x) 255, (0xbe | ((x)&0x01))
 
#define U8G_ESC_END 255, 254
 
#define U8G_ESC_255 255, 255
 
//uint8_t u8g_WriteEscSeqP(u8g_t *u8g, u8g_dev_t *dev, u8g_pgm_uint8_t *esc_seq);
 
uint8_t u8g_WriteEscSeqP(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq);
 

	
 

	
 
/* u8g_com_api_16gr.c */
 
uint8_t u8g_WriteByteBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b);
 
uint8_t u8g_WriteSequenceBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr);
 
uint8_t u8g_WriteByte4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b);
 
uint8_t u8g_WriteSequence4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr);
 

	
 

	
 
/*===============================================================*/
 
/* u8g_arduino_common.c */
 
void u8g_com_arduino_digital_write(u8g_t *u8g, uint8_t pin_index, uint8_t value);
 
void u8g_com_arduino_assign_pin_output_high(u8g_t *u8g);
 

	
 
/*===============================================================*/
 
/* u8g_com_io.c */
 

	
 
/* create internal number from port and pin */
 
uint8_t u8g_Pin(uint8_t port, uint8_t bitpos);
 
#define PN(port,bitpos) u8g_Pin(port,bitpos)
 

	
 
/* low level procedures */
 
void u8g_SetPinOutput(uint8_t internal_pin_number);
 
void u8g_SetPinLevel(uint8_t internal_pin_number, uint8_t level);
 
void u8g_SetPinInput(uint8_t internal_pin_number);
 
uint8_t u8g_GetPinLevel(uint8_t internal_pin_number);
 

	
 
/* u8g level procedures, expect U8G_PI_xxx macro */
 
void u8g_SetPIOutput(u8g_t *u8g, uint8_t pi);
 
void u8g_SetPILevel(u8g_t *u8g, uint8_t pi, uint8_t level);
 

	
 

	
 
/*===============================================================*/
 
/* page */
 
struct _u8g_page_t
 
{
 
  u8g_uint_t page_height;
 
  u8g_uint_t total_height;
 
  u8g_uint_t page_y0;
 
  u8g_uint_t page_y1;
 
  uint8_t page;
 
};
 
typedef struct _u8g_page_t u8g_page_t;
 

	
 
void u8g_page_First(u8g_page_t *p) U8G_NOINLINE;                                                                                        /* u8g_page.c */
 
void u8g_page_Init(u8g_page_t *p, u8g_uint_t page_height, u8g_uint_t total_height ) U8G_NOINLINE;            /* u8g_page.c */
 
uint8_t u8g_page_Next(u8g_page_t *p) U8G_NOINLINE;                                                                                   /* u8g_page.c */
 

	
 
/*===============================================================*/
 
/* page buffer (pb) */
 

	
 
struct _u8g_pb_t
 
{
 
  u8g_page_t p;
 
  u8g_uint_t width;		/* pixel width */
 
  void *buf;
 
};
 
typedef struct _u8g_pb_t u8g_pb_t;
 

	
 

	
 
/* u8g_pb.c */
 
void u8g_pb_Clear(u8g_pb_t *b);
 
uint8_t u8g_pb_IsYIntersection(u8g_pb_t *pb, u8g_uint_t v0, u8g_uint_t v1);
 
uint8_t u8g_pb_IsXIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1);
 
uint8_t u8g_pb_IsIntersection(u8g_pb_t *pb, u8g_dev_arg_bbx_t *bbx);
 
void u8g_pb_GetPageBox(u8g_pb_t *pb, u8g_box_t *box);
 
uint8_t u8g_pb_Is8PixelVisible(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel);
 
uint8_t u8g_pb_WriteBuffer(u8g_pb_t *b, u8g_t *u8g, u8g_dev_t *dev);
 

	
 
/*
 
  note on __attribute__ ((nocommon))
 
    AVR scripts often use  --gc-sections on the linker to remove unused section.
 
    This works fine for initialed data and text sections. In principle .bss is also
 
    handled, but the name##_pb definition is not removed. Reason is, that
 
    array definitions are placed in the COMMON section, by default
 
    The attribute "nocommon" removes this automatic assignment to the
 
    COMMON section and directly puts it into .bss. As a result, if more
 
    than one buffer is defined in one file, then it will be removed with --gc-sections
 

	
 
    .. not sure if Arduino IDE uses -fno-common... if yes, then the attribute is
 
    redundant.
 
*/
 
#define U8G_PB_DEV(name, width, height, page_height, dev_fn, com_fn) \
 
uint8_t name##_buf[width] U8G_NOCOMMON ; \
 
u8g_pb_t name##_pb = { {page_height, height, 0, 0, 0},  width, name##_buf}; \
 
u8g_dev_t name = { dev_fn, &name##_pb, com_fn }
 

	
 

	
 
void u8g_pb8v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)   U8G_NOINLINE;
 
void u8g_pb8v1_Clear(u8g_pb_t *b) U8G_NOINLINE;
 

	
 
uint8_t u8g_pb8v1_IsYIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1);
 
uint8_t u8g_pb8v1_IsXIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1);
 
uint8_t u8g_pb8v1_WriteBuffer(u8g_pb_t *b, u8g_t *u8g, u8g_dev_t *dev);
 

	
 
uint8_t u8g_dev_pb8v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 
/* u8g_pb16v1.c */
 
uint8_t u8g_dev_pb16v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 
/* u8g_pb14v1.c */
 
uint8_t u8g_dev_pb14v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 
/* u8g_pb8v2.c */
 
uint8_t u8g_dev_pb8v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 
/* u8g_pb16v2.c (double memory of pb8v2) */
 
uint8_t u8g_dev_pb16v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 

	
 
/* u8g_pb8h1.c */
 
uint8_t u8g_dev_pb8h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 
/* u8g_pb16h1.c */
 
uint8_t u8g_dev_pb16h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 
/* u8g_pb32h1.c */
 
uint8_t u8g_dev_pb32h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 

	
 
/* u8g_pb8h2.c 8 pixel rows, byte has horzontal orientation */
 
uint8_t u8g_dev_pb8h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 
/* u8g_pb16h2.c */
 
uint8_t u8g_dev_pb16h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 

	
 

	
 
/* u8g_pb8h1f.c */
 
uint8_t u8g_dev_pb8h1f_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 
/* u8g_pb8h8.c */
 
uint8_t u8g_dev_pb8h8_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 
/* u8g_pbxh16.c */
 
uint8_t u8g_dev_pbxh16_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 
/* u8g_pbxh24.c */
 
uint8_t u8g_dev_pbxh24_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 

	
 
/*===============================================================*/
 
/* u8g_ll_api.c */
 

	
 
/* cursor draw callback */
 
typedef void (*u8g_draw_cursor_fn)(u8g_t *u8g);
 

	
 
/* vertical reference point calculation callback */
 
typedef u8g_uint_t (*u8g_font_calc_vref_fnptr)(u8g_t *u8g);
 

	
 
/* state backup and restore procedure */
 
typedef void (*u8g_state_cb)(uint8_t msg);
 

	
 

	
 
/* PI = Pin Index */
 

	
 
/* reset pin, usually optional */
 
#define U8G_PI_RESET 0
 

	
 
/* address / data or instruction */
 
#define U8G_PI_A0 1
 
#define U8G_PI_DI 1
 

	
 
/* chip select line */
 
#define U8G_PI_CS 2
 
#define U8G_PI_CS1 2
 
#define U8G_PI_CS2 3
 
/* Feb 2013: A0 state moved from 7 to 3 for t6963 controller*/
 
#define U8G_PI_A0_STATE 3
 

	
 
/* enable / clock signal */
 
#define U8G_PI_EN 4
 
#define U8G_PI_CS_STATE 4
 
#define U8G_PI_SCK 4
 
#define U8G_PI_SCL 4
 
#define U8G_PI_RD 4
 

	
 

	
 
/* data pins, shared with SPI and I2C pins */
 
#define U8G_PI_D0 5
 
#define U8G_PI_MOSI 5
 
#define U8G_PI_SDA 5
 
#define U8G_PI_D1 6
 
#define U8G_PI_MISO 6
 
#define U8G_PI_D2 7
 
#define U8G_PI_D3 8
 
#define U8G_PI_SET_A0 8
 
#define U8G_PI_D4 9
 
#define U8G_PI_D5 10
 
#define U8G_PI_I2C_OPTION 11
 
#define U8G_PI_D6 11
 
#define U8G_PI_D7 12
 

	
 
/* read/write pin, must be the last pin in the list, this means U8G_PIN_LIST_LEN =  U8G_PI_RW + 1*/
 
#define U8G_PI_WR 13
 
#define U8G_PI_RW 13 
 

	
 
#define U8G_PIN_LIST_LEN 14
 

	
 

	
 
#define U8G_PIN_DUMMY 254
 
#define U8G_PIN_NONE 255
 

	
 
#define U8G_FONT_HEIGHT_MODE_TEXT 0
 
#define U8G_FONT_HEIGHT_MODE_XTEXT 1
 
#define U8G_FONT_HEIGHT_MODE_ALL 2
 

	
 
struct _u8g_t
 
{
 
  u8g_uint_t width;
 
  u8g_uint_t height;
 
  
 
  
 
  u8g_dev_t *dev;               /* first device in the device chain */
 
  const u8g_pgm_uint8_t *font;             /* regular font for all text procedures */
 
  const u8g_pgm_uint8_t *cursor_font;  /* special font for cursor procedures */
 
  uint8_t cursor_fg_color, cursor_bg_color;
 
  uint8_t cursor_encoding;
 
  uint8_t mode;                         /* display mode, one of U8G_MODE_xxx */
 
  u8g_uint_t cursor_x;
 
  u8g_uint_t cursor_y;
 
  u8g_draw_cursor_fn cursor_fn;
 
  
 
  int8_t glyph_dx;
 
  int8_t glyph_x;
 
  int8_t glyph_y;
 
  uint8_t glyph_width;
 
  uint8_t glyph_height;
 
  
 
  u8g_font_calc_vref_fnptr font_calc_vref;
 
  uint8_t font_height_mode;
 
  int8_t font_ref_ascent;
 
  int8_t font_ref_descent;
 
  uint8_t font_line_spacing_factor;     /* line_spacing = factor * (ascent - descent) / 64 */
 
  uint8_t line_spacing;
 
  
 
  u8g_dev_arg_pixel_t arg_pixel;
 
  /* uint8_t color_index; */
 

	
 
#ifdef U8G_WITH_PINLIST
 
  uint8_t pin_list[U8G_PIN_LIST_LEN];
 
#endif
 
  
 
  u8g_state_cb state_cb;
 
  
 
  u8g_box_t current_page;		/* current box of the visible page */
 

	
 
};
 

	
 
#define u8g_GetFontAscent(u8g) ((u8g)->font_ref_ascent)
 
#define u8g_GetFontDescent(u8g) ((u8g)->font_ref_descent)
 
#define u8g_GetFontLineSpacing(u8g) ((u8g)->line_spacing)
 

	
 
uint8_t u8g_call_dev_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 
uint8_t u8g_InitLL(u8g_t *u8g, u8g_dev_t *dev);
 
void u8g_FirstPageLL(u8g_t *u8g, u8g_dev_t *dev);
 
uint8_t u8g_NextPageLL(u8g_t *u8g, u8g_dev_t *dev);
 
uint8_t u8g_SetContrastLL(u8g_t *u8g, u8g_dev_t *dev, uint8_t contrast);
 
void u8g_DrawPixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y);
 
void u8g_Draw8PixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel);
 
void u8g_Draw4TPixelLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel);
 
uint8_t u8g_IsBBXIntersectionLL(u8g_t *u8g, u8g_dev_t *dev, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h);	/* obsolete */
 
u8g_uint_t u8g_GetWidthLL(u8g_t *u8g, u8g_dev_t *dev);
 
u8g_uint_t u8g_GetHeightLL(u8g_t *u8g, u8g_dev_t *dev);
 

	
 
void u8g_UpdateDimension(u8g_t *u8g);
 
uint8_t u8g_Begin(u8g_t *u8g);				/* reset device, put it into default state and call u8g_UpdateDimension() */
 
uint8_t u8g_Init(u8g_t *u8g, u8g_dev_t *dev);   /* only usefull if the device only as hardcoded ports */
 
uint8_t u8g_InitComFn(u8g_t *u8g, u8g_dev_t *dev, u8g_com_fnptr com_fn);	/* Init procedure for anything which is not Arduino or AVR (e.g. ARM, but not Due, which is Arduino) */
 
uint8_t u8g_InitSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset);
 
uint8_t u8g_InitHWSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs, uint8_t a0, uint8_t reset);
 
uint8_t u8g_InitI2C(u8g_t *u8g, u8g_dev_t *dev, uint8_t options);	/* use U8G_I2C_OPT_NONE as options */
 
uint8_t u8g_Init8BitFixedPort(u8g_t *u8g, u8g_dev_t *dev, uint8_t en, uint8_t cs, uint8_t di, uint8_t rw, uint8_t reset);
 
uint8_t u8g_Init8Bit(u8g_t *u8g, u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, 
 
  uint8_t en, uint8_t cs1, uint8_t cs2, uint8_t di, uint8_t rw, uint8_t reset);
 
uint8_t u8g_InitRW8Bit(u8g_t *u8g, u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, 
 
  uint8_t cs, uint8_t a0, uint8_t wr, uint8_t rd, uint8_t reset);
 
void u8g_FirstPage(u8g_t *u8g);
 
uint8_t u8g_NextPage(u8g_t *u8g);
 
uint8_t u8g_SetContrast(u8g_t *u8g, uint8_t contrast);
 
void u8g_SleepOn(u8g_t *u8g);
 
void u8g_SleepOff(u8g_t *u8g);
 
void u8g_DrawPixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y);
 
void u8g_Draw8Pixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel);
 
void u8g_Draw4TPixel(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t pixel);
 

	
 
uint8_t u8g_Stop(u8g_t *u8g);
 
void u8g_SetColorEntry(u8g_t *u8g, uint8_t idx, uint8_t r, uint8_t g, uint8_t b);
 
void u8g_SetColorIndex(u8g_t *u8g, uint8_t idx);
 
void u8g_SetHiColor(u8g_t *u8g, uint16_t rgb);
 
void u8g_SetHiColorByRGB(u8g_t *u8g, uint8_t r, uint8_t g, uint8_t b);
 
void u8g_SetRGB(u8g_t *u8g, uint8_t r, uint8_t g, uint8_t b);
 
uint8_t u8g_GetColorIndex(u8g_t *u8g);
 

	
 
uint8_t u8g_GetDefaultForegroundColor(u8g_t *u8g);
 
void u8g_SetDefaultForegroundColor(u8g_t *u8g);
 

	
 
uint8_t u8g_GetDefaultBackgroundColor(u8g_t *u8g);
 
void u8g_SetDefaultBackgroundColor(u8g_t *u8g);
 

	
 
uint8_t u8g_GetDefaultMidColor(u8g_t *u8g);
 
void u8g_SetDefaultMidColor(u8g_t *u8g);
 

	
 
#define u8g_GetWidth(u8g) ((u8g)->width)
 
#define u8g_GetHeight(u8g) ((u8g)->height)
 
#define u8g_GetMode(u8g) ((u8g)->mode)
 
/*
 
  U8G_MODE_GET_BITS_PER_PIXEL(u8g_GetMode(u8g))
 
  U8G_MODE_IS_COLOR(u8g_GetMode(u8g)) 
 
*/
 

	
 
/* u8g_state.c */
 
#define U8G_STATE_ENV_IDX 0
 
#define U8G_STATE_U8G_IDX 1
 
#define U8G_STATE_RESTORE 0
 
#define U8G_STATE_BACKUP 1
 
#define U8G_STATE_MSG_COMPOSE(cmd,idx) (((cmd)<<1) | (idx))
 

	
 
#define U8G_STATE_MSG_RESTORE_ENV U8G_STATE_MSG_COMPOSE(U8G_STATE_RESTORE,U8G_STATE_ENV_IDX)
 
#define U8G_STATE_MSG_BACKUP_ENV U8G_STATE_MSG_COMPOSE(U8G_STATE_BACKUP,U8G_STATE_ENV_IDX)
 
#define U8G_STATE_MSG_RESTORE_U8G U8G_STATE_MSG_COMPOSE(U8G_STATE_RESTORE,U8G_STATE_U8G_IDX)
 
#define U8G_STATE_MSG_BACKUP_U8G U8G_STATE_MSG_COMPOSE(U8G_STATE_BACKUP,U8G_STATE_U8G_IDX)
 

	
 
#define U8G_STATE_MSG_GET_IDX(msg) ((msg)&1)
 
#define U8G_STATE_MSG_IS_BACKUP(msg) ((msg)&2)
 

	
 

	
 

	
 
void u8g_state_dummy_cb(uint8_t msg);
 
void u8g_backup_spi(uint8_t msg);		/* backup SPI state controller */
 
/* backward compatible definition */
 
#define u8g_backup_avr_spi u8g_backup_spi
 

	
 
void u8g_SetHardwareBackup(u8g_t *u8g, u8g_state_cb backup_cb);
 

	
 
/* u8g_clip.c */
 

	
 
uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h);
 

	
 

	
 
/* u8g_rot.c */
 

	
 
void u8g_UndoRotation(u8g_t *u8g);
 
void u8g_SetRot90(u8g_t *u8g);
 
void u8g_SetRot180(u8g_t *u8g);
 
void u8g_SetRot270(u8g_t *u8g);
 

	
 
/* u8g_scale.c */
 

	
 
void u8g_UndoScale(u8g_t *u8g);
 
void u8g_SetScale2x2(u8g_t *u8g);
 

	
 

	
 
/* u8g_font.c */
 

	
 
size_t u8g_font_GetSize(const void *font);
 
uint8_t u8g_font_GetFontStartEncoding(const void *font) U8G_NOINLINE;
 
uint8_t u8g_font_GetFontEndEncoding(const void *font) U8G_NOINLINE;
 

	
 
void u8g_SetFont(u8g_t *u8g, const u8g_fntpgm_uint8_t *font);
 

	
 
uint8_t u8g_GetFontBBXWidth(u8g_t *u8g);
 
uint8_t u8g_GetFontBBXHeight(u8g_t *u8g);
 
int8_t u8g_GetFontBBXOffX(u8g_t *u8g);
 
int8_t u8g_GetFontBBXOffY(u8g_t *u8g);
 
uint8_t u8g_GetFontCapitalAHeight(u8g_t *u8g);
 

	
 
uint8_t u8g_IsGlyph(u8g_t *u8g, uint8_t requested_encoding);
 
int8_t u8g_GetGlyphDeltaX(u8g_t *u8g, uint8_t requested_encoding);
 

	
 
int8_t u8g_draw_glyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding); /* used by u8g_cursor.c */
 

	
 
int8_t u8g_DrawGlyphDir(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t encoding);
 
int8_t u8g_DrawGlyph(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding);
 
int8_t u8g_DrawGlyph90(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding);
 
int8_t u8g_DrawGlyph180(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding);
 
int8_t u8g_DrawGlyph270(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t encoding);
 
int8_t u8g_DrawGlyphFontBBX(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, uint8_t encoding);
 

	
 
u8g_uint_t u8g_DrawStr(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s);
 
u8g_uint_t u8g_DrawStr90(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s);
 
u8g_uint_t u8g_DrawStr180(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s);
 
u8g_uint_t u8g_DrawStr270(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s);
 

	
 
u8g_uint_t u8g_DrawStrDir(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, const char *s);
 

	
 

	
 
u8g_uint_t u8g_DrawStrP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s);
 
u8g_uint_t u8g_DrawStr90P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s);
 
u8g_uint_t u8g_DrawStr180P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s);
 
u8g_uint_t u8g_DrawStr270P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s);
 

	
 

	
 
void u8g_SetFontRefHeightText(u8g_t *u8g);
 
void u8g_SetFontRefHeightExtendedText(u8g_t *u8g);
 
void u8g_SetFontRefHeightAll(u8g_t *u8g);
 
void u8g_SetFontLineSpacingFactor(u8g_t *u8g, uint8_t factor);
 

	
 
u8g_uint_t u8g_font_calc_vref_font(u8g_t *u8g);
 
u8g_uint_t u8g_font_calc_vref_bottom(u8g_t *u8g);
 
u8g_uint_t u8g_font_calc_vref_top(u8g_t *u8g);
 
u8g_uint_t u8g_font_calc_vref_center(u8g_t *u8g);
 

	
 
void u8g_SetFontPosBaseline(u8g_t *u8g);
 
void u8g_SetFontPosBottom(u8g_t *u8g);
 
void u8g_SetFontPosCenter(u8g_t *u8g);
 
void u8g_SetFontPosTop(u8g_t *u8g);
 

	
 

	
 
u8g_uint_t u8g_GetStrPixelWidth(u8g_t *u8g, const char *s);
 
u8g_uint_t u8g_GetStrPixelWidthP(u8g_t *u8g, const u8g_pgm_uint8_t *s);
 
int8_t u8g_GetStrX(u8g_t *u8g, const char *s);
 
int8_t u8g_GetStrXP(u8g_t *u8g, const u8g_pgm_uint8_t *s);
 
u8g_uint_t u8g_GetStrWidth(u8g_t *u8g, const char *s) U8G_NOINLINE;
 
u8g_uint_t u8g_GetStrWidthP(u8g_t *u8g, const u8g_pgm_uint8_t *s);
 

	
 
u8g_uint_t u8g_DrawStrFontBBX(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, uint8_t dir, const char *s);
 

	
 
void u8g_GetStrMinBox(u8g_t *u8g, const char *s, u8g_uint_t *x, u8g_uint_t *y, u8g_uint_t *width, u8g_uint_t *height);
 
void u8g_GetStrAMinBox(u8g_t *u8g, const char *s, u8g_uint_t *x, u8g_uint_t *y, u8g_uint_t *width, u8g_uint_t *height);
 

	
 

	
 
u8g_uint_t u8g_DrawAAStr(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s);
 

	
 
/* u8g_rect.c */
 

	
 
void u8g_draw_box(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h) U8G_NOINLINE; 
 

	
 
void u8g_DrawHLine(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w) U8G_NOINLINE;
 
void u8g_DrawVLine(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w) U8G_NOINLINE;
 
void u8g_DrawFrame(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h) U8G_NOINLINE;
 
void u8g_DrawBox(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h) U8G_NOINLINE;
 

	
 
void u8g_DrawRFrame(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, u8g_uint_t r) U8G_NOINLINE;
 
void u8g_DrawRBox(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, u8g_uint_t r) U8G_NOINLINE;
 

	
 
/* u8g_bitmap.c */
 

	
 
void u8g_DrawHBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const uint8_t *bitmap);
 
void u8g_DrawHBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const u8g_pgm_uint8_t *bitmap);
 
void u8g_DrawBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const uint8_t *bitmap);
 
void u8g_DrawBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap);
 

	
 
void u8g_DrawXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const uint8_t *bitmap);
 
void u8g_DrawXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap);
 

	
 

	
 
/* u8g_line.c */
 
void u8g_DrawLine(u8g_t *u8g, u8g_uint_t x1, u8g_uint_t y1, u8g_uint_t x2, u8g_uint_t y2);
 

	
 

	
 
/* u8g_circle.c */
 

	
 
/* the following, commented code has been rewritten or is not yet finished
 
#define U8G_CIRC_UPPER_RIGHT 0x01
 
#define U8G_CIRC_UPPER_LEFT  0x02
 
#define U8G_CIRC_LOWER_LEFT 0x04
 
#define U8G_CIRC_LOWER_RIGHT  0x08
 
#define U8G_CIRC_ALL (U8G_CIRC_UPPER_RIGHT|U8G_CIRC_UPPER_LEFT|U8G_CIRC_LOWER_RIGHT|U8G_CIRC_LOWER_LEFT)
 
void u8g_DrawEmpCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option);
 
void u8g_DrawFillCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option);
 
void u8g_DrawEllipseRect(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t x1, u8g_uint_t y1);
 
*/
 

	
 
#define U8G_DRAW_UPPER_RIGHT 0x01
 
#define U8G_DRAW_UPPER_LEFT  0x02
 
#define U8G_DRAW_LOWER_LEFT 0x04
 
#define U8G_DRAW_LOWER_RIGHT  0x08
 
#define U8G_DRAW_ALL (U8G_DRAW_UPPER_RIGHT|U8G_DRAW_UPPER_LEFT|U8G_DRAW_LOWER_RIGHT|U8G_DRAW_LOWER_LEFT)
 

	
 
void u8g_draw_circle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option) U8G_NOINLINE;
 
void u8g_draw_disc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option) U8G_NOINLINE;
 

	
 
void u8g_DrawCircle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option);
 
void u8g_DrawDisc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option);
 

	
 
/* u8g_ellipse.c */
 
void u8g_DrawEllipse(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rx, u8g_uint_t ry, uint8_t option);
 
void u8g_DrawFilledEllipse(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rx, u8g_uint_t ry, uint8_t option);
 

	
 
/* u8g_clip.c */
 
uint8_t u8g_is_box_bbx_intersection(u8g_box_t *box, u8g_dev_arg_bbx_t *bbx);
 

	
 

	
 
/* u8g_cursor.c */
 
void u8g_SetCursorFont(u8g_t *u8g, const u8g_pgm_uint8_t *cursor_font);
 
void u8g_SetCursorStyle(u8g_t *u8g, uint8_t encoding);
 
void u8g_SetCursorPos(u8g_t *u8g, u8g_uint_t cursor_x, u8g_uint_t cursor_y);
 
void u8g_SetCursorColor(u8g_t *u8g, uint8_t fg, uint8_t bg);
 
void u8g_EnableCursor(u8g_t *u8g);
 
void u8g_DisableCursor(u8g_t *u8g);
 
void u8g_DrawCursor(u8g_t *u8g);
 

	
 
/* u8g_polygon.c */
 

	
 
typedef int16_t pg_word_t;
 

	
 
#define PG_NOINLINE U8G_NOINLINE
 

	
 
struct pg_point_struct
 
{
 
  pg_word_t x;
 
  pg_word_t y;
 
};
 

	
 
typedef struct _pg_struct pg_struct;	/* forward declaration */
 

	
 
struct pg_edge_struct
 
{
 
  pg_word_t x_direction;	/* 1, if x2 is greater than x1, -1 otherwise */
 
  pg_word_t height;
 
  pg_word_t current_x_offset;
 
  pg_word_t error_offset;
 
  
 
  /* --- line loop --- */
 
  pg_word_t current_y;
 
  pg_word_t max_y;
 
  pg_word_t current_x;
 
  pg_word_t error;
 

	
 
  /* --- outer loop --- */
 
  uint8_t (*next_idx_fn)(pg_struct *pg, uint8_t i);
 
  uint8_t curr_idx;
 
};
 

	
 
/* maximum number of points in the polygon */
 
/* can be redefined, but highest possible value is 254 */
 
#define PG_MAX_POINTS 6
 

	
 
/* index numbers for the pge structures below */
 
#define PG_LEFT 0
 
#define PG_RIGHT 1
 

	
 

	
 
struct _pg_struct
 
{
 
  struct pg_point_struct list[PG_MAX_POINTS];
 
  uint8_t cnt;
 
  uint8_t is_min_y_not_flat;
 
  pg_word_t total_scan_line_cnt;
 
  struct pg_edge_struct pge[2];	/* left and right line draw structures */
 
};
 

	
 
void pg_ClearPolygonXY(pg_struct *pg);
 
void pg_AddPolygonXY(pg_struct *pg, u8g_t *u8g, int16_t x, int16_t y);
 
void pg_DrawPolygon(pg_struct *pg, u8g_t *u8g);
 
void u8g_ClearPolygonXY(void);
 
void u8g_AddPolygonXY(u8g_t *u8g, int16_t x, int16_t y);
 
void u8g_DrawPolygon(u8g_t *u8g);
 
void u8g_DrawTriangle(u8g_t *u8g, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
 

	
 

	
 
/*===============================================================*/
 
/* u8g_virtual_screen.c */
 
void u8g_SetVirtualScreenDimension(u8g_t *vs_u8g, u8g_uint_t width, u8g_uint_t height);
 
uint8_t u8g_AddToVirtualScreen(u8g_t *vs_u8g, u8g_uint_t x, u8g_uint_t y, u8g_t *child_u8g);
 

	
 
/*===============================================================*/
 
void st_Draw(uint8_t fps);
 
void st_Step(uint8_t player_pos, uint8_t is_auto_fire, uint8_t is_fire);
 

	
 
/*===============================================================*/
 
/* u8g_com_i2c.c */
 

	
 
/* options for u8g_i2c_init() */
 
#define U8G_I2C_OPT_NONE 0
 

	
 
/* retrun values from u8g_twi_get_error() */
 
#define U8G_I2C_ERR_NONE 0x00
 
/* the following values are bit masks */
 
#define U8G_I2C_ERR_TIMEOUT 0x01
 
#define U8G_I2C_ERR_BUS 0x02
 

	
 
void u8g_i2c_clear_error(void) U8G_NOINLINE;
 
uint8_t  u8g_i2c_get_error(void) U8G_NOINLINE;
 
uint8_t u8g_i2c_get_err_pos(void) U8G_NOINLINE;
 
void u8g_i2c_init(uint8_t options) U8G_NOINLINE;		/* use U8G_I2C_OPT_NONE as options */
 
uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos) U8G_NOINLINE;
 
uint8_t u8g_i2c_start(uint8_t sla) U8G_NOINLINE;
 
uint8_t u8g_i2c_send_byte(uint8_t data) U8G_NOINLINE;
 
void u8g_i2c_stop(void) U8G_NOINLINE;
 

	
 

	
 
/*===============================================================*/
 
/* u8g_u8toa.c */
 
/* v = value, d = number of digits */
 
const char *u8g_u8toa(uint8_t v, uint8_t d);
 

	
 
/* u8g_u8toa.c */
 
/* v = value, d = number of digits */
 
const char *u8g_u16toa(uint16_t v, uint8_t d);
 

	
 
/*===============================================================*/
 
/* u8g_delay.c */
 

	
 
/* delay by the specified number of milliseconds */
 
void u8g_Delay(uint16_t val);
 

	
 
/* delay by one microsecond */
 
void u8g_MicroDelay(void);
 

	
 
/* delay by 10 microseconds */
 
void u8g_10MicroDelay(void);
 

	
 
/*===============================================================*/
 
/* chessengine.c */
 
#define CHESS_KEY_NONE 0
 
#define CHESS_KEY_NEXT 1
 
#define CHESS_KEY_PREV 2
 
#define CHESS_KEY_SELECT 3
 
#define CHESS_KEY_BACK 4
 

	
 
void chess_Init(u8g_t *u8g, uint8_t empty_body_color);
 
void chess_Draw(void);
 
void chess_Step(uint8_t keycode);
 

	
 
/*===============================================================*/
 
/* font definitions */
 
extern const u8g_fntpgm_uint8_t u8g_font_m2icon_5[] U8G_FONT_SECTION("u8g_font_m2icon_5");
 
extern const u8g_fntpgm_uint8_t u8g_font_m2icon_7[] U8G_FONT_SECTION("u8g_font_m2icon_7");
 
extern const u8g_fntpgm_uint8_t u8g_font_m2icon_9[] U8G_FONT_SECTION("u8g_font_m2icon_9");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_u8glib_4[] U8G_FONT_SECTION("u8g_font_u8glib_4");
 
extern const u8g_fntpgm_uint8_t u8g_font_u8glib_4r[] U8G_FONT_SECTION("u8g_font_u8glib_4r");
 

	
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_6x12_75r[] U8G_FONT_SECTION("u8g_font_6x12_75r");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x13_75r[] U8G_FONT_SECTION("u8g_font_6x13_75r");
 
extern const u8g_fntpgm_uint8_t u8g_font_7x13_75r[] U8G_FONT_SECTION("u8g_font_7x13_75r");
 
extern const u8g_fntpgm_uint8_t u8g_font_8x13_75r[] U8G_FONT_SECTION("u8g_font_8x13_75r");
 
extern const u8g_fntpgm_uint8_t u8g_font_9x15_75r[] U8G_FONT_SECTION("u8g_font_9x15_75r");
 
extern const u8g_fntpgm_uint8_t u8g_font_9x18_75r[] U8G_FONT_SECTION("u8g_font_9x18_75r");
 
extern const u8g_fntpgm_uint8_t u8g_font_cu12_75r[] U8G_FONT_SECTION("u8g_font_cu12_75r");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont_75r[] U8G_FONT_SECTION("u8g_font_unifont_75r");
 
extern const u8g_fntpgm_uint8_t u8g_font_10x20_75r[] U8G_FONT_SECTION("u8g_font_10x20_75r");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_10x20_67_75[] U8G_FONT_SECTION("u8g_font_10x20_67_75");
 
extern const u8g_fntpgm_uint8_t u8g_font_10x20_78_79[] U8G_FONT_SECTION("u8g_font_10x20_78_79");
 
extern const u8g_fntpgm_uint8_t u8g_font_10x20[] U8G_FONT_SECTION("u8g_font_10x20");
 
extern const u8g_fntpgm_uint8_t u8g_font_10x20r[] U8G_FONT_SECTION("u8g_font_10x20r");
 
extern const u8g_fntpgm_uint8_t u8g_font_4x6[] U8G_FONT_SECTION("u8g_font_4x6");
 
extern const u8g_fntpgm_uint8_t u8g_font_4x6r[] U8G_FONT_SECTION("u8g_font_4x6r");
 
//extern const u8g_fntpgm_uint8_t u8g_font_4x6n[] U8G_FONT_SECTION("u8g_font_4x6n");
 
extern const u8g_fntpgm_uint8_t u8g_font_5x7[] U8G_FONT_SECTION("u8g_font_5x7");
 
extern const u8g_fntpgm_uint8_t u8g_font_5x7r[] U8G_FONT_SECTION("u8g_font_5x7r");
 
extern const u8g_fntpgm_uint8_t u8g_font_5x8[] U8G_FONT_SECTION("u8g_font_5x8");
 
extern const u8g_fntpgm_uint8_t u8g_font_5x8r[] U8G_FONT_SECTION("u8g_font_5x8r");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x10[] U8G_FONT_SECTION("u8g_font_6x10");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x10r[] U8G_FONT_SECTION("u8g_font_6x10r");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x12_67_75[] U8G_FONT_SECTION("u8g_font_6x12_67_75");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x12_78_79[] U8G_FONT_SECTION("u8g_font_6x12_78_79");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x12[] U8G_FONT_SECTION("u8g_font_6x12");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x12r[] U8G_FONT_SECTION("u8g_font_6x12r");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x13_67_75[] U8G_FONT_SECTION("u8g_font_6x13_67_75");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x13_78_79[] U8G_FONT_SECTION("u8g_font_6x13_78_79");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x13B[] U8G_FONT_SECTION("u8g_font_6x13B");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x13Br[] U8G_FONT_SECTION("u8g_font_6x13Br");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x13[] U8G_FONT_SECTION("u8g_font_6x13");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x13r[] U8G_FONT_SECTION("u8g_font_6x13r");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x13O[] U8G_FONT_SECTION("u8g_font_6x13O");
 
extern const u8g_fntpgm_uint8_t u8g_font_6x13Or[] U8G_FONT_SECTION("u8g_font_6x13Or");
 
extern const u8g_fntpgm_uint8_t u8g_font_7x13_67_75[] U8G_FONT_SECTION("u8g_font_7x13_67_75");
 
extern const u8g_fntpgm_uint8_t u8g_font_7x13_78_79[] U8G_FONT_SECTION("u8g_font_7x13_78_79");
 
extern const u8g_fntpgm_uint8_t u8g_font_7x13B[] U8G_FONT_SECTION("u8g_font_7x13B");
 
extern const u8g_fntpgm_uint8_t u8g_font_7x13Br[] U8G_FONT_SECTION("u8g_font_7x13Br");
 
extern const u8g_fntpgm_uint8_t u8g_font_7x13[] U8G_FONT_SECTION("u8g_font_7x13");
 
extern const u8g_fntpgm_uint8_t u8g_font_7x13r[] U8G_FONT_SECTION("u8g_font_7x13r");
 
extern const u8g_fntpgm_uint8_t u8g_font_7x13O[] U8G_FONT_SECTION("u8g_font_7x13O");
 
extern const u8g_fntpgm_uint8_t u8g_font_7x13Or[] U8G_FONT_SECTION("u8g_font_7x13Or");
 
extern const u8g_fntpgm_uint8_t u8g_font_7x14B[] U8G_FONT_SECTION("u8g_font_7x14B");
 
extern const u8g_fntpgm_uint8_t u8g_font_7x14Br[] U8G_FONT_SECTION("u8g_font_7x14Br");
 
extern const u8g_fntpgm_uint8_t u8g_font_7x14[] U8G_FONT_SECTION("u8g_font_7x14");
 
extern const u8g_fntpgm_uint8_t u8g_font_7x14r[] U8G_FONT_SECTION("u8g_font_7x14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_8x13_67_75[] U8G_FONT_SECTION("u8g_font_8x13_67_75");
 
extern const u8g_fntpgm_uint8_t u8g_font_8x13B[] U8G_FONT_SECTION("u8g_font_8x13B");
 
extern const u8g_fntpgm_uint8_t u8g_font_8x13Br[] U8G_FONT_SECTION("u8g_font_8x13Br");
 
extern const u8g_fntpgm_uint8_t u8g_font_8x13[] U8G_FONT_SECTION("u8g_font_8x13");
 
extern const u8g_fntpgm_uint8_t u8g_font_8x13r[] U8G_FONT_SECTION("u8g_font_8x13r");
 
extern const u8g_fntpgm_uint8_t u8g_font_8x13O[] U8G_FONT_SECTION("u8g_font_8x13O");
 
extern const u8g_fntpgm_uint8_t u8g_font_8x13Or[] U8G_FONT_SECTION("u8g_font_8x13Or");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_9x15_67_75[] U8G_FONT_SECTION("u8g_font_9x15_67_75");
 
extern const u8g_fntpgm_uint8_t u8g_font_9x15_78_79[] U8G_FONT_SECTION("u8g_font_9x15_78_79");
 
extern const u8g_fntpgm_uint8_t u8g_font_9x15B[] U8G_FONT_SECTION("u8g_font_9x15B");
 
extern const u8g_fntpgm_uint8_t u8g_font_9x15Br[] U8G_FONT_SECTION("u8g_font_9x15Br");
 
extern const u8g_fntpgm_uint8_t u8g_font_9x15[] U8G_FONT_SECTION("u8g_font_9x15");
 
extern const u8g_fntpgm_uint8_t u8g_font_9x15r[] U8G_FONT_SECTION("u8g_font_9x15r");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_9x18_67_75[] U8G_FONT_SECTION("u8g_font_9x18_67_75");
 
extern const u8g_fntpgm_uint8_t u8g_font_9x18_78_79[] U8G_FONT_SECTION("u8g_font_9x18_78_79");
 
extern const u8g_fntpgm_uint8_t u8g_font_9x18B[] U8G_FONT_SECTION("u8g_font_9x18B");
 
extern const u8g_fntpgm_uint8_t u8g_font_9x18[] U8G_FONT_SECTION("u8g_font_9x18");
 
extern const u8g_fntpgm_uint8_t u8g_font_9x18Br[] U8G_FONT_SECTION("u8g_font_9x18Br");
 
extern const u8g_fntpgm_uint8_t u8g_font_9x18r[] U8G_FONT_SECTION("u8g_font_9x18r");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_cursor[] U8G_FONT_SECTION("u8g_font_cursor");
 
extern const u8g_fntpgm_uint8_t u8g_font_cursorr[] U8G_FONT_SECTION("u8g_font_cursorr");
 
extern const u8g_fntpgm_uint8_t u8g_font_micro[] U8G_FONT_SECTION("u8g_font_micro");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_cu12_67_75[] U8G_FONT_SECTION("u8g_font_cu12_67_75");
 
extern const u8g_fntpgm_uint8_t u8g_font_cu12_78_79[] U8G_FONT_SECTION("u8g_font_cu12_78_79");
 
extern const u8g_fntpgm_uint8_t u8g_font_cu12[] U8G_FONT_SECTION("u8g_font_cu12");
 

	
 
/* 
 
  Free-Universal Bold 
 
  r: Reduced char set (codes 32 - 128)
 
  n: Numbers (codes 42 - 57)
 
  no char: Full set (codes 32 - 255)
 
*/
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_fub11[] U8G_FONT_SECTION("u8g_font_fub11");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub11r[] U8G_FONT_SECTION("u8g_font_fub11r");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub11n[] U8G_FONT_SECTION("u8g_font_fub11n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub14[] U8G_FONT_SECTION("u8g_font_fub14");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub14r[] U8G_FONT_SECTION("u8g_font_fub14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub14n[] U8G_FONT_SECTION("u8g_font_fub14n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub17[] U8G_FONT_SECTION("u8g_font_fub17");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub17r[] U8G_FONT_SECTION("u8g_font_fub17r");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub17n[] U8G_FONT_SECTION("u8g_font_fub17n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub20[] U8G_FONT_SECTION("u8g_font_fub20");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub20r[] U8G_FONT_SECTION("u8g_font_fub20r");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub20n[] U8G_FONT_SECTION("u8g_font_fub20n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub25[] U8G_FONT_SECTION("u8g_font_fub25");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub25r[] U8G_FONT_SECTION("u8g_font_fub25r");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub25n[] U8G_FONT_SECTION("u8g_font_fub25n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub30[] U8G_FONT_SECTION("u8g_font_fub30");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub30r[] U8G_FONT_SECTION("u8g_font_fub30r");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub30n[] U8G_FONT_SECTION("u8g_font_fub30n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub35n[] U8G_FONT_SECTION("u8g_font_fub35n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub42n[] U8G_FONT_SECTION("u8g_font_fub42n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fub49n[] U8G_FONT_SECTION("u8g_font_fub49n");
 

	
 
/* 
 
  Free-Universal Regular
 
  r: Reduced char set (codes 32 - 128)
 
  n: Numbers (codes 42 - 57)
 
  no char: Full set (codes 32 - 255)
 
*/
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_fur11[] U8G_FONT_SECTION("u8g_font_fur11");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur11r[] U8G_FONT_SECTION("u8g_font_fur11r");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur11n[] U8G_FONT_SECTION("u8g_font_fur11n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur14[] U8G_FONT_SECTION("u8g_font_fur14");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur14r[] U8G_FONT_SECTION("u8g_font_fur14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur14n[] U8G_FONT_SECTION("u8g_font_fur14n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur17[] U8G_FONT_SECTION("u8g_font_fur17");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur17r[] U8G_FONT_SECTION("u8g_font_fur17r");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur17n[] U8G_FONT_SECTION("u8g_font_fur17n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur20[] U8G_FONT_SECTION("u8g_font_fur20");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur20r[] U8G_FONT_SECTION("u8g_font_fur20r");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur20n[] U8G_FONT_SECTION("u8g_font_fur20n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur25[] U8G_FONT_SECTION("u8g_font_fur25");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur25r[] U8G_FONT_SECTION("u8g_font_fur25r");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur25n[] U8G_FONT_SECTION("u8g_font_fur25n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur30[] U8G_FONT_SECTION("u8g_font_fur30");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur30r[] U8G_FONT_SECTION("u8g_font_fur30r");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur30n[] U8G_FONT_SECTION("u8g_font_fur30n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur35n[] U8G_FONT_SECTION("u8g_font_fur35n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur42n[] U8G_FONT_SECTION("u8g_font_fur42n");
 
extern const u8g_fntpgm_uint8_t u8g_font_fur49n[] U8G_FONT_SECTION("u8g_font_fur49n");
 

	
 
/* 
 
  Gentium Bold
 
  r: Reduced char set (codes 32 - 128)
 
  n: Numbers (codes 42 - 57)
 
  no char: Full set (codes 32 - 255)
 
*/
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb11[] U8G_FONT_SECTION("u8g_font_gdb11");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb12[] U8G_FONT_SECTION("u8g_font_gdb12");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb14[] U8G_FONT_SECTION("u8g_font_gdb14");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb17[] U8G_FONT_SECTION("u8g_font_gdb17");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb20[] U8G_FONT_SECTION("u8g_font_gdb20");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb25[] U8G_FONT_SECTION("u8g_font_gdb25");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb30[] U8G_FONT_SECTION("u8g_font_gdb30");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb11r[] U8G_FONT_SECTION("u8g_font_gdb11r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb12r[] U8G_FONT_SECTION("u8g_font_gdb12r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb14r[] U8G_FONT_SECTION("u8g_font_gdb14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb17r[] U8G_FONT_SECTION("u8g_font_gdb17r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb20r[] U8G_FONT_SECTION("u8g_font_gdb20r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb25r[] U8G_FONT_SECTION("u8g_font_gdb25r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb30r[] U8G_FONT_SECTION("u8g_font_gdb30r");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb11n[] U8G_FONT_SECTION("u8g_font_gdb11n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb12n[] U8G_FONT_SECTION("u8g_font_gdb12n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb14n[] U8G_FONT_SECTION("u8g_font_gdb14n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb17n[] U8G_FONT_SECTION("u8g_font_gdb17n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb20n[] U8G_FONT_SECTION("u8g_font_gdb20n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb25n[] U8G_FONT_SECTION("u8g_font_gdb25n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdb30n[] U8G_FONT_SECTION("u8g_font_gdb30n");
 

	
 
/* 
 
  Gentium Regular
 
  r: Reduced char set (codes 32 - 128)
 
  n: Numbers (codes 42 - 57)
 
  no char: Full set (codes 32 - 255)
 
*/
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr9[] U8G_FONT_SECTION("u8g_font_gdr9");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr10[] U8G_FONT_SECTION("u8g_font_gdr10");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr11[] U8G_FONT_SECTION("u8g_font_gdr11");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr12[] U8G_FONT_SECTION("u8g_font_gdr12");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr14[] U8G_FONT_SECTION("u8g_font_gdr14");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr17[] U8G_FONT_SECTION("u8g_font_gdr17");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr20[] U8G_FONT_SECTION("u8g_font_gdr20");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr25[] U8G_FONT_SECTION("u8g_font_gdr25");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr30[] U8G_FONT_SECTION("u8g_font_gdr30");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr9r[] U8G_FONT_SECTION("u8g_font_gdr9r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr10r[] U8G_FONT_SECTION("u8g_font_gdr10r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr11r[] U8G_FONT_SECTION("u8g_font_gdr11r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr12r[] U8G_FONT_SECTION("u8g_font_gdr12r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr14r[] U8G_FONT_SECTION("u8g_font_gdr14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr17r[] U8G_FONT_SECTION("u8g_font_gdr17r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr20r[] U8G_FONT_SECTION("u8g_font_gdr20r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr25r[] U8G_FONT_SECTION("u8g_font_gdr25r");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr30r[] U8G_FONT_SECTION("u8g_font_gdr30r");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr9n[] U8G_FONT_SECTION("u8g_font_gdr9n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr10n[] U8G_FONT_SECTION("u8g_font_gdr10n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr11n[] U8G_FONT_SECTION("u8g_font_gdr11n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr12n[] U8G_FONT_SECTION("u8g_font_gdr12n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr14n[] U8G_FONT_SECTION("u8g_font_gdr14n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr17n[] U8G_FONT_SECTION("u8g_font_gdr17n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr20n[] U8G_FONT_SECTION("u8g_font_gdr20n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr25n[] U8G_FONT_SECTION("u8g_font_gdr25n");
 
extern const u8g_fntpgm_uint8_t u8g_font_gdr30n[] U8G_FONT_SECTION("u8g_font_gdr30n");
 

	
 
/* 
 
  Old-Standard Bold
 
  r: Reduced char set (codes 32 - 128)
 
  n: Numbers (codes 42 - 57)
 
  no char: Full set (codes 32 - 255)
 
*/
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_osb18[] U8G_FONT_SECTION("u8g_font_osb18");
 
extern const u8g_fntpgm_uint8_t u8g_font_osb21[] U8G_FONT_SECTION("u8g_font_osb21");
 
extern const u8g_fntpgm_uint8_t u8g_font_osb26[] U8G_FONT_SECTION("u8g_font_osb26");
 
extern const u8g_fntpgm_uint8_t u8g_font_osb29[] U8G_FONT_SECTION("u8g_font_osb29");
 
extern const u8g_fntpgm_uint8_t u8g_font_osb35[] U8G_FONT_SECTION("u8g_font_osb35");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_osb18r[] U8G_FONT_SECTION("u8g_font_osb18r");
 
extern const u8g_fntpgm_uint8_t u8g_font_osb21r[] U8G_FONT_SECTION("u8g_font_osb21r");
 
extern const u8g_fntpgm_uint8_t u8g_font_osb26r[] U8G_FONT_SECTION("u8g_font_osb26r");
 
extern const u8g_fntpgm_uint8_t u8g_font_osb29r[] U8G_FONT_SECTION("u8g_font_osb29r");
 
extern const u8g_fntpgm_uint8_t u8g_font_osb35r[] U8G_FONT_SECTION("u8g_font_osb35r");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_osb18n[] U8G_FONT_SECTION("u8g_font_osb18n");
 
extern const u8g_fntpgm_uint8_t u8g_font_osb21n[] U8G_FONT_SECTION("u8g_font_osb21n");
 
extern const u8g_fntpgm_uint8_t u8g_font_osb26n[] U8G_FONT_SECTION("u8g_font_osb26n");
 
extern const u8g_fntpgm_uint8_t u8g_font_osb29n[] U8G_FONT_SECTION("u8g_font_osb29n");
 
extern const u8g_fntpgm_uint8_t u8g_font_osb35n[] U8G_FONT_SECTION("u8g_font_osb35n");
 

	
 
/* 
 
  Old-Standard Regular
 
  r: Reduced char set (codes 32 - 128)
 
  n: Numbers (codes 42 - 57)
 
  no char: Full set (codes 32 - 255)
 
*/
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_osr18[] U8G_FONT_SECTION("u8g_font_osr18");
 
extern const u8g_fntpgm_uint8_t u8g_font_osr21[] U8G_FONT_SECTION("u8g_font_osr21");
 
extern const u8g_fntpgm_uint8_t u8g_font_osr26[] U8G_FONT_SECTION("u8g_font_osr26");
 
extern const u8g_fntpgm_uint8_t u8g_font_osr29[] U8G_FONT_SECTION("u8g_font_osr29");
 
extern const u8g_fntpgm_uint8_t u8g_font_osr35[] U8G_FONT_SECTION("u8g_font_osr35");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_osr18r[] U8G_FONT_SECTION("u8g_font_osr18r");
 
extern const u8g_fntpgm_uint8_t u8g_font_osr21r[] U8G_FONT_SECTION("u8g_font_osr21r");
 
extern const u8g_fntpgm_uint8_t u8g_font_osr26r[] U8G_FONT_SECTION("u8g_font_osr26r");
 
extern const u8g_fntpgm_uint8_t u8g_font_osr29r[] U8G_FONT_SECTION("u8g_font_osr29r");
 
extern const u8g_fntpgm_uint8_t u8g_font_osr35r[] U8G_FONT_SECTION("u8g_font_osr35r");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_osr18n[] U8G_FONT_SECTION("u8g_font_osr18n");
 
extern const u8g_fntpgm_uint8_t u8g_font_osr21n[] U8G_FONT_SECTION("u8g_font_osr21n");
 
extern const u8g_fntpgm_uint8_t u8g_font_osr26n[] U8G_FONT_SECTION("u8g_font_osr26n");
 
extern const u8g_fntpgm_uint8_t u8g_font_osr29n[] U8G_FONT_SECTION("u8g_font_osr29n");
 
extern const u8g_fntpgm_uint8_t u8g_font_osr35n[] U8G_FONT_SECTION("u8g_font_osr35n");
 

	
 
//extern const u8g_fntpgm_uint8_t u8g_font_osr41[] U8G_FONT_SECTION("u8g_font_osr41");
 

	
 
/* GNU unifont */
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont_18_19[] U8G_FONT_SECTION("u8g_font_unifont_18_19");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont_72_73[] U8G_FONT_SECTION("u8g_font_unifont_72_73");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont_67_75[] U8G_FONT_SECTION("u8g_font_unifont_67_75");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont_76[] U8G_FONT_SECTION("u8g_font_unifont_76");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont_77[] U8G_FONT_SECTION("u8g_font_unifont_77");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont_78_79[] U8G_FONT_SECTION("u8g_font_unifont_78_79");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont_86[] U8G_FONT_SECTION("u8g_font_unifont_86");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont[] U8G_FONT_SECTION("u8g_font_unifont");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifontr[] U8G_FONT_SECTION("u8g_font_unifontr");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont_0_8[] U8G_FONT_SECTION("u8g_font_unifont_0_8");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont_2_3[] U8G_FONT_SECTION("u8g_font_unifont_2_3");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont_4_5[] U8G_FONT_SECTION("u8g_font_unifont_4_5");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont_8_9[] U8G_FONT_SECTION("u8g_font_unifont_8_9");
 
extern const u8g_fntpgm_uint8_t u8g_font_unifont_12_13[] U8G_FONT_SECTION("u8g_font_unifont_12_13");
 

	
 

	
 
/* 04b fonts */
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_04b_03b[] U8G_FONT_SECTION("u8g_font_04b_03b"); 
 
extern const u8g_fntpgm_uint8_t u8g_font_04b_03bn[] U8G_FONT_SECTION("u8g_font_04b_03bn");
 
extern const u8g_fntpgm_uint8_t u8g_font_04b_03br[] U8G_FONT_SECTION("u8g_font_04b_03br");
 
extern const u8g_fntpgm_uint8_t u8g_font_04b_03[] U8G_FONT_SECTION("u8g_font_04b_03");
 
extern const u8g_fntpgm_uint8_t u8g_font_04b_03n[] U8G_FONT_SECTION("u8g_font_04b_03n");
 
extern const u8g_fntpgm_uint8_t u8g_font_04b_03r[] U8G_FONT_SECTION("u8g_font_04b_03r");
 
extern const u8g_fntpgm_uint8_t u8g_font_04b_24[] U8G_FONT_SECTION("u8g_font_04b_24");
 
extern const u8g_fntpgm_uint8_t u8g_font_04b_24n[] U8G_FONT_SECTION("u8g_font_04b_24n");
 
extern const u8g_fntpgm_uint8_t u8g_font_04b_24r[] U8G_FONT_SECTION("u8g_font_04b_24r");
 

	
 
/* orgdot fonts */
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_orgv01[] U8G_FONT_SECTION("u8g_font_orgv01");
 
extern const u8g_fntpgm_uint8_t u8g_font_orgv01r[] U8G_FONT_SECTION("u8g_font_orgv01r");
 
extern const u8g_fntpgm_uint8_t u8g_font_orgv01n[] U8G_FONT_SECTION("u8g_font_orgv01n");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_fixed_v0[] U8G_FONT_SECTION("u8g_font_fixed_v0");
 
extern const u8g_fntpgm_uint8_t u8g_font_fixed_v0r[] U8G_FONT_SECTION("u8g_font_fixed_v0r");
 
extern const u8g_fntpgm_uint8_t u8g_font_fixed_v0n[] U8G_FONT_SECTION("u8g_font_fixed_v0n");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_tpssb[] U8G_FONT_SECTION("u8g_font_tpssb");
 
extern const u8g_fntpgm_uint8_t u8g_font_tpssbr[] U8G_FONT_SECTION("u8g_font_tpssbr");
 
extern const u8g_fntpgm_uint8_t u8g_font_tpssbn[] U8G_FONT_SECTION("u8g_font_tpssbn");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_tpss[] U8G_FONT_SECTION("u8g_font_tpss");
 
extern const u8g_fntpgm_uint8_t u8g_font_tpssr[] U8G_FONT_SECTION("u8g_font_tpssr");
 
extern const u8g_fntpgm_uint8_t u8g_font_tpssn[] U8G_FONT_SECTION("u8g_font_tpssn");
 

	
 
/* contributed */
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_freedoomr25n[] U8G_FONT_SECTION("u8g_font_freedoomr25n");
 
extern const u8g_fntpgm_uint8_t u8g_font_freedoomr10r[] U8G_FONT_SECTION("u8g_font_freedoomr10r");
 

	
 
/* adobe X11 */
 
extern const u8g_fntpgm_uint8_t u8g_font_courB08[] U8G_FONT_SECTION("u8g_font_courB08");
 
extern const u8g_fntpgm_uint8_t u8g_font_courB08r[] U8G_FONT_SECTION("u8g_font_courB08r");
 
extern const u8g_fntpgm_uint8_t u8g_font_courB10[] U8G_FONT_SECTION("u8g_font_courB10");
 
extern const u8g_fntpgm_uint8_t u8g_font_courB10r[] U8G_FONT_SECTION("u8g_font_courB10r");
 
extern const u8g_fntpgm_uint8_t u8g_font_courB12[] U8G_FONT_SECTION("u8g_font_courB12");
 
extern const u8g_fntpgm_uint8_t u8g_font_courB12r[] U8G_FONT_SECTION("u8g_font_courB12r");
 
extern const u8g_fntpgm_uint8_t u8g_font_courB14[] U8G_FONT_SECTION("u8g_font_courB14");
 
extern const u8g_fntpgm_uint8_t u8g_font_courB14r[] U8G_FONT_SECTION("u8g_font_courB14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_courB18[] U8G_FONT_SECTION("u8g_font_courB18");
 
extern const u8g_fntpgm_uint8_t u8g_font_courB18r[] U8G_FONT_SECTION("u8g_font_courB18r");
 
extern const u8g_fntpgm_uint8_t u8g_font_courB24[] U8G_FONT_SECTION("u8g_font_courB24");
 
extern const u8g_fntpgm_uint8_t u8g_font_courB24r[] U8G_FONT_SECTION("u8g_font_courB24r");
 
extern const u8g_fntpgm_uint8_t u8g_font_courB24n[] U8G_FONT_SECTION("u8g_font_courB24n");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_courR08[] U8G_FONT_SECTION("u8g_font_courR08");
 
extern const u8g_fntpgm_uint8_t u8g_font_courR08r[] U8G_FONT_SECTION("u8g_font_courR08r");
 
extern const u8g_fntpgm_uint8_t u8g_font_courR10[] U8G_FONT_SECTION("u8g_font_courR10");
 
extern const u8g_fntpgm_uint8_t u8g_font_courR10r[] U8G_FONT_SECTION("u8g_font_courR10r");
 
extern const u8g_fntpgm_uint8_t u8g_font_courR12[] U8G_FONT_SECTION("u8g_font_courR12");
 
extern const u8g_fntpgm_uint8_t u8g_font_courR12r[] U8G_FONT_SECTION("u8g_font_courR12r");
 
extern const u8g_fntpgm_uint8_t u8g_font_courR14[] U8G_FONT_SECTION("u8g_font_courR14");
 
extern const u8g_fntpgm_uint8_t u8g_font_courR14r[] U8G_FONT_SECTION("u8g_font_courR14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_courR18[] U8G_FONT_SECTION("u8g_font_courR18");
 
extern const u8g_fntpgm_uint8_t u8g_font_courR18r[] U8G_FONT_SECTION("u8g_font_courR18r");
 
extern const u8g_fntpgm_uint8_t u8g_font_courR24[] U8G_FONT_SECTION("u8g_font_courR24");
 
extern const u8g_fntpgm_uint8_t u8g_font_courR24r[] U8G_FONT_SECTION("u8g_font_courR24r");
 
extern const u8g_fntpgm_uint8_t u8g_font_courR24n[] U8G_FONT_SECTION("u8g_font_courR24n");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_helvB08[] U8G_FONT_SECTION("u8g_font_helvB08");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvB08r[] U8G_FONT_SECTION("u8g_font_helvB08r");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvB10[] U8G_FONT_SECTION("u8g_font_helvB10");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvB10r[] U8G_FONT_SECTION("u8g_font_helvB10r");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvB12[] U8G_FONT_SECTION("u8g_font_helvB12");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvB12r[] U8G_FONT_SECTION("u8g_font_helvB12r");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvB14[] U8G_FONT_SECTION("u8g_font_helvB14");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvB14r[] U8G_FONT_SECTION("u8g_font_helvB14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvB18[] U8G_FONT_SECTION("u8g_font_helvB18");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvB18r[] U8G_FONT_SECTION("u8g_font_helvB18r");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvB24[] U8G_FONT_SECTION("u8g_font_helvB24");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvB24r[] U8G_FONT_SECTION("u8g_font_helvB24r");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvB24n[] U8G_FONT_SECTION("u8g_font_helvB24n");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_helvR08[] U8G_FONT_SECTION("u8g_font_helvR08");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvR08r[] U8G_FONT_SECTION("u8g_font_helvR08r");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvR10[] U8G_FONT_SECTION("u8g_font_helvR10");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvR10r[] U8G_FONT_SECTION("u8g_font_helvR10r");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvR12[] U8G_FONT_SECTION("u8g_font_helvR12");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvR12r[] U8G_FONT_SECTION("u8g_font_helvR12r");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvR14[] U8G_FONT_SECTION("u8g_font_helvR14");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvR14r[] U8G_FONT_SECTION("u8g_font_helvR14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvR18[] U8G_FONT_SECTION("u8g_font_helvR18");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvR18r[] U8G_FONT_SECTION("u8g_font_helvR18r");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvR24[] U8G_FONT_SECTION("u8g_font_helvR24");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvR24r[] U8G_FONT_SECTION("u8g_font_helvR24r");
 
extern const u8g_fntpgm_uint8_t u8g_font_helvR24n[] U8G_FONT_SECTION("u8g_font_helvR24n");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenB08[] U8G_FONT_SECTION("u8g_font_ncenB08");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenB08r[] U8G_FONT_SECTION("u8g_font_ncenB08r");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenB10[] U8G_FONT_SECTION("u8g_font_ncenB10");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenB10r[] U8G_FONT_SECTION("u8g_font_ncenB10r");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenB12[] U8G_FONT_SECTION("u8g_font_ncenB12");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenB12r[] U8G_FONT_SECTION("u8g_font_ncenB12r");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenB14[] U8G_FONT_SECTION("u8g_font_ncenB14");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenB14r[] U8G_FONT_SECTION("u8g_font_ncenB14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenB18[] U8G_FONT_SECTION("u8g_font_ncenB18");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenB18r[] U8G_FONT_SECTION("u8g_font_ncenB18r");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenB24[] U8G_FONT_SECTION("u8g_font_ncenB24");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenB24r[] U8G_FONT_SECTION("u8g_font_ncenB24r");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenB24n[] U8G_FONT_SECTION("u8g_font_ncenB24n");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenR08[] U8G_FONT_SECTION("u8g_font_ncenR08");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenR08r[] U8G_FONT_SECTION("u8g_font_ncenR08r");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenR10[] U8G_FONT_SECTION("u8g_font_ncenR10");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenR10r[] U8G_FONT_SECTION("u8g_font_ncenR10r");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenR12[] U8G_FONT_SECTION("u8g_font_ncenR12");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenR12r[] U8G_FONT_SECTION("u8g_font_ncenR12r");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenR14[] U8G_FONT_SECTION("u8g_font_ncenR14");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenR14r[] U8G_FONT_SECTION("u8g_font_ncenR14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenR18[] U8G_FONT_SECTION("u8g_font_ncenR18");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenR18r[] U8G_FONT_SECTION("u8g_font_ncenR18r");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenR24[] U8G_FONT_SECTION("u8g_font_ncenR24");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenR24r[] U8G_FONT_SECTION("u8g_font_ncenR24r");
 
extern const u8g_fntpgm_uint8_t u8g_font_ncenR24n[] U8G_FONT_SECTION("u8g_font_ncenR24n");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_symb08[] U8G_FONT_SECTION("u8g_font_symb08");
 
extern const u8g_fntpgm_uint8_t u8g_font_symb08r[] U8G_FONT_SECTION("u8g_font_symb08r");
 
extern const u8g_fntpgm_uint8_t u8g_font_symb10[] U8G_FONT_SECTION("u8g_font_symb10");
 
extern const u8g_fntpgm_uint8_t u8g_font_symb10r[] U8G_FONT_SECTION("u8g_font_symb10r");
 
extern const u8g_fntpgm_uint8_t u8g_font_symb12[] U8G_FONT_SECTION("u8g_font_symb12");
 
extern const u8g_fntpgm_uint8_t u8g_font_symb12r[] U8G_FONT_SECTION("u8g_font_symb12r");
 
extern const u8g_fntpgm_uint8_t u8g_font_symb14[] U8G_FONT_SECTION("u8g_font_symb14");
 
extern const u8g_fntpgm_uint8_t u8g_font_symb14r[] U8G_FONT_SECTION("u8g_font_symb14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_symb18[] U8G_FONT_SECTION("u8g_font_symb18");
 
extern const u8g_fntpgm_uint8_t u8g_font_symb18r[] U8G_FONT_SECTION("u8g_font_symb18r");
 
extern const u8g_fntpgm_uint8_t u8g_font_symb24[] U8G_FONT_SECTION("u8g_font_symb24");
 
extern const u8g_fntpgm_uint8_t u8g_font_symb24r[] U8G_FONT_SECTION("u8g_font_symb24r");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_timB08[] U8G_FONT_SECTION("u8g_font_timB08");
 
extern const u8g_fntpgm_uint8_t u8g_font_timB08r[] U8G_FONT_SECTION("u8g_font_timB08r");
 
extern const u8g_fntpgm_uint8_t u8g_font_timB10[] U8G_FONT_SECTION("u8g_font_timB10");
 
extern const u8g_fntpgm_uint8_t u8g_font_timB10r[] U8G_FONT_SECTION("u8g_font_timB10r");
 
extern const u8g_fntpgm_uint8_t u8g_font_timB12[] U8G_FONT_SECTION("u8g_font_timB12");
 
extern const u8g_fntpgm_uint8_t u8g_font_timB12r[] U8G_FONT_SECTION("u8g_font_timB12r");
 
extern const u8g_fntpgm_uint8_t u8g_font_timB14[] U8G_FONT_SECTION("u8g_font_timB14");
 
extern const u8g_fntpgm_uint8_t u8g_font_timB14r[] U8G_FONT_SECTION("u8g_font_timB14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_timB18[] U8G_FONT_SECTION("u8g_font_timB18");
 
extern const u8g_fntpgm_uint8_t u8g_font_timB18r[] U8G_FONT_SECTION("u8g_font_timB18r");
 
extern const u8g_fntpgm_uint8_t u8g_font_timB24[] U8G_FONT_SECTION("u8g_font_timB24");
 
extern const u8g_fntpgm_uint8_t u8g_font_timB24r[] U8G_FONT_SECTION("u8g_font_timB24r");
 
extern const u8g_fntpgm_uint8_t u8g_font_timB24n[] U8G_FONT_SECTION("u8g_font_timB24n");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_timR08[] U8G_FONT_SECTION("u8g_font_timR08");
 
extern const u8g_fntpgm_uint8_t u8g_font_timR08r[] U8G_FONT_SECTION("u8g_font_timR08r");
 
extern const u8g_fntpgm_uint8_t u8g_font_timR10[] U8G_FONT_SECTION("u8g_font_timR10");
 
extern const u8g_fntpgm_uint8_t u8g_font_timR10r[] U8G_FONT_SECTION("u8g_font_timR10r");
 
extern const u8g_fntpgm_uint8_t u8g_font_timR12[] U8G_FONT_SECTION("u8g_font_timR12");
 
extern const u8g_fntpgm_uint8_t u8g_font_timR12r[] U8G_FONT_SECTION("u8g_font_timR12r");
 
extern const u8g_fntpgm_uint8_t u8g_font_timR14[] U8G_FONT_SECTION("u8g_font_timR14");
 
extern const u8g_fntpgm_uint8_t u8g_font_timR14r[] U8G_FONT_SECTION("u8g_font_timR14r");
 
extern const u8g_fntpgm_uint8_t u8g_font_timR18[] U8G_FONT_SECTION("u8g_font_timR18");
 
extern const u8g_fntpgm_uint8_t u8g_font_timR18r[] U8G_FONT_SECTION("u8g_font_timR18r");
 
extern const u8g_fntpgm_uint8_t u8g_font_timR24[] U8G_FONT_SECTION("u8g_font_timR24");
 
extern const u8g_fntpgm_uint8_t u8g_font_timR24r[] U8G_FONT_SECTION("u8g_font_timR24r");
 
extern const u8g_fntpgm_uint8_t u8g_font_timR24n[] U8G_FONT_SECTION("u8g_font_timR24n");
 

	
 
/* fontstruct */
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_p01type[] U8G_FONT_SECTION("u8g_font_p01type");
 
extern const u8g_fntpgm_uint8_t u8g_font_p01typer[] U8G_FONT_SECTION("u8g_font_p01typer");
 
extern const u8g_fntpgm_uint8_t u8g_font_p01typen[] U8G_FONT_SECTION("u8g_font_p01typen");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_lucasfont_alternate[] U8G_FONT_SECTION("u8g_font_lucasfont_alternate");
 
extern const u8g_fntpgm_uint8_t u8g_font_lucasfont_alternater[] U8G_FONT_SECTION("u8g_font_lucasfont_alternater");
 
extern const u8g_fntpgm_uint8_t u8g_font_lucasfont_alternaten[] U8G_FONT_SECTION("u8g_font_lucasfont_alternaten");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_chikita[] U8G_FONT_SECTION("u8g_font_chikita");
 
extern const u8g_fntpgm_uint8_t u8g_font_chikitar[] U8G_FONT_SECTION("u8g_font_chikitar");
 
extern const u8g_fntpgm_uint8_t u8g_font_chikitan[] U8G_FONT_SECTION("u8g_font_chikitan");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_pixelle_micro[] U8G_FONT_SECTION("u8g_font_pixelle_micro");
 
extern const u8g_fntpgm_uint8_t u8g_font_pixelle_micror[] U8G_FONT_SECTION("u8g_font_pixelle_micror");
 
extern const u8g_fntpgm_uint8_t u8g_font_pixelle_micron[] U8G_FONT_SECTION("u8g_font_pixelle_micron");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_trixel_square[] U8G_FONT_SECTION("u8g_font_trixel_square");
 
extern const u8g_fntpgm_uint8_t u8g_font_trixel_squarer[] U8G_FONT_SECTION("u8g_font_trixel_squarer");
 
extern const u8g_fntpgm_uint8_t u8g_font_trixel_squaren[] U8G_FONT_SECTION("u8g_font_trixel_squaren");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_robot_de_niro[] U8G_FONT_SECTION("u8g_font_robot_de_niro");
 
extern const u8g_fntpgm_uint8_t u8g_font_robot_de_niror[] U8G_FONT_SECTION("u8g_font_robot_de_niror");
 
extern const u8g_fntpgm_uint8_t u8g_font_robot_de_niron[] U8G_FONT_SECTION("u8g_font_robot_de_niron");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_baby[] U8G_FONT_SECTION("u8g_font_baby");
 
extern const u8g_fntpgm_uint8_t u8g_font_babyr[] U8G_FONT_SECTION("u8g_font_babyr");
 
extern const u8g_fntpgm_uint8_t u8g_font_babyn[] U8G_FONT_SECTION("u8g_font_babyn");
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_blipfest_07[] U8G_FONT_SECTION("u8g_font_blipfest_07");
 
extern const u8g_fntpgm_uint8_t u8g_font_blipfest_07r[] U8G_FONT_SECTION("u8g_font_blipfest_07r");
 
extern const u8g_fntpgm_uint8_t u8g_font_blipfest_07n[] U8G_FONT_SECTION("u8g_font_blipfest_07n");
 

	
 
/* profont */
 

	
 
extern const u8g_fntpgm_uint8_t u8g_font_profont10[] U8G_FONT_SECTION("u8g_font_profont10");
 
extern const u8g_fntpgm_uint8_t u8g_font_profont10r[] U8G_FONT_SECTION("u8g_font_profont10r");
 
extern const u8g_fntpgm_uint8_t u8g_font_profont11[] U8G_FONT_SECTION("u8g_font_profont11");
 
extern const u8g_fntpgm_uint8_t u8g_font_profont11r[] U8G_FONT_SECTION("u8g_font_profont11r");
 
extern const u8g_fntpgm_uint8_t u8g_font_profont12[] U8G_FONT_SECTION("u8g_font_profont12");
 
extern const u8g_fntpgm_uint8_t u8g_font_profont12r[] U8G_FONT_SECTION("u8g_font_profont12r");
 
extern const u8g_fntpgm_uint8_t u8g_font_profont15[] U8G_FONT_SECTION("u8g_font_profont15");
 
extern const u8g_fntpgm_uint8_t u8g_font_profont15r[] U8G_FONT_SECTION("u8g_font_profont15r");
 
extern const u8g_fntpgm_uint8_t u8g_font_profont17[] U8G_FONT_SECTION("u8g_font_profont17");
 
extern const u8g_fntpgm_uint8_t u8g_font_profont17r[] U8G_FONT_SECTION("u8g_font_profont17r");
 
extern const u8g_fntpgm_uint8_t u8g_font_profont22[] U8G_FONT_SECTION("u8g_font_profont22");
 
extern const u8g_fntpgm_uint8_t u8g_font_profont22r[] U8G_FONT_SECTION("u8g_font_profont22r");
 
extern const u8g_fntpgm_uint8_t u8g_font_profont29[] U8G_FONT_SECTION("u8g_font_profont29");
 
extern const u8g_fntpgm_uint8_t u8g_font_profont29r[] U8G_FONT_SECTION("u8g_font_profont29r");
 

	
 

	
 
#ifdef __cplusplus
 
}
 
#endif
 

	
 
#endif /* _U8G_H */
 

	
Libraries/u8glib/u8g_arm.c
Show inline comments
 
new file 100644
 
uint8_t u8g_com_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
 
{
 

	
 
  switch(msg)
 
  {
 
    case U8G_COM_MSG_STOP:
 
      break; //do nothing...
 

	
 
    case U8G_COM_MSG_INIT:
 
      i2c_init(); //inits the i2c hardware, gpios and timers
 
      u8g_MicroDelay();      
 
      break;
 

	
 
    case U8G_COM_MSG_ADDRESS: 
 
      //the control byte switches the mode on the device and is set here
 
      if (arg_val == 0)
 
      {
 
    	  control = 0;
 
      }
 
      else
 
      {
 
    	  control = 0x40;
 
      }
 
      u8g_10MicroDelay();
 
     break;
 

	
 
    case U8G_COM_MSG_RESET:
 
      //pin 9 is my reset pin
 
      GPIO_WriteBit(GPIOB, GPIO_Pin_9, arg_val);
 
      u8g_10MicroDelay();
 
      break;
 

	
 
    case U8G_COM_MSG_WRITE_BYTE:
 
      //simple: just write one byte
 
      i2c_out(arg_val);
 
      u8g_MicroDelay();
 
      break;
 

	
 
    case U8G_COM_MSG_WRITE_SEQ:
 
    case U8G_COM_MSG_WRITE_SEQ_P:
 
      {
 
        register uint8_t *ptr = arg_ptr;
 
        //send the control byte (to switch from command to data mode)
 
        I2C_start(SSD1306_I2C_ADDRESS, I2C_Direction_Transmitter);
 
    	I2C_SendData(I2C2, control);
 
    	while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
 

	
 
        //now send the rest of data
 
        while( arg_val > 0 )
 
        {
 
        	I2C_SendData(I2C2, *ptr++);
 
        	arg_val--;
 
        	while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
 
        }
 
        //done
 
    	I2C_stop();
 
        u8g_MicroDelay();
 
      }
 
      break;
 

	
 
  }
 
  return 1;
 
}
Libraries/u8glib/u8g_arm.h
Show inline comments
 
new file 100644
 
#ifndef _U8G_ARM_H
 
#define _U8G_ARM_H
 
 
 
//adjust this path:
 
#include "u8g.h"
 
 
 
//main com function. read on...
 
uint8_t u8g_com_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
 
 
 
#endif
Libraries/u8glib/u8g_bitmap.c
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g_bitmap.c
 

	
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2011, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
  
 

	
 
*/
 

	
 
#include "u8g.h"
 

	
 
void u8g_DrawHBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const uint8_t *bitmap)
 
{
 
  while( cnt > 0 )
 
  {
 
    u8g_Draw8Pixel(u8g, x, y, 0, *bitmap);
 
    bitmap++;
 
    cnt--;
 
    x+=8;
 
  }
 
}
 

	
 
void u8g_DrawBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const uint8_t *bitmap)
 
{
 
  if ( u8g_IsBBXIntersection(u8g, x, y, cnt*8, h) == 0 )
 
    return;
 
  while( h > 0 )
 
  {
 
    u8g_DrawHBitmap(u8g, x, y, cnt, bitmap);
 
    bitmap += cnt;
 
    y++;
 
    h--;
 
  }
 
}
 

	
 

	
 
void u8g_DrawHBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const u8g_pgm_uint8_t *bitmap)
 
{
 
  while( cnt > 0 )
 
  {
 
    u8g_Draw8Pixel(u8g, x, y, 0, u8g_pgm_read(bitmap));
 
    bitmap++;
 
    cnt--;
 
    x+=8;
 
  }
 
}
 

	
 
void u8g_DrawBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap)
 
{
 
  if ( u8g_IsBBXIntersection(u8g, x, y, cnt*8, h) == 0 )
 
    return;
 
  while( h > 0 )
 
  {
 
    u8g_DrawHBitmapP(u8g, x, y, cnt, bitmap);
 
    bitmap += cnt;
 
    y++;
 
    h--;
 
  }
 
}
 

	
 
/*=========================================================================*/
 

	
 
static void u8g_DrawHXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, const uint8_t *bitmap)
 
{
 
  uint8_t d;
 
  x+=7;
 
  while( w >= 8 )
 
  {
 
    u8g_Draw8Pixel(u8g, x, y, 2, *bitmap);
 
    bitmap++;
 
    w-= 8;
 
    x+=8;
 
  }
 
  if ( w > 0 )
 
  {
 
    d = *bitmap;
 
    x -= 7;
 
    do
 
    {
 
      if ( d & 1 )
 
        u8g_DrawPixel(u8g, x, y);
 
      x++;
 
      w--;
 
      d >>= 1;      
 
    } while ( w > 0 );
 
  }
 
}
 

	
 
void u8g_DrawXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const uint8_t *bitmap)
 
{
 
  u8g_uint_t b;
 
  b = w;
 
  b += 7;
 
  b >>= 3;
 
  
 
  if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
 
    return;
 
  
 
  while( h > 0 )
 
  {
 
    u8g_DrawHXBM(u8g, x, y, w, bitmap);
 
    bitmap += b;
 
    y++;
 
    h--;
 
  }
 
}
 

	
 
static void u8g_DrawHXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, const u8g_pgm_uint8_t *bitmap)
 
{
 
  uint8_t d;
 
  x+=7;
 
  while( w >= 8 )
 
  {
 
    u8g_Draw8Pixel(u8g, x, y, 2, u8g_pgm_read(bitmap));
 
    bitmap++;
 
    w-= 8;
 
    x+=8;
 
  }
 
  if ( w > 0 )
 
  {
 
    d = u8g_pgm_read(bitmap);
 
    x -= 7;
 
    do
 
    {
 
      if ( d & 1 )
 
        u8g_DrawPixel(u8g, x, y);
 
      x++;
 
      w--;
 
      d >>= 1;      
 
    } while ( w > 0 );
 
  }
 
}
 

	
 
void u8g_DrawXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap)
 
{
 
  u8g_uint_t b;
 
  b = w;
 
  b += 7;
 
  b >>= 3;
 
  
 
  if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
 
    return;
 
  while( h > 0 )
 
  {
 
    u8g_DrawHXBMP(u8g, x, y, w, bitmap);
 
    bitmap += b;
 
    y++;
 
    h--;
 
  }
 
}
Libraries/u8glib/u8g_circle.c
Show inline comments
 
new file 100644
 
/*
 
 
  u8g_circle.c
 
 
  Utility to draw empty and filled circles.
 
  
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2011, bjthom@gmail.com
 
  u8g_DrawCircle & u8g_DrawDisc by olikraus@gmail.com
 
  
 
  All rights reserved.
 
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
  
 
  Addition to the U8G Library 02/25/12
 
  
 
  
 
*/
 
 
#include "u8g.h"
 
 
#ifdef OLD_CODE
 
 
void circ_upperRight(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
 
  u8g_DrawPixel(u8g, x0 + x, y0 - y);
 
  u8g_DrawPixel(u8g, x0 + y, y0 - x);
 
}
 
		
 
void circ_upperLeft(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
 
  u8g_DrawPixel(u8g, x0 - x, y0 - y);
 
  u8g_DrawPixel(u8g, x0 - y, y0 - x);
 
}
 
		
 
void circ_lowerRight(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
 
  u8g_DrawPixel(u8g, x0 + x, y0 + y);
 
  u8g_DrawPixel(u8g, x0 + y, y0 + x);
 
}
 
		
 
void circ_lowerLeft(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
 
  u8g_DrawPixel(u8g, x0 - x, y0 + y);
 
  u8g_DrawPixel(u8g, x0 - y, y0 + x);
 
}
 
			
 
void circ_all(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) {
 
  circ_upperRight(u8g, x, y, x0, y0);
 
  circ_upperLeft(u8g, x, y, x0, y0);
 
  circ_lowerRight(u8g, x, y, x0, y0);
 
  circ_lowerLeft(u8g, x, y, x0, y0);
 
}
 
 
void u8g_DrawEmpCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
 
{
 
  if ( u8g_IsBBXIntersection(u8g, x0-rad-1, y0-rad-1, 2*rad+1, 2*rad+1) == 0)
 
    return;
 
 
  int f = 1 - rad;
 
  int ddF_x = 1;
 
  int ddF_y = -2*rad;
 
  uint8_t x = 0;
 
  uint8_t y = rad;
 
 
  void ( *circ_util )(u8g_t *, u8g_uint_t, u8g_uint_t, u8g_uint_t, u8g_uint_t);
 
  
 
  switch (option)
 
  {
 
	case U8G_CIRC_UPPER_RIGHT:
 
		u8g_DrawPixel(u8g, x0, y0 - rad);
 
		u8g_DrawPixel(u8g, x0 + rad, y0);
 
		circ_util = circ_upperRight;
 
		break;
 
	case U8G_CIRC_UPPER_LEFT:
 
		u8g_DrawPixel(u8g, x0, y0 - rad);
 
		u8g_DrawPixel(u8g, x0 - rad, y0);
 
		circ_util = circ_upperLeft;
 
		break;
 
	case U8G_CIRC_LOWER_RIGHT:
 
		u8g_DrawPixel(u8g, x0, y0 + rad);
 
		u8g_DrawPixel(u8g, x0 + rad, y0);
 
		circ_util = circ_lowerRight;
 
		break;
 
	case U8G_CIRC_LOWER_LEFT:
 
		u8g_DrawPixel(u8g, x0, y0 + rad);
 
		u8g_DrawPixel(u8g, x0 - rad, y0);
 
		circ_util = circ_lowerLeft;
 
		break;
 
        default:
 
	case U8G_CIRC_ALL:
 
		u8g_DrawPixel(u8g, x0, y0 + rad);
 
		u8g_DrawPixel(u8g, x0, y0 - rad);
 
		u8g_DrawPixel(u8g, x0 + rad, y0);
 
		u8g_DrawPixel(u8g, x0 - rad, y0);
 
		circ_util = circ_all;
 
		break;
 
  }
 
  
 
  while( x < y )
 
  {
 
    if(f >= 0) 
 
    {
 
      y--;
 
      ddF_y += 2;
 
      f += ddF_y;
 
    }
 
    x++;
 
    ddF_x += 2;
 
    f += ddF_x;
 
    
 
    circ_util(u8g, x, y, x0, y0);
 
  }
 
}
 
 
 
void u8g_DrawFillCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
 
{
 
  if ( u8g_IsBBXIntersection(u8g, x0-rad-1, y0-rad-1, 2*rad+1, 2*rad+1) == 0)
 
    return;
 
 
  int f = 1 - rad;
 
  int ddF_x = 1;
 
  int ddF_y = -2*rad;
 
  uint8_t x = 0;
 
  uint8_t y = rad;
 
  
 
  // Draw vertical diameter at the horiz. center
 
  // u8g_DrawVLine(u8g, x0, y0 - rad, 2*rad+1);
 
 
  if (option == U8G_CIRC_UPPER_LEFT || option == U8G_CIRC_UPPER_RIGHT) {
 
	u8g_DrawVLine(u8g, x0, y0 - rad, rad+1);
 
  }
 
  else if (option == U8G_CIRC_LOWER_LEFT || option == U8G_CIRC_LOWER_RIGHT) {
 
	u8g_DrawVLine(u8g, x0, y0, rad+1);
 
  }
 
  else {
 
	u8g_DrawVLine(u8g, x0, y0 - rad, 2*rad+1);
 
  }
 
  
 
  while( x < y )
 
  {
 
    if(f >= 0) 
 
    {
 
      y--;
 
      ddF_y += 2;
 
      f += ddF_y;
 
    }
 
    x++;
 
    ddF_x += 2;
 
    f += ddF_x;
 
    
 
	//Draw vertical lines from one point to another
 
	
 
	switch (option)
 
	{
 
		case U8G_CIRC_UPPER_RIGHT:
 
			u8g_DrawVLine(u8g, x0+x, y0-y, y+1);
 
			u8g_DrawVLine(u8g, x0+y, y0-x, x+1);
 
			break;
 
		case U8G_CIRC_UPPER_LEFT:
 
			u8g_DrawVLine(u8g, x0-x, y0-y, y+1);
 
			u8g_DrawVLine(u8g, x0-y, y0-x, x+1);
 
			break;
 
		case U8G_CIRC_LOWER_RIGHT:
 
			u8g_DrawVLine(u8g, x0+x, y0, y+1);
 
			u8g_DrawVLine(u8g, x0+y, y0, x+1);
 
			break;
 
		case U8G_CIRC_LOWER_LEFT:
 
			u8g_DrawVLine(u8g, x0-x, y0, y+1);
 
			u8g_DrawVLine(u8g, x0-y, y0, x+1);
 
			break;
 
		case U8G_CIRC_ALL:
 
			u8g_DrawVLine(u8g, x0+x, y0-y, 2*y+1);
 
			u8g_DrawVLine(u8g, x0-x, y0-y, 2*y+1);
 
			u8g_DrawVLine(u8g, x0+y, y0-x, 2*x+1);
 
			u8g_DrawVLine(u8g, x0-y, y0-x, 2*x+1);
 
			break;
 
	}
 
  }
 
}
 
 
#endif 
 
 
/*=========================================================================*/
 
 
static void u8g_draw_circle_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) U8G_NOINLINE;
 
 
static void u8g_draw_circle_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option)
 
{
 
    /* upper right */
 
    if ( option & U8G_DRAW_UPPER_RIGHT )
 
    {
 
      u8g_DrawPixel(u8g, x0 + x, y0 - y);
 
      u8g_DrawPixel(u8g, x0 + y, y0 - x);
 
    }
 
    
 
    /* upper left */
 
    if ( option & U8G_DRAW_UPPER_LEFT )
 
    {
 
      u8g_DrawPixel(u8g, x0 - x, y0 - y);
 
      u8g_DrawPixel(u8g, x0 - y, y0 - x);
 
    }
 
    
 
    /* lower right */
 
    if ( option & U8G_DRAW_LOWER_RIGHT )
 
    {
 
      u8g_DrawPixel(u8g, x0 + x, y0 + y);
 
      u8g_DrawPixel(u8g, x0 + y, y0 + x);
 
    }
 
    
 
    /* lower left */
 
    if ( option & U8G_DRAW_LOWER_LEFT )
 
    {
 
      u8g_DrawPixel(u8g, x0 - x, y0 + y);
 
      u8g_DrawPixel(u8g, x0 - y, y0 + x);
 
    }
 
}
 
 
void u8g_draw_circle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
 
{
 
    u8g_int_t f;
 
    u8g_int_t ddF_x;
 
    u8g_int_t ddF_y;
 
    u8g_uint_t x;
 
    u8g_uint_t y;
 
 
    f = 1;
 
    f -= rad;
 
    ddF_x = 1;
 
    ddF_y = 0;
 
    ddF_y -= rad;
 
    ddF_y *= 2;
 
    x = 0;
 
    y = rad;
 
 
    u8g_draw_circle_section(u8g, x, y, x0, y0, option);
 
    
 
    while ( x < y )
 
    {
 
      if (f >= 0) 
 
      {
 
        y--;
 
        ddF_y += 2;
 
        f += ddF_y;
 
      }
 
      x++;
 
      ddF_x += 2;
 
      f += ddF_x;
 
 
      u8g_draw_circle_section(u8g, x, y, x0, y0, option);    
 
    }
 
}
 
 
void u8g_DrawCircle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
 
{
 
  /* check for bounding box */
 
  {
 
    u8g_uint_t radp, radp2;
 
    
 
    radp = rad;
 
    radp++;
 
    radp2 = radp;
 
    radp2 *= 2;
 
    
 
    if ( u8g_IsBBXIntersection(u8g, x0-radp, y0-radp, radp2, radp2) == 0)
 
      return;    
 
  }
 
  
 
  /* draw circle */
 
  u8g_draw_circle(u8g, x0, y0, rad, option);
 
}
 
 
static void u8g_draw_disc_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) U8G_NOINLINE;
 
 
static void u8g_draw_disc_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option)
 
{
 
    /* upper right */
 
    if ( option & U8G_DRAW_UPPER_RIGHT )
 
    {
 
      u8g_DrawVLine(u8g, x0+x, y0-y, y+1);
 
      u8g_DrawVLine(u8g, x0+y, y0-x, x+1);
 
    }
 
    
 
    /* upper left */
 
    if ( option & U8G_DRAW_UPPER_LEFT )
 
    {
 
      u8g_DrawVLine(u8g, x0-x, y0-y, y+1);
 
      u8g_DrawVLine(u8g, x0-y, y0-x, x+1);
 
    }
 
    
 
    /* lower right */
 
    if ( option & U8G_DRAW_LOWER_RIGHT )
 
    {
 
      u8g_DrawVLine(u8g, x0+x, y0, y+1);
 
      u8g_DrawVLine(u8g, x0+y, y0, x+1);
 
    }
 
    
 
    /* lower left */
 
    if ( option & U8G_DRAW_LOWER_LEFT )
 
    {
 
      u8g_DrawVLine(u8g, x0-x, y0, y+1);
 
      u8g_DrawVLine(u8g, x0-y, y0, x+1);
 
    }
 
}
 
 
void u8g_draw_disc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
 
{
 
  u8g_int_t f;
 
  u8g_int_t ddF_x;
 
  u8g_int_t ddF_y;
 
  u8g_uint_t x;
 
  u8g_uint_t y;
 
 
  f = 1;
 
  f -= rad;
 
  ddF_x = 1;
 
  ddF_y = 0;
 
  ddF_y -= rad;
 
  ddF_y *= 2;
 
  x = 0;
 
  y = rad;
 
 
  u8g_draw_disc_section(u8g, x, y, x0, y0, option);
 
  
 
  while ( x < y )
 
  {
 
    if (f >= 0) 
 
    {
 
      y--;
 
      ddF_y += 2;
 
      f += ddF_y;
 
    }
 
    x++;
 
    ddF_x += 2;
 
    f += ddF_x;
 
 
    u8g_draw_disc_section(u8g, x, y, x0, y0, option);    
 
  }
 
}
 
 
void u8g_DrawDisc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option)
 
{
 
  /* check for bounding box */
 
  {
 
    u8g_uint_t radp, radp2;
 
    
 
    radp = rad;
 
    radp++;
 
    radp2 = radp;
 
    radp2 *= 2;
 
    
 
    if ( u8g_IsBBXIntersection(u8g, x0-radp, y0-radp, radp2, radp2) == 0)
 
      return;    
 
  }
 
  
 
  /* draw disc */
 
  u8g_draw_disc(u8g, x0, y0, rad, option);
 
}
 
 
 
 
Libraries/u8glib/u8g_clip.c
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g_clip.c
 
  
 
  procedures for clipping
 
  taken over from procs in u8g_pb.c
 

	
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2012, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
  
 
  Notes
 
  
 
  This is one of the most critical parts of u8glib. It must be fast, but still reliable.
 
  Based on the intersection program (see tools folder), there is minimized version of
 
  the condition for the intersaction test:
 
    minimized version
 
    ---1----0 1             b1 <= a2 && b1 > b2
 
    -----1--0 1             b2 >= a1 && b1 > b2
 
    ---1-1--- 1             b1 <= a2 && b2 >= a1
 
  It includes the assumption, that a1 <= a2 is always true (correct, because
 
  a1, a2 are the page dimensions.
 

	
 
  The direct implementation of the above result is done in:
 
  uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
 
  However, this is slower than a decision tree version:  
 
  static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 
 
  Also suprising is, that the macro implementation is slower than the inlined version.
 
  
 
  The decision tree is based on the expansion of the truth table.
 
  
 
*/
 

	
 
#include "u8g.h"
 

	
 
#ifdef __GNUC__
 
#define U8G_ALWAYS_INLINE __inline__ __attribute__((always_inline))
 
#else
 
#define U8G_ALWAYS_INLINE
 
 #endif 
 

	
 
/*
 
  intersection assumptions:
 
    a1 <= a2 is always true    
 
    
 
    minimized version
 
    ---1----0 1             b1 <= a2 && b1 > b2
 
    -----1--0 1             b2 >= a1 && b1 > b2
 
    ---1-1--- 1             b1 <= a2 && b2 >= a1
 
  */
 

	
 
#ifdef OLD_CODE_WHICH_IS_TOO_SLOW
 
static uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
 
{
 
  uint8_t c1, c2, c3, tmp;
 
  c1 = v0 <= a1;
 
  c2 = v1 >= a0;
 
  c3 = v0 > v1;
 
  
 
  tmp = c1;
 
  c1 &= c2;
 
  c2 &= c3;
 
  c3 &= tmp;
 
  c1 |= c2;
 
  c1 |= c3;
 
  return c1 & 1;
 
}
 
#endif
 

	
 
#define U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1) ((uint8_t)( (v0) <= (a1) ) ? ( ( (v1) >= (a0) ) ? ( 1 ) : ( (v0) > (v1) ) ) : ( ( (v1) >= (a0) ) ? ( (v0) > (v1) ) : ( 0 ) ))
 

	
 
//static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) U8G_ALWAYS_INLINE;
 
static uint8_t U8G_ALWAYS_INLINE u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 
 
{
 
  /* surprisingly the macro leads to larger code */
 
  /* return U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1); */
 
  if ( v0 <= a1 )
 
  {
 
    if ( v1 >= a0 )
 
    {
 
      return 1;
 
    }
 
    else
 
    {
 
      if ( v0 > v1 )
 
      {
 
	return 1;
 
      }
 
      else
 
      {
 
	return 0;
 
      }
 
    }
 
  }
 
  else
 
  {
 
    if ( v1 >= a0 )
 
    {
 
      if ( v0 > v1 )
 
      {
 
	return 1;
 
      }
 
      else
 
      {
 
	return 0;
 
      }
 
    }
 
    else
 
    {
 
      return 0;
 
    }
 
  }
 
}
 

	
 

	
 
uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
 
{
 
  register u8g_uint_t tmp;
 
  tmp = y;
 
  tmp += h;
 
  tmp--;
 
  if ( u8g_is_intersection_decision_tree(u8g->current_page.y0, u8g->current_page.y1, y, tmp) == 0 )
 
    return 0; 
 
  
 
  tmp = x;
 
  tmp += w;
 
  tmp--;
 
  return u8g_is_intersection_decision_tree(u8g->current_page.x0, u8g->current_page.x1, x, tmp);
 
}
 

	
 

	
Libraries/u8glib/u8g_com_api.c
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g_com_api.c
 

	
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2011, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
  
 
  
 
*/
 

	
 
#include "u8g.h"
 

	
 
uint8_t u8g_InitCom(u8g_t *u8g, u8g_dev_t *dev, uint8_t clk_cycle_time)
 
{
 
  return dev->com_fn(u8g, U8G_COM_MSG_INIT, clk_cycle_time, NULL);
 
}
 

	
 
void u8g_StopCom(u8g_t *u8g, u8g_dev_t *dev)
 
{
 
  dev->com_fn(u8g, U8G_COM_MSG_STOP, 0, NULL);
 
}
 

	
 
/* cs contains the chip number, which should be enabled */
 
void u8g_SetChipSelect(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs)
 
{
 
  dev->com_fn(u8g, U8G_COM_MSG_CHIP_SELECT, cs, NULL);
 
}
 

	
 
void u8g_SetResetLow(u8g_t *u8g, u8g_dev_t *dev)
 
{
 
  dev->com_fn(u8g, U8G_COM_MSG_RESET, 0, NULL);
 
}
 

	
 
void u8g_SetResetHigh(u8g_t *u8g, u8g_dev_t *dev)
 
{
 
  dev->com_fn(u8g, U8G_COM_MSG_RESET, 1, NULL);
 
}
 

	
 

	
 
void u8g_SetAddress(u8g_t *u8g, u8g_dev_t *dev, uint8_t address)
 
{
 
  dev->com_fn(u8g, U8G_COM_MSG_ADDRESS, address, NULL);
 
}
 

	
 
uint8_t u8g_WriteByte(u8g_t *u8g, u8g_dev_t *dev, uint8_t val)
 
{
 
  return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, val, NULL);
 
}
 

	
 
uint8_t u8g_WriteSequence(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *seq)
 
{
 
  return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, cnt, seq);
 
}
 

	
 
uint8_t u8g_WriteSequenceP(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, const uint8_t *seq)
 
{
 
  return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ_P, cnt, (void *)seq);
 
}
 

	
 
/*
 
  sequence := { direct_value | escape_sequence }
 
  direct_value := 0..254
 
  escape_sequence := value_255 | sequence_end | delay | adr | cs | not_used 
 
  value_255 := 255 255
 
  sequence_end = 255 254
 
  delay := 255 0..127
 
  adr := 255 0x0e0 .. 0x0ef 
 
  cs := 255 0x0d0 .. 0x0df 
 
  not_used := 255 101..254
 

	
 
#define U8G_ESC_DLY(x) 255, ((x) & 0x7f)
 
#define U8G_ESC_CS(x) 255, (0xd0 | ((x)&0x0f))
 
#define U8G_ESC_ADR(x) 255, (0xe0 | ((x)&0x0f))
 
#define U8G_ESC_VCC(x) 255, (0xbe | ((x)&0x01))
 
#define U8G_ESC_END 255, 254
 
#define U8G_ESC_255 255, 255
 
#define U8G_ESC_RST(x) 255, (0xc0 | ((x)&0x0f))
 

	
 
*/
 
uint8_t u8g_WriteEscSeqP(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq)
 
{
 
  uint8_t is_escape = 0;
 
  uint8_t value;
 
  for(;;)
 
  {
 
    value = u8g_pgm_read(esc_seq);
 
    if ( is_escape == 0 )
 
    {
 
      if ( value != 255 )
 
      {
 
        if ( u8g_WriteByte(u8g, dev, value) == 0 )
 
          return 0;
 
      }
 
      else
 
      {
 
        is_escape = 1;
 
      }
 
    }
 
    else
 
    {
 
      if ( value == 255 )
 
      {
 
        if ( u8g_WriteByte(u8g, dev, value) == 0 )
 
          return 0;
 
      }
 
      else if ( value == 254 )
 
      {
 
        break;
 
      }
 
      else if ( value >= 0x0f0 )
 
      {
 
        /* not yet used, do nothing */
 
      }
 
      else if ( value >= 0xe0  )
 
      {
 
        u8g_SetAddress(u8g, dev, value & 0x0f);
 
      }
 
      else if ( value >= 0xd0 )
 
      {
 
        u8g_SetChipSelect(u8g, dev, value & 0x0f);
 
      }
 
      else if ( value >= 0xc0 )
 
      {
 
        u8g_SetResetLow(u8g, dev);
 
        value &= 0x0f;
 
        value <<= 4;
 
        value+=2;
 
        u8g_Delay(value);
 
        u8g_SetResetHigh(u8g, dev);
 
        u8g_Delay(value);
 
      }
 
      else if ( value >= 0xbe )
 
      {
 
	/* not yet implemented */
 
        /* u8g_SetVCC(u8g, dev, value & 0x01); */
 
      }
 
      else if ( value <= 127 )
 
      {
 
        u8g_Delay(value);
 
      }
 
      is_escape = 0;
 
    }
 
    esc_seq++;
 
  }
 
  return 1;
 
}
 

	
Libraries/u8glib/u8g_com_api_16gr.c
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g_com_api_16gr.c
 
  
 
  Extension of the com api for devices with 16 graylevels (4 bit per pixel).
 
  This should fit to the 8h and 16h architectures (pb8v1, pb8v2, pb16v1, pb16v2), 
 
  mainly intended for SSD OLEDs
 

	
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2011, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
  
 
  
 
*/
 

	
 
#include "u8g.h"
 

	
 
/* interpret b as a monochrome bit pattern, write value 15 for high bit and value 0 for a low bit */
 
/* topbit (msb) is sent last */
 
/* example: b = 0x083 will send 0xff, 0x00, 0x00, 0xf0 */
 
uint8_t u8g_WriteByteBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b)
 
{
 
  static uint8_t buf[4];
 
  static uint8_t map[4] = { 0, 0x00f, 0x0f0, 0x0ff };
 
  buf [3] = map[b & 3];
 
  b>>=2;
 
  buf [2] = map[b & 3];
 
  b>>=2;
 
  buf [1] = map[b & 3];
 
  b>>=2;
 
  buf [0] = map[b & 3];
 
  return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, 4, buf);
 
}
 

	
 
uint8_t u8g_WriteSequenceBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr)
 
{
 
  do
 
  {
 
    if ( u8g_WriteByteBWTo16GrDevice(u8g, dev, *ptr++) == 0 )
 
      return 0;
 
    cnt--;
 
  } while( cnt != 0 );
 
  return 1;
 
}
 

	
 
/* interpret b as a 4L bit pattern, write values 0x000, 0x004, 0x008, 0x00c */
 
uint8_t u8g_WriteByte4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b)
 
{
 
  //static uint8_t map[16] = { 0x000, 0x004, 0x008, 0x00c, 0x040, 0x044, 0x048, 0x04c, 0x080, 0x084, 0x088, 0x08c, 0x0c0, 0x0c4, 0x0c8, 0x0cc};
 
  //static uint8_t map[16] = { 0x000, 0x004, 0x00a, 0x00f, 0x040, 0x044, 0x04a, 0x04f, 0x0a0, 0x0a4, 0x0aa, 0x0af, 0x0f0, 0x0f4, 0x0fa, 0x0ff};
 
  static uint8_t map[16] = { 0x000, 0x040, 0x0a0, 0x0f0, 0x004, 0x044, 0x0a4, 0x0f4, 0x00a, 0x04a, 0x0aa, 0x0fa, 0x00f, 0x04f, 0x0af, 0x0ff};
 
  uint8_t bb;
 
  bb = b;
 
  bb &= 15;
 
  b>>=4;
 
  dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[bb], NULL);
 
  return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[b], NULL);
 
}
 

	
 
uint8_t u8g_WriteSequence4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr)
 
{
 
  do
 
  {
 
    if ( u8g_WriteByte4LTo16GrDevice(u8g, dev, *ptr++) == 0 )
 
      return 0;
 
    cnt--;
 
  } while( cnt != 0 );
 
  return 1;
 
}
Libraries/u8glib/u8g_com_i2c.c
Show inline comments
 
new file 100644
 
/*
 
  
 
  u8g_com_i2c.c
 

	
 
  generic i2c interface
 

	
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2011, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
  
 
*/
 

	
 
#include "u8g.h"
 

	
 
static uint8_t u8g_i2c_err_code;
 

	
 
/*
 
  position values
 
    1: start condition
 
    2: sla transfer
 
*/
 
static uint8_t u8g_i2c_err_pos;
 

	
 

	
 
void u8g_i2c_clear_error(void)
 
{
 
  u8g_i2c_err_code = U8G_I2C_ERR_NONE;
 
  u8g_i2c_err_pos = 0;
 
}
 

	
 
uint8_t  u8g_i2c_get_error(void)
 
{
 
  return u8g_i2c_err_code;
 
}
 

	
 
uint8_t u8g_i2c_get_err_pos(void)
 
{
 
  return u8g_i2c_err_pos;
 
}
 

	
 
static void u8g_i2c_set_error(uint8_t code, uint8_t pos)
 
{
 
  if ( u8g_i2c_err_code > 0 )
 
    return;
 
  u8g_i2c_err_code |= code;
 
  u8g_i2c_err_pos = pos;
 
}
 

	
 

	
 

	
 
#if defined(__AVR__)
 
#define U8G_ATMEGA_HW_TWI
 

	
 
/* remove the definition for attiny */
 
#if __AVR_ARCH__ == 2
 
#undef U8G_ATMEGA_HW_TWI
 
#endif
 
#if __AVR_ARCH__ == 25
 
#undef U8G_ATMEGA_HW_TWI
 
#endif
 
#endif
 

	
 
#if defined(U8G_ATMEGA_HW_TWI)
 

	
 
#include <avr/io.h>
 
#include <util/twi.h>
 

	
 

	
 

	
 
void u8g_i2c_init(uint8_t options)
 
{
 
  /*
 
  TWBR: bit rate register
 
  TWSR: status register (contains preselector bits)
 

	
 
  prescalar
 
    0		1
 
    1		4
 
    2		16
 
    3		64
 

	
 
  f = F_CPU/(16+2*TWBR*prescalar)
 
  
 
  F_CPU = 16MHz
 
    TWBR = 152;
 
    TWSR = 0;
 
	--> 50KHz
 

	
 
    TWBR = 72;
 
    TWSR = 0;
 
	--> 100KHz
 

	
 
    F_CPU/(2*100000)-8  --> calculate TWBR value for 100KHz
 
*/
 
  TWSR = 0;
 
  TWBR = F_CPU/(2*100000)-8;
 
  u8g_i2c_clear_error();
 
}
 

	
 
uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos)
 
{
 
  volatile uint16_t cnt = 2000;	/* timout value should be > 280 for 50KHz Bus and 16 Mhz CPU, however the start condition might need longer */
 
  while( !(TWCR & mask) )
 
  {
 
      if ( cnt == 0 )
 
      {
 
	u8g_i2c_set_error(U8G_I2C_ERR_TIMEOUT, pos);
 
	return 0; /* error */
 
      }
 
      cnt--;
 
    }
 
  return 1;	/* all ok */
 
}
 

	
 
/* sla includes all 8 bits (with r/w bit), assums master transmit */
 
uint8_t u8g_i2c_start(uint8_t sla)
 
{
 
  register uint8_t status;
 
  
 
  /* send start */
 
  TWCR = _BV(TWINT) |  _BV(TWSTA)  |  _BV(TWEN);
 
   
 
  /* wait */
 
  if ( u8g_i2c_wait(_BV(TWINT), 1) == 0 )
 
    return 0;
 
  
 
  status = TW_STATUS;
 
 
 
  /* check status after start */  
 
  if ( status != TW_START && status != TW_REP_START )
 
  {
 
    u8g_i2c_set_error(U8G_I2C_ERR_BUS, 1);
 
    return 0;
 
  }
 

	
 
  /* set slave address */  
 
  TWDR = sla;
 
  
 
  /* enable sla transfer */
 
  TWCR = _BV(TWINT)  |  _BV(TWEN);
 

	
 
  /* wait */
 
  if ( u8g_i2c_wait(_BV(TWINT), 2) == 0 )
 
    return 0;
 
  status = TW_STATUS;
 

	
 
  /* check status after sla */  
 
  if ( status != TW_MT_SLA_ACK )
 
  {
 
    u8g_i2c_set_error(U8G_I2C_ERR_BUS, 2);
 
    return 0;
 
  }
 

	
 
   return 1;
 
}
 

	
 
uint8_t u8g_i2c_send_byte(uint8_t data)
 
{
 
  register uint8_t status;
 
  TWDR = data;
 
  TWCR = _BV(TWINT)  |  _BV(TWEN);
 
  if ( u8g_i2c_wait(_BV(TWINT), 3) == 0 )
 
    return 0;
 
  status = TW_STATUS;
 
  
 
  if ( status != TW_MT_DATA_ACK )
 
  {
 
    u8g_i2c_set_error(U8G_I2C_ERR_BUS, 3);
 
    return 0;
 
  }
 
  
 
  return 1;  
 
}
 

	
 
void u8g_i2c_stop(void)
 
{
 
  /* write stop */
 
  TWCR = _BV(TWINT) | _BV(TWEN) | _BV(TWSTO);
 

	
 
  /* no error is checked for the stop condition */  
 
  u8g_i2c_wait(_BV(TWSTO), 4);
 
  
 
}
 

	
 
/*
 
void twi_send(uint8_t adr, uint8_t data1, uint8_t data2)
 
{
 
  u8g_i2c_start(adr<<1);
 
  u8g_i2c_send_byte(data1);
 
  u8g_i2c_send_byte(data2);
 
  u8g_i2c_stop();
 
}
 
*/
 

	
 
#else
 

	
 
/* empty interface */
 

	
 
void u8g_i2c_init(uint8_t options)
 
{
 
  u8g_i2c_clear_error();
 
}
 

	
 
uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos)
 
{
 
  return 1;
 
}
 

	
 
uint8_t u8g_i2c_start(uint8_t sla)
 
{
 
  return 1;
 
}
 
uint8_t u8g_i2c_send_byte(uint8_t data)
 
{
 
  return 1;
 
}
 

	
 
void u8g_i2c_stop(void)
 
{
 
}
 

	
 

	
 
#endif
 

	
Libraries/u8glib/u8g_com_io.c
Show inline comments
 
new file 100644
 
/*
 
  
 
  u8g_com_io.c
 
  
 
  abstraction layer for low level i/o 
 

	
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2012, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 

	
 
  Update for ATOMIC operation done (01 Jun 2013)
 
    U8G_ATOMIC_OR(ptr, val)
 
    U8G_ATOMIC_AND(ptr, val)
 
    U8G_ATOMIC_START();
 
    U8G_ATOMIC_END();
 

	
 
  uint8_t u8g_Pin(uint8_t port, uint8_t bitpos)						Convert to internal number: AVR: port*8+bitpos, ARM: port*16+bitpos
 
  void u8g_SetPinOutput(uint8_t internal_pin_number)
 
  void u8g_SetPinInput(uint8_t internal_pin_number)
 
  void u8g_SetPinLevel(uint8_t internal_pin_number, uint8_t level)
 
  uint8_t u8g_GetPinLevel(uint8_t internal_pin_number)
 

	
 

	
 
*/
 

	
 
#include "u8g.h"
 

	
 
#if defined(__AVR__)
 

	
 
#include <avr/interrupt.h>
 
#include <avr/io.h>
 

	
 
typedef volatile uint8_t * IO_PTR;
 

	
 
/* create internal pin number */
 
uint8_t u8g_Pin(uint8_t port, uint8_t bitpos)
 
{
 
  port <<= 3;
 
  port += bitpos;
 
  return port;
 
}
 

	
 
const IO_PTR u8g_avr_ddr_P[] PROGMEM = {
 
#ifdef DDRA
 
  &DDRA,
 
#else
 
  0,
 
#endif
 
  &DDRB,
 
#ifdef DDRC
 
  &DDRC,
 
#ifdef DDRD
 
  &DDRD,
 
#ifdef DDRE
 
  &DDRE,
 
#ifdef DDRF
 
  &DDRF,
 
#ifdef DDRG
 
  &DDRG,
 
#ifdef DDRH
 
  &DDRH,
 
#endif
 
#endif
 
#endif
 
#endif
 
#endif
 
#endif
 
};
 

	
 

	
 
const IO_PTR u8g_avr_port_P[] PROGMEM = {
 
#ifdef PORTA
 
  &PORTA,
 
#else
 
  0,
 
#endif
 
  &PORTB,
 
#ifdef PORTC
 
  &PORTC,
 
#ifdef PORTD
 
  &PORTD,
 
#ifdef PORTE
 
  &PORTE,
 
#ifdef PORTF
 
  &PORTF,
 
#ifdef PORTG
 
  &PORTG,
 
#ifdef PORTH
 
  &PORTH,
 
#endif
 
#endif
 
#endif
 
#endif
 
#endif
 
#endif
 
};
 

	
 
const IO_PTR u8g_avr_pin_P[] PROGMEM = {
 
#ifdef PINA
 
  &PINA,
 
#else
 
  0,
 
#endif
 
  &PINB,
 
#ifdef PINC
 
  &PINC,
 
#ifdef PIND
 
  &PIND,
 
#ifdef PINE
 
  &PINE,
 
#ifdef PINF
 
  &PINF,
 
#ifdef PING
 
  &PING,
 
#ifdef PINH
 
  &PINH,
 
#endif
 
#endif
 
#endif
 
#endif
 
#endif
 
#endif
 
};
 

	
 
static volatile uint8_t *u8g_get_avr_io_ptr(const IO_PTR *base, uint8_t offset)
 
{
 
  volatile uint8_t * tmp;
 
  base += offset;
 
  memcpy_P(&tmp, base, sizeof(volatile uint8_t * PROGMEM));
 
  return tmp; 
 
}
 

	
 
/* set direction to output of the specified pin (internal pin number) */
 
void u8g_SetPinOutput(uint8_t internal_pin_number)
 
{
 
  *u8g_get_avr_io_ptr(u8g_avr_ddr_P, internal_pin_number>>3) |= _BV(internal_pin_number&7);
 
}
 

	
 
void u8g_SetPinInput(uint8_t internal_pin_number)
 
{
 
  *u8g_get_avr_io_ptr(u8g_avr_ddr_P, internal_pin_number>>3) &= ~_BV(internal_pin_number&7);
 
}
 

	
 
void u8g_SetPinLevel(uint8_t internal_pin_number, uint8_t level)
 
{
 
  volatile uint8_t * tmp = u8g_get_avr_io_ptr(u8g_avr_port_P, internal_pin_number>>3);
 
  
 
  if ( level == 0 )
 
  {
 
    U8G_ATOMIC_AND(tmp, ~_BV(internal_pin_number&7));
 
   // *tmp &= ~_BV(internal_pin_number&7);
 
  }
 
  else
 
  {
 
    U8G_ATOMIC_OR(tmp, _BV(internal_pin_number&7));
 
    //*tmp |= _BV(internal_pin_number&7);
 
  }
 
  
 
}
 

	
 
uint8_t u8g_GetPinLevel(uint8_t internal_pin_number)
 
{
 
  volatile uint8_t * tmp = u8g_get_avr_io_ptr(u8g_avr_pin_P, internal_pin_number>>3);
 
  if ( ((*tmp) & _BV(internal_pin_number&7))  != 0 )
 
    return 1;
 
  return 0;
 
}
 

	
 
#else
 

	
 
/* convert "port" and "bitpos" to internal pin number */
 
uint8_t u8g_Pin(uint8_t port, uint8_t bitpos)
 
{
 
  port <<= 3;
 
  port += bitpos;
 
  return port;
 
}
 

	
 
void u8g_SetPinOutput(uint8_t internal_pin_number)
 
{
 
}
 

	
 
void u8g_SetPinInput(uint8_t internal_pin_number)
 
{
 
}
 

	
 
void u8g_SetPinLevel(uint8_t internal_pin_number, uint8_t level)
 
{
 
}
 

	
 
uint8_t u8g_GetPinLevel(uint8_t internal_pin_number)
 
{
 
  return 0;
 
}
 

	
 
#endif
 

	
 

	
 
#if defined(U8G_WITH_PINLIST)
 

	
 
void u8g_SetPIOutput(u8g_t *u8g, uint8_t pi)
 
{
 
  uint8_t pin;
 
  pin = u8g->pin_list[pi];
 
  if ( pin != U8G_PIN_NONE )
 
    u8g_SetPinOutput(pin);
 
}
 

	
 
void u8g_SetPILevel(u8g_t *u8g, uint8_t pi, uint8_t level)
 
{
 
  uint8_t pin;
 
  pin = u8g->pin_list[pi];
 
  if ( pin != U8G_PIN_NONE )
 
    u8g_SetPinLevel(pin, level);
 
}
 

	
 
#else  /* defined(U8G_WITH_PINLIST) */
 
void u8g_SetPIOutput(u8g_t *u8g, uint8_t pi)
 
{
 
}
 

	
 
void u8g_SetPILevel(u8g_t *u8g, uint8_t pi, uint8_t level)
 
{
 
}
 

	
 
#endif /* defined(U8G_WITH_PINLIST) */
Libraries/u8glib/u8g_com_null.c
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g_com_null.c
 
 
 
  communication null device
 

	
 
  Universal 8bit Graphics Library
 
 
 
  Copyright (c) 2011, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification,
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list
 
    of conditions and the following disclaimer.
 
   
 
  * Redistributions in binary form must reproduce the above copyright notice, this
 
    list of conditions and the following disclaimer in the documentation and/or other
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
 
 
 
 
*/
 

	
 
#include "u8g.h"
 

	
 
uint8_t u8g_com_null_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
 
{
 
  switch(msg)
 
  {
 
    case U8G_COM_MSG_INIT:
 
      break;
 
    case U8G_COM_MSG_STOP:
 
      break;
 

	
 
   
 
    case U8G_COM_MSG_CHIP_SELECT:
 
      /* arg_val contains the chip number, which should be enabled */
 
      break;
 

	
 

	
 
    case U8G_COM_MSG_WRITE_BYTE:
 
      break;
 
    case U8G_COM_MSG_WRITE_SEQ:
 
      break;
 
  }
 
  return 1;
 
}
 

	
Libraries/u8glib/u8g_cursor.c
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g_cursor.c
 

	
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2011, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
  
 
  
 
*/
 

	
 
#include "u8g.h"
 

	
 
void u8g_SetCursorFont(u8g_t *u8g, const u8g_pgm_uint8_t *cursor_font)
 
{
 
  u8g->cursor_font = cursor_font;
 
}
 

	
 
void u8g_SetCursorStyle(u8g_t *u8g, uint8_t encoding)
 
{
 
  u8g->cursor_encoding = encoding;
 
}
 

	
 
void u8g_SetCursorColor(u8g_t *u8g, uint8_t fg, uint8_t bg)
 
{
 
  u8g->cursor_bg_color = bg;
 
  u8g->cursor_fg_color = fg;
 
}
 

	
 
void u8g_SetCursorPos(u8g_t *u8g, u8g_uint_t cursor_x, u8g_uint_t cursor_y)
 
{
 
  u8g->cursor_x = cursor_x;
 
  u8g->cursor_y = cursor_y;
 
}
 

	
 
void u8g_EnableCursor(u8g_t *u8g)
 
{
 
    u8g->cursor_fn = u8g_DrawCursor;
 
}
 

	
 
void u8g_DisableCursor(u8g_t *u8g)
 
{
 
    u8g->cursor_fn = (u8g_draw_cursor_fn)0;
 
}
 

	
 
void u8g_DrawCursor(u8g_t *u8g)
 
{
 
  const u8g_pgm_uint8_t *font;
 
  uint8_t color;
 
  uint8_t encoding = u8g->cursor_encoding;
 
  
 
  /* get current values */
 
  color = u8g_GetColorIndex(u8g);
 
  font = u8g->font;
 
  
 
  /* draw cursor */
 
  u8g->font = u8g->cursor_font;  
 
  encoding++;
 
  u8g_SetColorIndex(u8g, u8g->cursor_bg_color); 
 
  /* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */
 
  /* required, because y adjustment should not happen to the cursor fonts */
 
  u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding);
 
  encoding--;
 
  u8g_SetColorIndex(u8g, u8g->cursor_fg_color); 
 
  /* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */
 
  /* required, because y adjustment should not happen to the cursor fonts */
 
  /* u8g_DrawGlyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); */
 
  u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding);
 
  
 
  /* restore previous values */
 
  u8g->font = font;
 
  u8g_SetColorIndex(u8g, color); 
 
}
 

	
Libraries/u8glib/u8g_delay.c
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g_delay.c
 

	
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2011, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 

	
 

	
 
  void u8g_Delay(uint16_t val)		Delay by "val" milliseconds
 
  void u8g_MicroDelay(void)		Delay be one microsecond
 
  void u8g_10MicroDelay(void)	Delay by 10 microseconds
 

	
 
  
 
*/
 

	
 

	
 
#include "u8g.h"
 

	
 
/*==== Part 1: Derive suitable delay procedure ====*/
 

	
 
#if defined(ARDUINO)
 

	
 
#  if ARDUINO < 100 
 
#    include <WProgram.h> 
 
#  else 
 
#    include <Arduino.h> 
 
#  endif
 

	
 
#  if defined(__AVR__)
 
#    define USE_AVR_DELAY
 
#  elif defined(__PIC32MX)
 
#    define USE_PIC32_DELAY
 
#  elif defined(__arm__)		/* Arduino Due & Teensy */
 
#    define USE_ARDUINO_DELAY
 
#  else
 
#    define USE_ARDUINO_DELAY
 
#  endif
 
#elif defined(__AVR__)
 
#  define USE_AVR_DELAY
 
#elif defined(__18CXX)
 
#  define USE_PIC18_DELAY
 
#elif defined(__arm__)
 
/* do not define anything, all procedures are expected to be defined outside u8glib */
 

	
 
/*
 
void u8g_Delay(uint16_t val);
 
void u8g_MicroDelay(void);
 
void u8g_10MicroDelay(void);
 
*/
 

	
 
#else
 
#  define USE_DUMMY_DELAY
 
#endif
 

	
 

	
 

	
 
/*==== Part 2: Definition of the delay procedures ====*/
 

	
 
/*== AVR Delay ==*/
 

	
 
#if defined(USE_AVR_DELAY)
 
#include <avr/interrupt.h>
 
#include <avr/io.h>
 
#include <util/delay.h>
 

	
 
/*
 
  Delay by the provided number of milliseconds.
 
  Thus, a 16 bit value will allow a delay of 0..65 seconds
 
  Makes use of the _delay_loop_2
 
  
 
  _delay_loop_2 will do a delay of n * 4 prozessor cycles.
 
  with f = F_CPU cycles per second,
 
  n = f / (1000 * 4 )
 
  with f = 16000000 the result is 4000
 
  with f = 1000000 the result is 250
 
  
 
  the millisec loop, gcc requires the following overhead:
 
  - movev 1
 
  - subwi 2x2
 
  - bne i 2
 
  ==> 7 cycles
 
  ==> must be devided by 4, rounded up 7/4 = 2
 
*/
 
void u8g_Delay(uint16_t val)
 
{
 
  /* old version did a call to the arduino lib: delay(val); */
 
  while( val != 0 )
 
  {
 
    _delay_loop_2( (F_CPU / 4000 ) -2);
 
    val--;
 
  }
 
}
 

	
 
/* delay by one micro second */
 
void u8g_MicroDelay(void)
 
{
 
#if (F_CPU / 4000000 ) > 0 
 
  _delay_loop_2( (F_CPU / 4000000 ) );
 
#endif
 
}
 

	
 
/* delay by 10 micro seconds */
 
void u8g_10MicroDelay(void)
 
{
 
#if (F_CPU / 400000 ) > 0 
 
  _delay_loop_2( (F_CPU / 400000 ) );
 
#endif
 
}
 

	
 
#endif 
 

	
 

	
 
/*== Delay for PIC18 (not tested) ==*/
 

	
 
#if defined(USE_PIC18_DELAY)
 
#include <delays.h>
 
#define GetSystemClock()		(64000000ul)      // Hz
 
#define GetInstructionClock()	(GetSystemClock()/4)
 

	
 
void u8g_Delay(uint16_t val)
 
{/*
 
	unsigned int _iTemp = (val);
 
	while(_iTemp--)		
 
		Delay1KTCYx((GetInstructionClock()+999999)/1000000);
 
		*/
 
}
 
void u8g_MicroDelay(void)
 
{
 
  /* not implemented */
 
}
 
void u8g_10MicroDelay(void)
 
{
 
  /* not implemented */
 
}
 
#endif
 

	
 

	
 
/*== Arduino Delay ==*/
 
#if defined(USE_ARDUINO_DELAY)
 
void u8g_Delay(uint16_t val)
 
{
 
#if defined(__arm__)
 
	delayMicroseconds((uint32_t)val*(uint32_t)1000);
 
#else
 
	delay(val);
 
#endif
 
}
 
void u8g_MicroDelay(void)
 
{
 
	delayMicroseconds(1);
 
}
 
void u8g_10MicroDelay(void)
 
{
 
	delayMicroseconds(10);
 
}
 
#endif
 

	
 
#if defined(USE_PIC32_DELAY)
 
/* 
 
  Assume chipkit here with F_CPU correctly defined
 
  The problem was, that u8g_Delay() is called within the constructor.
 
  It seems that the chipkit is not fully setup at this time, so a
 
  call to delay() will not work. So here is my own implementation.
 

	
 
*/
 
#define CPU_COUNTS_PER_SECOND (F_CPU/2UL)
 
#define TICKS_PER_MILLISECOND  (CPU_COUNTS_PER_SECOND/1000UL)
 
#include "plib.h"
 
void u8g_Delay(uint16_t val)
 
{
 
	uint32_t d;
 
	uint32_t s;
 
	d = val;
 
	d *= TICKS_PER_MILLISECOND;
 
	s = ReadCoreTimer();
 
	while ( (uint32_t)(ReadCoreTimer() - s) < d )
 
		;
 
} 
 

	
 
void u8g_MicroDelay(void)
 
{
 
	uint32_t d;
 
	uint32_t s;
 
	d = TICKS_PER_MILLISECOND/1000;
 
	s = ReadCoreTimer();
 
	while ( (uint32_t)(ReadCoreTimer() - s) < d )
 
		;
 
} 
 

	
 
void u8g_10MicroDelay(void)
 
{
 
	uint32_t d;
 
	uint32_t s;
 
	d = TICKS_PER_MILLISECOND/100;
 
	s = ReadCoreTimer();
 
	while ( (uint32_t)(ReadCoreTimer() - s) < d )
 
		;
 
} 
 

	
 
#endif
 

	
 
/*== Any other systems: Dummy Delay ==*/
 
#if defined(USE_DUMMY_DELAY)
 
void u8g_Delay(uint16_t val)
 
{
 
	/* do not know how to delay... */
 
}
 
void u8g_MicroDelay(void)
 
{
 
}
 
void u8g_10MicroDelay(void)
 
{
 
}
 
#endif
Libraries/u8glib/u8g_dev_a2_micro_printer.c
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g_dev_a2_micro_printer_ds.c
 

	
 
  Use DC2 bitmap command of the A2 Micro panel termal printer
 
  double stroke
 

	
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2013, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
  
 
  
 
*/
 

	
 
#include "u8g.h"
 

	
 
#define LINE_DELAY 40
 

	
 

	
 
uint8_t u8g_dev_a2_micro_printer_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
 
{
 
  switch(msg)
 
  {
 
    case U8G_DEV_MSG_INIT:
 
      u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
 
      break;
 
    case U8G_DEV_MSG_STOP:
 
      break;
 
    case U8G_DEV_MSG_PAGE_NEXT:
 
      {
 
        uint8_t y, i, j;
 
        uint8_t *ptr;
 
        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
 
        
 
        y = pb->p.page_y0;
 
        ptr = pb->buf;
 

	
 
	u8g_WriteByte(u8g, dev, 27);      /* ESC */
 
	u8g_WriteByte(u8g, dev, 55 );      /* parameter command */
 
	u8g_WriteByte(u8g, dev, 7);      /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
 
	u8g_WriteByte(u8g, dev, 160);      /* 3-255 Heating time,Unit(10us),Default:80(800us) */
 
	u8g_WriteByte(u8g, dev, 20);      /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
 
	
 
	u8g_WriteByte(u8g, dev, 18);      /* DC2 */
 
	u8g_WriteByte(u8g, dev, 42 );      /* *  */
 
	u8g_WriteByte(u8g, dev, pb->p.page_height ); 
 
	u8g_WriteByte(u8g, dev, pb->width/8 ); 
 
	
 
        for( i = 0; i < pb->p.page_height; i ++ )
 
        {
 
	  for( j = 0; j < pb->width/8; j++ )
 
	  {
 
	    u8g_WriteByte(u8g, dev, *ptr);
 
	    ptr++;
 
	  }
 
	  u8g_Delay(LINE_DELAY);
 
          y++;
 
        }
 

	
 
	/* set parameters back to their default values */
 
	u8g_WriteByte(u8g, dev, 27);      /* ESC */
 
	u8g_WriteByte(u8g, dev, 55 );      /* parameter command */
 
	u8g_WriteByte(u8g, dev, 7);      /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
 
	u8g_WriteByte(u8g, dev, 80);      /* 3-255 Heating time,Unit(10us),Default:80(800us) */
 
	u8g_WriteByte(u8g, dev, 2);      /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
 
	
 
      }
 
      break;
 
  }
 
  return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
 
}
 

	
 
static uint8_t u8g_dev_expand4(uint8_t val)
 
{
 
  uint8_t a,b,c,d;
 
  a = val&1;
 
  b = (val&2)<<1;
 
  c = (val&4)<<2;
 
  d = (val&8)<<3;
 
  a |=b;
 
  a |=c;
 
  a |=d;
 
  a |= a<<1;
 
  return a;
 
}
 

	
 
uint8_t u8g_dev_a2_micro_printer_double_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
 
{
 
  switch(msg)
 
  {
 
    case U8G_DEV_MSG_INIT:
 
      u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
 
      break;
 
    case U8G_DEV_MSG_STOP:
 
      break;
 
    case U8G_DEV_MSG_PAGE_FIRST:
 
      {
 
        //u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
 
	//u8g_WriteByte(u8g, dev, 18);      /* DC2 */
 
	//u8g_WriteByte(u8g, dev, 42 );      /* *  */
 
	//u8g_WriteByte(u8g, dev, pb->p.total_height*2 ); 
 
	//u8g_WriteByte(u8g, dev, pb->width/8*2 ); 
 
      }
 
      break;
 
    case U8G_DEV_MSG_PAGE_NEXT:
 
      {
 
        uint8_t y, i, j;
 
        uint8_t *ptr;
 
        uint8_t *p2;
 
        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
 
        
 
        y = pb->p.page_y0;
 
        ptr = pb->buf;
 
	//u8g_WriteByte(u8g, dev, 18);      /* DC2 */
 
	//u8g_WriteByte(u8g, dev, 35 );      /* #  */
 
	//u8g_WriteByte(u8g, dev, 0x0ff );      /* max  */
 

	
 
	u8g_WriteByte(u8g, dev, 27);      /* ESC */
 
	u8g_WriteByte(u8g, dev, 55 );      /* parameter command */
 
	u8g_WriteByte(u8g, dev, 7);      /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
 
	u8g_WriteByte(u8g, dev, 160);      /* 3-255 Heating time,Unit(10us),Default:80(800us) */
 
	u8g_WriteByte(u8g, dev, 20);      /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
 
	
 
	u8g_WriteByte(u8g, dev, 18);      /* DC2 */
 
	u8g_WriteByte(u8g, dev, 42 );      /* *  */
 
	u8g_WriteByte(u8g, dev, pb->p.page_height*2 ); 
 
	u8g_WriteByte(u8g, dev, pb->width/8*2 ); 
 
	
 
        for( i = 0; i < pb->p.page_height; i ++ )
 
        {
 
	  p2 = ptr;
 
	  for( j = 0; j < pb->width/8; j++ )
 
	  {
 
	    u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 >> 4));
 
	    u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 & 15));
 
	    p2++;
 
	  }
 
	  u8g_Delay(LINE_DELAY);
 
	  p2 = ptr;
 
	  for( j = 0; j < pb->width/8; j++ )
 
	  {
 
	    u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 >> 4));
 
	    u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 & 15));
 
	    p2++;
 
	  }
 
	  u8g_Delay(LINE_DELAY);
 
	  ptr += pb->width/8;
 
          y++;
 
        }
 
	
 
	/* set parameters back to their default values */
 
	u8g_WriteByte(u8g, dev, 27);      /* ESC */
 
	u8g_WriteByte(u8g, dev, 55 );      /* parameter command */
 
	u8g_WriteByte(u8g, dev, 7);      /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
 
	u8g_WriteByte(u8g, dev, 80);      /* 3-255 Heating time,Unit(10us),Default:80(800us) */
 
	u8g_WriteByte(u8g, dev, 2);      /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
 
	
 
      }
 
      break;
 
  }
 
  return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
 
}
 

	
 
#if defined(U8G_16BIT)
 
U8G_PB_DEV(u8g_dev_a2_micro_printer_384x240, 384, 240, 8, u8g_dev_a2_micro_printer_fn, u8g_com_null_fn);
 
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x360_ds, 192, 360, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
 
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x720_ds, 192, 720, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
 
#else
 
U8G_PB_DEV(u8g_dev_a2_micro_printer_384x240, 240, 240, 8, u8g_dev_a2_micro_printer_fn, u8g_com_null_fn);
 
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x360_ds, 192, 240, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
 
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x720_ds, 192, 240, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
 
#endif
 

	
 
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x120_ds, 192, 120, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
Libraries/u8glib/u8g_dev_flipdisc_2x7.c
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g_dev_flipdisc.c
 
  
 
  1-Bit (BW) Driver for flip disc matrix
 
  2x 7 pixel height
 

	
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2011, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
  
 
*/
 

	
 
#include "u8g.h"
 

	
 
#define WIDTH 28
 
#define HEIGHT 14
 
#define PAGE_HEIGHT 14
 

	
 
/*
 
  Write data to the flip disc matrix.
 
  This procedure must be implemented by the user.
 
  Arguments:
 
    id:	Id for the matrix. Currently always 0.
 
    page: 	A page has a height of 14 pixel. For a matrix with HEIGHT == 14 this will be always 0
 
    width: 	The width of the flip disc matrix. Always equal to WIDTH
 
    row1: 	first data line (7 pixel per byte)
 
    row2: 	first data line (7 pixel per byte)
 
*/
 
void writeFlipDiscMatrix(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2);
 

	
 

	
 

	
 
void (*u8g_write_flip_disc_matrix)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2);
 

	
 
void u8g_SetFlipDiscCallback(u8g_t *u8g, void (*cb)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2))
 
{
 
  u8g_write_flip_disc_matrix = cb;
 
}
 

	
 
uint8_t u8g_dev_flipdisc_2x7_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
 
{
 
  switch(msg)
 
  {
 
    case U8G_DEV_MSG_INIT:
 
      break;
 
    case U8G_DEV_MSG_STOP:
 
      break;
 
    case U8G_DEV_MSG_PAGE_NEXT:
 
      {
 
        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
 
        
 
	/* current page: pb->p.page */
 
	/* ptr to the buffer: pb->buf */
 
	
 
	(*u8g_write_flip_disc_matrix)(0, pb->p.page, WIDTH, pb->buf, (uint8_t *)(pb->buf)+WIDTH);
 
      }
 
      break;
 
    case U8G_DEV_MSG_CONTRAST:
 
      return 1;
 
  }
 
  return u8g_dev_pb14v1_base_fn(u8g, dev, msg, arg);
 
}
 

	
 
uint8_t u8g_dev_flipdisc_2x7_bw_buf[WIDTH*2] U8G_NOCOMMON ; 
 
u8g_pb_t u8g_dev_flipdisc_2x7_bw_pb = { {16, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_flipdisc_2x7_bw_buf}; 
 
u8g_dev_t u8g_dev_flipdisc_2x7 = { u8g_dev_flipdisc_2x7_bw_fn, &u8g_dev_flipdisc_2x7_bw_pb, u8g_com_null_fn };
Libraries/u8glib/u8g_dev_gprof.c
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g_dev_gprof.c
 

	
 
  Device for performance measurement with gprof.
 
  Does not write any data, but uses a buffer.
 

	
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2011, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
  
 
  
 

	
 
*/
 

	
 
#include "u8g.h"
 

	
 

	
 
#define WIDTH 128
 
#define HEIGHT 64
 
#define PAGE_HEIGHT 8
 

	
 
uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg);
 

	
 
uint8_t u8g_pb_dev_gprof_buf[WIDTH];
 
u8g_pb_t u8g_pb_dev_gprof = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0},  WIDTH, u8g_pb_dev_gprof_buf };
 

	
 
u8g_dev_t u8g_dev_gprof = { u8g_dev_gprof_fn, &u8g_pb_dev_gprof, NULL };
 

	
 
uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
 
{
 
  u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
 
  
 
  switch(msg)
 
  {
 
    case U8G_DEV_MSG_INIT:
 
      break;
 
    case U8G_DEV_MSG_STOP:
 
      break;
 
    case U8G_DEV_MSG_PAGE_FIRST:
 
      u8g_pb_Clear(pb);
 
      u8g_page_First(&(pb->p));
 
      break;
 
    case U8G_DEV_MSG_PAGE_NEXT:
 
      /*
 
      {
 
        uint8_t i, j;
 
        uint8_t page_height;
 
        page_height = pb->p.page_y1;
 
        page_height -= pb->p.page_y0;
 
        page_height++;
 
        for( j = 0; j < page_height; j++ )
 
        {
 
          printf("%02d ", j);
 
          for( i = 0; i < WIDTH; i++ )
 
          {
 
            if ( (u8g_pb_dev_stdout_buf[i] & (1<<j)) != 0 )
 
              printf("#");
 
            else
 
              printf(".");
 
          }
 
          printf("\n");
 
        }
 
      }
 
      */
 
      if ( u8g_page_Next(&(pb->p)) == 0 )
 
      {
 
        //printf("\n");
 
        return 0;
 
      }
 
      u8g_pb_Clear(pb);
 
      break;
 
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
 
    case U8G_DEV_MSG_IS_BBX_INTERSECTION:
 
       {
 
        u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg;
 
        u8g_uint_t x2, y2;
 

	
 
        y2 = bbx->y;
 
        y2 += bbx->h;
 
        y2--;
 
        
 
        if ( u8g_pb_IsYIntersection(pb, bbx->y, y2) == 0 )
 
          return 0;
 
        
 
        /* maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 */
 
        x2 = bbx->x;
 
        x2 += bbx->w;
 
        x2--;
 
        
 
        if ( u8g_pb_IsXIntersection(pb, bbx->x, x2) == 0 )
 
          return 0;
 
      }
 
      return 1;
 
#endif
 
    case U8G_DEV_MSG_GET_PAGE_BOX:
 
      u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
 
      break;
 
    case U8G_DEV_MSG_SET_COLOR_ENTRY:
 
      break;
 
    case U8G_DEV_MSG_SET_XY_CB:
 
      break;
 
  }
 
  return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
 
}
Libraries/u8glib/u8g_dev_ht1632.c
Show inline comments
 
new file 100644
 
/*
 
 
 
  u8g_dev_ht1632.c
 
 
 
  1-Bit (BW) Driver for HT1632 controller
 
 
 
  Universal 8bit Graphics Library
 
 
 
  Copyright (c) 2013, olikraus@gmail.com
 
  All rights reserved.
 
 
 
  Redistribution and use in source and binary forms, with or without modification,
 
  are permitted provided that the following conditions are met:
 
 
 
  * Redistributions of source code must retain the above copyright notice, this list
 
    of conditions and the following disclaimer.
 
   
 
  * Redistributions in binary form must reproduce the above copyright notice, this
 
    list of conditions and the following disclaimer in the documentation and/or other
 
    materials provided with the distribution.
 
 
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 

	
 

	
 

	
 
    U8G_PIN_NONE can be used as argument
 
   
 
    uint8_t u8g_InitSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset)
 
    {
 
      ...      
 
      u8g->pin_list[U8G_PI_SCK] = sck;
 
      u8g->pin_list[U8G_PI_MOSI] = mosi;
 
      u8g->pin_list[U8G_PI_CS] = cs;
 
      u8g->pin_list[U8G_PI_A0] = a0;
 
      u8g->pin_list[U8G_PI_RESET] = reset;
 

	
 
mapping  
 

	
 
#define DATA_PIN --> U8G_PI_MOSI
 
#define WR_PIN    --> U8G_PI_SCK
 
#define CS_PIN      --> U8G_PI_CS
 
				    U8G_PI_A0 --> not used
 
				    U8G_PI_RESET --> not used
 

	
 
Usage:
 

	
 
    u8g_InitSPI(&u8g, &u8g_dev_ht1632_24x16, WR_PIN, DATA_IN, CS_PIN, U8G_PIN_NONE, U8G_PIN_NONE)
 

	
 
*/
 
 
 
#include "u8g.h"
 
 
 
#define WIDTH 24
 
#define HEIGHT 16
 
#define PAGE_HEIGHT 16
 
 
 
/* http://forum.arduino.cc/index.php?topic=168537.0 */
 
 
 
#define HT1632_CMD_SYSDIS       0x00    // CMD= 0000-0000-x Turn off oscil
 
#define HT1632_CMD_SYSON        0x01    // CMD= 0000-0001-x Enable system oscil
 
#define HT1632_CMD_LEDOFF       0x02    // CMD= 0000-0010-x LED duty cycle gen off
 
#define HT1632_CMD_LEDON        0x03    // CMD= 0000-0011-x LEDs ON
 
#define HT1632_CMD_BLOFF        0x08    // CMD= 0000-1000-x Blink OFF
 
#define HT1632_CMD_BLON         0x09    // CMD= 0000-1001-x Blink On
 
#define HT1632_CMD_SLVMD        0x10    // CMD= 0001-00xx-x Slave Mode
 
#define HT1632_CMD_MSTMD        0x14    // CMD= 0001-01xx-x Master Mode
 
#define HT1632_CMD_RCCLK        0x18    // CMD= 0001-10xx-x Use on-chip clock
 
#define HT1632_CMD_EXTCLK       0x1C    // CMD= 0001-11xx-x Use external clock
 
#define HT1632_CMD_COMS00       0x20    // CMD= 0010-ABxx-x commons options
 
#define HT1632_CMD_COMS01       0x24    // CMD= 0010-ABxx-x commons options
 
#define HT1632_CMD_COMS10       0x28    // CMD= 0010-ABxx-x commons options
 
#define HT1632_CMD_COMS11       0x2C    // P-MOS OUTPUT AND 16COMMON OPTION
 
#define HT1632_CMD_PWM          0xA0    // CMD= 101x-PPPP-x PWM duty cycle
 
 
 
#define HT1632_ID_CMD   4       /* ID = 100 - Commands */
 
#define HT1632_ID_RD    6       /* ID = 110 - Read RAM */
 
#define HT1632_ID_WR    5       /* ID = 101 - Write RAM */
 
 
 
#define HT1632_ID_LEN           3               // IDs are 3 bits
 
#define HT1632_CMD_LEN          8               // CMDs are 8 bits
 
#define HT1632_DATA_LEN         8               // Data are 4*2 bits
 
#define HT1632_ADDR_LEN         7               // Address are 7 bits
 
 
 
#if defined(ARDUINO)
 
 
 
#if ARDUINO < 100
 
#include <WProgram.h>
 
#else
 
#include <Arduino.h>
 
#endif
 
 
 
//#define WR_PIN 3
 
//#define DATA_PIN 2
 
//#define CS_PIN 4
 
 
 
void ht1632_write_data_MSB(u8g_t *u8g, uint8_t cnt, uint8_t data, uint8_t extra)
 
{
 
  int8_t i;
 
  uint8_t data_pin = u8g->pin_list[U8G_PI_MOSI];
 
  uint8_t wr_pin = u8g->pin_list[U8G_PI_SCK];
 
 
 
  for(i = cnt - 1; i >= 0; i--)
 
  {
 
    if ((data >> i) & 1)
 
    {  
 
      digitalWrite(data_pin, HIGH);
 
    }
 
    else
 
    {
 
      digitalWrite(data_pin, LOW);
 
    }
 
 
 
    digitalWrite(wr_pin, LOW);
 
    u8g_MicroDelay();
 
    digitalWrite(wr_pin, HIGH);
 
    u8g_MicroDelay();
 
  }
 
 
 
  // Send an extra bit
 
  if (extra)
 
  {
 
    digitalWrite(data_pin, HIGH);
 
    digitalWrite(wr_pin, LOW);
 
    u8g_MicroDelay();
 
    digitalWrite(wr_pin, HIGH);
 
    u8g_MicroDelay();
 
  }
 
}
 
 
 
void ht1632_write_data(u8g_t *u8g, uint8_t cnt, uint8_t data)
 
{
 
  uint8_t i;
 
  uint8_t data_pin = u8g->pin_list[U8G_PI_MOSI];
 
  uint8_t wr_pin = u8g->pin_list[U8G_PI_SCK];
 
  for (i = 0; i < cnt; i++)
 
  {
 
 
 
    if ((data >> i) & 1) {
 
      digitalWrite(data_pin, HIGH);
 
    }
 
    else {
 
      digitalWrite(data_pin, LOW);
 
    }
 
 
 
    digitalWrite(wr_pin, LOW);
 
    u8g_MicroDelay();
 
    digitalWrite(wr_pin, HIGH);
 
    u8g_MicroDelay();
 
  }
 
}
 
 
 
 
 
void ht1632_init(u8g_t *u8g)
 
{
 
  //uint8_t i;
 
  uint8_t data_pin = u8g->pin_list[U8G_PI_MOSI];
 
  uint8_t wr_pin = u8g->pin_list[U8G_PI_SCK];
 
  uint8_t cs_pin = u8g->pin_list[U8G_PI_CS];
 
  pinMode(data_pin, OUTPUT);
 
  pinMode(wr_pin, OUTPUT);
 
  pinMode(cs_pin, OUTPUT);
 
 
 
  digitalWrite(data_pin, HIGH);
 
  digitalWrite(wr_pin, HIGH);
 
  digitalWrite(cs_pin, HIGH);
 
 
 
  digitalWrite(cs_pin, LOW);
 
  /* init display once after startup */
 
  ht1632_write_data_MSB(u8g, 3, HT1632_ID_CMD, false); // IDs are 3 bits
 
  ht1632_write_data_MSB(u8g, 8, HT1632_CMD_SYSDIS, true); // 8 bits
 
  ht1632_write_data_MSB(u8g, 8, HT1632_CMD_SYSON, true); // 8 bits
 
  ht1632_write_data_MSB(u8g, 8, HT1632_CMD_COMS11, true); // 8 bits
 
  ht1632_write_data_MSB(u8g, 8, HT1632_CMD_LEDON, true); // 8 bits
 
  ht1632_write_data_MSB(u8g, 8, HT1632_CMD_BLOFF, true); // 8 bits
 
  ht1632_write_data_MSB(u8g, 8, HT1632_CMD_PWM+15, true); // 8 bits  
 
  digitalWrite(cs_pin, HIGH);
 
 
 
  /* removed following (debug) code */
 
  /*
 
  digitalWrite(cs_pin, LOW);
 
  ht1632_write_data_MSB(u8g, 3, HT1632_ID_WR, false); // Send "write to display" command
 
  ht1632_write_data_MSB(u8g, 7, 0, false);
 
  for(i = 0; i<48; ++i)
 
  {
 
    ht1632_write_data(u8g, 8, 0xFF);
 
  }
 
  digitalWrite(cs_pin, HIGH);
 
  */
 
}
 
 
 
/*
 
  page: 0=data contain lines 0..16, 1=data contain lines 16..32  (a 24x16 display will only have page 0)
 
  cnt: width of the display
 
  data: pointer to a buffer with 2*cnt bytes.
 
*/
 
void ht1632_transfer_data(u8g_t *u8g, uint8_t page, uint8_t cnt, uint8_t *data)
 
{
 
  uint8_t addr;
 
  uint8_t cs_pin = u8g->pin_list[U8G_PI_CS];
 
  /* send data to the ht1632 */
 
  digitalWrite(cs_pin, LOW);
 
  ht1632_write_data_MSB(u8g, 3, HT1632_ID_WR, false); // Send "write to display" command
 
  ht1632_write_data_MSB(u8g, 7, page*2*cnt, false); 
 
  
 
  // Operating in progressive addressing mode
 
  for (addr = 0; addr < cnt; addr++)
 
  {
 
    ht1632_write_data(u8g, 8, data[addr]);  
 
    ht1632_write_data(u8g, 8, data[addr+cnt]);
 
  }  
 
  digitalWrite(cs_pin, HIGH);
 
}
 

	
 
/* value is between 0...15 */
 
void ht1632_set_contrast(u8g_t *u8g, uint8_t value)
 
{
 
  uint8_t cs_pin = u8g->pin_list[U8G_PI_CS];
 
  digitalWrite(cs_pin, LOW);
 
  ht1632_write_data_MSB(u8g, 3, HT1632_ID_CMD, false);
 
  ht1632_write_data_MSB(u8g, 8, HT1632_CMD_PWM + value, false);
 
  digitalWrite(cs_pin, HIGH);
 
}
 
 
 
#else
 
void ht1632_init(u8g_t *u8g)
 
{
 
}
 
 
 
void ht1632_transfer_data(u8g_t *u8g, uint8_t page, uint8_t cnt, uint8_t *data)
 
{
 
}
 

	
 
void ht1632_set_contrast(u8g_t *u8g, uint8_t value)
 
{
 
}
 

	
 
#endif /* ARDUINO */
 
 
 
 
 
uint8_t u8g_dev_ht1632_24x16_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
 
{
 
  switch(msg)
 
  {
 
    case U8G_DEV_MSG_INIT:
 
      ht1632_init(u8g);
 
      break;
 
    case U8G_DEV_MSG_STOP:
 
      break;
 
    case U8G_DEV_MSG_PAGE_NEXT:
 
      {
 
	u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
 
       
 
	/* current page: pb->p.page */
 
	/* ptr to the buffer: pb->buf */
 
	ht1632_transfer_data(u8g, pb->p.page, WIDTH, pb->buf);
 
      }
 
      break;
 
    case U8G_DEV_MSG_CONTRAST:
 
      /* values passed to SetContrast() are between 0 and 255, scale down to 0...15 */
 
      ht1632_set_contrast(u8g, (*(uint8_t *)arg) >> 4);
 
    return 1;
 
  }
 
  return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
 
}
 
 
 
uint8_t u8g_dev_ht1632_24x16_buf[WIDTH*2] U8G_NOCOMMON ; 
 
u8g_pb_t u8g_dev_ht1632_24x16_pb = { {16, HEIGHT, 0, 0, 0},  WIDTH, u8g_dev_ht1632_24x16_buf}; 
 
u8g_dev_t u8g_dev_ht1632_24x16 = { u8g_dev_ht1632_24x16_fn, &u8g_dev_ht1632_24x16_pb, u8g_com_null_fn };
 

	
Libraries/u8glib/u8g_dev_ili9325d_320x240.c
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g_dev_ili9325d_320x240.c
 
  
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2011, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 

	
 
  Color format
 
    Red: 5 Bit
 
    Green: 6 Bit
 
    Blue: 5 Bit
 
  
 
    
 
*/
 

	
 
#include "u8g.h"
 

	
 
#define WIDTH 240
 

	
 
#if defined(U8G_16BIT)
 
#define HEIGHT 320
 
#else
 
/* if the user tries to compile the 8Bit version of the lib, then restrict the height to something which fits to 8Bit */
 
#define HEIGHT 240
 
#endif
 
#define PAGE_HEIGHT 4
 

	
 

	
 
/*
 
  reference board for this device:
 
    http://iteadstudio.com/store/index.php?main_page=product_info&cPath=57_58&products_id=55
 
  documentation:
 
    http://iteadstudio.com/Downloadfile/ITDB02_material.rar
 
  datasheet
 
    http://www.newhavendisplay.com/app_notes/ILI9325D.pdf
 
  other libs
 
    http://henningkarlsen.com/electronics/library.php
 
  init sequence
 
    http://code.google.com/p/itdb02/, ITDB02.cpp, iteadstudio.com
 
*/
 

	
 
static const uint8_t u8g_dev_ili9325d_320x240_init_seq[] PROGMEM = {
 
  U8G_ESC_CS(0),             /* disable chip */
 
  U8G_ESC_DLY(50),         /* delay 50 ms */
 
  U8G_ESC_RST(15),           /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
 
  U8G_ESC_DLY(50),         /* delay 50 ms */
 
  U8G_ESC_RST(15),           /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
 
  U8G_ESC_DLY(50),         /* delay 50 ms */
 
  U8G_ESC_CS(1),             /* enable chip */
 
  U8G_ESC_DLY(50),         /* delay 50 ms */
 

	
 
  
 
  //U8G_ESC_ADR(0),  0x000, 0x0E5,               /* only used for none D version: set SRAM internal timing */
 
  //U8G_ESC_ADR(1),  0x078, 0x0f0,             
 
  U8G_ESC_ADR(0),  0x000, 0x001,               /* Driver Output Control, bits 8 & 10 */
 
  U8G_ESC_ADR(1),  0x001, 0x000,           
 
  U8G_ESC_ADR(0),  0x000, 0x002,               /* LCD Driving Wave Control, bit 9: Set line inversion */
 
  U8G_ESC_ADR(1),  0x002, 0x000,               /* ITDB02 none D verion: 0x007, 0x000 */        
 
  U8G_ESC_ADR(0),  0x000, 0x003,               /* Entry Mode, GRAM write direction and BGR=1 */
 
  U8G_ESC_ADR(1),  0x010, 0x030,           
 
  U8G_ESC_ADR(0),  0x000, 0x004,               /* Resize register */
 
  U8G_ESC_ADR(1),  0x000, 0x000,           
 
  U8G_ESC_ADR(0),  0x000, 0x008,               /* Display Control 2: set the back porch and front porch */
 
  U8G_ESC_ADR(1),  0x002, 0x007,           
 
  
 
  U8G_ESC_ADR(0),  0x000, 0x009,               /* Display Control 3 */
 
  U8G_ESC_ADR(1),  0x000, 0x000,           
 

	
 
  U8G_ESC_ADR(0),  0x000, 0x00a,               /* Display Control 4: FMARK */
 
  U8G_ESC_ADR(1),  0x000, 0x000,           
 
  U8G_ESC_ADR(0),  0x000, 0x00c,               /* RGB Display Interface Control 1 */
 
  U8G_ESC_ADR(1),  0x000, 0x000,           
 
  U8G_ESC_ADR(0),  0x000, 0x00d,               /* Frame Maker Position */
 
  U8G_ESC_ADR(1),  0x000, 0x000,           
 
  U8G_ESC_ADR(0),  0x000, 0x00f,                /* RGB Display Interface Control 2 */
 
  U8G_ESC_ADR(1),  0x000, 0x000,  
 
  U8G_ESC_ADR(0),  0x000, 0x010,               /* Power Control 1: SAP, BT[3:0], AP, DSTB, SLP, STB */
 
  U8G_ESC_ADR(1),  0x000, 0x000,  
 
  U8G_ESC_ADR(0),  0x000, 0x011,               /* Power Control 2: DC1[2:0], DC0[2:0], VC[2:0] */
 
  U8G_ESC_ADR(1),  0x000, 0x007,  
 
  U8G_ESC_ADR(0),  0x000, 0x012,               /* Power Control 3: VREG1OUT voltage */
 
  U8G_ESC_ADR(1),  0x000, 0x000,  
 
  U8G_ESC_ADR(0),  0x000, 0x013,               /* Power Control 4: VDV[4:0] for VCOM amplitude */
 
  U8G_ESC_ADR(1),  0x000, 0x000,  
 
  U8G_ESC_ADR(0),  0x000, 0x007,               /* Display Control 1: Operate, but do not display */
 
  U8G_ESC_ADR(1),  0x000, 0x001,   
 
  
 
  U8G_ESC_DLY(100),         /* delay 100 ms */  /*  ITDB02 none D verion:  50ms */
 
  U8G_ESC_DLY(100),         /* delay 100 ms */
 
  
 
  U8G_ESC_ADR(0),  0x000, 0x010,               /* Power Control 1: SAP, BT[3:0], AP, DSTB, SLP, STB */
 
  U8G_ESC_ADR(1),  0x016, 0x090,               /*  ITDB02 none D verion:  0x010, 0x090 */
 
  U8G_ESC_ADR(0),  0x000, 0x011,               /* Power Control 2: SAP, BT[3:0], AP, DSTB, SLP, STB */
 
  U8G_ESC_ADR(1),  0x002, 0x027,
 

	
 
  U8G_ESC_DLY(50),         /* delay 50 ms */
 
  
 
  U8G_ESC_ADR(0),  0x000, 0x012,               /* Power Control 3: VCI: External, VCI*1.80 */
 
  U8G_ESC_ADR(1),  0x000, 0x00d,               /*  ITDB02 none D verion:  0x000, 0x01f */
 

	
 
  U8G_ESC_DLY(50),         /* delay 50 ms */
 
  
 
  U8G_ESC_ADR(0),  0x000, 0x013,               /* Power Control 4: VDV[4:0] for VCOM amplitude */
 
  U8G_ESC_ADR(1),  0x012, 0x000,               /*  ITDB02 none D verion:  0x015, 0x000 */
 
  U8G_ESC_ADR(0),  0x000, 0x029,               /* Power Control 7 */
 
  U8G_ESC_ADR(1),  0x000, 0x00a,               /*  ITDB02 none D verion:  0x000, 0x027 */
 
  U8G_ESC_ADR(0),  0x000, 0x02b,               /* Frame Rate: 83 */
 
  U8G_ESC_ADR(1),  0x000, 0x00d,
 

	
 
  U8G_ESC_DLY(50),         /* delay 50 ms */
 
  
 
  U8G_ESC_ADR(0),  0x000, 0x020,               /* Horizontal GRAM Address Set */
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 
  U8G_ESC_ADR(0),  0x000, 0x021,               /* Vertical GRAM Address Set */
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 

	
 
  /* gamma control */
 
  U8G_ESC_ADR(0),  0x000, 0x030,               
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 
  U8G_ESC_ADR(0),  0x000, 0x031,
 
  U8G_ESC_ADR(1),  0x004, 0x004,
 
  U8G_ESC_ADR(0),  0x000, 0x032,
 
  U8G_ESC_ADR(1),  0x000, 0x003,
 
  U8G_ESC_ADR(0),  0x000, 0x035,               
 
  U8G_ESC_ADR(1),  0x004, 0x005,
 
  U8G_ESC_ADR(0),  0x000, 0x036,               
 
  U8G_ESC_ADR(1),  0x008, 0x008,
 
  U8G_ESC_ADR(0),  0x000, 0x037,               
 
  U8G_ESC_ADR(1),  0x004, 0x007,
 
  U8G_ESC_ADR(0),  0x000, 0x038,               
 
  U8G_ESC_ADR(1),  0x003, 0x003,
 
  U8G_ESC_ADR(0),  0x000, 0x039,               
 
  U8G_ESC_ADR(1),  0x007, 0x007,
 
  U8G_ESC_ADR(0),  0x000, 0x03c,               
 
  U8G_ESC_ADR(1),  0x005, 0x004,
 
  U8G_ESC_ADR(0),  0x000, 0x03d,               
 
  U8G_ESC_ADR(1),  0x008, 0x008,
 
  
 
  U8G_ESC_ADR(0),  0x000, 0x050,               /* Horizontal GRAM Start Address */
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 
  U8G_ESC_ADR(0),  0x000, 0x051,               /* Horizontal GRAM End Address: 239 */
 
  U8G_ESC_ADR(1),  0x000, 0x0EF,
 
  U8G_ESC_ADR(0),  0x000, 0x052,               /* Vertical GRAM Start Address */
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 
  U8G_ESC_ADR(0),  0x000, 0x053,               /* Vertical GRAM End Address: 319 */
 
  U8G_ESC_ADR(1),  0x001, 0x03F,
 
  
 
  U8G_ESC_ADR(0),  0x000, 0x060,               /* Driver Output Control 2 */
 
  U8G_ESC_ADR(1),  0x0a7, 0x000,
 
  U8G_ESC_ADR(0),  0x000, 0x061,               /* Base Image Display Control: NDL,VLE, REV */
 
  U8G_ESC_ADR(1),  0x000, 0x001,
 
  U8G_ESC_ADR(0),  0x000, 0x06a,               /* Vertical Scroll Control */
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 

	
 
  U8G_ESC_ADR(0),  0x000, 0x080,               /* Partial Image 1 Display Position */
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 
  U8G_ESC_ADR(0),  0x000, 0x081,               /* Partial Image 1 RAM Start Address */
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 
  U8G_ESC_ADR(0),  0x000, 0x082,               /* Partial Image 1 RAM End Address */
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 
  U8G_ESC_ADR(0),  0x000, 0x083,               /* Partial Image 2 Display Position */
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 
  U8G_ESC_ADR(0),  0x000, 0x084,               /* Partial Image 2 RAM Start Address */
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 
  U8G_ESC_ADR(0),  0x000, 0x085,               /* Partial Image 2 RAM End Address */
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 

	
 
  U8G_ESC_ADR(0),  0x000, 0x090,               /* Panel Interface Control 1 */
 
  U8G_ESC_ADR(1),  0x000, 0x010,
 
  U8G_ESC_ADR(0),  0x000, 0x092,               /* Panel Interface Control 2 */
 
  U8G_ESC_ADR(1),  0x000, 0x000,        /* 0x006, 0x000 */
 

	
 
  U8G_ESC_ADR(0),  0x000, 0x007,               /* Display Control 1: Operate, display ON */
 
  U8G_ESC_ADR(1),  0x001, 0x033,   
 

	
 
  U8G_ESC_DLY(10),               /* delay 10 ms */
 
  
 
  /* write test pattern */  
 
  U8G_ESC_ADR(0),  0x000, 0x020,               /* Horizontal GRAM Address Set */
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 
  U8G_ESC_ADR(0),  0x000, 0x021,               /* Vertical GRAM Address Set */
 
  U8G_ESC_ADR(1),  0x000, 0x010,
 
  U8G_ESC_ADR(0),  0x000, 0x022,               /* Write Data to GRAM */
 
  U8G_ESC_ADR(1),  0x0fe, 0x0fe,
 
  0x000, 0x000,
 
  0x0fe, 0x0fe,
 
  0x000, 0x000,
 
  0x0fe, 0x0fe,
 
  0x000, 0x000,
 
  0x0fe, 0x0fe,
 
  0x000, 0x000,
 
  0x0fe, 0x0fe,
 
  0x000, 0x000,
 
  0x0fe, 0x0fe,
 
  0x000, 0x000,
 
  0x0fe, 0x0fe,
 
  0x000, 0x000,
 
  0x0fe, 0x0fe,
 
  0x000, 0x000,
 
  0x0fe, 0x0fe,
 
  
 
  U8G_ESC_CS(0),             /* disable chip */
 
  U8G_ESC_END                /* end of sequence */
 
};
 

	
 

	
 
static const uint8_t u8g_dev_ili9325d_320x240_page_seq[] PROGMEM = {
 
  U8G_ESC_CS(1),             /* enable chip */
 
  U8G_ESC_ADR(0),  0x000, 0x020,               /* Horizontal GRAM Address Set */
 
  U8G_ESC_ADR(1),  0x000, 0x000,
 
  U8G_ESC_ADR(0),  0x000, 0x021,               /* Vertical GRAM Address Set */
 
  U8G_ESC_ADR(1), 
 
  U8G_ESC_END                /* end of sequence */
 
};
 

	
 
/* convert the internal RGB 332 to 65K high byte */
 
static uint8_t u8g_dev_ili9325d_get_65K_high_byte(uint8_t color)
 
{
 
  uint8_t h;
 
  h = color;
 
  h &= 0x0e0;
 
  h |= h>>3;
 
  h &= 0x0f8;
 
  color>>=2;
 
  color &= 7;
 
  h |= color;
 
  return h;  
 
}
 

	
 
/* convert the internal RGB 332 to 65K high byte */
 
static uint8_t u8g_dev_ili9325d_get_65K_low_byte(uint8_t color)
 
{
 
  uint8_t l;
 
  l = color;
 
  l <<= 3;
 
  color &= 3;
 
  color <<= 1;
 
  l |= color;
 
  return l;  
 
}
 

	
 

	
 
uint8_t u8g_dev_ili9325d_320x240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
 
{
 
  
 
  switch(msg)
 
  {
 
    case U8G_DEV_MSG_INIT:
 
      u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
 
      //for(;;)
 
        u8g_WriteEscSeqP(u8g, dev, u8g_dev_ili9325d_320x240_init_seq);
 
    
 
      break;
 
    case U8G_DEV_MSG_STOP:
 
      break;
 
    case U8G_DEV_MSG_PAGE_NEXT:
 
      {
 
        uint8_t i;
 
        uint16_t y, j;
 
        uint8_t *ptr;
 
        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
 
        
 
        y = pb->p.page_y0;
 
        ptr = pb->buf;
 
        for( i = 0; i < pb->p.page_height; i ++ )
 
        {
 
          u8g_WriteEscSeqP(u8g, dev, u8g_dev_ili9325d_320x240_page_seq);
 
          u8g_WriteByte(u8g, dev, y >> 8 );      /* display ram (cursor) address high byte */
 
          u8g_WriteByte(u8g, dev, y & 255 );      /* display ram (cursor) address low byte */
 

	
 
          u8g_SetAddress(u8g, dev, 0);           /* cmd mode */
 
          u8g_WriteByte(u8g, dev, 0 );  
 
          u8g_WriteByte(u8g, dev, 0x022 );      /* start gram data */  
 
          
 
          u8g_SetAddress(u8g, dev, 1);           /* data mode */
 
          
 
          for( j = 0; j < pb->width; j++ )
 
          {
 
            u8g_WriteByte(u8g, dev, u8g_dev_ili9325d_get_65K_high_byte(*ptr) );  
 
            u8g_WriteByte(u8g, dev, u8g_dev_ili9325d_get_65K_low_byte(*ptr) );  
 
              
 
            ptr++;
 
          }
 
          y++;
 
        }
 
        u8g_SetChipSelect(u8g, dev, 0);
 
      }
 
      break;
 
  }
 
  return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
 
}
 

	
 
uint8_t u8g_ili9325d_320x240_8h8_buf[WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ; 
 
u8g_pb_t u8g_ili9325d_320x240_8h8_pb U8G_NOCOMMON = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0},  WIDTH, u8g_ili9325d_320x240_8h8_buf}; 
 
u8g_dev_t u8g_dev_ili9325d_320x240_8bit U8G_NOCOMMON = { u8g_dev_ili9325d_320x240_fn, &u8g_ili9325d_320x240_8h8_pb, u8g_com_arduino_port_d_wr_fn };
 
//u8g_dev_t u8g_dev_ili9325d_320x240_8bit = { u8g_dev_ili9325d_320x240_fn, &u8g_ili9325d_320x240_8h8_pb, u8g_com_arduino_parallel_fn };
 

	
 
//U8G_PB_DEV(u8g_dev_ili9325d_320x240_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ili9325d_320x240_fn, U8G_COM_PARALLEL);
 

	
 

	
Libraries/u8glib/u8g_dev_ks0108_128x64.c
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g_dev_ks0108_128x64.c
 

	
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2011, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
  
 

	
 
  ADDRESS = 0   (Command Mode)
 
    0x03f       Display On
 
    0x0c0       Start Display at line 0
 
    0x040 | y   write to y address (y:0..63)
 
    0x0b8 | x   write to page [0..7]
 

	
 

	
 
  u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
 
  u8g_Init8Bit(u8g, dev,  8,    9, 10, 11,   4,   5,   6,   7, 18, 14, 15, 17, 16, U8G_PIN_NONE)
 
  
 
*/
 

	
 
#include "u8g.h"
 

	
 
#define WIDTH 128
 
#define HEIGHT 64
 
#define PAGE_HEIGHT 8
 

	
 
static const uint8_t u8g_dev_ks0108_128x64_init_seq[] PROGMEM = {
 
  U8G_ESC_CS(0),             /* disable chip */
 
  U8G_ESC_ADR(0),           /* instruction mode */
 
  U8G_ESC_RST(1),           /* do reset low pulse with (1*16)+2 milliseconds */
 
  U8G_ESC_CS(1),             /* enable chip 1 */
 
  0x03f,		                /* display on */
 
  0x0c0,		                /* start at line 0 */
 
  U8G_ESC_DLY(20),         /* delay 20 ms */
 
  U8G_ESC_CS(2),             /* enable chip 2 */
 
  0x03f,		                /* display on */
 
  0x0c0,		                /* start at line 0 */
 
  U8G_ESC_DLY(20),         /* delay 20 ms */
 
  U8G_ESC_CS(0),             /* disable all chips */
 
  U8G_ESC_END                /* end of sequence */
 
};
 

	
 

	
 
uint8_t u8g_dev_ks0108_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
 
{
 
  
 
  switch(msg)
 
  {
 
    case U8G_DEV_MSG_INIT:
 
      u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
 
      u8g_WriteEscSeqP(u8g, dev, u8g_dev_ks0108_128x64_init_seq);
 
      break;
 
    case U8G_DEV_MSG_STOP:
 
      break;
 
    case U8G_DEV_MSG_PAGE_NEXT:
 
      {
 
        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
 
        
 
        u8g_SetAddress(u8g, dev, 0);           /* command mode */
 
        u8g_SetChipSelect(u8g, dev, 2);
 
        u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (KS0108b) */
 
        u8g_WriteByte(u8g, dev, 0x040 );		/* set address 0 */
 
        u8g_SetAddress(u8g, dev, 1);           /* data mode */
 
        u8g_WriteSequence(u8g, dev, 64, pb->buf);
 
        u8g_SetChipSelect(u8g, dev, 0);
 
        
 
        u8g_SetAddress(u8g, dev, 0);           /* command mode */
 
        u8g_SetChipSelect(u8g, dev, 1);
 
        u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (KS0108b) */
 
        u8g_WriteByte(u8g, dev, 0x040 );		/* set address 0 */
 
        u8g_SetAddress(u8g, dev, 1);           /* data mode */
 
        u8g_WriteSequence(u8g, dev, 64, 64+(uint8_t *)pb->buf);
 
        u8g_SetChipSelect(u8g, dev, 0);
 
        
 
      }
 
      break;
 
  }
 
  return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
 
}
 

	
 
U8G_PB_DEV(u8g_dev_ks0108_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_128x64_fn, U8G_COM_PARALLEL);
 
U8G_PB_DEV(u8g_dev_ks0108_128x64_fast, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_128x64_fn, U8G_COM_FAST_PARALLEL);
 

	
 

	
Libraries/u8glib/u8g_dev_lc7981_160x80.c
Show inline comments
 
new file 100644
 
/*
 

	
 
  u8g_dev_lc7981_160x80.c
 
  
 
  Universal 8bit Graphics Library
 
  
 
  Copyright (c) 2011, olikraus@gmail.com
 
  All rights reserved.
 

	
 
  Redistribution and use in source and binary forms, with or without modification, 
 
  are permitted provided that the following conditions are met:
 

	
 
  * Redistributions of source code must retain the above copyright notice, this list 
 
    of conditions and the following disclaimer.
 
    
 
  * Redistributions in binary form must reproduce the above copyright notice, this 
 
    list of conditions and the following disclaimer in the documentation and/or other 
 
    materials provided with the distribution.
 

	
 
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 
  
 
  
 
*/
 

	
 
#include "u8g.h"
 

	
 
#define WIDTH 160
 
#define HEIGHT 80
 
#define PAGE_HEIGHT 8
 

	
 

	
 
/*
 
  code ideas: 
 
  https://github.com/vsergeev/embedded-drivers/tree/master/avr-lc7981
 
  data sheets:
 
  http://www.lcd-module.de/eng/pdf/zubehoer/lc7981.pdf
 
  http://www.lcd-module.de/pdf/grafik/w160-6.pdf
 
*/
 

	
 
static const uint8_t u8g_dev_lc7981_160x80_init_seq[] PROGMEM = {
 
  U8G_ESC_CS(0),             /* disable chip */
 
  U8G_ESC_ADR(1),           /* instruction mode */
 
  U8G_ESC_RST(15),           /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
 
  U8G_ESC_CS(1),             /* enable chip */
 
  U8G_ESC_DLY(50),         /* delay 50 ms */
 
  
 
  
 
  U8G_ESC_ADR(1),               /* instruction mode */
 
  0x000,                                /* mode register */
 
  U8G_ESC_ADR(0),               /* data mode */
 
  0x032,                                /* display on (bit 5), master mode on (bit 4), graphics mode on (bit 1)*/
 

	
 
  U8G_ESC_ADR(1),               /* instruction mode */
 
  0x001,                                /* character/bits per pixel pitch */
 
  U8G_ESC_ADR(0),               /* data mode */
 
  0x007,                                /* 8 bits per pixel */
 

	
 
  U8G_ESC_ADR(1),               /* instruction mode */
 
  0x002,                                /* number of chars/byte width of the screen */
 
  U8G_ESC_ADR(0),               /* data mode */
 
  WIDTH/8-1,                         /* 8 bits per pixel */
 

	
 
  U8G_ESC_ADR(1),               /* instruction mode */
 
  0x003,                                /* time division */
 
  U8G_ESC_ADR(0),               /* data mode */
 
  0x07f,                                /*  */
 

	
 
  U8G_ESC_ADR(1),               /* instruction mode */
 
  0x008,                                /* display start low */
 
  U8G_ESC_ADR(0),               /* data mode */
 
  0x000,                                /*  */
 

	
 
  U8G_ESC_ADR(1),               /* instruction mode */
 
  0x009,                                /* display start high */
 
  U8G_ESC_ADR(0),               /* data mode */
 
  0x000,                                /*  */
 
    
 
  U8G_ESC_DLY(10),               /* delay 10 ms */
 
  
 
  U8G_ESC_CS(0),             /* disable chip */
 
  U8G_ESC_END                /* end of sequence */
 
};
 

	
 
uint8_t u8g_dev_lc7981_160x80_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
 
{
 
  switch(msg)
 
  {
 
    case U8G_DEV_MSG_INIT:
 
      u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
 
      u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_160x80_init_seq);
 
      break;
 
    case U8G_DEV_MSG_STOP:
 
      break;
 
    case U8G_DEV_MSG_PAGE_NEXT:
 
      {
 
        uint8_t y, i;
 
        uint16_t disp_ram_adr;
 
        uint8_t *ptr;
 
        u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
 
        
 
        u8g_SetAddress(u8g, dev, 1);           /* cmd mode */
 
        u8g_SetChipSelect(u8g, dev, 1);
 
        y = pb->p.page_y0;
 
        ptr = pb->buf;
 
        disp_ram_adr = WIDTH/8;
 
        disp_ram_adr *= y;
 
        for( i = 0; i < 8; i ++ )
 
        {
 
          u8g_SetAddress(u8g, dev, 1);           /* cmd mode */
 
          u8g_WriteByte(u8g, dev, 0x00a );      /* display ram (cursor) address low byte */
 
          u8g_SetAddress(u8g, dev, 0);           /* data mode */
 
          u8g_WriteByte(u8g, dev, disp_ram_adr & 0x0ff );  
 

	
 
          u8g_SetAddress(u8g, dev, 1);           /* cmd mode */
 
          u8g_WriteByte(u8g, dev, 0x00b );      /* display ram (cursor) address hight byte */
 
          u8g_SetAddress(u8g, dev, 0);           /* data mode */
 
          u8g_WriteByte(u8g, dev, disp_ram_adr >> 8 );  
 
          
 
          u8g_SetAddress(u8g, dev, 1);           /* cmd mode */
 
          u8g_WriteByte(u8g, dev, 0x00c );      /* write data */
 
          u8g_SetAddress(u8g, dev, 0);           /* data mode */
 
          u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
 
          ptr += WIDTH/8;
 
          disp_ram_adr += WIDTH/8;
 
        }
 
        u8g_SetChipSelect(u8g, dev, 0);
 
      }
 
      break;
 
  }
 
  return u8g_dev_pb8h1f_base_fn(u8g, dev, msg, arg);
 
}
 

	
 
U8G_PB_DEV(u8g_dev_lc7981_160x80_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_lc7981_160x80_fn, U8G_COM_FAST_PARALLEL);
 

	
 

	

Changeset was too big and was cut off... Show full diff anyway

0 comments (0 inline, 0 general)