Flipper Zero Firmware
Loading...
Searching...
No Matches
level_duration.h
1#pragma once
2
3#include <stdint.h>
4
5#define LEVEL_DURATION_BIG
6
7#ifdef LEVEL_DURATION_BIG
8
9#define LEVEL_DURATION_RESET 0U
10#define LEVEL_DURATION_LEVEL_LOW 1U
11#define LEVEL_DURATION_LEVEL_HIGH 2U
12#define LEVEL_DURATION_WAIT 3U
13#define LEVEL_DURATION_RESERVED 0x800000U
14
15typedef struct {
16 uint32_t duration : 30;
17 uint8_t level : 2;
19
20static inline LevelDuration level_duration_make(bool level, uint32_t duration) {
21 LevelDuration level_duration;
22 level_duration.level = level ? LEVEL_DURATION_LEVEL_HIGH : LEVEL_DURATION_LEVEL_LOW;
23 level_duration.duration = duration;
24 return level_duration;
25}
26
27static inline LevelDuration level_duration_reset() {
28 LevelDuration level_duration;
29 level_duration.level = LEVEL_DURATION_RESET;
30 return level_duration;
31}
32
33static inline LevelDuration level_duration_wait() {
34 LevelDuration level_duration;
35 level_duration.level = LEVEL_DURATION_WAIT;
36 return level_duration;
37}
38
39static inline bool level_duration_is_reset(LevelDuration level_duration) {
40 return level_duration.level == LEVEL_DURATION_RESET;
41}
42
43static inline bool level_duration_is_wait(LevelDuration level_duration) {
44 return level_duration.level == LEVEL_DURATION_WAIT;
45}
46
47static inline bool level_duration_get_level(LevelDuration level_duration) {
48 return level_duration.level == LEVEL_DURATION_LEVEL_HIGH;
49}
50
51static inline uint32_t level_duration_get_duration(LevelDuration level_duration) {
52 return level_duration.duration;
53}
54
55#else
56
57#define LEVEL_DURATION_RESET 0U
58#define LEVEL_DURATION_RESERVED 0x800000U
59
60typedef int32_t LevelDuration;
61
62static inline LevelDuration level_duration(bool level, uint32_t duration) {
63 return level ? duration : -(int32_t)duration;
64}
65
66static inline LevelDuration level_duration_reset() {
67 return LEVEL_DURATION_RESET;
68}
69
70static inline bool level_duration_is_reset(LevelDuration level_duration) {
71 return level_duration == LEVEL_DURATION_RESET;
72}
73
74static inline bool level_duration_get_level(LevelDuration level_duration) {
75 return level_duration > 0;
76}
77
78static inline uint32_t level_duration_get_duration(LevelDuration level_duration) {
79 return (level_duration >= 0) ? level_duration : -level_duration;
80}
81
82#endif
Definition level_duration.h:15