This commit is contained in:
David Rice
2026-02-18 16:23:27 +00:00
parent 869aba188a
commit e22e0a0e5a
7 changed files with 13969 additions and 13846 deletions

View File

@@ -95,6 +95,7 @@ float vout_adj = 0;
uint32_t vout_adj_uint = 0x00000000;
uint8_t buffer_count = 0x00;
uint32_t v_scale = 0x00000000;
uint8_t solid_state_flag = 0x00;
/* Stored in RAM */
const uint16_t dataBuffer[25] =
@@ -140,6 +141,7 @@ static void MX_ADC1_Init(void);
static void MX_TIM16_Init(void);
/* USER CODE BEGIN PFP */
void power_switch (uint8_t state);
void power_switch_solid_state (uint8_t state);
void adc_task(void);
float get_actual_vdda(ADC_HandleTypeDef *hadc);
void voltage_conversion_task(void);
@@ -282,7 +284,10 @@ int main(void)
else
{
__HAL_TIM_SET_COMPARE(&htim16, TIM_CHANNEL_1, 0);
if (solid_state_flag == 0x00)
{
__HAL_TIM_SET_COMPARE(&htim16, TIM_CHANNEL_1, 0);
}
}
@@ -824,6 +829,22 @@ void power_switch (uint8_t state)
}
}
/* Power switch solid state function */
void power_switch_solid_state (uint8_t state)
{
if (state == 1)
{
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
__HAL_TIM_SET_COMPARE(&htim16, TIM_CHANNEL_1, 63999);
}
else
{
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
__HAL_TIM_SET_COMPARE(&htim16, TIM_CHANNEL_1, 0);
}
}
/* UART Tx callback */
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
@@ -938,11 +959,19 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
/* 'S' - Set power output state */
case 0x53:
solid_state_flag = 0x00;
power_state_value = rx_buffer[1];
v_target = ((uint32_t)rx_buffer[2] << 24) | ((uint32_t)rx_buffer[3] << 16) | ((uint32_t)rx_buffer[4] << 8) | ((uint32_t)rx_buffer[5]);
power_switch(power_state_value);
break;
/* 's' - Set power output solid state */
case 0x73:
solid_state_flag = 0xff;
power_state_value = rx_buffer[1];
power_switch_solid_state(power_state_value);
break;
/* 'V' - Get voltages (both input and output) */
case 0x56:
adc_task_flag = 0xff;