Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
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
Show more breadcrumbs
card10
firmware
Commits
26db6b6b
Commit
26db6b6b
authored
5 years ago
by
swym
Browse files
Options
Downloads
Patches
Plain Diff
fix(gpio): fields in gpio_cfg_t are not bit-sets
parent
67b113ce
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!205
fix(gpio): fields in gpio_cfg_t are not bit-sets
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
epicardium/epicardium.h
+1
-1
1 addition, 1 deletion
epicardium/epicardium.h
epicardium/modules/gpio.c
+29
-29
29 additions, 29 deletions
epicardium/modules/gpio.c
pycardium/modules/gpio.c
+4
-4
4 additions, 4 deletions
pycardium/modules/gpio.c
with
34 additions
and
34 deletions
epicardium/epicardium.h
+
1
−
1
View file @
26db6b6b
...
...
@@ -543,7 +543,7 @@ API(API_GPIO_WRITE_PIN, int epic_gpio_write_pin(uint8_t pin, bool on));
* :param uint8_t pin: ID of the pin to get the configuration of. Use on of the IDs defined in :c:type:`gpio_pin`.
* :returns: ``-EINVAL`` if ``pin`` is not valid, an integer value otherwise.
*/
API
(
API_GPIO_READ_PIN
,
u
int
32_t
epic_gpio_read_pin
(
uint8_t
pin
));
API
(
API_GPIO_READ_PIN
,
int
epic_gpio_read_pin
(
uint8_t
pin
));
/**
* LEDs
...
...
This diff is collapsed.
Click to expand it.
epicardium/modules/gpio.c
+
29
−
29
View file @
26db6b6b
...
...
@@ -21,27 +21,27 @@ int epic_gpio_set_pin_mode(uint8_t pin, uint8_t mode)
gpio_cfg_t
*
cfg
=
&
gpio_configs
[
pin
];
bool
is_input
=
(
mode
&
GPIO_MODE_IN
)
==
GPIO_MODE_IN
;
bool
is_output
=
(
mode
&
GPIO_MODE_OUT
)
==
GPIO_MODE_OUT
;
// Pins can't be input and output at the same time.
if
(
is_input
&&
is_output
)
if
(
mode
&
GPIO_MODE_IN
)
{
cfg
->
func
=
GPIO_FUNC_IN
;
if
(
mode
&
GPIO_MODE_OUT
)
{
return
-
EINVAL
;
}
}
else
if
(
mode
&
GPIO_MODE_OUT
)
{
cfg
->
func
=
GPIO_FUNC_OUT
;
if
(
mode
&
GPIO_MODE_IN
)
{
return
-
EINVAL
;
}
}
else
{
return
-
EINVAL
;
}
uint32_t
func_value
=
0
;
if
(
is_input
)
func_value
|=
GPIO_FUNC_IN
;
if
(
is_output
)
func_value
|=
GPIO_FUNC_OUT
;
uint32_t
pad_value
=
0
;
if
(
mode
&
GPIO_PULL_UP
)
pad_value
|=
GPIO_PAD_PULL_UP
;
if
(
mode
&
GPIO_PULL_DOWN
)
pad_value
|=
GPIO_PAD_PULL_DOWN
;
cfg
->
func
=
func_value
;
cfg
->
pad
=
pad_value
;
if
(
mode
&
GPIO_PULL_UP
)
{
cfg
->
pad
=
GPIO_PAD_PULL_UP
;
}
else
if
(
mode
&
GPIO_PULL_DOWN
)
{
cfg
->
pad
=
GPIO_PAD_PULL_DOWN
;
}
else
{
cfg
->
pad
=
GPIO_PAD_NONE
;
}
if
(
GPIO_Config
(
cfg
)
!=
E_NO_ERROR
)
return
-
EINVAL
;
...
...
@@ -55,13 +55,13 @@ int epic_gpio_get_pin_mode(uint8_t pin)
gpio_cfg_t
*
cfg
=
&
gpio_configs
[
pin
];
int
res
=
0
;
if
(
(
cfg
->
func
&
GPIO_FUNC_IN
)
==
GPIO_FUNC_IN
)
if
(
cfg
->
func
==
GPIO_FUNC_IN
)
res
|=
GPIO_MODE_IN
;
if
(
(
cfg
->
func
&
GPIO_FUNC_OUT
)
==
GPIO_FUNC_OUT
)
else
if
(
cfg
->
func
==
GPIO_FUNC_OUT
)
res
|=
GPIO_MODE_OUT
;
if
(
(
cfg
->
pad
&
GPIO_PAD_PULL_UP
)
==
GPIO_PAD_PULL_UP
)
if
(
cfg
->
pad
==
GPIO_PAD_PULL_UP
)
res
|=
GPIO_PULL_UP
;
if
(
(
cfg
->
pad
&
GPIO_PAD_PULL_DOWN
)
==
GPIO_PAD_PULL_DOWN
)
else
if
(
cfg
->
pad
==
GPIO_PAD_PULL_DOWN
)
res
|=
GPIO_PULL_DOWN
;
return
res
;
...
...
@@ -73,7 +73,7 @@ int epic_gpio_write_pin(uint8_t pin, bool on)
return
-
EINVAL
;
gpio_cfg_t
*
cfg
=
&
gpio_configs
[
pin
];
if
(
(
cfg
->
func
&
GPIO_FUNC_IN
)
==
GPIO_FUNC_IN
)
if
(
cfg
->
func
==
GPIO_FUNC_IN
)
return
-
EINVAL
;
if
(
on
)
...
...
@@ -84,16 +84,16 @@ int epic_gpio_write_pin(uint8_t pin, bool on)
return
0
;
}
u
int
32_t
epic_gpio_read_pin
(
uint8_t
pin
)
int
epic_gpio_read_pin
(
uint8_t
pin
)
{
if
(
pin
<
GPIO_WRISTBAND_1
||
pin
>
GPIO_WRISTBAND_4
)
return
-
EINVAL
;
gpio_cfg_t
*
cfg
=
&
gpio_configs
[
pin
];
if
(
(
cfg
->
func
&
GPIO_FUNC_OUT
)
==
GPIO_FUNC_OUT
)
{
return
GPIO_OutGet
(
cfg
);
}
else
if
(
(
cfg
->
func
&
GPIO_FUNC_IN
)
==
GPIO_FUNC_IN
)
{
return
GPIO_InGet
(
cfg
);
if
(
cfg
->
func
==
GPIO_FUNC_OUT
)
{
return
GPIO_OutGet
(
cfg
)
!=
0
;
}
else
if
(
cfg
->
func
==
GPIO_FUNC_IN
)
{
return
GPIO_InGet
(
cfg
)
!=
0
;
}
else
{
return
-
EINVAL
;
}
...
...
This diff is collapsed.
Click to expand it.
pycardium/modules/gpio.c
+
4
−
4
View file @
26db6b6b
...
...
@@ -28,10 +28,10 @@ static MP_DEFINE_CONST_FUN_OBJ_1(gpio_get_mode, mp_gpio_get_mode);
static
mp_obj_t
mp_gpio_read
(
mp_obj_t
pin_obj
)
{
int
pin
=
mp_obj_get_int
(
pin_obj
);
u
int
32_t
value
=
epic_gpio_read_pin
(
pin
);
if
(
value
==
-
EINVAL
)
mp_raise_OSError
(
EINVAL
);
int
pin
=
mp_obj_get_int
(
pin_obj
);
int
value
=
epic_gpio_read_pin
(
pin
);
if
(
value
<
0
)
mp_raise_OSError
(
-
value
);
return
MP_OBJ_NEW_SMALL_INT
(
value
);
};
...
...
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