Skip to content

Commit

Permalink
Merge branch 'feature/zero_detection_support_ci' into 'master'
Browse files Browse the repository at this point in the history
Feature/zero detection support ci

See merge request ae_group/esp-iot-solution!895
  • Loading branch information
Yuan Ming Fu committed Nov 29, 2023
2 parents 8db53aa + c16260a commit bdb39a4
Show file tree
Hide file tree
Showing 19 changed files with 408 additions and 74 deletions.
1 change: 1 addition & 0 deletions .github/workflows/upload_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
components/usb/usb_device_uvc;
components/usb/usb_stream;
components/utilities/xz;
components/zero_detection;
tools/cmake_utilities;
namespace: "espressif"
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}
11 changes: 11 additions & 0 deletions .gitlab/ci/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -742,3 +742,14 @@ build_example_elf_loader_build_elf_file_example:
- IMAGE: espressif/idf:release-v5.0
variables:
EXAMPLE_DIR: examples/elf_loader/build_elf_file_example

build_components_zero_detection_test_apps:
extends:
- .build_examples_template
- .rules:build:components_zero_detection_test_apps
parallel:
matrix:
- IMAGE: espressif/idf:release-v5.0
- IMAGE: espressif/idf:release-v5.1
variables:
EXAMPLE_DIR: components/zero_detection/test_apps
19 changes: 19 additions & 0 deletions .gitlab/ci/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@
.patterns-components_utilities_xz: &patterns-components_utilities_xz
- "components/utilities/xz/**/*"

.patterns-components_zero_detection: &patterns-components_zero_detection
- "components/zero_detection/**/*"
- "components/tools/cmake_utilities/package_manager.cmake"

# examples folder, in the alphabetic order
.patterns-docs: &patterns-docs
- "docs/**/*"
Expand All @@ -217,6 +221,7 @@
- "components/sensors/sensor_hub/include/iot_sensor_hub.h"
- "components/usb/usb_stream/include/usb_stream.h"
- "components/bluetooth/ble_conn_mgr/include/esp_ble_conn_mgr.h"
- "components/zero_detection/include/zero_detection.h"

# examples folder, in the alphabetic order
.patterns-example_audio_wav_player: &patterns-example_audio_wav_player
Expand Down Expand Up @@ -348,6 +353,9 @@
.patterns-example_elf_loader_build_elf_file_example: &patterns-example_elf_loader_build_elf_file_example
- "examples/elf_loader/build_elf_file_example/**/*"

.patterns-example_zero_cross_detection_example: &patterns-example_zero_cross_detection_example
- "examples/zero_cross_detecion/**/*"

# tools folder, in the alphabetic order
.patterns-tools_cmake_utilities: &patterns-tools_cmake_utilities
- "tools/cmake_utilities/**/*"
Expand Down Expand Up @@ -1392,6 +1400,17 @@
- <<: *if-dev-push
changes: *patterns-components_sensors_radar_at581x

.rules:build:components_zero_detection_test_apps:
rules:
- <<: *if-protected
- <<: *if-label-build
- <<: *if-label-target_test
- <<: *if-trigger-job
- <<: *if-dev-push
changes: *patterns-build_system
- <<: *if-dev-push
changes: *patterns-components_zero_detection

.rules:build:tools_cmake_utilities_test_apps:
rules:
- <<: *if-protected
Expand Down
31 changes: 31 additions & 0 deletions .gitlab/ci/target_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,37 @@ examples_test_usb_uf2_ota:
TEST_FOLDER: examples/usb/device/usb_uf2_ota
TEST_ENV: ${ENV_TAG}

components_test_zero_detection:
extends:
- .pytest_template
- .rules:build:components_zero_detection_test_apps
needs:
- job: "build_components_zero_detection_test_apps"
artifacts: true
optional: true
parallel:
matrix:
- IDF_TARGET: esp32s3
IDF_VERSION: "5.0"
ENV_TAG: zero_detection
- IDF_TARGET: esp32s3
IDF_VERSION: "5.1"
ENV_TAG: zero_detection
- IDF_TARGET: esp32c3
IDF_VERSION: "5.0"
ENV_TAG: zero_detection
- IDF_TARGET: esp32c3
IDF_VERSION: "5.1"
ENV_TAG: zero_detection
tags:
- ${IDF_TARGET}
- ${ENV_TAG}
image: $DOCKER_TARGET_TEST_v5_1_ENV_IMAGE
variables:
TEST_TARGET: ${IDF_TARGET}
TEST_FOLDER: components/zero_detection
TEST_ENV: ${ENV_TAG}

tools_test_cmake_utilities:
extends:
- .pytest_template
Expand Down
7 changes: 7 additions & 0 deletions components/zero_detection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ChangeLog

## v0.0.1 - 2023-11-28

First release version.

- Support zero_cross_detection
5 changes: 4 additions & 1 deletion components/zero_detection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0")
INCLUDE_DIRS "include")
else()
message(FATAL_ERROR "Not supported in the current version")
endif()
endif()

include(package_manager)
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})
38 changes: 18 additions & 20 deletions components/zero_detection/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
[![Component Registry](https://components.espressif.com/components/espressif/button/badge.svg)](https://components.espressif.com/components/espressif/button)
[![Component Registry](https://components.espressif.com/components/espressif/zero_detection/badge.svg)](https://components.espressif.com/components/espressif/zero_detection)

# Component: Zero_Detection
[Online documentation](https://docs.espressif.com/projects/esp-iot-solution/en/latest/input_device/button.html)

The zero cross detection driver is a component designed to analyze zero cross signals. By examining the period and triggering edges of zero cross signals, it can determine the signal's validity, invalidity, whether it exceeds the expected frequency range, and if there are signal losses.

The program returns results in the form of events, meeting the user's need for timely signal processing. Additionally, it supports the analysis of two types of zero cross signals, including square waveforms and pulse types.

After creating a new zero detection object by calling function `zero_detect_create()`, the zero detection object can create many events.

List of supported events:
* Button pressed
* Button released
* Button pressed repeat
* Button press repeat done
* Button single click
* Button double click
* Button multiple click
* Button long press start
* Button long press hold
* Button long press up

![](https://dl.espressif.com/button_v2/button.svg)

There are three ways this driver can handle buttons:
1. Buttons connected to standard digital GPIO
2. Multiple buttons connected to single ADC channel
3. Custom button connect to any driver
* SIGNAL_FREQ_OUT_OF_RANGE
* SIGNAL_VALID
* SIGNAL_INVALID
* SIGNAL_LOST
* SIGNAL_RISING_EDGE
* SIGNAL_FALLING_EDGE

Users have the flexibility to configure the program's drive modes, including MCPWM capture and GPIO interrupt. Furthermore, users can adjust parameters such as the effective frequency range and the number of valid signal judgments, providing a high level of flexibility.

There are two ways this driver can handle signal:
1. Analyzing and collecting signals using GPIO interrupts
2. Using GPIO for signal collection and analysis

## Add component to your project

Please use the component manager command `add-dependency` to add the `zero_detection` to your project's dependency, during the `CMake` step the component will be downloaded automatically

```
idf.py add-dependency "espressif/zero_detection=*"
```
```
8 changes: 8 additions & 0 deletions components/zero_detection/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "0.0.1"
description: Zero Cross Detection Driver
url: https://github.com/espressif/esp-iot-solution/tree/master/components/zero_detection
dependencies:
idf: ">=5.0"
espressif/cmake_utilities: "0.*"
examples:
- path: ../../examples/zero_cross_detection
50 changes: 22 additions & 28 deletions components/zero_detection/include/zero_detection.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
#ifndef _ZERO_DETECTION_H_
#define _ZERO_DETECTION_H_

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

#include "driver/gpio.h"
#include "driver/mcpwm_cap.h"
#include "hal/gpio_ll.h"
Expand All @@ -22,7 +17,6 @@
#include "soc/gpio_struct.h"
#include "esp_log.h"
#include "esp_check.h"
#include "esp_private/esp_clk.h"

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
Expand Down Expand Up @@ -83,44 +77,44 @@ typedef union {
* @brief Signal exceeds frequency range data return type
*/
struct {
mcpwm_capture_edge_t cap_edge;
uint32_t full_cycle_us;
mcpwm_capture_edge_t cap_edge; /*!< Trigger edge of zero cross signal */
uint32_t full_cycle_us; /*!< Current signal cycle */
} signal_freq_event_data_t;

/**
* @brief Signal valid data return type
*/
struct {
mcpwm_capture_edge_t cap_edge;
uint32_t full_cycle_us;
uint16_t valid_count;
mcpwm_capture_edge_t cap_edge; /*!< Trigger edge of zero cross signal */
uint32_t full_cycle_us; /*!< Current signal cycle */
uint16_t valid_count; /*!< Counting when the signal is valid */
} signal_valid_event_data_t;

/**
* @brief Signal invalid data return type
*/
struct {
mcpwm_capture_edge_t cap_edge;
uint32_t full_cycle_us;
uint16_t invalid_count;
mcpwm_capture_edge_t cap_edge; /*!< Trigger edge of zero cross signal */
uint32_t full_cycle_us; /*!< Current signal cycle */
uint16_t invalid_count; /*!< Counting when the signal is invalid */
} signal_invalid_event_data_t;

/**
* @brief Signal rising edge data return type
*/
struct {
uint16_t valid_count;
uint16_t invalid_count;
uint32_t full_cycle_us;
uint16_t valid_count; /*!< Counting when the signal is valid */
uint16_t invalid_count; /*!< Counting when the signal is invalid */
uint32_t full_cycle_us; /*!< Current signal cycle */
} signal_rising_edge_event_data_t;

/**
* @brief Signal falling edge data return type
*/
struct {
uint16_t valid_count;
uint16_t invalid_count;
uint32_t full_cycle_us;
uint16_t valid_count; /*!< Counting when the signal is valid */
uint16_t invalid_count; /*!< Counting when the signal is invalid */
uint32_t full_cycle_us; /*!< Current signal cycle */
} signal_falling_edge_event_data_t;
} zero_detect_cb_param_t;

Expand All @@ -133,14 +127,14 @@ typedef int (*esp_zero_detect_cb_t)(zero_detect_event_t zero_detect_event, zero_
* @brief User config data type
*/
typedef struct {
uint32_t capture_pin;
uint16_t valid_time; //Count value when the signal is valid
uint16_t invalid_time; //Count value when thea signl exceeds the frequency range
zero_signal_type_t zero_signal_type; //Zero Crossing Signal Type
zero_driver_type_t zero_driver_type; //Zero crossing driver type
double freq_range_max_hz; //Maximum value of the frequency range when determining a valid signal
double freq_range_min_hz; //Minimum value of the frequency range when determining a valid signal
esp_zero_detect_cb_t event_callback;
int32_t capture_pin; /*!< GPIO number for zero cross detect capture */
uint16_t valid_time; /*!< Comparison value for determining signal validity */
uint16_t invalid_time; /*!< Comparison value for determining signal invalidity */
zero_signal_type_t zero_signal_type; /*!< Zero Crossing Signal type */
zero_driver_type_t zero_driver_type; /*!< Zero crossing driver type */
double freq_range_max_hz; /*!< Maximum value of the frequency range when determining a valid signal */
double freq_range_min_hz; /*!< Minimum value of the frequency range when determining a valid signal */
esp_zero_detect_cb_t event_callback; /*!< Various event returns in zero cross detection */
} zero_detect_config_t;

typedef void *zero_detect_handle_t;
Expand Down
9 changes: 9 additions & 0 deletions components/zero_detection/test_apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 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 "$ENV{IDF_PATH}/tools/unit-test-app/components"
"../../zero_detection")

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(zero_cross_detecion_test)
3 changes: 3 additions & 0 deletions components/zero_detection/test_apps/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils zero_detection)
Loading

0 comments on commit bdb39a4

Please sign in to comment.