Skip to content

Commit ea46874

Browse files
committed
feat: add ESP32-IDF example
1 parent b88df2f commit ea46874

4 files changed

Lines changed: 83 additions & 0 deletions

File tree

example/ESP-IDF/counter/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/
2+
sdkconfig
3+
sdkconfig.old
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
4+
project(blink)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
idf_component_register(
2+
SRCS "./main.c" "../../../../src/TM1638.c" "../../../../port/ESP32-IDF/TM1638_platform.c"
3+
INCLUDE_DIRS "../../../../config" "../../../../src/include" "../../../../port/ESP32-IDF"
4+
)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
**********************************************************************************
3+
* @file main.c
4+
* @author Hossein.M (https://github.com/Hossein-M98)
5+
* @brief example code for TM1638 Driver (for ESP32-IDF)
6+
**********************************************************************************
7+
*
8+
* Copyright (c) 2023 Mahda Embedded System (MIT License)
9+
*
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy
11+
* of this software and associated documentation files (the "Software"), to deal
12+
* in the Software without restriction, including without limitation the rights
13+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
* copies of the Software, and to permit persons to whom the Software is
15+
* furnished to do so, subject to the following conditions:
16+
*
17+
* The above copyright notice and this permission notice shall be included in all
18+
* copies or substantial portions of the Software.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
* SOFTWARE.
27+
*
28+
**********************************************************************************
29+
*/
30+
31+
#include <stdio.h>
32+
#include "freertos/FreeRTOS.h"
33+
#include "freertos/task.h"
34+
#include "driver/gpio.h"
35+
#include "esp_log.h"
36+
#include "sdkconfig.h"
37+
38+
#include "TM1638.h"
39+
#include "TM1638_platform.h"
40+
41+
static const char *TAG = "example";
42+
43+
void app_main(void)
44+
{
45+
TM1638_Handler_t Handler = {0};
46+
47+
ESP_LOGI(TAG, "example code for TM1638 Driver (for ESP-IDF)");
48+
49+
TM1638_Platform_Init(&Handler);
50+
TM1638_Platform_Init(&Handler);
51+
TM1638_Init(&Handler, TM1638DisplayTypeComCathode);
52+
TM1638_ConfigDisplay(&Handler, 7, TM1638DisplayStateON);
53+
54+
while (1)
55+
{
56+
for (uint16_t i = 0; i < 10000; i++)
57+
{
58+
uint8_t Buffer[4] = {0};
59+
Buffer[0] = i % 10;
60+
Buffer[1] = (i / 10) % 10;
61+
Buffer[2] = (i / 100) % 10;
62+
Buffer[3] = (i / 1000) % 10;
63+
64+
Buffer[1] |= TM1638DecimalPoint;
65+
66+
TM1638_SetMultipleDigit_HEX(&Handler, Buffer, 0, 4);
67+
vTaskDelay(100 / portTICK_PERIOD_MS);
68+
}
69+
}
70+
71+
TM1638_DeInit(&Handler);
72+
}

0 commit comments

Comments
 (0)