From 2e17dd17ee9777084b2f211f08c4231dd5f8b906 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Sun, 16 Feb 2025 20:17:07 +0100 Subject: extended gpio implemented --- fw/fe310/eos/dev/spi.c | 122 +++++++++++++++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 45 deletions(-) (limited to 'fw/fe310/eos/dev/spi.c') diff --git a/fw/fe310/eos/dev/spi.c b/fw/fe310/eos/dev/spi.c index 12549fc..fef00e1 100644 --- a/fw/fe310/eos/dev/spi.c +++ b/fw/fe310/eos/dev/spi.c @@ -12,72 +12,112 @@ #include "soc/interrupt.h" #include "soc/spi.h" +#include "soc/spi_priv.h" #include "net.h" +#include "egpio.h" #include "spi.h" #include "spi_cfg.h" -static uint8_t spi_dev; -static uint8_t spi_lock; +#ifdef EOS_DEBUG +#include +#endif + +static unsigned char spi_dstack[EOS_SPI_MAX_DSTACK]; +static unsigned char spi_dstack_len; static uint16_t spi_div[EOS_SPI_MAX_DEV]; -int eos_spi_dev_init(uint8_t wakeup_cause) { +static uint8_t spi_dev(void) { + return spi_dstack_len ? spi_dstack[spi_dstack_len - 1] : EOS_SPI_DEV_NET; +} + +static void spi_stop(unsigned char dev) { + if (dev == EOS_SPI_DEV_NET) { + eos_net_stop(); + } else if (spi_cfg[dev].flags & SPI_DEV_FLAG_9BIT) { + eos_spi_enable(); + } else { + eos_spi_stop(); + } +} + +static void spi_start(unsigned char dev) { + if (dev == EOS_SPI_DEV_NET) { + eos_net_start(); + } else if (spi_cfg[dev].flags & SPI_DEV_FLAG_9BIT) { + eos_spi_configure(spi_div[dev], spi_cfg[dev].csid, spi_cfg[dev].cspin, spi_cfg[dev].evt); + eos_spi_disable(); + } else { + eos_spi_start(spi_div[dev], spi_cfg[dev].csid, spi_cfg[dev].cspin, spi_cfg[dev].evt); + } +} + +int eos_spi_dev_init(void) { int i; for (i=0; i