From 0e5b18635b944f77ecbd21c6e678a2033b94b0d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Thu, 17 Nov 2016 17:44:18 +0100 Subject: [PATCH] cc2538: gpio: Add macro to get pin direction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/dev/gpio.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cpu/cc2538/dev/gpio.h b/cpu/cc2538/dev/gpio.h index e97ba2825..00ee1b1dc 100644 --- a/cpu/cc2538/dev/gpio.h +++ b/cpu/cc2538/dev/gpio.h @@ -100,6 +100,20 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin); #define GPIO_SET_OUTPUT(PORT_BASE, PIN_MASK) \ do { REG((PORT_BASE) + GPIO_DIR) |= (PIN_MASK); } while(0) +/** \brief Return whether pins with PIN_MASK of port with PORT_BASE are set to + * output. + * \param PORT_BASE GPIO Port register offset + * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80 + * \return The direction of the pins specified by PIN_MASK + * + * This macro will \e not return 0 or 1. Instead, it will return the directions + * of the pins specified by PIN_MASK ORed together. Thus, if 0xC3 + * (0x80 | 0x40 | 0x02 | 0x01) is passed as the PIN_MASK and pins 7 and 0 are + * set to output, the macro will return 0x81. + */ +#define GPIO_IS_OUTPUT(PORT_BASE, PIN_MASK) \ + (REG((PORT_BASE) + GPIO_DIR) & (PIN_MASK)) + /** \brief Set pins with PIN_MASK of port with PORT_BASE high. * \param PORT_BASE GPIO Port register offset * \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80