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
f10daa00
Commit
f10daa00
authored
2 weeks ago
by
Václav Jelínek
Browse files
Options
Downloads
Patches
Plain Diff
Change i2c slave irq logic, add irq handler to i2c slave menu program
parent
e7d83d76
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#124395
canceled
2 weeks ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
menu_programs/i2c_slave.py
+5
-1
5 additions, 1 deletion
menu_programs/i2c_slave.py
micropython/modules/opencube_brick/oc_i2c_slave.c
+7
-3
7 additions, 3 deletions
micropython/modules/opencube_brick/oc_i2c_slave.c
with
12 additions
and
4 deletions
menu_programs/i2c_slave.py
+
5
−
1
View file @
f10daa00
...
...
@@ -7,9 +7,13 @@ ASCII_a = 97
ADDRESS
=
0x44
def
i2c_slave_run
(
robot
):
def
i2c_slave_irq
(
i2c_slave
):
print
(
i2c_slave
)
print
(
robot
.
i2c_slave
.
read
(
1
))
robot
.
init_i2c_slave
(
ADDRESS
)
robot
.
i2c_slave
.
irq
(
i2c_slave_irq
,
robot
.
i2c_slave
.
READ
|
robot
.
i2c_slave
.
RECEIVED
,
False
)
data_received
=
None
data_show
=
0x5F
data_sending
=
0
...
...
This diff is collapsed.
Click to expand it.
micropython/modules/opencube_brick/oc_i2c_slave.c
+
7
−
3
View file @
f10daa00
...
...
@@ -30,6 +30,7 @@ typedef struct _oc_i2c_slave_obj_t {
oc_i2c_slave_memory
context
;
uint16_t
mp_irq_trigger
;
// user IRQ trigger mask
uint16_t
mp_irq_flags
;
// user IRQ active IRQ flags
uint16_t
mp_irq_flags_unfinished
;
// future IRQ flags
mp_irq_obj_t
*
mp_irq_obj
;
// user IRQ object
}
oc_i2c_slave_obj_t
;
...
...
@@ -42,6 +43,7 @@ static oc_i2c_slave_obj_t oc_i2c_slave_obj = {
{{
0
}},
0
,
0
,
0
,
NULL
};
...
...
@@ -70,7 +72,7 @@ static void oc_i2c_slave_handler(i2c_inst_t *i2c, i2c_slave_event_t event) {
// save into memory
oc_i2c_slave_obj
.
context
.
mem
[
oc_i2c_slave_obj
.
context
.
mem_address
]
=
i2c_read_byte_raw
(
i2c
);
oc_i2c_slave_obj
.
context
.
mem_address
++
;
oc_i2c_slave_obj
.
mp_irq_flags
=
OC_I2C_SLAVE_RECEIVE
;
oc_i2c_slave_obj
.
mp_irq_flags
_unfinished
|
=
OC_I2C_SLAVE_RECEIVE
;
}
break
;
...
...
@@ -78,14 +80,16 @@ static void oc_i2c_slave_handler(i2c_inst_t *i2c, i2c_slave_event_t event) {
// load from memory
i2c_write_byte_raw
(
i2c
,
oc_i2c_slave_obj
.
context
.
mem
[
oc_i2c_slave_obj
.
context
.
mem_address
]);
oc_i2c_slave_obj
.
context
.
mem_address
++
;
oc_i2c_slave_obj
.
mp_irq_flags
=
OC_I2C_SLAVE_READ
;
oc_i2c_slave_obj
.
mp_irq_flags
_unfinished
|
=
OC_I2C_SLAVE_READ
;
break
;
case
I2C_SLAVE_FINISH
:
// master has signalled Stop / Restart
oc_i2c_slave_obj
.
context
.
mem_address
=
0
;
oc_i2c_slave_obj
.
context
.
mem_address_written
=
false
;
// Check the flags to see if the user handler should be called
if
(
oc_i2c_slave_obj
.
mp_irq_trigger
&
oc_i2c_slave_obj
.
mp_irq_flags
)
{
if
(
oc_i2c_slave_obj
.
mp_irq_trigger
&
oc_i2c_slave_obj
.
mp_irq_flags_unfinished
)
{
oc_i2c_slave_obj
.
mp_irq_flags
=
oc_i2c_slave_obj
.
mp_irq_flags_unfinished
;
oc_i2c_slave_obj
.
mp_irq_flags_unfinished
=
0
;
mp_irq_handler
(
oc_i2c_slave_obj
.
mp_irq_obj
);
}
break
;
...
...
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