pw_digital_io_mcuxpresso#

Digital I/O for NXP MCUXpresso

Stable C++

pw_digital_io_mcuxpresso implements the pw_digital_io interface using the NXP MCUXpresso SDK.

Overview#

This module consists of these main classes:

Setup#

Use of this module requires setting up the MCUXpresso SDK for use with Pigweed. Follow the steps in pw_build_mcuxpresso to create a pw_source_set for an MCUXpresso SDK. Include the GPIO and PINT driver components in this SDK definition.

Examples#

Digital input#

Use McuxpressoDigitalIn to read the state of an input.

Example code to use GPIO pins from an NXP SDK board definition:

#include "board/pin_mux.h"
#include "pw_digital_io_mcuxpresso/digital_io.h"

McuxpressoDigitalIn input(BOARD_INITPINS_D9_GPIO,
                          BOARD_INITPINS_D9_PORT,
                          BOARD_INITPINS_D9_PIN);

Status Init() {
  return input.Enable();
}

Status InputExample() {
  PW_TRY_ASSIGN(const DigitalIo::State state, input.GetState());
  // ...
}

Digital output#

Use McuxpressoDigitalOut to set the state of an output.

Example code to use GPIO pins from an NXP SDK board definition:

#include "board/pin_mux.h"
#include "pw_digital_io_mcuxpresso/digital_io.h"
#include "pw_status/status.h"

McuxpressoDigitalOut output(BOARD_INITPINS_D8_GPIO,
                            BOARD_INITPINS_D8_PORT,
                            BOARD_INITPINS_D8_PIN,
                            pw::digital_io::State::kActive);

Status Init() {
  return output.Enable();
}

Status OutputExample() {
  return output.SetState(pw::digital_io::State::kInactive);
}

GPIO interrupt#

Use McuxpressoDigitalInOutInterrupt to handle interrupts via the GPIO module.

Example code to use GPIO pins from an NXP SDK board definition:

#include "board/pin_mux.h"
#include "pw_digital_io_mcuxpresso/digital_io.h"
#include "pw_status/status.h"

McuxpressoDigitalInOutInterrupt irq_pin(BOARD_INITPINS_D9_GPIO,
                                        BOARD_INITPINS_D9_PORT,
                                        BOARD_INITPINS_D9_PIN,
                                        /* output= */ false);

Status Init() {
  PW_TRY(irq_pin.Enable());
  PW_TRY(irq_pin.SetInterruptHandler(
      pw::digital_io::InterruptTrigger::kDeactivatingEdge,
      [](State /* state */) {
        irq_count++;
      }));
  PW_TRY(irq_pin.EnableInterruptHandler());
  return OkStatus();
}

PINT interrupt#

McuxpressoPintInterrupt can also be used to handle interrupts, via the PINT module. It must be used with an instance of McuxpressoPintController.

#include "pw_digital_io_mcuxpresso/pint.h"
#include "pw_sync/interrupt_spin_lock.h"

McuxpressoPintController raw_pint_controller(PINT);

pw::sync::VirtualInterruptSpinLock controller_lock;

pw::sync::Borrowable<McuxpressoPintController>
    pint_controller(raw_pint_controller, controller_lock);

McuxpressoPintInterrupt irq_line0(pint_controller, kPINT_PinInt0);

Status Init() {
  // Attach pin PIO0_4 to PINT interrupt 0.
  INPUTMUX_AttachSignal(INPUTMUX, kPINT_PinInt0, kINPUTMUX_GpioPort0Pin4ToPintsel);

  PW_TRY(irq_line0.Enable());
  PW_TRY(irq_line0.SetInterruptHandler(
      pw::digital_io::InterruptTrigger::kBothEdges,
      [](State /* state */) {
        irq_count++;
      }));
  PW_TRY(irq_line0.EnableInterruptHandler());
  return OkStatus();
}

API reference#

McuxpressoDigitalIn#

class McuxpressoDigitalIn : public pw::digital_io::DigitalIn#

Provides input-only support for an MCUXpresso GPIO pin.

Class-specific behaviors:

  • 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.

Public Functions

McuxpressoDigitalIn(GPIO_Type *base, uint32_t port, uint32_t pin)#

Constructs a McuxpressoDigitalIn for a specific GPIO module+port+pin.

Parameters:
  • base[in] The base address of the GPIO module (e.g. GPIO).

  • port[in] The port number on the given GPIO module.

  • pin[in] The pin number on the given GPIO port.

inline bool is_enabled() const#

Returns true if the input is enabled.

McuxpressoDigitalOut#

class McuxpressoDigitalOut : public pw::digital_io::DigitalOut#

Provides output-only support for an MCUXpresso GPIO pin.

Class-specific behaviors:

  • When Disable is called, the GPIO is configured as an input, which disables the output driver.

Public Functions

McuxpressoDigitalOut(GPIO_Type *base, uint32_t port, uint32_t pin, pw::digital_io::State initial_state)#

Constructs a McuxpressoDigitalOut for a specific GPIO module+port+pin.

Parameters:
  • base[in] The base address of the GPIO module (e.g. GPIO).

  • port[in] The port number on the given GPIO module.

  • pin[in] The pin number on the given GPIO port.

  • initial_state[in] The state to be driven when the line is enabled.

inline bool is_enabled() const#

Returns true if the output is enabled.

McuxpressoDigitalInOutInterrupt#

class McuxpressoDigitalInOutInterrupt : public pw::digital_io::DigitalInOutInterrupt, public pw::IntrusiveForwardList<T>::Item#

Provides input, output, and interrupt support for an MCUXpresso GPIO pin.

Interrupts are provided by IRQ “A” on the GPIO module.

Class-specific behaviors:

  • The direction of the pin cannot be changed after construction.

  • If configured as an output:

    • The default state on Enable is 0 (inactive).

    • Disable has no actual effect; unlike McuxpressoDigitalOut, the GPIO is not reverted to an input.

  • If configured as an input:

    • 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.

Public Functions

McuxpressoDigitalInOutInterrupt(GPIO_Type *base, uint32_t port, uint32_t pin, bool output)#

Constructs a McuxpressoDigitalInOutInterrupt for a specific GPIO module+port+pin.

Parameters:
  • base[in] The base address of the GPIO module (e.g. GPIO).

  • port[in] The port number on the given GPIO module.

  • pin[in] The pin number on the given GPIO port.

  • output[in] True if the line should be configured as an output on enable; False if it should be an input.

inline bool is_enabled() const#

Returns true if the line is enabled (in any state).

McuxpressoPintInterrupt#

pw::digital_io::McuxpressoPintInterrupt can also be used to handle interrupts, via the PINT module, which supports other features:

  • Dedicated (non-shared) IRQs for each interrupt

  • Double edge detection (InterruptTrigger::kBothEdges)

  • Waking from deep sleep with edge detection

  • Pattern matching support (currently unsupported here)

  • Triggering interrupts on pins configured for a non-GPIO function

class McuxpressoPintInterrupt : public pw::digital_io::DigitalInterrupt#

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.

Public Functions

McuxpressoPintInterrupt(pw::sync::Borrowable<McuxpressoPintController> &controller, pint_pin_int_t pin)#

Constructs a McuxpressoPintInterrupt for a specific pin.

Parameters:

McuxpressoPintController#

class McuxpressoPintController#

Abstracts the Pin Interrupt (PINT) module.

One instance of this class should be created to enable the creation of McuxpressoPintInterrupt lines.

Public Functions

McuxpressoPintController(PINT_Type *base)#

Constructs a McuxpressoPintController for an instance of the PINT module.

Parameters:

base[in] The base address of the PINT module (e.g. PINT).