diff --git a/Source/Meadow.Contracts/Hardware/Bases/DigitalInterruptPortBase.cs b/Source/Meadow.Contracts/Hardware/Bases/DigitalInterruptPortBase.cs index 1a95c3fb..90d23e8d 100644 --- a/Source/Meadow.Contracts/Hardware/Bases/DigitalInterruptPortBase.cs +++ b/Source/Meadow.Contracts/Hardware/Bases/DigitalInterruptPortBase.cs @@ -19,7 +19,7 @@ public abstract class DigitalInterruptPortBase : DigitalInputPortBase, IDigitalI /// Gets or sets a value indicating the type of interrupt monitoring this input. /// /// true if interrupt enabled; otherwise, false. - public InterruptMode InterruptMode { get; protected set; } + public abstract InterruptMode InterruptMode { get; set; } /// /// Gets or sets the debounce duration for the port @@ -35,17 +35,13 @@ public abstract class DigitalInterruptPortBase : DigitalInputPortBase, IDigitalI /// /// The pin associated with the port. /// The channel information for the port. - /// /// Thrown if or is null. protected DigitalInterruptPortBase( IPin pin, - IDigitalChannelInfo channel, - InterruptMode interruptMode = InterruptMode.None + IDigitalChannelInfo channel ) : base(pin, channel) { - // TODO: check interrupt mode (i.e. if != none, make sure channel info agrees) - InterruptMode = interruptMode; } /// diff --git a/Source/Meadow.Contracts/Hardware/Contracts/IOControllers/ICanController.cs b/Source/Meadow.Contracts/Hardware/Contracts/IOControllers/ICanController.cs new file mode 100644 index 00000000..5e60f5c8 --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/IOControllers/ICanController.cs @@ -0,0 +1,15 @@ +namespace Meadow.Hardware; + +/// +/// Contract for devices that expose `ICanBus(es)`. +/// +public interface ICanController +{ + /// + /// Creates a CAN bus instance for the requested bus number and bus speed + /// + /// The bus number + /// The bus bit rate + /// An instance of an + ICanBus CreateCanBus(CanBitrate bitrate, int busNumber); +} diff --git a/Source/Meadow.Contracts/Hardware/Contracts/IOControllers/ISpiController.cs b/Source/Meadow.Contracts/Hardware/Contracts/IOControllers/ISpiController.cs index 5ea82e5e..fa12b02d 100644 --- a/Source/Meadow.Contracts/Hardware/Contracts/IOControllers/ISpiController.cs +++ b/Source/Meadow.Contracts/Hardware/Contracts/IOControllers/ISpiController.cs @@ -1,54 +1,53 @@ -namespace Meadow.Hardware +namespace Meadow.Hardware; + +/// +/// Contract for devices that expose `ISpiBus(es)`. +/// +public interface ISpiController : IDigitalOutputController { /// - /// Contract for devices who expose `ISpiBus(es)`. + /// The default SPI Bus speed, in kHz, used when speed parameters are not provided /// - public interface ISpiController : IDigitalOutputController - { - /// - /// The default SPI Bus speed, in kHz, used when speed parameters are not provided - /// - 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); - /// - /// Creates a SPI bus instance for the requested control pins and clock configuration - /// - /// The IPin instance to use as the bus clock - /// The IPin instance to use for data transmit (controller out/peripheral in) - /// The IPin instance to use for data receive (controller in/peripheral out) - /// The bus clock configuration parameters - /// An instance of an - public ISpiBus CreateSpiBus( - IPin clock, - IPin copi, - IPin cipo, - SpiClockConfiguration config - ); + /// + /// Creates a SPI bus instance for the requested control pins and clock configuration + /// + /// The IPin instance to use as the bus clock + /// The IPin instance to use for data transmit (controller out/peripheral in) + /// The IPin instance to use for data receive (controller in/peripheral out) + /// The bus clock configuration parameters + /// An instance of an + public ISpiBus CreateSpiBus( + IPin clock, + IPin copi, + IPin cipo, + SpiClockConfiguration config + ); - /// - /// Creates a SPI bus instance for the requested control pins and bus speed - /// - /// The IPin instance to use as the bus clock - /// The IPin instance to use for data transmit (controller out/peripheral in) - /// The IPin instance to use for data receive (controller in/peripheral out) - /// The bus speed - /// An instance of an - ISpiBus CreateSpiBus( - IPin clock, - IPin copi, - IPin cipo, - Units.Frequency speed - ); + /// + /// Creates a SPI bus instance for the requested control pins and bus speed + /// + /// The IPin instance to use as the bus clock + /// The IPin instance to use for data transmit (controller out/peripheral in) + /// The IPin instance to use for data receive (controller in/peripheral out) + /// The bus speed + /// An instance of an + ISpiBus CreateSpiBus( + IPin clock, + IPin copi, + IPin cipo, + Units.Frequency speed + ); - /// - /// Creates a SPI bus instance for the requested bus number and bus speed - /// - /// The bus speed - /// The bus number - /// An instance of an - ISpiBus CreateSpiBus( - int busNumber, - Units.Frequency speed - ); - } + /// + /// Creates a SPI bus instance for the requested bus number and bus speed + /// + /// The bus speed + /// The bus number + /// An instance of an + ISpiBus CreateSpiBus( + int busNumber, + Units.Frequency speed + ); } diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ActiveErrorFrame.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ActiveErrorFrame.cs new file mode 100644 index 00000000..652b7c8b --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ActiveErrorFrame.cs @@ -0,0 +1,8 @@ +namespace Meadow.Hardware; + +/// +/// Represents an active error frame for CAN communication. +/// +public class ActiveErrorFrame : Frame +{ +} diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/CanBitrate.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/CanBitrate.cs new file mode 100644 index 00000000..74279c2f --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/CanBitrate.cs @@ -0,0 +1,97 @@ +namespace Meadow.Hardware; + +/// +/// Specifies the bitrate for CAN communication. +/// +public enum CanBitrate +{ + /// + /// 5 kbps CAN bitrate. + /// + Can_5kbps, + + /// + /// 10 kbps CAN bitrate. + /// + Can_10kbps, + + /// + /// 20 kbps CAN bitrate. + /// + Can_20kbps, + + /// + /// 33 kbps CAN bitrate. + /// + Can_33kbps, + + /// + /// 40 kbps CAN bitrate. + /// + Can_40kbps, + + /// + /// 47 kbps CAN bitrate. + /// + Can_47kbps, + + /// + /// 50 kbps CAN bitrate. + /// + Can_50kbps, + + /// + /// 80 kbps CAN bitrate. + /// + Can_80kbps, + + /// + /// 83 kbps CAN bitrate. + /// + Can_83kbps, + + /// + /// 95 kbps CAN bitrate. + /// + Can_95kbps, + + /// + /// 100 kbps CAN bitrate. + /// + Can_100kbps, + + /// + /// 125 kbps CAN bitrate. + /// + Can_125kbps, + + /// + /// 200 kbps CAN bitrate. + /// + Can_200kbps, + + /// + /// 250 kbps CAN bitrate. + /// + Can_250kbps, + + /// + /// 500 kbps CAN bitrate. + /// + Can_500kbps, + + /// + /// 800 kbps CAN bitrate. + /// + Can_800kbps, + + /// + /// 1 Mbps CAN bitrate. + /// + Can_1Mbps, + + /// + /// Flexible Data Rate + /// + Can_FD, +} diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/DataFrame.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/DataFrame.cs new file mode 100644 index 00000000..04b63e4c --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/DataFrame.cs @@ -0,0 +1,17 @@ +namespace Meadow.Hardware; + +/// +/// Represents an abstract data frame for CAN communication, inheriting from Frame. +/// +public abstract class DataFrame : Frame +{ + /// + /// Gets or sets the identifier for the data frame. + /// + public int ID { get; set; } + + /// + /// Gets or sets the payload of the data frame. + /// + public byte[] Payload { get; set; } = new byte[0]; +} diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ExtendedDataFrame.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ExtendedDataFrame.cs new file mode 100644 index 00000000..33f07211 --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ExtendedDataFrame.cs @@ -0,0 +1,8 @@ +namespace Meadow.Hardware; + +/// +/// Represents an extended data frame for CAN communication. +/// +public class ExtendedDataFrame : DataFrame +{ +} diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ExtendedRtrFrame.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ExtendedRtrFrame.cs new file mode 100644 index 00000000..cc6e69f3 --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ExtendedRtrFrame.cs @@ -0,0 +1,8 @@ +namespace Meadow.Hardware; + +/// +/// Represents an extended remote transfer request (RTR) frame for CAN communication. +/// +public class ExtendedRtrFrame : RemoteTransferRequestFrame +{ +} diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/Frame.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/Frame.cs new file mode 100644 index 00000000..ac1f6b66 --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/Frame.cs @@ -0,0 +1,8 @@ +namespace Meadow.Hardware; + +/// +/// Represents an abstract base class for CAN (Controller Area Network) frames. +/// +public abstract class Frame : ICanFrame +{ +} diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ICanBus.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ICanBus.cs new file mode 100644 index 00000000..8ee2e248 --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ICanBus.cs @@ -0,0 +1,44 @@ +using System; + +namespace Meadow.Hardware; + +/// +/// Represents a Controller Area Network (CAN) bus interface. +/// +public interface ICanBus +{ + /// + /// Occurs when a CAN frame is received. + /// + event EventHandler? FrameReceived; + + /// + /// Writes a CAN frame to the specified buffer. + /// + /// The CAN frame to write. + void WriteFrame(ICanFrame frame); + + /// + /// Checks if a CAN frame is available to read. + /// + /// true if a frame is available; otherwise, false. + bool IsFrameAvailable(); + + /// + /// Reads a CAN frame. + /// + /// The CAN frame if available; otherwise, null. + ICanFrame? ReadFrame(); + + /// + /// Sets the CAN filter. + /// + /// The filter value. + void SetFilter(int filter); + + /// + /// Sets the CAN mask. + /// + /// The mask value. + void SetMask(int filter); +} diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ICanFrame.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ICanFrame.cs new file mode 100644 index 00000000..8c16c121 --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/ICanFrame.cs @@ -0,0 +1,8 @@ +namespace Meadow.Hardware; + +/// +/// Represents a CAN (Controller Area Network) frame. +/// +public interface ICanFrame +{ +} diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/OverloadFrame.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/OverloadFrame.cs new file mode 100644 index 00000000..bfe65515 --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/OverloadFrame.cs @@ -0,0 +1,8 @@ +namespace Meadow.Hardware; + +/// +/// Represents an overload frame for CAN communication. +/// +public class OverloadFrame : Frame +{ +} diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/RemoteTransferRequestFrame.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/RemoteTransferRequestFrame.cs new file mode 100644 index 00000000..0aa53530 --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/RemoteTransferRequestFrame.cs @@ -0,0 +1,8 @@ +namespace Meadow.Hardware; + +/// +/// Represents a remote transfer request frame for CAN communication. +/// +public class RemoteTransferRequestFrame : DataFrame +{ +} diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/StandardDataFrame.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/StandardDataFrame.cs new file mode 100644 index 00000000..02efa105 --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/StandardDataFrame.cs @@ -0,0 +1,8 @@ +namespace Meadow.Hardware; + +/// +/// Represents a standard data frame for CAN communication. +/// +public class StandardDataFrame : DataFrame +{ +} diff --git a/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/StandardRtrFrame.cs b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/StandardRtrFrame.cs new file mode 100644 index 00000000..86bf1fdb --- /dev/null +++ b/Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/CAN/StandardRtrFrame.cs @@ -0,0 +1,8 @@ +namespace Meadow.Hardware; + +/// +/// Represents a standard remote transfer request frame (RTR) for CAN communication. +/// +public class StandardRtrFrame : RemoteTransferRequestFrame +{ +} diff --git a/Source/Meadow.Contracts/Peripherals/Sensors/Hid/IDigitalPushButtonJoystick.cs b/Source/Meadow.Contracts/Peripherals/Sensors/Hid/IDigitalPushButtonJoystick.cs new file mode 100644 index 00000000..5ccf2f70 --- /dev/null +++ b/Source/Meadow.Contracts/Peripherals/Sensors/Hid/IDigitalPushButtonJoystick.cs @@ -0,0 +1,10 @@ +using Meadow.Peripherals.Sensors.Buttons; + +namespace Meadow.Peripherals.Sensors.Hid; + +/// +/// Interface describing digital joysticks and d-pads with a center push button +/// +public interface IDigitalPushButtonJoystick : IDigitalJoystick, IButton +{ +}