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 binding for IS31FL3730 LED driver #1930

Merged
merged 48 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
8299345
Binding for IS31FL3731 LED Matrix driver
richlander Sep 21, 2022
ccd9b9a
Add sample
richlander Sep 22, 2022
be62d43
Update sample
richlander Sep 23, 2022
7b78e6f
Update comments
richlander Sep 23, 2022
f0a1458
Add Matrix5x7 class
richlander Sep 24, 2022
1c6130a
Add higher-level bindings
richlander Sep 29, 2022
c795dbf
Rename sample project
richlander Sep 29, 2022
b4c9e37
Rename sample project
richlander Sep 29, 2022
13a95a8
Apply suggestions from code review
richlander Sep 29, 2022
bc4b4a4
Update src/devices/Is31fl3730/Bonnet5x7x6.cs
richlander Sep 29, 2022
565fa6e
Use lists/arrays more
richlander Sep 29, 2022
cd0dbc3
Add MicrDotpHat binding
richlander Sep 29, 2022
e920490
Cleanup
richlander Oct 5, 2022
3e81307
Update per feedback
richlander Nov 30, 2022
f7524ad
Merge branch 'main' into Is31fl3730
richlander Nov 30, 2022
d82f7ff
Add Index/Range support for netstandard2.0
richlander Nov 30, 2022
8f7d961
Enable decimal point
richlander Dec 14, 2022
5b8c341
Update target matrix
richlander Dec 14, 2022
0d1e95f
Add support for Micro Dot pHat
richlander Dec 17, 2022
5923b31
Add Length concept
richlander Dec 17, 2022
a900e7c
Update ordering of matrices
richlander Dec 17, 2022
a3800da
Update README
richlander Dec 17, 2022
bcd92dc
Change comment
richlander Dec 17, 2022
5712706
Merge branch 'main' into Is31fl3730
richlander Dec 17, 2022
ac4d819
Switch to Slice syntax
richlander Dec 17, 2022
230a212
Remove magic numbers
richlander Dec 18, 2022
57eacd2
Remove code duplication
richlander Dec 19, 2022
096bdce
Fix type name
richlander Dec 19, 2022
0992e82
Update README
richlander Dec 19, 2022
6322a24
Switch dimensional fields to properties
richlander Dec 20, 2022
0b24344
Remove code by subclassing
richlander Dec 20, 2022
62459d7
Add more value bounds checking
richlander Dec 20, 2022
4ef5b67
Update bounds checking
richlander Dec 20, 2022
6a34bc0
Add IMatrix interface
richlander Dec 20, 2022
18a685b
Fix markdown error
richlander Dec 20, 2022
c2c6916
Update fill value
richlander Dec 20, 2022
b151d50
Update README
richlander Dec 20, 2022
5fad1d5
Add solution file
richlander Jan 12, 2023
ecab9e3
Update src/devices/Is31fl3730/Current.cs
richlander Jan 16, 2023
bf10f22
Update per feedback
richlander Jan 16, 2023
9396154
Update to PinValue
richlander Jan 16, 2023
de781f6
Update per feedback
richlander Jan 16, 2023
0001fab
Update per feedback
richlander Jan 16, 2023
d0d0964
Remove IMatrix interface
richlander Jan 16, 2023
0921724
Update type names
richlander Jan 17, 2023
2a81f18
Update per feedback
richlander Jan 26, 2023
a4222e8
Fix fill logic
richlander Feb 2, 2023
67ca483
Update per feedback
richlander Feb 2, 2023
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
61 changes: 61 additions & 0 deletions src/devices/Is31fl3730/Bonnet5x7x6.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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.Collections.Generic;
using System.Device.I2c;
using System.Threading;

namespace Iot.Device.Display
{
/// <summary>
/// Represents LED Dot Matrix Breakout
/// </summary>
// Datasheet: https://cdn-shop.adafruit.com/product-files/3017/31FL3730.pdf
// Product: https://shop.pimoroni.com/products/led-dot-matrix-breakout
// Related repo: https://github.com/pimoroni/microdot-phat
public class Matrix5x7 : IDisposable
{
private readonly Is31fl3730 _is31fl3730;

/// <summary>
/// Initialize IS31FL3730 device
/// </summary>
/// <param name="is31fl3730">The <see cref="Iot.Device.Display.Is31fl3730"/> to create with.</param>
/// <param name="width">The width of the LED matrix.</param>
/// <param name="height">The height of the LED matrix.</param>
public Matrix5x7(Is31fl3730 is31fl3730, int width, int height, int matrix)
{
_is31fl3730 = is31fl3730;
Width = width;
Height = height;
Matrix = matrix;
}

/// <summary>
/// Indexer for matrix.
/// </summary>
public int this[int x, int y]
{
get => _is31fl3730.ReadLed(Matrix, x, y);
set => _is31fl3730.WriteLed(Matrix, x, y, value);
}

public const int DefaultI2cAddress = 0x61;

/// <summary>
/// Width of LED matrix (x axis).
/// </summary>
public readonly int Width = 5;
richlander marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Height of LED matrix (y axis).
/// </summary>
public readonly int Height = 7;

/// <summary>
/// Identification of matrix (of 2).
/// </summary>
public readonly int Matrix = 0;
}
}
96 changes: 96 additions & 0 deletions src/devices/Is31fl3730/BreakoutPair5x7.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// 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.Collections;
using System.Collections.Generic;
using System.Device.I2c;
using System.Threading;

namespace Iot.Device.Display
{
/// <summary>
/// Represents an IS31FL3731 LED Matrix driver
/// </summary>
// Datasheet: https://cdn-shop.adafruit.com/product-files/3017/31FL3730.pdf
// Product: https://shop.pimoroni.com/products/microdot-phat
// Product: https://shop.pimoroni.com/products/led-dot-matrix-breakout
// Related repo: https://github.com/pimoroni/microdot-phat
public class BreakoutPair5x7 : IDisposable
{
private readonly Matrix3730 _matrixOne;
private readonly Matrix3730 _matrixTwo;
private readonly Matrix3730[] _pair = new Matrix3730[2];
private Is31fl3730 _is31fl3730;
private I2cDevice? _i2cDevice;

/// <summary>
/// Initialize IS31FL3730 device
/// </summary>
/// <param name="i2cDevice">The <see cref="System.Device.I2c.I2cDevice"/> to create with.</param>
public BreakoutPair5x7(I2cDevice? i2cDevice = null)
{
_i2cDevice = i2cDevice is not null ? i2cDevice : I2cDevice.Create(new(1, Is31fl3730.DefaultI2cAddress));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not using this pattern and always leave the creation of the I2cDevice to the caller. Reason is because bus may be different, ownership as well and finally adaptors like FT4222 or Arduino. So don't pass the null as default and raise and exception if null.

_is31fl3730 = new(_i2cDevice);
_is31fl3730.DisplayMode = DisplayMode.MatrixOneAndTwo;
_is31fl3730.Initialize();
_matrixOne = new Matrix3730(_is31fl3730, 0);
_matrixTwo = new Matrix3730(_is31fl3730, 1);
_pair = new Matrix3730[] { _matrixOne, _matrixTwo };
}

/// <summary>
/// Initialize IS31FL3730 device
/// </summary>
/// <param name="is31fl3730">The <see cref="Iot.Device.Display.Is31fl3730"/> to create with.</param>
public BreakoutPair5x7(Is31fl3730 is31fl3730)
{
_is31fl3730 = is31fl3730;
_matrixOne = new Matrix3730(_is31fl3730, 0);
_matrixTwo = new Matrix3730(_is31fl3730, 1);
_pair = new Matrix3730[] { _matrixOne, _matrixTwo };
}

/// <summary>
/// Indexer for matrix pair.
/// </summary>
public Matrix3730 this[int matrix]
{
get => _pair[matrix];
}

/// <summary>
/// Default I2C address for device.
/// </summary>
public const int DefaultI2cAddress = 0x61;

/// <summary>
/// Width of LED matrix (x axis).
/// </summary>
public readonly int Width = 10;

/// <summary>
/// Height of LED matrix (y axis).
/// </summary>
public readonly int Height = 7;

/// <summary>
/// Identification of matrix (of 2).
/// </summary>
public readonly int Matrix = 0;

/// <summary>
/// Fill All LEDs.
/// </summary>
public void Fill(int value) => _is31fl3730.FillAll(value);

/// <inheritdoc/>
public void Dispose()
{
_is31fl3730?.Dispose();
_is31fl3730 = null!;
_i2cDevice?.Dispose();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the pattern we are using, as we don't create I2cDevice in the bindings, we don't dispose them. It's to the caller to take care of this.

_i2cDevice = null!;
}
}
}
48 changes: 48 additions & 0 deletions src/devices/Is31fl3730/Current.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.Threading;
using System.Threading.Tasks;
using System.Device.Gpio;
using System.Device.Spi;
using Iot.Device.Multiplexing.Utility;

namespace Iot.Device.Display
{
/// <summary>
/// Represents an IS31FL3731 LED Matrix driver
/// </summary>
public enum Current
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation is apparently wrong. Should be something about (maximum?) LED current.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I copied the text from the datasheet.

{
/// <summary>
/// 5 mA
/// </summary>
MA5 = 0b1000,

/// <summary>
/// 10 mA
/// </summary>
MA10 = 0b1001,

/// <summary>
/// 35 mA
/// </summary>
MA35 = 0b1110,

/// <summary>
/// 10 mA
/// </summary>
MA40 = 0b0,

/// <summary>
/// 10 mA
/// </summary>
MA45 = 0b0001,

/// <summary>
/// 40 mA
/// </summary>
MA75 = 0b0111,
}
}
33 changes: 33 additions & 0 deletions src/devices/Is31fl3730/DisplayMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.Threading;
using System.Threading.Tasks;
using System.Device.Gpio;
using System.Device.Spi;
using Iot.Device.Multiplexing.Utility;

namespace Iot.Device.Display
{
/// <summary>
/// Represents an IS31FL3731 LED Matrix driver
/// </summary>
public enum DisplayMode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again: This documentation doesn't describe the enum

{
/// <summary>
/// Enable matrix one only.
/// </summary>
MatrixOneOnly = 0x0,

/// <summary>
/// Enable matrix two only.
/// </summary>
MatrixTwoOnly = 0x8,

/// <summary>
/// Enable matrix one and two.
/// </summary>
MatrixOneAndTwo = 0x18,
}
}
Loading