#ifndef __IAP_H
#define __IAP_H

#include "settings_api.h"
#include <stdbool.h>


#define BLOCK_SIZE		    128
#define FW_BUF_SIZE		    2048

#define WRITE_BLOCK_COM     2


//
typedef enum 
{
	IAP_START = 0x01,
	IAP_BLOCK = 0x02,
	IAP_FINISH = 0x03,
    IAP_RETURN = 0x04,  
    IAP_FLASH_ERROR = 0x05,
    IAP_RESET = 0x06,

} iap_state_t;


//
void iap_init(void);

//
bool write_buf(void);

//
bool erase_flash(void);

// 
mb_err_code_t check_crc(void);

//
void iap_finish(void);

//
void swap(uint8_t *in_buf, uint8_t *out_buf,  uint8_t size);

#endif // __IAP_H