Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ISpiPeripheral and II2cPeripheral abstractions #636

Merged
merged 5 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
public partial class Tea5767
{
/// <summary>
/// Valid addresses for the sensor.
/// Valid I2C addresses for the sensor
/// </summary>
public enum Address : byte
public enum Addresses : byte
{
/// <summary>
/// I2C address 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Meadow.Foundation.Audio.Radio
/// <summary>
/// Represents a TEA5767 radio
/// </summary>
public partial class Tea5767
public partial class Tea5767 : II2cPeripheral
{
/// <summary>
/// I2C Communication bus used to communicate with the peripheral
Expand All @@ -25,12 +25,17 @@ public partial class Tea5767
/// </summary>
public bool IsMuted { get; set; }

/// <summary>
/// The default I2C address for the peripheral
/// </summary>
public byte DefaultI2cAddress => (byte)Addresses.Default;

/// <summary>
/// Create a new TEA5767 object using the default parameters
/// </summary>
/// <param name="i2cBus">I2Cbus connected to the radio</param>
/// <param name="address">Address of the bus on the I2C display.</param>
public Tea5767(II2cBus i2cBus, byte address = (byte)Address.Default)
public Tea5767(II2cBus i2cBus, byte address = (byte)Addresses.Default)
{
i2cComms = new I2cCommunications(i2cBus, address);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Meadow.Foundation.Displays
/// <summary>
/// Provide an interface to the Ch1115 family of displays
/// </summary>
public partial class Ch1115 : IGraphicsDisplay, ISpiDevice
public partial class Ch1115 : IGraphicsDisplay, ISpiPeripheral
{
/// <summary>
/// The display color mode - 1 bit per pixel monochrome
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Threading;
using Meadow.Hardware;
using Meadow.Hardware;
using System.Threading;

namespace Meadow.Foundation.Displays.Lcd
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public partial class I2cCharacterDisplay
{
/// <summary>
/// Valid addresses for the sensor.
/// Valid I2C addresses for the sensor
/// </summary>
public enum Addresses : byte
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ namespace Meadow.Foundation.Displays.Lcd
/// <summary>
/// Represents a character display using I2C
/// </summary>
public partial class I2cCharacterDisplay : ICharacterDisplay
public partial class I2cCharacterDisplay : ICharacterDisplay, II2cPeripheral
{
/// <summary>
/// The default I2C address for the peripheral
/// </summary>
public byte DefaultI2cAddress => (byte)Addresses.Default;

/// <summary>
/// I2C Communication bus used to communicate with the peripheral
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public class FourDigitSevenSegment
CancellationTokenSource cts = null;

readonly IDigitalOutputPort[] digits;

SevenSegment[] sevenSegments;
readonly SevenSegment[] sevenSegments;

/// <summary>
/// Creates a SevenSegment connected to the especified IPins to a IODevice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Meadow.Foundation.Displays
/// <summary>
/// Max7219 LED matrix driver
/// </summary>
public partial class Max7219 : ISpiDevice
public partial class Max7219 : ISpiPeripheral
{
/// <summary>
/// Number of digits per Module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Meadow.Foundation.Displays
/// <summary>
/// Represents a Pcd8544 monochrome display
/// </summary>
public class Pcd8544 : IGraphicsDisplay, ISpiDevice
public class Pcd8544 : IGraphicsDisplay, ISpiPeripheral
{
/// <summary>
/// Display color mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Meadow.Foundation.Displays
/// <summary>
/// Provide an interface to the Sh110x family of displays
/// </summary>
public abstract partial class Sh110x : IGraphicsDisplay, ISpiDevice
public abstract partial class Sh110x : IGraphicsDisplay, ISpiPeripheral, II2cPeripheral
{
/// <summary>
/// The display color mode - 1 bit per pixel monochrome
Expand Down Expand Up @@ -60,6 +60,11 @@ public SpiClockConfiguration.Mode SpiBusMode
set => spiComms.BusMode = value;
}

/// <summary>
/// The default I2C address for the peripheral
/// </summary>
public byte DefaultI2cAddress => (byte)Addresses.Default;

/// <summary>
/// The connection type (I2C or SPI)
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Meadow.Foundation.Displays
/// <summary>
/// Represents the SSD130x family of OLED displays
/// </summary>
public abstract partial class Ssd130xBase : IGraphicsDisplay, ISpiDevice
public abstract partial class Ssd130xBase : IGraphicsDisplay, ISpiPeripheral, II2cPeripheral
{
/// <summary>
/// The display color mode
Expand Down Expand Up @@ -50,6 +50,11 @@ public Frequency SpiBusSpeed
set => spiComms.BusSpeed = value;
}

/// <summary>
/// The default I2C address for the peripheral
/// </summary>
public byte DefaultI2cAddress => (byte)Addresses.Default;

/// <summary>
/// The default SPI bus mode for the device
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Meadow.Foundation.Displays
/// <summary>
/// Provides an interface to the Ssd1327 greyscale OLED display
/// </summary>
public partial class Ssd1327 : IGraphicsDisplay, ISpiDevice
public partial class Ssd1327 : IGraphicsDisplay, ISpiPeripheral
{
/// <summary>
/// The display color mode (4 bit per pixel grayscale)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Meadow.Foundation.Displays
/// <summary>
/// Provide an interface to the ST7565 family of displays
/// </summary>
public partial class St7565 : IGraphicsDisplay, ISpiDevice
public partial class St7565 : IGraphicsDisplay, ISpiPeripheral
{
/// <summary>
/// The display color mode - 1 bit per pixel monochrome
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Meadow.Foundation.Displays
{
public abstract partial class TftSpiBase : IGraphicsDisplay, ISpiDevice
public abstract partial class TftSpiBase : IGraphicsDisplay, ISpiPeripheral
{
//these displays typically support 16 & 18 bit, some also include 8, 9, 12 and/or 24 bit color

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Meadow.Foundation.Displays
/// <summary>
/// Represents a base ePaper display driver
/// </summary>
public abstract class EPaperBase : ISpiDevice
public abstract class EPaperBase : ISpiPeripheral
{
/// <summary>
/// The default SPI bus speed for the device
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public abstract partial class Ads1x15Base
{
/// <summary>
/// Valid addresses for the sensor
/// Valid I2C addresses for the sensor
/// </summary>
public enum Addresses : byte
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ namespace Meadow.Foundation.ICs.ADC
/// <summary>
/// Encapsulation for ADCs based upon the Ads1x1x family of chips.
/// </summary>
public abstract partial class Ads1x15Base : PollingSensorBase<Voltage>
public abstract partial class Ads1x15Base : PollingSensorBase<Voltage>, II2cPeripheral
{
/// <summary>
/// The default I2C address for the peripheral
/// </summary>
public byte DefaultI2cAddress => (byte)Addresses.Default;

/// <summary>
/// I2C Communication bus used to communicate with the peripheral
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
public partial class At24Cxx
{
/// <summary>
/// Valid addresses for the sensor.
/// Valid I2C addresses for the sensor
/// </summary>
public enum Address : byte
public enum Addresses : byte
{
/// <summary>
/// Bus address 0x50
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ namespace Meadow.Foundation.ICs.EEPROM
/// <summary>
/// Encapsulation for EEPROMs based upon the AT24Cxx family of chips
/// </summary>
public partial class At24Cxx
public partial class At24Cxx : II2cPeripheral
{
/// <summary>
/// The default I2C address for the peripheral
/// </summary>
public byte DefaultI2cAddress => (byte)Addresses.Default;

/// <summary>
/// I2C Communication bus used to communicate with the peripheral
/// </summary>
Expand All @@ -35,7 +40,7 @@ public partial class At24Cxx
/// <param name="pageSize">Number of bytes in a page (default = 32 - AT24C32).</param>
/// <param name="memorySize">Total number of bytes in the EEPROM (default = 8192 - AT24C32).</param>
public At24Cxx(II2cBus i2cBus,
byte address = (byte)Address.Default,
byte address = (byte)Addresses.Default,
ushort pageSize = 32,
ushort memorySize = 8192)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ public enum DataRate : byte
/// <summary>
/// 32hz
/// </summary>
_32hz,
_32hz,
}

/// <summary>
/// Valid addresses for the sensor
/// Valid I2C addresses for the sensor
/// </summary>
public enum Address : byte
public enum Addresses : byte
{
/// <summary>
/// Bus address 0x4C
Expand Down Expand Up @@ -188,4 +188,4 @@ public enum LutIndex : byte
Index7,
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace Meadow.Foundation.ICs.FanControllers
/// Represents an EMC2101 fan controller and temperature monitor
/// </summary>
public partial class Emc2101 :
PollingSensorBase<(Temperature? InternalTemperature, Temperature? ExternalTemperature, AngularVelocity? FanSpeed)>
PollingSensorBase<(Temperature? InternalTemperature, Temperature? ExternalTemperature, AngularVelocity? FanSpeed)>,
II2cPeripheral
{
/// <summary>
/// Internal Temperature changed event
Expand Down Expand Up @@ -42,6 +43,11 @@ public partial class Emc2101 :
/// </summary>
public AngularVelocity? FanSpeed => Conditions.FanSpeed;

/// <summary>
/// The default I2C address for the peripheral
/// </summary>
public byte DefaultI2cAddress => (byte)Addresses.Default;

/// <summary>
/// Get/Set the minimum fan speed for the currently connected fan
/// </summary>
Expand Down Expand Up @@ -150,7 +156,7 @@ public bool DACOutputEnabled
/// </summary>
/// <param name="i2cBus">I2CBus connected to display</param>
/// <param name="address">Address of the EMC2101 (default = 0x4C)</param>
public Emc2101(II2cBus i2cBus, byte address = (byte)Address.Default)
public Emc2101(II2cBus i2cBus, byte address = (byte)Addresses.Default)
{
i2cComms = new I2cCommunications(i2cBus, address);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public partial class As1115
{
/// <summary>
/// Valid addresses for the sensor.
/// Valid I2C addresses for the sensor
/// </summary>
public enum Addresses : byte
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Meadow.Foundation.ICs.IOExpanders
/// <summary>
/// Represents an As1115 led driver and key scanner
/// </summary>
public partial class As1115 : IGraphicsDisplay, IDisposable
public partial class As1115 : IGraphicsDisplay, II2cPeripheral, IDisposable
{
/// <summary>
/// Event raised when any key scan button is pressed
Expand Down Expand Up @@ -45,6 +45,11 @@ public partial class As1115 : IGraphicsDisplay, IDisposable
/// </summary>
protected readonly II2cCommunications i2cComms;

/// <summary>
/// The default I2C address for the peripheral
/// </summary>
public byte DefaultI2cAddress => (byte)Addresses.Default;

/// <summary>
/// The display color mode (1 bit per pixel)
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public partial class Ds3502
{
/// <summary>
/// Valid addresses for the sensor
/// Valid I2C addresses for the sensor
/// Controlled by pulling A0 and A1 high or low
/// </summary>
public enum Addresses : byte
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ namespace Meadow.Foundation.ICs.IOExpanders
/// <summary>
/// Represents a DS3502 digital potentiometer
/// </summary>
public partial class Ds3502
public partial class Ds3502 : II2cPeripheral
{
/// <summary>
/// The default I2C address for the peripheral
/// </summary>
public byte DefaultI2cAddress => (byte)Addresses.Default;

/// <summary>
/// Default I2C bus speed
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public partial class Ht16k33
{
/// <summary>
/// Valid addresses for the sensor.
/// Valid I2C addresses for the sensor
/// </summary>
public enum Addresses : byte
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ namespace Meadow.Foundation.ICs.IOExpanders
/// <summary>
/// Represents an Ht16k33 128 led driver and 39 key scanner
/// </summary>
public partial class Ht16k33
public partial class Ht16k33 : II2cPeripheral
{
/// <summary>
/// The default I2C address for the peripheral
/// </summary>
public byte DefaultI2cAddress => (byte)Addresses.Default;

/// <summary>
/// I2C Communication bus used to communicate with the peripheral
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public partial class Is31fl3731
{
/// <summary>
/// Valid addresses for the sensor.
/// Valid I2C addresses for the sensor
/// </summary>
public enum Addresses : byte
{
Expand Down
Loading