Includes library modifications to allow access to AIN_4 (AIN_0 / 5)
mbd_os/hal/api/PortOut.h@0:eafc3fd41f75, 2016-09-20 (annotated)
- Committer:
- bryantaylor
- Date:
- Tue Sep 20 21:26:12 2016 +0000
- Revision:
- 0:eafc3fd41f75
hackathon
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bryantaylor | 0:eafc3fd41f75 | 1 | /* mbed Microcontroller Library |
bryantaylor | 0:eafc3fd41f75 | 2 | * Copyright (c) 2006-2013 ARM Limited |
bryantaylor | 0:eafc3fd41f75 | 3 | * |
bryantaylor | 0:eafc3fd41f75 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
bryantaylor | 0:eafc3fd41f75 | 5 | * you may not use this file except in compliance with the License. |
bryantaylor | 0:eafc3fd41f75 | 6 | * You may obtain a copy of the License at |
bryantaylor | 0:eafc3fd41f75 | 7 | * |
bryantaylor | 0:eafc3fd41f75 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
bryantaylor | 0:eafc3fd41f75 | 9 | * |
bryantaylor | 0:eafc3fd41f75 | 10 | * Unless required by applicable law or agreed to in writing, software |
bryantaylor | 0:eafc3fd41f75 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
bryantaylor | 0:eafc3fd41f75 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bryantaylor | 0:eafc3fd41f75 | 13 | * See the License for the specific language governing permissions and |
bryantaylor | 0:eafc3fd41f75 | 14 | * limitations under the License. |
bryantaylor | 0:eafc3fd41f75 | 15 | */ |
bryantaylor | 0:eafc3fd41f75 | 16 | #ifndef MBED_PORTOUT_H |
bryantaylor | 0:eafc3fd41f75 | 17 | #define MBED_PORTOUT_H |
bryantaylor | 0:eafc3fd41f75 | 18 | |
bryantaylor | 0:eafc3fd41f75 | 19 | #include "platform.h" |
bryantaylor | 0:eafc3fd41f75 | 20 | |
bryantaylor | 0:eafc3fd41f75 | 21 | #if DEVICE_PORTOUT |
bryantaylor | 0:eafc3fd41f75 | 22 | |
bryantaylor | 0:eafc3fd41f75 | 23 | #include "port_api.h" |
bryantaylor | 0:eafc3fd41f75 | 24 | #include "critical.h" |
bryantaylor | 0:eafc3fd41f75 | 25 | |
bryantaylor | 0:eafc3fd41f75 | 26 | namespace mbed { |
bryantaylor | 0:eafc3fd41f75 | 27 | /** A multiple pin digital out |
bryantaylor | 0:eafc3fd41f75 | 28 | * |
bryantaylor | 0:eafc3fd41f75 | 29 | * @Note Synchronization level: Interrupt safe |
bryantaylor | 0:eafc3fd41f75 | 30 | * |
bryantaylor | 0:eafc3fd41f75 | 31 | * Example: |
bryantaylor | 0:eafc3fd41f75 | 32 | * @code |
bryantaylor | 0:eafc3fd41f75 | 33 | * // Toggle all four LEDs |
bryantaylor | 0:eafc3fd41f75 | 34 | * |
bryantaylor | 0:eafc3fd41f75 | 35 | * #include "mbed.h" |
bryantaylor | 0:eafc3fd41f75 | 36 | * |
bryantaylor | 0:eafc3fd41f75 | 37 | * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23 |
bryantaylor | 0:eafc3fd41f75 | 38 | * #define LED_MASK 0x00B40000 |
bryantaylor | 0:eafc3fd41f75 | 39 | * |
bryantaylor | 0:eafc3fd41f75 | 40 | * PortOut ledport(Port1, LED_MASK); |
bryantaylor | 0:eafc3fd41f75 | 41 | * |
bryantaylor | 0:eafc3fd41f75 | 42 | * int main() { |
bryantaylor | 0:eafc3fd41f75 | 43 | * while(1) { |
bryantaylor | 0:eafc3fd41f75 | 44 | * ledport = LED_MASK; |
bryantaylor | 0:eafc3fd41f75 | 45 | * wait(1); |
bryantaylor | 0:eafc3fd41f75 | 46 | * ledport = 0; |
bryantaylor | 0:eafc3fd41f75 | 47 | * wait(1); |
bryantaylor | 0:eafc3fd41f75 | 48 | * } |
bryantaylor | 0:eafc3fd41f75 | 49 | * } |
bryantaylor | 0:eafc3fd41f75 | 50 | * @endcode |
bryantaylor | 0:eafc3fd41f75 | 51 | */ |
bryantaylor | 0:eafc3fd41f75 | 52 | class PortOut { |
bryantaylor | 0:eafc3fd41f75 | 53 | public: |
bryantaylor | 0:eafc3fd41f75 | 54 | |
bryantaylor | 0:eafc3fd41f75 | 55 | /** Create an PortOut, connected to the specified port |
bryantaylor | 0:eafc3fd41f75 | 56 | * |
bryantaylor | 0:eafc3fd41f75 | 57 | * @param port Port to connect to (Port0-Port5) |
bryantaylor | 0:eafc3fd41f75 | 58 | * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) |
bryantaylor | 0:eafc3fd41f75 | 59 | */ |
bryantaylor | 0:eafc3fd41f75 | 60 | PortOut(PortName port, int mask = 0xFFFFFFFF) { |
bryantaylor | 0:eafc3fd41f75 | 61 | core_util_critical_section_enter(); |
bryantaylor | 0:eafc3fd41f75 | 62 | port_init(&_port, port, mask, PIN_OUTPUT); |
bryantaylor | 0:eafc3fd41f75 | 63 | core_util_critical_section_exit(); |
bryantaylor | 0:eafc3fd41f75 | 64 | } |
bryantaylor | 0:eafc3fd41f75 | 65 | |
bryantaylor | 0:eafc3fd41f75 | 66 | /** Write the value to the output port |
bryantaylor | 0:eafc3fd41f75 | 67 | * |
bryantaylor | 0:eafc3fd41f75 | 68 | * @param value An integer specifying a bit to write for every corresponding PortOut pin |
bryantaylor | 0:eafc3fd41f75 | 69 | */ |
bryantaylor | 0:eafc3fd41f75 | 70 | void write(int value) { |
bryantaylor | 0:eafc3fd41f75 | 71 | port_write(&_port, value); |
bryantaylor | 0:eafc3fd41f75 | 72 | } |
bryantaylor | 0:eafc3fd41f75 | 73 | |
bryantaylor | 0:eafc3fd41f75 | 74 | /** Read the value currently output on the port |
bryantaylor | 0:eafc3fd41f75 | 75 | * |
bryantaylor | 0:eafc3fd41f75 | 76 | * @returns |
bryantaylor | 0:eafc3fd41f75 | 77 | * An integer with each bit corresponding to associated PortOut pin setting |
bryantaylor | 0:eafc3fd41f75 | 78 | */ |
bryantaylor | 0:eafc3fd41f75 | 79 | int read() { |
bryantaylor | 0:eafc3fd41f75 | 80 | return port_read(&_port); |
bryantaylor | 0:eafc3fd41f75 | 81 | } |
bryantaylor | 0:eafc3fd41f75 | 82 | |
bryantaylor | 0:eafc3fd41f75 | 83 | /** A shorthand for write() |
bryantaylor | 0:eafc3fd41f75 | 84 | */ |
bryantaylor | 0:eafc3fd41f75 | 85 | PortOut& operator= (int value) { |
bryantaylor | 0:eafc3fd41f75 | 86 | write(value); |
bryantaylor | 0:eafc3fd41f75 | 87 | return *this; |
bryantaylor | 0:eafc3fd41f75 | 88 | } |
bryantaylor | 0:eafc3fd41f75 | 89 | |
bryantaylor | 0:eafc3fd41f75 | 90 | PortOut& operator= (PortOut& rhs) { |
bryantaylor | 0:eafc3fd41f75 | 91 | write(rhs.read()); |
bryantaylor | 0:eafc3fd41f75 | 92 | return *this; |
bryantaylor | 0:eafc3fd41f75 | 93 | } |
bryantaylor | 0:eafc3fd41f75 | 94 | |
bryantaylor | 0:eafc3fd41f75 | 95 | /** A shorthand for read() |
bryantaylor | 0:eafc3fd41f75 | 96 | */ |
bryantaylor | 0:eafc3fd41f75 | 97 | operator int() { |
bryantaylor | 0:eafc3fd41f75 | 98 | return read(); |
bryantaylor | 0:eafc3fd41f75 | 99 | } |
bryantaylor | 0:eafc3fd41f75 | 100 | |
bryantaylor | 0:eafc3fd41f75 | 101 | private: |
bryantaylor | 0:eafc3fd41f75 | 102 | port_t _port; |
bryantaylor | 0:eafc3fd41f75 | 103 | }; |
bryantaylor | 0:eafc3fd41f75 | 104 | |
bryantaylor | 0:eafc3fd41f75 | 105 | } // namespace mbed |
bryantaylor | 0:eafc3fd41f75 | 106 | |
bryantaylor | 0:eafc3fd41f75 | 107 | #endif |
bryantaylor | 0:eafc3fd41f75 | 108 | |
bryantaylor | 0:eafc3fd41f75 | 109 | #endif |