Adding sendNEC helper

This commit is contained in:
Rodrigo Alfonso
2025-02-10 00:35:22 -03:00
parent a3ce3d76fc
commit c0c2283cfb
2 changed files with 75 additions and 43 deletions

View File

@@ -39,49 +39,52 @@ int main() {
if (Common::didPress(KEY_A, a)) {
Common::log("Sending...");
linkIR->send<true>((u16[]){
// leader
9000, 4500,
// address 0x04, LSB first (bits: 0,0,1,0,0,0,0,0)
560, 560, // bit0: 0
560, 560, // bit1: 0
560, 1690, // bit2: 1
560, 560, // bit3: 0
560, 560, // bit4: 0
560, 560, // bit5: 0
560, 560, // bit6: 0
560, 560, // bit7: 0
// inverted Address 0xFB, LSB first (bits: 1,1,0,1,1,1,1,1)
560, 1690, // bit0: 1
560, 1690, // bit1: 1
560, 560, // bit2: 0
560, 1690, // bit3: 1
560, 1690, // bit4: 1
560, 1690, // bit5: 1
560, 1690, // bit6: 1
560, 1690, // bit7: 1
// command 0x03, LSB first (bits: 1,1,0,0,0,0,0,0)
560, 1690, // bit0: 1
560, 1690, // bit1: 1
560, 560, // bit2: 0
560, 560, // bit3: 0
560, 560, // bit4: 0
560, 560, // bit5: 0
560, 560, // bit6: 0
560, 560, // bit7: 0
// inverted command 0xFC, LSB first (bits: 0,0,1,1,1,1,1,1)
560, 560, // bit0: 0
560, 560, // bit1: 0
560, 1690, // bit2: 1
560, 1690, // bit3: 1
560, 1690, // bit4: 1
560, 1690, // bit5: 1
560, 1690, // bit6: 1
560, 1690, // bit7: 1
// final burst
560,
// terminator
0});
linkIR->sendNEC(0x04, 0x03);
// linkIR->send<true>((u16[]){
// // leader
// 9000, 4500,
// // address 0x04, LSB first (bits: 0,0,1,0,0,0,0,0)
// 560, 560, // bit0: 0
// 560, 560, // bit1: 0
// 560, 1690, // bit2: 1
// 560, 560, // bit3: 0
// 560, 560, // bit4: 0
// 560, 560, // bit5: 0
// 560, 560, // bit6: 0
// 560, 560, // bit7: 0
// // inverted Address 0xFB, LSB first (bits: 1,1,0,1,1,1,1,1)
// 560, 1690, // bit0: 1
// 560, 1690, // bit1: 1
// 560, 560, // bit2: 0
// 560, 1690, // bit3: 1
// 560, 1690, // bit4: 1
// 560, 1690, // bit5: 1
// 560, 1690, // bit6: 1
// 560, 1690, // bit7: 1
// // command 0x03, LSB first (bits: 1,1,0,0,0,0,0,0)
// 560, 1690, // bit0: 1
// 560, 1690, // bit1: 1
// 560, 560, // bit2: 0
// 560, 560, // bit3: 0
// 560, 560, // bit4: 0
// 560, 560, // bit5: 0
// 560, 560, // bit6: 0
// 560, 560, // bit7: 0
// // inverted command 0xFC, LSB first (bits: 0,0,1,1,1,1,1,1)
// 560, 560, // bit0: 0
// 560, 560, // bit1: 0
// 560, 1690, // bit2: 1
// 560, 1690, // bit3: 1
// 560, 1690, // bit4: 1
// 560, 1690, // bit5: 1
// 560, 1690, // bit6: 1
// 560, 1690, // bit7: 1
// // final burst
// 560,
// // terminator
// 0});
Common::log("DONE!");
Common::waitForKey(KEY_B);
}

View File

@@ -36,6 +36,11 @@
LINK_VERSION_TAG LINK_IR_VERSION = "vLinkIR/v8.0.0";
#define LINK_IR_SIGNAL_END 0
#define LINK_IR_NEC_LEADER_MARK 9000
#define LINK_IR_NEC_LEADER_SPACE 4500
#define LINK_IR_NEC_PULSE 560
#define LINK_IR_NEC_SPACE_1 1690
#define LINK_IR_NEC_SPACE_0 560
#define LINK_IR_DEFAULT_TOLERANCE_PERCENTAGE 15
#define LINK_IR_DEFAULT_TIMER_ID 3
@@ -109,6 +114,22 @@ class LinkIR {
return success;
}
void sendNEC(u8 address, u8 command) {
u16 pulses[68];
u32 i = 0;
pulses[i++] = LINK_IR_NEC_LEADER_MARK;
pulses[i++] = LINK_IR_NEC_LEADER_SPACE;
addNECByte(pulses, i, address);
addNECByte(pulses, i, (u8)~address);
addNECByte(pulses, i, command);
addNECByte(pulses, i, (u8)~command);
pulses[i++] = LINK_IR_NEC_PULSE;
pulses[i++] = LINK_IR_SIGNAL_END;
send<true>(pulses);
}
/**
* Sends a generic IR signal.
* @param pulses An array of u16 numbers describing the signal. Even indices
@@ -174,6 +195,14 @@ class LinkIR {
volatile bool isEnabled = false;
volatile bool irq = false;
void addNECByte(u16* pulses, u32& i, u8 value) {
for (u32 b = 0; b < 8; b++) {
pulses[i++] = LINK_IR_NEC_PULSE;
pulses[i++] =
(value >> b) & 1 ? LINK_IR_NEC_SPACE_1 : LINK_IR_NEC_SPACE_0;
}
}
void generate38kHzSignal(u32 microseconds); // defined in ASM (`LinkIR.cpp`)
void waitMicroseconds(u32 microseconds); // defined in ASM (`LinkIR.cpp`)