Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PortInOut.h Source File

PortInOut.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2019 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #ifndef MBED_PORTINOUT_H
00018 #define MBED_PORTINOUT_H
00019 
00020 #include "platform/platform.h"
00021 
00022 #if DEVICE_PORTINOUT || defined(DOXYGEN_ONLY)
00023 
00024 #include "hal/port_api.h"
00025 
00026 namespace mbed {
00027 /**
00028  * \defgroup drivers_PortInOut PortInOut class
00029  * \ingroup drivers-public-api-gpio
00030  * @{
00031  */
00032 
00033 /** A multiple pin digital in/out used to set/read multiple bi-directional pins
00034  *
00035  * @note Synchronization level: Interrupt safe
00036  */
00037 class PortInOut {
00038 public:
00039 
00040     /** Create an PortInOut, connected to the specified port
00041      *
00042      *  @param port Port to connect to (Port0-Port5)
00043      *  @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
00044      */
00045     PortInOut(PortName port, int mask = 0xFFFFFFFF);
00046 
00047     /** Write the value to the output port
00048      *
00049      *  @param value An integer specifying a bit to write for every corresponding port pin
00050      */
00051     void write(int value)
00052     {
00053         port_write(&_port, value);
00054     }
00055 
00056     /** Read the value currently output on the port
00057      *
00058      *  @returns
00059      *    An integer with each bit corresponding to associated port pin setting
00060      */
00061     int read()
00062     {
00063         return port_read(&_port);
00064     }
00065 
00066     /** Set as an output
00067      */
00068     void output();
00069 
00070     /** Set as an input
00071      */
00072     void input();
00073 
00074     /** Set the input pin mode
00075      *
00076      *  @param mode PullUp, PullDown, PullNone, OpenDrain
00077      */
00078     void mode(PinMode mode);
00079 
00080     /** A shorthand for write()
00081      * \sa PortInOut::write()
00082      */
00083     PortInOut &operator= (int value)
00084     {
00085         write(value);
00086         return *this;
00087     }
00088 
00089     /** A shorthand for write()
00090      * \sa PortInOut::write()
00091      */
00092     PortInOut &operator= (PortInOut &rhs)
00093     {
00094         write(rhs.read());
00095         return *this;
00096     }
00097 
00098     /** A shorthand for read()
00099      * \sa PortInOut::read()
00100      */
00101     operator int()
00102     {
00103         return read();
00104     }
00105 
00106 private:
00107     port_t _port;
00108 };
00109 
00110 /** @}*/
00111 
00112 } // namespace mbed
00113 
00114 #endif
00115 
00116 #endif