]> cloudbase.mooo.com Git - irmp.git/blame - irmp-main-stm32.c
Version 3.0.2
[irmp.git] / irmp-main-stm32.c
CommitLineData
ea29682a 1/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
2 * irmp-main-stm32.c - demo main module to test IRMP decoder on STM32\r
3 *\r
7365350c 4 * Copyright (c) 2009-2016 Frank Meyer - frank(at)fli4l.de\r
ea29682a 5 *\r
7365350c 6 * $Id: irmp-main-stm32.c,v 1.2 2016/01/12 21:15:16 fm Exp $\r
ea29682a 7 *\r
8 * This demo module is runnable on STM32\r
9 *\r
10 * This program is free software; you can redistribute it and/or modify\r
11 * it under the terms of the GNU General Public License as published by\r
12 * the Free Software Foundation; either version 2 of the License, or\r
13 * (at your option) any later version.\r
14 *---------------------------------------------------------------------------------------------------------------------------------------------------\r
15 */\r
16\r
17#include "irmp.h"\r
18\r
19#ifndef F_CPU\r
20#error F_CPU unknown\r
21#endif\r
22\r
23uint32_t\r
24SysCtlClockGet(void)\r
25{\r
26 RCC_ClocksTypeDef RCC_ClocksStatus;\r
27 RCC_GetClocksFreq(&RCC_ClocksStatus);\r
28 return RCC_ClocksStatus.SYSCLK_Frequency;\r
29}\r
30\r
31void\r
32timer2_init (void)\r
33{\r
34 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;\r
35 NVIC_InitTypeDef NVIC_InitStructure;\r
36 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);\r
37\r
38 TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;\r
39 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;\r
40 TIM_TimeBaseStructure.TIM_Period = 7;\r
41 TIM_TimeBaseStructure.TIM_Prescaler = ((F_CPU / F_INTERRUPTS)/8) - 1;\r
42 TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);\r
43\r
44 TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);\r
45\r
46 NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;\r
47 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;\r
48 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;\r
49 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;\r
50 NVIC_Init(&NVIC_InitStructure);\r
51\r
52 TIM_Cmd(TIM2, ENABLE);\r
53}\r
54\r
55void\r
56TIM2_IRQHandler(void) // Timer2 Interrupt Handler\r
57{\r
58 TIM_ClearITPendingBit(TIM2, TIM_IT_Update);\r
59 (void) irmp_ISR(); // call irmp ISR\r
60 // call other timer interrupt routines...\r
61}\r
62\r
63int\r
64main (void)\r
65{\r
66 IRMP_DATA irmp_data;\r
67 \r
68 irmp_init(); // initialize irmp\r
69 timer2_init(); // initialize timer2\r
70\r
71 for (;;)\r
72 {\r
73 if (irmp_get_data (&irmp_data))\r
74 {\r
75 // ir signal decoded, do something here...\r
76 // irmp_data.protocol is the protocol, see irmp.h\r
77 // irmp_data.address is the address/manufacturer code of ir sender\r
78 // irmp_data.command is the command code\r
79 // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h)\r
80 }\r
81 }\r
82}\r