Fork of Silabs MemoryLCD library

Dependents:   demoUI whrmDemoUI Host_Software_MAX32664GWEB_HR_EXTENDED Host_Software_MAX32664GWEC_SpO2_HR-_EXTE ... more

C++ library for Sharp Microelectronics 1.28 inch LCD TFT, LS013B7DH03, SPI bus. Forked from Silicon Labs MemoryLCD display driver.

Committer:
stevew817
Date:
Wed Aug 12 14:06:07 2015 +0000
Revision:
11:0f8ae10b308d
Parent:
4:b02dfd360729
Child:
12:ca0bcb4777e9
Implement Paul Staron's enhancements to the display driver classes, from https://developer.mbed.org/users/star297/code/MemoryLCD/rev/b64f87859c57

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Steven Cooreman 0:a0faa86660d4 1 /* mbed TextDisplay Display Library Base Class
Steven Cooreman 0:a0faa86660d4 2 * Copyright (c) 2007-2009 sford
Steven Cooreman 0:a0faa86660d4 3 * Released under the MIT License: http://mbed.org/license/mit
Steven Cooreman 0:a0faa86660d4 4 */
Steven Cooreman 0:a0faa86660d4 5
Steven Cooreman 0:a0faa86660d4 6 #include "TextDisplay.h"
Steven Cooreman 0:a0faa86660d4 7 #include <cstdarg>
Steven Cooreman 0:a0faa86660d4 8
Steven Cooreman 0:a0faa86660d4 9 TextDisplay::TextDisplay(const char *name){
Steven Cooreman 0:a0faa86660d4 10 _row = 0;
Steven Cooreman 0:a0faa86660d4 11 _column = 0;
Steven Cooreman 0:a0faa86660d4 12
Steven Cooreman 0:a0faa86660d4 13 if (name == NULL) {
Steven Cooreman 0:a0faa86660d4 14 _path = NULL;
Steven Cooreman 0:a0faa86660d4 15 } else {
Steven Cooreman 0:a0faa86660d4 16 _path = new char[strlen(name) + 2];
Steven Cooreman 0:a0faa86660d4 17 sprintf(_path, "/%s", name);
Steven Cooreman 0:a0faa86660d4 18 }
Steven Cooreman 0:a0faa86660d4 19 }
Steven Cooreman 0:a0faa86660d4 20
Steven Cooreman 0:a0faa86660d4 21 int TextDisplay::_putc(int value) {
Steven Cooreman 0:a0faa86660d4 22 if(value == '\n') {
Steven Cooreman 0:a0faa86660d4 23 _column = 0;
Steven Cooreman 0:a0faa86660d4 24 _row++;
Steven Cooreman 0:a0faa86660d4 25 if(_row >= rows()) {
Steven Cooreman 0:a0faa86660d4 26 _row = 0;
Steven Cooreman 0:a0faa86660d4 27 }
Steven Cooreman 0:a0faa86660d4 28 } else {
Steven Cooreman 0:a0faa86660d4 29 character(_column, _row, value);
Steven Cooreman 0:a0faa86660d4 30 _column++;
Steven Cooreman 0:a0faa86660d4 31 if(_column >= columns()) {
Steven Cooreman 0:a0faa86660d4 32 _column = 0;
Steven Cooreman 0:a0faa86660d4 33 _row++;
Steven Cooreman 0:a0faa86660d4 34 if(_row >= rows()) {
Steven Cooreman 0:a0faa86660d4 35 _row = 0;
Steven Cooreman 0:a0faa86660d4 36 }
Steven Cooreman 0:a0faa86660d4 37 }
Steven Cooreman 0:a0faa86660d4 38 }
Steven Cooreman 0:a0faa86660d4 39 return value;
Steven Cooreman 0:a0faa86660d4 40 }
Steven Cooreman 0:a0faa86660d4 41
Steven Cooreman 0:a0faa86660d4 42 // crude cls implementation, should generally be overwritten in derived class
Steven Cooreman 0:a0faa86660d4 43 void TextDisplay::cls() {
Steven Cooreman 0:a0faa86660d4 44 locate(0, 0);
Steven Cooreman 0:a0faa86660d4 45 for(int i=0; i<columns()*rows(); i++) {
Steven Cooreman 0:a0faa86660d4 46 _putc(' ');
Steven Cooreman 0:a0faa86660d4 47 }
Steven Cooreman 0:a0faa86660d4 48 }
Steven Cooreman 0:a0faa86660d4 49
stevew817 11:0f8ae10b308d 50 void TextDisplay::set_font(const unsigned char * f) {
stevew817 11:0f8ae10b308d 51 font = f;
stevew817 11:0f8ae10b308d 52 if(font==NULL) {
stevew817 11:0f8ae10b308d 53 externalfont = 0; // set display.font
stevew817 11:0f8ae10b308d 54 locate(0, 0);
stevew817 11:0f8ae10b308d 55 }
stevew817 11:0f8ae10b308d 56 else{
stevew817 11:0f8ae10b308d 57 externalfont = 1;
stevew817 11:0f8ae10b308d 58 locate(0, 0);
stevew817 11:0f8ae10b308d 59 }
stevew817 11:0f8ae10b308d 60 }
stevew817 11:0f8ae10b308d 61
Steven Cooreman 0:a0faa86660d4 62 void TextDisplay::locate(int column, int row) {
Steven Cooreman 0:a0faa86660d4 63 _column = column;
Steven Cooreman 0:a0faa86660d4 64 _row = row;
stevew817 11:0f8ae10b308d 65 char_x = column;
stevew817 11:0f8ae10b308d 66 char_y = row;
Steven Cooreman 0:a0faa86660d4 67 }
Steven Cooreman 0:a0faa86660d4 68
Steven Cooreman 0:a0faa86660d4 69 int TextDisplay::_getc() {
Steven Cooreman 0:a0faa86660d4 70 return -1;
Steven Cooreman 0:a0faa86660d4 71 }
Steven Cooreman 0:a0faa86660d4 72
Steven Cooreman 0:a0faa86660d4 73 void TextDisplay::foreground(uint16_t colour) {
Steven Cooreman 0:a0faa86660d4 74 _foreground = colour;
Steven Cooreman 0:a0faa86660d4 75 }
Steven Cooreman 0:a0faa86660d4 76
Steven Cooreman 0:a0faa86660d4 77 void TextDisplay::background(uint16_t colour) {
Steven Cooreman 0:a0faa86660d4 78 _background = colour;
Steven Cooreman 0:a0faa86660d4 79 }
Steven Cooreman 0:a0faa86660d4 80
Steven Cooreman 0:a0faa86660d4 81 void TextDisplay::printf(const char* format, ...) {
Steven Cooreman 0:a0faa86660d4 82 char buffer[MAX_PRINTF_CHARS + 1] = { 0 };
Steven Cooreman 0:a0faa86660d4 83 uint32_t iterator = 0;
Steven Cooreman 0:a0faa86660d4 84 va_list args;
Steven Cooreman 0:a0faa86660d4 85 va_start(args, format);
Steven Cooreman 0:a0faa86660d4 86 vsprintf(buffer, format, args);
Steven Cooreman 0:a0faa86660d4 87 va_end(args);
Steven Cooreman 0:a0faa86660d4 88
Steven Cooreman 0:a0faa86660d4 89 while((buffer[iterator] != 0) && (iterator < MAX_PRINTF_CHARS)) {
Steven Cooreman 0:a0faa86660d4 90 _putc(buffer[iterator++]);
Steven Cooreman 0:a0faa86660d4 91 }
Steven Cooreman 0:a0faa86660d4 92 }