RP.I2C

Entities

Simple Types

Record Types

Tagged Types

Subtypes

Constants

Subprograms

Description

Abort_Write

procedure Abort_Write
   (This : in out I2C_Port)
Parameters
This

Clear_Error

procedure Clear_Error
   (This : in out I2C_Port)
Parameters
This

Configure

procedure Configure
   (This   : in out I2C_Port;
    Config : I2C_Config)
Parameters
This
Config

Disable

procedure Disable
   (This     : in out I2C_Port;
    Deadline : RP.Timer.Time := RP.Timer.Time'Last)
Parameters
This
Deadline

Enable

procedure Enable
   (This     : in out I2C_Port;
    Deadline : RP.Timer.Time := RP.Timer.Time'Last)
Parameters
This
Deadline

Enabled

function Enabled
   (This : I2C_Port)
   return Boolean
Parameters
This
Return Value

Fast_Mode

Fast_Mode      : constant I2C_Timing :=
   (High   => 1_160,
    Low    => 1_330,
    Hold   => 800,
    Spike  => 50,
    others => <>);

Fast_Mode_Plus

Fast_Mode_Plus : constant I2C_Timing :=
   (High   => 400,
    Low    => 600,
    Hold   => 200,
    Spike  => 50,
    others => <>);

I2C_Abort_Source

type I2C_Abort_Source is record
   No_Ack_Addr_7b          : Boolean := False;
   No_Ack_Addr_10b_1       : Boolean := False;
   No_Ack_Addr_10b_2       : Boolean := False;
   No_Ack_Transmit         : Boolean := False;
   No_Ack_General_Call     : Boolean := False;
   Invalid_General_Call    : Boolean := False;
   Invalid_Ack_High_Speed  : Boolean := False;
   Invalid_Ack_Start       : Boolean := False;
   No_Restart_High_Speed   : Boolean := False;
   No_Restart_Start        : Boolean := False;
   No_Restart_10b_Read     : Boolean := False;
   Not_Controller_Mode     : Boolean := False;
   Arbitration_Lost        : Boolean := False;
   Target_Transmit_Abort   : Boolean := False;
   Target_Arbitration_Lost : Boolean := False;
   Invalid_Target_Read     : Boolean := False;
   Transfer_Aborted        : Boolean := False;
   Transmit_Flush_Count    : HAL.UInt9 := 0;
end record
   with Size => 32;
Record fields
No_Ack_Addr_7b

7 bit address unacknowledged

No_Ack_Addr_10b_1

10 bit address unacknowledged (first byte)

No_Ack_Addr_10b_2

10 bit address unacknowledged (second byte)

No_Ack_Transmit

Upon controller transmit, the address was acknowledged, but a data byte was not.

No_Ack_General_Call

No target acknowledged a general call

Invalid_General_Call

General call command with read bit set

Invalid_Ack_High_Speed

High speed mode was selected, but an ack was received before the end of the transfer.

Invalid_Ack_Start

A start byte was acknowledged, but only data should be acknowledged.

No_Restart_High_Speed

High speed mode was selected but restart is not enabled

No_Restart_Start

Attempting to send a start byte but restart is not enabled

No_Restart_10b_Read

10 bit read attempted but restart is not enabled

Not_Controller_Mode

A controller operation was attempted while in target mode

Arbitration_Lost

Something pulled SDA low before being addressed by the controller

Target_Transmit_Abort

A target read command was issued while there was still data in the transmit FIFO, transmit aborted.

Target_Arbitration_Lost

Something pulled SDA to the wrong state while transmitting in target mode

Invalid_Target_Read

The read bit was set in the CMD register during a target transmit

Transfer_Aborted

User aborted a transfer in controller mode

Transmit_Flush_Count

I2C_Config

type I2C_Config is record
   Role   : I2C_Role := Controller;
   Timing : I2C_Timing := Standard_Mode;
end record;
Record fields
Role
Timing

I2C_Number

subtype I2C_Number is Natural range 0 .. 1;

I2C_Port

type I2C_Port
   (Num    : I2C_Number;
    Periph : not null access RP2040_SVD.I2C.I2C_Peripheral)
is tagged private;

I2C_Role

type I2C_Role is (Controller, Target);
Enumeration Literal
Controller
Target

I2C_State

type I2C_State is record
   Abort_Source   : I2C_Abort_Source;
   Last_Command   : RP2040_SVD.I2C.IC_DATA_CMD_Register;
   RX_Remaining   : Natural;
   TX_Remaining   : Natural;
   TX_Empty       : Boolean;
   RX_Empty       : Boolean;
   Repeated_Start : Boolean;
   Is_Error       : Boolean;
end record;
Record fields
Abort_Source
Last_Command
RX_Remaining
TX_Remaining
TX_Empty
RX_Empty
Repeated_Start
Is_Error

I2C_Status

type I2C_Status is
   (Ok, Timeout, Error);

If a procedure sets Status to Error, the record returned by function State will provide more information useful for debugging.

Enumeration Literal
Ok
Timeout
Error

I2C_Timing

type I2C_Timing is record
   High, Low, Hold, Spike : Nanoseconds;
   Rise, Fall : Nanoseconds := 0;
end record;
Record fields
High
Low
Hold
Spike
Rise
Fall

Nanoseconds

type Nanoseconds is new Natural;

Read

procedure Read
   (This     : in out I2C_Port;
    Data     : out HAL.UInt8;
    Status   : out I2C_Status;
    Deadline : RP.Timer.Time := RP.Timer.Time'Last)
Parameters
This
Data
Status
Deadline

Read_Ready

function Read_Ready
   (This : I2C_Port)
   return Boolean

Returns True if a call to Read would not block

Parameters
This
Return Value

Set_Address

procedure Set_Address
   (This : in out I2C_Port;
    Addr : HAL.UInt10)

When configured as a Controller, Set_Address indicates the address of the Target for Read and Write. When configured as a Target, Set_Address indicates this device's address.

Parameters
This
Addr

Set_Address

procedure Set_Address
   (This : in out I2C_Port;
    Addr : HAL.UInt7)
Parameters
This
Addr

Set_Timing

procedure Set_Timing
   (This : in out I2C_Port;
    T    : I2C_Timing)
Parameters
This
T

Standard_Mode

Standard_Mode  : constant I2C_Timing :=
   (High   => 5_200,
    Low    => 4_700,
    Hold   => 3_450,
    others => <>);

Start_Read

procedure Start_Read
   (This   : in out I2C_Port;
    Length : Positive := 1;
    Stop   : Boolean := True)

If Stop is False, the Controller does not release the bus after this transaction completes and will issue a repeated start before the first byte of the next transaction. Stop has no effect if Role = Target.

Parameters
This
Length
Stop

Start_Write

procedure Start_Write
   (This     : in out I2C_Port;
    Length   : Positive := 1;
    Stop     : Boolean := True;
    Deadline : RP.Timer.Time := RP.Timer.Time'Last)

In Target mode, Start_Write waits until Deadline for the Controller to send our address. If a Deadline is specified and nonblocking behavior is expected, the caller should check the value of Write_Ready before calling Write.

Parameters
This
Length
Stop
Deadline

State

function State
   (This : I2C_Port)
   return I2C_State
Parameters
This
Return Value

Write

procedure Write
   (This     : in out I2C_Port;
    Data     : HAL.UInt8;
    Status   : out I2C_Status;
    Deadline : RP.Timer.Time := RP.Timer.Time'Last)

If Deadline is reached before Write_Ready returns True, Abort_Write will be called and Status is set to Err_Timeout. After a timeout, call Clear_Error before attempting another Write.

Parameters
This
Data
Status
Deadline

Write_Ready

function Write_Ready
   (This : I2C_Port)
   return Boolean

Returns True if a call to Write would not block

Parameters
This
Return Value