Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

1 /**

2 * @file xmc_gpio.c
3 * @date 2019-12-16
4 *
5 * @cond
6 *****************************************************************************
7 * XMClib v2.2.0 - XMC Peripheral Driver Library
8 *
9 * Copyright (c) 2015-2020, Infineon Technologies AG
10 * All rights reserved.
11 *
12 * Boost Software License - Version 1.0 - August 17th, 2003
13 *
14 * Permission is hereby granted, free of charge, to any person or organization
15 * obtaining a copy of the software and accompanying documentation covered by
16 * this license (the "Software") to use, reproduce, display, distribute,
17 * execute, and transmit the Software, and to prepare derivative works of the
18 * Software, and to permit third-parties to whom the Software is furnished to
19 * do so, all subject to the following:
20 *
21 * The copyright notices in the Software and this entire statement, including
22 * the above license grant, this restriction and the following disclaimer,
23 * must be included in all copies of the Software, in whole or in part, and
24 * all derivative works of the Software, unless such copies or derivative
25 * works are solely in the form of machine-executable object code generated by
26 * a source language processor.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
31 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
32 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
33 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
34 * DEALINGS IN THE SOFTWARE.
35 *
36 * To improve the quality of the software, users are encouraged to share
37 * modifications, enhancements or bug fixes with Infineon Technologies AG
38 * at XMCSupport@infineon.com.
39 *****************************************************************************
40 *
41 * Change History
42 * --------------
43 *
44 * 2015-02-20:
45 * - Initial draft <br>
46 *
47 * 2015-06-20:
48 * - Removed version macros and declaration of GetDriverVersion API
49 *
50 * 2019-12-16:
51 * - Fix including files following the convention: angle brackets are used for
standard includes and double quotes for everything else.
52 *
53 * @endcond
54 *
55 */
56
57 /*******************************************************************************
58 * HEADER FILES
59 *******************************************************************************/
60
61 #include "xmc_gpio.h"
62
63 /*******************************************************************************
64 * MACROS
65 *******************************************************************************/
66
67 #define PORT_HWSEL_Msk PORT0_HWSEL_HW0_Msk
68
69 /*******************************************************************************
70 * API IMPLEMENTATION
71 *******************************************************************************/
72
73 void XMC_GPIO_SetMode(XMC_GPIO_PORT_t *const port, const uint8_t pin, const
XMC_GPIO_MODE_t mode)
74 {
75 XMC_ASSERT("XMC_GPIO_SetMode: Invalid port", XMC_GPIO_CHECK_PORT(port));
76 XMC_ASSERT("XMC_GPIO_SetMode: Invalid mode", XMC_GPIO_IsModeValid(mode));
77
78 port->IOCR[(uint32_t)pin >> 2U] &= ~(uint32_t)((uint32_t)PORT_IOCR_PC_Msk << ((
uint32_t)PORT_IOCR_PC_Size * ((uint32_t)pin & 0x3U)));
79 port->IOCR[(uint32_t)pin >> 2U] |= (uint32_t)mode << ((uint32_t)PORT_IOCR_PC_Size *
((uint32_t)pin & 0x3U));
80 }
81
82 void XMC_GPIO_SetHardwareControl(XMC_GPIO_PORT_t *const port, const uint8_t pin, const
XMC_GPIO_HWCTRL_t hwctrl)
83 {
84 XMC_ASSERT("XMC_GPIO_SetHardwareControl: Invalid port", XMC_GPIO_CHECK_PORT(port));
85 XMC_ASSERT("XMC_GPIO_SetHardwareControl: Invalid hwctrl", XMC_GPIO_CHECK_HWCTRL(
hwctrl));
86
87 port->HWSEL &= ~(uint32_t)((uint32_t)PORT_HWSEL_Msk << ((uint32_t)pin << 1U));
88 port->HWSEL |= (uint32_t)hwctrl << ((uint32_t)pin << 1U);
89 }
90

You might also like