-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Add hardware gpio port test for SAMV71 Xplained Ultra
- Loading branch information
1 parent
8ec225b
commit 9dde068
Showing
3 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2023, Christopher Durand | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include <unittest/testsuite.hpp> | ||
|
||
/// @ingroup modm_test_test_platform_gpio_port | ||
class GpioPortTest : public unittest::TestSuite | ||
{ | ||
public: | ||
virtual void | ||
setUp() override; | ||
|
||
void | ||
testPortRead(); | ||
|
||
void | ||
testPortWrite(); | ||
|
||
void | ||
testPortInverted(); | ||
}; |
132 changes: 132 additions & 0 deletions
132
test/modm/platform/software_gpio_port/gpio_port_test_samv71.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright (c) 2023, Christopher Durand | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include "gpio_port_test.hpp" | ||
|
||
#include <modm/platform.hpp> | ||
|
||
using namespace modm::platform; | ||
|
||
using Port = SoftwareGpioPort< | ||
GpioA23, | ||
GpioC9, | ||
GpioD20, | ||
GpioD21 | ||
>; | ||
|
||
using Port2 = SoftwareGpioPort< | ||
GpioA23, | ||
GpioInverted<GpioC9>, | ||
GpioInverted<GpioD20>, | ||
GpioD21 | ||
>; | ||
|
||
void | ||
GpioPortTest::setUp() | ||
{ | ||
Port::setOutput(false); | ||
} | ||
|
||
void | ||
GpioPortTest::testPortRead() | ||
{ | ||
Port::setOutput(false); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b0000); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b0000); | ||
|
||
GpioA23::set(); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b1000); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b1000); | ||
|
||
GpioD20::set(); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b1010); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b1010); | ||
|
||
GpioA23::reset(); | ||
GpioD20::reset(); | ||
GpioC9::set(); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b0100); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b0100); | ||
|
||
GpioD21::set(); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b0101); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b0101); | ||
|
||
Port::reset(); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b0000); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b0000); | ||
} | ||
|
||
void | ||
GpioPortTest::testPortWrite() | ||
{ | ||
Port::write(0b1001); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b1001); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b1001); | ||
|
||
Port::write(0b0110); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b0110); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b0110); | ||
|
||
Port::write(0b0010); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b0010); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b0010); | ||
|
||
Port::write(0b0000); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b0000); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b0000); | ||
|
||
Port::set(); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b1111); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b1111); | ||
|
||
Port::reset(); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b0000); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b0000); | ||
} | ||
|
||
void | ||
GpioPortTest::testPortInverted() | ||
{ | ||
// inverted read | ||
Port::write(0b1111); | ||
TEST_ASSERT_EQUALS(Port2::isSet(), 0b1001); | ||
TEST_ASSERT_EQUALS(Port2::read(), 0b1001); | ||
|
||
Port::write(0b1101); | ||
TEST_ASSERT_EQUALS(Port2::isSet(), 0b1011); | ||
TEST_ASSERT_EQUALS(Port2::read(), 0b1011); | ||
|
||
Port::write(0b1001); | ||
TEST_ASSERT_EQUALS(Port2::isSet(), 0b1111); | ||
TEST_ASSERT_EQUALS(Port2::read(), 0b1111); | ||
|
||
Port::write(0b0000); | ||
TEST_ASSERT_EQUALS(Port2::isSet(), 0b0110); | ||
TEST_ASSERT_EQUALS(Port2::read(), 0b0110); | ||
|
||
// inverted write | ||
Port2::write(0b0000); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b0110); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b0110); | ||
|
||
Port2::write(0b0100); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b0010); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b0010); | ||
|
||
Port2::write(0b0110); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b0000); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b0000); | ||
|
||
Port2::write(0b1111); | ||
TEST_ASSERT_EQUALS(Port::isSet(), 0b1001); | ||
TEST_ASSERT_EQUALS(Port::read(), 0b1001); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
def init(module): | ||
module.name = ":test:platform:software_gpio_port" | ||
module.description = "Tests for Software GPIO port" | ||
|
||
def prepare(module, options): | ||
if not options[":target"].partname == "samv71q21b-aab": | ||
return False | ||
|
||
module.depends(":platform:gpio") | ||
return True | ||
|
||
def build(env): | ||
if not env.has_module(":board:samv71-xplained-ultra"): | ||
env.log.warn("GPIO port test has been hardcoded to the SAMV71 Xplained board" | ||
"When porting make sure this test does not damage your board!") | ||
return | ||
|
||
#env.substitutions = properties | ||
env.outbasepath = "modm-test/src/modm-test/platform/software_gpio_port" | ||
env.copy("gpio_port_test.hpp") | ||
env.copy("gpio_port_test_samv71.cpp") |