Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/gfx_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "gfx_settings.h"
#include "stdio_glue.h"
#include "usb_host.h"
#include "hardware_config.h"

#define Y_CHART_SIZE_X 410
#define Y_CHART_SIZE_Y 130
Expand Down Expand Up @@ -144,6 +145,7 @@ void auto_trigger_callback(lv_timer_t * timer)
lv_timer_set_period(timer, AUTO_TRIGGER_PERIOD_MS + (rand() % 10));
} else {
auto_trigger_clear_timer();
hw_exti_interrupts_enable();
}
}

Expand All @@ -158,7 +160,9 @@ static void btn_trigger_event_cb(lv_event_t * e)
// Already running
count = 0;
auto_trigger_clear_timer();
hw_exti_interrupts_enable();
} else {
hw_exti_interrupts_disable();
// Trigger a new series of measurements
printf("AutoTrigger activated\n");
count = 1000;
Expand Down
18 changes: 18 additions & 0 deletions src/hardware_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ static void MX_TIM1_Init(void)
static void MX_TIM2_Init(void)
{
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};

htim2.Instance = TIM2;
Expand All @@ -368,6 +369,18 @@ static void MX_TIM2_Init(void)
{
Error_Handler();
}
if (HAL_TIM_OC_Init(&htim2) != HAL_OK)
{
Error_Handler();
}

sConfigOC.OCMode = TIM_OCMODE_TOGGLE;
sConfigOC.Pulse = 0;
sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
if (HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
Expand All @@ -377,6 +390,11 @@ static void MX_TIM2_Init(void)

// Start as free-running timer right away
HAL_TIM_Base_Start(&htim2);
if (HAL_TIM_OC_Start(&htim2, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
HAL_TIM_MspPostInit(&htim2);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/stm32f7xx_hal_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
PA15 ------> TIM2_CH1
*/
GPIO_InitStruct.Pin = ARDUINO_PWM_D9_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
Expand Down
13 changes: 5 additions & 8 deletions src/xlat.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,18 +602,15 @@ enum xlat_mode xlat_get_mode(void)

void xlat_auto_trigger_action(void)
{
// random delay, such that we do not always perfectly align with USB timing
srand(xTaskGetTickCount());
int val = rand() & 0xFFF;
for (volatile int i = 0; i < val; i++) {
__NOP();
}
HAL_GPIO_WritePin(ARDUINO_D11_GPIO_Port, ARDUINO_D11_Pin, auto_trigger_level_high ? GPIO_PIN_SET : GPIO_PIN_RESET);
uint32_t delay = rand() % 1000 + 100;
last_btn_gpio_timestamp = xlat_counter_1mhz_get() + delay;
htim2.Instance->CCR1 = last_btn_gpio_timestamp;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a potential issue if we get interrupted for longer than the chosen delay time before this line as the output compare function checks for exact match, so we might miss it. Could possibly solve it with PWM mode or just making the delay long enough.

gpio_irq_producer++;
}

void xlat_auto_trigger_turn_off_action(void)
{
HAL_GPIO_WritePin(ARDUINO_D11_GPIO_Port, ARDUINO_D11_Pin, auto_trigger_level_high ? GPIO_PIN_RESET : GPIO_PIN_SET);
htim2.Instance->CCR1 = xlat_counter_1mhz_get() + 100;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar issue here.

}

void xlat_auto_trigger_level_set(bool high)
Expand Down