main.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 "board.h"
  48. #include "gpio.h"
  49. #include "i2c.h"
  50. #include "ds3231.h"
  51. #include "bme280.h"
  52. #include "rtos.h"
  53. #include "event-system.h"
  54. #include "list_event.h"
  55. /* USER CODE END Includes */
  56. /* Exported types ------------------------------------------------------------*/
  57. /* USER CODE BEGIN ET */
  58. typedef enum {
  59. DOWN = 0,
  60. UP = 1
  61. } updown_t;
  62. typedef enum {
  63. OFF = 0,
  64. ON = 1
  65. } onoff_t;
  66. typedef struct {
  67. uint32_t RTC_IRQ: 1;
  68. uint32_t SPI_TX_End: 1;
  69. uint32_t I2C_TX_End: 1;
  70. uint32_t I2C_RX_End: 1;
  71. uint32_t I2C_TX_Err: 1;
  72. uint32_t I2C_RX_Err: 1;
  73. uint32_t BME280: 1;
  74. uint32_t Blink_1: 1;
  75. uint32_t Blink_2: 1;
  76. uint32_t Blink_3: 1;
  77. uint32_t Blink_4: 1;
  78. uint32_t Blink_5: 1;
  79. uint32_t _reserv: 20;
  80. } flag_t;
  81. extern volatile flag_t Flag;
  82. typedef union {
  83. uint16_t u16; // element specifier for accessing whole u16
  84. int16_t i16; // element specifier for accessing whole i16
  85. struct {
  86. #ifdef LITTLE_ENDIAN // Byte-order is little endian
  87. uint8_t u8L; // element specifier for accessing low u8
  88. uint8_t u8H; // element specifier for accessing high u8
  89. #else // Byte-order is big endian
  90. uint8_t u8H; // element specifier for accessing low u8
  91. uint8_t u8L; // element specifier for accessing high u8
  92. #endif
  93. } s16; // element spec. for acc. struct with low or high u8
  94. } nt16_t;
  95. typedef union {
  96. uint32_t u32; // element specifier for accessing whole u32
  97. int32_t i32; // element specifier for accessing whole i32
  98. struct {
  99. #ifdef LITTLE_ENDIAN // Byte-order is little endian
  100. uint16_t u16L; // element specifier for accessing low u16
  101. uint16_t u16H; // element specifier for accessing high u16
  102. #else // Byte-order is big endian
  103. uint16_t u16H; // element specifier for accessing low u16
  104. uint16_t u16L; // element specifier for accessing high u16
  105. #endif
  106. } s32; // element spec. for acc. struct with low or high u16
  107. } nt32_t;
  108. /* USER CODE END ET */
  109. /* Exported constants --------------------------------------------------------*/
  110. /* USER CODE BEGIN EC */
  111. /* USER CODE END EC */
  112. /* Exported macro ------------------------------------------------------------*/
  113. /* USER CODE BEGIN EM */
  114. /* USER CODE END EM */
  115. /* Exported functions prototypes ---------------------------------------------*/
  116. void Error_Handler(void);
  117. /* USER CODE BEGIN EFP */
  118. /* USER CODE END EFP */
  119. /* Private defines -----------------------------------------------------------*/
  120. /* USER CODE BEGIN Private defines */
  121. /* BTNs */
  122. #define BTN_NUM 4
  123. #define BTN1_PIN GPIO_IDR_ID2
  124. #define BTN2_PIN GPIO_IDR_ID12
  125. #define BTN3_PIN GPIO_IDR_ID4
  126. #define BTN4_PIN GPIO_IDR_ID5
  127. #define BTN1_STATE (BTN1_GPIO_Port->IDR & BTN1_PIN)
  128. #define BTN2_STATE (BTN2_GPIO_Port->IDR & BTN2_PIN)
  129. #define BTN3_STATE (BTN3_GPIO_Port->IDR & BTN3_PIN)
  130. #define BTN4_STATE (BTN4_GPIO_Port->IDR & BTN4_PIN)
  131. #define BTNS1_STATE (GPIOB->IDR & (BTN1_PIN | BTN3_PIN))
  132. #define BTNS2_STATE (GPIOA->IDR & (BTN2_PIN | BTN4_PIN))
  133. #define BTNS_STATE (BTNS1_STATE | BTNS2_STATE)
  134. /* time constant in ms */
  135. #define BTN_SCAN_PERIOD 10
  136. #define BTN_SCAN_PAUSE 200
  137. #define BTN_TIME_PRESSED 30
  138. #define BTN_TIME_HOLDED 500
  139. #define BTN_TIME_REPEATED 50
  140. typedef struct {
  141. uint8_t time;
  142. es_event_t pressed;
  143. es_event_t holded;
  144. uint32_t pin;
  145. //(GPIO_TypeDef *) GPIOA; // ?->IDR
  146. } btn_t;
  147. /* USER CODE END Private defines */
  148. #ifdef __cplusplus
  149. }
  150. #endif
  151. #endif /* __MAIN_H */
  152. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/