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
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
Show more breadcrumbs
Jochen
firmware
Commits
9f9fd2a9
Commit
9f9fd2a9
authored
5 years ago
by
schneider
Browse files
Options
Downloads
Plain Diff
Merge branch 'gpio_fix' into 'master'
fix(gpio): fields in gpio_cfg_t are not bit-sets See merge request
!205
parents
44c48cc9
412fc625
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
epicardium/epicardium.h
+9
-9
9 additions, 9 deletions
epicardium/epicardium.h
epicardium/modules/gpio.c
+53
-41
53 additions, 41 deletions
epicardium/modules/gpio.c
pycardium/modules/gpio.c
+14
-12
14 additions, 12 deletions
pycardium/modules/gpio.c
with
76 additions
and
62 deletions
epicardium/epicardium.h
+
9
−
9
View file @
9f9fd2a9
...
@@ -427,26 +427,26 @@ API(API_BUTTONS_READ, uint8_t epic_buttons_read(uint8_t mask));
...
@@ -427,26 +427,26 @@ API(API_BUTTONS_READ, uint8_t epic_buttons_read(uint8_t mask));
/** GPIO pins IDs */
/** GPIO pins IDs */
enum
gpio_pin
{
enum
gpio_pin
{
/** ``1``, Wristband connector 1 */
/** ``1``, Wristband connector 1 */
GPIO_WRISTBAND_1
=
1
,
EPIC_
GPIO_WRISTBAND_1
=
1
,
/** ``2``, Wristband connector 2 */
/** ``2``, Wristband connector 2 */
GPIO_WRISTBAND_2
=
2
,
EPIC_
GPIO_WRISTBAND_2
=
2
,
/** ``3``, Wristband connector 3 */
/** ``3``, Wristband connector 3 */
GPIO_WRISTBAND_3
=
3
,
EPIC_
GPIO_WRISTBAND_3
=
3
,
/** ``4``, Wristband connector 4 */
/** ``4``, Wristband connector 4 */
GPIO_WRISTBAND_4
=
4
,
EPIC_
GPIO_WRISTBAND_4
=
4
,
};
};
/** GPIO pin modes */
/** GPIO pin modes */
enum
gpio_mode
{
enum
gpio_mode
{
/** Configure the pin as input */
/** Configure the pin as input */
GPIO_MODE_IN
=
(
1
<<
0
),
EPIC_
GPIO_MODE_IN
=
(
1
<<
0
),
/** Configure the pin as output */
/** Configure the pin as output */
GPIO_MODE_OUT
=
(
1
<<
1
),
EPIC_
GPIO_MODE_OUT
=
(
1
<<
1
),
/** Enable the internal pull-up resistor */
/** Enable the internal pull-up resistor */
GPIO_PULL_UP
=
(
1
<<
6
),
EPIC_
GPIO_PULL_UP
=
(
1
<<
6
),
/** Enable the internal pull-down resistor */
/** Enable the internal pull-down resistor */
GPIO_PULL_DOWN
=
(
1
<<
7
),
EPIC_
GPIO_PULL_DOWN
=
(
1
<<
7
),
};
};
/**
/**
...
@@ -543,7 +543,7 @@ API(API_GPIO_WRITE_PIN, int epic_gpio_write_pin(uint8_t pin, bool on));
...
@@ -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`.
* :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.
* :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
* LEDs
...
...
This diff is collapsed.
Click to expand it.
epicardium/modules/gpio.c
+
53
−
41
View file @
9f9fd2a9
...
@@ -8,40 +8,52 @@
...
@@ -8,40 +8,52 @@
* pins for wristband GPIO 1-4 (not 0-3 as the schematic states)
* pins for wristband GPIO 1-4 (not 0-3 as the schematic states)
*/
*/
static
gpio_cfg_t
gpio_configs
[]
=
{
static
gpio_cfg_t
gpio_configs
[]
=
{
[
GPIO_WRISTBAND_1
]
=
{
PORT_0
,
PIN_21
,
GPIO_FUNC_OUT
,
GPIO_PAD_NONE
},
[
EPIC_GPIO_WRISTBAND_1
]
=
{
PORT_0
,
[
GPIO_WRISTBAND_2
]
=
{
PORT_0
,
PIN_22
,
GPIO_FUNC_OUT
,
GPIO_PAD_NONE
},
PIN_21
,
[
GPIO_WRISTBAND_3
]
=
{
PORT_0
,
PIN_29
,
GPIO_FUNC_OUT
,
GPIO_PAD_NONE
},
GPIO_FUNC_OUT
,
[
GPIO_WRISTBAND_4
]
=
{
PORT_0
,
PIN_20
,
GPIO_FUNC_OUT
,
GPIO_PAD_NONE
},
GPIO_PAD_NONE
},
[
EPIC_GPIO_WRISTBAND_2
]
=
{
PORT_0
,
PIN_22
,
GPIO_FUNC_OUT
,
GPIO_PAD_NONE
},
[
EPIC_GPIO_WRISTBAND_3
]
=
{
PORT_0
,
PIN_29
,
GPIO_FUNC_OUT
,
GPIO_PAD_NONE
},
[
EPIC_GPIO_WRISTBAND_4
]
=
{
PORT_0
,
PIN_20
,
GPIO_FUNC_OUT
,
GPIO_PAD_NONE
},
};
};
int
epic_gpio_set_pin_mode
(
uint8_t
pin
,
uint8_t
mode
)
int
epic_gpio_set_pin_mode
(
uint8_t
pin
,
uint8_t
mode
)
{
{
if
(
pin
<
GPIO_WRISTBAND_1
||
pin
>
GPIO_WRISTBAND_4
)
if
(
pin
<
EPIC_
GPIO_WRISTBAND_1
||
pin
>
EPIC_
GPIO_WRISTBAND_4
)
return
-
EINVAL
;
return
-
EINVAL
;
gpio_cfg_t
*
cfg
=
&
gpio_configs
[
pin
];
gpio_cfg_t
*
cfg
=
&
gpio_configs
[
pin
];
bool
is_input
=
(
mode
&
GPIO_MODE_IN
)
==
GPIO_MODE_IN
;
if
(
mode
&
EPIC_GPIO_MODE_IN
)
{
bool
is_output
=
(
mode
&
GPIO_MODE_OUT
)
==
GPIO_MODE_OUT
;
cfg
->
func
=
GPIO_FUNC_IN
;
if
(
mode
&
EPIC_GPIO_MODE_OUT
)
{
// Pins can't be input and output at the same time.
if
(
is_input
&&
is_output
)
return
-
EINVAL
;
return
-
EINVAL
;
}
}
else
if
(
mode
&
EPIC_GPIO_MODE_OUT
)
{
cfg
->
func
=
GPIO_FUNC_OUT
;
if
(
mode
&
EPIC_GPIO_MODE_IN
)
{
return
-
EINVAL
;
}
}
else
{
return
-
EINVAL
;
}
uint32_t
func_value
=
0
;
if
(
mode
&
EPIC_GPIO_PULL_UP
)
{
if
(
is_input
)
cfg
->
pad
=
GPIO_PAD_PULL_UP
;
func_value
|=
GPIO_FUNC_IN
;
}
else
if
(
mode
&
EPIC_GPIO_PULL_DOWN
)
{
if
(
is_output
)
cfg
->
pad
=
GPIO_PAD_PULL_DOWN
;
func_value
|=
GPIO_FUNC_OUT
;
}
else
{
cfg
->
pad
=
GPIO_PAD_NONE
;
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
(
GPIO_Config
(
cfg
)
!=
E_NO_ERROR
)
if
(
GPIO_Config
(
cfg
)
!=
E_NO_ERROR
)
return
-
EINVAL
;
return
-
EINVAL
;
...
@@ -50,30 +62,30 @@ int epic_gpio_set_pin_mode(uint8_t pin, uint8_t mode)
...
@@ -50,30 +62,30 @@ int epic_gpio_set_pin_mode(uint8_t pin, uint8_t mode)
int
epic_gpio_get_pin_mode
(
uint8_t
pin
)
int
epic_gpio_get_pin_mode
(
uint8_t
pin
)
{
{
if
(
pin
<
GPIO_WRISTBAND_1
||
pin
>
GPIO_WRISTBAND_4
)
if
(
pin
<
EPIC_
GPIO_WRISTBAND_1
||
pin
>
EPIC_
GPIO_WRISTBAND_4
)
return
-
EINVAL
;
return
-
EINVAL
;
gpio_cfg_t
*
cfg
=
&
gpio_configs
[
pin
];
gpio_cfg_t
*
cfg
=
&
gpio_configs
[
pin
];
int
res
=
0
;
int
res
=
0
;
if
(
(
cfg
->
func
&
GPIO_FUNC_IN
)
==
GPIO_FUNC_IN
)
if
(
cfg
->
func
==
GPIO_FUNC_IN
)
res
|=
GPIO_MODE_IN
;
res
|=
EPIC_
GPIO_MODE_IN
;
if
(
(
cfg
->
func
&
GPIO_FUNC_OUT
)
==
GPIO_FUNC_OUT
)
else
if
(
cfg
->
func
==
GPIO_FUNC_OUT
)
res
|=
GPIO_MODE_OUT
;
res
|=
EPIC_
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
;
res
|=
EPIC_
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
;
res
|=
EPIC_
GPIO_PULL_DOWN
;
return
res
;
return
res
;
}
}
int
epic_gpio_write_pin
(
uint8_t
pin
,
bool
on
)
int
epic_gpio_write_pin
(
uint8_t
pin
,
bool
on
)
{
{
if
(
pin
<
GPIO_WRISTBAND_1
||
pin
>
GPIO_WRISTBAND_4
)
if
(
pin
<
EPIC_
GPIO_WRISTBAND_1
||
pin
>
EPIC_
GPIO_WRISTBAND_4
)
return
-
EINVAL
;
return
-
EINVAL
;
gpio_cfg_t
*
cfg
=
&
gpio_configs
[
pin
];
gpio_cfg_t
*
cfg
=
&
gpio_configs
[
pin
];
if
(
(
cfg
->
func
&
GPIO_FUNC_IN
)
==
GPIO_FUNC_IN
)
if
(
cfg
->
func
==
GPIO_FUNC_IN
)
return
-
EINVAL
;
return
-
EINVAL
;
if
(
on
)
if
(
on
)
...
@@ -84,16 +96,16 @@ int epic_gpio_write_pin(uint8_t pin, bool on)
...
@@ -84,16 +96,16 @@ int epic_gpio_write_pin(uint8_t pin, bool on)
return
0
;
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
)
if
(
pin
<
EPIC_
GPIO_WRISTBAND_1
||
pin
>
EPIC_
GPIO_WRISTBAND_4
)
return
-
EINVAL
;
return
-
EINVAL
;
gpio_cfg_t
*
cfg
=
&
gpio_configs
[
pin
];
gpio_cfg_t
*
cfg
=
&
gpio_configs
[
pin
];
if
(
(
cfg
->
func
&
GPIO_FUNC_OUT
)
==
GPIO_FUNC_OUT
)
{
if
(
cfg
->
func
==
GPIO_FUNC_OUT
)
{
return
GPIO_OutGet
(
cfg
);
return
GPIO_OutGet
(
cfg
)
!=
0
;
}
else
if
(
(
cfg
->
func
&
GPIO_FUNC_IN
)
==
GPIO_FUNC_IN
)
{
}
else
if
(
cfg
->
func
==
GPIO_FUNC_IN
)
{
return
GPIO_InGet
(
cfg
);
return
GPIO_InGet
(
cfg
)
!=
0
;
}
else
{
}
else
{
return
-
EINVAL
;
return
-
EINVAL
;
}
}
...
...
This diff is collapsed.
Click to expand it.
pycardium/modules/gpio.c
+
14
−
12
View file @
9f9fd2a9
...
@@ -29,9 +29,9 @@ static MP_DEFINE_CONST_FUN_OBJ_1(gpio_get_mode, mp_gpio_get_mode);
...
@@ -29,9 +29,9 @@ 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
)
static
mp_obj_t
mp_gpio_read
(
mp_obj_t
pin_obj
)
{
{
int
pin
=
mp_obj_get_int
(
pin_obj
);
int
pin
=
mp_obj_get_int
(
pin_obj
);
u
int
32_t
value
=
epic_gpio_read_pin
(
pin
);
int
value
=
epic_gpio_read_pin
(
pin
);
if
(
value
==
-
EINVAL
)
if
(
value
<
0
)
mp_raise_OSError
(
EINVAL
);
mp_raise_OSError
(
-
value
);
return
MP_OBJ_NEW_SMALL_INT
(
value
);
return
MP_OBJ_NEW_SMALL_INT
(
value
);
};
};
...
@@ -51,11 +51,13 @@ static MP_DEFINE_CONST_FUN_OBJ_2(gpio_write, mp_gpio_write);
...
@@ -51,11 +51,13 @@ static MP_DEFINE_CONST_FUN_OBJ_2(gpio_write, mp_gpio_write);
static
const
mp_rom_map_elem_t
gpio_module_modes_table
[]
=
{
static
const
mp_rom_map_elem_t
gpio_module_modes_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_mode
)
},
{
MP_ROM_QSTR
(
MP_QSTR___name__
),
MP_ROM_QSTR
(
MP_QSTR_mode
)
},
{
MP_ROM_QSTR
(
MP_QSTR_INPUT
),
MP_OBJ_NEW_SMALL_INT
(
GPIO_MODE_IN
)
},
{
MP_ROM_QSTR
(
MP_QSTR_INPUT
),
MP_OBJ_NEW_SMALL_INT
(
EPIC_GPIO_MODE_IN
)
},
{
MP_ROM_QSTR
(
MP_QSTR_OUTPUT
),
MP_OBJ_NEW_SMALL_INT
(
GPIO_MODE_OUT
)
},
{
MP_ROM_QSTR
(
MP_QSTR_OUTPUT
),
{
MP_ROM_QSTR
(
MP_QSTR_PULL_UP
),
MP_OBJ_NEW_SMALL_INT
(
GPIO_PULL_UP
)
},
MP_OBJ_NEW_SMALL_INT
(
EPIC_GPIO_MODE_OUT
)
},
{
MP_ROM_QSTR
(
MP_QSTR_PULL_UP
),
MP_OBJ_NEW_SMALL_INT
(
EPIC_GPIO_PULL_UP
)
},
{
MP_ROM_QSTR
(
MP_QSTR_PULL_DOWN
),
{
MP_ROM_QSTR
(
MP_QSTR_PULL_DOWN
),
MP_OBJ_NEW_SMALL_INT
(
GPIO_PULL_DOWN
)
},
MP_OBJ_NEW_SMALL_INT
(
EPIC_
GPIO_PULL_DOWN
)
},
};
};
static
MP_DEFINE_CONST_DICT
(
gpio_module_modes_dict
,
gpio_module_modes_table
);
static
MP_DEFINE_CONST_DICT
(
gpio_module_modes_dict
,
gpio_module_modes_table
);
...
@@ -72,13 +74,13 @@ static const mp_rom_map_elem_t gpio_module_globals_table[] = {
...
@@ -72,13 +74,13 @@ static const mp_rom_map_elem_t gpio_module_globals_table[] = {
{
MP_ROM_QSTR
(
MP_QSTR_read
),
MP_ROM_PTR
(
&
gpio_read
)
},
{
MP_ROM_QSTR
(
MP_QSTR_read
),
MP_ROM_PTR
(
&
gpio_read
)
},
{
MP_ROM_QSTR
(
MP_QSTR_write
),
MP_ROM_PTR
(
&
gpio_write
)
},
{
MP_ROM_QSTR
(
MP_QSTR_write
),
MP_ROM_PTR
(
&
gpio_write
)
},
{
MP_ROM_QSTR
(
MP_QSTR_WRISTBAND_1
),
{
MP_ROM_QSTR
(
MP_QSTR_WRISTBAND_1
),
MP_OBJ_NEW_SMALL_INT
(
GPIO_WRISTBAND_1
)
},
MP_OBJ_NEW_SMALL_INT
(
EPIC_
GPIO_WRISTBAND_1
)
},
{
MP_ROM_QSTR
(
MP_QSTR_WRISTBAND_2
),
{
MP_ROM_QSTR
(
MP_QSTR_WRISTBAND_2
),
MP_OBJ_NEW_SMALL_INT
(
GPIO_WRISTBAND_2
)
},
MP_OBJ_NEW_SMALL_INT
(
EPIC_
GPIO_WRISTBAND_2
)
},
{
MP_ROM_QSTR
(
MP_QSTR_WRISTBAND_3
),
{
MP_ROM_QSTR
(
MP_QSTR_WRISTBAND_3
),
MP_OBJ_NEW_SMALL_INT
(
GPIO_WRISTBAND_3
)
},
MP_OBJ_NEW_SMALL_INT
(
EPIC_
GPIO_WRISTBAND_3
)
},
{
MP_ROM_QSTR
(
MP_QSTR_WRISTBAND_4
),
{
MP_ROM_QSTR
(
MP_QSTR_WRISTBAND_4
),
MP_OBJ_NEW_SMALL_INT
(
GPIO_WRISTBAND_4
)
},
MP_OBJ_NEW_SMALL_INT
(
EPIC_
GPIO_WRISTBAND_4
)
},
{
MP_ROM_QSTR
(
MP_QSTR_mode
),
MP_ROM_PTR
(
&
gpio_module_modes
)
},
{
MP_ROM_QSTR
(
MP_QSTR_mode
),
MP_ROM_PTR
(
&
gpio_module_modes
)
},
};
};
static
MP_DEFINE_CONST_DICT
(
gpio_module_globals
,
gpio_module_globals_table
);
static
MP_DEFINE_CONST_DICT
(
gpio_module_globals
,
gpio_module_globals_table
);
...
...
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