11-- ----------------------------------------------------------------------------
22-- --
3- -- Copyright (C) 2015-2023 , AdaCore --
3+ -- Copyright (C) 2015-2024 , AdaCore --
44-- --
55-- Redistribution and use in source and binary forms, with or without --
66-- modification, are permitted provided that the following conditions are --
2929-- --
3030-- ----------------------------------------------------------------------------
3131
32+ with Bitmap_Color_Conversion ;
33+
34+ with ILI9341.Regs ;
35+
3236package body ILI9341.SPI_Connector is
3337
38+ -- ---------------
39+ -- Read_Pixels --
40+ -- ---------------
41+
42+ procedure Read_Pixels
43+ (This : ILI9341_Connector;
44+ Cmd : HAL.UInt8;
45+ Address : System.Address;
46+ Count : Positive)
47+ is
48+ use all type HAL.SPI.SPI_Status;
49+
50+ subtype Raw_Buffer is HAL.SPI.SPI_Data_8b (1 .. 3 * Count);
51+
52+ Raw_Pixels : Raw_Buffer
53+ with Import, Address => Address;
54+
55+ Status : HAL.SPI.SPI_Status;
56+ begin
57+ This.WRX.Clear;
58+ This.Chip_Select.Clear;
59+ This.Port.Transmit (HAL.SPI.SPI_Data_8b'(1 => Cmd), Status);
60+
61+ if Status /= Ok then
62+ raise Program_Error;
63+ end if ;
64+
65+ This.WRX.Set;
66+ This.Port.Receive (Raw_Pixels, Status);
67+
68+ This.Chip_Select.Set;
69+ end Read_Pixels ;
70+
3471 -- ----------------
3572 -- Send_Command --
3673 -- ----------------
@@ -41,6 +78,7 @@ package body ILI9341.SPI_Connector is
4178 Data : HAL.UInt8_Array)
4279 is
4380 use HAL.SPI;
81+
4482 Status : SPI_Status;
4583 begin
4684 This.WRX.Clear;
@@ -60,7 +98,126 @@ package body ILI9341.SPI_Connector is
6098 end if ;
6199 end if ;
62100
63- This.Chip_Select.Set;
101+ if Cmd not in ILI9341.Regs.ILI9341_GRAM then
102+ This.Chip_Select.Set;
103+ end if ;
64104 end Send_Command ;
65105
106+ -- ----------------
107+ -- Write_Pixels --
108+ -- ----------------
109+
110+ procedure Write_Pixels
111+ (This : ILI9341_Connector;
112+ Mode : HAL.Bitmap.Bitmap_Color_Mode;
113+ Address : System.Address;
114+ Count : Positive;
115+ Repeat : Positive)
116+ is
117+
118+ procedure Transmit (Color : HAL.Bitmap.Bitmap_Color);
119+ -- Transmit RGB on a single pixel
120+
121+ -- ------------
122+ -- Transmit --
123+ -- ------------
124+
125+ procedure Transmit (Color : HAL.Bitmap.Bitmap_Color) is
126+ Status : HAL.SPI.SPI_Status;
127+
128+ Pixel : HAL.SPI.SPI_Data_8b (1 .. 4 )
129+ with Import, Address => Color'Address;
130+ begin
131+ This.Port.Transmit (Pixel (1 .. 3 ), Status);
132+ end Transmit ;
133+
134+ begin
135+ This.WRX.Set;
136+
137+ case Mode is
138+ when HAL.Bitmap.RGB_888 =>
139+ -- Native format for SPI interface
140+ declare
141+ subtype Raw_Buffer is HAL.SPI.SPI_Data_8b (1 .. 3 * Count);
142+
143+ Raw_Pixels : Raw_Buffer
144+ with Import, Address => Address;
145+
146+ Status : HAL.SPI.SPI_Status;
147+ begin
148+ for Step in 1 .. Repeat loop
149+ This.Port.Transmit (Raw_Pixels, Status);
150+ end loop ;
151+ end ;
152+
153+ when HAL.Bitmap.ARGB_8888 =>
154+ declare
155+ subtype Raw_Buffer is HAL.UInt32_Array (1 .. Count);
156+
157+ Raw_Pixels : Raw_Buffer
158+ with Import, Address => Address;
159+ begin
160+ for Step in 1 .. Repeat loop
161+ for Raw of Raw_Pixels loop
162+ declare
163+ Color : constant HAL.Bitmap.Bitmap_Color :=
164+ Bitmap_Color_Conversion.Word_To_Bitmap_Color
165+ (Mode, Raw);
166+ begin
167+ Transmit (Color);
168+ end ;
169+ end loop ;
170+ end loop ;
171+ end ;
172+
173+ when HAL.Bitmap.RGB_565 |
174+ HAL.Bitmap.ARGB_1555 |
175+ HAL.Bitmap.ARGB_4444 |
176+ HAL.Bitmap.AL_88 =>
177+ declare
178+ subtype Raw_Buffer is HAL.UInt16_Array (1 .. Count);
179+
180+ Raw_Pixels : Raw_Buffer
181+ with Import, Address => Address;
182+ begin
183+ for Step in 1 .. Repeat loop
184+ for Raw of Raw_Pixels loop
185+ declare
186+ Color : constant HAL.Bitmap.Bitmap_Color :=
187+ Bitmap_Color_Conversion.Word_To_Bitmap_Color
188+ (Mode, HAL.UInt32 (Raw));
189+ begin
190+ Transmit (Color);
191+ end ;
192+ end loop ;
193+ end loop ;
194+ end ;
195+
196+ when HAL.Bitmap.L_8 | HAL.Bitmap.AL_44 =>
197+ declare
198+ subtype Raw_Buffer is HAL.UInt8_Array (1 .. Count);
199+
200+ Raw_Pixels : Raw_Buffer
201+ with Import, Address => Address;
202+ begin
203+ for Step in 1 .. Repeat loop
204+ for Raw of Raw_Pixels loop
205+ declare
206+ Color : constant HAL.Bitmap.Bitmap_Color :=
207+ Bitmap_Color_Conversion.Word_To_Bitmap_Color
208+ (Mode, HAL.UInt32 (Raw));
209+ begin
210+ Transmit (Color);
211+ end ;
212+ end loop ;
213+ end loop ;
214+ end ;
215+
216+ when others =>
217+ raise Program_Error;
218+ end case ;
219+
220+ This.Chip_Select.Set;
221+ end Write_Pixels ;
222+
66223end ILI9341.SPI_Connector ;
0 commit comments