Skip to content
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
51 changes: 27 additions & 24 deletions Source/Meadow.ProjectLab/ProjectLab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,23 @@ public abstract class ProjectLabCoreComputeApp : App<F7CoreComputeV2, ProjectLab
{
}

/// <summary>
/// A base class for F7 Core Compute (v5)-based, Project Lab-targeted applications
/// </summary>
public abstract class ProjectLabV5App : App<F7CoreComputeV2, ProjectLabV5, IProjectLabHardware>
{
}

/// <summary>
/// Represents Project Lab hardware and exposes its peripherals
/// </summary>
public class ProjectLabV5 : ProjectLab
{
protected override IPin GetMcpResetPin(IF7CoreComputeMeadowDevice ccm)
{
return ccm.Pins.PB4;
//return ccm.Pins.PH10;
}
}

/// <summary>
/// Represents Project Lab hardware and exposes its peripherals
/// </summary>
public class ProjectLab : IMeadowAppEmbeddedHardwareProvider<IProjectLabHardware>
{
private static IProjectLabHardware? _instance;

protected ProjectLab() { }
internal ProjectLab() { }

protected virtual IPin GetMcpResetPin(IF7CoreComputeMeadowDevice ccm)
internal virtual IPin GetMcpResetPin1(IF7CoreComputeMeadowDevice ccm)
{
return ccm.Pins.PB4; // this is where it is on the 4.e
return ccm.Pins.PH10; // this is where it is on the 3.x and 5.b+
}

internal virtual IPin GetMcpResetPin2(IF7CoreComputeMeadowDevice ccm)
{
return ccm.Pins.PB4; // this is where it is on the 4.e and 5.a
}

/// <summary>
Expand Down Expand Up @@ -114,7 +100,7 @@ public IProjectLabHardware Create(IMeadowDevice device)
{
try
{
var reset = GetMcpResetPin(c);
var reset = GetMcpResetPin1(c);
Resolver.Log.Info($"Using MCP reset pin {reset.Name}");
mcpReset = device.CreateDigitalOutputPort(reset);

Expand All @@ -125,7 +111,24 @@ public IProjectLabHardware Create(IMeadowDevice device)
}
catch
{
logger?.Debug("Failed to create version MCP: could be a v3 board");
mcpReset?.Dispose();
mcp = null;

try
{
var reset = GetMcpResetPin2(c);
Resolver.Log.Info($"Using MCP reset pin {reset.Name}");
mcpReset = device.CreateDigitalOutputPort(reset);

mcp = new Mcp23008(i2cBus, address: 0x27, resetPort: mcpReset);

logger?.Trace("Mcp_version up");
version = mcp.ReadFromPorts();
}
catch
{
logger?.Debug("Failed to create version MCP: could be a v3 board");
}
}
finally
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Meadow.ProjectLab/ProjectLabHardwareBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ public IPixelDisplay? Display

internal abstract DisplayConnector CreateDisplayConnector();

private readonly object _syncRoot = new object();
internal readonly object _syncRoot = new object();

/// <summary>
/// Collection of connectors on the Project Lab board
/// </summary>
public IConnector?[] Connectors
public virtual IConnector?[] Connectors
{
get
{
Expand Down
27 changes: 27 additions & 0 deletions Source/Meadow.ProjectLab/ProjectLabHardwareV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,33 @@ private void InitializeBme688()
return _rgbled;
}

/// <summary>
/// Collection of connectors on the Project Lab board
/// </summary>
public override IConnector?[] Connectors
{
get
{
lock (_syncRoot)
{
if (_connectors == null)
{
_connectors = new IConnector[8];
_connectors[0] = CreateMikroBus1();
_connectors[1] = CreateMikroBus2();
_connectors[2] = CreateGroveDigitalConnector();
_connectors[3] = CreateGroveAnalogConnector();
_connectors[4] = CreateGroveUartConnector();
_connectors[5] = CreateQwiicConnector();
_connectors[6] = CreateIOTerminalConnector();
_connectors[7] = CreateDisplayConnector();
}

return _connectors;
}
}
}

internal override MikroBusConnector CreateMikroBus1()
{
Logger?.Trace("Creating MikroBus1 connector");
Expand Down
27 changes: 27 additions & 0 deletions Source/Meadow.ProjectLab/ProjectLabHardwareV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,33 @@ private void InitializeBme688()
return _rgbled;
}

/// <summary>
/// Collection of connectors on the Project Lab board
/// </summary>
public override IConnector?[] Connectors
{
get
{
lock (_syncRoot)
{
if (_connectors == null)
{
_connectors = new IConnector[8];
_connectors[0] = CreateMikroBus1();
_connectors[1] = CreateMikroBus2();
_connectors[2] = CreateGroveDigitalConnector();
_connectors[3] = CreateGroveAnalogConnector();
_connectors[4] = CreateGroveUartConnector();
_connectors[5] = CreateQwiicConnector();
_connectors[6] = CreateIOTerminalConnector();
_connectors[7] = CreateDisplayConnector();
}

return _connectors;
}
}
}

internal override MikroBusConnector CreateMikroBus1()
{
Logger?.Trace("Creating MikroBus1 connector");
Expand Down
9 changes: 6 additions & 3 deletions Source/Meadow.ProjectLab/ProjectLabHardwareV5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Meadow.Devices;
/// </summary>
public class ProjectLabHardwareV5 : ProjectLabHardwareBase
{
private readonly IF7CoreComputeMeadowDevice _device;
internal readonly IF7CoreComputeMeadowDevice _device;
private IToneGenerator? _speaker;
private IRgbPwmLed? _rgbled;
private readonly ITouchScreen? _touchscreen;
Expand Down Expand Up @@ -99,7 +99,7 @@ internal ProjectLabHardwareV5(IF7CoreComputeMeadowDevice device, II2cBus i2cBus)
{
mcp1Interrupt = device.CreateDigitalInterruptPort(device.Pins.PC0, InterruptMode.EdgeRising);

mcp1Reset = device.CreateDigitalOutputPort(device.Pins.PB4);
mcp1Reset = device.CreateDigitalOutputPort(GetVersionResetPin(device));

Mcp_1 = new Mcp23008(i2cBus, address: 0x20, mcp1Interrupt, mcp1Reset);

Expand Down Expand Up @@ -147,8 +147,11 @@ internal ProjectLabHardwareV5(IF7CoreComputeMeadowDevice device, II2cBus i2cBus)
var downPort = Mcp_1?.CreateDigitalInterruptPort(Mcp_1.Pins.GP3, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp);
if (downPort != null) DownButton = new PushButton(downPort);
Logger?.Trace("Buttons up");
}


internal virtual IPin GetVersionResetPin(IF7CoreComputeMeadowDevice device)
{
return device.Pins.PB4;
}

/// <inheritdoc/>
Expand Down
45 changes: 45 additions & 0 deletions Source/Meadow.ProjectLab/ProjectLabHardwareV5a.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Meadow.Hardware;
using System.Diagnostics;

namespace Meadow.Devices;

/// <summary>
/// Represents Project Lab V5a hardware and exposes its peripherals
/// </summary>
internal class ProjectLabHardwareV5a : ProjectLabHardwareV5
{
internal ProjectLabHardwareV5a(IF7CoreComputeMeadowDevice device, II2cBus i2cBus) : base(device, i2cBus)
{
}

internal override IPin GetVersionResetPin(IF7CoreComputeMeadowDevice device)
{
return device.Pins.PH10;
}

internal override DisplayConnector CreateDisplayConnector()
{
Logger?.Trace("Creating display connector");
Debug.Assert(Mcp_1 != null, nameof(Mcp_1) + " != null");
Debug.Assert(Mcp_2 != null, nameof(Mcp_2) + " != null");

return new DisplayConnector(
nameof(Display),
new PinMapping
{
new PinMapping.PinAlias(DisplayConnector.PinNames.DISPLAY_CS, _device.Pins.PB4),
new PinMapping.PinAlias(DisplayConnector.PinNames.DISPLAY_RST, _device.Pins.PB8),
new PinMapping.PinAlias(DisplayConnector.PinNames.DISPLAY_DC, _device.Pins.PI11),
new PinMapping.PinAlias(DisplayConnector.PinNames.DISPLAY_CLK, _device.Pins.SPI5_SCK),
new PinMapping.PinAlias(DisplayConnector.PinNames.DISPLAY_COPI, _device.Pins.SPI5_COPI),
new PinMapping.PinAlias(DisplayConnector.PinNames.DISPLAY_LED, Mcp_1.Pins.GP5),
new PinMapping.PinAlias(DisplayConnector.PinNames.TOUCH_INT, Mcp_2.Pins.GP0),
new PinMapping.PinAlias(DisplayConnector.PinNames.TOUCH_CLK, _device.Pins.I2C1_SCL),
new PinMapping.PinAlias(DisplayConnector.PinNames.TOUCH_SDA, _device.Pins.I2C1_SDA),
new PinMapping.PinAlias(DisplayConnector.PinNames.TOUCH_RST, Mcp_1.Pins.GP6),
},
new SpiBusMapping(_device, _device.Pins.SPI5_SCK, _device.Pins.SPI5_COPI, _device.Pins.SPI5_CIPO),
new I2cBusMapping(_device, 1)
);
}
}
4 changes: 2 additions & 2 deletions Source/ProjectLab_Demo/DisplayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public DisplayController(IPixelDisplay display, string revisionVersion)
HorizontalAlignment = HorizontalAlignment.Center
});

displayScreen.Controls.Add(CreateLeftLabel("Temperature:", atmosphericColor, rowMargin, rowOffset, displayScreen.Width, rowHeight));
displayScreen.Controls.Add(CreateLeftLabel(displayScreen.Width == 240 ? "Temp:" : "Temperature:", atmosphericColor, rowMargin, rowOffset, displayScreen.Width, rowHeight));
displayScreen.Controls.Add(CreateLeftLabel("Pressure:", atmosphericColor, rowMargin, rowOffset + rowHeight, displayScreen.Width, rowHeight));
displayScreen.Controls.Add(CreateLeftLabel("Humidity:", atmosphericColor, rowMargin, rowOffset + rowHeight * 2, displayScreen.Width, rowHeight));
displayScreen.Controls.Add(CreateLeftLabel("Illuminance:", atmosphericColor, rowMargin, rowOffset + rowHeight * 3, displayScreen.Width, rowHeight));
displayScreen.Controls.Add(CreateLeftLabel(displayScreen.Width == 240 ? "Light:" : "Illuminance:", atmosphericColor, rowMargin, rowOffset + rowHeight * 3, displayScreen.Width, rowHeight));
displayScreen.Controls.Add(CreateLeftLabel("Accel:", motionColor, rowMargin, rowOffset + rowHeight * 4, displayScreen.Width, rowHeight));
displayScreen.Controls.Add(CreateLeftLabel("Gyro:", motionColor, rowMargin, rowOffset + rowHeight * 5, displayScreen.Width, rowHeight));
displayScreen.Controls.Add(CreateLeftLabel("Up:", buttonColor, rowMargin, rowOffset + rowHeight * 6, displayScreen.Width, rowHeight));
Expand Down
3 changes: 1 addition & 2 deletions Source/ProjectLab_Demo/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ namespace ProjectLab_Demo;

// Change to ProjectLabFeatherApp for Project Lab V1 or V2
// Change to ProjectLabCoreComputeApp for Project Lab V3+
// public class MeadowApp : ProjectLabCoreComputeApp // <-- this is for V3/v4
public class MeadowApp : ProjectLabV5App // this is for v5+
public class MeadowApp : ProjectLabCoreComputeApp
{
private DisplayController? displayController;

Expand Down
Loading