Mangue Baja Box

Dependencies:   mbed

Committer:
einsteingustavo
Date:
Mon Jul 29 20:38:00 2019 +0000
Revision:
0:0dee8840a1c0
Mangue Baja Box

Who changed what in which revision?

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