~aleteoryx/muditaos

f3fee0587eda0a9a8d19cfaf71005e4a25435834 — Lukasz Skrzypczak 4 years ago a2ab137
[EGD-6576] Corrected after PR comments

I hope this is final
M module-bsp/board/rt1051/bsp/eeprom/M24256.hpp => module-bsp/board/rt1051/bsp/eeprom/M24256.hpp +2 -0
@@ 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

M module-bsp/board/rt1051/bsp/eeprom/eeprom.cpp => module-bsp/board/rt1051/bsp/eeprom/eeprom.cpp +14 -14
@@ 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<drivers::DriverI2C> i2c;

        drivers::I2CAddress addr = {
            .deviceAddress = static_cast<uint32_t>(M24256_MEM_DEVICE_ADDR), .subAddress = 0, .subAddressSize = 2};
            .deviceAddress = static_cast<std::uint32_t>(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<uint32_t>(busid) & M24256_DEV_ID_MASK;
        addr.deviceAddress |= static_cast<std::uint32_t>(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<char *>(buf);

        addr.deviceAddress |= static_cast<uint32_t>(busid) & M24256_DEV_ID_MASK;
        addr.deviceAddress |= static_cast<std::uint32_t>(busid) & M24256_DEV_ID_MASK;
        addr.subAddress = mem_addr;

        size_t bl_len   = static_cast<size_t>(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<uint8_t *>(ptr), static_cast<size_t>(bl_len));
                vTaskDelay(10 / portTICK_PERIOD_MS);
                written += i2c->Write(addr, reinterpret_cast<std::uint8_t *>(ptr), static_cast<size_t>(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<uint8_t *>(ptr), reminder);
            vTaskDelay(10 / portTICK_PERIOD_MS);
            written += i2c->Write(addr, reinterpret_cast<std::uint8_t *>(ptr), reminder);
            vTaskDelay(pdMS_TO_TICKS(10));
        }

        return static_cast<int>(written);


@@ 77,7 77,7 @@ namespace bsp::eeprom
        size_t read = 0;
        char *ptr   = const_cast<char *>(buf);

        addr.deviceAddress |= static_cast<uint32_t>(busid) & M24256_DEV_ID_MASK;
        addr.deviceAddress |= static_cast<std::uint32_t>(busid) & M24256_DEV_ID_MASK;
        addr.subAddress = mem_addr;

        size_t bl_len   = static_cast<size_t>(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<uint8_t *>(ptr), static_cast<size_t>(bl_len));
                read += i2c->Read(addr, reinterpret_cast<std::uint8_t *>(ptr), static_cast<size_t>(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<uint8_t *>(ptr), reminder);
            read += i2c->Read(addr, reinterpret_cast<std::uint8_t *>(ptr), reminder);
        }

        return static_cast<int>(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

M module-bsp/bsp/BoardDefinitions.hpp => module-bsp/bsp/BoardDefinitions.hpp +1 -1
@@ 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

M module-bsp/bsp/eeprom/eeprom.hpp => module-bsp/bsp/eeprom/eeprom.hpp +1 -3
@@ 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();