forked from rdkcentral/rdkvhal-devicesettings-raspberrypi4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdsDisplay.c
More file actions
807 lines (752 loc) · 30 KB
/
Copy pathdsDisplay.c
File metadata and controls
807 lines (752 loc) · 30 KB
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2017 RDK Management
*
* 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 <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include "dsTypes.h"
#include "dsDisplay.h"
#include "dsUtl.h"
#include "dsError.h"
#include "dsVideoResolutionSettings.h"
#include "dshalLogger.h"
#include "dshalUtils.h"
#include "halif-versions.h"
#define MAX_HDMI_CODE_ID (127)
dsDisplayEventCallback_t _halcallback = NULL;
dsVideoPortResolution_t *HdmiSupportedResolution = NULL;
static unsigned int numSupportedResn = 0;
static bool _bDisplayInited = false;
static bool isBootup = true;
static dsError_t dsQueryHdmiResolution();
TV_SUPPORTED_MODE_T dsVideoPortgetVideoFormatFromInfo(dsVideoResolution_t res,
unsigned frameRate, bool interlaced);
static dsVideoPortResolution_t *dsgetResolutionInfo(const char *res_name);
typedef struct _VDISPHandle_t {
dsVideoPortType_t m_vType;
int m_index;
int m_nativeHandle;
} VDISPHandle_t;
static VDISPHandle_t _VDispHandles[dsVIDEOPORT_TYPE_MAX][2] = {};
bool dsIsValidVDispHandle(intptr_t m_handle) {
for (int i = 0; i < dsVIDEOPORT_TYPE_MAX; i++) {
//hal_info("Checking if m_handle(%p) is a match - &_VDispHandles[%d][0](%p).\n", m_handle, i, &_VDispHandles[i][0]);
if ((intptr_t)&_VDispHandles[i][0] == m_handle) {
hal_info("m_handle(%p) is a match.\n", m_handle);
return true;
}
}
return false;
}
static void tvservice_callback(void *callback_data, uint32_t reason, uint32_t param1, uint32_t param2)
{
VDISPHandle_t *hdmiHandle = (VDISPHandle_t*)callback_data;
unsigned char eventData = 0;
hal_info("Got handle %p and reason %d, param1 %d, param2 %d\n", hdmiHandle, reason, param1, param2);
switch (reason) {
case VC_HDMI_UNPLUGGED:
hal_dbg("HDMI cable is unplugged\n");
if (NULL != _halcallback) {
_halcallback((int)(hdmiHandle->m_nativeHandle), dsDISPLAY_EVENT_DISCONNECTED, &eventData);
} else {
hal_warn("_halcallback is NULL, dropping event reporting.\n");
}
break;
case VC_HDMI_ATTACHED:
case VC_HDMI_DVI:
case VC_HDMI_HDMI:
hal_dbg("HDMI is attached\n");
if (NULL != _halcallback) {
_halcallback((int)(hdmiHandle->m_nativeHandle), dsDISPLAY_EVENT_CONNECTED, &eventData);
} else {
hal_warn("_halcallback is NULL, dropping event reporting.\n");
}
break;
case VC_HDMI_HDCP_UNAUTH:
case VC_HDMI_HDCP_AUTH:
case VC_HDMI_HDCP_KEY_DOWNLOAD:
case VC_HDMI_HDCP_SRM_DOWNLOAD:
hal_warn("HDCP related events; dropping\n");
break;
default:
if (isBootup == true) {
hal_dbg("For Rpi - HDMI is attached by default\n");
if (NULL != _halcallback) {
_halcallback((int)(hdmiHandle->m_nativeHandle), dsDISPLAY_EVENT_CONNECTED, &eventData);
} else {
hal_warn("_halcallback is NULL, dropping event reporting.\n");
}
isBootup = false;
}
break;
}
}
/**
* @brief Initialize underlying Video display units
*
* This function must initialize all the video display units and associated data structs
*
* @param None
* @return dsError_t Error Code.
*/
dsError_t dsDisplayInit()
{
hal_info("Invoked\n");
if (true == _bDisplayInited) {
return dsERR_ALREADY_INITIALIZED;
}
_VDispHandles[dsVIDEOPORT_TYPE_HDMI][0].m_vType = dsVIDEOPORT_TYPE_HDMI;
_VDispHandles[dsVIDEOPORT_TYPE_HDMI][0].m_nativeHandle = dsVIDEOPORT_TYPE_HDMI;
_VDispHandles[dsVIDEOPORT_TYPE_HDMI][0].m_index = 0;
_VDispHandles[dsVIDEOPORT_TYPE_COMPONENT][0].m_vType = dsVIDEOPORT_TYPE_BB;
_VDispHandles[dsVIDEOPORT_TYPE_COMPONENT][0].m_nativeHandle = dsVIDEOPORT_TYPE_BB;
_VDispHandles[dsVIDEOPORT_TYPE_COMPONENT][0].m_index = 0;
int32_t res = vchi_tv_init();
if (res != 0) {
hal_err("vchi_tv_init failed.\n");
return dsERR_GENERAL;
}
// Register callback for HDMI hotplug
vc_tv_register_callback(&tvservice_callback, &_VDispHandles[dsVIDEOPORT_TYPE_HDMI][0]);
/*Query the HDMI Resolution */
dsQueryHdmiResolution();
_bDisplayInited = true;
return dsERR_NONE;
}
/**
* @brief To get the handle of the video display device
*
* This function is used to get the display handle of a given type
*
* @param [in] index The index of the display device (0, 1, ...)
* @param [out] *handle The handle of video display device
* @return dsError_t Error code.
*/
dsError_t dsGetDisplay(dsVideoPortType_t m_vType, int index, intptr_t *handle)
{
hal_info("Invoked\n");
if (false == _bDisplayInited) {
return dsERR_NOT_INITIALIZED;
}
if (index != 0 || !dsVideoPortType_isValid(m_vType) || NULL == handle) {
hal_err("Invalid params, index %d, m_vType %d, handle %p\n", index, m_vType, handle);
return dsERR_INVALID_PARAM;
}
*handle = (intptr_t)&_VDispHandles[m_vType][index];
return dsERR_NONE;
}
/**
* @brief To get the aspect ration of the video display
*
* This function is used to get the aspect ratio that is set and used currently in
* connected display device.
*
* @param [in] handle Handle for the video display
* @param [out] *aspectRatio The Aspect ration that is used
* @return dsError_t Error code.
*/
dsError_t dsGetDisplayAspectRatio(intptr_t handle, dsVideoAspectRatio_t *aspect)
{
hal_info("Invoked\n");
TV_DISPLAY_STATE_T tvstate;
VDISPHandle_t *vDispHandle = (VDISPHandle_t *)handle;
if (false == _bDisplayInited) {
return dsERR_NOT_INITIALIZED;
}
if (!dsIsValidVDispHandle((intptr_t)vDispHandle) || NULL == aspect) {
hal_err("Invalid params, handle %p, aspect %p\n", vDispHandle, aspect);
return dsERR_INVALID_PARAM;
}
if (vc_tv_get_display_state(&tvstate) == 0) {
if (vDispHandle->m_vType == dsVIDEOPORT_TYPE_HDMI) {
hal_info("PortType:HDMI, aspect ratio is %d\n", tvstate.display.hdmi.aspect_ratio);
switch (tvstate.display.hdmi.aspect_ratio) {
case HDMI_ASPECT_4_3:
*aspect = dsVIDEO_ASPECT_RATIO_4x3;
break;
case HDMI_ASPECT_16_9:
*aspect = dsVIDEO_ASPECT_RATIO_16x9;
break;
default:
*aspect = dsVIDEO_ASPECT_RATIO_4x3;
break;
}
} else if (vDispHandle->m_vType == dsVIDEOPORT_TYPE_BB) {
hal_info("PortType:BB, aspect ratio is %d\n", tvstate.display.sdtv.display_options.aspect);
switch (tvstate.display.sdtv.display_options.aspect) {
case SDTV_ASPECT_4_3:
*aspect = dsVIDEO_ASPECT_RATIO_4x3;
break;
case SDTV_ASPECT_16_9:
*aspect = dsVIDEO_ASPECT_RATIO_16x9;
break;
default:
*aspect = dsVIDEO_ASPECT_RATIO_4x3;
break;
}
}
} else {
hal_err("Error getting current display state\n");
return dsERR_GENERAL;
}
hal_dbg("Aspect ratio is %d\n", *aspect);
return dsERR_NONE;
}
#if RDK_HALIF_DEVICE_SETTINGS_VERSION >= 0x05010000
/**
* @brief Enables/Disables ALLM mode for HDMI output port connected to display.
*
* This function enables or disables the ALLM mode for specified HDMI output port.
*
* @param[in] handle - Handle of the display device returned from dsGetDisplay()
* @param[in] enabled - Flag to enable/disable the ALLM mode for the HDMI output port
* ( @a true to enable, @a false to disable)
* @return dsError_t Error code.
*/
dsError_t dsSetAllmEnabled (intptr_t handle, bool enabled)
{
hal_info("invoked.\n");
VDISPHandle_t *vDispHandle = (VDISPHandle_t *)handle;
if (!dsIsValidVDispHandle((intptr_t)vDispHandle) ) {
hal_err("Invalid params, handle %p \n", vDispHandle );
return dsERR_INVALID_PARAM;
}
/*
* ALLM (Auto Low Latency Mode) is a feature defined in HDMI 2.1.
* It allows a source device to signal a connected display to automatically switch to a low-latency, low-lag mode — often called "Game Mode".
* Raspberry Pi firmware and drivers support basic HDMI 2.0a features (like 4K@60 ) but do not implement ALLM signaling.
*/
hal_info("Allm operations is not supported\n" );
return dsERR_OPERATION_NOT_SUPPORTED;
}
/**
* @brief Checks whether ALLM mode of HDMI output port connected to display is enabled or not.
*
* This function indicates whether ALLM mode for specified HDMI output port is enabled or not.
* By default ALLM mode is disabled on bootup.
*
* @param[in] handle - Handle of the display device returned from dsGetDisplay()
* @param[out] enabled - Flag to hold the enabled status of ALLM mode for given HDMI output port.
* ( @a true when ALLM mode is enabled or @a false otherwise)
*
* @return dsError_t Error code.
*/
dsError_t dsGetAllmEnabled (intptr_t handle, bool *enabled)
{
hal_info("invoked.\n");
VDISPHandle_t *vDispHandle = (VDISPHandle_t *)handle;
if (!dsIsValidVDispHandle((intptr_t)vDispHandle) || NULL == enabled ) {
hal_err("Invalid params, handle %p enabled %p\n", vDispHandle, enabled );
return dsERR_INVALID_PARAM;
}
/*
* ALLM (Auto Low Latency Mode) is a feature defined in HDMI 2.1.
* It allows a source device to signal a connected display to automatically switch to a low-latency, low-lag mode — often called "Game Mode".
* Raspberry Pi firmware and drivers support basic HDMI 2.0a features (like 4K@60 ) but do not implement ALLM signaling.
*/
hal_info("Allm operations is not supported\n" );
return dsERR_OPERATION_NOT_SUPPORTED;
}
/**
* @brief Configures the AVI InfoFrame content type signalling for HDMI output port connected to display.
*
* For source devices, this function configures the AVI InfoFrame ITC, CN1 and CN0 bits.
* AVI InfoFrame set remains until the power mode change or device reboot
*
* @param[in] handle - Handle of the display device from dsGetDisplay()
* @param[in] contentType - The content type (or none) to signal in the AVI InfoFrame. Please refer ::dsAviContentType_t
*
* @return dsError_t Error code.
*/
dsError_t dsSetAVIContentType(intptr_t handle, dsAviContentType_t contentType)
{
hal_info("invoked.\n");
VDISPHandle_t *vDispHandle = (VDISPHandle_t *)handle;
if (!dsIsValidVDispHandle((intptr_t)vDispHandle) ) {
hal_err("Invalid params, handle %p \n", vDispHandle );
return dsERR_INVALID_PARAM;
}
/*
* Raspberry Pi 4 is using the vc4 DRM driver with Firmware KMS (FKMS) backend.
* vc4_fkms_ops refers to the "Firmware KMS" (FKMS) display pipeline used in the vc4 DRM (Direct Rendering Manager) driver on Raspberry Pi devices.
* HDMI AVI InfoFrame fields are not exposed by vc4_fkms_ops or its underlying firmware.
* So, We have defined HAL-level stubs that follow the expected structure and provide compatibility for higher layer.
*/
hal_info("AVI ContentType operations is not supported\n" );
return dsERR_OPERATION_NOT_SUPPORTED;
}
/**
* @brief Gets the configured AVI InfoFrame content type signalling for HDMI output port connected to display.
*
* For source devices, this function gets the configuration of the AVI InfoFrame ITC, CN1 and CN0 bits.
* By default, IT content is dsAVICONTENT_TYPE_NOT_SIGNALLED on bootup and after wakeup/resume.
*
* @param[in] handle - Handle of the display device from dsGetDisplay()
* @param[out] contentType - Pointer that receives the content type configuration set for AVI InfoFrames.
* Please refer ::dsAviContentType_t
*
* @return dsError_t Error code.
*/
dsError_t dsGetAVIContentType(intptr_t handle, dsAviContentType_t* contentType)
{
hal_info("invoked.\n");
VDISPHandle_t *vDispHandle = (VDISPHandle_t *)handle;
if (!dsIsValidVDispHandle((intptr_t)vDispHandle) || NULL == contentType ) {
hal_err("Invalid params, handle %p contentType %p\n", vDispHandle, contentType );
return dsERR_INVALID_PARAM;
}
/*
* Raspberry Pi 4 is using the vc4 DRM driver with Firmware KMS (FKMS) backend.
* vc4_fkms_ops refers to the "Firmware KMS" (FKMS) display pipeline used in the vc4 DRM (Direct Rendering Manager) driver on Raspberry Pi devices.
* HDMI AVI InfoFrame fields are not exposed by vc4_fkms_ops or its underlying firmware.
* So, We have defined HAL-level stubs that follow the expected structure and provide compatibility for higher layer.
*/
hal_info("AVI ContentType operations is not supported\n" );
return dsERR_OPERATION_NOT_SUPPORTED;
}
/**
* @brief Configures the AVI InfoFrame scan information signalling for HDMI output port connected to display.
*
* For source devices, this function configures the AVI InfoFrame S1 and S0 bits.
* Source scan info (on AVI) is set only if Sink scan bit is set (on HF-VSDB) as per HDMI 2.1 Specification
* AVI InfoFrame set remains until the power mode change or device reboot
* This function return dsERR_OPERATION_NOT_SUPPORTED when when Sink doesn't support scan or HDMI disconnected
*
* @param[in] handle - Handle of the display device from dsGetDisplay()
* @param[in] scanInfo - The scan information to signal in the AVI InfoFrame. Please refer ::dsAVIScanInformation_t
*
* @return dsError_t Error code.
*/
dsError_t dsSetAVIScanInformation(intptr_t handle, dsAVIScanInformation_t scanInfo)
{
hal_info("invoked.\n");
VDISPHandle_t *vDispHandle = (VDISPHandle_t *)handle;
if (!dsIsValidVDispHandle((intptr_t)vDispHandle) ) {
hal_err("Invalid params, handle %p \n", vDispHandle );
return dsERR_INVALID_PARAM;
}
/*
* Raspberry Pi 4 is using the vc4 DRM driver with Firmware KMS (FKMS) backend.
* vc4_fkms_ops refers to the "Firmware KMS" (FKMS) display pipeline used in the vc4 DRM (Direct Rendering Manager) driver on Raspberry Pi devices.
* HDMI AVI InfoFrame fields are not exposed by vc4_fkms_ops or its underlying firmware.
* So, We have defined HAL-level stubs that follow the expected structure and provide compatibility for higher layer.
*/
hal_info("AVI Scan Information operations is not supported\n" );
return dsERR_OPERATION_NOT_SUPPORTED;
}
/**
* @brief Gets the configured AVI InfoFrame scan information signalling for HDMI output port connected to display.
*
* For source devices, this function gets the configuration of the AVI InfoFrame S1 and S0 bits.
* By default, scan info is dsAVI_SCAN_TYPE_NO_DATA on bootup and after wakeup/resume.
* For sink devices, this function returns dsERR_OPERATION_NOT_SUPPORTED always.
*
* @param[in] handle - Handle of the display device from dsGetDisplay()
* @param[out] scanInfo - Pointer that receives the scan information configuration set for AVI InfoFrames. Please refer ::dsAVIScanInformation_t
*
*/
dsError_t dsGetAVIScanInformation(intptr_t handle, dsAVIScanInformation_t* scanInfo)
{
hal_info("invoked.\n");
VDISPHandle_t *vDispHandle = (VDISPHandle_t *)handle;
if (!dsIsValidVDispHandle((intptr_t)vDispHandle) || NULL == scanInfo ) {
hal_err("Invalid params, handle %p scanInfo %p\n", vDispHandle, scanInfo );
return dsERR_INVALID_PARAM;
}
/*
* Raspberry Pi 4 is using the vc4 DRM driver with Firmware KMS (FKMS) backend.
* vc4_fkms_ops refers to the "Firmware KMS" (FKMS) display pipeline used in the vc4 DRM (Direct Rendering Manager) driver on Raspberry Pi devices.
* HDMI AVI InfoFrame fields are not exposed by vc4_fkms_ops or its underlying firmware.
* So, We have defined HAL-level stubs that follow the expected structure and provide compatibility for higher layer.
*/
hal_info("AVI Scan Information operations is not supported\n" );
return dsERR_OPERATION_NOT_SUPPORTED;
}
#endif
/**
* @brief Callback registration for display related events.
*
* This function registers a callback for display events corresponding to
* the specified display device handle.
*
* @note Caller should install at most one callback function per handle.
* Multiple listeners are supported at Caller layer and thus not
* required in HAL implementation.
*
* @param[in] handle - Handle of the display device
* @param[in] cb - Display Event callback function. Please refer ::dsDisplayEventCallback_t
*
* @return dsError_t - Status
* @retval dsERR_NONE - Success
* @retval dsERR_NOT_INITIALIZED - Module is not initialised
* @retval dsERR_INVALID_PARAM - Parameter passed to this function is invalid
* @retval dsERR_OPERATION_NOT_SUPPORTED - The attempted operation is not supported
* @retval dsERR_GENERAL - Underlying undefined platform error
*
* @pre dsDisplayInit() and dsGetDisplay() must be called before calling this API
*
* @warning This API is Not thread safe
*
* @see dsDisplayEventCallback_t()
*
*/
dsError_t dsRegisterDisplayEventCallback(intptr_t handle, dsDisplayEventCallback_t cb)
{
hal_info("Invoked\n");
VDISPHandle_t *vDispHandle = (VDISPHandle_t *)handle;
if (false == _bDisplayInited) {
return dsERR_NOT_INITIALIZED;
}
if (NULL == cb || !dsIsValidVDispHandle((intptr_t)vDispHandle)) {
hal_err("Invalid params, cb %p, handle %p\n", cb, vDispHandle);
return dsERR_INVALID_PARAM;
}
/* Register The call Back */
if (NULL != _halcallback) {
hal_warn("Callback already registered; override with new one.\n");
}
_halcallback = cb;
return dsERR_NONE;
}
/**
* @brief Gets the EDID information from the specified display device.
*
* This function gets the EDID information from the HDMI/DVI display corresponding to
* the specified display device handle.
*
* @param[in] handle - Handle of the display device
* @param[out] edid - EDID info of the specified display device. Please refer ::dsDisplayEDID_t
*
* @return dsError_t - Status
* @retval dsERR_NONE - Success
* @retval dsERR_NOT_INITIALIZED - Module is not initialised
* @retval dsERR_INVALID_PARAM - Parameter passed to this function is invalid
* @retval dsERR_OPERATION_NOT_SUPPORTED - The attempted operation is not supported
* @retval dsERR_GENERAL - Underlying undefined platform error
*
* @pre dsDisplayInit() and dsGetDisplay() must be called before calling this API
*
* @warning This API is Not thread safe
*
*/
dsError_t dsGetEDID(intptr_t handle, dsDisplayEDID_t *edid)
{
hal_info("Invoked\n");
VDISPHandle_t *vDispHandle = (VDISPHandle_t *)handle;
if (false == _bDisplayInited) {
return dsERR_NOT_INITIALIZED;
}
if (!dsIsValidVDispHandle((intptr_t)vDispHandle) || NULL == edid) {
hal_err("Invalid params, handle %p, edid %p\n", vDispHandle, edid);
return dsERR_INVALID_PARAM;
}
unsigned char *raw = (unsigned char *)calloc(MAX_EDID_BYTES_LEN, sizeof(unsigned char));
int length = 0;
edid->numOfSupportedResolution = 0;
if (vDispHandle->m_vType == dsVIDEOPORT_TYPE_HDMI) {
if (dsGetEDIDBytes(handle, raw, &length) != dsERR_NONE) {
hal_err("Failed to get EDID bytes\n");
return dsERR_GENERAL;
}
hal_dbg("Raw EDID debug\n");
EDID_t parsed_edid;
parse_edid(raw, &parsed_edid);
print_edid(&parsed_edid);
edid->productCode = parsed_edid.product_code;
edid->serialNumber = parsed_edid.serial_number;
edid->manufactureWeek = parsed_edid.week_of_manufacture;
edid->manufactureYear = parsed_edid.year_of_manufacture;
edid->hdmiDeviceType = true;
edid->isRepeater = false;
edid->physicalAddressA = 0;
edid->physicalAddressB = 0;
edid->physicalAddressC = 0;
edid->physicalAddressD = 0;
strncpy(edid->monitorName, "Unknown", sizeof(edid->monitorName));
edid->monitorName[dsEEDID_MAX_MON_NAME_LENGTH - 1] = '\0';
if (dsQueryHdmiResolution() != dsERR_NONE) {
hal_err("Failed to query HDMI resolution\n");
return dsERR_GENERAL;
}
hal_dbg("numSupportedResn from Table - %d\n", numSupportedResn);
if (numSupportedResn == 0) {
hal_err("No supported resolutions found\n");
return dsERR_GENERAL;
}
for (unsigned int i = 0; i < numSupportedResn; i++) {
memcpy(&edid->suppResolutionList[i], &HdmiSupportedResolution[i], sizeof(dsVideoPortResolution_t));
hal_dbg("Copied resolution %s\n", edid->suppResolutionList[i].name);
}
edid->numOfSupportedResolution = numSupportedResn;
if (NULL != raw) {
free(raw);
}
} else {
hal_err("Handle type %d is not supported(not dsVIDEOPORT_TYPE_HDMI)\n", vDispHandle->m_vType);
return dsERR_OPERATION_NOT_SUPPORTED;
}
return dsERR_NONE;
}
/**
* @brief Terminate the usage of video display module
*
* This function will reset the data structs used within this module and release the video display specific handles
*
* @param None
* @return dsError_t Error code.
*/
dsError_t dsDisplayTerm()
{
hal_info("Invoked\n");
if (false == _bDisplayInited) {
return dsERR_NOT_INITIALIZED;
}
vchi_tv_uninit();
if (HdmiSupportedResolution) {
free(HdmiSupportedResolution);
HdmiSupportedResolution = NULL;
}
_bDisplayInited = false;
return dsERR_NONE;
}
/**
* @brief To get the native handle of the video display device
*
* This function is used to get the display handle of a given type
*
* @param [in] m_vType Type of video display (HDMI, COMPONENT, ...)
* @param [in] index The index of the display device (0, 1, ...)
* @param [out] *handle The handle of video display device
* @return dsError_t Error code.
*/
dsError_t dsDisplaygetNativeHandle(intptr_t handle, int *native)
{
hal_info("Invoked\n");
VDISPHandle_t *vDispHandle = (VDISPHandle_t *)handle;
if (!dsIsValidVDispHandle((intptr_t)vDispHandle) || NULL == native) {
hal_err("Invalid params, handle %p, native %p\n", vDispHandle, native);
return dsERR_INVALID_PARAM;
}
if (vDispHandle->m_vType == dsVIDEOPORT_TYPE_HDMI && vDispHandle->m_index == 0) {
*native = vDispHandle->m_nativeHandle;
return dsERR_NONE;
} else {
hal_warn("Failed to get native handle of type %d\n", vDispHandle->m_vType);
}
return dsERR_GENERAL;
}
/**
* Get The HDMI Resolution List
*
**/
static dsError_t dsQueryHdmiResolution()
{
hal_info("Invoked\n");
static TV_SUPPORTED_MODE_NEW_T modeSupported[MAX_HDMI_CODE_ID];
HDMI_RES_GROUP_T group;
uint32_t mode;
int num_of_modes;
memset(modeSupported, 0, sizeof(modeSupported));
num_of_modes = vc_tv_hdmi_get_supported_modes_new(HDMI_RES_GROUP_CEA, modeSupported,
vcos_countof(modeSupported),
&group,
&mode);
if (num_of_modes < 0) {
hal_err("Failed to get modes vc_tv_hdmi_get_supported_modes_new\n");
return dsERR_GENERAL;
}
if (HdmiSupportedResolution) {
free(HdmiSupportedResolution);
HdmiSupportedResolution = NULL;
}
numSupportedResn = 0;
HdmiSupportedResolution = (dsVideoPortResolution_t *)malloc(sizeof(dsVideoPortResolution_t)*noOfItemsInResolutionMap);
if (HdmiSupportedResolution) {
for (size_t i = 0; i < noOfItemsInResolutionMap; i++) {
for (int j = 0; j < num_of_modes; j++) {
if (modeSupported[j].code == resolutionMap[i].mode) {
dsVideoPortResolution_t *resolution = dsgetResolutionInfo(resolutionMap[i].rdkRes);
memcpy(&HdmiSupportedResolution[numSupportedResn], resolution, sizeof(dsVideoPortResolution_t));
hal_dbg("Supported Resolution '%s'\n", HdmiSupportedResolution[numSupportedResn].name);
numSupportedResn++;
}
}
}
} else {
hal_err("malloc failed\n");
return dsERR_GENERAL;
}
hal_dbg("Total Device supported resolutions on HDMI = %d\n", numSupportedResn);
return dsERR_NONE;
}
static dsVideoPortResolution_t* dsgetResolutionInfo(const char *res_name)
{
hal_info("Invoked\n");
size_t iCount = 0;
iCount = (sizeof(kResolutions) / sizeof(kResolutions[0]));
for (size_t i=0; i < iCount; i++) {
if (!strncmp(res_name, kResolutions[i].name, strlen(res_name))) {
return &kResolutions[i];
}
}
return NULL;
}
TV_SUPPORTED_MODE_T dsVideoPortgetVideoFormatFromInfo(dsVideoResolution_t res, unsigned frameRate, bool interlaced)
{
hal_info("Invoked\n");
TV_SUPPORTED_MODE_T format = {0};
switch (res) {
case dsVIDEO_PIXELRES_720x480:
format.height = 480;
break;
case dsVIDEO_PIXELRES_720x576:
format.height = 576;
break;
case dsVIDEO_PIXELRES_1280x720:
format.height = 720;
break;
case dsVIDEO_PIXELRES_1366x768:
format.height = 768;
break;
case dsVIDEO_PIXELRES_1920x1080:
format.height = 1080;
break;
case dsVIDEO_PIXELRES_3840x2160:
format.height = 2160;
break;
case dsVIDEO_PIXELRES_4096x2160:
format.height = 2160;
break;
case dsVIDEO_PIXELRES_MAX:
default:
break;
}
switch (frameRate) {
case dsVIDEO_FRAMERATE_24:
format.frame_rate = 24;
break;
case dsVIDEO_FRAMERATE_25:
format.frame_rate = 25;
break;
case dsVIDEO_FRAMERATE_30:
format.frame_rate = 30;
break;
case dsVIDEO_FRAMERATE_60:
format.frame_rate = 60;
break;
case dsVIDEO_FRAMERATE_23dot98:
format.frame_rate = 23.98;
break;
case dsVIDEO_FRAMERATE_29dot97:
format.frame_rate = 29.97;
break;
case dsVIDEO_FRAMERATE_50:
format.frame_rate = 50;
break;
case dsVIDEO_FRAMERATE_59dot94:
format.frame_rate = 59.94;
break;
case dsVIDEO_FRAMERATE_MAX:
case dsVIDEO_FRAMERATE_UNKNOWN:
default:
break;
}
if (interlaced) {
format.scan_mode = 1; // Interlaced
} else {
format.scan_mode = 0; // Progressive
}
return format;
}
/**
* @brief Gets the EDID buffer and EDID length of connected display device.
*
* This function is used to get the EDID buffer and EDID size of the connected display corresponding to
* the specified display device handle.
*
* @param[in] handle - Handle of the display device
* @param[out] edid - Pointer to raw EDID buffer
* @param[out] length - length of the EDID buffer data. Min value is 0
*
* @note Caller is responsible for allocating memory for edid( please refer ::MAX_EDID_BYTES_LEN ) and freeing the EDID buffer
*
* @return dsError_t - Status
* @retval dsERR_NONE - Success
* @retval dsERR_INVALID_PARAM - Parameter passed to this function is invalid
* @retval dsERR_NOT_INITIALIZED - Module is not initialised
* @retval dsERR_OPERATION_NOT_SUPPORTED - The attempted operation is not supported
* @retval dsERR_GENERAL - Underlying undefined platform error
*
* @pre dsDisplayInit() and dsGetDisplay() must be called before calling this API
*
* @warning This API is Not thread safe
*
*/
dsError_t dsGetEDIDBytes(intptr_t handle, unsigned char *edid, int *length)
{
hal_info("Invoked\n");
uint8_t buffer[128] = {0};
size_t offset = 0;
int i, extensions = 0;
VDISPHandle_t *vDispHandle = (VDISPHandle_t *)handle;
if (false == _bDisplayInited) {
return dsERR_NOT_INITIALIZED;
}
if (edid == NULL || length == NULL) {
hal_err("invalid params\n");
return dsERR_INVALID_PARAM;
} else if (!dsIsValidVDispHandle((intptr_t)vDispHandle) || vDispHandle != &_VDispHandles[dsVIDEOPORT_TYPE_HDMI][0]) {
hal_err("invalid handle\n");
return dsERR_INVALID_PARAM;
}
*length = 0;
int siz = vc_tv_hdmi_ddc_read(offset, sizeof (buffer), buffer);
if (siz <= 0) {
hal_err("vc_tv_hdmi_ddc_read returned %d.\n", siz);
return dsERR_GENERAL;
}
offset += sizeof( buffer);
extensions = buffer[0x7e]; /* This tells you how many more blocks to read */
memcpy(edid, (unsigned char *)buffer, sizeof(buffer));
/* First block always exist */
for (i = 0; i < extensions; i++, offset += sizeof( buffer)) {
memset(buffer, 0, sizeof(buffer));
siz = vc_tv_hdmi_ddc_read(offset, sizeof(buffer), buffer);
if (siz <= 0) {
hal_err("subsequent vc_tv_hdmi_ddc_read returned %d.\n", siz);
return dsERR_GENERAL;
}
memcpy(edid + offset, buffer, sizeof(buffer));
}
*length = offset;
#if 1 // Print EDID bytes for debugging
FILE *file = fopen("/tmp/.hal-edid-bytes.dat", "wb");
if (file != NULL) {
for (i = 0; i < *length; i++) {
fprintf(file, "%02x", edid[i]);
}
fclose(file);
hal_info("EDID bytes written to /tmp/.hal-edid-bytes.dat\n");
} else {
hal_err("Failed to open /tmp/.hal-edid-bytes.dat\n");
}
#endif
return dsERR_NONE;
}