PortInOut
Use the PortInOut interface to read and write an underlying GPIO port as one value. This is much faster than BusInOut because you can write a port all at once, but it is much less flexible because you are constrained by the port and bit layout of the underlying GPIO ports.
A mask can be supplied so you only use certain parts of a port, allowing other bits to be used for other interfaces.
PortInOut class reference
Public Member Functions | |
PortInOut (PortName port, int mask=0xFFFFFFFF) | |
Create an PortInOut, connected to the specified port. More... | |
void | write (int value) |
Write the value to the output port. More... | |
int | read () |
Read the value currently output on the port. More... | |
void | output () |
Set as an output. More... | |
void | input () |
Set as an input. More... | |
void | mode (PinMode mode) |
Set the input pin mode. More... | |
PortInOut & | operator= (int value) |
A shorthand for write() More... | |
PortInOut & | operator= (PortInOut &rhs) |
A shorthand for write() More... | |
operator int () | |
A shorthand for read() More... |
PortInOut hello, world
/*
* Copyright (c) 2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
// Switch on an LED if any of mbed pins 21-26 is high
PortIn p(PortA, 0x0000003F); // p21-p26
DigitalOut ind(LED_RED);
int main()
{
while (1) {
int pins = p.read();
if (pins) {
ind = 1;
} else {
ind = 0;
}
}
}
Related content
- BusInOut API reference.