Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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