An interface to the Sparkfun Serial Graphic LCD, LCD-09351; and Graphic LCD Serial Backpack, LCD-09352. Derived class from Serial so that you can conveniently send text to the display with printf(), putc(), etc.

Dependents:   DataBus2018

Committer:
shimniok
Date:
Wed Apr 11 07:13:52 2012 +0000
Revision:
3:dff460658aed
Parent:
2:84b78506add6
Updated to support both stock SFE firmware and summoningdark firmware

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 2:84b78506add6 1 #include "SerialGraphicLCD.h"
shimniok 2:84b78506add6 2
shimniok 2:84b78506add6 3 #define XSIZE 6
shimniok 2:84b78506add6 4 #define YSIZE 9
shimniok 2:84b78506add6 5
shimniok 2:84b78506add6 6 SerialGraphicLCD::SerialGraphicLCD(PinName tx, PinName rx):
shimniok 3:dff460658aed 7 Serial(tx, rx), _firmware(SFE_FW)
shimniok 3:dff460658aed 8 {
shimniok 3:dff460658aed 9 baud(115200); // default baud rate
shimniok 3:dff460658aed 10 resolution(LCD_128x64); // default resolution
shimniok 3:dff460658aed 11 }
shimniok 3:dff460658aed 12
shimniok 3:dff460658aed 13 SerialGraphicLCD::SerialGraphicLCD(PinName tx, PinName rx, int firmware):
shimniok 3:dff460658aed 14 Serial(tx, rx), _firmware(firmware)
shimniok 2:84b78506add6 15 {
shimniok 2:84b78506add6 16 baud(115200); // default baud rate
shimniok 2:84b78506add6 17 resolution(LCD_128x64); // default resolution
shimniok 2:84b78506add6 18 }
shimniok 2:84b78506add6 19
shimniok 2:84b78506add6 20 void SerialGraphicLCD::clear() {
shimniok 2:84b78506add6 21 putc(0x7c);
shimniok 2:84b78506add6 22 putc(0x00);
shimniok 2:84b78506add6 23 }
shimniok 2:84b78506add6 24
shimniok 2:84b78506add6 25 void SerialGraphicLCD::pos(int col, int row) {
shimniok 3:dff460658aed 26 if (_firmware == SD_FW)
shimniok 3:dff460658aed 27 posXY(XSIZE*col, (YSIZE*row));
shimniok 3:dff460658aed 28 else if (_firmware == SFE_FW)
shimniok 3:dff460658aed 29 posXY(XSIZE*col, _yMax-(YSIZE*row)-1);
shimniok 2:84b78506add6 30 }
shimniok 2:84b78506add6 31
shimniok 2:84b78506add6 32 void SerialGraphicLCD::posXY(int x, int y) {
shimniok 2:84b78506add6 33 putc(0x7c);
shimniok 2:84b78506add6 34 putc(0x18);
shimniok 2:84b78506add6 35 putc(x);
shimniok 2:84b78506add6 36 putc(0x7c);
shimniok 2:84b78506add6 37 putc(0x19);
shimniok 2:84b78506add6 38 putc(y);
shimniok 2:84b78506add6 39 }
shimniok 2:84b78506add6 40
shimniok 2:84b78506add6 41 void SerialGraphicLCD::pixel(int x, int y, bool set) {
shimniok 2:84b78506add6 42 putc(0x7c);
shimniok 2:84b78506add6 43 putc(0x10);
shimniok 2:84b78506add6 44 putc(x);
shimniok 2:84b78506add6 45 putc(y);
shimniok 2:84b78506add6 46 putc((set) ? 0x01 : 0x00);
shimniok 2:84b78506add6 47 }
shimniok 2:84b78506add6 48
shimniok 2:84b78506add6 49 void SerialGraphicLCD::line(int x1, int y1, int x2, int y2, bool set) {
shimniok 2:84b78506add6 50 putc(0x7c);
shimniok 2:84b78506add6 51 putc(0x0c);
shimniok 2:84b78506add6 52 putc(x1);
shimniok 2:84b78506add6 53 putc(y1);
shimniok 2:84b78506add6 54 putc(x2);
shimniok 2:84b78506add6 55 putc(y2);
shimniok 2:84b78506add6 56 putc((set) ? 0x01 : 0x00);
shimniok 2:84b78506add6 57 }
shimniok 2:84b78506add6 58
shimniok 2:84b78506add6 59 void SerialGraphicLCD::circle(int x, int y, int r, bool set) {
shimniok 2:84b78506add6 60 putc(0x7c);
shimniok 2:84b78506add6 61 putc(0x03);
shimniok 2:84b78506add6 62 putc(x);
shimniok 2:84b78506add6 63 putc(y);
shimniok 2:84b78506add6 64 putc(r);
shimniok 2:84b78506add6 65 putc((set) ? 0x01 : 0x00);
shimniok 2:84b78506add6 66 }
shimniok 2:84b78506add6 67
shimniok 2:84b78506add6 68 // Unfortunately, the datasheet is incorrect; the box command
shimniok 2:84b78506add6 69 // does not take a 5th parameter for draw/erase like the others
shimniok 2:84b78506add6 70 void SerialGraphicLCD::rect(int x1, int y1, int x2, int y2) {
shimniok 2:84b78506add6 71 putc(0x7c);
shimniok 2:84b78506add6 72 putc(0x0f);
shimniok 2:84b78506add6 73 putc(x1);
shimniok 2:84b78506add6 74 putc(y1);
shimniok 2:84b78506add6 75 putc(x2);
shimniok 2:84b78506add6 76 putc(y2);
shimniok 2:84b78506add6 77 }
shimniok 2:84b78506add6 78
shimniok 2:84b78506add6 79 void SerialGraphicLCD::erase(int x1, int y1, int x2, int y2) {
shimniok 2:84b78506add6 80 putc(0x7c);
shimniok 2:84b78506add6 81 putc(0x05);
shimniok 2:84b78506add6 82 putc(x1);
shimniok 2:84b78506add6 83 putc(y1);
shimniok 2:84b78506add6 84 putc(x2);
shimniok 2:84b78506add6 85 putc(y2);
shimniok 2:84b78506add6 86 }
shimniok 2:84b78506add6 87
shimniok 2:84b78506add6 88 void SerialGraphicLCD::backlight(int i) {
shimniok 2:84b78506add6 89 if (i >= 0 && i <= 100) {
shimniok 2:84b78506add6 90 putc(0x7c);
shimniok 2:84b78506add6 91 putc(0x02);
shimniok 2:84b78506add6 92 putc(i);
shimniok 2:84b78506add6 93 }
shimniok 2:84b78506add6 94 }
shimniok 2:84b78506add6 95
shimniok 2:84b78506add6 96 void SerialGraphicLCD::reverseMode() {
shimniok 2:84b78506add6 97 putc(0x7c);
shimniok 2:84b78506add6 98 putc(0x12);
shimniok 2:84b78506add6 99 }
shimniok 2:84b78506add6 100
shimniok 2:84b78506add6 101 void SerialGraphicLCD::resolution(int type) {
shimniok 2:84b78506add6 102 switch (type) {
shimniok 2:84b78506add6 103 case LCD_128x64 :
shimniok 2:84b78506add6 104 resolution(128, 64);
shimniok 2:84b78506add6 105 break;
shimniok 2:84b78506add6 106 case LCD_160x128 :
shimniok 2:84b78506add6 107 resolution(160, 128);
shimniok 2:84b78506add6 108 break;
shimniok 2:84b78506add6 109 }
shimniok 2:84b78506add6 110 }
shimniok 2:84b78506add6 111
shimniok 2:84b78506add6 112 void SerialGraphicLCD::resolution(int x, int y) {
shimniok 2:84b78506add6 113 _xMax = x;
shimniok 2:84b78506add6 114 _yMax = y;
shimniok 2:84b78506add6 115 }
shimniok 2:84b78506add6 116
shimniok 2:84b78506add6 117
shimniok 2:84b78506add6 118 void SerialGraphicLCD::lcdbaud(int b) {
shimniok 2:84b78506add6 119 if (b > 0 && b < 7) {
shimniok 2:84b78506add6 120 putc(0x7c);
shimniok 2:84b78506add6 121 putc(0x07);
shimniok 2:84b78506add6 122 putc(b+'0');
shimniok 2:84b78506add6 123 }
shimniok 2:84b78506add6 124 }