text
stringlengths
0
234
function To_Bytes is new Ada.Unchecked_Conversion
(SPAD_Map, SPAD_Map_Bytes);
SPAD_Count : UInt8;
SPAD_Is_Aperture : Boolean;
Ref_SPAD_Map_Bytes : SPAD_Map_Bytes;
Ref_SPAD_Map : SPAD_Map;
First_SPAD : UInt8;
SPADS_Enabled : UInt8;
Timing_Budget : UInt32;
begin
Status := SPAD_Info (This, SPAD_Count, SPAD_Is_Aperture);
if not Status then
return;
end if;
Read
(This, REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,
Ref_SPAD_Map_Bytes, Status);
Ref_SPAD_Map := To_Map (Ref_SPAD_Map_Bytes);
-- Set reference spads
if Status then
Write (This, 16#FF#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, REG_DYNAMIC_SPAD_REF_EN_START_OFFSET,
UInt8'(16#00#), Status);
end if;
if Status then
Write (This, REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD,
UInt8'(16#2C#), Status);
end if;
if Status then
Write (This, 16#FF#, UInt8'(16#00#), Status);
end if;
if Status then
Write (This, REG_GLOBAL_CONFIG_REF_EN_START_SELECT,
UInt8'(16#B4#), Status);
end if;
if Status then
if SPAD_Is_Aperture then
First_SPAD := 13;
else
First_SPAD := 1;
end if;
SPADS_Enabled := 0;
for J in UInt8 range 1 .. 48 loop
if J < First_SPAD or else SPADS_Enabled = SPAD_Count then
-- This bit is lower than the first one that should be enabled,
-- or SPAD_Count bits have already been enabled, so zero this
-- bit
Ref_SPAD_Map (J) := False;
elsif Ref_SPAD_Map (J) then
SPADS_Enabled := SPADS_Enabled + 1;
end if;
end loop;
end if;
if Status then
Ref_SPAD_Map_Bytes := To_Bytes (Ref_SPAD_Map);
Write (This, REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,
Ref_SPAD_Map_Bytes, Status);
end if;
-- Load tuning Settings
-- default tuning settings from vl53l0x_tuning.h
if Status then
Write (This, 16#FF#, UInt8'(16#01#), Status);
Write (This, 16#00#, UInt8'(16#00#), Status);
Write (This, 16#FF#, UInt8'(16#00#), Status);
Write (This, 16#09#, UInt8'(16#00#), Status);
Write (This, 16#10#, UInt8'(16#00#), Status);
Write (This, 16#11#, UInt8'(16#00#), Status);
Write (This, 16#24#, UInt8'(16#01#), Status);
Write (This, 16#25#, UInt8'(16#FF#), Status);
Write (This, 16#75#, UInt8'(16#00#), Status);
Write (This, 16#FF#, UInt8'(16#01#), Status);
Write (This, 16#4E#, UInt8'(16#2C#), Status);
Write (This, 16#48#, UInt8'(16#00#), Status);
Write (This, 16#30#, UInt8'(16#20#), Status);
Write (This, 16#FF#, UInt8'(16#00#), Status);
Write (This, 16#30#, UInt8'(16#09#), Status);
Write (This, 16#54#, UInt8'(16#00#), Status);
Write (This, 16#31#, UInt8'(16#04#), Status);
Write (This, 16#32#, UInt8'(16#03#), Status);
Write (This, 16#40#, UInt8'(16#83#), Status);
Write (This, 16#46#, UInt8'(16#25#), Status);
Write (This, 16#60#, UInt8'(16#00#), Status);