mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Thu Nov 08 11:46:34 2018 +0000
Revision:
188:bcfe06ba3d64
Parent:
187:0387e8f68319
Child:
189:f392fc9709a3
mbed-dev library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /* mbed Microcontroller Library
<> 149:156823d33999 2 * Copyright (c) 2006-2013 ARM Limited
<> 149:156823d33999 3 *
<> 149:156823d33999 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 149:156823d33999 5 * you may not use this file except in compliance with the License.
<> 149:156823d33999 6 * You may obtain a copy of the License at
<> 149:156823d33999 7 *
<> 149:156823d33999 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 149:156823d33999 9 *
<> 149:156823d33999 10 * Unless required by applicable law or agreed to in writing, software
<> 149:156823d33999 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 149:156823d33999 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 149:156823d33999 13 * See the License for the specific language governing permissions and
<> 149:156823d33999 14 * limitations under the License.
<> 149:156823d33999 15 */
<> 149:156823d33999 16 #ifndef MBED_PORTIN_H
<> 149:156823d33999 17 #define MBED_PORTIN_H
<> 149:156823d33999 18
<> 149:156823d33999 19 #include "platform/platform.h"
<> 149:156823d33999 20
AnnaBridge 167:e84263d55307 21 #if defined (DEVICE_PORTIN) || defined(DOXYGEN_ONLY)
<> 149:156823d33999 22
<> 149:156823d33999 23 #include "hal/port_api.h"
<> 160:d5399cc887bb 24 #include "platform/mbed_critical.h"
<> 149:156823d33999 25
<> 149:156823d33999 26 namespace mbed {
<> 149:156823d33999 27 /** \addtogroup drivers */
<> 149:156823d33999 28
<> 149:156823d33999 29 /** A multiple pin digital input
<> 149:156823d33999 30 *
AnnaBridge 167:e84263d55307 31 * @note Synchronization level: Interrupt safe
<> 149:156823d33999 32 *
<> 149:156823d33999 33 * Example:
<> 149:156823d33999 34 * @code
AnnaBridge 188:bcfe06ba3d64 35 * // Turn on an LED if any pins of Port2[0:5] are high
<> 149:156823d33999 36 *
<> 149:156823d33999 37 * #include "mbed.h"
<> 149:156823d33999 38 *
AnnaBridge 188:bcfe06ba3d64 39 * PortIn p(Port2, 0x0000003F); // Port2 pins [0:5] only
AnnaBridge 188:bcfe06ba3d64 40 * DigitalOut led(LED4);
<> 149:156823d33999 41 *
<> 149:156823d33999 42 * int main() {
<> 149:156823d33999 43 * while(1) {
<> 149:156823d33999 44 * int pins = p.read();
<> 149:156823d33999 45 * if(pins) {
AnnaBridge 188:bcfe06ba3d64 46 * led = 1;
<> 149:156823d33999 47 * } else {
AnnaBridge 188:bcfe06ba3d64 48 * led = 0;
<> 149:156823d33999 49 * }
<> 149:156823d33999 50 * }
<> 149:156823d33999 51 * }
<> 149:156823d33999 52 * @endcode
AnnaBridge 167:e84263d55307 53 * @ingroup drivers
<> 149:156823d33999 54 */
<> 149:156823d33999 55 class PortIn {
<> 149:156823d33999 56 public:
<> 149:156823d33999 57
AnnaBridge 188:bcfe06ba3d64 58 /** Create a PortIn, connected to the specified port
<> 149:156823d33999 59 *
AnnaBridge 188:bcfe06ba3d64 60 * @param port Port to connect to (as defined in target's PortNames.h)
AnnaBridge 188:bcfe06ba3d64 61 * @param mask Bitmask defines which port pins should be an input (0 - ignore, 1 - include)
<> 149:156823d33999 62 */
AnnaBridge 187:0387e8f68319 63 PortIn(PortName port, int mask = 0xFFFFFFFF)
AnnaBridge 187:0387e8f68319 64 {
<> 149:156823d33999 65 core_util_critical_section_enter();
<> 149:156823d33999 66 port_init(&_port, port, mask, PIN_INPUT);
<> 149:156823d33999 67 core_util_critical_section_exit();
<> 149:156823d33999 68 }
<> 149:156823d33999 69
AnnaBridge 188:bcfe06ba3d64 70 /** Read the value input to the port
<> 149:156823d33999 71 *
<> 149:156823d33999 72 * @returns
AnnaBridge 188:bcfe06ba3d64 73 * An integer with each bit corresponding to the associated pin value
<> 149:156823d33999 74 */
AnnaBridge 187:0387e8f68319 75 int read()
AnnaBridge 187:0387e8f68319 76 {
<> 149:156823d33999 77 return port_read(&_port);
<> 149:156823d33999 78 }
<> 149:156823d33999 79
<> 149:156823d33999 80 /** Set the input pin mode
<> 149:156823d33999 81 *
<> 149:156823d33999 82 * @param mode PullUp, PullDown, PullNone, OpenDrain
<> 149:156823d33999 83 */
AnnaBridge 187:0387e8f68319 84 void mode(PinMode mode)
AnnaBridge 187:0387e8f68319 85 {
<> 149:156823d33999 86 core_util_critical_section_enter();
<> 149:156823d33999 87 port_mode(&_port, mode);
<> 149:156823d33999 88 core_util_critical_section_exit();
<> 149:156823d33999 89 }
<> 149:156823d33999 90
<> 149:156823d33999 91 /** A shorthand for read()
<> 149:156823d33999 92 */
AnnaBridge 187:0387e8f68319 93 operator int()
AnnaBridge 187:0387e8f68319 94 {
<> 149:156823d33999 95 return read();
<> 149:156823d33999 96 }
<> 149:156823d33999 97
<> 149:156823d33999 98 private:
<> 149:156823d33999 99 port_t _port;
<> 149:156823d33999 100 };
<> 149:156823d33999 101
<> 149:156823d33999 102 } // namespace mbed
<> 149:156823d33999 103
<> 149:156823d33999 104 #endif
<> 149:156823d33999 105
<> 149:156823d33999 106 #endif