Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
10e173aa
Commit
10e173aa
authored
5 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
stm32/extint: Add extint_set() function for internal C access to EXTI.
parent
345e9864
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ports/stm32/extint.c
+50
-0
50 additions, 0 deletions
ports/stm32/extint.c
with
50 additions
and
0 deletions
ports/stm32/extint.c
+
50
−
0
View file @
10e173aa
...
...
@@ -297,6 +297,53 @@ void extint_register_pin(const pin_obj_t *pin, uint32_t mode, bool hard_irq, mp_
}
}
void
extint_set
(
const
pin_obj_t
*
pin
,
uint32_t
mode
)
{
uint32_t
line
=
pin
->
pin
;
mp_obj_t
*
cb
=
&
MP_STATE_PORT
(
pyb_extint_callback
)[
line
];
extint_disable
(
line
);
*
cb
=
MP_OBJ_SENTINEL
;
pyb_extint_mode
[
line
]
=
(
mode
&
0x00010000
)
?
// GPIO_MODE_IT == 0x00010000
EXTI_Mode_Interrupt
:
EXTI_Mode_Event
;
{
// Configure and enable the callback
pyb_extint_hard_irq
[
line
]
=
1
;
pyb_extint_callback_arg
[
line
]
=
MP_OBJ_FROM_PTR
(
pin
);
// Route the GPIO to EXTI
__HAL_RCC_SYSCFG_CLK_ENABLE
();
SYSCFG
->
EXTICR
[
line
>>
2
]
=
(
SYSCFG
->
EXTICR
[
line
>>
2
]
&
~
(
0x0f
<<
(
4
*
(
line
&
0x03
))))
|
((
uint32_t
)(
GPIO_GET_INDEX
(
pin
->
gpio
))
<<
(
4
*
(
line
&
0x03
)));
// Enable or disable the rising detector
if
((
mode
&
GPIO_MODE_IT_RISING
)
==
GPIO_MODE_IT_RISING
)
{
EXTI_RTSR
|=
1
<<
line
;
}
else
{
EXTI_RTSR
&=
~
(
1
<<
line
);
}
// Enable or disable the falling detector
if
((
mode
&
GPIO_MODE_IT_FALLING
)
==
GPIO_MODE_IT_FALLING
)
{
EXTI_FTSR
|=
1
<<
line
;
}
else
{
EXTI_FTSR
&=
~
(
1
<<
line
);
}
// Configure the NVIC
NVIC_SetPriority
(
IRQn_NONNEG
(
nvic_irq_channel
[
line
]),
IRQ_PRI_EXTINT
);
HAL_NVIC_EnableIRQ
(
nvic_irq_channel
[
line
]);
// Enable the interrupt
extint_enable
(
line
);
}
}
void
extint_enable
(
uint
line
)
{
if
(
line
>=
EXTI_NUM_VECTORS
)
{
return
;
...
...
@@ -552,6 +599,9 @@ const mp_obj_type_t extint_type = {
void
extint_init0
(
void
)
{
for
(
int
i
=
0
;
i
<
PYB_EXTI_NUM_VECTORS
;
i
++
)
{
if
(
MP_STATE_PORT
(
pyb_extint_callback
)[
i
]
==
MP_OBJ_SENTINEL
)
{
continue
;
}
MP_STATE_PORT
(
pyb_extint_callback
)[
i
]
=
mp_const_none
;
pyb_extint_mode
[
i
]
=
EXTI_Mode_Interrupt
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment