Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waveshare 10.3" display #120

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/app/drivers/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def drivers_for_device(device: str) -> dict[str, Driver]:
else:
device_drivers = {"waveshare": waveshare, "spi": DRIVERS["spi"]}

if waveshare.variant == "EPD_10in3":
device_drivers["bootconfig"] = DRIVERS["bootConfig"]
device_drivers["bootconfig"].lines = [
"dtoverlay=spi0-0cs",
]
if waveshare.variant == "EPD_13in3e":
device_drivers["bootconfig"] = DRIVERS["bootConfig"]
device_drivers["bootconfig"].lines = [
Expand Down
16 changes: 15 additions & 1 deletion backend/app/drivers/waveshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class WaveshareVariant:
"EPD_4in0e": "SpectraSixColor",
"EPD_7in3e": "SpectraSixColor",
"EPD_13in3e": "SpectraSixColor",

"EPD_10in3": "SixteenGray",
}

def get_variant_keys_for(folder: str) -> list[str]:
Expand All @@ -77,13 +79,20 @@ def get_variant_keys_for(folder: str) -> list[str]:
]

def get_variant_keys() -> list[str]:
return [*get_variant_keys_for("ePaper"), *get_variant_keys_for("epd12in48"), *get_variant_keys_for("epd13in3e")]
return [
*get_variant_keys_for("ePaper"),
*get_variant_keys_for("it8951"),
*get_variant_keys_for("epd12in48"),
*get_variant_keys_for("epd13in3e"),
]

def get_variant_folder(variant_key: str) -> str:
if variant_key in get_variant_keys_for("ePaper") :
return "ePaper"
elif variant_key == "EPD_13in3e":
return "epd13in3e"
elif variant_key == "EPD_10in3":
return "it8951"
else:
return "epd12in48"

Expand Down Expand Up @@ -181,6 +190,9 @@ def convert_waveshare_source(variant_key: Optional[str]) -> WaveshareVariant:
variant.display_function = proc_name
variant.display_arguments = get_proc_arguments(line, variant_key)
# print("-> " + proc_name + "(" + (", ".join(variant.display_arguments)) + ") <-")
if (proc_name.lower() == f"{variant.prefix}_16Gray_Display".lower()):
variant.display_function = proc_name
variant.display_arguments = get_proc_arguments(line, variant_key)

if variant.display_arguments == ["Black"]:
variant.color_option = "Black"
Expand All @@ -197,6 +209,8 @@ def convert_waveshare_source(variant_key: Optional[str]) -> WaveshareVariant:
variant.color_option = "SevenColor"
elif variant.display_arguments == ["SpectraSixColor"]:
variant.color_option = "SpectraSixColor"
elif variant_key == "EPD_10in3":
variant.color_option = "SixteenGray"
else:
print(f"Unknown color: {variant_key} - {variant.display_function} -- {variant.display_arguments}" )

Expand Down
11 changes: 9 additions & 2 deletions backend/app/tasks/deploy_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async def install_if_necessary(pkg: str, raise_on_error=True) -> int:
)

if low_memory:
await log(db, redis, id, "stdout", "- Low memory device, stopping FrameOS for compile")
await log(db, redis, id, "stdout", "- Low memory device, stopping FrameOS for compilation")
await exec_command(db, redis, frame, ssh, "sudo service frameos stop", raise_on_error=False)

# 2. Remote steps
Expand Down Expand Up @@ -486,7 +486,12 @@ async def create_local_build_archive(
if waveshare := drivers.get('waveshare'):
if waveshare.variant:
variant_folder = get_variant_folder(waveshare.variant)
util_files = ["Debug.h", "DEV_Config.c", "DEV_Config.h"]

if variant_folder == "it8951":
util_files = ["DEV_Config.c", "DEV_Config.h"]
else:
util_files = ["Debug.h", "DEV_Config.c", "DEV_Config.h"]

for uf in util_files:
shutil.copy(
os.path.join(source_dir, "src", "drivers", "waveshare", variant_folder, uf),
Expand All @@ -501,6 +506,8 @@ async def create_local_build_archive(
]:
c_file = re.sub(r'[bc]', 'bc', waveshare.variant)
variant_files = [f"{waveshare.variant}.nim", f"{c_file}.c", f"{c_file}.h"]
elif waveshare.variant == "EPD_10in3":
variant_files = [f"{waveshare.variant}.nim", "IT8951.c", "IT8951.h", "IT8951.nim"]
else:
variant_files = [f"{waveshare.variant}.nim", f"{waveshare.variant}.c", f"{waveshare.variant}.h"]

Expand Down
1 change: 1 addition & 0 deletions backend/list_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"BlackWhiteYellow": "Black/White/Yellow",
"BlackWhiteYellowRed": "Black/White/Yellow/Red",
"FourGray": "4 Grayscale",
"SixteenGray": "16 Grayscale",
"SevenColor": "7 Color",
"SpectraSixColor": "Spectra 6 Color",
}.get(v.color_option, v.color_option)
Expand Down
186 changes: 186 additions & 0 deletions frameos/src/drivers/waveshare/it8951/DEV_Config.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*****************************************************************************
* | File : DEV_Config.c
* | Author : Waveshare team
* | Function : Hardware underlying interface
* | Info :
*----------------
* | This version: V3.0
* | Date : 2019-09-17
* | 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 theex 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 "DEV_Config.h"
#include <fcntl.h>

int GPIO_Handle;
int SPI_Handle;

/******************************************************************************
function: GPIO Write
parameter:
Info:
******************************************************************************/
void DEV_Digital_Write(UWORD Pin, UBYTE Value)
{
lgGpioWrite(GPIO_Handle, Pin, Value);
}

/******************************************************************************
function: GPIO Read
parameter:
Info:
******************************************************************************/
UBYTE DEV_Digital_Read(UWORD Pin)
{
UBYTE Read_Value = 0;
Read_Value = lgGpioRead(GPIO_Handle,Pin);
return Read_Value;
}

/******************************************************************************
function: SPI Write
parameter:
Info:
******************************************************************************/
void DEV_SPI_WriteByte(UBYTE Value)
{
lgSpiWrite(SPI_Handle,(char*)&Value, 1);
}

/******************************************************************************
function: SPI Read
parameter:
Info:
******************************************************************************/
UBYTE DEV_SPI_ReadByte()
{
UBYTE Read_Value = 0x00;
lgSpiRead(SPI_Handle, (char*)&Read_Value, 1);
return Read_Value;
}

/******************************************************************************
function: Time delay for ms
parameter:
Info:
******************************************************************************/
void DEV_Delay_ms(UDOUBLE xms)
{
lguSleep(xms/1000.0);
}


/******************************************************************************
function: Time delay for us
parameter:
Info:
******************************************************************************/
void DEV_Delay_us(UDOUBLE xus)
{
lguSleep(xus/1000000.0);
}


/**
* GPIO Mode
**/
static void DEV_GPIO_Mode(UWORD Pin, UWORD Mode)
{
if(Mode == 0 || Mode == LG_SET_INPUT){
lgGpioClaimInput(GPIO_Handle,LFLAGS,Pin);
// Debug("IN Pin = %d\r\n",Pin);
}else{
lgGpioClaimOutput(GPIO_Handle, LFLAGS, Pin, LG_LOW);
// Debug("OUT Pin = %d\r\n",Pin);
}
}


/**
* GPIO Init
**/
static void DEV_GPIO_Init(void)
{
DEV_GPIO_Mode(EPD_BUSY_PIN, 0);
DEV_GPIO_Mode(EPD_RST_PIN, 1);
DEV_GPIO_Mode(EPD_CS_PIN, 1);

DEV_Digital_Write(EPD_CS_PIN, 1);
}



/******************************************************************************
function: Module Initialize, the library and initialize the pins, SPI protocol
parameter:
Info:
******************************************************************************/
UBYTE DEV_Module_Init(void)
{
Debug("/***********************************/ \r\n");

char buffer[NUM_MAXBUF];
FILE *fp;

fp = popen("cat /proc/cpuinfo | grep 'Raspberry Pi 5'", "r");
if (fp == NULL) {
Debug("It is not possible to determine the model of the Raspberry PI\n");
return -1;
}

if(fgets(buffer, sizeof(buffer), fp) != NULL)
{
GPIO_Handle = lgGpiochipOpen(4);
if (GPIO_Handle < 0)
{
Debug( "gpiochip4 Export Failed\n");
return -1;
}
}
else
{
GPIO_Handle = lgGpiochipOpen(0);
if (GPIO_Handle < 0)
{
Debug( "gpiochip0 Export Failed\n");
return -1;
}
}
SPI_Handle = lgSpiOpen(0, 0, 12500000, 0);
DEV_GPIO_Init();
Debug("/***********************************/!! \r\n");
return 0;
}



/******************************************************************************
function: Module exits, closes SPI and BCM2835 library
parameter:
Info:
******************************************************************************/
void DEV_Module_Exit(void)
{
// DEV_Digital_Write(EPD_CS_PIN, 0);
// DEV_Digital_Write(EPD_RST_PIN, 0);
// lgSpiClose(SPI_Handle);
// lgGpiochipClose(GPIO_Handle);
}
104 changes: 104 additions & 0 deletions frameos/src/drivers/waveshare/it8951/DEV_Config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*****************************************************************************
* | File : DEV_Config.h
* | Author : Waveshare team
* | Function : Hardware underlying interface
* | Info :
* Used to shield the underlying layers of each master
* and enhance portability
*----------------
* | This version: V2.0
* | Date : 2018-10-30
* | Info :
* 1.add:
* UBYTE\UWORD\UDOUBLE
* 2.Change:
* EPD_RST -> EPD_RST_PIN
* EPD_DC -> EPD_DC_PIN
* EPD_CS -> EPD_CS_PIN
* EPD_BUSY -> EPD_BUSY_PIN
* 3.Remote:
* EPD_RST_1\EPD_RST_0
* EPD_DC_1\EPD_DC_0
* EPD_CS_1\EPD_CS_0
* EPD_BUSY_1\EPD_BUSY_0
* 3.add:
* #define DEV_Digital_Write(_pin, _value) bcm2835_GPIOI_write(_pin, _value)
* #define DEV_Digital_Read(_pin) bcm2835_GPIOI_lev(_pin)
* #define DEV_SPI_WriteByte(__value) bcm2835_spi_transfer(__value)
#
# 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 _DEV_CONFIG_H_
#define _DEV_CONFIG_H_

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <lgpio.h>

#define Debug(fmt,...) printf(fmt,##__VA_ARGS__)

#define LFLAGS 0
#define NUM_MAXBUF 4


#define HIGH 0x1
#define LOW 0x0

/**
* GPIO
**/

#define EPD_RST_PIN 17
#define EPD_CS_PIN 8
#define EPD_BUSY_PIN 24



/**
* data
**/
#define UBYTE uint8_t
#define UWORD uint16_t
#define UDOUBLE uint32_t





/*------------------------------------------------------------------------------------------------------*/
void DEV_Digital_Write(UWORD Pin, UBYTE Value);
UBYTE DEV_Digital_Read(UWORD Pin);

void DEV_SPI_WriteByte(UBYTE Value);
UBYTE DEV_SPI_ReadByte();

void DEV_Delay_ms(UDOUBLE xms);
void DEV_Delay_us(UDOUBLE xus);

UBYTE DEV_Module_Init(void);
void DEV_Module_Exit(void);


#endif
Loading
Loading