Renesas GR-PEACH OpenCV Development / gr-peach-opencv-project-sd-card_update

Fork of gr-peach-opencv-project-sd-card by the do

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  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef MBED_BUSIN_H
00017 #define MBED_BUSIN_H
00018 
00019 #include "platform/platform.h"
00020 #include "drivers/DigitalIn.h"
00021 #include "platform/PlatformMutex.h"
00022 
00023 namespace mbed {
00024 /** \addtogroup drivers */
00025 
00026 /** A digital input bus, used for reading the state of a collection of pins
00027  *
00028  * @note Synchronization level: Thread safe
00029  * @ingroup drivers
00030  */
00031 class BusIn {
00032 
00033 public:
00034     /* Group: Configuration Methods */
00035 
00036     /** Create an BusIn, connected to the specified pins
00037      *
00038      * @param p0 DigitalIn pin to connect to bus bit
00039      * @param p1 DigitalIn pin to connect to bus bit
00040      * @param p2 DigitalIn pin to connect to bus bit
00041      * @param p3 DigitalIn pin to connect to bus bit
00042      * @param p4 DigitalIn pin to connect to bus bit
00043      * @param p5 DigitalIn pin to connect to bus bit
00044      * @param p6 DigitalIn pin to connect to bus bit
00045      * @param p7 DigitalIn pin to connect to bus bit
00046      * @param p8 DigitalIn pin to connect to bus bit
00047      * @param p9 DigitalIn pin to connect to bus bit
00048      * @param p10 DigitalIn pin to connect to bus bit
00049      * @param p11 DigitalIn pin to connect to bus bit
00050      * @param p12 DigitalIn pin to connect to bus bit
00051      * @param p13 DigitalIn pin to connect to bus bit
00052      * @param p14 DigitalIn pin to connect to bus bit
00053      * @param p15 DigitalIn pin to connect to bus bit
00054      *
00055      * @note
00056      *  It is only required to specify as many pin variables as is required
00057      *  for the bus; the rest will default to NC (not connected)
00058      */
00059     BusIn(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
00060           PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
00061           PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
00062           PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
00063 
00064     
00065     /** Create an BusIn, connected to the specified pins
00066      *
00067      * @param pins An array of pins to connect to bus bit
00068      */
00069      BusIn(PinName pins[16]);
00070 
00071     virtual ~BusIn();
00072 
00073     /** Read the value of the input bus
00074      *
00075      *  @returns
00076      *   An integer with each bit corresponding to the value read from the associated DigitalIn pin
00077      */
00078     int read();
00079 
00080     /** Set the input pin mode
00081      *
00082      *  @param pull PullUp, PullDown, PullNone
00083      */
00084     void mode(PinMode pull);
00085 
00086     /** Binary mask of bus pins connected to actual pins (not NC pins)
00087      *  If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
00088      *
00089      *  @returns
00090      *    Binary mask of connected pins
00091      */
00092     int mask() {
00093         // No lock needed since _nc_mask is not modified outside the constructor
00094         return _nc_mask;
00095     }
00096 
00097     /** A shorthand for read()
00098      */
00099     operator int();
00100 
00101     /** Access to particular bit in random-iterator fashion
00102      */
00103     DigitalIn & operator[] (int index);
00104 
00105 protected:
00106     DigitalIn* _pin[16];
00107 
00108     /* Mask of bus's NC pins
00109      * If bit[n] is set to 1 - pin is connected
00110      * if bit[n] is cleared - pin is not connected (NC)
00111      */
00112     int _nc_mask;
00113 
00114     PlatformMutex _mutex;
00115 
00116     /* disallow copy constructor and assignment operators */
00117 private:
00118     virtual void lock();
00119     virtual void unlock();
00120     BusIn(const BusIn&);
00121     BusIn & operator = (const BusIn&);
00122 };
00123 
00124 } // namespace mbed
00125 
00126 #endif
00127 
00128