Add initial eink display firmware

This commit is contained in:
Zuckerberg 2023-05-10 22:54:22 -06:00
parent 8a3022477b
commit 7f9e03d4ba
13 changed files with 2333 additions and 10 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
result
.pio

View File

@ -0,0 +1,321 @@
/*****************************************************************************
* | File : EPD_7in3f.c
* | Author : Waveshare team
* | Function : 7.3inch e-Paper (F)
* | Info :
*----------------
* | This version: V1.0
* | Date : 2022-10-21
* | Info :
* -----------------------------------------------------------------------------
#
# 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 "epd7in3f.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;
};
/******************************************************************************
function : Initialize the e-Paper register
parameter:
******************************************************************************/
int Epd::Init(void)
{
if (IfInit() != 0)
{
return -1;
}
Reset();
DelayMs(20);
EPD_7IN3F_BusyHigh();
SendCommand(0xAA); // CMDH
SendData(0x49);
SendData(0x55);
SendData(0x20);
SendData(0x08);
SendData(0x09);
SendData(0x18);
SendCommand(0x01);
SendData(0x3F);
SendData(0x00);
SendData(0x32);
SendData(0x2A);
SendData(0x0E);
SendData(0x2A);
SendCommand(0x00);
SendData(0x5F);
SendData(0x69);
SendCommand(0x03);
SendData(0x00);
SendData(0x54);
SendData(0x00);
SendData(0x44);
SendCommand(0x05);
SendData(0x40);
SendData(0x1F);
SendData(0x1F);
SendData(0x2C);
SendCommand(0x06);
SendData(0x6F);
SendData(0x1F);
SendData(0x1F);
SendData(0x22);
SendCommand(0x08);
SendData(0x6F);
SendData(0x1F);
SendData(0x1F);
SendData(0x22);
SendCommand(0x13); // IPC
SendData(0x00);
SendData(0x04);
SendCommand(0x30);
SendData(0x3C);
SendCommand(0x41); // TSE
SendData(0x00);
SendCommand(0x50);
SendData(0x3F);
SendCommand(0x60);
SendData(0x02);
SendData(0x00);
SendCommand(0x61);
SendData(0x03);
SendData(0x20);
SendData(0x01);
SendData(0xE0);
SendCommand(0x82);
SendData(0x1E);
SendCommand(0x84);
SendData(0x00);
SendCommand(0x86); // AGID
SendData(0x00);
SendCommand(0xE3);
SendData(0x2F);
SendCommand(0xE0); // CCSET
SendData(0x00);
SendCommand(0xE6); // TSSET
SendData(0x00);
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);
}
void Epd::EPD_7IN3F_BusyHigh(void) // If BUSYN=0 then waiting
{
while (!DigitalRead(BUSY_PIN))
{
DelayMs(1);
}
}
/**
* @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(1);
DigitalWrite(reset_pin, HIGH);
DelayMs(20);
}
void Epd::TurnOnDisplay(void)
{
SendCommand(0x04); // POWER_ON
EPD_7IN3F_BusyHigh();
SendCommand(0x12); // DISPLAY_REFRESH
SendData(0x00);
EPD_7IN3F_BusyHigh();
SendCommand(0x02); // POWER_OFF
SendData(0x00);
EPD_7IN3F_BusyHigh();
}
/******************************************************************************
function : Sends the image buffer in RAM to e-Paper and displays
parameter:
******************************************************************************/
void Epd::EPD_7IN3F_Display(const UBYTE *image)
{
unsigned long i, j;
SendCommand(0x10);
for (i = 0; i < height; i++)
{
for (j = 0; j < width / 2; j++)
{
SendData(image[j + width * i]);
}
}
TurnOnDisplay();
}
/******************************************************************************
function : Sends the part image buffer in RAM to e-Paper and displays
parameter:
******************************************************************************/
void Epd::EPD_7IN3F_Display_part(const UBYTE *image, UWORD xstart, UWORD ystart,
UWORD image_width, UWORD image_heigh)
{
unsigned long i, j;
SendCommand(0x10);
for (i = 0; i < height; i++)
{
for (j = 0; j < width / 2; j++)
{
if (i < image_heigh + ystart && i >= ystart && j < (image_width + xstart) / 2 && j >= xstart / 2)
{
SendData(pgm_read_byte(&image[(j - xstart / 2) + (image_width / 2 * (i - ystart))]));
}
else
{
SendData(0x11);
}
}
}
TurnOnDisplay();
}
/******************************************************************************
function : show 7 kind of color block
parameter:
******************************************************************************/
void Epd::EPD_7IN3F_Show7Block(void)
{
unsigned long i, j, k;
unsigned char const Color_seven[8] =
{EPD_7IN3F_BLACK, EPD_7IN3F_BLUE, EPD_7IN3F_GREEN, EPD_7IN3F_ORANGE,
EPD_7IN3F_RED, EPD_7IN3F_YELLOW, EPD_7IN3F_WHITE, EPD_7IN3F_WHITE};
SendCommand(0x10);
for (i = 0; i < 240; i++)
{
for (k = 0; k < 4; k++)
{
for (j = 0; j < 100; j++)
{
SendData((Color_seven[k] << 4) | Color_seven[k]);
}
}
}
for (i = 0; i < 240; i++)
{
for (k = 4; k < 8; k++)
{
for (j = 0; j < 100; j++)
{
SendData((Color_seven[k] << 4) | Color_seven[k]);
}
}
}
TurnOnDisplay();
}
/******************************************************************************
function :
Clear screen
******************************************************************************/
void Epd::Clear(UBYTE color)
{
SendCommand(0x10);
for (int i = 0; i < width / 2; i++)
{
for (int j = 0; j < height; j++)
{
SendData((color << 4) | color);
}
}
TurnOnDisplay();
}
/**
* @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.
* The only one parameter is a check code, the command would be
* You can use EPD_Reset() to awaken
*/
void Epd::Sleep(void)
{
SendCommand(0x07);
SendData(0xA5);
DelayMs(10);
DigitalWrite(RST_PIN, 0); // Reset
}
/* END OF FILE */

View File

@ -0,0 +1,86 @@
/*****************************************************************************
* | File : EPD_7in3f.h
* | Author : Waveshare team
* | Function : 7.3inch e-paper F
* | Info :
*----------------
* | This version: V1.0
* | Date : 2022-10-21
* | Info :
* -----------------------------------------------------------------------------
#
# 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.
#
******************************************************************************/
#ifndef __EPD_7IN3F_H__
#define __EPD_7IN3F_H__
#include "epdif.h"
// Display resolution
#define EPD_WIDTH 800
#define EPD_HEIGHT 480
#define UWORD unsigned int
#define UBYTE unsigned char
#define UDOUBLE unsigned long
/**********************************
Color Index
**********************************/
#define EPD_7IN3F_BLACK 0x0 /// 000
#define EPD_7IN3F_WHITE 0x1 /// 001
#define EPD_7IN3F_GREEN 0x2 /// 010
#define EPD_7IN3F_BLUE 0x3 /// 011
#define EPD_7IN3F_RED 0x4 /// 100
#define EPD_7IN3F_YELLOW 0x5 /// 101
#define EPD_7IN3F_ORANGE 0x6 /// 110
#define EPD_7IN3F_CLEAN 0x7 /// 111 unavailable Afterimage
class Epd : EpdIf
{
public:
Epd();
~Epd();
int Init(void);
void EPD_7IN3F_BusyHigh(void);
void TurnOnDisplay(void);
void Reset(void);
void EPD_7IN3F_Display(const UBYTE *image);
void EPD_7IN3F_Display_part(const UBYTE *image, UWORD xstart, UWORD ystart,
UWORD image_width, UWORD image_heigh);
void EPD_7IN3F_Show7Block(void);
void SendCommand(unsigned char command);
void SendData(unsigned char data);
void Sleep(void);
void Clear(UBYTE color);
private:
unsigned int reset_pin;
unsigned int dc_pin;
unsigned int cs_pin;
unsigned int busy_pin;
unsigned long width;
unsigned long height;
};
#endif /* EPD5IN83B_HD_H */
/* END OF FILE */

View File

@ -0,0 +1,67 @@
/**
* @filename : epdif.cpp
* @brief : Implements EPD interface functions
* Users have to implement all the functions in epdif.cpp
* @author : Yehui from Waveshare
*
* Copyright (C) Waveshare August 10 2017
*
* 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 "epdif.h"
#include <SPI.h>
EpdIf::EpdIf(){};
EpdIf::~EpdIf(){};
void EpdIf::DigitalWrite(int pin, int value)
{
digitalWrite(pin, value);
}
int EpdIf::DigitalRead(int pin)
{
return digitalRead(pin);
}
void EpdIf::DelayMs(unsigned int delaytime)
{
delay(delaytime);
}
void EpdIf::SpiTransfer(unsigned char data)
{
digitalWrite(CS_PIN, LOW);
SPI.transfer(data);
digitalWrite(CS_PIN, HIGH);
}
int EpdIf::IfInit(void)
{
pinMode(CS_PIN, OUTPUT);
pinMode(RST_PIN, OUTPUT);
pinMode(DC_PIN, OUTPUT);
pinMode(BUSY_PIN, INPUT);
SPI.begin();
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
return 0;
}

View File

@ -0,0 +1,52 @@
/**
* @filename : epdif.h
* @brief : Header file of epdif.cpp providing EPD interface functions
* Users have to implement all the functions in epdif.cpp
* @author : Yehui from Waveshare
*
* Copyright (C) Waveshare August 10 2017
*
* 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.
*/
#ifndef EPDIF_H
#define EPDIF_H
#include <Arduino.h>
// Pin definition
#define BUSY_PIN 26
#define RST_PIN 27
#define DC_PIN 15
#define CS_PIN 14
class EpdIf
{
public:
EpdIf(void);
~EpdIf(void);
static int IfInit(void);
static void DigitalWrite(int pin, int value);
static int DigitalRead(int pin);
static void DelayMs(unsigned int delaytime);
static void SpiTransfer(unsigned char data);
};
#endif

14
firmware/platformio.ini Normal file
View File

@ -0,0 +1,14 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:tinypico]
platform = espressif32
board = tinypico
framework = arduino

1721
firmware/src/imagedata.cpp Normal file

File diff suppressed because it is too large Load Diff

28
firmware/src/imagedata.h Normal file
View File

@ -0,0 +1,28 @@
/**
* @filename : imagedata.h
* @brief : head file for imagedata.cpp
*
* Copyright (C) Waveshare July 8 2020
*
* 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.
*/
extern const unsigned char gImage_7in3f[];
/* FILE END */

33
firmware/src/main.cpp Normal file
View File

@ -0,0 +1,33 @@
#include <SPI.h>
#include "imagedata.h"
#include "epd7in3f.h"
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
Epd epd;
if (epd.Init() != 0)
{
Serial.print("e-Paper init failed");
return;
}
Serial.print("e-Paper Clear\r\n ");
epd.Clear(EPD_7IN3F_WHITE);
Serial.print("Show pic\r\n ");
epd.EPD_7IN3F_Display_part(gImage_7in3f, 250, 150, 300, 180);
delay(2000);
Serial.print("draw 7 color block\r\n ");
epd.EPD_7IN3F_Show7Block();
delay(2000);
epd.Sleep();
}
void loop()
{
// put your main code here, to run repeatedly:
}

8
flake.lock generated
View File

@ -20,16 +20,16 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1683627095,
"narHash": "sha256-8u9SejRpL2TrMuHBdhYh4FKc1OGPDLyWTpIbNTtoHsA=",
"lastModified": 1683741689,
"narHash": "sha256-VY6gjqAFQe0Xyz+olc979zbsW9dC4VG+mINGffFKVEw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a08e061a4ee8329747d54ddf1566d34c55c895eb",
"rev": "f431ee4a85cb985075b4ed27596913e8087f4264",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-22.11",
"ref": "master",
"repo": "nixpkgs",
"type": "github"
}

View File

@ -2,7 +2,7 @@
description = "A simple Go project built with Nix";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";
nixpkgs.url = "github:NixOS/nixpkgs/master";
flake-utils.url = "github:numtide/flake-utils";
};
@ -15,9 +15,7 @@
{
packages."dynamic-frame-server" = server;
packages.default = server;
devShell = pkgs.mkShell {
buildInputs = [ pkgs.go ];
};
devShell = pkgs.callPackage ./shell.nix { };
}
);
}

View File

@ -23,7 +23,7 @@ func requestHandler(w http.ResponseWriter, r *http.Request) {
}
func main() {
fmt.Println("Hello, Nix!")
fmt.Println("Hello, Nix!")
// Create a new Chi router
router := chi.NewRouter()

View File

@ -1,10 +1,12 @@
{ pkgs ? import <nixpkgs> { } }:
{ pkgs ? import <nixpkgs> { }, ... }:
with pkgs;
mkShell {
buildInputs = [
go
python3
platformio
];
# Disabling hardening is required for go debugger to work. Not needed for packaging.