1 //
2 // Copyright (c) 2010-2023 Antmicro
3 // Copyright (c) 2011-2015 Realtime Embedded
4 //
5 // This file is licensed under the MIT License.
6 // Full license text is available in 'licenses/MIT.txt'.
7 //
8 using System;
9 using Antmicro.Renode.Backends.Display;
10 using Antmicro.Renode.Core;
11 using Antmicro.Renode.Peripherals.Bus;
12 using Antmicro.Renode.Logging;
13 
14 namespace Antmicro.Renode.Peripherals.Video
15 {
16     public class TegraDisplay : AutoRepaintingVideo, IDoubleWordPeripheral, IKnownSize
17     {
TegraDisplay(IMachine machine)18         public TegraDisplay(IMachine machine) : base(machine)
19         {
20             Reconfigure(640, 480, PixelFormat.RGB565);
21             sysbus = machine.GetSystemBus(this);
22             sync = new object();
23         }
24 
25         public long Size
26         {
27             get
28             {
29                 return 0x40000;
30             }
31         }
32 
WriteDoubleWord(long address, uint value)33         public void WriteDoubleWord(long address, uint value)
34         {
35             if(address == 0x1c14) // DC_WIN_SIZE
36             {
37                 int w = (int)(value & 0xFFFF);
38                 int h = (int)((value >> 16) & 0xFFFF);
39                 this.DebugLog("Setting resolution to {0}x{1}", w, h);
40                 Reconfigure(w, h);
41             }
42     	    if(address == 0x1c0c) // DC_WIN_COLOR_DEPTH
43     	    {
44     	    	this.Log(LogLevel.Warning, "Depth ID={0}", value);
45         		lock (sync) {
46         			switch (value)
47                     {
48                     case 3:
49                         Reconfigure(format: PixelFormat.RGB565);
50     					break;
51                     case 12:
52                         Reconfigure(format: PixelFormat.BGRX8888);
53     					break;
54                     case 13:
55                         Reconfigure(format: PixelFormat.RGBX8888);
56     					break;
57                     default:
58                         this.Log(LogLevel.Warning, "Depth ID={0} is not supported (might be YUV)!", value);
59                         Reconfigure(format: PixelFormat.RGB565);
60     					break;
61         			}
62         		}
63     	    }
64             if(address == 0x2000) // DC_WINBUF_START_ADDR
65             {
66                 this.DebugLog("Setting buffer addr to 0x{0:X}", value);
67                 lock (sync) {
68                         bufferAddress = value;
69                 }
70             }
71         }
72 
ReadDoubleWord(long offset)73         public uint ReadDoubleWord(long offset)
74         {
75             return 0x00;
76         }
77 
Reset()78         public override void Reset()
79         {
80             // TODO!
81         }
82 
Repaint()83         protected override void Repaint()
84         {
85             if(bufferAddress == 0xFFFFFFFF)
86             {
87                 return;
88             }
89             lock (sync)
90             {
91                 sysbus.ReadBytes(bufferAddress, buffer.Length, buffer, 0);
92             }
93         }
94 
95         private object sync;
96         private uint bufferAddress = 0xFFFFFFFF;
97         private readonly IBusController sysbus;
98     }
99 }
100 
101