2013-02-18 15:32:11 +00:00
|
|
|
/* mbed Microcontroller Library
|
2019-07-11 15:23:39 +00:00
|
|
|
* Copyright (c) 2006-2019 ARM Limited
|
2018-11-09 11:22:52 +00:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2013-02-18 15:32:11 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#ifndef MBED_PORTINOUT_H
|
|
|
|
#define MBED_PORTINOUT_H
|
|
|
|
|
2016-10-01 07:11:36 +00:00
|
|
|
#include "platform/platform.h"
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2018-12-04 02:44:27 +00:00
|
|
|
#if DEVICE_PORTINOUT || defined(DOXYGEN_ONLY)
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2016-10-01 07:11:36 +00:00
|
|
|
#include "hal/port_api.h"
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
namespace mbed {
|
2019-07-11 15:23:39 +00:00
|
|
|
/**
|
|
|
|
* \defgroup drivers_PortInOut PortInOut class
|
2019-07-24 15:59:40 +00:00
|
|
|
* \ingroup drivers-public-api-gpio
|
2019-07-11 15:23:39 +00:00
|
|
|
* @{
|
|
|
|
*/
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
/** A multiple pin digital in/out used to set/read multiple bi-directional pins
|
2016-06-08 12:52:14 +00:00
|
|
|
*
|
2017-04-04 17:40:09 +00:00
|
|
|
* @note Synchronization level: Interrupt safe
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
|
|
|
class PortInOut {
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** Create an PortInOut, connected to the specified port
|
|
|
|
*
|
|
|
|
* @param port Port to connect to (Port0-Port5)
|
|
|
|
* @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
|
|
|
|
*/
|
2019-07-11 15:23:39 +00:00
|
|
|
PortInOut(PortName port, int mask = 0xFFFFFFFF);
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
/** Write the value to the output port
|
|
|
|
*
|
|
|
|
* @param value An integer specifying a bit to write for every corresponding port pin
|
|
|
|
*/
|
2018-05-24 15:58:14 +00:00
|
|
|
void write(int value)
|
|
|
|
{
|
2013-02-18 15:32:11 +00:00
|
|
|
port_write(&_port, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Read the value currently output on the port
|
|
|
|
*
|
|
|
|
* @returns
|
|
|
|
* An integer with each bit corresponding to associated port pin setting
|
|
|
|
*/
|
2018-05-24 15:58:14 +00:00
|
|
|
int read()
|
|
|
|
{
|
2013-02-18 15:32:11 +00:00
|
|
|
return port_read(&_port);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set as an output
|
|
|
|
*/
|
2019-07-11 15:23:39 +00:00
|
|
|
void output();
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
/** Set as an input
|
|
|
|
*/
|
2019-07-11 15:23:39 +00:00
|
|
|
void input();
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
/** Set the input pin mode
|
|
|
|
*
|
|
|
|
* @param mode PullUp, PullDown, PullNone, OpenDrain
|
|
|
|
*/
|
2019-07-11 15:23:39 +00:00
|
|
|
void mode(PinMode mode);
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
/** A shorthand for write()
|
2017-06-08 04:30:43 +00:00
|
|
|
* \sa PortInOut::write()
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
2018-05-24 15:58:14 +00:00
|
|
|
PortInOut &operator= (int value)
|
|
|
|
{
|
2013-02-18 15:32:11 +00:00
|
|
|
write(value);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-06-08 04:30:43 +00:00
|
|
|
/** A shorthand for write()
|
|
|
|
* \sa PortInOut::write()
|
|
|
|
*/
|
2018-05-24 15:58:14 +00:00
|
|
|
PortInOut &operator= (PortInOut &rhs)
|
|
|
|
{
|
2013-02-18 15:32:11 +00:00
|
|
|
write(rhs.read());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** A shorthand for read()
|
2017-06-08 04:30:43 +00:00
|
|
|
* \sa PortInOut::read()
|
2013-02-18 15:32:11 +00:00
|
|
|
*/
|
2018-05-24 15:58:14 +00:00
|
|
|
operator int()
|
|
|
|
{
|
2013-02-18 15:32:11 +00:00
|
|
|
return read();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
port_t _port;
|
|
|
|
};
|
|
|
|
|
2019-07-11 15:23:39 +00:00
|
|
|
/** @}*/
|
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
} // namespace mbed
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|