tests: gpio_basic_api: update for output initialization to logic level

Test output init active and inactive in active high and active low
cases.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2019-12-03 11:30:28 -06:00 committed by Carles Cufí
commit bf8990bd87

View file

@ -36,7 +36,7 @@ static bool logic_in(void)
int rc = gpio_port_get(dev, &v); int rc = gpio_port_get(dev, &v);
zassert_equal(rc, 0, zassert_equal(rc, 0,
"raw_in failed"); "logic_in failed");
return (v & BIT(PIN_IN)) ? true : false; return (v & BIT(PIN_IN)) ? true : false;
} }
@ -54,6 +54,20 @@ static void raw_out(bool set)
"raw_out failed"); "raw_out failed");
} }
/* Short-hand for a checked write of PIN_OUT logic state */
static void logic_out(bool set)
{
int rc;
if (set) {
rc = gpio_port_set_bits(dev, BIT(PIN_OUT));
} else {
rc = gpio_port_clear_bits(dev, BIT(PIN_OUT));
}
zassert_equal(rc, 0,
"raw_out failed");
}
/* Verify device, configure for physical in and out, verify /* Verify device, configure for physical in and out, verify
* connection, verify raw_in(). * connection, verify raw_in().
*/ */
@ -307,6 +321,59 @@ static int check_raw_output_levels(void)
return TC_PASS; return TC_PASS;
} }
/* Verify configure output level is dependent on active level, and
* logic output is dependent on active level.
*/
static int check_logic_output_levels(void)
{
int rc;
TC_PRINT("- %s\n", __func__);
rc = gpio_pin_configure(dev, PIN_OUT,
GPIO_ACTIVE_HIGH | GPIO_OUTPUT_INACTIVE);
zassert_equal(rc, 0,
"active true output false failed: %d", rc);
zassert_equal(raw_in(), false,
"active true output false logic mismatch");
logic_out(true);
zassert_equal(raw_in(), true,
"set true mismatch");
rc = gpio_pin_configure(dev, PIN_OUT,
GPIO_ACTIVE_HIGH | GPIO_OUTPUT_ACTIVE);
zassert_equal(rc, 0,
"active true output true failed");
zassert_equal(raw_in(), true,
"active true output true logic mismatch");
logic_out(false);
zassert_equal(raw_in(), false,
"set false mismatch");
rc = gpio_pin_configure(dev, PIN_OUT,
GPIO_ACTIVE_LOW | GPIO_OUTPUT_ACTIVE);
zassert_equal(rc, 0,
"active low output true failed");
zassert_equal(raw_in(), false,
"active low output true raw mismatch");
logic_out(false);
zassert_equal(raw_in(), true,
"set false mismatch");
rc = gpio_pin_configure(dev, PIN_OUT,
GPIO_ACTIVE_LOW | GPIO_OUTPUT_INACTIVE);
zassert_equal(rc, 0,
"active low output false failed");
zassert_equal(raw_in(), true,
"active low output false logic mismatch");
logic_out(true);
zassert_equal(raw_in(), false,
"set true mismatch");
return TC_PASS;
}
/* Verify active-high input matches physical level, and active-low /* Verify active-high input matches physical level, and active-low
* input inverts physical level. * input inverts physical level.
*/ */
@ -563,6 +630,8 @@ void test_gpio_port(void)
"pin_physical failed"); "pin_physical failed");
zassert_equal(check_raw_output_levels(), TC_PASS, zassert_equal(check_raw_output_levels(), TC_PASS,
"check_raw_output_levels failed"); "check_raw_output_levels failed");
zassert_equal(check_logic_output_levels(), TC_PASS,
"check_logic_output_levels failed");
zassert_equal(check_input_levels(), TC_PASS, zassert_equal(check_input_levels(), TC_PASS,
"check_input_levels failed"); "check_input_levels failed");
zassert_equal(bits_logical(), TC_PASS, zassert_equal(bits_logical(), TC_PASS,