A module-bsp/board/linux/eeprom/eeprom.cpp => module-bsp/board/linux/eeprom/eeprom.cpp +39 -0
@@ 0,0 1,39 @@
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#include <cstdint>
+#include "bsp/eeprom/eeprom.hpp"
+
+namespace bsp::eeprom
+{
+ int init()
+ {
+ return true;
+ }
+
+ bool isPresent(int busid)
+ {
+ return true;
+ }
+
+ int eeprom_write(int busid, addr_t mem_addr, const char *buf, size_t len)
+ {
+ return true;
+ }
+
+ int eeprom_read(int busid, addr_t mem_addr, char *buf, size_t len)
+ {
+ return 0;
+ }
+
+ int eeprom_total_size(int busid)
+ {
+ return 0;
+ }
+
+ int eeprom_block_size(int busid)
+ {
+ return 0;
+ }
+
+} // namespace bsp::eeprom<
\ No newline at end of file
A module-bsp/board/rt1051/bsp/eeprom/M24256.hpp => module-bsp/board/rt1051/bsp/eeprom/M24256.hpp +16 -0
@@ 0,0 1,16 @@
+// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#pragma once
+
+#include <cstdint>
+
+namespace bsp::eeprom
+{
+ constexpr inline auto M24256_MEM_DEVICE_ADDR = 0xA0;
+ constexpr inline auto M24256_ID_DEVICE_ADDR = 0xB0;
+
+ constexpr inline auto M24256_PAGE_SIZE = 64;
+ constexpr inline auto M24256_TOTAL_SIZE = (32 * 1024); // bytes
+
+} // namespace bsp::eeprom
A module-bsp/board/rt1051/bsp/eeprom/eeprom.cpp => module-bsp/board/rt1051/bsp/eeprom/eeprom.cpp +110 -0
@@ 0,0 1,110 @@
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#include "M24256.hpp"
+#include "bsp/eeprom/eeprom.hpp"
+#include "bsp/BoardDefinitions.hpp"
+#include "drivers/i2c/DriverI2C.hpp"
+
+#include "fsl_common.h"
+#include "log/log.hpp"
+
+namespace bsp::eeprom
+{
+ namespace
+ {
+ std::shared_ptr<drivers::DriverI2C> i2c;
+
+ drivers::I2CAddress addr = {
+ .deviceAddress = static_cast<uint32_t>(M24256_MEM_DEVICE_ADDR), .subAddress = 0, .subAddressSize = 1};
+
+ } // namespace
+
+ int init()
+ {
+ drivers::DriverI2CParams i2cParams;
+ i2cParams.baudrate = static_cast<std::uint32_t>(BoardDefinitions::EEPROM_I2C_BAUDRATE);
+ i2c = drivers::DriverI2C::Create(static_cast<drivers::I2CInstances>(BoardDefinitions::EEPROM_I2C), i2cParams);
+
+ return isPresent() ? kStatus_Success : kStatus_Fail;
+ }
+
+ bool isPresent(int busid)
+ {
+ std::uint8_t readout;
+ addr.deviceAddress |= static_cast<uint32_t>(busid) & 0x7;
+ addr.subAddress = 0x00;
+ return i2c->Read(addr, &readout, 1) > 0;
+ }
+
+ int eeprom_write(int busid, addr_t mem_addr, const char *buf, size_t len)
+ {
+ size_t written = 0;
+ char* ptr = const_cast<char *>(buf);
+
+ addr.deviceAddress |= static_cast<uint32_t>(busid) & 0x7;
+ addr.subAddress = mem_addr;
+
+ size_t bl_len = static_cast<size_t>(eeprom_block_size(busid));
+ size_t chunks = len / bl_len;
+
+ if (chunks > 0)
+ {
+ for (size_t i = 0; i < chunks; i++)
+ {
+ written += i2c->Write(addr, reinterpret_cast<uint8_t *>(ptr), static_cast<size_t>(bl_len));
+ ptr += bl_len;
+ }
+ }
+ //reminder
+ written += i2c->Write(addr, reinterpret_cast<uint8_t *>(ptr), static_cast<size_t>(len % bl_len));
+
+ return static_cast<int>(written);
+ }
+
+ int eeprom_read(int busid, addr_t mem_addr, char *buf, size_t len)
+ {
+ size_t read = 0;
+ char* ptr = const_cast<char *>(buf);
+
+ addr.deviceAddress |= static_cast<uint32_t>(busid) & 0x7;
+ addr.subAddress = mem_addr;
+
+ size_t bl_len = static_cast<size_t>(eeprom_block_size(busid));
+ size_t chunks = len / bl_len;
+
+ if (chunks > 0)
+ {
+ for (size_t i = 0; i < chunks; i++)
+ {
+ read += i2c->Read(addr, reinterpret_cast<uint8_t *>(ptr), static_cast<size_t>(bl_len));
+ ptr += bl_len;
+ }
+ }
+ //reminder
+ read += i2c->Read(addr, reinterpret_cast<uint8_t *>(ptr), static_cast<size_t>(len % bl_len));
+
+ return static_cast<int>(read);
+ }
+
+ int eeprom_total_size(int busid)
+ {
+ // 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)
+ return M24256_TOTAL_SIZE;
+ else
+ return -EFAULT;
+ }
+
+ int eeprom_block_size(int busid)
+ {
+ // 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)
+ return M24256_PAGE_SIZE;
+ else
+ return -EFAULT;
+ }
+
+} // namespace bsp::eeprom<
\ No newline at end of file
M module-bsp/bsp/BoardDefinitions.hpp => module-bsp/bsp/BoardDefinitions.hpp +3 -0
@@ 129,6 129,9 @@ enum class BoardDefinitions
LIGHT_SENSOR_I2C_BAUDRATE = AUDIOCODEC_I2C_BAUDRATE,
LIGHT_SENSOR_IRQ_GPIO = static_cast<int>(drivers::GPIOInstances::GPIO_2),
LIGHT_SENSOR_IRQ = 15, // GPIO_B0_15
+
+ EEPROM_I2C = AUDIOCODEC_I2C,
+ EEPROM_I2C_BAUDRATE = AUDIOCODEC_I2C_BAUDRATE,
};
#endif //PUREPHONE_BOARDDEFINITIONS_HPP
A module-bsp/bsp/eeprom/eeprom.hpp => module-bsp/bsp/eeprom/eeprom.hpp +31 -0
@@ 0,0 1,31 @@
+// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#pragma once
+
+#include <cstdint>
+
+extern "C"
+{
+#include "FreeRTOS.h"
+#include "task.h"
+#include "queue.h"
+}
+
+namespace bsp::eeprom
+{
+ typedef uint32_t addr_t;
+
+ int init();
+
+ bool isPresent();
+
+ int eeprom_write( int busid, addr_t mem_addr, const char *buf, size_t len );
+
+ int eeprom_read( int busid, addr_t mem_addr, char* buf, size_t len );
+
+ int eeprom_total_size( int busid );
+
+ int eeprom_block_size( int busid );
+
+} // namespace bsp::eeprom
M module-bsp/targets/Target_Linux.cmake => module-bsp/targets/Target_Linux.cmake +2 -0
@@ 34,6 34,8 @@ set(BOARD_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/board/linux/watchdog/watchdog.cpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/board/linux/eeprom/eeprom.cpp"
+
CACHE INTERNAL "")
set(BOARD_DIR_INCLUDES
M module-bsp/targets/Target_RT1051.cmake => module-bsp/targets/Target_RT1051.cmake +2 -0
@@ 84,6 84,8 @@ set(BOARD_SOURCES ${BOARD_SOURCES}
"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/bsp/keypad_backlight/keypad_backlight.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/bsp/eink_frontlight/eink_frontlight.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/bsp/light_sensor/light_sensor.cpp"
+
+ "${CMAKE_CURRENT_SOURCE_DIR}/board/rt1051/bsp/eeprom/eeprom.cpp"
CACHE INTERNAL ""
)