switch to graphic fonts
authorJim Morris <morris@wolfman.com>
Wed, 31 Jul 2013 10:02:25 +0000 (03:02 -0700)
committerJim Morris <morris@wolfman.com>
Wed, 31 Jul 2013 10:08:17 +0000 (03:08 -0700)
make 20x8 screen

src/modules/utils/panel/Panel.cpp
src/modules/utils/panel/Panel.h
src/modules/utils/panel/panels/LcdBase.cpp
src/modules/utils/panel/panels/LcdBase.h
src/modules/utils/panel/panels/ReprapDiscountGLCD.cpp
src/modules/utils/panel/panels/ReprapDiscountGLCD.h
src/modules/utils/panel/panels/rrdglcd/RrdGlcd.cpp
src/modules/utils/panel/panels/rrdglcd/RrdGlcd.h

index 9a4f72c..8b2d791 100644 (file)
@@ -20,6 +20,7 @@ using namespace std;
 #include "panels/VikiLCD.h"
 #include "panels/Smoothiepanel.h"
 #include "panels/ReprapDiscountGLCD.h"
+#include "version.h"
 
 Panel::Panel(){
     this->counter_changed = false;
@@ -29,6 +30,8 @@ Panel::Panel(){
     this->lcd= NULL;
     this->do_buttons = false;
     this->idle_time= 0;
+    this->start_up= true;
+    this->current_screen= NULL;
     strcpy(this->playing_file, "Playing file");
 }
 
@@ -43,7 +46,6 @@ void Panel::on_module_loaded(){
         return;
     } 
 
-  
     // Initialise the LCD, see which LCD to use
     if (this->lcd != NULL) delete this->lcd;
     int lcd_cksm = get_checksum(this->kernel->config->value(panel_checksum, lcd_checksum)->by_default("i2c")->as_string());
@@ -86,8 +88,6 @@ void Panel::on_module_loaded(){
     default_bed_temperature= this->kernel->config->value( panel_checksum, bed_temp_checksum )->by_default(60.0)->as_number();
 
     this->encoder_click_resolution= this->lcd->getEncoderResolution();
-    this->lcd->init();
-    this->lcd->printf("Starting...");
     
     this->up_button.up_attach(    this, &Panel::on_up );
     this->down_button.up_attach(  this, &Panel::on_down );
@@ -97,12 +97,7 @@ void Panel::on_module_loaded(){
 
     this->kernel->slow_ticker->attach( 100,  this, &Panel::button_tick );
     this->kernel->slow_ticker->attach( 1000, this, &Panel::encoder_check );
-
-    // Default top screen
-    this->top_screen = new MainMenuScreen();
-    this->top_screen->set_panel(this);
-    this->enter_screen(this->top_screen->watch_screen); // default first screen is watch screen even though its parent is Mainmenu
-    
+   
     // Register for events
     this->register_for_event(ON_IDLE);
     this->register_for_event(ON_MAIN_LOOP);
@@ -157,13 +152,33 @@ uint32_t Panel::button_tick(uint32_t dummy){
 
 // on main loop, we can send gcodes or do anything that waits in this loop
 void Panel::on_main_loop(void* argument){
-    this->current_screen->on_main_loop();
-    this->lcd->on_main_loop();
+    if(this->current_screen != NULL) {
+        this->current_screen->on_main_loop();
+        this->lcd->on_main_loop();
+    }
 }
 
 // On idle things, we don't want to do shit in interrupts
 // don't queue gcodes in this
 void Panel::on_idle(void* argument){
+    if(this->start_up) {
+        this->lcd->init();
+
+        if(this->lcd->hasGraphics()) {
+      
+        }else{
+            this->lcd->clear();
+            this->lcd->setCursor(0,0); this->lcd->printf("Smoothie");
+            Version vers;
+            this->lcd->setCursor(0,1); this->lcd->printf("Build %s", vers.get_build());
+            this->lcd->setCursor(0,2); this->lcd->printf("Date %s",  vers.get_build_date());
+        }
+
+        // Default top screen
+        this->top_screen = new MainMenuScreen();
+        this->top_screen->set_panel(this);
+        this->start_up= false;
+    }
 
     // after being idle for a while switch to Watch screen
     if(this->idle_time > 20*5) { // 5 seconds
@@ -182,20 +197,17 @@ void Panel::on_idle(void* argument){
 
         // read the actual buttons
         int but= lcd->readButtons();
-        if(but != 0) this->idle_time= 0;
-        
+        if(but != 0){
+            this->idle_time= 0;
+        }
+
         // fire events if the buttons are active and debounce is satisfied
         this->up_button.check_signal(but&BUTTON_UP);
         this->down_button.check_signal(but&BUTTON_DOWN);
         this->back_button.check_signal(but&BUTTON_LEFT);
         this->click_button.check_signal(but&BUTTON_SELECT);
         this->pause_button.check_signal(but&BUTTON_PAUSE);
-
-        // for debugging
-        if(but&BUTTON_RIGHT) {
-            lcd->init();    
-        }
-    }
+     }
     
     // If we are in menu mode and the position has changed
     if( this->mode == MENU_MODE && this->counter_change() ){
@@ -210,8 +222,10 @@ void Panel::on_idle(void* argument){
     // If we must refresh
     if( this->refresh_flag ){
         this->refresh_flag = false;
-        this->current_screen->on_refresh();
-        this->lcd->on_refresh();
+        if(this->current_screen != NULL) {
+            this->current_screen->on_refresh();
+            this->lcd->on_refresh();
+        }
     }
 }
 
@@ -233,7 +247,7 @@ uint32_t Panel::on_down(uint32_t dummy){
 
 // on most menu screens will go back to previous higher menu
 uint32_t Panel::on_back(uint32_t dummy){
-    if(this->mode == MENU_MODE && this->current_screen->parent != NULL) {
+    if(this->mode == MENU_MODE && this->current_screen != NULL && this->current_screen->parent != NULL) {
         this->enter_screen(this->current_screen->parent);
     }
     return 0;
index e33a44c..a7b1676 100644 (file)
@@ -123,6 +123,7 @@ class Panel : public Module {
         volatile bool do_buttons;
         bool paused;
         int idle_time;
+        bool start_up;
         int encoder_click_resolution;
         char mode;
         uint16_t screen_lines;
dissimilarity index 70%
index 463b825..57fd59b 100644 (file)
@@ -1,27 +1,18 @@
-#include "LcdBase.h"
-
-LcdBase::LcdBase() {}
-LcdBase::~LcdBase() {}
-
-
-int LcdBase::printf(const std::string format, ...){
-       wait_us(10); 
-       va_list args;
-       va_start(args, format);
-       int size = format.size() * 2;
-       char* buffer = new char[size];
-       while (vsprintf(buffer, format.c_str(), args) < 0){
-               delete[] buffer;
-               size *= 2;
-               buffer = new char[size];
-       }
-       string message = std::string(buffer);
-       va_end(args);
-       for(unsigned int i=0; i < message.size(); i++){
-               this->write(message.at(i)); 
-       }
-       this->writeDone();
-       
-       delete[] buffer;
-       return 0;
-}
+#include "LcdBase.h"
+
+LcdBase::LcdBase() {}
+LcdBase::~LcdBase() {}
+
+
+int LcdBase::printf(const char* format, ...){
+       va_list args;
+       va_start(args, format);
+       char buffer[80]; // max length for display anyway
+       int n= vsnprintf(buffer, sizeof(buffer), format, args);
+       va_end(args);
+       for(int i=0; i < n; i++){
+               this->write(buffer[i]); 
+       }
+       this->writeDone();
+       return 0;
+}
index 237e2ff..7cf5df4 100644 (file)
@@ -79,7 +79,7 @@ class LcdBase {
         LcdBase();
         virtual ~LcdBase();
         virtual void init()= 0;
-        int printf(const std::string format, ...);
+        int printf(const char* format, ...);
 
         void setPanel(Panel* p) { panel= p; }
         
@@ -106,11 +106,13 @@ class LcdBase {
         virtual void setLedBrightness(int led, int val){};
         virtual void buzz(long,uint16_t){};
         virtual void writeDone(){};
+        virtual bool hasGraphics() { return false; }
+        virtual void bltGlyph(int x, int y, const uint8_t *glyph, int size){};
 
         // only used on certain panels
         virtual void on_refresh(){};
         virtual void on_main_loop(){};
-        // override this if the panel can hndle more or less screen lines
+        // override this if the panel can handle more or less screen lines
         virtual uint16_t get_screen_lines() { return 4; }
         // used to set a variant for a panel (like viki vs panelolou2)
         virtual void set_variant(int n) {};
index 6132ef1..f63736c 100644 (file)
@@ -31,18 +31,12 @@ ReprapDiscountGLCD::ReprapDiscountGLCD() {
 
     int spi_frequency = THEKERNEL->config->value(panel_checksum, spi_frequency_checksum)->by_default(1000000)->as_number();
     this->glcd->setFrequency(spi_frequency);
-
-    char_buffer.clear();
 }
 
 ReprapDiscountGLCD::~ReprapDiscountGLCD() {
     delete this->glcd;
 }
 
-int getEncoderResolution() {
-    return 2;
-}
-
 uint8_t ReprapDiscountGLCD::readButtons() {
     uint8_t state= 0;
     state |= (this->click_pin.get() ? BUTTON_SELECT : 0);
@@ -75,25 +69,21 @@ void ReprapDiscountGLCD::buzz(long duration, uint16_t freq) {
     }
 }
 
-// we buffer the characters due to the way the glcd does things
 void ReprapDiscountGLCD::ReprapDiscountGLCD::write(char value){
-    char_buffer.append(1, value);
+    this->glcd->displayString(this->row, this->col, &value, 1);
+    this->col++;
 }
 
 void ReprapDiscountGLCD::writeDone(){
-    this->glcd->displayString(this->row, this->col, char_buffer.c_str(), char_buffer.size());
-    char_buffer.clear();
 }
 
 void ReprapDiscountGLCD::home(){
-    this->glcd->returnHome();
     this->col= 0;
     this->row= 0;
 }
 
 void ReprapDiscountGLCD::clear(){
     this->glcd->clearScreen();
-    char_buffer.clear();
     this->col= 0;
     this->row= 0;
 }
@@ -110,3 +100,13 @@ void ReprapDiscountGLCD::setCursor(uint8_t col, uint8_t row){
 void ReprapDiscountGLCD::init(){
     this->glcd->initDisplay();
 }
+
+void ReprapDiscountGLCD::bltGlyph(int x, int y, int w, int h, const uint8_t *glyph) {
+    // TODO
+}
+
+void ReprapDiscountGLCD::on_refresh(){
+    static int refresh_counts = 0;
+    refresh_counts++;
+    if( refresh_counts % 10 == 0 ) this->glcd->refresh();
+}
\ No newline at end of file
index c2c3a5a..a32d130 100644 (file)
@@ -28,8 +28,10 @@ class ReprapDiscountGLCD : public LcdBase {
         ReprapDiscountGLCD();
         virtual ~ReprapDiscountGLCD();
 
-        int getEncoderResolution() { return 4; }
-        
+        int getEncoderResolution() { return 2; }
+        bool hasGraphics() { return false; }
+        uint16_t get_screen_lines() { return 8; }
+
         uint8_t readButtons();
         int readEncoderDelta();
         void write(char value);
@@ -40,12 +42,14 @@ class ReprapDiscountGLCD : public LcdBase {
         void setCursor(uint8_t col, uint8_t row);
         void init();
         void buzz(long,uint16_t);
+        // blit a glyph of w pixels wide and h pixels high to x,y. The glyph will be zero left padded bytes from top left to bottom right
+        void bltGlyph(int x, int y, int w, int h, const uint8_t *glyph);
+        void on_refresh();
 
     private:
         RrdGlcd* glcd;
         uint8_t col;
         uint8_t row;
-        string char_buffer;
 
         Pin spi_cs_pin;
         Pin encoder_a_pin;
dissimilarity index 89%
index 1b97870..c719019 100644 (file)
-#include "RrdGlcd.h"
-
-RrdGlcd::RrdGlcd(PinName mosi, PinName sclk, Pin cs) {
-    this->spi= new mbed::SPI(mosi, NC, sclk); 
-     //chip select
-    this->cs= cs;
-    this->cs.set(0);
-
-    initDisplay();
-}
-
-RrdGlcd::~RrdGlcd() {
-    delete this->spi;
-}
-
-void RrdGlcd::setFrequency(int freq) {
-       this->spi->frequency(freq);
-}
-
-void RrdGlcd::writeInstruction(unsigned int command) {
-    unsigned int hn, ln;
-    hn = command & 0xF0;
-    ln = (command & 0x0F) << 4;
-    
-    this->cs.set(1); // chip select
-    //delay_ns(60); // setup time
-
-    this->spi->write(0xF8); // sync, rw=0, rs=0
-    this->spi->write(hn); // hi nibble
-    this->spi->write(ln); // lo nibble
-
-    this->cs.set(0);
-
-    wait_us(80);
-}
-
-void RrdGlcd::writeRAM(unsigned int data) {
-   unsigned int hn, ln;
-    hn = data & 0xF0;
-    ln = (data & 0x0F) << 4;
-    
-    this->cs.set(1); // chip select
-    //delay_ns(60); // setup time
-
-    this->spi->write(0xFA); // sync, rw=0, rs=1
-    this->spi->write(hn); // hi nibble
-    this->spi->write(ln); // lo nibble
-
-    this->cs.set(0);
-
-    wait_us(80);
-}
-
-void RrdGlcd::initDisplay() {
-    wait_ms(40); // wait 40ms
-    writeInstruction(FUNCTION_SET | DATA_LENGTH_DL); // 8 bits interface, RE=0
-    writeInstruction(DISPLAY_CONTROL | DISPLAY_ON_D ); // display on
-    writeInstruction(DISPLAY_CLEAR); // clear display
-    wait_ms(2); // wait 2ms for clear
-    writeInstruction(ENTRY_MODE_SET | INCREASE_DECREASE_ID); // move cursor right
-    writeInstruction(RETURN_HOME);
-    setGraphicsMode();
-}
-
-//************************************************************************************************
-//public methodes
-void RrdGlcd::setGraphicsMode() {
-    writeInstruction(EXTENDED_FUNCTION_SET | DATA_LENGTH_DL);
-    writeInstruction(EXTENDED_FUNCTION_SET | DATA_LENGTH_DL | EXTENDED_INSTRUCTION_RE); //RE=1 (Extended funtion set)
-    writeInstruction(EXTENDED_FUNCTION_SET | DATA_LENGTH_DL | EXTENDED_INSTRUCTION_RE | GRAPHIC_ON_G);
-}
-
-void RrdGlcd::setTextMode() {
-    writeInstruction(FUNCTION_SET | DATA_LENGTH_DL); // RE=0 (Basic funtion set)
-}
-
-void RrdGlcd::clearScreen() {
-    writeInstruction(FUNCTION_SET | DATA_LENGTH_DL); // RE=0 (Basic funtion set)
-    writeInstruction(DISPLAY_CLEAR);
-}
-
-void RrdGlcd::returnHome() {
-    writeInstruction(FUNCTION_SET | DATA_LENGTH_DL); //RE=0 (Basic funtion set)
-    writeInstruction(RETURN_HOME);
-}
-
-void RrdGlcd::standby() {
-    writeInstruction(EXTENDED_FUNCTION_SET | DATA_LENGTH_DL | EXTENDED_INSTRUCTION_RE); //RE=1 (Extended funtion set)
-    writeInstruction(STANDBY);
-}
-
-//Basic text functions
-void RrdGlcd::displayString(int Row,int Column,const char *ptr,int length) {
-    int i=0;
-
-    switch (Row) {
-        case 0:
-            Column|=0x80;
-            break;
-        case 1:
-            Column|=0x90;
-            break;
-        case 2:
-            Column|=0x88;
-            break;
-        case 3:
-            Column|=0x98;
-            break;
-        default:
-            Column=0x80;
-            break;
-    }
-
-    if (Column%2!=0) {
-        Column-=1;
-        i=1;
-    }
-    writeInstruction((unsigned int)Column);
-
-    if (i==1) {
-        writeRAM(' ');
-    }
-    for (i=0; i<length; i++) {
-        writeRAM((unsigned int)ptr[i]);
-    }
-}
-
-void RrdGlcd::displayChar(int Row,int Column,int inpChr) {
-    int i=0;
-
-    switch (Row) {
-        case 0:
-            Column|=0x80; // SET_DDRAM_ADDRESS
-            break;
-        case 1:
-            Column|=0x90;
-            break;
-        case 2:
-            Column|=0x88;
-            break;
-        case 3:
-            Column|=0x98;
-            break;
-        default:
-            Column=0x80;
-            break;
-    }
-
-    if (Column%2!=0) {
-        Column-=1;
-        i=1;
-    }
-    writeInstruction((unsigned int)Column);
-
-    if (i==1) {
-        writeRAM(' ');
-    }
-    writeRAM((unsigned int)inpChr);
-}
-
-// Graphic functions
-void RrdGlcd::fillGDRAM(unsigned char *bitmap) {
-    unsigned char i, j, k ;
-
-    for ( i = 0 ; i < 2 ; i++ ) {
-        for ( j = 0 ; j < 32 ; j++ ) {
-            writeInstruction(SET_GRAPHIC_RAM_ADDRESS | j) ;
-            if ( i == 0 ) {
-                writeInstruction(SET_GRAPHIC_RAM_ADDRESS) ;
-            } else {
-                writeInstruction(SET_GRAPHIC_RAM_ADDRESS | 0x08) ;
-            }
-            for ( k = 0 ; k < 16 ; k++ ) {
-                writeRAM( *bitmap++ ) ;
-            }
-        }
-    }
-}
-
-void RrdGlcd::fillGDRAM_Turned(unsigned char *bitmap) {
-    int i, j, k, m, offset_row, mask ;
-    unsigned char data;
-
-    for ( i = 0 ; i < 2 ; i++ ) { //upper and lower page
-        for ( j = 0 ; j < 32 ; j++ ) { //32 lines per page
-            writeInstruction(SET_GRAPHIC_RAM_ADDRESS | j) ;
-            if ( i == 0 ) {
-                writeInstruction(SET_GRAPHIC_RAM_ADDRESS) ;
-            } else {
-                writeInstruction(SET_GRAPHIC_RAM_ADDRESS | 0x08) ;
-            }
-            mask=1<<(j%8); // extract bitnumber
-            //printf("mask: %d\r\n",mask);
-            for ( k = 0 ; k < 16 ; k++ ) { //16 bytes per line
-                offset_row=((i*32+j)/8)*128 + k*8; //y coordinate/8 = row 0-7 * 128 = byte offset, read 8 bytes
-                data=0;
-                for (m = 0 ; m < 8 ; m++) { // read 8 bytes from source
-
-                    if ((bitmap[offset_row+m] & mask)) { //pixel = 1
-                        data|=(128>>m);
-                    }
-                }
-                writeRAM(data) ;
-            }
-        }
-    }
-}
-
-void RrdGlcd::clearGDRAM() {
-    unsigned char i, j, k ;
-
-    for ( i = 0 ; i < 2 ; i++ ) {
-        for ( j = 0 ; j < 32 ; j++ ) {
-            writeInstruction(SET_GRAPHIC_RAM_ADDRESS | j) ;
-            if ( i == 0 ) {
-                writeInstruction(SET_GRAPHIC_RAM_ADDRESS) ;
-            } else {
-                writeInstruction(SET_GRAPHIC_RAM_ADDRESS | 0x08) ;
-            }
-            for ( k = 0 ; k < 16 ; k++ ) {
-                writeRAM(0);
-            }
-        }
-    }
-}
+#include "RrdGlcd.h"
+
+static const uint8_t font5x7[] = { 
+    // each of the 5 bytes is an X bit the first byte being X==0, the last being X==5
+    // bit0 is y==0, bit7 is y==7
+    0x00,0x00,0x00,0x00,0x00, // ascii 0
+    0x3e,0x5b,0x4f,0x5b,0x3e, // ascii 1
+    0x3e,0x6b,0x4f,0x6b,0x3e, // ascii 2 .. etc
+    0x1c,0x3e,0x7c,0x3e,0x1c,
+    0x18,0x3c,0x7e,0x3c,0x18,
+    0x1c,0x57,0x7d,0x57,0x1c,
+    0x1c,0x5e,0x7f,0x5e,0x1c,
+    0x00,0x18,0x3c,0x18,0x00,
+    0xff,0xe7,0xc3,0xe7,0xff,
+    0x00,0x18,0x24,0x18,0x00,
+    0xff,0xe7,0xdb,0xe7,0xff,
+    0x30,0x48,0x3a,0x06,0x0e,
+    0x26,0x29,0x79,0x29,0x26,
+    0x40,0x7f,0x05,0x05,0x07,
+    0x40,0x7f,0x05,0x25,0x3f,
+    0x5a,0x3c,0xe7,0x3c,0x5a,
+    0x7f,0x3e,0x1c,0x1c,0x08,
+    0x08,0x1c,0x1c,0x3e,0x7f,
+    0x14,0x22,0x7f,0x22,0x14,
+    0x5f,0x5f,0x00,0x5f,0x5f,
+    0x06,0x09,0x7f,0x01,0x7f,
+    0x00,0x66,0x89,0x95,0x6a,
+    0x60,0x60,0x60,0x60,0x60,
+    0x94,0xa2,0xff,0xa2,0x94,
+    0x08,0x04,0x7e,0x04,0x08,
+    0x10,0x20,0x7e,0x20,0x10,
+    0x08,0x08,0x2a,0x1c,0x08,
+    0x08,0x1c,0x2a,0x08,0x08,
+    0x1e,0x10,0x10,0x10,0x10,
+    0x0c,0x1e,0x0c,0x1e,0x0c,
+    0x30,0x38,0x3e,0x38,0x30,
+    0x06,0x0e,0x3e,0x0e,0x06,
+    0x00,0x00,0x00,0x00,0x00,
+    0x00,0x00,0x5f,0x00,0x00,
+    0x00,0x07,0x00,0x07,0x00,
+    0x14,0x7f,0x14,0x7f,0x14,
+    0x24,0x2a,0x7f,0x2a,0x12,
+    0x23,0x13,0x08,0x64,0x62,
+    0x36,0x49,0x56,0x20,0x50,
+    0x00,0x08,0x07,0x03,0x00,
+    0x00,0x1c,0x22,0x41,0x00,
+    0x00,0x41,0x22,0x1c,0x00,
+    0x2a,0x1c,0x7f,0x1c,0x2a,
+    0x08,0x08,0x3e,0x08,0x08,
+    0x00,0x80,0x70,0x30,0x00,
+    0x08,0x08,0x08,0x08,0x08,
+    0x00,0x00,0x60,0x60,0x00,
+    0x20,0x10,0x08,0x04,0x02,
+    0x3e,0x51,0x49,0x45,0x3e,
+    0x00,0x42,0x7f,0x40,0x00,
+    0x72,0x49,0x49,0x49,0x46,
+    0x21,0x41,0x49,0x4d,0x33,
+    0x18,0x14,0x12,0x7f,0x10,
+    0x27,0x45,0x45,0x45,0x39,
+    0x3c,0x4a,0x49,0x49,0x31,
+    0x41,0x21,0x11,0x09,0x07,
+    0x36,0x49,0x49,0x49,0x36,
+    0x46,0x49,0x49,0x29,0x1e,
+    0x00,0x00,0x14,0x00,0x00,
+    0x00,0x40,0x34,0x00,0x00,
+    0x00,0x08,0x14,0x22,0x41,
+    0x14,0x14,0x14,0x14,0x14,
+    0x00,0x41,0x22,0x14,0x08,
+    0x02,0x01,0x59,0x09,0x06,
+    0x3e,0x41,0x5d,0x59,0x4e,
+    0x7c,0x12,0x11,0x12,0x7c,
+    0x7f,0x49,0x49,0x49,0x36,
+    0x3e,0x41,0x41,0x41,0x22,
+    0x7f,0x41,0x41,0x41,0x3e,
+    0x7f,0x49,0x49,0x49,0x41,
+    0x7f,0x09,0x09,0x09,0x01,
+    0x3e,0x41,0x41,0x51,0x73,
+    0x7f,0x08,0x08,0x08,0x7f,
+    0x00,0x41,0x7f,0x41,0x00,
+    0x20,0x40,0x41,0x3f,0x01,
+    0x7f,0x08,0x14,0x22,0x41,
+    0x7f,0x40,0x40,0x40,0x40,
+    0x7f,0x02,0x1c,0x02,0x7f,
+    0x7f,0x04,0x08,0x10,0x7f,
+    0x3e,0x41,0x41,0x41,0x3e,
+    0x7f,0x09,0x09,0x09,0x06,
+    0x3e,0x41,0x51,0x21,0x5e,
+    0x7f,0x09,0x19,0x29,0x46,
+    0x26,0x49,0x49,0x49,0x32,
+    0x03,0x01,0x7f,0x01,0x03,
+    0x3f,0x40,0x40,0x40,0x3f,
+    0x1f,0x20,0x40,0x20,0x1f,
+    0x3f,0x40,0x38,0x40,0x3f,
+    0x63,0x14,0x08,0x14,0x63,
+    0x03,0x04,0x78,0x04,0x03,
+    0x61,0x59,0x49,0x4d,0x43,
+    0x00,0x7f,0x41,0x41,0x41,
+    0x02,0x04,0x08,0x10,0x20,
+    0x00,0x41,0x41,0x41,0x7f,
+    0x04,0x02,0x01,0x02,0x04,
+    0x40,0x40,0x40,0x40,0x40,
+    0x00,0x03,0x07,0x08,0x00,
+    0x20,0x54,0x54,0x78,0x40,
+    0x7f,0x28,0x44,0x44,0x38,
+    0x38,0x44,0x44,0x44,0x28,
+    0x38,0x44,0x44,0x28,0x7f,
+    0x38,0x54,0x54,0x54,0x18,
+    0x00,0x08,0x7e,0x09,0x02,
+    0x18,0xa4,0xa4,0x9c,0x78,
+    0x7f,0x08,0x04,0x04,0x78,
+    0x00,0x44,0x7d,0x40,0x00,
+    0x20,0x40,0x40,0x3d,0x00,
+    0x7f,0x10,0x28,0x44,0x00,
+    0x00,0x41,0x7f,0x40,0x00,
+    0x7c,0x04,0x78,0x04,0x78,
+    0x7c,0x08,0x04,0x04,0x78,
+    0x38,0x44,0x44,0x44,0x38,
+    0xfc,0x18,0x24,0x24,0x18,
+    0x18,0x24,0x24,0x18,0xfc,
+    0x7c,0x08,0x04,0x04,0x08,
+    0x48,0x54,0x54,0x54,0x24,
+    0x04,0x04,0x3f,0x44,0x24,
+    0x3c,0x40,0x40,0x20,0x7c,
+    0x1c,0x20,0x40,0x20,0x1c,
+    0x3c,0x40,0x30,0x40,0x3c,
+    0x44,0x28,0x10,0x28,0x44,
+    0x4c,0x90,0x90,0x90,0x7c,
+    0x44,0x64,0x54,0x4c,0x44,
+    0x00,0x08,0x36,0x41,0x00,
+    0x00,0x00,0x77,0x00,0x00,
+    0x00,0x41,0x36,0x08,0x00,
+    0x02,0x01,0x02,0x04,0x02,
+    0x3c,0x26,0x23,0x26,0x3c,
+    0x1e,0xa1,0xa1,0x61,0x12,
+    0x3a,0x40,0x40,0x20,0x7a,
+    0x38,0x54,0x54,0x55,0x59,
+    0x21,0x55,0x55,0x79,0x41,
+    0x21,0x54,0x54,0x78,0x41,
+    0x21,0x55,0x54,0x78,0x40,
+    0x20,0x54,0x55,0x79,0x40,
+    0x0c,0x1e,0x52,0x72,0x12,
+    0x39,0x55,0x55,0x55,0x59,
+    0x39,0x54,0x54,0x54,0x59,
+    0x39,0x55,0x54,0x54,0x58,
+    0x00,0x00,0x45,0x7c,0x41,
+    0x00,0x02,0x45,0x7d,0x42,
+    0x00,0x01,0x45,0x7c,0x40,
+    0xf0,0x29,0x24,0x29,0xf0,
+    0xf0,0x28,0x25,0x28,0xf0,
+    0x7c,0x54,0x55,0x45,0x00,
+    0x20,0x54,0x54,0x7c,0x54,
+    0x7c,0x0a,0x09,0x7f,0x49,
+    0x32,0x49,0x49,0x49,0x32,
+    0x32,0x48,0x48,0x48,0x32,
+    0x32,0x4a,0x48,0x48,0x30,
+    0x3a,0x41,0x41,0x21,0x7a,
+    0x3a,0x42,0x40,0x20,0x78,
+    0x00,0x9d,0xa0,0xa0,0x7d,
+    0x39,0x44,0x44,0x44,0x39,
+    0x3d,0x40,0x40,0x40,0x3d,
+    0x3c,0x24,0xff,0x24,0x24,
+    0x48,0x7e,0x49,0x43,0x66,
+    0x2b,0x2f,0xfc,0x2f,0x2b,
+    0xff,0x09,0x29,0xf6,0x20,
+    0xc0,0x88,0x7e,0x09,0x03,
+    0x20,0x54,0x54,0x79,0x41,
+    0x00,0x00,0x44,0x7d,0x41,
+    0x30,0x48,0x48,0x4a,0x32,
+    0x38,0x40,0x40,0x22,0x7a,
+    0x00,0x7a,0x0a,0x0a,0x72,
+    0x7d,0x0d,0x19,0x31,0x7d,
+    0x26,0x29,0x29,0x2f,0x28,
+    0x26,0x29,0x29,0x29,0x26,
+    0x30,0x48,0x4d,0x40,0x20,
+    0x38,0x08,0x08,0x08,0x08,
+    0x08,0x08,0x08,0x08,0x38,
+    0x2f,0x10,0xc8,0xac,0xba,
+    0x2f,0x10,0x28,0x34,0xfa,
+    0x00,0x00,0x7b,0x00,0x00,
+    0x08,0x14,0x2a,0x14,0x22,
+    0x22,0x14,0x2a,0x14,0x08,
+    0xaa,0x00,0x55,0x00,0xaa,
+    0xaa,0x55,0xaa,0x55,0xaa,
+    0x55,0xaa,0x55,0xaa,0x55,
+    0x00,0x00,0x00,0xff,0x00,
+    0x10,0x10,0x10,0xff,0x00,
+    0x14,0x14,0x14,0xff,0x00,
+    0x10,0x10,0xff,0x00,0xff,
+    0x10,0x10,0xf0,0x10,0xf0,
+    0x14,0x14,0x14,0xfc,0x00,
+    0x14,0x14,0xf7,0x00,0xff,
+    0x00,0x00,0xff,0x00,0xff,
+    0x14,0x14,0xf4,0x04,0xfc,
+    0x14,0x14,0x17,0x10,0x1f,
+    0x10,0x10,0x1f,0x10,0x1f,
+    0x14,0x14,0x14,0x1f,0x00,
+    0x10,0x10,0x10,0xf0,0x00,
+    0x00,0x00,0x00,0x1f,0x10,
+    0x10,0x10,0x10,0x1f,0x10,
+    0x10,0x10,0x10,0xf0,0x10,
+    0x00,0x00,0x00,0xff,0x10,
+    0x10,0x10,0x10,0x10,0x10,
+    0x10,0x10,0x10,0xff,0x10,
+    0x00,0x00,0x00,0xff,0x14,
+    0x00,0x00,0xff,0x00,0xff,
+    0x00,0x00,0x1f,0x10,0x17,
+    0x00,0x00,0xfc,0x04,0xf4,
+    0x14,0x14,0x17,0x10,0x17,
+    0x14,0x14,0xf4,0x04,0xf4,
+    0x00,0x00,0xff,0x00,0xf7,
+    0x14,0x14,0x14,0x14,0x14,
+    0x14,0x14,0xf7,0x00,0xf7,
+    0x14,0x14,0x14,0x17,0x14,
+    0x10,0x10,0x1f,0x10,0x1f,
+    0x14,0x14,0x14,0xf4,0x14,
+    0x10,0x10,0xf0,0x10,0xf0,
+    0x00,0x00,0x1f,0x10,0x1f,
+    0x00,0x00,0x00,0x1f,0x14,
+    0x00,0x00,0x00,0xfc,0x14,
+    0x00,0x00,0xf0,0x10,0xf0,
+    0x10,0x10,0xff,0x10,0xff,
+    0x14,0x14,0x14,0xff,0x14,
+    0x10,0x10,0x10,0x1f,0x00,
+    0x00,0x00,0x00,0xf0,0x10,
+    0xff,0xff,0xff,0xff,0xff,
+    0xf0,0xf0,0xf0,0xf0,0xf0,
+    0xff,0xff,0xff,0x00,0x00,
+    0x00,0x00,0x00,0xff,0xff,
+    0x0f,0x0f,0x0f,0x0f,0x0f,
+    0x38,0x44,0x44,0x38,0x44,
+    0x7c,0x2a,0x2a,0x3e,0x14,
+    0x7e,0x02,0x02,0x06,0x06,
+    0x02,0x7e,0x02,0x7e,0x02,
+    0x63,0x55,0x49,0x41,0x63,
+    0x38,0x44,0x44,0x3c,0x04,
+    0x40,0x7e,0x20,0x1e,0x20,
+    0x06,0x02,0x7e,0x02,0x02,
+    0x99,0xa5,0xe7,0xa5,0x99,
+    0x1c,0x2a,0x49,0x2a,0x1c,
+    0x4c,0x72,0x01,0x72,0x4c,
+    0x30,0x4a,0x4d,0x4d,0x30,
+    0x30,0x48,0x78,0x48,0x30,
+    0xbc,0x62,0x5a,0x46,0x3d,
+    0x3e,0x49,0x49,0x49,0x00,
+    0x7e,0x01,0x01,0x01,0x7e,
+    0x2a,0x2a,0x2a,0x2a,0x2a,
+    0x44,0x44,0x5f,0x44,0x44,
+    0x40,0x51,0x4a,0x44,0x40,
+    0x40,0x44,0x4a,0x51,0x40,
+    0x00,0x00,0xff,0x01,0x03,
+    0xe0,0x80,0xff,0x00,0x00,
+    0x08,0x08,0x6b,0x6b,0x08,
+    0x36,0x12,0x36,0x24,0x36,
+    0x06,0x0f,0x09,0x0f,0x06,
+    0x00,0x01,0x02,0x01,0x40,
+    0x00,0x00,0x10,0x10,0x00,
+    0x30,0x40,0xff,0x01,0x01,
+    0x00,0x1f,0x01,0x01,0x1e,
+    0x00,0x19,0x1d,0x17,0x12,
+    0x00,0x3c,0x3c,0x3c,0x3c
+};
+
+#define ST7920_CS()              {cs.set(1);wait_us(10);}
+#define ST7920_NCS()             {cs.set(0);wait_us(10);}
+#define ST7920_WRITE_BYTE(a)     {this->spi->write((a)&0xf0);this->spi->write((a)<<4);wait_us(10);}
+#define ST7920_WRITE_BYTES(p,l)  {uint8_t i;for(i=0;i<l;i++){this->spi->write(*p&0xf0);this->spi->write(*p<<4);p++;} wait_us(10); }
+#define ST7920_SET_CMD()         {this->spi->write(0xf8);wait_us(10);}
+#define ST7920_SET_DAT()         {this->spi->write(0xfa);wait_us(10);}
+#define PAGE_HEIGHT 32  //512 byte framebuffer
+#define WIDTH 128
+#define HEIGHT 64
+
+RrdGlcd::RrdGlcd(PinName mosi, PinName sclk, Pin cs) {
+    this->spi= new mbed::SPI(mosi, NC, sclk); 
+     //chip select
+    this->cs= cs;
+    this->cs.set(0);
+    inited= false;
+}
+
+RrdGlcd::~RrdGlcd() {
+    delete this->spi;
+}
+
+void RrdGlcd::setFrequency(int freq) {
+       this->spi->frequency(freq);
+}
+
+void RrdGlcd::initDisplay() {
+    // wait_ms(40); // wait 40ms
+    // writeInstruction(FUNCTION_SET | DATA_LENGTH_DL); // 8 bits interface, RE=0
+    // writeInstruction(DISPLAY_CONTROL | DISPLAY_ON_D ); // display on
+    // writeInstruction(DISPLAY_CLEAR); // clear display
+    // wait_ms(2); // wait 2ms for clear
+    // writeInstruction(ENTRY_MODE_SET | INCREASE_DECREASE_ID); // move cursor right
+    // writeInstruction(RETURN_HOME);
+    // setGraphicsMode();
+    // wait_ms(100);
+
+    ST7920_CS();
+    wait_ms(90);                 //initial delay for boot up
+    ST7920_SET_CMD();
+    ST7920_WRITE_BYTE(0x08);       //display off, cursor+blink off
+    ST7920_WRITE_BYTE(0x01);       //clear CGRAM ram
+    wait_ms(10);                 //delay for cgram clear
+    ST7920_WRITE_BYTE(0x3E);       //extended mode + gdram active
+    for(int y=0;y<HEIGHT/2;y++)        //clear GDRAM
+    {
+        ST7920_WRITE_BYTE(0x80|y);   //set y
+        ST7920_WRITE_BYTE(0x80);     //set x = 0
+        ST7920_SET_DAT();
+        for(int i=0;i<2*WIDTH/8;i++)     //2x width clears both segments
+            ST7920_WRITE_BYTE(0);
+        ST7920_SET_CMD();
+    }
+    ST7920_WRITE_BYTE(0x0C); //display on, cursor+blink off
+    ST7920_NCS();
+    wait_ms(100);
+    memset(fb, 0, sizeof(fb));
+    inited= true;
+}
+
+void RrdGlcd::clearScreen() {
+    memset(fb, 0, sizeof(fb));
+}
+
+// render into local screenbuffer
+void RrdGlcd::displayString(int row, int col, const char *ptr, int length) {
+    for (int i = 0; i < length; ++i) {
+        displayChar(row, col, ptr[i]);
+        col+=1;
+    }
+}
+
+static void renderChar(uint8_t *fb, char c, int ox, int oy) {
+    int i= c*5;
+    for(int y=0;y<8;y++) {
+      for(int x=0;x<5;x++) {
+        int b= font5x7[i+x];
+        if((b & (1<<(y))) != 0){
+            fb[(y+oy)*16 + (x+ox)/8] |= (1<<(8-(x+ox)%8-1));
+        }else{
+            fb[(y+oy)*16 + (x+ox)/8] &= ~(1<<(8-(x+ox)%8-1));
+        }
+      }
+    }
+}
+
+void RrdGlcd::displayChar(int row, int col, char c) {
+    renderChar(this->fb, c, col*6, row*8);
+}
+
+// static void draw(uint8_t *fb) {
+//   int ox= 0;
+//   int oy= 0;
+//   for(int c=' ';c<='z';c++) {
+//     int i= c*5;
+//     for(int y=0;y<8;y++) {
+//       for(int x=0;x<5;x++) {
+//         int b= font5x7[i+x];
+//         if((b & (1<<(y))) != 0){
+//             fb[(y+oy)*16 + (x+ox)/8] |= (1<<(8-(x+ox)%8-1));
+//         }
+//       }
+//     }
+//     ox += 6;
+//     if(ox >= 20*6){
+//       ox= 0;
+//       oy+=8;
+//     }
+//   }
+// }
+
+
+// static void draw(uint8_t *fb) {
+//     for (int i = 0; i < 1024; ++i) {
+//         *fb++ = 0x92;
+//     }
+// }
+
+void RrdGlcd::refresh() {
+    if(!inited) return;
+    fillGDRAM(this->fb);
+}
+   
+// Graphic functions
+void RrdGlcd::fillGDRAM(const uint8_t *bitmap) {
+    unsigned char i, y;
+    for ( i = 0 ; i < 2 ; i++ ) {
+        ST7920_CS();
+        for ( y = 0 ; y < PAGE_HEIGHT ; y++ ) {
+            ST7920_SET_CMD();
+            ST7920_WRITE_BYTE(0x80 | y);
+            if ( i == 0 ) {
+                ST7920_WRITE_BYTE(0x80);
+            } else {
+                ST7920_WRITE_BYTE(0x80 | 0x08);
+            }
+            ST7920_SET_DAT();
+            ST7920_WRITE_BYTES(bitmap, WIDTH/8);
+        }
+        ST7920_NCS();
+    }
+}
+
+// void RrdGlcd::fillGDRAM_Turned(unsigned char *bitmap) {
+//     int i, j, k, m, offset_row, mask ;
+//     unsigned char data;
+
+//     for ( i = 0 ; i < 2 ; i++ ) { //upper and lower page
+//         for ( j = 0 ; j < 32 ; j++ ) { //32 lines per page
+//             writeInstruction(SET_GRAPHIC_RAM_ADDRESS | j) ;
+//             if ( i == 0 ) {
+//                 writeInstruction(SET_GRAPHIC_RAM_ADDRESS) ;
+//             } else {
+//                 writeInstruction(SET_GRAPHIC_RAM_ADDRESS | 0x08) ;
+//             }
+//             mask=1<<(j%8); // extract bitnumber
+//             //printf("mask: %d\r\n",mask);
+//             for ( k = 0 ; k < 16 ; k++ ) { //16 bytes per line
+//                 offset_row=((i*32+j)/8)*128 + k*8; //y coordinate/8 = row 0-7 * 128 = byte offset, read 8 bytes
+//                 data=0;
+//                 for (m = 0 ; m < 8 ; m++) { // read 8 bytes from source
+
+//                     if ((bitmap[offset_row+m] & mask)) { //pixel = 1
+//                         data|=(128>>m);
+//                     }
+//                 }
+//                 writeRAM(data) ;
+//             }
+//         }
+//     }
+// }
dissimilarity index 68%
index 1f11a61..7757fd9 100644 (file)
-#ifndef __RRDGLCD_H
-#define __RRDGLCD_H
-
-/*  
-      This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
-      Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
-      Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-      You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. 
-*/
-
-/**
- * Based on st7920.h from http://mbed.org/users/Bas/code/ST7920/
- * Original License: Unknown
- * Modified from original to use SPI instead of parallel by Jim Morris
- * Removed all read commands as SPI does not support read
- */
-
-#define VERSION 1.0
-
-#include <mbed.h>
-#include "libs/Kernel.h"
-#include "libs/utils.h"
-#include <libs/Pin.h>
-
-// Instruction Set 1: (RE=0: Basic Instruction)
-#define DISPLAY_CLEAR           0x01 // Fill DDRAM with "20H" and set DDRAM address counter (AC) to "00H"
-#define RETURN_HOME             0x02 // Set DDRAM address counter (AC) to "00H", and put cursor
-// to origin &#65533;Gthe content of DDRAM are not changed
-#define ENTRY_MODE_SET          0x04 // Set cursor position and display shift when doing write or read
-// operation
-#define DISPLAY_CONTROL         0x08 // D=1: Display ON, C=1: Cursor ON, B=1: Character Blink ON
-#define CURSOR_DISPLAY_CONTROL  0x10 // Cursor position and display shift control; the content of
-// DDRAM are not changed
-#define FUNCTION_SET            0x20 // DL=1 8-bit interface, DL=0 4-bit interface
-// RE=1: extended instruction, RE=0: basic instruction
-#define SET_CGRAM_ADDRESS       0x40 // Set CGRAM address to address counter (AC)
-// Make sure that in extended instruction SR=0
-#define SET_DDRAM_ADDRESS       0x80 // Set DDRAM address to address counter (AC)
-// AC6 is fixed to 0
-
-// Instruction set 2: (RE=1: extended instruction)
-#define STANDBY                 0x01 // Enter standby mode, any other instruction can terminate.
-// COM1&#65533;c32 are halted
-#define SCROLL_OR_RAM_ADDR_SEL  0x02 // SR=1: enable vertical scroll position
-// SR=0: enable CGRAM address (basic instruction)
-#define REVERSE_BY_LINE         0x04 // Select 1 out of 4 line (in DDRAM) and decide whether to
-// reverse the display by toggling this instruction
-// R1,R0 initial value is 0,0
-#define EXTENDED_FUNCTION_SET   0x20 // DL=1 :8-bit interface, DL=0 :4-bit interface
-// RE=1: extended instruction, RE=0: basic instruction
-#define SET_SCROLL_ADDRESS      0x40 // G=1 :graphic display ON, G=0 :graphic display OFF
-#define SET_GRAPHIC_RAM_ADDRESS 0x80 // Set GDRAM address to address counter (AC)
-// Set the vertical address first and followed the horizontal
-// address by consecutive writings
-// Vertical address range: AC5&#65533;cAC0, Horizontal address range: AC3&#65533;cAC0
-
-// Parameters regarding Instruction Sets 1 & 2
-#define DISPLAY_SHIFT_S         0x01 // Set 1, ENTRY_MODE_SET
-#define INCREASE_DECREASE_ID    0x02 // Set 1, ENTRY_MODE_SET
-#define CURSOR_BLINK_ON_B       0x01 // Set 1, DISPLAY_CONTROL
-#define CURSOR_ON_C             0x02 // Set 1, DISPLAY_CONTROL
-#define DISPLAY_ON_D            0x04 // Set 1, DISPLAY_CONTROL
-#define SHIFT_RL                0x04 // Set 1, CURSOR_DISPLAY_CONTROL
-#define CURSOR_SC               0x08 // Set 1, CURSOR_DISPLAY_CONTROL
-#define EXTENDED_INSTRUCTION_RE 0x04 // Set 1, FUNCTION_SET; Set 2, EXTENDED_FUNTION_SET
-#define DATA_LENGTH_DL          0x10 // Set 1, FUNCTION_SET; Set 2, EXTENDED_FUNTION_SET
-#define REVERSE_BY_LINE_R0      0x01 // Set 2, REVERSE_BY_LINE
-#define REVERSE_BY_LINE_R1      0x02 // Set 2, REVERSE_BY_LINE
-#define EN_VERTICAL_SCROLL_SR   0x01 // Set 2, SCROLL_OR_RAM_ADDR_SEL
-#define GRAPHIC_ON_G            0x02 // Set 2, EXTENDED_FUNTION_SET
-
-/*********************************************************************************/
-
-class RrdGlcd {
-public:
-    /**
-    *@brief Constructor, initializes the lcd on the respective pins.
-    *@param mosi mbed pinname for mosi
-    *@param sclk mbed name for sclk
-    *@param cd Smoothie Pin for cs
-    *@return none
-    *@  ----> pin PSB @ Gnd for Serial/SPI bus mode.
-    */
-    RrdGlcd (PinName mosi, PinName sclk, Pin cs);
-    virtual ~RrdGlcd();
-
-    void setFrequency(int f);
-
-    /**
-     *@brief Display initialization
-     *
-     *@param none
-     *@return none
-     *
-     */
-    void initDisplay(void);
-
-
-    /**
-     *@brief Enable Extended Instructions, RE=1, Graphic on
-     *
-     *@param none
-     *@return none
-     *
-     */
-    void setGraphicsMode(void);
-    
-    /**
-     *@brief Go back to Basic Instructions, RE=0
-     *
-     *@param none
-     *@return none
-     *
-     */
-    void setTextMode(void);
-
-    /**
-    *@brief Sets DDRAM address counter (AC) to '00H'
-    *@basic function, clear screen
-    *@param none
-    *@return none
-    *
-    */
-    void clearScreen(void);
-    
-    void returnHome(void);
-    void standby(void);
-
-    /**
-    *@brief Places a string on the screen with internal characters from the HCGROM
-    *@
-    *@param row, column, string
-    *@return none
-    *
-    */
-    void displayString(int Row,int Column, const char *ptr,int length);
-
-    /**
-    *@brief Places a character on the screen with an internal character from the HCGROM
-    *@
-    *@param row, column, character
-    *@return none
-    *
-    */    
-    void displayChar(int Row, int Column,int inpChr);
-    
-     /**
-    *@brief Fills the screen with the graphics described in a 1024-byte array
-    *@
-    *@param bitmap 128x64, bytes horizontal
-    *@return none
-    *
-    */
-    void fillGDRAM(unsigned char *bitmap);
-    
-    //same as FILLGDRAM, but turnes all the bytes from vertical to horizontal
-    //now pictures for eg KS0108 can be used
-    void fillGDRAM_Turned(unsigned char *bitmap);
-    
-    /**
-    *@brief Clears the graphics RAM of the screen
-    *@writes all pixels to zero
-    *@param none
-    *@return none
-    *
-    */
-    void clearGDRAM(void);
-    
-private:
-    Pin cs;
-    mbed::SPI* spi;
-
-    /**
-    *@brief Write instruction to the controller.
-    *@param Command     command to send to the controller
-    *@return none
-    *
-    */
-    void  writeInstruction(unsigned int command);
-
-    /**
-     *@brief Write data byte to the controller.
-     *@param data     data send to the controller chip (DDRAM/CGRAM/GDRAM)
-     *@return none
-     *
-     */
-    void writeRAM(unsigned int data);
-
-};
-#endif
-
+#ifndef __RRDGLCD_H
+#define __RRDGLCD_H
+
+/*  
+      This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
+      Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+      Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+      You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. 
+*/
+
+/**
+ * Based loosely on st7920.h from http://mbed.org/users/Bas/code/ST7920 and parts of the Arduino U8glib library.
+ * Written by Jim Morris
+ */
+
+#include <mbed.h>
+#include "libs/Kernel.h"
+#include "libs/utils.h"
+#include <libs/Pin.h>
+
+
+class RrdGlcd {
+public:
+    /**
+    *@brief Constructor, initializes the lcd on the respective pins.
+    *@param mosi mbed pinname for mosi
+    *@param sclk mbed name for sclk
+    *@param cd Smoothie Pin for cs
+    *@return none
+    *@  ----> pin PSB @ Gnd for Serial/SPI bus mode.
+    */
+    RrdGlcd (PinName mosi, PinName sclk, Pin cs);
+
+    virtual ~RrdGlcd();
+
+    void setFrequency(int f);
+
+    /**
+     *@brief Display initialization
+     *
+     *@param none
+     *@return none
+     *
+     */
+    void initDisplay(void);
+
+    void clearScreen(void);
+
+    /**
+    *@brief Places a string on the screen with internal characters from the HCGROM
+    *@
+    *@param row, column, string
+    *@return none
+    *
+    */
+    void displayString(int Row,int Column, const char *ptr,int length);
+
+    /**
+    *@brief Places a character on the screen with an internal character from the HCGROM
+    *@
+    *@param row, column, character
+    *@return none
+    *
+    */    
+    void displayChar(int Row, int Column,char inpChr);
+    void refresh();
+
+     /**
+    *@brief Fills the screen with the graphics described in a 1024-byte array
+    *@
+    *@param bitmap 128x64, bytes horizontal
+    *@return none
+    *
+    */
+    void fillGDRAM(const uint8_t *bitmap);
+    
+private:
+    Pin cs;
+    mbed::SPI* spi;
+    uint8_t fb[1024];
+    bool inited;
+};
+#endif
+