Display text on LCD displays (even on multiple ones). Allow to create windows (frames) on display, and to combine them (split, add, duplicate, scroll). See http://mbed.org/users/hlipka/notebook/lcdwindow/ for more information.

Dependents:   Mbell

Committer:
hlipka
Date:
Tue Feb 22 22:57:44 2011 +0000
Revision:
9:2fe93daa2106
Parent:
2:5ac5bab7daaf
fixed semaphore handling - should now be really thread safe (can be called from interrupts)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hlipka 0:ae5037e3d6e0 1 /*
hlipka 0:ae5037e3d6e0 2 * mbed LCDWindow library
hlipka 0:ae5037e3d6e0 3 * Copyright (c) 2010 Hendrik Lipka
hlipka 0:ae5037e3d6e0 4 *
hlipka 0:ae5037e3d6e0 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
hlipka 0:ae5037e3d6e0 6 * of this software and associated documentation files (the "Software"), to deal
hlipka 0:ae5037e3d6e0 7 * in the Software without restriction, including without limitation the rights
hlipka 0:ae5037e3d6e0 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
hlipka 0:ae5037e3d6e0 9 * copies of the Software, and to permit persons to whom the Software is
hlipka 0:ae5037e3d6e0 10 * furnished to do so, subject to the following conditions:
hlipka 0:ae5037e3d6e0 11 *
hlipka 0:ae5037e3d6e0 12 * The above copyright notice and this permission notice shall be included in
hlipka 0:ae5037e3d6e0 13 * all copies or substantial portions of the Software.
hlipka 0:ae5037e3d6e0 14 *
hlipka 0:ae5037e3d6e0 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
hlipka 0:ae5037e3d6e0 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
hlipka 0:ae5037e3d6e0 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
hlipka 0:ae5037e3d6e0 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
hlipka 0:ae5037e3d6e0 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
hlipka 0:ae5037e3d6e0 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
hlipka 0:ae5037e3d6e0 21 * THE SOFTWARE.
hlipka 0:ae5037e3d6e0 22 */
hlipka 0:ae5037e3d6e0 23
hlipka 0:ae5037e3d6e0 24 #include "lcd_spi.h"
hlipka 0:ae5037e3d6e0 25
hlipka 0:ae5037e3d6e0 26 #include "SPI.h"
hlipka 0:ae5037e3d6e0 27 #include "DigitalOut.h"
hlipka 0:ae5037e3d6e0 28 #include "wait_api.h"
hlipka 0:ae5037e3d6e0 29
hlipka 0:ae5037e3d6e0 30 SPILCDBase::SPILCDBase
hlipka 2:5ac5bab7daaf 31 (unsigned int columns, unsigned int rows, SPI *spi, PinName enable, PinName rs)
hlipka 2:5ac5bab7daaf 32 :TextLCDBase(columns,rows)
hlipka 0:ae5037e3d6e0 33 {
hlipka 0:ae5037e3d6e0 34 _spi=spi;
hlipka 0:ae5037e3d6e0 35 _enable=new DigitalOut(enable);
hlipka 0:ae5037e3d6e0 36 _rs=new DigitalOut(rs);
hlipka 0:ae5037e3d6e0 37 _enable->write(1);
hlipka 0:ae5037e3d6e0 38 _spi->format(8,3); // 8 bits, cpol=1, cpha=1 (should be mode 2, but phase seems inverted)
hlipka 0:ae5037e3d6e0 39 // set SPI frequency at 0.1 MHz
hlipka 0:ae5037e3d6e0 40 _spi->frequency(100000);
hlipka 0:ae5037e3d6e0 41 }
hlipka 0:ae5037e3d6e0 42
hlipka 1:65f72ed914fa 43 void SPILCDBase::sendByte(const unsigned char byte)
hlipka 0:ae5037e3d6e0 44 {
hlipka 0:ae5037e3d6e0 45 _enable->write(0); // enable transfer
hlipka 0:ae5037e3d6e0 46 wait_us(1);
hlipka 0:ae5037e3d6e0 47 _spi->write(byte); // send byte over wire
hlipka 0:ae5037e3d6e0 48 wait_us(20);
hlipka 0:ae5037e3d6e0 49 _enable->write(1);
hlipka 0:ae5037e3d6e0 50 }
hlipka 0:ae5037e3d6e0 51
hlipka 1:65f72ed914fa 52 void SPILCDBase::sendCmd(const unsigned char cmd)
hlipka 0:ae5037e3d6e0 53 {
hlipka 0:ae5037e3d6e0 54 _rs->write(0);
hlipka 0:ae5037e3d6e0 55 wait_us(1);
hlipka 0:ae5037e3d6e0 56 sendByte(cmd);
hlipka 0:ae5037e3d6e0 57 wait_us(1);
hlipka 0:ae5037e3d6e0 58 _rs->write(1);
hlipka 0:ae5037e3d6e0 59 }
hlipka 0:ae5037e3d6e0 60
hlipka 1:65f72ed914fa 61 void SPILCDBase::sendData(const unsigned char cmd)
hlipka 0:ae5037e3d6e0 62 {
hlipka 0:ae5037e3d6e0 63 _rs->write(1);
hlipka 0:ae5037e3d6e0 64 wait_us(1);
hlipka 0:ae5037e3d6e0 65 sendByte(cmd);
hlipka 0:ae5037e3d6e0 66 }