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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
/*
* Copyright (C) 2014-2020 NXP Semiconductors, All Rights Reserved.
* Copyright 2020 GOODIX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
/*
* tfaContainer.h
*
* Created on: Sep 11, 2013
* Author: wim
*/
#ifndef TFACONTAINER_H_
#define TFACONTAINER_H_
/* static limits */
#define TFACONT_MAXDEVS (4) /* maximum nr of devices */
#define TFACONT_MAXPROFS (16) /* maximum nr of profiles */
#include "tfa98xx_parameters.h"
/**
* Pass the container buffer, initialize and allocate internal memory.
*
* @param cnt pointer to the start of the buffer holding the container file
* @param length of the data in bytes
* @return
* - tfa_error_ok if normal
* - tfa_error_container invalid container data
* - tfa_error_bad_param invalid parameter
*
*/
enum tfa_error tfa_load_cnt(void *cnt, int length);
/**
* Return the descriptor string
* @param cnt pointer to the container struct
* @param dsc pointer to Tfa descriptor
* @return descriptor string
*/
char *tfaContGetString(TfaContainer_t *cnt, TfaDescPtr_t *dsc);
/**
* Gets the string for the given command type number
* @param type number representing a command
* @return string of a command
*/
char *tfaContGetCommandString(uint32_t type);
/**
* get the device type from the patch in this devicelist
* - find the patch file for this devidx
* - return the devid from the patch or 0 if not found
* @param cnt pointer to container file
* @param dev_idx device index
* @return descriptor string
*/
int tfa_cnt_get_devid(TfaContainer_t *cnt, int dev_idx);
/**
* Get the slave for the device if it exists.
* @param tfa the device struct pointer
* @param slave_addr the index of the device
* @return Tfa98xx_Error
*/
enum Tfa98xx_Error tfaContGetSlave(struct tfa_device *tfa, uint8_t *slave_addr);
void tfaContSetSlave(uint8_t slave_addr);
/**
* Get the index for a skave address.
* @param tfa the device struct pointer
* @return the device index
*/
int tfa_cont_get_idx(struct tfa_device *tfa);
/**
* Write reg and bitfield items in the devicelist to the target.
* @param tfa the device struct pointer
* @return Tfa98xx_Error
*/
enum Tfa98xx_Error tfaContWriteRegsDev(struct tfa_device *tfa);
/**
* Write reg and bitfield items in the profilelist to the target.
* @param tfa the device struct pointer
* @param prof_idx the profile index
* @return Tfa98xx_Error
*/
enum Tfa98xx_Error tfaContWriteRegsProf(struct tfa_device *tfa, int prof_idx);
/**
* Write a patchfile in the devicelist to the target.
* @param tfa the device struct pointer
* @return Tfa98xx_Error
*/
enum Tfa98xx_Error tfaContWritePatch(struct tfa_device *tfa);
/**
* Write all param files in the devicelist to the target.
* @param tfa the device struct pointer
* @return Tfa98xx_Error
*/
enum Tfa98xx_Error tfaContWriteFiles(struct tfa_device *tfa);
/**
* Get sample rate from passed profile index
* @param tfa the device struct pointer
* @param prof_idx the index of the profile
* @return sample rate value
*/
unsigned int tfa98xx_get_profile_sr(struct tfa_device *tfa, unsigned int prof_idx);
/**
* Get the device name string
* @param cnt the pointer to the container struct
* @param dev_idx the index of the device
* @return device name string or error string if not found
*/
char *tfaContDeviceName(TfaContainer_t *cnt, int dev_idx);
/**
* Get the application name from the container file application field
* @param tfa the device struct pointer
* @param name the input stringbuffer with size: sizeof(application field)+1
* @return actual string length
*/
int tfa_cnt_get_app_name(struct tfa_device *tfa, char *name);
/**
* Get profile index of the calibration profile
* @param tfa the device struct pointer
* @return profile index, -2 if no calibration profile is found or -1 on error
*/
int tfaContGetCalProfile(struct tfa_device *tfa);
/**
* Is the profile a tap profile ?
* @param tfa the device struct pointer
* @param prof_idx the index of the profile
* @return 1 if the profile is a tap profile or 0 if not
*/
int tfaContIsTapProfile(struct tfa_device *tfa, int prof_idx);
/**
* Get the name of the profile at certain index for a device in the container file
* @param cnt the pointer to the container struct
* @param dev_idx the index of the device
* @param prof_idx the index of the profile
* @return profile name string or error string if not found
*/
char *tfaContProfileName(TfaContainer_t *cnt, int dev_idx, int prof_idx);
/**
* Process all items in the profilelist
* NOTE an error return during processing will leave the device muted
* @param tfa the device struct pointer
* @param prof_idx index of the profile
* @param vstep_idx index of the vstep
* @return Tfa98xx_Error
*/
enum Tfa98xx_Error tfaContWriteProfile(struct tfa_device *tfa, int prof_idx, int vstep_idx);
/**
* Specify the speaker configurations (cmd id) (Left, right, both, none)
* @param dev_idx index of the device
* @param configuration name string of the configuration
*/
void tfa98xx_set_spkr_select(int dev_idx, char *configuration);
enum Tfa98xx_Error tfa_cont_write_filterbank(struct tfa_device *tfa, TfaFilter_t *filter);
/**
* Write all param files in the profilelist to the target
* this is used during startup when maybe ACS is set
* @param tfa the device struct pointer
* @param prof_idx the index of the profile
* @param vstep_idx the index of the vstep
* @return Tfa98xx_Error
*/
enum Tfa98xx_Error tfaContWriteFilesProf(struct tfa_device *tfa, int prof_idx, int vstep_idx);
enum Tfa98xx_Error tfaContWriteFilesVstep(struct tfa_device *tfa, int prof_idx, int vstep_idx);
enum Tfa98xx_Error tfaContWriteDrcFile(struct tfa_device *tfa, int size, uint8_t data[]);
/**
* Get the device list dsc from the tfaContainer
* @param cont pointer to the tfaContainer
* @param dev_idx the index of the device
* @return device list pointer
*/
TfaDeviceList_t *tfaContGetDevList(TfaContainer_t *cont, int dev_idx);
/**
* Get the Nth profile for the Nth device
* @param cont pointer to the tfaContainer
* @param dev_idx the index of the device
* @param prof_idx the index of the profile
* @return profile list pointer
*/
TfaProfileList_t *tfaContGetDevProfList(TfaContainer_t *cont, int dev_idx, int prof_idx);
/**
* Get the number of profiles for device from contaienr
* @param cont pointer to the tfaContainer
* @param dev_idx the index of the device
* @return device list pointer
*/
int tfa_cnt_get_dev_nprof(struct tfa_device *tfa);
/**
* Get the Nth livedata for the Nth device
* @param cont pointer to the tfaContainer
* @param dev_idx the index of the device
* @param livedata_idx the index of the livedata
* @return livedata list pointer
*/
TfaLiveDataList_t *tfaContGetDevLiveDataList(TfaContainer_t *cont, int dev_idx, int livedata_idx);
/**
* Check CRC for container
* @param cont pointer to the tfaContainer
* @return error value 0 on error
*/
int tfaContCrcCheckContainer(TfaContainer_t *cont);
/**
* Get the device list pointer
* @param cnt pointer to the container struct
* @param dev_idx the index of the device
* @return pointer to device list
*/
TfaDeviceList_t *tfaContDevice(TfaContainer_t *cnt, int dev_idx);
/**
* Return the pointer to the first profile in a list from the tfaContainer
* @param cont pointer to the tfaContainer
* @return pointer to first profile in profile list
*/
TfaProfileList_t *tfaContGet1stProfList(TfaContainer_t *cont);
/**
* Return the pointer to the next profile in a list
* @param prof is the pointer to the profile list
* @return profile list pointer
*/
TfaProfileList_t *tfaContNextProfile(TfaProfileList_t *prof);
/**
* Return the pointer to the first livedata in a list from the tfaContainer
* @param cont pointer to the tfaContainer
* @return pointer to first livedata in profile list
*/
TfaLiveDataList_t *tfaContGet1stLiveDataList(TfaContainer_t *cont);
/**
* Return the pointer to the next livedata in a list
* @param livedata_idx is the pointer to the livedata list
* @return livedata list pointer
*/
TfaLiveDataList_t *tfaContNextLiveData(TfaLiveDataList_t *livedata_idx);
/**
* Write a bit field
* @param tfa the device struct pointer
* @param bf bitfield to write
* @return Tfa98xx_Error
*/
enum Tfa98xx_Error tfaRunWriteBitfield(struct tfa_device *tfa, TfaBitfield_t bf);
/**
* Write a parameter file to the device
* @param tfa the device struct pointer
* @param file filedescriptor pointer
* @param vstep_idx index to vstep
* @param vstep_msg_idx index to vstep message
* @return Tfa98xx_Error
*/
enum Tfa98xx_Error tfaContWriteFile(struct tfa_device *tfa, TfaFileDsc_t *file, int vstep_idx, int vstep_msg_idx);
/**
* Get the max volume step associated with Nth profile for the Nth device
* @param tfa the device struct pointer
* @param prof_idx profile index
* @return the number of vsteps
*/
int tfacont_get_max_vstep(struct tfa_device *tfa, int prof_idx);
/**
* Get the file contents associated with the device or profile
* Search within the device tree, if not found, search within the profile
* tree. There can only be one type of file within profile or device.
* @param tfa the device struct pointer
* @param prof_idx I2C profile index in the device
* @param type file type
* @return 0 NULL if file type is not found
* @return 1 file contents
*/
TfaFileDsc_t *tfacont_getfiledata(struct tfa_device *tfa, int prof_idx, enum TfaHeaderType type);
/**
* Dump the contents of the file header
* @param hdr pointer to file header data
*/
void tfaContShowHeader(TfaHeader_t *hdr);
/**
* Read a bit field
* @param tfa the device struct pointer
* @param bf bitfield to read out
* @return Tfa98xx_Error
*/
enum Tfa98xx_Error tfaRunReadBitfield(struct tfa_device *tfa, TfaBitfield_t *bf);
/**
* Get hw feature bits from container file
* @param tfa the device struct pointer
* @param hw_feature_register pointer to where hw features are stored
*/
void get_hw_features_from_cnt(struct tfa_device *tfa, int *hw_feature_register);
/**
* Get sw feature bits from container file
* @param tfa the device struct pointer
* @param sw_feature_register pointer to where sw features are stored
*/
void get_sw_features_from_cnt(struct tfa_device *tfa, int sw_feature_register[2]);
/**
* Factory trimming for the Boost converter
* check if there is a correction needed
* @param tfa the device struct pointer
*/
enum Tfa98xx_Error tfa98xx_factory_trimmer(struct tfa_device *tfa);
/**
* Search for filters settings and if found then write them to the device
* @param tfa the device struct pointer
* @param prof_idx profile to look in
* @return Tfa98xx_Error
*/
enum Tfa98xx_Error tfa_set_filters(struct tfa_device *tfa, int prof_idx);
/**
* Get the firmware version from the patch in the container file
* @param tfa the device struct pointer
* @return firmware version
*/
int tfa_cnt_get_patch_version(struct tfa_device *tfa);
int tfa_tib_dsp_msgmulti(struct tfa_device *tfa, int length, const char *buffer);
#endif /* TFACONTAINER_H_ */
|