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

Committer:
modtronix
Date:
Fri Aug 07 18:27:11 2015 +1000
Revision:
2:fe0c1e27f362
Parent:
1:429b7d3f7b95
Improvements

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 2:fe0c1e27f362 24
modtronix 1:429b7d3f7b95 25 // DEFINES ////////////////////////////////////////////////////////////////////
modtronix 1:429b7d3f7b95 26
modtronix 1:429b7d3f7b95 27
modtronix 1:429b7d3f7b95 28 // GLOBAL VARIABLES ///////////////////////////////////////////////////////////
modtronix 1:429b7d3f7b95 29 #if (LCD2S_USE_MALLOC == 0)
modtronix 1:429b7d3f7b95 30 uint8_t buf[80];
modtronix 1:429b7d3f7b95 31 uint32_t dirtyRows[4];
modtronix 1:429b7d3f7b95 32 #endif
modtronix 1:429b7d3f7b95 33
modtronix 1:429b7d3f7b95 34 // Function Prototypes ////////////////////////////////////////////////////////
modtronix 1:429b7d3f7b95 35
modtronix 1:429b7d3f7b95 36
modtronix 2:fe0c1e27f362 37 // DEBUG ////////////////////////////////////////////////////////////////////
modtronix 2:fe0c1e27f362 38 //IMPORTANT, when enabling debugging, it is very important to note the following:
modtronix 2:fe0c1e27f362 39 //- If (MX_DEBUG_IS_POINTER==1), ensure there is global Stream pointer defined somewhere in code to override "pMxDebug = NULL" below!
modtronix 2:fe0c1e27f362 40 //- If (MX_DEBUG_IS_POINTER==0), define a mxDebug() function somewhere in code to handel debug output
modtronix 2:fe0c1e27f362 41 #define DEBUG_ENABLE 1
modtronix 2:fe0c1e27f362 42 #if (DEBUG_ENABLE==1) && !defined(NDEBUG)
modtronix 2:fe0c1e27f362 43 //Alternative method in stead of using NULL below. This requires to create derived Stream class in each file we want to use debugging
modtronix 2:fe0c1e27f362 44 // class modtronixDebugStream : public Stream {int _putc(int value) {return 0;}int _getc() {return 0;}};
modtronix 2:fe0c1e27f362 45 // static modtronixDebugStream modtronixDebug;
modtronix 2:fe0c1e27f362 46 // WEAK Stream* pMxDebug = &modtronixDebug;
modtronix 2:fe0c1e27f362 47 #if (MX_DEBUG_IS_POINTER==1) //More efficient, but only works if pMxDebug is defined in code. Disabled by default!
modtronix 2:fe0c1e27f362 48 WEAK Stream* pMxDebug = NULL;
modtronix 2:fe0c1e27f362 49 #define MX_DEBUG pMxDebug->printf
modtronix 2:fe0c1e27f362 50 #else
modtronix 2:fe0c1e27f362 51 WEAK void mxDebug(const char *format, ...) {}
modtronix 2:fe0c1e27f362 52 #define MX_DEBUG mxDebug
modtronix 2:fe0c1e27f362 53 #endif
modtronix 2:fe0c1e27f362 54 #else
modtronix 2:fe0c1e27f362 55 //GCC's CPP has extensions; it allows for macros with a variable number of arguments. We use this extension here to preprocess pmesg away.
modtronix 2:fe0c1e27f362 56 #define MX_DEBUG(format, args...) ((void)0)
modtronix 2:fe0c1e27f362 57 #endif
modtronix 2:fe0c1e27f362 58
modtronix 2:fe0c1e27f362 59
modtronix 2:fe0c1e27f362 60
modtronix 1:429b7d3f7b95 61 LCD2S::LCD2S(uint8_t rows/* = 4*/, uint8_t columns/* = 20*/) {
modtronix 1:429b7d3f7b95 62 contrast = 200;
modtronix 1:429b7d3f7b95 63 brightness = 200;
modtronix 1:429b7d3f7b95 64 this->rows = rows;
modtronix 1:429b7d3f7b95 65 this->columns = columns;
modtronix 1:429b7d3f7b95 66 bufSize = rows * columns;
modtronix 1:429b7d3f7b95 67 cursor_row = cursor_col = 0;
modtronix 1:429b7d3f7b95 68
modtronix 2:fe0c1e27f362 69 //MX_DEBUG("\r\nLCD2S()");
modtronix 2:fe0c1e27f362 70
modtronix 1:429b7d3f7b95 71 #if (LCD2S_USE_MALLOC == 1)
modtronix 1:429b7d3f7b95 72 buf = new uint8_t[bufSize)];
modtronix 1:429b7d3f7b95 73 dirtyRows = new uint32_t(rows);
modtronix 1:429b7d3f7b95 74 #endif
modtronix 1:429b7d3f7b95 75
modtronix 1:429b7d3f7b95 76 pBuf = buf;
modtronix 1:429b7d3f7b95 77 pDirtyRows = dirtyRows;
modtronix 1:429b7d3f7b95 78 memset(pBuf, ' ', sizeof(buf));
modtronix 1:429b7d3f7b95 79 memset(pDirtyRows, 0, 4 * rows);
modtronix 1:429b7d3f7b95 80 }
modtronix 1:429b7d3f7b95 81
modtronix 1:429b7d3f7b95 82 void LCD2S::clearDisplay() {
modtronix 1:429b7d3f7b95 83 memset(pBuf, ' ', sizeof(buf));
modtronix 1:429b7d3f7b95 84 memset(pDirtyRows, 0xff, 4 * rows);
modtronix 1:429b7d3f7b95 85 }
modtronix 1:429b7d3f7b95 86
modtronix 1:429b7d3f7b95 87 void LCD2S::setCursor(int8_t row, int8_t col) {
modtronix 1:429b7d3f7b95 88 cursor_row = row-1;
modtronix 1:429b7d3f7b95 89 if(cursor_row > rows)
modtronix 1:429b7d3f7b95 90 cursor_row = rows-1;
modtronix 1:429b7d3f7b95 91
modtronix 1:429b7d3f7b95 92 cursor_col = col-1;
modtronix 1:429b7d3f7b95 93 if(cursor_col > columns)
modtronix 1:429b7d3f7b95 94 cursor_col = columns-1;
modtronix 1:429b7d3f7b95 95 };
modtronix 1:429b7d3f7b95 96