Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BusIn.h Source File

BusIn.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 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_BUSIN_H
00018 #define MBED_BUSIN_H
00019 
00020 #include "platform/platform.h"
00021 #include "drivers/DigitalIn.h"
00022 #include "platform/PlatformMutex.h"
00023 #include "platform/NonCopyable.h"
00024 
00025 namespace mbed {
00026 /**
00027  * \defgroup drivers_BusIn BusIn class
00028  * \ingroup drivers-public-api-gpio
00029  * @{
00030  */
00031 
00032 /** A digital input bus, used for reading the state of a collection of pins
00033  *
00034  * @note Synchronization level: Thread safe
00035  */
00036 class BusIn : private NonCopyable<BusIn> {
00037 
00038 public:
00039     /* Group: Configuration Methods */
00040 
00041     /** Create an BusIn, connected to the specified pins
00042      *
00043      * @param p0 DigitalIn pin to connect to bus bit
00044      * @param p1 DigitalIn pin to connect to bus bit
00045      * @param p2 DigitalIn pin to connect to bus bit
00046      * @param p3 DigitalIn pin to connect to bus bit
00047      * @param p4 DigitalIn pin to connect to bus bit
00048      * @param p5 DigitalIn pin to connect to bus bit
00049      * @param p6 DigitalIn pin to connect to bus bit
00050      * @param p7 DigitalIn pin to connect to bus bit
00051      * @param p8 DigitalIn pin to connect to bus bit
00052      * @param p9 DigitalIn pin to connect to bus bit
00053      * @param p10 DigitalIn pin to connect to bus bit
00054      * @param p11 DigitalIn pin to connect to bus bit
00055      * @param p12 DigitalIn pin to connect to bus bit
00056      * @param p13 DigitalIn pin to connect to bus bit
00057      * @param p14 DigitalIn pin to connect to bus bit
00058      * @param p15 DigitalIn pin to connect to bus bit
00059      *
00060      * @note
00061      *  It is only required to specify as many pin variables as is required
00062      *  for the bus; the rest will default to NC (not connected)
00063      */
00064     BusIn(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
00065           PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
00066           PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
00067           PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
00068 
00069 
00070     /** Create an BusIn, connected to the specified pins
00071      *
00072      * @param pins An array of pins to connect to bus bit
00073      */
00074     BusIn(PinName pins[16]);
00075 
00076     virtual ~BusIn();
00077 
00078     /** Read the value of the input bus
00079      *
00080      *  @returns
00081      *   An integer with each bit corresponding to the value read from the associated DigitalIn pin
00082      */
00083     int read();
00084 
00085     /** Set the input pin mode
00086      *
00087      *  @param pull PullUp, PullDown, PullNone
00088      */
00089     void mode(PinMode pull);
00090 
00091     /** Binary mask of bus pins connected to actual pins (not NC pins)
00092      *  If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
00093      *
00094      *  @returns
00095      *    Binary mask of connected pins
00096      */
00097     int mask()
00098     {
00099         // No lock needed since _nc_mask is not modified outside the constructor
00100         return _nc_mask;
00101     }
00102 
00103     /** A shorthand for read()
00104      *  \sa DigitalIn::read()
00105      */
00106     operator int();
00107 
00108     /** Access to particular bit in random-iterator fashion
00109      * @param index  Position of bit
00110      */
00111     DigitalIn &operator[](int index);
00112 
00113 #if !defined(DOXYGEN_ONLY)
00114 protected:
00115     DigitalIn *_pin[16];
00116 
00117     /* Mask of bus's NC pins
00118      * If bit[n] is set to 1 - pin is connected
00119      * if bit[n] is cleared - pin is not connected (NC)
00120      */
00121     int _nc_mask;
00122 
00123     PlatformMutex _mutex;
00124 
00125 private:
00126     virtual void lock();
00127     virtual void unlock();
00128 #endif
00129 };
00130 
00131 /** @}*/
00132 
00133 } // namespace mbed
00134 
00135 #endif
00136