mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Tue Oct 23 09:20:18 2012 +0000
Revision:
7:73c5efe92a6c
Parent:
6:0d4e7384bff6
Child:
8:c14af7958ef5
Make the C++ library completely TARGET independent.; Implement "gpio_irq_api" and "port_api" to KL25Z.

Who changed what in which revision?

UserRevisionLine numberNew 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 7:73c5efe92a6c 3 */
emilmont 2:e9a661555b58 4 #ifndef MBED_GPIO_API_H
emilmont 2:e9a661555b58 5 #define MBED_GPIO_API_H
emilmont 2:e9a661555b58 6
emilmont 2:e9a661555b58 7 #include "PinNames.h"
emilmont 2:e9a661555b58 8
emilmont 2:e9a661555b58 9 #ifdef __cplusplus
emilmont 2:e9a661555b58 10 extern "C" {
emilmont 7:73c5efe92a6c 11 #endif
emilmont 2:e9a661555b58 12
emilmont 2:e9a661555b58 13 /* This version of the gpio API caches the gpio register pointer and the pin mask */
emilmont 2:e9a661555b58 14 typedef struct {
emilmont 7:73c5efe92a6c 15 PinName pin;
emilmont 7:73c5efe92a6c 16 uint32_t mask;
emilmont 2:e9a661555b58 17
emilmont 2:e9a661555b58 18 __IO uint32_t *reg_dir;
emilmont 2:e9a661555b58 19 __IO uint32_t *reg_set;
emilmont 2:e9a661555b58 20 __IO uint32_t *reg_clr;
emilmont 2:e9a661555b58 21 __I uint32_t *reg_in;
emilmont 2:e9a661555b58 22 } gpio_object;
emilmont 2:e9a661555b58 23
emilmont 7:73c5efe92a6c 24 /* Set the given pin as GPIO
emilmont 7:73c5efe92a6c 25 * @param pin The pin to be set as GPIO
emilmont 7:73c5efe92a6c 26 * @return The GPIO port mask for this pin
emilmont 7:73c5efe92a6c 27 **/
emilmont 7:73c5efe92a6c 28 uint32_t gpio_set (PinName pin);
emilmont 2:e9a661555b58 29
emilmont 7:73c5efe92a6c 30 /* GPIO object */
emilmont 7:73c5efe92a6c 31 void gpio_init(gpio_object *obj, PinName pin, PinDirection direction);
emilmont 2:e9a661555b58 32 void gpio_mode(gpio_object *obj, PinMode mode);
emilmont 2:e9a661555b58 33 void gpio_dir (gpio_object *obj, PinDirection direction);
emilmont 2:e9a661555b58 34
emilmont 2:e9a661555b58 35 static inline void gpio_write(gpio_object *obj, int value) {
emilmont 2:e9a661555b58 36 if (value)
emilmont 2:e9a661555b58 37 *obj->reg_set = obj->mask;
emilmont 2:e9a661555b58 38 else
emilmont 2:e9a661555b58 39 *obj->reg_clr = obj->mask;
emilmont 2:e9a661555b58 40 }
emilmont 2:e9a661555b58 41
emilmont 2:e9a661555b58 42 static inline int gpio_read(gpio_object *obj) {
emilmont 2:e9a661555b58 43 return ((*obj->reg_in & obj->mask) ? 1 : 0);
emilmont 2:e9a661555b58 44 }
emilmont 2:e9a661555b58 45
emilmont 2:e9a661555b58 46 #ifdef __cplusplus
emilmont 2:e9a661555b58 47 }
emilmont 7:73c5efe92a6c 48 #endif
emilmont 2:e9a661555b58 49
emilmont 7:73c5efe92a6c 50 #endif