esp_gpio_reserve.c 644 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "esp_types.h"
  7. #include "esp_bit_defs.h"
  8. #include "soc/soc_caps.h"
  9. static uint64_t s_reserve_status = 0;
  10. void esp_gpio_reserve_pins(uint64_t mask)
  11. {
  12. #if SOC_GPIO_PIN_COUNT < 64
  13. mask &= BIT64(SOC_GPIO_PIN_COUNT) - 1;
  14. #endif
  15. s_reserve_status |= mask;
  16. }
  17. bool esp_gpio_is_pin_reserved(uint32_t gpio_num)
  18. {
  19. if (gpio_num >= SOC_GPIO_PIN_COUNT) {
  20. return false;
  21. }
  22. return !!(s_reserve_status & BIT64(gpio_num));
  23. }
  24. // TODO: IDF-6968 reserve the pins that not fanned out regarding the SiP version