Skip to content

Commit 3ba4f9b

Browse files
committed
Move instance pointer to lzss_download function
1 parent 8d6958e commit 3ba4f9b

File tree

4 files changed

+9
-37
lines changed

4 files changed

+9
-37
lines changed

Diff for: src/Arduino_ESP32_OTA.cpp

+1-22
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,6 @@
2626
#include "decompress/utility.h"
2727
#include "esp_ota_ops.h"
2828

29-
/* Used to bind local module function to actual class instance */
30-
static Arduino_ESP32_OTA * _esp_ota_obj_ptr = 0;
31-
32-
/******************************************************************************
33-
LOCAL MODULE FUNCTIONS
34-
******************************************************************************/
35-
36-
static uint8_t read_byte() {
37-
if(_esp_ota_obj_ptr) {
38-
return _esp_ota_obj_ptr->read_byte_from_network();
39-
}
40-
return -1;
41-
}
42-
43-
static void write_byte(uint8_t data) {
44-
if(_esp_ota_obj_ptr) {
45-
_esp_ota_obj_ptr->write_byte_to_flash(data);
46-
}
47-
}
48-
4929
/******************************************************************************
5030
CTOR/DTOR
5131
******************************************************************************/
@@ -67,7 +47,6 @@ Arduino_ESP32_OTA::Arduino_ESP32_OTA()
6747

6848
Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::begin()
6949
{
70-
_esp_ota_obj_ptr = this;
7150

7251
/* ... initialize CRC ... */
7352
_crc32 = 0xFFFFFFFF;
@@ -273,7 +252,7 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
273252
_crc32 = crc_update(_crc32, &_ota_header.header.magic_number, 12);
274253

275254
/* Download and decode OTA file */
276-
_ota_size = lzss_download(read_byte, write_byte, content_length_val - sizeof(_ota_header));
255+
_ota_size = lzss_download(this, content_length_val - sizeof(_ota_header));
277256

278257
if(_ota_size <= content_length_val - sizeof(_ota_header))
279258
{

Diff for: src/Arduino_ESP32_OTA.h

-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ static uint32_t const ARDUINO_ESP32_OTA_HTTP_HEADER_RECEIVE_TIMEOUT_ms = 10000;
4242
static uint32_t const ARDUINO_ESP32_OTA_BINARY_HEADER_RECEIVE_TIMEOUT_ms = 10000;
4343
static uint32_t const ARDUINO_ESP32_OTA_BINARY_BYTE_RECEIVE_TIMEOUT_ms = 2000;
4444

45-
/******************************************************************************
46-
* TYPEDEF
47-
******************************************************************************/
48-
49-
typedef uint8_t(*ArduinoEsp32OtaReadByteFuncPointer)(void);
50-
typedef void(*ArduinoEsp32OtaWriteByteFuncPointer)(uint8_t);
51-
5245
/******************************************************************************
5346
* CLASS DECLARATION
5447
******************************************************************************/

Diff for: src/decompress/lzss.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
GLOBAL VARIABLES
2323
**************************************************************************************/
2424

25+
/* Used to bind local module function to actual class instance */
26+
static Arduino_ESP32_OTA * esp_ota_obj_ptr = 0;
27+
2528
static size_t LZSS_FILE_SIZE = 0;
26-
static ArduinoEsp32OtaReadByteFuncPointer read_byte_fptr = 0;
27-
static ArduinoEsp32OtaWriteByteFuncPointer write_byte_fptr = 0;
2829

2930
int bit_buffer = 0, bit_mask = 128;
3031
unsigned char buffer[N * 2];
@@ -38,7 +39,7 @@ static size_t bytes_read_fgetc = 0;
3839

3940
void lzss_fputc(int const c)
4041
{
41-
write_byte_fptr((uint8_t)c);
42+
esp_ota_obj_ptr->write_byte_to_flash((uint8_t)c);
4243

4344
/* write byte callback */
4445
bytes_written_fputc++;
@@ -56,7 +57,7 @@ int lzss_fgetc()
5657
return LZSS_EOF;
5758

5859
/* read byte callback */
59-
uint8_t const c = read_byte_fptr();
60+
uint8_t const c = esp_ota_obj_ptr->read_byte_from_network();
6061
bytes_read_fgetc++;
6162

6263
return c;
@@ -157,10 +158,9 @@ void lzss_decode(void)
157158
PUBLIC FUNCTIONS
158159
**************************************************************************************/
159160

160-
int lzss_download(ArduinoEsp32OtaReadByteFuncPointer read_byte, ArduinoEsp32OtaWriteByteFuncPointer write_byte, size_t const lzss_file_size)
161+
int lzss_download(Arduino_ESP32_OTA * instance, size_t const lzss_file_size)
161162
{
162-
read_byte_fptr = read_byte;
163-
write_byte_fptr = write_byte;
163+
esp_ota_obj_ptr = instance;
164164
LZSS_FILE_SIZE = lzss_file_size;
165165
bytes_written_fputc = 0;
166166
bytes_read_fgetc = 0;

Diff for: src/decompress/lzss.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
FUNCTION DEFINITION
1212
**************************************************************************************/
1313

14-
int lzss_download(ArduinoEsp32OtaReadByteFuncPointer read_byte, ArduinoEsp32OtaWriteByteFuncPointer write_byte, size_t const lzss_file_size);
14+
int lzss_download(Arduino_ESP32_OTA * instance, size_t const lzss_file_size);
1515

1616
#endif /* SSU_LZSS_H_ */

0 commit comments

Comments
 (0)