NIIETCM4 PD  v0.9.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 = COMMON_REG_GPIOQPAD_SPRDA_Msk;
168  }
169  else /* (GPIOx == NT_GPIOB) */
170  {
171  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLB);
172  gpioqp_port_mask = COMMON_REG_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 = COMMON_REG_GPIOQPAD_SPRDC_Msk;
190  }
191  else /* (GPIOx == NT_GPIOD) */
192  {
193  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLD);
194  gpioqp_port_mask = COMMON_REG_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 = COMMON_REG_GPIOQPEH_SPRDE_Msk;
212  }
213  else /* (GPIOx == NT_GPIOF) */
214  {
215  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLF);
216  gpioqp_port_mask = COMMON_REG_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 = COMMON_REG_GPIOQPEH_SPRDG_Msk;
234  }
235  else /* (GPIOx == NT_GPIOH) */
236  {
237  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLH);
238  gpioqp_port_mask = COMMON_REG_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 
278 void GPIO_AltFuncConfig(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, GPIO_AltFunc_TypeDef GPIO_AltFunc)
279 {
280  uint32_t alt_func_temp;
281  __IO uint32_t* GPIOPCTLx;
282 
283  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
284  assert_param(IS_GPIO_PIN(GPIO_Pin));
285  assert_param(IS_GPIO_ALT_FUNC(GPIO_AltFunc));
286 
287  if (GPIOx == NT_GPIOA)
288  {
289  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLA);
290  }
291  else if (GPIOx == NT_GPIOB)
292  {
293  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLB);
294  }
295  else if (GPIOx == NT_GPIOC)
296  {
297  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLC);
298  }
299  else if (GPIOx == NT_GPIOD)
300  {
301  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLD);
302  }
303  else if (GPIOx == NT_GPIOE)
304  {
305  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLE);
306  }
307  else if (GPIOx == NT_GPIOF)
308  {
309  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLF);
310  }
311  else if (GPIOx == NT_GPIOG)
312  {
313  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLG);
314  }
315  else /* (GPIOx == NT_GPIOH) */
316  {
317  GPIOPCTLx = &(NT_COMMON_REG->GPIOPCTLH);
318  }
319 
320  alt_func_temp = *GPIOPCTLx;
321  for (uint32_t i = 0; i < 16; i++)
322  {
323  if (GPIO_Pin & (1<<i))
324  {
325  alt_func_temp &= ~(3 << i*2);
326  alt_func_temp |= GPIO_AltFunc << i*2;
327  }
328  }
329  *GPIOPCTLx = alt_func_temp;
330 }
331 
340 void GPIO_Init(NT_GPIO_TypeDef* GPIOx, GPIO_Init_TypeDef* GPIO_InitStruct)
341 {
342  uint32_t port_offset;
343  __IO uint32_t* GPIOODSCTLx;
344  __IO uint32_t* GPIOPUCTLx;
345  __IO uint32_t* GPIOODCTLx;
346  __IO uint32_t* GPIODENx;
347 
348  /* Check the parameters */
349  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
350  assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
351  assert_param(IS_GPIO_DIR(GPIO_InitStruct->GPIO_Dir));
352  assert_param(IS_GPIO_OUT(GPIO_InitStruct->GPIO_Out));
353  assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
354  assert_param(IS_GPIO_ALT_FUNC(GPIO_InitStruct->GPIO_AltFunc));
355  assert_param(IS_GPIO_LOAD(GPIO_InitStruct->GPIO_Load));
356  assert_param(IS_GPIO_OUT_MODE(GPIO_InitStruct->GPIO_OutMode));
357  assert_param(IS_GPIO_PULLUP(GPIO_InitStruct->GPIO_PullUp));
358 
359  /* Preparation routine */
360  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOC) ||
361  (GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOG))
362  {
363  port_offset = 0;
364  }
365  else /* ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOD) ||
366  (GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOH)) */
367  {
368  port_offset = 16;
369  }
370 
371  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
372  {
373  GPIOODSCTLx = &(NT_COMMON_REG->GPIOODSCTL0);
374  GPIOPUCTLx = &(NT_COMMON_REG->GPIOODSCTL0);
375  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL0);
376  GPIODENx = &(NT_COMMON_REG->GPIODEN0);
377  }
378  else if ((GPIOx == NT_GPIOC) || (GPIOx == NT_GPIOD))
379  {
380  GPIOODSCTLx = &(NT_COMMON_REG->GPIOODSCTL1);
381  GPIOPUCTLx = &(NT_COMMON_REG->GPIOODSCTL1);
382  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL1);
383  GPIODENx = &(NT_COMMON_REG->GPIODEN1);
384  }
385  else if ((GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOF))
386  {
387  GPIOODSCTLx = &(NT_COMMON_REG->GPIOODSCTL2);
388  GPIOPUCTLx = &(NT_COMMON_REG->GPIOODSCTL2);
389  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL2);
390  GPIODENx = &(NT_COMMON_REG->GPIODEN2);
391  }
392  else /* ((GPIOx == NT_GPIOG) || (GPIOx == NT_GPIOH)) */
393  {
394  GPIOODSCTLx = &(NT_COMMON_REG->GPIOODSCTL3);
395  GPIOPUCTLx = &(NT_COMMON_REG->GPIOODSCTL3);
396  GPIOODCTLx = &(NT_COMMON_REG->GPIOODCTL3);
397  GPIODENx = &(NT_COMMON_REG->GPIODEN3);
398  }
399 
400  /* Init routine */
401  GPIO_AltFuncConfig(GPIOx, GPIO_InitStruct->GPIO_Pin, GPIO_InitStruct->GPIO_AltFunc);
402 
403  if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IO)
404  {
405  GPIOx->ALTFUNCCLR = GPIO_InitStruct->GPIO_Pin;
406  }
407  else if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AltFunc)
408  {
409  GPIOx->ALTFUNCSET = GPIO_InitStruct->GPIO_Pin;
410  }
411 
412  if (GPIO_InitStruct->GPIO_Dir == GPIO_Dir_In)
413  {
414  GPIOx->OUTENCLR = GPIO_InitStruct->GPIO_Pin;
415  }
416  else if (GPIO_InitStruct->GPIO_Dir == GPIO_Dir_Out)
417  {
418  GPIOx->OUTENSET = GPIO_InitStruct->GPIO_Pin;
419  }
420 
421  if (GPIO_InitStruct->GPIO_Load == GPIO_Load_8mA)
422  {
423  *GPIOODSCTLx &= ~(GPIO_InitStruct->GPIO_Pin << port_offset);
424  }
425  else if (GPIO_InitStruct->GPIO_Load == GPIO_Load_16mA)
426  {
427  *GPIOODSCTLx |= (GPIO_InitStruct->GPIO_Pin << port_offset);
428  }
429 
430  if (GPIO_InitStruct->GPIO_PullUp == GPIO_PullUp_Dis)
431  {
432  *GPIOPUCTLx &= ~(GPIO_InitStruct->GPIO_Pin << port_offset);
433  }
434  else if (GPIO_InitStruct->GPIO_PullUp == GPIO_PullUp_En)
435  {
436  *GPIOPUCTLx |= (GPIO_InitStruct->GPIO_Pin << port_offset);
437  }
438 
439  if (GPIO_InitStruct->GPIO_OutMode == GPIO_OutMode_PP)
440  {
441  *GPIOODCTLx &= ~(GPIO_InitStruct->GPIO_Pin << port_offset);
442  }
443  else if (GPIO_InitStruct->GPIO_OutMode == GPIO_OutMode_OD)
444  {
445  *GPIOODCTLx |= (GPIO_InitStruct->GPIO_Pin << port_offset);
446  }
447 
448  if (GPIO_InitStruct->GPIO_Out == GPIO_Out_Dis)
449  {
450  *GPIODENx &= ~(GPIO_InitStruct->GPIO_Pin << port_offset);
451  }
452  else if (GPIO_InitStruct->GPIO_Out == GPIO_Out_En)
453  {
454  *GPIODENx |= (GPIO_InitStruct->GPIO_Pin << port_offset);
455  }
456 }
457 
465 void GPIO_StructInit(GPIO_Init_TypeDef* GPIO_InitStruct)
466 {
467  /* Reset GPIO init structure parameters values */
468  GPIO_InitStruct->GPIO_AltFunc = GPIO_AltFunc_1;
469  GPIO_InitStruct->GPIO_Dir = GPIO_Dir_In;
470  GPIO_InitStruct->GPIO_Load = GPIO_Load_8mA;
471  GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IO;
472  GPIO_InitStruct->GPIO_Out = GPIO_Out_Dis;
473  GPIO_InitStruct->GPIO_OutMode = GPIO_OutMode_PP;
474  GPIO_InitStruct->GPIO_PullUp = GPIO_PullUp_Dis;
475  GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
476 }
477 
486 uint32_t GPIO_ReadBit(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
487 {
488  uint32_t bitval;
489 
490  /* Check the parameters */
491  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
492  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
493 
494  if ((GPIOx->DATA & GPIO_Pin) != (uint32_t)Bit_CLEAR)
495  {
496  bitval = (uint32_t)Bit_SET;
497  }
498  else
499  {
500  bitval = (uint32_t)Bit_CLEAR;
501  }
502 
503  return bitval;
504 }
505 
512 uint32_t GPIO_Read(NT_GPIO_TypeDef* GPIOx)
513 {
514  /* Check the parameters */
515  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
516 
517  return ((uint32_t)GPIOx->DATA);
518 }
519 
527 uint32_t GPIO_ReadMask(NT_GPIO_TypeDef* GPIOx, uint32_t MaskVal)
528 {
529  uint32_t mask_low_byte_offset;
530  uint32_t mask_high_byte_offset;
531  uint32_t low_byte;
532  uint32_t high_byte;
533 
534  /* Check the parameters */
535  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
536 
537  mask_low_byte_offset = (MaskVal & GPIO_MASKLOWBYTE_MASKLB_Msk) >> GPIO_MASKLOWBYTE_MASKLB_Pos;
538  mask_high_byte_offset = (MaskVal & GPIO_MASKHIGHBYTE_MASKHB_Msk) >> GPIO_MASKHIGHBYTE_MASKHB_Pos;
539  low_byte = GPIOx->MASKLOWBYTE[mask_low_byte_offset];
540  high_byte = GPIOx->MASKHIGHBYTE[mask_high_byte_offset];
541 
542  return ((low_byte | high_byte));
543 }
544 
555 void GPIO_WriteBit(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, BitAction BitVal)
556 {
557  /* Check the parameters */
558  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
559  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
560  assert_param(IS_GPIO_BIT_ACTION(BitVal));
561 
562  if (BitVal == Bit_SET)
563  {
564  GPIOx->DATAOUT |= GPIO_Pin;
565  }
566  else if (BitVal == Bit_CLEAR)
567  {
568  GPIOx->DATAOUT &= ~GPIO_Pin;
569  }
570 }
571 
579 void GPIO_Write(NT_GPIO_TypeDef* GPIOx, uint32_t PortVal)
580 {
581  /* Check the parameters */
582  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
583 
584  GPIOx->DATAOUT = PortVal;
585 }
586 
595 void GPIO_WriteMask(NT_GPIO_TypeDef* GPIOx, uint32_t MaskVal, uint32_t PortVal)
596 {
597  uint32_t mask_low_byte_offset;
598  uint32_t mask_high_byte_offset;
599 
600  /* Check the parameters */
601  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
602 
603  mask_low_byte_offset = (MaskVal & GPIO_MASKLOWBYTE_MASKLB_Msk) >> GPIO_MASKLOWBYTE_MASKLB_Pos;
604  mask_high_byte_offset = (MaskVal & GPIO_MASKHIGHBYTE_MASKHB_Msk) >> GPIO_MASKHIGHBYTE_MASKHB_Pos;
605  GPIOx->MASKLOWBYTE[mask_low_byte_offset] = PortVal;
606  GPIOx->MASKHIGHBYTE[mask_high_byte_offset] = PortVal;
607 }
608 
609 
618 void GPIO_SetBits(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
619 {
620  /* Check the parameters */
621  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
622  assert_param(IS_GPIO_PIN(GPIO_Pin));
623 
624  GPIOx->DATAOUT |= GPIO_Pin;
625 }
626 
635 void GPIO_ClearBits(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
636 {
637  /* Check the parameters */
638  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
639  assert_param(IS_GPIO_PIN(GPIO_Pin));
640 
641  GPIOx->DATAOUT &= ~GPIO_Pin;
642 }
643 
652 void GPIO_ToggleBits(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
653 {
654  /* Check the parameters */
655  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
656  assert_param(IS_GPIO_PIN(GPIO_Pin));
657 
658  GPIOx->DATAOUT ^= GPIO_Pin;
659 }
660 
673 void GPIO_QualConfig(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, GPIO_QualMode_TypeDef Mode, uint32_t SamplePerod)
674 {
675  uint32_t gpioqp_port_pos;
676  __IO uint32_t* GPIOQMx;
677  __IO uint32_t* GPIOQPx;
678 
679  /* Check the parameters */
680  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
681  assert_param(IS_GPIO_PIN(GPIO_Pin));
682  assert_param(IS_GPIO_QUAL_MODE(Mode));
683  assert_param(IS_GPIO_QUAL_PERIOD(SamplePerod));
684 
685  /* Preparation routine */
686  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
687  {
688  GPIOQMx = &(NT_COMMON_REG->GPIOQM0);
689  GPIOQPx = &(NT_COMMON_REG->GPIOQPAD);
690  if (GPIOx == NT_GPIOA)
691  {
692  gpioqp_port_pos = COMMON_REG_GPIOQPAD_SPRDA_Pos;
693  }
694  else /* (GPIOx == NT_GPIOB) */
695  {
696  gpioqp_port_pos = COMMON_REG_GPIOQPAD_SPRDB_Pos;
697  }
698  }
699  else if ((GPIOx == NT_GPIOC) || (GPIOx == NT_GPIOD))
700  {
701  GPIOQMx = &(NT_COMMON_REG->GPIOQM1);
702  GPIOQPx = &(NT_COMMON_REG->GPIOQPAD);
703  if (GPIOx == NT_GPIOC)
704  {
705  gpioqp_port_pos = COMMON_REG_GPIOQPAD_SPRDC_Pos;
706  }
707  else /* (GPIOx == NT_GPIOD) */
708  {
709  gpioqp_port_pos = COMMON_REG_GPIOQPAD_SPRDD_Pos;
710  }
711  }
712  else if ((GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOF))
713  {
714  GPIOQMx = &(NT_COMMON_REG->GPIOQM2);
715  GPIOQPx = &(NT_COMMON_REG->GPIOQPEH);
716  if (GPIOx == NT_GPIOE)
717  {
718  gpioqp_port_pos = COMMON_REG_GPIOQPEH_SPRDE_Pos;
719  }
720  else /* (GPIOx == NT_GPIOF) */
721  {
722  gpioqp_port_pos = COMMON_REG_GPIOQPEH_SPRDF_Pos;
723  }
724  }
725  else /* ((GPIOx == NT_GPIOG) || (GPIOx == NT_GPIOH)) */
726  {
727  GPIOQMx = &(NT_COMMON_REG->GPIOQM3);
728  GPIOQPx = &(NT_COMMON_REG->GPIOQPEH);
729  if (GPIOx == NT_GPIOG)
730  {
731  gpioqp_port_pos = COMMON_REG_GPIOQPEH_SPRDG_Pos;
732  }
733  else /* (GPIOx == NT_GPIOH) */
734  {
735  gpioqp_port_pos = COMMON_REG_GPIOQPEH_SPRDH_Pos;
736  }
737  }
738 
739  /* Config procedure */
740  if (Mode == GPIO_QualMode_3sample)
741  {
742  *GPIOQMx &= ~GPIO_Pin;
743  }
744  else if (Mode == GPIO_QualMode_6sample)
745  {
746  *GPIOQMx |= GPIO_Pin;
747  }
748 
749  *GPIOQPx = SamplePerod << gpioqp_port_pos;
750 }
751 
762 void GPIO_QualCmd(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, FunctionalState State)
763 {
764  uint32_t port_offset;
765  __IO uint32_t* GPIOQEx;
766 
767  /* Check the parameters */
768  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
769  assert_param(IS_GPIO_PIN(GPIO_Pin));
770  assert_param(IS_FUNCTIONAL_STATE(State));
771 
772  /* Preparation routine */
773  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOC) ||
774  (GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOG))
775  {
776  port_offset = 0;
777  }
778  else /* ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOD) ||
779  (GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOH)) */
780  {
781  port_offset = 16;
782  }
783 
784  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
785  {
786  GPIOQEx = &(NT_COMMON_REG->GPIOQE0);
787  }
788  else if ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOC))
789  {
790  GPIOQEx = &(NT_COMMON_REG->GPIOQE1);
791  }
792  else if ((GPIOx == NT_GPIOD) || (GPIOx == NT_GPIOE))
793  {
794  GPIOQEx = &(NT_COMMON_REG->GPIOQE2);
795  }
796  else /* ((GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOG)) */
797  {
798  GPIOQEx = &(NT_COMMON_REG->GPIOQE3);
799  }
800 
801  /* Cmd procedure */
802  if (State == DISABLE)
803  {
804  *GPIOQEx &= ~(GPIO_Pin<<port_offset);
805  }
806  else if (State == ENABLE)
807  {
808  *GPIOQEx |= GPIO_Pin<<port_offset;
809  }
810 }
811 
812 
823 void GPIO_SyncCmd(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, FunctionalState State)
824 {
825  uint32_t port_offset;
826  __IO uint32_t* GPIOSEx;
827 
828  /* Check the parameters */
829  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
830  assert_param(IS_GPIO_PIN(GPIO_Pin));
831  assert_param(IS_FUNCTIONAL_STATE(State));
832 
833  /* Preparation routine */
834  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOC) ||
835  (GPIOx == NT_GPIOE) || (GPIOx == NT_GPIOG))
836  {
837  port_offset = 0;
838  }
839  else /* ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOD) ||
840  (GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOH)) */
841  {
842  port_offset = 16;
843  }
844 
845  if ((GPIOx == NT_GPIOA) || (GPIOx == NT_GPIOB))
846  {
847  GPIOSEx = &(NT_COMMON_REG->GPIOSE0);
848  }
849  else if ((GPIOx == NT_GPIOB) || (GPIOx == NT_GPIOC))
850  {
851  GPIOSEx = &(NT_COMMON_REG->GPIOSE1);
852  }
853  else if ((GPIOx == NT_GPIOD) || (GPIOx == NT_GPIOE))
854  {
855  GPIOSEx = &(NT_COMMON_REG->GPIOSE2);
856  }
857  else /* ((GPIOx == NT_GPIOF) || (GPIOx == NT_GPIOG)) */
858  {
859  GPIOSEx = &(NT_COMMON_REG->GPIOSE3);
860  }
861 
862  /* Cmd procedure */
863  if (State == DISABLE)
864  {
865  *GPIOSEx &= ~(GPIO_Pin<<port_offset);
866  }
867  else if (State == ENABLE)
868  {
869  *GPIOSEx |= GPIO_Pin<<port_offset;
870  }
871 }
872 
885 void GPIO_ITConfig(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, GPIO_IntType_TypeDef IntType, GPIO_IntPol_TypeDef IntPol)
886 {
887  /* Check the parameters */
888  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
889  assert_param(IS_GPIO_PIN(GPIO_Pin));
890  assert_param(IS_GPIO_INT_TYPE(IntType));
891  assert_param(IS_GPIO_INT_POL(IntPol));
892 
893  if (IntType == GPIO_IntType_Level)
894  {
895  GPIOx->INTTYPECLR = GPIO_Pin;
896  }
897  else if (IntType == GPIO_IntType_Edge)
898  {
899  GPIOx->INTTYPESET = GPIO_Pin;
900  }
901 
902  if (IntPol == GPIO_IntPol_Neg)
903  {
904  GPIOx->INTPOLCLR = GPIO_Pin;
905  }
906  else if (IntPol == GPIO_IntPol_Pos)
907  {
908  GPIOx->INTPOLSET = GPIO_Pin;
909  }
910 }
911 
922 void GPIO_ITCmd(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, FunctionalState State)
923 {
924  /* Check the parameters */
925  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
926  assert_param(IS_GPIO_PIN(GPIO_Pin));
927  assert_param(IS_FUNCTIONAL_STATE(State));
928 
929  if (State == DISABLE)
930  {
931  GPIOx->INTENCLR = GPIO_Pin;
932  }
933  else if (State == ENABLE)
934  {
935  GPIOx->INTENSET = GPIO_Pin;
936  }
937 }
938 
947 void GPIO_ITStatusClear(NT_GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin)
948 {
949  /* Check the parameters */
950  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
951  assert_param(IS_GPIO_PIN(GPIO_Pin));
952 
953  GPIOx->INTSTATUS = GPIO_Pin;
954 }
955 
972 /******************* (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 значениями по умолчанию.
void GPIO_AltFuncConfig(NT_GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, GPIO_AltFunc_TypeDef GPIO_AltFunc)
Осуществляет выбор альтернативной функции вывода GPIOx.
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