Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
cf43df4c
Commit
cf43df4c
authored
Mar 04, 2023
by
robert-hh
Committed by
Damien George
Mar 10, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nrf/modules/machine/pwm: Add paramter checks and error messages.
parent
b336b6bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
ports/nrf/modules/machine/pwm.c
ports/nrf/modules/machine/pwm.c
+6
-4
No files found.
ports/nrf/modules/machine/pwm.c
View file @
cf43df4c
...
...
@@ -97,7 +97,6 @@ STATIC int hard_pwm_find(mp_obj_t id) {
if
(
pwm_id
>=
0
&&
pwm_id
<
MP_ARRAY_SIZE
(
machine_hard_pwm_obj
))
{
return
pwm_id
;
}
mp_raise_ValueError
(
MP_ERROR_TEXT
(
"PWM doesn't exist"
));
}
return
-
1
;
}
...
...
@@ -231,19 +230,22 @@ STATIC mp_obj_t machine_hard_pwm_make_new(mp_arg_val_t *args) {
enum
{
ARG_id
,
ARG_pin
,
ARG_freq
,
ARG_period
,
ARG_duty
,
ARG_pulse_width
,
ARG_mode
};
// get static peripheral object
int
pwm_id
=
hard_pwm_find
(
args
[
ARG_id
].
u_obj
);
if
(
pwm_id
<
0
)
{
mp_raise_ValueError
(
MP_ERROR_TEXT
(
"invalid or missing PWM id"
));
}
const
machine_hard_pwm_obj_t
*
self
=
&
machine_hard_pwm_obj
[
pwm_id
];
// check if PWM pin is set
if
(
args
[
ARG_pin
].
u_obj
!=
MP_OBJ_NULL
)
{
self
->
p_config
->
pwm_pin
=
mp_hal_get_pin_obj
(
args
[
ARG_pin
].
u_obj
)
->
pin
;
}
else
{
// TODO: raise exception.
mp_raise_ValueError
(
MP_ERROR_TEXT
(
"Pin missing"
));
}
if
(
args
[
ARG_freq
].
u_obj
!=
MP_OBJ_NULL
)
{
self
->
p_config
->
freq
=
mp_obj_get_int
(
args
[
ARG_freq
].
u_obj
);
}
else
{
self
->
p_config
->
freq
=
50
;
// 50
Hz by default.
self
->
p_config
->
freq
=
2
;
// 4 M
Hz by default.
}
if
(
args
[
ARG_period
].
u_obj
!=
MP_OBJ_NULL
)
{
...
...
@@ -294,7 +296,7 @@ STATIC void machine_hard_pwm_init(mp_obj_t self_in, mp_arg_val_t *args) {
uint16_t
pulse_width
=
((
self
->
p_config
->
period
*
self
->
p_config
->
duty
)
/
100
);
// If manual p
eriod
has been set, override duty-cycle.
// If manual p
ulse width
has been set, override duty-cycle.
if
(
self
->
p_config
->
pulse_width
>
0
)
{
pulse_width
=
self
->
p_config
->
pulse_width
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment