|
@@ -27,6 +27,7 @@
|
|
|
#include "uartio.h"
|
|
|
#include "commprt.h"
|
|
|
#include "menu.h"
|
|
|
+#include "preferences.h"
|
|
|
#include "ssd1306_tests.h"
|
|
|
#include <stdlib.h>
|
|
|
#include <stdio.h>
|
|
@@ -61,6 +62,7 @@ DAC_HandleTypeDef hdac;
|
|
|
I2C_HandleTypeDef hi2c1;
|
|
|
I2C_HandleTypeDef hi2c2;
|
|
|
|
|
|
+TIM_HandleTypeDef htim2;
|
|
|
TIM_HandleTypeDef htim3;
|
|
|
TIM_HandleTypeDef htim4;
|
|
|
TIM_HandleTypeDef htim6;
|
|
@@ -87,41 +89,7 @@ volatile struct {
|
|
|
} Flags;
|
|
|
|
|
|
volatile uint32_t pulses = 0;
|
|
|
-
|
|
|
-uint32_t Wave_LUT[] = {
|
|
|
- 0x80,0x83,0x86,0x89,0x8c,0x8f,0x92,0x95,
|
|
|
- 0x98,0x9b,0x9e,0xa2,0xa5,0xa7,0xaa,0xad,
|
|
|
- 0xb0,0xb3,0xb6,0xb9,0xbc,0xbe,0xc1,0xc4,
|
|
|
- 0xc6,0xc9,0xcb,0xce,0xd0,0xd3,0xd5,0xd7,
|
|
|
- 0xda,0xdc,0xde,0xe0,0xe2,0xe4,0xe6,0xe8,
|
|
|
- 0xea,0xeb,0xed,0xee,0xf0,0xf1,0xf3,0xf4,
|
|
|
- 0xf5,0xf6,0xf8,0xf9,0xfa,0xfa,0xfb,0xfc,
|
|
|
- 0xfd,0xfd,0xfe,0xfe,0xfe,0xff,0xff,0xff,
|
|
|
- 0xff,0xff,0xff,0xff,0xfe,0xfe,0xfe,0xfd,
|
|
|
- 0xfd,0xfc,0xfb,0xfa,0xfa,0xf9,0xf8,0xf6,
|
|
|
- 0xf5,0xf4,0xf3,0xf1,0xf0,0xee,0xed,0xeb,
|
|
|
- 0xea,0xe8,0xe6,0xe4,0xe2,0xe0,0xde,0xdc,
|
|
|
- 0xda,0xd7,0xd5,0xd3,0xd0,0xce,0xcb,0xc9,
|
|
|
- 0xc6,0xc4,0xc1,0xbe,0xbc,0xb9,0xb6,0xb3,
|
|
|
- 0xb0,0xad,0xaa,0xa7,0xa5,0xa2,0x9e,0x9b,
|
|
|
- 0x98,0x95,0x92,0x8f,0x8c,0x89,0x86,0x83,
|
|
|
- 0x80,0x7c,0x79,0x76,0x73,0x70,0x6d,0x6a,
|
|
|
- 0x67,0x64,0x61,0x5d,0x5a,0x58,0x55,0x52,
|
|
|
- 0x4f,0x4c,0x49,0x46,0x43,0x41,0x3e,0x3b,
|
|
|
- 0x39,0x36,0x34,0x31,0x2f,0x2c,0x2a,0x28,
|
|
|
- 0x25,0x23,0x21,0x1f,0x1d,0x1b,0x19,0x17,
|
|
|
- 0x15,0x14,0x12,0x11,0xf,0xe,0xc,0xb,
|
|
|
- 0xa,0x9,0x7,0x6,0x5,0x5,0x4,0x3,
|
|
|
- 0x2,0x2,0x1,0x1,0x1,0x0,0x0,0x0,
|
|
|
- 0x0,0x0,0x0,0x0,0x1,0x1,0x1,0x2,
|
|
|
- 0x2,0x3,0x4,0x5,0x5,0x6,0x7,0x9,
|
|
|
- 0xa,0xb,0xc,0xe,0xf,0x11,0x12,0x14,
|
|
|
- 0x15,0x17,0x19,0x1b,0x1d,0x1f,0x21,0x23,
|
|
|
- 0x25,0x28,0x2a,0x2c,0x2f,0x31,0x34,0x36,
|
|
|
- 0x39,0x3b,0x3e,0x41,0x43,0x46,0x49,0x4c,
|
|
|
- 0x4f,0x52,0x55,0x58,0x5a,0x5d,0x61,0x64,
|
|
|
- 0x67,0x6a,0x6d,0x70,0x73,0x76,0x79,0x7c,
|
|
|
-};
|
|
|
+uint8_t screen = 0;
|
|
|
|
|
|
/* USER CODE END PV */
|
|
|
|
|
@@ -139,6 +107,7 @@ static void MX_TIM4_Init(void);
|
|
|
static void MX_TIM3_Init(void);
|
|
|
static void MX_I2C1_Init(void);
|
|
|
static void MX_CRC_Init(void);
|
|
|
+static void MX_TIM2_Init(void);
|
|
|
/* USER CODE BEGIN PFP */
|
|
|
|
|
|
/* USER CODE END PFP */
|
|
@@ -194,11 +163,16 @@ void SwitchPeriphSupply(OnOff_t state)
|
|
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
|
|
|
}
|
|
|
|
|
|
-void Beep()
|
|
|
+void Beep(uint8_t tone, uint8_t volume, uint8_t duration)
|
|
|
{
|
|
|
- //HAL_TIM_PWM_Start_DMA(&htim3, TIM_CHANNEL_4, Wave_LUT, sizeof(Wave_LUT) / 4);
|
|
|
- //HAL_TIM_Base_Stop(&htim2);
|
|
|
- //HAL_TIM_Base_Start(&htim2);
|
|
|
+ HAL_TIM_OC_Stop(&htim3, TIM_CHANNEL_4);
|
|
|
+ HAL_TIM_Base_Stop(&htim2);
|
|
|
+
|
|
|
+ htim3.Instance->CCR4 = volume * 5;
|
|
|
+ htim3.Instance->ARR = 2000 / (1 + tone);
|
|
|
+
|
|
|
+ HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_4);
|
|
|
+ HAL_TIM_Base_Start(&htim2);
|
|
|
}
|
|
|
|
|
|
/* USER CODE END 0 */
|
|
@@ -242,6 +216,7 @@ int main(void)
|
|
|
MX_I2C1_Init();
|
|
|
MX_USB_DEVICE_Init();
|
|
|
MX_CRC_Init();
|
|
|
+ MX_TIM2_Init();
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
|
|
Switch3V3Regulator(ON);
|
|
@@ -268,89 +243,120 @@ int main(void)
|
|
|
HAL_COMP_Start_IT(&hcomp2);
|
|
|
HAL_TIM_Base_Start_IT(&htim6);
|
|
|
HAL_TIM_Base_Start_IT(&htim4);
|
|
|
- //HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_4);
|
|
|
+ HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_4);
|
|
|
|
|
|
UARTIO_Init(&huart1);
|
|
|
|
|
|
+ MenuInit();
|
|
|
+ PrefLoadFromFlash();
|
|
|
+
|
|
|
/* USER CODE END 2 */
|
|
|
|
|
|
/* Infinite loop */
|
|
|
/* USER CODE BEGIN WHILE */
|
|
|
char tempstr[32];
|
|
|
|
|
|
- uint8_t imgbuffer[172];
|
|
|
-
|
|
|
uint32_t pps = 0;
|
|
|
uint32_t pps_avg = 0;
|
|
|
uint32_t total_dose = 0;
|
|
|
uint8_t pwdn_cnt = 0;
|
|
|
- uint8_t window = 0;
|
|
|
|
|
|
Flags.Exti = 0;
|
|
|
|
|
|
- //ssd1306_SetContrast(60);
|
|
|
- //ssd1306_TestAll();
|
|
|
- Beep();
|
|
|
-
|
|
|
while (1)
|
|
|
{
|
|
|
- if(window == 1)
|
|
|
- {
|
|
|
- if(COMM_Receive(imgbuffer, COMM_USB, 200) == COMM_OK)
|
|
|
- {
|
|
|
- ssd1306_Fill(Black);
|
|
|
- for(int y = 0; y < 32; y++)
|
|
|
- {
|
|
|
- for(int x = 0; x < 43; x++)
|
|
|
- {
|
|
|
- uint16_t pos = (y * 43) + x;
|
|
|
- if(imgbuffer[pos / 8] & (1 << (pos % 8)))
|
|
|
- ssd1306_DrawPixel(x + 43, y, White);
|
|
|
- }
|
|
|
- }
|
|
|
- ssd1306_UpdateScreen();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
if(Flags.Exti)
|
|
|
{
|
|
|
uint16_t btn = Flags.Exti;
|
|
|
Flags.Exti = 0;
|
|
|
+ if(btn == GPIO_PIN_14)
|
|
|
+ {
|
|
|
+ if(screen == 50)
|
|
|
+ MenuScroll();
|
|
|
+ }
|
|
|
+
|
|
|
if(btn == GPIO_PIN_15)
|
|
|
{
|
|
|
- window ^= 1;
|
|
|
- ssd1306_Fill(Black);
|
|
|
- ssd1306_UpdateScreen();
|
|
|
+ if(screen == 50)
|
|
|
+ MenuEnter();
|
|
|
+ else
|
|
|
+ screen = 50;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ switch(screen)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ ssd1306_Fill(Black);
|
|
|
+ ssd1306_DrawRectangle(0, 0, SSD1306_WIDTH - 1, SSD1306_HEIGHT - 1, White);
|
|
|
+ ssd1306_SetCursor(1, 7);
|
|
|
+ sprintf(tempstr, "%5.2f uSv/h", (float)pps_avg / 100.0);
|
|
|
+ ssd1306_WriteString(tempstr, Font_11x18, White);
|
|
|
+ ssd1306_UpdateScreen();
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 1:
|
|
|
+ ssd1306_Fill(Black);
|
|
|
+ ssd1306_DrawRectangle(0, 0, SSD1306_WIDTH - 1, SSD1306_HEIGHT - 1, White);
|
|
|
+ ssd1306_SetCursor(1, 7);
|
|
|
+ sprintf(tempstr, "%5.2f uSv", (float)total_dose / 360000.0);
|
|
|
+ ssd1306_WriteString(tempstr, Font_11x18, White);
|
|
|
+ ssd1306_UpdateScreen();
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 2:
|
|
|
+ ssd1306_Fill(Black);
|
|
|
+ ssd1306_DrawRectangle(0, 0, SSD1306_WIDTH - 1, SSD1306_HEIGHT - 1, White);
|
|
|
+ ssd1306_SetCursor(1, 7);
|
|
|
+ sprintf(tempstr, "00:00:00");
|
|
|
+ ssd1306_WriteString(tempstr, Font_11x18, White);
|
|
|
+ ssd1306_UpdateScreen();
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 3: // < DEBUG SCREEN >
|
|
|
+ ssd1306_Fill(Black);
|
|
|
+ ssd1306_DrawRectangle(0, 0, SSD1306_WIDTH - 1, SSD1306_HEIGHT - 1, White);
|
|
|
+ ssd1306_SetCursor(1, 7);
|
|
|
+ //sprintf(tempstr, "%lx", (uint32_t)&saved_settings);
|
|
|
+ ssd1306_WriteString(tempstr, Font_7x10, White);
|
|
|
+ ssd1306_UpdateScreen();
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 44:
|
|
|
+ ssd1306_Fill(Black);
|
|
|
+ ssd1306_DrawRectangle(0, 0, SSD1306_WIDTH - 1, SSD1306_HEIGHT - 1, White);
|
|
|
+ ssd1306_SetCursor(1, 7);
|
|
|
+ sprintf(tempstr, "Balaboliya");
|
|
|
+ ssd1306_WriteString(tempstr, Font_11x18, White);
|
|
|
+ ssd1306_UpdateScreen();
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ MenuShow();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
if(Flags.Tim6)
|
|
|
{
|
|
|
- int rcvlen = CDC_ReadData(imgbuffer, sizeof(imgbuffer));
|
|
|
- if(rcvlen > 0)
|
|
|
- UARTIO_Transmit(imgbuffer, rcvlen);
|
|
|
+ Flags.Tim6 = 0;
|
|
|
|
|
|
- rcvlen = UARTIO_Receive(imgbuffer, sizeof(imgbuffer));
|
|
|
- if(rcvlen > 0)
|
|
|
- CDC_WriteData(imgbuffer, rcvlen);
|
|
|
+ ssd1306_SetContrast((PrefGetValue(PREF_ENERGY_BRIGHT) + 1) * 23);
|
|
|
|
|
|
- Flags.Tim6 = 0;
|
|
|
HAL_ADC_Stop_DMA(&hadc);
|
|
|
|
|
|
if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_14) == GPIO_PIN_RESET)
|
|
|
{
|
|
|
- if(++pwdn_cnt > 10)
|
|
|
- {
|
|
|
- ssd1306_Reset();
|
|
|
- SwitchPeriphSupply(OFF);
|
|
|
- HAL_I2C_DeInit(&hi2c1);
|
|
|
- HAL_I2C_DeInit(&hi2c2);
|
|
|
- HAL_UART_DeInit(&huart1);
|
|
|
- HAL_GPIO_DeInit(GPIOB, GPIO_PIN_All);
|
|
|
- HAL_GPIO_DeInit(GPIOA, GPIO_PIN_All);
|
|
|
- HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
|
|
|
-
|
|
|
- }
|
|
|
+ if(++pwdn_cnt > 10)
|
|
|
+ {
|
|
|
+ ssd1306_Reset();
|
|
|
+ SwitchPeriphSupply(OFF);
|
|
|
+ HAL_I2C_DeInit(&hi2c1);
|
|
|
+ HAL_I2C_DeInit(&hi2c2);
|
|
|
+ HAL_UART_DeInit(&huart1);
|
|
|
+ HAL_GPIO_DeInit(GPIOB, GPIO_PIN_All);
|
|
|
+ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_All);
|
|
|
+ HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -366,19 +372,13 @@ int main(void)
|
|
|
pps_avg = (pps + pps_avg) / 2;
|
|
|
}
|
|
|
|
|
|
- if(window == 0)
|
|
|
- {
|
|
|
- ssd1306_DrawRectangle(0, 0, SSD1306_WIDTH - 1, SSD1306_HEIGHT - 1, White);
|
|
|
- ssd1306_SetCursor(1, 7);
|
|
|
- sprintf(tempstr, "%5.2f uSv/h", (float)pps_avg / 100.0);
|
|
|
- ssd1306_WriteString(tempstr, Font_11x18, White);
|
|
|
- ssd1306_UpdateScreen();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //ssd1306_SetCursor(2, 2);
|
|
|
- //ssd1306_WriteString(tempstr, Font_7x10, White);
|
|
|
- }
|
|
|
+ /*
|
|
|
+ ssd1306_DrawRectangle(0, 0, SSD1306_WIDTH - 1, SSD1306_HEIGHT - 1, White);
|
|
|
+ ssd1306_SetCursor(1, 7);
|
|
|
+ sprintf(tempstr, "%5.2f uSv/h", (float)pps_avg / 100.0);
|
|
|
+ ssd1306_WriteString(tempstr, Font_11x18, White);
|
|
|
+ ssd1306_UpdateScreen();
|
|
|
+ */
|
|
|
|
|
|
SetDACVoltage(DAC_CHANNEL_1, SIPM_BIAS_VOLTAGE_OFFSET);
|
|
|
SetDACVoltage(DAC_CHANNEL_2, COMP_THRESHOLD_VOLTAGE);
|
|
@@ -395,13 +395,14 @@ int main(void)
|
|
|
|
|
|
pps = (pulses * 100000) / elapsed;
|
|
|
|
|
|
+ total_dose += pulses;
|
|
|
+
|
|
|
pulses = 0;
|
|
|
Flags.Tim4 = 0;
|
|
|
htim4.Instance->CNT = 0;
|
|
|
HAL_TIM_Base_Start(&htim4);
|
|
|
|
|
|
- //if(window == 0)
|
|
|
- // Beep();
|
|
|
+ Beep(PrefGetValue(PREF_SOUND_TONE), PrefGetValue(PREF_SOUND_VOLUME), 100);
|
|
|
}
|
|
|
|
|
|
/* USER CODE END WHILE */
|
|
@@ -693,6 +694,55 @@ static void MX_I2C2_Init(void)
|
|
|
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @brief TIM2 Initialization Function
|
|
|
+ * @param None
|
|
|
+ * @retval None
|
|
|
+ */
|
|
|
+static void MX_TIM2_Init(void)
|
|
|
+{
|
|
|
+
|
|
|
+ /* USER CODE BEGIN TIM2_Init 0 */
|
|
|
+
|
|
|
+ /* USER CODE END TIM2_Init 0 */
|
|
|
+
|
|
|
+ TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
|
+ TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
|
+
|
|
|
+ /* USER CODE BEGIN TIM2_Init 1 */
|
|
|
+
|
|
|
+ /* USER CODE END TIM2_Init 1 */
|
|
|
+ htim2.Instance = TIM2;
|
|
|
+ htim2.Init.Prescaler = 600;
|
|
|
+ htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
|
+ htim2.Init.Period = 1000;
|
|
|
+ htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
|
+ htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
|
+ if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
|
|
|
+ {
|
|
|
+ Error_Handler();
|
|
|
+ }
|
|
|
+ sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
|
|
+ if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
|
|
|
+ {
|
|
|
+ Error_Handler();
|
|
|
+ }
|
|
|
+ if (HAL_TIM_OnePulse_Init(&htim2, TIM_OPMODE_SINGLE) != HAL_OK)
|
|
|
+ {
|
|
|
+ Error_Handler();
|
|
|
+ }
|
|
|
+ sMasterConfig.MasterOutputTrigger = TIM_TRGO_ENABLE;
|
|
|
+ sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|
|
+ if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
|
|
|
+ {
|
|
|
+ Error_Handler();
|
|
|
+ }
|
|
|
+ /* USER CODE BEGIN TIM2_Init 2 */
|
|
|
+
|
|
|
+ /* USER CODE END TIM2_Init 2 */
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* @brief TIM3 Initialization Function
|
|
|
* @param None
|
|
@@ -706,6 +756,7 @@ static void MX_TIM3_Init(void)
|
|
|
/* USER CODE END TIM3_Init 0 */
|
|
|
|
|
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
|
+ TIM_SlaveConfigTypeDef sSlaveConfig = {0};
|
|
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
|
TIM_OC_InitTypeDef sConfigOC = {0};
|
|
|
|
|
@@ -713,9 +764,9 @@ static void MX_TIM3_Init(void)
|
|
|
|
|
|
/* USER CODE END TIM3_Init 1 */
|
|
|
htim3.Instance = TIM3;
|
|
|
- htim3.Init.Prescaler = 0;
|
|
|
+ htim3.Init.Prescaler = 48;
|
|
|
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
|
- htim3.Init.Period = 255;
|
|
|
+ htim3.Init.Period = 1000;
|
|
|
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
|
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
|
|
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
|
|
@@ -731,6 +782,12 @@ static void MX_TIM3_Init(void)
|
|
|
{
|
|
|
Error_Handler();
|
|
|
}
|
|
|
+ sSlaveConfig.SlaveMode = TIM_SLAVEMODE_GATED;
|
|
|
+ sSlaveConfig.InputTrigger = TIM_TS_ITR1;
|
|
|
+ if (HAL_TIM_SlaveConfigSynchro(&htim3, &sSlaveConfig) != HAL_OK)
|
|
|
+ {
|
|
|
+ Error_Handler();
|
|
|
+ }
|
|
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
|
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
|