main: first NEC decoding
This commit is contained in:
parent
68a096be7b
commit
058ab29990
29
main.c
29
main.c
|
@ -382,8 +382,8 @@ void time_isr(void) __interrupt(IRQ_TIM4)
|
|||
// IR capture timer counter
|
||||
void nec_uo_isr(void) __interrupt(IRQ_TIM1_UO)
|
||||
{
|
||||
if (TIM1->SR1.fields.UIF) { // slot longer than NEC slot
|
||||
nec_bit = -2; // set to invalid message
|
||||
if (TIM1->SR1.fields.UIF) { // timer overflow
|
||||
nec_bit = -2; // set to invalid message since it took longer than NEC slot
|
||||
TIM1->SR1.fields.UIF = 0; // clear flag
|
||||
}
|
||||
}
|
||||
|
@ -394,20 +394,12 @@ void nec_cc_isr(void) __interrupt(IRQ_TIM1_CC)
|
|||
static uint32_t nec_bits = 0; // temporary buffer to construct message
|
||||
if (TIM1->SR1.fields.CC1IF) { // start of burst
|
||||
const uint16_t slot = (TIM1->CCR1H.reg << 8) + TIM1->CCR1L.reg;
|
||||
nec_bit++; // start the bit
|
||||
if (0 == nec_bit) { // AGC received
|
||||
if (-1 == nec_bit) { // AGC received
|
||||
nec_bits = 0; // reset message
|
||||
if (slot < NEC_AGC_SLOT_MIN || slot > NEC_AGC_SLOT_MAX) {
|
||||
nec_bit = -2; // slot invalid
|
||||
}
|
||||
} else if (32 == nec_bit) { // trailing pulse received
|
||||
nec_msg[0] = (nec_bits >> 0); // save message
|
||||
nec_msg[1] = (nec_bits >> 8); // save message
|
||||
nec_msg[2] = (nec_bits >> 16); // save message
|
||||
nec_msg[3] = (nec_bits >> 24); // save message
|
||||
nec_flag = true; // notify we received a message
|
||||
nec_bit = -2; // restart message
|
||||
} else if (nec_bit > 0) {
|
||||
} else if (nec_bit >= 0 && nec_bit < 32) {
|
||||
if (slot >= NEC_0_SLOT_MIN && slot <= NEC_0_SLOT_MAX) {
|
||||
// bit should already be 0
|
||||
} else if (slot >= NEC_1_SLOT_MIN && slot <= NEC_1_SLOT_MAX) {
|
||||
|
@ -416,9 +408,20 @@ void nec_cc_isr(void) __interrupt(IRQ_TIM1_CC)
|
|||
nec_bit = -2; // slot invalid
|
||||
}
|
||||
}
|
||||
nec_bit++; // start the bit
|
||||
TIM1->SR1.fields.CC1IF = 0; // clear flag
|
||||
}
|
||||
if (TIM1->SR1.fields.CC2IF) {
|
||||
if (TIM1->SR1.fields.CC2IF) { // start of pause
|
||||
if (32 == nec_bit) {
|
||||
nec_msg[0] = (nec_bits >> 0); // save message
|
||||
nec_msg[1] = (nec_bits >> 8); // save message
|
||||
nec_msg[2] = (nec_bits >> 16); // save message
|
||||
nec_msg[3] = (nec_bits >> 24); // save message
|
||||
nec_flag = true; // notify we received a message
|
||||
nec_bit = -2; // restart message
|
||||
} else if (nec_bit >= 0) {
|
||||
// here we could verify the burst length
|
||||
}
|
||||
TIM1->SR1.fields.CC2IF = 0; // clear flag
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue