Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
86b4a414
Unverified
Commit
86b4a414
authored
6 years ago
by
Hauke Petersen
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #10158 from silkeh/fix-nrf5x-gpio
nrf5x_common: gpio: fix port 1 functionality
parents
266f7ee3
58e39da2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cpu/nrf5x_common/periph/gpio.c
+25
-12
25 additions, 12 deletions
cpu/nrf5x_common/periph/gpio.c
with
25 additions
and
12 deletions
cpu/nrf5x_common/periph/gpio.c
+
25
−
12
View file @
86b4a414
...
@@ -44,7 +44,7 @@ static gpio_isr_ctx_t exti_chan;
...
@@ -44,7 +44,7 @@ static gpio_isr_ctx_t exti_chan;
/**
/**
* @brief Get the port's base address
* @brief Get the port's base address
*/
*/
static
inline
NRF_GPIO_Type
*
port
(
gpio_t
pin
)
static
inline
NRF_GPIO_Type
*
port
(
gpio_t
pin
)
{
{
#if (CPU_FAM_NRF51)
#if (CPU_FAM_NRF51)
(
void
)
pin
;
(
void
)
pin
;
...
@@ -57,6 +57,18 @@ static inline NRF_GPIO_Type* port(gpio_t pin)
...
@@ -57,6 +57,18 @@ static inline NRF_GPIO_Type* port(gpio_t pin)
#endif
#endif
}
}
/**
* @brief Get a pin's offset
*/
static
inline
int
pin_num
(
gpio_t
pin
)
{
#ifdef CPU_MODEL_NRF52840XXAA
return
(
pin
&
PIN_MASK
);
#else
return
(
int
)
pin
;
#endif
}
int
gpio_init
(
gpio_t
pin
,
gpio_mode_t
mode
)
int
gpio_init
(
gpio_t
pin
,
gpio_mode_t
mode
)
{
{
switch
(
mode
)
{
switch
(
mode
)
{
...
@@ -65,7 +77,7 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
...
@@ -65,7 +77,7 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
case
GPIO_IN_PU
:
case
GPIO_IN_PU
:
case
GPIO_OUT
:
case
GPIO_OUT
:
/* configure pin direction, input buffer and pull resistor state */
/* configure pin direction, input buffer and pull resistor state */
port
(
pin
)
->
PIN_CNF
[
pin
]
=
mode
;
port
(
pin
)
->
PIN_CNF
[
pin
_num
(
pin
)
]
=
mode
;
break
;
break
;
default:
default:
return
-
1
;
return
-
1
;
...
@@ -76,35 +88,36 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
...
@@ -76,35 +88,36 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
int
gpio_read
(
gpio_t
pin
)
int
gpio_read
(
gpio_t
pin
)
{
{
if
(
port
(
pin
)
->
DIR
&
(
1
<<
pin
))
{
if
(
port
(
pin
)
->
DIR
&
(
1
<<
pin
_num
(
pin
)
))
{
return
(
port
(
pin
)
->
OUT
&
(
1
<<
pin
))
?
1
:
0
;
return
(
port
(
pin
)
->
OUT
&
(
1
<<
pin
_num
(
pin
)
))
?
1
:
0
;
}
}
else
{
else
{
return
(
port
(
pin
)
->
IN
&
(
1
<<
pin
))
?
1
:
0
;
return
(
port
(
pin
)
->
IN
&
(
1
<<
pin
_num
(
pin
)
))
?
1
:
0
;
}
}
}
}
void
gpio_set
(
gpio_t
pin
)
void
gpio_set
(
gpio_t
pin
)
{
{
port
(
pin
)
->
OUTSET
=
(
1
<<
pin
);
port
(
pin
)
->
OUTSET
=
(
1
<<
pin
_num
(
pin
)
);
}
}
void
gpio_clear
(
gpio_t
pin
)
void
gpio_clear
(
gpio_t
pin
)
{
{
port
(
pin
)
->
OUTCLR
=
(
1
<<
pin
);
port
(
pin
)
->
OUTCLR
=
(
1
<<
pin
_num
(
pin
)
);
}
}
void
gpio_toggle
(
gpio_t
pin
)
void
gpio_toggle
(
gpio_t
pin
)
{
{
port
(
pin
)
->
OUT
^=
(
1
<<
pin
);
port
(
pin
)
->
OUT
^=
(
1
<<
pin
_num
(
pin
)
);
}
}
void
gpio_write
(
gpio_t
pin
,
int
value
)
void
gpio_write
(
gpio_t
pin
,
int
value
)
{
{
if
(
value
)
{
if
(
value
)
{
port
(
pin
)
->
OUTSET
=
(
1
<<
pin
);
port
(
pin
)
->
OUTSET
=
(
1
<<
pin_num
(
pin
));
}
else
{
}
port
(
pin
)
->
OUTCLR
=
(
1
<<
pin
);
else
{
port
(
pin
)
->
OUTCLR
=
(
1
<<
pin_num
(
pin
));
}
}
}
}
...
@@ -123,7 +136,7 @@ int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
...
@@ -123,7 +136,7 @@ int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank,
NVIC_EnableIRQ
(
GPIOTE_IRQn
);
NVIC_EnableIRQ
(
GPIOTE_IRQn
);
/* configure the GPIOTE channel: set even mode, pin and active flank */
/* configure the GPIOTE channel: set even mode, pin and active flank */
NRF_GPIOTE
->
CONFIG
[
0
]
=
(
GPIOTE_CONFIG_MODE_Event
|
NRF_GPIOTE
->
CONFIG
[
0
]
=
(
GPIOTE_CONFIG_MODE_Event
|
(
pin
<<
GPIOTE_CONFIG_PSEL_Pos
)
|
(
pin
_num
(
pin
)
<<
GPIOTE_CONFIG_PSEL_Pos
)
|
#ifdef CPU_MODEL_NRF52840XXAA
#ifdef CPU_MODEL_NRF52840XXAA
((
pin
&
PORT_BIT
)
<<
8
)
|
((
pin
&
PORT_BIT
)
<<
8
)
|
#endif
#endif
...
...
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