+ LCD example: first command issued, more to go
This commit is contained in:
parent
b31de60f73
commit
256fbfb187
184
examples/lcd/ili9341.ads
Normal file
184
examples/lcd/ili9341.ads
Normal file
|
@ -0,0 +1,184 @@
|
|||
--with Interfaces; use Interfaces;
|
||||
package ILI9341 is
|
||||
|
||||
type Command is (
|
||||
NOP,
|
||||
SWRESET,
|
||||
RDDIDIF,
|
||||
RDDST,
|
||||
RDDPM,
|
||||
RDDMADCTL,
|
||||
RDDCOLMOD,
|
||||
RDDIM,
|
||||
RDDSM,
|
||||
RDDSDR,
|
||||
SLPIN,
|
||||
SLPOUT,
|
||||
PTLON,
|
||||
NORON,
|
||||
DINVOFF,
|
||||
DINVON,
|
||||
GAMSET,
|
||||
DISPOFF,
|
||||
DISPON,
|
||||
CASET,
|
||||
PASET,
|
||||
RAMWR,
|
||||
RGBSET,
|
||||
RAMRD,
|
||||
PTLAR,
|
||||
VSCRDEF,
|
||||
TEOFF,
|
||||
TEON,
|
||||
MADCTL,
|
||||
VSCRSADD,
|
||||
IDMOFF,
|
||||
IDMON,
|
||||
PIXSET,
|
||||
Write_Memory_Continue,
|
||||
Read_Memory_Continue,
|
||||
Set_Tear_Scanline,
|
||||
Get_Scanline,
|
||||
WRDISBV,
|
||||
RDDISBV,
|
||||
WRCTRLD,
|
||||
RDCTRLD,
|
||||
WRCABC,
|
||||
RDCABC,
|
||||
Write_CABC_Min_Brightness,
|
||||
Read_CABC_Min_Brightness,
|
||||
IFMODE ,
|
||||
FRMCTR1,
|
||||
FRMCTR2,
|
||||
FRMCTR3,
|
||||
INVTR,
|
||||
PRCTR,
|
||||
DISCTRL,
|
||||
ETMOD,
|
||||
Backlight_Control_1,
|
||||
Backlight_Control_2,
|
||||
Backlight_Control_3,
|
||||
Backlight_Control_4,
|
||||
Backlight_Control_5,
|
||||
Backlight_Control_7,
|
||||
Backlight_Control_8,
|
||||
PWCTRL1,
|
||||
PWCTRL2,
|
||||
VMCTRL1,
|
||||
VMCTRL2,
|
||||
Undocumented_CA,
|
||||
Power_Control_A,
|
||||
Power_Control_B,
|
||||
NVMWR,
|
||||
NVMPKEY,
|
||||
RDNVM,
|
||||
RDID4,
|
||||
RDID1,
|
||||
RDID2,
|
||||
RDID3,
|
||||
PGAMCTRL,
|
||||
NGAMCTRL,
|
||||
DGAMCTRL1,
|
||||
DGAMCTRL2,
|
||||
Driver_Timing_Control_A,
|
||||
Driver_Timing_Control_A1,
|
||||
Driver_Timing_Control_B,
|
||||
Power_On_Sequence_Control,
|
||||
Undocumented_EF,
|
||||
Enable_3G,
|
||||
IFCTL,
|
||||
Pump_Ratio_Control
|
||||
) with Size => 8;
|
||||
|
||||
for Command use (
|
||||
NOP => 16#00#,
|
||||
SWRESET => 16#01#,
|
||||
RDDIDIF => 16#04#,
|
||||
RDDST => 16#09#,
|
||||
RDDPM => 16#0A#,
|
||||
RDDMADCTL => 16#0B#,
|
||||
RDDCOLMOD => 16#0C#,
|
||||
RDDIM => 16#0D#,
|
||||
RDDSM => 16#0E#,
|
||||
RDDSDR => 16#0F#,
|
||||
SLPIN => 16#10#,
|
||||
SLPOUT => 16#11#,
|
||||
PTLON => 16#12#,
|
||||
NORON => 16#13#,
|
||||
DINVOFF => 16#20#,
|
||||
DINVON => 16#21#,
|
||||
GAMSET => 16#26#,
|
||||
DISPOFF => 16#28#,
|
||||
DISPON => 16#29#,
|
||||
CASET => 16#2A#,
|
||||
PASET => 16#2B#,
|
||||
RAMWR => 16#2C#,
|
||||
RGBSET => 16#2D#,
|
||||
RAMRD => 16#2E#,
|
||||
PTLAR => 16#30#,
|
||||
VSCRDEF => 16#33#,
|
||||
TEOFF => 16#34#,
|
||||
TEON => 16#35#,
|
||||
MADCTL => 16#36#,
|
||||
VSCRSADD => 16#37#,
|
||||
IDMOFF => 16#38#,
|
||||
IDMON => 16#39#,
|
||||
PIXSET => 16#3A#,
|
||||
Write_Memory_Continue => 16#3C#,
|
||||
Read_Memory_Continue => 16#3E#,
|
||||
Set_Tear_Scanline => 16#44#,
|
||||
Get_Scanline => 16#45#,
|
||||
WRDISBV => 16#51#,
|
||||
RDDISBV => 16#52#,
|
||||
WRCTRLD => 16#53#,
|
||||
RDCTRLD => 16#54#,
|
||||
WRCABC => 16#55#,
|
||||
RDCABC => 16#56#,
|
||||
Write_CABC_Min_Brightness => 16#5E#,
|
||||
Read_CABC_Min_Brightness => 16#5F#,
|
||||
IFMODE => 16#B0#,
|
||||
FRMCTR1 => 16#B1#,
|
||||
FRMCTR2 => 16#B2#,
|
||||
FRMCTR3 => 16#B3#,
|
||||
INVTR => 16#B4#,
|
||||
PRCTR => 16#B5#,
|
||||
DISCTRL => 16#B6#,
|
||||
ETMOD => 16#B7#,
|
||||
Backlight_Control_1 => 16#B8#,
|
||||
Backlight_Control_2 => 16#B9#,
|
||||
Backlight_Control_3 => 16#BA#,
|
||||
Backlight_Control_4 => 16#BB#,
|
||||
Backlight_Control_5 => 16#BC#,
|
||||
Backlight_Control_7 => 16#BE#,
|
||||
Backlight_Control_8 => 16#BF#,
|
||||
PWCTRL1 => 16#C0#,
|
||||
PWCTRL2 => 16#C1#,
|
||||
VMCTRL1 => 16#C5#,
|
||||
VMCTRL2 => 16#C7#,
|
||||
Undocumented_CA => 16#CA#,
|
||||
Power_Control_A => 16#CB#,
|
||||
Power_Control_B => 16#CF#,
|
||||
NVMWR => 16#D0#,
|
||||
NVMPKEY => 16#D1#,
|
||||
RDNVM => 16#D2#,
|
||||
RDID4 => 16#D3#,
|
||||
RDID1 => 16#DA#,
|
||||
RDID2 => 16#DB#,
|
||||
RDID3 => 16#DC#,
|
||||
PGAMCTRL => 16#E0#,
|
||||
NGAMCTRL => 16#E1#,
|
||||
DGAMCTRL1 => 16#E2#,
|
||||
DGAMCTRL2 => 16#E3#,
|
||||
Driver_Timing_Control_A => 16#E8#,
|
||||
Driver_Timing_Control_A1 => 16#E9#,
|
||||
Driver_Timing_Control_B => 16#EA#,
|
||||
Power_On_Sequence_Control => 16#ED#,
|
||||
Undocumented_EF => 16#EF#,
|
||||
Enable_3G => 16#F2#,
|
||||
IFCTL => 16#F6#,
|
||||
Pump_Ratio_Control => 16#F7#
|
||||
);
|
||||
-- Note: There are undocumented commands in drivers, see
|
||||
-- https://forums.adafruit.com/viewtopic.php?f=47&t=63229&p=320378&hilit=0xef+ili9341#p320378
|
||||
|
||||
end ILI9341;
|
|
@ -1,12 +1,15 @@
|
|||
with Interfaces;
|
||||
with Ada.Real_Time; use Ada.Real_Time;
|
||||
with Ada.Unchecked_Conversion;
|
||||
with Chip.Units; use Chip.Units;
|
||||
with Board.UART; use Board;
|
||||
with ILI9341;
|
||||
|
||||
with STM32.RCC; use STM32.RCC;
|
||||
with STM32.SPI;
|
||||
with STM32.GPIO.Ports; use STM32.GPIO.Ports;
|
||||
|
||||
|
||||
procedure LCD is
|
||||
package LED is new GPIO_Port_Boolean(LED_Port, LED_Bit);
|
||||
|
||||
|
@ -14,12 +17,14 @@ procedure LCD is
|
|||
|
||||
|
||||
package CSX is new GPIO_Port_Boolean (LCD_CSX_Port, LCD_CSX_Bit);
|
||||
package DCX is new GPIO_Port_Boolean (LCD_CSX_Port, LCD_CSX_Bit);
|
||||
package DCX is new GPIO_Port_Boolean (LCD_DCX_Port, LCD_DCX_Bit);
|
||||
package SCL is new GPIO_Port_Boolean (LCD_SCL_Port, LCD_SCL_Bit);
|
||||
package SDA is new GPIO_Port_Boolean (LCD_SDA_Port, LCD_SDA_Bit);
|
||||
|
||||
procedure SPI_Transmit (Data : Integer) is
|
||||
procedure SPI_Transmit (Data : Interfaces.Unsigned_16) is
|
||||
pragma Warnings (Off, "variable ""X"" is assigned but never read");
|
||||
X: Interfaces.Unsigned_16;
|
||||
pragma Warnings (On, "variable ""X"" is assigned but never read");
|
||||
begin
|
||||
--LED.Set(LED_On);
|
||||
|
||||
|
@ -27,9 +32,9 @@ procedure LCD is
|
|||
null;
|
||||
end loop;
|
||||
|
||||
LED_2.Set(LED_2_On);
|
||||
LED_2.Set (LED_2_On);
|
||||
|
||||
LCD_SPI_Module.DR := Interfaces.Unsigned_16 (Data);
|
||||
LCD_SPI_Module.DR := Data;
|
||||
|
||||
if LCD_SPI_Module.SR.BSY then
|
||||
null;
|
||||
|
@ -40,7 +45,7 @@ procedure LCD is
|
|||
end loop;
|
||||
|
||||
--LED.Set(not LED_On);
|
||||
LED_2.Set(not LED_2_On);
|
||||
LED_2.Set (not LED_2_On);
|
||||
|
||||
if LCD_SPI_Module.SR.RXNE then
|
||||
X := LCD_SPI_Module.DR;
|
||||
|
@ -49,6 +54,19 @@ procedure LCD is
|
|||
|
||||
end;
|
||||
|
||||
procedure LCD_Command (Command : ILI9341.Command) is
|
||||
function To_Unsigned_8 is new Ada.Unchecked_Conversion (ILI9341.Command, Interfaces.Unsigned_8);
|
||||
begin
|
||||
DCX.Set(False);
|
||||
SPI_Transmit (Interfaces.Unsigned_16 (To_Unsigned_8 (Command)));
|
||||
end;
|
||||
|
||||
procedure LCD_Data (Data : Interfaces.Unsigned_8) is
|
||||
begin
|
||||
DCX.Set (True);
|
||||
SPI_Transmit(Interfaces.Unsigned_16 (Data));
|
||||
end;
|
||||
|
||||
Period: constant Time_Span := Milliseconds(500);
|
||||
Now: Time := Clock;
|
||||
|
||||
|
@ -60,7 +78,7 @@ begin
|
|||
RCC.APB2RSTR (Index.SPI5) := True;
|
||||
RCC.APB2RSTR (Index.SPI5) := False;
|
||||
|
||||
UART.Transmit(Boolean'Image(LCD_SPI_Module.CR1.SPE) & ASCII.CR & ASCII.LF);
|
||||
UART.Transmit (Boolean'Image (LCD_SPI_Module.CR1.SPE) & ASCII.CR & ASCII.LF);
|
||||
|
||||
declare
|
||||
R : STM32.SPI.Control_Register_1 := LCD_SPI_Module.CR1;
|
||||
|
@ -125,7 +143,7 @@ begin
|
|||
LED.Set_OSPEEDR (STM32.GPIO.Very_High_Speed);
|
||||
LED.Set_PUPDR (STM32.GPIO.No_Pull);
|
||||
|
||||
LED.Set(not LED_On);
|
||||
LED.Set (not LED_On);
|
||||
|
||||
LED_2_RCC_EN := True;
|
||||
|
||||
|
@ -134,10 +152,10 @@ begin
|
|||
LED_2.Set_OSPEEDR (STM32.GPIO.Very_High_Speed);
|
||||
LED_2.Set_PUPDR (STM32.GPIO.No_Pull);
|
||||
|
||||
LED_2.Set(not LED_2_On);
|
||||
LED_2.Set (not LED_2_On);
|
||||
|
||||
UART.Transmit(Boolean'Image(LCD_SPI_Module.CR1.SPE) & ASCII.CR & ASCII.LF);
|
||||
UART.Transmit(STM32.GPIO.Alternate_Function'Image(LCD_SCL_Port.AFR(LCD_SCL_Bit)) & ASCII.CR & ASCII.LF);
|
||||
UART.Transmit (Boolean'Image (LCD_SPI_Module.CR1.SPE) & ASCII.CR & ASCII.LF);
|
||||
UART.Transmit (STM32.GPIO.Alternate_Function'Image (LCD_SCL_Port.AFR (LCD_SCL_Bit)) & ASCII.CR & ASCII.LF);
|
||||
|
||||
-- Trying to transmit
|
||||
|
||||
|
@ -154,19 +172,30 @@ begin
|
|||
--UART.Transmit("RXNE " & Boolean'Image(LCD_SPI_Module.SR.RXNE) & ASCII.CR & ASCII.LF);
|
||||
|
||||
|
||||
LED.Set(LED_On);
|
||||
SPI_Transmit (2#01010011#);
|
||||
--LED.Set (LED_On);
|
||||
--SPI_Transmit (2#01010011#);
|
||||
|
||||
CSX.Set (False);
|
||||
|
||||
LCD_Command (ILI9341.Undocumented_CA);
|
||||
LCD_Data (16#C3#);
|
||||
LCD_Data (16#08#);
|
||||
LCD_Data (16#50#);
|
||||
|
||||
CSX.Set (True);
|
||||
|
||||
|
||||
Now := Now + Period;
|
||||
delay until Now;
|
||||
|
||||
LED.Set(not LED_On);
|
||||
SPI_Transmit (2#10101100#);
|
||||
--LED.Set (not LED_On);
|
||||
--SPI_Transmit (2#10101100#);
|
||||
|
||||
Now := Now + Period;
|
||||
delay until Now;
|
||||
--Now := Now + Period;
|
||||
--delay until Now;
|
||||
|
||||
|
||||
end loop;
|
||||
|
||||
|
||||
end LCD;
|
Loading…
Reference in a new issue