libfmjni: implement getPs, getLrText and readRds
[GitHub/LineageOS/android_hardware_samsung_slsi_fm.git] / FmRadioController_slsi.h
1 #ifndef __FM_RADIO_CONTROLLER_SLSI_H__
2 #define __FM_RADIO_CONTROLLER_SLSI_H__
3
4 #define FM_RADIO_TEST_MODE
5
6 #include <pthread.h>
7
8 #if defined(FM_RADIO_TEST_MODE)
9 #include "FmRadioController_test.h"
10 #else
11 #include "FmRadioRDSParser.h"
12 #endif
13 #include <linux/videodev2.h>
14
15 #define FM_RADIO_DEVICE "/dev/radio0"
16
17 #define FM_FAILURE -1
18 #define FM_SUCCESS 0
19
20 enum fm_radio_state
21 {
22 FM_RADIO_OFF = 0,
23 FM_RADIO_ON,
24 FM_RADIO_WORKING,
25 FM_RADIO_STOP,
26 };
27
28 /*******************************************************************************
29 *
30 * Definitions for radio basic functions
31 *
32 ******************************************************************************/
33
34 enum fm_radio_seek_dir
35 {
36 FM_RADIO_SEEK_DOWN = 0,
37 FM_RADIO_SEEK_UP,
38 };
39
40 enum fm_radio_band
41 {
42 FM_RADIO_BAND_EUR = 0, /* European/U.S. (87.5 - 108)MHz */
43 FM_RADIO_BAND_JAP, /* Japanese (76 - 90)MHz */
44 };
45
46 enum fm_radio_mute
47 {
48 FM_RADIO_MUTE_ON = 0,
49 FM_RADIO_MUTE_OFF,
50 };
51
52 enum fm_radio_tuner_mode
53 {
54 FM_RADIO_TUNER_MONO = 0,
55 FM_RADIO_TUNER_STEREO,
56 };
57
58 #define FM_RADIO_SPACING_50KHZ 5
59 #define FM_RADIO_SPACING_100KHZ 10
60 #define FM_RADIO_SPACING_200KHZ 20
61
62 enum fm_radio_deconstant_val
63 {
64 FM_RADIO_DE_TIME_CONSTANT_0 = 0,
65 FM_RADIO_DE_TIME_CONSTANT_75,
66 };
67
68 enum fm_radio_search_mode
69 {
70 FM_RADIO_STOP_SEARCH_MODE = 0,
71 FM_RADIO_PRESET_MODE,
72 FM_RADIO_AUTONOMOUS_SEARCH_MODE,
73 FM_RADIO_AF_JUMP_MODE,
74 FM_RADIO_AUTONOMOUS_SEARCH_MODE_SKIP,
75 };
76
77 #define V4L2_CID_USER_S610_BASE (V4L2_CID_USER_BASE + 0x1070)
78
79 enum s610_ctrl_id {
80 V4L2_CID_S610_CH_SPACING = (V4L2_CID_USER_S610_BASE + 0x01),
81 V4L2_CID_S610_CH_BAND = (V4L2_CID_USER_S610_BASE + 0x02),
82 V4L2_CID_S610_SOFT_STEREO_BLEND = (V4L2_CID_USER_S610_BASE + 0x03),
83 V4L2_CID_S610_SOFT_STEREO_BLEND_COEFF = (V4L2_CID_USER_S610_BASE + 0x04),
84 V4L2_CID_S610_SOFT_MUTE_COEFF = (V4L2_CID_USER_S610_BASE + 0x05),
85 V4L2_CID_S610_RSSI_CURR = (V4L2_CID_USER_S610_BASE + 0x06),
86 V4L2_CID_S610_SNR_CURR = (V4L2_CID_USER_S610_BASE + 0x07),
87 V4L2_CID_S610_SEEK_CANCEL = (V4L2_CID_USER_S610_BASE + 0x08),
88 V4L2_CID_S610_SEEK_MODE = (V4L2_CID_USER_S610_BASE + 0x09),
89 V4L2_CID_S610_RDS_ON = (V4L2_CID_USER_S610_BASE + 0x0A),
90 V4L2_CID_S610_IF_COUNT1 = (V4L2_CID_USER_S610_BASE + 0x0B),
91 V4L2_CID_S610_IF_COUNT2 = (V4L2_CID_USER_S610_BASE + 0x0C),
92 V4L2_CID_S610_RSSI_TH = (V4L2_CID_USER_S610_BASE + 0x0D),
93 };
94
95 /*******************************************************************************
96 *
97 * Decalarations for RDS
98 *
99 ******************************************************************************/
100
101 #define FM_RADIO_ENABLED_RDS (1 << 0)
102 #define FM_RADIO_ENABLED_DNS (1 << 1)
103 #define FM_RADIO_ENABLED_AF (1 << 2)
104 #define FM_RADIO_ENABLED_ALL (FM_RADIO_ENABLED_RDS | FM_RADIO_ENABLED_DNS | FM_RADIO_ENABLED_AF)
105
106 #define FM_RADIO_RDS_DATA_MAX 48
107
108 #define FM_RADIO_RDS_GRP_NUM 3
109 #define FM_RADIO_RDS_BLK_NUM 4
110 #define FM_RADIO_RDS_SET_NUM (FM_RADIO_RDS_GRP_NUM * FM_RADIO_RDS_BLK_NUM)
111
112 #define FM_RADIO_RDS_BLER_MASK (0x3 << 3)
113
114 enum fm_radio_rds_index
115 {
116 FM_RADIO_RDS_LSB = 0,
117 FM_RADIO_RDS_MSB,
118 FM_RADIO_RDS_BLER,
119 };
120
121 typedef enum {
122 RDS_EVT_UPDATE = 0x0001,
123 RDS_EVT_PI_UPDATE = 0x0002,
124 RDS_EVT_PTY_UPDATE = 0x0004,
125 RDS_EVT_PS_UPDATE = 0x0008,
126 RDS_EVT_RT_UPDATE = 0x0040,
127 RDS_EVT_AF_JUMP = 0x0080,
128 RDS_EVT_AF_LIST = 0x0100,
129 RDS_EVT_AF_LIST_UPDATE = 0x0200,
130 RDS_EVT_RDS_AVL = 0x2000,
131 RDS_EVT_RDS_NOT_AVL = 0x4000,
132 } RdsEvts;
133
134 #if !defined(FM_RADIO_TEST_MODE)
135 extern void RDSDataReceived(Final_RDS_data rdsData);
136 extern void RTPlusDataReceived(RTPlus_data rtplusData);
137 extern void PIECCDataReceived(PIECC_data PIECCData);
138 extern void AFDataReceived(long AF);
139 extern void CallbackAFStarted();
140 #endif
141
142 /*******************************************************************************
143 *
144 * FmRadioController_slsi Class
145 *
146 ******************************************************************************/
147
148 class FmRadioController_slsi {
149 private:
150 int radio_state;
151 int radio_fd;
152
153 int is_mute_on;
154 int tuner_mode;
155 int channel_spacing;
156 int current_band;
157 long current_volume;
158 bool is_seeking;
159
160 /* RDS/DNS/AF */
161 #if !defined(FM_RADIO_TEST_MODE)
162 FmRadioRDSParser RDSParser;
163 AF_List AFList;
164 #endif
165 bool radio_thread_termination;
166 pthread_t radio_rds_thread;
167 pthread_t radio_af_thread;
168 unsigned char is_enabled_functions;
169 unsigned char is_af_switching;
170 unsigned short current_pi;
171 long curr_channel;
172 int af_threshold;
173 int afvalid_threshold;
174 bool cancel_af_switching;
175
176 /* Sub functions for RDS/DNS/AF */
177 int startThreadforFmRadio(unsigned char func);
178 int stopThreadforFmRadio(unsigned char func);
179 static void* radio_thread_handler(void *arg);
180 void radio_data_proc(unsigned char *buf, int count);
181 #if !defined(FM_RADIO_TEST_MODE)
182 void radio_af_switching();
183 static void* radio_af_thread_handler(void *arg);
184 int af_signal_check(AF_List *af_list);
185 #endif
186
187 public:
188 FmRadioController_slsi();
189 ~FmRadioController_slsi();
190
191 int Initialise();
192
193 void TuneChannel(long channel);
194 long GetChannel();
195
196 long SeekUp();
197 long SeekDown();
198 long SearchUp();
199 long SearchDown();
200 long SearchAll();
201 void SeekCancel();
202
203 /* Audio */
204 void SetVolume(long volume);
205 long GetVolume();
206 long GetMaxVolume();
207 void SetSpeakerOn(bool on);
208 void SetRecordMode(int on);
209
210 void SetBand(int band);
211 void SetChannelSpacing(int spacing);
212 void SetStereo();
213 void SetMono();
214 void MuteOn();
215 void MuteOff();
216 void setSoftmute(bool setSoftmute);
217 void SetDeConstant(long constant);
218
219 long GetCurrentRSSI();
220 long GetCurrentSNR();
221 void SetCurrentRSSI(long rssi);
222 long GetSeekMode();
223 void SetSeekMode(long seek_mode);
224 int GetChannelSpacing();
225 void SetSoftStereoBlendCoeff(long value);
226 void SetSoftMuteCoeff(long value);
227
228 void EnableRDS();
229 void DisableRDS();
230 void EnableDNS();
231 void DisableDNS();
232 void EnableAF();
233 void DisableAF();
234 void CancelAfSwitchingProcess();
235 void SetAF_th(int freq);
236 int GetAF_th();
237 void SetAFValid_th(int freq);
238 int GetAFValid_th();
239
240 /* Not Support */
241 void SetSeekRSSI(long freq);
242 void SetSeekSNR(long freq);
243 void SetRSSI_th(int threshold);
244 void SetSNR_th(int threshold);
245 void SetCnt_th(int threshold);
246 int GetRSSI_th();
247 int GetSNR_th();
248 int GetCnt_th();
249 void setScanning(bool value);
250
251 ServiceName GetPs();
252 RadioText GetLrText();
253 int ReadRDS();
254 };
255
256 #endif /* __FM_RADIO_CONTROLLER_SLSI_H__ */