Skip to content

Commit

Permalink
Adding support for I2S pin configuration on ESP32 (#2073)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellerbach authored Sep 25, 2021
1 parent 01916a7 commit f72f7c1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum Esp32_MapDeviceType
DEV_TYPE_LED_PWM,
DEV_TYPE_ADC,
DEV_TYPE_DAC,
DEV_TYPE_I2S,
DEV_TYPE_MAX,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,25 @@ int8_t Esp32_DAC_DevicePinMap[2] = {
25,
26};

// =============================================
// I2S
// 2 devices I2S1 & I2S2
// Map pins various pins. If not used, I2S_PIN_NO_CHANGE is used
int8_t Esp32_I2S_DevicePinMap[2][5] = {
// No pin pre configured
{-1, -1, -1, -1, -1},
// No pin pre configured
{-1, -1, -1, -1, -1}};

void Esp32_DecodeAlternateFunction(
uint32_t alternateFunction,
uint32_t alternateFunction,
Esp32_MapDeviceType &deviceType,
uint8_t & busIndex,
uint16_t & PinIndex)
uint8_t &busIndex,
uint16_t &PinIndex)
{
deviceType = (Esp32_MapDeviceType)((alternateFunction >> 16) & 0x00ff);
busIndex = (uint8_t)((alternateFunction >> 8) & 0x00ff) - 1;
PinIndex = (uint16_t)(alternateFunction & 0x00ff);
busIndex = (uint8_t)((alternateFunction >> 8) & 0x00ff) - 1;
PinIndex = (uint16_t)(alternateFunction & 0x00ff);
}

int Esp32_GetMappedDevicePins(Esp32_MapDeviceType deviceType, int DevNumber, int PinIndex)
Expand All @@ -121,6 +131,9 @@ int Esp32_GetMappedDevicePins(Esp32_MapDeviceType deviceType, int DevNumber, int
case DEV_TYPE_DAC:
return (int)Esp32_DAC_DevicePinMap[PinIndex];

case DEV_TYPE_I2S:
return (int)Esp32_I2S_DevicePinMap[DevNumber][PinIndex];

default:
break;
};
Expand All @@ -131,8 +144,8 @@ int Esp32_GetMappedDevicePins(Esp32_MapDeviceType deviceType, int DevNumber, int
int Esp32_GetMappedDevicePinsWithFunction(uint32_t alternateFunction)
{
Esp32_MapDeviceType deviceType;
uint8_t deviceIndex;
uint16_t pinIndex;
uint8_t deviceIndex;
uint16_t pinIndex;

Esp32_DecodeAlternateFunction(alternateFunction, deviceType, deviceIndex, pinIndex);

Expand Down Expand Up @@ -163,6 +176,9 @@ void Esp32_SetMappedDevicePins(Esp32_MapDeviceType deviceType, int devNumber, in
case DEV_TYPE_DAC:
Esp32_DAC_DevicePinMap[pinIndex] = ioPinNumber;

case DEV_TYPE_I2S:
Esp32_I2S_DevicePinMap[pinIndex][pinIndex] = ioPinNumber;

default:
break;
};
Expand All @@ -179,8 +195,8 @@ void Esp32_SetMappedDevicePins(Esp32_MapDeviceType deviceType, int devNumber, in
void Esp32_SetMappedDevicePins(uint8_t pin, int32_t alternateFunction)
{
Esp32_MapDeviceType deviceType;
uint8_t deviceIndex;
uint16_t mapping;
uint8_t deviceIndex;
uint16_t mapping;

Esp32_DecodeAlternateFunction(alternateFunction, deviceType, deviceIndex, mapping);

Expand Down Expand Up @@ -219,6 +235,12 @@ void Esp32_SetMappedDevicePins(uint8_t pin, int32_t alternateFunction)
}
break;

case DEV_TYPE_I2S:
if (deviceIndex <= 1)
{
Esp32_I2S_DevicePinMap[deviceIndex][mapping] = pin;
}

default: // ignore
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "nanoFramework_hardware_esp32_native.h"

// clang-format off

static const CLR_RT_MethodHandler method_lookup[] =
{
NULL,
Expand Down Expand Up @@ -74,3 +76,5 @@ const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_Hardware_Esp3
method_lookup,
{ 100, 0, 7, 2 }
};

// clang-format on

0 comments on commit f72f7c1

Please sign in to comment.