mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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