/** @filename : epd5in83.h @brief : Header file for e-paper library epd5in83.cpp @author : MyMX from Waveshare Copyright (C) Waveshare April 6 2018 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 #include "epd5in83.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(void) { if (IfInit() != 0) { return -1; } Reset(); SendCommand(POWER_SETTING); SendData(0x37); SendData(0x00); SendCommand(PANEL_SETTING); SendData(0xCF); SendData(0x08); SendCommand(BOOSTER_SOFT_START); SendData(0xc7); SendData(0xcc); SendData(0x28); SendCommand(POWER_ON); WaitUntilIdle(); SendCommand(PLL_CONTROL); SendData(0x3c); SendCommand(TEMPERATURE_CALIBRATION); SendData(0x00); SendCommand(VCOM_AND_DATA_INTERVAL_SETTING); SendData(0x77); SendCommand(TCON_SETTING); SendData(0x22); SendCommand(TCON_RESOLUTION); SendData(width >> 8); //source 640 SendData(width & 0xff); SendData(height >> 8); //gate 384 SendData(height & 0xff); SendCommand(VCM_DC_SETTING); SendData(0x1E); //decide by LUT file SendCommand(0xe5); //FLASH MODE SendData(0x03); 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 HIGH */ void Epd::WaitUntilIdle(void) { while (DigitalRead(busy_pin) == 0) { //0: busy, 1: idle DelayMs(100); } } /** @brief: module reset. often used to awaken the module in deep sleep, see Epd::Sleep(); */ void Epd::Reset(void) { DigitalWrite(reset_pin, LOW); //module reset DelayMs(200); DigitalWrite(reset_pin, HIGH); DelayMs(200); } void Epd::DisplayFrame(const unsigned char* frame_buffer) { unsigned char temp1, temp2; unsigned int n; SendCommand(DATA_START_TRANSMISSION_1); for (long i = 0; i