Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Nov 11 20:59:50 2016 +0000
Revision:
0:5c4d7b2438d3
Initial commit

Who changed what in which revision?

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