| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- /**
- * @filename : epd7in3g.cpp
- * @brief : Implements for e-paper library
- * @author : Waveshare
- *
- * Copyright (C) Waveshare 2022/7/22
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documnetation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- #include <stdlib.h>
- #include "epd7in3g.h"
- Epd::~Epd() {
- };
- Epd::Epd() {
- reset_pin = RST_PIN;
- dc_pin = DC_PIN;
- cs_pin = CS_PIN;
- busy_pin = BUSY_PIN;
- WIDTH = EPD_WIDTH;
- HEIGHT = EPD_HEIGHT;
- };
- int Epd::Init() {
- /* this calls the peripheral hardware interface, see epdif */
- if (IfInit() != 0) {
- return -1;
- }
- Reset();
- ReadBusyH();
- DelayMs(30);
- SendCommand(0xAA);
- SendData(0x49);
- SendData(0x55);
- SendData(0x20);
- SendData(0x08);
- SendData(0x09);
- SendData(0x18);
- SendCommand(0x01);
- SendData(0x3F);
- SendCommand(0x00);
- SendData(0x4F);
- SendData(0x69);
- SendCommand(0x05);
- SendData(0x40);
- SendData(0x1F);
- SendData(0x1F);
- SendData(0x2C);
- SendCommand(0x08);
- SendData(0x6F);
- SendData(0x1F);
- SendData(0x1F);
- SendData(0x22);
- //===================
- //20211212
- //First setting
- SendCommand(0x06);
- SendData(0x6F);
- SendData(0x1F);
- SendData(0x14);
- SendData(0x14);
- //===================
- SendCommand(0x03);
- SendData(0x00);
- SendData(0x54);
- SendData(0x00);
- SendData(0x44);
- SendCommand(0x60);
- SendData(0x02);
- SendData(0x00);
- //Please notice that PLL must be set for version 2 IC
- SendCommand(0x30);
- SendData(0x08);
- SendCommand(0x50);
- SendData(0x3F);
- SendCommand(0x61);
- SendData(0x03);
- SendData(0x20);
- SendData(0x01);
- SendData(0xE0);
- SendCommand(0xE3);
- SendData(0x2F);
- SendCommand(0x84);
- SendData(0x01);
- return 0;
- }
- /**
- * @brief: basic function for sending commands
- */
- void Epd::SendCommand(unsigned char command) {
- DigitalWrite(dc_pin, LOW);
- SpiTransfer(command);
- }
- /**
- * @brief: basic function for sending data
- */
- void Epd::SendData(unsigned char data) {
- DigitalWrite(dc_pin, HIGH);
- SpiTransfer(data);
- }
- /**
- * @brief: Wait until the busy_pin goes LOW
- */
- void Epd::ReadBusyH(void) {
- Serial.print("e-Paper busy H\r\n ");
- while(DigitalRead(busy_pin) == LOW) { //LOW: busy, HIGH: idle
- DelayMs(5);
- }
- Serial.print("e-Paper busy release H\r\n ");
- }
- void Epd::ReadBusyL(void) {
- Serial.print("e-Paper busy L\r\n ");
- while(DigitalRead(busy_pin) == HIGH) { //LOW: idle, HIGH: busy
- DelayMs(5);
- }
- Serial.print("e-Paper busy release L\r\n ");
- }
- /**
- * @brief: module reset.
- * often used to awaken the module in deep sleep,
- * see Epd::Sleep();
- */
- void Epd::Reset(void) {
- DigitalWrite(reset_pin, HIGH);
- DelayMs(20);
- DigitalWrite(reset_pin, LOW); //module reset
- DelayMs(2);
- DigitalWrite(reset_pin, HIGH);
- DelayMs(20);
- }
- /******************************************************************************
- function : Turn On Display
- parameter:
- ******************************************************************************/
- void Epd::TurnOnDisplay(void)
- {
- SendCommand(0x12); // DISPLAY_REFRESH
- SendData(0x01);
- ReadBusyH();
- SendCommand(0x02); // POWER_OFF
- SendData(0X00);
- ReadBusyH();
- }
- /******************************************************************************
- function : Clear screen
- parameter:
- ******************************************************************************/
- void Epd::Clear(UBYTE color)
- {
- UWORD Width, Height;
- Width = (WIDTH % 4 == 0)? (WIDTH / 4 ): (WIDTH / 4 + 1);
- Height = HEIGHT;
- SendCommand(0x68);
- SendData(0x01);
-
- SendCommand(0x04);
- ReadBusyH();
- SendCommand(0x10);
- for (UWORD j = 0; j < Height; j++) {
- for (UWORD i = 0; i < Width; i++) {
- for(UBYTE k = 0; k < 4; k++) {
- SendData(color);
- }
- }
- }
- SendCommand(0x68);
- SendData(0x00);
- TurnOnDisplay();
- }
- /******************************************************************************
- function : Sends the image buffer in RAM to e-Paper and displays
- parameter:
- ******************************************************************************/
- void Epd::Display(UBYTE *Image)
- {
- UWORD Width, Height;
- Width = (WIDTH % 4 == 0)? (WIDTH / 4 ): (WIDTH / 4 + 1);
- Height = HEIGHT;
- SendCommand(0x68);
- SendData(0x01);
-
- SendCommand(0x04);
- ReadBusyH();
- SendCommand(0x10);
- for (UWORD j = 0; j < Height; j++) {
- for (UWORD i = 0; i < Width; i++) {
- SendData(pgm_read_byte(&Image[i + j * Width]));
- }
- }
- TurnOnDisplay();
- }
- void Epd::Display_part(UBYTE *Image, UWORD xstart, UWORD ystart, UWORD image_width, UWORD image_heigh)
- {
- UWORD Width, Height;
- Width = (WIDTH % 4 == 0)? (WIDTH / 4 ): (WIDTH / 4 + 1);
- Height = HEIGHT;
- SendCommand(0x68);
- SendData(0x01);
-
- SendCommand(0x04);
- ReadBusyH();
- SendCommand(0x10);
- for (UWORD i = 0; i < Height; i++) {
- for (UWORD j = 0; j < Width; j++) {
- if((j >= xstart/4) && (j < (image_width + xstart)/4) && (i >= ystart) && (i <= (ystart + image_heigh)) )
- {
- SendData(pgm_read_byte(&Image[(i-ystart) * image_width/4 + j - xstart/4]));
- // Serial.print(Image[(i-ystart) * image_width/8 + j - xstart], HEX);
- // Serial.print(" ");
- }
- else
- {
- SendData(0x55);
- }
- }
- }
- TurnOnDisplay();
- }
- /******************************************************************************
- function : Enter sleep mode
- parameter:
- ******************************************************************************/
- void Epd::Sleep(void)
- {
- SendCommand(0x02); // POWER_OFF
- SendData(0X00);
- SendCommand(0x07); // DEEP_SLEEP
- SendData(0XA5);
- }
- /* END OF FILE */
|