+/* macros for ir decoders */
+#define PULSE(units) ((units))
+#define SPACE(units) (-(units))
+#define IS_RESET(duration) ((duration) == 0)
+#define IS_PULSE(duration) ((duration) > 0)
+#define IS_SPACE(duration) ((duration) < 0)
+#define DURATION(duration) (abs((duration)))
+#define IS_TRANSITION(x, y) ((x) * (y) < 0)
+#define DECREASE_DURATION(duration, amount) \
+ do { \
+ if (IS_SPACE(duration)) \
+ duration += (amount); \
+ else if (IS_PULSE(duration)) \
+ duration -= (amount); \
+ } while (0)
+
+#define TO_UNITS(duration, unit_len) \
+ ((int)((duration) > 0 ? \
+ DIV_ROUND_CLOSEST(abs((duration)), (unit_len)) :\
+ -DIV_ROUND_CLOSEST(abs((duration)), (unit_len))))
+#define TO_US(duration) ((int)TO_UNITS(duration, 1000))
+