mbed libraries for KL25Z
gpio_api.h@6:0d4e7384bff6, 2012-10-12 (annotated)
- Committer:
- emilmont
- Date:
- Fri Oct 12 10:06:08 2012 +0000
- Revision:
- 6:0d4e7384bff6
- Parent:
- 2:e9a661555b58
- Child:
- 7:73c5efe92a6c
PinDirection moved to PinNames.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 2:e9a661555b58 | 1 | /* mbed Microcontroller Library - gpio_api |
emilmont | 2:e9a661555b58 | 2 | * Copyright (c) 2009-2011 ARM Limited. All rights reserved. |
emilmont | 2:e9a661555b58 | 3 | */ |
emilmont | 2:e9a661555b58 | 4 | |
emilmont | 2:e9a661555b58 | 5 | #ifndef MBED_GPIO_API_H |
emilmont | 2:e9a661555b58 | 6 | #define MBED_GPIO_API_H |
emilmont | 2:e9a661555b58 | 7 | |
emilmont | 2:e9a661555b58 | 8 | #include "PinNames.h" |
emilmont | 2:e9a661555b58 | 9 | |
emilmont | 2:e9a661555b58 | 10 | #ifdef __cplusplus |
emilmont | 2:e9a661555b58 | 11 | extern "C" { |
emilmont | 2:e9a661555b58 | 12 | #endif |
emilmont | 2:e9a661555b58 | 13 | |
emilmont | 2:e9a661555b58 | 14 | /* This version of the gpio API caches the gpio register pointer and the pin mask */ |
emilmont | 2:e9a661555b58 | 15 | typedef struct { |
emilmont | 2:e9a661555b58 | 16 | PinName pin; |
emilmont | 2:e9a661555b58 | 17 | uint32_t mask; |
emilmont | 2:e9a661555b58 | 18 | |
emilmont | 2:e9a661555b58 | 19 | __IO uint32_t *reg_dir; |
emilmont | 2:e9a661555b58 | 20 | __IO uint32_t *reg_set; |
emilmont | 2:e9a661555b58 | 21 | __IO uint32_t *reg_clr; |
emilmont | 2:e9a661555b58 | 22 | __I uint32_t *reg_in; |
emilmont | 2:e9a661555b58 | 23 | } gpio_object; |
emilmont | 2:e9a661555b58 | 24 | |
emilmont | 2:e9a661555b58 | 25 | void gpio_init (gpio_object *obj, PinName pin, PinDirection direction); |
emilmont | 2:e9a661555b58 | 26 | |
emilmont | 2:e9a661555b58 | 27 | void gpio_mode(gpio_object *obj, PinMode mode); |
emilmont | 2:e9a661555b58 | 28 | void gpio_dir (gpio_object *obj, PinDirection direction); |
emilmont | 2:e9a661555b58 | 29 | |
emilmont | 2:e9a661555b58 | 30 | static inline void gpio_write(gpio_object *obj, int value) { |
emilmont | 2:e9a661555b58 | 31 | if (value) |
emilmont | 2:e9a661555b58 | 32 | *obj->reg_set = obj->mask; |
emilmont | 2:e9a661555b58 | 33 | else |
emilmont | 2:e9a661555b58 | 34 | *obj->reg_clr = obj->mask; |
emilmont | 2:e9a661555b58 | 35 | } |
emilmont | 2:e9a661555b58 | 36 | |
emilmont | 2:e9a661555b58 | 37 | static inline int gpio_read(gpio_object *obj) { |
emilmont | 2:e9a661555b58 | 38 | return ((*obj->reg_in & obj->mask) ? 1 : 0); |
emilmont | 2:e9a661555b58 | 39 | } |
emilmont | 2:e9a661555b58 | 40 | |
emilmont | 2:e9a661555b58 | 41 | #ifdef __cplusplus |
emilmont | 2:e9a661555b58 | 42 | } |
emilmont | 2:e9a661555b58 | 43 | #endif |
emilmont | 2:e9a661555b58 | 44 | |
emilmont | 2:e9a661555b58 | 45 | #endif |