Skip to content

Commit

Permalink
Merge branch 'feat/knob_add_power_save' into 'master'
Browse files Browse the repository at this point in the history
feat(knob): add power save support

See merge request ae_group/esp-iot-solution!1043
  • Loading branch information
lijunru-hub committed Jul 8, 2024
2 parents d8782c7 + 128269e commit 593e59b
Show file tree
Hide file tree
Showing 26 changed files with 732 additions and 56 deletions.
8 changes: 8 additions & 0 deletions .gitlab/ci/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,14 @@ build_example_get_started_button_power_save:
variables:
EXAMPLE_DIR: examples/get-started/button_power_save

build_example_get_started_knob_power_save:
extends:
- .build_examples_template
- .rules:build:example_get_started_knob_power_save
- .build_idf_active_release_version
variables:
EXAMPLE_DIR: examples/get-started/knob_power_save

build_example_gprof_gprof_simple:
extends:
- .build_examples_template
Expand Down
18 changes: 16 additions & 2 deletions .gitlab/ci/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
- "components/i2c_bus/include/i2c_bus.h"
- "components/ir/ir_learn/include/ir_learn.h"
- "components/keyboard_button/include/keyboard_button.h"
- "components/knob/iot_knob.h"
- "components/knob/include/iot_knob.h"
- "components/led/led_indicator/include/led_indicator.h"
- "components/motor/esp_sensorless_bldc_control/control/include/bldc_control.h"
- "components/motor/esp_sensorless_bldc_control/control/include/bldc_control_param.h"
Expand Down Expand Up @@ -418,6 +418,9 @@
.patterns-example_get_started_button_power_save: &patterns-example_get_started_button_power_save
- "examples/get-started/button_power_save/**/*"

.patterns-example_get_started_knob_power_save: &patterns-example_get_started_knob_power_save
- "examples/get-started/knob_power_save/**/*"

.patterns-example_indicator: &patterns-example_indicator
- "examples/indicator/**/*"

Expand Down Expand Up @@ -885,6 +888,18 @@
- <<: *if-dev-push
changes: *patterns-example_get_started_button_power_save

.rules:build:example_get_started_knob_power_save:
rules:
- <<: *if-protected
- <<: *if-label-build
- <<: *if-trigger-job
- <<: *if-dev-push
changes: *patterns-build_system
- <<: *if-dev-push
changes: *patterns-components_knob
- <<: *if-dev-push
changes: *patterns-example_get_started_knob_power_save

.rules:build:example_gprof_gprof_simple:
rules:
- <<: *if-protected
Expand Down Expand Up @@ -1635,7 +1650,6 @@
- <<: *if-dev-push
changes: *patterns-components_keyboard_button


.rules:build:components_expander_io_expander_mcp23017_test:
rules:
- <<: *if-protected
Expand Down
5 changes: 5 additions & 0 deletions components/knob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ChangeLog

## v0.1.5 - 2024-7-3

### Enhancements:
* Support power save mode

## v0.1.4 - 2023-11-23

* Fix possible cmake_utilities dependency issue
Expand Down
4 changes: 2 additions & 2 deletions components/knob/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
idf_component_register(SRCS "iot_knob.c"
INCLUDE_DIRS "."
idf_component_register(SRCS "iot_knob.c" "knob_gpio.c"
INCLUDE_DIRS "include"
REQUIRES driver
PRIV_REQUIRES esp_timer)

Expand Down
3 changes: 2 additions & 1 deletion components/knob/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "0.1.4"
version: "0.1.5"
description: Knob driver implemented through software pcnt
url: https://github.com/espressif/esp-iot-solution/tree/master/components/knob
documentation: https://docs.espressif.com/projects/esp-iot-solution/en/latest/input_device/knob.html
Expand All @@ -9,3 +9,4 @@ dependencies:
cmake_utilities: "0.*"
examples:
- path: ../../examples/usb/device/usb_surface_dial
- path: ../../examples/get-started/knob_power_save
23 changes: 23 additions & 0 deletions components/knob/iot_knob.h → components/knob/include/iot_knob.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#pragma once

#include <stdint.h>
#include "esp_err.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -24,6 +27,7 @@ typedef enum {
KNOB_L_LIM, /*!< EVENT: Count reaches the minimum limit */
KNOB_ZERO, /*!< EVENT: Count back to 0 */
KNOB_EVENT_MAX, /*!< EVENT: Number of events */
KNOB_NONE, /*!< EVENT: No event */
} knob_event_t;

/**
Expand All @@ -34,6 +38,7 @@ typedef struct {
uint8_t default_direction; /*!< 0:positive increase 1:negative increase */
uint8_t gpio_encoder_a; /*!< Encoder Pin A */
uint8_t gpio_encoder_b; /*!< Encoder Pin B */
bool enable_power_save; /*!< Enable power save mode */
} knob_config_t;

/**
Expand Down Expand Up @@ -110,6 +115,24 @@ int iot_knob_get_count_value(knob_handle_t knob_handle);
*/
esp_err_t iot_knob_clear_count_value(knob_handle_t knob_handle);

/**
* @brief resume knob timer, if knob timer is stopped. Make sure iot_knob_create() is called before calling this API.
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_STATE timer state is invalid.
*/
esp_err_t iot_knob_resume(void);

/**
* @brief stop knob timer, if knob timer is running. Make sure iot_knob_create() is called before calling this API.
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_STATE timer state is invalid
*/
esp_err_t iot_knob_stop(void);

#ifdef __cplusplus
}
#endif
126 changes: 126 additions & 0 deletions components/knob/include/knob_gpio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

#include "esp_err.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Initialize a GPIO pin for knob input.
*
* This function configures a specified GPIO pin as an input for knob control.
* It sets the pin mode, disables interrupts, and enables the pull-up resistor.
*
* @param gpio_num The GPIO number to be configured.
* @return
* - ESP_OK: Configuration successful.
* - ESP_ERR_INVALID_ARG: Parameter error.
* - ESP_FAIL: Configuration failed.
*/
esp_err_t knob_gpio_init(uint32_t gpio_num);

/**
* @brief Deinitialize a GPIO pin for knob input.
*
* This function resets the specified GPIO pin.
*
* @param gpio_num The GPIO number to be deinitialized.
* @return
* - ESP_OK: Reset successful.
* - ESP_FAIL: Reset failed.
*/
esp_err_t knob_gpio_deinit(uint32_t gpio_num);

/**
* @brief Get the level of a GPIO pin.
*
* This function returns the current level (high or low) of the specified GPIO pin.
*
* @param gpio_num The GPIO number to read the level from.
* @return The level of the GPIO pin (0 or 1).
*/
uint8_t knob_gpio_get_key_level(void *gpio_num);

/**
* @brief Initialize a GPIO pin with interrupt capability for knob input.
*
* This function configures a specified GPIO pin to trigger interrupts and installs
* an ISR service if not already installed. It adds an ISR handler for the GPIO pin.
*
* @param gpio_num The GPIO number to be configured.
* @param intr_type The type of interrupt to be configured.
* @param isr_handler The ISR handler function to be called on interrupt.
* @param args Arguments to be passed to the ISR handler.
* @return
* - ESP_OK: Configuration successful.
* - ESP_ERR_INVALID_ARG: Parameter error.
* - ESP_FAIL: Configuration failed.
*/
esp_err_t knob_gpio_init_intr(uint32_t gpio_num, gpio_int_type_t intr_type, gpio_isr_t isr_handler, void *args);

/**
* @brief Set the interrupt type for a GPIO pin.
*
* This function sets the interrupt type for the specified GPIO pin.
*
* @param gpio_num The GPIO number to configure.
* @param intr_type The type of interrupt to be configured.
* @return
* - ESP_OK: Configuration successful.
* - ESP_ERR_INVALID_ARG: Parameter error.
* - ESP_FAIL: Configuration failed.
*/
esp_err_t knob_gpio_set_intr(uint32_t gpio_num, gpio_int_type_t intr_type);

/**
* @brief Control the interrupt for a GPIO pin.
*
* This function enables or disables the interrupt for the specified GPIO pin.
*
* @param gpio_num The GPIO number to configure.
* @param enable Whether to enable or disable the interrupt.
* @return
* - ESP_OK: Configuration successful.
* - ESP_ERR_INVALID_ARG: Parameter error.
* - ESP_FAIL: Configuration failed.
*/
esp_err_t knob_gpio_intr_control(uint32_t gpio_num, bool enable);

/**
* @brief Control the wake up functionality of GPIO pins.
*
* This function enables or disables the wake up functionality from GPIO pins.
*
* @param enable Whether to enable or disable the wake up functionality.
* @param wake_up_level Level of the GPIO when triggered.
* @param enable Enable or disable the GPIO wakeup.
* @return
* - ESP_OK: Operation successful.
* - ESP_FAIL: Operation failed.
*/
esp_err_t knob_gpio_wake_up_control(uint32_t gpio_num, uint8_t wake_up_level, bool enable);

/**
* @brief Initialize wake up functionality for a GPIO pin.
*
* This function configures a specified GPIO pin to wake up the system from sleep
* based on the specified wake up level.
*
* @param gpio_num The GPIO number to configure.
* @param wake_up_level The level (0 or 1) to trigger wake up.
* @return
* - ESP_OK: Configuration successful.
* - ESP_ERR_INVALID_ARG: Parameter error.
* - ESP_FAIL: Configuration failed.
*/
esp_err_t knob_gpio_wake_up_init(uint32_t gpio_num, uint8_t wake_up_level);

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit 593e59b

Please sign in to comment.