ir_nec: add support for extended command address
This commit is contained in:
parent
2f42659b18
commit
a7aab104ba
21
lib/ir_nec.c
21
lib/ir_nec.c
|
@ -39,14 +39,21 @@
|
||||||
*/
|
*/
|
||||||
#define IR_NEC_TIMER 4 /**< timer peripheral */
|
#define IR_NEC_TIMER 4 /**< timer peripheral */
|
||||||
#define IR_NEC_CHANNEL 3 /**< channel used as input capture */
|
#define IR_NEC_CHANNEL 3 /**< channel used as input capture */
|
||||||
#define IR_NEC_JITTER 20 /**< signal timing jitter in % tolerated in timing */
|
#define IR_NEC_JITTER 40 /**< signal timing jitter in % tolerated in timing */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
volatile bool ir_nec_code_received_flag = false;
|
volatile bool ir_nec_code_received_flag = false;
|
||||||
struct ir_nec_code_t ir_nec_code_received;
|
struct ir_nec_code_t ir_nec_code_received;
|
||||||
|
|
||||||
void ir_nec_setup(void)
|
/** if the extended address in the code is used
|
||||||
|
* the extended address uses all 16-bits instead of having redundant/robust 2x8-bits address
|
||||||
|
*/
|
||||||
|
static bool ir_nec_extended = false;
|
||||||
|
|
||||||
|
void ir_nec_setup(bool extended)
|
||||||
{
|
{
|
||||||
|
ir_nec_extended = extended; // remember setting
|
||||||
|
|
||||||
// setup timer to measure signal timing for bit decoding (use timer channel as input capture)
|
// setup timer to measure signal timing for bit decoding (use timer channel as input capture)
|
||||||
rcc_periph_clock_enable(RCC_TIM_CH(IR_NEC_TIMER, IR_NEC_CHANNEL)); // enable clock for GPIO peripheral
|
rcc_periph_clock_enable(RCC_TIM_CH(IR_NEC_TIMER, IR_NEC_CHANNEL)); // enable clock for GPIO peripheral
|
||||||
rcc_periph_clock_enable(RCC_TIM(IR_NEC_TIMER)); // enable clock for timer peripheral
|
rcc_periph_clock_enable(RCC_TIM(IR_NEC_TIMER)); // enable clock for timer peripheral
|
||||||
|
@ -149,15 +156,21 @@ void TIM_ISR(IR_NEC_TIMER)(void)
|
||||||
uint8_t naddress = (bits >> 16) & 0xff; // get negated 8 address bits
|
uint8_t naddress = (bits >> 16) & 0xff; // get negated 8 address bits
|
||||||
uint8_t command = (bits >> 8) & 0xff; // get 8 command bits
|
uint8_t command = (bits >> 8) & 0xff; // get 8 command bits
|
||||||
uint8_t ncommand = (bits >> 0) & 0xff; // get negate 8 commend bits
|
uint8_t ncommand = (bits >> 0) & 0xff; // get negate 8 commend bits
|
||||||
if (0xff != (address ^ naddress)) { // the address and its negative do not match
|
if (!ir_nec_extended) { // the 8-bits address has its inverse
|
||||||
|
if (0xff != (address ^ naddress)) { // the address and its inverse do not match
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (0xff != (command ^ ncommand)) { // the command and its negative do not match
|
}
|
||||||
|
if (0xff != (command ^ ncommand)) { // the command and its inverse do not match
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
valid = true; // remember we have a valid signal
|
valid = true; // remember we have a valid signal
|
||||||
code.repeat = false; // this is not a repeat code
|
code.repeat = false; // this is not a repeat code
|
||||||
|
if (ir_nec_extended) {
|
||||||
|
code.address = (address << 8) + naddress;
|
||||||
|
} else {
|
||||||
code.address = address; // save decoded address
|
code.address = address; // save decoded address
|
||||||
|
}
|
||||||
code.command = command; // save decoded command
|
code.command = command; // save decoded command
|
||||||
ir_nec_code_received.repeat = code.repeat; // transfer code to user
|
ir_nec_code_received.repeat = code.repeat; // transfer code to user
|
||||||
ir_nec_code_received.address = code.address; // transfer code to user
|
ir_nec_code_received.address = code.address; // transfer code to user
|
||||||
|
|
|
@ -26,12 +26,14 @@ extern volatile bool ir_nec_code_received_flag;
|
||||||
/** IR NEC code */
|
/** IR NEC code */
|
||||||
struct ir_nec_code_t {
|
struct ir_nec_code_t {
|
||||||
bool repeat; /**< if this is only a code repeat (received 42.42 ms after the code, 98.75 ms after a repeat) */
|
bool repeat; /**< if this is only a code repeat (received 42.42 ms after the code, 98.75 ms after a repeat) */
|
||||||
uint8_t address; /**< code address (extended 16-bit address is not supported) */
|
uint16_t address; /**< code address (8-bit for non-extended, 16-bit for extended) */
|
||||||
uint8_t command; /**< code command */
|
uint8_t command; /**< code command */
|
||||||
};
|
};
|
||||||
|
|
||||||
/** last IR NEC code received */
|
/** last IR NEC code received */
|
||||||
extern struct ir_nec_code_t ir_nec_code_received;
|
extern struct ir_nec_code_t ir_nec_code_received;
|
||||||
|
|
||||||
/** setup peripherals to receive IR NEC codes */
|
/** setup peripherals to receive IR NEC codes
|
||||||
void ir_nec_setup(void);
|
* @param[in] extended if the command address is extended (using 16 bits instead of 8, at the cost of error checking)
|
||||||
|
*/
|
||||||
|
void ir_nec_setup(bool extended);
|
||||||
|
|
Loading…
Reference in New Issue