NXP's driver library for LPC17xx, ported to mbed's online compiler. Not tested! I had to fix a lot of warings and found a couple of pretty obvious bugs, so the chances are there are more. Original: http://ics.nxp.com/support/documents/microcontrollers/zip/lpc17xx.cmsis.driver.library.zip

Dependencies:   mbed

Committer:
igorsk
Date:
Wed Feb 17 16:22:39 2010 +0000
Revision:
0:1063a091a062

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
igorsk 0:1063a091a062 1 /**
igorsk 0:1063a091a062 2 * @file : lpc17xx_gpio.c
igorsk 0:1063a091a062 3 * @brief : Contains all functions support for GPIO firmware library on LPC17xx
igorsk 0:1063a091a062 4 * @version : 1.0
igorsk 0:1063a091a062 5 * @date : 11. Jun. 2009
igorsk 0:1063a091a062 6 * @author : HieuNguyen
igorsk 0:1063a091a062 7 **************************************************************************
igorsk 0:1063a091a062 8 * Software that is described herein is for illustrative purposes only
igorsk 0:1063a091a062 9 * which provides customers with programming information regarding the
igorsk 0:1063a091a062 10 * products. This software is supplied "AS IS" without any warranties.
igorsk 0:1063a091a062 11 * NXP Semiconductors assumes no responsibility or liability for the
igorsk 0:1063a091a062 12 * use of the software, conveys no license or title under any patent,
igorsk 0:1063a091a062 13 * copyright, or mask work right to the product. NXP Semiconductors
igorsk 0:1063a091a062 14 * reserves the right to make changes in the software without
igorsk 0:1063a091a062 15 * notification. NXP Semiconductors also make no representation or
igorsk 0:1063a091a062 16 * warranty that such application will be suitable for the specified
igorsk 0:1063a091a062 17 * use without further testing or modification.
igorsk 0:1063a091a062 18 **********************************************************************/
igorsk 0:1063a091a062 19
igorsk 0:1063a091a062 20 /* Peripheral group ----------------------------------------------------------- */
igorsk 0:1063a091a062 21 /** @addtogroup GPIO
igorsk 0:1063a091a062 22 * @{
igorsk 0:1063a091a062 23 */
igorsk 0:1063a091a062 24
igorsk 0:1063a091a062 25 /* Includes ------------------------------------------------------------------- */
igorsk 0:1063a091a062 26 #include "lpc17xx_gpio.h"
igorsk 0:1063a091a062 27
igorsk 0:1063a091a062 28 /* If this source file built with example, the LPC17xx FW library configuration
igorsk 0:1063a091a062 29 * file in each example directory ("lpc17xx_libcfg.h") must be included,
igorsk 0:1063a091a062 30 * otherwise the default FW library configuration file must be included instead
igorsk 0:1063a091a062 31 */
igorsk 0:1063a091a062 32 #ifdef __BUILD_WITH_EXAMPLE__
igorsk 0:1063a091a062 33 #include "lpc17xx_libcfg.h"
igorsk 0:1063a091a062 34 #else
igorsk 0:1063a091a062 35 #include "lpc17xx_libcfg_default.h"
igorsk 0:1063a091a062 36 #endif /* __BUILD_WITH_EXAMPLE__ */
igorsk 0:1063a091a062 37
igorsk 0:1063a091a062 38
igorsk 0:1063a091a062 39 #ifdef _GPIO
igorsk 0:1063a091a062 40
igorsk 0:1063a091a062 41 /* Private Functions ---------------------------------------------------------- */
igorsk 0:1063a091a062 42 /** @addtogroup GPIO_Private_Functions
igorsk 0:1063a091a062 43 * @{
igorsk 0:1063a091a062 44 */
igorsk 0:1063a091a062 45 /*********************************************************************//**
igorsk 0:1063a091a062 46 * @brief Get pointer to GPIO peripheral due to GPIO port
igorsk 0:1063a091a062 47 * @param[in] portNum Port Number value, should be in range from 0 to 4.
igorsk 0:1063a091a062 48 * @return Pointer to GPIO peripheral
igorsk 0:1063a091a062 49 **********************************************************************/
igorsk 0:1063a091a062 50 static LPC_GPIO_TypeDef *GPIO_GetPointer(uint8_t portNum)
igorsk 0:1063a091a062 51 {
igorsk 0:1063a091a062 52 LPC_GPIO_TypeDef *pGPIO = NULL;
igorsk 0:1063a091a062 53
igorsk 0:1063a091a062 54 switch (portNum) {
igorsk 0:1063a091a062 55 case 0:
igorsk 0:1063a091a062 56 pGPIO = LPC_GPIO0;
igorsk 0:1063a091a062 57 break;
igorsk 0:1063a091a062 58 case 1:
igorsk 0:1063a091a062 59 pGPIO = LPC_GPIO1;
igorsk 0:1063a091a062 60 break;
igorsk 0:1063a091a062 61 case 2:
igorsk 0:1063a091a062 62 pGPIO = LPC_GPIO2;
igorsk 0:1063a091a062 63 break;
igorsk 0:1063a091a062 64 case 3:
igorsk 0:1063a091a062 65 pGPIO = LPC_GPIO3;
igorsk 0:1063a091a062 66 break;
igorsk 0:1063a091a062 67 case 4:
igorsk 0:1063a091a062 68 pGPIO = LPC_GPIO4;
igorsk 0:1063a091a062 69 break;
igorsk 0:1063a091a062 70 default:
igorsk 0:1063a091a062 71 break;
igorsk 0:1063a091a062 72 }
igorsk 0:1063a091a062 73
igorsk 0:1063a091a062 74 return pGPIO;
igorsk 0:1063a091a062 75 }
igorsk 0:1063a091a062 76
igorsk 0:1063a091a062 77 /*********************************************************************//**
igorsk 0:1063a091a062 78 * @brief Get pointer to FIO peripheral in halfword accessible style
igorsk 0:1063a091a062 79 * due to FIO port
igorsk 0:1063a091a062 80 * @param[in] portNum Port Number value, should be in range from 0 to 4.
igorsk 0:1063a091a062 81 * @return Pointer to FIO peripheral
igorsk 0:1063a091a062 82 **********************************************************************/
igorsk 0:1063a091a062 83 static GPIO_HalfWord_TypeDef *FIO_HalfWordGetPointer(uint8_t portNum)
igorsk 0:1063a091a062 84 {
igorsk 0:1063a091a062 85 GPIO_HalfWord_TypeDef *pFIO = NULL;
igorsk 0:1063a091a062 86
igorsk 0:1063a091a062 87 switch (portNum) {
igorsk 0:1063a091a062 88 case 0:
igorsk 0:1063a091a062 89 pFIO = GPIO0_HalfWord;
igorsk 0:1063a091a062 90 break;
igorsk 0:1063a091a062 91 case 1:
igorsk 0:1063a091a062 92 pFIO = GPIO1_HalfWord;
igorsk 0:1063a091a062 93 break;
igorsk 0:1063a091a062 94 case 2:
igorsk 0:1063a091a062 95 pFIO = GPIO2_HalfWord;
igorsk 0:1063a091a062 96 break;
igorsk 0:1063a091a062 97 case 3:
igorsk 0:1063a091a062 98 pFIO = GPIO3_HalfWord;
igorsk 0:1063a091a062 99 break;
igorsk 0:1063a091a062 100 case 4:
igorsk 0:1063a091a062 101 pFIO = GPIO4_HalfWord;
igorsk 0:1063a091a062 102 break;
igorsk 0:1063a091a062 103 default:
igorsk 0:1063a091a062 104 break;
igorsk 0:1063a091a062 105 }
igorsk 0:1063a091a062 106
igorsk 0:1063a091a062 107 return pFIO;
igorsk 0:1063a091a062 108 }
igorsk 0:1063a091a062 109
igorsk 0:1063a091a062 110 /*********************************************************************//**
igorsk 0:1063a091a062 111 * @brief Get pointer to FIO peripheral in byte accessible style
igorsk 0:1063a091a062 112 * due to FIO port
igorsk 0:1063a091a062 113 * @param[in] portNum Port Number value, should be in range from 0 to 4.
igorsk 0:1063a091a062 114 * @return Pointer to FIO peripheral
igorsk 0:1063a091a062 115 **********************************************************************/
igorsk 0:1063a091a062 116 static GPIO_Byte_TypeDef *FIO_ByteGetPointer(uint8_t portNum)
igorsk 0:1063a091a062 117 {
igorsk 0:1063a091a062 118 GPIO_Byte_TypeDef *pFIO = NULL;
igorsk 0:1063a091a062 119
igorsk 0:1063a091a062 120 switch (portNum) {
igorsk 0:1063a091a062 121 case 0:
igorsk 0:1063a091a062 122 pFIO = GPIO0_Byte;
igorsk 0:1063a091a062 123 break;
igorsk 0:1063a091a062 124 case 1:
igorsk 0:1063a091a062 125 pFIO = GPIO1_Byte;
igorsk 0:1063a091a062 126 break;
igorsk 0:1063a091a062 127 case 2:
igorsk 0:1063a091a062 128 pFIO = GPIO2_Byte;
igorsk 0:1063a091a062 129 break;
igorsk 0:1063a091a062 130 case 3:
igorsk 0:1063a091a062 131 pFIO = GPIO3_Byte;
igorsk 0:1063a091a062 132 break;
igorsk 0:1063a091a062 133 case 4:
igorsk 0:1063a091a062 134 pFIO = GPIO4_Byte;
igorsk 0:1063a091a062 135 break;
igorsk 0:1063a091a062 136 default:
igorsk 0:1063a091a062 137 break;
igorsk 0:1063a091a062 138 }
igorsk 0:1063a091a062 139
igorsk 0:1063a091a062 140 return pFIO;
igorsk 0:1063a091a062 141 }
igorsk 0:1063a091a062 142
igorsk 0:1063a091a062 143 /**
igorsk 0:1063a091a062 144 * @}
igorsk 0:1063a091a062 145 */
igorsk 0:1063a091a062 146
igorsk 0:1063a091a062 147
igorsk 0:1063a091a062 148 /* Public Functions ----------------------------------------------------------- */
igorsk 0:1063a091a062 149 /** @addtogroup GPIO_Public_Functions
igorsk 0:1063a091a062 150 * @{
igorsk 0:1063a091a062 151 */
igorsk 0:1063a091a062 152
igorsk 0:1063a091a062 153
igorsk 0:1063a091a062 154 /* GPIO ------------------------------------------------------------------------------ */
igorsk 0:1063a091a062 155
igorsk 0:1063a091a062 156 /*********************************************************************//**
igorsk 0:1063a091a062 157 * @brief Set Direction for GPIO port.
igorsk 0:1063a091a062 158 * @param[in] portNum Port Number value, should be in range from 0 to 4
igorsk 0:1063a091a062 159 * @param[in] bitValue Value that contains all bits to set direction,
igorsk 0:1063a091a062 160 * in range from 0 to 0xFFFFFFFF.
igorsk 0:1063a091a062 161 * example: value 0x5 to set direction for bit 0 and bit 1.
igorsk 0:1063a091a062 162 * @param[in] dir Direction value, should be:
igorsk 0:1063a091a062 163 * - 0: Input.
igorsk 0:1063a091a062 164 * - 1: Output.
igorsk 0:1063a091a062 165 * @return None
igorsk 0:1063a091a062 166 *
igorsk 0:1063a091a062 167 * Note: All remaining bits that are not activated in bitValue (value '0')
igorsk 0:1063a091a062 168 * will not be effected by this function.
igorsk 0:1063a091a062 169 **********************************************************************/
igorsk 0:1063a091a062 170 void GPIO_SetDir(uint8_t portNum, uint32_t bitValue, uint8_t dir)
igorsk 0:1063a091a062 171 {
igorsk 0:1063a091a062 172 LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);
igorsk 0:1063a091a062 173
igorsk 0:1063a091a062 174 if (pGPIO != NULL) {
igorsk 0:1063a091a062 175 // Enable Output
igorsk 0:1063a091a062 176 if (dir) {
igorsk 0:1063a091a062 177 pGPIO->FIODIR |= bitValue;
igorsk 0:1063a091a062 178 }
igorsk 0:1063a091a062 179 // Enable Input
igorsk 0:1063a091a062 180 else {
igorsk 0:1063a091a062 181 pGPIO->FIODIR &= ~bitValue;
igorsk 0:1063a091a062 182 }
igorsk 0:1063a091a062 183 }
igorsk 0:1063a091a062 184 }
igorsk 0:1063a091a062 185
igorsk 0:1063a091a062 186
igorsk 0:1063a091a062 187 /*********************************************************************//**
igorsk 0:1063a091a062 188 * @brief Set Value for bits that have output direction on GPIO port.
igorsk 0:1063a091a062 189 * @param[in] portNum Port number value, should be in range from 0 to 4
igorsk 0:1063a091a062 190 * @param[in] bitValue Value that contains all bits on GPIO to set,
igorsk 0:1063a091a062 191 * in range from 0 to 0xFFFFFFFF.
igorsk 0:1063a091a062 192 * example: value 0x5 to set bit 0 and bit 1.
igorsk 0:1063a091a062 193 * @return None
igorsk 0:1063a091a062 194 *
igorsk 0:1063a091a062 195 * Note:
igorsk 0:1063a091a062 196 * - For all bits that has been set as input direction, this function will
igorsk 0:1063a091a062 197 * not effect.
igorsk 0:1063a091a062 198 * - For all remaining bits that are not activated in bitValue (value '0')
igorsk 0:1063a091a062 199 * will not be effected by this function.
igorsk 0:1063a091a062 200 **********************************************************************/
igorsk 0:1063a091a062 201 void GPIO_SetValue(uint8_t portNum, uint32_t bitValue)
igorsk 0:1063a091a062 202 {
igorsk 0:1063a091a062 203 LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);
igorsk 0:1063a091a062 204
igorsk 0:1063a091a062 205 if (pGPIO != NULL) {
igorsk 0:1063a091a062 206 pGPIO->FIOSET = bitValue;
igorsk 0:1063a091a062 207 }
igorsk 0:1063a091a062 208 }
igorsk 0:1063a091a062 209
igorsk 0:1063a091a062 210 /*********************************************************************//**
igorsk 0:1063a091a062 211 * @brief Clear Value for bits that have output direction on GPIO port.
igorsk 0:1063a091a062 212 * @param[in] portNum Port number value, should be in range from 0 to 4
igorsk 0:1063a091a062 213 * @param[in] bitValue Value that contains all bits on GPIO to clear,
igorsk 0:1063a091a062 214 * in range from 0 to 0xFFFFFFFF.
igorsk 0:1063a091a062 215 * example: value 0x5 to clear bit 0 and bit 1.
igorsk 0:1063a091a062 216 * @return None
igorsk 0:1063a091a062 217 *
igorsk 0:1063a091a062 218 * Note:
igorsk 0:1063a091a062 219 * - For all bits that has been set as input direction, this function will
igorsk 0:1063a091a062 220 * not effect.
igorsk 0:1063a091a062 221 * - For all remaining bits that are not activated in bitValue (value '0')
igorsk 0:1063a091a062 222 * will not be effected by this function.
igorsk 0:1063a091a062 223 **********************************************************************/
igorsk 0:1063a091a062 224 void GPIO_ClearValue(uint8_t portNum, uint32_t bitValue)
igorsk 0:1063a091a062 225 {
igorsk 0:1063a091a062 226 LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);
igorsk 0:1063a091a062 227
igorsk 0:1063a091a062 228 if (pGPIO != NULL) {
igorsk 0:1063a091a062 229 pGPIO->FIOCLR = bitValue;
igorsk 0:1063a091a062 230 }
igorsk 0:1063a091a062 231 }
igorsk 0:1063a091a062 232
igorsk 0:1063a091a062 233 /*********************************************************************//**
igorsk 0:1063a091a062 234 * @brief Read Current state on port pin that have input direction of GPIO
igorsk 0:1063a091a062 235 * @param[in] portNum Port number to read value, in range from 0 to 4
igorsk 0:1063a091a062 236 * @return Current value of GPIO port.
igorsk 0:1063a091a062 237 *
igorsk 0:1063a091a062 238 * Note: Return value contain state of each port pin (bit) on that GPIO regardless
igorsk 0:1063a091a062 239 * its direction is input or output.
igorsk 0:1063a091a062 240 **********************************************************************/
igorsk 0:1063a091a062 241 uint32_t GPIO_ReadValue(uint8_t portNum)
igorsk 0:1063a091a062 242 {
igorsk 0:1063a091a062 243 LPC_GPIO_TypeDef *pGPIO = GPIO_GetPointer(portNum);
igorsk 0:1063a091a062 244
igorsk 0:1063a091a062 245 if (pGPIO != NULL) {
igorsk 0:1063a091a062 246 return pGPIO->FIOPIN;
igorsk 0:1063a091a062 247 }
igorsk 0:1063a091a062 248
igorsk 0:1063a091a062 249 return (0);
igorsk 0:1063a091a062 250 }
igorsk 0:1063a091a062 251
igorsk 0:1063a091a062 252 /* FIO word accessible ----------------------------------------------------------------- */
igorsk 0:1063a091a062 253 /* Stub function for FIO (word-accessible) style */
igorsk 0:1063a091a062 254
igorsk 0:1063a091a062 255 /**
igorsk 0:1063a091a062 256 * @brief The same with GPIO_SetDir()
igorsk 0:1063a091a062 257 */
igorsk 0:1063a091a062 258 void FIO_SetDir(uint8_t portNum, uint32_t bitValue, uint8_t dir)
igorsk 0:1063a091a062 259 {
igorsk 0:1063a091a062 260 GPIO_SetDir(portNum, bitValue, dir);
igorsk 0:1063a091a062 261 }
igorsk 0:1063a091a062 262
igorsk 0:1063a091a062 263 /**
igorsk 0:1063a091a062 264 * @brief The same with GPIO_SetValue()
igorsk 0:1063a091a062 265 */
igorsk 0:1063a091a062 266 void FIO_SetValue(uint8_t portNum, uint32_t bitValue)
igorsk 0:1063a091a062 267 {
igorsk 0:1063a091a062 268 GPIO_SetValue(portNum, bitValue);
igorsk 0:1063a091a062 269 }
igorsk 0:1063a091a062 270
igorsk 0:1063a091a062 271 /**
igorsk 0:1063a091a062 272 * @brief The same with GPIO_ClearValue()
igorsk 0:1063a091a062 273 */
igorsk 0:1063a091a062 274 void FIO_ClearValue(uint8_t portNum, uint32_t bitValue)
igorsk 0:1063a091a062 275 {
igorsk 0:1063a091a062 276 GPIO_ClearValue(portNum, bitValue);
igorsk 0:1063a091a062 277 }
igorsk 0:1063a091a062 278
igorsk 0:1063a091a062 279 /**
igorsk 0:1063a091a062 280 * @brief The same with GPIO_ReadValue()
igorsk 0:1063a091a062 281 */
igorsk 0:1063a091a062 282 uint32_t FIO_ReadValue(uint8_t portNum)
igorsk 0:1063a091a062 283 {
igorsk 0:1063a091a062 284 return (GPIO_ReadValue(portNum));
igorsk 0:1063a091a062 285 }
igorsk 0:1063a091a062 286
igorsk 0:1063a091a062 287
igorsk 0:1063a091a062 288 /*********************************************************************//**
igorsk 0:1063a091a062 289 * @brief Set mask value for bits in FIO port
igorsk 0:1063a091a062 290 * @param[in] portNum Port number, in range from 0 to 4
igorsk 0:1063a091a062 291 * @param[in] bitValue Value that contains all bits in to set,
igorsk 0:1063a091a062 292 * in range from 0 to 0xFFFFFFFF.
igorsk 0:1063a091a062 293 * @param[in] maskValue Mask value contains state value for each bit:
igorsk 0:1063a091a062 294 * - 0: not mask.
igorsk 0:1063a091a062 295 * - 1: mask.
igorsk 0:1063a091a062 296 * @return None
igorsk 0:1063a091a062 297 *
igorsk 0:1063a091a062 298 * Note:
igorsk 0:1063a091a062 299 * - All remaining bits that are not activated in bitValue (value '0')
igorsk 0:1063a091a062 300 * will not be effected by this function.
igorsk 0:1063a091a062 301 * - After executing this function, in mask register, value '0' on each bit
igorsk 0:1063a091a062 302 * enables an access to the corresponding physical pin via a read or write access,
igorsk 0:1063a091a062 303 * while value '1' on bit (masked) that corresponding pin will not be changed
igorsk 0:1063a091a062 304 * with write access and if read, will not be reflected in the updated pin.
igorsk 0:1063a091a062 305 **********************************************************************/
igorsk 0:1063a091a062 306 void FIO_SetMask(uint8_t portNum, uint32_t bitValue, uint8_t maskValue)
igorsk 0:1063a091a062 307 {
igorsk 0:1063a091a062 308 LPC_GPIO_TypeDef *pFIO = GPIO_GetPointer(portNum);
igorsk 0:1063a091a062 309 if(pFIO != NULL) {
igorsk 0:1063a091a062 310 // Mask
igorsk 0:1063a091a062 311 if (maskValue){
igorsk 0:1063a091a062 312 pFIO->FIOMASK |= bitValue;
igorsk 0:1063a091a062 313 }
igorsk 0:1063a091a062 314 // Un-mask
igorsk 0:1063a091a062 315 else {
igorsk 0:1063a091a062 316 pFIO->FIOMASK &= ~bitValue;
igorsk 0:1063a091a062 317 }
igorsk 0:1063a091a062 318 }
igorsk 0:1063a091a062 319 }
igorsk 0:1063a091a062 320
igorsk 0:1063a091a062 321
igorsk 0:1063a091a062 322 /* FIO halfword accessible ------------------------------------------------------------- */
igorsk 0:1063a091a062 323
igorsk 0:1063a091a062 324 /*********************************************************************//**
igorsk 0:1063a091a062 325 * @brief Set direction for FIO port in halfword accessible style
igorsk 0:1063a091a062 326 * @param[in] portNum Port number, in range from 0 to 4
igorsk 0:1063a091a062 327 * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
igorsk 0:1063a091a062 328 * @param[in] bitValue Value that contains all bits in to set direction,
igorsk 0:1063a091a062 329 * in range from 0 to 0xFFFF.
igorsk 0:1063a091a062 330 * @param[in] dir Direction value, should be:
igorsk 0:1063a091a062 331 * - 0: Input.
igorsk 0:1063a091a062 332 * - 1: Output.
igorsk 0:1063a091a062 333 * @return None
igorsk 0:1063a091a062 334 *
igorsk 0:1063a091a062 335 * Note: All remaining bits that are not activated in bitValue (value '0')
igorsk 0:1063a091a062 336 * will not be effected by this function.
igorsk 0:1063a091a062 337 **********************************************************************/
igorsk 0:1063a091a062 338 void FIO_HalfWordSetDir(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue, uint8_t dir)
igorsk 0:1063a091a062 339 {
igorsk 0:1063a091a062 340 GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
igorsk 0:1063a091a062 341 if(pFIO != NULL) {
igorsk 0:1063a091a062 342 // Output direction
igorsk 0:1063a091a062 343 if (dir) {
igorsk 0:1063a091a062 344 // Upper
igorsk 0:1063a091a062 345 if(halfwordNum) {
igorsk 0:1063a091a062 346 pFIO->FIODIRU |= bitValue;
igorsk 0:1063a091a062 347 }
igorsk 0:1063a091a062 348 // lower
igorsk 0:1063a091a062 349 else {
igorsk 0:1063a091a062 350 pFIO->FIODIRL |= bitValue;
igorsk 0:1063a091a062 351 }
igorsk 0:1063a091a062 352 }
igorsk 0:1063a091a062 353 // Input direction
igorsk 0:1063a091a062 354 else {
igorsk 0:1063a091a062 355 // Upper
igorsk 0:1063a091a062 356 if(halfwordNum) {
igorsk 0:1063a091a062 357 pFIO->FIODIRU &= ~bitValue;
igorsk 0:1063a091a062 358 }
igorsk 0:1063a091a062 359 // lower
igorsk 0:1063a091a062 360 else {
igorsk 0:1063a091a062 361 pFIO->FIODIRL &= ~bitValue;
igorsk 0:1063a091a062 362 }
igorsk 0:1063a091a062 363 }
igorsk 0:1063a091a062 364 }
igorsk 0:1063a091a062 365 }
igorsk 0:1063a091a062 366
igorsk 0:1063a091a062 367
igorsk 0:1063a091a062 368 /*********************************************************************//**
igorsk 0:1063a091a062 369 * @brief Set mask value for bits in FIO port in halfword accessible style
igorsk 0:1063a091a062 370 * @param[in] portNum Port number, in range from 0 to 4
igorsk 0:1063a091a062 371 * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
igorsk 0:1063a091a062 372 * @param[in] bitValue Value that contains all bits in to set,
igorsk 0:1063a091a062 373 * in range from 0 to 0xFFFF.
igorsk 0:1063a091a062 374 * @param[in] maskValue Mask value contains state value for each bit:
igorsk 0:1063a091a062 375 * - 0: not mask.
igorsk 0:1063a091a062 376 * - 1: mask.
igorsk 0:1063a091a062 377 * @return None
igorsk 0:1063a091a062 378 *
igorsk 0:1063a091a062 379 * Note:
igorsk 0:1063a091a062 380 * - All remaining bits that are not activated in bitValue (value '0')
igorsk 0:1063a091a062 381 * will not be effected by this function.
igorsk 0:1063a091a062 382 * - After executing this function, in mask register, value '0' on each bit
igorsk 0:1063a091a062 383 * enables an access to the corresponding physical pin via a read or write access,
igorsk 0:1063a091a062 384 * while value '1' on bit (masked) that corresponding pin will not be changed
igorsk 0:1063a091a062 385 * with write access and if read, will not be reflected in the updated pin.
igorsk 0:1063a091a062 386 **********************************************************************/
igorsk 0:1063a091a062 387 void FIO_HalfWordSetMask(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue, uint8_t maskValue)
igorsk 0:1063a091a062 388 {
igorsk 0:1063a091a062 389 GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
igorsk 0:1063a091a062 390 if(pFIO != NULL) {
igorsk 0:1063a091a062 391 // Mask
igorsk 0:1063a091a062 392 if (maskValue){
igorsk 0:1063a091a062 393 // Upper
igorsk 0:1063a091a062 394 if(halfwordNum) {
igorsk 0:1063a091a062 395 pFIO->FIOMASKU |= bitValue;
igorsk 0:1063a091a062 396 }
igorsk 0:1063a091a062 397 // lower
igorsk 0:1063a091a062 398 else {
igorsk 0:1063a091a062 399 pFIO->FIOMASKL |= bitValue;
igorsk 0:1063a091a062 400 }
igorsk 0:1063a091a062 401 }
igorsk 0:1063a091a062 402 // Un-mask
igorsk 0:1063a091a062 403 else {
igorsk 0:1063a091a062 404 // Upper
igorsk 0:1063a091a062 405 if(halfwordNum) {
igorsk 0:1063a091a062 406 pFIO->FIOMASKU &= ~bitValue;
igorsk 0:1063a091a062 407 }
igorsk 0:1063a091a062 408 // lower
igorsk 0:1063a091a062 409 else {
igorsk 0:1063a091a062 410 pFIO->FIOMASKL &= ~bitValue;
igorsk 0:1063a091a062 411 }
igorsk 0:1063a091a062 412 }
igorsk 0:1063a091a062 413 }
igorsk 0:1063a091a062 414 }
igorsk 0:1063a091a062 415
igorsk 0:1063a091a062 416
igorsk 0:1063a091a062 417 /*********************************************************************//**
igorsk 0:1063a091a062 418 * @brief Set bits for FIO port in halfword accessible style
igorsk 0:1063a091a062 419 * @param[in] portNum Port number, in range from 0 to 4
igorsk 0:1063a091a062 420 * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
igorsk 0:1063a091a062 421 * @param[in] bitValue Value that contains all bits in to set,
igorsk 0:1063a091a062 422 * in range from 0 to 0xFFFF.
igorsk 0:1063a091a062 423 * @return None
igorsk 0:1063a091a062 424 *
igorsk 0:1063a091a062 425 * Note:
igorsk 0:1063a091a062 426 * - For all bits that has been set as input direction, this function will
igorsk 0:1063a091a062 427 * not effect.
igorsk 0:1063a091a062 428 * - For all remaining bits that are not activated in bitValue (value '0')
igorsk 0:1063a091a062 429 * will not be effected by this function.
igorsk 0:1063a091a062 430 **********************************************************************/
igorsk 0:1063a091a062 431 void FIO_HalfWordSetValue(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue)
igorsk 0:1063a091a062 432 {
igorsk 0:1063a091a062 433 GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
igorsk 0:1063a091a062 434 if(pFIO != NULL) {
igorsk 0:1063a091a062 435 // Upper
igorsk 0:1063a091a062 436 if(halfwordNum) {
igorsk 0:1063a091a062 437 pFIO->FIOSETU = bitValue;
igorsk 0:1063a091a062 438 }
igorsk 0:1063a091a062 439 // lower
igorsk 0:1063a091a062 440 else {
igorsk 0:1063a091a062 441 pFIO->FIOSETL = bitValue;
igorsk 0:1063a091a062 442 }
igorsk 0:1063a091a062 443 }
igorsk 0:1063a091a062 444 }
igorsk 0:1063a091a062 445
igorsk 0:1063a091a062 446
igorsk 0:1063a091a062 447 /*********************************************************************//**
igorsk 0:1063a091a062 448 * @brief Clear bits for FIO port in halfword accessible style
igorsk 0:1063a091a062 449 * @param[in] portNum Port number, in range from 0 to 4
igorsk 0:1063a091a062 450 * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
igorsk 0:1063a091a062 451 * @param[in] bitValue Value that contains all bits in to clear,
igorsk 0:1063a091a062 452 * in range from 0 to 0xFFFF.
igorsk 0:1063a091a062 453 * @return None
igorsk 0:1063a091a062 454 *
igorsk 0:1063a091a062 455 * Note:
igorsk 0:1063a091a062 456 * - For all bits that has been set as input direction, this function will
igorsk 0:1063a091a062 457 * not effect.
igorsk 0:1063a091a062 458 * - For all remaining bits that are not activated in bitValue (value '0')
igorsk 0:1063a091a062 459 * will not be effected by this function.
igorsk 0:1063a091a062 460 **********************************************************************/
igorsk 0:1063a091a062 461 void FIO_HalfWordClearValue(uint8_t portNum, uint8_t halfwordNum, uint16_t bitValue)
igorsk 0:1063a091a062 462 {
igorsk 0:1063a091a062 463 GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
igorsk 0:1063a091a062 464 if(pFIO != NULL) {
igorsk 0:1063a091a062 465 // Upper
igorsk 0:1063a091a062 466 if(halfwordNum) {
igorsk 0:1063a091a062 467 pFIO->FIOCLRU = bitValue;
igorsk 0:1063a091a062 468 }
igorsk 0:1063a091a062 469 // lower
igorsk 0:1063a091a062 470 else {
igorsk 0:1063a091a062 471 pFIO->FIOCLRL = bitValue;
igorsk 0:1063a091a062 472 }
igorsk 0:1063a091a062 473 }
igorsk 0:1063a091a062 474 }
igorsk 0:1063a091a062 475
igorsk 0:1063a091a062 476
igorsk 0:1063a091a062 477 /*********************************************************************//**
igorsk 0:1063a091a062 478 * @brief Read Current state on port pin that have input direction of GPIO
igorsk 0:1063a091a062 479 * in halfword accessible style.
igorsk 0:1063a091a062 480 * @param[in] portNum Port number, in range from 0 to 4
igorsk 0:1063a091a062 481 * @param[in] halfwordNum HalfWord part number, should be 0 (lower) or 1(upper)
igorsk 0:1063a091a062 482 * @return Current value of FIO port pin of specified halfword.
igorsk 0:1063a091a062 483 * Note: Return value contain state of each port pin (bit) on that FIO regardless
igorsk 0:1063a091a062 484 * its direction is input or output.
igorsk 0:1063a091a062 485 **********************************************************************/
igorsk 0:1063a091a062 486 uint16_t FIO_HalfWordReadValue(uint8_t portNum, uint8_t halfwordNum)
igorsk 0:1063a091a062 487 {
igorsk 0:1063a091a062 488 GPIO_HalfWord_TypeDef *pFIO = FIO_HalfWordGetPointer(portNum);
igorsk 0:1063a091a062 489 if(pFIO != NULL) {
igorsk 0:1063a091a062 490 // Upper
igorsk 0:1063a091a062 491 if(halfwordNum) {
igorsk 0:1063a091a062 492 return (pFIO->FIOPINU);
igorsk 0:1063a091a062 493 }
igorsk 0:1063a091a062 494 // lower
igorsk 0:1063a091a062 495 else {
igorsk 0:1063a091a062 496 return (pFIO->FIOPINL);
igorsk 0:1063a091a062 497 }
igorsk 0:1063a091a062 498 }
igorsk 0:1063a091a062 499 return (0);
igorsk 0:1063a091a062 500 }
igorsk 0:1063a091a062 501
igorsk 0:1063a091a062 502
igorsk 0:1063a091a062 503 /* FIO Byte accessible ------------------------------------------------------------ */
igorsk 0:1063a091a062 504
igorsk 0:1063a091a062 505 /*********************************************************************//**
igorsk 0:1063a091a062 506 * @brief Set direction for FIO port in byte accessible style
igorsk 0:1063a091a062 507 * @param[in] portNum Port number, in range from 0 to 4
igorsk 0:1063a091a062 508 * @param[in] byteNum Byte part number, should be in range from 0 to 3
igorsk 0:1063a091a062 509 * @param[in] bitValue Value that contains all bits in to set direction,
igorsk 0:1063a091a062 510 * in range from 0 to 0xFF.
igorsk 0:1063a091a062 511 * @param[in] dir Direction value, should be:
igorsk 0:1063a091a062 512 * - 0: Input.
igorsk 0:1063a091a062 513 * - 1: Output.
igorsk 0:1063a091a062 514 * @return None
igorsk 0:1063a091a062 515 *
igorsk 0:1063a091a062 516 * Note: All remaining bits that are not activated in bitValue (value '0')
igorsk 0:1063a091a062 517 * will not be effected by this function.
igorsk 0:1063a091a062 518 **********************************************************************/
igorsk 0:1063a091a062 519 void FIO_ByteSetDir(uint8_t portNum, uint8_t byteNum, uint8_t bitValue, uint8_t dir)
igorsk 0:1063a091a062 520 {
igorsk 0:1063a091a062 521 GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
igorsk 0:1063a091a062 522 if(pFIO != NULL) {
igorsk 0:1063a091a062 523 // Output direction
igorsk 0:1063a091a062 524 if (dir) {
igorsk 0:1063a091a062 525 if (byteNum <= 3) {
igorsk 0:1063a091a062 526 pFIO->FIODIR[byteNum] |= bitValue;
igorsk 0:1063a091a062 527 }
igorsk 0:1063a091a062 528 }
igorsk 0:1063a091a062 529 // Input direction
igorsk 0:1063a091a062 530 else {
igorsk 0:1063a091a062 531 if (byteNum <= 3) {
igorsk 0:1063a091a062 532 pFIO->FIODIR[byteNum] &= ~bitValue;
igorsk 0:1063a091a062 533 }
igorsk 0:1063a091a062 534 }
igorsk 0:1063a091a062 535 }
igorsk 0:1063a091a062 536 }
igorsk 0:1063a091a062 537
igorsk 0:1063a091a062 538 /*********************************************************************//**
igorsk 0:1063a091a062 539 * @brief Set mask value for bits in FIO port in byte accessible style
igorsk 0:1063a091a062 540 * @param[in] portNum Port number, in range from 0 to 4
igorsk 0:1063a091a062 541 * @param[in] byteNum Byte part number, should be in range from 0 to 3
igorsk 0:1063a091a062 542 * @param[in] bitValue Value that contains all bits in to set mask,
igorsk 0:1063a091a062 543 * in range from 0 to 0xFF.
igorsk 0:1063a091a062 544 * @param[in] maskValue Mask value contains state value for each bit:
igorsk 0:1063a091a062 545 * - 0: not mask.
igorsk 0:1063a091a062 546 * - 1: mask.
igorsk 0:1063a091a062 547 * @return None
igorsk 0:1063a091a062 548 *
igorsk 0:1063a091a062 549 * Note:
igorsk 0:1063a091a062 550 * - All remaining bits that are not activated in bitValue (value '0')
igorsk 0:1063a091a062 551 * will not be effected by this function.
igorsk 0:1063a091a062 552 * - After executing this function, in mask register, value '0' on each bit
igorsk 0:1063a091a062 553 * enables an access to the corresponding physical pin via a read or write access,
igorsk 0:1063a091a062 554 * while value '1' on bit (masked) that corresponding pin will not be changed
igorsk 0:1063a091a062 555 * with write access and if read, will not be reflected in the updated pin.
igorsk 0:1063a091a062 556 **********************************************************************/
igorsk 0:1063a091a062 557 void FIO_ByteSetMask(uint8_t portNum, uint8_t byteNum, uint8_t bitValue, uint8_t maskValue)
igorsk 0:1063a091a062 558 {
igorsk 0:1063a091a062 559 GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
igorsk 0:1063a091a062 560 if(pFIO != NULL) {
igorsk 0:1063a091a062 561 // Mask
igorsk 0:1063a091a062 562 if (maskValue) {
igorsk 0:1063a091a062 563 if (byteNum <= 3) {
igorsk 0:1063a091a062 564 pFIO->FIOMASK[byteNum] |= bitValue;
igorsk 0:1063a091a062 565 }
igorsk 0:1063a091a062 566 }
igorsk 0:1063a091a062 567 // Un-mask
igorsk 0:1063a091a062 568 else {
igorsk 0:1063a091a062 569 if (byteNum <= 3) {
igorsk 0:1063a091a062 570 pFIO->FIOMASK[byteNum] &= ~bitValue;
igorsk 0:1063a091a062 571 }
igorsk 0:1063a091a062 572 }
igorsk 0:1063a091a062 573 }
igorsk 0:1063a091a062 574 }
igorsk 0:1063a091a062 575
igorsk 0:1063a091a062 576
igorsk 0:1063a091a062 577 /*********************************************************************//**
igorsk 0:1063a091a062 578 * @brief Set bits for FIO port in byte accessible style
igorsk 0:1063a091a062 579 * @param[in] portNum Port number, in range from 0 to 4
igorsk 0:1063a091a062 580 * @param[in] byteNum Byte part number, should be in range from 0 to 3
igorsk 0:1063a091a062 581 * @param[in] bitValue Value that contains all bits in to set,
igorsk 0:1063a091a062 582 * in range from 0 to 0xFF.
igorsk 0:1063a091a062 583 * @return None
igorsk 0:1063a091a062 584 *
igorsk 0:1063a091a062 585 * Note:
igorsk 0:1063a091a062 586 * - For all bits that has been set as input direction, this function will
igorsk 0:1063a091a062 587 * not effect.
igorsk 0:1063a091a062 588 * - For all remaining bits that are not activated in bitValue (value '0')
igorsk 0:1063a091a062 589 * will not be effected by this function.
igorsk 0:1063a091a062 590 **********************************************************************/
igorsk 0:1063a091a062 591 void FIO_ByteSetValue(uint8_t portNum, uint8_t byteNum, uint8_t bitValue)
igorsk 0:1063a091a062 592 {
igorsk 0:1063a091a062 593 GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
igorsk 0:1063a091a062 594 if (pFIO != NULL) {
igorsk 0:1063a091a062 595 if (byteNum <= 3){
igorsk 0:1063a091a062 596 pFIO->FIOSET[byteNum] = bitValue;
igorsk 0:1063a091a062 597 }
igorsk 0:1063a091a062 598 }
igorsk 0:1063a091a062 599 }
igorsk 0:1063a091a062 600
igorsk 0:1063a091a062 601
igorsk 0:1063a091a062 602 /*********************************************************************//**
igorsk 0:1063a091a062 603 * @brief Clear bits for FIO port in byte accessible style
igorsk 0:1063a091a062 604 * @param[in] portNum Port number, in range from 0 to 4
igorsk 0:1063a091a062 605 * @param[in] byteNum Byte part number, should be in range from 0 to 3
igorsk 0:1063a091a062 606 * @param[in] bitValue Value that contains all bits in to clear,
igorsk 0:1063a091a062 607 * in range from 0 to 0xFF.
igorsk 0:1063a091a062 608 * @return None
igorsk 0:1063a091a062 609 *
igorsk 0:1063a091a062 610 * Note:
igorsk 0:1063a091a062 611 * - For all bits that has been set as input direction, this function will
igorsk 0:1063a091a062 612 * not effect.
igorsk 0:1063a091a062 613 * - For all remaining bits that are not activated in bitValue (value '0')
igorsk 0:1063a091a062 614 * will not be effected by this function.
igorsk 0:1063a091a062 615 **********************************************************************/
igorsk 0:1063a091a062 616 void FIO_ByteClearValue(uint8_t portNum, uint8_t byteNum, uint8_t bitValue)
igorsk 0:1063a091a062 617 {
igorsk 0:1063a091a062 618 GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
igorsk 0:1063a091a062 619 if (pFIO != NULL) {
igorsk 0:1063a091a062 620 if (byteNum <= 3){
igorsk 0:1063a091a062 621 pFIO->FIOCLR[byteNum] = bitValue;
igorsk 0:1063a091a062 622 }
igorsk 0:1063a091a062 623 }
igorsk 0:1063a091a062 624 }
igorsk 0:1063a091a062 625
igorsk 0:1063a091a062 626
igorsk 0:1063a091a062 627 /*********************************************************************//**
igorsk 0:1063a091a062 628 * @brief Read Current state on port pin that have input direction of GPIO
igorsk 0:1063a091a062 629 * in byte accessible style.
igorsk 0:1063a091a062 630 * @param[in] portNum Port number, in range from 0 to 4
igorsk 0:1063a091a062 631 * @param[in] byteNum Byte part number, should be in range from 0 to 3
igorsk 0:1063a091a062 632 * @return Current value of FIO port pin of specified byte part.
igorsk 0:1063a091a062 633 * Note: Return value contain state of each port pin (bit) on that FIO regardless
igorsk 0:1063a091a062 634 * its direction is input or output.
igorsk 0:1063a091a062 635 **********************************************************************/
igorsk 0:1063a091a062 636 uint8_t FIO_ByteReadValue(uint8_t portNum, uint8_t byteNum)
igorsk 0:1063a091a062 637 {
igorsk 0:1063a091a062 638 GPIO_Byte_TypeDef *pFIO = FIO_ByteGetPointer(portNum);
igorsk 0:1063a091a062 639 if (pFIO != NULL) {
igorsk 0:1063a091a062 640 if (byteNum <= 3){
igorsk 0:1063a091a062 641 return (pFIO->FIOPIN[byteNum]);
igorsk 0:1063a091a062 642 }
igorsk 0:1063a091a062 643 }
igorsk 0:1063a091a062 644 return (0);
igorsk 0:1063a091a062 645 }
igorsk 0:1063a091a062 646
igorsk 0:1063a091a062 647 /**
igorsk 0:1063a091a062 648 * @}
igorsk 0:1063a091a062 649 */
igorsk 0:1063a091a062 650
igorsk 0:1063a091a062 651 #endif /* _GPIO */
igorsk 0:1063a091a062 652
igorsk 0:1063a091a062 653 /**
igorsk 0:1063a091a062 654 * @}
igorsk 0:1063a091a062 655 */
igorsk 0:1063a091a062 656
igorsk 0:1063a091a062 657 /* --------------------------------- End Of File ------------------------------ */