board/esp32c3-devkit: Add support for SPI Slave chardev driver

This commit is contained in:
Gustavo Henrique Nihei
2021-05-14 22:41:51 -03:00
committed by Abdelatif Guettouche
parent 7e15d897bd
commit 8914646c27
4 changed files with 113 additions and 1 deletions
@@ -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
@@ -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
*
@@ -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 <nuttx/config.h>
#include <stdio.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/spi/slave.h>
#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;
}
@@ -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 */