Initial version for Modtronix LCD2S I2C and SPI serial LCD displays. For details, see http://modtronix.com/products-serial-lcd-board/

Committer:
modtronix
Date:
Tue Aug 04 18:54:37 2015 +1000
Revision:
1:429b7d3f7b95
Parent:
0:cea36bae632b
Child:
2:fe0c1e27f362
Added functionality

Who changed what in which revision?

UserRevisionLine numberNew contents of line
modtronix 1:429b7d3f7b95 1 /**
modtronix 1:429b7d3f7b95 2 * File: lcd2s.cpp
modtronix 1:429b7d3f7b95 3 *
modtronix 1:429b7d3f7b95 4 * Author: Modtronix Engineering - www.modtronix.com
modtronix 1:429b7d3f7b95 5 *
modtronix 1:429b7d3f7b95 6 * Description:
modtronix 1:429b7d3f7b95 7 *
modtronix 1:429b7d3f7b95 8 * Software License Agreement:
modtronix 1:429b7d3f7b95 9 * This software has been written or modified by Modtronix Engineering. The code
modtronix 1:429b7d3f7b95 10 * may be modified and can be used free of charge for commercial and non commercial
modtronix 1:429b7d3f7b95 11 * applications. If this is modified software, any license conditions from original
modtronix 1:429b7d3f7b95 12 * software also apply. Any redistribution must include reference to 'Modtronix
modtronix 1:429b7d3f7b95 13 * Engineering' and web link(www.modtronix.com) in the file header.
modtronix 1:429b7d3f7b95 14 *
modtronix 1:429b7d3f7b95 15 * THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS,
modtronix 1:429b7d3f7b95 16 * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
modtronix 1:429b7d3f7b95 17 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE
modtronix 1:429b7d3f7b95 18 * COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
modtronix 1:429b7d3f7b95 19 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
modtronix 1:429b7d3f7b95 20 */
modtronix 1:429b7d3f7b95 21 #include "mbed.h"
modtronix 1:429b7d3f7b95 22 #include "lcd2s.h"
modtronix 1:429b7d3f7b95 23
modtronix 1:429b7d3f7b95 24 // DEFINES ////////////////////////////////////////////////////////////////////
modtronix 1:429b7d3f7b95 25
modtronix 1:429b7d3f7b95 26
modtronix 1:429b7d3f7b95 27 // GLOBAL VARIABLES ///////////////////////////////////////////////////////////
modtronix 1:429b7d3f7b95 28 #if (LCD2S_USE_MALLOC == 0)
modtronix 1:429b7d3f7b95 29 uint8_t buf[80];
modtronix 1:429b7d3f7b95 30 uint32_t dirtyRows[4];
modtronix 1:429b7d3f7b95 31 #endif
modtronix 1:429b7d3f7b95 32
modtronix 1:429b7d3f7b95 33 // Function Prototypes ////////////////////////////////////////////////////////
modtronix 1:429b7d3f7b95 34
modtronix 1:429b7d3f7b95 35
modtronix 1:429b7d3f7b95 36 LCD2S::LCD2S(uint8_t rows/* = 4*/, uint8_t columns/* = 20*/) {
modtronix 1:429b7d3f7b95 37 contrast = 200;
modtronix 1:429b7d3f7b95 38 brightness = 200;
modtronix 1:429b7d3f7b95 39 this->rows = rows;
modtronix 1:429b7d3f7b95 40 this->columns = columns;
modtronix 1:429b7d3f7b95 41 bufSize = rows * columns;
modtronix 1:429b7d3f7b95 42 cursor_row = cursor_col = 0;
modtronix 1:429b7d3f7b95 43
modtronix 1:429b7d3f7b95 44 #if (LCD2S_USE_MALLOC == 1)
modtronix 1:429b7d3f7b95 45 buf = new uint8_t[bufSize)];
modtronix 1:429b7d3f7b95 46 dirtyRows = new uint32_t(rows);
modtronix 1:429b7d3f7b95 47 #endif
modtronix 1:429b7d3f7b95 48
modtronix 1:429b7d3f7b95 49 pBuf = buf;
modtronix 1:429b7d3f7b95 50 pDirtyRows = dirtyRows;
modtronix 1:429b7d3f7b95 51 memset(pBuf, ' ', sizeof(buf));
modtronix 1:429b7d3f7b95 52 memset(pDirtyRows, 0, 4 * rows);
modtronix 1:429b7d3f7b95 53 }
modtronix 1:429b7d3f7b95 54
modtronix 1:429b7d3f7b95 55 void LCD2S::clearDisplay() {
modtronix 1:429b7d3f7b95 56 memset(pBuf, ' ', sizeof(buf));
modtronix 1:429b7d3f7b95 57 memset(pDirtyRows, 0xff, 4 * rows);
modtronix 1:429b7d3f7b95 58 }
modtronix 1:429b7d3f7b95 59
modtronix 1:429b7d3f7b95 60 void LCD2S::setCursor(int8_t row, int8_t col) {
modtronix 1:429b7d3f7b95 61 cursor_row = row-1;
modtronix 1:429b7d3f7b95 62 if(cursor_row > rows)
modtronix 1:429b7d3f7b95 63 cursor_row = rows-1;
modtronix 1:429b7d3f7b95 64
modtronix 1:429b7d3f7b95 65 cursor_col = col-1;
modtronix 1:429b7d3f7b95 66 if(cursor_col > columns)
modtronix 1:429b7d3f7b95 67 cursor_col = columns-1;
modtronix 1:429b7d3f7b95 68 };
modtronix 1:429b7d3f7b95 69