Adding IR adapter README

This commit is contained in:
Rodrigo Alfonso 2025-02-11 22:19:54 -03:00
parent 5b5846aade
commit 4f664002ba
8 changed files with 293 additions and 234 deletions

3
.prettierignore Normal file
View File

@ -0,0 +1,3 @@
# ignore all files except *.md
*
!*.md

4
.prettierrc Normal file
View File

@ -0,0 +1,4 @@
{
"tabWidth": 2,
"useTabs": false
}

View File

@ -17,6 +17,7 @@ A set of Game Boy Advance (GBA) C++ libraries to interact with the Serial Port.
- [⏱️](#%EF%B8%8F-LinkUART) [LinkUART.hpp](lib/LinkUART.hpp): Easily connect to **any PC** using a USB to UART cable!
- [🟪](#-LinkCube) [LinkCube.hpp](lib/LinkCube.hpp): Exchange data with a _Wii_ or a _GameCube_ using the classic **Joybus** protocol!
- [📱](#-LinkMobile) [LinkMobile.hpp](lib/LinkMobile.hpp): Connect to **the internet** using the _Mobile Adapter GB_, brought back to life thanks to the [REON](https://github.com/REONTeam) project!
- [📺](#-LinkIR) [LinkIR.hpp](lib/LinkIR.hpp): Turn down the volume of your **neighbor's TV** using the _Infrared Adapter_!
- [🖱️](#%EF%B8%8F-LinkPS2Mouse) [LinkPS2Mouse.hpp](lib/LinkPS2Mouse.hpp): Connect a **PS/2 mouse** to the GBA for extended controls!
- [⌨️](#%EF%B8%8F-LinkPS2Keyboard) [LinkPS2Keyboard.hpp](lib/LinkPS2Keyboard.hpp): Connect a **PS/2 keyboard** to the GBA for extended controls!
@ -92,7 +93,7 @@ The library uses message queues to send/receive data and transmits when it's pos
`new LinkCable(...)` accepts these **optional** parameters:
| Name | Type | Default | Description |
| ------------- | -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ------------- | -------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `baudRate` | **BaudRate** | `BaudRate::BAUD_RATE_1` | Sets a specific baud rate. |
| `timeout` | **u32** | `3` | Maximum number of _frames_ without receiving data from other player before marking them as disconnected or resetting the connection. |
| `interval` | **u16** | `50` | Number of _1024-cycle ticks_ (61.04μs) between transfers _(50 = 3.052ms)_. It's the interval of Timer #`sendTimerId`. <br/><br/>Lower values will transfer faster but also consume more CPU. You can use `Link::perFrame(...)` to convert from _transfers per frame_ to _interval values_. |
@ -107,7 +108,7 @@ You can update these values at any time without creating a new instance:
## Methods
| Name | Return type | Description |
| --------------------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| --------------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `isActive()` | **bool** | Returns whether the library is active or not. |
| `activate()` | - | Activates the library. |
| `deactivate()` | - | Deactivates the library. |
@ -120,7 +121,7 @@ You can update these values at any time without creating a new instance:
| `canRead(playerId)` | **bool** | Returns `true` if there are pending messages from player #`playerId`. <br/><br/>Keep in mind that if this returns `false`, it will keep doing so until you _fetch new data_ with `sync()`. |
| `read(playerId)` | **u16** | Dequeues and returns the next message from player #`playerId`. If there's no data from that player, a `0` will be returned. |
| `peek(playerId)` | **u16** | Returns the next message from player #`playerId` without dequeuing it. If there's no data from that player, a `0` will be returned. |
| `canSend()` | **bool** | Returns if a `send(...)` call would fail due to the queue being full. |
| `canSend()` | **bool** | Returns whether a `send(...)` call would fail due to the queue being full or not. |
| `send(data)` | **bool** | Sends `data` to all connected players. If `data` is invalid or the send queue is full, a `false` will be returned. |
| `didQueueOverflow([clear])` | **bool** | Returns whether the internal queue lost messages at some point due to being full. This can happen if your queue size is too low, if you receive too much data without calling `sync(...)` enough times, or if you don't `read(...)` enough messages before the next `sync()` call. <br/><br/>After this call, the overflow flag is cleared if `clear` is `true` (default behavior). |
| `resetTimeout()` | - | Resets other players' timeout count to `0`. Call this before reducing `config.timeout`. |
@ -152,7 +153,7 @@ This version is simpler and blocks the system thread until completion. It doesn'
### Methods
| Name | Return type | Description |
| --------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| --------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sendRom(rom, romSize, cancel, [mode])` | **Result** | Sends the `rom` (must be 4-byte aligned). During the handshake process, the library will continuously invoke `cancel`, and abort the transfer if it returns `true`. <br/><br/>The `romSize` must be a number between `448` and `262144`, and a multiple of `16`. <br/><br/>The `mode` can be either `LinkCableMultiboot::TransferMode::MULTI_PLAY` for GBA cable (default value) or `LinkCableMultiboot::TransferMode::SPI` for GBC cable. <br/><br/>Once completed, the return value should be `LinkCableMultiboot::Result::SUCCESS`. |
⚠️ stop DMA before sending the ROM! _(you might need to stop your audio player)_
@ -169,13 +170,12 @@ This version is simpler and blocks the system thread until completion. It doesn'
This version (`LinkCableMultiboot::Async`) allows more advanced use cases like playing animations and/or audio during the transfers, displaying the number of connected players and send percentage, and marking the transfer as 'ready' to start. It requires adding the provided interrupt service routines. The class is polymorphic with `LinkWirelessMultiboot::Async`.
### Constructor
`new LinkCableMultiboot::Async(...)` accepts these **optional** parameters:
| Name | Type | Default | Description |
| ------------- | -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| -------------------- | ---------------- | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `waitForReadySignal` | **bool** | `false` | Whether the code should wait for a `markReady()` call to start the actual transfer. |
| `mode` | **TransferMode** | `TransferMode::MULTI_PLAY` | Either `LinkCableMultiboot::TransferMode::MULTI_PLAY` for GBA cable (default value) or `LinkCableMultiboot::TransferMode::SPI` for GBC cable. |
@ -184,7 +184,7 @@ You can update these values at any time without creating a new instance by mutat
### Methods
| Name | Return type | Description |
| --------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ---------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `sendRom(rom, romSize)` | **bool** | Sends the `rom` (must be 4-byte aligned). <br/><br/>The `romSize` must be a number between `448` and `262144`, and a multiple of `16`. <br/><br/>Once completed, `getState()` should return `LinkCableMultiboot::Async::State::STOPPED` and `getResult()` should return `LinkCableMultiboot::Async::GeneralResult::SUCCESS`. <br/><br/>Returns `false` if there's a pending transfer or the data is invalid. |
| `reset()` | **bool** | Deactivates the library, canceling the in-progress transfer, if any. |
| `isSending()` | **bool** | Returns whether there's an active transfer or not. |
@ -215,7 +215,7 @@ You can update these values at any time without creating a new instance by mutat
## Methods
| Name | Return type | Description |
| ---------------------------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ---------------------------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `isActive()` | **bool** | Returns whether the library is active or not. |
| `activate(baudRate = BAUD_RATE_1)` | - | Activates the library in a specific `baudRate` (`LinkRawCable::BaudRate`). |
| `deactivate()` | - | Deactivates the library. |
@ -249,7 +249,7 @@ https://github.com/afska/gba-link-connection/assets/1631752/7eeafc49-2dfa-4902-a
`new LinkWireless(...)` accepts these **optional** parameters:
| Name | Type | Default | Description |
| ---------------- | -------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ---------------- | -------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `forwarding` | **bool** | `true` | If `true`, the server forwards all messages to the clients. Otherwise, clients only see messages sent from the server (ignoring other peers). |
| `retransmission` | **bool** | `true` | If `true`, the library handles retransmission for you, so there should be no packet loss. |
| `maxPlayers` | **u8** _(2~5)_ | `5` | Maximum number of allowed players. |
@ -274,7 +274,7 @@ You can update these values at any time without creating a new instance:
- `getSignalLevel(...)`, to retrieve signal levels.
| Name | Return type | Description |
| ----------------------------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| -------------------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `isActive()` | **bool** | Returns whether the library is active or not. |
| `activate()` | **bool** | Activates the library. When an adapter is connected, it changes the state to `AUTHENTICATED`. It can also be used to disconnect or reset the adapter. |
| `restoreExistingConnection()` | **bool** | Restores the state from an existing connection on the Wireless Adapter hardware. <br/><br/>This is useful, for example, after a fresh launch of a Multiboot game, to synchronize the library with the current state and avoid a reconnection. <br/><br/>Returns whether the restoration was successful. On success, the state should be either `SERVING` or `CONNECTED`. <br/><br/>This should be used as a replacement for `activate()`. |
@ -287,7 +287,7 @@ You can update these values at any time without creating a new instance:
| `getServersAsyncEnd(servers, serverCount)` | **bool** | Fills the `servers` array with all the currently broadcasting servers. Changes the state to `AUTHENTICATED` again. |
| `connect(serverId)` | **bool** | Starts a connection with `serverId` and changes the state to `CONNECTING`. |
| `keepConnecting()` | **bool** | When connecting, this needs to be called until the state is `CONNECTED`. It assigns a player ID. <br/><br/>Keep in mind that `isConnected()` and `playerCount()` won't be updated until the first message from the server arrives. |
| `canSend()` | **bool** | Returns if a `send(...)` call would fail due to the queue being full. |
| `canSend()` | **bool** | Returns whether a `send(...)` call would fail due to the queue being full or not. |
| `send(data)` | **bool** | Enqueues `data` to be sent to other nodes. |
| `receive(messages, receivedCount)` | **bool** | Fills the `messages` array with incoming messages. |
| `getState()` | **State** | Returns the current state (one of `LinkWireless::State::NEEDS_RESET`, `LinkWireless::State::AUTHENTICATED`, `LinkWireless::State::SEARCHING`, `LinkWireless::State::SERVING`, `LinkWireless::State::CONNECTING`, or `LinkWireless::State::CONNECTED`). |
@ -312,10 +312,10 @@ You can update these values at any time without creating a new instance:
- `LINK_WIRELESS_PUT_ISR_IN_IWRAM`: to put critical functions in IWRAM, which can significantly improve performance due to its faster access. This is disabled by default to conserve IWRAM space, which is limited, but it's enabled in demos to showcase its performance benefits.
- If you enable this, make sure that `lib/iwram_code/LinkWireless.cpp` gets compiled! For example, in a Makefile-based project, verify that the directory is in your `SRCDIRS` list.
- Depending on how much IWRAM you have available, you might want to tweak these knobs:
* `LINK_WIRELESS_PUT_ISR_IN_IWRAM_SERIAL`: (default: `1`) Put the SERIAL ISR in IWRAM (recommended, since this handler runs ~20 times per frame)
* `LINK_WIRELESS_PUT_ISR_IN_IWRAM_TIMER`: (default: `1`) Put the TIMER ISR in IWRAM (not that necessary)
* `LINK_WIRELESS_PUT_ISR_IN_IWRAM_SERIAL_LEVEL`: (default: `"-Ofast"`) Optimization level for the SERIAL ISR
* `LINK_WIRELESS_PUT_ISR_IN_IWRAM_TIMER_LEVEL`: (default: `"-Ofast"`) Optimization level for the TIMER ISR
- `LINK_WIRELESS_PUT_ISR_IN_IWRAM_SERIAL`: (default: `1`) Put the SERIAL ISR in IWRAM (recommended, since this handler runs ~20 times per frame)
- `LINK_WIRELESS_PUT_ISR_IN_IWRAM_TIMER`: (default: `1`) Put the TIMER ISR in IWRAM (not that necessary)
- `LINK_WIRELESS_PUT_ISR_IN_IWRAM_SERIAL_LEVEL`: (default: `"-Ofast"`) Optimization level for the SERIAL ISR
- `LINK_WIRELESS_PUT_ISR_IN_IWRAM_TIMER_LEVEL`: (default: `"-Ofast"`) Optimization level for the TIMER ISR
- `LINK_WIRELESS_ENABLE_NESTED_IRQ`: to allow `LINK_WIRELESS_ISR_*` functions to be interrupted. This can be useful, for example, if your audio engine requires calling a VBlank handler with precise timing.
# 💻 LinkWirelessMultiboot
@ -335,7 +335,7 @@ This version is simpler and blocks the system thread until completion. It doesn'
### Methods
| Name | Return type | Description |
| -------------------------------------------------------------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| --------------------------------------------------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `sendRom(rom, romSize, gameName, userName, gameId, players, listener, [keepConnectionAlive])` | **Result** | Sends the `rom`. <br/><br/>The `players` must be the number of consoles that will download the ROM. Once this number of players is reached, the code will start transmitting the ROM bytes. <br/><br/>During the process, the library will continuously invoke `listener` (passing a `LinkWirelessMultiboot::MultibootProgress` object as argument), and abort the transfer if it returns `true`. <br/><br/>The `romSize` must be a number between `448` and `262144`. It's recommended to use a ROM size that is a multiple of `16`, since this also ensures compatibility with Multiboot via Link Cable. <br/><br/>Once completed, the return value should be `LinkWirelessMultiboot::Result::SUCCESS`. <br/><br/>You can start the transfer before the player count is reached by running `*progress.ready = true;` in the`cancel` callback. <br/><br/>If `keepConnectionAlive` is `true`, the adapter won't be reset after a successful transfer, so users can continue the session using `LinkWireless::restoreExistingConnection()`. |
| `reset()` | **bool** | Turns off the adapter and deactivates the library. It returns a boolean indicating whether the transition to low consumption mode was successful. |
@ -352,13 +352,13 @@ This version (`LinkWirelessMultiboot::Async`) allows more advanced use cases lik
`new LinkWirelessMultiboot::Async(...)` accepts these **optional** parameters:
| Name | Type | Default | Description |
| ------------- | -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| --------------------- | ---------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gameName` | **const char\*** | `""` | Game name. Maximum `14` characters + null terminator. |
| `userName` | **const char\*** | `""` | Maximum number of _frames_ without receiving data from other player before marking them as disconnected or resetting the connection. |
| `gameId` | **u16** _(0 ~ 0x7FFF)_ | `0x7FFF` | The Game ID to be broadcasted. |
| `players` | **u32** _(2~5)_ | `5` | The number of consoles that will download the ROM. Once this number of players is reached, the code will start transmitting the ROM bytes, unless `waitForReadySignal` is `true`. |
| `waitForReadySignal` | **bool** | `false` | Whether the code should wait for a `markReady()` call to start the actual transfer. |
| `keepConnectionAlive` | **bool** | `false` | If `true`, the adapter won't be reset after a successful transfer, so users can continue the session using `LinkWireless::restoreExistingConnection()`.
| `keepConnectionAlive` | **bool** | `false` | If `true`, the adapter won't be reset after a successful transfer, so users can continue the session using `LinkWireless::restoreExistingConnection()`. |
| `interval` | **u16** | `50` | Number of _1024-cycle ticks_ (61.04μs) between transfers _(50 = 3.052ms)_. It's the interval of Timer #`timerId`. <br/><br/>Lower values will transfer faster but also consume more CPU. Some audio players require precise interrupt timing to avoid crashes! Use a minimum of 30. |
| `timerId` | **u8** _(0~3)_ | `3` | GBA Timer to use for sending. |
@ -367,7 +367,7 @@ You can update these values at any time without creating a new instance by mutat
### Methods
| Name | Return type | Description |
| --------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ---------------------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sendRom(rom, romSize)` | **bool** | Sends the `rom`. <br/><br/>The `romSize` must be a number between `448` and `262144`. It's recommended to use a ROM size that is a multiple of `16`, since this also ensures compatibility with Multiboot via Link Cable. <br/><br/>Once completed, `isSending()` should return `false` and `getResult()` should return `LinkWirelessMultiboot::Async::GeneralResult::SUCCESS`. <br/><br/>Returns `false` if there's a pending transfer or the data is invalid. |
| `reset()` | **bool** | Turns off the adapter and deactivates the library, canceling the in-progress transfer, if any. It returns a boolean indicating whether the transition to low consumption mode was successful. |
| `isSending()` | **bool** | Returns whether there's an active transfer or not. |
@ -443,7 +443,7 @@ Additionally, there's a `LinkWirelessOpenSDK::MultiTransfer` class for file tran
## Methods
| Name | Return type | Description |
| ------------------------------------------------------------------------------------- | ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ------------------------------------------------------------------------------------- | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `getChildrenData(response)` | **ChildrenData** | Parses the `response` and returns a struct containing all the received packets from the connected clients. |
| `getParentData(response)` | **ParentData** | Parses the `response` and returns a struct containing all the received packets from the host. |
| `createServerBuffer(fullPayload, fullPayloadSize, sequence, [targetSlots], [offset])` | **SendBuffer<ServerSDKHeader>** | Creates a buffer for the host to send a `fullPayload` with a valid header. <br/><br/>If `fullPayloadSize` is higher than `84` (the maximum payload size), the buffer will only contain the **first** `84` bytes (unless an `offset` > 0 is used). <br/><br/>A `sequence` number must be created by using `LinkWirelessOpenSDK::SequenceNumber::fromPacketId(...)`. <br/><br/>Optionally, a `targetSlots` bit array can be used to exclude some clients from the transmissions (the default is `0b1111`). |
@ -464,7 +464,7 @@ https://github.com/afska/gba-link-connection/assets/1631752/d1f49a48-6b17-4954-9
`new LinkUniversal(...)` accepts these **optional** parameters:
| Name | Type | Default | Description |
| ----------------- | ---------------------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ----------------- | ------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `protocol` | **Protocol** | `AUTODETECT` | Specifies what protocol should be used (one of `LinkUniversal::Protocol::AUTODETECT`, `LinkUniversal::Protocol::CABLE`, `LinkUniversal::Protocol::WIRELESS_AUTO`, `LinkUniversal::Protocol::WIRELESS_SERVER`, `LinkUniversal::Protocol::WIRELESS_CLIENT`, or `LinkUniversal::Protocol::WIRELESS_RESTORE_EXISTING`). |
| `gameName` | **const char\*** | `""` | The game name that will be broadcasted in wireless sessions (max `14` characters). The string must be a null-terminated character array. The library uses this to only connect to servers from the same game. |
| `cableOptions` | **CableOptions** | _same as LinkCable_ | All the [👾 LinkCable](#-LinkCable) constructor parameters in one _struct_. |
@ -475,7 +475,7 @@ https://github.com/afska/gba-link-connection/assets/1631752/d1f49a48-6b17-4954-9
The interface is the same as [👾 LinkCable](#-LinkCable). Additionally, it supports these methods:
| Name | Return type | Description |
| ----------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ----------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `getState()` | **State** | Returns the current state (one of `LinkUniversal::State::INITIALIZING`, `LinkUniversal::State::WAITING`, or `LinkUniversal::State::CONNECTED`). |
| `getMode()` | **Mode** | Returns the active mode (one of `LinkUniversal::Mode::LINK_CABLE`, or `LinkUniversal::Mode::LINK_WIRELESS`). |
| `getProtocol()` | **Protocol** | Returns the active protocol (one of `LinkUniversal::Protocol::AUTODETECT`, `LinkUniversal::Protocol::CABLE`, `LinkUniversal::Protocol::WIRELESS_AUTO`, `LinkUniversal::Protocol::WIRELESS_SERVER`, `LinkUniversal::Protocol::WIRELESS_CLIENT`, or `LinkUniversal::Protocol::WIRELESS_RESTORE_EXISTING`). |
@ -500,7 +500,7 @@ _(aka General Purpose Mode)_
## Methods
| Name | Return type | Description |
| ---------------------------- | ----------------------- | --------------------------------------------------------------------------------------------------------------- |
| ---------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------- |
| `reset()` | - | Resets communication mode to General Purpose (same as `Link::reset()`). **Required to initialize the library!** |
| `setMode(pin, direction)` | - | Configures a `pin` to use a `direction` (input or output). |
| `getMode(pin)` | **Direction** | Returns the direction set at `pin`. |
@ -524,7 +524,7 @@ _(aka Normal Mode)_
## Methods
| Name | Return type | Description |
| ------------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `isActive()` | **bool** | Returns whether the library is active or not. |
| `activate(mode, [dataSize])` | - | Activates the library in a specific `mode` (one of `LinkSPI::Mode::SLAVE`, `LinkSPI::Mode::MASTER_256KBPS`, or `LinkSPI::Mode::MASTER_2MBPS`). By default, the `dataSize` is 32-bit, but can be changed to `LinkSPI::DataSize::SIZE_8BIT`. |
| `deactivate()` | - | Deactivates the library. |
@ -580,7 +580,7 @@ _(aka UART Mode)_
## Methods
| Name | Return type | Description |
| ---------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ---------------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `isActive()` | **bool** | Returns whether the library is active or not. |
| `activate(baudRate, dataSize, parity, useCTS)` | - | Activates the library using a specific UART mode. _Defaults: 9600bps, 8-bit data, no parity bit, no CTS_. |
| `deactivate()` | - | Deactivates the library. |
@ -622,7 +622,7 @@ _(aka JOYBUS Mode)_
## Methods
| Name | Return type | Description |
| ------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| --------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `isActive()` | **bool** | Returns whether the library is active or not. |
| `activate()` | - | Activates the library. |
| `deactivate()` | - | Deactivates the library. |
@ -639,7 +639,9 @@ _(aka JOYBUS Mode)_
## Compile-time constants
- `LINK_CUBE_QUEUE_SIZE`: to set a custom buffer size (how many incoming and outgoing values the queues can store at max). The default value is `10`, which seems fine for most games.
- This affects how much memory is allocated. With the default value, it's around `120` bytes. There's a double-buffered pending queue (to avoid data races), and 1 outgoing queue.
- You can approximate the memory usage with:
- `LINK_CUBE_QUEUE_SIZE * sizeof(u32) * 3` <=> `LINK_CUBE_QUEUE_SIZE * 12`
@ -709,6 +711,49 @@ You can update these values at any time without creating a new instance:
- `LINK_MOBILE_QUEUE_SIZE`: to set a custom request queue size (how many commands can be queued at the same time). The default value is `10`, which seems fine for most games.
- This affects how much memory is allocated. With the default value, it's around `3` KB.
# 📺 LinkIR
_(aka Infrared Adapter or AGB-006)_
[⬆️](#gba-link-connection) The Infrared adapter was only used in one commercial game: _Cyber Drive Zoids: Kiju no Senshi Hyuu_, but we can now give it a better use with homebrew!
This library lets you control the IR LED directly via bitbanging, send/receive modulated 38kHz signals, and send/receive pulses in the standard NEC protocol.
// TODO: VIDEO
![screenshot](https://github.com/user-attachments/assets/fcc1488b-4955-4a1b-8ffa-dd660175a45c)
## Constructor
`new LinkIR(...)` accepts these **optional** parameters:
| Name | Type | Default | Description |
| ------------------ | -------------- | ------- | ----------------------------------------- |
| `primaryTimerId` | **u8** _(0~3)_ | `2` | GBA Timer to use for counting time (1/2). |
| `secondaryTimerId` | **u8** _(0~3)_ | `3` | GBA Timer to use for counting time (2/2). |
You can update these values at any time without creating a new instance:
- Call `deactivate()`.
- Mutate the `config` property.
- Call `activate()`.
## Methods
| Name | Return type | Description |
| -------------------------------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `isActive()` | **bool** | Returns whether the library is active or not. |
| `activate()` | - | Activates the library. Returns whether the adapter is connected or not. |
| `deactivate()` | - | Deactivates the library. |
| `sendNEC(address, command)` | - | Sends a NEC signal, with an 8-bit `address` and an 8-bit `command`. |
| `receiveNEC(address, command, [startTimeout])` | **bool** | Receives a signal and returns whether it's a NEC signal or not. If it is, the `address` and `command` will be filled. Returns `true` on success. <br/><br/>If a `startTimeout` is provided, the reception will be canceled after that number of microseconds if no signal is detected. |
| `parseNEC(pulses, address, command)` | **bool** | Tries to interpret an already received array of `pulses` as a NEC signal. On success, returns `true` and fills the `address` and `command` parameters. |
| `send(pulses)` | - | Sends a generic IR signal, modulating at standard 38kHz. <br/><br/>The `pulses` are u16 numbers describing the signal. Even indices are _marks_ (IR on), odd indices are _spaces_ (IR off), and `0` ends the signal. |
| `receive(pulses, maxEntries, [startTimeout], [signalTimeout])` | **bool** | Receives a generic IR signal modulated at standard 38kHz, up to a certain number of pulses (`maxEntries`). Returns whether something was received or not. <br/><br/>The `pulses` are u16 numbers describing the signal. Even indices are _marks_ (IR on), odd indices are _spaces_ (IR off), and `0` ends the signal. <br/><br/>If a `startTimeout` is provided, the reception will be canceled after that number of microseconds if no signal is detected. <br/><br/>If a `signalTimeout` is provided, the reception will be terminated after a _space_ longer than that number of microseconds (default: `15000`). |
| `setLight(on)` | - | Turns the output IR LED ON/OFF through the `SO` pin (HIGH = ON). Add some pauses after every 10µs! |
| `isEmittingLight()` | **bool** | Returns whether the output IR LED is ON or OFF. |
| `isDetectingLight()` | **bool** | Returns whether a remote light signal is detected through the `SI` pin (LOW = DETECTED) or not. |
⚠️ wait at least 1 microsecond before `send(...)` and `receive(...)` calls!
# 🖱️ LinkPS2Mouse
@ -723,7 +768,7 @@ You can update these values at any time without creating a new instance:
## Methods
| Name | Return type | Description |
| ----------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ----------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `isActive()` | **bool** | Returns whether the library is active or not. |
| `activate()` | - | Activates the library. |
| `deactivate()` | - | Deactivates the library. |

View File

@ -13,10 +13,10 @@
The AGB-006 is an accessory released in conjunction with Cyber Drive Zoids: Kiju no Senshi Hyuu on July 18, 2003. It serves as an infrared adapter, coming as a bundle with each game. Using IR signals, players can turn their GBAs into remote controls to pilot three toy model Zoids. Although the GBA removed the GBC's IR port, the AGB-006 officially restored that functionality as an add-on. Unfortunately Cyber Drive Zoids was the only game to take adavantage of the AGB-006.
* The AGB-006 is a small attachment that fits into the GBA serial port providing IR functionalities
* Has 2 IR diodes, one for receiving and one for transmitting
* Very similar in size and shape to the connecting end of a DOL-011 (Gamecube-to-GBA cable)
* Compatible with CDZ-01 Diablotiger, CDZ-02 Cyclops, and CDZ-EX Diablotiger B
- The AGB-006 is a small attachment that fits into the GBA serial port providing IR functionalities
- Has 2 IR diodes, one for receiving and one for transmitting
- Very similar in size and shape to the connecting end of a DOL-011 (Gamecube-to-GBA cable)
- Compatible with CDZ-01 Diablotiger, CDZ-02 Cyclops, and CDZ-EX Diablotiger B
## \[AGB-006\] : Device Detection

View File

@ -265,7 +265,7 @@ class LinkCable {
}
/**
* @brief Returns if a `send(...)` call would fail due to the queue being
* @brief Returns whether a `send(...)` call would fail due to the queue being
* full.
*/
bool canSend() { return !_state.outgoingMessages.isFull(); }

View File

@ -34,6 +34,9 @@
// - 9) Receive manually:
// bool ledOn = linkIR->isDetectingLight();
// --------------------------------------------------------------------------
// considerations:
// - wait at least 1 microsecond before `send(...)` and `receive(...)` calls!
// --------------------------------------------------------------------------
#ifndef LINK_DEVELOPMENT
#pragma GCC system_header
@ -100,7 +103,8 @@ class LinkIR {
[[nodiscard]] bool isActive() { return isEnabled; }
/**
* @brief Activates the library. Returns if the adapter is connected or not.
* @brief Activates the library. Returns whether the adapter is connected or
* not.
*/
bool activate() {
LINK_READ_TAG(LINK_IR_VERSION);
@ -133,6 +137,14 @@ class LinkIR {
return detected;
}
/**
* @brief Deactivates the library.
*/
void deactivate() {
isEnabled = false;
linkGPIO.reset();
}
/**
* Sends a NEC signal.
* @param address An 8-bit address, to specify the device.
@ -178,6 +190,8 @@ class LinkIR {
/**
* Tries to interpret an already received array of `pulses` as a NEC signal.
* On success, returns `true` and fills the `address` and `command` 
* parameters.
* @param pulses The pulses to interpret. Returns `true` on success.
* @param address The read 8-bit address, specifying the device.
* @param command The read 8-bit command, specifying the action.
@ -231,7 +245,8 @@ class LinkIR {
void send(u16 pulses[]); // defined in `LinkIR.cpp`
/**
* Receives a generic IR signal modulated at standard 38kHz.
* Receives a generic IR signal modulated at standard 38kHz. Returns whether
* something was received or not.
* @param pulses An array to be filled with u16 numbers describing the signal.
* Even indices are *marks* (IR on), odd indices are *spaces* (IR off), and
* `0` ends the signal.
@ -251,7 +266,7 @@ class LinkIR {
/**
* Turns the output IR LED ON/OFF through the `SO` pin (HIGH = ON).
* @param on Whether the light should be ON.
* \warning Add some pauses after every 10µs.
* \warning Add some pauses after every 10µs!
*/
void setLight(bool on) { linkGPIO.writePin(Pin::SO, on); }
@ -266,14 +281,6 @@ class LinkIR {
*/
bool isDetectingLight() { return !linkGPIO.readPin(Pin::SI); }
/**
* @brief Deactivates the library.
*/
void deactivate() {
isEnabled = false;
linkGPIO.reset();
}
/**
* @brief This method is called by the SERIAL interrupt handler.
* \warning This is internal API!

View File

@ -354,8 +354,8 @@ class LinkUniversal {
}
/**
* @brief Returns if a `send(...)` call would fail due to the queue being
* full.
* @brief Returns whether a `send(...)` call would fail due to the queue being
* full or not.
*/
bool canSend() {
return mode == Mode::LINK_CABLE ? linkCable.canSend()

View File

@ -613,8 +613,8 @@ class LinkWireless {
}
/**
* @brief Returns if a `send(...)` call would fail due to the queue being
* full.
* @brief Returns whether a `send(...)` call would fail due to the queue being
* full or not.
*/
bool canSend() { return !sessionState.newOutgoingMessages.isFull(); }