File lt_ota.h
Go to the documentation of this file.
/* Copyright (c) Kuba Szczodrzyński 2023-03-09. */
#pragma once
#include <libretiny.h>
#include <uf2ota/uf2types.h>
typedef enum {
    OTA_TYPE_SINGLE = 0,
    OTA_TYPE_DUAL   = 1,
    OTA_TYPE_FILE   = 2,
} lt_ota_type_t;
typedef struct {
    uf2_ota_t uf2;
    uf2_info_t info;
    uint8_t buf[UF2_BLOCK_SIZE];   // block data buffer
    uint8_t *buf_pos;              // buffer writing position
    uint32_t bytes_written;        // update progress
    uint32_t bytes_total;          // total update size
    uf2_err_t error;               // LT OTA/uf2ota error code
    bool running;                  // whether update has begun
    void (*callback)(void *param); // progress callback
    void *callback_param;          // callback argument
} lt_ota_ctx_t;
void lt_ota_begin(lt_ota_ctx_t *ctx, size_t size);
bool lt_ota_end(lt_ota_ctx_t *ctx);
void lt_ota_set_write_protect(uf2_ota_t *uf2);
size_t lt_ota_write(lt_ota_ctx_t *ctx, const uint8_t *data, size_t len);
bool lt_ota_write_block(lt_ota_ctx_t *ctx, uf2_block_t *block);
lt_ota_type_t lt_ota_get_type();
bool lt_ota_is_valid(uint8_t index);
bool lt_ota_can_rollback();
uint8_t lt_ota_dual_get_current();
uint8_t lt_ota_dual_get_stored();
uf2_ota_scheme_t lt_ota_get_uf2_scheme();
bool lt_ota_switch(bool revert);