mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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