2009-11-29 08:50:13 +00:00
|
|
|
/*
|
2011-03-18 18:38:08 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
|
|
|
2011 Giovanni Di Sirio.
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
This file is part of ChibiOS/RT.
|
|
|
|
|
|
|
|
ChibiOS/RT is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ChibiOS/RT is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2011-08-25 15:14:09 +00:00
|
|
|
* @file STM32/GPIOv1/pal_lld.h
|
|
|
|
* @brief STM32F1xx GPIO low level driver header.
|
2010-05-14 09:23:32 +00:00
|
|
|
*
|
2010-10-25 18:48:13 +00:00
|
|
|
* @addtogroup PAL
|
2009-11-29 08:50:13 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PAL_LLD_H_
|
|
|
|
#define _PAL_LLD_H_
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#if HAL_USE_PAL || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
2010-05-14 09:23:32 +00:00
|
|
|
/* Unsupported modes and specific modes */
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
2011-11-26 13:34:15 +00:00
|
|
|
/**
|
|
|
|
* @name STM32-specific I/O mode flags
|
|
|
|
* @{
|
|
|
|
*/
|
2009-12-18 11:42:05 +00:00
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief STM32 specific alternate push-pull output mode.
|
2009-12-18 11:42:05 +00:00
|
|
|
*/
|
|
|
|
#define PAL_MODE_STM32_ALTERNATE_PUSHPULL 16
|
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief STM32 specific alternate open-drain output mode.
|
2009-12-18 11:42:05 +00:00
|
|
|
*/
|
|
|
|
#define PAL_MODE_STM32_ALTERNATE_OPENDRAIN 17
|
2011-11-26 13:34:15 +00:00
|
|
|
/** @} */
|
2009-12-18 11:42:05 +00:00
|
|
|
|
2010-05-14 09:23:32 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* I/O Ports Types and constants. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief GPIO port setup info.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/** Initial value for ODR register.*/
|
|
|
|
uint32_t odr;
|
|
|
|
/** Initial value for CRL register.*/
|
|
|
|
uint32_t crl;
|
|
|
|
/** Initial value for CRH register.*/
|
|
|
|
uint32_t crh;
|
|
|
|
} stm32_gpio_setup_t;
|
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief STM32 GPIO static initializer.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details An instance of this structure must be passed to @p palInit() at
|
2009-12-08 08:28:49 +00:00
|
|
|
* system startup time in order to initialize the digital I/O
|
2009-11-29 08:50:13 +00:00
|
|
|
* subsystem. This represents only the initial setup, specific pads
|
|
|
|
* or whole ports can be reprogrammed at later time.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/** @brief Port A setup data.*/
|
|
|
|
stm32_gpio_setup_t PAData;
|
|
|
|
/** @brief Port B setup data.*/
|
|
|
|
stm32_gpio_setup_t PBData;
|
|
|
|
/** @brief Port C setup data.*/
|
|
|
|
stm32_gpio_setup_t PCData;
|
|
|
|
/** @brief Port D setup data.*/
|
|
|
|
stm32_gpio_setup_t PDData;
|
2010-11-14 13:29:09 +00:00
|
|
|
#if STM32_HAS_GPIOE || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
/** @brief Port E setup data.*/
|
|
|
|
stm32_gpio_setup_t PEData;
|
2010-11-14 13:29:09 +00:00
|
|
|
#if STM32_HAS_GPIOF || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
/** @brief Port F setup data.*/
|
|
|
|
stm32_gpio_setup_t PFData;
|
2010-11-14 13:29:09 +00:00
|
|
|
#if STM32_HAS_GPIOG || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
/** @brief Port G setup data.*/
|
|
|
|
stm32_gpio_setup_t PGData;
|
|
|
|
#endif
|
2010-11-14 13:29:09 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2010-05-14 09:50:43 +00:00
|
|
|
} PALConfig;
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief Width, in bits, of an I/O port.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
#define PAL_IOPORTS_WIDTH 16
|
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief Whole port mask.
|
2010-10-04 17:16:18 +00:00
|
|
|
* @details This macro specifies all the valid bits into a port.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
#define PAL_WHOLE_PORT ((ioportmask_t)0xFFFF)
|
|
|
|
|
|
|
|
/**
|
2010-02-21 07:24:53 +00:00
|
|
|
* @brief Digital I/O port sized unsigned type.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
typedef uint32_t ioportmask_t;
|
|
|
|
|
2011-06-20 19:03:17 +00:00
|
|
|
/**
|
|
|
|
* @brief Digital I/O modes.
|
|
|
|
*/
|
|
|
|
typedef uint32_t iomode_t;
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief Port Identifier.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details This type can be a scalar or some kind of pointer, do not make
|
|
|
|
* any assumption about it, use the provided macros when populating
|
2010-02-21 07:24:53 +00:00
|
|
|
* variables of this type.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
typedef GPIO_TypeDef * ioportid_t;
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* I/O Ports Identifiers. */
|
|
|
|
/* The low level driver wraps the definitions already present in the STM32 */
|
|
|
|
/* firmware library. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief GPIO port A identifier.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-11-14 13:29:09 +00:00
|
|
|
#if STM32_HAS_GPIOA || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
#define IOPORT1 GPIOA
|
2010-11-14 13:29:09 +00:00
|
|
|
#endif
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief GPIO port B identifier.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-11-14 13:29:09 +00:00
|
|
|
#if STM32_HAS_GPIOB || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
#define IOPORT2 GPIOB
|
2010-11-14 13:29:09 +00:00
|
|
|
#endif
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief GPIO port C identifier.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-11-14 13:29:09 +00:00
|
|
|
#if STM32_HAS_GPIOC || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
#define IOPORT3 GPIOC
|
2010-11-14 13:29:09 +00:00
|
|
|
#endif
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief GPIO port D identifier.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-11-14 13:29:09 +00:00
|
|
|
#if STM32_HAS_GPIOD || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
#define IOPORT4 GPIOD
|
2010-11-14 13:29:09 +00:00
|
|
|
#endif
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief GPIO port E identifier.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-11-14 13:29:09 +00:00
|
|
|
#if STM32_HAS_GPIOE || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
#define IOPORT5 GPIOE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief GPIO port F identifier.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-11-14 13:29:09 +00:00
|
|
|
#if STM32_HAS_GPIOF || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
#define IOPORT6 GPIOF
|
2010-11-14 13:29:09 +00:00
|
|
|
#endif
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief GPIO port G identifier.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-11-14 13:29:09 +00:00
|
|
|
#if STM32_HAS_GPIOG || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
#define IOPORT7 GPIOG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Implementation, some of the following macros could be implemented as */
|
|
|
|
/* functions, please put them in a file named ioports_lld.c if so. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief GPIO ports subsystem initialization.
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
#define pal_lld_init(config) _pal_lld_init(config)
|
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief Reads an I/O port.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details This function is implemented by reading the GPIO IDR register, the
|
|
|
|
* implementation has no side effects.
|
2010-05-14 09:23:32 +00:00
|
|
|
* @note This function is not meant to be invoked directly by the application
|
|
|
|
* code.
|
2009-11-29 08:50:13 +00:00
|
|
|
*
|
2011-12-31 10:07:43 +00:00
|
|
|
* @param[in] port port identifier
|
2010-05-14 09:23:32 +00:00
|
|
|
* @return The port bits.
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
#define pal_lld_readport(port) ((port)->IDR)
|
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief Reads the output latch.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details This function is implemented by reading the GPIO ODR register, the
|
|
|
|
* implementation has no side effects.
|
2010-05-14 09:23:32 +00:00
|
|
|
* @note This function is not meant to be invoked directly by the application
|
|
|
|
* code.
|
2009-11-29 08:50:13 +00:00
|
|
|
*
|
2011-12-31 10:07:43 +00:00
|
|
|
* @param[in] port port identifier
|
2010-05-14 09:23:32 +00:00
|
|
|
* @return The latched logical states.
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
#define pal_lld_readlatch(port) ((port)->ODR)
|
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief Writes on a I/O port.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details This function is implemented by writing the GPIO ODR register, the
|
|
|
|
* implementation has no side effects.
|
2010-05-14 09:23:32 +00:00
|
|
|
* @note Writing on pads programmed as pull-up or pull-down has the side
|
|
|
|
* effect to modify the resistor setting because the output latched
|
|
|
|
* data is used for the resistor selection.
|
2009-11-29 08:50:13 +00:00
|
|
|
*
|
2011-12-31 10:07:43 +00:00
|
|
|
* @param[in] port port identifier
|
|
|
|
* @param[in] bits bits to be written on the specified port
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
#define pal_lld_writeport(port, bits) ((port)->ODR = (bits))
|
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief Sets a bits mask on a I/O port.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details This function is implemented by writing the GPIO BSRR register, the
|
|
|
|
* implementation has no side effects.
|
2010-05-14 09:23:32 +00:00
|
|
|
* @note Writing on pads programmed as pull-up or pull-down has the side
|
|
|
|
* effect to modify the resistor setting because the output latched
|
|
|
|
* data is used for the resistor selection.
|
2009-11-29 08:50:13 +00:00
|
|
|
*
|
2011-12-31 10:07:43 +00:00
|
|
|
* @param[in] port port identifier
|
|
|
|
* @param[in] bits bits to be ORed on the specified port
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
#define pal_lld_setport(port, bits) ((port)->BSRR = (bits))
|
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief Clears a bits mask on a I/O port.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details This function is implemented by writing the GPIO BRR register, the
|
|
|
|
* implementation has no side effects.
|
2010-05-14 09:23:32 +00:00
|
|
|
* @note Writing on pads programmed as pull-up or pull-down has the side
|
|
|
|
* effect to modify the resistor setting because the output latched
|
|
|
|
* data is used for the resistor selection.
|
2009-11-29 08:50:13 +00:00
|
|
|
*
|
2011-12-31 10:07:43 +00:00
|
|
|
* @param[in] port port identifier
|
|
|
|
* @param[in] bits bits to be cleared on the specified port
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
#define pal_lld_clearport(port, bits) ((port)->BRR = (bits))
|
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief Writes a group of bits.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details This function is implemented by writing the GPIO BSRR register, the
|
|
|
|
* implementation has no side effects.
|
2010-05-14 09:23:32 +00:00
|
|
|
* @note Writing on pads programmed as pull-up or pull-down has the side
|
|
|
|
* effect to modify the resistor setting because the output latched
|
|
|
|
* data is used for the resistor selection.
|
2009-11-29 08:50:13 +00:00
|
|
|
*
|
2011-12-31 10:07:43 +00:00
|
|
|
* @param[in] port port identifier
|
|
|
|
* @param[in] mask group mask
|
2010-05-14 09:23:32 +00:00
|
|
|
* @param[in] offset the group bit offset within the port
|
2011-12-31 10:07:43 +00:00
|
|
|
* @param[in] bits bits to be written. Values exceeding the group
|
2010-05-14 09:23:32 +00:00
|
|
|
* width are masked.
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2011-04-03 11:29:27 +00:00
|
|
|
#define pal_lld_writegroup(port, mask, offset, bits) \
|
|
|
|
((port)->BSRR = ((~(bits) & (mask)) << (16 + (offset))) | \
|
|
|
|
(((bits) & (mask)) << (offset)))
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief Pads group mode setup.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details This function programs a pads group belonging to the same port
|
|
|
|
* with the specified mode.
|
2010-05-14 09:23:32 +00:00
|
|
|
* @note Writing on pads programmed as pull-up or pull-down has the side
|
|
|
|
* effect to modify the resistor setting because the output latched
|
|
|
|
* data is used for the resistor selection.
|
2009-11-29 08:50:13 +00:00
|
|
|
*
|
2011-12-31 10:07:43 +00:00
|
|
|
* @param[in] port port identifier
|
|
|
|
* @param[in] mask group mask
|
|
|
|
* @param[in] offset group bit offset within the port
|
|
|
|
* @param[in] mode group mode
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2011-12-31 10:07:43 +00:00
|
|
|
#define pal_lld_setgroupmode(port, mask, offset, mode) \
|
|
|
|
_pal_lld_setgroupmode(port, mask << offset, mode)
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
/**
|
2010-05-14 09:23:32 +00:00
|
|
|
* @brief Writes a logical state on an output pad.
|
|
|
|
* @note Writing on pads programmed as pull-up or pull-down has the side
|
|
|
|
* effect to modify the resistor setting because the output latched
|
|
|
|
* data is used for the resistor selection.
|
2009-11-29 08:50:13 +00:00
|
|
|
*
|
2011-12-31 10:07:43 +00:00
|
|
|
* @param[in] port port identifier
|
|
|
|
* @param[in] pad pad number within the port
|
2010-05-14 09:23:32 +00:00
|
|
|
* @param[in] bit logical value, the value must be @p PAL_LOW or
|
|
|
|
* @p PAL_HIGH
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
#define pal_lld_writepad(port, pad, bit) pal_lld_writegroup(port, 1, pad, bit)
|
|
|
|
|
2010-05-14 09:50:43 +00:00
|
|
|
extern const PALConfig pal_default_config;
|
2009-11-29 13:37:19 +00:00
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2010-05-14 09:50:43 +00:00
|
|
|
void _pal_lld_init(const PALConfig *config);
|
2009-11-29 08:50:13 +00:00
|
|
|
void _pal_lld_setgroupmode(ioportid_t port,
|
|
|
|
ioportmask_t mask,
|
2011-07-17 13:07:16 +00:00
|
|
|
iomode_t mode);
|
2009-11-29 08:50:13 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#endif /* HAL_USE_PAL */
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
#endif /* _PAL_LLD_H_ */
|
|
|
|
|
|
|
|
/** @} */
|