Skip to content

Commit 593e59b

Browse files
committed
Merge branch 'feat/knob_add_power_save' into 'master'
feat(knob): add power save support See merge request ae_group/esp-iot-solution!1043
2 parents d8782c7 + 128269e commit 593e59b

26 files changed

+732
-56
lines changed

.gitlab/ci/build.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,14 @@ build_example_get_started_button_power_save:
445445
variables:
446446
EXAMPLE_DIR: examples/get-started/button_power_save
447447

448+
build_example_get_started_knob_power_save:
449+
extends:
450+
- .build_examples_template
451+
- .rules:build:example_get_started_knob_power_save
452+
- .build_idf_active_release_version
453+
variables:
454+
EXAMPLE_DIR: examples/get-started/knob_power_save
455+
448456
build_example_gprof_gprof_simple:
449457
extends:
450458
- .build_examples_template

.gitlab/ci/rules.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@
301301
- "components/i2c_bus/include/i2c_bus.h"
302302
- "components/ir/ir_learn/include/ir_learn.h"
303303
- "components/keyboard_button/include/keyboard_button.h"
304-
- "components/knob/iot_knob.h"
304+
- "components/knob/include/iot_knob.h"
305305
- "components/led/led_indicator/include/led_indicator.h"
306306
- "components/motor/esp_sensorless_bldc_control/control/include/bldc_control.h"
307307
- "components/motor/esp_sensorless_bldc_control/control/include/bldc_control_param.h"
@@ -418,6 +418,9 @@
418418
.patterns-example_get_started_button_power_save: &patterns-example_get_started_button_power_save
419419
- "examples/get-started/button_power_save/**/*"
420420

421+
.patterns-example_get_started_knob_power_save: &patterns-example_get_started_knob_power_save
422+
- "examples/get-started/knob_power_save/**/*"
423+
421424
.patterns-example_indicator: &patterns-example_indicator
422425
- "examples/indicator/**/*"
423426

@@ -885,6 +888,18 @@
885888
- <<: *if-dev-push
886889
changes: *patterns-example_get_started_button_power_save
887890

891+
.rules:build:example_get_started_knob_power_save:
892+
rules:
893+
- <<: *if-protected
894+
- <<: *if-label-build
895+
- <<: *if-trigger-job
896+
- <<: *if-dev-push
897+
changes: *patterns-build_system
898+
- <<: *if-dev-push
899+
changes: *patterns-components_knob
900+
- <<: *if-dev-push
901+
changes: *patterns-example_get_started_knob_power_save
902+
888903
.rules:build:example_gprof_gprof_simple:
889904
rules:
890905
- <<: *if-protected
@@ -1635,7 +1650,6 @@
16351650
- <<: *if-dev-push
16361651
changes: *patterns-components_keyboard_button
16371652

1638-
16391653
.rules:build:components_expander_io_expander_mcp23017_test:
16401654
rules:
16411655
- <<: *if-protected

components/knob/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# ChangeLog
22

3+
## v0.1.5 - 2024-7-3
4+
5+
### Enhancements:
6+
* Support power save mode
7+
38
## v0.1.4 - 2023-11-23
49

510
* Fix possible cmake_utilities dependency issue

components/knob/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
idf_component_register(SRCS "iot_knob.c"
2-
INCLUDE_DIRS "."
1+
idf_component_register(SRCS "iot_knob.c" "knob_gpio.c"
2+
INCLUDE_DIRS "include"
33
REQUIRES driver
44
PRIV_REQUIRES esp_timer)
55

components/knob/idf_component.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.1.4"
1+
version: "0.1.5"
22
description: Knob driver implemented through software pcnt
33
url: https://github.com/espressif/esp-iot-solution/tree/master/components/knob
44
documentation: https://docs.espressif.com/projects/esp-iot-solution/en/latest/input_device/knob.html
@@ -9,3 +9,4 @@ dependencies:
99
cmake_utilities: "0.*"
1010
examples:
1111
- path: ../../examples/usb/device/usb_surface_dial
12+
- path: ../../examples/get-started/knob_power_save

components/knob/iot_knob.h renamed to components/knob/include/iot_knob.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
#pragma once
88

9+
#include <stdint.h>
10+
#include "esp_err.h"
11+
912
#ifdef __cplusplus
1013
extern "C" {
1114
#endif
@@ -24,6 +27,7 @@ typedef enum {
2427
KNOB_L_LIM, /*!< EVENT: Count reaches the minimum limit */
2528
KNOB_ZERO, /*!< EVENT: Count back to 0 */
2629
KNOB_EVENT_MAX, /*!< EVENT: Number of events */
30+
KNOB_NONE, /*!< EVENT: No event */
2731
} knob_event_t;
2832

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

3944
/**
@@ -110,6 +115,24 @@ int iot_knob_get_count_value(knob_handle_t knob_handle);
110115
*/
111116
esp_err_t iot_knob_clear_count_value(knob_handle_t knob_handle);
112117

118+
/**
119+
* @brief resume knob timer, if knob timer is stopped. Make sure iot_knob_create() is called before calling this API.
120+
*
121+
* @return
122+
* - ESP_OK on success
123+
* - ESP_ERR_INVALID_STATE timer state is invalid.
124+
*/
125+
esp_err_t iot_knob_resume(void);
126+
127+
/**
128+
* @brief stop knob timer, if knob timer is running. Make sure iot_knob_create() is called before calling this API.
129+
*
130+
* @return
131+
* - ESP_OK on success
132+
* - ESP_ERR_INVALID_STATE timer state is invalid
133+
*/
134+
esp_err_t iot_knob_stop(void);
135+
113136
#ifdef __cplusplus
114137
}
115138
#endif

components/knob/include/knob_gpio.h

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#pragma once
7+
8+
#include "esp_err.h"
9+
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
/**
15+
* @brief Initialize a GPIO pin for knob input.
16+
*
17+
* This function configures a specified GPIO pin as an input for knob control.
18+
* It sets the pin mode, disables interrupts, and enables the pull-up resistor.
19+
*
20+
* @param gpio_num The GPIO number to be configured.
21+
* @return
22+
* - ESP_OK: Configuration successful.
23+
* - ESP_ERR_INVALID_ARG: Parameter error.
24+
* - ESP_FAIL: Configuration failed.
25+
*/
26+
esp_err_t knob_gpio_init(uint32_t gpio_num);
27+
28+
/**
29+
* @brief Deinitialize a GPIO pin for knob input.
30+
*
31+
* This function resets the specified GPIO pin.
32+
*
33+
* @param gpio_num The GPIO number to be deinitialized.
34+
* @return
35+
* - ESP_OK: Reset successful.
36+
* - ESP_FAIL: Reset failed.
37+
*/
38+
esp_err_t knob_gpio_deinit(uint32_t gpio_num);
39+
40+
/**
41+
* @brief Get the level of a GPIO pin.
42+
*
43+
* This function returns the current level (high or low) of the specified GPIO pin.
44+
*
45+
* @param gpio_num The GPIO number to read the level from.
46+
* @return The level of the GPIO pin (0 or 1).
47+
*/
48+
uint8_t knob_gpio_get_key_level(void *gpio_num);
49+
50+
/**
51+
* @brief Initialize a GPIO pin with interrupt capability for knob input.
52+
*
53+
* This function configures a specified GPIO pin to trigger interrupts and installs
54+
* an ISR service if not already installed. It adds an ISR handler for the GPIO pin.
55+
*
56+
* @param gpio_num The GPIO number to be configured.
57+
* @param intr_type The type of interrupt to be configured.
58+
* @param isr_handler The ISR handler function to be called on interrupt.
59+
* @param args Arguments to be passed to the ISR handler.
60+
* @return
61+
* - ESP_OK: Configuration successful.
62+
* - ESP_ERR_INVALID_ARG: Parameter error.
63+
* - ESP_FAIL: Configuration failed.
64+
*/
65+
esp_err_t knob_gpio_init_intr(uint32_t gpio_num, gpio_int_type_t intr_type, gpio_isr_t isr_handler, void *args);
66+
67+
/**
68+
* @brief Set the interrupt type for a GPIO pin.
69+
*
70+
* This function sets the interrupt type for the specified GPIO pin.
71+
*
72+
* @param gpio_num The GPIO number to configure.
73+
* @param intr_type The type of interrupt to be configured.
74+
* @return
75+
* - ESP_OK: Configuration successful.
76+
* - ESP_ERR_INVALID_ARG: Parameter error.
77+
* - ESP_FAIL: Configuration failed.
78+
*/
79+
esp_err_t knob_gpio_set_intr(uint32_t gpio_num, gpio_int_type_t intr_type);
80+
81+
/**
82+
* @brief Control the interrupt for a GPIO pin.
83+
*
84+
* This function enables or disables the interrupt for the specified GPIO pin.
85+
*
86+
* @param gpio_num The GPIO number to configure.
87+
* @param enable Whether to enable or disable the interrupt.
88+
* @return
89+
* - ESP_OK: Configuration successful.
90+
* - ESP_ERR_INVALID_ARG: Parameter error.
91+
* - ESP_FAIL: Configuration failed.
92+
*/
93+
esp_err_t knob_gpio_intr_control(uint32_t gpio_num, bool enable);
94+
95+
/**
96+
* @brief Control the wake up functionality of GPIO pins.
97+
*
98+
* This function enables or disables the wake up functionality from GPIO pins.
99+
*
100+
* @param enable Whether to enable or disable the wake up functionality.
101+
* @param wake_up_level Level of the GPIO when triggered.
102+
* @param enable Enable or disable the GPIO wakeup.
103+
* @return
104+
* - ESP_OK: Operation successful.
105+
* - ESP_FAIL: Operation failed.
106+
*/
107+
esp_err_t knob_gpio_wake_up_control(uint32_t gpio_num, uint8_t wake_up_level, bool enable);
108+
109+
/**
110+
* @brief Initialize wake up functionality for a GPIO pin.
111+
*
112+
* This function configures a specified GPIO pin to wake up the system from sleep
113+
* based on the specified wake up level.
114+
*
115+
* @param gpio_num The GPIO number to configure.
116+
* @param wake_up_level The level (0 or 1) to trigger wake up.
117+
* @return
118+
* - ESP_OK: Configuration successful.
119+
* - ESP_ERR_INVALID_ARG: Parameter error.
120+
* - ESP_FAIL: Configuration failed.
121+
*/
122+
esp_err_t knob_gpio_wake_up_init(uint32_t gpio_num, uint8_t wake_up_level);
123+
124+
#ifdef __cplusplus
125+
}
126+
#endif

0 commit comments

Comments
 (0)