Add gpio_set and gpio_reset

Use them like gpio_set(GPIO_xx) and gpio_reset(GPIO_xx).
These macros efficiently set the DATA_SET and DATA_RESET bits without
reading the registers first, as a direct GPIO->DATA_SET.GPIO_xx would do
This commit is contained in:
maralvira 2010-11-07 14:29:04 +00:00
parent 4a4a39c84a
commit dab7faf13c

View File

@ -30,7 +30,7 @@
* This file is part of libmc1322x: see http://mc1322x.devl.org
* for details.
*
* $Id: gpio.h,v 1.4 2010/11/07 14:28:30 maralvira Exp $
* $Id: gpio.h,v 1.5 2010/11/07 14:29:04 maralvira Exp $
*/
#ifndef GPIO_H
@ -46,6 +46,9 @@
#define MY_PIN GPIO_08
GPIO->FUNC_SEL.MY_PIN = 2; // same, to allow #define for pin names
GPIO->DATA.MY_PIN = 1;
gpio_set(GPIO_08); // efficiently set or clear a single output bit
gpio_reset(GPIO_08);
*/
#define _V(x,n,i) uint32_t x##_##i : n;
@ -84,6 +87,24 @@ struct GPIO_struct {
};
#undef _IO
#undef _IO_2bit
/* Build an enum lookup to map GPIO_08 -> 8 */
#undef _V
#define _V(x,n,i) __NUM_GPIO_GPIO_##i,
enum { _REP(0,0) };
/* Macros to set or reset a data pin in the fastest possible way */
#define gpio_set(gpio_xx) __gpio_set(gpio_xx)
#define __gpio_set(gpio_xx) \
((__NUM_GPIO_##gpio_xx < 32) \
? (GPIO->DATA_SET0 = (1 << (__NUM_GPIO_##gpio_xx - 0))) \
: (GPIO->DATA_SET1 = (1 << (__NUM_GPIO_##gpio_xx - 32))))
#define gpio_reset(gpio_xx) __gpio_reset(gpio_xx)
#define __gpio_reset(gpio_xx) \
((__NUM_GPIO_##gpio_xx < 32) \
? (GPIO->DATA_RESET0 = (1 << (__NUM_GPIO_##gpio_xx - 0))) \
: (GPIO->DATA_RESET1 = (1 << (__NUM_GPIO_##gpio_xx - 32))))
#undef _REP
#undef _V