test

Dependencies:   mbed Watchdog

Dependents:   STM32-MC_node

Committer:
ommpy
Date:
Mon Jul 06 17:18:59 2020 +0530
Revision:
0:d383e2dee0f7
first commit

Who changed what in which revision?

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