board.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #pragma once
  2. #ifndef _BOARD_H
  3. #define _BOARD_H
  4. /* Includes */
  5. #include "main.h"
  6. #include "gpio.h"
  7. /* Type Defs */
  8. typedef enum {
  9. Tube_All = 0xf,
  10. Tube_C = 4,
  11. Tube_A = 3,
  12. Tube_B = 2,
  13. Tube_D = 1,
  14. Tube_E = 0
  15. } tube_pos_t;
  16. typedef enum {
  17. sym_None = 0,
  18. sym_Pressure = 0x1,
  19. sym_Plus = 0x2,
  20. sym_Minus = 0x4,
  21. sym_Percent = 0x8,
  22. sym_Off = 0xf << 16
  23. } in15_pin_t;
  24. typedef struct {
  25. uint8_t r;
  26. uint8_t g;
  27. uint8_t b;
  28. } RGB_t;
  29. typedef struct {
  30. uint8_t h;
  31. uint8_t s;
  32. uint8_t v;
  33. } HSV_t;
  34. typedef union {
  35. uint32_t u32; /* element specifier for accessing whole u32 */
  36. uint8_t ar[4]; /* element specifier for accessing as array */
  37. struct {
  38. uint8_t tE; /* element specifier for accessing Tube_E(4) */
  39. uint8_t tD; /* element specifier for accessing Tube_D(3) */
  40. uint8_t tB; /* element specifier for accessing Tube_B(2) */
  41. uint8_t tA; /* element specifier for accessing Tube_A(1) */
  42. } s8; /* element spec. for acc. struct with tubes */
  43. } tube4_t;
  44. /* Exported macros */
  45. #define LATCH_DOWN GPIOC->BRR = 0x40
  46. #define LATCH_UP GPIOC->BSRR = 0x40
  47. #define TUBE_PWR_ON GPIOA->BRR = 0x10
  48. #define TUBE_PWR_OFF GPIOA->BSRR = 0x10
  49. #define TUBE_A_ON TIM1->CCER |= (TIM_CCER_CC1E)
  50. #define TUBE_B_ON TIM3->CCER |= (TIM_CCER_CC4E)
  51. #define TUBE_C_ON TIM3->CCER |= (TIM_CCER_CC3E)
  52. #define TUBE_D_ON TIM3->CCER |= (TIM_CCER_CC2E)
  53. #define TUBE_E_ON TIM3->CCER |= (TIM_CCER_CC1E)
  54. #define TUBE_BCDE_ON TIM3->CCER |= (TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E)
  55. #define TUBE_ALL_ON TUBE_A_ON; TUBE_BCDE_ON
  56. #define TUBE_A_OFF TIM1->CCER &= ~(TIM_CCER_CC1E)
  57. #define TUBE_B_OFF TIM3->CCER &= ~(TIM_CCER_CC4E)
  58. #define TUBE_C_OFF TIM3->CCER &= ~(TIM_CCER_CC3E)
  59. #define TUBE_D_OFF TIM3->CCER &= ~(TIM_CCER_CC2E)
  60. #define TUBE_E_OFF TIM3->CCER &= ~(TIM_CCER_CC1E)
  61. #define TUBE_BCDE_OFF TIM3->CCER &= ~(TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E)
  62. #define TUBE_ALL_OFF TUBE_A_OFF; TUBE_BCDE_OFF
  63. #define IN15_P GPIOA->BSRR = 0x1
  64. #define IN15_Plus GPIOA->BSRR = 0x2
  65. #define IN15_Minus GPIOA->BSRR = 0x4
  66. #define IN15_Percent GPIOA->BSRR = 0x8
  67. #define IN15_OFF GPIOA->BRR = 0xF
  68. #define COLOR_R(x) TIM1->CCR2 = x
  69. #define COLOR_G(x) TIM1->CCR3 = x
  70. #define COLOR_B(x) TIM1->CCR4 = x
  71. #define LEDS_OFF COLOR_R(0); COLOR_G(0); COLOR_B(0)
  72. #define TUBE_A_BRIGHT(x) TIM1->CCR1 = x
  73. #define TUBE_B_BRIGHT(x) TIM3->CCR4 = x
  74. #define TUBE_C_BRIGHT(x) TIM3->CCR3 = x
  75. #define TUBE_D_BRIGHT(x) TIM3->CCR2 = x
  76. #define TUBE_E_BRIGHT(x) TIM3->CCR1 = x
  77. #define TUBES_BRIGHT(x) TUBE_A_BRIGHT(x); TUBE_B_BRIGHT(x); TUBE_C_BRIGHT(x); TUBE_D_BRIGHT(x); TUBE_E_BRIGHT(x)
  78. /* Constants */
  79. /* PWM Timers for 250 Hz */
  80. #define TIM1_PSC (375 - 1)
  81. #define TIM1_ARR (256 - 1)
  82. #define TIM3_PSC (375 - 1)
  83. #define TIM3_ARR (256 - 1)
  84. #define PWM_TUBE_INIT_VAL 127
  85. #define PWM_LED_INIT_VAL 127
  86. #define PWM_LED_MAX_VAL TIM3_ARR
  87. #define TIM14_PSC (12000 - 1)
  88. #define TIM14_ARR (1000 - 1)
  89. #define TIM14_PULSE_VAL 500
  90. #define TIM16_PSC (24 - 1)
  91. #define TIM16_ARR (1000 - 1)
  92. #define TIM17_PSC (24 - 1)
  93. #define TIM17_ARR (1000 - 1)
  94. #define TUBE_BLANK 0xa
  95. /* Defines */
  96. #define BTN1_GPIO_Port GPIOB
  97. #define BTN1_Pin GPIO_PIN_2
  98. #define BTN2_GPIO_Port GPIOA
  99. #define BTN2_Pin GPIO_PIN_12
  100. #define BTN3_GPIO_Port GPIOB
  101. #define BTN3_Pin GPIO_PIN_4
  102. #define BTN4_GPIO_Port GPIOA
  103. #define BTN4_Pin GPIO_PIN_5
  104. #define IRQ_EXTI_IRQn EXTI4_15_IRQn
  105. #define IRQ_GPIO_Port GPIOC
  106. #define IRQ_Pin GPIO_PIN_14
  107. #define Latch_GPIO_Port GPIOC
  108. #define Latch_Pin GPIO_PIN_6
  109. #define LC0_GPIO_Port GPIOA
  110. #define LC0_Pin GPIO_PIN_0
  111. #define LC1_GPIO_Port GPIOA
  112. #define LC1_Pin GPIO_PIN_1
  113. #define LC2_GPIO_Port GPIOA
  114. #define LC2_Pin GPIO_PIN_2
  115. #define LC3_GPIO_Port GPIOA
  116. #define LC3_Pin GPIO_PIN_3
  117. #define PWM_1_GPIO_Port GPIOA
  118. #define PWM_1_Pin GPIO_PIN_8
  119. #define PWM_2_GPIO_Port GPIOB
  120. #define PWM_2_Pin GPIO_PIN_1
  121. #define PWM_3_GPIO_Port GPIOB
  122. #define PWM_3_Pin GPIO_PIN_0
  123. #define PWM_4_GPIO_Port GPIOA
  124. #define PWM_4_Pin GPIO_PIN_7
  125. #define PWM_5_GPIO_Port GPIOA
  126. #define PWM_5_Pin GPIO_PIN_6
  127. #define PWM_B_GPIO_Port GPIOA
  128. #define PWM_B_Pin GPIO_PIN_11
  129. #define PWM_G_GPIO_Port GPIOA
  130. #define PWM_G_Pin GPIO_PIN_10
  131. #define PWM_R_GPIO_Port GPIOA
  132. #define PWM_R_Pin GPIO_PIN_9
  133. #define SHDN_GPIO_Port GPIOA
  134. #define SHDN_Pin GPIO_PIN_4
  135. #define SWCLK_GPIO_Port GPIOA
  136. #define SWCLK_Pin GPIO_PIN_14
  137. #define SWDIO_GPIO_Port GPIOA
  138. #define SWDIO_Pin GPIO_PIN_13
  139. #define UART_EN_GPIO_Port GPIOC
  140. #define UART_EN_Pin GPIO_PIN_15
  141. #define UART_ST_GPIO_Port GPIOA
  142. #define UART_ST_Pin GPIO_PIN_15
  143. /* BTNs */
  144. #define BTN_NUM 4
  145. #define BTN1_PIN GPIO_IDR_ID2
  146. #define BTN2_PIN GPIO_IDR_ID12
  147. #define BTN3_PIN GPIO_IDR_ID4
  148. #define BTN4_PIN GPIO_IDR_ID5
  149. #define BTN1_STATE (BTN1_GPIO_Port->IDR & BTN1_PIN)
  150. #define BTN2_STATE (BTN2_GPIO_Port->IDR & BTN2_PIN)
  151. #define BTN3_STATE (BTN3_GPIO_Port->IDR & BTN3_PIN)
  152. #define BTN4_STATE (BTN4_GPIO_Port->IDR & BTN4_PIN)
  153. #define BTNS1_STATE (GPIOB->IDR & (BTN1_PIN | BTN3_PIN))
  154. #define BTNS2_STATE (GPIOA->IDR & (BTN2_PIN | BTN4_PIN))
  155. #define BTNS_STATE (BTNS1_STATE | BTNS2_STATE)
  156. /* Variables */
  157. /* Exported funcions */
  158. void SystemClock_Config(void);
  159. void Board_Init(void);
  160. void Blink_Start(void);
  161. void Blink_Stop(void);
  162. void showDigits(tube4_t dig);
  163. void tube_Refresh(void);
  164. void lShiftDigits(const tube4_t old, const tube4_t dig);
  165. void slideDigits(tube4_t dig);
  166. void tube_PowerOn(tube_pos_t tube);
  167. void tube_PowerOff(tube_pos_t tube);
  168. void tube_BrightLevel(tube_pos_t tube, uint8_t bright);
  169. #endif /* _BPARD_H */