Development mbed library for MAX32630FTHR
Dependents: blinky_max32630fthr
drivers/PortOut.h@0:5c4d7b2438d3, 2016-11-11 (annotated)
- Committer:
- switches
- Date:
- Fri Nov 11 20:59:50 2016 +0000
- Revision:
- 0:5c4d7b2438d3
Initial commit
Who changed what in which revision?
User | Revision | Line number | New 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_PORTOUT_H |
switches | 0:5c4d7b2438d3 | 17 | #define MBED_PORTOUT_H |
switches | 0:5c4d7b2438d3 | 18 | |
switches | 0:5c4d7b2438d3 | 19 | #include "platform/platform.h" |
switches | 0:5c4d7b2438d3 | 20 | |
switches | 0:5c4d7b2438d3 | 21 | #if DEVICE_PORTOUT |
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 | /** A multiple pin digital out |
switches | 0:5c4d7b2438d3 | 30 | * |
switches | 0:5c4d7b2438d3 | 31 | * @Note Synchronization level: Interrupt safe |
switches | 0:5c4d7b2438d3 | 32 | * |
switches | 0:5c4d7b2438d3 | 33 | * Example: |
switches | 0:5c4d7b2438d3 | 34 | * @code |
switches | 0:5c4d7b2438d3 | 35 | * // Toggle all four LEDs |
switches | 0:5c4d7b2438d3 | 36 | * |
switches | 0:5c4d7b2438d3 | 37 | * #include "mbed.h" |
switches | 0:5c4d7b2438d3 | 38 | * |
switches | 0:5c4d7b2438d3 | 39 | * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23 |
switches | 0:5c4d7b2438d3 | 40 | * #define LED_MASK 0x00B40000 |
switches | 0:5c4d7b2438d3 | 41 | * |
switches | 0:5c4d7b2438d3 | 42 | * PortOut ledport(Port1, LED_MASK); |
switches | 0:5c4d7b2438d3 | 43 | * |
switches | 0:5c4d7b2438d3 | 44 | * int main() { |
switches | 0:5c4d7b2438d3 | 45 | * while(1) { |
switches | 0:5c4d7b2438d3 | 46 | * ledport = LED_MASK; |
switches | 0:5c4d7b2438d3 | 47 | * wait(1); |
switches | 0:5c4d7b2438d3 | 48 | * ledport = 0; |
switches | 0:5c4d7b2438d3 | 49 | * wait(1); |
switches | 0:5c4d7b2438d3 | 50 | * } |
switches | 0:5c4d7b2438d3 | 51 | * } |
switches | 0:5c4d7b2438d3 | 52 | * @endcode |
switches | 0:5c4d7b2438d3 | 53 | */ |
switches | 0:5c4d7b2438d3 | 54 | class PortOut { |
switches | 0:5c4d7b2438d3 | 55 | public: |
switches | 0:5c4d7b2438d3 | 56 | |
switches | 0:5c4d7b2438d3 | 57 | /** Create an PortOut, connected to the specified port |
switches | 0:5c4d7b2438d3 | 58 | * |
switches | 0:5c4d7b2438d3 | 59 | * @param port Port to connect to (Port0-Port5) |
switches | 0:5c4d7b2438d3 | 60 | * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) |
switches | 0:5c4d7b2438d3 | 61 | */ |
switches | 0:5c4d7b2438d3 | 62 | PortOut(PortName port, int mask = 0xFFFFFFFF) { |
switches | 0:5c4d7b2438d3 | 63 | core_util_critical_section_enter(); |
switches | 0:5c4d7b2438d3 | 64 | port_init(&_port, port, mask, PIN_OUTPUT); |
switches | 0:5c4d7b2438d3 | 65 | core_util_critical_section_exit(); |
switches | 0:5c4d7b2438d3 | 66 | } |
switches | 0:5c4d7b2438d3 | 67 | |
switches | 0:5c4d7b2438d3 | 68 | /** Write the value to the output port |
switches | 0:5c4d7b2438d3 | 69 | * |
switches | 0:5c4d7b2438d3 | 70 | * @param value An integer specifying a bit to write for every corresponding PortOut pin |
switches | 0:5c4d7b2438d3 | 71 | */ |
switches | 0:5c4d7b2438d3 | 72 | void write(int value) { |
switches | 0:5c4d7b2438d3 | 73 | port_write(&_port, value); |
switches | 0:5c4d7b2438d3 | 74 | } |
switches | 0:5c4d7b2438d3 | 75 | |
switches | 0:5c4d7b2438d3 | 76 | /** Read the value currently output on the port |
switches | 0:5c4d7b2438d3 | 77 | * |
switches | 0:5c4d7b2438d3 | 78 | * @returns |
switches | 0:5c4d7b2438d3 | 79 | * An integer with each bit corresponding to associated PortOut pin setting |
switches | 0:5c4d7b2438d3 | 80 | */ |
switches | 0:5c4d7b2438d3 | 81 | int read() { |
switches | 0:5c4d7b2438d3 | 82 | return port_read(&_port); |
switches | 0:5c4d7b2438d3 | 83 | } |
switches | 0:5c4d7b2438d3 | 84 | |
switches | 0:5c4d7b2438d3 | 85 | /** A shorthand for write() |
switches | 0:5c4d7b2438d3 | 86 | */ |
switches | 0:5c4d7b2438d3 | 87 | PortOut& operator= (int value) { |
switches | 0:5c4d7b2438d3 | 88 | write(value); |
switches | 0:5c4d7b2438d3 | 89 | return *this; |
switches | 0:5c4d7b2438d3 | 90 | } |
switches | 0:5c4d7b2438d3 | 91 | |
switches | 0:5c4d7b2438d3 | 92 | PortOut& operator= (PortOut& rhs) { |
switches | 0:5c4d7b2438d3 | 93 | write(rhs.read()); |
switches | 0:5c4d7b2438d3 | 94 | return *this; |
switches | 0:5c4d7b2438d3 | 95 | } |
switches | 0:5c4d7b2438d3 | 96 | |
switches | 0:5c4d7b2438d3 | 97 | /** A shorthand for read() |
switches | 0:5c4d7b2438d3 | 98 | */ |
switches | 0:5c4d7b2438d3 | 99 | operator int() { |
switches | 0:5c4d7b2438d3 | 100 | return read(); |
switches | 0:5c4d7b2438d3 | 101 | } |
switches | 0:5c4d7b2438d3 | 102 | |
switches | 0:5c4d7b2438d3 | 103 | private: |
switches | 0:5c4d7b2438d3 | 104 | port_t _port; |
switches | 0:5c4d7b2438d3 | 105 | }; |
switches | 0:5c4d7b2438d3 | 106 | |
switches | 0:5c4d7b2438d3 | 107 | } // namespace mbed |
switches | 0:5c4d7b2438d3 | 108 | |
switches | 0:5c4d7b2438d3 | 109 | #endif |
switches | 0:5c4d7b2438d3 | 110 | |
switches | 0:5c4d7b2438d3 | 111 | #endif |
switches | 0:5c4d7b2438d3 | 112 | |
switches | 0:5c4d7b2438d3 | 113 | /** @}*/ |