Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

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