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