An example of GT20L16J1Y (15x16 Japanese Kanji ROM) and C12823 LCD

Dependencies:   C12832_lcd mbed

Fork of app-board-LCD by Chris Styles

Committer:
dreschpe
Date:
Mon Oct 15 21:48:28 2012 +0000
Revision:
0:f6a57b843f79
first test of the lcd driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 0:f6a57b843f79 1 /* mbed TextDisplay Display Library Base Class
dreschpe 0:f6a57b843f79 2 * Copyright (c) 2007-2009 sford
dreschpe 0:f6a57b843f79 3 * Released under the MIT License: http://mbed.org/license/mit
dreschpe 0:f6a57b843f79 4 */
dreschpe 0:f6a57b843f79 5
dreschpe 0:f6a57b843f79 6 #include "TextDisplay.h"
dreschpe 0:f6a57b843f79 7
dreschpe 0:f6a57b843f79 8 TextDisplay::TextDisplay(const char *name) : Stream(name){
dreschpe 0:f6a57b843f79 9 _row = 0;
dreschpe 0:f6a57b843f79 10 _column = 0;
dreschpe 0:f6a57b843f79 11 if (name == NULL) {
dreschpe 0:f6a57b843f79 12 _path = NULL;
dreschpe 0:f6a57b843f79 13 } else {
dreschpe 0:f6a57b843f79 14 _path = new char[strlen(name) + 2];
dreschpe 0:f6a57b843f79 15 sprintf(_path, "/%s", name);
dreschpe 0:f6a57b843f79 16 }
dreschpe 0:f6a57b843f79 17 }
dreschpe 0:f6a57b843f79 18
dreschpe 0:f6a57b843f79 19 int TextDisplay::_putc(int value) {
dreschpe 0:f6a57b843f79 20 if(value == '\n') {
dreschpe 0:f6a57b843f79 21 _column = 0;
dreschpe 0:f6a57b843f79 22 _row++;
dreschpe 0:f6a57b843f79 23 if(_row >= rows()) {
dreschpe 0:f6a57b843f79 24 _row = 0;
dreschpe 0:f6a57b843f79 25 }
dreschpe 0:f6a57b843f79 26 } else {
dreschpe 0:f6a57b843f79 27 character(_column, _row, value);
dreschpe 0:f6a57b843f79 28 _column++;
dreschpe 0:f6a57b843f79 29 if(_column >= columns()) {
dreschpe 0:f6a57b843f79 30 _column = 0;
dreschpe 0:f6a57b843f79 31 _row++;
dreschpe 0:f6a57b843f79 32 if(_row >= rows()) {
dreschpe 0:f6a57b843f79 33 _row = 0;
dreschpe 0:f6a57b843f79 34 }
dreschpe 0:f6a57b843f79 35 }
dreschpe 0:f6a57b843f79 36 }
dreschpe 0:f6a57b843f79 37 return value;
dreschpe 0:f6a57b843f79 38 }
dreschpe 0:f6a57b843f79 39
dreschpe 0:f6a57b843f79 40 // crude cls implementation, should generally be overwritten in derived class
dreschpe 0:f6a57b843f79 41 void TextDisplay::cls() {
dreschpe 0:f6a57b843f79 42 locate(0, 0);
dreschpe 0:f6a57b843f79 43 for(int i=0; i<columns()*rows(); i++) {
dreschpe 0:f6a57b843f79 44 putc(' ');
dreschpe 0:f6a57b843f79 45 }
dreschpe 0:f6a57b843f79 46 }
dreschpe 0:f6a57b843f79 47
dreschpe 0:f6a57b843f79 48 void TextDisplay::locate(int column, int row) {
dreschpe 0:f6a57b843f79 49 _column = column;
dreschpe 0:f6a57b843f79 50 _row = row;
dreschpe 0:f6a57b843f79 51 }
dreschpe 0:f6a57b843f79 52
dreschpe 0:f6a57b843f79 53 int TextDisplay::_getc() {
dreschpe 0:f6a57b843f79 54 return -1;
dreschpe 0:f6a57b843f79 55 }
dreschpe 0:f6a57b843f79 56
dreschpe 0:f6a57b843f79 57 void TextDisplay::foreground(uint16_t colour) {
dreschpe 0:f6a57b843f79 58 _foreground = colour;
dreschpe 0:f6a57b843f79 59 }
dreschpe 0:f6a57b843f79 60
dreschpe 0:f6a57b843f79 61 void TextDisplay::background(uint16_t colour) {
dreschpe 0:f6a57b843f79 62 _background = colour;
dreschpe 0:f6a57b843f79 63 }
dreschpe 0:f6a57b843f79 64
dreschpe 0:f6a57b843f79 65 bool TextDisplay::claim (FILE *stream) {
dreschpe 0:f6a57b843f79 66 if ( _path == NULL) {
dreschpe 0:f6a57b843f79 67 fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n");
dreschpe 0:f6a57b843f79 68 return false;
dreschpe 0:f6a57b843f79 69 }
dreschpe 0:f6a57b843f79 70 if (freopen(_path, "w", stream) == NULL) {
dreschpe 0:f6a57b843f79 71 // Failed, should not happen
dreschpe 0:f6a57b843f79 72 return false;
dreschpe 0:f6a57b843f79 73 }
dreschpe 0:f6a57b843f79 74 // make sure we use line buffering
dreschpe 0:f6a57b843f79 75 setvbuf(stdout, NULL, _IOLBF, columns());
dreschpe 0:f6a57b843f79 76 return true;
dreschpe 0:f6a57b843f79 77 }