this hurts

Dependencies:   FFT

Committer:
annieluo2
Date:
Wed Dec 02 18:02:03 2020 +0000
Revision:
0:d6c9b09b4042
boo

Who changed what in which revision?

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