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

Mirid v2 docs updates + xml comments #1112

Merged
merged 12 commits into from
Jan 12, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ private void ExecutePlatformDisplayRunner()
sd.Run();
}
MeadowOS.TerminateRun();
System.Environment.Exit(0);
Environment.Exit(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>App</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
<None Include="..\..\..\icon.png" Pack="true" PackagePath="" />
<ProjectReference Include="..\..\..\Meadow.Foundation.Core\Meadow.Foundation.Core.csproj" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,33 @@ namespace Meadow.Foundation.ICs.CAN;

public partial class Mcp2515
{
/// <summary>
/// Represents the available CAN oscillator frequencies.
/// </summary>
public enum CanOscillator
{
/// <summary>
/// 8 MHz oscillator frequency.
/// </summary>
Osc_8MHz = 8_000_000,

/// <summary>
/// 10 MHz oscillator frequency.
/// </summary>
Osc_10MHz = 10_000_000,

/// <summary>
/// 16 MHz oscillator frequency.
/// </summary>
Osc_16MHz = 16_000_000,

/// <summary>
/// 20 MHz oscillator frequency.
/// </summary>
Osc_20MHz = 20_000_000,
}


private enum Register : byte
{
RXF0SIDH = 0x00,
Expand Down Expand Up @@ -237,4 +256,4 @@ private enum TxRtsSettings : byte
private const int CAN_ERR_FLAG = 0x20000000;

private const byte RXBnCTRL_RTR = 0x08;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Meadow.Hardware;
using Peak.Can.Basic.BackwardCompatibility;

namespace ICs.IOExpanders.PCanBasic;
namespace Meadow.Foundation.ICs.CAN;

/// <summary>
/// Represents a PCAN Basic
/// </summary>
public class PCanBus : ICanBus
public class PCanBasic : ICanBus
{
/// <inheritdoc/>
public event EventHandler<ICanFrame>? FrameReceived;
Expand All @@ -18,7 +18,7 @@ public class PCanBus : ICanBus

private PCanConfiguration configuration;

internal PCanBus(PCanConfiguration configuration)
internal PCanBasic(PCanConfiguration configuration)
{
var result = PCANBasic.Initialize(
configuration.BusHandle,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Meadow.Hardware;
using Peak.Can.Basic.BackwardCompatibility;

namespace Meadow.Foundation.ICs.CAN;

/// <summary>
/// Represents the configuration settings for a PCAN device, including the bus handle and bitrate.
/// </summary>
public class PCanConfiguration
{
/// <summary>
/// Gets or sets the handle for the CAN bus.
/// Default value is <see cref="PCANBasic.PCAN_USBBUS1"/>.
/// </summary>
/// <remarks>
/// This handle corresponds to the specific PCAN device to be used, such as a USB or other supported interface.
/// </remarks>
public ushort BusHandle { get; set; } = PCANBasic.PCAN_USBBUS1;

/// <summary>
/// Gets or sets the bitrate for the CAN communication.
/// Default value is <see cref="CanBitrate.Can_250kbps"/>.
/// </summary>
/// <remarks>
/// The bitrate determines the speed of communication on the CAN bus. Common values include 125kbps, 250kbps, and 500kbps.
/// </remarks>
public CanBitrate Bitrate { get; set; } = CanBitrate.Can_250kbps;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Meadow.Hardware;
using Peak.Can.Basic.BackwardCompatibility;

namespace ICs.IOExpanders.PCanBasic;
namespace Meadow.Foundation.ICs.CAN;

internal static class PCanExtensions
{
Expand All @@ -26,4 +26,4 @@ internal static TPCANBaudrate ToPCANBaudrate(this CanBitrate bitrate)
_ => throw new NotSupportedException()
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using Meadow.Hardware;

namespace Meadow.Foundation.ICs.CAN;

/// <summary>
/// Represents a PCAN FD (Flexible Data Rate) CAN bus implementation.
/// </summary>
/// <remarks>
/// This class provides functionality to interact with a PCAN FD CAN bus, including sending and receiving frames, managing filters, and handling bus errors.
/// </remarks>
public class PCanFdBus : ICanBus
{
/// <summary>
/// Occurs when a CAN frame is received on the bus.
/// </summary>
/// <remarks>
/// This event provides access to the received <see cref="ICanFrame"/> object.
/// </remarks>
public event EventHandler<ICanFrame>? FrameReceived;

/// <summary>
/// Occurs when a bus error is detected.
/// </summary>
/// <remarks>
/// This event provides access to detailed error information through a <see cref="CanErrorInfo"/> object.
/// </remarks>
public event EventHandler<CanErrorInfo>? BusError;

/// <summary>
/// Initializes a new instance of the <see cref="PCanFdBus"/> class using the specified configuration.
/// </summary>
/// <param name="configuration">The configuration settings for the PCAN FD bus.</param>
/// <exception cref="NotImplementedException">This constructor is not yet implemented.</exception>
internal PCanFdBus(PCanConfiguration configuration)
{
throw new NotImplementedException();
}

/// <summary>
/// Gets or sets the bitrate for the CAN bus.
/// </summary>
/// <exception cref="NotImplementedException">This property is not yet implemented.</exception>
public CanBitrate BitRate
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}

/// <summary>
/// Gets the collection of acceptance filters for the CAN bus.
/// </summary>
/// <remarks>
/// Acceptance filters allow specific CAN frames to be received while ignoring others.
/// </remarks>
/// <exception cref="NotImplementedException">This property is not yet implemented.</exception>
public CanAcceptanceFilterCollection AcceptanceFilters => throw new NotImplementedException();

/// <summary>
/// Clears all receive buffers on the CAN bus.
/// </summary>
/// <exception cref="NotImplementedException">This method is not yet implemented.</exception>
public void ClearReceiveBuffers()
{
throw new NotImplementedException();
}

/// <summary>
/// Checks if a CAN frame is available in the receive buffer.
/// </summary>
/// <returns><c>true</c> if a frame is available; otherwise, <c>false</c>.</returns>
/// <exception cref="NotImplementedException">This method is not yet implemented.</exception>
public bool IsFrameAvailable()
{
throw new NotImplementedException();
}

/// <summary>
/// Reads a CAN frame from the receive buffer.
/// </summary>
/// <returns>The received <see cref="ICanFrame"/>, or <c>null</c> if no frame is available.</returns>
/// <exception cref="NotImplementedException">This method is not yet implemented.</exception>
public ICanFrame? ReadFrame()
{
throw new NotImplementedException();
}

/// <summary>
/// Sets a filter for incoming CAN frames.
/// </summary>
/// <param name="filter">The filter to apply.</param>
/// <exception cref="NotImplementedException">This method is not yet implemented.</exception>
public void SetFilter(int filter)
{
throw new NotImplementedException();
}

/// <summary>
/// Sets a mask for filtering incoming CAN frames.
/// </summary>
/// <param name="filter">The mask to apply.</param>
/// <exception cref="NotImplementedException">This method is not yet implemented.</exception>
public void SetMask(int filter)
{
throw new NotImplementedException();
}

/// <summary>
/// Writes a CAN frame to the bus.
/// </summary>
/// <param name="frame">The <see cref="ICanFrame"/> to write to the bus.</param>
/// <exception cref="NotImplementedException">This method is not yet implemented.</exception>
public void WriteFrame(ICanFrame frame)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Meadow.Hardware;
using Peak.Can.Basic.BackwardCompatibility;

namespace Meadow.Foundation.ICs.CAN;

/// <summary>
/// Represents a PCAN USB CAN controller implementation.
/// </summary>
/// <remarks>
/// This class provides functionality to create CAN buses for PCAN USB devices.
/// Note that this implementation is only supported on Windows and requires the PCANBasic DLL.
/// </remarks>
public class PCanUsb : ICanController
{
/// <summary>
/// Initializes a new instance of the <see cref="PCanUsb"/> class.
/// </summary>
/// <remarks>
/// This constructor checks for PCAN USB compatibility and assumes the presence of the PCANBasic DLL.
/// </remarks>
public PCanUsb()
{
// TODO: only supported on Windows
// TODO: check for PCANBasic DLL
}

/// <summary>
/// Creates a CAN bus with the specified bitrate and bus number.
/// </summary>
/// <param name="bitrate">The bitrate to configure for the CAN bus.</param>
/// <param name="busNumber">
/// The bus number to use for the CAN interface. Defaults to 0, corresponding to <see cref="PCANBasic.PCAN_USBBUS1"/>.
/// </param>
/// <returns>
/// An instance of <see cref="ICanBus"/> configured for the specified bitrate and bus number.
/// </returns>
/// <remarks>
/// If the specified bitrate is <see cref="CanBitrate.Can_FD"/>, the returned bus will support Flexible Data Rate (CAN FD).
/// Otherwise, a standard CAN bus will be created.
/// </remarks>
/// <exception cref="NotImplementedException">
/// Thrown if the method is invoked without implementing the required functionality.
/// </exception>
public ICanBus CreateCanBus(CanBitrate bitrate, int busNumber = 0)
{
var config = new PCanConfiguration
{
Bitrate = bitrate,
BusHandle = (ushort)(PCANBasic.PCAN_USBBUS1 + busNumber)
};

if (bitrate == CanBitrate.Can_FD)
{
return new PCanFdBus(config);
}
else
{
return new PCanBasic(config);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Driver\ICs.IOExpanders.PCanBasic.csproj" />
<ProjectReference Include="..\..\Driver\ICs.CAN.PCanBasic.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using ICs.IOExpanders.PCanBasic;
using Meadow.Foundation.ICs.CAN;
using Meadow.Hardware;

namespace PCanBasic_ReadSample;
namespace PCanBus_ReadSample;

internal class Program
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Meadow.Sdk/1.1.0">
<Project Sdk="Meadow.Sdk/1.1.0">
<PropertyGroup>
<Version>1.14.0</Version>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
Expand All @@ -24,4 +24,4 @@
<None Include="..\..\..\icon.png" Pack="true" PackagePath="" />
<ProjectReference Include="..\..\..\Meadow.Foundation.Core\Meadow.Foundation.Core.csproj" />
</ItemGroup>
</Project>
</Project>

This file was deleted.

Loading
Loading