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 support for v3 hardware #34

Merged
merged 4 commits into from
Oct 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
Binary file added Hardware/Schematic_v1.pdf
Binary file not shown.
Binary file added Hardware/Schematic_v2.c.pdf
Binary file not shown.
Binary file added Hardware/Schematic_v3.b.pdf
Binary file not shown.
18 changes: 18 additions & 0 deletions Source/Juego.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meadow.Modbus", "..\..\Mead
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet", "..\..\MQTTnet\Source\MQTTnet\MQTTnet.csproj", "{20EC73F2-5F86-40DB-8FEA-4B60BFE3D7EA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sensors.Motion.Bmi270", "..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\Sensors.Motion.Bmi270\Driver\Sensors.Motion.Bmi270.csproj", "{638A262A-E4F3-4D86-9E34-21717F928D79}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Audio.MicroAudio", "..\..\Meadow.Foundation\Source\Meadow.Foundation.Libraries_and_Frameworks\Audio.MicroAudio\Driver\Audio.MicroAudio.csproj", "{8E8CE3FA-D9D8-4912-A76D-F8017A7AEBC7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -135,6 +139,18 @@ Global
{20EC73F2-5F86-40DB-8FEA-4B60BFE3D7EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20EC73F2-5F86-40DB-8FEA-4B60BFE3D7EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20EC73F2-5F86-40DB-8FEA-4B60BFE3D7EA}.Release|Any CPU.Build.0 = Release|Any CPU
{638A262A-E4F3-4D86-9E34-21717F928D79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{638A262A-E4F3-4D86-9E34-21717F928D79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{638A262A-E4F3-4D86-9E34-21717F928D79}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{638A262A-E4F3-4D86-9E34-21717F928D79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{638A262A-E4F3-4D86-9E34-21717F928D79}.Release|Any CPU.Build.0 = Release|Any CPU
{638A262A-E4F3-4D86-9E34-21717F928D79}.Release|Any CPU.Deploy.0 = Release|Any CPU
{8E8CE3FA-D9D8-4912-A76D-F8017A7AEBC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E8CE3FA-D9D8-4912-A76D-F8017A7AEBC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E8CE3FA-D9D8-4912-A76D-F8017A7AEBC7}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{8E8CE3FA-D9D8-4912-A76D-F8017A7AEBC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E8CE3FA-D9D8-4912-A76D-F8017A7AEBC7}.Release|Any CPU.Build.0 = Release|Any CPU
{8E8CE3FA-D9D8-4912-A76D-F8017A7AEBC7}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -154,6 +170,8 @@ Global
{7D611BC9-B5BF-424C-A03C-3FC7FA8E703A} = {FF570CB7-3F54-4049-A167-304A90098DB6}
{D1FD4798-703D-4199-940C-4EDC516E88FC} = {FF570CB7-3F54-4049-A167-304A90098DB6}
{20EC73F2-5F86-40DB-8FEA-4B60BFE3D7EA} = {FF570CB7-3F54-4049-A167-304A90098DB6}
{638A262A-E4F3-4D86-9E34-21717F928D79} = {FF570CB7-3F54-4049-A167-304A90098DB6}
{8E8CE3FA-D9D8-4912-A76D-F8017A7AEBC7} = {FF570CB7-3F54-4049-A167-304A90098DB6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CB582CC6-C626-484E-9742-43FD65FE8158}
Expand Down
15 changes: 13 additions & 2 deletions Source/Juego/IJuegoHardware.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using Meadow.Foundation.Audio;
using Meadow.Foundation.Graphics;
using Meadow.Foundation.Leds;
using Meadow.Foundation.Sensors.Accelerometers;
using Meadow.Foundation.Sensors.Buttons;
using Meadow.Hardware;

namespace WildernessLabs.Hardware.Juego
{
/// <summary>
/// Represents the hardware interface for the Juego device.
/// Represents the hardware interface for the Juego device
/// </summary>
public interface IJuegoHardware
{
/// <summary>
/// Gets the graphics display interface.
/// Gets the graphics display interface
/// </summary>
public IGraphicsDisplay? Display { get; }

Expand Down Expand Up @@ -74,9 +75,19 @@ public interface IJuegoHardware
/// </summary>
public PwmLed? BlinkyLed { get; }

/// <summary>
/// Gets the motion sensor
/// </summary>
public Bmi270? MotionSensor { get; }

/// <summary>
/// Gets the display header connector
/// </summary>
public DisplayConnector DisplayHeader { get; }

/// <summary>
/// Gets the Stemma QT I2C Qwiic connector
/// </summary>
public I2cConnector? Qwiic { get; }
}
}
55 changes: 50 additions & 5 deletions Source/Juego/Juego.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
using Meadow;
using Meadow.Foundation.Audio;
using Meadow.Foundation.ICs.IOExpanders;
using Meadow.Logging;
using System;

namespace WildernessLabs.Hardware.Juego
{
/// <summary>
/// Juego hardware factory class for Juego v1, v2, and v3 hardware
/// </summary>
public class Juego
{
private Juego() { }

/// <summary>
/// Create an instance of the Juego class
/// Create an instance of the Juego class for the current hardware
/// </summary>
public static IJuegoHardware Create()
public static IJuegoHardware? Create()
{
IJuegoHardware hardware;
IJuegoHardware? hardware;
Logger? logger = Resolver.Log;

logger?.Debug("Initializing Juego...");
Expand All @@ -35,8 +40,48 @@ public static IJuegoHardware Create()
}
else if (device is IF7CoreComputeMeadowDevice { } ccm)
{
logger?.Info("Instantiating Juego v2 hardware");
hardware = new JuegoHardwareV2(ccm);
try
{
// hack for PWM init bug .... move back into the hardware classes once it's fixed
Copy link
Contributor

Choose a reason for hiding this comment

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

id put a ToDo here to not forget to change this.

var leftSpeaker = new PiezoSpeaker(ccm.Pins.PB8);
var rightSpeaker = new PiezoSpeaker(ccm.Pins.PB9);

var i2cBus = ccm.CreateI2cBus(busSpeed: Meadow.Hardware.I2cBusSpeed.FastPlus);
logger?.Info("I2C Bus instantiated");

var mcpVersion = new Mcp23008(i2cBus, address: 0x23);

logger?.Trace("McpVersion up");
var version = mcpVersion.ReadFromPorts();

logger?.Info($"Hardware version is {version}");

if (version >= JuegoHardwareV3.MinimumHardareVersion)
{
logger?.Info("Instantiating Juego v3 hardware");
hardware = new JuegoHardwareV3(ccm, i2cBus)
{
Mcp_VersionInfo = mcpVersion,
LeftSpeaker = leftSpeaker,
RightSpeaker = rightSpeaker,
};
}
else
{
logger?.Info("Instantiating Juego v2 hardware");
hardware = new JuegoHardwareV2(ccm, i2cBus)
{
Mcp_VersionInfo = mcpVersion,
LeftSpeaker = leftSpeaker,
RightSpeaker = rightSpeaker,
};
}
}
catch (Exception e)
{
logger?.Debug($"Failed to create McpVersion: {e.Message}");
hardware = null;
}
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions Source/Juego/Juego.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Meadow.Core\Source\implementations\f7\Meadow.F7\Meadow.F7.csproj" />
<ProjectReference Include="..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Libraries_and_Frameworks\Audio.MicroAudio\Driver\Audio.MicroAudio.csproj" />
<ProjectReference Include="..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\Displays.TftSpi\Driver\Displays.TftSpi.csproj" />
<ProjectReference Include="..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\ICs.IOExpanders.Mcp23xxx\Driver\ICs.IOExpanders.Mcp23xxx.csproj" />
<ProjectReference Include="..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\Sensors.Motion.Bmi270\Driver\Sensors.Motion.Bmi270.csproj" />
</ItemGroup>
</Project>
41 changes: 33 additions & 8 deletions Source/Juego/JuegoHardwareV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Meadow.Foundation.Displays;
using Meadow.Foundation.Graphics;
using Meadow.Foundation.Leds;
using Meadow.Foundation.Sensors.Accelerometers;
using Meadow.Foundation.Sensors.Buttons;
using Meadow.Foundation.Sensors.Hid;
using Meadow.Hardware;
Expand All @@ -11,39 +12,60 @@

namespace WildernessLabs.Hardware.Juego
{
/// <summary>
/// Represents the hardware interface for the Juego v1 device
/// </summary>
public class JuegoHardwareV1 : IJuegoHardware
{
/// <inheritdoc/>
protected IF7FeatherMeadowDevice Device { get; }

/// <inheritdoc/>
public IGraphicsDisplay Display { get; }

/// <inheritdoc/>
protected ISpiBus SpiBus { get; }

/// <inheritdoc/>
public AnalogJoystick? AnalogJoystick { get; protected set; }

/// <inheritdoc/>
public PushButton? Right_UpButton { get; protected set; }
/// <inheritdoc/>
public PushButton? Right_DownButton { get; protected set; }
/// <inheritdoc/>
public PushButton? Right_LeftButton { get; protected set; }
/// <inheritdoc/>
public PushButton? Right_RightButton { get; protected set; }

/// <inheritdoc/>
public PushButton? Left_UpButton => null;
/// <inheritdoc/>
public PushButton? Left_DownButton => null;
/// <inheritdoc/>
public PushButton? Left_LeftButton => null;
/// <inheritdoc/>
public PushButton? Left_RightButton => null;

/// <inheritdoc/>
public PushButton? StartButton { get; protected set; }
/// <inheritdoc/>
public PushButton? SelectButton { get; protected set; }

/// <inheritdoc/>
public PiezoSpeaker? LeftSpeaker { get; protected set; }
/// <inheritdoc/>
public PiezoSpeaker? RightSpeaker { get; protected set; }

/// <inheritdoc/>
public PwmLed? BlinkyLed => null;

/// <summary>
/// Gets the display header connector on the Juego board
/// </summary>
/// <inheritdoc/>
public Bmi270? MotionSensor => null;

/// <inheritdoc/>
public DisplayConnector DisplayHeader => (DisplayConnector)Connectors[0];

/// <inheritdoc/>
public I2cConnector Qwiic => null;


/// <summary>
/// Collection of connectors on the Juego board
/// </summary>
Expand All @@ -54,7 +76,7 @@ public IConnector?[] Connectors
if (_connectors == null)
{
_connectors = new IConnector[1];
_connectors[1] = CreateDisplayConnector();
_connectors[0] = CreateDisplayConnector();
}

return _connectors;
Expand All @@ -63,6 +85,9 @@ public IConnector?[] Connectors

private IConnector?[]? _connectors;

/// <summary>
/// Create a new Juego hardware v1 object
/// </summary>
public JuegoHardwareV1(IF7FeatherMeadowDevice device)
{
Device = device;
Expand Down
Loading
Loading