Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

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