Fork of LCD-Window which works with Enhanced TextLCD from Wim

Fork of LcdWindow by Hendrik Lipka

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dogm_spi.cpp Source File

dogm_spi.cpp

00001 /*
00002  * mbed LCDWindow library
00003 * Copyright (c) 2010 Hendrik Lipka
00004 * 
00005 * Permission is hereby granted, free of charge, to any person obtaining a copy
00006 * of this software and associated documentation files (the "Software"), to deal
00007 * in the Software without restriction, including without limitation the rights
00008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 * copies of the Software, and to permit persons to whom the Software is
00010 * furnished to do so, subject to the following conditions:
00011 * 
00012 * The above copyright notice and this permission notice shall be included in
00013 * all copies or substantial portions of the Software.
00014 * 
00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 * THE SOFTWARE.
00022 */
00023 
00024 #include "dogm_spi.h"
00025 
00026 #include "SPI.h"
00027 #include "DigitalOut.h"
00028 #include "wait_api.h"
00029 
00030 DogmLCDSPI::DogmLCDSPI 
00031 (unsigned int columns, unsigned int rows, SPI *spi, PinName enable, PinName rs)
00032 :SPILCDBase(columns,rows,spi,enable,rs)
00033 {
00034 }
00035 
00036 void DogmLCDSPI::init()
00037 {
00038     unsigned char initCmd[10]={0x38,0x39,0x14,0x55,0x6d,0x78,0x38,0x0c,0x01,0x06};
00039     
00040     _enable->write(1);
00041     wait_ms(80);
00042     
00043     for (int i=0;i<sizeof(initCmd);i++)
00044     {
00045         sendCmd(initCmd[i]);
00046         wait_ms(4);
00047     }
00048 }
00049 
00050 void DogmLCDSPI::character(int column, int row, int c)
00051 {
00052     int address=(row)*0x40+(column);
00053     if (!_guard->take())
00054         return;
00055     sendCmd((char)address|0x80);
00056     wait_ms(1);
00057     sendData(c);
00058     _guard->release();
00059     wait_ms(1);
00060 }
00061 
00062 void DogmLCDSPI::writeText(const unsigned int column, const unsigned int row, const char text[])
00063 {
00064     int address=(row)*0x40+(column);
00065     if (!_guard->take())
00066         return;
00067     sendCmd((char)address|0x80);
00068     wait_ms(1);
00069     
00070     int i=0;
00071     while(text[i]!=0)
00072     {
00073         sendData(text[i]);
00074         wait_ms(1);
00075         i++;
00076     }
00077     _guard->release();
00078 }
00079 
00080 void DogmLCDSPI::clear()
00081 {
00082     if (!_guard->take())
00083         return;
00084     sendCmd(1);
00085     _guard->release();
00086 }
00087