From d2666545d1fee2554e35270d71cfd653eb0612ac Mon Sep 17 00:00:00 2001 From: "Michael (XIAO Xufeng)" Date: Tue, 12 May 2020 02:31:30 +0800 Subject: [PATCH] spi: simplify the caps header --- components/soc/esp32/include/hal/spi_flash_ll.h | 17 +++++++++++++---- components/soc/esp32/include/soc/spi_caps.h | 2 +- .../esp32s2beta/include/hal/gpspi_flash_ll.h | 12 ++++++++---- .../soc/esp32s2beta/include/hal/spi_flash_ll.h | 6 ++++++ .../esp32s2beta/include/hal/spimem_flash_ll.h | 3 ++- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/components/soc/esp32/include/hal/spi_flash_ll.h b/components/soc/esp32/include/hal/spi_flash_ll.h index d818f011ca..a242450bd4 100644 --- a/components/soc/esp32/include/hal/spi_flash_ll.h +++ b/components/soc/esp32/include/hal/spi_flash_ll.h @@ -40,7 +40,16 @@ #define SPI_FLASH_LL_CLKREG_VAL_80MHZ ((spi_flash_ll_clock_reg_t){.val=0x80000000}) ///< Clock set to 80 MHz /// Get the start address of SPI peripheral registers by the host ID -#define spi_flash_ll_get_hw(host_id) ((host_id)==SPI1_HOST? &SPI1:((host_id)==SPI2_HOST?&SPI2:((host_id)==SPI3_HOST?&SPI3:({abort();(spi_dev_t*)0;})))) +#define spi_flash_ll_get_hw(host_id) ( ((host_id)==SPI1_HOST) ? &SPI1 :(\ + ((host_id)==SPI2_HOST) ? &SPI2 :(\ + ((host_id)==SPI3_HOST) ? &SPI3 :(\ + {abort();(spi_dev_t*)0;}\ + ))) ) +#define spi_flash_ll_hw_get_id(dev) ( ((dev) == &SPI1) ? SPI1_HOST :(\ + ((dev) == &SPI2) ? SPI2_HOST :(\ + ((dev) == &SPI3) ? SPI3_HOST :(\ + -1\ + ))) ) /// type to store pre-calculated register value in above layers typedef typeof(SPI1.clock) spi_flash_ll_clock_reg_t; @@ -155,12 +164,12 @@ static inline void spi_flash_ll_write_word(spi_dev_t *dev, uint32_t word) /** * Set the data to be written in the data buffer. - * + * * @param dev Beginning address of the peripheral registers. - * @param buffer Buffer holding the data + * @param buffer Buffer holding the data * @param length Length of data in bytes. */ -static inline void spi_flash_ll_set_buffer_data(spi_dev_t *dev, const void *buffer, uint32_t length) +static inline void spi_flash_ll_set_buffer_data(spi_dev_t *dev, const void *buffer, uint32_t length) { // Load data registers, word at a time int num_words = (length + 3) >> 2; diff --git a/components/soc/esp32/include/soc/spi_caps.h b/components/soc/esp32/include/soc/spi_caps.h index d5b19b4d70..e1b4708522 100644 --- a/components/soc/esp32/include/soc/spi_caps.h +++ b/components/soc/esp32/include/soc/spi_caps.h @@ -60,4 +60,4 @@ //#define SOC_SPI_SLAVE_SUPPORT_SEG_TRANS //#define SOC_SPI_SUPPORT_CD_SIG -#define SOC_SPI_PERIPH_SUPPORT_MULTILINE_MODE(SPI_HOST) true +#define SOC_SPI_PERIPH_SUPPORT_MULTILINE_MODE(SPI_HOST) ({(void)SPI_HOST; true;}) diff --git a/components/soc/esp32s2beta/include/hal/gpspi_flash_ll.h b/components/soc/esp32s2beta/include/hal/gpspi_flash_ll.h index b08564856e..5e1f0e0655 100644 --- a/components/soc/esp32s2beta/include/hal/gpspi_flash_ll.h +++ b/components/soc/esp32s2beta/include/hal/gpspi_flash_ll.h @@ -31,10 +31,14 @@ #include -#define gpspi_flash_ll_get_hw(host_id) (((host_id)==SPI2_HOST ? &GPSPI2 \ - : ((host_id)==SPI3_HOST ? &GPSPI3 \ - : ((host_id)==SPI4_HOST ? &GPSPI4 \ - : ({abort();(spi_dev_t*)0;}))))) +#define gpspi_flash_ll_get_hw(host_id) ( ((host_id)==SPI2_HOST) ? &GPSPI2 : (\ + ((host_id)==SPI3_HOST) ? &GPSPI3 : (\ + {abort();(spi_dev_t*)0;}\ + )) ) +#define gpspi_flash_ll_hw_get_id(dev) ( ((dev) == (void*)&GPSPI2) ? SPI2_HOST : (\ + ((dev) == (void*)&GPSPI3) ? SPI3_HOST : (\ + -1 \ + )) ) typedef typeof(GPSPI2.clock) gpspi_flash_ll_clock_reg_t; diff --git a/components/soc/esp32s2beta/include/hal/spi_flash_ll.h b/components/soc/esp32s2beta/include/hal/spi_flash_ll.h index cae39f4f91..ced6103e38 100644 --- a/components/soc/esp32s2beta/include/hal/spi_flash_ll.h +++ b/components/soc/esp32s2beta/include/hal/spi_flash_ll.h @@ -37,6 +37,12 @@ #define spi_flash_ll_get_hw(host_id) (((host_id)<=SPI1_HOST ? (spi_dev_t*) spimem_flash_ll_get_hw(host_id) \ : gpspi_flash_ll_get_hw(host_id))) +#define spi_flash_ll_hw_get_id(dev) ({int dev_id = spimem_flash_ll_hw_get_id(dev); \ + if (dev_id < 0) {\ + dev_id = gpspi_flash_ll_hw_get_id(dev);\ + }\ + dev_id; \ + }) typedef union { gpspi_flash_ll_clock_reg_t gpspi; diff --git a/components/soc/esp32s2beta/include/hal/spimem_flash_ll.h b/components/soc/esp32s2beta/include/hal/spimem_flash_ll.h index 100dd31c99..fdf26fd3fe 100644 --- a/components/soc/esp32s2beta/include/hal/spimem_flash_ll.h +++ b/components/soc/esp32s2beta/include/hal/spimem_flash_ll.h @@ -31,7 +31,8 @@ #include "hal/spi_types.h" #include "hal/spi_flash_types.h" -#define spimem_flash_ll_get_hw(host_id) (((host_id)==SPI1_HOST ? &SPIMEM1 : NULL )) +#define spimem_flash_ll_get_hw(host_id) (((host_id)==SPI1_HOST ? &SPIMEM1 : NULL )) +#define spimem_flash_ll_hw_get_id(dev) ((dev) == (void*)&SPIMEM1? SPI1_HOST: -1) typedef typeof(SPIMEM1.clock) spimem_flash_ll_clock_reg_t;