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