EPD
Dependencies: mbed-STM32F103C8T6 mbed
Revision 0:1d2c0afef43c, committed 2017-12-29
- Comitter:
- spin7ion
- Date:
- Fri Dec 29 22:35:18 2017 +0000
- Commit message:
- test;
Changed in this revision
diff -r 000000000000 -r 1d2c0afef43c epd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/epd.h Fri Dec 29 22:35:18 2017 +0000 @@ -0,0 +1,156 @@ +#ifndef EPD_H +#define EPD_H + +// Display resolution +#define EPD_WIDTH 128 +#define EPD_HEIGHT 296 + +// EPD2IN9 commands +#define DRIVER_OUTPUT_CONTROL 0x01 +#define BOOSTER_SOFT_START_CONTROL 0x0C +#define GATE_SCAN_START_POSITION 0x0F +#define DEEP_SLEEP_MODE 0x10 +#define DATA_ENTRY_MODE_SETTING 0x11 +#define SW_RESET 0x12 +#define TEMPERATURE_SENSOR_CONTROL 0x1A +#define MASTER_ACTIVATION 0x20 +#define DISPLAY_UPDATE_CONTROL_1 0x21 +#define DISPLAY_UPDATE_CONTROL_2 0x22 +#define WRITE_RAM 0x24 +#define WRITE_VCOM_REGISTER 0x2C +#define WRITE_LUT_REGISTER 0x32 +#define SET_DUMMY_LINE_PERIOD 0x3A +#define SET_GATE_TIME 0x3B +#define BORDER_WAVEFORM_CONTROL 0x3C +#define SET_RAM_X_ADDRESS_START_END_POSITION 0x44 +#define SET_RAM_Y_ADDRESS_START_END_POSITION 0x45 +#define SET_RAM_X_ADDRESS_COUNTER 0x4E +#define SET_RAM_Y_ADDRESS_COUNTER 0x4F +#define TERMINATE_FRAME_READ_WRITE 0xFF + +#define BACKGROUND_BLACK 0x00 +#define BACKGROUND_WHITE 0xFF + +const unsigned char lut_full_update[] = +{ + 0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22, + 0x66, 0x69, 0x69, 0x59, 0x58, 0x99, 0x99, 0x88, + 0x00, 0x00, 0x00, 0x00, 0xF8, 0xB4, 0x13, 0x51, + 0x35, 0x51, 0x51, 0x19, 0x01, 0x00 +}; + +const unsigned char lut_partial_update[] = +{ + 0x10, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x44, 0x12, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +/*static unsigned char lut_full_update[] = {0x32,0x02,0x02,0x01,0x11,0x12,0x12,0x22,0x22,0x66,0x69,0x69,0x59,0x58,0x99,0x99,0x88,0x00,0x00,0x00 +,0x00,0xF8,0xB4,0x13,0x51,0x35,0x51,0x51,0x19,0x01,0x00}; + static unsigned char lut_partial_update[] = {0x32,0x10,0x18,0x18,0x08,0x18,0x18,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 +,0x00,0x13,0x14,0x44,0x12,0x00,0x00,0x00,0x00,0x00,0x00};*/ + +const unsigned char FONT8x8[97][8] = { +0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20 +0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // ! +0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // " +0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // # +0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $ +0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // % +0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // & +0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // ' +0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // ( +0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // ) +0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // * +0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // + +0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // , +0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // - +0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // . +0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash) +0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30 +0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1 +0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2 +0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3 +0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4 +0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5 +0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6 +0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7 +0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8 +0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9 +0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // : +0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ; +0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // < +0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // = +0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // > +0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ? +0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40 +0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A +0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B +0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C +0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D +0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E +0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F +0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G +0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H +0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I +0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J +0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K +0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L +0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M +0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N +0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O +0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50 +0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q +0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R +0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S +0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T +0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U +0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V +0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W +0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X +0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y +0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z +0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [ +0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash) +0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ] +0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^ +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _ +0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60 +0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a +0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b +0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c +0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d +0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e +0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f +0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g +0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h +0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i +0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j +0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k +0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l +0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m +0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n +0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o +0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p +0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q +0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r +0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s +0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t +0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u +0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v +0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w +0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x +0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y +0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z +0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // { +0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // | +0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // } +0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~ +0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL + +unsigned char img[EPD_WIDTH][EPD_HEIGHT]; + +#endif /* EPD2IN9_H */ \ No newline at end of file
diff -r 000000000000 -r 1d2c0afef43c main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Dec 29 22:35:18 2017 +0000 @@ -0,0 +1,244 @@ +#include "stm32f103c8t6.h" +#include "mbed.h" +#include "epd.h" + +DigitalOut myled1(LED1); + +DigitalOut edp_reset(PB_0); +DigitalOut edp_dataCommand(PB_10); +DigitalOut edp_chipSelect(PA_4); +DigitalIn edp_busy(PB_11); +SPI spi(PA_7,PA_6,PA_5); // mosi, miso, sclk, ss +//DigitalOut eink(PB_0); +/* +EaEpaper epaper(NC, // PWR_CTRL + NC, // BORDER + PB_10, // DISCHARGE + PB_0, // RESET_DISP + PB_11, // BUSY + PA_4, // SSEL + NC, // PWM + PA_7,PA_6,PA_5, // MOSI,MISO,SCLK + "eink"); // SDA,SCL */ + +void EPD_SendCommand(unsigned char data) { + edp_chipSelect=0; + edp_dataCommand=0; + spi.write(data); + edp_chipSelect=1; +} + +void EPD_SendData(unsigned char data) { + edp_chipSelect=0; + edp_dataCommand=1; + spi.write(data); + edp_chipSelect=1; +} + +void EPD_Reset() { + edp_reset=0; + wait_ms(200); + edp_reset=1; + wait_ms(200); +} + +void EPD_WaitUntilIdle() { + while(edp_busy == 1) { //0: busy, 1: idle + wait_ms(100); + } +} + +/** + * @brief: private function to specify the memory area for data R/W + */ +static void EPD_SetMemoryArea(int x_start, int y_start, int x_end, int y_end) { + EPD_SendCommand(SET_RAM_X_ADDRESS_START_END_POSITION); + /* x point must be the multiple of 8 or the last 3 bits will be ignored */ + EPD_SendData((x_start >> 3) & 0xFF); + EPD_SendData((x_end >> 3) & 0xFF); + EPD_SendCommand(SET_RAM_Y_ADDRESS_START_END_POSITION); + EPD_SendData(y_start & 0xFF); + EPD_SendData((y_start >> 8) & 0xFF); + EPD_SendData(y_end & 0xFF); + EPD_SendData((y_end >> 8) & 0xFF); +} + +/** + * @brief: private function to specify the start point for data R/W + */ +static void EPD_SetMemoryPointer(int x, int y) { + EPD_SendCommand(SET_RAM_X_ADDRESS_COUNTER); + /* x point must be the multiple of 8 or the last 3 bits will be ignored */ + EPD_SendData((x >> 3) & 0xFF); + EPD_SendCommand(SET_RAM_Y_ADDRESS_COUNTER); + EPD_SendData(y & 0xFF); + EPD_SendData((y >> 8) & 0xFF); + EPD_WaitUntilIdle(); +} + +void EPD_SetLut(const unsigned char* lut) { + EPD_SendCommand(WRITE_LUT_REGISTER); + /* the length of look-up table is 30 bytes */ + for (int i = 0; i < 30; i++) { + EPD_SendData(lut[i]); + } +} + +int EPD_Init() { + EPD_Reset(); + EPD_SendCommand(DRIVER_OUTPUT_CONTROL); + EPD_SendData((EPD_HEIGHT - 1) & 0xFF); + EPD_SendData(((EPD_HEIGHT - 1) >> 8) & 0xFF); + EPD_SendData(0x00); // GD = 0; SM = 0; TB = 0; + EPD_SendCommand(BOOSTER_SOFT_START_CONTROL); + EPD_SendData(0xD7); + EPD_SendData(0xD6); + EPD_SendData(0x9D); + EPD_SendCommand(WRITE_VCOM_REGISTER); + EPD_SendData(0xA8); // VCOM 7C + EPD_SendCommand(SET_DUMMY_LINE_PERIOD); + EPD_SendData(0x1A); // 4 dummy lines per gate + EPD_SendCommand(SET_GATE_TIME); + EPD_SendData(0x08); // 2us per line + EPD_SendCommand(DATA_ENTRY_MODE_SETTING); + EPD_SendData(0x03); // X increment; Y increment + EPD_SetLut(lut_full_update); + //EPD_SetLut(lut_partial_update); + /* EPD hardware init end */ + return 0; +} + +/** + * @brief: put an image buffer to the frame memory. + * this won't update the display. + */ +void EPD_SetFrameMemory( + const unsigned char* image_buffer, + int x, + int y, + int image_width, + int image_height +) { + int x_end; + int y_end; + + if ( + image_buffer == NULL || + x < 0 || image_width < 0 || + y < 0 || image_height < 0 + ) { + return; + } + /* x point must be the multiple of 8 or the last 3 bits will be ignored */ + x &= 0xF8; + image_width &= 0xF8; + if (x + image_width >= EPD_WIDTH) { + x_end = EPD_WIDTH - 1; + } else { + x_end = x + image_width - 1; + } + if (y + image_height >= EPD_HEIGHT) { + y_end = EPD_HEIGHT - 1; + } else { + y_end = y + image_height - 1; + } + EPD_SetMemoryArea(x, y, x_end, y_end); + EPD_SetMemoryPointer(x, y); + EPD_SendCommand(WRITE_RAM); + /* send the image data */ + for (int j = 0; j < y_end - y + 1; j++) { + for (int i = 0; i < (x_end - x + 1) / 8; i++) { + EPD_SendData(image_buffer[i + j * (image_width / 8)]); + } + } +} + +/** +* @brief: clear the frame memory with the specified color. +* this won't update the display. +*/ +void EPD_ClearFrameMemory(unsigned char color) { + EPD_SetMemoryArea(0, 0, EPD_WIDTH - 1, EPD_HEIGHT - 1); + EPD_SetMemoryPointer(0, 0); + EPD_SendCommand(WRITE_RAM); + /* send the color data */ + for (int i = 0; i < EPD_WIDTH / 8 * EPD_HEIGHT; i++) { + EPD_SendData(color); + } +} + +/** +* @brief: update the display +* there are 2 memory areas embedded in the e-paper display +* but once this function is called, +* the the next action of SetFrameMemory or ClearFrame will +* set the other memory area. +*/ +void EPD_DisplayFrame() { + EPD_SendCommand(DISPLAY_UPDATE_CONTROL_2); + EPD_SendData(0xC4); + EPD_SendCommand(MASTER_ACTIVATION); + EPD_SendCommand(TERMINATE_FRAME_READ_WRITE); + EPD_WaitUntilIdle(); +} + +/** + * @brief: After this command is transmitted, the chip would enter the + * deep-sleep mode to save power. + * The deep sleep mode would return to standby by hardware reset. + * You can use EPD_Init() to awaken + */ +void EPD_Sleep() { + EPD_SendCommand(DEEP_SLEEP_MODE); + EPD_WaitUntilIdle(); +} + +void setChar(char chr, int x, int y, unsigned char color){ + unsigned char arr[8]; + memcpy(arr, (unsigned char*)&(FONT8x8[chr - 0x1F][0]), 8); + + if(color==0){ + for(int i=0;i<8;i++){ + arr[i]=~arr[i]; + } + } + + EPD_SetFrameMemory(arr,x,y,8,8); +} + +void setString(char *str, int len, int x, int y, unsigned char color){ + for (int i=0;i<len;i++) { + if(str[i]=='\n' && i<len-1){y+=8;i++;x-=i*8;} + setChar(str[i], x+i*8, y, color); + } +} + +int main() { + confSysClock(); + spi.format(8,0); + spi.frequency(4000000); + + EPD_Init(); + + //EPD_ClearFrameMemory(BACKGROUND_WHITE); + //EPD_DisplayFrame(); + setString("Alexander\nSemion",16,0,0,0); + EPD_DisplayFrame(); + /*unsigned char arr[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + EPD_SetFrameMemory((unsigned char*)&(FONT8x8['S' - 0x1F][0]),0,0,8,8); + EPD_SetFrameMemory((unsigned char*)&(FONT8x8['P' - 0x1F][0]),8,0,8,8); + EPD_SetFrameMemory((unsigned char*)&(FONT8x8['I' - 0x1F][0]),16,0,8,8); + EPD_SetFrameMemory((unsigned char*)&(FONT8x8['N' - 0x1F][0]),24,0,8,8); + EPD_SetFrameMemory((unsigned char*)&(FONT8x8['7' - 0x1F][0]),32,0,8,8); + EPD_SetFrameMemory((unsigned char*)&(FONT8x8['I' - 0x1F][0]),40,0,8,8); + EPD_SetFrameMemory((unsigned char*)&(FONT8x8['O' - 0x1F][0]),48,0,8,8); + EPD_SetFrameMemory((unsigned char*)&(FONT8x8['N' - 0x1F][0]),56,0,8,8); + EPD_DisplayFrame();*/ + /* + while(1){ + myled1 = 1; + wait_ms(1000); + myled1 = 0; + wait_ms(1000); + }*/ +} \ No newline at end of file
diff -r 000000000000 -r 1d2c0afef43c mbed-STM32F103C8T6.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-STM32F103C8T6.lib Fri Dec 29 22:35:18 2017 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/users/hudakz/code/mbed-STM32F103C8T6/#727468adfd1d
diff -r 000000000000 -r 1d2c0afef43c mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Dec 29 22:35:18 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e7ca05fa8600 \ No newline at end of file