roll_value.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include <stdint.h>
  3. typedef uint8_t TotpRollValueOverflowBehavior;
  4. enum TotpRollValueOverflowBehaviors {
  5. /**
  6. * @brief Do not change value if it reached constraint
  7. */
  8. RollOverflowBehaviorStop,
  9. /**
  10. * @brief Set value to opposite constraint value if it reached constraint
  11. */
  12. RollOverflowBehaviorRoll
  13. };
  14. #define TOTP_ROLL_VALUE_FN_HEADER(type, step_type) \
  15. void totp_roll_value_##type( \
  16. type* value, \
  17. step_type step, \
  18. type min, \
  19. type max, \
  20. TotpRollValueOverflowBehavior overflow_behavior)
  21. /**
  22. * @brief Rolls \c int8_t \p value using \p min and \p max as an value constraints with \p step step.
  23. * When value reaches constraint value \p overflow_behavior defines what to do next.
  24. * @param[in,out] value value to roll
  25. * @param step step to be used to change value
  26. * @param min minimal possible value
  27. * @param max maximum possible value
  28. * @param overflow_behavior defines what to do when value reaches constraint value
  29. */
  30. TOTP_ROLL_VALUE_FN_HEADER(int8_t, int8_t);
  31. /**
  32. * @brief Rolls \c uint8_t \p value using \p min and \p max as an value constraints with \p step step.
  33. * When value reaches constraint value \p overflow_behavior defines what to do next.
  34. * @param[in,out] value value to roll
  35. * @param step step to be used to change value
  36. * @param min minimal possible value
  37. * @param max maximum possible value
  38. * @param overflow_behavior defines what to do when value reaches constraint value
  39. */
  40. TOTP_ROLL_VALUE_FN_HEADER(uint8_t, int8_t);
  41. /**
  42. * @brief Rolls \c uint16_t \p value using \p min and \p max as an value constraints with \p step step.
  43. * When value reaches constraint value \p overflow_behavior defines what to do next.
  44. * @param[in,out] value value to roll
  45. * @param step step to be used to change value
  46. * @param min minimal possible value
  47. * @param max maximum possible value
  48. * @param overflow_behavior defines what to do when value reaches constraint value
  49. */
  50. TOTP_ROLL_VALUE_FN_HEADER(uint16_t, int16_t);