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

Create I2S Configuration Class #1

Merged
merged 4 commits into from
Sep 25, 2021
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
34 changes: 34 additions & 0 deletions System.Device.I2s/I2sBitsPerSample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

namespace System.Device.I2s
{
/// <summary>
/// Defines how bit per sample is synchronized between devices on a I2s bus.
/// </summary>
public enum I2sBitsPerSample
{
/// <summary>
/// I2S bits per sample: 8-bits
/// </summary>
Bit8 = 8,

/// <summary>
/// I2S bits per sample: 16-bits
/// </summary>
Bit16 = 16,

/// <summary>
/// I2S bits per sample: 24-bits
/// </summary>
Bit24 = 24,

/// <summary>
/// I2S bits per sample: 32-bits
/// </summary>
Bit32 = 32

}
}
23 changes: 23 additions & 0 deletions System.Device.I2s/I2sChannel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

namespace System.Device.I2s
{
/// <summary>
/// Defines channels on a I2s bus.
/// </summary>
public enum I2sChannel
{
/// <summary>
/// I2S 1 channel (mono)
/// </summary>
Mono = 1,

/// <summary>
/// I2S 2 channel (stereo)
/// </summary>
Stereo = 2,
}
}
38 changes: 38 additions & 0 deletions System.Device.I2s/I2sChannelFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

namespace System.Device.I2s
{
/// <summary>
/// Defines channels on a I2s bus.
/// </summary>
public enum I2sChannelFormat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is that different from mono and stereo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For initializing I2S configuration I2sChannelFormat is required, We'll need mono and stereo when we use i2s_set_clk We can delete I2sChannel for now

{
/// <summary>
/// I2S_CHANNEL_FMT_RIGHT_LEFT
/// </summary>
RightLeft = 0x00,

/// <summary>
/// I2S_CHANNEL_FMT_ALL_RIGHT
/// </summary>
AllRight,

/// <summary>
/// I2S_CHANNEL_FMT_ALL_LEFT
/// </summary>
AllLeft,

/// <summary>
/// I2S_CHANNEL_FMT_ONLY_RIGHT
/// </summary>
OnlyRight,

/// <summary>
/// I2S_CHANNEL_FMT_ONLY_LEFT
/// </summary>
OnlyLeft
}
}
43 changes: 43 additions & 0 deletions System.Device.I2s/I2sCommunicationFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

namespace System.Device.I2s
{
/// <summary>
/// Defines channels on a I2s bus.
/// </summary>
public enum I2sCommunicationFormat
{
/// <summary>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please simplify all this, there is no real reason to have multiple times the same elements with the same values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values are provided in the reference documentation for I2S communication standard format. Do you have any suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :-) Clean :-) Just keep one per value (those having the same value do have the same behavior)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StandardI2s = 0X01,
Lsb = 0x02,
Msb = 0x03,
PcmShort = 0x04,
PcmLong = 0x0C, or 0x08?

/// I2S communication I2S Philips standard, data launch at second BCK
/// </summary>
StandardI2s = 0X01,

/// <summary>
/// I2S format LSB, (I2S_COMM_FORMAT_I2S |I2S_COMM_FORMAT_I2S_LSB) correspond to I2S_MSB
/// </summary>
Lsb = 0X02,

/// <summary>
/// I2S communication MSB alignment standard, data launch at first BCK
/// </summary>
Msb = 0X03,

/// <summary>
/// PCM Short standard, also known as DSP mode. The period of synchronization signal (WS) is 1 bck cycle.
/// </summary>
PcmShort = 0X04,

/// <summary>
/// PCM Long standard. The period of synchronization signal (WS) is channel_bit*bck cycles.
/// </summary>
PcmLong = 0X0C,

/// <summary>
/// standard max
/// </summary>
StandMax,
}
}
130 changes: 127 additions & 3 deletions System.Device.I2s/I2sConnectionSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,132 @@
using System;
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

using System;

namespace System.Device.I2s
{
public class I2sConnectionSettings
/// <summary>
/// The connection settings of a device on a I2Sbus.
/// </summary>
public sealed class I2sConnectionSettings
{
private int _busId = 1;

private int _sampleRate = 44_100;

private I2sMode _i2sMode = I2sMode.Pdm;

private I2sBitsPerSample _i2sBitsPerSample = I2sBitsPerSample.Bit16;

private I2sChannelFormat _i2sChannelFormat = I2sChannelFormat.RightLeft;

private I2sCommunicationFormat _i2sConnectionFormat = I2sCommunicationFormat.StandardI2s;

/// <summary>
/// Initializes new instance of I2sConnectionSettings.
/// </summary>

private I2sConnectionSettings()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="I2sConnectionSettings"/> class.
/// </summary>
/// <param name="busId">The bus ID the device is connected to.</param>
public I2sConnectionSettings(int busId)
{
BusId = busId;
}

internal I2sConnectionSettings(I2sConnectionSettings other)
{
BusId = other.BusId;
Mode = other.Mode;
SampleRate = other.SampleRate;
CommunicationFormat = other.CommunicationFormat;
ChannelFormat = other.ChannelFormat;
BitsPerSample = other.BitsPerSample;
}

/// <summary>
/// The bus ID the device is connected to.
/// </summary>
public int BusId
{
get => _busId;

set
{
_busId = value;
}
}

/// <summary>
/// The I2Smode being used.
/// </summary>
public I2sMode Mode
{
get => _i2sMode;

set
{
_i2sMode = value;
}
}

/// <summary>
/// Bits per sample
/// </summary>
public I2sBitsPerSample BitsPerSample
{
get => _i2sBitsPerSample;

set
{
_i2sBitsPerSample = value;
}
}

/// <summary>
/// I2S Channel Format
/// </summary>
public I2sChannelFormat ChannelFormat
{
get => _i2sChannelFormat;

set
{
_i2sChannelFormat = value;
}
}

/// <summary>
/// Specifies communication format on the I2Sbus.
/// </summary>
public I2sCommunicationFormat CommunicationFormat
{
get => _i2sConnectionFormat;

set
{
_i2sConnectionFormat = value;
}
}

/// <summary>
/// Sample Rate.
/// </summary>
public int SampleRate
{
get => _sampleRate;

set
{
_sampleRate = value;
}
}
}
}
}
49 changes: 49 additions & 0 deletions System.Device.I2s/I2sMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

namespace System.Device.I2s
{
/// <summary>
/// Defines how data is synchronized between devices on a I2s bus.
/// </summary>
public enum I2sMode
{
/// <summary>
/// Master mode
/// </summary>
Master = 1,

/// <summary>
/// Slave mode
/// </summary>
Slave = 2,

/// <summary>
/// TX mode
/// </summary>
Tx = 4,

/// <summary>
/// RX mode
/// </summary>
Rx = 8,

/// <summary>
/// Output I2S data to built-in DAC, no matter the data format is 16bit or 32 bit, the DAC module will only take the 8bits from MSB
/// </summary>
DacBuiltIn = 16,

/// <summary>
/// Input I2S data from built-in ADC, each data can be 12-bit width at most
/// </summary>
AdcBuiltIn = 32,

/// <summary>
/// PDM mode
/// </summary>
Pdm = 64

}
}
5 changes: 5 additions & 0 deletions System.Device.I2s/System.Device.I2s.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@
</ItemGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
<ItemGroup>
<Compile Include="I2sBitsPerSample.cs" />
<Compile Include="I2sChannel.cs" />
<Compile Include="I2sChannelFormat.cs" />
<Compile Include="I2sCommunicationFormat.cs" />
<Compile Include="I2sConnectionSettings.cs" />
<Compile Include="I2sDevice.cs" />
<Compile Include="I2sMode.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions nanoFramework.System.Device.I2s.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
# Visual Studio Version 16
VisualStudioVersion = 16.0.31702.278
MinimumVisualStudioVersion = 10.0.40219.1
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "System.Device.I2s", "System.Device.I2s\System.Device.I2s.nfproj", "{D74A7890-8A23-417B-AB74-923D57E987EA}"
EndProject
Expand Down