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