Gamebit/src/gamebit-lcd.adb

108 lines
3.4 KiB
Ada

with HAL.GPIO;
with MicroBit.IOs;
package body Gamebit.LCD is
procedure Initialize is
begin
-- The SPI controller needs to be initialized before it's used
MicroBit.SPI.Initialize;
-- In order for the display to work, the CS, RS, RST pins need to be set to output
MicroBit.MB_P16.Set_Mode (HAL.GPIO.Output);
MicroBit.MB_P12.Set_Mode (HAL.GPIO.Output);
MicroBit.MB_P8.Set_Mode (HAL.GPIO.Output);
Initialize (Screen);
Screen.Set_Memory_Data_Access (
Color_Order => RGB_Order,
Vertical => Vertical_Refresh_Top_Bottom,
Horizontal => Horizontal_Refresh_Left_Right,
Row_Addr_Order => Row_Address_Bottom_Top,
Column_Addr_Order => Column_Address_Right_Left,
Row_Column_Exchange => False);
Screen.Set_Pixel_Format (Pixel_16bits);
Set_Frame_Rate_Normal (Screen,
RTN => 16#01#,
Front_Porch => 16#2C#,
Back_Porch => 16#2D#);
Set_Frame_Rate_Idle (Screen,
RTN => 16#01#,
Front_Porch => 16#2C#,
Back_Porch => 16#2D#);
Set_Frame_Rate_Partial_Full (Screen,
RTN_Part => 16#01#,
Front_Porch_Part => 16#2C#,
Back_Porch_Part => 16#2D#,
RTN_Full => 16#01#,
Front_Porch_Full => 16#2C#,
Back_Porch_Full => 16#2D#);
Set_Inversion_Control (Screen,
Normal => Line_Inversion,
Idle => Line_Inversion,
Full_Partial => Line_Inversion);
Set_Power_Control_1 (Screen,
AVDD => 2#101#, -- 5
VRHP => 2#0_0010#, -- 4.6
VRHN => 2#0_0010#, -- -4.6
MODE => 2#10#); -- AUTO
Set_Power_Control_2 (Screen,
VGH25 => 2#11#, -- 2.4
VGSEL => 2#01#, -- 3*AVDD
VGHBT => 2#01#); -- -10
Set_Power_Control_3 (Screen, 16#0A#, 16#00#);
Set_Power_Control_4 (Screen, 16#8A#, 16#2A#);
Set_Power_Control_5 (Screen, 16#8A#, 16#EE#);
Set_Vcom (Screen, 16#E#);
Set_Address (Screen,
X_Start => 0,
X_End => 127,
Y_Start => 0,
Y_End => 159);
Turn_On (Screen);
Initialize_Layer (
Display => Screen,
Layer => 1,
Mode => HAL.Bitmap.RGB_565,
X => 0,
Y => 0,
Width => Width,
Height => Height);
Initialized := True;
end Initialize;
procedure On is
begin
MicroBit.IOs.Set (1, True);
end On;
procedure Off is
begin
MicroBit.IOs.Set (1, False);
end Off;
function Framebuffer return HAL.Bitmap.Any_Bitmap_Buffer is
begin
return Screen.Hidden_Buffer (1);
end Framebuffer;
procedure Update is
begin
Screen.Update_Layers;
end Update;
end Gamebit.LCD;