Parcourir la source

Copy of blink project

Thomas Chef il y a 4 mois
commit
ffc133f1ff
10 fichiers modifiés avec 275 ajouts et 0 suppressions
  1. 78 0
      .gitignore
  2. 8 0
      CMakeLists.txt
  3. 10 0
      Makefile
  4. 43 0
      example_test.py
  5. 2 0
      main/CMakeLists.txt
  6. 46 0
      main/Kconfig.projbuild
  7. 83 0
      main/blink_example_main.c
  8. 4 0
      main/component.mk
  9. 0 0
      sdkconfig.ci
  10. 1 0
      sdkconfig.defaults

+ 78 - 0
.gitignore

@@ -0,0 +1,78 @@
+# Prerequisites
+*.d
+
+# Object files
+*.o
+*.ko
+*.obj
+*.elf
+
+# Linker output
+*.ilk
+*.map
+*.exp
+
+# Precompiled Headers
+*.gch
+*.pch
+
+# Libraries
+*.lib
+*.a
+*.la
+*.lo
+
+# Shared objects (inc. Windows DLLs)
+*.dll
+*.so
+*.so.*
+*.dylib
+
+# Executables
+*.exe
+*.out
+*.app
+*.i*86
+*.x86_64
+*.hex
+
+# Debug files
+*.dSYM/
+*.su
+*.idb
+*.pdb
+
+# Kernel Module Compile Results
+*.mod*
+*.cmd
+.tmp_versions/
+modules.order
+Module.symvers
+Mkfile.old
+dkms.conf
+
+# Eclipse
+.metadata/
+RemoteSystemsTempFiles/.project
+.settings/
+*.a
+*.o
+*.d
+wifi_manager/.cproject
+wifi_manager/.project
+sdkconfig
+sdkconfig.old
+**/build/
+#doxygen
+Doxyfile
+wifi_manager/doc/
+.project
+.cproject
+
+# Visual Studio Code
+.vscode/
+.DS_Store
+
+#Others ?
+.ipynb_checkpoints/
+Untitled.ipynb

+ 8 - 0
CMakeLists.txt

@@ -0,0 +1,8 @@
+# The following five 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 $ENV{IDF_PATH}/examples/common_components/led_strip)
+
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+project(blink)

+ 10 - 0
Makefile

@@ -0,0 +1,10 @@
+#
+# This is a project Makefile. It is assumed the directory this Makefile resides in is a
+# project subdirectory.
+#
+
+PROJECT_NAME := blink
+
+EXTRA_COMPONENT_DIRS = $(IDF_PATH)/examples/common_components/led_strip
+
+include $(IDF_PATH)/make/project.mk

+ 43 - 0
example_test.py

@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+
+from __future__ import division, print_function, unicode_literals
+
+import hashlib
+import os
+import re
+
+import ttfw_idf
+from tiny_test_fw import Utility
+
+
+def verify_elf_sha256_embedding(dut):
+    elf_file = os.path.join(dut.app.binary_path, 'blink.elf')
+    sha256 = hashlib.sha256()
+    with open(elf_file, 'rb') as f:
+        sha256.update(f.read())
+    sha256_expected = sha256.hexdigest()
+
+    dut.reset()
+    sha256_reported = dut.expect(re.compile(r'ELF file SHA256:\s+([a-f0-9]+)'), timeout=5)[0]
+
+    Utility.console_log('ELF file SHA256: %s' % sha256_expected)
+    Utility.console_log('ELF file SHA256 (reported by the app): %s' % sha256_reported)
+    # the app reports only the first several hex characters of the SHA256, check that they match
+    if not sha256_expected.startswith(sha256_reported):
+        raise ValueError('ELF file SHA256 mismatch')
+
+
+@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
+def test_examples_blink(env, extra_data):
+    dut = env.get_dut('blink', 'examples/get-started/blink')
+    binary_file = os.path.join(dut.app.binary_path, 'blink.bin')
+    bin_size = os.path.getsize(binary_file)
+    ttfw_idf.log_performance('blink_bin_size', '{}KB'.format(bin_size // 1024))
+
+    dut.start_app()
+
+    verify_elf_sha256_embedding(dut)
+
+
+if __name__ == '__main__':
+    test_examples_blink()

+ 2 - 0
main/CMakeLists.txt

@@ -0,0 +1,2 @@
+idf_component_register(SRCS "blink_example_main.c"
+                    INCLUDE_DIRS ".")

+ 46 - 0
main/Kconfig.projbuild

@@ -0,0 +1,46 @@
+menu "Example Configuration"
+
+    choice BLINK_LED
+        prompt "Blink LED type"
+        default BLINK_LED_GPIO if IDF_TARGET_ESP32
+        default BLINK_LED_RMT
+        help
+            Defines the default peripheral for blink example
+
+        config BLINK_LED_GPIO
+            bool "GPIO"
+        config BLINK_LED_RMT
+            bool "RMT - Addressable LED"
+    endchoice
+
+    config BLINK_LED_RMT_CHANNEL
+        depends on BLINK_LED_RMT
+        int "RMT Channel"
+        range 0 7
+        default 0
+        help
+            Set the RMT peripheral channel.
+            ESP32 RMT channel from 0 to 7
+            ESP32-S2 RMT channel from 0 to 3
+            ESP32-S3 RMT channel from 0 to 3
+            ESP32-C3 RMT channel from 0 to 1
+
+    config BLINK_GPIO
+        int "Blink GPIO number"
+        range 0 48
+        default 8 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32H2
+        default 18 if IDF_TARGET_ESP32S2
+        default 48 if IDF_TARGET_ESP32S3
+        default 5
+        help
+            GPIO number (IOxx) to blink on and off or the RMT signal for the addressable LED.
+            Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink.
+
+    config BLINK_PERIOD
+        int "Blink period in ms"
+        range 10 3600000
+        default 1000
+        help
+            Define the blinking period in milliseconds.
+
+endmenu

+ 83 - 0
main/blink_example_main.c

@@ -0,0 +1,83 @@
+/* Blink Example
+
+   This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+#include <stdio.h>
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+#include "driver/gpio.h"
+#include "esp_log.h"
+#include "led_strip.h"
+#include "sdkconfig.h"
+
+static const char *TAG = "example";
+
+/* Use project configuration menu (idf.py menuconfig) to choose the GPIO to blink,
+   or you can edit the following line and set a number here.
+*/
+#define BLINK_GPIO CONFIG_BLINK_GPIO
+
+static uint8_t s_led_state = 0;
+
+#ifdef CONFIG_BLINK_LED_RMT
+static led_strip_t *pStrip_a;
+
+static void blink_led(void)
+{
+    /* If the addressable LED is enabled */
+    if (s_led_state) {
+        /* Set the LED pixel using RGB from 0 (0%) to 255 (100%) for each color */
+        pStrip_a->set_pixel(pStrip_a, 0, 16, 16, 16);
+        /* Refresh the strip to send data */
+        pStrip_a->refresh(pStrip_a, 100);
+    } else {
+        /* Set all LED off to clear all pixels */
+        pStrip_a->clear(pStrip_a, 50);
+    }
+}
+
+static void configure_led(void)
+{
+    ESP_LOGI(TAG, "Example configured to blink addressable LED!");
+    /* LED strip initialization with the GPIO and pixels number*/
+    pStrip_a = led_strip_init(CONFIG_BLINK_LED_RMT_CHANNEL, BLINK_GPIO, 1);
+    /* Set all LED off to clear all pixels */
+    pStrip_a->clear(pStrip_a, 50);
+}
+
+#elif CONFIG_BLINK_LED_GPIO
+
+static void blink_led(void)
+{
+    /* Set the GPIO level according to the state (LOW or HIGH)*/
+    gpio_set_level(BLINK_GPIO, s_led_state);
+}
+
+static void configure_led(void)
+{
+    ESP_LOGI(TAG, "Example configured to blink GPIO LED!");
+    gpio_reset_pin(BLINK_GPIO);
+    /* Set the GPIO as a push/pull output */
+    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
+}
+
+#endif
+
+void app_main(void)
+{
+
+    /* Configure the peripheral according to the LED type */
+    configure_led();
+
+    while (1) {
+        ESP_LOGI(TAG, "Turning the LED %s!", s_led_state == true ? "ON" : "OFF");
+        blink_led();
+        /* Toggle the LED state */
+        s_led_state = !s_led_state;
+        vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS);
+    }
+}

+ 4 - 0
main/component.mk

@@ -0,0 +1,4 @@
+#
+# "main" pseudo-component makefile.
+#
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

+ 0 - 0
sdkconfig.ci


+ 1 - 0
sdkconfig.defaults

@@ -0,0 +1 @@
+#