Skip to content

Commit

Permalink
Standardize I2C addresses enums
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianstevens committed Jan 20, 2022
1 parent e311b84 commit 6eed9a6
Show file tree
Hide file tree
Showing 71 changed files with 511 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ public partial class Tea5767
/// <summary>
/// Valid addresses for the sensor.
/// </summary>
public enum Addresses : byte
public enum Address : byte
{
/// <summary>
/// I2C address 0
/// </summary>
Address0 = 0x60,
Address_0x60 = 0x60,
/// <summary>
/// Default I2C address
/// </summary>
Default = Address0
Default = Address_0x60
}

enum Command : byte
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public partial class Tea5767
/// </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)Addresses.Default)
public Tea5767(II2cBus i2cBus, byte address = (byte)Address.Default)
{
i2cPeripheral = new I2cPeripheral(i2cBus, address);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ public partial class I2cCharacterDisplay
/// </summary>
public enum Addresses : byte
{
Address0 = 0x27,
Default = Address0
/// <summary>
/// Bus address 0x27
/// </summary>
Address_0x27 = 0x27,
/// <summary>
/// Default bus address
/// </summary>
Default = Address_0x27
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ public Ssd1306(IMeadowDevice device, ISpiBus spiBus, IPin chipSelectPin, IPin dc
/// <summary>
/// Create a new SSD1306 object using the default parameters for
/// </summary>
/// <remarks>
/// Note that by default, any pixels out of bounds will throw and exception.
/// This can be changed by setting the <seealso cref="IgnoreOutOfBoundsPixels" />
/// property to true.
/// </remarks>
/// <param name="i2cBus">I2cBus connected to display</param>
/// <param name="address">Address of the bus on the I2C display.</param>
/// <param name="displayType">Type of SSD1306 display (default = 128x64 pixel display).</param>
public Ssd1306(II2cBus i2cBus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ public Ssd1309(IMeadowDevice device, ISpiBus spiBus, IPin chipSelectPin, IPin dc
}

/// <summary>
/// Create a new SSD1309 object using the default parameters for
/// Create a new SSD1309 object
/// </summary>
/// <remarks>
/// Note that by default, any pixels out of bounds will throw and exception.
/// This can be changed by setting the <seealso cref="IgnoreOutOfBoundsPixels" />
/// property to true.
/// </remarks>
/// <param name="i2cBus">I2cBus connected to display</param>
/// <param name="address">Address of the bus on the I2C display.</param>
public Ssd1309(II2cBus i2cBus, byte address = (byte)Addresses.Default) : base(i2cBus, address, DisplayType.OLED128x64)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ public abstract partial class Ssd130xBase
/// </summary>
public enum Addresses : byte
{
Address0 = 0x3C,
Address1 = 0x3D,
Default = Address0
/// <summary>
/// Bus address 0x3C
/// </summary>
Address_0x3C = 0x3C,
/// <summary>
/// Bus address 0x3D
/// </summary>
Address_0x3D = 0x3D,
/// <summary>
/// Default bus address
/// </summary>
Default = Address_0x3C
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ namespace Meadow.Foundation.FeatherWings
/// </summary>
public class CharlieWing : IGraphicsDisplay
{
/// <summary>
/// Color mode of display
/// </summary>
public ColorType ColorMode => ColorType.Format8bppGray;

/// <summary>
/// Width of display in pixels
/// </summary>
public int Width => 15;

/// <summary>
/// Height of display in pixels
/// </summary>
public int Height => 7;

public byte Frame { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MotorWing
/// </summary>
/// <param name="i2cBus">i2c bus</param>
/// <param name="address">The address of the i2c Peripheral</param>
/// <param name="freq">The PWM frequency for the PCA9685 IC</param>
/// <param name="frequency">The PWM frequency for the PCA9685 IC</param>
public MotorWing(II2cBus i2cBus, byte address = (byte)Pca9685.Addresses.Default, int frequency = 1600)
{
if (i2cBus == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public SampleRateSetting SampleRate
}

public Ads1015(II2cBus i2cBus,
Address address = Address.Default,
Addresses address = Addresses.Default,
MeasureMode mode = MeasureMode.OneShot,
ChannelSetting channel = ChannelSetting.A0A1Differential,
SampleRateSetting sampleRate = SampleRateSetting.Sps1600)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public SampleRateSetting SampleRate
}

public Ads1115(II2cBus i2cBus,
Address address = Address.Default,
Addresses address = Addresses.Default,
MeasureMode mode = MeasureMode.OneShot,
ChannelSetting channel = ChannelSetting.A0A1Differential,
SampleRateSetting sampleRate = SampleRateSetting.Sps128)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public partial class Ads1x15
/// <summary>
/// Valid addresses for the sensor.
/// </summary>
public enum Address : byte
public enum Addresses : byte
{
Address48 = 0x48,
Address49 = 0x49,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract partial class Ads1x15 : SamplingSensorBase<Units.Voltage>
/// <param name="mode"></param>
/// <param name="channel"></param>
protected Ads1x15(II2cBus i2cBus,
Address address,
Addresses address,
MeasureMode mode,
ChannelSetting channel)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void Initialize()
Console.WriteLine("Initialize hardware...");
_adc = new Ads1015(
Device.CreateI2cBus(Meadow.Hardware.I2cBusSpeed.FastPlus),
Ads1x15.Address.Default,
Ads1x15.Addresses.Default,
Ads1x15.MeasureMode.Continuous,
Ads1x15.ChannelSetting.A0SingleEnded,
Ads1015.SampleRateSetting.Sps3300);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ public partial class At24Cxx
/// <summary>
/// Valid addresses for the sensor.
/// </summary>
public enum Addresses : byte
public enum Address : byte
{
Address0 = 0x50,
Default = Address0
/// <summary>
/// Bus address 0x50
/// </summary>
Address_0x50 = 0x50,
/// <summary>
/// Default bus address
/// </summary>
Default = Address_0x50
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public partial class At24Cxx
/// <summary>
/// Create a new AT24Cxx object using the default parameters for the component.
/// </summary>
/// <param name="i2cBus">I2CBus connected to display</param>
/// <param name="address">Address of the At24Cxx (default = 0x50).</param>
/// <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)Addresses.Default,
byte address = (byte)Address.Default,
ushort pageSize = 32,
ushort memorySize = 8192)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,36 @@ public partial class Ht16k33
/// </summary>
public enum Addresses : byte
{
Address0 = 0x70,
Default = Address0
/// <summary>
/// Bus address 0x70
/// </summary>
Address_0x70 = 0x70,
/// <summary>
/// Default bus address
/// </summary>
Default = Address_0x70
}

/// <summary>
/// Blink rate
/// </summary>
public enum BlinkRate : byte
{
/// <summary>
/// Off
/// </summary>
Off = 0,
/// <summary>
/// Fast (2Hz)
/// </summary>
Fast = 2, //2hz
/// <summary>
/// Medium (1Hz)
/// </summary>
Medium = 4, //1hz
/// <summary>
/// Slow (0.5Hz)
/// </summary>
Slow = 8, //0.5hz
}

Expand Down Expand Up @@ -55,6 +76,5 @@ enum Register : byte
HT16K33_DIM = 0xE0, // Set brightness / dimmer
HT16K33_DDAP = 0, //display address pointer
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ public partial class Is31fl3731
/// </summary>
public enum Addresses : byte
{
Address0 = 0x74,
Address1 = 0x77,
Default = Address0
/// <summary>
/// Bus address 0x74
/// </summary>
Address_0x74 = 0x74,
/// <summary>
/// Bus address 0x77
/// </summary>
Address_0x77 = 0x77,
/// <summary>
/// Default bus address
/// </summary>
Default = Address_0x74
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ public partial class Mcp23x08
/// <summary>
/// Valid addresses for the sensor.
/// </summary>
public enum Addresses : byte
public enum Address : byte
{
Address0 = 0x20,
Default = Address0
/// <summary>
/// Bus address 0x20
/// </summary>
Address_0x20 = 0x20,
/// <summary>
/// Default bus address
/// </summary>
Default = Address_0x20
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public Mcp23x08(II2cBus i2cBus, bool pinA0, bool pinA1, bool pinA2,
/// </summary>
/// <param name="i2cBus"></param>
/// <param name="address"></param>
public Mcp23x08(II2cBus i2cBus, byte address = (byte)Addresses.Default,
/// <param name="interruptPort">optional interupt port</param>
public Mcp23x08(II2cBus i2cBus, byte address = (byte)Address.Default,
IDigitalInputPort interruptPort = null) :
// use the internal constructor that takes an IMcpDeviceComms
this(new I2cMcpDeviceComms(i2cBus, address), interruptPort)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ public partial class Pca9685
/// </summary>
public enum Addresses : byte
{
Address0 = 0x40,
Default = Address0
/// <summary>
/// Bus address 0x44
/// </summary>
Address_0x44 = 0x40,
/// <summary>
/// Default bus address
/// </summary>
Default = Address_0x44
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public partial class Pca9685
protected const byte mode1AI = 0x21;

public II2cBus i2CBus { get; protected set; }
public byte Address { get; protected set; }
byte address;

public Pca9685(II2cBus i2cBus, byte address = (byte)Addresses.Default, int frequency = 100)
{
i2CBus = i2cBus;
Address = address;
i2cPeripheral = new I2cPeripheral(i2CBus, Address);
this.address = address;
i2cPeripheral = new I2cPeripheral(i2CBus, address);
this.frequency = frequency;
}

Expand All @@ -53,8 +53,8 @@ public Pca9685(II2cBus i2cBus, byte address = (byte)Addresses.Default, int frequ
/// </summary>
public virtual void Initialize()
{
i2CBus.WriteData(Address, Mode1, 0X00);
i2CBus.WriteData(Address, Mode1);
i2CBus.WriteData(address, Mode1, 0X00);
i2CBus.WriteData(address, Mode1);

Thread.Sleep(5);

Expand All @@ -79,7 +79,7 @@ public virtual IPwmPort CreatePwmPort(byte portNumber, float dutyCycle = 0.5f)
throw new ArgumentException("Value must be between 0 and 15", "portNumber");
}

var pwmPort = new PwmPort(i2CBus, Address, Led0OnL, frequency, portNumber, dutyCycle);
var pwmPort = new PwmPort(i2CBus, address, Led0OnL, frequency, portNumber, dutyCycle);

return pwmPort;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ public virtual void SetPwm(byte pin, int on, int off)

protected virtual void Write(byte register, byte ledXOnL, byte ledXOnH, byte ledXOffL, byte ledXOffH)
{
i2CBus.WriteData(Address, register, ledXOnL, ledXOnH, ledXOffL, ledXOffH);
i2CBus.WriteData(address, register, ledXOnL, ledXOnH, ledXOffL, ledXOffH);
}

protected virtual void Write(byte register, byte value)
Expand Down
Loading

0 comments on commit 6eed9a6

Please sign in to comment.