main.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. typedef 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_t;
  80. extern volatile flag_t Flag;
  81. typedef union {
  82. uint16_t u16; // element specifier for accessing whole u16
  83. int16_t i16; // element specifier for accessing whole i16
  84. struct {
  85. #ifdef LITTLE_ENDIAN // Byte-order is little endian
  86. uint8_t u8L; // element specifier for accessing low u8
  87. uint8_t u8H; // element specifier for accessing high u8
  88. #else // Byte-order is big endian
  89. uint8_t u8H; // element specifier for accessing low u8
  90. uint8_t u8L; // element specifier for accessing high u8
  91. #endif
  92. } s16; // element spec. for acc. struct with low or high u8
  93. } nt16_t;
  94. typedef union {
  95. uint32_t u32; // element specifier for accessing whole u32
  96. int32_t i32; // element specifier for accessing whole i32
  97. struct {
  98. #ifdef LITTLE_ENDIAN // Byte-order is little endian
  99. uint16_t u16L; // element specifier for accessing low u16
  100. uint16_t u16H; // element specifier for accessing high u16
  101. #else // Byte-order is big endian
  102. uint16_t u16H; // element specifier for accessing low u16
  103. uint16_t u16L; // element specifier for accessing high u16
  104. #endif
  105. } s32; // element spec. for acc. struct with low or high u16
  106. } nt32_t;
  107. /* USER CODE END ET */
  108. /* Exported constants --------------------------------------------------------*/
  109. /* USER CODE BEGIN EC */
  110. /* USER CODE END EC */
  111. /* Exported macro ------------------------------------------------------------*/
  112. /* USER CODE BEGIN EM */
  113. #define LATCH_DOWN GPIOC->BRR = 0x40
  114. #define LATCH_UP GPIOC->BSRR = 0x40
  115. #define TUBE_PWR_ON GPIOA->BRR = 0x10
  116. #define TUBE_PWR_OFF GPIOA->BSRR = 0x10
  117. #define TUBE_A_ON TIM1->CCER |= (TIM_CCER_CC1E)
  118. #define TUBE_B_ON TIM3->CCER |= (TIM_CCER_CC4E)
  119. #define TUBE_C_ON TIM3->CCER |= (TIM_CCER_CC3E)
  120. #define TUBE_D_ON TIM3->CCER |= (TIM_CCER_CC2E)
  121. #define TUBE_E_ON TIM3->CCER |= (TIM_CCER_CC1E)
  122. #define TUBE_A_OFF TIM1->CCER &= ~(TIM_CCER_CC1E)
  123. #define TUBE_B_OFF TIM3->CCER &= ~(TIM_CCER_CC4E)
  124. #define TUBE_C_OFF TIM3->CCER &= ~(TIM_CCER_CC3E)
  125. #define TUBE_D_OFF TIM3->CCER &= ~(TIM_CCER_CC2E)
  126. #define TUBE_E_OFF TIM3->CCER &= ~(TIM_CCER_CC1E)
  127. #define IN15_P GPIOA->BSRR = 0x1
  128. #define IN15_Plus GPIOA->BSRR = 0x2
  129. #define IN15_Minus GPIOA->BSRR = 0x4
  130. #define IN15_Percent GPIOA->BSRR = 0x8
  131. #define IN15_OFF GPIOA->BRR = 0xF
  132. #define COLOR_R(x) TIM1->CCR2 = x
  133. #define COLOR_G(x) TIM1->CCR3 = x
  134. #define COLOR_B(x) TIM1->CCR4 = x
  135. /* USER CODE END EM */
  136. /* Exported functions prototypes ---------------------------------------------*/
  137. void Error_Handler(void);
  138. /* USER CODE BEGIN EFP */
  139. /* USER CODE END EFP */
  140. /* Private defines -----------------------------------------------------------*/
  141. #define BTN1_GPIO_Port GPIOB
  142. #define BTN1_Pin LL_GPIO_PIN_2
  143. #define BTN2_GPIO_Port GPIOA
  144. #define BTN2_Pin LL_GPIO_PIN_12
  145. #define BTN3_GPIO_Port GPIOB
  146. #define BTN3_Pin LL_GPIO_PIN_4
  147. #define BTN4_GPIO_Port GPIOA
  148. #define BTN4_Pin LL_GPIO_PIN_5
  149. #define IRQ_EXTI_IRQn EXTI4_15_IRQn
  150. #define IRQ_GPIO_Port GPIOC
  151. #define IRQ_Pin LL_GPIO_PIN_14
  152. #define Latch_GPIO_Port GPIOC
  153. #define Latch_Pin LL_GPIO_PIN_6
  154. #define LC0_GPIO_Port GPIOA
  155. #define LC0_Pin LL_GPIO_PIN_0
  156. #define LC1_GPIO_Port GPIOA
  157. #define LC1_Pin LL_GPIO_PIN_1
  158. #define LC2_GPIO_Port GPIOA
  159. #define LC2_Pin LL_GPIO_PIN_2
  160. #define LC3_GPIO_Port GPIOA
  161. #define LC3_Pin LL_GPIO_PIN_3
  162. #define PWM_1_GPIO_Port GPIOA
  163. #define PWM_1_Pin LL_GPIO_PIN_8
  164. #define PWM_2_GPIO_Port GPIOB
  165. #define PWM_2_Pin LL_GPIO_PIN_1
  166. #define PWM_3_GPIO_Port GPIOB
  167. #define PWM_3_Pin LL_GPIO_PIN_0
  168. #define PWM_4_GPIO_Port GPIOA
  169. #define PWM_4_Pin LL_GPIO_PIN_7
  170. #define PWM_5_GPIO_Port GPIOA
  171. #define PWM_5_Pin LL_GPIO_PIN_6
  172. #define PWM_B_GPIO_Port GPIOA
  173. #define PWM_B_Pin LL_GPIO_PIN_10
  174. #define PWM_G_GPIO_Port GPIOA
  175. #define PWM_G_Pin LL_GPIO_PIN_11
  176. #define PWM_R_GPIO_Port GPIOA
  177. #define PWM_R_Pin LL_GPIO_PIN_9
  178. #define SHDN_GPIO_Port GPIOA
  179. #define SHDN_Pin LL_GPIO_PIN_4
  180. #define SWCLK_GPIO_Port GPIOA
  181. #define SWCLK_Pin LL_GPIO_PIN_14
  182. #define SWDIO_GPIO_Port GPIOA
  183. #define SWDIO_Pin LL_GPIO_PIN_13
  184. #define UART_EN_GPIO_Port GPIOC
  185. #define UART_EN_Pin LL_GPIO_PIN_15
  186. #define UART_ST_GPIO_Port GPIOA
  187. #define UART_ST_Pin LL_GPIO_PIN_15
  188. /* USER CODE BEGIN Private defines */
  189. /* BTNs */
  190. #define BTN_NUM 4
  191. #define BTN1_PIN GPIO_IDR_ID2
  192. #define BTN2_PIN GPIO_IDR_ID12
  193. #define BTN3_PIN GPIO_IDR_ID4
  194. #define BTN4_PIN GPIO_IDR_ID5
  195. #define BTN1_STATE (BTN1_GPIO_Port->IDR & BTN1_PIN)
  196. #define BTN2_STATE (BTN2_GPIO_Port->IDR & BTN2_PIN)
  197. #define BTN3_STATE (BTN3_GPIO_Port->IDR & BTN3_PIN)
  198. #define BTN4_STATE (BTN4_GPIO_Port->IDR & BTN4_PIN)
  199. #define BTNS1_STATE (GPIOB->IDR & (BTN1_PIN | BTN3_PIN))
  200. #define BTNS2_STATE (GPIOA->IDR & (BTN2_PIN | BTN4_PIN))
  201. #define BTNS_STATE (BTNS1_STATE | BTNS2_STATE)
  202. /* time constant in ms */
  203. #define BTN_SCAN_PERIOD 10
  204. #define BTN_SCAN_PAUSE 200
  205. #define BTN_TIME_PRESSED 30
  206. #define BTN_TIME_HOLDED 500
  207. #define BTN_TIME_REPEATED 50
  208. typedef struct {
  209. uint8_t time;
  210. es_event_t pressed;
  211. es_event_t holded;
  212. uint32_t pin;
  213. //(GPIO_TypeDef *) GPIOA; // ?->IDR
  214. } btn_t;
  215. /* USER CODE END Private defines */
  216. #ifdef __cplusplus
  217. }
  218. #endif
  219. #endif /* __MAIN_H */
  220. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/