I2cDevice.cs 1.9 KB
Newer Older
1 2 3 4 5 6
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.Device.I2c
{
G
Greg Ingram 已提交
7 8 9
    /// <summary>
    /// The communications channel to a device on an I2C bus.
    /// </summary>
10 11
    public abstract class I2cDevice : IDisposable
    {
G
Greg Ingram 已提交
12 13 14
        /// <summary>
        /// The connection settings of a device on an I2C bus.
        /// </summary>
15
        public abstract I2cConnectionSettings ConnectionSettings { get; }
G
Greg Ingram 已提交
16 17 18 19 20

        /// <summary>
        /// Reads a byte from the I2C device.
        /// </summary>
        /// <returns>A byte read from the I2C device.</returns>
21
        public abstract byte ReadByte();
G
Greg Ingram 已提交
22 23 24 25 26 27 28 29

        /// <summary>
        /// Reads data from the I2C device.
        /// </summary>
        /// <param name="buffer">
        /// The buffer to read the data from the I2C device.
        /// The length of the buffer determines how much data to read from the I2C device.
        /// </param>
30
        public abstract void Read(Span<byte> buffer);
G
Greg Ingram 已提交
31 32 33 34 35

        /// <summary>
        /// Writes a byte to the I2C device.
        /// </summary>
        /// <param name="data">The byte to be written to the I2C device.</param>
36
        public abstract void WriteByte(byte data);
G
Greg Ingram 已提交
37 38 39 40 41 42 43 44

        /// <summary>
        /// Writes data to the I2C device.
        /// </summary>
        /// <param name="data">
        /// The buffer that contains the data to be written to the I2C device.
        /// The data should not include the I2C device address.
        /// </param>
45
        public abstract void Write(Span<byte> data);
46

47 48 49 50 51
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
52

53 54 55 56 57 58
        public virtual void Dispose(bool disposing)
        {
            // Nothing to do in base class.
        }
    }
}