forked from DualTachyon/uv-k5-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfm.c
83 lines (71 loc) · 1.84 KB
/
fm.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
/* Copyright 2023 Dual Tachyon
* https://github.com/DualTachyon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bsp/dp32g030/gpio.h"
#include "driver/bk1080.h"
#include "driver/gpio.h"
#include "fm.h"
#include "misc.h"
#include "settings.h"
uint16_t gFM_Channels[20];
bool gFmMute;
bool FM_CheckValidChannel(uint8_t Channel)
{
if (Channel < 20 && gFM_Channels[Channel] - 760 < 321) {
return true;
}
return false;
}
uint8_t FM_FindNextChannel(uint8_t Channel, uint8_t Direction)
{
uint8_t i;
for (i = 0; i < 20; i++) {
if (Channel == 0xFF) {
Channel = 19;
} else if (Channel >= 20) {
Channel = 0;
}
if (FM_CheckValidChannel(Channel)) {
return Channel;
}
Channel += Direction;
}
return 0xFF;
}
int FM_ConfigureChannelState(void)
{
uint8_t Channel;
gEeprom.FM_FrequencyToPlay = gEeprom.FM_CurrentFrequency;
if (gEeprom.FM_IsChannelSelected) {
Channel = FM_FindNextChannel(gEeprom.FM_CurrentChannel, FM_CHANNEL_UP);
if (Channel == 0xFF) {
gEeprom.FM_IsChannelSelected = false;
return -1;
}
gEeprom.FM_CurrentChannel = Channel;
gEeprom.FM_FrequencyToPlay = gFM_Channels[Channel];
}
return 0;
}
void FM_TurnOff(void)
{
gFmMute = false;
g_20000390 = 0;
g_2000038E = 0;
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 0;
BK1080_Init(0, false);
g_2000036F = 1;
}