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