mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/driver-w25qxxx.git
synced 2025-06-10 18:45:59 +00:00
Fixed the binary search
This commit is contained in:
parent
aea0b1c262
commit
0de96367af
@ -81,22 +81,26 @@ namespace sta
|
||||
while (left < right)
|
||||
{
|
||||
middle = (left + right) / 2;
|
||||
STA_DEBUG_PRINTF("left=%d, middle=%d, right=%d", left, middle, right);
|
||||
readData(middle * bytes, buffer, bytes);
|
||||
STA_DEBUG_PRINTF("Left %d Middle %d Right %d\n", left, middle, right);
|
||||
|
||||
if (criterion(buffer))
|
||||
{
|
||||
left = middle+1;
|
||||
left = middle + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
right = middle-1;
|
||||
right = middle - 1;
|
||||
}
|
||||
}
|
||||
|
||||
middle = (left + right) / 2;
|
||||
|
||||
readData(middle * bytes, buffer, bytes);
|
||||
if (!criterion(buffer))
|
||||
middle -= 1;
|
||||
if (criterion(buffer))
|
||||
{
|
||||
middle += 1;
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
|
||||
@ -189,13 +193,27 @@ namespace sta
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t addrBuffer[3] = {
|
||||
(uint8_t) (address >> 16),
|
||||
(uint8_t) (address >> 8),
|
||||
(uint8_t) (address)
|
||||
};
|
||||
if (fast)
|
||||
{
|
||||
uint8_t addrBuffer[4] = {
|
||||
(uint8_t) (address >> 16),
|
||||
(uint8_t) (address >> 8),
|
||||
(uint8_t) (address),
|
||||
0x00 // Dummy byte for fast mode
|
||||
};
|
||||
|
||||
return busRead(instruction, buffer, length, addrBuffer, 3);
|
||||
return busRead(instruction, buffer, length, addrBuffer, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t addrBuffer[3] = {
|
||||
(uint8_t) (address >> 16),
|
||||
(uint8_t) (address >> 8),
|
||||
(uint8_t) (address)
|
||||
};
|
||||
|
||||
return busRead(instruction, buffer, length, addrBuffer, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user