Driver for Text OLED display - 20x4 Winstar or Newhaven, with Winstar WS0010 driver IC

Committer:
RodColeman
Date:
Mon Jan 21 11:26:17 2013 +0000
Revision:
3:d955c3213b6a
Parent:
2:c7834290ea1c
added return value for out-of-range column address.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RodColeman 2:c7834290ea1c 1 /* mbed TextOLED20x4 Library, for a 4-bit LCD based on HD44780
RodColeman 2:c7834290ea1c 2 * copyleft Rod Coleman 2012
RodColeman 0:4d453b617559 3 * Copyright (c) 2007-2010, sford, http://mbed.org
RodColeman 0:4d453b617559 4 *
RodColeman 0:4d453b617559 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
RodColeman 0:4d453b617559 6 * of this software and associated documentation files (the "Software"), to deal
RodColeman 0:4d453b617559 7 * in the Software without restriction, including without limitation the rights
RodColeman 0:4d453b617559 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
RodColeman 0:4d453b617559 9 * copies of the Software, and to permit persons to whom the Software is
RodColeman 0:4d453b617559 10 * furnished to do so, subject to the following conditions:
RodColeman 0:4d453b617559 11 *
RodColeman 0:4d453b617559 12 * The above copyright notice and this permission notice shall be included in
RodColeman 0:4d453b617559 13 * all copies or substantial portions of the Software.
RodColeman 0:4d453b617559 14 *
RodColeman 0:4d453b617559 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
RodColeman 0:4d453b617559 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
RodColeman 0:4d453b617559 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
RodColeman 0:4d453b617559 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
RodColeman 0:4d453b617559 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
RodColeman 0:4d453b617559 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
RodColeman 0:4d453b617559 21 * THE SOFTWARE.
RodColeman 0:4d453b617559 22 */
RodColeman 0:4d453b617559 23
RodColeman 2:c7834290ea1c 24 #ifndef MBED_TextOLED20x4_H
RodColeman 2:c7834290ea1c 25 #define MBED_TextOLED20x4_H
RodColeman 2:c7834290ea1c 26
RodColeman 2:c7834290ea1c 27
RodColeman 0:4d453b617559 28
RodColeman 0:4d453b617559 29 #include "mbed.h"
RodColeman 0:4d453b617559 30
RodColeman 2:c7834290ea1c 31 /** A TextOLED20x4 interface for driving 4-bit HD44780-based LCDs
RodColeman 0:4d453b617559 32 *
RodColeman 0:4d453b617559 33 * Currently supports 16x2, 20x2 and 20x4 panels
RodColeman 0:4d453b617559 34 *
RodColeman 0:4d453b617559 35 * @code
RodColeman 0:4d453b617559 36 * #include "mbed.h"
RodColeman 2:c7834290ea1c 37 * #include "TextOLED20x4.h"
RodColeman 0:4d453b617559 38 *
RodColeman 2:c7834290ea1c 39 * TextOLED20x4 lcd(p10, p12, p15, p16, p29, p30); // rs, e, d4-d7
RodColeman 0:4d453b617559 40 *
RodColeman 0:4d453b617559 41 * int main() {
RodColeman 0:4d453b617559 42 * lcd.printf("Hello World!\n");
RodColeman 0:4d453b617559 43 * }
RodColeman 0:4d453b617559 44 * @endcode
RodColeman 0:4d453b617559 45 */
RodColeman 2:c7834290ea1c 46 class TextOLED20x4 : public Stream {
RodColeman 0:4d453b617559 47 public:
RodColeman 0:4d453b617559 48
RodColeman 0:4d453b617559 49 /** LCD panel format */
RodColeman 0:4d453b617559 50 enum LCDType {
RodColeman 0:4d453b617559 51 LCD16x2 /**< 16x2 LCD panel (default) */
RodColeman 0:4d453b617559 52 , LCD16x2B /**< 16x2 LCD panel alternate addressing */
RodColeman 0:4d453b617559 53 , LCD20x2 /**< 20x2 LCD panel */
RodColeman 0:4d453b617559 54 , LCD20x4 /**< 20x4 LCD panel */
RodColeman 0:4d453b617559 55 };
RodColeman 0:4d453b617559 56
RodColeman 2:c7834290ea1c 57 /** Create a TextOLED20x4 interface
RodColeman 0:4d453b617559 58 *
RodColeman 0:4d453b617559 59 * @param rs Instruction/data control line
RodColeman 0:4d453b617559 60 * @param e Enable line (clock)
RodColeman 0:4d453b617559 61 * @param d4-d7 Data lines for using as a 4-bit interface
RodColeman 0:4d453b617559 62 * @param type Sets the panel size/addressing mode (default = LCD16x2)
RodColeman 0:4d453b617559 63 */
RodColeman 2:c7834290ea1c 64 TextOLED20x4(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2);
RodColeman 0:4d453b617559 65
RodColeman 0:4d453b617559 66 #if DOXYGEN_ONLY
RodColeman 0:4d453b617559 67 /** Write a character to the LCD
RodColeman 0:4d453b617559 68 *
RodColeman 0:4d453b617559 69 * @param c The character to write to the display
RodColeman 0:4d453b617559 70 */
RodColeman 0:4d453b617559 71 int putc(int c);
RodColeman 0:4d453b617559 72
RodColeman 0:4d453b617559 73 /** Write a formated string to the LCD
RodColeman 0:4d453b617559 74 *
RodColeman 0:4d453b617559 75 * @param format A printf-style format string, followed by the
RodColeman 0:4d453b617559 76 * variables to use in formating the string.
RodColeman 0:4d453b617559 77 */
RodColeman 0:4d453b617559 78 int printf(const char* format, ...);
RodColeman 0:4d453b617559 79 #endif
RodColeman 0:4d453b617559 80
RodColeman 0:4d453b617559 81 /** Locate to a screen column and row
RodColeman 0:4d453b617559 82 *
RodColeman 0:4d453b617559 83 * @param column The horizontal position from the left, indexed from 0
RodColeman 0:4d453b617559 84 * @param row The vertical position from the top, indexed from 0
RodColeman 0:4d453b617559 85 */
RodColeman 0:4d453b617559 86 void locate(int column, int row);
RodColeman 0:4d453b617559 87
RodColeman 0:4d453b617559 88 /** Clear the screen and locate to 0,0 */
RodColeman 0:4d453b617559 89 void cls();
RodColeman 0:4d453b617559 90
RodColeman 0:4d453b617559 91 int rows();
RodColeman 0:4d453b617559 92 int columns();
RodColeman 0:4d453b617559 93
RodColeman 0:4d453b617559 94 protected:
RodColeman 0:4d453b617559 95
RodColeman 0:4d453b617559 96 // Stream implementation functions
RodColeman 0:4d453b617559 97 virtual int _putc(int value);
RodColeman 0:4d453b617559 98 virtual int _getc();
RodColeman 0:4d453b617559 99
RodColeman 0:4d453b617559 100 int address(int column, int row);
RodColeman 0:4d453b617559 101 void character(int column, int row, int c);
RodColeman 0:4d453b617559 102 void writeByte(int value);
RodColeman 0:4d453b617559 103 void writeCommand(int command);
RodColeman 0:4d453b617559 104 void writeData(int data);
RodColeman 0:4d453b617559 105
RodColeman 0:4d453b617559 106 DigitalOut _rs, _e;
RodColeman 0:4d453b617559 107 BusOut _d;
RodColeman 0:4d453b617559 108 LCDType _type;
RodColeman 0:4d453b617559 109
RodColeman 0:4d453b617559 110 int _column;
RodColeman 0:4d453b617559 111 int _row;
RodColeman 0:4d453b617559 112 };
RodColeman 0:4d453b617559 113
RodColeman 0:4d453b617559 114 #endif