button_gpio.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  2. *
  3. * SPDX-License-Identifier: Apache-2.0
  4. */
  5. #pragma once
  6. #include "driver/gpio.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /**
  11. * @brief gpio button configuration
  12. *
  13. */
  14. typedef struct {
  15. int32_t gpio_num; /**< num of gpio */
  16. uint8_t active_level; /**< gpio level when press down */
  17. } button_gpio_config_t;
  18. /**
  19. * @brief Initialize gpio button
  20. *
  21. * @param config pointer of configuration struct
  22. *
  23. * @return
  24. * - ESP_OK on success
  25. * - ESP_ERR_INVALID_ARG Arguments is NULL.
  26. */
  27. esp_err_t button_gpio_init(const button_gpio_config_t *config);
  28. /**
  29. * @brief Deinitialize gpio button
  30. *
  31. * @param gpio_num gpio number of button
  32. *
  33. * @return Always return ESP_OK
  34. */
  35. esp_err_t button_gpio_deinit(int gpio_num);
  36. /**
  37. * @brief Get current level on button gpio
  38. *
  39. * @param gpio_num gpio number of button, it will be treated as a uint32_t variable.
  40. *
  41. * @return Level on gpio
  42. */
  43. uint8_t button_gpio_get_key_level(void *gpio_num);
  44. #ifdef __cplusplus
  45. }
  46. #endif