Skip to content

Commit

Permalink
fix(all): unify default mosi level to low on all targets
Browse files Browse the repository at this point in the history
  • Loading branch information
wanckl committed Jul 26, 2023
1 parent 79b1379 commit 7a30edc
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 82 deletions.
13 changes: 7 additions & 6 deletions components/hal/esp32/include/hal/spi_ll.h
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -41,6 +41,7 @@ extern "C" {

#define SPI_LL_DMA_MAX_BIT_LEN (1 << 24) //reg len: 24 bits
#define SPI_LL_CPU_MAX_BIT_LEN (16 * 32) //Fifo len: 16 words
#define SPI_LL_MOSI_FREE_LEVEL 0 //Default level after bus initialized

/**
* The data structure holding calculated clock configuration. Since the
Expand Down Expand Up @@ -123,21 +124,21 @@ static inline bool spi_ll_usr_is_done(spi_dev_t *hw)
}

/**
* Trigger start of user-defined transaction for master.
* Apply the register configurations and wait until it's done
*
* @param hw Beginning address of the peripheral registers.
*/
static inline void spi_ll_master_user_start(spi_dev_t *hw)
static inline void spi_ll_apply_config(spi_dev_t *hw)
{
hw->cmd.usr = 1;
// 32 don't need this option
}

/**
* Trigger start of user-defined transaction for slave.
* Trigger start of user-defined transaction.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline void spi_ll_slave_user_start(spi_dev_t *hw)
static inline void spi_ll_user_start(spi_dev_t *hw)
{
hw->cmd.usr = 1;
}
Expand Down
35 changes: 22 additions & 13 deletions components/hal/esp32c2/include/hal/spi_ll.h
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -40,6 +40,7 @@ extern "C" {

#define SPI_LL_DMA_MAX_BIT_LEN (1 << 18) //reg len: 18 bits
#define SPI_LL_CPU_MAX_BIT_LEN (16 * 32) //Fifo len: 16 words
#define SPI_LL_MOSI_FREE_LEVEL 1 //Default level after bus initialized

/**
* The data structure holding calculated clock configuration. Since the
Expand Down Expand Up @@ -186,36 +187,44 @@ static inline void spi_ll_slave_hd_init(spi_dev_t *hw)
}

/**
* Check whether user-defined transaction is done.
* Determine and unify the default level of mosi line when bus free
*
* @param hw Beginning address of the peripheral registers.
*
* @return True if transaction is done, otherwise false.
*/
static inline bool spi_ll_usr_is_done(spi_dev_t *hw)
static inline void spi_ll_set_mosi_free_level(spi_dev_t *hw, bool level)
{
return hw->dma_int_raw.trans_done;
hw->ctrl.d_pol = level; //set default level for MOSI only on IDLE state
}

/**
* Trigger start of user-defined transaction for master.
* The synchronization between two clock domains is required in ESP32-S3
* Apply the register configurations and wait until it's done
*
* @param hw Beginning address of the peripheral registers.
*/
static inline void spi_ll_master_user_start(spi_dev_t *hw)
static inline void spi_ll_apply_config(spi_dev_t *hw)
{
hw->cmd.update = 1;
while (hw->cmd.update);
hw->cmd.usr = 1;
while (hw->cmd.update); //waiting config applied
}

/**
* Check whether user-defined transaction is done.
*
* @param hw Beginning address of the peripheral registers.
*
* @return True if transaction is done, otherwise false.
*/
static inline bool spi_ll_usr_is_done(spi_dev_t *hw)
{
return hw->dma_int_raw.trans_done;
}

/**
* Trigger start of user-defined transaction for slave.
* Trigger start of user-defined transaction.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline void spi_ll_slave_user_start(spi_dev_t *hw)
static inline void spi_ll_user_start(spi_dev_t *hw)
{
hw->cmd.usr = 1;
}
Expand Down
35 changes: 22 additions & 13 deletions components/hal/esp32c3/include/hal/spi_ll.h
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -40,6 +40,7 @@ extern "C" {

#define SPI_LL_DMA_MAX_BIT_LEN (1 << 18) //reg len: 18 bits
#define SPI_LL_CPU_MAX_BIT_LEN (16 * 32) //Fifo len: 16 words
#define SPI_LL_MOSI_FREE_LEVEL 1 //Default level after bus initialized

/**
* The data structure holding calculated clock configuration. Since the
Expand Down Expand Up @@ -186,36 +187,44 @@ static inline void spi_ll_slave_hd_init(spi_dev_t *hw)
}

/**
* Check whether user-defined transaction is done.
* Determine and unify the default level of mosi line when bus free
*
* @param hw Beginning address of the peripheral registers.
*
* @return True if transaction is done, otherwise false.
*/
static inline bool spi_ll_usr_is_done(spi_dev_t *hw)
static inline void spi_ll_set_mosi_free_level(spi_dev_t *hw, bool level)
{
return hw->dma_int_raw.trans_done;
hw->ctrl.d_pol = level; //set default level for MOSI only on IDLE state
}

/**
* Trigger start of user-defined transaction for master.
* The synchronization between two clock domains is required in ESP32-S3
* Apply the register configurations and wait until it's done
*
* @param hw Beginning address of the peripheral registers.
*/
static inline void spi_ll_master_user_start(spi_dev_t *hw)
static inline void spi_ll_apply_config(spi_dev_t *hw)
{
hw->cmd.update = 1;
while (hw->cmd.update);
hw->cmd.usr = 1;
while (hw->cmd.update); //waiting config applied
}

/**
* Check whether user-defined transaction is done.
*
* @param hw Beginning address of the peripheral registers.
*
* @return True if transaction is done, otherwise false.
*/
static inline bool spi_ll_usr_is_done(spi_dev_t *hw)
{
return hw->dma_int_raw.trans_done;
}

/**
* Trigger start of user-defined transaction for slave.
* Trigger start of user-defined transaction.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline void spi_ll_slave_user_start(spi_dev_t *hw)
static inline void spi_ll_user_start(spi_dev_t *hw)
{
hw->cmd.usr = 1;
}
Expand Down
33 changes: 21 additions & 12 deletions components/hal/esp32c6/include/hal/spi_ll.h
Expand Up @@ -41,6 +41,7 @@ extern "C" {

#define SPI_LL_DMA_MAX_BIT_LEN (1 << 18) //reg len: 18 bits
#define SPI_LL_CPU_MAX_BIT_LEN (16 * 32) //Fifo len: 16 words
#define SPI_LL_MOSI_FREE_LEVEL 1 //Default level after bus initialized

/**
* The data structure holding calculated clock configuration. Since the
Expand Down Expand Up @@ -190,36 +191,44 @@ static inline void spi_ll_slave_hd_init(spi_dev_t *hw)
}

/**
* Check whether user-defined transaction is done.
* Determine and unify the default level of mosi line when bus free
*
* @param hw Beginning address of the peripheral registers.
*
* @return True if transaction is done, otherwise false.
*/
static inline bool spi_ll_usr_is_done(spi_dev_t *hw)
static inline void spi_ll_set_mosi_free_level(spi_dev_t *hw, bool level)
{
return hw->dma_int_raw.trans_done;
hw->ctrl.d_pol = level; //set default level for MOSI only on IDLE state
}

/**
* Trigger start of user-defined transaction for master.
* The synchronization between two clock domains is required in ESP32-S3
* Apply the register configurations and wait until it's done
*
* @param hw Beginning address of the peripheral registers.
*/
static inline void spi_ll_master_user_start(spi_dev_t *hw)
static inline void spi_ll_apply_config(spi_dev_t *hw)
{
hw->cmd.update = 1;
while (hw->cmd.update);
hw->cmd.usr = 1;
while (hw->cmd.update); //waiting config applied
}

/**
* Check whether user-defined transaction is done.
*
* @param hw Beginning address of the peripheral registers.
*
* @return True if transaction is done, otherwise false.
*/
static inline bool spi_ll_usr_is_done(spi_dev_t *hw)
{
return hw->dma_int_raw.trans_done;
}

/**
* Trigger start of user-defined transaction for slave.
* Trigger start of user-defined transaction.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline void spi_ll_slave_user_start(spi_dev_t *hw)
static inline void spi_ll_user_start(spi_dev_t *hw)
{
hw->cmd.usr = 1;
}
Expand Down
33 changes: 21 additions & 12 deletions components/hal/esp32h2/include/hal/spi_ll.h
Expand Up @@ -43,6 +43,7 @@ extern "C" {

#define SPI_LL_DMA_MAX_BIT_LEN (1 << 18) //reg len: 18 bits
#define SPI_LL_CPU_MAX_BIT_LEN (16 * 32) //Fifo len: 16 words
#define SPI_LL_MOSI_FREE_LEVEL 1 //Default level after bus initialized

/**
* The data structure holding calculated clock configuration. Since the
Expand Down Expand Up @@ -192,36 +193,44 @@ static inline void spi_ll_slave_hd_init(spi_dev_t *hw)
}

/**
* Check whether user-defined transaction is done.
* Determine and unify the default level of mosi line when bus free
*
* @param hw Beginning address of the peripheral registers.
*
* @return True if transaction is done, otherwise false.
*/
static inline bool spi_ll_usr_is_done(spi_dev_t *hw)
static inline void spi_ll_set_mosi_free_level(spi_dev_t *hw, bool level)
{
return hw->dma_int_raw.trans_done_int_raw;
hw->ctrl.d_pol = level; //set default level for MOSI only on IDLE state
}

/**
* Trigger start of user-defined transaction for master.
* The synchronization between two clock domains is required in ESP32-S3
* Apply the register configurations and wait until it's done
*
* @param hw Beginning address of the peripheral registers.
*/
static inline void spi_ll_master_user_start(spi_dev_t *hw)
static inline void spi_ll_apply_config(spi_dev_t *hw)
{
hw->cmd.update = 1;
while (hw->cmd.update);
hw->cmd.usr = 1;
while (hw->cmd.update); //waiting config applied
}

/**
* Check whether user-defined transaction is done.
*
* @param hw Beginning address of the peripheral registers.
*
* @return True if transaction is done, otherwise false.
*/
static inline bool spi_ll_usr_is_done(spi_dev_t *hw)
{
return hw->dma_int_raw.trans_done_int_raw;
}

/**
* Trigger start of user-defined transaction for slave.
* Trigger start of user-defined transaction.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline void spi_ll_slave_user_start(spi_dev_t *hw)
static inline void spi_ll_user_start(spi_dev_t *hw)
{
hw->cmd.usr = 1;
}
Expand Down
31 changes: 21 additions & 10 deletions components/hal/esp32s2/include/hal/spi_ll.h
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -43,6 +43,7 @@ extern "C" {

#define SPI_LL_DMA_MAX_BIT_LEN (1 << 23) //reg len: 23 bits
#define SPI_LL_CPU_MAX_BIT_LEN (18 * 32) //Fifo len: 18 words
#define SPI_LL_MOSI_FREE_LEVEL 1 //Default level after bus initialized

/**
* The data structure holding calculated clock configuration. Since the
Expand Down Expand Up @@ -176,33 +177,43 @@ static inline void spi_ll_slave_hd_init(spi_dev_t *hw)
}

/**
* Check whether user-defined transaction is done.
* Determine and unify the default level of mosi line when bus free
*
* @param hw Beginning address of the peripheral registers.
*/
static inline void spi_ll_set_mosi_free_level(spi_dev_t *hw, bool level)
{
hw->ctrl.d_pol = level; //set default level for MOSI only on IDLE state
}

/**
* Apply the register configurations and wait until it's done
*
* @return true if transaction is done, otherwise false.
* @param hw Beginning address of the peripheral registers.
*/
static inline bool spi_ll_usr_is_done(spi_dev_t *hw)
static inline void spi_ll_apply_config(spi_dev_t *hw)
{
return hw->slave.trans_done;
// S2 don't need this option
}

/**
* Trigger start of user-defined transaction for master.
* Check whether user-defined transaction is done.
*
* @param hw Beginning address of the peripheral registers.
*
* @return true if transaction is done, otherwise false.
*/
static inline void spi_ll_master_user_start(spi_dev_t *hw)
static inline bool spi_ll_usr_is_done(spi_dev_t *hw)
{
hw->cmd.usr = 1;
return hw->slave.trans_done;
}

/**
* Trigger start of user-defined transaction for slave.
* Trigger start of user-defined transaction.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline void spi_ll_slave_user_start(spi_dev_t *hw)
static inline void spi_ll_user_start(spi_dev_t *hw)
{
hw->cmd.usr = 1;
}
Expand Down

0 comments on commit 7a30edc

Please sign in to comment.