Skip to content

Commit

Permalink
pw_digital_io_mcuxpresso: Reorganize PINT support
Browse files Browse the repository at this point in the history
* Rename McuxpressoInterruptController to McuxpressoPintController to
  more accurately reflect its purpose.
* Move McuxpressoPintController and McuxpressoPintInterrupt to new
  pint.h header file and pint.cc source file.
* Make McuxpressoPintController methods private, friending
  McuxpressoPintInterrupt.

Bug: 337927184
Change-Id: I9be90c1a6563126afd6c6e08bd2d3d7ee5672216
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/260013
Reviewed-by: Eli Lipsitz <[email protected]>
Lint: Lint 🤖 <[email protected]>
Reviewed-by: Austin Foxley <[email protected]>
Commit-Queue: Jonathon Reinhart <[email protected]>
Reviewed-by: Kayce Basques <[email protected]>
Reviewed-by: Richard Pasek <[email protected]>
  • Loading branch information
JonathonReinhart authored and CQ Bot Account committed Jan 14, 2025
1 parent 2b3049b commit 5f53ccb
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 150 deletions.
1 change: 1 addition & 0 deletions docs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ _doxygen_input_files = [ # keep-sorted: start
"$dir_pw_digital_io_mcuxpresso/public/pw_digital_io_mcuxpresso/digital_io.h",
"$dir_pw_digital_io_mcuxpresso/public/pw_digital_io_mcuxpresso/interrupt_controller.h",
"$dir_pw_digital_io_mcuxpresso/public/pw_digital_io_mcuxpresso/interrupt_line.h",
"$dir_pw_digital_io_mcuxpresso/public/pw_digital_io_mcuxpresso/pint.h",
"$dir_pw_display/public/pw_display/color.h",
"$dir_pw_elf/public/pw_elf/reader.h",
"$dir_pw_function/public/pw_function/function.h",
Expand Down
7 changes: 3 additions & 4 deletions pw_digital_io_mcuxpresso/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ cc_library(
name = "pw_digital_io_mcuxpresso",
srcs = [
"digital_io.cc",
"interrupt_controller.cc",
"interrupt_line.cc",
"pint.cc",
],
hdrs = [
"public/pw_digital_io_mcuxpresso/digital_io.h",
"public/pw_digital_io_mcuxpresso/interrupt_controller.h",
"public/pw_digital_io_mcuxpresso/interrupt_line.h",
"public/pw_digital_io_mcuxpresso/pint.h",
],
strip_include_prefix = "public",
deps = [
Expand Down Expand Up @@ -62,7 +62,6 @@ filegroup(
name = "doxygen",
srcs = [
"public/pw_digital_io_mcuxpresso/digital_io.h",
"public/pw_digital_io_mcuxpresso/interrupt_controller.h",
"public/pw_digital_io_mcuxpresso/interrupt_line.h",
"public/pw_digital_io_mcuxpresso/pint.h",
],
)
4 changes: 2 additions & 2 deletions pw_digital_io_mcuxpresso/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ if (pw_third_party_mcuxpresso_SDK != "") {
"public/pw_digital_io_mcuxpresso/digital_io.h",
"public/pw_digital_io_mcuxpresso/interrupt_controller.h",
"public/pw_digital_io_mcuxpresso/interrupt_line.h",
"public/pw_digital_io_mcuxpresso/pint.h",
]
public_deps = [
"$dir_pw_containers:intrusive_forward_list",
Expand All @@ -44,8 +45,7 @@ if (pw_third_party_mcuxpresso_SDK != "") {
deps = [ "$dir_pw_assert" ]
sources = [
"digital_io.cc",
"interrupt_controller.cc",
"interrupt_line.cc",
"pint.cc",
]
}
}
Expand Down
17 changes: 8 additions & 9 deletions pw_digital_io_mcuxpresso/docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This module consists of these main classes:
- `McuxpressoDigitalIn`_ - Provides only input support.
- `McuxpressoDigitalOut`_ - Provides only output support.
- `McuxpressoDigitalInOutInterrupt`_ - Provides support for input, output, and GPIO interrupts.
- `McuxpressoInterruptController`_ - Controller class for use with ``McuxpressoPintInterrupt``.
- `McuxpressoPintController`_ - Controller class for use with ``McuxpressoPintInterrupt``.
- `McuxpressoPintInterrupt`_ - Provides only interrupt support for a PINT interrupt.

-----
Expand Down Expand Up @@ -113,19 +113,18 @@ Example code to use GPIO pins from an NXP SDK board definition:
PINT interrupt
==============
`McuxpressoPintInterrupt`_ can also be used to handle interrupts, via the PINT
module. It must be used with an instance of `McuxpressoInterruptController`_.
module. It must be used with an instance of `McuxpressoPintController`_.

.. code-block:: cpp
#include "pw_digital_io_mcuxpresso/interrupt_controller.h"
#include "pw_digital_io_mcuxpresso/interrupt_line.h"
#include "pw_digital_io_mcuxpresso/pint.h"
#include "pw_sync/interrupt_spin_lock.h"
McuxpressoInterruptController raw_pint_controller(PINT);
McuxpressoPintController raw_pint_controller(PINT);
pw::sync::VirtualInterruptSpinLock controller_lock;
pw::sync::Borrowable<McuxpressoInterruptController>
pw::sync::Borrowable<McuxpressoPintController>
pint_controller(raw_pint_controller, controller_lock);
McuxpressoPintInterrupt irq_line0(pint_controller, kPINT_PinInt0);
Expand Down Expand Up @@ -177,7 +176,7 @@ interrupts, via the PINT module, which supports other features:
.. doxygenclass:: pw::digital_io::McuxpressoPintInterrupt
:members:

McuxpressoInterruptController
=============================
.. doxygenclass:: pw::digital_io::McuxpressoInterruptController
McuxpressoPintController
========================
.. doxygenclass:: pw::digital_io::McuxpressoPintController
:members:
47 changes: 0 additions & 47 deletions pw_digital_io_mcuxpresso/interrupt_line.cc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
// License for the specific language governing permissions and limitations under
// the License.

#include "pw_digital_io_mcuxpresso/interrupt_controller.h"
#include "pw_digital_io_mcuxpresso/pint.h"

#include <array>
#include <cstdint>

#include "fsl_pint.h"
#include "pw_digital_io/digital_io.h"
#include "pw_function/function.h"
#include "pw_status/status.h"

namespace pw::digital_io {
namespace {
Expand All @@ -45,16 +43,16 @@ void PintCallback(pint_pin_int_t pin, uint32_t) {

} // namespace

McuxpressoInterruptController::McuxpressoInterruptController(PINT_Type* base)
// McuxpressoPintController

McuxpressoPintController::McuxpressoPintController(PINT_Type* base)
: base_(base) {
PINT_Init(base_);
}

McuxpressoInterruptController::~McuxpressoInterruptController() {
PINT_Deinit(base_);
}
McuxpressoPintController::~McuxpressoPintController() { PINT_Deinit(base_); }

pw::Status McuxpressoInterruptController::Config(
pw::Status McuxpressoPintController::Config(
pint_pin_int_t pin,
InterruptTrigger trigger,
pw::digital_io::InterruptHandler&& handler) {
Expand Down Expand Up @@ -82,8 +80,8 @@ pw::Status McuxpressoInterruptController::Config(
return pw::OkStatus();
}

pw::Status McuxpressoInterruptController::EnableHandler(pint_pin_int_t pin,
bool enable) {
pw::Status McuxpressoPintController::EnableHandler(pint_pin_int_t pin,
bool enable) {
if (enable) {
PINT_EnableCallbackByIndex(base_, pin);
} else {
Expand All @@ -92,4 +90,27 @@ pw::Status McuxpressoInterruptController::EnableHandler(pint_pin_int_t pin,
return pw::OkStatus();
}

// McuxpressoPintInterrupt

McuxpressoPintInterrupt::McuxpressoPintInterrupt(
pw::sync::Borrowable<McuxpressoPintController>& controller,
pint_pin_int_t pin)
: controller_(controller), pin_(pin) {}

pw::Status McuxpressoPintInterrupt::DoEnable(bool) {
// Can not enabled at individual line level. Only at controller level, which
// is always enabled.
return pw::OkStatus();
}

pw::Status McuxpressoPintInterrupt::DoSetInterruptHandler(
pw::digital_io::InterruptTrigger trigger,
pw::digital_io::InterruptHandler&& handler) {
return controller_.acquire()->Config(pin_, trigger, std::move(handler));
}

pw::Status McuxpressoPintInterrupt::DoEnableInterruptHandler(bool enable) {
return controller_.acquire()->EnableHandler(pin_, enable);
}

} // namespace pw::digital_io
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,7 @@
// the License.
#pragma once

#include "fsl_pint.h"
#include "pw_digital_io/digital_io.h"
#include "pw_status/status.h"
#include "pw_digital_io_mcuxpresso/pint.h"

namespace pw::digital_io {

/// Abstracts the Pin Interrupt (PINT) module.
///
/// One instance of this class should be created to enable the creation of
/// `McuxpressoPintInterrupt` lines; it is not intended to be otherwise used by
/// end-users.
class McuxpressoInterruptController {
public:
/// Constructs a McuxpressoInterruptController for an instance of the PINT
/// module.
///
/// @param[in] base The base address of the PINT module (e.g. `PINT`).
McuxpressoInterruptController(PINT_Type* base);
~McuxpressoInterruptController();

McuxpressoInterruptController(const McuxpressoInterruptController&) = delete;
McuxpressoInterruptController& operator=(
const McuxpressoInterruptController&) = delete;

pw::Status Config(pint_pin_int_t pin,
pw::digital_io::InterruptTrigger trigger,
pw::digital_io::InterruptHandler&& handler);
pw::Status EnableHandler(pint_pin_int_t pin, bool enable);

private:
PINT_Type* base_;
};

} // namespace pw::digital_io
// Deprecated compatibility header.
// TODO: https://pwbug.dev/337927184 - Remove this after downstreams migrate.
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,7 @@
// the License.
#pragma once

#include "pw_digital_io/digital_io.h"
#include "pw_digital_io_mcuxpresso/interrupt_controller.h"
#include "pw_status/status.h"
#include "pw_sync/borrow.h"
#include "pw_digital_io_mcuxpresso/pint.h"

namespace pw::digital_io {

/// Represents one interrupt on the PINT module.
///
/// Class-specific behaviors:
/// * The pin must be attached to the PINT module via
/// `INPUTMUX_AttachSignal()`.
/// * `Enable` and `Disable` have no effect.
/// * The input buffer for the pin must be enabled in the IO Pad Controller
/// (`IOPCTL`) via the Input Buffer Enable (`IBENA`) bit.
/// * The input polarity is affected by the Input Invert Enable (`IIENA`) bit
/// on the corresponding IO Pad Controller (`IOPCTL`) register.
class McuxpressoPintInterrupt : public pw::digital_io::DigitalInterrupt {
public:
/// Constructs a McuxpressoPintInterrupt for a specific pin.
///
/// @param[in] controller A `pw::sync::Borrowable` reference to the
/// `McuxpressoInterruptController` representing the PINT module.
///
/// @param[in] pin The `pint_pin_int_t` enum member identifying the pin
/// interrupt on the PINT module.
McuxpressoPintInterrupt(
pw::sync::Borrowable<McuxpressoInterruptController>& controller,
pint_pin_int_t pin);

McuxpressoPintInterrupt(const McuxpressoPintInterrupt&) = delete;
McuxpressoPintInterrupt& operator=(const McuxpressoPintInterrupt&) = delete;

private:
// pw::digital_io::DigitalInterrupt implementation
pw::Status DoEnable(bool enable) override;
pw::Status DoSetInterruptHandler(
pw::digital_io::InterruptTrigger trigger,
pw::digital_io::InterruptHandler&& handler) override;
pw::Status DoEnableInterruptHandler(bool enable) override;

pw::sync::Borrowable<McuxpressoInterruptController>& controller_;
pint_pin_int_t pin_;
};

} // namespace pw::digital_io
// Deprecated compatibility header.
// TODO: https://pwbug.dev/337927184 - Remove this after downstreams migrate.
Loading

0 comments on commit 5f53ccb

Please sign in to comment.