Text console library for ST7032 text LCD controller over I2C interface.

Committer:
kayekss
Date:
Mon Apr 06 20:16:13 2015 +0000
Revision:
0:db0ffd858ca1
Initial release.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kayekss 0:db0ffd858ca1 1 // ==================================================== Mar 18 2015, kayeks ==
kayekss 0:db0ffd858ca1 2 // TextLCD_ST7032I2C.h
kayekss 0:db0ffd858ca1 3 // ===========================================================================
kayekss 0:db0ffd858ca1 4 // Text console library for ST7032 text LCD controller over I2C interface.
kayekss 0:db0ffd858ca1 5
kayekss 0:db0ffd858ca1 6 #ifndef TEXTLCD_ST7032I2C_H_
kayekss 0:db0ffd858ca1 7 #define TEXTLCD_ST7032I2C_H_
kayekss 0:db0ffd858ca1 8
kayekss 0:db0ffd858ca1 9 #include "mbed.h"
kayekss 0:db0ffd858ca1 10
kayekss 0:db0ffd858ca1 11 #define MIN(x, y) ((x) < (y) ? (x) : (y))
kayekss 0:db0ffd858ca1 12
kayekss 0:db0ffd858ca1 13 /** Text console library for ST7032 text LCD controller over I2C interface. */
kayekss 0:db0ffd858ca1 14 class TextLCD_ST7032I2C : public Stream {
kayekss 0:db0ffd858ca1 15 public:
kayekss 0:db0ffd858ca1 16 /** Bias select: 1/4 or 1/5. */
kayekss 0:db0ffd858ca1 17 enum Bias {
kayekss 0:db0ffd858ca1 18 Bias1_4 /** 1/4 bias */
kayekss 0:db0ffd858ca1 19 , Bias1_5 /** 1/5 bias */
kayekss 0:db0ffd858ca1 20 };
kayekss 0:db0ffd858ca1 21
kayekss 0:db0ffd858ca1 22 const static uint8_t CLEAR_DISPLAY = 0x01;
kayekss 0:db0ffd858ca1 23 const static uint8_t RETURN_HOME = 0x02;
kayekss 0:db0ffd858ca1 24 const static uint8_t ENTRY_MODE_DECR_NO_SHIFT = 0x04;
kayekss 0:db0ffd858ca1 25 const static uint8_t ENTRY_MODE_DECR_SHIFT = 0x05;
kayekss 0:db0ffd858ca1 26 const static uint8_t ENTRY_MODE_INCR_NO_SHIFT = 0x06;
kayekss 0:db0ffd858ca1 27 const static uint8_t ENTRY_MODE_INCR_SHIFT = 0x07;
kayekss 0:db0ffd858ca1 28 const static uint8_t DISPLAY_OFF_CURSOR_OFF_POS_OFF = 0x08;
kayekss 0:db0ffd858ca1 29 const static uint8_t DISPLAY_OFF_CURSOR_OFF_POS_ON = 0x09;
kayekss 0:db0ffd858ca1 30 const static uint8_t DISPLAY_OFF_CURSOR_ON_POS_OFF = 0x0a;
kayekss 0:db0ffd858ca1 31 const static uint8_t DISPLAY_OFF_CURSOR_ON_POS_ON = 0x0b;
kayekss 0:db0ffd858ca1 32 const static uint8_t DISPLAY_ON_CURSOR_OFF_POS_OFF = 0x0c;
kayekss 0:db0ffd858ca1 33 const static uint8_t DISPLAY_ON_CURSOR_OFF_POS_ON = 0x0d;
kayekss 0:db0ffd858ca1 34 const static uint8_t DISPLAY_ON_CURSOR_ON_POS_OFF = 0x0e;
kayekss 0:db0ffd858ca1 35 const static uint8_t DISPLAY_ON_CURSOR_ON_POS_ON = 0x0f;
kayekss 0:db0ffd858ca1 36 const static uint8_t FUNCTION_4B_1LINE_7DOT_IS0 = 0x20;
kayekss 0:db0ffd858ca1 37 const static uint8_t FUNCTION_4B_1LINE_7DOT_IS1 = 0x21;
kayekss 0:db0ffd858ca1 38 const static uint8_t FUNCTION_4B_1LINE_11DOT_IS0 = 0x24;
kayekss 0:db0ffd858ca1 39 const static uint8_t FUNCTION_4B_1LINE_11DOT_IS1 = 0x25;
kayekss 0:db0ffd858ca1 40 const static uint8_t FUNCTION_4B_2LINE_7DOT_IS0 = 0x28;
kayekss 0:db0ffd858ca1 41 const static uint8_t FUNCTION_4B_2LINE_7DOT_IS1 = 0x29;
kayekss 0:db0ffd858ca1 42 const static uint8_t FUNCTION_4B_2LINE_11DOT_IS0 = 0x2c;
kayekss 0:db0ffd858ca1 43 const static uint8_t FUNCTION_4B_2LINE_11DOT_IS1 = 0x2d;
kayekss 0:db0ffd858ca1 44 const static uint8_t FUNCTION_8B_1LINE_7DOT_IS0 = 0x30;
kayekss 0:db0ffd858ca1 45 const static uint8_t FUNCTION_8B_1LINE_7DOT_IS1 = 0x31;
kayekss 0:db0ffd858ca1 46 const static uint8_t FUNCTION_8B_1LINE_11DOT_IS0 = 0x34;
kayekss 0:db0ffd858ca1 47 const static uint8_t FUNCTION_8B_1LINE_11DOT_IS1 = 0x35;
kayekss 0:db0ffd858ca1 48 const static uint8_t FUNCTION_8B_2LINE_7DOT_IS0 = 0x38;
kayekss 0:db0ffd858ca1 49 const static uint8_t FUNCTION_8B_2LINE_7DOT_IS1 = 0x39;
kayekss 0:db0ffd858ca1 50 const static uint8_t FUNCTION_8B_2LINE_11DOT_IS0 = 0x3c;
kayekss 0:db0ffd858ca1 51 const static uint8_t FUNCTION_8B_2LINE_11DOT_IS1 = 0x3d;
kayekss 0:db0ffd858ca1 52 const static uint8_t DDRAM = 0x80;
kayekss 0:db0ffd858ca1 53 const static uint8_t IS0_LEFT_MOVE = 0x10;
kayekss 0:db0ffd858ca1 54 const static uint8_t IS0_LEFT_SHIFT = 0x14;
kayekss 0:db0ffd858ca1 55 const static uint8_t IS0_RIGHT_MOVE = 0x18;
kayekss 0:db0ffd858ca1 56 const static uint8_t IS0_RIGHT_SHIFT = 0x1c;
kayekss 0:db0ffd858ca1 57 const static uint8_t IS0_CGRAM = 0x40;
kayekss 0:db0ffd858ca1 58 const static uint8_t IS1_BIAS5_OSC = 0x10;
kayekss 0:db0ffd858ca1 59 const static uint8_t IS1_BIAS4_OSC = 0x18;
kayekss 0:db0ffd858ca1 60 const static uint8_t IS1_ICON_ADDR = 0x40;
kayekss 0:db0ffd858ca1 61 const static uint8_t IS1_ICON_OFF_BOOST_OFF_CONTRAST = 0x50;
kayekss 0:db0ffd858ca1 62 const static uint8_t IS1_ICON_OFF_BOOST_ON_CONTRAST = 0x54;
kayekss 0:db0ffd858ca1 63 const static uint8_t IS1_ICON_ON_BOOST_OFF_CONTRAST = 0x58;
kayekss 0:db0ffd858ca1 64 const static uint8_t IS1_ICON_ON_BOOST_ON_CONTRAST = 0x5c;
kayekss 0:db0ffd858ca1 65 const static uint8_t IS1_FOLLOWER_OFF_RAB = 0x60;
kayekss 0:db0ffd858ca1 66 const static uint8_t IS1_FOLLOWER_ON_RAB = 0x68;
kayekss 0:db0ffd858ca1 67 const static uint8_t IS1_CONTRAST = 0x70;
kayekss 0:db0ffd858ca1 68
kayekss 0:db0ffd858ca1 69 private:
kayekss 0:db0ffd858ca1 70 uint8_t** _lineBuffer;
kayekss 0:db0ffd858ca1 71 uint8_t _column, _row;
kayekss 0:db0ffd858ca1 72 uint8_t _columns, _rows;
kayekss 0:db0ffd858ca1 73 uint8_t _address;
kayekss 0:db0ffd858ca1 74 uint8_t _osc, _rab, _contrast;
kayekss 0:db0ffd858ca1 75 Bias _bias;
kayekss 0:db0ffd858ca1 76 I2C _i2c;
kayekss 0:db0ffd858ca1 77
kayekss 0:db0ffd858ca1 78 public:
kayekss 0:db0ffd858ca1 79 /** Constructor of class TextLCD_ST7032I2C.
kayekss 0:db0ffd858ca1 80 * @param sda I2C SPI data output (MOSI) pin.
kayekss 0:db0ffd858ca1 81 * @param scl SPI clock output (SCK) pin.
kayekss 0:db0ffd858ca1 82 * @param address I2C address of the LCD device.
kayekss 0:db0ffd858ca1 83 * @param columns Number of characters in a row.
kayekss 0:db0ffd858ca1 84 * @param rows Number of rows.
kayekss 0:db0ffd858ca1 85 */
kayekss 0:db0ffd858ca1 86 TextLCD_ST7032I2C(PinName sda, PinName scl, uint8_t address,
kayekss 0:db0ffd858ca1 87 uint8_t columns, uint8_t rows);
kayekss 0:db0ffd858ca1 88
kayekss 0:db0ffd858ca1 89 /** Destructor of class TextLCD_ST7032I2C. */
kayekss 0:db0ffd858ca1 90 virtual ~TextLCD_ST7032I2C();
kayekss 0:db0ffd858ca1 91
kayekss 0:db0ffd858ca1 92 /** Hit hardware reset pin. */
kayekss 0:db0ffd858ca1 93 void reset();
kayekss 0:db0ffd858ca1 94
kayekss 0:db0ffd858ca1 95 /** Initialize controller.
kayekss 0:db0ffd858ca1 96 * @param osc Oscillator configuration (0..7).
kayekss 0:db0ffd858ca1 97 * @param rab Rab value setting (0..7).
kayekss 0:db0ffd858ca1 98 * @param contrast Contrast setting (0..63).
kayekss 0:db0ffd858ca1 99 * @param bias Bias configuration for your LCD.
kayekss 0:db0ffd858ca1 100 */
kayekss 0:db0ffd858ca1 101 void init(uint8_t osc, uint8_t rab, uint8_t contrast, Bias bias);
kayekss 0:db0ffd858ca1 102
kayekss 0:db0ffd858ca1 103 /** Clear display and set cursor to home. */
kayekss 0:db0ffd858ca1 104 void cls();
kayekss 0:db0ffd858ca1 105
kayekss 0:db0ffd858ca1 106 /** Set cursor position for next character.
kayekss 0:db0ffd858ca1 107 * @param column Column position indexed from 0.
kayekss 0:db0ffd858ca1 108 * @param row Row position indexed from 0.
kayekss 0:db0ffd858ca1 109 */
kayekss 0:db0ffd858ca1 110 void locate(uint8_t column, uint8_t row);
kayekss 0:db0ffd858ca1 111
kayekss 0:db0ffd858ca1 112 /** Enable icon display. */
kayekss 0:db0ffd858ca1 113 void iconOn();
kayekss 0:db0ffd858ca1 114
kayekss 0:db0ffd858ca1 115 /** Disable icon display. */
kayekss 0:db0ffd858ca1 116 void iconOff();
kayekss 0:db0ffd858ca1 117
kayekss 0:db0ffd858ca1 118 /** Set icon display pattern.
kayekss 0:db0ffd858ca1 119 * @param iconAddr Icon address (0x00..0x0f).
kayekss 0:db0ffd858ca1 120 * @param bits Icon bit pattern (0x00..0x1f).
kayekss 0:db0ffd858ca1 121 */
kayekss 0:db0ffd858ca1 122 void setIcon(uint8_t iconAddr, uint8_t bits);
kayekss 0:db0ffd858ca1 123
kayekss 0:db0ffd858ca1 124 private:
kayekss 0:db0ffd858ca1 125 /** Implementation of putc from Stream class. */
kayekss 0:db0ffd858ca1 126 virtual int _putc(int c);
kayekss 0:db0ffd858ca1 127
kayekss 0:db0ffd858ca1 128 /** Implementation of getc from Stream class. */
kayekss 0:db0ffd858ca1 129 virtual int _getc();
kayekss 0:db0ffd858ca1 130
kayekss 0:db0ffd858ca1 131 /** Shift up the lower line for scrolling. */
kayekss 0:db0ffd858ca1 132 void shiftUp();
kayekss 0:db0ffd858ca1 133
kayekss 0:db0ffd858ca1 134 /** Clear entire display. */
kayekss 0:db0ffd858ca1 135 void clear();
kayekss 0:db0ffd858ca1 136
kayekss 0:db0ffd858ca1 137 /** Set instruction set to 0. */
kayekss 0:db0ffd858ca1 138 void is0();
kayekss 0:db0ffd858ca1 139
kayekss 0:db0ffd858ca1 140 /** Set instruction set to 1. */
kayekss 0:db0ffd858ca1 141 void is1();
kayekss 0:db0ffd858ca1 142
kayekss 0:db0ffd858ca1 143 /** Write a command byte for LCD controller.
kayekss 0:db0ffd858ca1 144 * @param c The command byte.
kayekss 0:db0ffd858ca1 145 */
kayekss 0:db0ffd858ca1 146 void command(uint8_t c);
kayekss 0:db0ffd858ca1 147
kayekss 0:db0ffd858ca1 148 /** Write a data byte for LCD controller.
kayekss 0:db0ffd858ca1 149 * @param d The data byte.
kayekss 0:db0ffd858ca1 150 */
kayekss 0:db0ffd858ca1 151 void data(uint8_t d);
kayekss 0:db0ffd858ca1 152 };
kayekss 0:db0ffd858ca1 153
kayekss 0:db0ffd858ca1 154 #endif