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_BUSIN_H
Charles David Young 0:aa13e1c335cd 17 #define MBED_BUSIN_H
Charles David Young 0:aa13e1c335cd 18
Charles David Young 0:aa13e1c335cd 19 #include "platform/platform.h"
Charles David Young 0:aa13e1c335cd 20 #include "drivers/DigitalIn.h"
Charles David Young 0:aa13e1c335cd 21 #include "platform/PlatformMutex.h"
Charles David Young 0:aa13e1c335cd 22
Charles David Young 0:aa13e1c335cd 23 namespace mbed {
Charles David Young 0:aa13e1c335cd 24 /** \addtogroup drivers */
Charles David Young 0:aa13e1c335cd 25 /** @{*/
Charles David Young 0:aa13e1c335cd 26
Charles David Young 0:aa13e1c335cd 27 /** A digital input bus, used for reading the state of a collection of pins
Charles David Young 0:aa13e1c335cd 28 *
Charles David Young 0:aa13e1c335cd 29 * @Note Synchronization level: Thread safe
Charles David Young 0:aa13e1c335cd 30 */
Charles David Young 0:aa13e1c335cd 31 class BusIn {
Charles David Young 0:aa13e1c335cd 32
Charles David Young 0:aa13e1c335cd 33 public:
Charles David Young 0:aa13e1c335cd 34 /* Group: Configuration Methods */
Charles David Young 0:aa13e1c335cd 35
Charles David Young 0:aa13e1c335cd 36 /** Create an BusIn, connected to the specified pins
Charles David Young 0:aa13e1c335cd 37 *
Charles David Young 0:aa13e1c335cd 38 * @param <n> DigitalIn pin to connect to bus bit <n> (p5-p30, NC)
Charles David Young 0:aa13e1c335cd 39 *
Charles David Young 0:aa13e1c335cd 40 * @note
Charles David Young 0:aa13e1c335cd 41 * It is only required to specify as many pin variables as is required
Charles David Young 0:aa13e1c335cd 42 * for the bus; the rest will default to NC (not connected)
Charles David Young 0:aa13e1c335cd 43 */
Charles David Young 0:aa13e1c335cd 44 BusIn(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
Charles David Young 0:aa13e1c335cd 45 PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
Charles David Young 0:aa13e1c335cd 46 PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
Charles David Young 0:aa13e1c335cd 47 PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
Charles David Young 0:aa13e1c335cd 48
Charles David Young 0:aa13e1c335cd 49 BusIn(PinName pins[16]);
Charles David Young 0:aa13e1c335cd 50
Charles David Young 0:aa13e1c335cd 51 virtual ~BusIn();
Charles David Young 0:aa13e1c335cd 52
Charles David Young 0:aa13e1c335cd 53 /** Read the value of the input bus
Charles David Young 0:aa13e1c335cd 54 *
Charles David Young 0:aa13e1c335cd 55 * @returns
Charles David Young 0:aa13e1c335cd 56 * An integer with each bit corresponding to the value read from the associated DigitalIn pin
Charles David Young 0:aa13e1c335cd 57 */
Charles David Young 0:aa13e1c335cd 58 int read();
Charles David Young 0:aa13e1c335cd 59
Charles David Young 0:aa13e1c335cd 60 /** Set the input pin mode
Charles David Young 0:aa13e1c335cd 61 *
Charles David Young 0:aa13e1c335cd 62 * @param mode PullUp, PullDown, PullNone
Charles David Young 0:aa13e1c335cd 63 */
Charles David Young 0:aa13e1c335cd 64 void mode(PinMode pull);
Charles David Young 0:aa13e1c335cd 65
Charles David Young 0:aa13e1c335cd 66 /** Binary mask of bus pins connected to actual pins (not NC pins)
Charles David Young 0:aa13e1c335cd 67 * 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 68 *
Charles David Young 0:aa13e1c335cd 69 * @returns
Charles David Young 0:aa13e1c335cd 70 * Binary mask of connected pins
Charles David Young 0:aa13e1c335cd 71 */
Charles David Young 0:aa13e1c335cd 72 int mask() {
Charles David Young 0:aa13e1c335cd 73 // No lock needed since _nc_mask is not modified outside the constructor
Charles David Young 0:aa13e1c335cd 74 return _nc_mask;
Charles David Young 0:aa13e1c335cd 75 }
Charles David Young 0:aa13e1c335cd 76
Charles David Young 0:aa13e1c335cd 77 /** A shorthand for read()
Charles David Young 0:aa13e1c335cd 78 */
Charles David Young 0:aa13e1c335cd 79 operator int();
Charles David Young 0:aa13e1c335cd 80
Charles David Young 0:aa13e1c335cd 81 /** Access to particular bit in random-iterator fashion
Charles David Young 0:aa13e1c335cd 82 */
Charles David Young 0:aa13e1c335cd 83 DigitalIn & operator[] (int index);
Charles David Young 0:aa13e1c335cd 84
Charles David Young 0:aa13e1c335cd 85 protected:
Charles David Young 0:aa13e1c335cd 86 DigitalIn* _pin[16];
Charles David Young 0:aa13e1c335cd 87
Charles David Young 0:aa13e1c335cd 88 /** Mask of bus's NC pins
Charles David Young 0:aa13e1c335cd 89 * If bit[n] is set to 1 - pin is connected
Charles David Young 0:aa13e1c335cd 90 * if bit[n] is cleared - pin is not connected (NC)
Charles David Young 0:aa13e1c335cd 91 */
Charles David Young 0:aa13e1c335cd 92 int _nc_mask;
Charles David Young 0:aa13e1c335cd 93
Charles David Young 0:aa13e1c335cd 94 PlatformMutex _mutex;
Charles David Young 0:aa13e1c335cd 95
Charles David Young 0:aa13e1c335cd 96 /* disallow copy constructor and assignment operators */
Charles David Young 0:aa13e1c335cd 97 private:
Charles David Young 0:aa13e1c335cd 98 virtual void lock();
Charles David Young 0:aa13e1c335cd 99 virtual void unlock();
Charles David Young 0:aa13e1c335cd 100 BusIn(const BusIn&);
Charles David Young 0:aa13e1c335cd 101 BusIn & operator = (const BusIn&);
Charles David Young 0:aa13e1c335cd 102 };
Charles David Young 0:aa13e1c335cd 103
Charles David Young 0:aa13e1c335cd 104 } // namespace mbed
Charles David Young 0:aa13e1c335cd 105
Charles David Young 0:aa13e1c335cd 106 #endif
Charles David Young 0:aa13e1c335cd 107
Charles David Young 0:aa13e1c335cd 108 /** @}*/