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

Add support for ESP-IDF >= v4.1 #5

Merged
merged 2 commits into from
Mar 20, 2023
Merged
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
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.projbuild
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
13 changes: 13 additions & 0 deletions epd1in54_V2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
#
******************************************************************************/
#include <stdlib.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "driver/spi_master.h"
#include "soc/gpio_struct.h"
#include "driver/gpio.h"
#include "esp_log.h"

#include "epd1in54_V2.h"

Epd::~Epd()
Expand Down
41 changes: 34 additions & 7 deletions epdif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
* THE SOFTWARE.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "driver/spi_master.h"
#include "soc/gpio_struct.h"
#include "driver/gpio.h"
#include "esp_log.h"

#include "epdif.h"
#include "esp_log.h"

Expand Down Expand Up @@ -68,18 +80,23 @@ int EpdIf::IfInit(void) {

if(spi) {
spi_bus_remove_device(spi);

}
spi_bus_free(SPI_HOST);

gpio_config_t io_conf = {0};

#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;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = ((uint64_t)1<<(uint64_t)DC_PIN) | ((uint64_t)1<<(uint64_t)RST_PIN);
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
ESP_ERROR_CHECK(gpio_config(&io_conf));

gpio_config_t i_conf = {0};
gpio_config_t i_conf;
memset(&i_conf, 0, sizeof(i_conf));
i_conf.intr_type = GPIO_INTR_DISABLE;
i_conf.mode = GPIO_MODE_INPUT;
i_conf.pin_bit_mask = ((uint64_t)1<<(uint64_t)BUSY_PIN);
Expand All @@ -89,15 +106,20 @@ int EpdIf::IfInit(void) {

esp_err_t ret;

spi_bus_config_t buscfg = {0};
spi_bus_config_t buscfg;
memset(&buscfg, 0, sizeof(buscfg));
buscfg.mosi_io_num = MOSI_PIN;
buscfg.sclk_io_num = CLK_PIN;
buscfg.miso_io_num = -1;
buscfg.quadwp_io_num = -1;
buscfg.quadhd_io_num = -1;

//Initialize the SPI bus
ret=spi_bus_initialize(SPI_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 @@ -124,7 +146,12 @@ int EpdIf::IfInit(void) {
devcfg.queue_size = 1;

//Attach the EPD to the SPI bus
ret=spi_bus_add_device(SPI_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
13 changes: 2 additions & 11 deletions include/epdif.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@
#ifndef EPDIF_H
#define EPDIF_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "driver/spi_master.h"
#include "soc/gpio_struct.h"
#include "driver/gpio.h"

// Pin definition
#define MOSI_PIN CONFIG_MOSI_PIN
#define CLK_PIN CONFIG_CLK_PIN
Expand All @@ -48,7 +37,9 @@
#define BUSY_PIN CONFIG_BUSY_PIN

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

#ifdef __cplusplus
extern "C" {
Expand Down