bsp_wrapper.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #ifndef __BSP_WRAPPER_H__
  2. #define __BSP_WRAPPER_H__
  3. #define BIT(x) ((uint32_t)((uint32_t)0x01U<<(x)))
  4. #define BITS(start, end) ((0xFFFFFFFFUL << (start)) & (0xFFFFFFFFUL >> (31U - (uint32_t)(end))))
  5. #define GPIO_MODE_AF_PP GPIO_Mode_AF_PP
  6. #define GPIO_MODE_AIN GPIO_Mode_AIN
  7. #define GPIO_MODE_IN_FLOATING GPIO_Mode_IN_FLOATING
  8. #define GPIO_MODE_OUT_PP GPIO_Mode_Out_PP
  9. #define GPIO_OSPEED_50MHZ GPIO_Speed_50MHz
  10. #define GPIO_MODE_IPU GPIO_Mode_IPU
  11. #define RCU_GPIOA RCC_APB2_PERIPH_GPIOA
  12. #define RCU_GPIOB RCC_APB2_PERIPH_GPIOB
  13. #define RCU_GPIOC RCC_APB2_PERIPH_GPIOC
  14. #define RCU_GPIOD RCC_APB2_PERIPH_GPIOD
  15. #define RCU_AF RCC_APB2_PERIPH_AFIO
  16. #define RCU_TIMER5 RCC_APB1_PERIPH_TIM5
  17. #define RCU_TIMER1 RCC_APB2_PERIPH_TIM1
  18. #define RCU_TIMER7 RCC_APB1_PERIPH_TIM7
  19. #define RCU_TIMER3 RCC_APB1_PERIPH_TIM3
  20. #define RCU_TIMER4 RCC_APB1_PERIPH_TIM4
  21. #define RCU_TIMER8 RCC_APB2_PERIPH_TIM8
  22. #define RCU_DMA1 RCC_AHB_PERIPH_DMA1
  23. #define RCU_ADC1 RCC_AHB_PERIPH_ADC1
  24. #define RCU_ADC2 RCC_AHB_PERIPH_ADC2
  25. #define RCU_CAN0 RCC_APB1_PERIPH_CAN1
  26. #define SET Bit_SET
  27. #define RESET Bit_RESET
  28. #define REG32(addr) (*(volatile uint32_t *)(uint32_t)(addr))
  29. #define REG16(addr) (*(volatile uint16_t *)(uint32_t)(addr))
  30. #define REG8(addr) (*(volatile uint8_t *)(uint32_t)(addr))
  31. #define TIMER_CNT(TIMx) (TIMx->CNT)
  32. #define TIMER_CTL0(TIMx) (TIMx->CTRL1)
  33. #define TIMER_INTF(TIMx) (TIMx->STS)
  34. #define TIMER_CTL0_DIR BIT(4) /*!< timer counter direction */
  35. #define TIMER_CH0CV(TIMx) (TIMx->CCDAT1)
  36. #define TIMER_CH1CV(TIMx) (TIMx->CCDAT2)
  37. #define TIMER_CH2CV(TIMx) (TIMx->CCDAT3)
  38. #define TIMER_CH3CV(TIMx) (TIMx->CCDAT4)
  39. #define TIMER_CCHP(TIMx) (TIMx->BKDT)
  40. #define TIMER_CHCTL1(TIMx) (TIMx->CCMOD2)
  41. #define TIMER_CHCTL2(TIMx) (TIMx->CCEN)
  42. #define gpio_init(gpio_periph, mode, speed, pin) \
  43. do {\
  44. GPIO_InitType GPIO_InitStructure; \
  45. GPIO_InitStructure.Pin = pin; \
  46. GPIO_InitStructure.GPIO_Speed = speed; \
  47. GPIO_InitStructure.GPIO_Mode = mode; \
  48. GPIO_InitPeripheral(gpio_periph, &GPIO_InitStructure); \
  49. }while(0);
  50. #define gpio_input_bit_get(gpio_periph, pin) GPIO_ReadInputDataBit(gpio_periph, pin)
  51. #define gpio_bit_write(gpio_periph, pin, value) GPIO_WriteBit(gpio_periph, pin, value)
  52. #define gpio_bit_reset(gpio_periph, pin) GPIO_ResetBits(gpio_periph, pin)
  53. #define gpio_pin_remap_config(pin, mode) GPIO_ConfigPinRemap(pin, mode)
  54. #define rcu_ahb_periph_clock_enable(clk) RCC_EnableAHBPeriphClk(clk, ENABLE)
  55. #define rcu_ahb_periph_clock_disable(clk) RCC_EnableAHBPeriphClk(clk, DISABLE)
  56. #define rcu_apb1_periph_clock_enable(clk) RCC_EnableAPB1PeriphClk(clk, ENABLE)
  57. #define rcu_apb1_periph_clock_disable(clk) RCC_EnableAPB1PeriphClk(clk, DISABLE)
  58. #define rcu_apb2_periph_clock_enable(clk) RCC_EnableAPB2PeriphClk(clk, ENABLE)
  59. #define rcu_apb2_periph_clock_disable(clk) RCC_EnableAPB2PeriphClk(clk, DISABLE)
  60. #define EXTI_INTERRUPT EXTI_Mode_Interrupt
  61. #define EXTI_TRIG_RISING EXTI_Trigger_Rising
  62. #define EXTI_TRIG_BOTH EXTI_Trigger_Rising_Falling
  63. #define nvic_irq_enable(irq, pri, subpri) \
  64. do { \
  65. NVIC_InitType NVIC_InitStructure; \
  66. NVIC_InitStructure.NVIC_IRQChannel = irq; \
  67. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = pri; \
  68. NVIC_InitStructure.NVIC_IRQChannelSubPriority = subpri; \
  69. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; \
  70. NVIC_Init(&NVIC_InitStructure); \
  71. }while(0);
  72. #define nvic_irq_disable(irq) \
  73. do { \
  74. NVIC_InitType NVIC_InitStructure; \
  75. NVIC_InitStructure.NVIC_IRQChannel = irq; \
  76. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; \
  77. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; \
  78. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; \
  79. NVIC_Init(&NVIC_InitStructure); \
  80. }while(0);
  81. #define gpio_exti_source_select(group, pin) GPIO_ConfigEXTILine(group, pin)
  82. #define exti_init(line, mode, edge) \
  83. do { \
  84. EXTI_InitType EXTI_InitStructure; \
  85. EXTI_InitStructure.EXTI_Line = line; \
  86. EXTI_InitStructure.EXTI_Mode = mode; \
  87. EXTI_InitStructure.EXTI_Trigger = edge; \
  88. EXTI_InitStructure.EXTI_LineCmd = ENABLE; \
  89. EXTI_InitPeripheral(&EXTI_InitStructure); \
  90. }while(0);
  91. #define exti_interrupt_flag_clear(flg) EXTI_ClrITPendBit(flg)
  92. #define exti_interrupt_flag_get(flg) EXTI_GetITStatus(flg)
  93. #define exti_interrupt_enable(line) \
  94. do { \
  95. EXTI_InitType EXTI_InitStructure; \
  96. EXTI_InitStructure.EXTI_Line = line; \
  97. EXTI_InitStructure.EXTI_LineCmd = ENABLE; \
  98. EXTI_InitPeripheral(&EXTI_InitStructure); \
  99. }while(0);
  100. #define exti_interrupt_disable(line) \
  101. do { \
  102. EXTI_InitType EXTI_InitStructure; \
  103. EXTI_InitStructure.EXTI_Line = line; \
  104. EXTI_InitStructure.EXTI_LineCmd = DISABLE; \
  105. EXTI_InitPeripheral(&EXTI_InitStructure); \
  106. }while(0);
  107. #endif /* __BSP_WRAPPER_H__
  108. */