ir_nec: add support for extended command address
This commit is contained in:
parent
2f42659b18
commit
a7aab104ba
25
lib/ir_nec.c
25
lib/ir_nec.c
|
@ -39,14 +39,21 @@
|
|||
*/
|
||||
#define IR_NEC_TIMER 4 /**< timer peripheral */
|
||||
#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;
|
||||
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)
|
||||
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
|
||||
|
@ -149,15 +156,21 @@ void TIM_ISR(IR_NEC_TIMER)(void)
|
|||
uint8_t naddress = (bits >> 16) & 0xff; // get negated 8 address bits
|
||||
uint8_t command = (bits >> 8) & 0xff; // get 8 command bits
|
||||
uint8_t ncommand = (bits >> 0) & 0xff; // get negate 8 commend bits
|
||||
if (0xff != (address ^ naddress)) { // the address and its negative do not match
|
||||
goto error;
|
||||
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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
valid = true; // remember we have a valid signal
|
||||
code.repeat = false; // this is not a repeat code
|
||||
code.address = address; // save decoded address
|
||||
if (ir_nec_extended) {
|
||||
code.address = (address << 8) + naddress;
|
||||
} else {
|
||||
code.address = address; // save decoded address
|
||||
}
|
||||
code.command = command; // save decoded command
|
||||
ir_nec_code_received.repeat = code.repeat; // 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 */
|
||||
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) */
|
||||
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 */
|
||||
};
|
||||
|
||||
/** last IR NEC code received */
|
||||
extern struct ir_nec_code_t ir_nec_code_received;
|
||||
|
||||
/** setup peripherals to receive IR NEC codes */
|
||||
void ir_nec_setup(void);
|
||||
/** setup peripherals to receive IR NEC codes
|
||||
* @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