#ifndef UTILS_H_
#define UTILS_H_

/**** Includes ****/
#include <stdint.h>

namespace util {

/**** Public definitions ****/
/**** Public function declarations ****/
uint8_t invert(uint8_t x);
uint16_t invert(uint16_t x);
uint32_t invert(uint32_t x);

uint8_t sat_add(uint8_t x, uint8_t y);
uint16_t sat_add(uint16_t x, uint16_t y);
uint32_t sat_add(uint32_t x, uint32_t y);

uint8_t sat_subtract(uint8_t x, uint8_t y);
uint16_t sat_subtract(uint16_t x, uint16_t y);
uint32_t sat_subtract(uint32_t x, uint32_t y);

uint8_t abs_subtract(uint8_t x, uint8_t y);
uint16_t abs_subtract(uint16_t x, uint16_t y);
uint32_t abs_subtract(uint32_t x, uint32_t y);

uint16_t sat_cast(uint32_t x);
uint16_t sat_cast(int32_t x);

uint8_t is_timed_out(uint16_t time, uint16_t limit);
uint8_t is_in_range(uint16_t value, uint16_t min, uint16_t max);

uint16_t time_delta(uint16_t start, uint16_t end);
uint32_t time_delta(uint32_t start, uint32_t end);

uint16_t time_delta(uint16_t start, uint16_t end, uint16_t max);
uint32_t time_delta(uint32_t start, uint32_t end, uint32_t max);

uint16_t convert_muldivoff(uint16_t raw, uint8_t mul, uint8_t div, int16_t offset);
uint16_t sat_mul_kilo(uint16_t xk, uint16_t yk);
uint16_t sat_div_kilo(uint16_t top, uint16_t bot);
uint16_t sat_ratio(uint16_t top, uint16_t bot);
uint16_t percent_to_16b(uint8_t percent);

uint16_t percent_of(uint8_t percent, uint16_t value);

#ifdef TESTING
#endif

} //namespace

#endif /* UTILS_H_ */