The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_NUCLEO_F413ZH/TARGET_STM/gpio_object.h@160:5571c4ff569f, 2018-01-17 (annotated)
- Committer:
- Anna Bridge
- Date:
- Wed Jan 17 16:13:02 2018 +0000
- Revision:
- 160:5571c4ff569f
mbed library. Release version 158
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anna Bridge |
160:5571c4ff569f | 1 | /* mbed Microcontroller Library |
Anna Bridge |
160:5571c4ff569f | 2 | ******************************************************************************* |
Anna Bridge |
160:5571c4ff569f | 3 | * Copyright (c) 2016, STMicroelectronics |
Anna Bridge |
160:5571c4ff569f | 4 | * All rights reserved. |
Anna Bridge |
160:5571c4ff569f | 5 | * |
Anna Bridge |
160:5571c4ff569f | 6 | * Redistribution and use in source and binary forms, with or without |
Anna Bridge |
160:5571c4ff569f | 7 | * modification, are permitted provided that the following conditions are met: |
Anna Bridge |
160:5571c4ff569f | 8 | * |
Anna Bridge |
160:5571c4ff569f | 9 | * 1. Redistributions of source code must retain the above copyright notice, |
Anna Bridge |
160:5571c4ff569f | 10 | * this list of conditions and the following disclaimer. |
Anna Bridge |
160:5571c4ff569f | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Anna Bridge |
160:5571c4ff569f | 12 | * this list of conditions and the following disclaimer in the documentation |
Anna Bridge |
160:5571c4ff569f | 13 | * and/or other materials provided with the distribution. |
Anna Bridge |
160:5571c4ff569f | 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Anna Bridge |
160:5571c4ff569f | 15 | * may be used to endorse or promote products derived from this software |
Anna Bridge |
160:5571c4ff569f | 16 | * without specific prior written permission. |
Anna Bridge |
160:5571c4ff569f | 17 | * |
Anna Bridge |
160:5571c4ff569f | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Anna Bridge |
160:5571c4ff569f | 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Anna Bridge |
160:5571c4ff569f | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Anna Bridge |
160:5571c4ff569f | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Anna Bridge |
160:5571c4ff569f | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Anna Bridge |
160:5571c4ff569f | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Anna Bridge |
160:5571c4ff569f | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Anna Bridge |
160:5571c4ff569f | 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Anna Bridge |
160:5571c4ff569f | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Anna Bridge |
160:5571c4ff569f | 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Anna Bridge |
160:5571c4ff569f | 28 | ******************************************************************************* |
Anna Bridge |
160:5571c4ff569f | 29 | */ |
Anna Bridge |
160:5571c4ff569f | 30 | #ifndef MBED_GPIO_OBJECT_H |
Anna Bridge |
160:5571c4ff569f | 31 | #define MBED_GPIO_OBJECT_H |
Anna Bridge |
160:5571c4ff569f | 32 | |
Anna Bridge |
160:5571c4ff569f | 33 | #include "mbed_assert.h" |
Anna Bridge |
160:5571c4ff569f | 34 | #include "cmsis.h" |
Anna Bridge |
160:5571c4ff569f | 35 | #include "PortNames.h" |
Anna Bridge |
160:5571c4ff569f | 36 | #include "PeripheralNames.h" |
Anna Bridge |
160:5571c4ff569f | 37 | #include "PinNames.h" |
Anna Bridge |
160:5571c4ff569f | 38 | |
Anna Bridge |
160:5571c4ff569f | 39 | #ifdef __cplusplus |
Anna Bridge |
160:5571c4ff569f | 40 | extern "C" { |
Anna Bridge |
160:5571c4ff569f | 41 | #endif |
Anna Bridge |
160:5571c4ff569f | 42 | |
Anna Bridge |
160:5571c4ff569f | 43 | /* |
Anna Bridge |
160:5571c4ff569f | 44 | * Note: reg_clr might actually be same as reg_set. |
Anna Bridge |
160:5571c4ff569f | 45 | * Depends on family whether BRR is available on top of BSRR |
Anna Bridge |
160:5571c4ff569f | 46 | * if BRR does not exist, family shall define GPIO_IP_WITHOUT_BRR |
Anna Bridge |
160:5571c4ff569f | 47 | */ |
Anna Bridge |
160:5571c4ff569f | 48 | typedef struct { |
Anna Bridge |
160:5571c4ff569f | 49 | uint32_t mask; |
Anna Bridge |
160:5571c4ff569f | 50 | __IO uint32_t *reg_in; |
Anna Bridge |
160:5571c4ff569f | 51 | __IO uint32_t *reg_set; |
Anna Bridge |
160:5571c4ff569f | 52 | __IO uint32_t *reg_clr; |
Anna Bridge |
160:5571c4ff569f | 53 | PinName pin; |
Anna Bridge |
160:5571c4ff569f | 54 | GPIO_TypeDef *gpio; |
Anna Bridge |
160:5571c4ff569f | 55 | uint32_t ll_pin; |
Anna Bridge |
160:5571c4ff569f | 56 | } gpio_t; |
Anna Bridge |
160:5571c4ff569f | 57 | |
Anna Bridge |
160:5571c4ff569f | 58 | static inline void gpio_write(gpio_t *obj, int value) |
Anna Bridge |
160:5571c4ff569f | 59 | { |
Anna Bridge |
160:5571c4ff569f | 60 | if (value) { |
Anna Bridge |
160:5571c4ff569f | 61 | *obj->reg_set = obj->mask; |
Anna Bridge |
160:5571c4ff569f | 62 | } else { |
Anna Bridge |
160:5571c4ff569f | 63 | #ifdef GPIO_IP_WITHOUT_BRR |
Anna Bridge |
160:5571c4ff569f | 64 | *obj->reg_clr = obj->mask << 16; |
Anna Bridge |
160:5571c4ff569f | 65 | #else |
Anna Bridge |
160:5571c4ff569f | 66 | *obj->reg_clr = obj->mask; |
Anna Bridge |
160:5571c4ff569f | 67 | #endif |
Anna Bridge |
160:5571c4ff569f | 68 | } |
Anna Bridge |
160:5571c4ff569f | 69 | } |
Anna Bridge |
160:5571c4ff569f | 70 | |
Anna Bridge |
160:5571c4ff569f | 71 | static inline int gpio_read(gpio_t *obj) |
Anna Bridge |
160:5571c4ff569f | 72 | { |
Anna Bridge |
160:5571c4ff569f | 73 | return ((*obj->reg_in & obj->mask) ? 1 : 0); |
Anna Bridge |
160:5571c4ff569f | 74 | } |
Anna Bridge |
160:5571c4ff569f | 75 | |
Anna Bridge |
160:5571c4ff569f | 76 | static inline int gpio_is_connected(const gpio_t *obj) |
Anna Bridge |
160:5571c4ff569f | 77 | { |
Anna Bridge |
160:5571c4ff569f | 78 | return obj->pin != (PinName)NC; |
Anna Bridge |
160:5571c4ff569f | 79 | } |
Anna Bridge |
160:5571c4ff569f | 80 | |
Anna Bridge |
160:5571c4ff569f | 81 | |
Anna Bridge |
160:5571c4ff569f | 82 | #ifdef __cplusplus |
Anna Bridge |
160:5571c4ff569f | 83 | } |
Anna Bridge |
160:5571c4ff569f | 84 | #endif |
Anna Bridge |
160:5571c4ff569f | 85 | |
Anna Bridge |
160:5571c4ff569f | 86 | #endif |