board.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #pragma once
  2. #ifndef _BOARD_H
  3. #define _BOARD_H
  4. /* Includes */
  5. #include "stm32g0xx.h"
  6. #include "gpio.h"
  7. /* Exported macros */
  8. #define LATCH_DOWN GPIOC->BRR = 0x40
  9. #define LATCH_UP GPIOC->BSRR = 0x40
  10. #define TUBE_PWR_ON GPIOA->BRR = 0x10
  11. #define TUBE_PWR_OFF GPIOA->BSRR = 0x10
  12. #define TUBE_A_ON TIM1->CCER |= (TIM_CCER_CC1E)
  13. #define TUBE_B_ON TIM3->CCER |= (TIM_CCER_CC4E)
  14. #define TUBE_C_ON TIM3->CCER |= (TIM_CCER_CC3E)
  15. #define TUBE_D_ON TIM3->CCER |= (TIM_CCER_CC2E)
  16. #define TUBE_E_ON TIM3->CCER |= (TIM_CCER_CC1E)
  17. #define TUBE_BCDE_ON TIM3->CCER |= (TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E)
  18. #define TUBE_ALL_ON TUBE_A_ON; TUBE_BCDE_ON
  19. #define TUBE_A_OFF TIM1->CCER &= ~(TIM_CCER_CC1E)
  20. #define TUBE_B_OFF TIM3->CCER &= ~(TIM_CCER_CC4E)
  21. #define TUBE_C_OFF TIM3->CCER &= ~(TIM_CCER_CC3E)
  22. #define TUBE_D_OFF TIM3->CCER &= ~(TIM_CCER_CC2E)
  23. #define TUBE_E_OFF TIM3->CCER &= ~(TIM_CCER_CC1E)
  24. #define IN15_P GPIOA->BSRR = 0x1
  25. #define IN15_Plus GPIOA->BSRR = 0x2
  26. #define IN15_Minus GPIOA->BSRR = 0x4
  27. #define IN15_Percent GPIOA->BSRR = 0x8
  28. #define IN15_OFF GPIOA->BRR = 0xF
  29. #define COLOR_R(x) TIM1->CCR2 = x
  30. #define COLOR_G(x) TIM1->CCR3 = x
  31. #define COLOR_B(x) TIM1->CCR4 = x
  32. /* Constants */
  33. #define PWM_LED_INIT_VAL 500
  34. #define PWM_TUBE_INIT_VAL 500
  35. #define TIM1_PSC (120 - 1)
  36. #define TIM1_ARR (1000 - 1)
  37. #define TIM3_PSC (120 - 1)
  38. #define TIM3_ARR (1000 - 1)
  39. #define TIM14_PSC (24000 - 1)
  40. #define TIM14_ARR (1000 - 1)
  41. #define TIM14_PULSE_VAL 750
  42. #define TIM16_PSC (24 - 1)
  43. #define TIM16_ARR (1000 - 1)
  44. #define TIM17_PSC (24 - 1)
  45. #define TIM17_ARR (1000 - 1)
  46. /* Defines */
  47. #define BTN1_GPIO_Port GPIOB
  48. #define BTN1_Pin GPIO_PIN_2
  49. #define BTN2_GPIO_Port GPIOA
  50. #define BTN2_Pin GPIO_PIN_12
  51. #define BTN3_GPIO_Port GPIOB
  52. #define BTN3_Pin GPIO_PIN_4
  53. #define BTN4_GPIO_Port GPIOA
  54. #define BTN4_Pin GPIO_PIN_5
  55. #define IRQ_EXTI_IRQn EXTI4_15_IRQn
  56. #define IRQ_GPIO_Port GPIOC
  57. #define IRQ_Pin GPIO_PIN_14
  58. #define Latch_GPIO_Port GPIOC
  59. #define Latch_Pin GPIO_PIN_6
  60. #define LC0_GPIO_Port GPIOA
  61. #define LC0_Pin GPIO_PIN_0
  62. #define LC1_GPIO_Port GPIOA
  63. #define LC1_Pin GPIO_PIN_1
  64. #define LC2_GPIO_Port GPIOA
  65. #define LC2_Pin GPIO_PIN_2
  66. #define LC3_GPIO_Port GPIOA
  67. #define LC3_Pin GPIO_PIN_3
  68. #define PWM_1_GPIO_Port GPIOA
  69. #define PWM_1_Pin GPIO_PIN_8
  70. #define PWM_2_GPIO_Port GPIOB
  71. #define PWM_2_Pin GPIO_PIN_1
  72. #define PWM_3_GPIO_Port GPIOB
  73. #define PWM_3_Pin GPIO_PIN_0
  74. #define PWM_4_GPIO_Port GPIOA
  75. #define PWM_4_Pin GPIO_PIN_7
  76. #define PWM_5_GPIO_Port GPIOA
  77. #define PWM_5_Pin GPIO_PIN_6
  78. #define PWM_B_GPIO_Port GPIOA
  79. #define PWM_B_Pin GPIO_PIN_10
  80. #define PWM_G_GPIO_Port GPIOA
  81. #define PWM_G_Pin GPIO_PIN_11
  82. #define PWM_R_GPIO_Port GPIOA
  83. #define PWM_R_Pin GPIO_PIN_9
  84. #define SHDN_GPIO_Port GPIOA
  85. #define SHDN_Pin GPIO_PIN_4
  86. #define SWCLK_GPIO_Port GPIOA
  87. #define SWCLK_Pin GPIO_PIN_14
  88. #define SWDIO_GPIO_Port GPIOA
  89. #define SWDIO_Pin GPIO_PIN_13
  90. #define UART_EN_GPIO_Port GPIOC
  91. #define UART_EN_Pin GPIO_PIN_15
  92. #define UART_ST_GPIO_Port GPIOA
  93. #define UART_ST_Pin GPIO_PIN_15
  94. /* Variables */
  95. uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
  96. /* Expoted funcions */
  97. void SystemClock_Config(void);
  98. void Board_Init();
  99. void Blink_Start(void);
  100. void Blink_Stop(void);
  101. #endif