mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/driver-w25qxxx.git
synced 2025-08-02 04:21:54 +00:00
Added search functionality using binary search
This commit is contained in:
parent
ad76f8e12f
commit
d88de338e9
@ -4,6 +4,8 @@
|
|||||||
#include <sta/bus/spi/device.hpp>
|
#include <sta/bus/spi/device.hpp>
|
||||||
#include <sta/drivers/w25qxx_defs.hpp>
|
#include <sta/drivers/w25qxx_defs.hpp>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
@ -53,8 +55,21 @@ namespace sta
|
|||||||
*/
|
*/
|
||||||
W25Qxx(SPIDevice * device, DelayUsFunc delay, AddressMode addrMode = AddressMode::_24BIT);
|
W25Qxx(SPIDevice * device, DelayUsFunc delay, AddressMode addrMode = AddressMode::_24BIT);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize the flash chip.
|
||||||
|
*
|
||||||
|
* @return uint8_t Returns 1 if successful, 0 otherwise.
|
||||||
|
*/
|
||||||
uint8_t init();
|
uint8_t init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find the last page satisfying the given criterion. Uses a binary search to find this page.
|
||||||
|
*
|
||||||
|
* @param criterion A function evaluating the criterion on a page.
|
||||||
|
* @return uint32_t The last address such that the criterion is satisfied.
|
||||||
|
*/
|
||||||
|
uint32_t findLastPage(std::function<bool(uint8_t*)> criterion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the Address Mode object
|
* @brief Set the Address Mode object
|
||||||
*
|
*
|
||||||
@ -173,8 +188,6 @@ namespace sta
|
|||||||
* @return uint8_t
|
* @return uint8_t
|
||||||
*/
|
*/
|
||||||
uint8_t pageProgram(uint32_t address, uint8_t * buffer, size_t length);
|
uint8_t pageProgram(uint32_t address, uint8_t * buffer, size_t length);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*
|
/*
|
||||||
* Erase operations
|
* Erase operations
|
||||||
|
@ -44,6 +44,31 @@ namespace sta
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t W25Qxx::findLastPage(std::function<bool(uint8_t*)> criterion)
|
||||||
|
{
|
||||||
|
uint32_t left = 0;
|
||||||
|
uint32_t right = 0xFFFFFFFF & (addrMode_ == AddressMode::_32BIT ? 0xFFFFFFFF : 0x00FFFFFF);
|
||||||
|
uint32_t middle;
|
||||||
|
uint8_t * page = new uint8_t[256];
|
||||||
|
|
||||||
|
while (left < right)
|
||||||
|
{
|
||||||
|
middle = (left + right) / 2 + 1;
|
||||||
|
readData(middle, page, 256);
|
||||||
|
|
||||||
|
if (criterion(page))
|
||||||
|
{
|
||||||
|
left = middle;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
right = middle-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return middle;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t W25Qxx::setAddressMode(AddressMode addrMode)
|
uint8_t W25Qxx::setAddressMode(AddressMode addrMode)
|
||||||
{
|
{
|
||||||
busWrite(W25QXX_4_BYTE_ADDR_ENABLE);
|
busWrite(W25QXX_4_BYTE_ADDR_ENABLE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user