|
ChibiOS/RT
2.5.1 |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, 00003 2011,2012 Giovanni Di Sirio. 00004 00005 This file is part of ChibiOS/RT. 00006 00007 ChibiOS/RT is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 ChibiOS/RT is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 /** 00022 * @file STM8S/pal_lld.h 00023 * @brief STM8S GPIO low level driver header. 00024 * 00025 * @addtogroup PAL 00026 * @{ 00027 */ 00028 00029 #ifndef _PAL_LLD_H_ 00030 #define _PAL_LLD_H_ 00031 00032 #if HAL_USE_PAL || defined(__DOXYGEN__) 00033 00034 /*===========================================================================*/ 00035 /* Unsupported modes and specific modes */ 00036 /*===========================================================================*/ 00037 00038 #undef PAL_MODE_INPUT_PULLDOWN 00039 00040 /** 00041 * @brief STM8S specific alternate push-pull slow output mode. 00042 */ 00043 #define PAL_MODE_OUTPUT_PUSHPULL_SLOW 16 00044 00045 /** 00046 * @brief STM8S specific alternate open-drain slow output mode. 00047 */ 00048 #define PAL_MODE_OUTPUT_OPENDRAIN_SLOW 17 00049 00050 /*===========================================================================*/ 00051 /* I/O Ports Types and constants. */ 00052 /*===========================================================================*/ 00053 00054 /** 00055 * @brief Generic I/O ports static initializer. 00056 * @details An instance of this structure must be passed to @p palInit() at 00057 * system startup time in order to initialized the digital I/O 00058 * subsystem. This represents only the initial setup, specific pads 00059 * or whole ports can be reprogrammed at later time. 00060 */ 00061 typedef struct { 00062 #if defined(STM8S105) || defined(__DOXYGEN__) 00063 GPIO_TypeDef P[7]; 00064 #elif defined(STM8S207) || defined(STM8S208) 00065 GPIO_TypeDef P[9]; 00066 #else 00067 GPIO_TypeDef P[6]; 00068 #endif 00069 } PALConfig; 00070 00071 /** 00072 * @brief Width, in bits, of an I/O port. 00073 */ 00074 #define PAL_IOPORTS_WIDTH 8 00075 00076 /** 00077 * @brief Whole port mask. 00078 * @brief This macro specifies all the valid bits into a port. 00079 */ 00080 #define PAL_WHOLE_PORT ((ioportmask_t)0xFF) 00081 00082 /** 00083 * @brief Digital I/O port sized unsigned type. 00084 */ 00085 typedef uint8_t ioportmask_t; 00086 00087 /** 00088 * @brief Digital I/O modes. 00089 */ 00090 typedef uint8_t iomode_t; 00091 00092 /** 00093 * @brief Port Identifier. 00094 */ 00095 typedef GPIO_TypeDef *ioportid_t; 00096 00097 /*===========================================================================*/ 00098 /* I/O Ports Identifiers. */ 00099 /*===========================================================================*/ 00100 00101 /** 00102 * @brief GPIO ports as a whole. 00103 */ 00104 #define IOPORTS ((PALConfig *)0x5000) 00105 00106 /** 00107 * @brief GPIO port A identifier. 00108 */ 00109 #define IOPORT1 GPIOA 00110 00111 /** 00112 * @brief GPIO port B identifier. 00113 */ 00114 #define IOPORT2 GPIOB 00115 00116 /** 00117 * @brief GPIO port C identifier. 00118 */ 00119 #define IOPORT3 GPIOC 00120 00121 /** 00122 * @brief GPIO port D identifier. 00123 */ 00124 #define IOPORT4 GPIOD 00125 00126 /** 00127 * @brief GPIO port E identifier. 00128 */ 00129 #define IOPORT5 GPIOE 00130 00131 /** 00132 * @brief GPIO port F identifier. 00133 */ 00134 #define IOPORT6 GPIOF 00135 00136 #if defined(STM8S207) || defined(STM8S208) || defined(STM8S105) || \ 00137 defined(__DOXYGEN__) 00138 /** 00139 * @brief GPIO port G identifier. 00140 */ 00141 #define IOPORT7 GPIOG 00142 #endif 00143 00144 #if defined(STM8S207) || defined(STM8S208) || defined(__DOXYGEN__) 00145 /** 00146 * @brief GPIO port H identifier. 00147 */ 00148 #define IOPORT8 GPIOH 00149 00150 /** 00151 * @brief GPIO port I identifier. 00152 */ 00153 #define IOPORT9 GPIOI 00154 #endif 00155 00156 /*===========================================================================*/ 00157 /* Implementation, some of the following macros could be implemented as */ 00158 /* functions, if so please put them in pal_lld.c. */ 00159 /*===========================================================================*/ 00160 00161 /** 00162 * @brief Low level PAL subsystem initialization. 00163 * 00164 * @param[in] config architecture-dependent ports configuration 00165 * 00166 * @notapi 00167 */ 00168 #define pal_lld_init(config) (*IOPORTS = *(config)) 00169 00170 /** 00171 * @brief Reads the physical I/O port states. 00172 * 00173 * @param[in] port port identifier 00174 * @return The port bits. 00175 * 00176 * @notapi 00177 */ 00178 #define pal_lld_readport(port) ((port)->IDR) 00179 00180 /** 00181 * @brief Reads the output latch. 00182 * @details The purpose of this function is to read back the latched output 00183 * value. 00184 * 00185 * @param[in] port port identifier 00186 * @return The latched logical states. 00187 * 00188 * @notapi 00189 */ 00190 #define pal_lld_readlatch(port) ((port)->ODR) 00191 00192 /** 00193 * @brief Writes a bits mask on a I/O port. 00194 * 00195 * @param[in] port port identifier 00196 * @param[in] bits bits to be written on the specified port 00197 * 00198 * @notapi 00199 */ 00200 #define pal_lld_writeport(port, bits) ((port)->ODR = (bits)) 00201 00202 /** 00203 * @brief Pads group mode setup. 00204 * @details This function programs a pads group belonging to the same port 00205 * with the specified mode. 00206 * 00207 * @param[in] port port identifier 00208 * @param[in] mask group mask 00209 * @param[in] offset group bit offset within the port 00210 * @param[in] mode group mode 00211 * 00212 * @notapi 00213 */ 00214 #define pal_lld_setgroupmode(port, mask, offset, mode) \ 00215 _pal_lld_setgroupmode(port, mask << offset, mode) 00216 00217 extern ROMCONST PALConfig pal_default_config; 00218 00219 #ifdef __cplusplus 00220 extern "C" { 00221 #endif 00222 void _pal_lld_setgroupmode(ioportid_t port, 00223 ioportmask_t mask, 00224 iomode_t mode); 00225 #ifdef __cplusplus 00226 } 00227 #endif 00228 00229 #endif /* HAL_USE_PAL */ 00230 00231 #endif /* _PAL_LLD_H_ */ 00232 00233 /** @} */