Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
1d8a0640
Commit
1d8a0640
authored
10 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
examples: Added pins.py example script to list pin config/af.
Script is due to Dave Hylands.
parent
2c4e67e3
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/pins.py
+58
-0
58 additions, 0 deletions
examples/pins.py
with
58 additions
and
0 deletions
examples/pins.py
0 → 100644
+
58
−
0
View file @
1d8a0640
# Print a nice list of pins, their current settings, and available afs.
# Requires pins_af.py from stmhal/build-PYBV10/ directory.
import
pyb
import
pins_af
def
af
():
max_name_width
=
0
max_af_width
=
0
for
pin_entry
in
pins_af
.
PINS_AF
:
max_name_width
=
max
(
max_name_width
,
len
(
pin_entry
[
0
]))
for
af_entry
in
pin_entry
[
1
:]:
max_af_width
=
max
(
max_af_width
,
len
(
af_entry
[
1
]))
for
pin_entry
in
pins_af
.
PINS_AF
:
pin_name
=
pin_entry
[
0
]
print
(
'
%-*s
'
%
(
max_name_width
,
pin_name
),
end
=
''
)
for
af_entry
in
pin_entry
[
1
:]:
print
(
'
%2d: %-*s
'
%
(
af_entry
[
0
],
max_af_width
,
af_entry
[
1
]),
end
=
''
)
print
(
''
)
def
pins
():
mode_str
=
{
pyb
.
Pin
.
IN
:
'
IN
'
,
pyb
.
Pin
.
OUT_PP
:
'
OUT_PP
'
,
pyb
.
Pin
.
OUT_OD
:
'
OUT_OD
'
,
pyb
.
Pin
.
AF_PP
:
'
AF_PP
'
,
pyb
.
Pin
.
AF_OD
:
'
AF_OD
'
,
pyb
.
Pin
.
ANALOG
:
'
ANALOG
'
}
pull_str
=
{
pyb
.
Pin
.
PULL_NONE
:
''
,
pyb
.
Pin
.
PULL_UP
:
'
PULL_UP
'
,
pyb
.
Pin
.
PULL_DOWN
:
'
PULL_DOWN
'
}
width
=
[
0
,
0
,
0
,
0
]
rows
=
[]
for
pin_entry
in
pins_af
.
PINS_AF
:
row
=
[]
pin_name
=
pin_entry
[
0
]
pin
=
pyb
.
Pin
(
pin_name
)
pin_mode
=
pin
.
mode
()
row
.
append
(
pin_name
)
row
.
append
(
mode_str
[
pin_mode
])
row
.
append
(
pull_str
[
pin
.
pull
()])
if
pin_mode
==
pyb
.
Pin
.
AF_PP
or
pin_mode
==
pyb
.
Pin
.
AF_OD
:
pin_af
=
pin
.
af
()
for
af_entry
in
pin_entry
[
1
:]:
if
pin_af
==
af_entry
[
0
]:
af_str
=
'
%d: %s
'
%
(
pin_af
,
af_entry
[
1
])
break
else
:
af_str
=
'
%d
'
%
pin_af
else
:
af_str
=
''
row
.
append
(
af_str
)
for
col
in
range
(
len
(
width
)):
width
[
col
]
=
max
(
width
[
col
],
len
(
row
[
col
]))
rows
.
append
(
row
)
for
row
in
rows
:
for
col
in
range
(
len
(
width
)):
print
(
'
%-*s
'
%
(
width
[
col
],
row
[
col
]),
end
=
''
)
print
(
''
)
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