main.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #pragma once
  2. #ifndef __MAIN_H__
  3. #define __MAIN_H__
  4. #include "buttons.h"
  5. /* Private defines */
  6. #define TOP_INFO_1_X 0
  7. #define TOP_INFO_1_Y 0
  8. #define TOP_INFO_2_X 120
  9. #define TOP_INFO_2_Y 0
  10. #define LCD_LINE_1 23
  11. #define LCD_LINE_2 33
  12. #define LCD_LINE_3 43
  13. #define LCD_LINE_4 53
  14. #define LCD_LINE_5 63
  15. #define LCD_LINE_6 73
  16. #define LCD_LINE_7 83
  17. #define LCD_LINE_8 93
  18. #define LCD_LINE_9 103
  19. #define ADC_GRP1_NUM_CHANNELS 1
  20. #define ADC_GRP1_BUF_DEPTH 100
  21. #define ADC_CHANNEL_NUM ADC_CHANNEL_IN9
  22. #define ADC_REF_VOLTAGE 3300
  23. #define ONEWIRE1_PORT GPIOB
  24. #define ONEWIRE1_PIN 9
  25. #define ONEWIRE1_PWM_DRIVER PWMD4
  26. #define ONEWIRE1_MASTER_CHANNEL 3
  27. #define ONEWIRE1_SAMPLE_CHANNEL 4
  28. #define ONEWIRE2_PORT GPIOB
  29. #define ONEWIRE2_PIN 8
  30. #define ONEWIRE2_PWM_DRIVER PWMD4
  31. #define ONEWIRE2_MASTER_CHANNEL 4
  32. #define ONEWIRE2_SAMPLE_CHANNEL 3
  33. #define ONWIRE_CHANNELS_NUM 2
  34. #define ONEWIRE_PAD_MODE_IDLE PAL_MODE_INPUT
  35. #define ONEWIRE_PAD_MODE_ACTIVE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
  36. /* Private variables */
  37. /*
  38. * SPI configuration structure.
  39. * Speed 12 MHz, CPHA=0, CPOL=0, 8bits frames, MSb transmitted first.
  40. * Soft slave select.
  41. */
  42. static const SPIConfig spi1cfg = {
  43. .circular = false,
  44. .slave = false,
  45. .data_cb = NULL,
  46. .error_cb = NULL,
  47. .cr1 = 0U,
  48. .cr2 = 0U
  49. };
  50. static adcsample_t ADC_Data[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];
  51. //static adcsample_t ADC_Data;
  52. static uint32_t Voltage;
  53. /* Private function prototypes */
  54. static void btn1_handler(const button_state_t);
  55. static void btn2_handler(const button_state_t);
  56. static void btn3_handler(const button_state_t);
  57. static void btn4_handler(const button_state_t);
  58. static btn_hndlr bha[Button_Num] = {
  59. btn1_handler,
  60. btn2_handler,
  61. btn3_handler,
  62. btn4_handler
  63. };
  64. static void lcd_MainScreen(void);
  65. static void lcd_ClearMain(void);
  66. static uint8_t X_centered(const uint8_t len, const uint8_t pix);
  67. static void ADC_cb(ADCDriver *adcp);
  68. /* Perephireal */
  69. static const ADCConversionGroup adcgrpcfg1 = {
  70. TRUE, // circular
  71. ADC_GRP1_NUM_CHANNELS,
  72. ADC_cb,
  73. NULL,
  74. 0, /* CR1 */
  75. (ADC_CR2_EXTTRIG|ADC_CR2_EXTSEL_2), /* CR2, Timer 1 CC1 event, Timer 3 TRGO event */
  76. ADC_SMPR2_SMP_AN9(ADC_SAMPLE_71P5), /* smpr1 */
  77. 0, /* SMPR2 */
  78. ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),/* sqr1 */
  79. 0, /* SQR2 */
  80. ADC_SQR3_SQ1_N(ADC_CHANNEL_NUM) /* sqr3 */
  81. };
  82. static const GPTConfig gptcfg1 = {
  83. .frequency = 1000000U,
  84. .callback = NULL,
  85. .cr2 = TIM_CR2_MMS_1, /* MMS = 010 - TRGO on Update Event. */
  86. .dier = 0U
  87. };
  88. /*
  89. * Config for underlying PWM driver.
  90. * Note! It is NOT constant because 1-wire driver needs to change them
  91. * during functioning.
  92. */
  93. static PWMConfig pwm_cfg = {
  94. 0,
  95. 0,
  96. NULL,
  97. {
  98. {PWM_OUTPUT_DISABLED, NULL},
  99. {PWM_OUTPUT_DISABLED, NULL},
  100. {PWM_OUTPUT_DISABLED, NULL},
  101. {PWM_OUTPUT_DISABLED, NULL}
  102. },
  103. 0,
  104. #if STM32_PWM_USE_ADVANCED
  105. 0,
  106. #endif
  107. 0,
  108. 0
  109. };
  110. /*
  111. * OneWire channel 1
  112. */
  113. static const onewireConfig ow_cfg1 = {
  114. &ONEWIRE1_PWM_DRIVER,
  115. &pwm_cfg,
  116. PWM_OUTPUT_ACTIVE_LOW,
  117. ONEWIRE1_MASTER_CHANNEL,
  118. ONEWIRE1_SAMPLE_CHANNEL,
  119. ONEWIRE1_PORT,
  120. ONEWIRE1_PIN,
  121. #if defined(STM32F1XX)
  122. ONEWIRE_PAD_MODE_IDLE,
  123. #endif
  124. ONEWIRE_PAD_MODE_ACTIVE,
  125. #if ONEWIRE_USE_STRONG_PULLUP
  126. strong_pullup_assert,
  127. strong_pullup_release
  128. #endif
  129. };
  130. /*
  131. * OneWire channel 2
  132. */
  133. static const onewireConfig ow_cfg2 = {
  134. &ONEWIRE2_PWM_DRIVER,
  135. &pwm_cfg,
  136. PWM_OUTPUT_ACTIVE_LOW,
  137. ONEWIRE2_MASTER_CHANNEL,
  138. ONEWIRE2_SAMPLE_CHANNEL,
  139. ONEWIRE2_PORT,
  140. ONEWIRE2_PIN,
  141. #if defined(STM32F1XX)
  142. ONEWIRE_PAD_MODE_IDLE,
  143. #endif
  144. ONEWIRE_PAD_MODE_ACTIVE,
  145. #if ONEWIRE_USE_STRONG_PULLUP
  146. strong_pullup_assert,
  147. strong_pullup_release
  148. #endif
  149. };
  150. #endif /* __MAIN_H__ */