Skip to content

Commit 122c87f

Browse files
authored
Create I2S Configuration Class (#1)
1 parent db9ff03 commit 122c87f

File tree

8 files changed

+321
-5
lines changed

8 files changed

+321
-5
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace System.Device.I2s
7+
{
8+
/// <summary>
9+
/// Defines how bit per sample is synchronized between devices on a I2s bus.
10+
/// </summary>
11+
public enum I2sBitsPerSample
12+
{
13+
/// <summary>
14+
/// I2S bits per sample: 8-bits
15+
/// </summary>
16+
Bit8 = 8,
17+
18+
/// <summary>
19+
/// I2S bits per sample: 16-bits
20+
/// </summary>
21+
Bit16 = 16,
22+
23+
/// <summary>
24+
/// I2S bits per sample: 24-bits
25+
/// </summary>
26+
Bit24 = 24,
27+
28+
/// <summary>
29+
/// I2S bits per sample: 32-bits
30+
/// </summary>
31+
Bit32 = 32
32+
33+
}
34+
}

System.Device.I2s/I2sChannel.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace System.Device.I2s
7+
{
8+
/// <summary>
9+
/// Defines channels on a I2s bus.
10+
/// </summary>
11+
public enum I2sChannel
12+
{
13+
/// <summary>
14+
/// I2S 1 channel (mono)
15+
/// </summary>
16+
Mono = 1,
17+
18+
/// <summary>
19+
/// I2S 2 channel (stereo)
20+
/// </summary>
21+
Stereo = 2,
22+
}
23+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace System.Device.I2s
7+
{
8+
/// <summary>
9+
/// Defines channels on a I2s bus.
10+
/// </summary>
11+
public enum I2sChannelFormat
12+
{
13+
/// <summary>
14+
/// I2S_CHANNEL_FMT_RIGHT_LEFT
15+
/// </summary>
16+
RightLeft = 0x00,
17+
18+
/// <summary>
19+
/// I2S_CHANNEL_FMT_ALL_RIGHT
20+
/// </summary>
21+
AllRight,
22+
23+
/// <summary>
24+
/// I2S_CHANNEL_FMT_ALL_LEFT
25+
/// </summary>
26+
AllLeft,
27+
28+
/// <summary>
29+
/// I2S_CHANNEL_FMT_ONLY_RIGHT
30+
/// </summary>
31+
OnlyRight,
32+
33+
/// <summary>
34+
/// I2S_CHANNEL_FMT_ONLY_LEFT
35+
/// </summary>
36+
OnlyLeft
37+
}
38+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace System.Device.I2s
7+
{
8+
/// <summary>
9+
/// Defines channels on a I2s bus.
10+
/// </summary>
11+
public enum I2sCommunicationFormat
12+
{
13+
/// <summary>
14+
/// I2S communication I2S Philips standard, data launch at second BCK
15+
/// </summary>
16+
StandardI2s = 0X01,
17+
18+
/// <summary>
19+
/// I2S format LSB, (I2S_COMM_FORMAT_I2S |I2S_COMM_FORMAT_I2S_LSB) correspond to I2S_MSB
20+
/// </summary>
21+
Lsb = 0X02,
22+
23+
/// <summary>
24+
/// I2S communication MSB alignment standard, data launch at first BCK
25+
/// </summary>
26+
Msb = 0X03,
27+
28+
/// <summary>
29+
/// PCM Short standard, also known as DSP mode. The period of synchronization signal (WS) is 1 bck cycle.
30+
/// </summary>
31+
PcmShort = 0X04,
32+
33+
/// <summary>
34+
/// PCM Long standard. The period of synchronization signal (WS) is channel_bit*bck cycles.
35+
/// </summary>
36+
PcmLong = 0X0C,
37+
38+
/// <summary>
39+
/// standard max
40+
/// </summary>
41+
StandMax,
42+
}
43+
}
Lines changed: 127 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,132 @@
1-
using System;
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
using System;
27

38
namespace System.Device.I2s
49
{
5-
public class I2sConnectionSettings
10+
/// <summary>
11+
/// The connection settings of a device on a I2Sbus.
12+
/// </summary>
13+
public sealed class I2sConnectionSettings
614
{
15+
private int _busId = 1;
16+
17+
private int _sampleRate = 44_100;
18+
19+
private I2sMode _i2sMode = I2sMode.Pdm;
20+
21+
private I2sBitsPerSample _i2sBitsPerSample = I2sBitsPerSample.Bit16;
22+
23+
private I2sChannelFormat _i2sChannelFormat = I2sChannelFormat.RightLeft;
24+
25+
private I2sCommunicationFormat _i2sConnectionFormat = I2sCommunicationFormat.StandardI2s;
26+
27+
/// <summary>
28+
/// Initializes new instance of I2sConnectionSettings.
29+
/// </summary>
30+
31+
private I2sConnectionSettings()
32+
{
33+
}
34+
35+
/// <summary>
36+
/// Initializes a new instance of the <see cref="I2sConnectionSettings"/> class.
37+
/// </summary>
38+
/// <param name="busId">The bus ID the device is connected to.</param>
39+
public I2sConnectionSettings(int busId)
40+
{
41+
BusId = busId;
42+
}
43+
44+
internal I2sConnectionSettings(I2sConnectionSettings other)
45+
{
46+
BusId = other.BusId;
47+
Mode = other.Mode;
48+
SampleRate = other.SampleRate;
49+
CommunicationFormat = other.CommunicationFormat;
50+
ChannelFormat = other.ChannelFormat;
51+
BitsPerSample = other.BitsPerSample;
52+
}
53+
54+
/// <summary>
55+
/// The bus ID the device is connected to.
56+
/// </summary>
57+
public int BusId
58+
{
59+
get => _busId;
60+
61+
set
62+
{
63+
_busId = value;
64+
}
65+
}
66+
67+
/// <summary>
68+
/// The I2Smode being used.
69+
/// </summary>
70+
public I2sMode Mode
71+
{
72+
get => _i2sMode;
73+
74+
set
75+
{
76+
_i2sMode = value;
77+
}
78+
}
79+
80+
/// <summary>
81+
/// Bits per sample
82+
/// </summary>
83+
public I2sBitsPerSample BitsPerSample
84+
{
85+
get => _i2sBitsPerSample;
86+
87+
set
88+
{
89+
_i2sBitsPerSample = value;
90+
}
91+
}
92+
93+
/// <summary>
94+
/// I2S Channel Format
95+
/// </summary>
96+
public I2sChannelFormat ChannelFormat
97+
{
98+
get => _i2sChannelFormat;
99+
100+
set
101+
{
102+
_i2sChannelFormat = value;
103+
}
104+
}
105+
106+
/// <summary>
107+
/// Specifies communication format on the I2Sbus.
108+
/// </summary>
109+
public I2sCommunicationFormat CommunicationFormat
110+
{
111+
get => _i2sConnectionFormat;
112+
113+
set
114+
{
115+
_i2sConnectionFormat = value;
116+
}
117+
}
118+
119+
/// <summary>
120+
/// Sample Rate.
121+
/// </summary>
122+
public int SampleRate
123+
{
124+
get => _sampleRate;
125+
126+
set
127+
{
128+
_sampleRate = value;
129+
}
130+
}
7131
}
8-
}
132+
}

System.Device.I2s/I2sMode.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace System.Device.I2s
7+
{
8+
/// <summary>
9+
/// Defines how data is synchronized between devices on a I2s bus.
10+
/// </summary>
11+
public enum I2sMode
12+
{
13+
/// <summary>
14+
/// Master mode
15+
/// </summary>
16+
Master = 1,
17+
18+
/// <summary>
19+
/// Slave mode
20+
/// </summary>
21+
Slave = 2,
22+
23+
/// <summary>
24+
/// TX mode
25+
/// </summary>
26+
Tx = 4,
27+
28+
/// <summary>
29+
/// RX mode
30+
/// </summary>
31+
Rx = 8,
32+
33+
/// <summary>
34+
/// 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
35+
/// </summary>
36+
DacBuiltIn = 16,
37+
38+
/// <summary>
39+
/// Input I2S data from built-in ADC, each data can be 12-bit width at most
40+
/// </summary>
41+
AdcBuiltIn = 32,
42+
43+
/// <summary>
44+
/// PDM mode
45+
/// </summary>
46+
Pdm = 64
47+
48+
}
49+
}

System.Device.I2s/System.Device.I2s.nfproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@
4444
</ItemGroup>
4545
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
4646
<ItemGroup>
47+
<Compile Include="I2sBitsPerSample.cs" />
48+
<Compile Include="I2sChannel.cs" />
49+
<Compile Include="I2sChannelFormat.cs" />
50+
<Compile Include="I2sCommunicationFormat.cs" />
4751
<Compile Include="I2sConnectionSettings.cs" />
4852
<Compile Include="I2sDevice.cs" />
53+
<Compile Include="I2sMode.cs" />
4954
<Compile Include="Properties\AssemblyInfo.cs" />
5055
</ItemGroup>
5156
<ItemGroup>

nanoFramework.System.Device.I2s.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

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

0 commit comments

Comments
 (0)