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 Cortex Challenge Team

Committer:
16038618
Date:
Sat Oct 29 15:11:28 2016 +0000
Revision:
1:4bdfa7d7e8bf
IOTIO

Who changed what in which revision?

UserRevisionLine numberNew 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_DIGITALOUT_H
16038618 1:4bdfa7d7e8bf 17 #define MBED_DIGITALOUT_H
16038618 1:4bdfa7d7e8bf 18
16038618 1:4bdfa7d7e8bf 19 #include "platform.h"
16038618 1:4bdfa7d7e8bf 20 #include "gpio_api.h"
16038618 1:4bdfa7d7e8bf 21
16038618 1:4bdfa7d7e8bf 22 namespace mbed {
16038618 1:4bdfa7d7e8bf 23
16038618 1:4bdfa7d7e8bf 24 /** A digital output, used for setting the state of a pin
16038618 1:4bdfa7d7e8bf 25 *
16038618 1:4bdfa7d7e8bf 26 * Example:
16038618 1:4bdfa7d7e8bf 27 * @code
16038618 1:4bdfa7d7e8bf 28 * // Toggle a LED
16038618 1:4bdfa7d7e8bf 29 * #include "mbed.h"
16038618 1:4bdfa7d7e8bf 30 *
16038618 1:4bdfa7d7e8bf 31 * DigitalOut led(LED1);
16038618 1:4bdfa7d7e8bf 32 *
16038618 1:4bdfa7d7e8bf 33 * int main() {
16038618 1:4bdfa7d7e8bf 34 * while(1) {
16038618 1:4bdfa7d7e8bf 35 * led = !led;
16038618 1:4bdfa7d7e8bf 36 * wait(0.2);
16038618 1:4bdfa7d7e8bf 37 * }
16038618 1:4bdfa7d7e8bf 38 * }
16038618 1:4bdfa7d7e8bf 39 * @endcode
16038618 1:4bdfa7d7e8bf 40 */
16038618 1:4bdfa7d7e8bf 41 class DigitalOut {
16038618 1:4bdfa7d7e8bf 42
16038618 1:4bdfa7d7e8bf 43 public:
16038618 1:4bdfa7d7e8bf 44 /** Create a DigitalOut connected to the specified pin
16038618 1:4bdfa7d7e8bf 45 *
16038618 1:4bdfa7d7e8bf 46 * @param pin DigitalOut pin to connect to
16038618 1:4bdfa7d7e8bf 47 */
16038618 1:4bdfa7d7e8bf 48 DigitalOut(PinName pin) : gpio() {
16038618 1:4bdfa7d7e8bf 49 gpio_init_out(&gpio, pin);
16038618 1:4bdfa7d7e8bf 50 }
16038618 1:4bdfa7d7e8bf 51
16038618 1:4bdfa7d7e8bf 52 /** Create a DigitalOut connected to the specified pin
16038618 1:4bdfa7d7e8bf 53 *
16038618 1:4bdfa7d7e8bf 54 * @param pin DigitalOut pin to connect to
16038618 1:4bdfa7d7e8bf 55 * @param value the initial pin value
16038618 1:4bdfa7d7e8bf 56 */
16038618 1:4bdfa7d7e8bf 57 DigitalOut(PinName pin, int value) : gpio() {
16038618 1:4bdfa7d7e8bf 58 gpio_init_out_ex(&gpio, pin, value);
16038618 1:4bdfa7d7e8bf 59 }
16038618 1:4bdfa7d7e8bf 60
16038618 1:4bdfa7d7e8bf 61 /** Set the output, specified as 0 or 1 (int)
16038618 1:4bdfa7d7e8bf 62 *
16038618 1:4bdfa7d7e8bf 63 * @param value An integer specifying the pin output value,
16038618 1:4bdfa7d7e8bf 64 * 0 for logical 0, 1 (or any other non-zero value) for logical 1
16038618 1:4bdfa7d7e8bf 65 */
16038618 1:4bdfa7d7e8bf 66 void write(int value) {
16038618 1:4bdfa7d7e8bf 67 gpio_write(&gpio, value);
16038618 1:4bdfa7d7e8bf 68 }
16038618 1:4bdfa7d7e8bf 69
16038618 1:4bdfa7d7e8bf 70 /** Return the output setting, represented as 0 or 1 (int)
16038618 1:4bdfa7d7e8bf 71 *
16038618 1:4bdfa7d7e8bf 72 * @returns
16038618 1:4bdfa7d7e8bf 73 * an integer representing the output setting of the pin,
16038618 1:4bdfa7d7e8bf 74 * 0 for logical 0, 1 for logical 1
16038618 1:4bdfa7d7e8bf 75 */
16038618 1:4bdfa7d7e8bf 76 int read() {
16038618 1:4bdfa7d7e8bf 77 return gpio_read(&gpio);
16038618 1:4bdfa7d7e8bf 78 }
16038618 1:4bdfa7d7e8bf 79
16038618 1:4bdfa7d7e8bf 80 /** Return the output setting, represented as 0 or 1 (int)
16038618 1:4bdfa7d7e8bf 81 *
16038618 1:4bdfa7d7e8bf 82 * @returns
16038618 1:4bdfa7d7e8bf 83 * Non zero value if pin is connected to uc GPIO
16038618 1:4bdfa7d7e8bf 84 * 0 if gpio object was initialized with NC
16038618 1:4bdfa7d7e8bf 85 */
16038618 1:4bdfa7d7e8bf 86 int is_connected() {
16038618 1:4bdfa7d7e8bf 87 return gpio_is_connected(&gpio);
16038618 1:4bdfa7d7e8bf 88 }
16038618 1:4bdfa7d7e8bf 89
16038618 1:4bdfa7d7e8bf 90 #ifdef MBED_OPERATORS
16038618 1:4bdfa7d7e8bf 91 /** A shorthand for write()
16038618 1:4bdfa7d7e8bf 92 */
16038618 1:4bdfa7d7e8bf 93 DigitalOut& operator= (int value) {
16038618 1:4bdfa7d7e8bf 94 write(value);
16038618 1:4bdfa7d7e8bf 95 return *this;
16038618 1:4bdfa7d7e8bf 96 }
16038618 1:4bdfa7d7e8bf 97
16038618 1:4bdfa7d7e8bf 98 DigitalOut& operator= (DigitalOut& rhs) {
16038618 1:4bdfa7d7e8bf 99 write(rhs.read());
16038618 1:4bdfa7d7e8bf 100 return *this;
16038618 1:4bdfa7d7e8bf 101 }
16038618 1:4bdfa7d7e8bf 102
16038618 1:4bdfa7d7e8bf 103 /** A shorthand for read()
16038618 1:4bdfa7d7e8bf 104 */
16038618 1:4bdfa7d7e8bf 105 operator int() {
16038618 1:4bdfa7d7e8bf 106 return read();
16038618 1:4bdfa7d7e8bf 107 }
16038618 1:4bdfa7d7e8bf 108 #endif
16038618 1:4bdfa7d7e8bf 109
16038618 1:4bdfa7d7e8bf 110 protected:
16038618 1:4bdfa7d7e8bf 111 gpio_t gpio;
16038618 1:4bdfa7d7e8bf 112 };
16038618 1:4bdfa7d7e8bf 113
16038618 1:4bdfa7d7e8bf 114 } // namespace mbed
16038618 1:4bdfa7d7e8bf 115
16038618 1:4bdfa7d7e8bf 116 #endif