-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
} | ||
} |
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, | ||
} | ||
} |
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 | ||
{ | ||
/// <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 | ||
} | ||
} |
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These values are provided in the reference documentation for There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. StandardI2s = 0X01, |
||
/// 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, | ||
} | ||
} |
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; | ||
} | ||
} | ||
} | ||
} | ||
} |
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 | ||
ikivanc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </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 | ||
|
||
} | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 deleteI2sChannel
for now