#ifndef _KIT_MATH_H_
#define _KIT_MATH_H_

#ifdef __cplusplus
extern "C" {
#endif 

#include "kit_core.h"


uint8_t  kit_check_sum8(uint8_t *buf, uint16_t len);
void     kit_append_crc16(uint8_t* buf, uint32_t len);
uint16_t kit_check_crc16(const uint8_t* buf, uint32_t len);

void     kit_set_buf(void* buf, uint32_t len, uint8_t value);
void     kit_copy_buf(void* dest, const void *const src, uint32_t len);
uint32_t kit_copy_str(void *dest, const char * src);
bool     kit_is_buf_same(const void *const dest, const void *const src, uint32_t len);

uint32_t kit_lt_read_buf(const uint8_t *const buf, uint32_t idx, uint32_t len);
uint32_t kit_bt_read_buf(const uint8_t *const buf, uint32_t idx, uint32_t len);
uint32_t kit_lt_add_read_buf(const uint8_t *const buf, uint32_t *idx, uint32_t len);
uint32_t kit_bt_add_read_buf(const uint8_t *const buf, uint32_t *idx, uint32_t len);

void     kit_lt_write_buf(uint8_t *const buf, uint32_t idx, uint32_t value, uint32_t len);
void     kit_add_lt_write_buf(uint8_t * buf, uint32_t *idx, uint32_t value, uint32_t len);
void     kit_add_bt_write_buf(uint8_t * buf, uint32_t *idx, uint32_t value, uint32_t len);

void kit_add_lt_8u_write_buf(uint8_t *const buf, uint32_t *idx, uint8_t value);
void kit_add_lt_16u_write_buf(uint8_t *const buf, uint32_t *idx, uint16_t value);
void kit_add_lt_32u_write_buf(uint8_t *const buf, uint32_t *idx, uint32_t value);


int32_t kit_get_avg_filter_max_min(const int16_t *buf, uint32_t len);
int32_t kit_get_int32_avg_filter_max_min(const int32_t *buf, uint32_t len);
int32_t kit_get_avg_filter_max_min_diff(const int16_t *buf, uint32_t len, uint16_t *diff);
uint32_t kit_get_unsign_avg_filter_max_min(const uint16_t *buf, uint32_t len);
int32_t  kit_get_dma_avg_filter_min_max(uint16_t *buf, uint32_t data_cnt, uint32_t idx, uint32_t sample_cnt);

uint32_t unsigned_add_signed_with_limit(uint32_t u_num,int32_t s_num,uint32_t upper_limit,uint32_t lower_limit);
void kit_bit_fill(uint8_t * buffer,uint8_t start_bit, uint8_t len, uint8_t data);
void kit_bit_fill_u16(uint16_t * buffer,uint8_t start_bit,uint8_t len,uint16_t data);
uint8_t  kit_dec_to_bcd(uint8_t data);
uint8_t  kit_dcb_to_dec(uint8_t data);






#ifdef __cplusplus
}
#endif

#endif    
