Skip to content

Commit

Permalink
Add LED matrix bindings for IS31FL3731 driver (#1926)
Browse files Browse the repository at this point in the history
* Add IS31FL3731 LED matrix binding

* Update sample

* Make program more generic

* Add specific bindings

* Add Phat 17x7 binding

* Add Phat 17x7 binding

* Add LED Shim 28x1 driver

* Update switch expression

* Update TPN

* Add README

* Add Led Matrix Breakout 11x7 binding

* Update README for led matrix breakout

* Add Led RGB Matrix 5x5 binding

* Add 5x5 RGB Matrix sample

* Switch integers to decimals

* Fix syntax

* Rename type

* Update per feedback

* Update per feedback

* Switch to enums for const data

* Switch from enum to static class

* Switch to ROS

* Fix flipped field

* Update brightness

* Update TFMs

* Adding GpioPin (#1895)

* Adding GpioPin

* adjusting based on PR feedback

* Adjusting to have natively drivers.

* make methods virtual

* adding Toggle to System.Device drivers

* Board and Mcp23xxx adjustments

* adding FT4222, FT232H and Pcx857x

* adding Arduino and Seasaw

* adjsting file encoding after conflict merge

* Adding missing Toggle implementation in Arduino native

* Adjusting test for new pattern with GpioPin

* adjusting PR feedback

* typo in test

* fixing nit

* fixing test

* fixing test

* Bump Microsoft.CodeAnalysis.CSharp.Scripting in /tools/DevicesApiTester (#1981)

Bumps [Microsoft.CodeAnalysis.CSharp.Scripting](https://github.com/dotnet/roslyn) from 4.3.1 to 4.4.0.
- [Release notes](https://github.com/dotnet/roslyn/releases)
- [Changelog](https://github.com/dotnet/roslyn/blob/main/docs/Breaking%20API%20Changes.md)
- [Commits](https://github.com/dotnet/roslyn/commits/Visual-Studio-2019-Version-16.0-Preview-4.4)

---
updated-dependencies:
- dependency-name: Microsoft.CodeAnalysis.CSharp.Scripting
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump Microsoft.Net.Compilers.Toolset in /tools/DevicesApiTester (#1980)

Bumps [Microsoft.Net.Compilers.Toolset](https://github.com/dotnet/roslyn) from 4.3.1 to 4.4.0.
- [Release notes](https://github.com/dotnet/roslyn/releases)
- [Changelog](https://github.com/dotnet/roslyn/blob/main/docs/Breaking%20API%20Changes.md)
- [Commits](https://github.com/dotnet/roslyn/commits/Visual-Studio-2019-Version-16.0-Preview-4.4)

---
updated-dependencies:
- dependency-name: Microsoft.Net.Compilers.Toolset
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Upgrade to .NET 7 GA (#1988)

* Upgrade to .NET 7 GA

* Update global.json

Co-authored-by: Jose Perez Rodriguez <joperezr@microsoft.com>

* Update blinking

* Add 'Port of' comments

* Update sample

* Update sample

* Update comment

* Update per feedback

* Add 'Port of' comment

* Move samples to directories

* Update README

* Change exception type

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Laurent Ellerbach <laurelle@microsoft.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jose Perez Rodriguez <joperezr@microsoft.com>
  • Loading branch information
4 people authored Jan 16, 2023
1 parent 2de8bc9 commit 2580229
Show file tree
Hide file tree
Showing 18 changed files with 1,292 additions and 0 deletions.
9 changes: 9 additions & 0 deletions THIRD-PARTY-NOTICES.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

License notice for CircuitPython driver for the IS31FL3731 charlieplex IC
-------------------------------------------------------------------------

https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3731/blob/main/LICENSE

The MIT License (MIT)

Copyright (c) 2016 Radomir Dopieralski

License notice for LED matrices with the HT16K33 chip
-----------------------------------------------------

Expand Down
34 changes: 34 additions & 0 deletions src/devices/Is31fl3731/Backpack16x9.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Device.I2c;
using System.Threading;

namespace Iot.Device.Display
{
/// <summary>
/// Represents 16x9 matrix, driven by an IS31FL3731 LED chip.
/// </summary>
// Product: https://www.adafruit.com/product/2974
// Port of: https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3731/blob/main/adafruit_is31fl3731/matrix.py
public class Backpack16x9 : Is31fl3731
{
/// <summary>
/// Initialize LED driver.
/// </summary>
/// <param name="i2cDevice">The <see cref="System.Device.I2c.I2cDevice"/> to create with.</param>
public Backpack16x9(I2cDevice i2cDevice)
: base(i2cDevice, 16, 9)
{
}

/// <summary>
/// Default I2C address for device.
/// </summary>
public static new readonly int DefaultI2cAddress = 0x74;

/// <inheritdoc/>
public override int GetLedAddress(int x, int y) => x + y * 16;
}
}
39 changes: 39 additions & 0 deletions src/devices/Is31fl3731/Bonnet16x8.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Device.I2c;
using System.Threading;

namespace Iot.Device.Display
{
/// <summary>
/// Represents 16x8 matrix, driven by an IS31FL3731 LED chip.
/// </summary>
// Product: https://www.adafruit.com/product/4122
// Port of: https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3731/blob/main/adafruit_is31fl3731/charlie_bonnet.py
public class Bonnet16x8 : Is31fl3731
{
/// <summary>
/// Initialize LED driver.
/// </summary>
/// <param name="i2cDevice">The <see cref="System.Device.I2c.I2cDevice"/> to create with.</param>
public Bonnet16x8(I2cDevice i2cDevice)
: base(i2cDevice, 16, 8)
{
}

/// <summary>
/// Default I2C address for device.
/// </summary>
public static new readonly int DefaultI2cAddress = 0x74;

/// <inheritdoc/>
public override int GetLedAddress(int x, int y) => x switch
{
< 8 => (x + 1) * 16 + (7 - y),
< 16 => (x - 6) * 16 - (y + 1),
_ => throw new ArgumentException($"{nameof(x)} value must be < 16.")
};
}
}
34 changes: 34 additions & 0 deletions src/devices/Is31fl3731/Breakout11x7.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Device.I2c;
using System.Threading;

namespace Iot.Device.Display
{
/// <summary>
/// Represents 11x7 matrix, driven by an IS31FL3731 LED chip.
/// </summary>
// Product: https://shop.pimoroni.com/products/11x7-led-matrix-breakout
// Port of: https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3731/blob/main/adafruit_is31fl3731/matrix_11x7.py
public class Breakout11x7 : Is31fl3731
{
/// <summary>
/// Initialize LED driver.
/// </summary>
/// <param name="i2cDevice">The <see cref="System.Device.I2c.I2cDevice"/> to create with.</param>
public Breakout11x7(I2cDevice i2cDevice)
: base(i2cDevice, 11, 7)
{
}

/// <summary>
/// Default I2C address for device.
/// </summary>
public static new readonly int DefaultI2cAddress = 0x75;

/// <inheritdoc/>
public override int GetLedAddress(int x, int y) => (x << 4) - y + (x <= 5 ? 6 : -82);
}
}
80 changes: 80 additions & 0 deletions src/devices/Is31fl3731/BreakoutRgb5x5.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Device.I2c;
using System.Threading;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;

namespace Iot.Device.Display
{
/// <summary>
/// Represents 5x5 RGB matrix, driven by an IS31FL3731 LED chip.
/// </summary>
// Product: https://shop.pimoroni.com/products/5x5-rgb-matrix-breakout
// Port of: https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3731/blob/main/adafruit_is31fl3731/rgbmatrix5x5.py
public class BreakoutRgb5x5 : Is31fl3731
{
private byte[][] _addresses = new byte[][]
{
new byte[] { 118, 69, 85 },
new byte[] { 117, 68, 101 },
new byte[] { 116, 84, 100 },
new byte[] { 115, 83, 99 },
new byte[] { 114, 82, 98 },
new byte[] { 132, 19, 35 },
new byte[] { 133, 20, 36 },
new byte[] { 134, 21, 37 },
new byte[] { 112, 80, 96 },
new byte[] { 113, 81, 97 },
new byte[] { 131, 18, 34 },
new byte[] { 130, 17, 50 },
new byte[] { 129, 33, 49 },
new byte[] { 128, 32, 48 },
new byte[] { 127, 47, 63 },
new byte[] { 125, 28, 44 },
new byte[] { 124, 27, 43 },
new byte[] { 123, 26, 42 },
new byte[] { 122, 25, 58 },
new byte[] { 121, 41, 57 },
new byte[] { 126, 29, 45 },
new byte[] { 15, 95, 111 },
new byte[] { 8, 89, 105 },
new byte[] { 9, 90, 106 },
new byte[] { 10, 91, 107 }
};

/// <summary>
/// Initialize LED driver.
/// </summary>
/// <param name="i2cDevice">The <see cref="System.Device.I2c.I2cDevice"/> to create with.</param>
public BreakoutRgb5x5(I2cDevice i2cDevice)
: base(i2cDevice, 25, 3)
{
}

/// <summary>
/// Default I2C address for device.
/// </summary>
public static new readonly int DefaultI2cAddress = 0x74;

/// <inheritdoc/>
public override int GetLedAddress(int x, int y) => _addresses[x][y];

/// <summary>
/// Write RGB value.
/// </summary>
/// <param name="x">Horizontal pixel position.</param>
/// <param name="y">Vertical pixel position.</param>
/// <param name="color">Color value.</param>
public void WritePixelRgb(int x, int y, Color color)
{
x += y * 5;
Rgb24 pixel = color.ToPixel<Rgb24>();
this[x, 0] = pixel.R;
this[x, 1] = pixel.G;
this[x, 2] = pixel.B;
}
}
}
Loading

0 comments on commit 2580229

Please sign in to comment.