1 /*
2  * Copyright (c) 2019 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 
8 #include "test_gpio.h"
9 
10 #define ALL_BITS ((gpio_port_value_t)-1)
11 
12 static const struct device *const dev = DEVICE_DT_GET(DEV);
13 
14 /* Short-hand for a checked read of PIN_IN raw state */
raw_in(void)15 static bool raw_in(void)
16 {
17 	gpio_port_value_t v;
18 	int rc = gpio_port_get_raw(dev, &v);
19 
20 	zassert_equal(rc, 0,
21 		      "raw_in failed");
22 	return (v & BIT(PIN_IN)) ? true : false;
23 }
24 
25 /* Short-hand for a checked read of PIN_IN logical state */
logic_in(void)26 static bool logic_in(void)
27 {
28 	gpio_port_value_t v;
29 	int rc = gpio_port_get(dev, &v);
30 
31 	zassert_equal(rc, 0,
32 		      "logic_in failed");
33 	return (v & BIT(PIN_IN)) ? true : false;
34 }
35 
36 /* Short-hand for a checked write of PIN_OUT raw state */
raw_out(bool set)37 static void raw_out(bool set)
38 {
39 	int rc;
40 
41 	if (set) {
42 		rc = gpio_port_set_bits_raw(dev, BIT(PIN_OUT));
43 	} else {
44 		rc = gpio_port_clear_bits_raw(dev, BIT(PIN_OUT));
45 	}
46 	zassert_equal(rc, 0,
47 		      "raw_out failed");
48 }
49 
50 /* Short-hand for a checked write of PIN_OUT logic state */
logic_out(bool set)51 static void logic_out(bool set)
52 {
53 	int rc;
54 
55 	if (set) {
56 		rc = gpio_port_set_bits(dev, BIT(PIN_OUT));
57 	} else {
58 		rc = gpio_port_clear_bits(dev, BIT(PIN_OUT));
59 	}
60 	zassert_equal(rc, 0,
61 		      "raw_out failed");
62 }
63 
64 /* Verify device, configure for physical in and out, verify
65  * connection, verify raw_in().
66  */
setup(void)67 static int setup(void)
68 {
69 	int rc;
70 	gpio_port_value_t v1;
71 
72 	TC_PRINT("Validate device %s\n", dev->name);
73 	zassert_true(device_is_ready(dev), "GPIO dev is not ready");
74 
75 	TC_PRINT("Check %s output %d connected to input %d\n", dev->name,
76 		 PIN_OUT, PIN_IN);
77 
78 	rc = gpio_pin_configure(dev, PIN_IN, GPIO_INPUT);
79 	zassert_equal(rc, 0,
80 		      "pin config input failed");
81 
82 	/* Test output low */
83 	rc = gpio_pin_configure(dev, PIN_OUT, GPIO_OUTPUT_LOW);
84 	zassert_equal(rc, 0,
85 		      "pin config output low failed");
86 
87 	rc = gpio_port_get_raw(dev, &v1);
88 	zassert_equal(rc, 0,
89 		      "get raw low failed");
90 	if (raw_in() != false) {
91 		TC_PRINT("FATAL output pin not wired to input pin? (out low => in high)\n");
92 		while (true) {
93 			k_sleep(K_FOREVER);
94 		}
95 	}
96 
97 	zassert_equal(v1 & BIT(PIN_IN), 0,
98 		      "out low does not read low");
99 
100 	/* Disconnect output */
101 	rc = gpio_pin_configure(dev, PIN_OUT, GPIO_DISCONNECTED);
102 	if (rc == -ENOTSUP) {
103 		TC_PRINT("NOTE: cannot configure pin as disconnected; trying as input\n");
104 		rc = gpio_pin_configure(dev, PIN_OUT, GPIO_INPUT);
105 	}
106 	zassert_equal(rc, 0,
107 		      "output disconnect failed");
108 
109 	/* Test output high */
110 	rc = gpio_pin_configure(dev, PIN_OUT, GPIO_OUTPUT_HIGH);
111 	zassert_equal(rc, 0,
112 		      "pin config output high failed");
113 
114 	rc = gpio_port_get_raw(dev, &v1);
115 	zassert_equal(rc, 0,
116 		      "get raw high failed");
117 	if (raw_in() != true) {
118 		TC_PRINT("FATAL output pin not wired to input pin? (out high => in low)\n");
119 		while (true) {
120 			k_sleep(K_FOREVER);
121 		}
122 	}
123 	zassert_not_equal(v1 & BIT(PIN_IN), 0,
124 			  "out high does not read low");
125 
126 	TC_PRINT("OUT %d to IN %d linkage works\n", PIN_OUT, PIN_IN);
127 	return TC_PASS;
128 }
129 
130 /* gpio_port_set_bits_raw()
131  * gpio_port_clear_bits_raw()
132  * gpio_port_set_masked_raw()
133  * gpio_port_toggle_bits()
134  */
bits_physical(void)135 static int bits_physical(void)
136 {
137 	int rc;
138 
139 	TC_PRINT("- %s\n", __func__);
140 
141 	/* port_set_bits_raw */
142 	rc = gpio_port_set_bits_raw(dev, BIT(PIN_OUT));
143 	zassert_equal(rc, 0,
144 		      "port set raw out failed");
145 	zassert_equal(raw_in(), true,
146 		      "raw set mismatch");
147 
148 	/* port_clear_bits_raw */
149 	rc = gpio_port_clear_bits_raw(dev, BIT(PIN_OUT));
150 	zassert_equal(rc, 0,
151 		      "port clear raw out failed");
152 	zassert_equal(raw_in(), false,
153 		      "raw clear mismatch");
154 
155 	/* set after clear changes */
156 	rc = gpio_port_set_bits_raw(dev, BIT(PIN_OUT));
157 	zassert_equal(rc, 0,
158 		      "port set raw out failed");
159 	zassert_equal(raw_in(), true,
160 		      "raw set mismatch");
161 
162 	/* raw_out() after set works */
163 	raw_out(false);
164 	zassert_equal(raw_in(), false,
165 		      "raw_out() false mismatch");
166 
167 	/* raw_out() set after raw_out() clear works */
168 	raw_out(true);
169 	zassert_equal(raw_in(), true,
170 		      "raw_out() true mismatch");
171 
172 	rc = gpio_port_set_masked_raw(dev, BIT(PIN_OUT), 0);
173 	zassert_equal(rc, 0,
174 		      "set_masked_raw low failed");
175 	zassert_equal(raw_in(), false,
176 		      "set_masked_raw low mismatch");
177 
178 	rc = gpio_port_set_masked_raw(dev, BIT(PIN_OUT), ALL_BITS);
179 	zassert_equal(rc, 0,
180 		      "set_masked_raw high failed");
181 	zassert_equal(raw_in(), true,
182 		      "set_masked_raw high mismatch");
183 
184 	rc = gpio_port_set_masked_raw(dev, BIT(PIN_IN), 0);
185 	zassert_equal(rc, 0,
186 		      "set_masked_raw low failed");
187 	zassert_equal(raw_in(), true,
188 		      "set_masked_raw low affected other pins");
189 
190 	rc = gpio_port_set_clr_bits_raw(dev, BIT(PIN_IN), BIT(PIN_OUT));
191 	zassert_equal(rc, 0,
192 		      "set in clear out failed");
193 	zassert_equal(raw_in(), false,
194 		      "set in clear out mismatch");
195 
196 	rc = gpio_port_set_clr_bits_raw(dev, BIT(PIN_OUT), BIT(PIN_IN));
197 	zassert_equal(rc, 0,
198 		      "set out clear in failed");
199 	zassert_equal(raw_in(), true,
200 		      "set out clear in mismatch");
201 
202 	/* Conditionally verify that behavior with __ASSERT disabled
203 	 * is to set the bit.
204 	 */
205 	if (false) {
206 		/* preserve set */
207 		rc = gpio_port_set_clr_bits_raw(dev, BIT(PIN_OUT), BIT(PIN_OUT));
208 		zassert_equal(rc, 0,
209 			      "s/c dup set failed");
210 		zassert_equal(raw_in(), true,
211 			      "s/c dup set mismatch");
212 
213 		/* do set */
214 		raw_out(false);
215 		rc = gpio_port_set_clr_bits_raw(dev, BIT(PIN_OUT), BIT(PIN_OUT));
216 		zassert_equal(rc, 0,
217 			      "s/c dup2 set failed");
218 		zassert_equal(raw_in(), true,
219 			      "s/c dup2 set mismatch");
220 	}
221 
222 	rc = gpio_port_toggle_bits(dev, BIT(PIN_OUT));
223 	zassert_equal(rc, 0,
224 		      "toggle_bits high-to-low failed");
225 	zassert_equal(raw_in(), false,
226 		      "toggle_bits high-to-low mismatch");
227 
228 	rc = gpio_port_toggle_bits(dev, BIT(PIN_OUT));
229 	zassert_equal(rc, 0,
230 		      "toggle_bits low-to-high failed");
231 	zassert_equal(raw_in(), true,
232 		      "toggle_bits low-to-high mismatch");
233 
234 	return TC_PASS;
235 }
236 
237 /* gpio_pin_get_raw()
238  * gpio_pin_set_raw()
239  */
pin_physical(void)240 static int pin_physical(void)
241 {
242 	int rc;
243 
244 	TC_PRINT("- %s\n", __func__);
245 
246 	raw_out(true);
247 	zassert_equal(gpio_pin_get_raw(dev, PIN_IN), raw_in(),
248 		      "pin_get_raw high failed");
249 
250 	raw_out(false);
251 	zassert_equal(gpio_pin_get_raw(dev, PIN_IN), raw_in(),
252 		      "pin_get_raw low failed");
253 
254 	rc = gpio_pin_set_raw(dev, PIN_OUT, 32);
255 	zassert_equal(rc, 0,
256 		      "pin_set_raw high failed");
257 	zassert_equal(raw_in(), true,
258 		      "pin_set_raw high failed");
259 
260 	rc = gpio_pin_set_raw(dev, PIN_OUT, 0);
261 	zassert_equal(rc, 0,
262 		      "pin_set_raw low failed");
263 	zassert_equal(raw_in(), false,
264 		      "pin_set_raw low failed");
265 
266 	rc = gpio_pin_toggle(dev, PIN_OUT);
267 	zassert_equal(rc, 0,
268 		      "pin_toggle low-to-high failed");
269 	zassert_equal(raw_in(), true,
270 		      "pin_toggle low-to-high mismatch");
271 
272 	rc = gpio_pin_toggle(dev, PIN_OUT);
273 	zassert_equal(rc, 0,
274 		      "pin_toggle high-to-low failed");
275 	zassert_equal(raw_in(), false,
276 		      "pin_toggle high-to-low mismatch");
277 
278 	return TC_PASS;
279 }
280 
281 /* Verify configure output level is independent of active level, and
282  * raw output is independent of active level.
283  */
check_raw_output_levels(void)284 static int check_raw_output_levels(void)
285 {
286 	int rc;
287 
288 	TC_PRINT("- %s\n", __func__);
289 
290 	rc = gpio_pin_configure(dev, PIN_OUT,
291 				GPIO_ACTIVE_HIGH | GPIO_OUTPUT_LOW);
292 	zassert_equal(rc, 0,
293 		      "active high output low failed");
294 	zassert_equal(raw_in(), false,
295 		      "active high output low raw mismatch");
296 	raw_out(true);
297 	zassert_equal(raw_in(), true,
298 		      "set high mismatch");
299 
300 	rc = gpio_pin_configure(dev, PIN_OUT,
301 				GPIO_ACTIVE_HIGH | GPIO_OUTPUT_HIGH);
302 	zassert_equal(rc, 0,
303 		      "active high output high failed");
304 	zassert_equal(raw_in(), true,
305 		      "active high output high raw mismatch");
306 	raw_out(false);
307 	zassert_equal(raw_in(), false,
308 		      "set low mismatch");
309 
310 	rc = gpio_pin_configure(dev, PIN_OUT,
311 				GPIO_ACTIVE_LOW | GPIO_OUTPUT_LOW);
312 	zassert_equal(rc, 0,
313 		      "active low output low failed");
314 	zassert_equal(raw_in(), false,
315 		      "active low output low raw mismatch");
316 	raw_out(true);
317 	zassert_equal(raw_in(), true,
318 		      "set high mismatch");
319 
320 	rc = gpio_pin_configure(dev, PIN_OUT,
321 				GPIO_ACTIVE_LOW | GPIO_OUTPUT_HIGH);
322 	zassert_equal(rc, 0,
323 		      "active low output high failed");
324 	zassert_equal(raw_in(), true,
325 		      "active low output high raw mismatch");
326 	raw_out(false);
327 	zassert_equal(raw_in(), false,
328 		      "set low mismatch");
329 
330 	return TC_PASS;
331 }
332 
333 /* Verify configure output level is dependent on active level, and
334  * logic output is dependent on active level.
335  */
check_logic_output_levels(void)336 static int check_logic_output_levels(void)
337 {
338 	int rc;
339 
340 	TC_PRINT("- %s\n", __func__);
341 
342 	rc = gpio_pin_configure(dev, PIN_OUT,
343 				GPIO_ACTIVE_HIGH | GPIO_OUTPUT_INACTIVE);
344 	zassert_equal(rc, 0,
345 		      "active true output false failed: %d", rc);
346 	zassert_equal(raw_in(), false,
347 		      "active true output false logic mismatch");
348 	logic_out(true);
349 	zassert_equal(raw_in(), true,
350 		      "set true mismatch");
351 
352 	rc = gpio_pin_configure(dev, PIN_OUT,
353 				GPIO_ACTIVE_HIGH | GPIO_OUTPUT_ACTIVE);
354 	zassert_equal(rc, 0,
355 		      "active true output true failed");
356 	zassert_equal(raw_in(), true,
357 		      "active true output true logic mismatch");
358 	logic_out(false);
359 	zassert_equal(raw_in(), false,
360 		      "set false mismatch");
361 
362 	rc = gpio_pin_configure(dev, PIN_OUT,
363 				GPIO_ACTIVE_LOW | GPIO_OUTPUT_ACTIVE);
364 	zassert_equal(rc, 0,
365 		      "active low output true failed");
366 
367 	zassert_equal(raw_in(), false,
368 		      "active low output true raw mismatch");
369 	logic_out(false);
370 	zassert_equal(raw_in(), true,
371 		      "set false mismatch");
372 
373 	rc = gpio_pin_configure(dev, PIN_OUT,
374 				GPIO_ACTIVE_LOW | GPIO_OUTPUT_INACTIVE);
375 	zassert_equal(rc, 0,
376 		      "active low output false failed");
377 	zassert_equal(raw_in(), true,
378 		      "active low output false logic mismatch");
379 	logic_out(true);
380 	zassert_equal(raw_in(), false,
381 		      "set true mismatch");
382 
383 	return TC_PASS;
384 }
385 
386 /* Verify active-high input matches physical level, and active-low
387  * input inverts physical level.
388  */
check_input_levels(void)389 static int check_input_levels(void)
390 {
391 	int rc;
392 
393 	TC_PRINT("- %s\n", __func__);
394 
395 	rc = gpio_pin_configure(dev, PIN_OUT, GPIO_OUTPUT);
396 	zassert_equal(rc, 0,
397 		      "output configure failed");
398 
399 	rc = gpio_pin_configure(dev, PIN_IN, GPIO_INPUT);
400 	zassert_equal(rc, 0,
401 		      "active high failed");
402 	raw_out(true);
403 	zassert_equal(raw_in(), true,
404 		      "raw high mismatch");
405 	zassert_equal(logic_in(), true,
406 		      "logic high mismatch");
407 
408 	raw_out(false);
409 	zassert_equal(raw_in(), false,
410 		      "raw low mismatch");
411 	zassert_equal(logic_in(), false,
412 		      "logic low mismatch");
413 
414 	rc = gpio_pin_configure(dev, PIN_IN, GPIO_INPUT | GPIO_ACTIVE_LOW);
415 	zassert_equal(rc, 0,
416 		      "active low failed");
417 
418 	raw_out(true);
419 	zassert_equal(raw_in(), true,
420 		      "raw high mismatch");
421 	zassert_equal(logic_in(), false,
422 		      "logic inactive mismatch");
423 
424 	raw_out(false);
425 	zassert_equal(raw_in(), false,
426 		      "raw low mismatch");
427 	zassert_equal(logic_in(), true,
428 		      "logic active mismatch");
429 
430 	return TC_PASS;
431 }
432 
433 /* Delay after pull input config to allow signal to settle.  The value
434  * selected is conservative (higher than may be necessary).
435  */
436 #define PULL_DELAY_US 100U
437 
438 /* Verify that pull-up and pull-down work for a disconnected input. */
check_pulls(void)439 static int check_pulls(void)
440 {
441 	int rc;
442 
443 	TC_PRINT("- %s\n", __func__);
444 
445 	/* Disconnect output */
446 	rc = gpio_pin_configure(dev, PIN_OUT, GPIO_DISCONNECTED);
447 	if (rc == -ENOTSUP) {
448 		TC_PRINT("NOTE: cannot configure pin as disconnected; trying as input\n");
449 		rc = gpio_pin_configure(dev, PIN_OUT, GPIO_INPUT);
450 	}
451 	zassert_equal(rc, 0,
452 		      "output disconnect failed");
453 
454 	rc = gpio_pin_configure(dev, PIN_IN, GPIO_INPUT | GPIO_PULL_UP);
455 	k_busy_wait(PULL_DELAY_US);
456 	if (rc == -ENOTSUP) {
457 		TC_PRINT("pull-up not supported\n");
458 		return TC_PASS;
459 	} else if (rc != 0) {
460 		TC_ERROR("input pull-up fail: %d\n", rc);
461 		return TC_FAIL;
462 	}
463 	zassert_equal(raw_in(), true,
464 		      "physical pull-up does not read high");
465 
466 	rc = gpio_pin_configure(dev, PIN_IN, GPIO_INPUT | GPIO_PULL_DOWN);
467 	k_busy_wait(PULL_DELAY_US);
468 	if (rc == -ENOTSUP) {
469 		TC_PRINT("pull-down not supported\n");
470 		return TC_PASS;
471 	} else if (rc != 0) {
472 		TC_ERROR("input pull-down fail: %d\n", rc);
473 		return TC_FAIL;
474 	}
475 	zassert_equal(raw_in(), false,
476 		      "physical pull-down does not read low");
477 
478 	/* Test that pull is not affected by active level */
479 	rc = gpio_pin_configure(dev, PIN_IN, GPIO_INPUT | GPIO_ACTIVE_LOW | GPIO_PULL_UP);
480 	k_busy_wait(PULL_DELAY_US);
481 	if (rc == -ENOTSUP) {
482 		TC_PRINT("pull-up not supported\n");
483 		return TC_PASS;
484 	} else if (rc != 0) {
485 		TC_ERROR("input pull-up fail: %d\n", rc);
486 		return TC_FAIL;
487 	}
488 	zassert_equal(raw_in(), true,
489 		      "logical pull-up does not read high");
490 	zassert_equal(logic_in(), false,
491 		      "logical pull-up reads true");
492 
493 	rc = gpio_pin_configure(dev, PIN_IN, GPIO_INPUT | GPIO_ACTIVE_LOW | GPIO_PULL_DOWN);
494 	k_busy_wait(PULL_DELAY_US);
495 	if (rc == -ENOTSUP) {
496 		TC_PRINT("pull-up not supported\n");
497 		return TC_PASS;
498 	} else if (rc != 0) {
499 		TC_ERROR("input pull-up fail: %d\n", rc);
500 		return TC_FAIL;
501 	}
502 	zassert_equal(raw_in(), false,
503 		      "logical pull-down does not read low");
504 	zassert_equal(logic_in(), true,
505 		      "logical pull-down reads false");
506 
507 	return TC_PASS;
508 }
509 
510 /* gpio_port_set_bits()
511  * gpio_port_clear_bits()
512  * gpio_port_set_masked()
513  * gpio_port_toggle_bits()
514  */
bits_logical(void)515 static int bits_logical(void)
516 {
517 	int rc;
518 
519 	TC_PRINT("- %s\n", __func__);
520 
521 	rc = gpio_pin_configure(dev, PIN_OUT,
522 				GPIO_OUTPUT_HIGH | GPIO_ACTIVE_LOW);
523 	zassert_equal(rc, 0,
524 		      "output configure failed");
525 	zassert_equal(raw_in(), true,
526 		      "raw out high mismatch");
527 	zassert_equal(logic_in(), !raw_in(),
528 		      "logic in active mismatch");
529 
530 	/* port_set_bits */
531 	rc = gpio_port_set_bits(dev, BIT(PIN_OUT));
532 	zassert_equal(rc, 0,
533 		      "port set raw out failed");
534 	zassert_equal(raw_in(), false,
535 		      "raw low set mismatch");
536 	zassert_equal(logic_in(), !raw_in(),
537 		      "logic in inactive mismatch");
538 
539 	/* port_clear_bits */
540 	rc = gpio_port_clear_bits(dev, BIT(PIN_OUT));
541 	zassert_equal(rc, 0,
542 		      "port clear raw out failed");
543 	zassert_equal(logic_in(), false,
544 		      "low clear mismatch");
545 
546 	/* set after clear changes */
547 	rc = gpio_port_set_bits_raw(dev, BIT(PIN_OUT));
548 	zassert_equal(rc, 0,
549 		      "port set raw out failed");
550 	zassert_equal(logic_in(), false,
551 		      "raw set mismatch");
552 
553 	/* pin_set false */
554 	rc = gpio_pin_set(dev, PIN_OUT, 0);
555 	zassert_equal(rc, 0,
556 		      "pin clear failed");
557 	zassert_equal(logic_in(), false,
558 		      "pin clear mismatch");
559 
560 	/* pin_set true */
561 	rc = gpio_pin_set(dev, PIN_OUT, 32);
562 	zassert_equal(rc, 0,
563 		      "pin set failed");
564 	zassert_equal(logic_in(), true,
565 		      "pin set mismatch");
566 
567 	rc = gpio_port_set_masked(dev, BIT(PIN_OUT), 0);
568 	zassert_equal(rc, 0,
569 		      "set_masked low failed");
570 	zassert_equal(logic_in(), false,
571 		      "set_masked low mismatch");
572 
573 	rc = gpio_port_set_masked(dev, BIT(PIN_OUT), ALL_BITS);
574 	zassert_equal(rc, 0,
575 		      "set_masked high failed");
576 	zassert_equal(logic_in(), true,
577 		      "set_masked high mismatch");
578 
579 	rc = gpio_port_set_clr_bits(dev, BIT(PIN_IN), BIT(PIN_OUT));
580 	zassert_equal(rc, 0,
581 		      "set in clear out failed");
582 	zassert_equal(logic_in(), false,
583 		      "set in clear out mismatch");
584 
585 	rc = gpio_port_set_clr_bits(dev, BIT(PIN_OUT), BIT(PIN_IN));
586 	zassert_equal(rc, 0,
587 		      "set out clear in failed");
588 	zassert_equal(logic_in(), true,
589 		      "set out clear in mismatch");
590 
591 	/* Conditionally verify that behavior with __ASSERT disabled
592 	 * is to set the bit.
593 	 */
594 	if (false) {
595 		/* preserve set */
596 		rc = gpio_port_set_clr_bits(dev, BIT(PIN_OUT), BIT(PIN_OUT));
597 		zassert_equal(rc, 0,
598 			      "s/c set toggle failed");
599 		zassert_equal(logic_in(), false,
600 			      "s/c set toggle mismatch");
601 
602 		/* force set */
603 		raw_out(true);
604 		rc = gpio_port_set_clr_bits(dev, BIT(PIN_OUT), BIT(PIN_OUT));
605 		zassert_equal(rc, 0,
606 			      "s/c dup set failed");
607 		zassert_equal(logic_in(), false,
608 			      "s/c dup set mismatch");
609 	}
610 
611 	rc = gpio_port_toggle_bits(dev, BIT(PIN_OUT));
612 	zassert_equal(rc, 0,
613 		      "toggle_bits active-to-inactive failed");
614 	zassert_equal(logic_in(), false,
615 		      "toggle_bits active-to-inactive mismatch");
616 
617 	rc = gpio_port_toggle_bits(dev, BIT(PIN_OUT));
618 	zassert_equal(rc, 0,
619 		      "toggle_bits inactive-to-active failed");
620 	zassert_equal(logic_in(), true,
621 		      "toggle_bits inactive-to-active mismatch");
622 
623 	rc = gpio_pin_toggle(dev, PIN_OUT);
624 	zassert_equal(rc, 0,
625 		      "pin_toggle low-to-high failed");
626 	zassert_equal(logic_in(), false,
627 		      "pin_toggle low-to-high mismatch");
628 
629 	return TC_PASS;
630 }
631 
632 /* gpio_pin_get_config()
633  */
pin_get_config(void)634 static int pin_get_config(void)
635 {
636 	gpio_flags_t flags_get = 0;
637 	gpio_flags_t flags_set;
638 	int rc;
639 
640 	flags_set = GPIO_OUTPUT_HIGH;
641 	rc = gpio_pin_configure(dev, PIN_OUT, flags_set);
642 	zassert_equal(rc, 0, "pin configure failed");
643 
644 	rc = gpio_pin_get_config(dev, PIN_OUT, &flags_get);
645 	if (rc == -ENOSYS) {
646 		return TC_PASS;
647 	}
648 
649 	zassert_equal(rc, 0, "pin get config failed");
650 	zassert_equal(flags_get, flags_set, "flags are different");
651 
652 	return TC_PASS;
653 }
654 
ZTEST(gpio_port,test_gpio_port)655 ZTEST(gpio_port, test_gpio_port)
656 {
657 	zassert_equal(setup(), TC_PASS,
658 		      "device setup failed");
659 	zassert_equal(bits_physical(), TC_PASS,
660 		      "bits_physical failed");
661 	zassert_equal(pin_physical(), TC_PASS,
662 		      "pin_physical failed");
663 	zassert_equal(check_raw_output_levels(), TC_PASS,
664 		      "check_raw_output_levels failed");
665 	zassert_equal(check_logic_output_levels(), TC_PASS,
666 		      "check_logic_output_levels failed");
667 	zassert_equal(check_input_levels(), TC_PASS,
668 		      "check_input_levels failed");
669 	zassert_equal(bits_logical(), TC_PASS,
670 		      "bits_logical failed");
671 	if (!IS_ENABLED(CONFIG_SKIP_PULL_TEST)) {
672 		zassert_equal(check_pulls(), TC_PASS,
673 				"check_pulls failed");
674 	}
675 	if (IS_ENABLED(CONFIG_GPIO_GET_CONFIG)) {
676 		zassert_equal(pin_get_config(), TC_PASS,
677 			      "pin_get_config failed");
678 	}
679 }
680