From 7efa9057c3bb49f75ef973ef0c29b6078c92ae6b Mon Sep 17 00:00:00 2001 From: dragonmux Date: Tue, 12 Dec 2023 00:11:02 +0000 Subject: [PATCH] sfdpInternal: Implemented a type for handling the write and erase granularity information --- src/include/sfdpInternal.hxx | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/include/sfdpInternal.hxx b/src/include/sfdpInternal.hxx index 61bded5..3c4d05e 100644 --- a/src/include/sfdpInternal.hxx +++ b/src/include/sfdpInternal.hxx @@ -67,6 +67,28 @@ namespace bmpflash::sfdp void validate() noexcept; }; + struct writeAndEraseGranularity_t + { + private: + uint8_t data{}; + + public: + [[nodiscard]] std::optional volatileStatusWriteEnable() const noexcept + { + // Check if the status register requires any write enables + if (!(data & 0x08U)) + return std::nullopt; + // Otherwise check if the device requires 0x06 as write enable + if (data & 0x10U) + return 0x06U; + // If not, then it's 0x50 as write enable + return 0x50U; + } + + [[nodiscard]] bool supports4KiBErase() const noexcept + { return (data & 0x03U) == 0x01U; } + }; + struct fastReadAndAddressing_t { private: @@ -168,7 +190,7 @@ END_PACKED() struct basicParameterTable_t { - uint8_t value1{}; + writeAndEraseGranularity_t writeAndEraseGranularity{}; uint8_t sectorEraseOpcode{}; fastReadAndAddressing_t fastReadAndAddressing{}; uint8_t reserved1{};