mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Wed Oct 10 14:14:12 2012 +0000
Revision:
2:e9a661555b58
Parent:
0:8024c367e29f
Child:
6:0d4e7384bff6
Add PWM and I2C implementation;

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 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 typedef enum {
emilmont 2:e9a661555b58 15 PIN_INPUT,
emilmont 2:e9a661555b58 16 PIN_OUTPUT
emilmont 2:e9a661555b58 17 } PinDirection;
emilmont 2:e9a661555b58 18
emilmont 2:e9a661555b58 19 /* This version of the gpio API caches the gpio register pointer and the pin mask */
emilmont 2:e9a661555b58 20 typedef struct {
emilmont 2:e9a661555b58 21 PinName pin;
emilmont 2:e9a661555b58 22 uint32_t mask;
emilmont 2:e9a661555b58 23
emilmont 2:e9a661555b58 24 __IO uint32_t *reg_dir;
emilmont 2:e9a661555b58 25 __IO uint32_t *reg_set;
emilmont 2:e9a661555b58 26 __IO uint32_t *reg_clr;
emilmont 2:e9a661555b58 27 __I uint32_t *reg_in;
emilmont 2:e9a661555b58 28 } gpio_object;
emilmont 2:e9a661555b58 29
emilmont 2:e9a661555b58 30 void gpio_init (gpio_object *obj, PinName pin, PinDirection direction);
emilmont 2:e9a661555b58 31
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 2:e9a661555b58 48 #endif
emilmont 2:e9a661555b58 49
emilmont 2:e9a661555b58 50 #endif