the do / gr-peach-opencv-project

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BusOut.h Source File

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