BusI2C
Base I2C bus interface to be used by devices. Concrete implementations in MCU drivers should be passed to drivers.
(c) Alexander Shiryaev, 2016.12 Modified by Tenko for use with ECS
Const
NoError* = 0;
ErrorTimeout* = -1;
ErrorNoDevice* = -2;
ErrorArgs* = -3;
Types
Bus* = RECORD
timeout*: UNSIGNED32; (* transfere timeout in ms. 0 or lower disable timeout check *)
error*: INTEGER; (* last transfer error code or NoError if success *)
END;
Procedures
Bus.Transfer
Read or Write data
PROCEDURE (VAR this: Bus) Transfer*(adr : INTEGER; rd : BOOLEAN; VAR buf : ARRAY OF BYTE; start, len : LENGTH; stop : BOOLEAN): LENGTH;
Bus.Probe
Probe address adr for device respons. Return 0 if device responded.
PROCEDURE (VAR this: Bus) Probe*(adr : INTEGER): INTEGER;
Bus.Read
Read into buffer from the peripheral specified by addr. The number of bytes read is length and the data is written to the buffer starting from start index. The function returns the number of bytes that were received.
PROCEDURE (VAR this: Bus) Read*(adr : INTEGER; VAR buffer : ARRAY OF BYTE; start, length : LENGTH): LENGTH;
Bus.Write
Write bytes from the buffer to the peripheral specified by addr. The number of bytes written is length and starting from start index. The function returns the number of bytes that were sent.
PROCEDURE (VAR this: Bus) Write*(adr : INTEGER; VAR buffer : ARRAY OF BYTE; start, length : LENGTH; stop : BOOLEAN): LENGTH;