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

lcd2s.cpp

Committer:
modtronix
Date:
2015-08-04
Revision:
1:429b7d3f7b95
Parent:
0:cea36bae632b
Child:
2:fe0c1e27f362

File content as of revision 1:429b7d3f7b95:

/**
 * File:      lcd2s.cpp
 * 
 * Author:    Modtronix Engineering - www.modtronix.com
 * 
 * Description:
 * 
 * Software License Agreement:
 * This software has been written or modified by Modtronix Engineering. The code
 * may be modified and can be used free of charge for commercial and non commercial
 * applications. If this is modified software, any license conditions from original
 * software also apply. Any redistribution must include reference to 'Modtronix
 * Engineering' and web link(www.modtronix.com) in the file header. 
 * 
 * THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS,
 * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE
 * COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 */ 
#include "mbed.h"
#include "lcd2s.h"

// DEFINES ////////////////////////////////////////////////////////////////////


// GLOBAL VARIABLES ///////////////////////////////////////////////////////////
#if (LCD2S_USE_MALLOC == 0)
uint8_t buf[80];
uint32_t dirtyRows[4];
#endif

// Function Prototypes ////////////////////////////////////////////////////////


LCD2S::LCD2S(uint8_t rows/* = 4*/, uint8_t columns/* = 20*/) {
    contrast = 200;
    brightness = 200;
    this->rows = rows;
    this->columns = columns;
    bufSize = rows * columns;
    cursor_row = cursor_col = 0;

#if (LCD2S_USE_MALLOC == 1)
    buf = new uint8_t[bufSize)];
    dirtyRows = new uint32_t(rows);
#endif

    pBuf = buf;
    pDirtyRows = dirtyRows;
    memset(pBuf, ' ', sizeof(buf));
    memset(pDirtyRows, 0, 4 * rows);
}

void LCD2S::clearDisplay() {
    memset(pBuf, ' ', sizeof(buf));
    memset(pDirtyRows, 0xff, 4 * rows);
}

void LCD2S::setCursor(int8_t row, int8_t col) {
    cursor_row = row-1;
    if(cursor_row > rows)
        cursor_row = rows-1;

    cursor_col = col-1;
    if(cursor_col > columns)
        cursor_col = columns-1;
};