Skip to content

Commit

Permalink
Adding backward compatibility for other ESP-IDF
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacNez authored and VedantParanjape committed Mar 20, 2023
1 parent 74b1d1a commit 382efa8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ elseif(CONFIG_EPD_2_7)
list(APPEND srcs "epd2in7.cpp")
endif()

string(REGEX MATCH "([0-9]+).([0-9])" VERSION ${IDF_VER})
string(REPLACE "." ";" VERSION_LIST ${VERSION})
list(GET ${VERSION_LIST} 0 VERSION_MAJOR)
if(${VERSION_MAJOR} LESS 4)
add_compile_definitions(ESP_IDF_VERSION_MAJOR=${VERSION_MAJOR})
list(GET ${VERSION_LIST} 0 VERSION_MINOR)
add_compile_definitions(ESP_IDF_VERSION_MINOR=${VERSION_MINOR})
endif()
idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "include"
REQUIRES esp_common driver)
55 changes: 55 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
menu "E-Paper display configuration"

choice
prompt "Display Type"
default EPD_1_54_V2
help
"Select waveshare's epaper display to be used"

config EPD_1_54_V2
bool "1.54\" V2 Display Module"

config EPD_2_13_D
bool "2.13\" D Display"

config EPD_2_7
bool "2.7\" Display"
endchoice

config MOSI_PIN
int "DATAIN (MOSI/DIN) Pin number"
default 14
help
set the pin to be connected to mosi/din pin of display

config CLK_PIN
int "CLOCK (CLK/SCK) Pin number"
default 13
help
set the pin to be connected to clk/sck pin of display

config CS_PIN
int "CHIPSELECT (CS) Pin number"
default 15
help
set the pin to be connected to cs pin of display

config DC_PIN
int "DATA/COMMAND (DC) Pin number"
default 27
help
set the pin to be connected to dc pin of display

config RST_PIN
int "RESET (RST) Pin number"
default 26
help
set the pin to be connected to rst pin of display

config BUSY_PIN
int "BUSY (BUSY) Pin number"
default 25
help
set the pin to be connected to busy pin of display

endmenu
17 changes: 14 additions & 3 deletions epdif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ int EpdIf::IfInit(void) {

}

// spi_bus_free(HSPI_HOST); -> This generates error on ESP-IDF >= v4.2
#if ESP_IDF_VERSION_MAJOR < 4
spi_bus_free(SPI_HOST); // This generates error on ESP-IDF >= v4.2
#endif

gpio_config_t io_conf = {};
io_conf.intr_type = GPIO_INTR_DISABLE;
Expand Down Expand Up @@ -113,7 +115,11 @@ int EpdIf::IfInit(void) {
buscfg.quadhd_io_num = -1;

//Initialize the SPI bus
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 0);
#if ESP_IDF_VERSION_MAJOR >= 4
ret=spi_bus_initialize(HSPI_HOST, &buscfg, 0);
#else
ret=spi_bus_initialize(SPI_HOST, &buscfg, 0);
#endif
switch (ret) {
case ESP_ERR_INVALID_ARG:
ESP_LOGE("EPDIF", "INVALID ARG");
Expand All @@ -140,7 +146,12 @@ int EpdIf::IfInit(void) {
devcfg.queue_size = 1;

//Attach the EPD to the SPI bus
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
#if ESP_IDF_VERSION_MAJOR >= 4
ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi);
#else
ret=spi_bus_add_device(SPI_HOST, &devcfg, &spi);
#endif

assert(ret==ESP_OK);

return 0;
Expand Down
4 changes: 3 additions & 1 deletion include/epdif.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
#define BUSY_PIN CONFIG_BUSY_PIN

// SPI host
// #define HSPI_HOST HHSPI_HOST
#if ESP_IDF_VERSION_MAJOR < 4
#define SPI_HOST HSPI_HOST
#endif

#ifdef __cplusplus
extern "C" {
Expand Down

0 comments on commit 382efa8

Please sign in to comment.