Skip to content

Commit d756c69

Browse files
afoxleyCQ Bot Account
authored and
CQ Bot Account
committed
pw_digital_io_mcuxpresso: Pass correct pin state for interrupt handler
Also allow enable on enabled pin to be a no-op to align with current digital_io reccomendations. Add a test that builds when the rt595 sample sdk is enabled to ensure this code is built in CI. If no tests are present in a conditionally compiled module then pigweed CI won't compile it. Change-Id: I472044989421c30e6a11bb39f208e6f0d5df136b Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/151131 Reviewed-by: Anton Markov <amarkov@google.com> Commit-Queue: Austin Foxley <afoxley@google.com>
1 parent 649f742 commit d756c69

File tree

6 files changed

+76
-6
lines changed

6 files changed

+76
-6
lines changed

pw_digital_io_mcuxpresso/BUILD.bazel

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
load(
1616
"//pw_build:pigweed.bzl",
1717
"pw_cc_library",
18+
"pw_cc_test",
1819
)
1920

2021
package(default_visibility = ["//visibility:public"])
@@ -41,3 +42,12 @@ pw_cc_library(
4142
"//pw_preprocessor",
4243
],
4344
)
45+
46+
pw_cc_test(
47+
name = "mimxrt595_test",
48+
srcs = ["mimxrt595_test.cc"],
49+
target_compatible_with = [
50+
"//pw_build/constraints/board:mimxrt595_evk",
51+
],
52+
deps = [":pw_digital_io_mcuxpresso"],
53+
)

pw_digital_io_mcuxpresso/BUILD.gn

+15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import("//build_overrides/pigweed.gni")
1717
import("$dir_pw_build/target_types.gni")
1818
import("$dir_pw_docgen/docs.gni")
1919
import("$dir_pw_third_party/mcuxpresso/mcuxpresso.gni")
20+
import("$dir_pw_toolchain/generate_toolchain.gni")
2021
import("$dir_pw_unit_test/test.gni")
2122

2223
config("default_config") {
@@ -47,7 +48,21 @@ if (pw_third_party_mcuxpresso_SDK != "") {
4748
}
4849
}
4950

51+
pw_test("mimxrt595_test") {
52+
enable_if =
53+
pw_third_party_mcuxpresso_SDK == "//targets/mimxrt595_evk:sample_sdk" &&
54+
(pw_toolchain_SCOPE.name == "mimxrt595_evk_debug" ||
55+
pw_toolchain_SCOPE.name == "mimxrt595_evk_size_optimized" ||
56+
pw_toolchain_SCOPE.name == "mimxrt595_evk_speed_optimized")
57+
sources = [ "mimxrt595_test.cc" ]
58+
deps = [
59+
":pw_digital_io_mcuxpresso",
60+
"//targets/mimxrt595_evk:sample_sdk",
61+
]
62+
}
63+
5064
pw_test_group("tests") {
65+
tests = [ ":mimxrt595_test" ]
5166
}
5267

5368
pw_doc_group("docs") {

pw_digital_io_mcuxpresso/digital_io.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "fsl_gpio.h"
2121
#include "fsl_reset.h"
2222
#include "pw_assert/check.h"
23-
#include "pw_digital_io_mcuxpresso/digital_io_mcuxpresso.h"
23+
#include "pw_digital_io_mcuxpresso/digital_io.h"
2424
#include "pw_status/status.h"
2525

2626
namespace pw::digital_io {
@@ -47,7 +47,7 @@ McuxpressoDigitalOut::McuxpressoDigitalOut(GPIO_Type* base,
4747
pw::Status McuxpressoDigitalOut::DoEnable(bool enable) {
4848
if (enable) {
4949
if (is_enabled()) {
50-
return pw::Status::FailedPrecondition();
50+
return pw::OkStatus();
5151
}
5252

5353
CLOCK_EnableClock(kGpioClocks[port_]);

pw_digital_io_mcuxpresso/docs.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ the NXP MCUXpresso SDK.
88

99
Setup
1010
=====
11-
Use of this module requires setting up the MCUXpresso SDK for use with pigweed. Follow
11+
Use of this module requires setting up the MCUXpresso SDK for use with Pigweed. Follow
1212
the steps in :ref:`module-pw_build_mcuxpresso` to create a ``pw_source_set`` for an
1313
MCUXpresso SDK. Include the GPIO and PINT driver components in this SDK definition.
1414

@@ -42,8 +42,8 @@ Then, depend on this module in your BUILD.gn to use.
4242
4343
deps = [ dir_pw_digital_io_mcuxpresso ]
4444
45-
Use
46-
===
45+
Examples
46+
========
4747
Use ``pw::digital_io::McuxpressoDigitalIn`` and ``pw::digital_io::McuxpressoDigitalOut``
4848
classes to control GPIO pins.
4949

pw_digital_io_mcuxpresso/interrupt_controller.cc

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ namespace {
2929
using ::pw::digital_io::InterruptTrigger;
3030
using ::pw::digital_io::State;
3131

32+
// PINT API doesn't allow context on callback API, so store globally.
3233
std::array<pw::digital_io::InterruptHandler,
3334
FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS>
3435
interrupt_handlers;
36+
std::array<PINT_Type*, FSL_FEATURE_PINT_NUMBER_OF_CONNECTED_OUTPUTS> bases;
3537

3638
void PintCallback(pint_pin_int_t pin, uint32_t) {
3739
PW_CHECK(pin < interrupt_handlers.size());
38-
interrupt_handlers[pin](State::kActive);
40+
State state = PINT_PinInterruptGetStatus(bases[pin], pin) == 1
41+
? State::kActive
42+
: State::kInactive;
43+
interrupt_handlers[pin](state);
3944
SDK_ISR_EXIT_BARRIER;
4045
}
4146

@@ -58,6 +63,7 @@ pw::Status McuxpressoInterruptController::Config(
5863
return pw::Status::InvalidArgument();
5964
}
6065
interrupt_handlers[pin] = std::move(handler);
66+
bases[pin] = base_;
6167
switch (trigger) {
6268
case InterruptTrigger::kActivatingEdge:
6369
PINT_PinInterruptConfig(
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2023 The Pigweed Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4+
// use this file except in compliance with the License. You may obtain a copy of
5+
// the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
// License for the specific language governing permissions and limitations under
13+
// the License.
14+
15+
#include <cstdint>
16+
17+
#include "gtest/gtest.h"
18+
#include "pw_digital_io/digital_io.h"
19+
#include "pw_digital_io_mcuxpresso/digital_io.h"
20+
#include "pw_status/status.h"
21+
22+
namespace pw::digital_io {
23+
namespace {
24+
25+
constexpr uint32_t kPort = 0;
26+
constexpr uint32_t kPin = 8;
27+
28+
TEST(DigitalIoTest, SetOk) {
29+
McuxpressoDigitalOut out(GPIO, kPort, kPin, pw::digital_io::State::kActive);
30+
EXPECT_TRUE(out.SetState(pw::digital_io::State::kInactive).ok());
31+
}
32+
33+
TEST(DigitalIoTest, GetOk) {
34+
McuxpressoDigitalIn in(GPIO, kPort, kPin);
35+
EXPECT_TRUE(in.GetState().ok());
36+
}
37+
38+
} // namespace
39+
} // namespace pw::digital_io

0 commit comments

Comments
 (0)