mirror of
https://github.com/esphome/esphome.git
synced 2025-04-20 17:50:29 +01:00
Co-authored-by: Kuba Szczodrzyński <kuba@szczodrzynski.pl> Co-authored-by: Sam Neirinck <git@samneirinck.com> Co-authored-by: David Buezas <dbuezas@users.noreply.github.com> Co-authored-by: Stroe Andrei Catalin <catalin2402@gmail.com> Co-authored-by: Sam Neirinck <github@samneirinck.be> Co-authored-by: Péter Sárközi <xmisterhu@gmail.com> Co-authored-by: Hajo Noerenberg <hn@users.noreply.github.com>
47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
#include "esphome/core/defines.h"
|
|
#ifdef USE_LIBRETINY
|
|
|
|
#include "ota_backend_arduino_libretiny.h"
|
|
#include "ota_component.h"
|
|
#include "ota_backend.h"
|
|
|
|
#include <Update.h>
|
|
|
|
namespace esphome {
|
|
namespace ota {
|
|
|
|
OTAResponseTypes ArduinoLibreTinyOTABackend::begin(size_t image_size) {
|
|
bool ret = Update.begin(image_size, U_FLASH);
|
|
if (ret) {
|
|
return OTA_RESPONSE_OK;
|
|
}
|
|
|
|
uint8_t error = Update.getError();
|
|
if (error == UPDATE_ERROR_SIZE)
|
|
return OTA_RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE;
|
|
return OTA_RESPONSE_ERROR_UNKNOWN;
|
|
}
|
|
|
|
void ArduinoLibreTinyOTABackend::set_update_md5(const char *md5) { Update.setMD5(md5); }
|
|
|
|
OTAResponseTypes ArduinoLibreTinyOTABackend::write(uint8_t *data, size_t len) {
|
|
size_t written = Update.write(data, len);
|
|
if (written != len) {
|
|
return OTA_RESPONSE_ERROR_WRITING_FLASH;
|
|
}
|
|
return OTA_RESPONSE_OK;
|
|
}
|
|
|
|
OTAResponseTypes ArduinoLibreTinyOTABackend::end() {
|
|
if (!Update.end())
|
|
return OTA_RESPONSE_ERROR_UPDATE_END;
|
|
return OTA_RESPONSE_OK;
|
|
}
|
|
|
|
void ArduinoLibreTinyOTABackend::abort() { Update.abort(); }
|
|
|
|
} // namespace ota
|
|
} // namespace esphome
|
|
|
|
#endif // USE_LIBRETINY
|