Skip to content

Commit

Permalink
sfdpInternal: Implemented a type for handling the write and erase gra…
Browse files Browse the repository at this point in the history
…nularity information
  • Loading branch information
dragonmux committed Dec 12, 2023
1 parent fd3f7dd commit 7efa905
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/include/sfdpInternal.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,28 @@ namespace bmpflash::sfdp
void validate() noexcept;
};

struct writeAndEraseGranularity_t
{
private:
uint8_t data{};

public:
[[nodiscard]] std::optional<uint8_t> 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:
Expand Down Expand Up @@ -168,7 +190,7 @@ END_PACKED()

struct basicParameterTable_t
{
uint8_t value1{};
writeAndEraseGranularity_t writeAndEraseGranularity{};
uint8_t sectorEraseOpcode{};
fastReadAndAddressing_t fastReadAndAddressing{};
uint8_t reserved1{};
Expand Down

0 comments on commit 7efa905

Please sign in to comment.