Skip to content

refactor(hal): Deprecate DevBoards class and bring HardwareSerial class up to the Sketch Layer#71

Merged
ZZ-Cat merged 15 commits intoMain-Trunkfrom
ZZ-Cat/issue70
Jan 21, 2024
Merged

refactor(hal): Deprecate DevBoards class and bring HardwareSerial class up to the Sketch Layer#71
ZZ-Cat merged 15 commits intoMain-Trunkfrom
ZZ-Cat/issue70

Conversation

@ZZ-Cat
Copy link
Copy Markdown
Owner

@ZZ-Cat ZZ-Cat commented Jan 19, 2024

Overview

This Pull Request deprecates the original DevBoards Hardware Abstraction Layer class and is replaced by Arduino's HardwareSerial class

Details

After a couple of failed attempts at trying to implement a system where you could pick your UART pins vicariously through simply picking which port you wanted, I have decided to bring the HardwareSerial class up to the Sketch Layer.
Here, this gives you more freedom to feed in your own hardware-specific UART port that you want CRSF for Arduino to use.

API Change

This introduces a change to CRSF for Arduino's API - Specifically to do with the constructor.
Instead of passing in the pins your receiver is connected to, you are passing in your chosen HardwareSerial class.

The old way

You would create an instance of CRSF for Arduino in the following ways:

/* As a fixed global instance - This is how Arduino shows most makers.*/
#include <CRSFforArduino.hpp>

#define SERIAL_RX_PIN 0
#define SERIAL_TX_PIN 1

/* This is how we used to do it. */
CRSFforArduino crsf = CRSFforArduino(SERIAL_RX_PIN, SERIAL_TX_PIN);
/* Allocated in dynamic memory (for the C++ Aficionados among us) */
#include <CRSFforArduino.hpp>
#include <new>
using namespace std;

#define SERIAL_RX_PIN 0
#define SERIAL_TX_PIN 1

CRSFforArduino *crsf = nullptr;

void setup()
{
    /* This is how we used to do it. */
    crsf = new CRSFforArduino(SERIAL_RX_PIN, SERIAL_TX_PIN);
}

The new way

Now, you create an instance of CRSF for Arduino in the following ways:

/* As a fixed global instance - This is how Arduino shows most makers.*/
#include <CRSFforArduino.hpp>


/* With your board's default UART port - Serial1: */
CRSFforArduino crsf = CRSFforArduino(&Serial1);
/* Allocated in dynamic memory (for the C++ Aficionados among us) */
#include <CRSFforArduino.hpp>
#include <new>
using namespace std;

CRSFforArduino *crsf = nullptr;

void setup()
{
    /* This is how we do it now. */
    crsf = new CRSFforArduino(&Serial1);
}

@ZZ-Cat ZZ-Cat linked an issue Jan 19, 2024 that may be closed by this pull request
@ZZ-Cat ZZ-Cat added the ...in progress 🚧 Development on this is in progress label Jan 19, 2024
@ZZ-Cat ZZ-Cat added this to the Version 1.0.0 milestone Jan 19, 2024
@ZZ-Cat ZZ-Cat self-assigned this Jan 19, 2024
@ZZ-Cat ZZ-Cat changed the title refactor(hal): Default UART and arbitrary UART port assignments refactor(hal): UART port and pin assignments Jan 19, 2024
@ZZ-Cat ZZ-Cat changed the title refactor(hal): UART port and pin assignments refactor(hal): Deprecate hw_uart API and bring HardwareSerial class up to the Sketch Layer Jan 21, 2024
@ZZ-Cat ZZ-Cat changed the title refactor(hal): Deprecate hw_uart API and bring HardwareSerial class up to the Sketch Layer refactor(hal): Deprecate DevBoards API and bring HardwareSerial class up to the Sketch Layer Jan 21, 2024
@ZZ-Cat ZZ-Cat changed the title refactor(hal): Deprecate DevBoards API and bring HardwareSerial class up to the Sketch Layer refactor(hal): Deprecate DevBoards class and bring HardwareSerial class up to the Sketch Layer Jan 21, 2024
@ZZ-Cat ZZ-Cat marked this pull request as ready for review January 21, 2024 08:53
@ZZ-Cat ZZ-Cat merged commit c9563f1 into Main-Trunk Jan 21, 2024
@ZZ-Cat ZZ-Cat deleted the ZZ-Cat/issue70 branch January 21, 2024 09:21
@ZZ-Cat ZZ-Cat removed the ...in progress 🚧 Development on this is in progress label Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

Re-factor UART pin assignments.

1 participant