-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.c
108 lines (90 loc) · 2.86 KB
/
app.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/***************************************************************************//**
* @file
* @brief Top level application functions
*******************************************************************************
* # License
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
/***************************************************************************//**
* Initialize application.
******************************************************************************/
#include <stdio.h>
#include "em_device.h"
#include "em_chip.h"
#include "em_timer.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "app_log.h"
#include "ir_generate.h"
volatile uint16_t timer_1ms = 0;
static bool repeat_flag = false;
static uint8_t restart_conter = 0;
void TIMER2_init(void);
void TIMER2_IRQHandler(void);
void TIMER2_IRQHandler(void)
{
// Acknowledge the interrupt
uint32_t flags = TIMER_IntGet(TIMER2);
TIMER_IntClear(TIMER2, flags);
timer_1ms++;
}
void TIMER2_init(void)
{
uint32_t timerFreq = 0;
CMU_ClockEnable(cmuClock_TIMER2, true);
// Initialize the timer
TIMER_Init_TypeDef timerInit = TIMER_INIT_DEFAULT;
timerInit.prescale = timerPrescale2;
timerInit.enable = false;
// Configure but do not start the timer
TIMER_Init(TIMER2, &timerInit);
timerFreq = CMU_ClockFreqGet(cmuClock_TIMER2) / (timerInit.prescale + 1);
TIMER_TopSet(TIMER2, (timerFreq / 1000));// 1000 for 1ms, 200 for 5ms
// Start the timer
TIMER_Enable(TIMER2, true);
// Enable TIMER2 compare event interrupts to update the duty cycle
TIMER_IntEnable(TIMER2, TIMER_IF_OF);
NVIC_EnableIRQ(TIMER2_IRQn);
}
/**
* @brief ir sent callback
*
* @param none
*
* @return none
*
*/
void app_ir_complete(void)
{
app_log("ir complete\r\n");
}
void app_init(void)
{
TIMER2_init();
app_log("test ir\r\n");
ir_generate_init(CODE_NEC, app_ir_complete);
// ir_generate_stream(0xFF, 0xFF, false); // for test
}
void app_process_action(void)
{
uint8_t frame_interval[2] = { 108, 45 }; // 108 for NEC, 45 for SONY
if (timer_1ms >= frame_interval[CODE_NEC]) {
timer_1ms -= frame_interval[CODE_NEC];
ir_generate_stream(0xFF, 0xFF, repeat_flag); // for test
// for NEC protocol, change after 4th repeat frame.
if (restart_conter++ % 5 == 0) {
repeat_flag = false;
} else {
repeat_flag = true;
}
}
}