Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(serial receiver interface): ♻️ Facilitate custom baud rates #132

Merged
merged 1 commit into from
Aug 16, 2024

Conversation

ZZ-Cat
Copy link
Owner

@ZZ-Cat ZZ-Cat commented Aug 13, 2024

Overview

Resolves #131.

This Pull Request enables the ability to set custom baud rates as a parameter to sketchLayer::CRSFforArduino::begin().
In turn, this passes the baud rate to the Serial Receiver Interface, where the physical UART is initialised with your custom baud rate and the expected time to receive a full length frame is automatically adjusted at initialisation to compensate.

For backwards-compatibility, if no parameter is provided in the begin() function, CRSF for Arduino defaults to the legacy 420 KB/s baud rate.

Code examples

Using the default baud rate

#include "Arduino.h"
#include "CRSFforArduino.hpp"

CRSFforArduino *cfa = nullptr;

void a_generic_function()
{
    /* ...previous set-up code...*/

    /* Initialise CRSF for Arduino. */
    cfa = new CRSFforArduino();
    if (cfa != nullptr)
    {
        /* By default, CRSF for Arduino initialises its hardware UART with the legacy 420 KB/s if no parameter is provided. */
        cfa->begin();
    }

    /* ...more set-up code... */

}

Providing your own baud rate

"Fine, I'll do it myself!" --Thanos

You MAY pass in your own baud rate as a parameter to sketchLayer::CRSFforArduino::begin()

#include "Arduino.h"
#include "CRSFforArduino.hpp"

CRSFforArduino *cfa = nullptr;

void a_generic_function()
{
    /* ...previous set-up code...*/

    /* Initialise CRSF for Arduino. */
    cfa = new CRSFforArduino();
    if (cfa != nullptr)
    {
        /* You MAY provide your own baud rate as a parameter. */
        const unsigned long yourCustomBaudRate = 416666;

        /* Pass your custom baud rate to `begin()` to tell CRSF for Arduino to initialise its UART with your custom baud rate.
        In this example, the "official" 416.67 KB/s baud rate is chosen. */
        cfa->begin(yourCustomBaudRate);
    }

    /* ...more set-up code... */

}

…through `CRSFforArduino::begin()`

The legacy 420 KB/s baud rate is used by default. You MAY pass in your own baud rate as the `baudRate` parameter to the function `CRSFforArduino::begin()` and CRSF for Arduino's Serial Receiver Interface will initialise its UART with this baud rate, and it will automatically adjust the time needed to receive a full frame to compensate.
@ZZ-Cat ZZ-Cat added the ✨️ Enhancement ✨️ New feature or request label Aug 13, 2024
@ZZ-Cat ZZ-Cat self-assigned this Aug 13, 2024
@ZZ-Cat ZZ-Cat changed the title refactor(serial receiver interface): ♻️ Facilitate custom baud rate as parameter to CRSFforArduino::begin() function refactor(serial receiver interface): ♻️ Facilitate custom baud rates Aug 13, 2024
@ZZ-Cat
Copy link
Owner Author

ZZ-Cat commented Aug 13, 2024

Right-oh. Looks like we're good-to-go here.

@krababonga can you check out the associated branch for this Pull Request, flash one of the examples in that branch (with your custom baud rate) onto a compatible development board, and let me know how you get on? TIA.

@krababonga
Copy link

I checked branch changes on new tracer receiver and old crossfire with ESP32, works like a charm.

@ZZ-Cat
Copy link
Owner Author

ZZ-Cat commented Aug 16, 2024

I checked branch changes on new tracer receiver and old crossfire with ESP32, works like a charm.

Sweet as. =^/.^=
I'mma go ahead and merge this into the v1.0.x Maintenance Branch.

Anything else comes up, don't hesitate to sing out, yea?

@ZZ-Cat ZZ-Cat merged commit 77a8843 into v1.0.x-Maintenance-Branch Aug 16, 2024
5 checks passed
@ZZ-Cat ZZ-Cat deleted the ZZ-Cat/issue131 branch August 16, 2024 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨️ Enhancement ✨️ New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants