Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Dec 16 16:27:57 2016 +0000
Revision:
3:1198227e6421
Parent:
0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms

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_PORTINOUT_H
switches 0:5c4d7b2438d3 17 #define MBED_PORTINOUT_H
switches 0:5c4d7b2438d3 18
switches 0:5c4d7b2438d3 19 #include "platform/platform.h"
switches 0:5c4d7b2438d3 20
switches 0:5c4d7b2438d3 21 #if DEVICE_PORTINOUT
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 in/out used to set/read multiple bi-directional pins
switches 0:5c4d7b2438d3 31 *
switches 0:5c4d7b2438d3 32 * @Note Synchronization level: Interrupt safe
switches 0:5c4d7b2438d3 33 */
switches 0:5c4d7b2438d3 34 class PortInOut {
switches 0:5c4d7b2438d3 35 public:
switches 0:5c4d7b2438d3 36
switches 0:5c4d7b2438d3 37 /** Create an PortInOut, connected to the specified port
switches 0:5c4d7b2438d3 38 *
switches 0:5c4d7b2438d3 39 * @param port Port to connect to (Port0-Port5)
switches 0:5c4d7b2438d3 40 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
switches 0:5c4d7b2438d3 41 */
switches 0:5c4d7b2438d3 42 PortInOut(PortName port, int mask = 0xFFFFFFFF) {
switches 0:5c4d7b2438d3 43 core_util_critical_section_enter();
switches 0:5c4d7b2438d3 44 port_init(&_port, port, mask, PIN_INPUT);
switches 0:5c4d7b2438d3 45 core_util_critical_section_exit();
switches 0:5c4d7b2438d3 46 }
switches 0:5c4d7b2438d3 47
switches 0:5c4d7b2438d3 48 /** Write the value to the output port
switches 0:5c4d7b2438d3 49 *
switches 0:5c4d7b2438d3 50 * @param value An integer specifying a bit to write for every corresponding port pin
switches 0:5c4d7b2438d3 51 */
switches 0:5c4d7b2438d3 52 void write(int value) {
switches 0:5c4d7b2438d3 53 port_write(&_port, value);
switches 0:5c4d7b2438d3 54 }
switches 0:5c4d7b2438d3 55
switches 0:5c4d7b2438d3 56 /** Read the value currently output on the port
switches 0:5c4d7b2438d3 57 *
switches 0:5c4d7b2438d3 58 * @returns
switches 0:5c4d7b2438d3 59 * An integer with each bit corresponding to associated port pin setting
switches 0:5c4d7b2438d3 60 */
switches 0:5c4d7b2438d3 61 int read() {
switches 0:5c4d7b2438d3 62 return port_read(&_port);
switches 0:5c4d7b2438d3 63 }
switches 0:5c4d7b2438d3 64
switches 0:5c4d7b2438d3 65 /** Set as an output
switches 0:5c4d7b2438d3 66 */
switches 0:5c4d7b2438d3 67 void output() {
switches 0:5c4d7b2438d3 68 core_util_critical_section_enter();
switches 0:5c4d7b2438d3 69 port_dir(&_port, PIN_OUTPUT);
switches 0:5c4d7b2438d3 70 core_util_critical_section_exit();
switches 0:5c4d7b2438d3 71 }
switches 0:5c4d7b2438d3 72
switches 0:5c4d7b2438d3 73 /** Set as an input
switches 0:5c4d7b2438d3 74 */
switches 0:5c4d7b2438d3 75 void input() {
switches 0:5c4d7b2438d3 76 core_util_critical_section_enter();
switches 0:5c4d7b2438d3 77 port_dir(&_port, PIN_INPUT);
switches 0:5c4d7b2438d3 78 core_util_critical_section_exit();
switches 0:5c4d7b2438d3 79 }
switches 0:5c4d7b2438d3 80
switches 0:5c4d7b2438d3 81 /** Set the input pin mode
switches 0:5c4d7b2438d3 82 *
switches 0:5c4d7b2438d3 83 * @param mode PullUp, PullDown, PullNone, OpenDrain
switches 0:5c4d7b2438d3 84 */
switches 0:5c4d7b2438d3 85 void mode(PinMode mode) {
switches 0:5c4d7b2438d3 86 core_util_critical_section_enter();
switches 0:5c4d7b2438d3 87 port_mode(&_port, mode);
switches 0:5c4d7b2438d3 88 core_util_critical_section_exit();
switches 0:5c4d7b2438d3 89 }
switches 0:5c4d7b2438d3 90
switches 0:5c4d7b2438d3 91 /** A shorthand for write()
switches 0:5c4d7b2438d3 92 */
switches 0:5c4d7b2438d3 93 PortInOut& operator= (int value) {
switches 0:5c4d7b2438d3 94 write(value);
switches 0:5c4d7b2438d3 95 return *this;
switches 0:5c4d7b2438d3 96 }
switches 0:5c4d7b2438d3 97
switches 0:5c4d7b2438d3 98 PortInOut& operator= (PortInOut& rhs) {
switches 0:5c4d7b2438d3 99 write(rhs.read());
switches 0:5c4d7b2438d3 100 return *this;
switches 0:5c4d7b2438d3 101 }
switches 0:5c4d7b2438d3 102
switches 0:5c4d7b2438d3 103 /** A shorthand for read()
switches 0:5c4d7b2438d3 104 */
switches 0:5c4d7b2438d3 105 operator int() {
switches 0:5c4d7b2438d3 106 return read();
switches 0:5c4d7b2438d3 107 }
switches 0:5c4d7b2438d3 108
switches 0:5c4d7b2438d3 109 private:
switches 0:5c4d7b2438d3 110 port_t _port;
switches 0:5c4d7b2438d3 111 };
switches 0:5c4d7b2438d3 112
switches 0:5c4d7b2438d3 113 } // namespace mbed
switches 0:5c4d7b2438d3 114
switches 0:5c4d7b2438d3 115 #endif
switches 0:5c4d7b2438d3 116
switches 0:5c4d7b2438d3 117 #endif
switches 0:5c4d7b2438d3 118
switches 0:5c4d7b2438d3 119 /** @}*/