mbed library sources. Supersedes mbed-src.

Dependents:   BREAK_SENSOR_LED

Fork of mbed-dev by mbed official

Committer:
Anythingconnected
Date:
Mon Dec 18 10:14:27 2017 +0000
Revision:
180:d79f997829d6
Parent:
167:e84263d55307
Getting byte by byte read to work

Who changed what in which revision?

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