output

Dependencies:   images mbed

Fork of display by madhu sudhana

Revision:
1:b64c81071d96
Parent:
0:c0be4e018a09
Child:
2:e7a5b9bc75b4
diff -r c0be4e018a09 -r b64c81071d96 ili9163lcd.cpp
--- a/ili9163lcd.cpp	Sat Jun 14 02:27:06 2014 +0000
+++ b/ili9163lcd.cpp	Sat Feb 28 20:26:45 2015 +0000
@@ -29,21 +29,28 @@
  * @copyright parts (C) 2012 NoccyLabs
  */
 
+#include "ili9163lcd.h"
 #include "mbed.h"
-#include "font5x8.h"
-#include "ili9163lcd.h"
 
-// Connection of mbed pins.
-DigitalOut SCK_(D2);
-DigitalOut SDA_(D3);
-DigitalOut A0_(D4);
-DigitalOut RESET_(D5);
-DigitalOut CS_(D6);
+//--------------------------------------------------------------------------
+// Construktor Objekt initialisieren
+//
+ILI9163::ILI9163(PinName SCK, PinName SDA, PinName A0, PinName RESET, PinName CS)
+ : SCK_(SCK), SDA_(SDA), A0_(A0), RESET_(RESET), CS_(CS)
+{
+  tm=10;
+  R=0,G=0,B=0;
+  RGB_state=0;
+  
+  font_size = 2;
+  
+  set_font((unsigned char*)font11x16);  
+}
 
-// Low-level LCD driving functions --------------------------------------------------------------------------
-
+//--------------------------------------------------------------------------
+// Low-level LCD driving functions
 // Reset the LCD hardware
-void lcdReset(void)
+void ILI9163::lcdReset(void)
 {
     // Reset pin is active low (0 = reset, 1 = ready)
     RESET_ = 0;
@@ -53,7 +60,7 @@
     wait_ms(120);
 }
 
-void lcdWriteCommand(uint8_t address)
+void ILI9163::lcdWriteCommand(uint8_t address)
 {
     uint8_t i;
 
@@ -69,7 +76,7 @@
     CS_ = 1;
 }
 
-void lcdWriteParameter(uint8_t parameter)
+void ILI9163::lcdWriteParameter(uint8_t parameter)
 {  
     uint8_t i;
 
@@ -85,7 +92,7 @@
     CS_ = 1;
 }
  
-void lcdWriteData(uint8_t dataByte1, uint8_t dataByte2)
+void ILI9163::lcdWriteData(uint8_t dataByte1, uint8_t dataByte2)
 {  
     uint8_t i;
 
@@ -109,7 +116,7 @@
 }
 
 // Initialise the display with the require screen orientation
-void lcdInitialise(uint8_t orientation)
+void ILI9163::lcdInitialise(uint8_t orientation)
 {   
     CS_ = 1;
     SCK_ = 0;
@@ -208,7 +215,7 @@
 
 // LCD graphics functions -----------------------------------------------------------------------------------
 
-void lcdClearDisplay(uint16_t colour)
+void ILI9163::lcdClearDisplay(uint16_t colour)
 {
     uint16_t pixel;
   
@@ -231,7 +238,7 @@
     for(pixel = 0; pixel < 16385; pixel++) lcdWriteData(colour >> 8, colour);
 }
 
-void lcdPlot(uint8_t x, uint8_t y, uint16_t colour)
+void ILI9163::lcdPlot(uint8_t x, uint8_t y, uint16_t colour)
 {
     // Horizontal Address Start Position
     lcdWriteCommand(SET_COLUMN_ADDRESS);
@@ -255,7 +262,7 @@
 // Draw a line from x0, y0 to x1, y1
 // Note:    This is a version of Bresenham's line drawing algorithm
 //          It only draws lines from left to right!
-void lcdLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour)
+void ILI9163::lcdLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour)
 {
     int16_t dy = y1 - y0;
     int16_t dx = x1 - x0;
@@ -312,7 +319,7 @@
 }
 
 // Draw a rectangle between x0, y0 and x1, y1
-void lcdRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour)
+void ILI9163::lcdRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour)
 {
     lcdLine(x0, y0, x0, y1, colour);
     lcdLine(x0, y1, x1, y1, colour);
@@ -323,7 +330,7 @@
 // Draw a filled rectangle
 // Note:    y1 must be greater than y0  and x1 must be greater than x0
 //          for this to work
-void lcdFilledRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour)
+void ILI9163::lcdFilledRectangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t colour)
 {
     uint16_t pixels;
             
@@ -353,7 +360,7 @@
 // Note:    This is another version of Bresenham's line drawing algorithm.
 //          There's plenty of documentation on the web if you are curious
 //          how this works.
-void lcdCircle(int16_t xCentre, int16_t yCentre, int16_t radius, uint16_t colour)
+void ILI9163::lcdCircle(int16_t xCentre, int16_t yCentre, int16_t radius, uint16_t colour)
 {
     int16_t x = 0, y = radius;
     int16_t d = 3 - (2 * radius);
@@ -382,10 +389,24 @@
 
 // LCD text manipulation functions --------------------------------------------------------------------------
 
+// die Schriftgröße definieren
+void ILI9163::set_font(unsigned char* f) {
+    font = f;
+    font_bp_char = font[0];                   // Anzal der Bytes pro Zeichen
+    font_hor = font[1];                       // get hor size of font
+    font_vert = font[2];                      // get vert size of font
+    font_bp_line = font[3];                   // bytes per line
+}
+
 // Plot a character at the specified x, y co-ordinates (top left hand corner of character)
-void lcdPutCh(unsigned char character, uint8_t x, uint8_t y, uint16_t fgColour, uint16_t bgColour)
+void ILI9163::lcdPutCh(unsigned char c, uint8_t x, uint8_t y, uint16_t fgColour, uint16_t bgColour)
 {
     uint8_t row, column;
+    uint16_t sign;
+    unsigned char z,w;
+    unsigned int j,i,b;
+    
+    if ((c < 31) || (c > 127)) return;   // auf druckbares Zeichen prüfen   
     
     // To speed up plotting we define a x window of 6 pixels and then
     // write out one row at a time.  This means the LCD will correctly
@@ -395,30 +416,44 @@
     lcdWriteParameter(0x00);
     lcdWriteParameter(x);
     lcdWriteParameter(0x00);
-    lcdWriteParameter(x+5);
+    lcdWriteParameter(x+font_hor-1);  // x + w -1 >> XEnd
   
     lcdWriteCommand(SET_PAGE_ADDRESS); // Vertical Address end Position
     lcdWriteParameter(0x00);
     lcdWriteParameter(y);
     lcdWriteParameter(0x00);
-    lcdWriteParameter(0x7f);
+    lcdWriteParameter(y+font_vert-1);  // y + h -1 >> YEnd  0x7F
         
     lcdWriteCommand(WRITE_MEMORY_START);
     
+    sign = (((c -32) * font_bp_char) + 4); // start of char bitmap
+  
     // Plot the font data
-    for (row = 0; row < 8; row++)
+    for (j=0; j<font_vert; j++) {      //  vert line
+        for (i=0; i<font_hor; i++) {   //  horz line
+            z =  font[sign + (font_bp_line * i) + ((j & 0xF8) >> 3)+1];
+            b = 1 << (j & 0x07);
+            if (( z & b ) == 0x00)  lcdWriteData(fgColour >> 8, fgColour);  
+            else                    lcdWriteData(bgColour >> 8, bgColour);
+        }
+    }
+    
+/*     
+    // Plot the font data
+    for (row = 0; row < font_vert; row++)
     {
-        for (column = 0; column < 6; column++)
+        for (column = 0; column < font_hor; column++)
         {
-            if ((font5x8[character][column]) & (1 << row))
+            if ((font[sign + column]) & (1 << row))
                 lcdWriteData(fgColour >> 8, fgColour);
             else lcdWriteData(bgColour >> 8, bgColour);
         }
     }
+*/
 }
 
 // Plot a string of characters to the LCD
-void lcdPutS(const char *string, uint8_t x, uint8_t y, uint16_t fgColour, uint16_t bgColour)
+void ILI9163::lcdPutS(const char *string, uint8_t x, uint8_t y, uint16_t fgColour, uint16_t bgColour)
 {
     uint8_t origin = x;
 
@@ -426,17 +461,17 @@
     {
         // Check if we are out of bounds and move to 
         // the next line if we are
-        if (x > 121)
+        if (x > (127 - font_vert))
         {
             x = origin;
-            y += 8;
+            y += font_vert;
         }
 
         // If we move past the bottom of the screen just exit
-        if (y > 120) break;
+        if (y > (127 - font_hor)) break;
 
         // Plot the current character
         lcdPutCh(string[characterNumber], x, y, fgColour, bgColour);
-        x += 6;
+        x += font_hor;
     }
 }