@@ -91,54 +91,49 @@ Create a button
9191.. code :: c
9292
9393 // create gpio button
94- button_config_t gpio_btn_cfg = {
95- .type = BUTTON_TYPE_GPIO,
96- .long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
97- .short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
98- .gpio_button_config = {
99- .gpio_num = 0,
100- .active_level = 0,
101- },
94+ const button_config_t btn_cfg = {0};
95+ const button_gpio_config_t btn_gpio_cfg = {
96+ .gpio_num = 0,
97+ .active_level = 0,
10298 };
103- button_handle_t gpio_btn = iot_button_create(&gpio_btn_cfg);
99+ button_handle_t gpio_btn = NULL;
100+ esp_err_t ret = iot_button_new_gpio_device(&btn_cfg, &btn_gpio_cfg, &gpio_btn);
104101 if(NULL == gpio_btn) {
105102 ESP_LOGE(TAG, "Button create failed");
106103 }
107104
108105 // create adc button
109- button_config_t adc_btn_cfg = {
110- .type = BUTTON_TYPE_ADC,
111- .long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
112- .short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
113- .adc_button_config = {
114- .adc_channel = 0,
115- .button_index = 0,
116- .min = 100,
117- .max = 400,
118- },
106+ const button_config_t btn_cfg = {0};
107+ button_adc_config_t btn_adc_cfg = {
108+ .unit_id = ADC_UNIT_1,
109+ .adc_channel = 0,
110+ .button_index = 0,
111+ .min = 100,
112+ .max = 400,
119113 };
120- button_handle_t adc_btn = iot_button_create(&adc_btn_cfg);
114+
115+ button_handle_t adc_btn = NULL;
116+ esp_err_t ret = iot_button_new_adc_device(&btn_cfg, &btn_adc_cfg, &adc_btn);
121117 if(NULL == adc_btn) {
122118 ESP_LOGE(TAG, "Button create failed");
123119 }
124120
125121 // create matrix keypad button
126- button_config_t matrix_button_cfg = {
127- .type = BUTTON_TYPE_MATRIX,
128- .long_press_time = CONFIG_BUTTON_LONG_PRESS_TIME_MS,
129- .short_press_time = CONFIG_BUTTON_SHORT_PRESS_TIME_MS,
130- .matrix_button_config = {
131- .row_gpio_num = 0,
132- .col_gpio_num = 1,
133- }
122+ const button_config_t btn_cfg = {0};
123+ const button_matrix_config_t matrix_cfg = {
124+ .row_gpios = (int32_t[]){4, 5, 6, 7},
125+ .col_gpios = (int32_t[]){3, 8, 16, 15},
126+ .row_gpio_num = 4,
127+ .col_gpio_num = 4,
134128 };
135- button_handle_t matrix_button = iot_button_create(&matrix_button_cfg);
129+ button_handle_t matrix_button = NULL;
130+ esp_err_t ret = iot_button_new_matrix_device(&btn_cfg, &matrix_cfg, btns, &matrix_button);
136131 if(NULL == matrix_button) {
137132 ESP_LOGE(TAG, "Button create failed");
138133 }
139134
140135 .. Note ::
141- When the IDF version is greater than or equal to release/5.0, the ADC button uses ADC1. If ADC1 is used elsewhere in the project, please provide the ` adc_handle ` and ` adc_channel ` to configure the ADC button.
136+ When using ADC1 for ADC buttons and ADC1 is also used elsewhere in the project, please pass in adc_handle and adc_channel to configure the ADC button.
142137
143138 .. code::C
144139 adc_oneshot_unit_handle_t adc1_handle;
@@ -147,15 +142,19 @@ Create a button
147142 };
148143 //-------------ADC1 Init---------------//
149144 adc_oneshot_new_unit(&init_config1, &adc1_handle);
150- // create adc button
151- button_config_t adc_btn_cfg = {
152- .type = BUTTON_TYPE_ADC,
153- .adc_button_config = {
154- .adc_handle = &adc1_handle,
155- .adc_channel = 1,
156- },
145+
146+ const button_config_t btn_cfg = {0};
147+ button_adc_config_t btn_adc_cfg = {
148+ .adc_handle = &adc1_handle,
149+ .unit_id = ADC_UNIT_1,
150+ .adc_channel = 0,
151+ .button_index = 0,
152+ .min = 100,
153+ .max = 400,
157154 };
158- button_handle_t adc_btn = iot_button_create(&adc_btn_cfg);
155+
156+ button_handle_t adc_btn = NULL;
157+ esp_err_t ret = iot_button_new_adc_device(&btn_cfg, &btn_adc_cfg, &adc_btn);
159158 if(NULL == adc_btn) {
160159 ESP_LOGE(TAG, "Button create failed");
161160 }
0 commit comments