ePaperDisplay (ePD) gde021a1 driver. This ePD is present on the STMicroelectronics Discovery L053 board (STM32L0538-DISCO).

Dependents:   DISCO-L053C8_ePD_demo DISCO-L053C8_ePD_demo Ruche_V1 DISCO-L053C8_ePD_demo ... more

GDE021A1 ePaper display Library.

Committer:
bcostm
Date:
Tue Apr 28 12:02:43 2015 +0000
Revision:
1:6ee9c1afd6ec
Parent:
0:5d8241e6bd3b
Add code example.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:5d8241e6bd3b 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
bcostm 0:5d8241e6bd3b 2 *
bcostm 0:5d8241e6bd3b 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
bcostm 0:5d8241e6bd3b 4 * and associated documentation files (the "Software"), to deal in the Software without
bcostm 0:5d8241e6bd3b 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
bcostm 0:5d8241e6bd3b 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
bcostm 0:5d8241e6bd3b 7 * Software is furnished to do so, subject to the following conditions:
bcostm 0:5d8241e6bd3b 8 *
bcostm 0:5d8241e6bd3b 9 * The above copyright notice and this permission notice shall be included in all copies or
bcostm 0:5d8241e6bd3b 10 * substantial portions of the Software.
bcostm 0:5d8241e6bd3b 11 *
bcostm 0:5d8241e6bd3b 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
bcostm 0:5d8241e6bd3b 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
bcostm 0:5d8241e6bd3b 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
bcostm 0:5d8241e6bd3b 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bcostm 0:5d8241e6bd3b 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
bcostm 0:5d8241e6bd3b 17 */
bcostm 0:5d8241e6bd3b 18
bcostm 0:5d8241e6bd3b 19 #ifndef __EPD_GDE021A1_H
bcostm 0:5d8241e6bd3b 20 #define __EPD_GDE021A1_H
bcostm 0:5d8241e6bd3b 21
bcostm 0:5d8241e6bd3b 22 #include "mbed.h"
bcostm 0:5d8241e6bd3b 23 #include "fontsepd.h"
bcostm 0:5d8241e6bd3b 24
bcostm 0:5d8241e6bd3b 25 /**
bcostm 0:5d8241e6bd3b 26 * @brief EPD color
bcostm 0:5d8241e6bd3b 27 */
bcostm 0:5d8241e6bd3b 28 #define EPD_COLOR_BLACK 0x00
bcostm 0:5d8241e6bd3b 29 #define EPD_COLOR_DARKGRAY 0x55
bcostm 0:5d8241e6bd3b 30 #define EPD_COLOR_LIGHTGRAY 0xAA
bcostm 0:5d8241e6bd3b 31 #define EPD_COLOR_WHITE 0xFF
bcostm 0:5d8241e6bd3b 32
bcostm 0:5d8241e6bd3b 33 /**
bcostm 0:5d8241e6bd3b 34 * @brief Line mode structures definition
bcostm 0:5d8241e6bd3b 35 */
bcostm 0:5d8241e6bd3b 36 typedef enum
bcostm 0:5d8241e6bd3b 37 {
bcostm 0:5d8241e6bd3b 38 CENTER_MODE = 0x01,
bcostm 0:5d8241e6bd3b 39 RIGHT_MODE = 0x02,
bcostm 0:5d8241e6bd3b 40 LEFT_MODE = 0x03
bcostm 0:5d8241e6bd3b 41 } Text_AlignModeTypdef;
bcostm 0:5d8241e6bd3b 42
bcostm 0:5d8241e6bd3b 43 /**
bcostm 0:5d8241e6bd3b 44 * ePaperDisplay on SPI
bcostm 1:6ee9c1afd6ec 45 *
bcostm 1:6ee9c1afd6ec 46 * Example:
bcostm 1:6ee9c1afd6ec 47 * @code
bcostm 1:6ee9c1afd6ec 48 * #include "mbed.h"
bcostm 1:6ee9c1afd6ec 49 * #include "EPD_GDE021A1.h"
bcostm 1:6ee9c1afd6ec 50 *
bcostm 1:6ee9c1afd6ec 51 * #define EPD_CS PA_15
bcostm 1:6ee9c1afd6ec 52 * #define EPD_DC PB_11
bcostm 1:6ee9c1afd6ec 53 * #define EPD_RESET PB_2
bcostm 1:6ee9c1afd6ec 54 * #define EPD_BUSY PA_8
bcostm 1:6ee9c1afd6ec 55 * #define EPD_POWER PB_10
bcostm 1:6ee9c1afd6ec 56 * #define EPD_SPI_MOSI PB_5
bcostm 1:6ee9c1afd6ec 57 * #define EPD_SPI_MISO PB_4
bcostm 1:6ee9c1afd6ec 58 * #define EPD_SPI_SCK PB_3
bcostm 1:6ee9c1afd6ec 59 *
bcostm 1:6ee9c1afd6ec 60 * EPD_GDE021A1 epd(EPD_CS, EPD_DC, EPD_RESET, EPD_BUSY, EPD_POWER, EPD_SPI_MOSI, EPD_SPI_MISO, EPD_SPI_SCK);
bcostm 1:6ee9c1afd6ec 61 *
bcostm 1:6ee9c1afd6ec 62 * int main()
bcostm 1:6ee9c1afd6ec 63 * {
bcostm 1:6ee9c1afd6ec 64 * epd.Clear(EPD_COLOR_WHITE);
bcostm 1:6ee9c1afd6ec 65 * epd.DisplayStringAtLine(5, (uint8_t*)"MBED", CENTER_MODE);
bcostm 1:6ee9c1afd6ec 66 * epd.DisplayStringAtLine(3, (uint8_t*)"Epaper display", LEFT_MODE);
bcostm 1:6ee9c1afd6ec 67 * epd.DisplayStringAtLine(2, (uint8_t*)"demo", LEFT_MODE);
bcostm 1:6ee9c1afd6ec 68 * epd.RefreshDisplay();
bcostm 1:6ee9c1afd6ec 69 * wait(2);
bcostm 1:6ee9c1afd6ec 70 *
bcostm 1:6ee9c1afd6ec 71 * while(1) {
bcostm 1:6ee9c1afd6ec 72 * led1 = !led1;
bcostm 1:6ee9c1afd6ec 73 * wait(1);
bcostm 1:6ee9c1afd6ec 74 * }
bcostm 1:6ee9c1afd6ec 75 * }
bcostm 1:6ee9c1afd6ec 76 * @endcode
bcostm 0:5d8241e6bd3b 77 */
bcostm 0:5d8241e6bd3b 78 class EPD_GDE021A1
bcostm 0:5d8241e6bd3b 79 {
bcostm 0:5d8241e6bd3b 80 public:
bcostm 0:5d8241e6bd3b 81 /**
bcostm 0:5d8241e6bd3b 82 * Constructor
bcostm 0:5d8241e6bd3b 83 * @param cs EPD CS pin
bcostm 0:5d8241e6bd3b 84 * @param dc EPD DC pin
bcostm 0:5d8241e6bd3b 85 * @param rst EPD RESET pin
bcostm 0:5d8241e6bd3b 86 * @param bsy EPD BUSY pin
bcostm 0:5d8241e6bd3b 87 * @param pwr EPD POWER pin
bcostm 0:5d8241e6bd3b 88 * @param mosi SPI MOSI pin
bcostm 0:5d8241e6bd3b 89 * @param miso SPI MISO pin
bcostm 0:5d8241e6bd3b 90 * @param scl SPI SCLK pin
bcostm 0:5d8241e6bd3b 91 */
bcostm 0:5d8241e6bd3b 92 EPD_GDE021A1(PinName cs, PinName dc, PinName rst, PinName bsy, PinName pwr, PinName spi_mosi, PinName spi_miso, PinName spi_scl);
bcostm 0:5d8241e6bd3b 93
bcostm 0:5d8241e6bd3b 94 /**
bcostm 0:5d8241e6bd3b 95 * Destructor
bcostm 0:5d8241e6bd3b 96 */
bcostm 0:5d8241e6bd3b 97 ~EPD_GDE021A1();
bcostm 0:5d8241e6bd3b 98
bcostm 0:5d8241e6bd3b 99 /**
bcostm 0:5d8241e6bd3b 100 * @brief Gets the EPD X size.
bcostm 0:5d8241e6bd3b 101 * @param None
bcostm 0:5d8241e6bd3b 102 * @retval EPD X size
bcostm 0:5d8241e6bd3b 103 */
bcostm 0:5d8241e6bd3b 104 uint32_t GetXSize(void);
bcostm 0:5d8241e6bd3b 105
bcostm 0:5d8241e6bd3b 106 /**
bcostm 0:5d8241e6bd3b 107 * @brief Gets the EPD Y size.
bcostm 0:5d8241e6bd3b 108 * @param None
bcostm 0:5d8241e6bd3b 109 * @retval EPD Y size
bcostm 0:5d8241e6bd3b 110 */
bcostm 0:5d8241e6bd3b 111 uint32_t GetYSize(void);
bcostm 0:5d8241e6bd3b 112
bcostm 0:5d8241e6bd3b 113 /**
bcostm 0:5d8241e6bd3b 114 * @brief Sets the Text Font.
bcostm 0:5d8241e6bd3b 115 * @param pFonts: specifies the layer font to be used.
bcostm 0:5d8241e6bd3b 116 * @retval None
bcostm 0:5d8241e6bd3b 117 */
bcostm 0:5d8241e6bd3b 118 void SetFont(sFONT *pFonts);
bcostm 0:5d8241e6bd3b 119
bcostm 0:5d8241e6bd3b 120 /**
bcostm 0:5d8241e6bd3b 121 * @brief Gets the Text Font.
bcostm 0:5d8241e6bd3b 122 * @param None.
bcostm 0:5d8241e6bd3b 123 * @retval the used layer font.
bcostm 0:5d8241e6bd3b 124 */
bcostm 0:5d8241e6bd3b 125 sFONT *GetFont(void);
bcostm 0:5d8241e6bd3b 126
bcostm 0:5d8241e6bd3b 127 /**
bcostm 0:5d8241e6bd3b 128 * @brief Clears the EPD.
bcostm 0:5d8241e6bd3b 129 * @param Color: Color of the background
bcostm 0:5d8241e6bd3b 130 * @retval None
bcostm 0:5d8241e6bd3b 131 */
bcostm 0:5d8241e6bd3b 132 void Clear(uint16_t Color);
bcostm 0:5d8241e6bd3b 133
bcostm 0:5d8241e6bd3b 134 /**
bcostm 0:5d8241e6bd3b 135 * @brief Displays one character.
bcostm 0:5d8241e6bd3b 136 * @param Xpos: start column address.
bcostm 0:5d8241e6bd3b 137 * @param Ypos: the Line where to display the character shape.
bcostm 0:5d8241e6bd3b 138 * @param Ascii: character ascii code, must be between 0x20 and 0x7E.
bcostm 0:5d8241e6bd3b 139 * @retval None
bcostm 0:5d8241e6bd3b 140 */
bcostm 0:5d8241e6bd3b 141 void DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii);
bcostm 0:5d8241e6bd3b 142
bcostm 0:5d8241e6bd3b 143 /**
bcostm 0:5d8241e6bd3b 144 * @brief Displays characters on the EPD.
bcostm 0:5d8241e6bd3b 145 * @param Xpos: X position
bcostm 0:5d8241e6bd3b 146 * @param Ypos: Y position
bcostm 0:5d8241e6bd3b 147 * @param Text: Pointer to string to display on EPD
bcostm 0:5d8241e6bd3b 148 * @param Mode: Display mode
bcostm 0:5d8241e6bd3b 149 * This parameter can be one of the following values:
bcostm 0:5d8241e6bd3b 150 * @arg CENTER_MODE
bcostm 0:5d8241e6bd3b 151 * @arg RIGHT_MODE
bcostm 0:5d8241e6bd3b 152 * @arg LEFT_MODE
bcostm 0:5d8241e6bd3b 153 * @retval None
bcostm 0:5d8241e6bd3b 154 */
bcostm 0:5d8241e6bd3b 155 void DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode);
bcostm 0:5d8241e6bd3b 156
bcostm 0:5d8241e6bd3b 157 /**
bcostm 0:5d8241e6bd3b 158 * @brief Displays a character on the EPD.
bcostm 0:5d8241e6bd3b 159 * @param Line: Line where to display the character shape
bcostm 0:5d8241e6bd3b 160 * This parameter can be one of the following values:
bcostm 0:5d8241e6bd3b 161 * @arg 0..8: if the Current fonts is Font8
bcostm 0:5d8241e6bd3b 162 * @arg 0..5: if the Current fonts is Font12
bcostm 0:5d8241e6bd3b 163 * @arg 0..3: if the Current fonts is Font16
bcostm 0:5d8241e6bd3b 164 * @arg 0..2: if the Current fonts is Font20
bcostm 0:5d8241e6bd3b 165 * @param ptr: Pointer to string to display on EPD
bcostm 0:5d8241e6bd3b 166 * @retval None
bcostm 0:5d8241e6bd3b 167 */
bcostm 0:5d8241e6bd3b 168 void DisplayStringAtLine(uint16_t Line, uint8_t *ptr, Text_AlignModeTypdef Mode);
bcostm 0:5d8241e6bd3b 169
bcostm 0:5d8241e6bd3b 170 /**
bcostm 0:5d8241e6bd3b 171 * @brief Draws an horizontal line.
bcostm 0:5d8241e6bd3b 172 * @param Xpos: X position
bcostm 0:5d8241e6bd3b 173 * @param Ypos: Y position
bcostm 0:5d8241e6bd3b 174 * @param Length: line length
bcostm 0:5d8241e6bd3b 175 * @retval None
bcostm 0:5d8241e6bd3b 176 */
bcostm 0:5d8241e6bd3b 177 void DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length);
bcostm 0:5d8241e6bd3b 178
bcostm 0:5d8241e6bd3b 179 /**
bcostm 0:5d8241e6bd3b 180 * @brief Draws a vertical line.
bcostm 0:5d8241e6bd3b 181 * @param Xpos: X position
bcostm 0:5d8241e6bd3b 182 * @param Ypos: Y position
bcostm 0:5d8241e6bd3b 183 * @param Length: line length.
bcostm 0:5d8241e6bd3b 184 * @retval None
bcostm 0:5d8241e6bd3b 185 */
bcostm 0:5d8241e6bd3b 186 void DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length);
bcostm 0:5d8241e6bd3b 187
bcostm 0:5d8241e6bd3b 188 /**
bcostm 0:5d8241e6bd3b 189 * @brief Draws a rectangle.
bcostm 0:5d8241e6bd3b 190 * @param Xpos: X position
bcostm 0:5d8241e6bd3b 191 * @param Ypos: Y position
bcostm 0:5d8241e6bd3b 192 * @param Height: rectangle height
bcostm 0:5d8241e6bd3b 193 * @param Width: rectangle width
bcostm 0:5d8241e6bd3b 194 * @retval None
bcostm 0:5d8241e6bd3b 195 */
bcostm 0:5d8241e6bd3b 196 void DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
bcostm 0:5d8241e6bd3b 197
bcostm 0:5d8241e6bd3b 198 /**
bcostm 0:5d8241e6bd3b 199 * @brief Displays a full rectangle.
bcostm 0:5d8241e6bd3b 200 * @param Xpos: X position.
bcostm 0:5d8241e6bd3b 201 * @param Ypos: Y position.
bcostm 0:5d8241e6bd3b 202 * @param Height: display rectangle height.
bcostm 0:5d8241e6bd3b 203 * @param Width: display rectangle width.
bcostm 0:5d8241e6bd3b 204 * @retval None
bcostm 0:5d8241e6bd3b 205 */
bcostm 0:5d8241e6bd3b 206 void FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
bcostm 0:5d8241e6bd3b 207
bcostm 0:5d8241e6bd3b 208 /**
bcostm 0:5d8241e6bd3b 209 * @brief Draws an Image.
bcostm 0:5d8241e6bd3b 210 * @param Xpos: X position in the EPD
bcostm 0:5d8241e6bd3b 211 * @param Ypos: Y position in the EPD
bcostm 0:5d8241e6bd3b 212 * @param Xsize: X size in the EPD
bcostm 0:5d8241e6bd3b 213 * @param Ysize: Y size in the EPD
bcostm 0:5d8241e6bd3b 214 * @param pdata: Pointer to the Image address
bcostm 0:5d8241e6bd3b 215 * @retval None
bcostm 0:5d8241e6bd3b 216 */
bcostm 0:5d8241e6bd3b 217 void DrawImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata);
bcostm 0:5d8241e6bd3b 218
bcostm 0:5d8241e6bd3b 219 /**
bcostm 0:5d8241e6bd3b 220 * @brief Disables the clock and the charge pump.
bcostm 0:5d8241e6bd3b 221 * @param None
bcostm 0:5d8241e6bd3b 222 * @retval None
bcostm 0:5d8241e6bd3b 223 */
bcostm 0:5d8241e6bd3b 224 void CloseChargePump(void);
bcostm 0:5d8241e6bd3b 225
bcostm 0:5d8241e6bd3b 226 /**
bcostm 0:5d8241e6bd3b 227 * @brief Updates the display from the data located into the RAM.
bcostm 0:5d8241e6bd3b 228 * @param None
bcostm 0:5d8241e6bd3b 229 * @retval None
bcostm 0:5d8241e6bd3b 230 */
bcostm 0:5d8241e6bd3b 231 void RefreshDisplay(void);
bcostm 0:5d8241e6bd3b 232
bcostm 0:5d8241e6bd3b 233 private:
bcostm 0:5d8241e6bd3b 234 SPI _spi;
bcostm 0:5d8241e6bd3b 235 DigitalOut _cs;
bcostm 0:5d8241e6bd3b 236 DigitalOut _dc;
bcostm 0:5d8241e6bd3b 237 DigitalOut _rst;
bcostm 0:5d8241e6bd3b 238 DigitalIn _bsy;
bcostm 0:5d8241e6bd3b 239 DigitalOut _pwr;
bcostm 0:5d8241e6bd3b 240
bcostm 0:5d8241e6bd3b 241 sFONT *pFont;
bcostm 0:5d8241e6bd3b 242
bcostm 0:5d8241e6bd3b 243 void EPD_IO_WriteData(uint16_t RegValue);
bcostm 0:5d8241e6bd3b 244 void EPD_IO_WriteReg(uint8_t Reg);
bcostm 0:5d8241e6bd3b 245 uint16_t EPD_IO_ReadData(void);
bcostm 0:5d8241e6bd3b 246
bcostm 0:5d8241e6bd3b 247 void gde021a1_Init(void);
bcostm 0:5d8241e6bd3b 248 void gde021a1_WriteReg(uint8_t EPD_Reg, uint8_t EPD_RegValue);
bcostm 0:5d8241e6bd3b 249 uint8_t gde021a1_ReadReg(uint8_t EPD_Reg);
bcostm 0:5d8241e6bd3b 250 void gde021a1_WritePixel(uint8_t HEX_Code);
bcostm 0:5d8241e6bd3b 251 void gde021a1_DrawImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata);
bcostm 0:5d8241e6bd3b 252 void gde021a1_RefreshDisplay(void);
bcostm 0:5d8241e6bd3b 253 void gde021a1_CloseChargePump(void);
bcostm 0:5d8241e6bd3b 254 void gde021a1_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
bcostm 0:5d8241e6bd3b 255 uint16_t gde021a1_GetEpdPixelWidth(void);
bcostm 0:5d8241e6bd3b 256 uint16_t gde021a1_GetEpdPixelHeight(void);
bcostm 0:5d8241e6bd3b 257
bcostm 0:5d8241e6bd3b 258 void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
bcostm 0:5d8241e6bd3b 259 };
bcostm 0:5d8241e6bd3b 260
bcostm 0:5d8241e6bd3b 261 #endif