Suga koubou / PCF2119

Dependents:   barometer-m0 PCF2119_hello

Fork of TextLCD by Simon Ford

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PCF2119.h Source File

PCF2119.h

00001 /* PCF2119x based I2C LCD Library
00002  * Copyright (c) 2014, Hiroshi Suga
00003  */
00004 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780
00005  * Copyright (c) 2007-2010, sford, http://mbed.org
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a copy
00008  * of this software and associated documentation files (the "Software"), to deal
00009  * in the Software without restriction, including without limitation the rights
00010  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011  * copies of the Software, and to permit persons to whom the Software is
00012  * furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included in
00015  * all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00022  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00023  * THE SOFTWARE.
00024  */
00025 
00026 #ifndef __PCF2119_H__
00027 #define __PCF2119_H__
00028 
00029 #include "mbed.h"
00030 
00031 /**  A PCF2119 interface for driving I2C PCF2119x-based LCDs
00032  *
00033  * Currently supports 16x2, 20x2 and 20x4 panels
00034  *
00035  * @code
00036  * #include "mbed.h"
00037  * #include "PCF2119.h"
00038  * 
00039  * TextLCD lcd(p10, p12, p15, p30); // sda, sck, reset
00040  * 
00041  * int main() {
00042  *     lcd.printf("Hello World!\n");
00043  * }
00044  * @endcode
00045  */
00046 class PCF2119 : public Stream {
00047 public:
00048 
00049     /** LCD panel format */
00050     enum LCDType {
00051         LCD16x2     /**< 16x2 LCD panel (default) */
00052         , LCD16x2B  /**< 16x2 LCD panel alternate addressing */
00053         , LCD20x2   /**< 20x2 LCD panel */
00054         , LCD20x4   /**< 20x4 LCD panel */
00055     };
00056 
00057     /** Create a TextLCD interface
00058      *
00059      * @param sda   I2C data line pin
00060      * @param sck   I2C clock line pin
00061      * @param reset Reset pin
00062      * @param type  Sets the panel size/addressing mode (default = LCD16x2)
00063      * @param addr  I2C address (default = 0x74)
00064      */
00065     PCF2119(PinName sda, PinName sck, PinName reset, LCDType type = LCD16x2, char addr = 0x74);
00066 
00067     /** Create a TextLCD interface
00068      *
00069      * @param i2c   I2C class
00070      * @param reset Reset pin
00071      * @param type  Sets the panel size/addressing mode (default = LCD16x2)
00072      * @param addr  I2C address (default = 0x74)
00073      */
00074     PCF2119(I2C &i2c, PinName reset, LCDType type = LCD16x2, char addr = 0x74);
00075 
00076 #if DOXYGEN_ONLY
00077     /** Write a character to the LCD
00078      *
00079      * @param c The character to write to the display
00080      */
00081     int putc(int c);
00082 
00083     /** Write a formated string to the LCD
00084      *
00085      * @param format A printf-style format string, followed by the
00086      *               variables to use in formating the string.
00087      */
00088     int printf(const char* format, ...);
00089 #endif
00090 
00091     /** Locate to a screen column and row
00092      *
00093      * @param column  The horizontal position from the left, indexed from 0
00094      * @param row     The vertical position from the top, indexed from 0
00095      */
00096     void locate(int column, int row);
00097 
00098     /** Clear the screen and locate to 0,0 */
00099     void cls();
00100 
00101     int rows();
00102     int columns();
00103 
00104     void cgram(int num, const char *data, int len);
00105 
00106     int raw;
00107 
00108 protected:
00109 
00110     // Stream implementation functions
00111     virtual int _putc(int value);
00112     virtual int _getc();
00113 
00114     void init ();
00115     int address(int column, int row);
00116     void character(int column, int row, int c);
00117     void writeCommand(int command);
00118     void writeData(int data);
00119     int ascii2lcd (int c);
00120 
00121     I2C _i2c;
00122     DigitalOut _reset;
00123     LCDType _type;
00124 
00125     int _column;
00126     int _row;
00127     int _addr;
00128 };
00129 
00130 #endif