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

Feature/ft23xx #908

Merged
merged 13 commits into from
Feb 22, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
namespace Meadow.Foundation.Graphics.MicroLayout;

public struct Coordinate2D
{
public int X { get; set; }
public int Y { get; set; }
}

/// <summary>
/// Represents a circle in the user interface.
/// </summary>
public class Circle : ThemedControl
{
private Color _foreColor;

/// <summary>
/// Gets or sets a value indicating whether the Circle is filled with the foreground color.
/// </summary>
public bool IsFilled { get; set; } = true;

/// <summary>
/// Initializes a new instance of the <see cref="Circle"/> class with the specified dimensions.
/// </summary>
/// <param name="centerX">The X coordinate of the circles's center.</param>
/// <param name="centerY">The Y coordinate of the circles's center.</param>
/// <param name="radius">The radius of the circle.</param>
public Circle(int centerX, int centerY, int radius)
: base(centerX - radius, centerY - radius, radius * 2, radius * 2)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="Circle"/> class with the specified dimensions.
/// </summary>
/// <param name="center">The coordinate of the circles's center.</param>
/// <param name="radius">The radius of the circle.</param>
public Circle(Coordinate2D center, int radius)
: base(center.X - radius, center.Y - radius, radius * 2, radius * 2)
{
}

/// <summary>
/// Applies the specified display theme to the Circle.
/// </summary>
/// <param name="theme">The display theme to apply.</param>
public override void ApplyTheme(DisplayTheme theme)
{
if (theme != null)
{
if (theme.ForegroundColor != null) this.ForeColor = theme.ForegroundColor.Value;
}
}

/// <summary>
/// Gets or sets the foreground color of the Circle.
/// </summary>
public Color ForeColor
{
get => _foreColor;
set => SetInvalidatingProperty(ref _foreColor, value);
}

/// <summary>
/// Gets or sets the foreground color of the Circle.
/// </summary>
public int Radius
{
get => Width / 2;
set
{
// keep centered
var coeff = (value > Radius) ? -1 : 1;
var offset = value - Radius;

Width = value * 2;
}
}

/// <summary>
/// Draws the Circle on the specified <see cref="MicroGraphics"/> surface.
/// </summary>
/// <param name="graphics">The <see cref="MicroGraphics"/> surface to draw the Circle on.</param>
protected override void OnDraw(MicroGraphics graphics)
{
if (ForeColor != Color.Transparent)
{
var radius = (Right - Left) / 2;
var centerX = Left + radius;
var centerY = Top + radius;
graphics.DrawCircle(centerX, centerY, radius, ForeColor, IsFilled);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override bool IsInputTypeSupported(InputType inputType)
/// </summary>
public IAnalogInputPort CreateAnalogInputPort(int sampleCount = 64)
{
return CreateAnalogInputPort(sampleCount, TimeSpan.FromSeconds(1), new Voltage(0));
return CreateAnalogInputPort(sampleCount, TimeSpan.FromSeconds(1), DefaultReferenceVoltage);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override bool IsInputTypeSupported(InputType inputType)
/// </summary>
public IAnalogInputPort CreateAnalogInputPort(int sampleCount = 64)
{
return CreateAnalogInputPort(sampleCount, TimeSpan.FromSeconds(1), new Voltage(0));
return CreateAnalogInputPort(sampleCount, TimeSpan.FromSeconds(1), DefaultReferenceVoltage);
}

/// <summary>
Expand Down Expand Up @@ -80,9 +80,7 @@ protected override int ReadInternal(int channel, InputType inputType, int adcRes
var data = (buffer[0] & 0x1f) << 8 | buffer[1];
// then shift back right 1 bit
var result = data >> 1;
Console.WriteLine($"raw: {result}");
return result;

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract partial class Mcp3xxx : IAnalogInputController, ISpiPeripheral,
/// <summary>
/// Did we create the port(s) used by the peripheral
/// </summary>
readonly bool createdPort = false;
private readonly bool createdPort = false;

/// <summary>
/// Gets the underlying ISpiCommunications instance
Expand All @@ -35,6 +35,11 @@ public abstract partial class Mcp3xxx : IAnalogInputController, ISpiPeripheral,
/// </summary>
public Frequency DefaultSpiBusSpeed => new(10000, Frequency.UnitType.Kilohertz);

/// <summary>
/// The default reference voltage for the device
/// </summary>
public Voltage DefaultReferenceVoltage => 3.3.Volts();

/// <summary>
/// The SPI bus speed for the device
/// </summary>
Expand Down Expand Up @@ -69,7 +74,7 @@ public SpiClockConfiguration.Mode SpiBusMode
/// </summary>
internal int AdcMaxValue { get; set; }

IDigitalOutputPort chipSelectPort;
private IDigitalOutputPort chipSelectPort;

/// <summary>
/// Mcp3xxx base class constructor
Expand Down Expand Up @@ -113,7 +118,7 @@ protected Mcp3xxx(ISpiBus spiBus,
/// <returns>An instance of <see cref="IAnalogInputPort"/> that represents the analog input on the specified pin</returns>
protected IAnalogInputPort CreateAnalogInputPort(IPin pin, int sampleCount = 64)
{
return CreateAnalogInputPort(pin, sampleCount, TimeSpan.FromSeconds(1), new Voltage(0));
return CreateAnalogInputPort(pin, sampleCount, TimeSpan.FromSeconds(1), DefaultReferenceVoltage);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Meadow.Hardware;
using System;

namespace Meadow.Foundation.ICs.IOExpanders;

public class Ft2232Expander : FtdiExpander
{
internal Ft2232Expander()
{
}

/// <inheritdoc/>
public override II2cBus CreateI2cBus(int channel = 0, I2cBusSpeed busSpeed = I2cBusSpeed.Standard)
{
// TODO: depends on part
// TODO: make sure no SPI is in use
var bus = new Ft23xxxI2cBus(this, busSpeed);
bus.Configure();
return bus;
}

/// <inheritdoc/>
public override ISpiBus CreateSpiBus(int channel, SpiClockConfiguration configuration)
{
// TODO: make sure no SPI is in use

throw new NotSupportedException();
}
}

This file was deleted.

Loading
Loading