* Generate 38 kHz IR signal by bit banging and using delayMicroseconds() and micros() */
| 69 | * Generate 38 kHz IR signal by bit banging and using delayMicroseconds() and micros() |
| 70 | */ |
| 71 | void sendMark(uint8_t aSendPin, unsigned int aMarkMicros) { |
| 72 | unsigned long tMicros = micros(); |
| 73 | unsigned long tNextPeriodEnding = tMicros; |
| 74 | #if defined(F_CPU) |
| 75 | unsigned long tEndMicros = tMicros + (112 / (F_CPU / MICROS_IN_ONE_SECOND)) + aMarkMicros; // To compensate for call duration - 112 is an empirical value |
| 76 | #else |
| 77 | unsigned long tEndMicros = tMicros + aMarkMicros; |
| 78 | #endif |
| 79 | do { |
| 80 | /* |
| 81 | * Generate pulse |
| 82 | */ |
| 83 | noInterrupts(); // do not let interrupts extend the short on period |
| 84 | digitalWriteFast(aSendPin, HIGH); |
| 85 | delayMicroseconds(8); // 8 us for a 30 % duty cycle for 38 kHz |
| 86 | digitalWriteFast(aSendPin, LOW); |
| 87 | interrupts(); // Enable interrupts - to keep micros correct- for the longer off period 3.4 us until receive ISR is active (for 7 us + pop's) |
| 88 | |
| 89 | /* |
| 90 | * PWM pause timing and end check |
| 91 | * Minimal pause duration is 4.3 us |
| 92 | */ |
| 93 | tNextPeriodEnding += 26; // 26.3 us period for 38 kHz; 26 us -> 38.48 kHz |
| 94 | do { |
| 95 | tMicros = micros(); // we have only 4 us resolution for AVR @16MHz |
| 96 | /* |
| 97 | * Exit the forever loop if aMarkMicros has reached |
| 98 | */ |
| 99 | if (tMicros >= tEndMicros) { |
| 100 | return; |
| 101 | } |
| 102 | } while (tMicros < tNextPeriodEnding); |
| 103 | } while (true); |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | * Send NEC with 16 bit address and command, even if aCommand < 0x100 (I.E. ONKYO) |
no outgoing calls
no test coverage detected