Appiko
SDK_EVAL_Gpio.c
Go to the documentation of this file.
1 
24 /* Includes ------------------------------------------------------------------*/
25 #include "SDK_EVAL_Gpio.h"
26 #include "SDK_EVAL_Config.h"
27 
48 GPIO_TypeDef* vectpxM2SGpioPort[M2S_GPIO_NUMBER] = {M2S_GPIO_0_PORT_NUCLEO,M2S_GPIO_1_PORT_NUCLEO,M2S_GPIO_2_PORT_NUCLEO,M2S_GPIO_3_PORT_NUCLEO,M2S_GPIO_SDN_PORT};
49 
53 static const uint16_t s_vectnM2SGpioPin[M2S_GPIO_NUMBER] = {
54  M2S_GPIO_0_PIN,
55  M2S_GPIO_1_PIN,
56  M2S_GPIO_2_PIN,
57  M2S_GPIO_3_PIN,
58  M2S_GPIO_SDN_PIN
59 };
60 
64 static const uint32_t s_vectxM2SGpioSpeed[M2S_GPIO_NUMBER] = {
65  M2S_GPIO_0_SPEED,
66  M2S_GPIO_1_SPEED,
67  M2S_GPIO_2_SPEED,
68  M2S_GPIO_3_SPEED,
69  M2S_GPIO_SDN_SPEED
70 };
71 
75 static const uint32_t s_vectxM2SGpioPuPd[M2S_GPIO_NUMBER] = {
76  M2S_GPIO_0_PUPD,
77  M2S_GPIO_1_PUPD,
78  M2S_GPIO_2_PUPD,
79  M2S_GPIO_3_PUPD,
80  M2S_GPIO_SDN_PUPD
81 };
82 
86 static const uint32_t s_vectxM2sGpioExtiMode[M2S_GPIO_NUMBER-1] = {
87  M2S_GPIO_0_EXTI_MODE,
88  M2S_GPIO_1_EXTI_MODE,
89  M2S_GPIO_2_EXTI_MODE,
90  M2S_GPIO_3_EXTI_MODE
91 };
92 
93 
97 static const IRQn_Type s_vectcM2SGpioExtiIrqn[M2S_GPIO_NUMBER-1] = {
98  M2S_GPIO_0_EXTI_IRQN,
99  M2S_GPIO_1_EXTI_IRQN,
100  M2S_GPIO_2_EXTI_IRQN,
101  M2S_GPIO_3_EXTI_IRQN,
102 };
103 
104 
135 {
136  GPIO_InitTypeDef GPIO_InitStructure, EXTI_InitStructure;
137 
138  /* Check the parameters */
139  assert_param(IS_M2S_GPIO_PIN(xGpio));
140  assert_param(IS_M2S_GPIO_MODE(xGpioMode));
141 
142  switch(xGpio)
143  {
144  case M2S_GPIO_0:
145  M2S_GPIO_0_CLOCK_NUCLEO();
146  break;
147  case M2S_GPIO_1:
148  M2S_GPIO_1_CLOCK_NUCLEO();
149  break;
150  case M2S_GPIO_2:
151  M2S_GPIO_2_CLOCK_NUCLEO();
152  break;
153  case M2S_GPIO_3:
154  M2S_GPIO_3_CLOCK_NUCLEO();
155  break;
156  case M2S_GPIO_SDN:
157  M2S_GPIO_SDN_CLOCK_NUCLEO();
158  break;
159  }
160 
161  /* Configures MCU GPIO */
162  if(xGpioMode == M2S_MODE_GPIO_OUT)
163  GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
164  else
165  GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
166 
167  GPIO_InitStructure.Pull = s_vectxM2SGpioPuPd[xGpio];
168  GPIO_InitStructure.Speed = s_vectxM2SGpioSpeed[xGpio];
169  GPIO_InitStructure.Pin = s_vectnM2SGpioPin[xGpio];
170  HAL_GPIO_Init(vectpxM2SGpioPort[xGpio], &GPIO_InitStructure);
171 
172  /* Configures MCU GPIO EXTI line */
173  EXTI_InitStructure.Pull = s_vectxM2SGpioPuPd[xGpio];
174  EXTI_InitStructure.Mode = s_vectxM2sGpioExtiMode[xGpio];
175  EXTI_InitStructure.Pin = s_vectnM2SGpioPin[xGpio];
176  EXTI_InitStructure.Speed = s_vectxM2SGpioSpeed[xGpio];
177 
178  if (xGpioMode == M2S_MODE_EXTI_IN) {
179  HAL_GPIO_Init(vectpxM2SGpioPort[xGpio], &EXTI_InitStructure);
180 
181  }
182 
183 }
184 
201 void SdkEvalM2SGpioInterruptCmd(M2SGpioPin xGpio, uint8_t nPreemption, uint8_t nSubpriority, FunctionalState xNewState)
202 {
203  if (xNewState == ENABLE) {
204  HAL_NVIC_EnableIRQ(s_vectcM2SGpioExtiIrqn[xGpio]);
205  HAL_NVIC_SetPriority(s_vectcM2SGpioExtiIrqn[xGpio], nPreemption, nSubpriority);
206 
207  }
208  else {
209  HAL_NVIC_DisableIRQ(s_vectcM2SGpioExtiIrqn[xGpio]);
210  }
211 }
212 
227 void SdkEvalM2SGpioTriggerRising(M2SGpioPin xGpio, FunctionalState xNewState)
228 {
229  if(xNewState)
230  EXTI->RTSR |= (uint16_t)s_vectnM2SGpioPin[xGpio];
231  else
232  EXTI->RTSR &= ~(uint16_t)s_vectnM2SGpioPin[xGpio];
233 }
234 
248 {
249  if(EXTI->RTSR & (uint16_t)s_vectnM2SGpioPin[xGpio])
250  return ENABLE;
251 
252  return DISABLE;
253 }
254 
269 void SdkEvalM2SGpioTriggerFalling(M2SGpioPin xGpio, FunctionalState xNewState)
270 {
271  if(xNewState)
272  EXTI->FTSR |= (uint16_t)s_vectnM2SGpioPin[xGpio];
273  else
274  EXTI->FTSR &= ~(uint16_t)s_vectnM2SGpioPin[xGpio];
275 }
276 
290 {
291  if(EXTI->FTSR & (uint16_t)s_vectnM2SGpioPin[xGpio])
292  return ENABLE;
293 
294  return DISABLE;
295 }
296 
309 {
310  /* Gets the GPIO level */
311  GPIO_PinState ret = HAL_GPIO_ReadPin(vectpxM2SGpioPort[xGpio], s_vectnM2SGpioPin[xGpio]);
312 
313  return (FlagStatus)ret;
314 }
315 
328 void SdkEvalGpioSetLevel(M2SGpioPin xGpio, FlagStatus xLevel)
329 {
330  /* Sets the GPIO level */
331  HAL_GPIO_WritePin(vectpxM2SGpioPort[xGpio], s_vectnM2SGpioPin[xGpio], (GPIO_PinState)xLevel);
332 }
333 
340 {
341  /* Puts high the GPIO connected to shutdown pin */
342  HAL_GPIO_WritePin(M2S_GPIO_SDN_PORT, M2S_GPIO_SDN_PIN, GPIO_PIN_SET);
343 }
344 
345 
352 {
353  /* Puts low the GPIO connected to shutdown pin */
354  HAL_GPIO_WritePin(M2S_GPIO_SDN_PORT, M2S_GPIO_SDN_PIN, GPIO_PIN_RESET);
355 
356  /* Delay to allow the circuit POR, about 700 us */
357  for(volatile uint32_t i=0;i<0x1E00;i++);
358 }
359 
365 FlagStatus SdkEvalCheckShutdown(void)
366 {
368 }
369 
376 {
377  return s_vectnM2SGpioPin[xGpio];
378 }
379 
380 
386 void SdkEvalTcxoInit(void)
387 {
388  GPIO_InitTypeDef GPIO_InitStructure;
389 
390  TCXO_EN_GPIO_CLK();
391 
392  /* Configures MCU GPIO */
393  GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
394  GPIO_InitStructure.Pull = GPIO_NOPULL;
395  GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
396  GPIO_InitStructure.Pin = TCXO_EN_PIN;
397  HAL_GPIO_Init(TCXO_EN_PORT, &GPIO_InitStructure);
398 }
399 
405 void SdkEvalTcxoOn(void)
406 {
407  /* Puts high the GPIO connected to TCXO pin */
408  HAL_GPIO_WritePin(TCXO_EN_PORT, TCXO_EN_PIN, GPIO_PIN_SET);
409 }
410 
411 
417 void SdkEvalTcxoOff(void)
418 {
419  /* Puts low the GPIO connected to TCXO pin */
420  HAL_GPIO_WritePin(TCXO_EN_PORT, TCXO_EN_PIN, GPIO_PIN_RESET);
421 }
422 
441 /******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/
void SdkEvalEnterShutdown(void)
Puts at logic 1 the SDN pin.
M2SGpioPin
MCU GPIO pin enumeration for GPIO.
Definition: SDK_EVAL_Gpio.h:83
This file contains SDK EVAL configuration and useful defines.
void SdkEvalExitShutdown(void)
Put at logic 0 the SDN pin.
void SdkEvalGpioSetLevel(M2SGpioPin xGpio, FlagStatus xLevel)
Sets the level of a specified GPIO.
M2SGpioMode
MCU GPIO pin working mode for GPIO.
#define M2S_GPIO_NUMBER
Number of MCU GPIO pins used for GPIO.
Definition: SDK_EVAL_Gpio.h:77
FunctionalState SdkEvalM2SGpioGetTriggerFalling(M2SGpioPin xGpio)
To assert if the falling edge IRQ is enabled for that GPIO .
void SdkEvalTcxoOff(void)
Put at logic 0 the TCXO pin.
void SdkEvalM2SGpioInterruptCmd(M2SGpioPin xGpio, uint8_t nPreemption, uint8_t nSubpriority, FunctionalState xNewState)
Enables or disables the interrupt on GPIO .
GPIO_TypeDef * vectpxM2SGpioPort[M2S_GPIO_NUMBER]
M2S GPio Port array.
Definition: SDK_EVAL_Gpio.c:48
void SdkEvalM2SGpioTriggerRising(M2SGpioPin xGpio, FunctionalState xNewState)
Enables or disables trigger on rising edge for that GPIO .
void SdkEvalM2SGpioTriggerFalling(M2SGpioPin xGpio, FunctionalState xNewState)
Enables or disables trigger on falling edge for that GPIO .
FunctionalState SdkEvalM2SGpioGetTriggerRising(M2SGpioPin xGpio)
To assert if the rising edge IRQ is enabled for that GPIO .
GPIO Configuration used in the Software Development Kit eval board to drive GPIOs.
void SdkEvalM2SGpioInit(M2SGpioPin xGpio, M2SGpioMode xGpioMode)
Configures MCU GPIO and EXTI Line for GPIOs.
uint16_t SdkEvalGpioGetPin(M2SGpioPin xGpio)
Gets the GPIO_PIN of the M2SGpioPin.
void SdkEvalTcxoInit(void)
Initialize the TCXO enable pin.
FlagStatus SdkEvalCheckShutdown(void)
check the logic(0 or 1) at the SDN pin.
void SdkEvalTcxoOn(void)
Puts at logic 1 the TCXO pin.
FlagStatus SdkEvalGpioGetLevel(M2SGpioPin xGpio)
Returns the level of a specified GPIO.