Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-pico
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-pico
Commits
09b5693f
Commit
09b5693f
authored
Mar 25, 2021
by
Earle F. Philhower, III
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add attach/detachInterrupt support
Fixes #21
parent
784217b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
cores/rp2040/Arduino.h
cores/rp2040/Arduino.h
+8
-0
cores/rp2040/wiring_private.cpp
cores/rp2040/wiring_private.cpp
+28
-0
No files found.
cores/rp2040/Arduino.h
View file @
09b5693f
...
...
@@ -28,6 +28,7 @@
#include "api/ArduinoAPI.h"
#include <pins_arduino.h>
#define digitalPinToInterrupt(P) (P)
#include "debug_internal.h"
...
...
@@ -35,6 +36,13 @@
extern
"C"
{
#endif // __cplusplus
void
interrupts
();
void
noInterrupts
();
void
attachInterrupt
(
pin_size_t
pin
,
voidFuncPtr
callback
,
PinStatus
mode
);
void
detachInterrupt
(
pin_size_t
pin
);
void
pinMode
(
pin_size_t
pinNumber
,
PinMode
pinMode
);
// SIO (GPIO)
...
...
cores/rp2040/wiring_private.cpp
View file @
09b5693f
...
...
@@ -19,6 +19,7 @@
*/
#include <Arduino.h>
#include <hardware/gpio.h>
#include <hardware/sync.h>
#include <stack>
...
...
@@ -37,3 +38,30 @@ extern "C" void noInterrupts() {
irqStack
.
push
(
save_and_disable_interrupts
());
}
static
uint32_t
_irqMap
=
0
;
extern
"C"
void
attachInterrupt
(
pin_size_t
pin
,
voidFuncPtr
callback
,
PinStatus
mode
)
{
uint32_t
events
;
switch
(
mode
)
{
case
LOW
:
events
=
1
;
break
;
case
HIGH
:
events
=
2
;
break
;
case
FALLING
:
events
=
4
;
break
;
case
RISING
:
events
=
8
;
break
;
case
CHANGE
:
events
=
4
|
8
;
break
;
default:
return
;
// ERROR
}
noInterrupts
();
detachInterrupt
(
pin
);
gpio_set_irq_enabled_with_callback
(
pin
,
events
,
true
,
(
gpio_irq_callback_t
)
callback
);
_irqMap
|=
1
<<
pin
;
interrupts
();
}
extern
"C"
void
detachInterrupt
(
pin_size_t
pin
){
noInterrupts
();
if
(
_irqMap
&
(
1
<<
pin
))
{
gpio_set_irq_enabled
(
pin
,
0x0f
/* all */
,
false
);
_irqMap
&=
~
(
1
<<
pin
);
}
interrupts
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment