test_gpio.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. /**
  2. * About test environment UT_T1_GPIO:
  3. * Please connect GPIO18 and GPIO19
  4. */
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include "esp_system.h"
  8. #include "esp_sleep.h"
  9. #include "unity.h"
  10. #include "driver/gpio.h"
  11. #include "freertos/FreeRTOS.h"
  12. #include "freertos/task.h"
  13. #include "freertos/queue.h"
  14. #include "sdkconfig.h"
  15. #if CONFIG_IDF_TARGET_ESP32
  16. #include "esp32/rom/uart.h"
  17. #elif CONFIG_IDF_TARGET_ESP32S2
  18. #include "esp32s2/rom/uart.h"
  19. #endif
  20. #define WAKE_UP_IGNORE 1 // gpio_wakeup function development is not completed yet, set it deprecated.
  21. #if CONFIG_IDF_TARGET_ESP32
  22. #define TEST_GPIO_EXT_OUT_IO 18 // default output GPIO
  23. #define TEST_GPIO_EXT_IN_IO 19 // default input GPIO
  24. #define TEST_GPIO_OUTPUT_PIN 23
  25. #define TEST_GPIO_INPUT_ONLY_PIN 34
  26. #define TEST_GPIO_OUTPUT_MAX GPIO_NUM_34
  27. #elif CONFIG_IDF_TARGET_ESP32S2
  28. // ESP32_S2 DEVKIC uses IO19 and IO20 as USB functions, so it is necessary to avoid using IO19, otherwise GPIO io pull up/down function cannot pass
  29. // Also the first version of ESP32-S2-Saola has pullup issue on GPIO18, which is tied to 3V3 on the
  30. // runner. Also avoid using GPIO18.
  31. #define TEST_GPIO_EXT_OUT_IO 17 // default output GPIO
  32. #define TEST_GPIO_EXT_IN_IO 21 // default input GPIO
  33. #define TEST_GPIO_OUTPUT_PIN 26
  34. #define TEST_GPIO_INPUT_ONLY_PIN 46
  35. #define TEST_GPIO_OUTPUT_MAX GPIO_NUM_46
  36. #endif
  37. static volatile int disable_intr_times = 0; // use this to calculate how many times it go into interrupt
  38. static volatile int level_intr_times = 0; // use this to get how many times the level interrupt happened
  39. static volatile int edge_intr_times = 0; // use this to get how many times the edge interrupt happened
  40. #if !WAKE_UP_IGNORE
  41. static bool wake_up_result = false; // use this to judge the wake up event happen or not
  42. #endif
  43. /**
  44. * do some initialization operation in this function
  45. * @param num: it is the destination GPIO wanted to be initialized
  46. *
  47. */
  48. static gpio_config_t init_io(gpio_num_t num)
  49. {
  50. TEST_ASSERT(num < TEST_GPIO_OUTPUT_MAX);
  51. gpio_config_t io_conf;
  52. io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
  53. io_conf.mode = GPIO_MODE_OUTPUT;
  54. io_conf.pin_bit_mask = (1ULL << num);
  55. io_conf.pull_down_en = 0;
  56. io_conf.pull_up_en = 0;
  57. return io_conf;
  58. }
  59. #if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2)
  60. //No runners
  61. // edge interrupt event
  62. static void gpio_isr_edge_handler(void* arg)
  63. {
  64. uint32_t gpio_num = (uint32_t) arg;
  65. ets_printf("GPIO[%d] intr, val: %d\n", gpio_num, gpio_get_level(gpio_num));
  66. edge_intr_times++;
  67. }
  68. // level interrupt event with "gpio_intr_disable"
  69. static void gpio_isr_level_handler(void* arg)
  70. {
  71. uint32_t gpio_num = (uint32_t) arg;
  72. disable_intr_times++;
  73. ets_printf("GPIO[%d] intr, val: %d, disable_intr_times = %d\n", gpio_num, gpio_get_level(gpio_num), disable_intr_times);
  74. gpio_intr_disable(gpio_num);
  75. }
  76. // level interrupt event
  77. static void gpio_isr_level_handler2(void* arg)
  78. {
  79. uint32_t gpio_num = (uint32_t) arg;
  80. level_intr_times++;
  81. ets_printf("GPIO[%d] intr, val: %d\n", gpio_num, gpio_get_level(gpio_num));
  82. if(gpio_get_level(gpio_num)) {
  83. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0);
  84. }else{
  85. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1);
  86. }
  87. ets_printf("GPIO[%d] intr, val: %d, level_intr_times = %d\n", TEST_GPIO_EXT_OUT_IO, gpio_get_level(TEST_GPIO_EXT_OUT_IO), level_intr_times);
  88. ets_printf("GPIO[%d] intr, val: %d, level_intr_times = %d\n", gpio_num, gpio_get_level(gpio_num), level_intr_times);
  89. }
  90. #endif
  91. #if !WAKE_UP_IGNORE
  92. // get result of waking up or not
  93. static void sleep_wake_up(void *arg)
  94. {
  95. gpio_config_t io_config = init_io(TEST_GPIO_EXT_IN_IO);
  96. io_config.mode = GPIO_MODE_INPUT;
  97. gpio_config(&io_config);
  98. TEST_ESP_OK(gpio_wakeup_enable(TEST_GPIO_EXT_IN_IO, GPIO_INTR_HIGH_LEVEL));
  99. esp_light_sleep_start();
  100. wake_up_result = true;
  101. }
  102. // wake up light sleep event
  103. static void trigger_wake_up(void *arg)
  104. {
  105. gpio_config_t io_config = init_io(TEST_GPIO_EXT_OUT_IO);
  106. gpio_config(&io_config);
  107. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0);
  108. gpio_install_isr_service(0);
  109. gpio_isr_handler_add(TEST_GPIO_EXT_OUT_IO, gpio_isr_level_handler, (void*) TEST_GPIO_EXT_IN_IO);
  110. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1);
  111. vTaskDelay(100 / portTICK_RATE_MS);
  112. }
  113. #endif
  114. static void prompt_to_continue(const char* str)
  115. {
  116. printf("%s , please press \"Enter\" to go on!\n", str);
  117. char sign[5] = {0};
  118. while(strlen(sign) == 0) {
  119. /* Flush anything already in the RX buffer */
  120. while(uart_rx_one_char((uint8_t *) sign) == OK) {
  121. }
  122. /* Read line */
  123. UartRxString((uint8_t*) sign, sizeof(sign) - 1);
  124. }
  125. }
  126. static void drive_capability_set_get(gpio_num_t num, gpio_drive_cap_t capability)
  127. {
  128. gpio_config_t pad_io = init_io(num);
  129. TEST_ESP_OK(gpio_config(&pad_io));
  130. TEST_ASSERT(gpio_set_drive_capability(num, GPIO_DRIVE_CAP_MAX) == ESP_ERR_INVALID_ARG);
  131. gpio_drive_cap_t cap;
  132. TEST_ESP_OK(gpio_set_drive_capability(num, capability));
  133. TEST_ESP_OK(gpio_get_drive_capability(num, &cap));
  134. TEST_ASSERT_EQUAL_INT(cap, capability);
  135. }
  136. // test the basic configuration function with right parameters and error parameters
  137. TEST_CASE("GPIO config parameters test", "[gpio]")
  138. {
  139. //error param test
  140. //ESP32 test 41 bit, ESP32-S2 test 48 bit
  141. gpio_config_t io_config;
  142. io_config.intr_type = GPIO_PIN_INTR_DISABLE;
  143. io_config.pin_bit_mask = ((uint64_t)1<<(GPIO_NUM_MAX+1));
  144. TEST_ASSERT(gpio_config(&io_config) == ESP_ERR_INVALID_ARG);
  145. // test 0
  146. io_config.pin_bit_mask = 0;
  147. TEST_ASSERT(gpio_config(&io_config) == ESP_ERR_INVALID_ARG);
  148. //ESP32 test 40 bit, ESP32-S2 test 47 bit
  149. io_config.pin_bit_mask = ((uint64_t)1<<GPIO_NUM_MAX);
  150. TEST_ASSERT(gpio_config(&io_config) == ESP_ERR_INVALID_ARG);
  151. io_config.pin_bit_mask = ((uint64_t)1<<TEST_GPIO_OUTPUT_PIN);
  152. TEST_ESP_OK(gpio_config(&io_config));
  153. io_config.pin_bit_mask = ((uint64_t)1 << TEST_GPIO_INPUT_ONLY_PIN);
  154. io_config.mode = GPIO_MODE_INPUT;
  155. TEST_ESP_OK(gpio_config(&io_config));
  156. io_config.mode = GPIO_MODE_OUTPUT;
  157. // The pin is input only, once set as output should log something
  158. TEST_ASSERT(gpio_config(&io_config) == ESP_ERR_INVALID_ARG);
  159. }
  160. #if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2)
  161. //No runners
  162. TEST_CASE("GPIO rising edge interrupt test", "[gpio][test_env=UT_T1_GPIO]")
  163. {
  164. edge_intr_times = 0; // set it as 0 prepare to test
  165. //init input and output gpio
  166. gpio_config_t output_io = init_io(TEST_GPIO_EXT_OUT_IO);
  167. gpio_config_t input_io = init_io(TEST_GPIO_EXT_IN_IO);
  168. input_io.intr_type = GPIO_INTR_POSEDGE;
  169. input_io.mode = GPIO_MODE_INPUT;
  170. input_io.pull_up_en = 1;
  171. TEST_ESP_OK(gpio_config(&output_io));
  172. TEST_ESP_OK(gpio_config(&input_io));
  173. TEST_ESP_OK(gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0));
  174. //rising edge intr
  175. TEST_ESP_OK(gpio_set_intr_type(TEST_GPIO_EXT_IN_IO, GPIO_INTR_POSEDGE));
  176. TEST_ESP_OK(gpio_install_isr_service(0));
  177. gpio_isr_handler_add(TEST_GPIO_EXT_IN_IO, gpio_isr_edge_handler, (void*)TEST_GPIO_EXT_IN_IO);
  178. TEST_ESP_OK(gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1));
  179. TEST_ASSERT_EQUAL_INT(edge_intr_times, 1);
  180. vTaskDelay(100 / portTICK_RATE_MS);
  181. gpio_isr_handler_remove(TEST_GPIO_EXT_IN_IO);
  182. gpio_uninstall_isr_service();
  183. }
  184. TEST_CASE("GPIO falling edge interrupt test", "[gpio][test_env=UT_T1_GPIO]")
  185. {
  186. edge_intr_times = 0;
  187. gpio_config_t output_io = init_io(TEST_GPIO_EXT_OUT_IO);
  188. gpio_config_t input_io = init_io(TEST_GPIO_EXT_IN_IO);
  189. input_io.intr_type = GPIO_INTR_POSEDGE;
  190. input_io.mode = GPIO_MODE_INPUT;
  191. input_io.pull_up_en = 1;
  192. TEST_ESP_OK(gpio_config(&output_io));
  193. TEST_ESP_OK(gpio_config(&input_io));
  194. TEST_ESP_OK(gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1));
  195. gpio_set_intr_type(TEST_GPIO_EXT_IN_IO, GPIO_INTR_NEGEDGE);
  196. gpio_install_isr_service(0);
  197. gpio_isr_handler_add(TEST_GPIO_EXT_IN_IO, gpio_isr_edge_handler, (void*) TEST_GPIO_EXT_IN_IO);
  198. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0);
  199. vTaskDelay(100 / portTICK_RATE_MS);
  200. TEST_ASSERT_EQUAL_INT(edge_intr_times, 1);
  201. vTaskDelay(100 / portTICK_RATE_MS);
  202. gpio_isr_handler_remove(TEST_GPIO_EXT_IN_IO);
  203. gpio_uninstall_isr_service();
  204. }
  205. TEST_CASE("GPIO both rising and falling edge interrupt test", "[gpio][test_env=UT_T1_GPIO]")
  206. {
  207. edge_intr_times = 0;
  208. gpio_config_t output_io = init_io(TEST_GPIO_EXT_OUT_IO);
  209. gpio_config_t input_io = init_io(TEST_GPIO_EXT_IN_IO);
  210. input_io.intr_type = GPIO_INTR_POSEDGE;
  211. input_io.mode = GPIO_MODE_INPUT;
  212. input_io.pull_up_en = 1;
  213. TEST_ESP_OK(gpio_config(&output_io));
  214. TEST_ESP_OK(gpio_config(&input_io));
  215. TEST_ESP_OK(gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0));
  216. int level = 0;
  217. gpio_set_intr_type(TEST_GPIO_EXT_IN_IO, GPIO_INTR_ANYEDGE);
  218. gpio_install_isr_service(0);
  219. gpio_isr_handler_add(TEST_GPIO_EXT_IN_IO, gpio_isr_edge_handler, (void*) TEST_GPIO_EXT_IN_IO);
  220. // for rising edge in GPIO_INTR_ANYEDGE
  221. while(1) {
  222. level = level + 1;
  223. gpio_set_level(TEST_GPIO_EXT_OUT_IO, level*0.2);
  224. if(level > 10) {
  225. break;
  226. }
  227. vTaskDelay(100 / portTICK_RATE_MS);
  228. }
  229. vTaskDelay(100 / portTICK_RATE_MS);
  230. // for falling rdge in GPIO_INTR_ANYEDGE
  231. while(1) {
  232. level = level - 1;
  233. gpio_set_level(TEST_GPIO_EXT_OUT_IO, level/5);
  234. if(level < 0) {
  235. break;
  236. }
  237. vTaskDelay(100 / portTICK_RATE_MS);
  238. }
  239. vTaskDelay(100 / portTICK_RATE_MS);
  240. TEST_ASSERT_EQUAL_INT(edge_intr_times, 2);
  241. vTaskDelay(100 / portTICK_RATE_MS);
  242. gpio_isr_handler_remove(TEST_GPIO_EXT_IN_IO);
  243. gpio_uninstall_isr_service();
  244. }
  245. TEST_CASE("GPIO input high level trigger, cut the interrupt source exit interrupt test", "[gpio][test_env=UT_T1_GPIO]")
  246. {
  247. level_intr_times=0;
  248. gpio_config_t output_io = init_io(TEST_GPIO_EXT_OUT_IO);
  249. gpio_config_t input_io = init_io(TEST_GPIO_EXT_IN_IO);
  250. input_io.intr_type = GPIO_INTR_POSEDGE;
  251. input_io.mode = GPIO_MODE_INPUT;
  252. input_io.pull_up_en = 1;
  253. TEST_ESP_OK(gpio_config(&output_io));
  254. TEST_ESP_OK(gpio_config(&input_io));
  255. TEST_ESP_OK(gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0));
  256. gpio_set_intr_type(TEST_GPIO_EXT_IN_IO, GPIO_INTR_HIGH_LEVEL);
  257. gpio_install_isr_service(0);
  258. gpio_isr_handler_add(TEST_GPIO_EXT_IN_IO, gpio_isr_level_handler2, (void*) TEST_GPIO_EXT_IN_IO);
  259. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1);
  260. vTaskDelay(100 / portTICK_RATE_MS);
  261. TEST_ASSERT_EQUAL_INT_MESSAGE(level_intr_times, 1, "go into high-level interrupt more than once with cur interrupt source way");
  262. gpio_isr_handler_remove(TEST_GPIO_EXT_IN_IO);
  263. gpio_uninstall_isr_service();
  264. }
  265. TEST_CASE("GPIO low level interrupt test", "[gpio][test_env=UT_T1_GPIO]")
  266. {
  267. disable_intr_times=0;
  268. gpio_config_t output_io = init_io(TEST_GPIO_EXT_OUT_IO);
  269. gpio_config_t input_io = init_io(TEST_GPIO_EXT_IN_IO);
  270. input_io.intr_type = GPIO_INTR_POSEDGE;
  271. input_io.mode = GPIO_MODE_INPUT;
  272. input_io.pull_up_en = 1;
  273. TEST_ESP_OK(gpio_config(&output_io));
  274. TEST_ESP_OK(gpio_config(&input_io));
  275. TEST_ESP_OK(gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1));
  276. gpio_set_intr_type(TEST_GPIO_EXT_IN_IO, GPIO_INTR_LOW_LEVEL);
  277. gpio_install_isr_service(0);
  278. gpio_isr_handler_add(TEST_GPIO_EXT_IN_IO, gpio_isr_level_handler, (void*) TEST_GPIO_EXT_IN_IO);
  279. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0);
  280. printf("get level:%d\n",gpio_get_level(TEST_GPIO_EXT_IN_IO));
  281. vTaskDelay(100 / portTICK_RATE_MS);
  282. TEST_ASSERT_EQUAL_INT_MESSAGE(disable_intr_times, 1, "go into low-level interrupt more than once with disable way");
  283. gpio_isr_handler_remove(TEST_GPIO_EXT_IN_IO);
  284. gpio_uninstall_isr_service();
  285. }
  286. TEST_CASE("GPIO multi-level interrupt test, to cut the interrupt source exit interrupt ", "[gpio][test_env=UT_T1_GPIO]")
  287. {
  288. level_intr_times=0;
  289. gpio_config_t output_io = init_io(TEST_GPIO_EXT_OUT_IO);
  290. gpio_config_t input_io = init_io(TEST_GPIO_EXT_IN_IO);
  291. input_io.intr_type = GPIO_INTR_POSEDGE;
  292. input_io.mode = GPIO_MODE_INPUT;
  293. input_io.pull_up_en = 1;
  294. TEST_ESP_OK(gpio_config(&output_io));
  295. TEST_ESP_OK(gpio_config(&input_io));
  296. TEST_ESP_OK(gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0));
  297. gpio_set_intr_type(TEST_GPIO_EXT_IN_IO, GPIO_INTR_HIGH_LEVEL);
  298. gpio_install_isr_service(0);
  299. gpio_isr_handler_add(TEST_GPIO_EXT_IN_IO, gpio_isr_level_handler2, (void*) TEST_GPIO_EXT_IN_IO);
  300. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1);
  301. vTaskDelay(100 / portTICK_RATE_MS);
  302. TEST_ASSERT_EQUAL_INT_MESSAGE(level_intr_times, 1, "go into high-level interrupt more than once with cur interrupt source way");
  303. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1);
  304. vTaskDelay(200 / portTICK_RATE_MS);
  305. TEST_ASSERT_EQUAL_INT_MESSAGE(level_intr_times, 2, "go into high-level interrupt more than once with cur interrupt source way");
  306. gpio_isr_handler_remove(TEST_GPIO_EXT_IN_IO);
  307. gpio_uninstall_isr_service();
  308. }
  309. TEST_CASE("GPIO enable and disable interrupt test", "[gpio][test_env=UT_T1_GPIO]")
  310. {
  311. disable_intr_times = 0;
  312. gpio_config_t output_io = init_io(TEST_GPIO_EXT_OUT_IO);
  313. gpio_config_t input_io = init_io(TEST_GPIO_EXT_IN_IO);
  314. input_io.intr_type = GPIO_INTR_POSEDGE;
  315. input_io.mode = GPIO_MODE_INPUT;
  316. input_io.pull_up_en = 1;
  317. TEST_ESP_OK(gpio_config(&output_io));
  318. TEST_ESP_OK(gpio_config(&input_io));
  319. TEST_ESP_OK(gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0)); // Because of GPIO_INTR_HIGH_LEVEL interrupt, 0 must be set first
  320. TEST_ESP_OK(gpio_set_intr_type(TEST_GPIO_EXT_IN_IO, GPIO_INTR_HIGH_LEVEL));
  321. TEST_ESP_OK(gpio_install_isr_service(0));
  322. TEST_ESP_OK(gpio_isr_handler_add(TEST_GPIO_EXT_IN_IO, gpio_isr_level_handler, (void*) TEST_GPIO_EXT_IN_IO));
  323. TEST_ESP_OK(gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1));
  324. TEST_ESP_OK(gpio_isr_handler_remove(TEST_GPIO_EXT_IN_IO));
  325. TEST_ESP_OK(gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0));
  326. TEST_ASSERT_EQUAL_INT_MESSAGE(disable_intr_times, 1, "go into high-level interrupt more than once with disable way");
  327. // not install service now
  328. vTaskDelay(100 / portTICK_RATE_MS);
  329. TEST_ESP_OK(gpio_intr_disable(TEST_GPIO_EXT_IN_IO));
  330. TEST_ESP_OK(gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1));
  331. TEST_ASSERT_EQUAL_INT_MESSAGE(disable_intr_times, 1, "disable interrupt does not work, still go into interrupt!");
  332. gpio_uninstall_isr_service(); //uninstall the service
  333. TEST_ASSERT(gpio_isr_handler_add(TEST_GPIO_EXT_IN_IO, gpio_isr_level_handler, (void*) TEST_GPIO_EXT_IN_IO) == ESP_ERR_INVALID_STATE);
  334. TEST_ASSERT(gpio_isr_handler_remove(TEST_GPIO_EXT_IN_IO) == ESP_ERR_INVALID_STATE);
  335. }
  336. #endif //DISABLED_FOR_TARGETS(ESP32S2)
  337. // ESP32 Connect GPIO18 with GPIO19, ESP32-S2 Connect GPIO18 with GPIO21
  338. // use multimeter to test the voltage, so it is ignored in CI
  339. TEST_CASE("GPIO set gpio output level test", "[gpio][ignore]")
  340. {
  341. gpio_config_t io_conf;
  342. io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
  343. io_conf.mode = GPIO_MODE_OUTPUT;
  344. io_conf.pin_bit_mask = (1<<TEST_GPIO_EXT_OUT_IO);
  345. io_conf.pull_down_en = 0;
  346. io_conf.pull_up_en = 0;
  347. gpio_config(&io_conf);
  348. io_conf.pin_bit_mask = (1<<TEST_GPIO_EXT_IN_IO);
  349. io_conf.mode = GPIO_MODE_INPUT;
  350. gpio_config(&io_conf);
  351. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0);
  352. // tested voltage is around 0v
  353. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), 0, "get level error! the level should be low!");
  354. vTaskDelay(1000 / portTICK_RATE_MS);
  355. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1);
  356. // tested voltage is around 3.3v
  357. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), 1, "get level error! the level should be high!");
  358. //This IO is just used for input
  359. io_conf.pin_bit_mask = ((uint64_t)1<<TEST_GPIO_INPUT_ONLY_PIN);
  360. io_conf.mode = GPIO_MODE_OUTPUT;
  361. gpio_config(&io_conf);
  362. TEST_ASSERT(gpio_config(&io_conf) == ESP_ERR_INVALID_ARG);
  363. }
  364. // gpio17 connects to 3.3v pin, gpio19 connects to the GND pin
  365. // use multimeter to test the voltage, so it is ignored in CI
  366. TEST_CASE("GPIO get input level test", "[gpio][ignore]")
  367. {
  368. gpio_num_t num = 17;
  369. int level = gpio_get_level(num);
  370. printf("gpio17's level is: %d\n", level);
  371. TEST_ASSERT_EQUAL_INT_MESSAGE(level, 1, "get level error! the level should be high!");
  372. gpio_num_t num2 = 19;
  373. int level2 = gpio_get_level(num2);
  374. printf("gpio19's level is: %d\n", level2);
  375. TEST_ASSERT_EQUAL_INT_MESSAGE(level2, 0, "get level error! the level should be low!");
  376. printf("the memory get: %d\n", esp_get_free_heap_size());
  377. gpio_num_t num3 = 34; // connect with 3.3v
  378. int level3 = gpio_get_level(num3);
  379. printf("gpio19's level is: %d\n", level3);
  380. TEST_ASSERT_EQUAL_INT_MESSAGE(level3, 0, "get level error! the level should be low!");
  381. printf("the memory get: %d\n", esp_get_free_heap_size());
  382. //when case finish, get the result from multimeter, the pin17 is 3.3v, the pin19 is 0.00v
  383. }
  384. TEST_CASE("GPIO io pull up/down function", "[gpio]")
  385. {
  386. // First, ensure that the output IO will not affect the level
  387. gpio_config_t io_conf = init_io(TEST_GPIO_EXT_OUT_IO);
  388. gpio_config(&io_conf);
  389. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_INPUT);
  390. io_conf = init_io(TEST_GPIO_EXT_IN_IO);
  391. gpio_config(&io_conf);
  392. gpio_set_direction(TEST_GPIO_EXT_IN_IO, GPIO_MODE_INPUT);
  393. TEST_ESP_OK(gpio_pullup_en(TEST_GPIO_EXT_IN_IO)); // pull up first
  394. vTaskDelay(100 / portTICK_RATE_MS);
  395. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), 1, "gpio_pullup_en error, it can't pull up");
  396. TEST_ESP_OK(gpio_pulldown_dis(TEST_GPIO_EXT_IN_IO)); //can't be pull down
  397. vTaskDelay(100 / portTICK_RATE_MS);
  398. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), 1, "gpio_pulldown_dis error, it can pull down");
  399. TEST_ESP_OK(gpio_pulldown_en(TEST_GPIO_EXT_IN_IO)); // can be pull down now
  400. vTaskDelay(100 / portTICK_RATE_MS);
  401. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), 0, "gpio_pulldown_en error, it can't pull down");
  402. TEST_ESP_OK(gpio_pullup_dis(TEST_GPIO_EXT_IN_IO)); // can't be pull up
  403. vTaskDelay(100 / portTICK_RATE_MS);
  404. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), 0, "gpio_pullup_dis error, it can pull up");
  405. }
  406. #if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2)
  407. //No runners
  408. TEST_CASE("GPIO output and input mode test", "[gpio][test_env=UT_T1_GPIO]")
  409. {
  410. //ESP32 connect io18 and io19, ESP32-S2 connect io18 and io21
  411. gpio_config_t output_io = init_io(TEST_GPIO_EXT_OUT_IO);
  412. gpio_config_t input_io = init_io(TEST_GPIO_EXT_IN_IO);
  413. gpio_config(&output_io);
  414. gpio_config(&input_io);
  415. int level = gpio_get_level(TEST_GPIO_EXT_IN_IO);
  416. //disable mode
  417. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_DISABLE);
  418. gpio_set_direction(TEST_GPIO_EXT_IN_IO, GPIO_MODE_OUTPUT);
  419. gpio_set_level(TEST_GPIO_EXT_OUT_IO, !level);
  420. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), level, "direction GPIO_MODE_DISABLE set error, it can output");
  421. //input mode and output mode
  422. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_OUTPUT);
  423. gpio_set_direction(TEST_GPIO_EXT_IN_IO, GPIO_MODE_INPUT);
  424. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1);
  425. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), 1, "direction GPIO_MODE_OUTPUT set error, it can't output");
  426. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0);
  427. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), 0, "direction GPIO_MODE_OUTPUT set error, it can't output");
  428. // open drain mode(output), can just output low level
  429. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_OUTPUT_OD);
  430. gpio_set_direction(TEST_GPIO_EXT_IN_IO, GPIO_MODE_INPUT);
  431. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1);
  432. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), 0, "direction GPIO_MODE_OUTPUT set error, it can't output");
  433. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0);
  434. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), 0, "direction GPIO_MODE_OUTPUT set error, it can't output");
  435. // open drain mode(output and input), can just output low level
  436. // output test
  437. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_INPUT_OUTPUT_OD);
  438. gpio_set_direction(TEST_GPIO_EXT_IN_IO, GPIO_MODE_INPUT);
  439. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1);
  440. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), 0, "direction GPIO_MODE_OUTPUT set error, it can't output");
  441. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0);
  442. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), 0, "direction GPIO_MODE_OUTPUT set error, it can't output");
  443. // GPIO_MODE_INPUT_OUTPUT mode
  444. // output test
  445. level = gpio_get_level(TEST_GPIO_EXT_IN_IO);
  446. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_INPUT_OUTPUT);
  447. gpio_set_direction(TEST_GPIO_EXT_IN_IO, GPIO_MODE_INPUT);
  448. gpio_set_level(TEST_GPIO_EXT_OUT_IO, !level);
  449. TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(TEST_GPIO_EXT_IN_IO), !level, "direction set error, it can't output");
  450. }
  451. TEST_CASE("GPIO repeate call service and isr has no memory leak test","[gpio][test_env=UT_T1_GPIO][timeout=90]")
  452. {
  453. gpio_config_t output_io = init_io(TEST_GPIO_EXT_OUT_IO);
  454. gpio_config_t input_io = init_io(TEST_GPIO_EXT_IN_IO);
  455. input_io.intr_type = GPIO_INTR_POSEDGE;
  456. input_io.mode = GPIO_MODE_INPUT;
  457. input_io.pull_up_en = 1;
  458. TEST_ESP_OK(gpio_config(&output_io));
  459. TEST_ESP_OK(gpio_config(&input_io));
  460. TEST_ESP_OK(gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0));
  461. //rising edge
  462. uint32_t size = esp_get_free_heap_size();
  463. for(int i=0;i<1000;i++) {
  464. TEST_ESP_OK(gpio_set_intr_type(TEST_GPIO_EXT_IN_IO, GPIO_INTR_POSEDGE));
  465. TEST_ESP_OK(gpio_install_isr_service(0));
  466. TEST_ESP_OK(gpio_isr_handler_add(TEST_GPIO_EXT_IN_IO, gpio_isr_edge_handler, (void*)TEST_GPIO_EXT_IN_IO));
  467. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1);
  468. TEST_ESP_OK(gpio_isr_handler_remove(TEST_GPIO_EXT_IN_IO));
  469. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 0);
  470. gpio_uninstall_isr_service();
  471. }
  472. TEST_ASSERT_INT32_WITHIN(size, esp_get_free_heap_size(), 100);
  473. }
  474. #endif //DISABLED_FOR_TARGETS(ESP32S2)
  475. #if !WAKE_UP_IGNORE
  476. //this function development is not completed yet, set it ignored
  477. TEST_CASE("GPIO wake up enable and disenable test", "[gpio][ignore]")
  478. {
  479. xTaskCreate(sleep_wake_up, "sleep_wake_up", 4096, NULL, 5, NULL);
  480. xTaskCreate(trigger_wake_up, "trigger_wake_up", 4096, NULL, 5, NULL);
  481. vTaskDelay(100 / portTICK_RATE_MS);
  482. TEST_ASSERT_TRUE(wake_up_result);
  483. wake_up_result = false;
  484. TEST_ESP_OK(gpio_wakeup_disable(TEST_GPIO_EXT_IN_IO));
  485. gpio_set_level(TEST_GPIO_EXT_OUT_IO, 1);
  486. vTaskDelay(100 / portTICK_RATE_MS);
  487. TEST_ASSERT_FALSE(wake_up_result);
  488. }
  489. #endif
  490. // this case need the resistance to pull up the voltage or pull down the voltage
  491. // ignored because the voltage needs to be tested with multimeter
  492. TEST_CASE("GPIO verify only the gpio with input ability can be set pull/down", "[gpio][ignore]")
  493. {
  494. gpio_config_t output_io = init_io(TEST_GPIO_EXT_OUT_IO);
  495. gpio_config_t input_io = init_io(TEST_GPIO_EXT_IN_IO);
  496. gpio_config(&output_io);
  497. input_io.mode = GPIO_MODE_INPUT;
  498. gpio_config(&input_io);
  499. printf("pull up test!\n");
  500. // pull up test
  501. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_OUTPUT);
  502. TEST_ESP_OK(gpio_set_pull_mode(TEST_GPIO_EXT_OUT_IO, GPIO_PULLUP_ONLY));
  503. prompt_to_continue("mode: GPIO_MODE_OUTPUT");
  504. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_OUTPUT_OD);
  505. TEST_ESP_OK(gpio_set_pull_mode(TEST_GPIO_EXT_OUT_IO, GPIO_PULLUP_ONLY));
  506. // open drain just can output low level
  507. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_INPUT_OUTPUT_OD);
  508. TEST_ESP_OK(gpio_set_pull_mode(TEST_GPIO_EXT_OUT_IO, GPIO_PULLUP_ONLY));
  509. prompt_to_continue("mode: GPIO_MODE_OUTPUT_OD");
  510. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_INPUT_OUTPUT);
  511. TEST_ESP_OK(gpio_set_pull_mode(TEST_GPIO_EXT_OUT_IO, GPIO_PULLUP_ONLY));
  512. prompt_to_continue("mode: GPIO_MODE_INPUT_OUTPUT");
  513. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_INPUT);
  514. TEST_ESP_OK(gpio_set_pull_mode(TEST_GPIO_EXT_OUT_IO, GPIO_PULLUP_ONLY));
  515. prompt_to_continue("mode: GPIO_MODE_INPUT");
  516. // after pull up the level is high now
  517. // pull down test
  518. printf("pull down test!\n");
  519. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_OUTPUT);
  520. TEST_ESP_OK(gpio_set_pull_mode(TEST_GPIO_EXT_OUT_IO, GPIO_PULLDOWN_ONLY));
  521. prompt_to_continue("mode: GPIO_MODE_OUTPUT");
  522. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_OUTPUT_OD);
  523. TEST_ESP_OK(gpio_set_pull_mode(TEST_GPIO_EXT_OUT_IO, GPIO_PULLDOWN_ONLY));
  524. prompt_to_continue("mode: GPIO_MODE_OUTPUT_OD");
  525. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_INPUT_OUTPUT_OD);
  526. TEST_ESP_OK(gpio_set_pull_mode(TEST_GPIO_EXT_OUT_IO, GPIO_PULLDOWN_ONLY));
  527. prompt_to_continue("mode: GPIO_MODE_INPUT_OUTPUT_OD");
  528. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_INPUT_OUTPUT);
  529. TEST_ESP_OK(gpio_set_pull_mode(TEST_GPIO_EXT_OUT_IO, GPIO_PULLDOWN_ONLY));
  530. prompt_to_continue("mode: GPIO_MODE_INPUT_OUTPUT");
  531. gpio_set_direction(TEST_GPIO_EXT_OUT_IO, GPIO_MODE_INPUT);
  532. TEST_ESP_OK(gpio_set_pull_mode(TEST_GPIO_EXT_OUT_IO, GPIO_PULLDOWN_ONLY));
  533. prompt_to_continue("mode: GPIO_MODE_INPUT");
  534. }
  535. /**
  536. * There are 5 situation for the GPIO drive capability:
  537. * 1. GPIO drive weak capability test
  538. * 2. GPIO drive stronger capability test
  539. * 3. GPIO drive default capability test
  540. * 4. GPIO drive default capability test2
  541. * 5. GPIO drive strongest capability test
  542. *
  543. * How to test:
  544. * when testing, use the sliding resistor and a multimeter
  545. * adjust the resistor from low to high, 0-10k
  546. * watch the current change
  547. * the current test result:
  548. * weak capability: (0.32-10.1)mA
  549. * stronger capability: (0.32-20.0)mA
  550. * default capability: (0.33-39.8)mA
  551. * default capability2: (0.33-39.9)mA
  552. * strongest capability: (0.33-64.2)mA
  553. *
  554. * the data shows:
  555. * weak capability<stronger capability<default capability=default capability2<strongest capability
  556. *
  557. * all of these cases should be ignored that it will not run in CI
  558. */
  559. // drive capability test
  560. TEST_CASE("GPIO drive capability test", "[gpio][ignore]")
  561. {
  562. printf("weak capability test! please view the current change!\n");
  563. drive_capability_set_get(TEST_GPIO_EXT_OUT_IO, GPIO_DRIVE_CAP_0);
  564. prompt_to_continue("If this test finishes");
  565. printf("stronger capability test! please view the current change!\n");
  566. drive_capability_set_get(TEST_GPIO_EXT_OUT_IO, GPIO_DRIVE_CAP_1);
  567. prompt_to_continue("If this test finishes");
  568. printf("default capability test! please view the current change!\n");
  569. drive_capability_set_get(TEST_GPIO_EXT_OUT_IO, GPIO_DRIVE_CAP_2);
  570. prompt_to_continue("If this test finishes");
  571. printf("default capability2 test! please view the current change!\n");
  572. drive_capability_set_get(TEST_GPIO_EXT_OUT_IO, GPIO_DRIVE_CAP_DEFAULT);
  573. prompt_to_continue("If this test finishes");
  574. printf("strongest capability test! please view the current change!\n");
  575. drive_capability_set_get(TEST_GPIO_EXT_OUT_IO, GPIO_DRIVE_CAP_3);
  576. prompt_to_continue("If this test finishes");
  577. }
  578. #if !CONFIG_FREERTOS_UNICORE
  579. void gpio_enable_task(void *param)
  580. {
  581. int gpio_num = (int)param;
  582. TEST_ESP_OK(gpio_intr_enable(gpio_num));
  583. vTaskDelete(NULL);
  584. }
  585. /** Test the GPIO Interrupt Enable API with dual core enabled. The GPIO ISR service routine is registered on one core.
  586. * When the GPIO interrupt on another core is enabled, the GPIO interrupt will be lost.
  587. * First on the core 0, Do the following steps:
  588. * 1. Configure the GPIO18 input_output mode, and enable the rising edge interrupt mode.
  589. * 2. Trigger the GPIO18 interrupt and check if the interrupt responds correctly.
  590. * 3. Disable the GPIO18 interrupt
  591. * Then on the core 1, Do the following steps:
  592. * 1. Enable the GPIO18 interrupt again.
  593. * 2. Trigger the GPIO18 interrupt and check if the interrupt responds correctly.
  594. *
  595. */
  596. TEST_CASE("GPIO Enable/Disable interrupt on multiple cores", "[gpio][ignore]")
  597. {
  598. const int test_io18 = GPIO_NUM_18;
  599. gpio_config_t io_conf;
  600. io_conf.intr_type = GPIO_INTR_NEGEDGE;
  601. io_conf.mode = GPIO_MODE_INPUT_OUTPUT;
  602. io_conf.pin_bit_mask = (1ULL << test_io18);
  603. io_conf.pull_down_en = 0;
  604. io_conf.pull_up_en = 1;
  605. TEST_ESP_OK(gpio_config(&io_conf));
  606. TEST_ESP_OK(gpio_set_level(test_io18, 0));
  607. TEST_ESP_OK(gpio_install_isr_service(0));
  608. TEST_ESP_OK(gpio_isr_handler_add(test_io18, gpio_isr_edge_handler, (void*) test_io18));
  609. vTaskDelay(1000 / portTICK_RATE_MS);
  610. TEST_ESP_OK(gpio_set_level(test_io18, 1));
  611. vTaskDelay(100 / portTICK_RATE_MS);
  612. TEST_ESP_OK(gpio_set_level(test_io18, 0));
  613. vTaskDelay(100 / portTICK_RATE_MS);
  614. TEST_ESP_OK(gpio_intr_disable(test_io18));
  615. TEST_ASSERT(edge_intr_times == 1);
  616. xTaskCreatePinnedToCore(gpio_enable_task, "gpio_enable_task", 1024*4, (void*)test_io18, 8, NULL, (xPortGetCoreID() == 0));
  617. vTaskDelay(1000 / portTICK_RATE_MS);
  618. TEST_ESP_OK(gpio_set_level(test_io18, 1));
  619. vTaskDelay(100 / portTICK_RATE_MS);
  620. TEST_ESP_OK(gpio_set_level(test_io18, 0));
  621. vTaskDelay(100 / portTICK_RATE_MS);
  622. TEST_ESP_OK(gpio_intr_disable(test_io18));
  623. TEST_ESP_OK(gpio_isr_handler_remove(test_io18));
  624. gpio_uninstall_isr_service();
  625. TEST_ASSERT(edge_intr_times == 2);
  626. }
  627. #endif
  628. typedef struct {
  629. int gpio_num;
  630. int isr_cnt;
  631. } gpio_isr_param_t;
  632. static void gpio_isr_handler(void* arg)
  633. {
  634. gpio_isr_param_t *param = (gpio_isr_param_t *)arg;
  635. ets_printf("GPIO[%d] intr, val: %d\n", param->gpio_num, gpio_get_level(param->gpio_num));
  636. param->isr_cnt++;
  637. }
  638. /** The previous GPIO interrupt service routine polls the interrupt raw status register to find the GPIO that triggered the interrupt.
  639. * But this will incorrectly handle the interrupt disabled GPIOs, because the raw interrupt status register can still be set when
  640. * the trigger signal arrives, even if the interrupt is disabled.
  641. * First on the core 0:
  642. * 1. Configure the GPIO18 and GPIO19(ESP32)/GPIO21(ESP32-S2) input_output mode.
  643. * 2. Enable GPIO18 dual edge triggered interrupt, enable GPIO19(ESP32)/GPIO21(ESP32-S2) falling edge triggered interrupt.
  644. * 3. Trigger GPIO18 interrupt, than disable the GPIO8 interrupt, and than trigger GPIO18 again(This time will not respond to the interrupt).
  645. * 4. Trigger GPIO19(ESP32)/GPIO21(ESP32-S2) interrupt.
  646. * If the bug is not fixed, you will see, in the step 4, the interrupt of GPIO18 will also respond.
  647. */
  648. TEST_CASE("GPIO ISR service test", "[gpio][ignore]")
  649. {
  650. const int test_io18 = GPIO_NUM_18;
  651. const int test_io19 = GPIO_NUM_19;
  652. static gpio_isr_param_t io18_param = {
  653. .gpio_num = GPIO_NUM_18,
  654. .isr_cnt = 0,
  655. };
  656. static gpio_isr_param_t io19_param = {
  657. .gpio_num = GPIO_NUM_19,
  658. .isr_cnt = 0,
  659. };
  660. gpio_config_t io_conf;
  661. io_conf.intr_type = GPIO_INTR_DISABLE;
  662. io_conf.mode = GPIO_MODE_INPUT_OUTPUT;
  663. io_conf.pin_bit_mask = (1ULL << test_io18) | (1ULL << test_io19);
  664. io_conf.pull_down_en = 0;
  665. io_conf.pull_up_en = 1;
  666. TEST_ESP_OK(gpio_config(&io_conf));
  667. TEST_ESP_OK(gpio_set_level(test_io18, 0));
  668. TEST_ESP_OK(gpio_set_level(test_io19, 0));
  669. TEST_ESP_OK(gpio_install_isr_service(0));
  670. TEST_ESP_OK(gpio_set_intr_type(test_io18, GPIO_INTR_ANYEDGE));
  671. TEST_ESP_OK(gpio_set_intr_type(test_io19, GPIO_INTR_NEGEDGE));
  672. TEST_ESP_OK(gpio_isr_handler_add(test_io18, gpio_isr_handler, (void*)&io18_param));
  673. TEST_ESP_OK(gpio_isr_handler_add(test_io19, gpio_isr_handler, (void*)&io19_param));
  674. printf("Triggering the interrupt of GPIO18\n");
  675. vTaskDelay(1000 / portTICK_RATE_MS);
  676. //Rising edge
  677. TEST_ESP_OK(gpio_set_level(test_io18, 1));
  678. printf("Disable the interrupt of GPIO18");
  679. vTaskDelay(100 / portTICK_RATE_MS);
  680. //Disable GPIO18 interrupt, GPIO18 will not respond to the next falling edge interrupt.
  681. TEST_ESP_OK(gpio_intr_disable(test_io18));
  682. vTaskDelay(100 / portTICK_RATE_MS);
  683. //Falling edge
  684. TEST_ESP_OK(gpio_set_level(test_io18, 0));
  685. printf("Triggering the interrupt of GPIO19\n");
  686. vTaskDelay(100 / portTICK_RATE_MS);
  687. TEST_ESP_OK(gpio_set_level(test_io19, 1));
  688. vTaskDelay(100 / portTICK_RATE_MS);
  689. //Falling edge
  690. TEST_ESP_OK(gpio_set_level(test_io19, 0));
  691. vTaskDelay(100 / portTICK_RATE_MS);
  692. TEST_ESP_OK(gpio_isr_handler_remove(test_io18));
  693. TEST_ESP_OK(gpio_isr_handler_remove(test_io19));
  694. gpio_uninstall_isr_service();
  695. TEST_ASSERT((io18_param.isr_cnt == 1) && (io19_param.isr_cnt == 1));
  696. }