help :(

Dependencies:   FFT

Committer:
dimitryjl23
Date:
Fri Dec 04 18:01:22 2020 +0000
Revision:
11:951bbb0385aa
Parent:
0:d6c9b09b4042
Final :)

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