summaryrefslogtreecommitdiff
path: root/bsp/radio-controller-1/Src/main.c
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-06-03 20:47:37 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-06-03 20:47:37 +0200
commit0bc2a81c0aab3c89b534415d6f07d07e392260ce (patch)
tree5995a09ea9212df38490b330fc878060b6bb9294 /bsp/radio-controller-1/Src/main.c
parentdcfb42c972f904482514ef194003018a02c8c260 (diff)
downloadradio-controller-0bc2a81c0aab3c89b534415d6f07d07e392260ce.tar.gz
radio-controller-0bc2a81c0aab3c89b534415d6f07d07e392260ce.tar.bz2
radio-controller-0bc2a81c0aab3c89b534415d6f07d07e392260ce.tar.xz
radio-controller-0bc2a81c0aab3c89b534415d6f07d07e392260ce.zip
o Adding support for reading IR codes.
Diffstat (limited to 'bsp/radio-controller-1/Src/main.c')
-rw-r--r--bsp/radio-controller-1/Src/main.c73
1 files changed, 72 insertions, 1 deletions
diff --git a/bsp/radio-controller-1/Src/main.c b/bsp/radio-controller-1/Src/main.c
index d7e4c04..dbcf975 100644
--- a/bsp/radio-controller-1/Src/main.c
+++ b/bsp/radio-controller-1/Src/main.c
@@ -54,6 +54,7 @@
IWDG_HandleTypeDef hiwdg;
TIM_HandleTypeDef htim1;
+TIM_HandleTypeDef htim2;
UART_HandleTypeDef huart2;
@@ -68,6 +69,7 @@ void Error_Handler(void);
static void MX_GPIO_Init(void);
static void MX_IWDG_Init(void);
static void MX_TIM1_Init(void);
+static void MX_TIM2_Init(void);
static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */
@@ -98,6 +100,7 @@ int main(void)
MX_GPIO_Init();
MX_IWDG_Init();
MX_TIM1_Init();
+ MX_TIM2_Init();
MX_USART2_UART_Init();
MX_USB_DEVICE_Init();
@@ -172,7 +175,7 @@ void SystemClock_Config(void)
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
+ HAL_NVIC_SetPriority(SysTick_IRQn, 1, 0);
}
/* IWDG init function */
@@ -240,6 +243,63 @@ static void MX_TIM1_Init(void)
}
+/* TIM2 init function */
+static void MX_TIM2_Init(void)
+{
+
+ TIM_SlaveConfigTypeDef sSlaveConfig;
+ TIM_MasterConfigTypeDef sMasterConfig;
+ TIM_IC_InitTypeDef sConfigIC;
+
+ htim2.Instance = TIM2;
+ htim2.Init.Prescaler = RADIO_RX_TIMER_PRESCALER;
+ htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
+ htim2.Init.Period = 0xffff;
+ htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
+ if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
+ {
+ Error_Handler();
+ }
+
+ if (HAL_TIM_IC_Init(&htim2) != HAL_OK)
+ {
+ Error_Handler();
+ }
+
+ sSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET;
+ sSlaveConfig.InputTrigger = TIM_TS_TI1FP1;
+ sSlaveConfig.TriggerPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
+ sSlaveConfig.TriggerFilter = 0;
+ if (HAL_TIM_SlaveConfigSynchronization(&htim2, &sSlaveConfig) != 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();
+ }
+
+}
+
/* USART2 init function */
static void MX_USART2_UART_Init(void)
{
@@ -269,11 +329,22 @@ static void MX_USART2_UART_Init(void)
static void MX_GPIO_Init(void)
{
+ GPIO_InitTypeDef GPIO_InitStruct;
+
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
+ /*Configure GPIO pin Output Level */
+ HAL_GPIO_WritePin(DEBUG_PIN_GPIO_Port, DEBUG_PIN_Pin, GPIO_PIN_RESET);
+
+ /*Configure GPIO pin : DEBUG_PIN_Pin */
+ GPIO_InitStruct.Pin = DEBUG_PIN_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ HAL_GPIO_Init(DEBUG_PIN_GPIO_Port, &GPIO_InitStruct);
+
}
/* USER CODE BEGIN 4 */