mbed libraries for KL25Z
Diff: gpio_api.h
- Revision:
- 2:e9a661555b58
- Parent:
- 0:8024c367e29f
- Child:
- 6:0d4e7384bff6
--- a/gpio_api.h Fri Oct 05 15:45:13 2012 +0000 +++ b/gpio_api.h Wed Oct 10 14:14:12 2012 +0000 @@ -1,50 +1,50 @@ -/* mbed Microcontroller Library - gpio_api - * Copyright (c) 2009-2011 ARM Limited. All rights reserved. - */ - -#ifndef MBED_GPIO_API_H -#define MBED_GPIO_API_H - -#include "PinNames.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - PIN_INPUT, - PIN_OUTPUT -} PinDirection; - -/* This version of the gpio API caches the gpio register pointer and the pin mask */ -typedef struct { - PinName pin; - uint32_t mask; - - __IO uint32_t *reg_dir; - __IO uint32_t *reg_set; - __IO uint32_t *reg_clr; - __I uint32_t *reg_in; -} gpio_object; - -void gpio_init (gpio_object *obj, PinName pin, PinDirection direction); - -void gpio_mode(gpio_object *obj, PinMode mode); -void gpio_dir (gpio_object *obj, PinDirection direction); - -static inline void gpio_write(gpio_object *obj, int value) { - if (value) - *obj->reg_set = obj->mask; - else - *obj->reg_clr = obj->mask; -} - -static inline int gpio_read(gpio_object *obj) { - return ((*obj->reg_in & obj->mask) ? 1 : 0); -} - -#ifdef __cplusplus -} -#endif - -#endif +/* mbed Microcontroller Library - gpio_api + * Copyright (c) 2009-2011 ARM Limited. All rights reserved. + */ + +#ifndef MBED_GPIO_API_H +#define MBED_GPIO_API_H + +#include "PinNames.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + PIN_INPUT, + PIN_OUTPUT +} PinDirection; + +/* This version of the gpio API caches the gpio register pointer and the pin mask */ +typedef struct { + PinName pin; + uint32_t mask; + + __IO uint32_t *reg_dir; + __IO uint32_t *reg_set; + __IO uint32_t *reg_clr; + __I uint32_t *reg_in; +} gpio_object; + +void gpio_init (gpio_object *obj, PinName pin, PinDirection direction); + +void gpio_mode(gpio_object *obj, PinMode mode); +void gpio_dir (gpio_object *obj, PinDirection direction); + +static inline void gpio_write(gpio_object *obj, int value) { + if (value) + *obj->reg_set = obj->mask; + else + *obj->reg_clr = obj->mask; +} + +static inline int gpio_read(gpio_object *obj) { + return ((*obj->reg_in & obj->mask) ? 1 : 0); +} + +#ifdef __cplusplus +} +#endif + +#endif