The pins used for I2S and I2C can be configured in software. The ESP32 has a multiplexer that can route a peripheral to almost any physical pin of the module you're using. There's a few pins that can't/shouldn't be used because they're being used e.g. for communication with the internal SPI flash or are bootstrapped. The datasheet of your respective module will tell you which pins those are.
The detailed information on software configuration for any peripheral can be found in the api docs:
IDF:
https://docs.espressif.com/projects/esp ... index.html
ADF:
https://docs.espressif.com/projects/esp ... index.html
If you're using ESP-IDF along with one of the eval boards, take a look in the respective documentation of that board (data sheet or schematic) to see how the pins of the on-board ESP32-module are routed on the PCB. Board docs are provided here:
https://www.espressif.com/en/products/devkits.
Since you asked this question in the ADF-forum, here is a blueprint of how to use ESP-ADF with a custom board/custom codec setup (
!! imho this is more advanced and you'll probably be better off using ESP-IDF at first !!):
If you're using ESP-ADF along with one of the Audio-dev boards, just take a look at the
board_pins_config.c and of your respective board here:
https://github.com/espressif/esp-adf/tr ... udio_board. For the most natural use of ADF along with the WM8731 you will have to write your own board-library and add a driver for the wm8731 to the
audio_hal driver lib. Take a look at the esxxx libs already provided in the ADF's
audio_hal component here
https://github.com/espressif/esp-adf/tr ... hal/driver. Those are the codecs used on the Audio-dev boards, which ESP-ADF natively supports. You'll have to add a folder for the WM8731 and implement those same functions. Use the WM8731 data sheet and/or search online for existing libraries to do that.
After you have successfully implemented the driver, you will then have to write your own board driver, where you specify and initialize the peripherals that your board is using. Again, take look at the source code of already existing boards in the
audio_board component of ESP-ADF (
https://github.com/espressif/esp-adf/tr ... udio_board) and it will be no rocket science. You will initialize the codec by populating an instance of the
audio_hal_func_t-struct defined in
audio_hal.h with the pointers to the functions you have implemented in your codec driver. This is basically a C-version of a C++ virtual base class:
Code: Select all
typedef struct audio_hal {
esp_err_t (*audio_codec_initialize)(audio_hal_codec_config_t *codec_cfg); /*!< initialize codec */
esp_err_t (*audio_codec_deinitialize)(void); /*!< deinitialize codec */
esp_err_t (*audio_codec_ctrl)(audio_hal_codec_mode_t mode, audio_hal_ctrl_t ctrl_state); /*!< control codec mode and state */
esp_err_t (*audio_codec_config_iface)(audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *iface); /*!< configure i2s interface */
esp_err_t (*audio_codec_set_mute) (bool mute); /*!< set codec mute */
esp_err_t (*audio_codec_set_volume)(int volume); /*!< set codec volume */
esp_err_t (*audio_codec_get_volume)(int *volume); /*!< get codec volume */
xSemaphoreHandle audio_hal_lock; /*!< semaphore of codec */
void *handle; /*!< handle of audio codec */
} audio_hal_func_t;
Finally, you will now have to add the paths of your newly written libraries to the make-files/CMakeLists of the components. Don't forget to also add a build flag for your board driver in the Make-File of the
audio_component. You will 'tell' the linker and compiler which board driver/codec to include by defining the according build-flag in the SDKconfig file of your project.
I think using those resources you should be able to hook up your (any) codec in no time. I know in the beginning it's a lot of reading, but unfortunately, no one else can't do it for you. However, if you're having trouble with a specific aspect of wiring things up or the software configuration, of course feel free to ask.
Happy coding!