diff --git a/Documentation/platforms/xtensa/esp32/boards/esp32-audio-kit/esp32-audio-config-file.png b/Documentation/platforms/xtensa/esp32/boards/esp32-audio-kit/esp32-audio-config-file.png new file mode 100644 index 00000000000..c51fa32e29d Binary files /dev/null and b/Documentation/platforms/xtensa/esp32/boards/esp32-audio-kit/esp32-audio-config-file.png differ diff --git a/Documentation/platforms/xtensa/esp32/boards/esp32-audio-kit/esp32-audio-kit.png b/Documentation/platforms/xtensa/esp32/boards/esp32-audio-kit/esp32-audio-kit.png new file mode 100644 index 00000000000..a3dd18a7300 Binary files /dev/null and b/Documentation/platforms/xtensa/esp32/boards/esp32-audio-kit/esp32-audio-kit.png differ diff --git a/Documentation/platforms/xtensa/esp32/boards/esp32-audio-kit/index.rst b/Documentation/platforms/xtensa/esp32/boards/esp32-audio-kit/index.rst new file mode 100644 index 00000000000..e352fb1f474 --- /dev/null +++ b/Documentation/platforms/xtensa/esp32/boards/esp32-audio-kit/index.rst @@ -0,0 +1,155 @@ +=============== +ESP32-AUDIO-KIT +=============== + +The `Ai-Thinker ESP32 Audio Kit `_ is a development board for the ESP32 SoC from Espressif, based on Ai-Thinker ESP32-A1S audio module. + +.. list-table:: + :align: center + + * - .. figure:: esp32-audio-kit.png + :align: center + + Ai-Thinker ESP32 Audio Kit board + +Features +======== + + - ESP32-A1S module + - Audio Earphones Output + - Audio LINEIN Input + - 2 Microphones in the board (stereo audio input) + - 8 Buttons in the boards (1 RST Button and 7 user buttons) + - MicroSD card slot + +Some of the ESP32 I/O pins are broken out to the board's pin header. + +Serial Console +============== + +UART0 is, by default, the serial console. It connects to the on-board +Silabs CP2102 converter and is available on the USB connector (UART label). + +It will show up as /dev/ttyUSB[n] where [n] normally is 0 if you don't have +another USB/Serial adapter connected in your computer. + +Buttons and LEDs +================ + +Board Buttons +------------- + +There are eight buttons labeled as RST, BOOT, KEY1..KEY6. +The RST button is not available to software. + +The BOOT button is connected to IO0. On reset it is used as a strapping +pin to determine whether the chip boots normally or into the serial +bootloader. After reset, however, the BOOT button can be used for software +input. + +Board LEDs +---------- + +There are several on-board LEDs for that indicate the presence of power +and USB activity. + +I/O Mapping +=========== + +===== ========================= ========== +I/O Signal Notes +===== ========================= ========== +0 BOOT Button +2 DATA0 SDCard +4 DATA1 SDCard +5 KEY6 Button +12 DATA2 SDCard +13 KEY2 Button/DATA3 SDCard (DIP Switch) +14 CLK SDCard +15 CMD SDCard/JTAG MTDO (DIP Switch) +18 KEY5 Button +19 KEY3 Button/LED5 +21 CTRL Audio AMP +22 LED4 +23 KEY4 Button +34 SDCard Detect +36 KEY1 Button +===== ========================= ========== + +Configurations +============== + +All of the configurations presented below can be tested by running the following commands:: + + $ ./tools/configure.sh esp32-audio-kit: + $ make flash ESPTOOL_PORT=/dev/ttyUSB0 -j + +Where is the name of board configuration you want to use, i.e.: nsh, buttons, wifi... +Then use a serial console terminal like ``minicom`` or ``picocom`` configured to 115200 8N1. + +audio +----- + +This configuration uses the I2S0 peripheral and the ES8388 audio codec +present on the ESP32-Audio-Kit board to play an audio file streamed over +HTTP while connected to a Wi-Fi network. + +**Simple HTTP server** + +Prepare a PCM-encoded (`.wav`) audio file with 16 bits/sample (sampled at +44.1kHz). This file must be placed into a folder in a computer that could +be accessed on the same Wi-Fi network the ESP32 will be connecting to. + +Python provides a simple HTTP server. `cd` to the audio file folder on the +PC and run:: + + $ python3 -m http.server + + Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) + +Look for your PC IP address and test playing the prepared audio on your +browser: + +.. figure:: esp32-audio-config-file.png + :align: center + +After successfully built and flashed, connect the board to the Wi-Fi network:: + + $ nsh> wapi psk wlan0 mypasswd 1 + $ nsh> wapi essid wlan0 myssid 1 + $ nsh> renew wlan0 + +Once connected, open NuttX's player and play the file according to its file +name and the IP address of the HTTP server (For example `tone.wav` and +`192.168.1.239:8000`, respectively):: + + $ nsh> nxplayer + $ nxplayer> play http://192.168.1.239:8000/tone.wav + +.. note:: + The codec implementation on the LyraT board was validated using 16-bit, + 44.1kHz WAV files. Other configurations might not work as expected. + +nsh +--- + +Basic NuttShell configuration (console enabled in UART0, exposed via +USB connection by means of FT2232HL converter, at 115200 bps). + +wifi +---- + +Enables Wi-Fi support. You can define your credentials this way:: + + $ make menuconfig + -> Application Configuration + -> Network Utilities + -> Network initialization (NETUTILS_NETINIT [=y]) + -> WAPI Configuration + +Or if you don't want to keep it saved in the firmware you can do it +at runtime:: + + nsh> wapi psk wlan0 mypasswd 3 + nsh> wapi essid wlan0 myssid 1 + nsh> renew wlan0 diff --git a/boards/Kconfig b/boards/Kconfig index 98646fd0e35..06da8216665 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -211,6 +211,18 @@ config ARCH_BOARD_QUICKFEATHER MC3635 accelerometer, DPS310 pressure sensor, IM69D130 PDM microphone, internal programmable FPGA fabric. +config ARCH_BOARD_ESP32_AUDIO_KIT + bool "Ai-Thinker ESP32 Audio Kit" + depends on ARCH_CHIP_ESP32_A1S + select ARCH_HAVE_LEDS + select ARCH_HAVE_BUTTONS + select ARCH_HAVE_IRQBUTTONS if ESP32_GPIO_IRQ + ---help--- + The Ai-Thinker ESP32-Audio-Kit is a board with the ESP32-A1S module + powered by ESP32-D0WD-V3 with 16MB of SPI Flash and 8MB PSRAM, and an + audio codec on it. There are two versions of ESP32-A1S module: ES8388 + codec and other with AC101. Currently only ES8388 is supported. + config ARCH_BOARD_ESP32_DEVKITC bool "Espressif ESP32 DevkitC board V4" depends on ARCH_CHIP_ESP32WROOM32 || ARCH_CHIP_ESP32WROOM32_8MB || ARCH_CHIP_ESP32WROOM32_16MB || ARCH_CHIP_ESP32WROVER || ARCH_CHIP_ESP32SOLO1 @@ -2791,6 +2803,7 @@ config ARCH_BOARD default "ekk-lm3s9b96" if ARCH_BOARD_EKKLM3S9B96 default "emw3162" if ARCH_BOARD_EMW3162 default "quickfeather" if ARCH_BOARD_QUICKFEATHER + default "esp32-audio-kit" if ARCH_BOARD_ESP32_AUDIO_KIT default "esp32-devkitc" if ARCH_BOARD_ESP32_DEVKITC default "ttgo_eink5_v2" if ARCH_BOARD_TTGO_T5V2_ESP32 default "esp32-ethernet-kit" if ARCH_BOARD_ESP32_ETHERNETKIT @@ -3831,6 +3844,9 @@ endif if ARCH_BOARD_RX65N_GRROSE source "boards/renesas/rx65n/rx65n-grrose/Kconfig" endif +if ARCH_BOARD_ESP32_AUDIO_KIT +source "boards/xtensa/esp32/esp32-audio-kit/Kconfig" +endif if ARCH_BOARD_ESP32_DEVKITC source "boards/xtensa/esp32/esp32-devkitc/Kconfig" endif diff --git a/boards/xtensa/esp32/esp32-audio-kit/Kconfig b/boards/xtensa/esp32/esp32-audio-kit/Kconfig new file mode 100644 index 00000000000..fd7affca599 --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/Kconfig @@ -0,0 +1,8 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if ARCH_BOARD_ESP32_AUDIO_KIT + +endif # ARCH_BOARD_ESP32_AUDIO_KIT diff --git a/boards/xtensa/esp32/esp32-audio-kit/configs/audio/defconfig b/boards/xtensa/esp32/esp32-audio-kit/configs/audio/defconfig new file mode 100644 index 00000000000..8ce0811cd85 --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/configs/audio/defconfig @@ -0,0 +1,120 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_LEDS is not set +# CONFIG_ESP32_I2S0_RX is not set +# CONFIG_NDEBUG is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ALLOW_BSD_COMPONENTS=y +CONFIG_ARCH="xtensa" +CONFIG_ARCH_BOARD="esp32-audio-kit" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32_AUDIO_KIT=y +CONFIG_ARCH_CHIP="esp32" +CONFIG_ARCH_CHIP_ESP32=y +CONFIG_ARCH_CHIP_ESP32_A1S=y +CONFIG_ARCH_INTERRUPTSTACK=4096 +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_XTENSA=y +CONFIG_AUDIO=y +CONFIG_AUDIOUTILS_MMLPARSER_LIB=y +CONFIG_AUDIO_BUFFER_NUMBYTES=4096 +CONFIG_AUDIO_ES8388=y +CONFIG_AUDIO_EXCLUDE_FFORWARD=y +CONFIG_AUDIO_EXCLUDE_TONE=y +CONFIG_AUDIO_I2S=y +CONFIG_AUDIO_I2SCHAR=y +CONFIG_AUDIO_NUM_BUFFERS=4 +CONFIG_BOARDCTL_ROMDISK=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEFAULT_TASK_STACKSIZE=4096 +CONFIG_DEV_URANDOM=y +CONFIG_DRIVERS_AUDIO=y +CONFIG_DRIVERS_IEEE80211=y +CONFIG_DRIVERS_WIRELESS=y +CONFIG_ESP32_I2C0=y +CONFIG_ESP32_I2C0_SCLPIN=32 +CONFIG_ESP32_I2C0_SDAPIN=33 +CONFIG_ESP32_I2S0=y +CONFIG_ESP32_I2S0_BCLKPIN=27 +CONFIG_ESP32_I2S0_DATA_BIT_WIDTH_16BIT=y +CONFIG_ESP32_I2S0_DOUTPIN=26 +CONFIG_ESP32_I2S0_MCLK=y +CONFIG_ESP32_I2S0_WSPIN=25 +CONFIG_ESP32_I2S=y +CONFIG_ESP32_SPIFLASH=y +CONFIG_ESP32_SPIFLASH_SPIFFS=y +CONFIG_ESP32_STORAGE_MTD_SIZE=0x80000 +CONFIG_ESP32_UART0=y +CONFIG_ESP32_WIFI=y +CONFIG_ESP32_WIFI_SAVE_PARAM=y +CONFIG_EXAMPLES_I2SCHAR=y +CONFIG_EXAMPLES_I2SCHAR_TX=y +CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS=2 +CONFIG_EXAMPLES_I2SCHAR_TXSTACKSIZE=2048 +CONFIG_EXAMPLES_ROMFS=y +CONFIG_FS_PROCFS=y +CONFIG_FS_ROMFS=y +CONFIG_I2C=y +CONFIG_I2S_DMADESC_NUM=4 +CONFIG_IDLETHREAD_STACKSIZE=3072 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_MM_REGIONS=3 +CONFIG_NAME_MAX=48 +CONFIG_NETDB_DNSCLIENT=y +CONFIG_NETDB_DNSCLIENT_NAMESIZE=64 +CONFIG_NETDEV_LATEINIT=y +CONFIG_NETDEV_PHY_IOCTL=y +CONFIG_NETDEV_WIRELESS_IOCTL=y +CONFIG_NETUTILS_IPERF=y +CONFIG_NETUTILS_TELNETD=y +CONFIG_NET_BROADCAST=y +CONFIG_NET_ETH_PKTSIZE=1518 +CONFIG_NET_ICMP=y +CONFIG_NET_ICMP_SOCKET=y +CONFIG_NET_PREALLOC_DEVIF_CALLBACKS=32 +CONFIG_NET_STATISTICS=y +CONFIG_NET_TCP=y +CONFIG_NET_TCP_DELAYED_ACK=y +CONFIG_NET_TCP_WRITE_BUFFERS=y +CONFIG_NET_UDP=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=300 +CONFIG_NSH_READLINE=y +CONFIG_NXPLAYER_HTTP_STREAMING_SUPPORT=y +CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=2048 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PTHREAD_MUTEX_TYPES=y +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_HPWORKSTACKSIZE=2048 +CONFIG_SCHED_LPWORK=y +CONFIG_SCHED_WAITPID=y +CONFIG_SIG_DEFAULT=y +CONFIG_SPI=y +CONFIG_SPIFFS_NAME_MAX=48 +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSTEM_DHCPC_RENEW=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NXPLAYER=y +CONFIG_SYSTEM_PING=y +CONFIG_TELNET_CHARACTER_MODE=y +CONFIG_TLS_TASK_NELEM=4 +CONFIG_UART0_SERIAL_CONSOLE=y +CONFIG_WIRELESS=y +CONFIG_WIRELESS_WAPI=y +CONFIG_WIRELESS_WAPI_CMDTOOL=y diff --git a/boards/xtensa/esp32/esp32-audio-kit/configs/nsh/defconfig b/boards/xtensa/esp32/esp32-audio-kit/configs/nsh/defconfig new file mode 100644 index 00000000000..6f19fa933ab --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/configs/nsh/defconfig @@ -0,0 +1,44 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_LEDS is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ARCH="xtensa" +CONFIG_ARCH_BOARD="esp32-audio-kit" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32_AUDIO_KIT=y +CONFIG_ARCH_CHIP="esp32" +CONFIG_ARCH_CHIP_ESP32=y +CONFIG_ARCH_CHIP_ESP32_A1S=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_XTENSA=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_ESP32_UART0=y +CONFIG_FS_PROCFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=3072 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_MM_REGIONS=3 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSTEM_NSH=y +CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/boards/xtensa/esp32/esp32-audio-kit/configs/wifi/defconfig b/boards/xtensa/esp32/esp32-audio-kit/configs/wifi/defconfig new file mode 100644 index 00000000000..6ff6b8c758b --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/configs/wifi/defconfig @@ -0,0 +1,90 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_LEDS is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ALLOW_BSD_COMPONENTS=y +CONFIG_ARCH="xtensa" +CONFIG_ARCH_BOARD="esp32-audio-kit" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32_AUDIO_KIT=y +CONFIG_ARCH_CHIP="esp32" +CONFIG_ARCH_CHIP_ESP32=y +CONFIG_ARCH_CHIP_ESP32_A1S=y +CONFIG_ARCH_INTERRUPTSTACK=4096 +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_XTENSA=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_DEBUG_ASSERTIONS=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEFAULT_TASK_STACKSIZE=4096 +CONFIG_DEV_URANDOM=y +CONFIG_DRIVERS_IEEE80211=y +CONFIG_DRIVERS_WIRELESS=y +CONFIG_ESP32_SPIFLASH=y +CONFIG_ESP32_SPIFLASH_SPIFFS=y +CONFIG_ESP32_STORAGE_MTD_SIZE=0x80000 +CONFIG_ESP32_UART0=y +CONFIG_ESP32_WIFI=y +CONFIG_ESP32_WIFI_SAVE_PARAM=y +CONFIG_FS_PROCFS=y +CONFIG_IDLETHREAD_STACKSIZE=3072 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_MM_REGIONS=3 +CONFIG_NAME_MAX=48 +CONFIG_NETDB_DNSCLIENT=y +CONFIG_NETDB_DNSCLIENT_NAMESIZE=64 +CONFIG_NETDEV_LATEINIT=y +CONFIG_NETDEV_PHY_IOCTL=y +CONFIG_NETDEV_WIRELESS_IOCTL=y +CONFIG_NETUTILS_IPERF=y +CONFIG_NETUTILS_TELNETD=y +CONFIG_NET_BROADCAST=y +CONFIG_NET_ETH_PKTSIZE=1518 +CONFIG_NET_ICMP=y +CONFIG_NET_ICMP_SOCKET=y +CONFIG_NET_PREALLOC_DEVIF_CALLBACKS=32 +CONFIG_NET_STATISTICS=y +CONFIG_NET_TCP=y +CONFIG_NET_TCP_DELAYED_ACK=y +CONFIG_NET_TCP_WRITE_BUFFERS=y +CONFIG_NET_UDP=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=300 +CONFIG_NSH_READLINE=y +CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE=2048 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PTHREAD_MUTEX_TYPES=y +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_LPWORK=y +CONFIG_SCHED_WAITPID=y +CONFIG_SIG_DEFAULT=y +CONFIG_SPI=y +CONFIG_SPIFFS_NAME_MAX=48 +CONFIG_STACK_COLORATION=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSTEM_DHCPC_RENEW=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_PING=y +CONFIG_SYSTEM_STACKMONITOR=y +CONFIG_TELNET_CHARACTER_MODE=y +CONFIG_TLS_TASK_NELEM=4 +CONFIG_UART0_SERIAL_CONSOLE=y +CONFIG_WIRELESS=y +CONFIG_WIRELESS_WAPI=y +CONFIG_WIRELESS_WAPI_CMDTOOL=y diff --git a/boards/xtensa/esp32/esp32-audio-kit/include/board.h b/boards/xtensa/esp32/esp32-audio-kit/include/board.h new file mode 100644 index 00000000000..3e6a8941cbf --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/include/board.h @@ -0,0 +1,78 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-audio-kit/include/board.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_XTENSA_ESP32_ESP32_AUDIO_KIT_INCLUDE_BOARD_H +#define __BOARDS_XTENSA_ESP32_ESP32_AUDIO_KIT_INCLUDE_BOARD_H + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Clocking *****************************************************************/ + +/* The ESP32-LyraT board is fitted with either a 26 or a 40MHz crystal */ + +#ifdef CONFIG_ESP32_XTAL_26MHz +# define BOARD_XTAL_FREQUENCY 26000000 +#else +# define BOARD_XTAL_FREQUENCY 40000000 +#endif + +#ifdef CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ +# define BOARD_CLOCK_FREQUENCY (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * 1000000) +#else +# define BOARD_CLOCK_FREQUENCY 80000000 +#endif + +/* Button definitions *******************************************************/ + +/* GPIO definitions *********************************************************/ + +/* ES8388 CODEC */ + +#define ES8388_I2C_CCLK 23 /* SCL */ +#define ES8388_I2C_CDATA 18 /* SDA */ + +#define ES8388_I2S_MCLK 0 /* Master clock */ +#define ES8388_I2S_SCLK 5 /* Audio data bit clock */ +#define ES8388_I2S_LRCK 25 /* Audio data left and right clock */ +#define ES8388_I2S_DSDIN 26 /* DAC audio data (to speakers) */ +#define ES8388_I2S_ASDOUT 35 /* ADC audio data (from microphone) */ + +/* LED definitions **********************************************************/ + +/* Define how many LEDs this board has (needed by userleds) */ + +#define BOARD_NLEDS 2 + +/* GPIO pins used by the GPIO Subsystem */ + +#define BOARD_NGPIOOUT 1 /* Amount of GPIO Output pins */ +#define BOARD_NGPIOIN 1 /* Amount of GPIO Input without Interruption */ +#define BOARD_NGPIOINT 1 /* Amount of GPIO Input w/ Interruption pins */ + +/* Peripherals definitions **************************************************/ + +/* ES8388 CODEC */ + +#define ES8388_I2C_FREQ 400000 +#define ES8388_I2C_ADDR 0x10 + +#endif /* __BOARDS_XTENSA_ESP32_ESP32_AUDIO_KIT_INCLUDE_BOARD_H */ diff --git a/boards/xtensa/esp32/esp32-audio-kit/include/board_memorymap.h b/boards/xtensa/esp32/esp32-audio-kit/include/board_memorymap.h new file mode 100644 index 00000000000..ece46113e8f --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/include/board_memorymap.h @@ -0,0 +1,128 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-audio-kit/include/board_memorymap.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_XTENSA_ESP32_ESP32_AUDIO_KIT_INCLUDE_BOARD_MEMORYMAP_H +#define __BOARDS_XTENSA_ESP32_ESP32_AUDIO_KIT_INCLUDE_BOARD_MEMORYMAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Kernel ROM */ + +#define KIROM_START (uintptr_t)__kirom_start +#define KIROM_SIZE (uintptr_t)__kirom_size +#define KDROM_START (uintptr_t)__kdrom_start +#define KDROM_SIZE (uintptr_t)__kdrom_size + +/* Kernel RAM */ + +#define KIRAM_0_START (uintptr_t)__kiram_0_start +#define KIRAM_0_SIZE (uintptr_t)__kiram_0_size +#define KIRAM_0_END (uintptr_t)__kiram_0_end +#define KIRAM_1_START (uintptr_t)__kiram_1_start +#define KIRAM_1_SIZE (uintptr_t)__kiram_1_size +#define KIRAM_1_END (uintptr_t)__kiram_1_end +#define KDRAM_0_START (uintptr_t)__kdram_0_start +#define KDRAM_0_SIZE (uintptr_t)__kdram_0_size +#define KDRAM_0_END (uintptr_t)__kdram_0_end +#define KDRAM_1_START (uintptr_t)__kdram_1_start +#define KDRAM_1_SIZE (uintptr_t)__kdram_1_size +#define KDRAM_1_END (uintptr_t)__kdram_1_end + +/* Exception vectors */ + +#define VECTORS_START (uintptr_t)__vectors_start +#define VECTORS_END (uintptr_t)__vectors_end + +/* User ROM */ + +#define UIROM_START (uintptr_t)__uirom_start +#define UIROM_SIZE (uintptr_t)__uirom_size +#define UIROM_END (uintptr_t)__uirom_end +#define UDROM_START (uintptr_t)__udrom_start +#define UDROM_SIZE (uintptr_t)__udrom_size +#define UDROM_END (uintptr_t)__udrom_end + +/* User RAM */ + +#define UIRAM_START (uintptr_t)__uiram_start +#define UIRAM_SIZE (uintptr_t)__uiram_size +#define UIRAM_END (uintptr_t)__uiram_end +#define UDRAM_START (uintptr_t)__udram_start +#define UDRAM_SIZE (uintptr_t)__udram_size +#define UDRAM_END (uintptr_t)__udram_end + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Kernel ROM (RX) */ + +extern uint8_t __kirom_start[]; +extern uint8_t __kirom_size[]; +extern uint8_t __kdrom_start[]; +extern uint8_t __kdrom_size[]; + +/* Kernel RAM (RW) */ + +extern uint8_t __kiram_0_start[]; +extern uint8_t __kiram_0_size[]; +extern uint8_t __kiram_0_end[]; +extern uint8_t __kiram_1_start[]; +extern uint8_t __kiram_1_size[]; +extern uint8_t __kiram_1_end[]; +extern uint8_t __kdram_0_start[]; +extern uint8_t __kdram_0_size[]; +extern uint8_t __kdram_0_end[]; +extern uint8_t __kdram_1_start[]; +extern uint8_t __kdram_1_size[]; +extern uint8_t __kdram_1_end[]; + +/* Exception vectors */ + +extern uint8_t __vectors_start[]; +extern uint8_t __vectors_end[]; + +/* User ROM (RX) */ + +extern uint8_t __uirom_start[]; +extern uint8_t __uirom_size[]; +extern uint8_t __uirom_end[]; +extern uint8_t __udrom_start[]; +extern uint8_t __udrom_size[]; +extern uint8_t __udrom_end[]; + +/* User RAM (RW) */ + +extern uint8_t __uiram_start[]; +extern uint8_t __uiram_size[]; +extern uint8_t __uiram_end[]; +extern uint8_t __udram_start[]; +extern uint8_t __udram_size[]; +extern uint8_t __udram_end[]; + +#endif /* __BOARDS_XTENSA_ESP32_ESP32_AUDIO_KIT_INCLUDE_BOARD_MEMORYMAP_H */ diff --git a/boards/xtensa/esp32/esp32-audio-kit/scripts/Make.defs b/boards/xtensa/esp32/esp32-audio-kit/scripts/Make.defs new file mode 100644 index 00000000000..11cc302c5b2 --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/scripts/Make.defs @@ -0,0 +1,72 @@ +############################################################################ +# boards/xtensa/esp32/esp32-audio-kit/scripts/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(TOPDIR)/.config +include $(TOPDIR)/tools/Config.mk +include $(TOPDIR)/tools/esp32/Config.mk +include $(TOPDIR)/arch/xtensa/src/lx6/Toolchain.defs + +ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld + +# Pick the linker scripts from the board level if they exist, if not +# pick the common linker scripts. + +ifeq ($(CONFIG_BUILD_PROTECTED),y) + ARCHSCRIPT += $(call FINDSCRIPT,protected_memory.ld) + ARCHSCRIPT += $(call FINDSCRIPT,kernel-space.ld) +else + ARCHSCRIPT += $(call FINDSCRIPT,flat_memory.ld) + + ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) + ARCHSCRIPT += $(call FINDSCRIPT,mcuboot_sections.ld) + else + ARCHSCRIPT += $(call FINDSCRIPT,legacy_sections.ld) + endif +endif + +ARCHPICFLAGS = -fpic + +# if SPIRAM/PSRAM is used then we need to include a workaround + +ifeq ($(CONFIG_ESP32_SPIRAM),y) + ARCHCFLAGS += -mfix-esp32-psram-cache-issue +endif + +CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +AFLAGS := $(CFLAGS) -D__ASSEMBLY__ + +# Loadable module definitions + +CMODULEFLAGS = $(CFLAGS) -mtext-section-literals + +LDMODULEFLAGS = -r -e module_initialize +LDMODULEFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)/libs/libc/modlib/gnu-elf.ld) + +# ELF module definitions + +CELFFLAGS = $(CFLAGS) -mtext-section-literals +CXXELFFLAGS = $(CXXFLAGS) -mtext-section-literals + +LDELFFLAGS = -r -e main +LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld) diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/Make.defs b/boards/xtensa/esp32/esp32-audio-kit/src/Make.defs new file mode 100644 index 00000000000..0b9528e64f3 --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/src/Make.defs @@ -0,0 +1,51 @@ +############################################################################# +# boards/xtensa/esp32/esp32-audio-kit/src/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################# + +include $(TOPDIR)/Make.defs + +CSRCS = esp32_boot.c esp32_bringup.c + +ifeq ($(CONFIG_USERLED),y) +CSRCS += esp32_userleds.c +endif + +ifeq ($(CONFIG_BOARDCTL),y) +CSRCS += esp32_appinit.c +ifeq ($(CONFIG_BOARDCTL_RESET),y) +CSRCS += esp32_reset.c +endif +endif + +ifeq ($(CONFIG_MMCSD),y) +CSRCS += esp32_mmcsd.c +endif + +ifeq ($(CONFIG_DEV_GPIO),y) +CSRCS += esp32_gpio.c +endif + +ifeq ($(CONFIG_ARCH_BUTTONS),y) +CSRCS += esp32_buttons.c +endif + +DEPPATH += --dep-path board +VPATH += :board +CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board) + diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32-audio-kit.h b/boards/xtensa/esp32/esp32-audio-kit/src/esp32-audio-kit.h new file mode 100644 index 00000000000..489f7b01068 --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/src/esp32-audio-kit.h @@ -0,0 +1,181 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-audio-kit/src/esp32-audio-kit.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_XTENSA_ESP32_ESP32_AUDIO_KIT_SRC_ESP32_AUDIO_KIT_H +#define __BOARDS_XTENSA_ESP32_ESP32_AUDIO_KIT_SRC_ESP32_AUDIO_KIT_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* ESP32-Audio-Kit GPIOs ****************************************************/ + +/* BOOT Button */ + +#define BUTTON_BOOT 0 + +/* LEDs */ + +#define GPIO_LED1 22 + +/* Audio Amplifier */ + +#define SPEAKER_ENABLE_GPIO 21 + +/* Buttons */ + +/* As BOOT_BUTTON shares pins with I2S and the SD card it cannot be used + * as an user button like regular ESP32 boards. As the ESP32-LyraT has + * other buttons that can be used, BOOT_BUTTON is disabled in the buttons + * driver to avoid conflict with the remaining peripherals. + */ + +#define BUTTON_REC 36 +#define BUTTON_MODE 39 +#define BUTTON_PLAY_TP_CHANNEL 8 +#define BUTTON_SET_TP_CHANNEL 9 +#define BUTTON_VOLM_TP_CHANNEL 4 +#define BUTTON_VOLP_TP_CHANNEL 7 + +/* TIMERS */ + +#define TIMER0 0 +#define TIMER1 1 +#define TIMER2 2 +#define TIMER3 3 + +/* ONESHOT */ + +#define ONESHOT_TIMER 1 +#define ONESHOT_RESOLUTION_US 1 + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_LATE_INITIALIZE=y : + * Called from board_late_initialize(). + * + * CONFIG_BOARD_LATE_INITIALIZE=y && CONFIG_BOARDCTL=y : + * Called from the NSH library via board_app_initialize() + * + ****************************************************************************/ + +int esp32_bringup(void); + +/**************************************************************************** + * Name: esp32_es8388_initialize + * + * Description: + * This function is called by platform-specific, setup logic to configure + * and register the ES8388 device. This function will register the driver + * as /dev/audio/pcm[x] where x is determined by the I2S port number. + * + * Input Parameters: + * i2c_port - The I2C port used for the device + * i2c_addr - The I2C address used by the device + * i2c_freq - The I2C frequency used for the device + * i2s_port - The I2S port used for the device + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int esp32_es8388_initialize(int i2c_port, uint8_t i2c_addr, int i2c_freq, + int i2s_port); + +/**************************************************************************** + * Name: board_i2sdev_initialize + * + * Description: + * This function is called by platform-specific, setup logic to configure + * and register the generic I2S audio driver. This function will register + * the driver as /dev/audio/pcm[x] where x is determined by the I2S port + * number. + * + * Input Parameters: + * port - The I2S port used for the device + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +#if defined CONFIG_ESP32_I2S0 && !defined CONFIG_AUDIO_ES8388 || \ + defined CONFIG_ESP32_I2S1 +int board_i2sdev_initialize(int port); +#endif + +/**************************************************************************** + * Name: esp32_mmcsd_initialize + * + * Description: + * Initialize SPI-based SD card and card detect thread. + * + ****************************************************************************/ + +int esp32_mmcsd_initialize(int minor); + +/**************************************************************************** + * Name: esp32_spiflash_init + * + * Description: + * Initialize the SPIFLASH and register the MTD device. + ****************************************************************************/ + +int esp32_spiflash_init(void); + +/**************************************************************************** + * Name: esp32_gpio_init + ****************************************************************************/ + +#ifdef CONFIG_DEV_GPIO +int esp32_gpio_init(void); +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_XTENSA_ESP32_ESP32_AUDIO_KIT_SRC_ESP32_AUDIO_KIT_H */ diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_appinit.c b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_appinit.c new file mode 100644 index 00000000000..2959ca024b6 --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_appinit.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-audio-kit/src/esp32_appinit.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "esp32-audio-kit.h" + +#ifdef CONFIG_BOARDCTL + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_app_initialize + * + * Description: + * Perform application specific initialization. This function is never + * called directly from application code, but only indirectly via the + * (non-standard) boardctl() interface using the command BOARDIOC_INIT. + * + * Input Parameters: + * arg - The boardctl() argument is passed to the board_app_initialize() + * implementation without modification. The argument has no + * meaning to NuttX; the meaning of the argument is a contract + * between the board-specific initialization logic and the + * matching application logic. The value could be such things as a + * mode enumeration value, a set of DIP switch settings, a + * pointer to configuration data read from a file or serial FLASH, + * or whatever you would like to do with it. Every implementation + * should accept zero/NULL as a default configuration. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure to indicate the nature of the failure. + * + ****************************************************************************/ + +int board_app_initialize(uintptr_t arg) +{ +#ifdef CONFIG_BOARD_LATE_INITIALIZE + /* Board initialization already performed by board_late_initialize() */ + + return OK; +#else + /* Perform board-specific initialization */ + + return esp32_bringup(); +#endif +} + +#endif /* CONFIG_BOARDCTL */ diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_boot.c b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_boot.c new file mode 100644 index 00000000000..a4446c86b42 --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_boot.c @@ -0,0 +1,101 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-audio-kit/src/esp32_boot.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include + +#include "esp32-audio-kit.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_board_initialize + * + * Description: + * All ESP32 architectures must provide the following entry point. + * This entry point is called early in the initialization -- after all + * memory has been configured and mapped but before any devices have been + * initialized. + * + ****************************************************************************/ + +void esp32_board_initialize(void) +{ + /* Configure on-board LEDs if LED support has been selected. */ + +#ifdef CONFIG_ARCH_LEDS + board_autoled_initialize(); +#endif +} + +/**************************************************************************** + * Name: board_late_initialize + * + * Description: + * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_late_initialize(). board_late_initialize() will + * be called immediately after up_initialize() is called and just before + * the initial application is started. This additional initialization + * phase may be used, for example, to initialize board-specific device + * drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_LATE_INITIALIZE +void board_late_initialize(void) +{ + /* Perform board-specific initialization */ + + esp32_bringup(); + +#ifdef CONFIG_SMP + /* To avoid corrupting the heap, this region of memory (~3KB) is not + * included until the APP CPU has started. + * So we can't add it with the rest of the regions at xtensa_add_region(), + * that function is called early from up_initialize(). We wait until the + * SMP bringup is complete. + */ + + umm_addregion((void *)HEAP_REGION_ROMAPP_START, + (size_t)(HEAP_REGION_ROMAPP_END - HEAP_REGION_ROMAPP_START)); +#endif +} +#endif diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_bringup.c new file mode 100644 index 00000000000..049c3e5bdaa --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_bringup.c @@ -0,0 +1,450 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-audio-kit/src/esp32_bringup.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "esp32_i2c.h" +#include "esp32_gpio.h" +#include "esp32_partition.h" + +#include + +#ifdef CONFIG_USERLED +# include +#endif + +#ifdef CONFIG_TIMER +#include +#endif + +#ifdef CONFIG_ONESHOT +# include "esp32_board_oneshot.h" +#endif + +#ifdef CONFIG_WATCHDOG +# include "esp32_board_wdt.h" +#endif + +#ifdef CONFIG_ESP32_SPIFLASH +# include "esp32_board_spiflash.h" +#endif + +#ifdef CONFIG_ESP32_BLE +# include "esp32_ble.h" +#endif + +#ifdef CONFIG_ESP32_WIFI +# include "esp32_board_wlan.h" +#endif + +#ifdef CONFIG_ESP32_I2C +# include "esp32_board_i2c.h" +#endif + +#ifdef CONFIG_ESP32_I2S +# include "esp32_i2s.h" +#endif + +#ifdef CONFIG_SENSORS_BMP180 +# include "esp32_bmp180.h" +#endif + +#ifdef CONFIG_INPUT_BUTTONS +# include +#endif + +#ifdef CONFIG_VIDEO_FB +# include +#endif + +#ifdef CONFIG_ESP32_RT_TIMER +# include "esp32_rt_timer.h" +#endif + +#ifdef CONFIG_LCD_DEV +# include +# include +#endif + +#ifdef CONFIG_RTC_DRIVER +# include "esp32_rtc_lowerhalf.h" +#endif + +#ifdef CONFIG_LCD_BACKPACK +# include "esp32_lcd_backpack.h" +#endif + +#include "esp32-audio-kit.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_LATE_INITIALIZE=y : + * Called from board_late_initialize(). + * + * CONFIG_BOARD_LATE_INITIALIZE=n && CONFIG_BOARDCTL=y : + * Called from the NSH library + * + ****************************************************************************/ + +int esp32_bringup(void) +{ + int ret; + +#if defined(CONFIG_ESP32_SPIRAM) && \ + defined(CONFIG_ESP32_SPIRAM_BANKSWITCH_ENABLE) + ret = esp_himem_init(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to init HIMEM: %d\n", ret); + } +#endif + +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = nx_mount(NULL, "/proc", "procfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount procfs at /proc: %d\n", ret); + } +#endif + +#ifdef CONFIG_FS_TMPFS + /* Mount the tmpfs file system */ + + ret = nx_mount(NULL, CONFIG_LIBC_TMPDIR, "tmpfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount tmpfs at %s: %d\n", + CONFIG_LIBC_TMPDIR, ret); + } +#endif + +#ifdef CONFIG_LCD_BACKPACK + /* slcd:0, i2c:0, rows=2, cols=16 */ + + ret = board_lcd_backpack_init(0, 0, 2, 16); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize PCF8574 LCD, error %d\n", ret); + } +#endif + +#ifdef CONFIG_MMCSD + ret = esp32_mmcsd_initialize(0); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize SD slot: %d\n", ret); + } +#endif + +#ifdef CONFIG_ESP32_SPIFLASH + ret = esp32_spiflash_init(); + if (ret) + { + syslog(LOG_ERR, "ERROR: Failed to initialize SPI Flash\n"); + } +#endif + +#ifdef CONFIG_ESP32_PARTITION_TABLE + ret = esp32_partition_init(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to initialize partition error=%d\n", + ret); + } +#endif + +#ifdef CONFIG_ESP32_RT_TIMER + ret = esp32_rt_timer_init(); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize RT timer: %d\n", ret); + } +#endif + +#ifdef CONFIG_ESP32_BLE + ret = esp32_ble_initialize(); + if (ret) + { + syslog(LOG_ERR, "ERROR: Failed to initialize BLE: %d\n", ret); + } +#endif + +#ifdef CONFIG_ESP32_WIFI + ret = board_wlan_init(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to initialize wireless subsystem=%d\n", + ret); + } +#endif + +/* First, register the timer drivers and let timer 1 for oneshot + * if it is enabled. + */ + +#ifdef CONFIG_TIMER + +#if defined(CONFIG_ESP32_TIMER0) && !defined(CONFIG_ESP32_RT_TIMER) + ret = esp32_timer_initialize("/dev/timer0", TIMER0); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize timer driver: %d\n", + ret); + } +#endif + +#if defined(CONFIG_ESP32_TIMER1) && !defined(CONFIG_ONESHOT) + ret = esp32_timer_initialize("/dev/timer1", TIMER1); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize timer driver: %d\n", + ret); + } +#endif + +#ifdef CONFIG_ESP32_TIMER2 + ret = esp32_timer_initialize("/dev/timer2", TIMER2); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize timer driver: %d\n", + ret); + } +#endif + +#ifdef CONFIG_ESP32_TIMER3 + ret = esp32_timer_initialize("/dev/timer3", TIMER3); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize timer driver: %d\n", + ret); + } +#endif + +#endif /* CONFIG_TIMER */ + + /* Now register one oneshot driver */ + +#if defined(CONFIG_ONESHOT) && defined(CONFIG_ESP32_TIMER1) + + ret = esp32_oneshot_init(ONESHOT_TIMER, ONESHOT_RESOLUTION_US); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: esp32_oneshot_init() failed: %d\n", ret); + } + +#endif /* CONFIG_ONESHOT */ + +#ifdef CONFIG_USERLED + /* Register the LED driver */ + + ret = userled_lower_initialize("/dev/userleds"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_WATCHDOG + /* Configure watchdog timer */ + + ret = board_wdt_init(); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize watchdog drivers: %d\n", + ret); + } +#endif + +#ifdef CONFIG_DEV_GPIO + ret = esp32_gpio_init(); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize GPIO Driver: %d\n", ret); + } +#endif + +#ifdef CONFIG_I2C_DRIVER + +#ifdef CONFIG_ESP32_I2C0 + ret = esp32_i2c_register(0); + + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize I2C Driver for I2C0: %d\n", ret); + } +#endif + +#ifdef CONFIG_ESP32_I2C1 + ret = esp32_i2c_register(1); + + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize I2C Driver for I2C1: %d\n", ret); + } +#endif + +#endif + +#ifdef CONFIG_ESP32_I2S + +#ifdef CONFIG_ESP32_I2S0 + + /* Configure I2S0 */ + +#ifdef CONFIG_AUDIO_ES8388 + + /* Configure ES8388 audio on I2C0 and I2S0 */ + + esp32_configgpio(SPEAKER_ENABLE_GPIO, OUTPUT); + esp32_gpiowrite(SPEAKER_ENABLE_GPIO, true); + + ret = esp32_es8388_initialize(ESP32_I2C0, ES8388_I2C_ADDR, + ES8388_I2C_FREQ, ESP32_I2S0); + if (ret != OK) + { + syslog(LOG_ERR, "Failed to initialize ES8388 audio: %d\n", ret); + } +#else + + /* Configure I2S generic audio on I2S0 */ + + ret = board_i2sdev_initialize(ESP32_I2S0); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize I2S%d driver: %d\n", + CONFIG_ESP32_I2S0, ret); + } +#endif /* CONFIG_AUDIO_ES8388 */ + +#endif /* CONFIG_ESP32_I2S0 */ + +#ifdef CONFIG_ESP32_I2S1 + + /* Configure I2S generic audio on I2S1 */ + + ret = board_i2sdev_initialize(ESP32_I2S1); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize I2S%d driver: %d\n", + CONFIG_ESP32_I2S0, ret); + } + +#endif /* CONFIG_ESP32_I2S1 */ + +#endif /* CONFIG_ESP32_I2S */ + +#ifdef CONFIG_SENSORS_BMP180 + /* Try to register BMP180 device in I2C0 */ + + ret = board_bmp180_initialize(0, 0); + + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize BMP180 driver: %d\n", ret); + } +#endif + +#ifdef CONFIG_INPUT_BUTTONS + /* Register the BUTTON driver */ + + ret = btn_lower_initialize("/dev/buttons"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_VIDEO_FB + ret = fb_register(0, 0); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to initialize Frame Buffer Driver.\n"); + } +#endif + +#ifdef CONFIG_LCD_DEV + ret = board_lcd_initialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: board_lcd_initialize() failed: %d\n", ret); + } + + ret = lcddev_register(0); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: lcddev_register() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_RTC_DRIVER + /* Instantiate the ESP32 RTC driver */ + + ret = esp32_rtc_driverinit(); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to Instantiate the RTC driver: %d\n", ret); + } +#endif + + /* If we got here then perhaps not all initialization was successful, but + * at least enough succeeded to bring-up NSH with perhaps reduced + * capabilities. + */ + + UNUSED(ret); + return OK; +} + diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_buttons.c b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_buttons.c new file mode 100644 index 00000000000..278ff8a6e3a --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_buttons.c @@ -0,0 +1,166 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-audio-kit/src/esp32_buttons.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "esp32_gpio.h" + +#include "esp32-audio-kit.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_button_initialize + * + * Description: + * board_button_initialize() must be called to initialize button resources. + * After that, board_buttons() may be called to collect the current state + * of all buttons or board_button_irq() may be called to register button + * interrupt handlers. + * + ****************************************************************************/ + +uint32_t board_button_initialize(void) +{ + esp32_configgpio(BUTTON_BOOT, INPUT_FUNCTION_3 | PULLUP); + return 1; +} + +/**************************************************************************** + * Name: board_buttons + * + * Description: + * After board_button_initialize() has been called, board_buttons() may be + * called to collect the state of all buttons. board_buttons() returns an + * 8-bit bit set with each bit associated with a button. See the + * BUTTON_*_BIT definitions in board.h for the meaning of each bit. + * + ****************************************************************************/ + +uint32_t board_buttons(void) +{ + uint8_t ret = 0; + int i = 0; + int n = 0; + + bool b0 = esp32_gpioread(BUTTON_BOOT); + + for (i = 0; i < 10; i++) + { + up_mdelay(1); /* TODO */ + + bool b1 = esp32_gpioread(BUTTON_BOOT); + + if (b0 == b1) + { + n++; + } + else + { + n = 0; + } + + if (3 == n) + { + break; + } + + b0 = b1; + } + + iinfo("b=%d n=%d\n", b0, n); + + /* Low value means that the button is pressed */ + + if (!b0) + { + ret = 0x1; + } + + return ret; +} + +/**************************************************************************** + * Name: board_button_irq + * + * Description: + * board_button_irq() may be called to register an interrupt handler that + * will be called when a button is depressed or released. The ID value is + * a button enumeration value that uniquely identifies a button resource. + * See the BUTTON_* definitions in board.h for the meaning of enumeration + * value. + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_IRQBUTTONS +int board_button_irq(int id, xcpt_t irqhandler, void *arg) +{ + int ret; + DEBUGASSERT(id == 0); + + int irq = ESP32_PIN2IRQ(BUTTON_BOOT); + + if (NULL != irqhandler) + { + /* Make sure the interrupt is disabled */ + + esp32_gpioirqdisable(irq); + + ret = irq_attach(irq, irqhandler, arg); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: irq_attach() failed: %d\n", ret); + return ret; + } + + gpioinfo("Attach %p\n", irqhandler); + + gpioinfo("Enabling the interrupt\n"); + + /* Configure the interrupt for rising and falling edges */ + + esp32_gpioirqenable(irq, CHANGE); + } + else + { + gpioinfo("Disable the interrupt\n"); + esp32_gpioirqdisable(irq); + } + + return OK; +} +#endif diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_gpio.c b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_gpio.c new file mode 100644 index 00000000000..e23048cc448 --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_gpio.c @@ -0,0 +1,391 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-audio-kit/src/esp32_gpio.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +#include + +#include + +#include "esp32-audio-kit.h" +#include "esp32_gpio.h" +#include "hardware/esp32_gpio_sigmap.h" + +#if defined(CONFIG_DEV_GPIO) && !defined(CONFIG_GPIO_LOWER_HALF) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if !defined(CONFIG_ESP32_GPIO_IRQ) && BOARD_NGPIOINT > 0 +# error "NGPIOINT is > 0 and GPIO interrupts aren't enabled" +#endif + +/* Output pins. GPIO16 is used as an example, any other outputs could be + * used. + */ + +#define GPIO_OUT1 16 + +/* Input pins. GPIO17 is used as an example, any other inputs could be + * used. + */ + +#define GPIO_IN1 17 + +/* Interrupt pins. GPIO24 is used as an example, any other inputs could be + * used. + */ + +#define GPIO_IRQPIN1 24 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct esp32gpio_dev_s +{ + struct gpio_dev_s gpio; + uint8_t id; +}; + +struct esp32gpint_dev_s +{ + struct esp32gpio_dev_s esp32gpio; + pin_interrupt_t callback; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +#if BOARD_NGPIOOUT > 0 +static int gpout_read(struct gpio_dev_s *dev, bool *value); +static int gpout_write(struct gpio_dev_s *dev, bool value); +#endif + +#if BOARD_NGPIOIN > 0 +static int gpin_read(struct gpio_dev_s *dev, bool *value); +#endif + +#if BOARD_NGPIOINT > 0 +static int gpint_read(struct gpio_dev_s *dev, bool *value); +static int gpint_attach(struct gpio_dev_s *dev, + pin_interrupt_t callback); +static int gpint_enable(struct gpio_dev_s *dev, bool enable); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#if BOARD_NGPIOOUT > 0 +static const struct gpio_operations_s gpout_ops = +{ + .go_read = gpout_read, + .go_write = gpout_write, + .go_attach = NULL, + .go_enable = NULL, +}; + +/* This array maps the GPIO pins used as OUTPUT */ + +static const uint32_t g_gpiooutputs[BOARD_NGPIOOUT] = +{ + GPIO_OUT1 +}; + +static struct esp32gpio_dev_s g_gpout[BOARD_NGPIOOUT]; +#endif + +#if BOARD_NGPIOIN > 0 +static const struct gpio_operations_s gpin_ops = +{ + .go_read = gpin_read, + .go_write = NULL, + .go_attach = NULL, + .go_enable = NULL, +}; + +/* This array maps the GPIO pins used as INTERRUPT INPUTS */ + +static const uint32_t g_gpioinputs[BOARD_NGPIOIN] = +{ + GPIO_IN1 +}; + +static struct esp32gpio_dev_s g_gpin[BOARD_NGPIOIN]; +#endif + +#if BOARD_NGPIOINT > 0 +static const struct gpio_operations_s gpint_ops = +{ + .go_read = gpint_read, + .go_write = NULL, + .go_attach = gpint_attach, + .go_enable = gpint_enable, +}; + +/* This array maps the GPIO pins used as INTERRUPT INPUTS */ + +static const uint32_t g_gpiointinputs[BOARD_NGPIOINT] = +{ + GPIO_IRQPIN1, +}; + +static struct esp32gpint_dev_s g_gpint[BOARD_NGPIOINT]; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gpout_read + ****************************************************************************/ + +#if BOARD_NGPIOOUT > 0 +static int gpout_read(struct gpio_dev_s *dev, bool *value) +{ + struct esp32gpio_dev_s *esp32gpio = (struct esp32gpio_dev_s *)dev; + + DEBUGASSERT(esp32gpio != NULL && value != NULL); + DEBUGASSERT(esp32gpio->id < BOARD_NGPIOOUT); + gpioinfo("Reading...\n"); + + *value = esp32_gpioread(g_gpiooutputs[esp32gpio->id]); + return OK; +} + +/**************************************************************************** + * Name: gpout_write + ****************************************************************************/ + +static int gpout_write(struct gpio_dev_s *dev, bool value) +{ + struct esp32gpio_dev_s *esp32gpio = (struct esp32gpio_dev_s *)dev; + + DEBUGASSERT(esp32gpio != NULL); + DEBUGASSERT(esp32gpio->id < BOARD_NGPIOOUT); + gpioinfo("Writing %d\n", (int)value); + + esp32_gpiowrite(g_gpiooutputs[esp32gpio->id], value); + return OK; +} +#endif + +/**************************************************************************** + * Name: gpin_read + ****************************************************************************/ + +#if BOARD_NGPIOIN > 0 +static int gpin_read(struct gpio_dev_s *dev, bool *value) +{ + struct esp32gpio_dev_s *esp32gpio = (struct esp32gpio_dev_s *)dev; + + DEBUGASSERT(esp32gpio != NULL && value != NULL); + DEBUGASSERT(esp32gpio->id < BOARD_NGPIOIN); + gpioinfo("Reading... pin %d\n", g_gpioinputs[esp32gpio->id]); + + *value = esp32_gpioread(g_gpioinputs[esp32gpio->id]); + return OK; +} +#endif + +/**************************************************************************** + * Name: esp32gpio_interrupt + ****************************************************************************/ + +#if BOARD_NGPIOINT > 0 +static int esp32gpio_interrupt(int irq, void *context, void *arg) +{ + struct esp32gpint_dev_s *esp32gpint = + (struct esp32gpint_dev_s *)arg; + + DEBUGASSERT(esp32gpint != NULL && esp32gpint->callback != NULL); + gpioinfo("Interrupt! callback=%p\n", esp32gpint->callback); + + esp32gpint->callback(&esp32gpint->esp32gpio.gpio, + esp32gpint->esp32gpio.id); + return OK; +} + +/**************************************************************************** + * Name: gpint_read + ****************************************************************************/ + +static int gpint_read(struct gpio_dev_s *dev, bool *value) +{ + struct esp32gpint_dev_s *esp32gpint = + (struct esp32gpint_dev_s *)dev; + + DEBUGASSERT(esp32gpint != NULL && value != NULL); + DEBUGASSERT(esp32gpint->esp32gpio.id < BOARD_NGPIOINT); + gpioinfo("Reading int pin...\n"); + + *value = esp32_gpioread(g_gpiointinputs[esp32gpint->esp32gpio.id]); + return OK; +} + +/**************************************************************************** + * Name: gpint_attach + ****************************************************************************/ + +static int gpint_attach(struct gpio_dev_s *dev, + pin_interrupt_t callback) +{ + struct esp32gpint_dev_s *esp32gpint = + (struct esp32gpint_dev_s *)dev; + int irq = ESP32_PIN2IRQ(g_gpiointinputs[esp32gpint->esp32gpio.id]); + int ret; + + gpioinfo("Attaching the callback\n"); + + /* Make sure the interrupt is disabled */ + + esp32_gpioirqdisable(irq); + ret = irq_attach(irq, + esp32gpio_interrupt, + &g_gpint[esp32gpint->esp32gpio.id]); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: gpint_attach() failed: %d\n", ret); + return ret; + } + + gpioinfo("Attach %p\n", callback); + esp32gpint->callback = callback; + return OK; +} + +/**************************************************************************** + * Name: gpint_enable + ****************************************************************************/ + +static int gpint_enable(struct gpio_dev_s *dev, bool enable) +{ + struct esp32gpint_dev_s *esp32gpint = + (struct esp32gpint_dev_s *)dev; + int irq = ESP32_PIN2IRQ(g_gpiointinputs[esp32gpint->esp32gpio.id]); + + if (enable) + { + if (esp32gpint->callback != NULL) + { + gpioinfo("Enabling the interrupt\n"); + + /* Configure the interrupt for rising edge */ + + esp32_gpioirqenable(irq, RISING); + } + } + else + { + gpioinfo("Disable the interrupt\n"); + esp32_gpioirqdisable(irq); + } + + return OK; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_gpio_init + ****************************************************************************/ + +int esp32_gpio_init(void) +{ + int pincount = 0; + int i; + +#if BOARD_NGPIOOUT > 0 + for (i = 0; i < BOARD_NGPIOOUT; i++) + { + /* Setup and register the GPIO pin */ + + g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN; + g_gpout[i].gpio.gp_ops = &gpout_ops; + g_gpout[i].id = i; + gpio_pin_register(&g_gpout[i].gpio, pincount); + + /* Configure the pins that will be used as output */ + + esp32_gpio_matrix_out(g_gpiooutputs[i], SIG_GPIO_OUT_IDX, 0, 0); + esp32_configgpio(g_gpiooutputs[i], OUTPUT_FUNCTION_3 | + INPUT_FUNCTION_3); + esp32_gpiowrite(g_gpiooutputs[i], 0); + + pincount++; + } +#endif + +#if BOARD_NGPIOIN > 0 + for (i = 0; i < BOARD_NGPIOIN; i++) + { + /* Setup and register the GPIO pin */ + + g_gpin[i].gpio.gp_pintype = GPIO_INPUT_PIN; + g_gpin[i].gpio.gp_ops = &gpin_ops; + g_gpin[i].id = i; + gpio_pin_register(&g_gpin[i].gpio, pincount); + + /* Configure the pins that will be used as INPUT */ + + esp32_configgpio(g_gpioinputs[i], INPUT_FUNCTION_3); + + pincount++; + } +#endif + +#if BOARD_NGPIOINT > 0 + for (i = 0; i < BOARD_NGPIOINT; i++) + { + /* Setup and register the GPIO pin */ + + g_gpint[i].esp32gpio.gpio.gp_pintype = GPIO_INTERRUPT_PIN; + g_gpint[i].esp32gpio.gpio.gp_ops = &gpint_ops; + g_gpint[i].esp32gpio.id = i; + gpio_pin_register(&g_gpint[i].esp32gpio.gpio, pincount); + + /* Configure the pins that will be used as interrupt input */ + + esp32_configgpio(g_gpiointinputs[i], INPUT_FUNCTION_3 | PULLDOWN); + + pincount++; + } +#endif + + return OK; +} +#endif /* CONFIG_DEV_GPIO && !CONFIG_GPIO_LOWER_HALF */ diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_mmcsd.c b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_mmcsd.c new file mode 100644 index 00000000000..2ae013af5ee --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_mmcsd.c @@ -0,0 +1,84 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-audio-kit/src/esp32_mmcsd.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "esp32_spi.h" +#include "esp32-audio-kit.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_mmcsd_initialize + * + * Description: + * Initialize SPI-based SD card and card detect thread. + ****************************************************************************/ + +int esp32_mmcsd_initialize(int minor) +{ + struct spi_dev_s *spi; + int rv; + + mcinfo("INFO: Initializing mmcsd card\n"); + + spi = esp32_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO); + if (spi == NULL) + { + mcerr("ERROR: Failed to initialize SPI port %d\n", 2); + return -ENODEV; + } + + rv = mmcsd_spislotinitialize(minor, 0, spi); + if (rv < 0) + { + mcerr("ERROR: Failed to bind SPI port %d to SD slot %d\n", + 2, 0); + return rv; + } + + spiinfo("INFO: mmcsd card has been initialized successfully\n"); + return OK; +} diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_reset.c b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_reset.c new file mode 100644 index 00000000000..a262a3d307f --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_reset.c @@ -0,0 +1,63 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-audio-kit/src/esp32_reset.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#ifdef CONFIG_BOARDCTL_RESET + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_reset + * + * Description: + * Reset board. Support for this function is required by board-level + * logic if CONFIG_BOARDCTL_RESET is selected. + * + * Input Parameters: + * status - Status information provided with the reset event. This + * meaning of this status information is board-specific. If not + * used by a board, the value zero may be provided in calls to + * board_reset(). + * + * Returned Value: + * If this function returns, then it was not possible to power-off the + * board due to some constraints. The return value in this case is a + * board-specific reason for the failure to shutdown. + * + ****************************************************************************/ + +int board_reset(int status) +{ + up_systemreset(); + + return 0; +} + +#endif /* CONFIG_BOARDCTL_RESET */ diff --git a/boards/xtensa/esp32/esp32-audio-kit/src/esp32_userleds.c b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_userleds.c new file mode 100644 index 00000000000..33964fe1e1d --- /dev/null +++ b/boards/xtensa/esp32/esp32-audio-kit/src/esp32_userleds.c @@ -0,0 +1,95 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-audio-kit/src/esp32_userleds.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "esp32_gpio.h" +#include "esp32-audio-kit.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* This array maps an LED number to GPIO pin configuration */ + +static const uint32_t g_ledcfg[BOARD_NLEDS] = +{ + GPIO_LED1 +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_userled_initialize + ****************************************************************************/ + +uint32_t board_userled_initialize(void) +{ + uint8_t i; + + /* Configure the LEDs GPIOs as outputs */ + + for (i = 0; i < BOARD_NLEDS; i++) + { + esp32_configgpio(g_ledcfg[i], OUTPUT); + } + + return BOARD_NLEDS; +} + +/**************************************************************************** + * Name: board_userled + ****************************************************************************/ + +void board_userled(int led, bool ledon) +{ + if ((unsigned)led < BOARD_NLEDS) + { + esp32_gpiowrite(g_ledcfg[led], ledon); + } +} + +/**************************************************************************** + * Name: board_userled_all + ****************************************************************************/ + +void board_userled_all(uint32_t ledset) +{ + uint8_t i; + + for (i = 0; i < BOARD_NLEDS; i++) + { + esp32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0); + } +} +