2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <peripheral_io.h>
20 #include "test_peripheral_gpio.h"
22 #define GPIO_PIN_RPI3 26
23 #define GPIO_PIN_ARTIK530 128
24 #define GPIO_PIN_INVALID -99
26 static bool g_feature = false;
29 int test_peripheral_io_gpio_initialize(char *model, bool feature)
33 if (!strcmp(model, "rpi3"))
35 else if (!strcmp(model, "artik"))
36 pin = GPIO_PIN_ARTIK530;
42 int test_peripheral_io_gpio_peripheral_gpio_open_p(void)
44 int ret = PERIPHERAL_ERROR_NONE;
46 peripheral_gpio_h gpio_h = NULL;
48 if (g_feature == false) {
49 ret = peripheral_gpio_open(pin, &gpio_h);
50 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
53 ret = peripheral_gpio_open(pin, &gpio_h);
54 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
56 ret = peripheral_gpio_close(gpio_h);
57 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
60 return PERIPHERAL_ERROR_NONE;
63 int test_peripheral_io_gpio_peripheral_gpio_open_n1(void)
65 int ret = PERIPHERAL_ERROR_NONE;
67 if (g_feature == false) {
68 ret = peripheral_gpio_open(pin, NULL);
69 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
72 ret = peripheral_gpio_open(pin, NULL);
73 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
76 return PERIPHERAL_ERROR_NONE;
79 int test_peripheral_io_gpio_peripheral_gpio_open_n2(void)
81 int ret = PERIPHERAL_ERROR_NONE;
83 peripheral_gpio_h gpio_h = NULL;
85 if (g_feature == false) {
86 ret = peripheral_gpio_open(GPIO_PIN_INVALID, &gpio_h);
87 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
90 ret = peripheral_gpio_open(GPIO_PIN_INVALID, &gpio_h);
91 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
94 return PERIPHERAL_ERROR_NONE;
97 int test_peripheral_io_gpio_peripheral_gpio_close_p(void)
99 int ret = PERIPHERAL_ERROR_NONE;
101 peripheral_gpio_h gpio_h = NULL;
103 if (g_feature == false) {
104 ret = peripheral_gpio_close(gpio_h);
105 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
108 ret = peripheral_gpio_open(pin, &gpio_h);
109 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
111 ret = peripheral_gpio_close(gpio_h);
112 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
115 return PERIPHERAL_ERROR_NONE;
118 int test_peripheral_io_gpio_peripheral_gpio_close_n(void)
120 int ret = PERIPHERAL_ERROR_NONE;
122 if (g_feature == false) {
123 ret = peripheral_gpio_close(NULL);
124 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
127 ret = peripheral_gpio_close(NULL);
128 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
131 return PERIPHERAL_ERROR_NONE;
134 int test_peripheral_io_gpio_peripheral_gpio_set_direction_p1(void)
136 int ret = PERIPHERAL_ERROR_NONE;
138 peripheral_gpio_h gpio_h = NULL;
140 if (g_feature == false) {
141 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
142 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
145 ret = peripheral_gpio_open(pin, &gpio_h);
146 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
148 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
149 if (ret != PERIPHERAL_ERROR_NONE) {
150 peripheral_gpio_close(gpio_h);
151 return PERIPHERAL_ERROR_UNKNOWN;
154 ret = peripheral_gpio_close(gpio_h);
155 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
158 return PERIPHERAL_ERROR_NONE;
161 int test_peripheral_io_gpio_peripheral_gpio_set_direction_p2(void)
163 int ret = PERIPHERAL_ERROR_NONE;
165 peripheral_gpio_h gpio_h = NULL;
167 if (g_feature == false) {
168 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH);
169 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
172 ret = peripheral_gpio_open(pin, &gpio_h);
173 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
175 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH);
176 if (ret != PERIPHERAL_ERROR_NONE) {
177 peripheral_gpio_close(gpio_h);
178 return PERIPHERAL_ERROR_UNKNOWN;
181 ret = peripheral_gpio_close(gpio_h);
182 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
185 return PERIPHERAL_ERROR_NONE;
188 int test_peripheral_io_gpio_peripheral_gpio_set_direction_p3(void)
190 int ret = PERIPHERAL_ERROR_NONE;
192 peripheral_gpio_h gpio_h = NULL;
194 if (g_feature == false) {
195 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
196 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
199 ret = peripheral_gpio_open(pin, &gpio_h);
200 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
202 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
203 if (ret != PERIPHERAL_ERROR_NONE) {
204 peripheral_gpio_close(gpio_h);
205 return PERIPHERAL_ERROR_UNKNOWN;
208 ret = peripheral_gpio_close(gpio_h);
209 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
212 return PERIPHERAL_ERROR_NONE;
215 int test_peripheral_io_gpio_peripheral_gpio_set_direction_n1(void)
217 int ret = PERIPHERAL_ERROR_NONE;
219 if (g_feature == false) {
220 ret = peripheral_gpio_set_direction(NULL, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH);
221 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
224 ret = peripheral_gpio_set_direction(NULL, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH);
225 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
228 return PERIPHERAL_ERROR_NONE;
231 int test_peripheral_io_gpio_peripheral_gpio_set_direction_n2(void)
233 int ret = PERIPHERAL_ERROR_NONE;
235 peripheral_gpio_h gpio_h = NULL;
237 if (g_feature == false) {
238 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN - 1);
239 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
242 ret = peripheral_gpio_open(pin, &gpio_h);
243 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
245 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN - 1);
246 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
247 peripheral_gpio_close(gpio_h);
248 return PERIPHERAL_ERROR_UNKNOWN;
251 ret = peripheral_gpio_close(gpio_h);
252 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
255 return PERIPHERAL_ERROR_NONE;
258 int test_peripheral_io_gpio_peripheral_gpio_set_direction_n3(void)
260 int ret = PERIPHERAL_ERROR_NONE;
262 peripheral_gpio_h gpio_h = NULL;
264 if (g_feature == false) {
265 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW + 1);
266 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
269 ret = peripheral_gpio_open(pin, &gpio_h);
270 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
272 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW + 1);
273 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
274 peripheral_gpio_close(gpio_h);
275 return PERIPHERAL_ERROR_UNKNOWN;
278 ret = peripheral_gpio_close(gpio_h);
279 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
282 return PERIPHERAL_ERROR_NONE;
285 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p1(void)
287 int ret = PERIPHERAL_ERROR_NONE;
289 peripheral_gpio_h gpio_h = NULL;
291 if (g_feature == false) {
292 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_NONE);
293 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
296 ret = peripheral_gpio_open(pin, &gpio_h);
297 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
299 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
300 if (ret != PERIPHERAL_ERROR_NONE) {
301 peripheral_gpio_close(gpio_h);
302 return PERIPHERAL_ERROR_UNKNOWN;
305 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_NONE);
306 if (ret != PERIPHERAL_ERROR_NONE) {
307 peripheral_gpio_close(gpio_h);
308 return PERIPHERAL_ERROR_UNKNOWN;
311 ret = peripheral_gpio_close(gpio_h);
312 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
315 return PERIPHERAL_ERROR_NONE;
318 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p2(void)
320 int ret = PERIPHERAL_ERROR_NONE;
322 peripheral_gpio_h gpio_h = NULL;
324 if (g_feature == false) {
325 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_RISING);
326 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
329 ret = peripheral_gpio_open(pin, &gpio_h);
330 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
332 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
333 if (ret != PERIPHERAL_ERROR_NONE) {
334 peripheral_gpio_close(gpio_h);
335 return PERIPHERAL_ERROR_UNKNOWN;
338 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_RISING);
339 if (ret != PERIPHERAL_ERROR_NONE && ret != PERIPHERAL_ERROR_TRY_AGAIN) {
340 peripheral_gpio_close(gpio_h);
341 return PERIPHERAL_ERROR_UNKNOWN;
344 ret = peripheral_gpio_close(gpio_h);
345 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
348 return PERIPHERAL_ERROR_NONE;
351 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p3(void)
353 int ret = PERIPHERAL_ERROR_NONE;
355 peripheral_gpio_h gpio_h = NULL;
357 if (g_feature == false) {
358 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_FALLING);
359 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
362 ret = peripheral_gpio_open(pin, &gpio_h);
363 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
365 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
366 if (ret != PERIPHERAL_ERROR_NONE) {
367 peripheral_gpio_close(gpio_h);
368 return PERIPHERAL_ERROR_UNKNOWN;
371 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_FALLING);
372 if (ret != PERIPHERAL_ERROR_NONE) {
373 peripheral_gpio_close(gpio_h);
374 return PERIPHERAL_ERROR_UNKNOWN;
377 ret = peripheral_gpio_close(gpio_h);
378 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
381 return PERIPHERAL_ERROR_NONE;
384 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_p4(void)
386 int ret = PERIPHERAL_ERROR_NONE;
388 peripheral_gpio_h gpio_h = NULL;
390 if (g_feature == false) {
391 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_BOTH);
392 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
395 ret = peripheral_gpio_open(pin, &gpio_h);
396 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
398 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_BOTH);
399 if (ret != PERIPHERAL_ERROR_NONE) {
400 peripheral_gpio_close(gpio_h);
401 return PERIPHERAL_ERROR_UNKNOWN;
404 ret = peripheral_gpio_close(gpio_h);
405 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
408 return PERIPHERAL_ERROR_NONE;
411 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n1(void)
413 int ret = PERIPHERAL_ERROR_NONE;
415 if (g_feature == false) {
416 ret = peripheral_gpio_set_edge_mode(NULL, PERIPHERAL_GPIO_EDGE_RISING);
417 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
420 ret = peripheral_gpio_set_edge_mode(NULL, PERIPHERAL_GPIO_EDGE_RISING);
421 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
424 return PERIPHERAL_ERROR_NONE;
427 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n2(void)
429 int ret = PERIPHERAL_ERROR_NONE;
431 peripheral_gpio_h gpio_h = NULL;
433 if (g_feature == false) {
434 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_NONE - 1);
435 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
438 ret = peripheral_gpio_open(pin, &gpio_h);
439 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
441 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_NONE - 1);
442 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
443 peripheral_gpio_close(gpio_h);
444 return PERIPHERAL_ERROR_UNKNOWN;
447 ret = peripheral_gpio_close(gpio_h);
448 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
451 return PERIPHERAL_ERROR_NONE;
454 int test_peripheral_io_gpio_peripheral_gpio_set_edge_mode_n3(void)
456 int ret = PERIPHERAL_ERROR_NONE;
458 peripheral_gpio_h gpio_h = NULL;
460 if (g_feature == false) {
461 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_BOTH + 1);
462 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
465 ret = peripheral_gpio_open(pin, &gpio_h);
466 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
468 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_BOTH + 1);
469 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
470 peripheral_gpio_close(gpio_h);
471 return PERIPHERAL_ERROR_UNKNOWN;
474 ret = peripheral_gpio_close(gpio_h);
475 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
478 return PERIPHERAL_ERROR_NONE;
481 static void gpio_interrupted_cb(peripheral_gpio_h gpio_h, peripheral_error_e error, void *user_data)
483 // interrupted callback
486 int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_p(void)
488 // see the gpio_interrupted_cb();
490 int ret = PERIPHERAL_ERROR_NONE;
492 peripheral_gpio_h gpio_h = NULL;
494 if (g_feature == false) {
495 ret = peripheral_gpio_set_interrupted_cb(gpio_h, gpio_interrupted_cb, NULL);
496 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
499 ret = peripheral_gpio_open(pin, &gpio_h);
500 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
502 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
503 if (ret != PERIPHERAL_ERROR_NONE) {
504 peripheral_gpio_close(gpio_h);
505 return PERIPHERAL_ERROR_UNKNOWN;
508 ret = peripheral_gpio_set_edge_mode(gpio_h, PERIPHERAL_GPIO_EDGE_RISING);
509 if (ret != PERIPHERAL_ERROR_NONE) {
510 peripheral_gpio_close(gpio_h);
511 return PERIPHERAL_ERROR_UNKNOWN;
514 ret = peripheral_gpio_set_interrupted_cb(gpio_h, gpio_interrupted_cb, NULL);
515 if (ret != PERIPHERAL_ERROR_NONE) {
516 peripheral_gpio_close(gpio_h);
517 return PERIPHERAL_ERROR_UNKNOWN;
520 ret = peripheral_gpio_unset_interrupted_cb(gpio_h);
521 if (ret != PERIPHERAL_ERROR_NONE) {
522 peripheral_gpio_close(gpio_h);
523 return PERIPHERAL_ERROR_UNKNOWN;
526 ret = peripheral_gpio_close(gpio_h);
527 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
530 return PERIPHERAL_ERROR_NONE;
533 int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n1(void)
535 int ret = PERIPHERAL_ERROR_NONE;
537 if (g_feature == false) {
538 ret = peripheral_gpio_set_interrupted_cb(NULL, gpio_interrupted_cb, NULL);
539 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
542 ret = peripheral_gpio_set_interrupted_cb(NULL, gpio_interrupted_cb, NULL);
543 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
546 return PERIPHERAL_ERROR_NONE;
549 int test_peripheral_io_gpio_peripheral_gpio_set_interrupted_cb_n2(void)
551 int ret = PERIPHERAL_ERROR_NONE;
553 peripheral_gpio_h gpio_h = NULL;
555 if (g_feature == false) {
556 ret = peripheral_gpio_set_interrupted_cb(gpio_h, NULL, NULL);
557 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
560 ret = peripheral_gpio_open(pin, &gpio_h);
561 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
563 ret = peripheral_gpio_set_interrupted_cb(gpio_h, NULL, NULL);
564 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
565 peripheral_gpio_close(gpio_h);
566 return PERIPHERAL_ERROR_UNKNOWN;
569 ret = peripheral_gpio_close(gpio_h);
570 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
573 return PERIPHERAL_ERROR_NONE;
576 int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p1(void)
578 int ret = PERIPHERAL_ERROR_NONE;
580 peripheral_gpio_h gpio_h = NULL;
582 if (g_feature == false) {
583 ret = peripheral_gpio_unset_interrupted_cb(gpio_h);
584 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
587 ret = peripheral_gpio_open(pin, &gpio_h);
588 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
590 ret = peripheral_gpio_set_interrupted_cb(gpio_h, gpio_interrupted_cb, NULL);
591 if (ret != PERIPHERAL_ERROR_NONE) {
592 peripheral_gpio_close(gpio_h);
593 return PERIPHERAL_ERROR_UNKNOWN;
596 ret = peripheral_gpio_unset_interrupted_cb(gpio_h);
597 if (ret != PERIPHERAL_ERROR_NONE) {
598 peripheral_gpio_close(gpio_h);
599 return PERIPHERAL_ERROR_UNKNOWN;
602 ret = peripheral_gpio_close(gpio_h);
603 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
606 return PERIPHERAL_ERROR_NONE;
609 int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_p2(void)
611 int ret = PERIPHERAL_ERROR_NONE;
613 peripheral_gpio_h gpio_h = NULL;
615 if (g_feature == false) {
616 ret = peripheral_gpio_unset_interrupted_cb(gpio_h);
617 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
620 ret = peripheral_gpio_open(pin, &gpio_h);
621 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
623 ret = peripheral_gpio_unset_interrupted_cb(gpio_h);
624 if (ret != PERIPHERAL_ERROR_NONE) {
625 peripheral_gpio_close(gpio_h);
626 return PERIPHERAL_ERROR_UNKNOWN;
629 ret = peripheral_gpio_close(gpio_h);
630 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
633 return PERIPHERAL_ERROR_NONE;
636 int test_peripheral_io_gpio_peripheral_gpio_unset_interrupted_cb_n(void)
638 int ret = PERIPHERAL_ERROR_NONE;
640 if (g_feature == false) {
641 ret = peripheral_gpio_unset_interrupted_cb(NULL);
642 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
645 ret = peripheral_gpio_unset_interrupted_cb(NULL);
646 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
649 return PERIPHERAL_ERROR_NONE;
652 int test_peripheral_io_gpio_peripheral_gpio_read_p(void)
654 int ret = PERIPHERAL_ERROR_NONE;
656 peripheral_gpio_h gpio_h = NULL;
660 if (g_feature == false) {
661 ret = peripheral_gpio_read(gpio_h, &value);
662 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
665 ret = peripheral_gpio_open(pin, &gpio_h);
666 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
668 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
669 if (ret != PERIPHERAL_ERROR_NONE) {
670 peripheral_gpio_close(gpio_h);
671 return PERIPHERAL_ERROR_UNKNOWN;
674 ret = peripheral_gpio_read(gpio_h, &value);
675 if (ret != PERIPHERAL_ERROR_NONE) {
676 peripheral_gpio_close(gpio_h);
677 return PERIPHERAL_ERROR_UNKNOWN;
680 ret = peripheral_gpio_close(gpio_h);
681 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
684 return PERIPHERAL_ERROR_NONE;
687 int test_peripheral_io_gpio_peripheral_gpio_read_n1(void)
689 int ret = PERIPHERAL_ERROR_NONE;
693 if (g_feature == false) {
694 ret = peripheral_gpio_read(NULL, &value);
695 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
698 ret = peripheral_gpio_read(NULL, &value);
699 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
702 return PERIPHERAL_ERROR_NONE;
705 int test_peripheral_io_gpio_peripheral_gpio_read_n2(void)
707 int ret = PERIPHERAL_ERROR_NONE;
709 peripheral_gpio_h gpio_h = NULL;
711 if (g_feature == false) {
712 ret = peripheral_gpio_read(gpio_h, NULL);
713 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
716 ret = peripheral_gpio_open(pin, &gpio_h);
717 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
719 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_IN);
720 if (ret != PERIPHERAL_ERROR_NONE) {
721 peripheral_gpio_close(gpio_h);
722 return PERIPHERAL_ERROR_UNKNOWN;
725 ret = peripheral_gpio_read(gpio_h, NULL);
726 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
727 peripheral_gpio_close(gpio_h);
728 return PERIPHERAL_ERROR_UNKNOWN;
731 ret = peripheral_gpio_close(gpio_h);
732 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
735 return PERIPHERAL_ERROR_NONE;
738 int test_peripheral_io_gpio_peripheral_gpio_write_p(void)
740 int ret = PERIPHERAL_ERROR_NONE;
742 peripheral_gpio_h gpio_h = NULL;
746 if (g_feature == false) {
747 ret = peripheral_gpio_write(gpio_h, value);
748 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
751 ret = peripheral_gpio_open(pin, &gpio_h);
752 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
754 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
755 if (ret != PERIPHERAL_ERROR_NONE) {
756 peripheral_gpio_close(gpio_h);
757 return PERIPHERAL_ERROR_UNKNOWN;
760 ret = peripheral_gpio_write(gpio_h, value);
761 if (ret != PERIPHERAL_ERROR_NONE) {
762 peripheral_gpio_close(gpio_h);
763 return PERIPHERAL_ERROR_UNKNOWN;
766 ret = peripheral_gpio_close(gpio_h);
767 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
770 return PERIPHERAL_ERROR_NONE;
773 int test_peripheral_io_gpio_peripheral_gpio_write_n1(void)
775 int ret = PERIPHERAL_ERROR_NONE;
779 if (g_feature == false) {
780 ret = peripheral_gpio_write(NULL, value);
781 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
784 ret = peripheral_gpio_write(NULL, value);
785 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
788 return PERIPHERAL_ERROR_NONE;
791 int test_peripheral_io_gpio_peripheral_gpio_write_n2(void)
793 int ret = PERIPHERAL_ERROR_NONE;
795 peripheral_gpio_h gpio_h = NULL;
799 if (g_feature == false) {
800 ret = peripheral_gpio_write(gpio_h, value);
801 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
804 ret = peripheral_gpio_open(pin, &gpio_h);
805 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
807 ret = peripheral_gpio_set_direction(gpio_h, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
808 if (ret != PERIPHERAL_ERROR_NONE) {
809 peripheral_gpio_close(gpio_h);
810 return PERIPHERAL_ERROR_UNKNOWN;
813 ret = peripheral_gpio_write(gpio_h, value);
814 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
815 peripheral_gpio_close(gpio_h);
816 return PERIPHERAL_ERROR_UNKNOWN;
819 ret = peripheral_gpio_close(gpio_h);
820 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
823 return PERIPHERAL_ERROR_NONE;