Skip to content

Commit

Permalink
Merge pull request #249 from WildernessLabs/feature/channel-info
Browse files Browse the repository at this point in the history
improving I2C channel info
  • Loading branch information
adrianstevens authored Jul 23, 2024
2 parents 2e4acf6 + 8abd055 commit 0e6f755
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 50 deletions.
6 changes: 6 additions & 0 deletions Source/Meadow.Contracts/Communications/I2cChannelInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ public class I2cChannelInfo : DigitalChannelInfoBase, II2cChannelInfo
/// </summary>
public I2cChannelFunctionType ChannelFunction { get; protected set; }

/// <inheritdoc/>
public int BusNumber { get; }

/// <summary>
/// Initializes a new instance of the <see cref="I2cChannelInfo"/> class
/// </summary>
/// <param name="name">The name of the I2C channel</param>
/// <param name="channelFunction">The function type of the I2C channel</param>
/// <param name="busNumber">The system bus number of I2C channel</param>
/// <param name="pullDownCapable">Indicates whether the I2C channel is capable of pull-down</param>
/// <param name="pullUpCapable">Indicates whether the I2C channel is capable of pull-up</param>
public I2cChannelInfo(string name,
I2cChannelFunctionType channelFunction,
int busNumber = 0,
bool pullDownCapable = false,
bool pullUpCapable = false)
: base(
Expand All @@ -30,6 +35,7 @@ public I2cChannelInfo(string name,
pullUpCapable: pullUpCapable,
inverseLogic: false) //TODO: switch to C# 7.2+ to get rid of trailing names
{
BusNumber = busNumber;
ChannelFunction = channelFunction;
}
}
11 changes: 1 addition & 10 deletions Source/Meadow.Contracts/Hardware/Bases/PwmPortBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,12 @@ public abstract class PwmPortBase : DigitalPortBase, IPwmPort
/// </summary>
/// <param name="pin">The pin associated with the PWM port.</param>
/// <param name="channel">The PWM channel information for the port.</param>
/// <param name="frequency">The PWM frequency.</param>
/// <param name="dutyCycle">The initial PWM duty cycle (default is 0).</param>
/// <param name="inverted">A value indicating whether the PWM signal is inverted (default is false).</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="pin"/> or <paramref name="channel"/> is <c>null</c>.</exception>
protected PwmPortBase(
IPin pin,
IPwmChannelInfo channel,
Frequency frequency,
float dutyCycle = 0,
bool inverted = false
IPwmChannelInfo channel
) : base(pin, channel)
{
Inverted = inverted;
Frequency = frequency;
DutyCycle = dutyCycle;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ public interface II2cChannelInfo : IDigitalChannelInfo, ICommunicationChannelInf
/// Gets the I2C channel function type.
/// </summary>
I2cChannelFunctionType ChannelFunction { get; }
/// <summary>
/// Gets the system bus number for the channel
/// </summary>
int BusNumber { get; }
}
}
79 changes: 39 additions & 40 deletions Source/Meadow.Contracts/Hardware/Contracts/PortsAndBuses/ISpiBus.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
using System;

namespace Meadow.Hardware
namespace Meadow.Hardware;

/// <summary>
/// Represents an SPI bus.
/// </summary>
public interface ISpiBus
{
/// <summary>
/// Represents an SPI bus.
/// Gets an array of all supported speeds of the SPI bus.
/// </summary>
public interface ISpiBus
{
/// <summary>
/// Gets an array of all supported speeds of the SPI bus.
/// </summary>
Units.Frequency[] SupportedSpeeds { get; }
Units.Frequency[] SupportedSpeeds { get; }

/// <summary>
/// Gets the current SPI clock configuration.
/// </summary>
SpiClockConfiguration Configuration { get; }
/// <summary>
/// Gets the current SPI clock configuration.
/// </summary>
SpiClockConfiguration Configuration { get; }

/// <summary>
/// Reads data from the SPI bus into the specified buffer.
/// </summary>
/// <param name="chipSelect">The chip select port to activate the bus.</param>
/// <param name="readBuffer">The buffer to read data into.</param>
/// <param name="csMode">The chip select mode that activates the peripheral.</param>
void Read(IDigitalOutputPort? chipSelect,
Span<byte> readBuffer,
ChipSelectMode csMode = ChipSelectMode.ActiveLow);
/// <summary>
/// Reads data from the SPI bus into the specified buffer.
/// </summary>
/// <param name="chipSelect">The chip select port to activate the bus.</param>
/// <param name="readBuffer">The buffer to read data into.</param>
/// <param name="csMode">The chip select mode that activates the peripheral.</param>
void Read(IDigitalOutputPort? chipSelect,
Span<byte> readBuffer,
ChipSelectMode csMode = ChipSelectMode.ActiveLow);

/// <summary>
/// Writes data to the SPI bus.
/// </summary>
/// <param name="chipSelect">The chip select port to activate the peripheral.</param>
/// <param name="writeBuffer">The buffer containing data to write.</param>
/// <param name="csMode">The chip select mode that activates the peripheral.</param>
void Write(
IDigitalOutputPort? chipSelect,
Span<byte> writeBuffer,
ChipSelectMode csMode = ChipSelectMode.ActiveLow);
/// <summary>
/// Writes data to the SPI bus.
/// </summary>
/// <param name="chipSelect">The chip select port to activate the peripheral.</param>
/// <param name="writeBuffer">The buffer containing data to write.</param>
/// <param name="csMode">The chip select mode that activates the peripheral.</param>
void Write(
IDigitalOutputPort? chipSelect,
Span<byte> writeBuffer,
ChipSelectMode csMode = ChipSelectMode.ActiveLow);

/// <summary>
/// Writes data from the write buffer to a peripheral on the bus while reading return data into the read buffer.
/// </summary>
/// <param name="chipSelect">The chip select port to activate the peripheral.</param>
/// <param name="writeBuffer">The buffer containing data to write.</param>
/// <param name="readBuffer">The buffer to read returning data into.</param>
/// <param name="csMode">The chip select mode that activates the peripheral.</param>
void Exchange(IDigitalOutputPort? chipSelect, Span<byte> writeBuffer, Span<byte> readBuffer, ChipSelectMode csMode = ChipSelectMode.ActiveLow);
}
/// <summary>
/// Writes data from the write buffer to a peripheral on the bus while reading return data into the read buffer.
/// </summary>
/// <param name="chipSelect">The chip select port to activate the peripheral.</param>
/// <param name="writeBuffer">The buffer containing data to write.</param>
/// <param name="readBuffer">The buffer to read returning data into.</param>
/// <param name="csMode">The chip select mode that activates the peripheral.</param>
void Exchange(IDigitalOutputPort? chipSelect, Span<byte> writeBuffer, Span<byte> readBuffer, ChipSelectMode csMode = ChipSelectMode.ActiveLow);
}

0 comments on commit 0e6f755

Please sign in to comment.