embclib  0.1
Macros | Functions
utils.h File Reference

helper function More...

#include "stdint.h"
Include dependency graph for utils.h:

Go to the source code of this file.

Macros

#define __UTILS_VERSION   (0x0001u)
 Source file version tag. More...
 
#define Min(a, b)   (((a) < (b)) ? (a) : (b))
 Find the smaller value. More...
 
#define Max(a, b)   (((a) > (b)) ? (a) : (b))
 Find the greater value. More...
 
#define Abs(n)   ((n < 0) ? (-n) : (n))
 convert negative value to non-negative value More...
 
#define Pow2(x)   (1 << (x))
 Find the power of 2 of given value. More...
 
#define Swap(a, b)   ((a) ^= (b) ^= (a) ^= (b))
 Swap/Exchange between the two values. More...
 
#define Limit(val, min, max)   (Min( Max(val, (min) ), (max) ))
 Limit value between maximum and minimum range. More...
 

Functions

int16_t UTILS_Rand_i16 (int16_t min_i16, int16_t max_i16)
 Generate the random value between range. More...
 
void UTILS_RandSeed (uint16_t seed_i16)
 Initialize the value to random number generator. More...
 
int16_t UTILS_Scale_i16 (int16_t in_value_i16, int16_t in_min_i16, int16_t in_max_i16, int16_t out_min_i16, int16_t out_max_i16)
 Scale a number from one range to another. More...
 

Detailed Description

helper function

Author
Binary Maker (https://github.com/binarymaker)
Date
2019-10-15

Macro Definition Documentation

◆ __UTILS_VERSION

#define __UTILS_VERSION   (0x0001u)

Source file version tag.

   version info: [15:8] main [7:0] beta

version: 0.1v

◆ Abs

#define Abs (   n)    ((n < 0) ? (-n) : (n))

convert negative value to non-negative value

◆ Limit

#define Limit (   val,
  min,
  max 
)    (Min( Max(val, (min) ), (max) ))

Limit value between maximum and minimum range.

◆ Max

#define Max (   a,
 
)    (((a) > (b)) ? (a) : (b))

Find the greater value.

◆ Min

#define Min (   a,
 
)    (((a) < (b)) ? (a) : (b))

Find the smaller value.

◆ Pow2

#define Pow2 (   x)    (1 << (x))

Find the power of 2 of given value.

◆ Swap

#define Swap (   a,
 
)    ((a) ^= (b) ^= (a) ^= (b))

Swap/Exchange between the two values.

Function Documentation

◆ UTILS_Rand_i16()

int16_t UTILS_Rand_i16 ( int16_t  min_i16,
int16_t  max_i16 
)

Generate the random value between range.

Parameters
min_i16[in] Minimum limit of random number
max_i16[in] Maximum limit of random number
Returns
int16_t Random number

◆ UTILS_RandSeed()

void UTILS_RandSeed ( uint16_t  seed_i16)

Initialize the value to random number generator.

Parameters
seed_i16initialize value

◆ UTILS_Scale_i16()

int16_t UTILS_Scale_i16 ( int16_t  in_value_i16,
int16_t  in_min_i16,
int16_t  in_max_i16,
int16_t  out_min_i16,
int16_t  out_max_i16 
)

Scale a number from one range to another.

Parameters
in_value_i16[in] Scaling value
in_min_i16[in] From range minimum value
in_max_i16[in] From range maximum value
out_min_i16[in] To range minimum value
out_max_i16[in] To range maximum value
Returns
int16_t Range scaled value