board.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #pragma once
  2. #ifndef _BOARD_H
  3. #define _BOARD_H
  4. /* Includes */
  5. #include "main.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 TUBE_BCDE_OFF TIM3->CCER &= ~(TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E)
  25. #define TUBE_ALL_OFF TUBE_A_OFF; TUBE_BCDE_OFF
  26. #define IN15_P GPIOA->BSRR = 0x1
  27. #define IN15_Plus GPIOA->BSRR = 0x2
  28. #define IN15_Minus GPIOA->BSRR = 0x4
  29. #define IN15_Percent GPIOA->BSRR = 0x8
  30. #define IN15_OFF GPIOA->BRR = 0xF
  31. #define COLOR_R(x) TIM1->CCR2 = x
  32. #define COLOR_G(x) TIM1->CCR3 = x
  33. #define COLOR_B(x) TIM1->CCR4 = x
  34. /* Constants */
  35. /* PWM Timers for 250 Hz */
  36. #define TIM1_PSC (375 - 1)
  37. #define TIM1_ARR (256 - 1)
  38. #define TIM3_PSC (375 - 1)
  39. #define TIM3_ARR (256 - 1)
  40. #define PWM_TUBE_INIT_VAL 127
  41. #define PWM_LED_INIT_VAL 127
  42. #define PWM_LED_MAX_VAL TIM3_ARR
  43. #define TIM14_PSC (24000 - 1)
  44. #define TIM14_ARR (1000 - 1)
  45. #define TIM14_PULSE_VAL 750
  46. #define TIM16_PSC (24 - 1)
  47. #define TIM16_ARR (1000 - 1)
  48. #define TIM17_PSC (24 - 1)
  49. #define TIM17_ARR (1000 - 1)
  50. /* Defines */
  51. #define BTN1_GPIO_Port GPIOB
  52. #define BTN1_Pin GPIO_PIN_2
  53. #define BTN2_GPIO_Port GPIOA
  54. #define BTN2_Pin GPIO_PIN_12
  55. #define BTN3_GPIO_Port GPIOB
  56. #define BTN3_Pin GPIO_PIN_4
  57. #define BTN4_GPIO_Port GPIOA
  58. #define BTN4_Pin GPIO_PIN_5
  59. #define IRQ_EXTI_IRQn EXTI4_15_IRQn
  60. #define IRQ_GPIO_Port GPIOC
  61. #define IRQ_Pin GPIO_PIN_14
  62. #define Latch_GPIO_Port GPIOC
  63. #define Latch_Pin GPIO_PIN_6
  64. #define LC0_GPIO_Port GPIOA
  65. #define LC0_Pin GPIO_PIN_0
  66. #define LC1_GPIO_Port GPIOA
  67. #define LC1_Pin GPIO_PIN_1
  68. #define LC2_GPIO_Port GPIOA
  69. #define LC2_Pin GPIO_PIN_2
  70. #define LC3_GPIO_Port GPIOA
  71. #define LC3_Pin GPIO_PIN_3
  72. #define PWM_1_GPIO_Port GPIOA
  73. #define PWM_1_Pin GPIO_PIN_8
  74. #define PWM_2_GPIO_Port GPIOB
  75. #define PWM_2_Pin GPIO_PIN_1
  76. #define PWM_3_GPIO_Port GPIOB
  77. #define PWM_3_Pin GPIO_PIN_0
  78. #define PWM_4_GPIO_Port GPIOA
  79. #define PWM_4_Pin GPIO_PIN_7
  80. #define PWM_5_GPIO_Port GPIOA
  81. #define PWM_5_Pin GPIO_PIN_6
  82. #define PWM_B_GPIO_Port GPIOA
  83. #define PWM_B_Pin GPIO_PIN_11
  84. #define PWM_G_GPIO_Port GPIOA
  85. #define PWM_G_Pin GPIO_PIN_10
  86. #define PWM_R_GPIO_Port GPIOA
  87. #define PWM_R_Pin GPIO_PIN_9
  88. #define SHDN_GPIO_Port GPIOA
  89. #define SHDN_Pin GPIO_PIN_4
  90. #define SWCLK_GPIO_Port GPIOA
  91. #define SWCLK_Pin GPIO_PIN_14
  92. #define SWDIO_GPIO_Port GPIOA
  93. #define SWDIO_Pin GPIO_PIN_13
  94. #define UART_EN_GPIO_Port GPIOC
  95. #define UART_EN_Pin GPIO_PIN_15
  96. #define UART_ST_GPIO_Port GPIOA
  97. #define UART_ST_Pin GPIO_PIN_15
  98. /* BTNs */
  99. #define BTN_NUM 4
  100. #define BTN1_PIN GPIO_IDR_ID2
  101. #define BTN2_PIN GPIO_IDR_ID12
  102. #define BTN3_PIN GPIO_IDR_ID4
  103. #define BTN4_PIN GPIO_IDR_ID5
  104. #define BTN1_STATE (BTN1_GPIO_Port->IDR & BTN1_PIN)
  105. #define BTN2_STATE (BTN2_GPIO_Port->IDR & BTN2_PIN)
  106. #define BTN3_STATE (BTN3_GPIO_Port->IDR & BTN3_PIN)
  107. #define BTN4_STATE (BTN4_GPIO_Port->IDR & BTN4_PIN)
  108. #define BTNS1_STATE (GPIOB->IDR & (BTN1_PIN | BTN3_PIN))
  109. #define BTNS2_STATE (GPIOA->IDR & (BTN2_PIN | BTN4_PIN))
  110. #define BTNS_STATE (BTNS1_STATE | BTNS2_STATE)
  111. /* Variables */
  112. /* Type Defs */
  113. typedef enum {
  114. Tube_A = 3,
  115. Tube_B = 2,
  116. Tube_D = 1,
  117. Tube_E = 0
  118. } tube_pos_t;
  119. typedef struct {
  120. uint8_t r;
  121. uint8_t g;
  122. uint8_t b;
  123. } RGB_t;
  124. typedef struct {
  125. uint8_t h;
  126. uint8_t s;
  127. uint8_t v;
  128. } HSV_t;
  129. typedef union {
  130. uint32_t u32; /* element specifier for accessing whole u32 */
  131. uint8_t ar[4]; /* element specifier for accessing as array */
  132. struct {
  133. uint8_t tE; /* element specifier for accessing Tube_E(4) */
  134. uint8_t tD; /* element specifier for accessing Tube_D(3) */
  135. uint8_t tB; /* element specifier for accessing Tube_B(2) */
  136. uint8_t tA; /* element specifier for accessing Tube_A(1) */
  137. } s32; /* element spec. for acc. struct with tubes */
  138. } tube4_t;
  139. /* Exported funcions */
  140. void SystemClock_Config(void);
  141. void Board_Init(void);
  142. void Blink_Start(void);
  143. void Blink_Stop(void);
  144. void showDigits(tube4_t dig);
  145. void HSV2LED(const uint8_t hue, const uint8_t sat, const uint8_t val);
  146. #endif /* _BPARD_H */