structs.rs (1453B)
1 pub(crate) type Result<T> = core::result::Result<T, OtaError>; 2 3 #[derive(Debug, PartialEq)] 4 #[cfg_attr(feature = "defmt", derive(defmt::Format))] 5 pub enum OtaError { 6 NotEnoughPartitions, 7 OtaNotStarted, 8 FlashRWError, 9 WrongCRC, 10 WrongOTAPArtitionOrder, 11 OtaVerifyError, 12 CannotFindCurrentBootPartition, 13 } 14 15 #[derive(Clone)] 16 pub struct FlashProgress { 17 pub last_crc: u32, 18 pub flash_offset: u32, 19 pub flash_size: u32, 20 pub remaining: u32, 21 22 pub target_partition: usize, 23 pub target_crc: u32, 24 } 25 26 #[derive(Debug)] 27 pub struct PartitionInfo { 28 pub ota_partitions: [(u32, u32); 16], 29 pub ota_partitions_count: usize, 30 31 pub otadata_offset: u32, 32 pub otadata_size: u32, 33 } 34 35 #[repr(u32)] 36 #[derive(Debug, PartialEq)] 37 #[cfg_attr(feature = "defmt", derive(defmt::Format))] 38 pub enum OtaImgState { 39 EspOtaImgNew = 0x0, 40 EspOtaImgPendingVerify = 0x1, 41 EspOtaImgValid = 0x2, 42 EspOtaImgInvalid = 0x3, 43 EspOtaImgAborted = 0x4, 44 EspOtaImgUndefined = 0xFFFFFFFF, 45 } 46 47 #[repr(C)] 48 #[derive(Debug)] 49 pub struct EspOtaSelectEntry { 50 pub seq: u32, 51 pub seq_label: [u8; 20], 52 pub ota_state: OtaImgState, 53 pub crc: u32, 54 } 55 56 impl EspOtaSelectEntry { 57 /// Check if crc(of seq) is correct, if not - its setting seq to 0 58 pub fn check_crc(&mut self) { 59 if !crate::helpers::is_crc_seq_correct(self.seq, self.crc) { 60 self.seq = 0; // set seq to 0 if crc not correct! 61 } 62 } 63 }