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