changeset 213:8245c6f136b5 main

First commit for the ILI93240 LCD driver package.
author Bob Cook <bob@bobcookdev.com>
date Sat, 14 Jun 2014 12:35:35 -0700
parents d1725a29353f
children 366405f448bb
files main/packages/avr/lcd/ili9340/ili9340.cpp main/packages/avr/lcd/ili9340/ili9340.h
diffstat 2 files changed, 245 insertions(+), 197 deletions(-) [+]
line wrap: on
line diff
--- a/main/packages/avr/lcd/ili9340/ili9340.cpp	Sat May 10 08:13:43 2014 -0700
+++ b/main/packages/avr/lcd/ili9340/ili9340.cpp	Sat Jun 14 12:35:35 2014 -0700
@@ -42,6 +42,8 @@
 #include "packages/avr/device/spi.h"
 #include "packages/avr/device/spinwait.h"
 
+#include "packages/common/font/font_defs.h"
+
 #include "project_defs.h"
 
 // always after other includes
@@ -113,14 +115,14 @@
 #if defined( PRJ_ILI9340_DISPLAY_ORIENTATION_0 ) \
     || defined( PRJ_ILI9340_DISPLAY_ORIENTATION_180 )
 
-const uint16_t ILI9340_MAX_HORIZONTAL_PIXELS = 240;
-const uint16_t ILI9340_MAX_VERTICAL_PIXELS   = 320;
+static const uint16_t ILI9340_MAX_HORIZONTAL_PIXELS = 240;
+static const uint16_t ILI9340_MAX_VERTICAL_PIXELS   = 320;
 
 #elif defined( PRJ_ILI9340_DISPLAY_ORIENTATION_90 ) \
     || defined( PRJ_ILI9340_DISPLAY_ORIENTATION_270 )
 
-const uint16_t ILI9340_MAX_HORIZONTAL_PIXELS = 320;
-const uint16_t ILI9340_MAX_VERTICAL_PIXELS   = 240;
+static const uint16_t ILI9340_MAX_HORIZONTAL_PIXELS = 320;
+static const uint16_t ILI9340_MAX_VERTICAL_PIXELS   = 240;
 
 #else
 #error PRJ_ILI9340_DISPLAY_ORIENTATION_* must be defined!
@@ -188,124 +190,16 @@
 const uint8_t ILI9340_COMMAND_RAMWR = 0x2c;
 
 // ----------------------------------------------------------------------------------------
-//
-//  This is an 8x6 monospaced font, organized as one byte per horizontal row.
-//
 
 #if defined( PRJ_ILI9340_INC_WRITE_CHAR )
 
-const uint8_t ILI9340_GLYPH_HEIGHT = 8;
-const uint8_t ILI9340_GLYPH_WIDTH  = 6;
-
 const uint8_t ILI9340_MAX_HORIZONTAL_CHARS
-    = ( ILI9340_MAX_HORIZONTAL_PIXELS / ILI9340_GLYPH_WIDTH );
+    = ( ILI9340_MAX_HORIZONTAL_PIXELS / FONT_8X12_GLYPH_WIDTH );
 
 const uint8_t ILI9340_MAX_VERTICAL_CHARS
-    = ( ILI9340_MAX_VERTICAL_PIXELS / ILI9340_GLYPH_HEIGHT );
-
-typedef uint8_t ili9340_glyph_t[ 8 ];
+    = ( ILI9340_MAX_VERTICAL_PIXELS / FONT_8X12_GLYPH_HEIGHT );
 
-static const ili9340_glyph_t PROGMEM glyphs[] =
-{
-    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },     // space, ascii 0x20
-    { 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10, 0x00 },     // !
-    { 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00 },     // "
-    { 0x28, 0x28, 0x7c, 0x28, 0x7c, 0x28, 0x28, 0x00 },     // #
-    { 0x10, 0x3c, 0x50, 0x38, 0x14, 0x78, 0x10, 0x00 },     // $
-    { 0x60, 0x64, 0x08, 0x10, 0x20, 0x4c, 0x0c, 0x00 },     // %
-    { 0x10, 0x28, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00 },     // &
-    { 0x30, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00 },     // '
-    { 0x10, 0x20, 0x40, 0x40, 0x40, 0x20, 0x10, 0x00 },     // (
-    { 0x10, 0x08, 0x04, 0x04, 0x04, 0x08, 0x10, 0x00 },     // )
-    { 0x00, 0x10, 0x54, 0x38, 0x54, 0x10, 0x00, 0x00 },     // *
-    { 0x00, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x00, 0x00 },     // +
-    { 0x00, 0x00, 0x00, 0x00, 0x30, 0x10, 0x20, 0x00 },     // ,
-    { 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00 },     // -
-    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00 },     // .
-    { 0x00, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00 },     // /
-    { 0x38, 0x44, 0x4c, 0x54, 0x64, 0x44, 0x38, 0x00 },     // 0
-    { 0x10, 0x30, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00 },     // 1
-    { 0x38, 0x44, 0x04, 0x08, 0x10, 0x20, 0x7c, 0x00 },     // 2
-    { 0x7c, 0x08, 0x10, 0x08, 0x04, 0x44, 0x38, 0x00 },     // 3
-    { 0x08, 0x18, 0x28, 0x48, 0x7c, 0x08, 0x08, 0x00 },     // 4
-    { 0x7c, 0x40, 0x78, 0x04, 0x04, 0x44, 0x38, 0x00 },     // 5
-    { 0x18, 0x20, 0x40, 0x78, 0x44, 0x44, 0x38, 0x00 },     // 6
-    { 0x7c, 0x04, 0x08, 0x10, 0x20, 0x20, 0x20, 0x00 },     // 7
-    { 0x38, 0x44, 0x44, 0x38, 0x44, 0x44, 0x38, 0x00 },     // 8
-    { 0x38, 0x44, 0x44, 0x38, 0x04, 0x04, 0x38, 0x00 },     // 9
-    { 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x00, 0x00 },     // :
-    { 0x00, 0x30, 0x30, 0x00, 0x30, 0x10, 0x20, 0x00 },     // ;
-    { 0x08, 0x10, 0x20, 0x40, 0x20, 0x10, 0x08, 0x00 },     // <
-    { 0x00, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x00, 0x00 },     // =
-    { 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x00 },     // >
-    { 0x38, 0x44, 0x04, 0x08, 0x10, 0x00, 0x10, 0x00 },     // ?
-    { 0x38, 0x44, 0x04, 0x34, 0x54, 0x54, 0x38, 0x00 },     // @
-    { 0x38, 0x44, 0x44, 0x44, 0x7c, 0x44, 0x44, 0x00 },     // A
-    { 0x78, 0x44, 0x44, 0x78, 0x44, 0x44, 0x78, 0x00 },     // B
-    { 0x38, 0x44, 0x40, 0x40, 0x40, 0x44, 0x38, 0x00 },     // C
-    { 0x70, 0x48, 0x44, 0x44, 0x44, 0x48, 0x70, 0x00 },     // D
-    { 0x7c, 0x40, 0x40, 0x78, 0x40, 0x40, 0x7c, 0x00 },     // E
-    { 0x7c, 0x40, 0x40, 0x78, 0x40, 0x40, 0x40, 0x00 },     // F
-    { 0x38, 0x44, 0x40, 0x5c, 0x44, 0x44, 0x3c, 0x00 },     // G
-    { 0x44, 0x44, 0x44, 0x7c, 0x44, 0x44, 0x44, 0x00 },     // H
-    { 0x38, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00 },     // I
-    { 0x1c, 0x08, 0x08, 0x08, 0x08, 0x48, 0x30, 0x00 },     // J
-    { 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x00 },     // K
-    { 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7c, 0x00 },     // L
-    { 0x44, 0x6c, 0x54, 0x54, 0x44, 0x44, 0x44, 0x00 },     // M
-    { 0x44, 0x44, 0x64, 0x54, 0x4c, 0x44, 0x44, 0x00 },     // N
-    { 0x38, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00 },     // O
-    { 0x78, 0x44, 0x44, 0x78, 0x40, 0x40, 0x40, 0x00 },     // P
-    { 0x38, 0x44, 0x44, 0x44, 0x54, 0x48, 0x34, 0x00 },     // Q
-    { 0x78, 0x44, 0x44, 0x78, 0x50, 0x48, 0x44, 0x00 },     // R
-    { 0x3c, 0x40, 0x40, 0x38, 0x04, 0x04, 0x78, 0x00 },     // S
-    { 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00 },     // T
-    { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x38, 0x00 },     // U
-    { 0x44, 0x44, 0x44, 0x44, 0x44, 0x28, 0x10, 0x00 },     // V
-    { 0x44, 0x44, 0x44, 0x54, 0x54, 0x54, 0x28, 0x00 },     // W
-    { 0x44, 0x44, 0x28, 0x10, 0x28, 0x44, 0x44, 0x00 },     // X
-    { 0x44, 0x44, 0x44, 0x28, 0x10, 0x10, 0x10, 0x00 },     // Y
-    { 0x7c, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7c, 0x00 },     // Z
-    { 0x70, 0x40, 0x40, 0x40, 0x40, 0x40, 0x70, 0x00 },     // [
-    { 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00, 0x00 },     // \ (backslash)
-    { 0x1c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x1c, 0x00 },     // ]
-    { 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00 },     // ^
-    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00 },     // _
-    { 0x20, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 },     // `
-    { 0x00, 0x00, 0x38, 0x04, 0x3c, 0x44, 0x3c, 0x00 },     // a
-    { 0x40, 0x40, 0x58, 0x64, 0x44, 0x44, 0x78, 0x00 },     // b
-    { 0x00, 0x00, 0x38, 0x40, 0x40, 0x44, 0x38, 0x00 },     // c
-    { 0x04, 0x04, 0x34, 0x4c, 0x44, 0x44, 0x3c, 0x00 },     // d
-    { 0x00, 0x00, 0x38, 0x44, 0x7c, 0x40, 0x38, 0x00 },     // e
-    { 0x18, 0x24, 0x20, 0x70, 0x20, 0x20, 0x20, 0x00 },     // f
-    { 0x00, 0x3c, 0x44, 0x44, 0x3c, 0x04, 0x38, 0x00 },     // g
-    { 0x40, 0x40, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00 },     // h
-    { 0x10, 0x00, 0x30, 0x10, 0x10, 0x10, 0x38, 0x00 },     // i
-    { 0x04, 0x00, 0x0c, 0x04, 0x04, 0x24, 0x18, 0x00 },     // j
-    { 0x40, 0x40, 0x48, 0x50, 0x60, 0x50, 0x48, 0x00 },     // k
-    { 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00 },     // l
-    { 0x00, 0x00, 0x68, 0x54, 0x54, 0x44, 0x44, 0x00 },     // m
-    { 0x00, 0x00, 0x58, 0x64, 0x44, 0x44, 0x44, 0x00 },     // n
-    { 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00 },     // o
-    { 0x00, 0x00, 0x78, 0x44, 0x78, 0x40, 0x40, 0x00 },     // p
-    { 0x00, 0x00, 0x34, 0x4c, 0x3c, 0x04, 0x04, 0x00 },     // q
-    { 0x00, 0x00, 0x58, 0x64, 0x40, 0x40, 0x40, 0x00 },     // r
-    { 0x00, 0x00, 0x38, 0x40, 0x38, 0x04, 0x78, 0x00 },     // s
-    { 0x20, 0x20, 0x70, 0x20, 0x20, 0x24, 0x18, 0x00 },     // t
-    { 0x00, 0x00, 0x44, 0x44, 0x44, 0x4c, 0x34, 0x00 },     // u
-    { 0x00, 0x00, 0x44, 0x44, 0x44, 0x28, 0x10, 0x00 },     // v
-    { 0x00, 0x00, 0x44, 0x44, 0x54, 0x54, 0x28, 0x00 },     // w
-    { 0x00, 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00 },     // x
-    { 0x00, 0x00, 0x44, 0x44, 0x3c, 0x04, 0x38, 0x00 },     // y
-    { 0x00, 0x00, 0x7c, 0x08, 0x10, 0x20, 0x7c, 0x00 },     // z
-    { 0x10, 0x20, 0x20, 0x40, 0x20, 0x20, 0x10, 0x00 },     // {
-    { 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00 },     // |
-    { 0x10, 0x08, 0x08, 0x04, 0x08, 0x08, 0x10, 0x00 },     // }
-    { 0x00, 0x00, 0x14, 0x28, 0x00, 0x00, 0x00, 0x00 },     // ~
-    { 0x00, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x00 }      // DEL
-};
-
-#endif
+#endif // #if defined( PRJ_ILI9340_INC_WRITE_CHAR )
 
 // ----------------------------------------------------------------------------------------
 
@@ -337,6 +231,7 @@
 {
     set_controller_command_mode();
     select_controller();
+    PORTB &= ~( 1 << PB7 );
     spi_write( cmd );
     deselect_controller();
 }
@@ -344,6 +239,7 @@
 static void send_data( uint8_t data )
 {
     set_controller_data_mode();
+    PORTB &= ~( 1 << PB7 );
     select_controller();
     spi_write( data );
     deselect_controller();
@@ -353,6 +249,11 @@
 
 void ili9340_init()
 {
+    //--    Configure the SPI hardware; the caller might have done it but it doesn't
+    //      hurt to do it again.
+
+    spi_init();
+
     //--    Configure our select line and mode line.
 
     PRJ_ILI9340_SELECT_DDR  |= ( 1 << PRJ_ILI9340_SELECT_PIN );
@@ -377,6 +278,87 @@
     //--    Configure the display controller. This is mostly copied from example code
     //      and reading the ILITEK datasheet.
 
+    //select_controller();
+
+#if 0
+    send_command(0xEF);
+    send_data(0x03);
+    send_data(0x80);
+    send_data(0x02);
+
+    send_command(0xCF);
+    send_data(0x00);
+    send_data(0XC1);
+    send_data(0X30);
+
+    send_command(0xED);
+    send_data(0x64);
+    send_data(0x03);
+    send_data(0X12);
+    send_data(0X81);
+
+    send_command(0xE8);
+    send_data(0x85);
+    send_data(0x00);
+    send_data(0x78);
+
+    send_command(0xCB);
+    send_data(0x39);
+    send_data(0x2C);
+    send_data(0x00);
+    send_data(0x34);
+    send_data(0x02);
+
+    send_command(0xF7);
+    send_data(0x20);
+
+    send_command(0xEA);
+    send_data(0x00);
+    send_data(0x00);
+#endif
+
+#if 1
+#define ILI9340_PWCTR1  0xC0
+#define ILI9340_PWCTR2  0xC1
+#define ILI9340_PWCTR3  0xC2
+    send_command(ILI9340_PWCTR1);    //Power control 
+    send_data(0x23);   //VRH[5:0] 
+
+    send_command(ILI9340_PWCTR2);    //Power control 
+    send_data(0x10);   //SAP[2:0];BT[3:0] 
+
+#define ILI9340_VMCTR1  0xC5
+    send_command(ILI9340_VMCTR1);    //VCM control 
+    send_data(0x3e); //�Աȶȵ���
+    send_data(0x28);
+
+#define ILI9340_VMCTR2  0xC7
+    send_command(ILI9340_VMCTR2);    //VCM control2 
+    send_data(0x86);  //--
+
+#define ILI9340_MADCTL  0x36
+#define ILI9340_MADCTL_MX  0x40
+#define ILI9340_MADCTL_BGR 0x08
+    send_command(ILI9340_MADCTL);    // Memory Access Control 
+    send_data(ILI9340_MADCTL_MX | ILI9340_MADCTL_BGR);
+
+#define ILI9340_PIXFMT  0x3A
+    send_command(ILI9340_PIXFMT);
+    send_data(0x55);
+
+#define ILI9340_FRMCTR1 0xB1
+    send_command(ILI9340_FRMCTR1);
+    send_data(0x00);
+    send_data(0x18);
+
+#define ILI9340_DFUNCTR 0xB6
+    send_command(ILI9340_DFUNCTR);    // Display Function Control 
+    send_data(0x08);
+    send_data(0x82);
+    send_data(0x27);
+#endif
+
+#if 0
     send_command( ILI9340_COMMAND_PWCTRL1 );
     send_data( 0x23 & ILI9340_PWCTRL1_VRH_MASK );   // GVDD = 4.60 V
     send_data( 0x00 & ILI9340_PWCTRL1_VC_MASK );    // VCI1 = 2.30 V
@@ -430,6 +412,60 @@
     spinwait_delay_ms( 120 );
 
     send_command( ILI9340_COMMAND_DISPON );
+#endif
+
+#if 0
+    send_command(0xF2);    // 3Gamma Function Disable 
+    send_data(0x00);
+
+#define ILI9340_GAMMASET 0x26
+    send_command(ILI9340_GAMMASET);    //Gamma curve selected 
+    send_data(0x01);
+
+#define ILI9340_GMCTRP1 0xE0
+    send_command(ILI9340_GMCTRP1);    //Set Gamma 
+    send_data(0x0F);
+    send_data(0x31);
+    send_data(0x2B);
+    send_data(0x0C);
+    send_data(0x0E);
+    send_data(0x08);
+    send_data(0x4E);
+    send_data(0xF1);
+    send_data(0x37);
+    send_data(0x07);
+    send_data(0x10);
+    send_data(0x03);
+    send_data(0x0E);
+    send_data(0x09);
+    send_data(0x00);
+
+#define ILI9340_GMCTRN1 0xE1
+    send_command(ILI9340_GMCTRN1);    //Set Gamma 
+    send_data(0x00);
+    send_data(0x0E);
+    send_data(0x14);
+    send_data(0x03);
+    send_data(0x11);
+    send_data(0x07);
+    send_data(0x31);
+    send_data(0xC1);
+    send_data(0x48);
+    send_data(0x08);
+    send_data(0x0F);
+    send_data(0x0C);
+    send_data(0x31);
+    send_data(0x36);
+    send_data(0x0F);
+#endif 
+
+#define ILI9340_SLPOUT  0x11
+    send_command(ILI9340_SLPOUT);    //Exit Sleep 
+    spinwait_delay_ms(120);
+#define ILI9340_DISPON  0x29
+    send_command(ILI9340_DISPON);    //Display on
+
+    deselect_controller();
 }
 
 // ----------------------------------------------------------------------------------------
@@ -447,10 +483,14 @@
 
 #else
 
+    //select_controller();
+
     spinwait_delay_ms( 5 );
     send_command( ILI9340_COMMAND_SWRESET );
     spinwait_delay_ms( 150 );
 
+    //deselect_controller();
+
 #endif
 
 }
@@ -462,16 +502,16 @@
 static void prep_page_col_address( uint16_t x, uint16_t dx, uint16_t y, uint16_t dy )
 {
     send_command( ILI9340_COMMAND_CASET );
-    send_data( x >> 8 );
-    send_data( x & 0xff );
-    send_data( ( x + dx ) >> 8 );
-    send_data( ( x + dx ) & 0xff );
+    send_data( static_cast< uint8_t >( x >> 8 ) );
+    send_data( static_cast< uint8_t >( x ) );
+    send_data( static_cast< uint8_t >( ( x + dx ) >> 8 ) );
+    send_data( static_cast< uint8_t >( x + dx ) );
 
     send_command( ILI9340_COMMAND_PASET );
-    send_data( y >> 8 );
-    send_data( y & 0xff );
-    send_data( ( y + dx ) >> 8 );
-    send_data( ( y + dx ) & 0xff );
+    send_data( static_cast< uint8_t >( y >> 8 ) );
+    send_data( static_cast< uint8_t >( y ) );
+    send_data( static_cast< uint8_t >( ( y + dy ) >> 8 ) );
+    send_data( static_cast< uint8_t >( y + dy ) );
 
     send_command( ILI9340_COMMAND_RAMWR );
 }
@@ -481,22 +521,26 @@
 
 void ili9340_fill_screen( ili9340_color_t color )
 {
-    select_controller();
-
-    //--    Set the page and column addressing to 0 - 131.
+    //--    Set the page and column addressing to the full screen.
 
     prep_page_col_address( 0, ILI9340_MAX_HORIZONTAL_PIXELS - 1,
                            0, ILI9340_MAX_VERTICAL_PIXELS - 1 );
 
+    set_controller_data_mode();
+    select_controller();
+
     uint8_t color_hi = static_cast< uint8_t >( color >> 8 );
     uint8_t color_lo = static_cast< uint8_t >( color );
 
-    for ( uint16_t i = 0;
-          i < ( ILI9340_MAX_HORIZONTAL_PIXELS * ILI9340_MAX_VERTICAL_PIXELS );
-          ++i ) 
+    for ( uint16_t i = 0; i < ILI9340_MAX_HORIZONTAL_PIXELS; ++i )
     {
-        send_data( color_hi );
-        send_data( color_lo );
+        for ( uint16_t j = 0; j < ILI9340_MAX_VERTICAL_PIXELS; ++j )
+        {
+    PORTB &= ~( 1 << PB7 );
+            spi_write( color_hi );
+    PORTB &= ~( 1 << PB7 );
+            spi_write( color_lo );
+        }
     }
 
     deselect_controller();
@@ -515,23 +559,15 @@
 {
     //--    Convert the glyph coordinates to pixel coordinates.
 
-    x %= ILI9340_MAX_HORIZONTAL_CHARS;
-    x *= ILI9340_GLYPH_WIDTH;
-
-    y %= ILI9340_MAX_VERTICAL_CHARS;
-    y *= ILI9340_GLYPH_HEIGHT;
-
-    //--    Glyphs are stored starting with the space character: ASCII 32 = 0x20.
+    uint16_t pixel_x = static_cast< uint16_t >( x ); //% ILI9340_MAX_HORIZONTAL_CHARS );
+    pixel_x *= FONT_8X12_GLYPH_WIDTH;
 
-    if ( c < 0x20 )
-    {
-        c = 0x7f;   // generic character glyph
-    }
+    uint16_t pixel_y = static_cast< uint16_t >( y ); //% ILI9340_MAX_VERTICAL_CHARS );
+    pixel_y *= FONT_8X12_GLYPH_HEIGHT;
 
-    c -= 0x20;
-    
-    const prog_uint8_t* this_glyph
-      = reinterpret_cast< const prog_uint8_t* >( &glyphs[ static_cast< uint8_t >( c ) ] );
+    //--    Fetch the PROGMEM ptr to the desired glyph data.
+
+    const prog_uint8_t* this_glyph = font_8x12_glyph_ptr( c );
 
     //--    Write the glyph pixels at the specified location.
 
@@ -541,25 +577,29 @@
     uint8_t bg_color_hi = static_cast< uint8_t >( bg_color >> 8 );
     uint8_t bg_color_lo = static_cast< uint8_t >( bg_color );
 
+    prep_page_col_address( pixel_x,
+                           static_cast< uint16_t >( FONT_8X12_GLYPH_WIDTH - 1 ),
+                           pixel_y, 
+                           static_cast< uint16_t >( FONT_8X12_GLYPH_HEIGHT - 1 ) );
+
+    set_controller_data_mode();
     select_controller();
-    
-    prep_page_col_address( x, ILI9340_GLYPH_WIDTH - 1, y, ILI9340_GLYPH_HEIGHT - 1 );
 
-    for ( uint8_t i = 0; i < ILI9340_GLYPH_HEIGHT; i++ )
+    for ( uint8_t i = 0; i < FONT_8X12_GLYPH_HEIGHT; i++ )
     {
         uint8_t data = pgm_read_byte_near( this_glyph++ );
 
-        for ( uint8_t j = 0; j < ILI9340_GLYPH_WIDTH; j++ )
+        for ( uint8_t j = 0; j < FONT_8X12_GLYPH_WIDTH; j++ )
         {
             if ( data & 0x80 )
             {
-                send_data( fg_color_hi );
-                send_data( fg_color_lo );
+                spi_write( fg_color_hi );
+                spi_write( fg_color_lo );
             }
             else
             {
-                send_data( bg_color_hi );
-                send_data( bg_color_lo );
+                spi_write( bg_color_hi );
+                spi_write( bg_color_lo );
             }
             data <<= 1;
         }
@@ -570,7 +610,6 @@
 
 #endif
 
-
 // ----------------------------------------------------------------------------------------
 
 #if defined( PRJ_ILI9340_INC_WRITE_CSTRINGS )
@@ -592,7 +631,6 @@
 
 #endif
 
-
 // ----------------------------------------------------------------------------------------
 
 #if defined( PRJ_ILI9340_INC_WRITE_PGM_CSTRINGS )
@@ -602,8 +640,8 @@
         const prog_char* str, 
         uint8_t          x, 
         uint8_t          y, 
-        ili9340_color_t   fg_color,
-        ili9340_color_t   bg_color 
+        ili9340_color_t  fg_color,
+        ili9340_color_t  bg_color 
     )
 {
     for ( ;; )
@@ -621,7 +659,6 @@
 
 #endif
 
-
 // ----------------------------------------------------------------------------------------
 
 #if defined( PRJ_ILI9340_INC_SET_PIXEL )
@@ -641,12 +678,11 @@
 
 #endif
 
-
 // ----------------------------------------------------------------------------------------
 
 #if defined( PRJ_ILI9340_INC_DRAWING )
 
-void ili9340_line_h( uint8_t x, uint8_t y, uint8_t len, ili9340_color_t color )
+void ili9340_line_h( uint16_t x, uint16_t y, uint16_t len, ili9340_color_t color )
 {
     x %= ILI9340_MAX_HORIZONTAL_PIXELS;
     y %= ILI9340_MAX_VERTICAL_PIXELS;
@@ -670,12 +706,11 @@
 
 #endif
 
-
 // ----------------------------------------------------------------------------------------
 
 #if defined( PRJ_ILI9340_INC_DRAWING )
 
-void ili9340_line_v( uint8_t x, uint8_t y, uint8_t len, ili9340_color_t color )
+void ili9340_line_v( uint16_t x, uint16_t y, uint16_t len, ili9340_color_t color )
 {
     x %= ILI9340_MAX_HORIZONTAL_PIXELS;
     y %= ILI9340_MAX_VERTICAL_PIXELS;
@@ -685,13 +720,18 @@
         len = ILI9340_MAX_VERTICAL_PIXELS - y;
     }
 
-    select_controller();
-    
     prep_page_col_address( x, 0, y, len - 1 );
     
+    set_controller_data_mode();
+    select_controller();
+
+    uint8_t color_hi = static_cast< uint8_t >( color >> 8 );
+    uint8_t color_lo = static_cast< uint8_t >( color );
+
     while ( len-- )
     {
-        send_data( color );
+        spi_write( color_hi );
+        spi_write( color_lo );
     }
 
     deselect_controller();
@@ -699,12 +739,11 @@
 
 #endif
 
-
 // ----------------------------------------------------------------------------------------
 
 #if defined( PRJ_ILI9340_INC_DRAWING )
 
-void ili9340_rect( uint8_t x, uint8_t y, uint8_t w, uint8_t h, ili9340_color_t color )
+void ili9340_rect( uint16_t x, uint16_t y, uint16_t w, uint16_t h, ili9340_color_t color )
 {
     ili9340_line_h( x, y, w, color );
     ili9340_line_h( x, y + h - 1, w, color );
@@ -714,15 +753,14 @@
 
 #endif
 
-
 // ----------------------------------------------------------------------------------------
 
 #if defined( PRJ_ILI9340_INC_DRAWING )
 
-void ili9340_fill( uint8_t x, uint8_t y, uint8_t w, uint8_t h, ili9340_color_t color )
+void ili9340_fill( uint16_t x, uint16_t y, uint16_t w, uint16_t h, ili9340_color_t color )
 {
-    x %= ILI9340_MAX_HORIZONTAL_PIXELS;
-    y %= ILI9340_MAX_VERTICAL_PIXELS;
+    if ( x > ILI9340_MAX_HORIZONTAL_PIXELS ) { x = ILI9340_MAX_HORIZONTAL_PIXELS; }
+    if ( y > ILI9340_MAX_VERTICAL_PIXELS )   { y = ILI9340_MAX_VERTICAL_PIXELS; }
     
     if ( w + x > ILI9340_MAX_HORIZONTAL_PIXELS )
     {
@@ -734,13 +772,23 @@
         h = ILI9340_MAX_VERTICAL_PIXELS - y;
     }
 
+    prep_page_col_address( x, w - 1, y, h - 1 );
+
+    set_controller_data_mode();
     select_controller();
-    
-    prep_page_col_address( x, w - 1, y, h - 1 );
-    
-    for ( uint16_t i = 0; i < static_cast< uint16_t >( h * w ); i++ )
+
+    uint8_t color_hi = static_cast< uint8_t >( color >> 8 );
+    uint8_t color_lo = static_cast< uint8_t >( color );
+
+    for ( uint16_t i = 0; i < w; ++i )
     {
-        send_data( color );
+        for ( uint16_t j = 0; j < h; ++j )
+        {
+    PORTB &= ~( 1 << PB7 );
+            spi_write( color_hi );
+    PORTB &= ~( 1 << PB7 );
+            spi_write( color_lo );
+        }
     }
 
     deselect_controller();
@@ -748,12 +796,15 @@
 
 #endif
 
-
 // ----------------------------------------------------------------------------------------
 
-#if defined( PRJ_ILI9340_INC_DRAWING )
+#if defined( PRJ_ILI9340_INC_DRAWING_ADV )
 
-void ili9340_line( uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, ili9340_color_t color )
+void ili9340_line( uint16_t x0,
+                   uint16_t y0,x
+                   uint16_t x1, x
+                   uint16_t y1, x
+                   ili9340_color_t color )
 {
     //--    Bresenham's line rasterization algorithm: 
     //      http://www.cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html
@@ -820,7 +871,6 @@
 
 #endif
 
-
 // ----------------------------------------------------------------------------------------
 
 #if defined( PRJ_ILI9340_INC_IMAGEMASK )
@@ -874,7 +924,6 @@
 
 #endif
 
-
 // ----------------------------------------------------------------------------------------
 
 #if defined( PRJ_ILI9340_INC_COLORIMAGE )
@@ -908,7 +957,6 @@
 
 #endif
 
-
 // ----------------------------------------------------------------------------------------
 
 #endif  // #if defined( PRJ_ILI9340_ENABLE )
--- a/main/packages/avr/lcd/ili9340/ili9340.h	Sat May 10 08:13:43 2014 -0700
+++ b/main/packages/avr/lcd/ili9340/ili9340.h	Sat Jun 14 12:35:35 2014 -0700
@@ -189,7 +189,7 @@
 //      This function is only available if PRJ_ILI9340_INC_SET_PIXEL is defined.
 //
 
-void ili9340_set_pixel( uint8_t x, uint8_t y, ili9340_color_t color );
+void ili9340_set_pixel( uint16_t x, uint16_t y, ili9340_color_t color );
 
 // ----------------------------------------------------------------------------------------
 //  ili9340_line_h
@@ -199,7 +199,7 @@
 //      This function is only available if PRJ_ILI9340_INC_DRAWING is defined.
 //
 
-void ili9340_line_h( uint8_t x, uint8_t y, uint8_t len, ili9340_color_t color );
+void ili9340_line_h( uint16_t x, uint16_t y, uint16_t len, ili9340_color_t color );
 
 // ----------------------------------------------------------------------------------------
 //  ili9340_line_v
@@ -209,7 +209,7 @@
 //      This function is only available if PRJ_ILI9340_INC_DRAWING is defined.
 //
 
-void ili9340_line_v( uint8_t x, uint8_t y, uint8_t len, ili9340_color_t color );
+void ili9340_line_v( uint16_t x, uint16_t y, uint16_t len, ili9340_color_t color );
 
 // ----------------------------------------------------------------------------------------
 //  ili9340_rect
@@ -219,7 +219,7 @@
 //      This function is only available if PRJ_ILI9340_INC_DRAWING is defined.
 //
 
-void ili9340_rect( uint8_t x, uint8_t y, uint8_t w, uint8_t h, ili9340_color_t color );
+void ili9340_rect( uint16_t x, uint16_t y, uint16_t w, uint16_t h, ili9340_color_t color );
 
 // ----------------------------------------------------------------------------------------
 //  ili9340_fill
@@ -229,7 +229,7 @@
 //      This function is only available if PRJ_ILI9340_INC_DRAWING is defined.
 //
 
-void ili9340_fill( uint8_t x, uint8_t y, uint8_t w, uint8_t h, ili9340_color_t color );
+void ili9340_fill( uint16_t x, uint16_t y, uint16_t w, uint16_t h, ili9340_color_t color );
 
 // ----------------------------------------------------------------------------------------
 //  ili9340_line
@@ -241,7 +241,7 @@
 //      This function is only available if PRJ_ILI9340_INC_DRAWING is defined.
 //
 
-void ili9340_line( uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, ili9340_color_t color );
+void ili9340_line( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, ili9340_color_t color );
 
 // ----------------------------------------------------------------------------------------
 //  ili9340_imagemask
@@ -255,10 +255,10 @@
 
 void ili9340_imagemask
     (
-        uint8_t             x,
-        uint8_t             y,
-        uint8_t             w,
-        uint8_t             h,
+        uint16_t             x,
+        uint16_t             y,
+        uint16_t             w,
+        uint16_t             h,
         ili9340_color_t     fg_color,
         ili9340_color_t     bg_color,
         const prog_uint8_t* pixels
@@ -276,10 +276,10 @@
 
 void ili9340_colorimage
     (
-        uint8_t             x,
-        uint8_t             y,
-        uint8_t             w,
-        uint8_t             h,
+        uint16_t             x,
+        uint16_t             y,
+        uint16_t             w,
+        uint16_t             h,
         const prog_uint8_t* pixels
     );