Theo/Ludo/Joe / ER2_Labyrinthe_V3

Dependencies:   mbed

Committer:
joehatier
Date:
Mon Jun 24 12:37:09 2019 +0000
Revision:
4:31025db8e579
Parent:
0:1a801a2a7b4b
laby;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joehatier 0:1a801a2a7b4b 1 /* mbed Microcontroller Library
joehatier 0:1a801a2a7b4b 2 * Copyright (c) 2006-2013 ARM Limited
joehatier 0:1a801a2a7b4b 3 *
joehatier 0:1a801a2a7b4b 4 * Licensed under the Apache License, Version 2.0 (the "License");
joehatier 0:1a801a2a7b4b 5 * you may not use this file except in compliance with the License.
joehatier 0:1a801a2a7b4b 6 * You may obtain a copy of the License at
joehatier 0:1a801a2a7b4b 7 *
joehatier 0:1a801a2a7b4b 8 * http://www.apache.org/licenses/LICENSE-2.0
joehatier 0:1a801a2a7b4b 9 *
joehatier 0:1a801a2a7b4b 10 * Unless required by applicable law or agreed to in writing, software
joehatier 0:1a801a2a7b4b 11 * distributed under the License is distributed on an "AS IS" BASIS,
joehatier 0:1a801a2a7b4b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
joehatier 0:1a801a2a7b4b 13 * See the License for the specific language governing permissions and
joehatier 0:1a801a2a7b4b 14 * limitations under the License.
joehatier 0:1a801a2a7b4b 15 */
joehatier 0:1a801a2a7b4b 16 #ifndef MBED_BUSOUT_H
joehatier 0:1a801a2a7b4b 17 #define MBED_BUSOUT_H
joehatier 0:1a801a2a7b4b 18
joehatier 0:1a801a2a7b4b 19 #include "drivers/DigitalOut.h"
joehatier 0:1a801a2a7b4b 20 #include "platform/PlatformMutex.h"
joehatier 0:1a801a2a7b4b 21 #include "platform/NonCopyable.h"
joehatier 0:1a801a2a7b4b 22
joehatier 0:1a801a2a7b4b 23 namespace mbed {
joehatier 0:1a801a2a7b4b 24 /** \addtogroup drivers */
joehatier 0:1a801a2a7b4b 25
joehatier 0:1a801a2a7b4b 26 /** A digital output bus, used for setting the state of a collection of pins
joehatier 0:1a801a2a7b4b 27 * @ingroup drivers
joehatier 0:1a801a2a7b4b 28 */
joehatier 0:1a801a2a7b4b 29 class BusOut : private NonCopyable<BusOut> {
joehatier 0:1a801a2a7b4b 30
joehatier 0:1a801a2a7b4b 31 public:
joehatier 0:1a801a2a7b4b 32
joehatier 0:1a801a2a7b4b 33 /** Create an BusOut, connected to the specified pins
joehatier 0:1a801a2a7b4b 34 *
joehatier 0:1a801a2a7b4b 35 * @param p0 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 36 * @param p1 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 37 * @param p2 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 38 * @param p3 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 39 * @param p4 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 40 * @param p5 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 41 * @param p6 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 42 * @param p7 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 43 * @param p8 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 44 * @param p9 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 45 * @param p10 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 46 * @param p11 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 47 * @param p12 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 48 * @param p13 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 49 * @param p14 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 50 * @param p15 DigitalOut pin to connect to bus bit
joehatier 0:1a801a2a7b4b 51 *
joehatier 0:1a801a2a7b4b 52 * @note Synchronization level: Thread safe
joehatier 0:1a801a2a7b4b 53 *
joehatier 0:1a801a2a7b4b 54 * @note
joehatier 0:1a801a2a7b4b 55 * It is only required to specify as many pin variables as is required
joehatier 0:1a801a2a7b4b 56 * for the bus; the rest will default to NC (not connected)
joehatier 0:1a801a2a7b4b 57 */
joehatier 0:1a801a2a7b4b 58 BusOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
joehatier 0:1a801a2a7b4b 59 PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
joehatier 0:1a801a2a7b4b 60 PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
joehatier 0:1a801a2a7b4b 61 PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
joehatier 0:1a801a2a7b4b 62
joehatier 0:1a801a2a7b4b 63 /** Create an BusOut, connected to the specified pins
joehatier 0:1a801a2a7b4b 64 *
joehatier 0:1a801a2a7b4b 65 * @param pins An array of pins to connect to bus the bit
joehatier 0:1a801a2a7b4b 66 */
joehatier 0:1a801a2a7b4b 67 BusOut(PinName pins[16]);
joehatier 0:1a801a2a7b4b 68
joehatier 0:1a801a2a7b4b 69 virtual ~BusOut();
joehatier 0:1a801a2a7b4b 70
joehatier 0:1a801a2a7b4b 71 /** Write the value to the output bus
joehatier 0:1a801a2a7b4b 72 *
joehatier 0:1a801a2a7b4b 73 * @param value An integer specifying a bit to write for every corresponding DigitalOut pin
joehatier 0:1a801a2a7b4b 74 */
joehatier 0:1a801a2a7b4b 75 void write(int value);
joehatier 0:1a801a2a7b4b 76
joehatier 0:1a801a2a7b4b 77 /** Read the value currently output on the bus
joehatier 0:1a801a2a7b4b 78 *
joehatier 0:1a801a2a7b4b 79 * @returns
joehatier 0:1a801a2a7b4b 80 * An integer with each bit corresponding to associated DigitalOut pin setting
joehatier 0:1a801a2a7b4b 81 */
joehatier 0:1a801a2a7b4b 82 int read();
joehatier 0:1a801a2a7b4b 83
joehatier 0:1a801a2a7b4b 84 /** Binary mask of bus pins connected to actual pins (not NC pins)
joehatier 0:1a801a2a7b4b 85 * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
joehatier 0:1a801a2a7b4b 86 *
joehatier 0:1a801a2a7b4b 87 * @returns
joehatier 0:1a801a2a7b4b 88 * Binary mask of connected pins
joehatier 0:1a801a2a7b4b 89 */
joehatier 0:1a801a2a7b4b 90 int mask()
joehatier 0:1a801a2a7b4b 91 {
joehatier 0:1a801a2a7b4b 92 // No lock needed since _nc_mask is not modified outside the constructor
joehatier 0:1a801a2a7b4b 93 return _nc_mask;
joehatier 0:1a801a2a7b4b 94 }
joehatier 0:1a801a2a7b4b 95
joehatier 0:1a801a2a7b4b 96 /** A shorthand for write()
joehatier 0:1a801a2a7b4b 97 * \sa BusOut::write()
joehatier 0:1a801a2a7b4b 98 */
joehatier 0:1a801a2a7b4b 99 BusOut &operator= (int v);
joehatier 0:1a801a2a7b4b 100 BusOut &operator= (BusOut &rhs);
joehatier 0:1a801a2a7b4b 101
joehatier 0:1a801a2a7b4b 102 /** Access to particular bit in random-iterator fashion
joehatier 0:1a801a2a7b4b 103 * @param index Bit Position
joehatier 0:1a801a2a7b4b 104 */
joehatier 0:1a801a2a7b4b 105 DigitalOut &operator[](int index);
joehatier 0:1a801a2a7b4b 106
joehatier 0:1a801a2a7b4b 107 /** A shorthand for read()
joehatier 0:1a801a2a7b4b 108 * \sa BusOut::read()
joehatier 0:1a801a2a7b4b 109 */
joehatier 0:1a801a2a7b4b 110 operator int();
joehatier 0:1a801a2a7b4b 111
joehatier 0:1a801a2a7b4b 112 protected:
joehatier 0:1a801a2a7b4b 113 virtual void lock();
joehatier 0:1a801a2a7b4b 114 virtual void unlock();
joehatier 0:1a801a2a7b4b 115 DigitalOut *_pin[16];
joehatier 0:1a801a2a7b4b 116
joehatier 0:1a801a2a7b4b 117 /* Mask of bus's NC pins
joehatier 0:1a801a2a7b4b 118 * If bit[n] is set to 1 - pin is connected
joehatier 0:1a801a2a7b4b 119 * if bit[n] is cleared - pin is not connected (NC)
joehatier 0:1a801a2a7b4b 120 */
joehatier 0:1a801a2a7b4b 121 int _nc_mask;
joehatier 0:1a801a2a7b4b 122
joehatier 0:1a801a2a7b4b 123 PlatformMutex _mutex;
joehatier 0:1a801a2a7b4b 124 };
joehatier 0:1a801a2a7b4b 125
joehatier 0:1a801a2a7b4b 126 } // namespace mbed
joehatier 0:1a801a2a7b4b 127
joehatier 0:1a801a2a7b4b 128 #endif