|
| 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 |
0 commit comments