-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[2.0.0] Adds the setRXInterrupt #4656
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
Closed
Closed
Changes from 40 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
4d262c5
Merge pull request #1 from espressif/master
timkoers a4df65f
Added UART RX interrupt function
timkoers b20b3cd
Merge branch 'master' of github.com:timkoers/arduino-esp32
timkoers 725ad11
Updated HardwareSerial class with the interrupt functions
timkoers e8272c7
Added Serial 'tests' for Interrupt and stock code
timkoers 623796a
This should add the Serial interrupt and no interrupt ino's to the co…
timkoers 000482e
Platform IO sketch sources are messing everything up
timkoers 2e657a7
Platform IO install script fixed
timkoers 38914ff
Arduino Core install script fixed
timkoers 8a27284
Fixed HardwareSerial setRXInterrupt argument type
timkoers ba351a8
Whoopsie
timkoers 8db7e7f
tested and verified to work
timkoers 96fa55f
Should fix compilation error
timkoers 7d84946
Rewrite of the interrupt handlers for the uart devs
timkoers 054c1a9
Should fix compilation error
timkoers c344425
Better use else if, or else the input get's duplicated whilest it is …
timkoers 1ba43fc
Updated code formatting and removed commented lines from ci test scripts
timkoers cadb74d
Updated code formatting once again
timkoers 02b29fd
Last code formatting fix
timkoers d63d896
Accidentally removed some args whilest formatting the code
timkoers 7bea5a4
Free the interupt from the array on enable/disable of the interrupt, …
timkoers def8f9c
Renamed the interrupt management functions
timkoers 21043d5
Removed tests from Windows and Mac
timkoers 55ae3be
Fixed setRxInterrupt in HardwareSerial.cpp and fixed double deletion …
timkoers be5000b
Resolved the if statements
timkoers 6d7e8eb
Cleaned up and commented the Interrupt example
timkoers e3298ea
Changed serials to Serial and Serial2
timkoers 3bfadf8
Changed example to buffer
timkoers 8cda769
Fixed compilation error
timkoers 36ebb83
Fixed compilation error
timkoers cf98504
Lost my focus a bit, I think
timkoers 0b2ae4e
Updated uart hal code, with comments regarding the interrupt clearing…
timkoers 715f399
Reverted scripts back to it's original form
timkoers 4f80e57
Reverted on-push to stock form
timkoers f33c332
Fixed ISR concurrency problems in example
timkoers 5beb727
Update on-push.sh
timkoers 52b8a41
Update on-push.sh
timkoers f948c78
Replaced tabs with spaces ;-)
timkoers 4441190
And fixed the remaining things
timkoers ce3952d
Fixed whitespace refactoring and compilation error
timkoers d8f54ee
Added documentation to the examples and added another Interrupt handl…
timkoers b3511e5
Don't forget to actually add the example ;-)
timkoers 32a7446
Fixed wrong define name
timkoers f89b634
Added include for queue.h
timkoers 41a869a
Not sure how I got confused with Queue_t, but fixed
timkoers 12b8725
Fixed
timkoers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#define BUFFER_SIZE 8 | ||
|
||
// This semaphore is here to handle the interruption of the loop when the interrupt is running. | ||
SemaphoreHandle_t bufferSemaphore; | ||
|
||
static volatile char inputBuffer[BUFFER_SIZE]; | ||
static volatile size_t inputBufferLength = 0; | ||
|
||
// Please keep in mind, since the ESP32 is dual core, | ||
// the interrupt will be running on the same core as the setRxInterrupt function was called on. | ||
static void IRAM_ATTR onSerialRX(uint8_t character, void* user_arg){ | ||
|
||
timkoers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Cast the user_arg back to a array | ||
char* buffer = (char*)user_arg; | ||
|
||
BaseType_t xHighPriorityTaskWoken; | ||
|
||
if(xSemaphoreTakeFromISR(bufferSemaphore, &xHighPriorityTaskWoken) == pdTRUE){ | ||
if(inputBufferLength < BUFFER_SIZE){ | ||
buffer[inputBufferLength++] = (char)character; | ||
} | ||
xSemaphoreGiveFromISR(bufferSemaphore, &xHighPriorityTaskWoken); | ||
} | ||
} | ||
|
||
void setup() | ||
{ | ||
bufferSemaphore = xSemaphoreCreateBinary(); | ||
|
||
Serial.begin(115200); | ||
Serial2.begin(115200); | ||
|
||
// The user_arg is expected to be a void pointer (void*), | ||
// so take the reference of the variable, and it to a void* | ||
Serial2.setRxInterrupt(onSerialRX, (void*)&inputBuffer); | ||
} | ||
|
||
void loop() | ||
{ | ||
if(xSemaphoreTake(bufferSemaphore, portMAX_DELAY) == pdTRUE && inputBufferLength == (BUFFER_SIZE - 1)){ | ||
for(size_t i = 0; i < inputBufferLength; i++){ | ||
Serial.write(inputBuffer[i]); | ||
|
||
// Clear the buffer | ||
inputBuffer[i] = '\0'; | ||
} | ||
// Clear the bufferLength | ||
inputBufferLength = 0; | ||
|
||
xSemaphoreGive(bufferSemaphore); | ||
} | ||
|
||
delay(1000); // Wait for one second | ||
timkoers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
13 changes: 13 additions & 0 deletions
13
libraries/ESP32/examples/Serial/NoInterrupt/NoInterrupt.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
HardwareSerial hwSerial(0); | ||
timkoers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
HardwareSerial hwSerial2(2); | ||
|
||
void setup() | ||
{ | ||
hwSerial.begin(115200); | ||
hwSerial2.begin(115200); | ||
} | ||
|
||
void loop() | ||
{ | ||
hwSerial.print(hwSerial2.read()); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.