Procedure for working with custom hardware?

wulph1
Posts: 2
Joined: Fri Feb 09, 2018 7:47 pm

Procedure for working with custom hardware?

Postby wulph1 » Thu Jan 02, 2020 7:24 pm

Hello,

It is time to move our project from ESP32-LyraT to our own hardware. What is the right way to create a new board definition? We could hack the components\audio_board\lyrat_v4_3 folder, but this doesn't seem appropriate or scalable.

Ideally, the new board definition should be a component of the active project. We need to accomplish the following:
  • change the I2S pins
  • define a driver for the MAX98357 decoder/amplifier IC
  • reassign button input pins
  • implement I2C SLAVE MODE to communicate with host IC
A project-level board definition seems the right place to do these things, but I'm getting lost in the heirarchy.

joncmaloney
Posts: 4
Joined: Thu Sep 07, 2017 12:05 pm

Re: Procedure for working with custom hardware?

Postby joncmaloney » Mon Jan 06, 2020 10:17 am

Hi wulph1,

I've recently had to use esp-adf on custom hardware. To do this i've implemented a custom driver for the TLV320AIC3110.

In terms of project hirarchy.

1. Create a component in your own project /component/audio to host custom driver and board definition.
2. In this component folder i've created a second sub folder called, for example, my_board ( /component/audio/my_board )
3. In the component.mk file within this folder i've added the following lines

Code: Select all

ifdef CONFIG_ESP_MY_BOARD_V1
COMPONENT_ADD_INCLUDEDIRS += ./my_board/src
COMPONENT_SRCDIRS += ./my_board/include
endif
4. Update your project kconfig to include the above #define

Code: Select all

#Audio HAL has been redefined here so each of the 
#	config's from the esp-adf are overriden. 
#	This is done to avoid making any changes to 
#	the esp-adf library source files. 
menu "Audio HAL"

choice AUDIO_BOARD
    prompt "Audio board"
    default ESP_MY_BOARD_V1
    help
        Select an audio board to use with the ESP-ADF

config ESP_LYRAT_V4_3_BOARD
    bool "ESP32-Lyrat V4.3"
config ESP_LYRAT_V4_2_BOARD
    bool "ESP32-Lyrat V4.2"
config ESP_LYRATD_MSC_V2_1_BOARD
    bool "ESP32-LyraTD-MSC V2.1"
config ESP_LYRATD_MSC_V2_2_BOARD
    bool "ESP32-LyraTD-MSC V2.2"
config ESP_LYRAT_MINI_V1_1_BOARD
    bool "ESP32-Lyrat-Mini V1.1"
config ESP_MY_BOARD_V1
    bool "ESP32 My Board V1.0"
endchoice

endmenu
5. Create your own copy of board.c and board.h place these in /component/audio/my_board/src and /component/audio/my_board/include respectively.

6. Similarly do the same for board_pins_config.c and board_def.h ( it is in board_pins_config.c that I've defined i2s pins i2c pins and button pins.

7. In your custom driver you will also need to create the global variable that implements the interface functions for example

Code: Select all

audio_hal_func_t AUDIO_CODEC_AIC31XX_DEFAULT_HANDLE = { .audio_codec_initialize = aic31xx_init, .audio_codec_deinitialize = aic31xx_adc_deinit, .audio_codec_ctrl = aic31xx_adc_ctrl_state, .audio_codec_config_iface = aic31xx_config_i2s, .audio_codec_set_mute = aic31xx_spl_spr_mute, .audio_codec_set_volume = aic31xx_set_spl_spr_volume, .audio_codec_get_volume = aic31xx_spl_spr_get_volume, };
This is an implementation for TLV320AIC3110 your's may differ (they are just function names thought so whatever is your preference).

8. Place your driver source code in /component/audio/my_board/src

Hope this helps.

Jon

wulph1
Posts: 2
Joined: Fri Feb 09, 2018 7:47 pm

Re: Procedure for working with custom hardware?

Postby wulph1 » Tue Jan 14, 2020 1:40 am

Thanks for your help, Jon.

I had a lot of trouble getting your method to work, but working through the challenges step by step encouraged me to get more intimate with the build system. Eventually, I stumbled across this blurb in the ESP-IDF documentation:

https://docs.espressif.com/projects/esp ... -same-name
Multiple components with the same name

When esp-idf is collecting all the components to compile, it will do this in the order specified by COMPONENT_DIRS; by default, this means the idf components first, the project components second and optionally the components in EXTRA_COMPONENT_DIRS last. If two or more of these directories contain component subdirectories with the same name, the component in the last place searched is used. This allows, for example, overriding esp-idf components with a modified version by simply copying the component from the esp-idf component directory to the project component tree and then modifying it there. If used in this way, the esp-idf directory itself can remain untouched.

So ultimately I copied the $ADF_PATH/components/audio_board directory to my project, which eliminated any conflict with the built-in board definitions. From there, your instructions were clear and simple to merge. In fact the template boards can be deleted from the project with no ill effects.

Cheers,
Joe

Who is online

Users browsing this forum: No registered users and 16 guests