ESPHome 2025.5.0
Loading...
Searching...
No Matches
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
8#include "esphome/core/log.h"
9
10#include <Updater.h>
11
12namespace esphome {
13namespace ota {
14
15static const char *const TAG = "ota.arduino_rp2040";
16
17std::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
41void 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
70
71} // namespace ota
72} // namespace esphome
73
74#endif // USE_RP2040
75#endif // USE_ARDUINO
OTAResponseTypes begin(size_t image_size) override
OTAResponseTypes write(uint8_t *data, size_t len) override
std::unique_ptr< ota::OTABackend > make_ota_backend()
@ OTA_RESPONSE_ERROR_WRONG_NEW_FLASH_CONFIG
Definition ota_backend.h:34
@ OTA_RESPONSE_ERROR_WRONG_CURRENT_FLASH_CONFIG
Definition ota_backend.h:33
@ OTA_RESPONSE_ERROR_WRITING_FLASH
Definition ota_backend.h:30
@ OTA_RESPONSE_ERROR_UPDATE_END
Definition ota_backend.h:31
@ OTA_RESPONSE_ERROR_RP2040_NOT_ENOUGH_SPACE
Definition ota_backend.h:39
@ OTA_RESPONSE_ERROR_UNKNOWN
Definition ota_backend.h:40
@ OTA_RESPONSE_ERROR_INVALID_BOOTSTRAPPING
Definition ota_backend.h:32
void preferences_prevent_write(bool prevent)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:301
std::unique_ptr< T > make_unique(Args &&...args)
Definition helpers.h:85