-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from WildernessLabs/feature/can
Feature/can
- Loading branch information
Showing
16 changed files
with
303 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Source/Meadow.Contracts/Hardware/Contracts/IOControllers/ICanController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Contract for devices that expose `ICanBus(es)`. | ||
/// </summary> | ||
public interface ICanController | ||
{ | ||
/// <summary> | ||
/// Creates a CAN bus instance for the requested bus number and bus speed | ||
/// </summary> | ||
/// <param name="busNumber">The bus number</param> | ||
/// <param name="bitrate">The bus bit rate</param> | ||
/// <returns>An instance of an <see cref="ISpiBus"/></returns> | ||
ICanBus CreateCanBus(CanBitrate bitrate, int busNumber); | ||
} |
93 changes: 46 additions & 47 deletions
93
Source/Meadow.Contracts/Hardware/Contracts/IOControllers/ISpiController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,53 @@ | ||
namespace Meadow.Hardware | ||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Contract for devices that expose `ISpiBus(es)`. | ||
/// </summary> | ||
public interface ISpiController : IDigitalOutputController | ||
{ | ||
/// <summary> | ||
/// Contract for devices who expose `ISpiBus(es)`. | ||
/// The default SPI Bus speed, in kHz, used when speed parameters are not provided | ||
/// </summary> | ||
public interface ISpiController : IDigitalOutputController | ||
{ | ||
/// <summary> | ||
/// The default SPI Bus speed, in kHz, used when speed parameters are not provided | ||
/// </summary> | ||
public static Units.Frequency DefaultSpiBusSpeed = new Units.Frequency(375, Units.Frequency.UnitType.Kilohertz); | ||
public static Units.Frequency DefaultSpiBusSpeed = new Units.Frequency(375, Units.Frequency.UnitType.Kilohertz); | ||
|
||
/// <summary> | ||
/// Creates a SPI bus instance for the requested control pins and clock configuration | ||
/// </summary> | ||
/// <param name="clock">The IPin instance to use as the bus clock</param> | ||
/// <param name="copi">The IPin instance to use for data transmit (controller out/peripheral in)</param> | ||
/// <param name="cipo">The IPin instance to use for data receive (controller in/peripheral out)</param> | ||
/// <param name="config">The bus clock configuration parameters</param> | ||
/// <returns>An instance of an <see cref="ISpiBus"/></returns> | ||
public ISpiBus CreateSpiBus( | ||
IPin clock, | ||
IPin copi, | ||
IPin cipo, | ||
SpiClockConfiguration config | ||
); | ||
/// <summary> | ||
/// Creates a SPI bus instance for the requested control pins and clock configuration | ||
/// </summary> | ||
/// <param name="clock">The IPin instance to use as the bus clock</param> | ||
/// <param name="copi">The IPin instance to use for data transmit (controller out/peripheral in)</param> | ||
/// <param name="cipo">The IPin instance to use for data receive (controller in/peripheral out)</param> | ||
/// <param name="config">The bus clock configuration parameters</param> | ||
/// <returns>An instance of an <see cref="ISpiBus"/></returns> | ||
public ISpiBus CreateSpiBus( | ||
IPin clock, | ||
IPin copi, | ||
IPin cipo, | ||
SpiClockConfiguration config | ||
); | ||
|
||
/// <summary> | ||
/// Creates a SPI bus instance for the requested control pins and bus speed | ||
/// </summary> | ||
/// <param name="clock">The IPin instance to use as the bus clock</param> | ||
/// <param name="copi">The IPin instance to use for data transmit (controller out/peripheral in)</param> | ||
/// <param name="cipo">The IPin instance to use for data receive (controller in/peripheral out)</param> | ||
/// <param name="speed">The bus speed</param> | ||
/// <returns>An instance of an <see cref="ISpiBus"/></returns> | ||
ISpiBus CreateSpiBus( | ||
IPin clock, | ||
IPin copi, | ||
IPin cipo, | ||
Units.Frequency speed | ||
); | ||
/// <summary> | ||
/// Creates a SPI bus instance for the requested control pins and bus speed | ||
/// </summary> | ||
/// <param name="clock">The IPin instance to use as the bus clock</param> | ||
/// <param name="copi">The IPin instance to use for data transmit (controller out/peripheral in)</param> | ||
/// <param name="cipo">The IPin instance to use for data receive (controller in/peripheral out)</param> | ||
/// <param name="speed">The bus speed</param> | ||
/// <returns>An instance of an <see cref="ISpiBus"/></returns> | ||
ISpiBus CreateSpiBus( | ||
IPin clock, | ||
IPin copi, | ||
IPin cipo, | ||
Units.Frequency speed | ||
); | ||
|
||
/// <summary> | ||
/// Creates a SPI bus instance for the requested bus number and bus speed | ||
/// </summary> | ||
/// <param name="speed">The bus speed</param> | ||
/// <param name="busNumber">The bus number</param> | ||
/// <returns>An instance of an <see cref="ISpiBus"/></returns> | ||
ISpiBus CreateSpiBus( | ||
int busNumber, | ||
Units.Frequency speed | ||
); | ||
} | ||
/// <summary> | ||
/// Creates a SPI bus instance for the requested bus number and bus speed | ||
/// </summary> | ||
/// <param name="speed">The bus speed</param> | ||
/// <param name="busNumber">The bus number</param> | ||
/// <returns>An instance of an <see cref="ISpiBus"/></returns> | ||
ISpiBus CreateSpiBus( | ||
int busNumber, | ||
Units.Frequency speed | ||
); | ||
} |
8 changes: 8 additions & 0 deletions
8
Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ActiveErrorFrame.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Represents an active error frame for CAN communication. | ||
/// </summary> | ||
public class ActiveErrorFrame : Frame | ||
{ | ||
} |
97 changes: 97 additions & 0 deletions
97
Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/CanBitrate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Specifies the bitrate for CAN communication. | ||
/// </summary> | ||
public enum CanBitrate | ||
{ | ||
/// <summary> | ||
/// 5 kbps CAN bitrate. | ||
/// </summary> | ||
Can_5kbps, | ||
|
||
/// <summary> | ||
/// 10 kbps CAN bitrate. | ||
/// </summary> | ||
Can_10kbps, | ||
|
||
/// <summary> | ||
/// 20 kbps CAN bitrate. | ||
/// </summary> | ||
Can_20kbps, | ||
|
||
/// <summary> | ||
/// 33 kbps CAN bitrate. | ||
/// </summary> | ||
Can_33kbps, | ||
|
||
/// <summary> | ||
/// 40 kbps CAN bitrate. | ||
/// </summary> | ||
Can_40kbps, | ||
|
||
/// <summary> | ||
/// 47 kbps CAN bitrate. | ||
/// </summary> | ||
Can_47kbps, | ||
|
||
/// <summary> | ||
/// 50 kbps CAN bitrate. | ||
/// </summary> | ||
Can_50kbps, | ||
|
||
/// <summary> | ||
/// 80 kbps CAN bitrate. | ||
/// </summary> | ||
Can_80kbps, | ||
|
||
/// <summary> | ||
/// 83 kbps CAN bitrate. | ||
/// </summary> | ||
Can_83kbps, | ||
|
||
/// <summary> | ||
/// 95 kbps CAN bitrate. | ||
/// </summary> | ||
Can_95kbps, | ||
|
||
/// <summary> | ||
/// 100 kbps CAN bitrate. | ||
/// </summary> | ||
Can_100kbps, | ||
|
||
/// <summary> | ||
/// 125 kbps CAN bitrate. | ||
/// </summary> | ||
Can_125kbps, | ||
|
||
/// <summary> | ||
/// 200 kbps CAN bitrate. | ||
/// </summary> | ||
Can_200kbps, | ||
|
||
/// <summary> | ||
/// 250 kbps CAN bitrate. | ||
/// </summary> | ||
Can_250kbps, | ||
|
||
/// <summary> | ||
/// 500 kbps CAN bitrate. | ||
/// </summary> | ||
Can_500kbps, | ||
|
||
/// <summary> | ||
/// 800 kbps CAN bitrate. | ||
/// </summary> | ||
Can_800kbps, | ||
|
||
/// <summary> | ||
/// 1 Mbps CAN bitrate. | ||
/// </summary> | ||
Can_1Mbps, | ||
|
||
/// <summary> | ||
/// Flexible Data Rate | ||
/// </summary> | ||
Can_FD, | ||
} |
17 changes: 17 additions & 0 deletions
17
Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/DataFrame.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Represents an abstract data frame for CAN communication, inheriting from Frame. | ||
/// </summary> | ||
public abstract class DataFrame : Frame | ||
{ | ||
/// <summary> | ||
/// Gets or sets the identifier for the data frame. | ||
/// </summary> | ||
public int ID { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the payload of the data frame. | ||
/// </summary> | ||
public byte[] Payload { get; set; } = new byte[0]; | ||
} |
8 changes: 8 additions & 0 deletions
8
Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ExtendedDataFrame.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Represents an extended data frame for CAN communication. | ||
/// </summary> | ||
public class ExtendedDataFrame : DataFrame | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ExtendedRtrFrame.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Represents an extended remote transfer request (RTR) frame for CAN communication. | ||
/// </summary> | ||
public class ExtendedRtrFrame : RemoteTransferRequestFrame | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/Frame.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Represents an abstract base class for CAN (Controller Area Network) frames. | ||
/// </summary> | ||
public abstract class Frame : ICanFrame | ||
{ | ||
} |
44 changes: 44 additions & 0 deletions
44
Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ICanBus.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
|
||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Represents a Controller Area Network (CAN) bus interface. | ||
/// </summary> | ||
public interface ICanBus | ||
{ | ||
/// <summary> | ||
/// Occurs when a CAN frame is received. | ||
/// </summary> | ||
event EventHandler<ICanFrame>? FrameReceived; | ||
|
||
/// <summary> | ||
/// Writes a CAN frame to the specified buffer. | ||
/// </summary> | ||
/// <param name="frame">The CAN frame to write.</param> | ||
void WriteFrame(ICanFrame frame); | ||
|
||
/// <summary> | ||
/// Checks if a CAN frame is available to read. | ||
/// </summary> | ||
/// <returns><c>true</c> if a frame is available; otherwise, <c>false</c>.</returns> | ||
bool IsFrameAvailable(); | ||
|
||
/// <summary> | ||
/// Reads a CAN frame. | ||
/// </summary> | ||
/// <returns>The CAN frame if available; otherwise, <c>null</c>.</returns> | ||
ICanFrame? ReadFrame(); | ||
|
||
/// <summary> | ||
/// Sets the CAN filter. | ||
/// </summary> | ||
/// <param name="filter">The filter value.</param> | ||
void SetFilter(int filter); | ||
|
||
/// <summary> | ||
/// Sets the CAN mask. | ||
/// </summary> | ||
/// <param name="filter">The mask value.</param> | ||
void SetMask(int filter); | ||
} |
8 changes: 8 additions & 0 deletions
8
Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ICanFrame.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Represents a CAN (Controller Area Network) frame. | ||
/// </summary> | ||
public interface ICanFrame | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/OverloadFrame.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Represents an overload frame for CAN communication. | ||
/// </summary> | ||
public class OverloadFrame : Frame | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/RemoteTransferRequestFrame.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Represents a remote transfer request frame for CAN communication. | ||
/// </summary> | ||
public class RemoteTransferRequestFrame : DataFrame | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/StandardDataFrame.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Represents a standard data frame for CAN communication. | ||
/// </summary> | ||
public class StandardDataFrame : DataFrame | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/StandardRtrFrame.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Meadow.Hardware; | ||
|
||
/// <summary> | ||
/// Represents a standard remote transfer request frame (RTR) for CAN communication. | ||
/// </summary> | ||
public class StandardRtrFrame : RemoteTransferRequestFrame | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/Meadow.Contracts/Peripherals/Sensors/Hid/IDigitalPushButtonJoystick.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Meadow.Peripherals.Sensors.Buttons; | ||
|
||
namespace Meadow.Peripherals.Sensors.Hid; | ||
|
||
/// <summary> | ||
/// Interface describing digital joysticks and d-pads with a center push button | ||
/// </summary> | ||
public interface IDigitalPushButtonJoystick : IDigitalJoystick, IButton | ||
{ | ||
} |