Description
Overview
I have been working on a project that requires processing the reception of UART frames in microseconds. The current API for the Serial class does not have a way to include user callbacks for whenever UART frames are received.
I would like to request a feature to add a callback function for the reception of frames as this gives the user more control over the data for real-time scenarios. I know the Arduino SDK provides basic APIs to access the HW peripherals but this would enrich the framework by providing advanced API methods for real-time scenarios.
As an example Espressif has an API to register callbacks for the UART peripherals of the ESP32. So I do not think I am the first to think this feature is useful.
Context
I work with Master's students at a University and giving them advanced API features would allow for more control of the Hardware peripherals while using the Arduino SDK.
Proposal
I have implemented already this callback API for the Arduino Sam Core in a fork as I needed the feature:
https://github.com/vChavezB/ArduinoCore-sam
I also made a pull-request and discussed this in a similar pull-request from another user.
As you can see, there is interest for advanced API methods in the SDK but unfortunately (at least) in the Arduino SAM repo there is no activity from the maintainers which could enhance the current status.
Open-questions
If this feature is of interest to be integrated by the Arduino Development Team, the main open-points are :
- What will happen to the circular buffer if the user attaches its own callback? Should it continue storing the RX frames?
- What type of callback is required? For my forked, I added the option of adding a callback parameter. This is useful for scenarios where you are using OOP and passing around object instances or if using an RTOS passing the context.