1 /*!
2  * @file        apm32f4xx_syscfg.c
3  *
4  * @brief       This file provides all the SYSCFG firmware functions
5  *
6  * @version     V1.0.2
7  *
8  * @date        2022-06-23
9  *
10  * @attention
11  *
12  *  Copyright (C) 2021-2022 Geehy Semiconductor
13  *
14  *  You may not use this file except in compliance with the
15  *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
16  *
17  *  The program is only for reference, which is distributed in the hope
18  *  that it will be usefull and instructional for customers to develop
19  *  their software. Unless required by applicable law or agreed to in
20  *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
21  *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
22  *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
23  *  and limitations under the License.
24  */
25 
26 #include "apm32f4xx_syscfg.h"
27 #include "apm32f4xx_rcm.h"
28 
29 /** @addtogroup APM32F4xx_StdPeriphDriver
30   @{
31 */
32 
33 /** @defgroup SYSCFG_Driver
34   * @brief SYSCFG driver modules
35   @{
36 */
37 
38 /** @defgroup SYSCFG_Functions
39   @{
40 */
41 
42 /*!
43  * @brief     Reset the remap and EINT configuration registers to their default values.
44  *
45  * @param     None
46  *
47  * @retval    None
48  */
SYSCFG_Reset(void)49 void SYSCFG_Reset(void)
50 {
51     RCM_EnableAPB2PeriphReset(RCM_APB2_PERIPH_SYSCFG);
52     RCM_DisableAPB2PeriphReset(RCM_APB2_PERIPH_SYSCFG);
53 }
54 
55 /*!
56  * @brief     Changes the mapping of the specified pin.
57  *
58  * @param     memory: selects the memory remapping.
59  *                   The parameter can be one of the following values:
60  *                   @arg SYSCFG_REMAP_FLASH        : Memory mapping to Flash
61  *                   @arg SYSCFG_REMAP_SYSTEM_FLASH : Memory mapping to SystemFlash
62  *                   @arg SYSCFG_REMAP_SMC_BANK1    : Memory mapping to bank1 of SMC (NOR-flash/PSRAM)
63  *                   @arg SYSCFG_REMAP_SRAM         : Memory mapping to SRAM
64  *
65  * @retval    None
66  */
SYSCFG_ConfigMemoryRemap(SYSCFG_REMAP_T memory)67 void SYSCFG_ConfigMemoryRemap(SYSCFG_REMAP_T memory)
68 {
69     SYSCFG->MMSEL_B.MMSEL = memory;
70 }
71 
72 /*!
73  * @brief     Config the GPIO pin used as EINT Line.
74  *
75  * @param     port: select the port
76  *                  The parameter can be one of the following values
77  *                  @arg SYSCFG_PORT_GPIOA : Port Source GPIOA
78  *                  @arg SYSCFG_PORT_GPIOB : Port Source GPIOB
79  *                  @arg SYSCFG_PORT_GPIOC : Port Source GPIOC
80  *                  @arg SYSCFG_PORT_GPIOD : Port Source GPIOD
81  *                  @arg SYSCFG_PORT_GPIOE : Port Source GPIOE
82  *                  @arg SYSCFG_PORT_GPIOF : Port Source GPIOF
83  *                  @arg SYSCFG_PORT_GPIOG : Port Source GPIOG
84  *                  @arg SYSCFG_PORT_GPIOH : Port Source GPIOH
85  *                  @arg SYSCFG_PORT_GPIOI : Port Source GPIOI
86  *
87  * @param     pin:  select the pin
88  *                  The parameter can be one of the following values
89  *                  @arg SYSCFG_PIN_0 : Pin Source 0
90  *                  @arg SYSCFG_PIN_1 : Pin Source 1
91  *                  @arg SYSCFG_PIN_2 : Pin Source 2
92  *                  @arg SYSCFG_PIN_3 : Pin Source 3
93  *                  @arg SYSCFG_PIN_4 : Pin Source 4
94  *                  @arg SYSCFG_PIN_5 : Pin Source 5
95  *                  @arg SYSCFG_PIN_6 : Pin Source 6
96  *                  @arg SYSCFG_PIN_7 : Pin Source 7
97  *                  @arg SYSCFG_PIN_8 : Pin Source 8
98  *                  @arg SYSCFG_PIN_9 : Pin Source 9
99  *                  @arg SYSCFG_PIN_10: Pin Source 10
100  *                  @arg SYSCFG_PIN_11: Pin Source 11
101  *                  @arg SYSCFG_PIN_12: Pin Source 12
102  *                  @arg SYSCFG_PIN_13: Pin Source 13
103  *                  @arg SYSCFG_PIN_14: Pin Source 14
104  *                  @arg SYSCFG_PIN_15: Pin Source 15
105  *
106  * @retval    None
107  *
108  * @note      pin from SYSCFG_PIN_12 to SYSCFG_PIN_15 is not fit for
109  *            SYSCFG_PORT_GPIOI of the port.
110  */
SYSCFG_ConfigEINTLine(SYSCFG_PORT_T port,SYSCFG_PIN_T pin)111 void SYSCFG_ConfigEINTLine(SYSCFG_PORT_T port, SYSCFG_PIN_T pin)
112 {
113     uint32_t status;
114 
115     status = ((uint32_t)(port & 0x0F)) << (0x04 * (pin & 0x03));
116 
117     if ((pin >> 2) == 0)
118     {
119         SYSCFG->EINTCFG1 |= status;
120     }
121     else if ((pin >> 2) == 1)
122     {
123         SYSCFG->EINTCFG2 |= status;
124     }
125     else if ((pin >> 2) == 2)
126     {
127         SYSCFG->EINTCFG3 |= status;
128     }
129     else if ((pin >> 2) == 3)
130     {
131         SYSCFG->EINTCFG4 |= status;
132     }
133 }
134 
135 /*!
136  * @brief     Selects the ETHERNET media interface
137  *
138  * @param     media: select the media
139  *                   The parameter can be combination of folling values
140  *                   @arg SYSCFG_INTERFACE_MII  : MII mode selected
141  *                   @arg SYSCFG_INTERFACE_RMII : RMII mode selected
142  *
143  * @retval    None
144  */
SYSCFG_ConfigMediaInterface(SYSCFG_INTERFACE_T media)145 void SYSCFG_ConfigMediaInterface(SYSCFG_INTERFACE_T media)
146 {
147     SYSCFG->PMC_B.ENETSEL = media;
148 }
149 
150 /*!
151  * @brief     Enables the I/O Compensation Cell.
152  *
153  * @param     None
154  *
155  * @retval    None
156  *
157  * @note      The I/O compensation cell can be used only when the device supply
158  *            voltage ranges from 2.4 to 3.6 V.
159  */
SYSCFG_EnableCompensationCell(void)160 void SYSCFG_EnableCompensationCell(void)
161 {
162     SYSCFG->CCCTRL_B.CCPD = BIT_SET;
163 }
164 
165 /*!
166  * @brief     Disables the I/O Compensation Cell.
167  *
168  * @param     None
169  *
170  * @retval    None
171  *
172  * @note      The I/O compensation cell can be used only when the device supply
173  *            voltage ranges from 2.4 to 3.6 V.
174  */
SYSCFG_DisableCompensationCell(void)175 void SYSCFG_DisableCompensationCell(void)
176 {
177     SYSCFG->CCCTRL_B.CCPD = BIT_RESET;
178 }
179 
180 /*!
181  * @brief     Read the I/O Compensation Cell ready flag.
182  *
183  * @param     None
184  *
185  * @retval    SET or RESET
186  */
SYSCFG_ReadCompensationCellStatus(void)187 uint8_t SYSCFG_ReadCompensationCellStatus(void)
188 {
189     return (SYSCFG->CCCTRL & BIT8) ? SET : RESET;
190 }
191 
192 /**@} end of group SYSCFG_Functions */
193 /**@} end of group SYSCFG_Driver */
194 /**@} end of group APM32F4xx_StdPeriphDriver */
195