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