CDY version that shares functionality with Counter

Dependencies:   SDFileSystem_HelloWorld mbed FATFileSystem

Committer:
Charles David Young
Date:
Mon Nov 05 09:52:17 2018 -0700
Revision:
3:c547dba5d39b
Parent:
0:aa13e1c335cd
debug

Who changed what in which revision?

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