ESPHome  2024.10.2
ota_backend_arduino_rp2040.cpp
Go to the documentation of this file.
1 #ifdef USE_ARDUINO
2 #ifdef USE_RP2040
4 #include "ota_backend.h"
5 
7 #include "esphome/core/defines.h"
8 #include "esphome/core/log.h"
9 
10 #include <Updater.h>
11 
12 namespace esphome {
13 namespace ota {
14 
15 static const char *const TAG = "ota.arduino_rp2040";
16 
17 std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoRP2040OTABackend>(); }
18 
20  bool ret = Update.begin(image_size, U_FLASH);
21  if (ret) {
23  return OTA_RESPONSE_OK;
24  }
25 
26  uint8_t error = Update.getError();
27  if (error == UPDATE_ERROR_BOOTSTRAP)
29  if (error == UPDATE_ERROR_NEW_FLASH_CONFIG)
31  if (error == UPDATE_ERROR_FLASH_CONFIG)
33  if (error == UPDATE_ERROR_SPACE)
35 
36  ESP_LOGE(TAG, "Begin error: %d", error);
37 
39 }
40 
41 void ArduinoRP2040OTABackend::set_update_md5(const char *md5) { Update.setMD5(md5); }
42 
44  size_t written = Update.write(data, len);
45  if (written == len) {
46  return OTA_RESPONSE_OK;
47  }
48 
49  uint8_t error = Update.getError();
50  ESP_LOGE(TAG, "Write error: %d", error);
51 
53 }
54 
56  if (Update.end()) {
57  return OTA_RESPONSE_OK;
58  }
59 
60  uint8_t error = Update.getError();
61  ESP_LOGE(TAG, "End error: %d", error);
62 
64 }
65 
67  Update.end();
69 }
70 
71 } // namespace ota
72 } // namespace esphome
73 
74 #endif // USE_RP2040
75 #endif // USE_ARDUINO
OTAResponseTypes write(uint8_t *data, size_t len) override
void preferences_prevent_write(bool prevent)
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 begin(size_t image_size) override