mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-18 16:53:45 +00:00
68a3f6b4b7
* Add F5 target, lp5562 driver and api-hal-light. Update api-usage, switch to F5 by default. * API HAL: add i2c and hardware version api. Dolphin: show hardware version. * OTP version generator and flashing utility. * Assets script: fix code formatting * Backport F5 changes to F4 * F4: disable insomnia, prevent damage to BLE RX path * F5 HAL API Light: remove magic delay to fix magic BLE * Dolphin: HW target validation on start * invert RSSI indication in sub-1 * API HAL: rename board to body in version api * Gpio tester: detach and release viewport on exit Co-authored-by: aanper <mail@s3f.ru>
47 lines
No EOL
1.7 KiB
C
47 lines
No EOL
1.7 KiB
C
#include "cmsis_os.h"
|
|
#include "api-hal-tim.h"
|
|
|
|
/* setup TIM2 CH1 and CH2 to capture rising and falling events */
|
|
void tim_irda_rx_init(void) {
|
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
|
TIM_IC_InitTypeDef sConfigIC = {0};
|
|
|
|
htim2.Instance = TIM2;
|
|
htim2.Init.Prescaler = 64 - 1;
|
|
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
htim2.Init.Period = 4294967295;
|
|
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
|
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_IC_Init(&htim2) != HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|
if(HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
|
|
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
|
|
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
|
|
sConfigIC.ICFilter = 0;
|
|
if(HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_1) != HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
|
|
sConfigIC.ICSelection = TIM_ICSELECTION_INDIRECTTI;
|
|
if(HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_2) != HAL_OK) {
|
|
Error_Handler();
|
|
}
|
|
|
|
HAL_NVIC_SetPriority(TIM2_IRQn, 5, 0);
|
|
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1);
|
|
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2);
|
|
} |