text stringlengths 0 234 |
|---|
-- When the pin is high (set), the device is in I2C mode. |
-- We want SPI mode communication, so Enabled, when True, |
-- means we must drive the pin low. |
begin |
if Enabled then |
This.CS.Clear; |
else |
This.CS.Set; |
end if; |
end SPI_Mode; |
----------- |
-- Write -- |
----------- |
procedure Write (This : Three_Axis_Gyroscope; Addr : Register; Data : UInt8) |
is |
Status : SPI_Status; |
begin |
SPI_Mode (This, Enabled => True); |
This.Port.Transmit (SPI_Data_8b'(1 => UInt8 (Addr)), Status); |
if Status /= Ok then |
raise Program_Error; |
end if; |
This.Port.Transmit (SPI_Data_8b'(1 => Data), Status); |
if Status /= Ok then |
raise Program_Error; |
end if; |
SPI_Mode (This, Enabled => False); |
end Write; |
---------- |
-- Read -- |
---------- |
procedure Read |
(This : Three_Axis_Gyroscope; |
Addr : Register; |
Data : out UInt8) |
is |
Status : SPI_Status; |
Tmp_Data : SPI_Data_8b (1 .. 1); |
begin |
SPI_Mode (This, Enabled => True); |
This.Port.Transmit (SPI_Data_8b'(1 => UInt8 (Addr) or ReadWrite_CMD), |
Status); |
if Status /= Ok then |
raise Program_Error; |
end if; |
This.Port.Receive (Tmp_Data, Status); |
if Status /= Ok then |
raise Program_Error; |
end if; |
Data := Tmp_Data (Tmp_Data'First); |
SPI_Mode (This, Enabled => False); |
end Read; |
---------------- |
-- Read_UInt8s -- |
---------------- |
procedure Read_UInt8s |
(This : Three_Axis_Gyroscope; |
Addr : Register; |
Buffer : out SPI_Data_8b; |
Count : Natural) |
is |
Index : Natural := Buffer'First; |
Status : SPI_Status; |
Tmp_Data : SPI_Data_8b (1 .. 1); |
begin |
SPI_Mode (This, Enabled => True); |
This.Port.Transmit |
(SPI_Data_8b'(1 => UInt8 (Addr) or ReadWrite_CMD or MultiUInt8_CMD), |
Status); |
if Status /= Ok then |
raise Program_Error; |
end if; |
for K in 1 .. Count loop |
This.Port.Receive (Tmp_Data, Status); |
if Status /= Ok then |
raise Program_Error; |
end if; |
Buffer (Index) := Tmp_Data (Tmp_Data'First); |
Index := Index + 1; |
end loop; |
SPI_Mode (This, Enabled => False); |
end Read_UInt8s; |
--------------- |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.