mirror of
https://github.com/afska/gba-link-connection.git
synced 2026-04-25 08:07:59 -05:00
Exposing the LED
This commit is contained in:
parent
acd414f017
commit
5aa625bf7c
|
|
@ -30,6 +30,16 @@ int main() {
|
|||
|
||||
bool a = true, b = true;
|
||||
|
||||
// linkIR->startCount();
|
||||
// for (u32 i = 0; i < 60; i++) {
|
||||
// VBlankIntrWait();
|
||||
// }
|
||||
// u32 elapsedUs = linkIR->stopCount();
|
||||
// linkIR->stopCount();
|
||||
// Common::log(std::to_string(elapsedUs));
|
||||
// while (true)
|
||||
// ;
|
||||
|
||||
while (true) {
|
||||
std::string output = "LinkIR_demo (v8.0.0)\n\n";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "LinkIR.hpp"
|
||||
|
||||
// To modulate a signal to 38kHz, we need to stay 13.15µs LOW and 13.15µs HIGH.
|
||||
// To modulate a signal at 38kHz, we need to stay 13.15µs LOW and 13.15µs HIGH.
|
||||
// 38kHz signal => 38000/second =>
|
||||
// period = 1000000µs / 38000 = 26.31µs
|
||||
// halfPeriod = 13.15µs
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
LINK_VERSION_TAG LINK_IR_VERSION = "vLinkIR/v8.0.0";
|
||||
|
||||
#define LINK_IR_SIGNAL_END 0
|
||||
#define LINK_IR_NEC_TOTAL_PULSES 68
|
||||
#define LINK_IR_NEC_LEADER_MARK 9000
|
||||
#define LINK_IR_NEC_LEADER_SPACE 4500
|
||||
#define LINK_IR_NEC_PULSE 560
|
||||
|
|
@ -109,9 +110,9 @@ class LinkIR {
|
|||
linkGPIO.writePin(Pin::SO, false);
|
||||
linkGPIO.setSIInterrupts(true);
|
||||
|
||||
linkGPIO.writePin(Pin::SO, true);
|
||||
turnLightOn();
|
||||
waitMicroseconds(TIMEOUT_MICROSECONDS);
|
||||
linkGPIO.writePin(Pin::SO, false);
|
||||
turnLightOff();
|
||||
linkGPIO.setSIInterrupts(false);
|
||||
|
||||
bool success = irq;
|
||||
|
|
@ -121,7 +122,7 @@ class LinkIR {
|
|||
}
|
||||
|
||||
void sendNEC(u8 address, u8 command) {
|
||||
u16 pulses[68];
|
||||
u16 pulses[LINK_IR_NEC_TOTAL_PULSES];
|
||||
u32 i = 0;
|
||||
|
||||
pulses[i++] = LINK_IR_NEC_LEADER_MARK;
|
||||
|
|
@ -133,37 +134,31 @@ class LinkIR {
|
|||
pulses[i++] = LINK_IR_NEC_PULSE;
|
||||
pulses[i++] = LINK_IR_SIGNAL_END;
|
||||
|
||||
send<true>(pulses);
|
||||
send(pulses);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a generic IR signal.
|
||||
* Sends a generic IR signal, modulating at standard 38kHz.
|
||||
* @param pulses An array of u16 numbers describing the signal. Even indices
|
||||
* are *marks* (IR on), odd indices are *spaces* (IR off), and `0` ends the
|
||||
* signal.
|
||||
* @tparam modulate38kHz Whether the *marks* should be modulated to 38kHz or
|
||||
* not. Most common protocols require this (for example, the NEC Protocol).
|
||||
* \warning The carrier frequency is tied to the ASM code. To transmit in
|
||||
* other frequencies, you'll have to bitbang the `SO` pin yourself.
|
||||
*/
|
||||
template <bool modulate38kHz>
|
||||
void send(u16* pulses) {
|
||||
linkGPIO.writePin(Pin::SO, false);
|
||||
turnLightOff();
|
||||
|
||||
for (u32 i = 0; pulses[i] != 0; i++) {
|
||||
u32 microseconds = pulses[i];
|
||||
bool isMark = i % 2 == 0;
|
||||
|
||||
if (isMark) {
|
||||
if constexpr (modulate38kHz) {
|
||||
generate38kHzSignal(microseconds);
|
||||
} else {
|
||||
linkGPIO.writePin(Pin::SO, true);
|
||||
waitMicroseconds(microseconds);
|
||||
}
|
||||
generate38kHzSignal(microseconds);
|
||||
} else {
|
||||
linkGPIO.writePin(Pin::SO, false);
|
||||
turnLightOff();
|
||||
waitMicroseconds(microseconds);
|
||||
}
|
||||
}
|
||||
linkGPIO.writePin(Pin::SO, false);
|
||||
}
|
||||
|
||||
bool receiveNEC(u8& address, u8& command) {
|
||||
|
|
@ -176,6 +171,18 @@ class LinkIR {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the IR LED on.
|
||||
* \warning The adapter won't keep it on for more than 10µs. Add some pauses
|
||||
* after every 10µs.
|
||||
*/
|
||||
void turnLightOn() { linkGPIO.writePin(Pin::SO, true); }
|
||||
|
||||
/**
|
||||
* Turns the IR LED off.
|
||||
*/
|
||||
void turnLightOff() { linkGPIO.writePin(Pin::SO, false); }
|
||||
|
||||
/**
|
||||
* @brief Deactivates the library.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user