Skip to content

Commit 02d835a

Browse files
lthiagovsanarchyysm
authored andcommitted
feat(ir): new multi-protocol ir library
1 parent d171716 commit 02d835a

25 files changed

Lines changed: 2089 additions & 11 deletions

firmware_p4/components/Service/CMakeLists.txt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,18 @@ idf_component_register(SRCS
3232
${STORAGE_VFS_SRCS}
3333
${STORAGE_ASSETS_SRCS}
3434

35-
"ir/ir_encoder.c"
36-
"ir/ir_common.c"
37-
"ir/ir_tx.c"
38-
"ir/ir_rx.c"
39-
"ir/ir_storage.c"
40-
"ir/protocol_nec.c"
41-
"ir/protocol_rc6.c"
42-
"ir/protocol_rc5.c"
43-
"ir/protocol_samsung32.c"
44-
"ir/protocol_sony.c"
45-
"ir/ir_burst.c"
35+
"ir/ir.c"
36+
"ir/ir_file.c"
37+
"ir/ir_protocol.c"
38+
"ir/ir_protocol_nec.c"
39+
"ir/ir_protocol_samsung.c"
40+
"ir/ir_protocol_lg.c"
41+
"ir/ir_protocol_jvc.c"
42+
"ir/ir_protocol_denon.c"
43+
"ir/ir_protocol_panasonic.c"
44+
"ir/ir_protocol_rc6.c"
45+
"ir/ir_protocol_rc5.c"
46+
"ir/ir_protocol_sony.c"
4647
"lvgl_port/lv_port_indev.c"
4748
"lvgl_port/lv_port_disp.c"
4849
${SD_CARD_SERVICE_SRCS}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2025 HIGH CODE LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef IR_H
16+
#define IR_H
17+
18+
#include "ir_protocol.h"
19+
20+
#define IR_RX_GPIO 6
21+
#define IR_TX_GPIO 5
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
void ir_rx_init(void);
28+
void ir_tx_init(void);
29+
30+
bool ir_receive(ir_data_t *out, uint32_t timeout_ms);
31+
void ir_send(const ir_data_t *data);
32+
void ir_send_raw(const rmt_symbol_word_t *symbols, size_t count, uint32_t carrier_hz);
33+
34+
const rmt_symbol_word_t *ir_last_raw(size_t *count);
35+
36+
void ir_print_raw(rmt_symbol_word_t *symbols, size_t count);
37+
void ir_print_data(const ir_data_t *data);
38+
39+
#ifdef __cplusplus
40+
}
41+
#endif
42+
43+
#endif // IR_H
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) 2025 HIGH CODE LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef IR_FILE_H
16+
#define IR_FILE_H
17+
18+
#include "ir.h"
19+
20+
#define IR_FILE_NAME_MAX 32
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
typedef struct {
27+
char name[IR_FILE_NAME_MAX];
28+
bool is_raw;
29+
ir_data_t data;
30+
uint32_t frequency;
31+
uint32_t *raw; // malloc'd: alternating mark/space durations in us
32+
size_t raw_count;
33+
} ir_signal_t;
34+
35+
typedef struct {
36+
ir_signal_t *signals; // malloc'd array
37+
size_t count;
38+
size_t capacity;
39+
} ir_file_t;
40+
41+
void ir_file_init(ir_file_t *file);
42+
void ir_file_free(ir_file_t *file);
43+
44+
bool ir_file_parse(const char *content, ir_file_t *file);
45+
size_t ir_file_to_string(const ir_file_t *file, char *buf, size_t buf_size);
46+
ir_signal_t *ir_file_find(const ir_file_t *file, const char *name);
47+
void ir_file_send(const ir_signal_t *signal);
48+
void ir_file_add_parsed(ir_file_t *file, const char *name, const ir_data_t *data);
49+
void ir_file_add_raw(ir_file_t *file, const char *name,
50+
const rmt_symbol_word_t *symbols, size_t count, uint32_t freq);
51+
52+
#ifdef __cplusplus
53+
}
54+
#endif
55+
56+
#endif // IR_FILE_H
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) 2025 HIGH CODE LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef IR_PROTOCOL_H
16+
#define IR_PROTOCOL_H
17+
18+
#include <stdbool.h>
19+
#include <stdint.h>
20+
#include <stdlib.h>
21+
#include <driver/rmt_types.h>
22+
23+
#define IR_TOLERANCE 25
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
typedef enum {
30+
IR_PROTO_UNKNOWN = 0,
31+
IR_PROTO_NEC,
32+
IR_PROTO_SAMSUNG,
33+
IR_PROTO_RC6,
34+
IR_PROTO_RC5,
35+
IR_PROTO_SONY,
36+
IR_PROTO_LG,
37+
IR_PROTO_JVC,
38+
IR_PROTO_DENON,
39+
IR_PROTO_PANASONIC,
40+
} ir_protocol_t;
41+
42+
typedef struct {
43+
ir_protocol_t protocol;
44+
uint16_t address;
45+
uint16_t command;
46+
bool repeat;
47+
} ir_data_t;
48+
49+
bool ir_match(uint32_t measured_us, uint32_t expected_us);
50+
const char *ir_protocol_name(ir_protocol_t proto);
51+
uint32_t ir_carrier_freq(ir_protocol_t proto);
52+
53+
bool ir_decode(rmt_symbol_word_t *symbols, size_t count, ir_data_t *out);
54+
size_t ir_encode(const ir_data_t *data, rmt_symbol_word_t *symbols, size_t max);
55+
56+
uint64_t ir_decode_pulse_distance(rmt_symbol_word_t *symbols, size_t offset, size_t num_bits,
57+
uint32_t one_space, uint32_t zero_space, bool msb_first);
58+
uint64_t ir_decode_pulse_width(rmt_symbol_word_t *symbols, size_t offset, size_t num_bits,
59+
uint32_t one_mark, uint32_t zero_mark, bool msb_first);
60+
61+
size_t ir_encode_pulse_distance(rmt_symbol_word_t *symbols,
62+
uint32_t header_mark, uint32_t header_space,
63+
uint32_t bit_mark, uint32_t one_space, uint32_t zero_space,
64+
uint64_t data, size_t num_bits, bool msb_first, bool stop_bit);
65+
size_t ir_encode_pulse_width(rmt_symbol_word_t *symbols,
66+
uint32_t header_mark, uint32_t header_space,
67+
uint32_t one_mark, uint32_t zero_mark, uint32_t bit_space,
68+
uint64_t data, size_t num_bits, bool msb_first, bool stop_bit);
69+
70+
#ifdef __cplusplus
71+
}
72+
#endif
73+
74+
#endif // IR_PROTOCOL_H
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2025 HIGH CODE LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef IR_PROTOCOL_DENON_H
16+
#define IR_PROTOCOL_DENON_H
17+
18+
#include "ir_protocol.h"
19+
20+
#define DENON_BIT_MARK 260
21+
#define DENON_ONE_SPACE 1820
22+
#define DENON_ZERO_SPACE 780
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
bool denon_decode(rmt_symbol_word_t *symbols, size_t count, ir_data_t *out);
29+
size_t denon_encode(const ir_data_t *data, rmt_symbol_word_t *symbols, size_t max);
30+
31+
#ifdef __cplusplus
32+
}
33+
#endif
34+
35+
#endif
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2025 HIGH CODE LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef IR_PROTOCOL_JVC_H
16+
#define IR_PROTOCOL_JVC_H
17+
18+
#include "ir_protocol.h"
19+
20+
#define JVC_HEADER_MARK 8400
21+
#define JVC_HEADER_SPACE 4200
22+
#define JVC_BIT_MARK 526
23+
#define JVC_ONE_SPACE 1578
24+
#define JVC_ZERO_SPACE 526
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
bool jvc_decode(rmt_symbol_word_t *symbols, size_t count, ir_data_t *out);
31+
size_t jvc_encode(const ir_data_t *data, rmt_symbol_word_t *symbols, size_t max);
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
37+
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2025 HIGH CODE LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef IR_PROTOCOL_LG_H
16+
#define IR_PROTOCOL_LG_H
17+
18+
#include "ir_protocol.h"
19+
20+
#define LG_HEADER_MARK 8416
21+
#define LG_HEADER_SPACE 4208
22+
#define LG_BIT_MARK 526
23+
#define LG_ONE_SPACE 1578
24+
#define LG_ZERO_SPACE 550
25+
#define LG_REPEAT_SPACE 2104
26+
27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
30+
31+
bool lg_decode(rmt_symbol_word_t *symbols, size_t count, ir_data_t *out);
32+
size_t lg_encode(const ir_data_t *data, rmt_symbol_word_t *symbols, size_t max);
33+
34+
#ifdef __cplusplus
35+
}
36+
#endif
37+
38+
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2025 HIGH CODE LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef IR_PROTOCOL_NEC_H
16+
#define IR_PROTOCOL_NEC_H
17+
18+
#include "ir_protocol.h"
19+
20+
#define NEC_HEADER_MARK 9000
21+
#define NEC_HEADER_SPACE 4500
22+
#define NEC_BIT_MARK 560
23+
#define NEC_ONE_SPACE 1690
24+
#define NEC_ZERO_SPACE 560
25+
#define NEC_REPEAT_SPACE 2250
26+
27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
30+
31+
bool nec_decode(rmt_symbol_word_t *symbols, size_t count, ir_data_t *out);
32+
size_t nec_encode(const ir_data_t *data, rmt_symbol_word_t *symbols, size_t max);
33+
34+
#ifdef __cplusplus
35+
}
36+
#endif
37+
38+
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2025 HIGH CODE LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef IR_PROTOCOL_PANASONIC_H
16+
#define IR_PROTOCOL_PANASONIC_H
17+
18+
#include "ir_protocol.h"
19+
20+
#define PANASONIC_HEADER_MARK 3456
21+
#define PANASONIC_HEADER_SPACE 1728
22+
#define PANASONIC_BIT_MARK 432
23+
#define PANASONIC_ONE_SPACE 1296
24+
#define PANASONIC_ZERO_SPACE 432
25+
#define PANASONIC_VENDOR_ID 0x2002
26+
27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
30+
31+
bool panasonic_decode(rmt_symbol_word_t *symbols, size_t count, ir_data_t *out);
32+
size_t panasonic_encode(const ir_data_t *data, rmt_symbol_word_t *symbols, size_t max);
33+
34+
#ifdef __cplusplus
35+
}
36+
#endif
37+
38+
#endif

0 commit comments

Comments
 (0)