From 54f343dbec5bd4557dbc04b24cbed2aff07a3048 Mon Sep 17 00:00:00 2001 From: Hays Chan <25737801+hayschan@users.noreply.github.com> Date: Thu, 31 Aug 2023 15:10:36 +0800 Subject: [PATCH 1/2] Add ESP-IDF examples and config files ESP32 MCU code examples for the TM1638 chip. --- CMakelists.txt | 3 +++ examples/esp32/CMakeLists.txt | 8 ++++++++ examples/esp32/main/CMakeLists.txt | 2 ++ examples/esp32/main/main.c | 19 +++++++++++++++++++ idf_component.yml | 11 +++++++++++ 5 files changed, 43 insertions(+) create mode 100644 CMakelists.txt create mode 100644 examples/esp32/CMakeLists.txt create mode 100644 examples/esp32/main/CMakeLists.txt create mode 100644 examples/esp32/main/main.c create mode 100644 idf_component.yml diff --git a/CMakelists.txt b/CMakelists.txt new file mode 100644 index 0000000..a040311 --- /dev/null +++ b/CMakelists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS "tm1638.c" "TM1638_platform.c" + INCLUDE_DIRS "." + REQUIRES driver) \ No newline at end of file diff --git a/examples/esp32/CMakeLists.txt b/examples/esp32/CMakeLists.txt new file mode 100644 index 0000000..65d8087 --- /dev/null +++ b/examples/esp32/CMakeLists.txt @@ -0,0 +1,8 @@ +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(tm1638) \ No newline at end of file diff --git a/examples/esp32/main/CMakeLists.txt b/examples/esp32/main/CMakeLists.txt new file mode 100644 index 0000000..8a3ab69 --- /dev/null +++ b/examples/esp32/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "main.c" + INCLUDE_DIRS "") diff --git a/examples/esp32/main/main.c b/examples/esp32/main/main.c new file mode 100644 index 0000000..a893fde --- /dev/null +++ b/examples/esp32/main/main.c @@ -0,0 +1,19 @@ +#include "TM1638.h" +#include "TM1638_platform.h" + +void app_main(void) +{ + TM1638_Handler_t Handler; + + TM1638_Platform_Init(&Handler); + TM1638_Init(&Handler, TM1638DisplayTypeComCathode); + TM1638_ConfigDisplay(&Handler, 7, TM1638DisplayStateON); + + while (1) + { + // Display the number 8 and Decimal Point in the SEG1 + TM1638_SetSingleDigit_HEX(&Handler, 8 | TM1638DecimalPoint, 0); + } + + TM1638_DeInit(&Handler); +} \ No newline at end of file diff --git a/idf_component.yml b/idf_component.yml new file mode 100644 index 0000000..5924293 --- /dev/null +++ b/idf_component.yml @@ -0,0 +1,11 @@ +version: "2.0.0" + +description: TM1638 driver for AVR (ATmega32), STM32 (HAL) and ESP32 (esp-idf) +url: https://github.com/MahdaSystem/TM1638 +repository: https://github.com/MahdaSystem/TM1638.git +documentation: https://github.com/MahdaSystem/TM1638#readme +issues: https://github.com/MahdaSystem/TM1638/issues + +dependencies: + # Required IDF version + idf: ">=4.2" \ No newline at end of file From ade162304c5c7fd047832729df3c8b799cc7cf36 Mon Sep 17 00:00:00 2001 From: Hays Chan <25737801+hayschan@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:43:54 +0800 Subject: [PATCH 2/2] Add ESP specific preprocessing logic and Kconfig --- Kconfig | 22 ++++++++++++++++++++++ TM1638_platform.h | 10 +++++----- 2 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 Kconfig diff --git a/Kconfig b/Kconfig new file mode 100644 index 0000000..888f21c --- /dev/null +++ b/Kconfig @@ -0,0 +1,22 @@ +menu "TM1638 config" + + config TM1638_CLK_GPIO + int "TM1638 CLK Pin" + default 0 + help + GPIO number (IOxx) for the TM638 CLK pin. + + + config TM1638_DIO_GPIO + int "TM1638 DIO Pin" + default 1 + help + GPIO number (IOxx) for the TM638 DIO pin. + + config TM1638_STB_GPIO + int "TM1638 STB Pin" + default 2 + help + GPIO number (IOxx) for the TM638 STB pin. + +endmenu # TM1638 \ No newline at end of file diff --git a/TM1638_platform.h b/TM1638_platform.h index a90ba29..2fae246 100644 --- a/TM1638_platform.h +++ b/TM1638_platform.h @@ -51,7 +51,6 @@ extern "C" { // #define TM1638_PLATFORM_STM32 // HAL Functions // #define TM1638_PLATFORM_ESP32_IDF // ESP-IDF - #if defined(TM1638_PLATFORM_AVR) /** * @brief Specify IO Pins of AVR connected to TM1638 @@ -79,13 +78,14 @@ extern "C" { #define TM1638_STB_GPIO GPIOA #define TM1638_STB_PIN GPIO_PIN_2 -#elif defined(TM1638_PLATFORM_ESP32_IDF) +#elif defined(TM1638_PLATFORM_ESP32_IDF) || defined(ESP_PLATFORM) /** * @brief Specify IO Pins of ESP32 connected to TM1638 + * @note `ESP_PLATFORM` automatically activates (value TRUE) when building with ESP-IDF build chain */ -#define TM1638_CLK_GPIO GPIO_NUM_0 -#define TM1638_DIO_GPIO GPIO_NUM_1 -#define TM1638_STB_GPIO GPIO_NUM_2 +#define TM1638_CLK_GPIO (gpio_num_t)CONFIG_TM1638_CLK_GPIO +#define TM1638_DIO_GPIO (gpio_num_t)CONFIG_TM1638_DIO_GPIO +#define TM1638_STB_GPIO (gpio_num_t)CONFIG_TM1638_STB_GPIO #endif