From b8c517e46d35e5c9691545eda8fe9b6c40d6943a Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Mon, 2 Nov 2015 10:07:40 +0000 Subject: Lines support in PAL driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8417 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/ports/STM32/LLD/GPIOv1/pal_lld.h | 64 ++++++++++++++++++++++++++------ os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h | 66 +++++++++++++++++++++++++++------ 2 files changed, 107 insertions(+), 23 deletions(-) (limited to 'os/hal/ports/STM32/LLD') diff --git a/os/hal/ports/STM32/LLD/GPIOv1/pal_lld.h b/os/hal/ports/STM32/LLD/GPIOv1/pal_lld.h index c083ca0ff..bf84466c3 100644 --- a/os/hal/ports/STM32/LLD/GPIOv1/pal_lld.h +++ b/os/hal/ports/STM32/LLD/GPIOv1/pal_lld.h @@ -50,6 +50,54 @@ /* I/O Ports Types and constants. */ /*===========================================================================*/ +/** + * @name Port related definitions + * @{ + */ +/** + * @brief Width, in bits, of an I/O port. + */ +#define PAL_IOPORTS_WIDTH 16 + +/** + * @brief Whole port mask. + * @details This macro specifies all the valid bits into a port. + */ +#define PAL_WHOLE_PORT ((ioportmask_t)0xFFFF) +/** @} */ + +/** + * @name Line handling macros + * @{ + */ +/** + * @brief Forms a line identifier. + * @details A port/pad pair are encoded into an @p ioline_t type. The encoding + * of this type is platform-dependent. + * @note In this driver the pad number is encoded in the lower 4 bits of + * the GPIO address which are guaranteed to be zero. + */ +#define PAL_LINE(port, pad) \ + ((ioline_t)((uint32_t)(port)) | ((uint32_t)(pad))) + +/** + * @brief Decodes a port identifier from a line identifier. + */ +#define PAL_PORT(line) \ + ((stm32_gpio_t *)(((uint32_t)(line)) & 0xFFFFFFF0U)) + +/** + * @brief Decodes a pad identifier from a line identifier. + */ +#define PAL_PAD(line) \ + ((uint32_t)((uint32_t)(line) & 0x0000000FU)) + +/** + * @brief Value identifying an invalid line. + */ +#define PAL_NOLINE 0U +/** @} */ + /** * @brief GPIO port setup info. */ @@ -92,17 +140,6 @@ typedef struct { #endif } PALConfig; -/** - * @brief Width, in bits, of an I/O port. - */ -#define PAL_IOPORTS_WIDTH 16 - -/** - * @brief Whole port mask. - * @details This macro specifies all the valid bits into a port. - */ -#define PAL_WHOLE_PORT ((ioportmask_t)0xFFFF) - /** * @brief Digital I/O port sized unsigned type. */ @@ -113,6 +150,11 @@ typedef uint32_t ioportmask_t; */ typedef uint32_t iomode_t; +/** + * @brief Type of an I/O line. + */ +typedef uint32_t ioline_t; + /** * @brief Port Identifier. * @details This type can be a scalar or some kind of pointer, do not make diff --git a/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h b/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h index a9f40b905..d17063564 100644 --- a/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h +++ b/os/hal/ports/STM32/LLD/GPIOv2/pal_lld.h @@ -167,6 +167,54 @@ /* I/O Ports Types and constants. */ /*===========================================================================*/ +/** + * @name Port related definitions + * @{ + */ +/** + * @brief Width, in bits, of an I/O port. + */ +#define PAL_IOPORTS_WIDTH 16 + +/** + * @brief Whole port mask. + * @details This macro specifies all the valid bits into a port. + */ +#define PAL_WHOLE_PORT ((ioportmask_t)0xFFFF) +/** @} */ + +/** + * @name Line handling macros + * @{ + */ +/** + * @brief Forms a line identifier. + * @details A port/pad pair are encoded into an @p ioline_t type. The encoding + * of this type is platform-dependent. + * @note In this driver the pad number is encoded in the lower 4 bits of + * the GPIO address which are guaranteed to be zero. + */ +#define PAL_LINE(port, pad) \ + ((ioline_t)((uint32_t)(port)) | ((uint32_t)(pad))) + +/** + * @brief Decodes a port identifier from a line identifier. + */ +#define PAL_PORT(line) \ + ((stm32_gpio_t *)(((uint32_t)(line)) & 0xFFFFFFF0U)) + +/** + * @brief Decodes a pad identifier from a line identifier. + */ +#define PAL_PAD(line) \ + ((uint32_t)((uint32_t)(line) & 0x0000000FU)) + +/** + * @brief Value identifying an invalid line. + */ +#define PAL_NOLINE 0U +/** @} */ + /** * @brief STM32 GPIO registers block. */ @@ -266,25 +314,19 @@ typedef struct { } PALConfig; /** - * @brief Width, in bits, of an I/O port. + * @brief Type of digital I/O port sized unsigned integer. */ -#define PAL_IOPORTS_WIDTH 16 - -/** - * @brief Whole port mask. - * @details This macro specifies all the valid bits into a port. - */ -#define PAL_WHOLE_PORT ((ioportmask_t)0xFFFF) +typedef uint32_t ioportmask_t; /** - * @brief Digital I/O port sized unsigned type. + * @brief Type of digital I/O modes. */ -typedef uint32_t ioportmask_t; +typedef uint32_t iomode_t; /** - * @brief Digital I/O modes. + * @brief Type of an I/O line. */ -typedef uint32_t iomode_t; +typedef uint32_t ioline_t; /** * @brief Port Identifier. -- cgit v1.2.3