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

V1.4.0 #36

Closed
wants to merge 9 commits into from
Closed
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.
102 changes: 102 additions & 0 deletions Source/Juego/DisplayConnector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using static Meadow.Hardware.DisplayConnector;

namespace Meadow.Hardware;

/// <summary>
/// Represents the display connector on Juego
/// </summary>
public class DisplayConnector : Connector<DisplayConnectorPinDefinitions>
{
/// <summary>
/// The set of Display connector connector pins
/// </summary>
public static class PinNames
{
/// <summary>
/// Chip Select pin
/// </summary>
public const string CS = "CS";
/// <summary>
/// Reset pin
/// </summary>
public const string RST = "RST";
/// <summary>
/// Data/Command pin
/// </summary>
public const string DC = "DC";
/// <summary>
/// SPI Clock pin
/// </summary>
public const string CLK = "CLK";
/// <summary>
/// SPI controller ouy, peripheral in pin
/// </summary>
public const string COPI = "COPI";
}

/// <summary>
/// Represents the pins definitions for the Display connector on Juego
/// </summary>
public class DisplayConnectorPinDefinitions : PinDefinitionBase
{
private readonly IPin? _cs;
private readonly IPin? _rst;
private readonly IPin? _dc;
private readonly IPin? _clk;
private readonly IPin? _copi;

/// <summary>
/// Chip Select pin
/// </summary>
public IPin CS => _cs ?? throw new PlatformNotSupportedException("Pin not connected");
/// <summary>
/// Reset pin
/// </summary>
public IPin RST => _rst ?? throw new PlatformNotSupportedException("Pin not connected");
/// <summary>
/// Data/Command pin
/// </summary>
public IPin DC => _dc ?? throw new PlatformNotSupportedException("Pin not connected");
/// <summary>
/// SPI Clock pin
/// </summary>
public IPin CLK => _clk ?? throw new PlatformNotSupportedException("Pin not connected");
/// <summary>
/// SPI controller in, peripheral out pin
/// </summary>
public IPin COPI => _copi ?? throw new PlatformNotSupportedException("Pin not connected");

internal DisplayConnectorPinDefinitions(PinMapping mapping)
{
foreach (var m in mapping)
{
switch (m.PinName)
{
case PinNames.CS:
_cs = m.ConnectsTo;
break;
case PinNames.RST:
_rst = m.ConnectsTo;
break;
case PinNames.DC:
_dc = m.ConnectsTo;
break;
case PinNames.CLK:
_clk = m.ConnectsTo;
break;
case PinNames.COPI:
_copi = m.ConnectsTo;
break;
}
}
}
}

/// <param name="name">The connector name</param>
/// <param name="mapping">The mappings to the host controller</param>
public DisplayConnector(string name, PinMapping mapping)
: base(name, new DisplayConnectorPinDefinitions(mapping))
{
}
}
63 changes: 63 additions & 0 deletions Source/Juego/IJuegoHardware.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,93 @@
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
/// </summary>
public interface IJuegoHardware
{
/// <summary>
/// Gets the graphics display interface
/// </summary>
public IGraphicsDisplay? Display { get; }

/// <summary>
/// Gets the right/up button
/// </summary>
public PushButton? Right_UpButton { get; }
/// <summary>
/// Gets the right/down button
/// </summary>
public PushButton? Right_DownButton { get; }
/// <summary>
/// Gets the right/left button
/// </summary>
public PushButton? Right_LeftButton { get; }
/// <summary>
/// Gets the right/right button
/// </summary>
public PushButton? Right_RightButton { get; }

/// <summary>
/// Gets the left/up button
/// </summary>
public PushButton? Left_UpButton { get; }
/// <summary>
/// Gets the left/down button
/// </summary>
public PushButton? Left_DownButton { get; }
/// <summary>
/// Gets the left/left button
/// </summary>
public PushButton? Left_LeftButton { get; }
/// <summary>
/// Gets the left/right button
/// </summary>
public PushButton? Left_RightButton { get; }

/// <summary>
/// Gets the start button
/// </summary>
public PushButton? StartButton { get; }
/// <summary>
/// Gets the select button
/// </summary>
public PushButton? SelectButton { get; }

// Speakers
/// <summary>
/// Gets the left speaker
/// </summary>
public PiezoSpeaker? LeftSpeaker { get; }
/// <summary>
/// Gets the right speaker
/// </summary>
public PiezoSpeaker? RightSpeaker { get; }

/// <summary>
/// Gets the PWM LED
/// </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
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>
<PackageReference Include="Meadow.F7" Version="*" />
<PackageReference Include="Meadow.Foundation.Audio.MicroAudio" Version="*" />
<PackageReference Include="Meadow.Foundation.Displays.TftSpi" Version="*" />
<PackageReference Include="Meadow.Foundation.ICs.IOExpanders.Mcp23xxx" Version="*" />
<PackageReference Include="Meadow.Foundation.Sensors.Motion.Bmi270" Version="*" />
</ItemGroup>
</Project>
Loading
Loading