mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-30 05:50:38 +00:00
refactor(spi_flash): Refactor gpspi flash for making it's clock accurate
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "soc/spi_periph.h"
|
||||
#include "soc/spi_struct.h"
|
||||
#include "soc/pcr_struct.h"
|
||||
#include "hal/spi_types.h"
|
||||
#include "hal/spi_flash_types.h"
|
||||
#include <sys/param.h> // For MIN/MAX
|
||||
@@ -426,6 +427,39 @@ static inline uint32_t gpspi_flash_ll_calculate_clock_reg(uint8_t clkdiv)
|
||||
return div_parameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the clock source
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param clk_source Clock source to use
|
||||
*/
|
||||
static inline void gpspi_flash_ll_set_clk_source(spi_dev_t *hw, spi_clock_source_t clk_source)
|
||||
{
|
||||
switch (clk_source) {
|
||||
case SPI_CLK_SRC_RC_FAST:
|
||||
PCR.spi2_clkm_conf.spi2_clkm_sel = 2;
|
||||
break;
|
||||
case SPI_CLK_SRC_XTAL:
|
||||
PCR.spi2_clkm_conf.spi2_clkm_sel = 0;
|
||||
break;
|
||||
default:
|
||||
PCR.spi2_clkm_conf.spi2_clkm_sel = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable SPI flash module clock
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param enable true to enable, false to disable
|
||||
*/
|
||||
static inline void gpspi_flash_ll_enable_clock(spi_dev_t *hw, bool enable)
|
||||
{
|
||||
(void) hw;
|
||||
PCR.spi2_clkm_conf.spi2_clkm_en = enable;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -24,7 +24,7 @@ extern "C" {
|
||||
#define spi_flash_ll_calculate_clock_reg(host_id, clock_div) (((host_id)<=SPI1_HOST) ? spimem_flash_ll_calculate_clock_reg(clock_div) \
|
||||
: gpspi_flash_ll_calculate_clock_reg(clock_div))
|
||||
|
||||
#define spi_flash_ll_get_source_clock_freq_mhz(host_id) (((host_id)<=SPI1_HOST) ? spimem_flash_ll_get_source_freq_mhz() : GPSPI_FLASH_LL_PERIPHERAL_FREQUENCY_MHZ)
|
||||
#define spi_flash_ll_get_source_clock_freq_mhz(host_id) (((host_id)<=SPI1_HOST) ? spimem_flash_ll_get_source_freq_mhz() : -1)
|
||||
|
||||
#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)))
|
||||
|
Reference in New Issue
Block a user