-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Add SAMV71 I2C unit test for Xplained Ultra board
- Loading branch information
1 parent
0689b05
commit d1938eb
Showing
3 changed files
with
133 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,71 @@ | ||
/* | ||
* 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 "i2c_platform_test.hpp" | ||
|
||
#include <modm/platform.hpp> | ||
#include <modm/board.hpp> | ||
#include <modm/driver/storage/at24mac402.hpp> | ||
|
||
using namespace modm::platform; | ||
using namespace Board; | ||
|
||
namespace | ||
{ | ||
modm::At24Mac402<I2c> eeprom{0x57}; | ||
} | ||
|
||
void | ||
I2cPlatformTest::setUp() | ||
{ | ||
I2c::connect<Sda::Twd, Scl::Twck>(); | ||
I2c::initialize<SystemClock, 400_kHz>(); | ||
} | ||
|
||
void | ||
I2cPlatformTest::testPing() | ||
{ | ||
// ping at wrong address | ||
for (uint8_t address = 0x50; address <= 0x56; ++address) { | ||
eeprom.setAddress(address); | ||
const bool response = RF_CALL_BLOCKING(eeprom.ping()); | ||
TEST_ASSERT_FALSE(response); | ||
} | ||
// set correct address 0x57 | ||
eeprom.setAddress(0x57); | ||
// ping at correct address | ||
for (int i = 0; i < 20; ++i) { | ||
const bool response = RF_CALL_BLOCKING(eeprom.ping()); | ||
TEST_ASSERT_TRUE(response); | ||
} | ||
} | ||
|
||
void | ||
I2cPlatformTest::testDataRead() | ||
{ | ||
std::array<uint8_t, 6> buffer{}; | ||
|
||
// read pre-programmed MAC address | ||
|
||
// read at wrong address | ||
eeprom.setAddress(0x55); | ||
bool readSuccess = RF_CALL_BLOCKING(eeprom.readMac(buffer)); | ||
TEST_ASSERT_FALSE(readSuccess); | ||
|
||
// read at correct address | ||
eeprom.setAddress(0x57); | ||
readSuccess = RF_CALL_BLOCKING(eeprom.readMac(buffer)); | ||
TEST_ASSERT_TRUE(readSuccess); | ||
|
||
TEST_ASSERT_EQUALS(buffer[0], 0xfc); | ||
TEST_ASSERT_EQUALS(buffer[1], 0xc2); | ||
TEST_ASSERT_EQUALS(buffer[2], 0x3d); | ||
} |
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,26 @@ | ||
/* | ||
* 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_i2c | ||
class I2cPlatformTest : public unittest::TestSuite | ||
{ | ||
public: | ||
void | ||
setUp() override; | ||
|
||
void | ||
testPing(); | ||
|
||
void | ||
testDataRead(); | ||
}; |
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,36 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# 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/. | ||
|
||
|
||
def init(module): | ||
module.name = ":test:platform:i2c" | ||
module.description = "Tests for SAMx7x I2C" | ||
|
||
def prepare(module, options): | ||
target = options[":target"] | ||
|
||
identifier = target.identifier | ||
if identifier.platform != "sam" or identifier.family != "e7x/s7x/v7x": | ||
return False | ||
|
||
module.depends(":platform:i2c:0") | ||
module.depends(":driver:at24mac402") | ||
return True | ||
|
||
def build(env): | ||
if not env.has_module(":board:samv71-xplained-ultra"): | ||
env.log.warn("The test requires an AT24MAC402 EEPROM to be connected to specific pins." | ||
"Only the SAMV71 Xplained Ultra board is supported for now.") | ||
return | ||
|
||
env.outbasepath = "modm-test/src/modm-test/platform/i2c_test" | ||
env.copy("i2c_platform_test.hpp") | ||
env.copy("i2c_platform_test.cpp") |