lpc-field

Template project for programming NXP's LPC1768 MCUs
git clone git://git.mdnr.space/lpc-field
Log | Files | Refs | README | LICENSE

lpc17xx_gpio.c (24336B)


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