This is an automated email from the ASF dual-hosted git repository. masayuki pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 7fb73dba1c2175d720170f21094194130819ff81 Author: Yuichi Nakamura <y.512.nakam...@gmail.com> AuthorDate: Sun Apr 18 19:05:37 2021 +0900 boards/raspberrypi-pico: Pico Audio Pack (I2S) support --- boards/arm/rp2040/common/src/Make.defs | 4 + boards/arm/rp2040/common/src/rp2040_i2sdev.c | 95 ++++++++++++++++++++++ boards/arm/rp2040/raspberrypi-pico/README.txt | 14 ++++ .../raspberrypi-pico/configs/audiopack/defconfig | 75 +++++++++++++++++ boards/arm/rp2040/raspberrypi-pico/include/board.h | 1 + .../include/{board.h => rp2040_i2sdev.h} | 62 +++----------- .../rp2040/raspberrypi-pico/src/rp2040_bringup.c | 8 ++ 7 files changed, 208 insertions(+), 51 deletions(-) diff --git a/boards/arm/rp2040/common/src/Make.defs b/boards/arm/rp2040/common/src/Make.defs index 259975a..68b28c3 100644 --- a/boards/arm/rp2040/common/src/Make.defs +++ b/boards/arm/rp2040/common/src/Make.defs @@ -26,6 +26,10 @@ ifeq ($(CONFIG_RP2040_SPI_DRIVER),y) CSRCS += rp2040_spidev.c endif +ifeq ($(CONFIG_RP2040_I2S),y) +CSRCS += rp2040_i2sdev.c +endif + ifeq ($(CONFIG_LCD_SSD1306),y) CSRCS += rp2040_ssd1306.c endif diff --git a/boards/arm/rp2040/common/src/rp2040_i2sdev.c b/boards/arm/rp2040/common/src/rp2040_i2sdev.c new file mode 100644 index 0000000..2b74f68 --- /dev/null +++ b/boards/arm/rp2040/common/src/rp2040_i2sdev.c @@ -0,0 +1,95 @@ +/**************************************************************************** + * boards/arm/rp2040/common/src/rp2040_i2sdev.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 <nuttx/config.h> + +#include <stdio.h> +#include <debug.h> +#include <errno.h> + +#include <nuttx/audio/audio.h> +#include <nuttx/audio/audio_i2s.h> +#include <nuttx/audio/i2s.h> +#include <nuttx/audio/pcm.h> + +#include <arch/board/board.h> + +#include "arm_arch.h" +#include "rp2040_i2s.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_i2sdev_initialize + * + * Description: + * Initialize i2s driver and register the /dev/audio/pcm0 device. + * + ****************************************************************************/ + +int board_i2sdev_initialize(int port) +{ + FAR struct audio_lowerhalf_s *audio_i2s; + FAR struct audio_lowerhalf_s *pcm; + FAR struct i2s_dev_s *i2s; + char devname[12]; + int ret; + + ainfo("Initializing I2S\n"); + + i2s = rp2040_i2sbus_initialize(port); + +#ifdef CONFIG_AUDIO_I2SCHAR + i2schar_register(i2s, 0); +#endif + + audio_i2s = audio_i2s_initialize(i2s, true); + + if (!audio_i2s) + { + auderr("ERROR: Failed to initialize I2S\n"); + return -ENODEV; + } + + pcm = pcm_decode_initialize(audio_i2s); + + if (!pcm) + { + auderr("ERROR: Failed create the PCM decoder\n"); + return -ENODEV; + } + + snprintf(devname, 12, "pcm%d", port); + + ret = audio_register(devname, pcm); + + if (ret < 0) + { + auderr("ERROR: Failed to register /dev/%s device: %d\n", devname, ret); + } + + return 0; +} diff --git a/boards/arm/rp2040/raspberrypi-pico/README.txt b/boards/arm/rp2040/raspberrypi-pico/README.txt index d3a4f30..23fa5f8 100644 --- a/boards/arm/rp2040/raspberrypi-pico/README.txt +++ b/boards/arm/rp2040/raspberrypi-pico/README.txt @@ -13,6 +13,7 @@ Currently only the following devices are suppored. - I2C - SPI - DMAC + - PIO (RP2040 Programmable I/O) - Flash ROM Boot - SRAM Boot - If Pico SDK is available, nuttx.uf2 file which can be used in @@ -21,6 +22,8 @@ Currently only the following devices are suppored. - INA219 sensor / module (don't forget to define I2C0 GPIOs at "I2C0 GPIO pin assign" in Board Selection menu) - Pico Display Pack (ST7789 LCD) - RGB leds and buttons are not supported yet. + - Pico Audio Pack (PCM5100A I2S DAC) + - I2S interface is realized by PIO. Not supported: - All other devices @@ -109,6 +112,12 @@ Defconfigs See the following page for connection: https://shop.pimoroni.com/products/pico-display-pack +- audiopack + Pico Audio Pack support + See the following page for connection: + https://shop.pimoroni.com/products/pico-audio-pack + SD card interface is also enabled. + License exceptions ================== @@ -120,5 +129,10 @@ So, the files are licensed under 3-Clause BSD same as Pico SDK. - arch/arm/src/rp2040/rp2040_xosc.c - These are created by referring the Pico SDK clock initialization. +- arch/arm/src/rp2040/rp2040_pio.c +- arch/arm/src/rp2040/rp2040_pio.h +- arch/arm/src/rp2040/rp2040_pio_instructions.h + - These provide the similar APIs to Pico SDK's hardware_pio APIs. + - arch/arm/src/rp2040/hardware/*.h - These are generated from rp2040.svd originally provided in Pico SDK. diff --git a/boards/arm/rp2040/raspberrypi-pico/configs/audiopack/defconfig b/boards/arm/rp2040/raspberrypi-pico/configs/audiopack/defconfig new file mode 100644 index 0000000..479ae48 --- /dev/null +++ b/boards/arm/rp2040/raspberrypi-pico/configs/audiopack/defconfig @@ -0,0 +1,75 @@ +# +# 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_AUDIO_FORMAT_MP3 is not set +# CONFIG_FS_PROCFS_EXCLUDE_ENVIRON is not set +# CONFIG_LIBC_LONG_LONG is not set +# CONFIG_MMCSD_HAVE_CARDDETECT is not set +# CONFIG_MMCSD_HAVE_WRITEPROTECT is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +# CONFIG_NSH_DISABLE_DATE is not set +# CONFIG_NSH_DISABLE_LOSMART is not set +# CONFIG_NSH_DISABLE_MB is not set +# CONFIG_NSH_DISABLE_MH is not set +# CONFIG_NSH_DISABLE_MW is not set +# CONFIG_NSH_DISABLE_PRINTF is not set +# CONFIG_NSH_DISABLE_TRUNCATE is not set +# CONFIG_SPI_CALLBACK is not set +# CONFIG_STANDARD_SERIAL is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="raspberrypi-pico" +CONFIG_ARCH_BOARD_RASPBERRYPI_PICO=y +CONFIG_ARCH_CHIP="rp2040" +CONFIG_ARCH_CHIP_RP2040=y +CONFIG_ARCH_RAMVECTORS=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_AUDIO=y +CONFIG_AUDIO_I2S=y +CONFIG_AUDIO_I2SCHAR=y +CONFIG_BOARDCTL_RESET=y +CONFIG_BOARD_LOOPSPERMSEC=10450 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DISABLE_POSIX_TIMERS=y +CONFIG_DRIVERS_AUDIO=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_FAT_LCNAMES=y +CONFIG_FAT_LFN=y +CONFIG_FS_FAT=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y +CONFIG_MAX_TASKS=8 +CONFIG_MMCSD=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_READLINE=y +CONFIG_NXPLAYER_DEFAULT_MEDIADIR="/mnt/sd0" +CONFIG_RAM_SIZE=270336 +CONFIG_RAM_START=0x20000000 +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_RP2040_I2S=y +CONFIG_RP2040_SPI0=y +CONFIG_RP2040_SPI0_GPIO=16 +CONFIG_RP2040_SPI=y +CONFIG_RP2040_SPISD=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_WAITPID=y +CONFIG_SDCLONE_DISABLE=y +CONFIG_START_DAY=9 +CONFIG_START_MONTH=2 +CONFIG_START_YEAR=2021 +CONFIG_SYSLOG_CONSOLE=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NXPLAYER=y +CONFIG_SYSTEM_SPITOOL=y +CONFIG_TESTING_GETPRIME=y +CONFIG_TESTING_OSTEST=y +CONFIG_UART0_SERIAL_CONSOLE=y +CONFIG_USER_ENTRYPOINT="nsh_main" diff --git a/boards/arm/rp2040/raspberrypi-pico/include/board.h b/boards/arm/rp2040/raspberrypi-pico/include/board.h index 7269745..539c809 100644 --- a/boards/arm/rp2040/raspberrypi-pico/include/board.h +++ b/boards/arm/rp2040/raspberrypi-pico/include/board.h @@ -29,6 +29,7 @@ #include "rp2040_i2cdev.h" #include "rp2040_spidev.h" +#include "rp2040_i2sdev.h" #include "rp2040_spisd.h" diff --git a/boards/arm/rp2040/raspberrypi-pico/include/board.h b/boards/arm/rp2040/raspberrypi-pico/include/rp2040_i2sdev.h similarity index 56% copy from boards/arm/rp2040/raspberrypi-pico/include/board.h copy to boards/arm/rp2040/raspberrypi-pico/include/rp2040_i2sdev.h index 7269745..7d1b575 100644 --- a/boards/arm/rp2040/raspberrypi-pico/include/board.h +++ b/boards/arm/rp2040/raspberrypi-pico/include/rp2040_i2sdev.h @@ -1,5 +1,5 @@ /**************************************************************************** - * boards/arm/rp2040/raspberrypi-pico/include/board.h + * boards/arm/rp2040/raspberrypi-pico/include/rp2040_i2sdev.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -18,50 +18,15 @@ * ****************************************************************************/ -#ifndef __BOARDS_ARM_RP2040_RASPBERRYPI_PICO_INCLUDE_BOARD_H -#define __BOARDS_ARM_RP2040_RASPBERRYPI_PICO_INCLUDE_BOARD_H +#ifndef __BOARDS_ARM_RP2040_RASPBERRYPI_PICO_INCLUDE_RP2040_I2SDEV_H +#define __BOARDS_ARM_RP2040_RASPBERRYPI_PICO_INCLUDE_RP2040_I2SDEV_H /**************************************************************************** * Included Files ****************************************************************************/ #include <nuttx/config.h> - -#include "rp2040_i2cdev.h" -#include "rp2040_spidev.h" - -#include "rp2040_spisd.h" - -#ifndef __ASSEMBLY__ -# include <stdint.h> -#endif - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Clocking *****************************************************************/ - -#define MHZ 1000000 - -#define BOARD_XOSC_FREQ (12 * MHZ) -#define BOARD_PLL_SYS_FREQ (125 * MHZ) -#define BOARD_PLL_USB_FREQ (48 * MHZ) - -#define BOARD_REF_FREQ (12 * MHZ) -#define BOARD_SYS_FREQ (125 * MHZ) -#define BOARD_PERI_FREQ (125 * MHZ) -#define BOARD_USB_FREQ (48 * MHZ) -#define BOARD_ADC_FREQ (48 * MHZ) -#define BOARD_RTC_FREQ 46875 - -#define BOARD_UART_BASEFREQ BOARD_PERI_FREQ - -#define BOARD_TICK_CLOCK (1 * MHZ) - -/* GPIO definitions *********************************************************/ - -#define BOARD_GPIO_LED_PIN 25 +#include <stdint.h> /**************************************************************************** * Public Types @@ -87,26 +52,21 @@ extern "C" ****************************************************************************/ /**************************************************************************** - * Name: rp2040_boardearlyinitialize - * - * Description: - * - ****************************************************************************/ - -void rp2040_boardearlyinitialize(void); - -/**************************************************************************** - * Name: rp2040_boardinitialize + * Name: board_i2sdev_initialize * * Description: + * Initialize i2s driver and register the /dev/audio/pcm0 device. * ****************************************************************************/ -void rp2040_boardinitialize(void); +#ifdef CONFIG_RP2040_I2S +int board_i2sdev_initialize(int bus); +#endif #undef EXTERN #if defined(__cplusplus) } #endif + #endif /* __ASSEMBLY__ */ -#endif /* __BOARDS_ARM_RP2040_RASPBERRYPI_PICO_INCLUDE_BOARD_H */ +#endif /* __BOARDS_ARM_RP2040_RASPBERRYPI_PICO_INCLUDE_RP2040_I2SDEV_H */ diff --git a/boards/arm/rp2040/raspberrypi-pico/src/rp2040_bringup.c b/boards/arm/rp2040/raspberrypi-pico/src/rp2040_bringup.c index dd040d7..570d0ed 100644 --- a/boards/arm/rp2040/raspberrypi-pico/src/rp2040_bringup.c +++ b/boards/arm/rp2040/raspberrypi-pico/src/rp2040_bringup.c @@ -134,5 +134,13 @@ int rp2040_bringup(void) } #endif +#ifdef CONFIG_RP2040_I2S + ret = board_i2sdev_initialize(0); + if (ret < 0) + { + _err("ERROR: Failed to initialize I2S.\n"); + } +#endif + return ret; }