I2cController Class
Namespace: GHIElectronics.TinyCLR.Devices.I2c · Assembly: GHIElectronics.TinyCLR.Devices.I2c
Represents an I²C bus controller. Open a peer with GetDevice(I2cConnectionSettings) to transact with a specific slave address. The same controller can serve multiple slaves — settings are re-applied per transfer.
public class I2cController : IDisposable
Properties
Provider
public II2cControllerProvider Provider { get; }
The low-level provider backing this controller.
Timeout
public TimeSpan Timeout { get; set; }
Maximum time the controller will block on a single transfer before giving up.
WriteBufferSize
public int WriteBufferSize { get; set; }
Slave-mode only: size in bytes of the controller's outgoing buffer.
ReadBufferSize
public int ReadBufferSize { get; set; }
Slave-mode only: size in bytes of the controller's incoming buffer.
BytesToWrite
public int BytesToWrite { get; }
Slave-mode only: bytes currently queued to transmit.
BytesToRead
public int BytesToRead { get; }
Slave-mode only: bytes currently available to read.
Methods
GetDefault()
public static I2cController GetDefault()
Returns the default I²C controller for this device.
Returns I2cController
FromName(string name)
public static I2cController FromName(string name)
Returns an I²C controller identified by its native API name.
| Parameter | Type | Description |
|---|---|---|
name | string |
Returns I2cController
FromName(string name, GpioPin sdaPin, GpioPin sclPin)
public static I2cController FromName(string name, GpioPin sdaPin, GpioPin sclPin)
Returns a software (bit-bang) I²C controller using the supplied SDA/SCL pins.
| Parameter | Type | Description |
|---|---|---|
name | string | |
sdaPin | GpioPin | |
sclPin | GpioPin |
Returns I2cController
FromName(string name, GpioPin sdaPin, GpioPin sclPin, bool usePullups)
public static I2cController FromName(string name, GpioPin sdaPin, GpioPin sclPin, bool usePullups)
Returns a software I²C controller, optionally engaging the internal pull-ups.
| Parameter | Type | Description |
|---|---|---|
name | string | Must be the SoftwareI2cController native API name. |
sdaPin | GpioPin | Pin used as SDA. |
sclPin | GpioPin | Pin used as SCL. |
usePullups | bool | When true, configures SDA/SCL as inputs with internal pull-ups. |
Returns I2cController
FromProvider(II2cControllerProvider provider)
public static I2cController FromProvider(II2cControllerProvider provider)
Creates a controller from a custom II2cControllerProvider.
| Parameter | Type | Description |
|---|---|---|
provider | II2cControllerProvider |
Returns I2cController
Dispose()
public void Dispose()
Releases the underlying provider.
GetDevice(I2cConnectionSettings connectionSettings)
public I2cDevice GetDevice(I2cConnectionSettings connectionSettings)
Creates an I2cDevice bound to this controller using the supplied settings.
| Parameter | Type | Description |
|---|---|---|
connectionSettings | I2cConnectionSettings | Slave address, bus speed, and master/slave mode. |
Returns I2cDevice
ClearWriteBuffer()
public void ClearWriteBuffer()
Slave-mode only: empties the controller's outgoing buffer.
ClearReadBuffer()
public void ClearReadBuffer()
Slave-mode only: empties the controller's incoming buffer.