main.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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_ll_dma.h"
  29. #include "stm32g0xx.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 "ds3231.h"
  49. #include "bme280.h"
  50. #include "rtos.h"
  51. #include "event-system.h"
  52. #include "list_event.h"
  53. /* USER CODE END Includes */
  54. /* Exported types ------------------------------------------------------------*/
  55. /* USER CODE BEGIN ET */
  56. typedef enum {
  57. DOWN = 0,
  58. UP = 1
  59. } updown_t;
  60. typedef enum {
  61. OFF = 0,
  62. ON = 1
  63. } onoff_t;
  64. volatile struct {
  65. uint32_t RTC_IRQ: 1;
  66. uint32_t SPI_TX_End: 1;
  67. uint32_t I2C_TX_End: 1;
  68. uint32_t I2C_RX_End: 1;
  69. uint32_t I2C_TX_Err: 1;
  70. uint32_t I2C_RX_Err: 1;
  71. uint32_t BME280: 1;
  72. uint32_t _reserv: 25;
  73. } Flag;
  74. typedef union {
  75. uint16_t u16; // element specifier for accessing whole u16
  76. int16_t i16; // element specifier for accessing whole i16
  77. struct {
  78. #ifdef LITTLE_ENDIAN // Byte-order is little endian
  79. uint8_t u8L; // element specifier for accessing low u8
  80. uint8_t u8H; // element specifier for accessing high u8
  81. #else // Byte-order is big endian
  82. uint8_t u8H; // element specifier for accessing low u8
  83. uint8_t u8L; // element specifier for accessing high u8
  84. #endif
  85. } s16; // element spec. for acc. struct with low or high u8
  86. } nt16_t;
  87. typedef union {
  88. uint32_t u32; // element specifier for accessing whole u32
  89. int32_t i32; // element specifier for accessing whole i32
  90. struct {
  91. #ifdef LITTLE_ENDIAN // Byte-order is little endian
  92. uint16_t u16L; // element specifier for accessing low u16
  93. uint16_t u16H; // element specifier for accessing high u16
  94. #else // Byte-order is big endian
  95. uint16_t u16H; // element specifier for accessing low u16
  96. uint16_t u16L; // element specifier for accessing high u16
  97. #endif
  98. } s32; // element spec. for acc. struct with low or high u16
  99. } nt32_t;
  100. /* USER CODE END ET */
  101. /* Exported constants --------------------------------------------------------*/
  102. /* USER CODE BEGIN EC */
  103. #define I2C_RET_OK (int8_t)0
  104. #define I2C_RET_NACK (int8_t)-1
  105. #define I2C_RET_ERR (int8_t)-2
  106. /* USER CODE END EC */
  107. /* Exported macro ------------------------------------------------------------*/
  108. /* USER CODE BEGIN EM */
  109. #define LATCH_DOWN GPIOC->BRR = 0x40
  110. #define LATCH_UP GPIOC->BSRR = 0x40
  111. #define TUBE_PWR_ON GPIOA->BRR = 0x10
  112. #define TUBE_PWR_OFF GPIOA->BSRR = 0x10
  113. #define IN15_P GPIOA->BSRR = 0x1
  114. #define IN15_Plus GPIOA->BSRR = 0x2
  115. #define IN15_Minus GPIOA->BSRR = 0x4
  116. #define IN15_Percent GPIOA->BSRR = 0x8
  117. #define IN15_OFF GPIOA->BRR = 0xF
  118. #define COLOR_R(x) TIM3->CCR1 = x
  119. #define COLOR_B(x) TIM3->CCR2 = x
  120. #define COLOR_G(x) TIM3->CCR3 = x
  121. #define COLOR_RGB(r, g, b) TIM3->CCR1 = r; TIM3->CCR3 = g; TIM3->CCR2 = b
  122. /* USER CODE END EM */
  123. /* Exported functions prototypes ---------------------------------------------*/
  124. void Error_Handler(void);
  125. /* USER CODE BEGIN EFP */
  126. /* USER CODE END EFP */
  127. /* Private defines -----------------------------------------------------------*/
  128. #define LC0_Pin LL_GPIO_PIN_0
  129. #define LC0_GPIO_Port GPIOA
  130. #define LC1_Pin LL_GPIO_PIN_1
  131. #define LC1_GPIO_Port GPIOA
  132. #define LC2_Pin LL_GPIO_PIN_2
  133. #define LC2_GPIO_Port GPIOA
  134. #define LC3_Pin LL_GPIO_PIN_3
  135. #define LC3_GPIO_Port GPIOA
  136. #define SHDN_Pin LL_GPIO_PIN_4
  137. #define SHDN_GPIO_Port GPIOA
  138. #define PWM_R_Pin LL_GPIO_PIN_6
  139. #define PWM_R_GPIO_Port GPIOA
  140. #define PWM_G_Pin LL_GPIO_PIN_7
  141. #define PWM_G_GPIO_Port GPIOA
  142. #define PWM_B_Pin LL_GPIO_PIN_0
  143. #define PWM_B_GPIO_Port GPIOB
  144. #define PWM_T_Pin LL_GPIO_PIN_1
  145. #define PWM_T_GPIO_Port GPIOB
  146. #define BTN1_Pin LL_GPIO_PIN_8
  147. #define BTN1_GPIO_Port GPIOA
  148. #define BTN2_Pin LL_GPIO_PIN_9
  149. #define BTN2_GPIO_Port GPIOA
  150. #define BTN3_Pin LL_GPIO_PIN_10
  151. #define BTN3_GPIO_Port GPIOA
  152. #define BTN4_Pin LL_GPIO_PIN_11
  153. #define BTN4_GPIO_Port GPIOA
  154. #define Latch_Pin LL_GPIO_PIN_6
  155. #define Latch_GPIO_Port GPIOC
  156. #define IRQ_Pin LL_GPIO_PIN_14
  157. #define IRQ_GPIO_Port GPIOC
  158. #define IRQ_EXTI_IRQn EXTI4_15_IRQn
  159. #define UART_EN_Pin LL_GPIO_PIN_15
  160. #define UART_EN_GPIO_Port GPIOC
  161. #define UART_ST_Pin LL_GPIO_PIN_15
  162. #define UART_ST_GPIO_Port GPIOA
  163. /* USER CODE BEGIN Private defines */
  164. #define USE_FULL_LL_DRIVER 1
  165. /* BTNs */
  166. #define BTN_NUM 4
  167. #define BTN1_PIN GPIO_IDR_ID8
  168. #define BTN2_PIN GPIO_IDR_ID9
  169. #define BTN3_PIN GPIO_IDR_ID10
  170. #define BTN4_PIN GPIO_IDR_ID11
  171. #define BTN_PORT GPIOA
  172. #define BTN_PINS (BTN1_PIN | BTN2_PIN | BTN3_PIN | BTN4_PIN)
  173. #define BTN1_STATE (BTN_PORT->IDR & BTN1_PIN)
  174. #define BTN2_STATE (BTN_PORT->IDR & BTN2_PIN)
  175. #define BTN3_STATE (BTN_PORT->IDR & BTN3_PIN)
  176. #define BTN4_STATE (BTN_PORT->IDR & BTN4_PIN)
  177. #define BTNS_STATE (BTN_PORT->IDR & BTN_PINS)
  178. #define BTN_STATE(pin) (BTN_PORT->IDR & pin)
  179. /* time constant in ms */
  180. #define BTN_SCAN_PERIOD 10
  181. #define BTN_SCAN_PAUSE 200
  182. #define BTN_TIME_PRESSED 30
  183. #define BTN_TIME_HOLDED 500
  184. #define BTN_TIME_REPEATED 50
  185. typedef struct {
  186. uint8_t time;
  187. es_event_t pressed;
  188. es_event_t holded;
  189. uint32_t pin;
  190. //(GPIO_TypeDef *) GPIOA; // ?->IDR
  191. } btn_t;
  192. /* USER CODE END Private defines */
  193. #ifdef __cplusplus
  194. }
  195. #endif
  196. #endif /* __MAIN_H */
  197. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/