From f3fee0587eda0a9a8d19cfaf71005e4a25435834 Mon Sep 17 00:00:00 2001 From: Lukasz Skrzypczak Date: Mon, 10 May 2021 10:56:17 +0200 Subject: [PATCH] [EGD-6576] Corrected after PR comments I hope this is final --- module-bsp/board/rt1051/bsp/eeprom/M24256.hpp | 2 ++ module-bsp/board/rt1051/bsp/eeprom/eeprom.cpp | 28 +++++++++---------- module-bsp/bsp/BoardDefinitions.hpp | 2 +- module-bsp/bsp/eeprom/eeprom.hpp | 4 +-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/module-bsp/board/rt1051/bsp/eeprom/M24256.hpp b/module-bsp/board/rt1051/bsp/eeprom/M24256.hpp index 3a51d86dca88af2cab1f4e7231990ee712eae757..75e6d3dbc11c592ac5cc3c6ce6507d842c71d3d6 100644 --- a/module-bsp/board/rt1051/bsp/eeprom/M24256.hpp +++ b/module-bsp/board/rt1051/bsp/eeprom/M24256.hpp @@ -15,4 +15,6 @@ namespace bsp::eeprom constexpr inline auto M24256_PAGE_SIZE = 64; constexpr inline auto M24256_TOTAL_SIZE = (32 * 1024); // bytes + constexpr inline auto M24256_SLAVE_ADDR = 0x00; + } // namespace bsp::eeprom diff --git a/module-bsp/board/rt1051/bsp/eeprom/eeprom.cpp b/module-bsp/board/rt1051/bsp/eeprom/eeprom.cpp index 304efd0172581b9fb6282289f23336ee3c3d5b17..4a31213d486c02c74719fccd33c5777d8207e5e9 100644 --- a/module-bsp/board/rt1051/bsp/eeprom/eeprom.cpp +++ b/module-bsp/board/rt1051/bsp/eeprom/eeprom.cpp @@ -9,7 +9,7 @@ #include "fsl_common.h" #include "log/log.hpp" -// generic i2c read() & write() doesn't provide correct i2c frame sequence for eeprom. i2c HAL API should be modified. +#include "task.h" namespace bsp::eeprom { @@ -18,7 +18,7 @@ namespace bsp::eeprom std::shared_ptr i2c; drivers::I2CAddress addr = { - .deviceAddress = static_cast(M24256_MEM_DEVICE_ADDR), .subAddress = 0, .subAddressSize = 2}; + .deviceAddress = static_cast(M24256_MEM_DEVICE_ADDR), .subAddress = 0, .subAddressSize = 2}; } // namespace @@ -34,7 +34,7 @@ namespace bsp::eeprom bool isPresent(int busid) { std::uint8_t readout; - addr.deviceAddress |= static_cast(busid) & M24256_DEV_ID_MASK; + addr.deviceAddress |= static_cast(busid) & M24256_DEV_ID_MASK; addr.subAddress = 0x0000; return i2c->Read(addr, &readout, 1) > 0; } @@ -44,7 +44,7 @@ namespace bsp::eeprom size_t written = 0; char *ptr = const_cast(buf); - addr.deviceAddress |= static_cast(busid) & M24256_DEV_ID_MASK; + addr.deviceAddress |= static_cast(busid) & M24256_DEV_ID_MASK; addr.subAddress = mem_addr; size_t bl_len = static_cast(eeprom_block_size(busid)); @@ -56,8 +56,8 @@ namespace bsp::eeprom if (chunks > 0) { for (size_t i = 0; i < chunks; i++) { LOG_DEBUG("[EEPROM - W] writing chunk %d of %d", i, chunks); - written += i2c->Write(addr, reinterpret_cast(ptr), static_cast(bl_len)); - vTaskDelay(10 / portTICK_PERIOD_MS); + written += i2c->Write(addr, reinterpret_cast(ptr), static_cast(bl_len)); + vTaskDelay(pdMS_TO_TICKS(10)); ptr += bl_len; addr.subAddress += bl_len; } @@ -65,8 +65,8 @@ namespace bsp::eeprom // reminder if (reminder > 0) { LOG_DEBUG("[EEPROM - W] writing remaining %d bytes", reminder); - written += i2c->Write(addr, reinterpret_cast(ptr), reminder); - vTaskDelay(10 / portTICK_PERIOD_MS); + written += i2c->Write(addr, reinterpret_cast(ptr), reminder); + vTaskDelay(pdMS_TO_TICKS(10)); } return static_cast(written); @@ -77,7 +77,7 @@ namespace bsp::eeprom size_t read = 0; char *ptr = const_cast(buf); - addr.deviceAddress |= static_cast(busid) & M24256_DEV_ID_MASK; + addr.deviceAddress |= static_cast(busid) & M24256_DEV_ID_MASK; addr.subAddress = mem_addr; size_t bl_len = static_cast(eeprom_block_size(busid)); @@ -89,7 +89,7 @@ namespace bsp::eeprom if (chunks > 0) { for (size_t i = 0; i < chunks; i++) { LOG_DEBUG("[EEPROM - R] reading chunk %d of %d", i, chunks); - read += i2c->Read(addr, reinterpret_cast(ptr), static_cast(bl_len)); + read += i2c->Read(addr, reinterpret_cast(ptr), static_cast(bl_len)); ptr += bl_len; addr.subAddress += bl_len; } @@ -97,7 +97,7 @@ namespace bsp::eeprom // reminder if (reminder > 0) { LOG_DEBUG("[EEPROM - R] reading remaining %d bytes", reminder); - read += i2c->Read(addr, reinterpret_cast(ptr), reminder); + read += i2c->Read(addr, reinterpret_cast(ptr), reminder); } return static_cast(read); @@ -107,7 +107,7 @@ namespace bsp::eeprom { // note that M24256 doesn't provide any ID or info register. So i assume that with T7 rev. this memory is @0x0h // address - if (busid == 0x00) + if (busid == M24256_SLAVE_ADDR) return M24256_TOTAL_SIZE; else return -EFAULT; @@ -117,10 +117,10 @@ namespace bsp::eeprom { // note that M24256 doesn't provide any ID or info register. So i assume that with T7 rev. this memory is @0x0h // address - if (busid == 0x00) + if (busid == M24256_SLAVE_ADDR) return M24256_PAGE_SIZE; else return -EFAULT; } -} // namespace bsp::eeprom \ No newline at end of file +} // namespace bsp::eeprom diff --git a/module-bsp/bsp/BoardDefinitions.hpp b/module-bsp/bsp/BoardDefinitions.hpp index a9122c04bc097b4e3691c1032859d05f58a7c828..421b29e368ba0882b04c879d11fc8ed8dd573a98 100644 --- a/module-bsp/bsp/BoardDefinitions.hpp +++ b/module-bsp/bsp/BoardDefinitions.hpp @@ -131,7 +131,7 @@ enum class BoardDefinitions LIGHT_SENSOR_IRQ = 15, // GPIO_B0_15 EEPROM_I2C = AUDIOCODEC_I2C, - EEPROM_I2C_BAUDRATE = AUDIOCODEC_I2C_BAUDRATE, + EEPROM_I2C_BAUDRATE = I2C_STD_BAUDRATE, }; #endif //PUREPHONE_BOARDDEFINITIONS_HPP diff --git a/module-bsp/bsp/eeprom/eeprom.hpp b/module-bsp/bsp/eeprom/eeprom.hpp index e2e16e1156d1e990b3cfa5929338ec4fff6b7caa..5ea76b1de49f90137361da735024fc5ee5709b47 100644 --- a/module-bsp/bsp/eeprom/eeprom.hpp +++ b/module-bsp/bsp/eeprom/eeprom.hpp @@ -8,13 +8,11 @@ extern "C" { #include "FreeRTOS.h" -#include "task.h" -#include "queue.h" } namespace bsp::eeprom { - typedef uint32_t addr_t; + typedef std::uint32_t addr_t; int init();