From dc364d82369ac69e8cbb4354a8d9c2b76a1f59e9 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Sat, 25 Sep 2021 12:37:29 +0300 Subject: [PATCH 1/2] Adding support for I2S pin configuraiton --- .../Include/Esp32_DeviceMapping.h | 1 + .../common/Esp32_DeviceMapping.cpp | 22 +++++++++++++++++++ .../nanoFramework_hardware_esp32_native.cpp | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Esp32_DeviceMapping.h b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Esp32_DeviceMapping.h index 94c00bc908..99946c1a42 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Esp32_DeviceMapping.h +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/Include/Esp32_DeviceMapping.h @@ -36,6 +36,7 @@ enum Esp32_MapDeviceType DEV_TYPE_LED_PWM, DEV_TYPE_ADC, DEV_TYPE_DAC, + DEV_TYPE_I2S, DEV_TYPE_MAX, }; diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Esp32_DeviceMapping.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Esp32_DeviceMapping.cpp index 00de732d04..ed02c46c0e 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Esp32_DeviceMapping.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Esp32_DeviceMapping.cpp @@ -86,6 +86,16 @@ 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, Esp32_MapDeviceType &deviceType, @@ -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; }; @@ -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; }; @@ -218,6 +234,12 @@ void Esp32_SetMappedDevicePins(uint8_t pin, int32_t alternateFunction) Esp32_LED_DevicePinMap[deviceIndex] = pin; } break; + + case DEV_TYPE_I2S: + if (deviceIndex <=1) + { + Esp32_I2S_DevicePinMap[deviceIndex][mapping] = pin; + } default: // ignore break; diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.cpp index 41e6294b93..f86ebd8c1a 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/nanoFramework.Hardware.ESP32/nanoFramework_hardware_esp32_native.cpp @@ -6,6 +6,8 @@ #include "nanoFramework_hardware_esp32_native.h" +// clang-format off + static const CLR_RT_MethodHandler method_lookup[] = { NULL, @@ -74,3 +76,5 @@ const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_Hardware_Esp3 method_lookup, { 100, 0, 7, 2 } }; + +// clang-format on From b071a3cd63906c2c373028ec73bf647f4ca17be1 Mon Sep 17 00:00:00 2001 From: nfbot Date: Sat, 25 Sep 2021 12:44:48 +0300 Subject: [PATCH 2/2] Code style fixes (#2074) Automated fixes for code style. --- .../common/Esp32_DeviceMapping.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Esp32_DeviceMapping.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Esp32_DeviceMapping.cpp index ed02c46c0e..7d8e58bad8 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Esp32_DeviceMapping.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/common/Esp32_DeviceMapping.cpp @@ -97,14 +97,14 @@ int8_t Esp32_I2S_DevicePinMap[2][5] = { {-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) @@ -144,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); @@ -195,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); @@ -234,9 +234,9 @@ void Esp32_SetMappedDevicePins(uint8_t pin, int32_t alternateFunction) Esp32_LED_DevicePinMap[deviceIndex] = pin; } break; - + case DEV_TYPE_I2S: - if (deviceIndex <=1) + if (deviceIndex <= 1) { Esp32_I2S_DevicePinMap[deviceIndex][mapping] = pin; }