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
84880c1f
Commit
84880c1f
authored
9 years ago
by
Hauke Petersen
Browse files
Options
Downloads
Patches
Plain Diff
cpu/stm32f0: adapted GPIO driver
parent
363eb58c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cpu/stm32f0/include/periph_cpu.h
+25
-0
25 additions, 0 deletions
cpu/stm32f0/include/periph_cpu.h
cpu/stm32f0/periph/gpio.c
+18
-17
18 additions, 17 deletions
cpu/stm32f0/periph/gpio.c
with
43 additions
and
17 deletions
cpu/stm32f0/include/periph_cpu.h
+
25
−
0
View file @
84880c1f
...
@@ -44,6 +44,31 @@ typedef uint32_t gpio_t;
...
@@ -44,6 +44,31 @@ typedef uint32_t gpio_t;
*/
*/
#define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y)
#define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y)
/**
* @brief Generate GPIO mode bitfields
*
* We use 5 bit to encode the mode:
* - bit 0+1: pin mode (input / output)
* - bit 2+3: pull resistor configuration
* - bit 4: output type (0: push-pull, 1: open-drain)
*/
#define GPIO_MODE(io, pr, ot) ((io << 0) | (pr << 2) | (ot << 4))
/**
* @brief Override GPIO mode options
* @{
*/
#define HAVE_GPIO_MODE_T
typedef
enum
{
GPIO_IN
=
GPIO_MODE
(
0
,
0
,
0
),
/**< input w/o pull R */
GPIO_IN_PD
=
GPIO_MODE
(
0
,
2
,
0
),
/**< input with pull-down */
GPIO_IN_PU
=
GPIO_MODE
(
0
,
1
,
0
),
/**< input with pull-up */
GPIO_OUT
=
GPIO_MODE
(
1
,
0
,
0
),
/**< push-pull output */
GPIO_OD
=
GPIO_MODE
(
1
,
0
,
1
),
/**< open-drain w/o pull R */
GPIO_OD_PU
=
GPIO_MODE
(
1
,
1
,
1
)
/**< open-drain with pull-up */
}
gpio_mode_t
;
/** @} */
/**
/**
* @brief Override flank configuration values
* @brief Override flank configuration values
* @{
* @{
...
...
This diff is collapsed.
Click to expand it.
cpu/stm32f0/periph/gpio.c
+
18
−
17
View file @
84880c1f
...
@@ -61,31 +61,32 @@ static inline int _pin_num(gpio_t pin)
...
@@ -61,31 +61,32 @@ static inline int _pin_num(gpio_t pin)
return
(
pin
&
0x0f
);
return
(
pin
&
0x0f
);
}
}
int
gpio_init
(
gpio_t
pin
,
gpio_
dir_t
dir
,
gpio_pp_t
pullup
)
int
gpio_init
(
gpio_t
pin
,
gpio_
mode_t
mode
)
{
{
GPIO_TypeDef
*
port
=
_port
(
pin
);
GPIO_TypeDef
*
port
=
_port
(
pin
);
int
pin_num
=
_pin_num
(
pin
);
int
pin_num
=
_pin_num
(
pin
);
/* enable clock */
/* enable clock */
RCC
->
AHBENR
|=
(
RCC_AHBENR_GPIOAEN
<<
_port_num
(
pin
));
RCC
->
AHBENR
|=
(
RCC_AHBENR_GPIOAEN
<<
_port_num
(
pin
));
/* configure pull register */
port
->
PUPDR
&=
~
(
3
<<
(
2
*
pin_num
));
/* set mode */
port
->
PUPD
R
|
=
(
pullup
<<
(
2
*
pin_num
));
port
->
MODE
R
&
=
~
(
0x3
<<
(
2
*
pin_num
));
/* set direction */
port
->
MODER
|=
((
mode
&
0x3
)
<<
(
2
*
pin_num
));
if
(
dir
==
GPIO_DIR_OUT
)
{
/* set pull resistor configuration */
port
->
MODE
R
&=
~
(
3
<<
(
2
*
pin_num
));
/* set pin to output mode */
port
->
PUPD
R
&=
~
(
0x
3
<<
(
2
*
pin_num
));
port
->
MODE
R
|=
(
1
<<
(
2
*
pin_num
));
port
->
PUPD
R
|=
(((
mode
>>
2
)
&
0x3
)
<<
(
2
*
pin_num
));
port
->
OTYPER
&=
~
(
1
<<
pin_num
);
/* set to push-pull
*/
/* set output mode
*/
port
->
O
SPEED
R
|
=
(
3
<<
(
2
*
pin_num
)
);
/* set to high speed */
port
->
O
TYPE
R
&
=
~
(
1
<<
pin_num
)
;
port
->
O
D
R
&
=
~
(
1
<<
pin_num
);
/* set pin to low signal */
port
->
O
TYPE
R
|
=
(((
mode
>>
4
)
&
0x1
)
<<
pin_num
);
}
/* finally set pin speed to maximum and reset output */
else
{
port
->
OSPEEDR
|=
(
3
<<
(
2
*
pin_num
));
port
->
MODE
R
&
=
~
(
3
<<
(
2
*
pin_num
)
)
;
/* configure pin as input */
port
->
BR
R
=
(
1
<<
pin_num
);
}
return
0
;
return
0
;
}
}
int
gpio_init_int
(
gpio_t
pin
,
gpio_pp_t
pullup
,
gpio_flank_t
flank
,
gpio_cb_t
cb
,
void
*
arg
)
int
gpio_init_int
(
gpio_t
pin
,
gpio_mode_t
mode
,
gpio_flank_t
flank
,
gpio_cb_t
cb
,
void
*
arg
)
{
{
int
pin_num
=
_pin_num
(
pin
);
int
pin_num
=
_pin_num
(
pin
);
int
port_num
=
_port_num
(
pin
);
int
port_num
=
_port_num
(
pin
);
...
@@ -98,7 +99,7 @@ int gpio_init_int(gpio_t pin, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb
...
@@ -98,7 +99,7 @@ int gpio_init_int(gpio_t pin, gpio_pp_t pullup, gpio_flank_t flank, gpio_cb_t cb
RCC
->
APB2ENR
|=
RCC_APB2ENR_SYSCFGCOMPEN
;
RCC
->
APB2ENR
|=
RCC_APB2ENR_SYSCFGCOMPEN
;
/* initialize pin as input */
/* initialize pin as input */
gpio_init
(
pin
,
GPIO_DIR_IN
,
pullup
);
gpio_init
(
pin
,
mode
);
/* enable global pin interrupt */
/* enable global pin interrupt */
if
(
pin_num
<
2
)
{
if
(
pin_num
<
2
)
{
...
...
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