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