From ca1e32977f8964432f119682922491c0f9792cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Tue, 7 Feb 2017 22:03:15 +0100 Subject: [PATCH 1/2] kinetis: Fix typo in periph_cpu.h --- cpu/kinetis_common/include/periph_cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/kinetis_common/include/periph_cpu.h b/cpu/kinetis_common/include/periph_cpu.h index 650c514d78..489003f172 100644 --- a/cpu/kinetis_common/include/periph_cpu.h +++ b/cpu/kinetis_common/include/periph_cpu.h @@ -59,7 +59,7 @@ typedef uint16_t gpio_t; * * We use the following bits to encode the pin mode: * - bit 0: 0 for pull-down or 1 for pull-up - * - bit 1: pull register enable (as configured in bit 0) + * - bit 1: pull resistor enable (as configured in bit 0) * - bit 5: OD enable * - bit 7: output or input mode */ From f5167179070210e56bb736d722c9ed834a3b505e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Tue, 7 Feb 2017 22:05:24 +0100 Subject: [PATCH 2/2] lpc11u34: Remove short name macros for GPIO modes ... and replace with a GPIO bitmask generator macro instead. The short macro names in the original implementation were prone to collisions or other problems with user applications and library code. --- cpu/lpc11u34/include/periph_cpu.h | 33 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/cpu/lpc11u34/include/periph_cpu.h b/cpu/lpc11u34/include/periph_cpu.h index 0c791c3c68..076d949371 100644 --- a/cpu/lpc11u34/include/periph_cpu.h +++ b/cpu/lpc11u34/include/periph_cpu.h @@ -68,27 +68,32 @@ typedef uint16_t gpio_t; #define PWM_CHAN_NUMOF (3U) /** - * @brief Override the default GPIO mode values + * @brief Generate GPIO mode bitfields + * + * We use the following bits to encode the pin mode: + * - bit 0: 0 for input or 1 for output + * - bit 3: Pull-down resistor enable + * - bit 4: Pull-up resistor enable + * - bit 10: Open drain enable + */ +#define GPIO_MODE_BITS(pu, pd, od, out) ((pu << 4) | (pd << 3) | (od << 10) | out) + +#ifndef DOXYGEN +/** + * @brief Override GPIO modes * @{ */ -#define IN (0x0000) -#define OUT (0x0001) -#define PD (0x1 << 3) -#define PU (0x2 << 3) -#define OD (0x1 << 10) - #define HAVE_GPIO_MODE_T typedef enum { - GPIO_IN = (IN), /**< in without pull resistor */ - GPIO_IN_PD = (IN | PD), /**< in with pull-down */ - GPIO_IN_PU = (IN | PU), /**< in with pull-up */ - GPIO_OUT = (OUT), /**< push-pull output */ - GPIO_OD = (OUT | OD), /**< open-drain output */ - GPIO_OD_PU = (OUT | OD | PU) /**< open-drain output with pull-up */ + GPIO_IN = GPIO_MODE_BITS(0, 0, 0, 0), /**< in without pull resistor */ + GPIO_IN_PD = GPIO_MODE_BITS(0, 1, 0, 0), /**< in with pull-down */ + GPIO_IN_PU = GPIO_MODE_BITS(1, 0, 0, 0), /**< in with pull-up */ + GPIO_OUT = GPIO_MODE_BITS(0, 0, 0, 1), /**< push-pull output */ + GPIO_OD = GPIO_MODE_BITS(0, 0, 1, 1), /**< open-drain output */ + GPIO_OD_PU = GPIO_MODE_BITS(1, 0, 1, 1), /**< open-drain output with pull-up */ } gpio_mode_t; /** @} */ -#ifndef DOXYGEN /** * @brief Override the ADC resolution settings * @{