NIIETCM4 PD  v0.10.5
Драйвер периферии для микроконтроллеров на базе ядра ARM Cortex-M4
 Указатель Структуры данных Файлы Функции Переменные Перечисления Элементы перечислений Группы Страницы
niietcm4_gpio.c
См. документацию.
1 
29 /* Includes ------------------------------------------------------------------*/
30 #include "niietcm4_gpio.h"
31 
72 #define GPIO_DATAOUT_Reset_Value ((uint32_t)0x00000000)
73 #define GPIO_GPIODEN0_Reset_Value ((uint32_t)0x00020062)
74 #define GPIO_GPIODEN1_Reset_Value ((uint32_t)0x08000000)
75 #define GPIO_GPIODEN2_Reset_Value ((uint32_t)0x00000400)
76 #define GPIO_GPIODEN3_Reset_Value ((uint32_t)0x00000000)
77 #define GPIO_GPIOODCTLx_Reset_Value ((uint32_t)0x00000000)
78 #define GPIO_GPIOPUCTLx_Reset_Value ((uint32_t)0x00000000)
79 #define GPIO_GPIOSEx_Reset_Value ((uint32_t)0x00000000)
80 #define GPIO_GPIOQEx_Reset_Value ((uint32_t)0x00000000)
81 #define GPIO_GPIOQMx_Reset_Value ((uint32_t)0x00000000)
82 #define GPIO_GPIOPCTLx_Reset_Value ((uint32_t)0x00000000)
83 #define GPIO_GPIOQPx_Reset_Value ((uint32_t)0x00000000)
93 #define GPIO_Regs_A_C_E_G_Mask ((uint32_t)0x0000FFFF)
94 #define GPIO_Regs_B_D_F_H_Mask ((uint32_t)0xFFFF0000)
95 #define GPIO_Regs_GPIOA_Mask ((uint32_t)0x0000FFFF)
96 #define GPIO_Regs_GPIOB_Mask ((uint32_t)0xFFFF0000)
97 #define GPIO_Regs_GPIOC_Mask ((uint32_t)0x0000FFFF)
98 #define GPIO_Regs_GPIOD_Mask ((uint32_t)0xFFFF0000)
99 #define GPIO_Regs_GPIOE_Mask ((uint32_t)0x0000FFFF)
100 #define GPIO_Regs_GPIOF_Mask ((uint32_t)0xFFFF0000)
101 #define GPIO_Regs_GPIOG_Mask ((uint32_t)0x0000FFFF)
102 #define GPIO_Regs_GPIOH_Mask ((uint32_t)0xFFFF0000)
122 void GPIO_DeInit(NT_GPIO_TypeDef* GPIOx)
123 {
124  uint32_t reg_port_mask;
125  uint32_t gpioqp_port_mask;
126  uint32_t gpiodenx_reset_value;
127  __IO uint32_t* GPIODENx;
128  __IO uint32_t* GPIOODCTLx;
129  __IO uint32_t* GPIOPUCTLx;
130  __IO uint32_t* GPIOSEx;
131  __IO uint32_t* GPIOQEx;
132  __IO uint32_t* GPIOQMx;
133  __IO uint32_t* GPIOPCTLx;
134  __IO uint32_t* GPIOQPx;
135 
136  /* Check the parameters */
137  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
138 
139  /* Preparation routine */
140  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOC) ||
141  (GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOG))
142  {
143  reg_port_mask = GPIO_Regs_A_C_E_G_Mask;
144  }
145  else /* ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOD) ||
146  (GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOH)) */
147  {
148  reg_port_mask = GPIO_Regs_B_D_F_H_Mask;
149  }
150 
151  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
152  {
153  GPIODENx = &(NT_COMMON_REG->GPIODEN0);
154  gpiodenx_reset_value = GPIO_GPIODEN0_Reset_Value;
155  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL0);
156  GPIOPUCTLx = &(NT_COMMON_REG->GPIOPUCTL0);
157  GPIOSEx = &(NT_COMMON_REG->GPIOSE0);
158  GPIOQEx = &(NT_COMMON_REG->GPIOQE0);
159  GPIOQMx = &(NT_COMMON_REG->GPIOQM0);
160  GPIOQPx = &(NT_COMMON_REG->GPIOQPAD);
161  if (GPIOx == NT_GPIOA)
162  {
163  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLA);
164  gpioqp_port_mask = COMMON_REG_GPIOQPAD_SPRDA_Msk;
165  }
166  else /* (GPIOx == NT_GPIOB) */
167  {
168  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLB);
169  gpioqp_port_mask = COMMON_REG_GPIOQPAD_SPRDB_Msk;
170  }
171  }
172  else if ((GPIOx == NT_GPIOC) || (GPIOx == NT_GPIOD))
173  {
174  GPIODENx = &(NT_COMMON_REG->GPIODEN1);
175  gpiodenx_reset_value = GPIO_GPIODEN1_Reset_Value;
176  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL1);
177  GPIOPUCTLx = &(NT_COMMON_REG->GPIOPUCTL1);
178  GPIOSEx = &(NT_COMMON_REG->GPIOSE1);
179  GPIOQEx = &(NT_COMMON_REG->GPIOQE1);
180  GPIOQMx = &(NT_COMMON_REG->GPIOQM1);
181  GPIOQPx = &(NT_COMMON_REG->GPIOQPAD);
182  if (GPIOx == NT_GPIOC)
183  {
184  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLC);
185  gpioqp_port_mask = COMMON_REG_GPIOQPAD_SPRDC_Msk;
186  }
187  else /* (GPIOx == NT_GPIOD) */
188  {
189  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLD);
190  gpioqp_port_mask = COMMON_REG_GPIOQPAD_SPRDD_Msk;
191  }
192  }
193  else if ((GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOF))
194  {
195  GPIODENx = &(NT_COMMON_REG->GPIODEN2);
196  gpiodenx_reset_value = GPIO_GPIODEN2_Reset_Value;
197  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL2);
198  GPIOPUCTLx = &(NT_COMMON_REG->GPIOPUCTL2);
199  GPIOSEx = &(NT_COMMON_REG->GPIOSE2);
200  GPIOQEx = &(NT_COMMON_REG->GPIOQE2);
201  GPIOQMx = &(NT_COMMON_REG->GPIOQM2);
202  GPIOQPx = &(NT_COMMON_REG->GPIOQPEH);
203  if (GPIOx == NT_GPIOE)
204  {
205  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLE);
206  gpioqp_port_mask = COMMON_REG_GPIOQPEH_SPRDE_Msk;
207  }
208  else /* (GPIOx == NT_GPIOF) */
209  {
210  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLF);
211  gpioqp_port_mask = COMMON_REG_GPIOQPEH_SPRDF_Msk;
212  }
213  }
214  else /* ((GPIOx == NT_GPIOG) || (GPIOx == NT_GPIOH)) */
215  {
216  GPIODENx = &(NT_COMMON_REG->GPIODEN3);
217  gpiodenx_reset_value = GPIO_GPIODEN3_Reset_Value;
218  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL3);
219  GPIOPUCTLx = &(NT_COMMON_REG->GPIOPUCTL3);
220  GPIOSEx = &(NT_COMMON_REG->GPIOSE3);
221  GPIOQEx = &(NT_COMMON_REG->GPIOQE3);
222  GPIOQMx = &(NT_COMMON_REG->GPIOQM3);
223  GPIOQPx = &(NT_COMMON_REG->GPIOQPEH);
224  if (GPIOx == NT_GPIOG)
225  {
226  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLG);
227  gpioqp_port_mask = COMMON_REG_GPIOQPEH_SPRDG_Msk;
228  }
229  else /* (GPIOx == NT_GPIOH) */
230  {
231  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLH);
232  gpioqp_port_mask = COMMON_REG_GPIOQPEH_SPRDH_Msk;
233  }
234  }
235  /* Reset all port regs and bit fields */
236  GPIOx->DATAOUT = GPIO_DATAOUT_Reset_Value;
237  GPIOx->OUTENCLR = ((uint32_t)0xFFFFFFFF);
238  GPIOx->ALTFUNCCLR = ((uint32_t)0xFFFFFFFF);
239  GPIOx->INTENCLR = ((uint32_t)0xFFFFFFFF);
240  GPIOx->INTTYPECLR = ((uint32_t)0xFFFFFFFF);
241  GPIOx->INTPOLCLR = ((uint32_t)0xFFFFFFFF);
242  GPIOx->INTSTATUS = ((uint32_t)0xFFFFFFFF);
243  *GPIODENx &= ~reg_port_mask;
244  *GPIODENx |= (gpiodenx_reset_value & reg_port_mask);
245  *GPIOODCTLx &= ~reg_port_mask;
246  *GPIOODCTLx |= (GPIO_GPIOODCTLx_Reset_Value & reg_port_mask);
247  *GPIOPUCTLx &= ~reg_port_mask;
248  *GPIOPUCTLx |= (GPIO_GPIOPUCTLx_Reset_Value & reg_port_mask);
249  *GPIOSEx &= ~reg_port_mask;
250  *GPIOSEx |= (GPIO_GPIOSEx_Reset_Value & reg_port_mask);
251  *GPIOQEx &= ~reg_port_mask;
252  *GPIOQEx |= (GPIO_GPIOQEx_Reset_Value & reg_port_mask);
253  *GPIOQMx &= ~reg_port_mask;
254  *GPIOQMx |= (GPIO_GPIOQMx_Reset_Value & reg_port_mask);
255  *GPIOPCTLx = GPIO_GPIOPCTLx_Reset_Value;
256  *GPIOQPx &= ~gpioqp_port_mask;
257  *GPIOQPx |= (GPIO_GPIOQPx_Reset_Value & gpioqp_port_mask);
258 }
259 
270 void GPIO_AltFuncConfig(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, GPIO_AltFunc_TypeDef GPIO_AltFunc)
271 {
272  uint32_t alt_func_temp;
273  __IO uint32_t* GPIOPCTLx;
274 
275  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
276  assert_param(IS_GPIO_PIN(GPIO_Pin));
277  assert_param(IS_GPIO_ALT_FUNC(GPIO_AltFunc));
278 
279  if (GPIOx == NT_GPIOA)
280  {
281  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLA);
282  }
283  else if (GPIOx == NT_GPIOB)
284  {
285  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLB);
286  }
287  else if (GPIOx == NT_GPIOC)
288  {
289  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLC);
290  }
291  else if (GPIOx == NT_GPIOD)
292  {
293  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLD);
294  }
295  else if (GPIOx == NT_GPIOE)
296  {
297  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLE);
298  }
299  else if (GPIOx == NT_GPIOF)
300  {
301  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLF);
302  }
303  else if (GPIOx == NT_GPIOG)
304  {
305  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLG);
306  }
307  else /* (GPIOx == NT_GPIOH) */
308  {
309  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLH);
310  }
311 
312  alt_func_temp = *GPIOPCTLx;
313  for (uint32_t i = 0; i < 16; i++)
314  {
315  if (GPIO_Pin & (1<<i))
316  {
317  alt_func_temp &= ~(3 << i*2);
318  alt_func_temp |= GPIO_AltFunc << i*2;
319  }
320  }
321  *GPIOPCTLx = alt_func_temp;
322 }
323 
332 void GPIO_Init(NT_GPIO_TypeDef* GPIOx, GPIO_Init_TypeDef* GPIO_InitStruct)
333 {
334  uint32_t port_offset;
335  __IO uint32_t* GPIOPUCTLx;
336  __IO uint32_t* GPIOODCTLx;
337  __IO uint32_t* GPIODENx;
338 
339  /* Check the parameters */
340  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
341  assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
342  assert_param(IS_GPIO_DIR(GPIO_InitStruct->GPIO_Dir));
343  assert_param(IS_GPIO_OUT(GPIO_InitStruct->GPIO_Out));
344  assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
345  assert_param(IS_GPIO_ALT_FUNC(GPIO_InitStruct->GPIO_AltFunc));
346  assert_param(IS_GPIO_OUT_MODE(GPIO_InitStruct->GPIO_OutMode));
347  assert_param(IS_GPIO_PULLUP(GPIO_InitStruct->GPIO_PullUp));
348 
349  /* Preparation routine */
350  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOC) ||
351  (GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOG))
352  {
353  port_offset = 0;
354  }
355  else /* ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOD) ||
356  (GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOH)) */
357  {
358  port_offset = 16;
359  }
360 
361  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
362  {
363  GPIOPUCTLx = &(NT_COMMON_REG->GPIOPUCTL0);
364  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL0);
365  GPIODENx = &(NT_COMMON_REG->GPIODEN0);
366  }
367  else if ((GPIOx == NT_GPIOC) || (GPIOx == NT_GPIOD))
368  {
369  GPIOPUCTLx = &(NT_COMMON_REG->GPIOPUCTL1);
370  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL1);
371  GPIODENx = &(NT_COMMON_REG->GPIODEN1);
372  }
373  else if ((GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOF))
374  {
375  GPIOPUCTLx = &(NT_COMMON_REG->GPIOPUCTL2);
376  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL2);
377  GPIODENx = &(NT_COMMON_REG->GPIODEN2);
378  }
379  else /* ((GPIOx == NT_GPIOG) || (GPIOx == NT_GPIOH)) */
380  {
381  GPIOPUCTLx = &(NT_COMMON_REG->GPIOPUCTL3);
382  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL3);
383  GPIODENx = &(NT_COMMON_REG->GPIODEN3);
384  }
385 
386  /* Init routine */
387  GPIO_AltFuncConfig(GPIOx, GPIO_InitStruct->GPIO_Pin, GPIO_InitStruct->GPIO_AltFunc);
388 
389  if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IO)
390  {
391  GPIOx->ALTFUNCCLR = GPIO_InitStruct->GPIO_Pin;
392  }
393  else if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AltFunc)
394  {
395  GPIOx->ALTFUNCSET = GPIO_InitStruct->GPIO_Pin;
396  }
397 
398  if (GPIO_InitStruct->GPIO_Dir == GPIO_Dir_In)
399  {
400  GPIOx->OUTENCLR = GPIO_InitStruct->GPIO_Pin;
401  }
402  else if (GPIO_InitStruct->GPIO_Dir == GPIO_Dir_Out)
403  {
404  GPIOx->OUTENSET = GPIO_InitStruct->GPIO_Pin;
405  }
406 
407  if (GPIO_InitStruct->GPIO_PullUp == GPIO_PullUp_Dis)
408  {
409  *GPIOPUCTLx &= ~(GPIO_InitStruct->GPIO_Pin << port_offset);
410  }
411  else if (GPIO_InitStruct->GPIO_PullUp == GPIO_PullUp_En)
412  {
413  *GPIOPUCTLx |= (GPIO_InitStruct->GPIO_Pin << port_offset);
414  }
415 
416  if (GPIO_InitStruct->GPIO_OutMode == GPIO_OutMode_PP)
417  {
418  *GPIOODCTLx &= ~(GPIO_InitStruct->GPIO_Pin << port_offset);
419  }
420  else if (GPIO_InitStruct->GPIO_OutMode == GPIO_OutMode_OD)
421  {
422  *GPIOODCTLx |= (GPIO_InitStruct->GPIO_Pin << port_offset);
423  }
424 
425  if (GPIO_InitStruct->GPIO_Out == GPIO_Out_Dis)
426  {
427  *GPIODENx &= ~(GPIO_InitStruct->GPIO_Pin << port_offset);
428  }
429  else if (GPIO_InitStruct->GPIO_Out == GPIO_Out_En)
430  {
431  *GPIODENx |= (GPIO_InitStruct->GPIO_Pin << port_offset);
432  }
433 }
434 
442 void GPIO_StructInit(GPIO_Init_TypeDef* GPIO_InitStruct)
443 {
444  /* Reset GPIO init structure parameters values */
445  GPIO_InitStruct->GPIO_AltFunc = GPIO_AltFunc_1;
446  GPIO_InitStruct->GPIO_Dir = GPIO_Dir_In;
447  GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IO;
448  GPIO_InitStruct->GPIO_Out = GPIO_Out_Dis;
449  GPIO_InitStruct->GPIO_OutMode = GPIO_OutMode_PP;
450  GPIO_InitStruct->GPIO_PullUp = GPIO_PullUp_Dis;
451  GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
452 }
453 
462 uint32_t GPIO_ReadBit(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
463 {
464  uint32_t bitval;
465 
466  /* Check the parameters */
467  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
468  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
469 
470  if ((GPIOx->DATA & GPIO_Pin) != (uint32_t)Bit_CLEAR)
471  {
472  bitval = (uint32_t)Bit_SET;
473  }
474  else
475  {
476  bitval = (uint32_t)Bit_CLEAR;
477  }
478 
479  return bitval;
480 }
481 
488 uint32_t GPIO_Read(NT_GPIO_TypeDef* GPIOx)
489 {
490  /* Check the parameters */
491  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
492 
493  return ((uint32_t)GPIOx->DATA);
494 }
495 
503 uint32_t GPIO_ReadMask(NT_GPIO_TypeDef* GPIOx, uint32_t MaskVal)
504 {
505  uint32_t mask_low_byte_offset;
506  uint32_t mask_high_byte_offset;
507  uint32_t low_byte;
508  uint32_t high_byte;
509 
510  /* Check the parameters */
511  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
512 
513  mask_low_byte_offset = (MaskVal & GPIO_MASKLOWBYTE_MASKLB_Msk) >> GPIO_MASKLOWBYTE_MASKLB_Pos;
514  mask_high_byte_offset = (MaskVal & GPIO_MASKHIGHBYTE_MASKHB_Msk) >> GPIO_MASKHIGHBYTE_MASKHB_Pos;
515  low_byte = GPIOx->MASKLOWBYTE[mask_low_byte_offset];
516  high_byte = GPIOx->MASKHIGHBYTE[mask_high_byte_offset];
517 
518  return ((low_byte | high_byte));
519 }
520 
531 void GPIO_WriteBit(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, BitAction BitVal)
532 {
533  /* Check the parameters */
534  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
535  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
536  assert_param(IS_GPIO_BIT_ACTION(BitVal));
537 
538  if (BitVal == Bit_SET)
539  {
540  GPIOx->DATAOUT |= GPIO_Pin;
541  }
542  else if (BitVal == Bit_CLEAR)
543  {
544  GPIOx->DATAOUT &= ~GPIO_Pin;
545  }
546 }
547 
555 void GPIO_Write(NT_GPIO_TypeDef* GPIOx, uint32_t PortVal)
556 {
557  /* Check the parameters */
558  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
559 
560  GPIOx->DATAOUT = PortVal;
561 }
562 
571 void GPIO_WriteMask(NT_GPIO_TypeDef* GPIOx, uint32_t MaskVal, uint32_t PortVal)
572 {
573  uint32_t mask_low_byte_offset;
574  uint32_t mask_high_byte_offset;
575 
576  /* Check the parameters */
577  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
578 
579  mask_low_byte_offset = (MaskVal & GPIO_MASKLOWBYTE_MASKLB_Msk) >> GPIO_MASKLOWBYTE_MASKLB_Pos;
580  mask_high_byte_offset = (MaskVal & GPIO_MASKHIGHBYTE_MASKHB_Msk) >> GPIO_MASKHIGHBYTE_MASKHB_Pos;
581  GPIOx->MASKLOWBYTE[mask_low_byte_offset] = PortVal;
582  GPIOx->MASKHIGHBYTE[mask_high_byte_offset] = PortVal;
583 }
584 
585 
594 void GPIO_SetBits(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
595 {
596  /* Check the parameters */
597  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
598  assert_param(IS_GPIO_PIN(GPIO_Pin));
599 
600  GPIOx->DATAOUT |= GPIO_Pin;
601 }
602 
611 void GPIO_ClearBits(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
612 {
613  /* Check the parameters */
614  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
615  assert_param(IS_GPIO_PIN(GPIO_Pin));
616 
617  GPIOx->DATAOUT &= ~GPIO_Pin;
618 }
619 
628 void GPIO_ToggleBits(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
629 {
630  /* Check the parameters */
631  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
632  assert_param(IS_GPIO_PIN(GPIO_Pin));
633 
634  GPIOx->DATAOUT ^= GPIO_Pin;
635 }
636 
649 void GPIO_QualConfig(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, GPIO_QualMode_TypeDef Mode, uint32_t SamplePerod)
650 {
651  uint32_t gpioqp_port_pos;
652  __IO uint32_t* GPIOQMx;
653  __IO uint32_t* GPIOQPx;
654 
655  /* Check the parameters */
656  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
657  assert_param(IS_GPIO_PIN(GPIO_Pin));
658  assert_param(IS_GPIO_QUAL_MODE(Mode));
659  assert_param(IS_GPIO_QUAL_PERIOD(SamplePerod));
660 
661  /* Preparation routine */
662  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
663  {
664  GPIOQMx = &(NT_COMMON_REG->GPIOQM0);
665  GPIOQPx = &(NT_COMMON_REG->GPIOQPAD);
666  if (GPIOx == NT_GPIOA)
667  {
668  gpioqp_port_pos = COMMON_REG_GPIOQPAD_SPRDA_Pos;
669  }
670  else /* (GPIOx == NT_GPIOB) */
671  {
672  gpioqp_port_pos = COMMON_REG_GPIOQPAD_SPRDB_Pos;
673  }
674  }
675  else if ((GPIOx == NT_GPIOC) || (GPIOx == NT_GPIOD))
676  {
677  GPIOQMx = &(NT_COMMON_REG->GPIOQM1);
678  GPIOQPx = &(NT_COMMON_REG->GPIOQPAD);
679  if (GPIOx == NT_GPIOC)
680  {
681  gpioqp_port_pos = COMMON_REG_GPIOQPAD_SPRDC_Pos;
682  }
683  else /* (GPIOx == NT_GPIOD) */
684  {
685  gpioqp_port_pos = COMMON_REG_GPIOQPAD_SPRDD_Pos;
686  }
687  }
688  else if ((GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOF))
689  {
690  GPIOQMx = &(NT_COMMON_REG->GPIOQM2);
691  GPIOQPx = &(NT_COMMON_REG->GPIOQPEH);
692  if (GPIOx == NT_GPIOE)
693  {
694  gpioqp_port_pos = COMMON_REG_GPIOQPEH_SPRDE_Pos;
695  }
696  else /* (GPIOx == NT_GPIOF) */
697  {
698  gpioqp_port_pos = COMMON_REG_GPIOQPEH_SPRDF_Pos;
699  }
700  }
701  else /* ((GPIOx == NT_GPIOG) || (GPIOx == NT_GPIOH)) */
702  {
703  GPIOQMx = &(NT_COMMON_REG->GPIOQM3);
704  GPIOQPx = &(NT_COMMON_REG->GPIOQPEH);
705  if (GPIOx == NT_GPIOG)
706  {
707  gpioqp_port_pos = COMMON_REG_GPIOQPEH_SPRDG_Pos;
708  }
709  else /* (GPIOx == NT_GPIOH) */
710  {
711  gpioqp_port_pos = COMMON_REG_GPIOQPEH_SPRDH_Pos;
712  }
713  }
714 
715  /* Config procedure */
716  if (Mode == GPIO_QualMode_3sample)
717  {
718  *GPIOQMx &= ~GPIO_Pin;
719  }
720  else if (Mode == GPIO_QualMode_6sample)
721  {
722  *GPIOQMx |= GPIO_Pin;
723  }
724 
725  *GPIOQPx = SamplePerod << gpioqp_port_pos;
726 }
727 
738 void GPIO_QualCmd(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, FunctionalState State)
739 {
740  uint32_t port_offset;
741  __IO uint32_t* GPIOQEx;
742 
743  /* Check the parameters */
744  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
745  assert_param(IS_GPIO_PIN(GPIO_Pin));
746  assert_param(IS_FUNCTIONAL_STATE(State));
747 
748  /* Preparation routine */
749  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOC) ||
750  (GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOG))
751  {
752  port_offset = 0;
753  }
754  else /* ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOD) ||
755  (GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOH)) */
756  {
757  port_offset = 16;
758  }
759 
760  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
761  {
762  GPIOQEx = &(NT_COMMON_REG->GPIOQE0);
763  }
764  else if ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOC))
765  {
766  GPIOQEx = &(NT_COMMON_REG->GPIOQE1);
767  }
768  else if ((GPIOx == NT_GPIOD) || (GPIOx == NT_GPIOE))
769  {
770  GPIOQEx = &(NT_COMMON_REG->GPIOQE2);
771  }
772  else /* ((GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOG)) */
773  {
774  GPIOQEx = &(NT_COMMON_REG->GPIOQE3);
775  }
776 
777  /* Cmd procedure */
778  if (State == DISABLE)
779  {
780  *GPIOQEx &= ~(GPIO_Pin<<port_offset);
781  }
782  else if (State == ENABLE)
783  {
784  *GPIOQEx |= GPIO_Pin<<port_offset;
785  }
786 }
787 
788 
799 void GPIO_SyncCmd(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, FunctionalState State)
800 {
801  uint32_t port_offset;
802  __IO uint32_t* GPIOSEx;
803 
804  /* Check the parameters */
805  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
806  assert_param(IS_GPIO_PIN(GPIO_Pin));
807  assert_param(IS_FUNCTIONAL_STATE(State));
808 
809  /* Preparation routine */
810  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOC) ||
811  (GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOG))
812  {
813  port_offset = 0;
814  }
815  else /* ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOD) ||
816  (GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOH)) */
817  {
818  port_offset = 16;
819  }
820 
821  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
822  {
823  GPIOSEx = &(NT_COMMON_REG->GPIOSE0);
824  }
825  else if ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOC))
826  {
827  GPIOSEx = &(NT_COMMON_REG->GPIOSE1);
828  }
829  else if ((GPIOx == NT_GPIOD) || (GPIOx == NT_GPIOE))
830  {
831  GPIOSEx = &(NT_COMMON_REG->GPIOSE2);
832  }
833  else /* ((GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOG)) */
834  {
835  GPIOSEx = &(NT_COMMON_REG->GPIOSE3);
836  }
837 
838  /* Cmd procedure */
839  if (State == DISABLE)
840  {
841  *GPIOSEx &= ~(GPIO_Pin<<port_offset);
842  }
843  else if (State == ENABLE)
844  {
845  *GPIOSEx |= GPIO_Pin<<port_offset;
846  }
847 }
848 
861 void GPIO_ITConfig(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, GPIO_IntType_TypeDef IntType, GPIO_IntPol_TypeDef IntPol)
862 {
863  /* Check the parameters */
864  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
865  assert_param(IS_GPIO_PIN(GPIO_Pin));
866  assert_param(IS_GPIO_INT_TYPE(IntType));
867  assert_param(IS_GPIO_INT_POL(IntPol));
868 
869  if (IntType == GPIO_IntType_Level)
870  {
871  GPIOx->INTTYPECLR = GPIO_Pin;
872  }
873  else if (IntType == GPIO_IntType_Edge)
874  {
875  GPIOx->INTTYPESET = GPIO_Pin;
876  }
877 
878  if (IntPol == GPIO_IntPol_Neg)
879  {
880  GPIOx->INTPOLCLR = GPIO_Pin;
881  }
882  else if (IntPol == GPIO_IntPol_Pos)
883  {
884  GPIOx->INTPOLSET = GPIO_Pin;
885  }
886 }
887 
898 void GPIO_ITCmd(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, FunctionalState State)
899 {
900  /* Check the parameters */
901  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
902  assert_param(IS_GPIO_PIN(GPIO_Pin));
903  assert_param(IS_FUNCTIONAL_STATE(State));
904 
905  if (State == DISABLE)
906  {
907  GPIOx->INTENCLR = GPIO_Pin;
908  }
909  else if (State == ENABLE)
910  {
911  GPIOx->INTENSET = GPIO_Pin;
912  }
913 }
914 
923 void GPIO_ITStatusClear(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
924 {
925  /* Check the parameters */
926  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
927  assert_param(IS_GPIO_PIN(GPIO_Pin));
928 
929  GPIOx->INTSTATUS = GPIO_Pin;
930 }
931 
941 FlagStatus GPIO_ITStatus(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
942 {
943  FlagStatus Status;
944  /* Check the parameters */
945  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
946  assert_param(IS_GPIO_PIN(GPIO_Pin));
947 
948  if (GPIOx->INTSTATUS & GPIO_Pin)
949  {
950  Status = Flag_SET;
951  }
952  else
953  {
954  Status = Flag_CLEAR;
955  }
956 
957  return Status;
958 }
959 
976 /******************* (C) COPYRIGHT 2015 NIIET *****END OF FILE****/
#define IS_GPIO_OUT_MODE(OUT_MODE)
Макрос проверки аргументов типа GPIO_OutMode_TypeDef.
FlagStatus GPIO_ITStatus(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
Чтение флага прерываний выбранных пинов.
void GPIO_WriteBit(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, BitAction BitVal)
Изменение состояния выбранного пина.
#define GPIO_DATAOUT_Reset_Value
Definition: niietcm4_gpio.c:72
#define IS_GPIO_ALT_FUNC(ALT_FUNC)
Макрос проверки аргументов типа GPIO_AltFunc_TypeDef.
#define GPIO_GPIODEN2_Reset_Value
Definition: niietcm4_gpio.c:75
#define IS_GPIO_ALL_PERIPH(PERIPH)
Макрос проверки аргументов типа NT_GPIO_TypeDef.
Definition: niietcm4.h:213
GPIO_AltFunc_TypeDef GPIO_AltFunc
#define IS_GET_GPIO_PIN(PIN)
Макрос проверки номера пина при работе с пинами по отдельности.
void GPIO_Init(NT_GPIO_TypeDef *GPIOx, GPIO_Init_TypeDef *GPIO_InitStruct)
Инициализирует модуль GPIOx согласно параметрам структуры GPIO_InitStruct.
#define GPIO_GPIOSEx_Reset_Value
Definition: niietcm4_gpio.c:79
void GPIO_WriteMask(NT_GPIO_TypeDef *GPIOx, uint32_t MaskVal, uint32_t PortVal)
Изменение состояния выбранного порта GPIOx с использованием маски.
void GPIO_AltFuncConfig(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, GPIO_AltFunc_TypeDef GPIO_AltFunc)
Осуществляет выбор альтернативной функции вывода GPIOx.
#define IS_GPIO_OUT(OUT)
Макрос проверки аргументов типа GPIO_Out_TypeDef.
void GPIO_StructInit(GPIO_Init_TypeDef *GPIO_InitStruct)
Заполнение каждого члена структуры GPIO_InitStruct значениями по умолчанию.
void GPIO_ClearBits(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
Сброс выбранных пинов.
#define GPIO_GPIODEN0_Reset_Value
Definition: niietcm4_gpio.c:73
#define GPIO_Regs_A_C_E_G_Mask
Definition: niietcm4_gpio.c:93
#define IS_GPIO_PULLUP(PULLUP)
Макрос проверки аргументов типа GPIO_PullUp_TypeDef.
uint32_t GPIO_ReadBit(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
Чтение состояния выбранного пина.
GPIO_OutMode_TypeDef GPIO_OutMode
void GPIO_QualConfig(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, GPIO_QualMode_TypeDef Mode, uint32_t SamplePerod)
Настройка фильтра выбранных пинов.
GPIO_IntPol_TypeDef
Выбор полярности события для возникновения прерывания.
#define GPIO_GPIOQMx_Reset_Value
Definition: niietcm4_gpio.c:81
void GPIO_ITCmd(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, FunctionalState State)
Включение прерываний выбранных пинов.
#define GPIO_GPIOQEx_Reset_Value
Definition: niietcm4_gpio.c:80
#define GPIO_GPIOPCTLx_Reset_Value
Definition: niietcm4_gpio.c:82
GPIO_AltFunc_TypeDef
Выбор номера альтернативной функции пина.
#define GPIO_GPIOPUCTLx_Reset_Value
Definition: niietcm4_gpio.c:78
#define IS_GPIO_INT_POL(INT_POL)
Макрос проверки аргументов типа GPIO_IntPol_TypeDef.
void GPIO_ITConfig(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, GPIO_IntType_TypeDef IntType, GPIO_IntPol_TypeDef IntPol)
Настройка прерываний пинов.
#define IS_GPIO_MODE(MODE)
Макрос проверки аргументов типа GPIO_Mode_TypeDef.
GPIO_Out_TypeDef GPIO_Out
GPIO_IntType_TypeDef
Выбор события для возникновения прерывания.
Структура инициализации GPIO.
#define GPIO_Pin_All
FlagStatus
Описывает возможные состояния флага при запросе его статуса.
Definition: niietcm4.h:195
#define IS_GPIO_DIR(DIR)
Макрос проверки аргументов типа GPIO_Dir_TypeDef.
Definition: niietcm4_gpio.h:88
GPIO_Mode_TypeDef GPIO_Mode
#define IS_GPIO_QUAL_PERIOD(PERIOD)
Макрос проверки соответсвия величины периода фильтрации разрешенному диапазону.
Definition: niietcm4_gpio.h:56
void GPIO_QualCmd(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, FunctionalState State)
Включение входных фильтров.
void GPIO_SyncCmd(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, FunctionalState State)
Включение пересинхронизации входов через 2 триггера-защелки.
FunctionalState
Описывает логическое состояние периферии. Используется для операций включения/выключения периферийных...
Definition: niietcm4.h:169
void GPIO_Write(NT_GPIO_TypeDef *GPIOx, uint32_t PortVal)
Изменение состояния выбранного порта GPIOx.
#define IS_GPIO_QUAL_MODE(QUAL_MODE)
Макрос проверки аргументов типа GPIO_QualMode_TypeDef.
void GPIO_SetBits(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
Установка выбранных пинов.
BitAction
Тип, определяющий состояния бита.
Definition: niietcm4_gpio.h:62
#define GPIO_GPIOODCTLx_Reset_Value
Definition: niietcm4_gpio.c:77
#define GPIO_Regs_B_D_F_H_Mask
Definition: niietcm4_gpio.c:94
#define IS_FUNCTIONAL_STATE(STATE)
Макрос проверки аргументов типа FunctionalState.
Definition: niietcm4.h:179
#define GPIO_GPIODEN3_Reset_Value
Definition: niietcm4_gpio.c:76
void GPIO_ToggleBits(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
Переключение выбранных пинов в противоположное состояние.
GPIO_PullUp_TypeDef GPIO_PullUp
GPIO_Dir_TypeDef GPIO_Dir
GPIO_QualMode_TypeDef
Выбор режима работы входного фильтра.
#define IS_GPIO_PIN(PIN)
Макрос проверки номеров пинов на попадание в допустимый диапазон.
#define IS_GPIO_BIT_ACTION(ACTION)
Макрос проверки аргументов типа BitAction.
Definition: niietcm4_gpio.h:72
Файл содержит все прототипы функций для GPIO.
#define GPIO_GPIODEN1_Reset_Value
Definition: niietcm4_gpio.c:74
void GPIO_ITStatusClear(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
Очистка флагов прерываний выбранных пинов.
uint32_t GPIO_ReadMask(NT_GPIO_TypeDef *GPIOx, uint32_t MaskVal)
Чтение состояния выбранного порта GPIOx c использованием маски.
#define GPIO_GPIOQPx_Reset_Value
Definition: niietcm4_gpio.c:83
uint32_t GPIO_Read(NT_GPIO_TypeDef *GPIOx)
Чтение состояния выбранного порта GPIOx.
#define IS_GPIO_INT_TYPE(INT_TYPE)
Макрос проверки аргументов типа GPIO_IntType_TypeDef.