use values pointer directly

This commit is contained in:
microDev 2020-11-24 11:44:11 +05:30
parent a25b27520d
commit 6ff24410eb
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
1 changed files with 2 additions and 11 deletions

View File

@ -26,8 +26,6 @@
#include "common-hal/nvm/ByteArray.h"
#include <string.h>
#include "py/runtime.h"
#include "nvs_flash.h"
@ -56,9 +54,6 @@ bool common_hal_nvm_bytearray_set_bytes(nvm_bytearray_obj_t *self,
uint32_t start_index, uint8_t* values, uint32_t len) {
char index[9];
uint8_t buffer[len];
memcpy(buffer, values, len);
// start nvs
nvs_handle_t handle;
get_nvs_handle(&handle);
@ -66,7 +61,7 @@ bool common_hal_nvm_bytearray_set_bytes(nvm_bytearray_obj_t *self,
// stage flash changes
for (uint32_t i = 0; i < len; i++) {
sprintf(index, "%i", start_index + i);
if (nvs_set_u8(handle, (const char *)index, buffer[i]) != ESP_OK) {
if (nvs_set_u8(handle, (const char *)index, values[i]) != ESP_OK) {
return false;
}
}
@ -84,7 +79,6 @@ bool common_hal_nvm_bytearray_set_bytes(nvm_bytearray_obj_t *self,
void common_hal_nvm_bytearray_get_bytes(nvm_bytearray_obj_t *self,
uint32_t start_index, uint32_t len, uint8_t* values) {
char index[9];
uint8_t buffer[len];
// start nvs
nvs_handle_t handle;
@ -93,14 +87,11 @@ void common_hal_nvm_bytearray_get_bytes(nvm_bytearray_obj_t *self,
// get from flash
for (uint32_t i = 0; i < len; i++) {
sprintf(index, "%i", start_index + i);
if (nvs_get_u8(handle, (const char *)index, &buffer[i]) != ESP_OK) {
if (nvs_get_u8(handle, (const char *)index, &values[i]) != ESP_OK) {
mp_raise_RuntimeError(translate("NVS Error"));
}
}
// set into values
memcpy(values, buffer, len);
// close nvs
nvs_close(handle);
}