Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Open-Cube FW
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
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
Open Cube
Open-Cube FW
Commits
b18a6e69
Commit
b18a6e69
authored
2 weeks ago
by
Václav Jelínek
Browse files
Options
Downloads
Patches
Plain Diff
Add function to trigger all I2C slaves
parent
e976f1d9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/cube/i2c_master.py
+29
-4
29 additions, 4 deletions
lib/cube/i2c_master.py
menu_programs/i2c_master.py
+3
-1
3 additions, 1 deletion
menu_programs/i2c_master.py
with
32 additions
and
5 deletions
lib/cube/i2c_master.py
+
29
−
4
View file @
b18a6e69
...
...
@@ -7,7 +7,7 @@ from lib.hw_defs.pins import UTZ_I2C_SDA_PIN, UTZ_I2C_SCK_PIN, I2C_STRONG_PULL_R
from
lib.robot_consts
import
I2C_MULTICUBE_FREQ
,
I2C_NXT_UTZ_BUS
I2C_TIME_TRIGGER_REG
=
const
(
256
-
4
)
I2C_TIME_TRIGGER_WRITE_TIME
=
const
(
900
)
# us
class
I2C_master
:
def
__init__
(
self
,
pcf_buttons
):
self
.
pcf_buttons
=
pcf_buttons
...
...
@@ -38,11 +38,11 @@ class I2C_master:
except
Exception
as
e
:
return
False
return
True
def
trigger
(
self
,
add
,
time_us
,
callback
=
None
):
def
trigger
(
self
,
time_us
,
address
,
callback
=
None
):
try
:
time_start
=
time
.
ticks_us
()
self
.
i2c
.
writeto_mem
(
add
,
I2C_TIME_TRIGGER_REG
,
time_us
.
to_bytes
(
4
,
'
little
'
))
self
.
i2c
.
writeto_mem
(
add
ress
,
I2C_TIME_TRIGGER_REG
,
time_us
.
to_bytes
(
4
,
'
little
'
))
time_diff
=
time_us
-
time
.
ticks_diff
(
time
.
ticks_us
(),
time_start
)
print
(
"
Time diff:
"
,
time_diff
)
if
callback
:
...
...
@@ -55,6 +55,31 @@ class I2C_master:
return
False
return
True
def
trigger_all
(
self
,
time_us
,
addresses
=
None
,
callback
=
None
):
try
:
time_start
=
time
.
ticks_us
()
if
not
addresses
:
addresses
=
self
.
i2c
.
scan
()
time_scan
=
time_start
-
time
.
ticks_us
()
time_reserve
=
time_scan
-
len
(
addresses
)
*
I2C_TIME_TRIGGER_WRITE_TIME
if
time_reserve
<
0
:
return
False
time_next
=
time_scan
for
i
in
range
(
len
(
addresses
)):
time_slave
=
time
.
ticks_us
()
self
.
i2c
.
writeto_mem
(
addresses
[
0
],
I2C_TIME_TRIGGER_REG
,
time_next
.
to_bytes
(
4
,
'
little
'
))
time_next
=
time_next
-
time
.
ticks_diff
(
time
.
ticks_us
(),
time_slave
)
print
(
"
Time diff:
"
,
time_next
)
if
callback
:
if
time_next
>
0
:
self
.
trigger_timer
.
init
(
freq
=
1000000
/
time_next
,
mode
=
Timer
.
ONE_SHOT
,
callback
=
callback
)
else
:
callback
(
None
)
except
Exception
as
e
:
return
False
return
True
def
deinit
(
self
):
self
.
trigger_timer
.
deinit
()
self
.
i2c
=
None
...
...
This diff is collapsed.
Click to expand it.
menu_programs/i2c_master.py
+
3
−
1
View file @
b18a6e69
...
...
@@ -80,7 +80,9 @@ def i2c_master_run(robot):
data_sending
=
data_sending
%
26
debounce
=
True
if
buttons
[
Button
.
OK
]:
robot
.
i2c_master
.
trigger
(
slave_add
,
SLAVE_TRIGGER_TIME
,
callback
=
master_trigger_callback
)
trigger
=
robot
.
i2c_master
.
trigger_all
(
SLAVE_TRIGGER_TIME
,
adressed
=
all_add
,
callback
=
master_trigger_callback
)
if
not
trigger
:
break
debounce
=
True
if
buttons
[
Button
.
RIGHT
]:
#robot.buttons.set_pin(I2C_STRONG_PULL_RPIN_BIT, True)
...
...
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