ESPHome  2024.7.2
ota_backend_arduino_libretiny.cpp
Go to the documentation of this file.
1 #ifdef USE_LIBRETINY
3 #include "ota_backend.h"
4 
5 #include "esphome/core/defines.h"
6 #include "esphome/core/log.h"
7 
8 #include <Update.h>
9 
10 namespace esphome {
11 namespace ota {
12 
13 static const char *const TAG = "ota.arduino_libretiny";
14 
15 std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoLibreTinyOTABackend>(); }
16 
18  bool ret = Update.begin(image_size, U_FLASH);
19  if (ret) {
20  return OTA_RESPONSE_OK;
21  }
22 
23  uint8_t error = Update.getError();
24  if (error == UPDATE_ERROR_SIZE)
26 
27  ESP_LOGE(TAG, "Begin error: %d", error);
28 
30 }
31 
32 void ArduinoLibreTinyOTABackend::set_update_md5(const char *md5) { Update.setMD5(md5); }
33 
35  size_t written = Update.write(data, len);
36  if (written == len) {
37  return OTA_RESPONSE_OK;
38  }
39 
40  uint8_t error = Update.getError();
41  ESP_LOGE(TAG, "Write error: %d", error);
42 
44 }
45 
47  if (Update.end()) {
48  return OTA_RESPONSE_OK;
49  }
50 
51  uint8_t error = Update.getError();
52  ESP_LOGE(TAG, "End error: %d", error);
53 
55 }
56 
57 void ArduinoLibreTinyOTABackend::abort() { Update.abort(); }
58 
59 } // namespace ota
60 } // namespace esphome
61 
62 #endif // USE_LIBRETINY
OTAResponseTypes begin(size_t image_size) override
std::unique_ptr< ota::OTABackend > make_ota_backend()
std::string size_t len
Definition: helpers.h:292
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
OTAResponseTypes write(uint8_t *data, size_t len) override