diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/src/Makefile b/boards/risc-v/esp32c3/esp32c3-devkit/src/Makefile index a1d7477757d..b46de7c8002 100644 --- a/boards/risc-v/esp32c3/esp32c3-devkit/src/Makefile +++ b/boards/risc-v/esp32c3/esp32c3-devkit/src/Makefile @@ -50,6 +50,10 @@ ifeq ($(CONFIG_SPI_DRIVER),y) CSRCS += esp32c3_board_spidev.c endif +ifeq ($(CONFIG_SPI_SLAVE_DRIVER),y) +CSRCS += esp32c3_board_spislavedev.c +endif + ifeq ($(CONFIG_I2C_DRIVER),y) CSRCS += esp32c3_i2c.c endif diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3-devkit.h b/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3-devkit.h index 7f903521ca5..de523f7679d 100644 --- a/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3-devkit.h +++ b/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3-devkit.h @@ -114,6 +114,25 @@ int board_wdt_init(void); int board_spidev_initialize(int bus); #endif +/**************************************************************************** + * Name: board_spislavedev_initialize + * + * Description: + * Initialize SPI Slave driver and register the /dev/spislv device. + * + * Input Parameters: + * bus - The SPI bus number, used to build the device path as /dev/spislvN + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_SLAVE +int board_spislavedev_initialize(int bus); +#endif + /**************************************************************************** * Name: board_i2c_init * diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_board_spislavedev.c b/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_board_spislavedev.c new file mode 100644 index 00000000000..effdcdaa501 --- /dev/null +++ b/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_board_spislavedev.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_board_spislavedev.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 "esp32c3_spi.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_spislavedev_initialize + * + * Description: + * Initialize SPI Slave driver and register the /dev/spislv device. + * + * Input Parameters: + * bus - The SPI bus number, used to build the device path as /dev/spislvN + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * + ****************************************************************************/ + +int board_spislavedev_initialize(int bus) +{ + int ret; + + FAR struct spi_sctrlr_s *sctrlr; + + spiinfo("Initializing /dev/spislv%d...\n", bus); + + /* Initialize SPI Slave controller device */ + + sctrlr = esp32c3_spislave_sctrlr_initialize(bus); + if (sctrlr == NULL) + { + spierr("Failed to initialize SPI%d as slave.\n", bus); + return -ENODEV; + } + + ret = spislv_register(sctrlr, bus); + if (ret < 0) + { + spierr("Failed to register /dev/spislv%d: %d\n", bus, ret); + + esp32c3_spislave_sctrlr_uninitialize(sctrlr); + } + + return ret; +} diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_bringup.c b/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_bringup.c index 405ee9d09bb..050a8d7b09e 100644 --- a/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_bringup.c +++ b/boards/risc-v/esp32c3/esp32c3-devkit/src/esp32c3_bringup.c @@ -42,7 +42,7 @@ #include "esp32c3_partition.h" #include "esp32c3-devkit.h" -#ifdef CONFIG_SPI_DRIVER +#ifdef CONFIG_SPI # include "esp32c3_spi.h" #endif @@ -185,6 +185,15 @@ int esp32c3_bringup(void) } #endif +#if defined(CONFIG_SPI_SLAVE_DRIVER) && defined(CONFIG_ESP32C3_SPI2) + ret = board_spislavedev_initialize(ESP32C3_SPI2); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize SPI%d Slave driver: %d\n", + ESP32C3_SPI2, ret); + } +#endif + #if defined(CONFIG_I2C_DRIVER) /* Configure I2C peripheral interfaces */