NIIETCM4 PD  v0.7.0
Драйвер периферии для микроконтроллеров на базе ядра 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_GPIOODSCTLx_Reset_Value ((uint32_t)0x00000000)
79 #define GPIO_GPIOPUCTLx_Reset_Value ((uint32_t)0x00000000)
80 #define GPIO_GPIOSEx_Reset_Value ((uint32_t)0x00000000)
81 #define GPIO_GPIOQEx_Reset_Value ((uint32_t)0x00000000)
82 #define GPIO_GPIOQMx_Reset_Value ((uint32_t)0x00000000)
83 #define GPIO_GPIOPCTLx_Reset_Value ((uint32_t)0x00000000)
84 #define GPIO_GPIOQPx_Reset_Value ((uint32_t)0x00000000)
94 #define GPIO_Regs_A_C_E_G_Mask ((uint32_t)0x0000FFFF)
95 #define GPIO_Regs_B_D_F_H_Mask ((uint32_t)0xFFFF0000)
96 #define GPIO_Regs_GPIOA_Mask ((uint32_t)0x0000FFFF)
97 #define GPIO_Regs_GPIOB_Mask ((uint32_t)0xFFFF0000)
98 #define GPIO_Regs_GPIOC_Mask ((uint32_t)0x0000FFFF)
99 #define GPIO_Regs_GPIOD_Mask ((uint32_t)0xFFFF0000)
100 #define GPIO_Regs_GPIOE_Mask ((uint32_t)0x0000FFFF)
101 #define GPIO_Regs_GPIOF_Mask ((uint32_t)0xFFFF0000)
102 #define GPIO_Regs_GPIOG_Mask ((uint32_t)0x0000FFFF)
103 #define GPIO_Regs_GPIOH_Mask ((uint32_t)0xFFFF0000)
123 void GPIO_DeInit(NT_GPIO_TypeDef* GPIOx)
124 {
125  uint32_t reg_port_mask;
126  uint32_t gpioqp_port_mask;
127  uint32_t gpiodenx_reset_value;
128  __IO uint32_t* GPIODENx;
129  __IO uint32_t* GPIOODCTLx;
130  __IO uint32_t* GPIOODSCTLx;
131  __IO uint32_t* GPIOPUCTLx;
132  __IO uint32_t* GPIOSEx;
133  __IO uint32_t* GPIOQEx;
134  __IO uint32_t* GPIOQMx;
135  __IO uint32_t* GPIOPCTLx;
136  __IO uint32_t* GPIOQPx;
137 
138  /* Check the parameters */
139  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
140 
141  /* Preparation routine */
142  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOC) ||
143  (GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOG))
144  {
145  reg_port_mask = GPIO_Regs_A_C_E_G_Mask;
146  }
147  else /* ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOD) ||
148  (GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOH)) */
149  {
150  reg_port_mask = GPIO_Regs_B_D_F_H_Mask;
151  }
152 
153  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
154  {
155  GPIODENx = &(NT_COMMON_REG->GPIODEN0);
156  gpiodenx_reset_value = GPIO_GPIODEN0_Reset_Value;
157  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL0);
158  GPIOODSCTLx = &(NT_COMMON_REG->GPIOODSCTL0);
159  GPIOPUCTLx = &(NT_COMMON_REG->GPIOPUCTL0);
160  GPIOSEx = &(NT_COMMON_REG->GPIOSE0);
161  GPIOQEx = &(NT_COMMON_REG->GPIOQE0);
162  GPIOQMx = &(NT_COMMON_REG->GPIOQM0);
163  GPIOQPx = &(NT_COMMON_REG->GPIOQPAD);
164  if (GPIOx == NT_GPIOA)
165  {
166  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLA);
167  gpioqp_port_mask = GPIOQPAD_SPRDA_Msk;
168  }
169  else /* (GPIOx == NT_GPIOB) */
170  {
171  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLB);
172  gpioqp_port_mask = GPIOQPAD_SPRDB_Msk;
173  }
174  }
175  else if ((GPIOx == NT_GPIOC) || (GPIOx == NT_GPIOD))
176  {
177  GPIODENx = &(NT_COMMON_REG->GPIODEN1);
178  gpiodenx_reset_value = GPIO_GPIODEN1_Reset_Value;
179  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL1);
180  GPIOODSCTLx = &(NT_COMMON_REG->GPIOODSCTL1);
181  GPIOPUCTLx = &(NT_COMMON_REG->GPIOPUCTL1);
182  GPIOSEx = &(NT_COMMON_REG->GPIOSE1);
183  GPIOQEx = &(NT_COMMON_REG->GPIOQE1);
184  GPIOQMx = &(NT_COMMON_REG->GPIOQM1);
185  GPIOQPx = &(NT_COMMON_REG->GPIOQPAD);
186  if (GPIOx == NT_GPIOC)
187  {
188  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLC);
189  gpioqp_port_mask = GPIOQPAD_SPRDC_Msk;
190  }
191  else /* (GPIOx == NT_GPIOD) */
192  {
193  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLD);
194  gpioqp_port_mask = GPIOQPAD_SPRDD_Msk;
195  }
196  }
197  else if ((GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOF))
198  {
199  GPIODENx = &(NT_COMMON_REG->GPIODEN2);
200  gpiodenx_reset_value = GPIO_GPIODEN2_Reset_Value;
201  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL2);
202  GPIOODSCTLx = &(NT_COMMON_REG->GPIOODSCTL2);
203  GPIOPUCTLx = &(NT_COMMON_REG->GPIOPUCTL2);
204  GPIOSEx = &(NT_COMMON_REG->GPIOSE2);
205  GPIOQEx = &(NT_COMMON_REG->GPIOQE2);
206  GPIOQMx = &(NT_COMMON_REG->GPIOQM2);
207  GPIOQPx = &(NT_COMMON_REG->GPIOQPEH);
208  if (GPIOx == NT_GPIOE)
209  {
210  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLE);
211  gpioqp_port_mask = GPIOQPEH_SPRDE_Msk;
212  }
213  else /* (GPIOx == NT_GPIOF) */
214  {
215  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLF);
216  gpioqp_port_mask = GPIOQPEH_SPRDF_Msk;
217  }
218  }
219  else /* ((GPIOx == NT_GPIOG) || (GPIOx == NT_GPIOH)) */
220  {
221  GPIODENx = &(NT_COMMON_REG->GPIODEN3);
222  gpiodenx_reset_value = GPIO_GPIODEN3_Reset_Value;
223  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL3);
224  GPIOODSCTLx = &(NT_COMMON_REG->GPIOODSCTL3);
225  GPIOPUCTLx = &(NT_COMMON_REG->GPIOPUCTL3);
226  GPIOSEx = &(NT_COMMON_REG->GPIOSE3);
227  GPIOQEx = &(NT_COMMON_REG->GPIOQE3);
228  GPIOQMx = &(NT_COMMON_REG->GPIOQM3);
229  GPIOQPx = &(NT_COMMON_REG->GPIOQPEH);
230  if (GPIOx == NT_GPIOG)
231  {
232  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLG);
233  gpioqp_port_mask = GPIOQPEH_SPRDG_Msk;
234  }
235  else /* (GPIOx == NT_GPIOH) */
236  {
237  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLH);
238  gpioqp_port_mask = GPIOQPEH_SPRDH_Msk;
239  }
240  }
241  /* Reset all port regs and bit fields */
242  GPIOx->DATAOUT = GPIO_DATAOUT_Reset_Value;
243  GPIOx->OUTENCLR = ((uint32_t)0xFFFFFFFF);
244  GPIOx->ALTFUNCCLR = ((uint32_t)0xFFFFFFFF);
245  GPIOx->INTENCLR = ((uint32_t)0xFFFFFFFF);
246  GPIOx->INTTYPECLR = ((uint32_t)0xFFFFFFFF);
247  GPIOx->INTPOLCLR = ((uint32_t)0xFFFFFFFF);
248  GPIOx->INTSTATUS = ((uint32_t)0xFFFFFFFF);
249  *GPIODENx &= ~reg_port_mask;
250  *GPIODENx |= (gpiodenx_reset_value & reg_port_mask);
251  *GPIOODCTLx &= ~reg_port_mask;
252  *GPIOODCTLx |= (GPIO_GPIOODCTLx_Reset_Value & reg_port_mask);
253  *GPIOODSCTLx &= ~reg_port_mask;
254  *GPIOODSCTLx |= (GPIO_GPIOODSCTLx_Reset_Value & reg_port_mask);
255  *GPIOPUCTLx &= ~reg_port_mask;
256  *GPIOPUCTLx |= (GPIO_GPIOPUCTLx_Reset_Value & reg_port_mask);
257  *GPIOSEx &= ~reg_port_mask;
258  *GPIOSEx |= (GPIO_GPIOSEx_Reset_Value & reg_port_mask);
259  *GPIOQEx &= ~reg_port_mask;
260  *GPIOQEx |= (GPIO_GPIOQEx_Reset_Value & reg_port_mask);
261  *GPIOQMx &= ~reg_port_mask;
262  *GPIOQMx |= (GPIO_GPIOQMx_Reset_Value & reg_port_mask);
263  *GPIOPCTLx = GPIO_GPIOPCTLx_Reset_Value;
264  *GPIOQPx &= ~gpioqp_port_mask;
265  *GPIOQPx |= (GPIO_GPIOQPx_Reset_Value & gpioqp_port_mask);
266 }
267 
268 
269 void GPIO_AltFuncConfig(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, GPIO_AltFunc_TypeDef GPIO_AltFunc)
270 {
271  uint32_t alt_func_temp;
272  __IO uint32_t* GPIOPCTLx;
273 
274  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
275  assert_param(IS_GPIO_PIN(GPIO_Pin));
276  assert_param(IS_GPIO_ALT_FUNC(GPIO_AltFunc));
277 
278  if (GPIOx == NT_GPIOA)
279  {
280  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLA);
281  }
282  else if (GPIOx == NT_GPIOB)
283  {
284  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLB);
285  }
286  else if (GPIOx == NT_GPIOC)
287  {
288  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLC);
289  }
290  else if (GPIOx == NT_GPIOD)
291  {
292  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLD);
293  }
294  else if (GPIOx == NT_GPIOE)
295  {
296  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLE);
297  }
298  else if (GPIOx == NT_GPIOF)
299  {
300  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLF);
301  }
302  else if (GPIOx == NT_GPIOG)
303  {
304  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLG);
305  }
306  else /* (GPIOx == NT_GPIOH) */
307  {
308  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLH);
309  }
310 
311  alt_func_temp = *GPIOPCTLx;
312  for (uint32_t i = 0; i < 16; i++)
313  {
314  if (GPIO_Pin & (1<<i))
315  {
316  alt_func_temp &= ~(3 << i*2);
317  alt_func_temp |= GPIO_AltFunc << i*2;
318  }
319  }
320  *GPIOPCTLx = alt_func_temp;
321 }
322 
331 void GPIO_Init(NT_GPIO_TypeDef* GPIOx, GPIO_Init_TypeDef* GPIO_InitStruct)
332 {
333  uint32_t port_offset;
334  __IO uint32_t* GPIOODSCTLx;
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_LOAD(GPIO_InitStruct->GPIO_Load));
347  assert_param(IS_GPIO_OUT_MODE(GPIO_InitStruct->GPIO_OutMode));
348  assert_param(IS_GPIO_PULLUP(GPIO_InitStruct->GPIO_PullUp));
349 
350  /* Preparation routine */
351  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOC) ||
352  (GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOG))
353  {
354  port_offset = 0;
355  }
356  else /* ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOD) ||
357  (GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOH)) */
358  {
359  port_offset = 16;
360  }
361 
362  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
363  {
364  GPIOODSCTLx = &(NT_COMMON_REG->GPIOODSCTL0);
365  GPIOPUCTLx = &(NT_COMMON_REG->GPIOODSCTL0);
366  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL0);
367  GPIODENx = &(NT_COMMON_REG->GPIODEN0);
368  }
369  else if ((GPIOx == NT_GPIOC) || (GPIOx == NT_GPIOD))
370  {
371  GPIOODSCTLx = &(NT_COMMON_REG->GPIOODSCTL1);
372  GPIOPUCTLx = &(NT_COMMON_REG->GPIOODSCTL1);
373  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL1);
374  GPIODENx = &(NT_COMMON_REG->GPIODEN1);
375  }
376  else if ((GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOF))
377  {
378  GPIOODSCTLx = &(NT_COMMON_REG->GPIOODSCTL2);
379  GPIOPUCTLx = &(NT_COMMON_REG->GPIOODSCTL2);
380  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL2);
381  GPIODENx = &(NT_COMMON_REG->GPIODEN2);
382  }
383  else /* ((GPIOx == NT_GPIOG) || (GPIOx == NT_GPIOH)) */
384  {
385  GPIOODSCTLx = &(NT_COMMON_REG->GPIOODSCTL3);
386  GPIOPUCTLx = &(NT_COMMON_REG->GPIOODSCTL3);
387  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL3);
388  GPIODENx = &(NT_COMMON_REG->GPIODEN3);
389  }
390 
391  /* Init routine */
392  GPIO_AltFuncConfig(GPIOx, GPIO_InitStruct->GPIO_Pin, GPIO_InitStruct->GPIO_AltFunc);
393 
394  if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IO)
395  {
396  GPIOx->ALTFUNCCLR = GPIO_InitStruct->GPIO_Pin;
397  }
398  else if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AltFunc)
399  {
400  GPIOx->ALTFUNCSET = GPIO_InitStruct->GPIO_Pin;
401  }
402 
403  if (GPIO_InitStruct->GPIO_Dir == GPIO_Dir_In)
404  {
405  GPIOx->OUTENCLR = GPIO_InitStruct->GPIO_Pin;
406  }
407  else if (GPIO_InitStruct->GPIO_Dir == GPIO_Dir_Out)
408  {
409  GPIOx->OUTENSET = GPIO_InitStruct->GPIO_Pin;
410  }
411 
412  if (GPIO_InitStruct->GPIO_Load == GPIO_Load_8mA)
413  {
414  *GPIOODSCTLx &= ~(GPIO_InitStruct->GPIO_Pin << port_offset);
415  }
416  else if (GPIO_InitStruct->GPIO_Load == GPIO_Load_16mA)
417  {
418  *GPIOODSCTLx |= (GPIO_InitStruct->GPIO_Pin << port_offset);
419  }
420 
421  if (GPIO_InitStruct->GPIO_PullUp == GPIO_PullUp_Dis)
422  {
423  *GPIOPUCTLx &= ~(GPIO_InitStruct->GPIO_Pin << port_offset);
424  }
425  else if (GPIO_InitStruct->GPIO_PullUp == GPIO_PullUp_En)
426  {
427  *GPIOPUCTLx |= (GPIO_InitStruct->GPIO_Pin << port_offset);
428  }
429 
430  if (GPIO_InitStruct->GPIO_OutMode == GPIO_OutMode_PP)
431  {
432  *GPIOODCTLx &= ~(GPIO_InitStruct->GPIO_Pin << port_offset);
433  }
434  else if (GPIO_InitStruct->GPIO_OutMode == GPIO_OutMode_OD)
435  {
436  *GPIOODCTLx |= (GPIO_InitStruct->GPIO_Pin << port_offset);
437  }
438 
439  if (GPIO_InitStruct->GPIO_Out == GPIO_Out_Dis)
440  {
441  *GPIODENx &= ~(GPIO_InitStruct->GPIO_Pin << port_offset);
442  }
443  else if (GPIO_InitStruct->GPIO_Out == GPIO_Out_En)
444  {
445  *GPIODENx |= (GPIO_InitStruct->GPIO_Pin << port_offset);
446  }
447 }
448 
456 void GPIO_StructInit(GPIO_Init_TypeDef* GPIO_InitStruct)
457 {
458  /* Reset GPIO init structure parameters values */
459  GPIO_InitStruct->GPIO_AltFunc = GPIO_AltFunc_1;
460  GPIO_InitStruct->GPIO_Dir = GPIO_Dir_In;
461  GPIO_InitStruct->GPIO_Load = GPIO_Load_8mA;
462  GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IO;
463  GPIO_InitStruct->GPIO_Out = GPIO_Out_Dis;
464  GPIO_InitStruct->GPIO_OutMode = GPIO_OutMode_PP;
465  GPIO_InitStruct->GPIO_PullUp = GPIO_PullUp_Dis;
466  GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
467 }
468 
477 uint32_t GPIO_ReadBit(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
478 {
479  uint32_t bitval;
480 
481  /* Check the parameters */
482  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
483  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
484 
485  if ((GPIOx->DATA & GPIO_Pin) != (uint32_t)Bit_CLEAR)
486  {
487  bitval = (uint32_t)Bit_SET;
488  }
489  else
490  {
491  bitval = (uint32_t)Bit_CLEAR;
492  }
493 
494  return bitval;
495 }
496 
503 uint32_t GPIO_Read(NT_GPIO_TypeDef* GPIOx)
504 {
505  /* Check the parameters */
506  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
507 
508  return ((uint32_t)GPIOx->DATA);
509 }
510 
518 uint32_t GPIO_ReadMask(NT_GPIO_TypeDef* GPIOx, uint32_t MaskVal)
519 {
520  uint32_t mask_low_byte_offset;
521  uint32_t mask_high_byte_offset;
522  uint32_t low_byte;
523  uint32_t high_byte;
524 
525  /* Check the parameters */
526  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
527 
528  mask_low_byte_offset = (MaskVal & MASKLOWBYTE_MASKLB_Msk) >> MASKLOWBYTE_MASKLB_Pos;
529  mask_high_byte_offset = (MaskVal & MASKHIGHBYTE_MASKHB_Msk) >> MASKHIGHBYTE_MASKHB_Pos;
530  low_byte = GPIOx->MASKLOWBYTE[mask_low_byte_offset];
531  high_byte = GPIOx->MASKHIGHBYTE[mask_high_byte_offset];
532 
533  return ((low_byte | high_byte));
534 }
535 
546 void GPIO_WriteBit(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, BitAction BitVal)
547 {
548  /* Check the parameters */
549  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
550  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
551  assert_param(IS_GPIO_BIT_ACTION(BitVal));
552 
553  if (BitVal == Bit_SET)
554  {
555  GPIOx->DATAOUT |= GPIO_Pin;
556  }
557  else if (BitVal == Bit_CLEAR)
558  {
559  GPIOx->DATAOUT &= ~GPIO_Pin;
560  }
561 }
562 
570 void GPIO_Write(NT_GPIO_TypeDef* GPIOx, uint32_t PortVal)
571 {
572  /* Check the parameters */
573  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
574 
575  GPIOx->DATAOUT = PortVal;
576 }
577 
586 void GPIO_WriteMask(NT_GPIO_TypeDef* GPIOx, uint32_t MaskVal, uint32_t PortVal)
587 {
588  uint32_t mask_low_byte_offset;
589  uint32_t mask_high_byte_offset;
590 
591  /* Check the parameters */
592  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
593 
594  mask_low_byte_offset = (MaskVal & MASKLOWBYTE_MASKLB_Msk) >> MASKLOWBYTE_MASKLB_Pos;
595  mask_high_byte_offset = (MaskVal & MASKHIGHBYTE_MASKHB_Msk) >> MASKHIGHBYTE_MASKHB_Pos;
596  GPIOx->MASKLOWBYTE[mask_low_byte_offset] = PortVal;
597  GPIOx->MASKHIGHBYTE[mask_high_byte_offset] = PortVal;
598 }
599 
600 
609 void GPIO_SetBits(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
610 {
611  /* Check the parameters */
612  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
613  assert_param(IS_GPIO_PIN(GPIO_Pin));
614 
615  GPIOx->DATAOUT |= GPIO_Pin;
616 }
617 
626 void GPIO_ClearBits(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
627 {
628  /* Check the parameters */
629  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
630  assert_param(IS_GPIO_PIN(GPIO_Pin));
631 
632  GPIOx->DATAOUT &= ~GPIO_Pin;
633 }
634 
643 void GPIO_ToggleBits(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
644 {
645  /* Check the parameters */
646  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
647  assert_param(IS_GPIO_PIN(GPIO_Pin));
648 
649  GPIOx->DATAOUT ^= GPIO_Pin;
650 }
651 
664 void GPIO_QualConfig(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, GPIO_QualMode_TypeDef Mode, uint32_t SamplePerod)
665 {
666  uint32_t gpioqp_port_pos;
667  __IO uint32_t* GPIOQMx;
668  __IO uint32_t* GPIOQPx;
669 
670  /* Check the parameters */
671  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
672  assert_param(IS_GPIO_PIN(GPIO_Pin));
673  assert_param(IS_GPIO_QUAL_MODE(Mode));
674  assert_param(IS_GPIO_QUAL_PERIOD(SamplePerod));
675 
676  /* Preparation routine */
677  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
678  {
679  GPIOQMx = &(NT_COMMON_REG->GPIOQM0);
680  GPIOQPx = &(NT_COMMON_REG->GPIOQPAD);
681  if (GPIOx == NT_GPIOA)
682  {
683  gpioqp_port_pos = GPIOQPAD_SPRDA_Pos;
684  }
685  else /* (GPIOx == NT_GPIOB) */
686  {
687  gpioqp_port_pos = GPIOQPAD_SPRDB_Pos;
688  }
689  }
690  else if ((GPIOx == NT_GPIOC) || (GPIOx == NT_GPIOD))
691  {
692  GPIOQMx = &(NT_COMMON_REG->GPIOQM1);
693  GPIOQPx = &(NT_COMMON_REG->GPIOQPAD);
694  if (GPIOx == NT_GPIOC)
695  {
696  gpioqp_port_pos = GPIOQPAD_SPRDC_Pos;
697  }
698  else /* (GPIOx == NT_GPIOD) */
699  {
700  gpioqp_port_pos = GPIOQPAD_SPRDD_Pos;
701  }
702  }
703  else if ((GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOF))
704  {
705  GPIOQMx = &(NT_COMMON_REG->GPIOQM2);
706  GPIOQPx = &(NT_COMMON_REG->GPIOQPEH);
707  if (GPIOx == NT_GPIOE)
708  {
709  gpioqp_port_pos = GPIOQPEH_SPRDE_Pos;
710  }
711  else /* (GPIOx == NT_GPIOF) */
712  {
713  gpioqp_port_pos = GPIOQPEH_SPRDF_Pos;
714  }
715  }
716  else /* ((GPIOx == NT_GPIOG) || (GPIOx == NT_GPIOH)) */
717  {
718  GPIOQMx = &(NT_COMMON_REG->GPIOQM3);
719  GPIOQPx = &(NT_COMMON_REG->GPIOQPEH);
720  if (GPIOx == NT_GPIOG)
721  {
722  gpioqp_port_pos = GPIOQPEH_SPRDG_Pos;
723  }
724  else /* (GPIOx == NT_GPIOH) */
725  {
726  gpioqp_port_pos = GPIOQPEH_SPRDH_Pos;
727  }
728  }
729 
730  /* Config procedure */
731  if (Mode == GPIO_QualMode_3sample)
732  {
733  *GPIOQMx &= ~GPIO_Pin;
734  }
735  else if (Mode == GPIO_QualMode_6sample)
736  {
737  *GPIOQMx |= GPIO_Pin;
738  }
739 
740  *GPIOQPx = SamplePerod << gpioqp_port_pos;
741 }
742 
753 void GPIO_QualCmd(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, FunctionalState State)
754 {
755  uint32_t port_offset;
756  __IO uint32_t* GPIOQEx;
757 
758  /* Check the parameters */
759  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
760  assert_param(IS_GPIO_PIN(GPIO_Pin));
761  assert_param(IS_FUNCTIONAL_STATE(State));
762 
763  /* Preparation routine */
764  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOC) ||
765  (GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOG))
766  {
767  port_offset = 0;
768  }
769  else /* ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOD) ||
770  (GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOH)) */
771  {
772  port_offset = 16;
773  }
774 
775  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
776  {
777  GPIOQEx = &(NT_COMMON_REG->GPIOQE0);
778  }
779  else if ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOC))
780  {
781  GPIOQEx = &(NT_COMMON_REG->GPIOQE1);
782  }
783  else if ((GPIOx == NT_GPIOD) || (GPIOx == NT_GPIOE))
784  {
785  GPIOQEx = &(NT_COMMON_REG->GPIOQE2);
786  }
787  else /* ((GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOG)) */
788  {
789  GPIOQEx = &(NT_COMMON_REG->GPIOQE3);
790  }
791 
792  /* Cmd procedure */
793  if (State == DISABLE)
794  {
795  *GPIOQEx &= ~(GPIO_Pin<<port_offset);
796  }
797  else if (State == ENABLE)
798  {
799  *GPIOQEx |= GPIO_Pin<<port_offset;
800  }
801 }
802 
803 
814 void GPIO_SyncCmd(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, FunctionalState State)
815 {
816  uint32_t port_offset;
817  __IO uint32_t* GPIOSEx;
818 
819  /* Check the parameters */
820  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
821  assert_param(IS_GPIO_PIN(GPIO_Pin));
822  assert_param(IS_FUNCTIONAL_STATE(State));
823 
824  /* Preparation routine */
825  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOC) ||
826  (GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOG))
827  {
828  port_offset = 0;
829  }
830  else /* ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOD) ||
831  (GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOH)) */
832  {
833  port_offset = 16;
834  }
835 
836  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
837  {
838  GPIOSEx = &(NT_COMMON_REG->GPIOSE0);
839  }
840  else if ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOC))
841  {
842  GPIOSEx = &(NT_COMMON_REG->GPIOSE1);
843  }
844  else if ((GPIOx == NT_GPIOD) || (GPIOx == NT_GPIOE))
845  {
846  GPIOSEx = &(NT_COMMON_REG->GPIOSE2);
847  }
848  else /* ((GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOG)) */
849  {
850  GPIOSEx = &(NT_COMMON_REG->GPIOSE3);
851  }
852 
853  /* Cmd procedure */
854  if (State == DISABLE)
855  {
856  *GPIOSEx &= ~(GPIO_Pin<<port_offset);
857  }
858  else if (State == ENABLE)
859  {
860  *GPIOSEx |= GPIO_Pin<<port_offset;
861  }
862 }
863 
876 void GPIO_ITConfig(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, GPIO_IntType_TypeDef IntType, GPIO_IntPol_TypeDef IntPol)
877 {
878  /* Check the parameters */
879  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
880  assert_param(IS_GPIO_PIN(GPIO_Pin));
881  assert_param(IS_GPIO_INT_TYPE(IntType));
882  assert_param(IS_GPIO_INT_POL(IntPol));
883 
884  if (IntType == GPIO_IntType_Level)
885  {
886  GPIOx->INTTYPECLR = GPIO_Pin;
887  }
888  else if (IntType == GPIO_IntType_Edge)
889  {
890  GPIOx->INTTYPESET = GPIO_Pin;
891  }
892 
893  if (IntPol == GPIO_IntPol_Neg)
894  {
895  GPIOx->INTPOLCLR = GPIO_Pin;
896  }
897  else if (IntPol == GPIO_IntPol_Pos)
898  {
899  GPIOx->INTPOLSET = GPIO_Pin;
900  }
901 }
902 
913 void GPIO_ITCmd(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, FunctionalState State)
914 {
915  /* Check the parameters */
916  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
917  assert_param(IS_GPIO_PIN(GPIO_Pin));
918  assert_param(IS_FUNCTIONAL_STATE(State));
919 
920  if (State == DISABLE)
921  {
922  GPIOx->INTENCLR = GPIO_Pin;
923  }
924  else if (State == ENABLE)
925  {
926  GPIOx->INTENSET = GPIO_Pin;
927  }
928 }
929 
938 void GPIO_ITStatusClear(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
939 {
940  /* Check the parameters */
941  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
942  assert_param(IS_GPIO_PIN(GPIO_Pin));
943 
944  GPIOx->INTSTATUS = GPIO_Pin;
945 }
946 
963 /******************* (C) COPYRIGHT 2015 NIIET *****END OF FILE****/
#define IS_GPIO_OUT_MODE(OUT_MODE)
Макрос проверки аргументов типа GPIO_OutMode_TypeDef.
void GPIO_StructInit(GPIO_Init_TypeDef *GPIO_InitStruct)
Заполнение каждого члена структуры GPIO_InitStruct значениями по умолчанию.
GPIO_Load_TypeDef GPIO_Load
void GPIO_ITConfig(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, GPIO_IntType_TypeDef IntType, GPIO_IntPol_TypeDef IntPol)
Настройка прерываний пинов.
#define GPIO_DATAOUT_Reset_Value
Definition: niietcm4_gpio.c:72
void GPIO_WriteMask(NT_GPIO_TypeDef *GPIOx, uint32_t MaskVal, uint32_t PortVal)
Изменение состояния выбранного порта GPIOx с использованием маски.
FunctionalState
Описывает логическое состояние периферии. Используется для операций включения/выключения периферийных...
Definition: niietcm4.h:157
#define IS_GPIO_ALT_FUNC(ALT_FUNC)
Макрос проверки аргументов типа GPIO_AltFunc_TypeDef.
#define GPIO_GPIODEN2_Reset_Value
Definition: niietcm4_gpio.c:75
#define IS_GPIO_BIT_ACTION(ACTION)
Макрос проверки аргументов типа BitAction.
Definition: niietcm4_gpio.h:72
#define IS_GPIO_ALL_PERIPH(PERIPH)
Макрос проверки аргументов типа NT_GPIO_TypeDef.
Definition: niietcm4.h:201
GPIO_AltFunc_TypeDef GPIO_AltFunc
#define IS_GET_GPIO_PIN(PIN)
Макрос проверки номера пина при работе с пинами по отдельности.
#define GPIO_GPIOSEx_Reset_Value
Definition: niietcm4_gpio.c:80
void GPIO_SyncCmd(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, FunctionalState State)
Включение пересинхронизации входов через 2 триггера-защелки.
#define IS_GPIO_OUT(OUT)
Макрос проверки аргументов типа GPIO_Out_TypeDef.
#define GPIO_GPIODEN0_Reset_Value
Definition: niietcm4_gpio.c:73
#define GPIO_Regs_A_C_E_G_Mask
Definition: niietcm4_gpio.c:94
#define IS_GPIO_PULLUP(PULLUP)
Макрос проверки аргументов типа GPIO_PullUp_TypeDef.
GPIO_OutMode_TypeDef GPIO_OutMode
void GPIO_QualCmd(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, FunctionalState State)
Включение входных фильтров.
GPIO_IntPol_TypeDef
Выбор полярности события для возникновения прерывания.
#define GPIO_GPIOQMx_Reset_Value
Definition: niietcm4_gpio.c:82
uint32_t GPIO_ReadBit(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
Чтение состояния выбранного пина.
#define GPIO_GPIOQEx_Reset_Value
Definition: niietcm4_gpio.c:81
void GPIO_ITStatusClear(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
Очистка флагов прерываний выбранных пинов.
#define GPIO_GPIOPCTLx_Reset_Value
Definition: niietcm4_gpio.c:83
GPIO_AltFunc_TypeDef
Выбор номера альтернативной функции пина.
uint32_t GPIO_ReadMask(NT_GPIO_TypeDef *GPIOx, uint32_t MaskVal)
Чтение состояния выбранного порта GPIOx c использованием маски.
#define GPIO_GPIOPUCTLx_Reset_Value
Definition: niietcm4_gpio.c:79
#define IS_GPIO_INT_POL(INT_POL)
Макрос проверки аргументов типа GPIO_IntPol_TypeDef.
void GPIO_Init(NT_GPIO_TypeDef *GPIOx, GPIO_Init_TypeDef *GPIO_InitStruct)
Инициализирует модуль GPIOx согласно параметрам структуры GPIO_InitStruct.
#define IS_GPIO_MODE(MODE)
Макрос проверки аргументов типа GPIO_Mode_TypeDef.
GPIO_Out_TypeDef GPIO_Out
GPIO_IntType_TypeDef
Выбор события для возникновения прерывания.
void GPIO_QualConfig(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, GPIO_QualMode_TypeDef Mode, uint32_t SamplePerod)
Настройка фильтра выбранных пинов.
Структура инициализации GPIO.
void GPIO_ClearBits(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
Сброс выбранных пинов.
#define GPIO_Pin_All
void GPIO_WriteBit(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, BitAction BitVal)
Изменение состояния выбранного пина.
#define IS_GPIO_DIR(DIR)
Макрос проверки аргументов типа GPIO_Dir_TypeDef.
Definition: niietcm4_gpio.h:88
#define IS_GPIO_QUAL_PERIOD(PERIOD)
Макрос проверки соответсвия величины периода фильтрации разрешенному диапазону.
Definition: niietcm4_gpio.h:56
GPIO_Mode_TypeDef GPIO_Mode
uint32_t GPIO_Read(NT_GPIO_TypeDef *GPIOx)
Чтение состояния выбранного порта GPIOx.
#define IS_GPIO_QUAL_MODE(QUAL_MODE)
Макрос проверки аргументов типа GPIO_QualMode_TypeDef.
#define IS_FUNCTIONAL_STATE(STATE)
Макрос проверки аргументов типа FunctionalState.
Definition: niietcm4.h:167
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:95
#define GPIO_GPIODEN3_Reset_Value
Definition: niietcm4_gpio.c:76
GPIO_PullUp_TypeDef GPIO_PullUp
GPIO_Dir_TypeDef GPIO_Dir
void GPIO_SetBits(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
Установка выбранных пинов.
GPIO_QualMode_TypeDef
Выбор режима работы входного фильтра.
void GPIO_Write(NT_GPIO_TypeDef *GPIOx, uint32_t PortVal)
Изменение состояния выбранного порта GPIOx.
Файл содержит все прототипы функций для GPIO.
#define GPIO_GPIODEN1_Reset_Value
Definition: niietcm4_gpio.c:74
void GPIO_ITCmd(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, FunctionalState State)
Включение прерываний выбранных пинов.
void GPIO_ToggleBits(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
Переключение выбранных пинов в противоположное состояние.
#define IS_GPIO_LOAD(LOAD)
Макрос проверки аргументов типа GPIO_Load_TypeDef.
#define GPIO_GPIOQPx_Reset_Value
Definition: niietcm4_gpio.c:84
#define IS_GPIO_PIN(PIN)
Макрос проверки номеров пинов на попадание в допустимый диапазон.
#define IS_GPIO_INT_TYPE(INT_TYPE)
Макрос проверки аргументов типа GPIO_IntType_TypeDef.
#define GPIO_GPIOODSCTLx_Reset_Value
Definition: niietcm4_gpio.c:78