main.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.h
  5. * @brief : Header for main.c file.
  6. * This file contains the common defines of the application.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by ST under BSD 3-Clause license,
  14. * the "License"; You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. ******************************************************************************
  19. */
  20. /* USER CODE END Header */
  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef __MAIN_H
  23. #define __MAIN_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /* Includes ------------------------------------------------------------------*/
  28. #include "stm32g0xx.h"
  29. #include "stm32g0xx_ll_dma.h"
  30. #include "stm32g0xx_ll_i2c.h"
  31. #include "stm32g0xx_ll_rcc.h"
  32. #include "stm32g0xx_ll_bus.h"
  33. #include "stm32g0xx_ll_system.h"
  34. #include "stm32g0xx_ll_exti.h"
  35. #include "stm32g0xx_ll_cortex.h"
  36. #include "stm32g0xx_ll_utils.h"
  37. #include "stm32g0xx_ll_pwr.h"
  38. #include "stm32g0xx_ll_spi.h"
  39. #include "stm32g0xx_ll_tim.h"
  40. #include "stm32g0xx_ll_gpio.h"
  41. #include "stm32g0xx_ll_usart.h"
  42. #if defined(USE_FULL_ASSERT)
  43. #include "stm32_assert.h"
  44. #endif /* USE_FULL_ASSERT */
  45. /* Private includes ----------------------------------------------------------*/
  46. /* USER CODE BEGIN Includes */
  47. #include "gpio.h"
  48. #include "i2c.h"
  49. #include "ds3231.h"
  50. #include "bme280.h"
  51. #include "rtos.h"
  52. #include "event-system.h"
  53. #include "list_event.h"
  54. /* USER CODE END Includes */
  55. /* Exported types ------------------------------------------------------------*/
  56. /* USER CODE BEGIN ET */
  57. typedef enum {
  58. DOWN = 0,
  59. UP = 1
  60. } updown_t;
  61. typedef enum {
  62. OFF = 0,
  63. ON = 1
  64. } onoff_t;
  65. volatile struct {
  66. uint32_t RTC_IRQ: 1;
  67. uint32_t SPI_TX_End: 1;
  68. uint32_t I2C_TX_End: 1;
  69. uint32_t I2C_RX_End: 1;
  70. uint32_t I2C_TX_Err: 1;
  71. uint32_t I2C_RX_Err: 1;
  72. uint32_t BME280: 1;
  73. uint32_t Blink_1: 1;
  74. uint32_t Blink_2: 1;
  75. uint32_t Blink_3: 1;
  76. uint32_t Blink_4: 1;
  77. uint32_t Blink_5: 1;
  78. uint32_t _reserv: 20;
  79. } Flag;
  80. typedef union {
  81. uint16_t u16; // element specifier for accessing whole u16
  82. int16_t i16; // element specifier for accessing whole i16
  83. struct {
  84. #ifdef LITTLE_ENDIAN // Byte-order is little endian
  85. uint8_t u8L; // element specifier for accessing low u8
  86. uint8_t u8H; // element specifier for accessing high u8
  87. #else // Byte-order is big endian
  88. uint8_t u8H; // element specifier for accessing low u8
  89. uint8_t u8L; // element specifier for accessing high u8
  90. #endif
  91. } s16; // element spec. for acc. struct with low or high u8
  92. } nt16_t;
  93. typedef union {
  94. uint32_t u32; // element specifier for accessing whole u32
  95. int32_t i32; // element specifier for accessing whole i32
  96. struct {
  97. #ifdef LITTLE_ENDIAN // Byte-order is little endian
  98. uint16_t u16L; // element specifier for accessing low u16
  99. uint16_t u16H; // element specifier for accessing high u16
  100. #else // Byte-order is big endian
  101. uint16_t u16H; // element specifier for accessing low u16
  102. uint16_t u16L; // element specifier for accessing high u16
  103. #endif
  104. } s32; // element spec. for acc. struct with low or high u16
  105. } nt32_t;
  106. /* USER CODE END ET */
  107. /* Exported constants --------------------------------------------------------*/
  108. /* USER CODE BEGIN EC */
  109. /* USER CODE END EC */
  110. /* Exported macro ------------------------------------------------------------*/
  111. /* USER CODE BEGIN EM */
  112. #define LATCH_DOWN GPIOC->BRR = 0x40
  113. #define LATCH_UP GPIOC->BSRR = 0x40
  114. #define TUBE_PWR_ON GPIOA->BRR = 0x10
  115. #define TUBE_PWR_OFF GPIOA->BSRR = 0x10
  116. #define TUBE_A_ON TIM1->CCER |= (TIM_CCER_CC1E)
  117. #define TUBE_B_ON TIM3->CCER |= (TIM_CCER_CC4E)
  118. #define TUBE_C_ON TIM3->CCER |= (TIM_CCER_CC3E)
  119. #define TUBE_D_ON TIM3->CCER |= (TIM_CCER_CC2E)
  120. #define TUBE_E_ON TIM3->CCER |= (TIM_CCER_CC1E)
  121. #define TUBE_A_OFF TIM1->CCER &= ~(TIM_CCER_CC1E)
  122. #define TUBE_B_OFF TIM3->CCER &= ~(TIM_CCER_CC4E)
  123. #define TUBE_C_OFF TIM3->CCER &= ~(TIM_CCER_CC3E)
  124. #define TUBE_D_OFF TIM3->CCER &= ~(TIM_CCER_CC2E)
  125. #define TUBE_E_OFF TIM3->CCER &= ~(TIM_CCER_CC1E)
  126. #define IN15_P GPIOA->BSRR = 0x1
  127. #define IN15_Plus GPIOA->BSRR = 0x2
  128. #define IN15_Minus GPIOA->BSRR = 0x4
  129. #define IN15_Percent GPIOA->BSRR = 0x8
  130. #define IN15_OFF GPIOA->BRR = 0xF
  131. #define COLOR_R(x) TIM1->CCR2 = x
  132. #define COLOR_B(x) TIM1->CCR3 = x
  133. #define COLOR_G(x) TIM1->CCR4 = x
  134. /* USER CODE END EM */
  135. /* Exported functions prototypes ---------------------------------------------*/
  136. void Error_Handler(void);
  137. /* USER CODE BEGIN EFP */
  138. /* USER CODE END EFP */
  139. /* Private defines -----------------------------------------------------------*/
  140. #define BTN1_GPIO_Port GPIOB
  141. #define BTN1_Pin LL_GPIO_PIN_2
  142. #define BTN2_GPIO_Port GPIOA
  143. #define BTN2_Pin LL_GPIO_PIN_12
  144. #define BTN3_GPIO_Port GPIOB
  145. #define BTN3_Pin LL_GPIO_PIN_4
  146. #define BTN4_GPIO_Port GPIOA
  147. #define BTN4_Pin LL_GPIO_PIN_5
  148. #define IRQ_EXTI_IRQn EXTI4_15_IRQn
  149. #define IRQ_GPIO_Port GPIOC
  150. #define IRQ_Pin LL_GPIO_PIN_14
  151. #define Latch_GPIO_Port GPIOC
  152. #define Latch_Pin LL_GPIO_PIN_6
  153. #define LC0_GPIO_Port GPIOA
  154. #define LC0_Pin LL_GPIO_PIN_0
  155. #define LC1_GPIO_Port GPIOA
  156. #define LC1_Pin LL_GPIO_PIN_1
  157. #define LC2_GPIO_Port GPIOA
  158. #define LC2_Pin LL_GPIO_PIN_2
  159. #define LC3_GPIO_Port GPIOA
  160. #define LC3_Pin LL_GPIO_PIN_3
  161. #define PWM_1_GPIO_Port GPIOA
  162. #define PWM_1_Pin LL_GPIO_PIN_8
  163. #define PWM_2_GPIO_Port GPIOB
  164. #define PWM_2_Pin LL_GPIO_PIN_1
  165. #define PWM_3_GPIO_Port GPIOB
  166. #define PWM_3_Pin LL_GPIO_PIN_0
  167. #define PWM_4_GPIO_Port GPIOA
  168. #define PWM_4_Pin LL_GPIO_PIN_7
  169. #define PWM_5_GPIO_Port GPIOA
  170. #define PWM_5_Pin LL_GPIO_PIN_6
  171. #define PWM_B_GPIO_Port GPIOA
  172. #define PWM_B_Pin LL_GPIO_PIN_10
  173. #define PWM_G_GPIO_Port GPIOA
  174. #define PWM_G_Pin LL_GPIO_PIN_11
  175. #define PWM_R_GPIO_Port GPIOA
  176. #define PWM_R_Pin LL_GPIO_PIN_9
  177. #define SHDN_GPIO_Port GPIOA
  178. #define SHDN_Pin LL_GPIO_PIN_4
  179. #define SWCLK_GPIO_Port GPIOA
  180. #define SWCLK_Pin LL_GPIO_PIN_14
  181. #define SWDIO_GPIO_Port GPIOA
  182. #define SWDIO_Pin LL_GPIO_PIN_13
  183. #define UART_EN_GPIO_Port GPIOC
  184. #define UART_EN_Pin LL_GPIO_PIN_15
  185. #define UART_ST_GPIO_Port GPIOA
  186. #define UART_ST_Pin LL_GPIO_PIN_15
  187. /* USER CODE BEGIN Private defines */
  188. /* BTNs */
  189. #define BTN_NUM 4
  190. #define BTN1_PIN GPIO_IDR_ID2
  191. #define BTN2_PIN GPIO_IDR_ID12
  192. #define BTN3_PIN GPIO_IDR_ID4
  193. #define BTN4_PIN GPIO_IDR_ID5
  194. #define BTN1_STATE (BTN1_GPIO_Port->IDR & BTN1_PIN)
  195. #define BTN2_STATE (BTN2_GPIO_Port->IDR & BTN2_PIN)
  196. #define BTN3_STATE (BTN3_GPIO_Port->IDR & BTN3_PIN)
  197. #define BTN4_STATE (BTN4_GPIO_Port->IDR & BTN4_PIN)
  198. #define BTNS1_STATE (GPIOB->IDR & (BTN1_PIN | BTN3_PIN))
  199. #define BTNS2_STATE (GPIOA->IDR & (BTN2_PIN | BTN4_PIN))
  200. #define BTNS_STATE (BTNS1_STATE | BTNS2_STATE)
  201. /* time constant in ms */
  202. #define BTN_SCAN_PERIOD 10
  203. #define BTN_SCAN_PAUSE 200
  204. #define BTN_TIME_PRESSED 30
  205. #define BTN_TIME_HOLDED 500
  206. #define BTN_TIME_REPEATED 50
  207. typedef struct {
  208. uint8_t time;
  209. es_event_t pressed;
  210. es_event_t holded;
  211. uint32_t pin;
  212. //(GPIO_TypeDef *) GPIOA; // ?->IDR
  213. } btn_t;
  214. /* USER CODE END Private defines */
  215. #ifdef __cplusplus
  216. }
  217. #endif
  218. #endif /* __MAIN_H */
  219. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/