Text console library for ST7565 graphics LCD controller over SPI interface.
Dependents: TextLCD_ST7565SPI_Test OpPanel_Offline OpPanel_Offline_cmake_gcc_arm_NUCLEO_F303RENew
TextLCD_ST7565SPI.h@0:1ea133b6a4de, 2015-03-02 (annotated)
- Committer:
- kayekss
- Date:
- Mon Mar 02 23:10:13 2015 +0000
- Revision:
- 0:1ea133b6a4de
Initial release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kayekss | 0:1ea133b6a4de | 1 | // ==================================================== Mar 03 2015, kayeks == |
kayekss | 0:1ea133b6a4de | 2 | // TextLCD_ST7565SPI.h |
kayekss | 0:1ea133b6a4de | 3 | // =========================================================================== |
kayekss | 0:1ea133b6a4de | 4 | // Text console library for ST7565 graphics LCD controller over SPI interface. |
kayekss | 0:1ea133b6a4de | 5 | |
kayekss | 0:1ea133b6a4de | 6 | #ifndef TEXTLCD_ST7565SPI_H_ |
kayekss | 0:1ea133b6a4de | 7 | #define TEXTLCD_ST7565SPI_H_ |
kayekss | 0:1ea133b6a4de | 8 | |
kayekss | 0:1ea133b6a4de | 9 | #include "mbed.h" |
kayekss | 0:1ea133b6a4de | 10 | |
kayekss | 0:1ea133b6a4de | 11 | /** Text console library for ST7565 graphics LCD controller over SPI interface. */ |
kayekss | 0:1ea133b6a4de | 12 | class TextLCD_ST7565SPI : public Stream { |
kayekss | 0:1ea133b6a4de | 13 | public: |
kayekss | 0:1ea133b6a4de | 14 | /** Bias select: 1/7 or 1/9. */ |
kayekss | 0:1ea133b6a4de | 15 | enum Bias { |
kayekss | 0:1ea133b6a4de | 16 | Bias1_7 /** 1/7 bias */ |
kayekss | 0:1ea133b6a4de | 17 | , Bias1_9 /** 1/9 bias */ |
kayekss | 0:1ea133b6a4de | 18 | }; |
kayekss | 0:1ea133b6a4de | 19 | |
kayekss | 0:1ea133b6a4de | 20 | const static uint8_t V0_INTERNAL_R_0 = 0x20; |
kayekss | 0:1ea133b6a4de | 21 | const static uint8_t V0_INTERNAL_R_1 = 0x21; |
kayekss | 0:1ea133b6a4de | 22 | const static uint8_t V0_INTERNAL_R_2 = 0x22; |
kayekss | 0:1ea133b6a4de | 23 | const static uint8_t V0_INTERNAL_R_3 = 0x23; |
kayekss | 0:1ea133b6a4de | 24 | const static uint8_t V0_INTERNAL_R_4 = 0x24; |
kayekss | 0:1ea133b6a4de | 25 | const static uint8_t V0_INTERNAL_R_5 = 0x25; |
kayekss | 0:1ea133b6a4de | 26 | const static uint8_t V0_INTERNAL_R_6 = 0x26; |
kayekss | 0:1ea133b6a4de | 27 | const static uint8_t V0_INTERNAL_R_7 = 0x27; |
kayekss | 0:1ea133b6a4de | 28 | const static uint8_t PCTRL_VFOLLOWER_ON = 0x29; |
kayekss | 0:1ea133b6a4de | 29 | const static uint8_t PCTRL_VFOLLOWER_OFF = 0x28; |
kayekss | 0:1ea133b6a4de | 30 | const static uint8_t PCTRL_REGULATOR_ON = 0x2a; |
kayekss | 0:1ea133b6a4de | 31 | const static uint8_t PCTRL_REGULATOR_OFF = 0x28; |
kayekss | 0:1ea133b6a4de | 32 | const static uint8_t PCTRL_BOOSTER_ON = 0x2c; |
kayekss | 0:1ea133b6a4de | 33 | const static uint8_t PCTRL_BOOSTER_OFF = 0x28; |
kayekss | 0:1ea133b6a4de | 34 | const static uint8_t COMMON_OFFSET = 0x40; |
kayekss | 0:1ea133b6a4de | 35 | const static uint8_t ELECTRONIC_VOL_MODE = 0x81; |
kayekss | 0:1ea133b6a4de | 36 | const static uint8_t ELECTRONIC_VOL_1 = 0x01; |
kayekss | 0:1ea133b6a4de | 37 | const static uint8_t ELECTRONIC_VOL_2 = 0x02; |
kayekss | 0:1ea133b6a4de | 38 | const static uint8_t ELECTRONIC_VOL_3 = 0x03; |
kayekss | 0:1ea133b6a4de | 39 | const static uint8_t ELECTRONIC_VOL_4 = 0x04; |
kayekss | 0:1ea133b6a4de | 40 | const static uint8_t ELECTRONIC_VOL_5 = 0x05; |
kayekss | 0:1ea133b6a4de | 41 | const static uint8_t ELECTRONIC_VOL_6 = 0x06; |
kayekss | 0:1ea133b6a4de | 42 | const static uint8_t ELECTRONIC_VOL_7 = 0x07; |
kayekss | 0:1ea133b6a4de | 43 | const static uint8_t ELECTRONIC_VOL_8 = 0x08; |
kayekss | 0:1ea133b6a4de | 44 | const static uint8_t ELECTRONIC_VOL_9 = 0x09; |
kayekss | 0:1ea133b6a4de | 45 | const static uint8_t ELECTRONIC_VOL_10 = 0x0a; |
kayekss | 0:1ea133b6a4de | 46 | const static uint8_t ELECTRONIC_VOL_11 = 0x0b; |
kayekss | 0:1ea133b6a4de | 47 | const static uint8_t ELECTRONIC_VOL_12 = 0x0c; |
kayekss | 0:1ea133b6a4de | 48 | const static uint8_t ELECTRONIC_VOL_13 = 0x0d; |
kayekss | 0:1ea133b6a4de | 49 | const static uint8_t ELECTRONIC_VOL_14 = 0x0e; |
kayekss | 0:1ea133b6a4de | 50 | const static uint8_t ELECTRONIC_VOL_15 = 0x0f; |
kayekss | 0:1ea133b6a4de | 51 | const static uint8_t ELECTRONIC_VOL_16 = 0x10; |
kayekss | 0:1ea133b6a4de | 52 | const static uint8_t ELECTRONIC_VOL_17 = 0x11; |
kayekss | 0:1ea133b6a4de | 53 | const static uint8_t ELECTRONIC_VOL_18 = 0x12; |
kayekss | 0:1ea133b6a4de | 54 | const static uint8_t ELECTRONIC_VOL_19 = 0x13; |
kayekss | 0:1ea133b6a4de | 55 | const static uint8_t ELECTRONIC_VOL_20 = 0x14; |
kayekss | 0:1ea133b6a4de | 56 | const static uint8_t ELECTRONIC_VOL_21 = 0x15; |
kayekss | 0:1ea133b6a4de | 57 | const static uint8_t ELECTRONIC_VOL_22 = 0x16; |
kayekss | 0:1ea133b6a4de | 58 | const static uint8_t ELECTRONIC_VOL_23 = 0x17; |
kayekss | 0:1ea133b6a4de | 59 | const static uint8_t ELECTRONIC_VOL_24 = 0x18; |
kayekss | 0:1ea133b6a4de | 60 | const static uint8_t ELECTRONIC_VOL_25 = 0x19; |
kayekss | 0:1ea133b6a4de | 61 | const static uint8_t ELECTRONIC_VOL_26 = 0x1a; |
kayekss | 0:1ea133b6a4de | 62 | const static uint8_t ELECTRONIC_VOL_27 = 0x1b; |
kayekss | 0:1ea133b6a4de | 63 | const static uint8_t ELECTRONIC_VOL_28 = 0x1c; |
kayekss | 0:1ea133b6a4de | 64 | const static uint8_t ELECTRONIC_VOL_29 = 0x1d; |
kayekss | 0:1ea133b6a4de | 65 | const static uint8_t ELECTRONIC_VOL_30 = 0x1e; |
kayekss | 0:1ea133b6a4de | 66 | const static uint8_t ELECTRONIC_VOL_31 = 0x1f; |
kayekss | 0:1ea133b6a4de | 67 | const static uint8_t ELECTRONIC_VOL_32 = 0x20; |
kayekss | 0:1ea133b6a4de | 68 | const static uint8_t ELECTRONIC_VOL_33 = 0x21; |
kayekss | 0:1ea133b6a4de | 69 | const static uint8_t ELECTRONIC_VOL_34 = 0x22; |
kayekss | 0:1ea133b6a4de | 70 | const static uint8_t ELECTRONIC_VOL_35 = 0x23; |
kayekss | 0:1ea133b6a4de | 71 | const static uint8_t ELECTRONIC_VOL_36 = 0x24; |
kayekss | 0:1ea133b6a4de | 72 | const static uint8_t ELECTRONIC_VOL_37 = 0x25; |
kayekss | 0:1ea133b6a4de | 73 | const static uint8_t ELECTRONIC_VOL_38 = 0x26; |
kayekss | 0:1ea133b6a4de | 74 | const static uint8_t ELECTRONIC_VOL_39 = 0x27; |
kayekss | 0:1ea133b6a4de | 75 | const static uint8_t ELECTRONIC_VOL_40 = 0x28; |
kayekss | 0:1ea133b6a4de | 76 | const static uint8_t ELECTRONIC_VOL_41 = 0x29; |
kayekss | 0:1ea133b6a4de | 77 | const static uint8_t ELECTRONIC_VOL_42 = 0x2a; |
kayekss | 0:1ea133b6a4de | 78 | const static uint8_t ELECTRONIC_VOL_43 = 0x2b; |
kayekss | 0:1ea133b6a4de | 79 | const static uint8_t ELECTRONIC_VOL_44 = 0x2c; |
kayekss | 0:1ea133b6a4de | 80 | const static uint8_t ELECTRONIC_VOL_45 = 0x2d; |
kayekss | 0:1ea133b6a4de | 81 | const static uint8_t ELECTRONIC_VOL_46 = 0x2e; |
kayekss | 0:1ea133b6a4de | 82 | const static uint8_t ELECTRONIC_VOL_47 = 0x2f; |
kayekss | 0:1ea133b6a4de | 83 | const static uint8_t ELECTRONIC_VOL_48 = 0x30; |
kayekss | 0:1ea133b6a4de | 84 | const static uint8_t ELECTRONIC_VOL_49 = 0x31; |
kayekss | 0:1ea133b6a4de | 85 | const static uint8_t ELECTRONIC_VOL_50 = 0x32; |
kayekss | 0:1ea133b6a4de | 86 | const static uint8_t ELECTRONIC_VOL_51 = 0x33; |
kayekss | 0:1ea133b6a4de | 87 | const static uint8_t ELECTRONIC_VOL_52 = 0x34; |
kayekss | 0:1ea133b6a4de | 88 | const static uint8_t ELECTRONIC_VOL_53 = 0x35; |
kayekss | 0:1ea133b6a4de | 89 | const static uint8_t ELECTRONIC_VOL_54 = 0x36; |
kayekss | 0:1ea133b6a4de | 90 | const static uint8_t ELECTRONIC_VOL_55 = 0x37; |
kayekss | 0:1ea133b6a4de | 91 | const static uint8_t ELECTRONIC_VOL_56 = 0x38; |
kayekss | 0:1ea133b6a4de | 92 | const static uint8_t ELECTRONIC_VOL_57 = 0x39; |
kayekss | 0:1ea133b6a4de | 93 | const static uint8_t ELECTRONIC_VOL_58 = 0x3a; |
kayekss | 0:1ea133b6a4de | 94 | const static uint8_t ELECTRONIC_VOL_59 = 0x3b; |
kayekss | 0:1ea133b6a4de | 95 | const static uint8_t ELECTRONIC_VOL_60 = 0x3c; |
kayekss | 0:1ea133b6a4de | 96 | const static uint8_t ELECTRONIC_VOL_61 = 0x3d; |
kayekss | 0:1ea133b6a4de | 97 | const static uint8_t ELECTRONIC_VOL_62 = 0x3e; |
kayekss | 0:1ea133b6a4de | 98 | const static uint8_t ELECTRONIC_VOL_63 = 0x3f; |
kayekss | 0:1ea133b6a4de | 99 | const static uint8_t SEGMENT_ASCENDING = 0xa0; |
kayekss | 0:1ea133b6a4de | 100 | const static uint8_t SEGMENT_DESCENDING = 0xa1; |
kayekss | 0:1ea133b6a4de | 101 | const static uint8_t BIAS_1_9 = 0xa2; |
kayekss | 0:1ea133b6a4de | 102 | const static uint8_t BIAS_1_7 = 0xa3; |
kayekss | 0:1ea133b6a4de | 103 | const static uint8_t ENTIRE_DISPLAY_OFF = 0xa4; |
kayekss | 0:1ea133b6a4de | 104 | const static uint8_t ENTIRE_DISPLAY_ON = 0xa5; |
kayekss | 0:1ea133b6a4de | 105 | const static uint8_t INVERT_DISPLAY_OFF = 0xa6; |
kayekss | 0:1ea133b6a4de | 106 | const static uint8_t INVERT_DISPLAY_ON = 0xa7; |
kayekss | 0:1ea133b6a4de | 107 | const static uint8_t DISPLAY_OFF = 0xae; |
kayekss | 0:1ea133b6a4de | 108 | const static uint8_t DISPLAY_ON = 0xaf; |
kayekss | 0:1ea133b6a4de | 109 | const static uint8_t COMMON_ASCENDING = 0xc0; |
kayekss | 0:1ea133b6a4de | 110 | const static uint8_t COMMON_DESCENDING = 0xc8; |
kayekss | 0:1ea133b6a4de | 111 | const static uint8_t MODIFY_WRITE_ON = 0xe0; |
kayekss | 0:1ea133b6a4de | 112 | const static uint8_t INTERNAL_RESET = 0xe2; |
kayekss | 0:1ea133b6a4de | 113 | const static uint8_t MODIFY_WRITE_OFF = 0xee; |
kayekss | 0:1ea133b6a4de | 114 | |
kayekss | 0:1ea133b6a4de | 115 | const static uint8_t FONT_5X7[128][5]; |
kayekss | 0:1ea133b6a4de | 116 | |
kayekss | 0:1ea133b6a4de | 117 | private: |
kayekss | 0:1ea133b6a4de | 118 | uint8_t** _lineBuffer; |
kayekss | 0:1ea133b6a4de | 119 | uint8_t _column, _row; |
kayekss | 0:1ea133b6a4de | 120 | uint8_t _columns, _rows; |
kayekss | 0:1ea133b6a4de | 121 | DigitalOut _rs; |
kayekss | 0:1ea133b6a4de | 122 | DigitalOut _rst; |
kayekss | 0:1ea133b6a4de | 123 | SPI _spi; |
kayekss | 0:1ea133b6a4de | 124 | DigitalOut _cs; |
kayekss | 0:1ea133b6a4de | 125 | |
kayekss | 0:1ea133b6a4de | 126 | public: |
kayekss | 0:1ea133b6a4de | 127 | /** Constructor of class TextLCD_ST7565SPI. |
kayekss | 0:1ea133b6a4de | 128 | * @param mosi SPI data output (MOSI) pin. |
kayekss | 0:1ea133b6a4de | 129 | * @param sck SPI clock output (SCK) pin. |
kayekss | 0:1ea133b6a4de | 130 | * @param cs SPI Chip select (CS) pin. |
kayekss | 0:1ea133b6a4de | 131 | * @param rs Register select (RS or A0) pin. |
kayekss | 0:1ea133b6a4de | 132 | * @param rst Hardware reset (RST) pin. |
kayekss | 0:1ea133b6a4de | 133 | * @param columns Number of characters in a row. |
kayekss | 0:1ea133b6a4de | 134 | * @param rows Number of rows. |
kayekss | 0:1ea133b6a4de | 135 | */ |
kayekss | 0:1ea133b6a4de | 136 | TextLCD_ST7565SPI(PinName mosi, PinName sck, PinName cs, |
kayekss | 0:1ea133b6a4de | 137 | PinName rs, PinName rst, |
kayekss | 0:1ea133b6a4de | 138 | uint8_t columns, uint8_t rows); |
kayekss | 0:1ea133b6a4de | 139 | |
kayekss | 0:1ea133b6a4de | 140 | /** Destructor of class TextLCD_ST7565SPI. */ |
kayekss | 0:1ea133b6a4de | 141 | virtual ~TextLCD_ST7565SPI(); |
kayekss | 0:1ea133b6a4de | 142 | |
kayekss | 0:1ea133b6a4de | 143 | /** Hit hardware reset pin. */ |
kayekss | 0:1ea133b6a4de | 144 | void reset(); |
kayekss | 0:1ea133b6a4de | 145 | |
kayekss | 0:1ea133b6a4de | 146 | /** Initialize controller. |
kayekss | 0:1ea133b6a4de | 147 | * @param v0 Internal V0 setting (0..7). |
kayekss | 0:1ea133b6a4de | 148 | * @param contrast Contrast setting (0..63). |
kayekss | 0:1ea133b6a4de | 149 | * @param bias Bias configuration for your LCD. |
kayekss | 0:1ea133b6a4de | 150 | */ |
kayekss | 0:1ea133b6a4de | 151 | void init(uint8_t v0, uint8_t contrast, Bias bias); |
kayekss | 0:1ea133b6a4de | 152 | |
kayekss | 0:1ea133b6a4de | 153 | /** Clear display and set cursor to home. */ |
kayekss | 0:1ea133b6a4de | 154 | void cls(); |
kayekss | 0:1ea133b6a4de | 155 | |
kayekss | 0:1ea133b6a4de | 156 | /** Set cursor position for next character. |
kayekss | 0:1ea133b6a4de | 157 | * @param column Column position indexed from 0. |
kayekss | 0:1ea133b6a4de | 158 | * @param row Row position indexed from 0. |
kayekss | 0:1ea133b6a4de | 159 | */ |
kayekss | 0:1ea133b6a4de | 160 | void locate(uint8_t column, uint8_t row); |
kayekss | 0:1ea133b6a4de | 161 | |
kayekss | 0:1ea133b6a4de | 162 | private: |
kayekss | 0:1ea133b6a4de | 163 | /** Implementation of putc from Stream class. */ |
kayekss | 0:1ea133b6a4de | 164 | virtual int _putc(int c); |
kayekss | 0:1ea133b6a4de | 165 | |
kayekss | 0:1ea133b6a4de | 166 | /** Implementation of getc from Stream class. */ |
kayekss | 0:1ea133b6a4de | 167 | virtual int _getc(); |
kayekss | 0:1ea133b6a4de | 168 | |
kayekss | 0:1ea133b6a4de | 169 | /** Shift up the lower line for scrolling. */ |
kayekss | 0:1ea133b6a4de | 170 | void shiftUp(); |
kayekss | 0:1ea133b6a4de | 171 | |
kayekss | 0:1ea133b6a4de | 172 | /** Clear entire display. */ |
kayekss | 0:1ea133b6a4de | 173 | void clear(); |
kayekss | 0:1ea133b6a4de | 174 | |
kayekss | 0:1ea133b6a4de | 175 | /** Set page position for next data. |
kayekss | 0:1ea133b6a4de | 176 | * @param page Page position indexed from 0 to 7. |
kayekss | 0:1ea133b6a4de | 177 | */ |
kayekss | 0:1ea133b6a4de | 178 | void setPage(uint8_t page); |
kayekss | 0:1ea133b6a4de | 179 | |
kayekss | 0:1ea133b6a4de | 180 | /** Set column position for next data. |
kayekss | 0:1ea133b6a4de | 181 | * @param column Column position indexed from 0. |
kayekss | 0:1ea133b6a4de | 182 | */ |
kayekss | 0:1ea133b6a4de | 183 | void setColumn(uint8_t column); |
kayekss | 0:1ea133b6a4de | 184 | |
kayekss | 0:1ea133b6a4de | 185 | /** Write a command byte for LCD controller. |
kayekss | 0:1ea133b6a4de | 186 | * @param c The command byte. |
kayekss | 0:1ea133b6a4de | 187 | */ |
kayekss | 0:1ea133b6a4de | 188 | void command(uint8_t c); |
kayekss | 0:1ea133b6a4de | 189 | |
kayekss | 0:1ea133b6a4de | 190 | /** Write a data byte for LCD controller. |
kayekss | 0:1ea133b6a4de | 191 | * @param d The data byte. |
kayekss | 0:1ea133b6a4de | 192 | */ |
kayekss | 0:1ea133b6a4de | 193 | void data(uint8_t d); |
kayekss | 0:1ea133b6a4de | 194 | }; |
kayekss | 0:1ea133b6a4de | 195 | |
kayekss | 0:1ea133b6a4de | 196 | #endif |