diff --git a/src/bb_ep.inl b/src/bb_ep.inl index 4c4f0b6..6cffe38 100644 --- a/src/bb_ep.inl +++ b/src/bb_ep.inl @@ -17,6 +17,26 @@ // #ifndef __BB_EP__ #define __BB_EP__ +// forward declarations +void InvertBytes(uint8_t *pData, uint8_t bLen); + +const uint8_t ucMirror[256] PROGMEM = +{0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, + 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, + 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, + 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252, + 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, + 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, + 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246, + 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254, + 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241, + 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, + 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, + 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, + 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, + 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251, + 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, + 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255}; const uint8_t epd35r_init_sequence_full[] PROGMEM = { 0x01, 0x12, // SW RESET @@ -36,12 +56,12 @@ const uint8_t epd35r_init_sequence_full[] PROGMEM = { // init sequence for GDEW042Z15 const uint8_t epd42r2_init_sequence_full[] PROGMEM = { 0x03, UC8151_PSR, 0xcf, 0x8d, - 0x06, UC8151_PWR, 0x03, 0x10, 0x3f, 0x3f, 0x0d, + 0x06, UC8151_PWR, 0x03, 0x10, 0x3f, 0x3f, 0x0d, 0x01, UC8151_PON, // power on BUSY_WAIT, 0x05, UC8151_TRES, 0x01, 0x90, 1, 0x2c, // resolution 0x04, UC8151_BTST, 0x17,0x17,0x17, // booster soft-start config - START_10MS | STRENGTH_3 | OFF_6_58US -// 0x02, 0x00, 0x0f, // LUT from OTP + // 0x02, 0x00, 0x0f, // LUT from OTP 0x02, UC8151_CDI, 0x5c, // inverted, white border 0x00 }; @@ -81,7 +101,7 @@ const uint8_t epd37xx_init_sequence_full[] PROGMEM = { 0x01, UC8151_PON, // power on BUSY_WAIT, 0x04, UC8151_TRES, 0xf0, 1, 0xa0, // resolution - + 0x04, UC8151_BTST, 0x17,0x17,0x17, // booster soft-start config - START_10MS | STRENGTH_3 | OFF_6_58US 0x02, UC8151_PFS, 0x00, // FRAMES_1 0x02, UC8151_TSE, 0x00, // TEMP_INTERNAL | OFFSET_0 @@ -174,64 +194,64 @@ const uint8_t epd154r_init_sequence_full[] PROGMEM = { const uint8_t epd75_init_sequence_partial[] PROGMEM = { 0x06, UC8151_PWR, 0x17, 0x17, 0x3f, 0x3f, 0x11, 0x02, 0x82, 0x26, // VCOM DC - // 0x05, UC8151_BTST, 0x27,0x27,0x2f,0x17, - // 0x02, 0x30, 0x06, // oscillator + // 0x05, UC8151_BTST, 0x27,0x27,0x2f,0x17, + // 0x02, 0x30, 0x06, // oscillator 0x01, UC8151_PON, // power on BUSY_WAIT, 0x02, UC8151_PSR, 0x3f, // from register - // 0x05, 0x61, 0x03, 0x20, 0x01, 0xe0, // resolution - // 0x02, 0x15, 0x00, // SPI mode + // 0x05, 0x61, 0x03, 0x20, 0x01, 0xe0, // resolution + // 0x02, 0x15, 0x00, // SPI mode 0x03, 0x50, 0x39, 0x07, // VCOM Data interval - // 0x02, 0x60, 0x22, // TCON - // 0x05, 0x65, 0x00, 0x00, 0x00, 0x00, // resolution -//#ifdef FUTURE -// 0x02, UC8151_PLL, 0x3a, // HZ_100 -// 0x02, UC8151_VDCS, 0x12, // VCOM DC setting -// 0x02, UC8151_CDI, 0x97, + // 0x02, 0x60, 0x22, // TCON + // 0x05, 0x65, 0x00, 0x00, 0x00, 0x00, // resolution + //#ifdef FUTURE + // 0x02, UC8151_PLL, 0x3a, // HZ_100 + // 0x02, UC8151_VDCS, 0x12, // VCOM DC setting + // 0x02, UC8151_CDI, 0x97, 0x2d, UC8151_LUT_VCOM, // VCOM LUT - 0x00, 30, 5, 30, 5, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - ,0x00, 0x00, + 0x00, 30, 5, 30, 5, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + ,0x00, 0x00, 0x2b, UC8151_LUT_WW, // WW LUT - 0x00, 30, 5, 30, 5, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 30, 5, 30, 5, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, UC8151_LUT_BW, - 0x5a, 30, 5, 30, 5, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x5a, 30, 5, 30, 5, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, UC8151_LUT_WB, - 0x84, 30, 5, 30, 5, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x84, 30, 5, 30, 5, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, UC8151_LUT_BB, - 0x00, 30, 5, 30, 5, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 30, 5, 30, 5, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, UC8151_LUT_VCOM2, 0x00, 30, 5, 30, 5, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -//#endif // FUTURE + //#endif // FUTURE 0x00 // end of table }; // 1.54" 152x152 @@ -254,25 +274,25 @@ const uint8_t epd154a_init_sequence_part[] PROGMEM = 2, UC8151_VDCS, 0x12, 2, UC8151_CDI, 0x17, // VCOM 37, 0x20, 0x00, 10, 0, 60, 10, 1, // VCOM LUT - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, 37, 0x21, 0x00, 10, 0, 60, 10, 1, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, 37, 0x22, 0x5a, 10, 0, 60, 10, 1, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, 37, 0x23, 0x84, 10, 0, 60, 10, 1, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, 37, 0x24, 0x00, 10, 0, 60, 10, 1, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0, 0 }; @@ -287,7 +307,7 @@ const uint8_t epd154_init_sequence_full[] PROGMEM = 0x05, 0x45, 0x00, 0x00, 0xc7, 0x00, 0x02, 0x3c, 0x05, // border waveform 0x02, 0x18, 0x80, // read temp sensor -// 0x03, 0x21, 0x00, 0x80, // display update control + // 0x03, 0x21, 0x00, 0x80, // display update control 0x02, 0x4e, 0x00, 0x03, 0x4f, 0x00, 0x00, BUSY_WAIT, @@ -307,14 +327,14 @@ const uint8_t epd154_init_sequence_part[] PROGMEM = // partial (no flash) updates const uint8_t epd154b_init_sequence_part[] PROGMEM = -{ - 0x02, 0x11, 0x03, - 0x02, 0x3c, 0x80, // border waveform +{ + 0x02, 0x11, 0x03, + 0x02, 0x3c, 0x80, // border waveform 0x03, 0x44, 0x00, 0x18, 0x05, 0x45, 0x00, 0x00, 199, 0x00, - 0x02, 0x4e, 0x00, + 0x02, 0x4e, 0x00, 0x03, 0x4f, 0x00, 0x00, - + 154, 0x32, // LUT 0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x80,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, @@ -334,7 +354,7 @@ const uint8_t epd154b_init_sequence_part[] PROGMEM = 0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x22,0x22,0x22,0x22,0x22,0x22,0x0,0x0,0x0, - + 2, 0x3f, 0x2, // ?? 2, 0x03, 0x17, // gate voltage 4, 0x04, 0x41, 0xb0, 0x32, // source voltage @@ -374,11 +394,11 @@ const uint8_t epd213b_init_sequence_part[] PROGMEM = }; const uint8_t epd294_init_sequence_full[] PROGMEM = -{ -// 0x02, 0x74, 0x54, -// 0x02, 0x7e, 0x3b, -// 0x03, 0x2b, 0x04, 0x63, -// 0x05, 0x0c, 0x8f, 0x8f, 0x8f, 0x3f, +{ + // 0x02, 0x74, 0x54, + // 0x02, 0x7e, 0x3b, + // 0x03, 0x2b, 0x04, 0x63, + // 0x05, 0x0c, 0x8f, 0x8f, 0x8f, 0x3f, 0x04, 0x01, 0x27, 0x01, 0x00, 0x02, 0x11, 0x03, 0x03, 0x44, 0x00, 0x0f, @@ -396,27 +416,27 @@ const uint8_t epd294_init_sequence_full[] PROGMEM = const uint8_t epd102_init_sequence_full[] PROGMEM = { - 2, 0x00, 0x5f, // panel setting - 3, 0x2a, 0x00, 0x00, // IC hidden instructions - 1, 0x04, // power on - BUSY_WAIT, - 2, 0x50, 0x97, // VCOM - 0 + 2, 0x00, 0x5f, // panel setting + 3, 0x2a, 0x00, 0x00, // IC hidden instructions + 1, 0x04, // power on + BUSY_WAIT, + 2, 0x50, 0x97, // VCOM + 0 }; const uint8_t epd102_init_sequence_part[] PROGMEM = { - 0x2, 0xd2, 0x3f, - 0x2, 0x00, 0x6f, // panel setting - 0x5, 0x01, 0x03, 0x00, 0x26, 0x26, // power - 0x2, 0x06, 0x3f, - 0x3, 0x2a, 0x00, 0x00, - 0x2, 0x30, 0x13, // 50Hz - 0x2, 0x50, 0xf2, - 0x2, 0x60, 0x22, - 0x2, 0x82, 0x12, // -0.1v - 0x2, 0xe3, 0x33, -// send LUTs - 43, 0x23, // white + 0x2, 0xd2, 0x3f, + 0x2, 0x00, 0x6f, // panel setting + 0x5, 0x01, 0x03, 0x00, 0x26, 0x26, // power + 0x2, 0x06, 0x3f, + 0x3, 0x2a, 0x00, 0x00, + 0x2, 0x30, 0x13, // 50Hz + 0x2, 0x50, 0xf2, + 0x2, 0x60, 0x22, + 0x2, 0x82, 0x12, // -0.1v + 0x2, 0xe3, 0x33, + // send LUTs + 43, 0x23, // white 0x60 ,0x01 ,0x01 ,0x00 ,0x00 ,0x01 , 0x80 ,0x0f ,0x00 ,0x00 ,0x00 ,0x01 , 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , @@ -424,7 +444,7 @@ const uint8_t epd102_init_sequence_part[] PROGMEM = 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , - 43, 0x24, // black + 43, 0x24, // black 0x90 ,0x01 ,0x01 ,0x00 ,0x00 ,0x01 , 0x40 ,0x0f ,0x00 ,0x00 ,0x00 ,0x01 , 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , @@ -432,23 +452,23 @@ const uint8_t epd102_init_sequence_part[] PROGMEM = 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , - 0x1, 0x4, // power on - BUSY_WAIT, - 0 + 0x1, 0x4, // power on + BUSY_WAIT, + 0 }; const uint8_t epd122_init_sequence_full[] PROGMEM = { 0x01, SSD1608_SW_RESET, BUSY_WAIT, - + 0x04, 0x01, 0xaf, 0x00, 0x00, // driver output control 0x02, 0x11, 0x03, // data entry mode 0x03, 0x44, 0x00, 0x17, // ram start/end 0x05, 0x45, 0x00, 0x00, 0xbf, 0x00, 0x02, 0x3c, 0x05, // border waveform 0x02, 0x18, 0x80, // read built-in temp sensor - + 0x02, 0x4e, 0x00, 0x03, 0x4f, 0x00, 0x00, BUSY_WAIT, @@ -459,7 +479,7 @@ const uint8_t epd122_init_sequence_fast[] PROGMEM = { 0x01, SSD1608_SW_RESET, BUSY_WAIT, - + 0x02, 0x11, 0x03, // data entry mode 0x02, 0x18, 0x80, // read built-in temp sensor 0x02, 0x22, 0xb1, // load temp value @@ -492,7 +512,7 @@ const uint8_t epd293_init_sequence_full[] PROGMEM = { 0x01, SSD1608_SW_RESET, BUSY_WAIT, - + 0x04, 0x01, 0x27, 0x01, 0x00, // driver output control 0x02, 0x11, 0x03, // data entry mode 0x03, 0x44, 0x00, 0x0f, // ram start/end @@ -500,7 +520,7 @@ const uint8_t epd293_init_sequence_full[] PROGMEM = 0x02, 0x3c, 0xc0, // border waveform 0x03, 0x21, 0x00, 0x80, // display update control 0x02, 0x18, 0x80, // read built-in temp sensor - + 0x02, 0x4e, 0x00, 0x03, 0x4f, 0x00, 0x00, BUSY_WAIT, @@ -542,14 +562,14 @@ const uint8_t epd293_init_sequence_part[] PROGMEM = // partial (no flash) updates const uint8_t epd295_init_sequence_part[] PROGMEM = -{ - 0x02, 0x11, 0x03, +{ + 0x02, 0x11, 0x03, 0x02, 0x3c, 0x80, // border waveform 0x03, 0x44, 0x00, 0x0f, 0x05, 0x45, 0x00, 0x00, 0x27, 0x01, 0x02, 0x4e, 0x00, 0x03, 0x4f, 0x00, 0x00, - + 91, 0x32, // LUT 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -564,15 +584,15 @@ const uint8_t epd295_init_sequence_part[] PROGMEM = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - + 0x00 // end of table -}; +}; const uint8_t epd266_init_sequence_full[] PROGMEM = { 0x01, SSD1608_SW_RESET, BUSY_WAIT, - + 0x04, 0x01, 0x27, 0x01, 0x00, // driver output control 0x02, 0x11, 0x03, // data entry mode 0x03, 0x44, 0x00, 0x12, // ram start/end @@ -580,7 +600,7 @@ const uint8_t epd266_init_sequence_full[] PROGMEM = 0x02, 0x3c, 0x05, // border waveform 0x03, 0x21, 0x00, 0x80, // display update control 0x02, 0x18, 0x80, // read built-in temp sensor - + 0x02, 0x4e, 0x00, 0x03, 0x4f, 0x00, 0x00, BUSY_WAIT, @@ -604,7 +624,7 @@ const uint8_t epd266_init_sequence_part[] PROGMEM = 0x05, 0x45, 0x00, 0x00, 0x27, 0x01, 0x02, 0x4e, 0x00, 0x03, 0x4f, 0x00, 0x00, - + 0x00 // end of table }; @@ -637,10 +657,10 @@ const uint8_t epd27_init_sequence_part[] PROGMEM = }; const uint8_t epd42b_init_sequence_full[] PROGMEM = -{ +{ 0x01, SSD1608_SW_RESET, BUSY_WAIT, - + 0x04, 0x01, 0x2b, 0x01, 0x00, // driver output control 0x03, 0x21, 0x40, 0x00, // display update control 0x02, 0x11, 0x03, // data entry mode @@ -648,7 +668,7 @@ const uint8_t epd42b_init_sequence_full[] PROGMEM = 0x05, 0x45, 0x00, 0x00, 0x2b, 0x01, 0x02, 0x3c, 0x05, // border waveform 0x02, 0x18, 0x80, // read built-in temp sensor - + 0x02, 0x4e, 0x00, 0x03, 0x4f, 0x00, 0x00, BUSY_WAIT, @@ -759,32 +779,15 @@ const uint8_t epd213_122x250_init_sequence_part[] PROGMEM = { 0 }; -const uint8_t epd75_init_sequence_full[] PROGMEM = { - 6, UC8151_PWR, 0x07, 0x07, 0x3f, 0x3f, 0x03, - 1, UC8151_PON, - BUSY_WAIT, - 2, UC8151_PSR, 0x1f, - 5, UC8151_TRES, 0x03, 0x20, 0x01, 0xe0, - 2, 0x15, 0x00, - 3, UC8151_CDI, 0x29, 0x07, - 2, UC8151_TCON, 0x22, -// 4, UC8151_BTST, 0x17, 0x17, 0x17, -// 2, UC8151_PFS, 0x00, -// 2, UC8151_TSE, 0x00, -// 2, UC8151_PLL, 0x3a, -// 2, UC8151_VDCS, 0x12, - 0 -}; - const uint8_t epd75_init_sequence_fast[] PROGMEM = { - 2, 0x00, 0x1f, // panel setting - 3, 0x50, 0x10, 0x07, // VCOM - 1, 0x04, // Power On - BUSY_WAIT, - 5, 0x06, 0x27, 0x27, 0x18, 0x17, // booster soft start - 2, 0xe0, 0x02, - 2, 0xe5, 0x5a, - 0 + 2, 0x00, 0x1f, // panel setting + 3, 0x50, 0x10, 0x07, // VCOM + 1, 0x04, // Power On + BUSY_WAIT, + 5, 0x06, 0x27, 0x27, 0x18, 0x17, // booster soft start + 2, 0xe0, 0x02, + 2, 0xe5, 0x5a, + 0 }; const uint8_t epd583_init_sequence_full[] PROGMEM = { @@ -818,46 +821,46 @@ const uint8_t epd583_init_sequence_part[] PROGMEM = { 2, 0x82, 0x12, // vcom_DC 2, 0x50, 0x47, // mode 45, 0x20, // VCOM LUT - 0x00, 0x01, 0x20, 0x01, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x20, 0x01, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43, 0x21, // WW LUT - 0x00, 0x01, 0x20, 0x01, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x20, 0x01, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43, 0x22, // BW LUT - 0x20, 0x01, 0x20, 0x01, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x01, 0x20, 0x01, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43, 0x23, // WB LUT - 0x10, 0x01, 0x20, 0x01, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x01, 0x20, 0x01, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43, 0x24, // BB LUT - 0x00, 0x01, 0x20, 0x01, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - + 0x00, 0x01, 0x20, 0x01, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00 // end of table }; @@ -885,64 +888,64 @@ const uint8_t epd42_init_sequence_part[] PROGMEM = { 2, 0x82, 0x12, // vcom_DC 2, 0x50, 0x47, // mode 45, 0x20, // VCOM LUT - 0x00, 0x01, 0x20, 0x01, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x20, 0x01, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43, 0x21, // WW LUT - 0x00, 0x01, 0x20, 0x01, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x20, 0x01, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43, 0x22, // BW LUT - 0x20, 0x01, 0x20, 0x01, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x01, 0x20, 0x01, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43, 0x23, // WB LUT - 0x10, 0x01, 0x20, 0x01, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x01, 0x20, 0x01, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43, 0x24, // BB LUT - 0x00, 0x01, 0x20, 0x01, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - + 0x00, 0x01, 0x20, 0x01, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00 // end of table }; const uint8_t epd294_init_sequence_part[] = { - 0x0b, 0x37, 0,0,0,0,0,0x40,0,0,0,0, + 0x0b, 0x37, 0,0,0,0,0,0x40,0,0,0,0, 0x04, 0x01, 0x27, 0x01, 0x00, 0x02, 0x11, 0x01, 0x03, 0x44, 0x00, 0x0f, 0x05, 0x45, 0x00, 0x00, 0x27, 0x01, 0x03, 0x21, 0x00, 0x80, 0x02, 0x3c, 0xc0, - 0x02, 0x22, 0xc0, - 0x01, 0x20, - BUSY_WAIT, - 0x02, 0x4e, 0x00, - 0x03, 0x4f, 0x00, 0x00, - 0x00 // end of sequence + 0x02, 0x22, 0xc0, + 0x01, 0x20, + BUSY_WAIT, + 0x02, 0x4e, 0x00, + 0x03, 0x4f, 0x00, 0x00, + 0x00 // end of sequence }; /* epd294_init_sequence_part */ const uint8_t epd213_inky_init_sequence_full[] PROGMEM = { @@ -955,7 +958,23 @@ const uint8_t epd213_inky_init_sequence_full[] PROGMEM = { 2, 0x30, 0x29, 4, UC8151_TRES, 104, 0, 212, 2, 0x82, 0x0a, - + + 0 +}; +const uint8_t epd75_init_sequence_full[] PROGMEM = { + 6, UC8151_PWR, 0x07, 0x07, 0x3f, 0x3f, 0x03, + 1, UC8151_PON, + BUSY_WAIT, + 2, UC8151_PSR, 0x1f, + 5, UC8151_TRES, 0x03, 0x20, 0x01, 0xe0, + 2, 0x15, 0x00, + 3, UC8151_CDI, 0x29, 0x07, + 2, UC8151_TCON, 0x22, + // 4, UC8151_BTST, 0x17, 0x17, 0x17, + // 2, UC8151_PFS, 0x00, + // 2, UC8151_TSE, 0x00, + // 2, UC8151_PLL, 0x3a, + // 2, UC8151_VDCS, 0x12, 0 }; @@ -984,8 +1003,12 @@ const EPD_PANEL panelDefs[] PROGMEM = { {400, 300, epd42r2_init_sequence_full, NULL, NULL, BBEP_3COLOR, BBEP_CHIP_UC81xx}, // EPD42R2_400x300 {240, 416, epd37_init_sequence_full, NULL, epd37_init_sequence_part, 0, BBEP_CHIP_UC81xx}, // EPD37_240x416 {104, 212, epd213_inky_init_sequence_full, NULL, NULL, 0, BBEP_CHIP_UC81xx}, // EPD213_104x212 InkyPHAT black and white + {800, 480, epd75_init_sequence_full, epd75_init_sequence_fast, epd75_init_sequence_partial, 0, BBEP_CHIP_UC81xx}, // EPD37_240x416 }; - +// +// Set the e-paper panel type +// This must be called before any other bb_epaper functions +// int bbepSetPanelType(BBEPDISP *pBBEP, int iPanel) { if (pBBEP == NULL || iPanel <= EPD_PANEL_UNDEFINED || iPanel >= EPD_PANEL_COUNT) @@ -1005,33 +1028,38 @@ int bbepSetPanelType(BBEPDISP *pBBEP, int iPanel) // // Toggle the reset line to wake up the eink from deep sleep -// +// void bbepWakeUp(BBEPDISP *pBBEP) { + if (!pBBEP) return; digitalWrite(pBBEP->iRSTPin, LOW); delay(10); digitalWrite(pBBEP->iRSTPin, HIGH); - delay(10); + delay(10); } /* bbepWakeUp() */ -// +// // Wait for the busy status line to show idle // The polarity of the busy signal is reversed on the UC81xx compared // to the SSD16xx controllers // void bbepWaitBusy(BBEPDISP *pBBEP) { + if (!pBBEP) return; uint8_t busy_idle = (pBBEP->chip_type == BBEP_CHIP_UC81xx) ? HIGH : LOW; delay(1); // some panels need a short delay before testing the BUSY line while (1) { if (digitalRead(pBBEP->iBUSYPin) == busy_idle) break; } } /* bbepWaitBusy() */ - +// +// Set the memory window for future writes into panel memory +// void bbepSetAddrWindow(BBEPDISP *pBBEP, int x, int y, int cx, int cy) { uint8_t uc[12]; int i, tx, ty; + if (!pBBEP) return; tx = x/8; // round down to next lower byte ty = y; cx = (cx + 7) & 0xfff8; // make width an even number of bytes @@ -1062,33 +1090,34 @@ void bbepSetAddrWindow(BBEPDISP *pBBEP, int x, int y, int cx, int cy) bbepWriteData(pBBEP, uc, i); // EPDWriteCmd(UC8151_PTOU); // partial out } else { // SSD16xx -// bbepCMD2(pBBEP, SSD1608_DATA_MODE, 0x3); + // bbepCMD2(pBBEP, SSD1608_DATA_MODE, 0x3); bbepWriteCmd(pBBEP, SSD1608_SET_RAMXPOS); uc[0] = tx; // start x (byte boundary) uc[1] = tx+((cx-1)>>3); // end x bbepWriteData(pBBEP, uc, 2); - + bbepWriteCmd(pBBEP, SSD1608_SET_RAMYPOS); uc[0] = (uint8_t)ty; // start y uc[1] = (uint8_t)(ty>>8); uc[2] = (uint8_t)(ty+cy-1); // end y uc[3] = (uint8_t)((ty+cy-1)>>8); bbepWriteData(pBBEP, uc, 4); - + // set ram counter to start of this region bbepCMD2(pBBEP, SSD1608_SET_RAMXCOUNT, tx); uc[0] = ty; uc[1] = (ty>>8); bbepWriteCmd(pBBEP, SSD1608_SET_RAMYCOUNT); bbepWriteData(pBBEP, uc, 2); -// bbepCMD2(pBBEP, SSD1608_DATA_MODE, 0x3); + // bbepCMD2(pBBEP, SSD1608_DATA_MODE, 0x3); } } /* bbepSetAddrWindow() */ -// +// // Put the eink into light or deep sleep -// -void bbepSleep(BBEPDISP *pBBEP, int bDeep) +// +void bbepSleep(BBEPDISP *pBBEP, int bDeep) { + if (!pBBEP) return; if (pBBEP->chip_type == BBEP_CHIP_UC81xx) { bbepCMD2(pBBEP, UC8151_CDI, 0x17); // border floating bbepWriteCmd(pBBEP, UC8151_POFF); // power off @@ -1104,18 +1133,19 @@ void bbepSleep(BBEPDISP *pBBEP, int bDeep) void bbepStartWrite(BBEPDISP *pBBEP, int iPlane) { -uint8_t u8Cmd; - + uint8_t u8Cmd; + + if (!pBBEP) return; if (pBBEP->chip_type == BBEP_CHIP_UC81xx) { - if (iPlane == PLANE_0) - u8Cmd = UC8151_DTM2; - else - u8Cmd = UC8151_DTM1; + if (iPlane == PLANE_0) + u8Cmd = UC8151_DTM2; + else + u8Cmd = UC8151_DTM1; } else { // SSD16xx - if (iPlane == PLANE_0) - u8Cmd = SSD1608_WRITE_RAM; - else - u8Cmd = SSD1608_WRITE_ALTRAM; + if (iPlane == PLANE_0) + u8Cmd = SSD1608_WRITE_RAM; + else + u8Cmd = SSD1608_WRITE_ALTRAM; } bbepWriteCmd(pBBEP, u8Cmd); } /* bbepStartWrite() */ @@ -1125,13 +1155,13 @@ uint8_t u8Cmd; // void bbepSendCMDSequence(BBEPDISP *pBBEP, const uint8_t *pSeq) { -int iLen; -uint8_t *s; + int iLen; + uint8_t *s; if (pBBEP == NULL || pSeq == NULL) return; s = (uint8_t *)pSeq; - while (s[0] != 0) { + while (s[0] != 0) { // A 0 length terminates the list iLen = *s++; if (iLen == BUSY_WAIT) { bbepWaitBusy(pBBEP); @@ -1139,8 +1169,8 @@ uint8_t *s; bbepWriteCmd(pBBEP, s[0]); s++; if (iLen > 1) { - bbepWriteData(pBBEP, s, iLen-1); - s += (iLen-1); + bbepWriteData(pBBEP, s, iLen-1); + s += (iLen-1); } } } // while more commands to send @@ -1154,9 +1184,9 @@ uint8_t *s; // void bbepFill(BBEPDISP *pBBEP, unsigned char ucData, int iPlane) { -uint8_t uc1=0, uc2=0; -int y, iSize, iPitch; -uint8_t ucCMD1, ucCMD2; + uint8_t uc1=0, uc2=0; + int y, iSize, iPitch; + uint8_t ucCMD1, ucCMD2; if (pBBEP == NULL) return; @@ -1248,7 +1278,7 @@ void bbepSetRotation(BBEPDISP *pBBEP, int iRotation) { pBBEP->iScreenOffset = 0; pBBEP->iOrientation = iRotation; - + switch (iRotation) { default: return; case 0: @@ -1267,123 +1297,91 @@ void bbepSetRotation(BBEPDISP *pBBEP, int iRotation) pBBEP->width = pBBEP->native_height; pBBEP->height = pBBEP->native_width; break; - } + } } /* bbepSetRotation() */ // -// Write EPD Image data +// Write Image data (entire plane) from RAM to the e-paper +// Rotate the pixels if necessary // -static void bbepWriteImage(BBEPDISP *pBBEP, uint8_t ucCMD, uint8_t *pBits, int x, int y, int w, int h, int bInvert) +static void bbepWriteImage(BBEPDISP *pBBEP, uint8_t ucCMD, uint8_t *pBits, int bInvert) { -int tx, ty; -uint8_t *s, *d, ucSrcMask, ucDstMask, uc; -uint8_t *pBuffer, ucInvert = 0; -int iPitch; + int tx, ty; + uint8_t *s, *d, ucSrcMask, ucDstMask, uc; + uint8_t *pBuffer, ucInvert = 0; + int iPitch; - if (pBits == NULL) { // use back buffer - pBuffer = pBBEP->ucScreen; - iPitch = pBBEP->width; - } else { - // assume the passed buffer is only the size and width of the requested write - pBuffer = pBits; - iPitch = w; - } - if (bInvert) {// use second bit plane - //pBuffer += pBBEP->width * ((pBBEP->height+7)/8); + iPitch = (pBBEP->width + 7) >> 3; + if (bInvert) { ucInvert = 0xff; // red logic is inverted } if (ucCMD) { bbepWriteCmd(pBBEP, ucCMD); // start write } - // Convert the bit direction and write the data to the EPD - u8Cache[0] = u8Cache[1] = 0; // prefix for IT8951 - if (pBBEP->iOrientation == 180) { - for (ty=y+h-1; ty>=y; ty--) { - ucSrcMask = 1 << (ty & 7); - ucDstMask = 0x80; - uc = 0xff; - d = u8Cache+2; - s = &pBuffer[(ty>>3) * iPitch]; - for (tx=x+w-1; tx>=x; tx--) { - if (s[tx] & ucSrcMask) - uc &= ~ucDstMask; - ucDstMask >>= 1; - if (ucDstMask == 0) { - *d++ = (uc ^ ucInvert); - uc = 0xff; - ucDstMask = 0x80; - } - } // for tx - *d++ = uc; // store final partial byte - bbepWriteData(pBBEP, u8Cache+2, (w+7)/8); - } // for ty - } else if (pBBEP->iOrientation == 0) { - for (ty=y; ty> 3) * iPitch]; - for (tx=x; tx>= 1; - if (ucDstMask == 0) { // completed byte - *d++ = (uc ^ ucInvert); - uc = 0xff; - ucDstMask = 0x80; - } - } // for tx - *d++ = (uc ^ ucInvert); // store final partial byte - bbepWriteData(pBBEP, u8Cache+2, (w+7)/8); - } // for ty - } else if (pBBEP->iOrientation == 90) { - for (tx=x; tx=y; ty--) { - s = &pBuffer[tx + (ty>>3) * iPitch]; - if (s[0] & ucSrcMask) uc &= ~ucDstMask; - ucDstMask >>= 1; - ucSrcMask >>= 1; - if (ucDstMask == 0) { - *d++ = (uc ^ ucInvert); - ucDstMask = 0x80; - uc = 0xff; - } - if (ucSrcMask == 0) - ucSrcMask = 0x80; // bottom up - } // for ty - *d++ = (uc ^ ucInvert); // store final partial byte - bbepWriteData(pBBEP, u8Cache+2, (h+7)/8); - } // for tx - } else if (pBBEP->iOrientation == 270) { - for (tx=x+w-1; tx>=x; tx--) { - d = u8Cache+2; - // reassemble every pixel - ucDstMask = 0x80; - uc = 0xff; - ucSrcMask = 1 << (y & 7); - for (ty=y; ty>3) * iPitch]; - if (s[0] & ucSrcMask) uc &= ~ucDstMask; - ucDstMask >>= 1; - ucSrcMask <<= 1; - if (ucDstMask == 0) { - *d++ = (uc ^ ucInvert); - ucDstMask = 0x80; - uc = 0xff; - } - if (ucSrcMask == 0) - ucSrcMask = 1; - } // for ty - *d++ = (uc ^ ucInvert); // store final partial byte - bbepWriteData(pBBEP, u8Cache+2, (h+7)/8); - } // for x - } // 270 + // Convert the bit direction and write the data to the EPD + switch (pBBEP->iOrientation) { + case 0: + for (ty=0; tynative_height; ty++) { + d = u8Cache; + s = &pBuffer[ty * iPitch]; + memcpy(d, s, iPitch); + if (ucInvert) InvertBytes(d, iPitch); + bbepWriteData(pBBEP, u8Cache, iPitch); + } // for ty + break; + case 90: + for (tx=0; txwidth; tx++) { + d = u8Cache; + // need to pick up and reassemble every pixel + ucDstMask = 0x80; + uc = 0xff; + ucSrcMask = 0x80 >> (tx & 7); + for (ty=pBBEP->height-1; ty>=0; ty--) { + s = &pBuffer[(tx >> 3) + (ty * iPitch)]; + if (s[0] & ucSrcMask) uc &= ~ucDstMask; + ucDstMask >>= 1; + if (ucDstMask == 0) { + *d++ = (uc ^ ucInvert); + ucDstMask = 0x80; + uc = 0xff; + } + } // for ty + *d++ = (uc ^ ucInvert); // store final partial byte + bbepWriteData(pBBEP, u8Cache, (pBBEP->native_width+7)/8); + } // for tx + break; + case 180: + for (ty=pBBEP->native_height-1; ty>=0; ty--) { + d = u8Cache; + s = &pBuffer[ty * iPitch]; + for (tx=iPitch-1; tx>=0; tx--) { + *d++ = (ucMirror[s[tx]] & ucInvert); + } // for tx + bbepWriteData(pBBEP, u8Cache, iPitch); + } // for ty + break; + case 270: + for (tx=pBBEP->width-1; tx>=0; tx--) { + d = u8Cache; + // reassemble every pixel + ucDstMask = 0x80; + uc = 0xff; + ucSrcMask = 0x80 << (tx & 7); + for (ty=0; tyheight; ty++) { + s = &pBuffer[(tx>>3) + (ty * iPitch)]; + if (s[0] & ucSrcMask) uc &= ~ucDstMask; + ucDstMask >>= 1; + if (ucDstMask == 0) { + *d++ = (uc ^ ucInvert); + ucDstMask = 0x80; + uc = 0xff; + } + } // for ty + *d++ = (uc ^ ucInvert); // store final partial byte + bbepWriteData(pBBEP, u8Cache, (pBBEP->native_width+7)/8); + } // for x + break; + } // switch on orientation } /* bbepWriteImage() */ // // Write the local copy of the memory plane(s) to the eink's internal framebuffer @@ -1393,7 +1391,7 @@ int bbepWritePlane(BBEPDISP *pBBEP, int iPlane) uint8_t ucCMD1, ucCMD2; int iOffset; - if (pBBEP == NULL || iPlane < PLANE_0 || iPlane > PLANE_DUPLICATE) + if (pBBEP == NULL || pBBEP->ucScreen == NULL || iPlane < PLANE_0 || iPlane > PLANE_DUPLICATE) return BBEP_ERROR_BAD_PARAMETER; if (pBBEP->chip_type == BBEP_CHIP_UC81xx) { ucCMD1 = UC8151_DTM1; @@ -1406,18 +1404,18 @@ int bbepWritePlane(BBEPDISP *pBBEP, int iPlane) switch (iPlane) { case PLANE_0: - bbepWriteImage(pBBEP, ucCMD1, pBBEP->ucScreen, 0, 0, pBBEP->width, pBBEP->height, 0); + bbepWriteImage(pBBEP, ucCMD1, pBBEP->ucScreen, 0); break; case PLANE_1: - bbepWriteImage(pBBEP, ucCMD2, &pBBEP->ucScreen[iOffset], 0, 0, pBBEP->width, pBBEP->height, 0); + bbepWriteImage(pBBEP, ucCMD2, &pBBEP->ucScreen[iOffset], 0); break; case PLANE_BOTH: - bbepWriteImage(pBBEP, ucCMD1, pBBEP->ucScreen, 0, 0, pBBEP->width, pBBEP->height, 0); - bbepWriteImage(pBBEP, ucCMD2, &pBBEP->ucScreen[iOffset], 0, 0, pBBEP->width, pBBEP->height, 0); + bbepWriteImage(pBBEP, ucCMD1, pBBEP->ucScreen, 0); + bbepWriteImage(pBBEP, ucCMD2, &pBBEP->ucScreen[iOffset], 0); break; case PLANE_DUPLICATE: - bbepWriteImage(pBBEP, ucCMD1, pBBEP->ucScreen, 0, 0, pBBEP->width, pBBEP->height, 0); - bbepWriteImage(pBBEP, ucCMD2, pBBEP->ucScreen, 0, 0, pBBEP->width, pBBEP->height, 0); + bbepWriteImage(pBBEP, ucCMD1, pBBEP->ucScreen, 0); + bbepWriteImage(pBBEP, ucCMD2, pBBEP->ucScreen, 0); break; } return BBEP_SUCCESS; diff --git a/src/bb_ep_gfx.inl b/src/bb_ep_gfx.inl index c4b3a71..8ae9c7a 100644 --- a/src/bb_ep_gfx.inl +++ b/src/bb_ep_gfx.inl @@ -558,7 +558,7 @@ void bbepSetCursor(BBEPDISP *pBBEP, int x, int y) pBBEP->iCursorY = y; } /* bbepSetCursor() */ // -// Turn text wrap on or off for the oldWriteString() function +// Turn text wrap on or off for the bbepWriteString() function // void bbepSetTextWrap(BBEPDISP *pBBEP, int bWrap) { @@ -705,6 +705,27 @@ void bbepWriteStringCustom(BBEPDISP *pBBEP, BB_FONT *pFont, int x, int y, char * pBBEP->iCursorY = y; } /* EPDWriteStringCustom() */ // +// Rotate an 8x8 pixel block (8 bytes) by 90 degrees +// Used to draw the built-in font at 2 angles +// +void RotateCharBox(uint8_t *pSrc) +{ + int x, y; + uint8_t ucDest[8], uc, ucSrcMask, ucDstMask; + + for (y=0; y<8; y++) { + ucSrcMask = 1<>= 1; + } + ucDest[y] = uc; + } + memcpy(pSrc, ucDest, 8); // rotate "in-place" +} /* RotateCharBox() */ +// // Draw a string of normal (8x8), small (6x8) or large (16x32) characters // At the given col+row // @@ -713,7 +734,7 @@ int bbepWriteString(BBEPDISP *pBBEP, int x, int y, char *szMsg, int iSize, int i int i, iFontOff, iLen; uint8_t c, *s, ucCMD, ucCMD1, ucCMD2; int iOldFG; // old fg color to make sure red works - uint8_t u8Temp[128]; + uint8_t u8Temp[40]; if (pBBEP == NULL) return BBEP_ERROR_BAD_PARAMETER; if (pBBEP->chip_type == BBEP_CHIP_UC81xx) { @@ -743,7 +764,7 @@ int bbepWriteString(BBEPDISP *pBBEP, int x, int y, char *szMsg, int iSize, int i if (iSize == FONT_8x8) // 8x8 font { i = 0; - while (pBBEP->iCursorX < pBBEP->width && szMsg[i] != 0 && pBBEP->iCursorY < pBBEP->height) + while (x < pBBEP->width && szMsg[i] != 0 && y < pBBEP->height) { c = (unsigned char)szMsg[i]; iFontOff = (int)(c-32) * 7; @@ -752,26 +773,41 @@ int bbepWriteString(BBEPDISP *pBBEP, int x, int y, char *szMsg, int iSize, int i memcpy_P(&u8Temp[1], &ucFont[iFontOff], 7); // only needed on AVR if (iColor == BBEP_BLACK) InvertBytes(u8Temp, 8); iLen = 8; - if (pBBEP->iCursorX + iLen > pBBEP->width) { // clip right edge - iLen = pBBEP->width - pBBEP->iCursorX; + if (x + iLen > pBBEP->width) { // clip right edge + iLen = pBBEP->width - x; } if (!pBBEP->ucScreen) { // bufferless mode, rotate the coordinate system to fit the situation - bbepSetAddrWindow(pBBEP, pBBEP->native_width-8-pBBEP->iCursorY, pBBEP->iCursorX, 8, pBBEP->native_height-pBBEP->iCursorX); + if (pBBEP->iOrientation == 0) { // need to rotate the font and bounding box + RotateCharBox(u8Temp); + bbepSetAddrWindow(pBBEP, x, y, 8, 8); + } else { + bbepSetAddrWindow(pBBEP, pBBEP->native_width-8-y, x, 8, pBBEP->native_height-pBBEP->iCursorX); + } bbepWriteCmd(pBBEP, ucCMD); // write to "new" plane bbepWriteData(pBBEP, u8Temp, iLen); } else { // draw in memory #ifndef NO_RAM - // DEBUG + uint8_t u8Mask; + for (int ty=y; tyiCursorX += iLen; - if (pBBEP->iCursorX >= pBBEP->width-7 && pBBEP->wrap) { // word wrap enabled? - pBBEP->iCursorX = 0; // start at the beginning of the next line - pBBEP->iCursorY+=8; + x += iLen; + if (x >= pBBEP->width-7 && pBBEP->wrap) { // word wrap enabled? + x = 0; // start at the beginning of the next line + y += 8; } i++; } // while pBBEP->iFG = iOldFG; // restore color + pBBEP->iCursorX = x; + pBBEP->iCursorY = y; return BBEP_SUCCESS; } else if (iSize == FONT_12x16) { // 6x8 stretched to 12x16 i = 0; @@ -896,14 +932,25 @@ int bbepWriteString(BBEPDISP *pBBEP, int x, int y, char *szMsg, int iSize, int i bbepWriteData(pBBEP, &u8Temp[18], iLen); } else { // write to RAM #ifndef NO_RAM - // DEBUG + uint8_t u8Mask; + for (int ty=y; tyiCursorX += iLen; if (pBBEP->iCursorX >= pBBEP->width-11 && pBBEP->wrap) // word wrap enabled? { - pBBEP->iCursorX = 0; // start at the beginning of the next line - pBBEP->iCursorY += 16; + x = pBBEP->iCursorX = 0; // start at the beginning of the next line + y = pBBEP->iCursorY = y+16; } i++; } // while @@ -929,14 +976,22 @@ int bbepWriteString(BBEPDISP *pBBEP, int x, int y, char *szMsg, int iSize, int i bbepWriteData(pBBEP, u8Temp, iLen); } else { // write to RAM #ifndef NO_RAM - // DEBUG + uint8_t u8Mask; + for (int ty=y; tyiCursorX += iLen; if (pBBEP->iCursorX >= pBBEP->width-5 && pBBEP->wrap) // word wrap enabled? { - pBBEP->iCursorX = 0; // start at the beginning of the next line - pBBEP->iCursorY +=8; + x = pBBEP->iCursorX = 0; // start at the beginning of the next line + y = pBBEP->iCursorY = y+8; } i++; } diff --git a/src/bb_epaper.h b/src/bb_epaper.h index 121c4b7..4d933af 100644 --- a/src/bb_epaper.h +++ b/src/bb_epaper.h @@ -108,6 +108,7 @@ enum { EPD42R2_400x300, // GDEQ042Z21 EPD37_240x416, // GDEY037T03 EPD213_104x212, // InkyPHAT 2.13 black and white + EPD75_800x480, // GDEY075T7 EPD_PANEL_COUNT }; #ifdef FUTURE @@ -130,7 +131,6 @@ enum { EPD37Y_240x416, // DEPG0370YN EPD579_792x272, // GDEY0579T93 EPD583R_600x448, - EPD75_800x480, // GDEY075T7 EPD74R_640x384, EPD583_648x480, // DEPG0583BN EPD29_BWYR_128x296, // GDEY029F51 @@ -332,17 +332,7 @@ class BBEPAPER void setPlane(int iPlane); int getPlane(void); int getChip(void); - void drawSprite(const uint8_t *pSprite, int cx, int cy, int iPitch, int x, int y, uint8_t iColor); -#ifdef FUTURE -// int drawGFX(int x, int y, int cx, int cy, uint8_t *pPlane0, uint8_t *pPlane1); -// void setFreeFont(const BB_FONT *pFont); - void pushBytes(uint8_t *pByte, int iCount); - void writeCommand(uint8_t ucCMD); - void writeRaw(uint8_t *pData, int iLen); - void pushImage(int x, int y, int w, int h, uint16_t *pixels); - void drawString(String text, int x, int y); -#endif // FUTURE - + void drawSprite(const uint8_t *pSprite, int cx, int cy, int iPitch, int x, int y, uint8_t iColor); #ifdef _LINUX_ void print(const char *pString); void println(const char *pString);