A C12832 LCD with generic interface

Dependents:   mbed_blinky HTTPClient_HelloWorld websocketandnode xbeerx ... more

Fork of C12832 by Chris Styles

Files at this revision

API Documentation at this revision

Comitter:
chris
Date:
Sat Nov 09 01:02:48 2013 +0000
Parent:
11:1d68011a277c
Parent:
10:8f86576007d6
Child:
13:8a9cad03124b
Commit message:
Merged pin map changes;

Changed in this revision

C12832_lcd.cpp Show annotated file Show diff for this revision Revisions of this file
C12832_lcd.h Show annotated file Show diff for this revision Revisions of this file
--- a/C12832_lcd.cpp	Sat Nov 09 01:00:59 2013 +0000
+++ b/C12832_lcd.cpp	Sat Nov 09 01:02:48 2013 +0000
@@ -14,7 +14,8 @@
 
 // 13.10.12    initial design
 // 25.10.12    add autorefresh of screen
-// 25.10.12    add standart font 
+// 25.10.12    add standart font
+// 20.12.12    add bitmap graphics
 
 // optional defines :
 // #define debug_lcd  1
@@ -107,7 +108,7 @@
 #else
     _spi.write(cmd);
 #endif
-_CS = 1;
+    _CS = 1;
 }
 
 // write data to lcd controller
@@ -160,7 +161,7 @@
 
     wr_cmd(0xA6);     // display normal
 
-    
+
 #if defined TARGET_LPC1768          //setup DMA channel 0       
     LPC_SC->PCONP |= (1UL << 29);   // Power up the GPDMA
     LPC_GPDMA->DMACConfig = 1;      // enable DMA controller
@@ -172,9 +173,10 @@
     memset(buffer,0x00,512);  // clear display buffer
     copy_to_lcd();
     auto_up = 1;              // switch on auto update
-    claim(stdout);           // redirekt printf to lcd
+    // dont do this by default. Make the user call
+    //claim(stdout);           // redirekt printf to lcd
     locate(0,0);
-    set_font((unsigned char*)Small_7);  // standart font 
+    set_font((unsigned char*)Small_7);  // standart font
 }
 
 // set one pixel in buffer
@@ -199,7 +201,7 @@
 
 void C12832_LCD::copy_to_lcd(void)
 {
-#ifndef TARGET_LPC1768 
+#ifndef TARGET_LPC1768
     int i;
 #endif
     //page 0
@@ -207,7 +209,7 @@
     wr_cmd(0x10);      // set column hi  nibble 0
     wr_cmd(0xB0);      // set page address  0
     _A0 = 1;
-#if defined TARGET_LPC1768     
+#if defined TARGET_LPC1768
     _CS = 0;
     // start 128 byte DMA transfer to SPI1
     LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1
@@ -224,17 +226,17 @@
     } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
     _CS = 1;
 #else  // no DMA
-    for(i=0;i<128;i++){
+    for(i=0; i<128; i++) {
         wr_dat(buffer[i]);
-        }
-#endif 
+    }
+#endif
 
     // page 1
     wr_cmd(0x00);      // set column low nibble 0
     wr_cmd(0x10);      // set column hi  nibble 0
     wr_cmd(0xB1);      // set page address  1
     _A0 = 1;
-#if defined TARGET_LPC1768         
+#if defined TARGET_LPC1768
     _CS = 0;
     // start 128 byte DMA transfer to SPI1
     LPC_GPDMA->DMACIntTCClear = 0x1;
@@ -249,17 +251,17 @@
     } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
     _CS = 1;
 #else // no DMA
-    for(i=128;i<256;i++){
+    for(i=128; i<256; i++) {
         wr_dat(buffer[i]);
-        }
-#endif     
+    }
+#endif
 
     //page 2
     wr_cmd(0x00);      // set column low nibble 0
     wr_cmd(0x10);      // set column hi  nibble 0
     wr_cmd(0xB2);      // set page address  2
     _A0 = 1;
-#if defined TARGET_LPC1768      
+#if defined TARGET_LPC1768
     _CS = 0;
     // start 128 byte DMA transfer to SPI1
     LPC_GPDMA->DMACIntTCClear = 0x1;
@@ -274,19 +276,19 @@
     } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
     _CS = 1;
 #else // no DMA
-    for(i=256;i<384;i++){
+    for(i=256; i<384; i++) {
         wr_dat(buffer[i]);
-        }
-#endif         
+    }
+#endif
 
     //page 3
     wr_cmd(0x00);      // set column low nibble 0
     wr_cmd(0x10);      // set column hi  nibble 0
     wr_cmd(0xB3);      // set page address  3
     _A0 = 1;
-    
-     _CS = 0;
-#if defined TARGET_LPC1768     
+
+    _CS = 0;
+#if defined TARGET_LPC1768
     // start 128 byte DMA transfer to SPI1
     LPC_GPDMA->DMACIntTCClear = 0x1;
     LPC_GPDMA->DMACIntErrClr = 0x1;
@@ -300,10 +302,10 @@
     } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
     _CS = 1;
 #else // no DMA
-    for(i=384;i<512;i++){
+    for(i=384; i<512; i++) {
         wr_dat(buffer[i]);
-        }
-#endif   
+    }
+#endif
 }
 
 void C12832_LCD::cls(void)
@@ -542,7 +544,7 @@
     for (i = 0; i <= r; i++)
         circle(x,y,i,color);
     auto_up = up;
-    if(auto_up) copy_to_lcd();  
+    if(auto_up) copy_to_lcd();
 }
 
 void C12832_LCD::setmode(int mode)
@@ -637,10 +639,33 @@
 void C12832_LCD::set_auto_up(unsigned int up)
 {
     if(up ) auto_up = 1;
+    else auto_up = 0;
 }
 
-unsigned int C12832_LCD::get_auto_up(void){
+unsigned int C12832_LCD::get_auto_up(void)
+{
     return (auto_up);
 }
 
+void C12832_LCD::print_bm(Bitmap bm, int x, int y)
+{
+    int h,v,b;
+    char d;
 
+    for(v=0; v < bm.ySize; v++) {   // lines
+        for(h=0; h < bm.xSize; h++) { // pixel
+            if(h + x > 127) break;
+            if(v + y > 31) break;
+            d = bm.data[bm.Byte_in_Line * v + ((h & 0xF8) >> 3)];
+            b = 0x80 >> (h & 0x07);
+            if((d & b) == 0) {
+                pixel(x+h,y+v,0);
+            } else {
+                pixel(x+h,y+v,1);
+            }
+        }
+    }
+
+}
+
+
--- a/C12832_lcd.h	Sat Nov 09 01:00:59 2013 +0000
+++ b/C12832_lcd.h	Sat Nov 09 01:02:48 2013 +0000
@@ -41,6 +41,15 @@
   */
 enum {NORMAL,XOR};
 
+/** Bitmap
+ */
+struct Bitmap{
+    int xSize;
+    int ySize;
+    int Byte_in_Line;
+    char* data;
+    };
+
 class C12832_LCD : public GraphicsDisplay
 {
 public:
@@ -164,7 +173,7 @@
 
     void setmode(int mode);
 
-    int columns(void);
+    virtual int columns(void);
 
     /** calculate the max number of columns
      *
@@ -172,7 +181,7 @@
      * depends on actual font size
      *
      */
-    int rows(void);
+    virtual int rows(void);
 
     /** put a char on the screen
      *
@@ -180,7 +189,7 @@
      * @returns printed char
      *
      */
-    int _putc(int value);
+    virtual int _putc(int value);
 
     /** draw a character on given position out of the active font to the LCD
      *
@@ -196,7 +205,7 @@
      * @param x x-position (top left)
      * @param y y-position
      */
-    void locate(int x, int y);
+    virtual void locate(int x, int y);
     
     /** setup auto update of screen 
       *
@@ -204,13 +213,13 @@
       * if switched off the program has to call copy_to_lcd() 
       * to update screen from framebuffer
       */
-    void C12832_LCD::set_auto_up(unsigned int up);
+    void set_auto_up(unsigned int up);
 
     /** get status of the auto update function
       *
       *  @returns if auto update is on
       */
-    unsigned int C12832_LCD::get_auto_up(void);
+    unsigned int get_auto_up(void);
 
     /** Vars     */
     SPI _spi;
@@ -235,7 +244,16 @@
       *
       */
     void set_font(unsigned char* f);
+    
+    /** print bitmap to buffer
+      *
+      * @param bm Bitmap in flash
+      * @param x  x start
+      * @param y  y start 
+      *
+      */
 
+    void print_bm(Bitmap bm, int x, int y);
 
 protected: