gpio.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include <esp_types.h>
  14. #include "esp_err.h"
  15. #include "esp_intr.h"
  16. #include "esp_intr_alloc.h"
  17. #include "freertos/FreeRTOS.h"
  18. #include "freertos/xtensa_api.h"
  19. #include "driver/gpio.h"
  20. #include "driver/rtc_io.h"
  21. #include "soc/soc.h"
  22. #include "esp_log.h"
  23. static const char* GPIO_TAG = "gpio";
  24. #define GPIO_CHECK(a, str, ret_val) \
  25. if (!(a)) { \
  26. ESP_LOGE(GPIO_TAG,"%s(%d): %s", __FUNCTION__, __LINE__, str); \
  27. return (ret_val); \
  28. }
  29. const uint32_t GPIO_PIN_MUX_REG[GPIO_PIN_COUNT] = {
  30. GPIO_PIN_REG_0,
  31. GPIO_PIN_REG_1,
  32. GPIO_PIN_REG_2,
  33. GPIO_PIN_REG_3,
  34. GPIO_PIN_REG_4,
  35. GPIO_PIN_REG_5,
  36. GPIO_PIN_REG_6,
  37. GPIO_PIN_REG_7,
  38. GPIO_PIN_REG_8,
  39. GPIO_PIN_REG_9,
  40. GPIO_PIN_REG_10,
  41. GPIO_PIN_REG_11,
  42. GPIO_PIN_REG_12,
  43. GPIO_PIN_REG_13,
  44. GPIO_PIN_REG_14,
  45. GPIO_PIN_REG_15,
  46. GPIO_PIN_REG_16,
  47. GPIO_PIN_REG_17,
  48. GPIO_PIN_REG_18,
  49. GPIO_PIN_REG_19,
  50. 0,
  51. GPIO_PIN_REG_21,
  52. GPIO_PIN_REG_22,
  53. GPIO_PIN_REG_23,
  54. 0,
  55. GPIO_PIN_REG_25,
  56. GPIO_PIN_REG_26,
  57. GPIO_PIN_REG_27,
  58. 0,
  59. 0,
  60. 0,
  61. 0,
  62. GPIO_PIN_REG_32,
  63. GPIO_PIN_REG_33,
  64. GPIO_PIN_REG_34,
  65. GPIO_PIN_REG_35,
  66. GPIO_PIN_REG_36,
  67. GPIO_PIN_REG_37,
  68. GPIO_PIN_REG_38,
  69. GPIO_PIN_REG_39
  70. };
  71. typedef struct {
  72. gpio_isr_t fn; /*!< isr function */
  73. void* args; /*!< isr function args */
  74. } gpio_isr_func_t;
  75. static gpio_isr_func_t* gpio_isr_func = NULL;
  76. static gpio_isr_handle_t gpio_isr_handle;
  77. static portMUX_TYPE gpio_spinlock = portMUX_INITIALIZER_UNLOCKED;
  78. esp_err_t gpio_pullup_en(gpio_num_t gpio_num)
  79. {
  80. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  81. if (RTC_GPIO_IS_VALID_GPIO(gpio_num)) {
  82. rtc_gpio_pullup_en(gpio_num);
  83. } else {
  84. REG_SET_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PU);
  85. }
  86. return ESP_OK;
  87. }
  88. esp_err_t gpio_pullup_dis(gpio_num_t gpio_num)
  89. {
  90. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  91. if (RTC_GPIO_IS_VALID_GPIO(gpio_num)) {
  92. rtc_gpio_pullup_dis(gpio_num);
  93. } else {
  94. REG_CLR_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PU);
  95. }
  96. return ESP_OK;
  97. }
  98. esp_err_t gpio_pulldown_en(gpio_num_t gpio_num)
  99. {
  100. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  101. if (RTC_GPIO_IS_VALID_GPIO(gpio_num)) {
  102. rtc_gpio_pulldown_en(gpio_num);
  103. } else {
  104. REG_SET_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PD);
  105. }
  106. return ESP_OK;
  107. }
  108. esp_err_t gpio_pulldown_dis(gpio_num_t gpio_num)
  109. {
  110. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  111. if (RTC_GPIO_IS_VALID_GPIO(gpio_num)) {
  112. rtc_gpio_pulldown_dis(gpio_num);
  113. } else {
  114. REG_CLR_BIT(GPIO_PIN_MUX_REG[gpio_num], FUN_PD);
  115. }
  116. return ESP_OK;
  117. }
  118. esp_err_t gpio_set_intr_type(gpio_num_t gpio_num, gpio_int_type_t intr_type)
  119. {
  120. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  121. GPIO_CHECK(intr_type < GPIO_INTR_MAX, "GPIO interrupt type error", ESP_ERR_INVALID_ARG);
  122. GPIO.pin[gpio_num].int_type = intr_type;
  123. return ESP_OK;
  124. }
  125. static esp_err_t gpio_intr_enable_on_core (gpio_num_t gpio_num, uint32_t core_id)
  126. {
  127. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  128. if (core_id == 0) {
  129. GPIO.pin[gpio_num].int_ena = GPIO_PRO_CPU_INTR_ENA; //enable pro cpu intr
  130. } else {
  131. GPIO.pin[gpio_num].int_ena = GPIO_APP_CPU_INTR_ENA; //enable pro cpu intr
  132. }
  133. return ESP_OK;
  134. }
  135. esp_err_t gpio_intr_enable(gpio_num_t gpio_num)
  136. {
  137. return gpio_intr_enable_on_core (gpio_num, xPortGetCoreID());
  138. }
  139. esp_err_t gpio_intr_disable(gpio_num_t gpio_num)
  140. {
  141. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  142. GPIO.pin[gpio_num].int_ena = 0; //disable GPIO intr
  143. return ESP_OK;
  144. }
  145. static esp_err_t gpio_output_disable(gpio_num_t gpio_num)
  146. {
  147. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  148. if (gpio_num < 32) {
  149. GPIO.enable_w1tc = (0x1 << gpio_num);
  150. } else {
  151. GPIO.enable1_w1tc.data = (0x1 << (gpio_num - 32));
  152. }
  153. // Ensure no other output signal is routed via GPIO matrix to this pin
  154. REG_WRITE(GPIO_FUNC0_OUT_SEL_CFG_REG + (gpio_num * 4),
  155. SIG_GPIO_OUT_IDX);
  156. return ESP_OK;
  157. }
  158. static esp_err_t gpio_output_enable(gpio_num_t gpio_num)
  159. {
  160. GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO output gpio_num error", ESP_ERR_INVALID_ARG);
  161. if (gpio_num < 32) {
  162. GPIO.enable_w1ts = (0x1 << gpio_num);
  163. } else {
  164. GPIO.enable1_w1ts.data = (0x1 << (gpio_num - 32));
  165. }
  166. gpio_matrix_out(gpio_num, SIG_GPIO_OUT_IDX, false, false);
  167. return ESP_OK;
  168. }
  169. esp_err_t gpio_set_level(gpio_num_t gpio_num, uint32_t level)
  170. {
  171. GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO output gpio_num error", ESP_ERR_INVALID_ARG);
  172. if (level) {
  173. if (gpio_num < 32) {
  174. GPIO.out_w1ts = (1 << gpio_num);
  175. } else {
  176. GPIO.out1_w1ts.data = (1 << (gpio_num - 32));
  177. }
  178. } else {
  179. if (gpio_num < 32) {
  180. GPIO.out_w1tc = (1 << gpio_num);
  181. } else {
  182. GPIO.out1_w1tc.data = (1 << (gpio_num - 32));
  183. }
  184. }
  185. return ESP_OK;
  186. }
  187. int gpio_get_level(gpio_num_t gpio_num)
  188. {
  189. if (gpio_num < 32) {
  190. return (GPIO.in >> gpio_num) & 0x1;
  191. } else {
  192. return (GPIO.in1.data >> (gpio_num - 32)) & 0x1;
  193. }
  194. }
  195. esp_err_t gpio_set_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t pull)
  196. {
  197. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  198. GPIO_CHECK(pull <= GPIO_FLOATING, "GPIO pull mode error", ESP_ERR_INVALID_ARG);
  199. esp_err_t ret = ESP_OK;
  200. switch (pull) {
  201. case GPIO_PULLUP_ONLY:
  202. gpio_pulldown_dis(gpio_num);
  203. gpio_pullup_en(gpio_num);
  204. break;
  205. case GPIO_PULLDOWN_ONLY:
  206. gpio_pulldown_en(gpio_num);
  207. gpio_pullup_dis(gpio_num);
  208. break;
  209. case GPIO_PULLUP_PULLDOWN:
  210. gpio_pulldown_en(gpio_num);
  211. gpio_pullup_en(gpio_num);
  212. break;
  213. case GPIO_FLOATING:
  214. gpio_pulldown_dis(gpio_num);
  215. gpio_pullup_dis(gpio_num);
  216. break;
  217. default:
  218. ESP_LOGE(GPIO_TAG, "Unknown pull up/down mode,gpio_num=%u,pull=%u", gpio_num, pull);
  219. ret = ESP_ERR_INVALID_ARG;
  220. break;
  221. }
  222. return ret;
  223. }
  224. esp_err_t gpio_set_direction(gpio_num_t gpio_num, gpio_mode_t mode)
  225. {
  226. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  227. if (gpio_num >= 34 && (mode & GPIO_MODE_DEF_OUTPUT)) {
  228. ESP_LOGE(GPIO_TAG, "io_num=%d can only be input", gpio_num);
  229. return ESP_ERR_INVALID_ARG;
  230. }
  231. esp_err_t ret = ESP_OK;
  232. if (mode & GPIO_MODE_DEF_INPUT) {
  233. PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[gpio_num]);
  234. } else {
  235. PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[gpio_num]);
  236. }
  237. if (mode & GPIO_MODE_DEF_OUTPUT) {
  238. gpio_output_enable(gpio_num);
  239. } else {
  240. gpio_output_disable(gpio_num);
  241. }
  242. if (mode & GPIO_MODE_DEF_OD) {
  243. GPIO.pin[gpio_num].pad_driver = 1;
  244. } else {
  245. GPIO.pin[gpio_num].pad_driver = 0;
  246. }
  247. return ret;
  248. }
  249. esp_err_t gpio_config(const gpio_config_t *pGPIOConfig)
  250. {
  251. uint64_t gpio_pin_mask = (pGPIOConfig->pin_bit_mask);
  252. uint32_t io_reg = 0;
  253. uint32_t io_num = 0;
  254. uint8_t input_en = 0;
  255. uint8_t output_en = 0;
  256. uint8_t od_en = 0;
  257. uint8_t pu_en = 0;
  258. uint8_t pd_en = 0;
  259. if (pGPIOConfig->pin_bit_mask == 0 || pGPIOConfig->pin_bit_mask >= (((uint64_t) 1) << GPIO_PIN_COUNT)) {
  260. ESP_LOGE(GPIO_TAG, "GPIO_PIN mask error ");
  261. return ESP_ERR_INVALID_ARG;
  262. }
  263. if ((pGPIOConfig->mode) & (GPIO_MODE_DEF_OUTPUT)) {
  264. //GPIO 34/35/36/37/38/39 can only be used as input mode;
  265. if ((gpio_pin_mask & ( GPIO_SEL_34 | GPIO_SEL_35 | GPIO_SEL_36 | GPIO_SEL_37 | GPIO_SEL_38 | GPIO_SEL_39))) {
  266. ESP_LOGE(GPIO_TAG, "GPIO34-39 can only be used as input mode");
  267. return ESP_ERR_INVALID_ARG;
  268. }
  269. }
  270. do {
  271. io_reg = GPIO_PIN_MUX_REG[io_num];
  272. if (((gpio_pin_mask >> io_num) & BIT(0)) && io_reg) {
  273. if(RTC_GPIO_IS_VALID_GPIO(io_num)){
  274. rtc_gpio_deinit(io_num);
  275. }
  276. if ((pGPIOConfig->mode) & GPIO_MODE_DEF_INPUT) {
  277. input_en = 1;
  278. PIN_INPUT_ENABLE(GPIO_PIN_MUX_REG[io_num]);
  279. } else {
  280. PIN_INPUT_DISABLE(GPIO_PIN_MUX_REG[io_num]);
  281. }
  282. if ((pGPIOConfig->mode) & GPIO_MODE_DEF_OD) {
  283. od_en = 1;
  284. GPIO.pin[io_num].pad_driver = 1; /*0x01 Open-drain */
  285. } else {
  286. GPIO.pin[io_num].pad_driver = 0; /*0x00 Normal gpio output */
  287. }
  288. if ((pGPIOConfig->mode) & GPIO_MODE_DEF_OUTPUT) {
  289. output_en = 1;
  290. gpio_output_enable(io_num);
  291. } else {
  292. gpio_output_disable(io_num);
  293. }
  294. if (pGPIOConfig->pull_up_en) {
  295. pu_en = 1;
  296. gpio_pullup_en(io_num);
  297. } else {
  298. gpio_pullup_dis(io_num);
  299. }
  300. if (pGPIOConfig->pull_down_en) {
  301. pd_en = 1;
  302. gpio_pulldown_en(io_num);
  303. } else {
  304. gpio_pulldown_dis(io_num);
  305. }
  306. ESP_LOGI(GPIO_TAG, "GPIO[%d]| InputEn: %d| OutputEn: %d| OpenDrain: %d| Pullup: %d| Pulldown: %d| Intr:%d ", io_num, input_en, output_en, od_en, pu_en, pd_en, pGPIOConfig->intr_type);
  307. gpio_set_intr_type(io_num, pGPIOConfig->intr_type);
  308. if (pGPIOConfig->intr_type) {
  309. gpio_intr_enable(io_num);
  310. } else {
  311. gpio_intr_disable(io_num);
  312. }
  313. PIN_FUNC_SELECT(io_reg, PIN_FUNC_GPIO); /*function number 2 is GPIO_FUNC for each pin */
  314. }
  315. io_num++;
  316. } while (io_num < GPIO_PIN_COUNT);
  317. return ESP_OK;
  318. }
  319. void IRAM_ATTR gpio_intr_service(void* arg)
  320. {
  321. //GPIO intr process
  322. uint32_t gpio_num = 0;
  323. //read status to get interrupt status for GPIO0-31
  324. uint32_t gpio_intr_status;
  325. gpio_intr_status = GPIO.status;
  326. //read status1 to get interrupt status for GPIO32-39
  327. uint32_t gpio_intr_status_h;
  328. gpio_intr_status_h = GPIO.status1.intr_st;
  329. if (gpio_isr_func == NULL) {
  330. return;
  331. }
  332. do {
  333. if (gpio_num < 32) {
  334. if (gpio_intr_status & BIT(gpio_num)) { //gpio0-gpio31
  335. if (gpio_isr_func[gpio_num].fn != NULL) {
  336. gpio_isr_func[gpio_num].fn(gpio_isr_func[gpio_num].args);
  337. }
  338. GPIO.status_w1tc = BIT(gpio_num);
  339. }
  340. } else {
  341. if (gpio_intr_status_h & BIT(gpio_num - 32)) {
  342. if (gpio_isr_func[gpio_num].fn != NULL) {
  343. gpio_isr_func[gpio_num].fn(gpio_isr_func[gpio_num].args);
  344. }
  345. GPIO.status1_w1tc.intr_st = BIT(gpio_num - 32);
  346. }
  347. }
  348. } while (++gpio_num < GPIO_PIN_COUNT);
  349. }
  350. esp_err_t gpio_isr_handler_add(gpio_num_t gpio_num, gpio_isr_t isr_handler, void* args)
  351. {
  352. GPIO_CHECK(gpio_isr_func != NULL, "GPIO isr service is not installed, call gpio_install_isr_service() first", ESP_ERR_INVALID_STATE);
  353. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  354. portENTER_CRITICAL(&gpio_spinlock);
  355. gpio_intr_disable(gpio_num);
  356. if (gpio_isr_func) {
  357. gpio_isr_func[gpio_num].fn = isr_handler;
  358. gpio_isr_func[gpio_num].args = args;
  359. }
  360. gpio_intr_enable_on_core (gpio_num, esp_intr_get_cpu(gpio_isr_handle));
  361. portEXIT_CRITICAL(&gpio_spinlock);
  362. return ESP_OK;
  363. }
  364. esp_err_t gpio_isr_handler_remove(gpio_num_t gpio_num)
  365. {
  366. GPIO_CHECK(gpio_isr_func != NULL, "GPIO isr service is not installed, call gpio_install_isr_service() first", ESP_ERR_INVALID_STATE);
  367. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  368. portENTER_CRITICAL(&gpio_spinlock);
  369. gpio_intr_disable(gpio_num);
  370. if (gpio_isr_func) {
  371. gpio_isr_func[gpio_num].fn = NULL;
  372. gpio_isr_func[gpio_num].args = NULL;
  373. }
  374. portEXIT_CRITICAL(&gpio_spinlock);
  375. return ESP_OK;
  376. }
  377. esp_err_t gpio_install_isr_service(int intr_alloc_flags)
  378. {
  379. GPIO_CHECK(gpio_isr_func == NULL, "GPIO isr service already installed", ESP_FAIL);
  380. esp_err_t ret;
  381. portENTER_CRITICAL(&gpio_spinlock);
  382. gpio_isr_func = (gpio_isr_func_t*) calloc(GPIO_NUM_MAX, sizeof(gpio_isr_func_t));
  383. if (gpio_isr_func == NULL) {
  384. ret = ESP_ERR_NO_MEM;
  385. } else {
  386. ret = gpio_isr_register(gpio_intr_service, NULL, intr_alloc_flags, &gpio_isr_handle);
  387. }
  388. portEXIT_CRITICAL(&gpio_spinlock);
  389. return ret;
  390. }
  391. void gpio_uninstall_isr_service()
  392. {
  393. if (gpio_isr_func == NULL) {
  394. return;
  395. }
  396. portENTER_CRITICAL(&gpio_spinlock);
  397. esp_intr_free(gpio_isr_handle);
  398. free(gpio_isr_func);
  399. gpio_isr_func = NULL;
  400. portEXIT_CRITICAL(&gpio_spinlock);
  401. return;
  402. }
  403. esp_err_t gpio_isr_register(void (*fn)(void*), void * arg, int intr_alloc_flags, gpio_isr_handle_t *handle)
  404. {
  405. GPIO_CHECK(fn, "GPIO ISR null", ESP_ERR_INVALID_ARG);
  406. return esp_intr_alloc(ETS_GPIO_INTR_SOURCE, intr_alloc_flags, fn, arg, handle);
  407. }
  408. /*only level interrupt can be used for wake-up function*/
  409. esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type)
  410. {
  411. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  412. esp_err_t ret = ESP_OK;
  413. if (( intr_type == GPIO_INTR_LOW_LEVEL ) || ( intr_type == GPIO_INTR_HIGH_LEVEL )) {
  414. GPIO.pin[gpio_num].int_type = intr_type;
  415. GPIO.pin[gpio_num].wakeup_enable = 0x1;
  416. } else {
  417. ESP_LOGE(GPIO_TAG, "GPIO wakeup only support Level mode,but edge mode set. gpio_num:%u", gpio_num);
  418. ret = ESP_ERR_INVALID_ARG;
  419. }
  420. return ret;
  421. }
  422. esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num)
  423. {
  424. GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  425. GPIO.pin[gpio_num].wakeup_enable = 0;
  426. return ESP_OK;
  427. }
  428. esp_err_t gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength)
  429. {
  430. GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  431. GPIO_CHECK(strength < GPIO_DRIVE_CAP_MAX, "GPIO drive capability error", ESP_ERR_INVALID_ARG);
  432. if (RTC_GPIO_IS_VALID_GPIO(gpio_num)) {
  433. rtc_gpio_set_drive_capability(gpio_num, strength);
  434. } else {
  435. SET_PERI_REG_BITS(GPIO_PIN_MUX_REG[gpio_num], FUN_DRV_V, strength, FUN_DRV_S);
  436. }
  437. return ESP_OK;
  438. }
  439. esp_err_t gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t* strength)
  440. {
  441. GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
  442. GPIO_CHECK(strength != NULL, "GPIO drive capability pointer error", ESP_ERR_INVALID_ARG);
  443. if (RTC_GPIO_IS_VALID_GPIO(gpio_num)) {
  444. return rtc_gpio_get_drive_capability(gpio_num, strength);
  445. } else {
  446. *strength = GET_PERI_REG_BITS2(GPIO_PIN_MUX_REG[gpio_num], FUN_DRV_V, FUN_DRV_S);
  447. }
  448. return ESP_OK;
  449. }