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