mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Fri Oct 05 09:16:41 2012 +0000
Revision:
0:8024c367e29f
Child:
2:e9a661555b58
First release of the mbed libraries for KL25Z

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 0:8024c367e29f 1 /* mbed Microcontroller Library - gpio_api
emilmont 0:8024c367e29f 2 * Copyright (c) 2009-2011 ARM Limited. All rights reserved.
emilmont 0:8024c367e29f 3 */
emilmont 0:8024c367e29f 4
emilmont 0:8024c367e29f 5 #ifndef MBED_GPIO_API_H
emilmont 0:8024c367e29f 6 #define MBED_GPIO_API_H
emilmont 0:8024c367e29f 7
emilmont 0:8024c367e29f 8 #include "PinNames.h"
emilmont 0:8024c367e29f 9
emilmont 0:8024c367e29f 10 #ifdef __cplusplus
emilmont 0:8024c367e29f 11 extern "C" {
emilmont 0:8024c367e29f 12 #endif
emilmont 0:8024c367e29f 13
emilmont 0:8024c367e29f 14 typedef enum {
emilmont 0:8024c367e29f 15 PIN_INPUT,
emilmont 0:8024c367e29f 16 PIN_OUTPUT
emilmont 0:8024c367e29f 17 } PinDirection;
emilmont 0:8024c367e29f 18
emilmont 0:8024c367e29f 19 /* This version of the gpio API caches the gpio register pointer and the pin mask */
emilmont 0:8024c367e29f 20 typedef struct {
emilmont 0:8024c367e29f 21 PinName pin;
emilmont 0:8024c367e29f 22 uint32_t mask;
emilmont 0:8024c367e29f 23
emilmont 0:8024c367e29f 24 __IO uint32_t *reg_dir;
emilmont 0:8024c367e29f 25 __IO uint32_t *reg_set;
emilmont 0:8024c367e29f 26 __IO uint32_t *reg_clr;
emilmont 0:8024c367e29f 27 __I uint32_t *reg_in;
emilmont 0:8024c367e29f 28 } gpio_object;
emilmont 0:8024c367e29f 29
emilmont 0:8024c367e29f 30 void gpio_init (gpio_object *obj, PinName pin, PinDirection direction);
emilmont 0:8024c367e29f 31
emilmont 0:8024c367e29f 32 void gpio_mode(gpio_object *obj, PinMode mode);
emilmont 0:8024c367e29f 33 void gpio_dir (gpio_object *obj, PinDirection direction);
emilmont 0:8024c367e29f 34
emilmont 0:8024c367e29f 35 static inline void gpio_write(gpio_object *obj, int value) {
emilmont 0:8024c367e29f 36 if (value)
emilmont 0:8024c367e29f 37 *obj->reg_set = obj->mask;
emilmont 0:8024c367e29f 38 else
emilmont 0:8024c367e29f 39 *obj->reg_clr = obj->mask;
emilmont 0:8024c367e29f 40 }
emilmont 0:8024c367e29f 41
emilmont 0:8024c367e29f 42 static inline int gpio_read(gpio_object *obj) {
emilmont 0:8024c367e29f 43 return ((*obj->reg_in & obj->mask) ? 1 : 0);
emilmont 0:8024c367e29f 44 }
emilmont 0:8024c367e29f 45
emilmont 0:8024c367e29f 46 #ifdef __cplusplus
emilmont 0:8024c367e29f 47 }
emilmont 0:8024c367e29f 48 #endif
emilmont 0:8024c367e29f 49
emilmont 0:8024c367e29f 50 #endif