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

Serial::eventOn and Serial::eventAfter do not enable rxInterrupt #158

Open
c272 opened this issue Oct 21, 2022 · 1 comment
Open

Serial::eventOn and Serial::eventAfter do not enable rxInterrupt #158

c272 opened this issue Oct 21, 2022 · 1 comment

Comments

@c272
Copy link
Contributor

c272 commented Oct 21, 2022

When configuring CODAL_SERIAL_EVT_HEAD_MATCH and CODAL_SERIAL_EVT_DELIM_MATCH events for Serial (through the use of eventOn and eventAfter), there is no lazy initialisation of the rxBuffer/rxInterrupt performed with initialiseRx. This results in the events not being fired until the the rxInterrupt and buffer is then later configured by another function call, even if data is sent over serial to the device.

This seems to me quite unintuitive behaviour; if the event is configured and data is then sent to the device over serial, then it should follow that the event is called. You can replicate this behaviour with the following code:

#include <MicroBit.h>
MicroBit uBit;

//Callback for when serial data is received.
void callback(MicroBitEvent e) {
    while (true)
        uBit.display.scroll("DATA!");
}

int main() {
    uBit.init();
    
    //Set up an eventAfter for when we receive any bytes.
    uBit.messageBus.listen(MICROBIT_ID_SERIAL, MICROBIT_SERIAL_EVT_HEAD_MATCH, callback);
    uBit.serial.eventAfter(1);

    //Release to the scheduler.
    release_fiber();
}

If this is is seen as unintended behaviour, then I can submit a pull request to lazy initialise the rxBuffer from both of these event functions. Let me know if this would be a change that would be acceptable!

@microbit-carlos
Copy link
Contributor

Great catch @c272! are you happy to submit a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants