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
38ac697b
Commit
38ac697b
authored
May 08, 2019
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stm32/machine_i2c: Update to support new C-level I2C API.
parent
606ea2b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
10 deletions
+28
-10
ports/stm32/machine_i2c.c
ports/stm32/machine_i2c.c
+28
-10
No files found.
ports/stm32/machine_i2c.c
View file @
38ac697b
...
...
@@ -109,14 +109,34 @@ void machine_hard_i2c_init(machine_hard_i2c_obj_t *self, uint32_t freq, uint32_t
i2c_init
(
self
->
i2c
,
self
->
scl
,
self
->
sda
,
freq
);
}
int
machine_hard_i2c_
readfrom
(
mp_obj_base_t
*
self_in
,
uint16_t
addr
,
uint8_t
*
dest
,
size_t
len
,
bool
stop
)
{
int
machine_hard_i2c_
transfer
(
mp_obj_base_t
*
self_in
,
uint16_t
addr
,
size_t
n
,
mp_machine_i2c_buf_t
*
bufs
,
unsigned
int
flags
)
{
machine_hard_i2c_obj_t
*
self
=
MP_OBJ_TO_PTR
(
self_in
);
return
i2c_readfrom
(
self
->
i2c
,
addr
,
dest
,
len
,
stop
);
}
int
machine_hard_i2c_writeto
(
mp_obj_base_t
*
self_in
,
uint16_t
addr
,
const
uint8_t
*
src
,
size_t
len
,
bool
stop
)
{
machine_hard_i2c_obj_t
*
self
=
MP_OBJ_TO_PTR
(
self_in
);
return
i2c_writeto
(
self
->
i2c
,
addr
,
src
,
len
,
stop
);
size_t
remain_len
=
0
;
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
remain_len
+=
bufs
[
i
].
len
;
}
int
ret
=
i2c_start_addr
(
self
->
i2c
,
flags
&
MP_MACHINE_I2C_FLAG_READ
,
addr
,
remain_len
,
flags
&
MP_MACHINE_I2C_FLAG_STOP
);
if
(
ret
<
0
)
{
return
ret
;
}
int
num_acks
=
0
;
// only valid for write; for read it'll be 0
for
(;
n
--
;
++
bufs
)
{
remain_len
-=
bufs
->
len
;
if
(
flags
&
MP_MACHINE_I2C_FLAG_READ
)
{
ret
=
i2c_read
(
self
->
i2c
,
bufs
->
buf
,
bufs
->
len
,
remain_len
);
}
else
{
ret
=
i2c_write
(
self
->
i2c
,
bufs
->
buf
,
bufs
->
len
,
remain_len
);
}
if
(
ret
<
0
)
{
return
ret
;
}
num_acks
+=
ret
;
}
return
num_acks
;
}
#else
...
...
@@ -174,8 +194,7 @@ STATIC void machine_hard_i2c_init(machine_hard_i2c_obj_t *self, uint32_t freq, u
mp_hal_pin_open_drain
(
self
->
sda
);
}
#define machine_hard_i2c_readfrom mp_machine_soft_i2c_readfrom
#define machine_hard_i2c_writeto mp_machine_soft_i2c_writeto
#define machine_hard_i2c_transfer mp_machine_soft_i2c_transfer
#endif
...
...
@@ -240,8 +259,7 @@ mp_obj_t machine_hard_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz
}
STATIC
const
mp_machine_i2c_p_t
machine_hard_i2c_p
=
{
.
readfrom
=
machine_hard_i2c_readfrom
,
.
writeto
=
machine_hard_i2c_writeto
,
.
transfer
=
machine_hard_i2c_transfer
,
};
STATIC
const
mp_obj_type_t
machine_hard_i2c_type
=
{
...
...
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