Skip to content

Commit 8e6e90d

Browse files
fixup! added Preferences api spi commands
1 parent c57c6b5 commit 8e6e90d

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/utility/wifi_drv.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,8 +1364,14 @@ void WiFiDrv::prefEnd() {
13641364

13651365
SpiDrv::sendCmd(PREFERENCES_END, PARAM_NUMS_0);
13661366
SpiDrv::spiSlaveDeselect();
1367+
//Wait the reply elaboration
1368+
SpiDrv::waitForSlaveReady();
1369+
SpiDrv::spiSlaveSelect();
13671370

1368-
// we do not need to wait for any response
1371+
uint8_t len = 1;
1372+
bool result = false;
1373+
SpiDrv::waitResponseCmd(PREFERENCES_END, PARAM_NUMS_1, (uint8_t*)&result, &len);
1374+
SpiDrv::spiSlaveDeselect();
13691375
}
13701376

13711377
bool WiFiDrv::prefClear() {
@@ -1534,30 +1540,36 @@ size_t WiFiDrv::prefGet(const char * key, PreferenceType type, uint8_t value[],
15341540
SpiDrv::waitForSlaveReady();
15351541
SpiDrv::spiSlaveSelect();
15361542

1537-
SpiDrv::waitResponseData16(PREFERENCES_GET, value, (uint16_t*)&len);
1543+
// we need to account for \0 if it is a string
1544+
size_t res_len = type == PT_STR? len-1 : len;
1545+
SpiDrv::waitResponseData16(PREFERENCES_GET, value, (uint16_t*)&res_len);
15381546

15391547
SpiDrv::spiSlaveDeselect();
15401548

1541-
// if len == 0 it means that the command retuned and error
1542-
if(len == 0) {
1549+
// if res_len == 0 it means that the command retuned and error
1550+
if(res_len == 0) {
15431551
return 0;
15441552
}
15451553

15461554
// fix endianness
15471555
if(type != PT_STR && type != PT_BLOB) {
1548-
for(uint8_t i=0; i<len/2; i++) {
1556+
for(uint8_t i=0; i<res_len/2; i++) {
15491557

15501558
// XOR swap algorithm:
15511559
// a=a^b; b=a^b; a=b^a; with a != b
1552-
if(value[i] != value[len-i-1]) {
1553-
value[i] = value[i]^value[len-i-1];
1554-
value[len-i-1] = value[i]^value[len-i-1];
1555-
value[i] = value[len-i-1]^value[i];
1560+
if(value[i] != value[res_len-i-1]) {
1561+
value[i] = value[i]^value[res_len-i-1];
1562+
value[res_len-i-1] = value[i]^value[res_len-i-1];
1563+
value[i] = value[res_len-i-1]^value[i];
15561564
}
15571565
}
15581566
}
15591567

1560-
return len;
1568+
if(type == PT_STR) {
1569+
value[res_len] = '\0';
1570+
}
1571+
1572+
return res_len;
15611573
}
15621574

15631575
PreferenceType WiFiDrv::prefGetType(const char * key) {

0 commit comments

Comments
 (0)