From b5c2120efce06895fb0dcba53f7b4f2dd67b7231 Mon Sep 17 00:00:00 2001 From: UncleRus Date: Sun, 6 Mar 2016 01:24:59 +0500 Subject: [PATCH] Removed redeclaration of peripheral bus freq --- core/esp_spi.c | 6 +++--- core/include/esp/spi.h | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/core/esp_spi.c b/core/esp_spi.c index 56ed196..02dae76 100644 --- a/core/esp_spi.c +++ b/core/esp_spi.c @@ -194,13 +194,13 @@ void spi_transfer(uint8_t bus, void *data, size_t len) spi_endianness_t e = spi_get_endianness(bus); spi_set_endianness(bus, SPI_LITTLE_ENDIAN); - size_t counts = len / _SPI_BUF_SIZE; - for (uint8_t i = 0; i < counts; i++) + size_t blocks = len / _SPI_BUF_SIZE; + for (uint8_t i = 0; i < blocks; i++) _spi_buf_transfer(bus, data + i * _SPI_BUF_SIZE, _SPI_BUF_SIZE); uint8_t tail = len % _SPI_BUF_SIZE; if (tail) - _spi_buf_transfer(bus, data + counts * _SPI_BUF_SIZE, tail); + _spi_buf_transfer(bus, data + blocks * _SPI_BUF_SIZE, tail); spi_set_endianness(bus, e); } diff --git a/core/include/esp/spi.h b/core/include/esp/spi.h index 6b2b0e2..55b9d14 100644 --- a/core/include/esp/spi.h +++ b/core/include/esp/spi.h @@ -12,9 +12,7 @@ #include #include #include "esp/spi_regs.h" - -// FIXME Better to define it somewhere else. This is not the CPU frequency! -#define SYSTEM_BUS_FREQ 80000000UL +#include "esp/clocks.h" /** * Macro for use with spi_init and spi_set_frequency_div. @@ -121,7 +119,7 @@ void spi_set_frequency_div(uint8_t bus, uint32_t divider); */ inline uint32_t spi_get_frequency_hz(uint8_t bus) { - return SYSTEM_BUS_FREQ / + return APB_CLK_FREQ / (((SPI(bus).CLOCK >> SPI_CLOCK_DIV_PRE_S) & SPI_CLOCK_DIV_PRE_M) + 1) / (((SPI(bus).CLOCK >> SPI_CLOCK_COUNT_NUM_S) & SPI_CLOCK_COUNT_NUM_M) + 1); }