Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
37333cb0
Commit
37333cb0
authored
Nov 23, 2016
by
Damien George
Browse files
extmod/machine_i2c: Add 'stop' argument to i2c readfrom/writeto meths.
parent
0bc99b48
Changes
1
Hide whitespace changes
Inline
Side-by-side
extmod/machine_i2c.c
View file @
37333cb0
...
...
@@ -392,45 +392,51 @@ STATIC mp_obj_t machine_i2c_write(mp_obj_t self_in, mp_obj_t buf_in) {
}
MP_DEFINE_CONST_FUN_OBJ_2
(
machine_i2c_write_obj
,
machine_i2c_write
);
STATIC
mp_obj_t
machine_i2c_readfrom
(
mp_obj_t
self_in
,
mp_obj_t
addr_in
,
mp_obj_t
nbytes_in
)
{
mp_obj_base_t
*
self
=
(
mp_obj_base_t
*
)
MP_OBJ_TO_PTR
(
self_in
);
STATIC
mp_obj_t
machine_i2c_readfrom
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
mp_obj_base_t
*
self
=
(
mp_obj_base_t
*
)
MP_OBJ_TO_PTR
(
args
[
0
]
);
mp_machine_i2c_p_t
*
i2c_p
=
(
mp_machine_i2c_p_t
*
)
self
->
type
->
protocol
;
mp_int_t
addr
=
mp_obj_get_int
(
args
[
1
]);
vstr_t
vstr
;
vstr_init_len
(
&
vstr
,
mp_obj_get_int
(
nbytes_in
));
int
ret
=
i2c_p
->
readfrom
(
self
,
mp_obj_get_int
(
addr_in
),
(
uint8_t
*
)
vstr
.
buf
,
vstr
.
len
,
true
);
vstr_init_len
(
&
vstr
,
mp_obj_get_int
(
args
[
2
]));
bool
stop
=
(
n_args
==
3
)
?
true
:
mp_obj_is_true
(
args
[
3
]);
int
ret
=
i2c_p
->
readfrom
(
self
,
addr
,
(
uint8_t
*
)
vstr
.
buf
,
vstr
.
len
,
stop
);
if
(
ret
<
0
)
{
mp_raise_OSError
(
-
ret
);
}
return
mp_obj_new_str_from_vstr
(
&
mp_type_bytes
,
&
vstr
);
}
MP_DEFINE_CONST_FUN_OBJ_
3
(
machine_i2c_readfrom_obj
,
machine_i2c_readfrom
);
MP_DEFINE_CONST_FUN_OBJ_
VAR_BETWEEN
(
machine_i2c_readfrom_obj
,
3
,
4
,
machine_i2c_readfrom
);
STATIC
mp_obj_t
machine_i2c_readfrom_into
(
mp_obj_t
self_in
,
mp_obj_t
addr_in
,
mp_obj_t
buf_in
)
{
mp_obj_base_t
*
self
=
(
mp_obj_base_t
*
)
MP_OBJ_TO_PTR
(
self_in
);
STATIC
mp_obj_t
machine_i2c_readfrom_into
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
mp_obj_base_t
*
self
=
(
mp_obj_base_t
*
)
MP_OBJ_TO_PTR
(
args
[
0
]
);
mp_machine_i2c_p_t
*
i2c_p
=
(
mp_machine_i2c_p_t
*
)
self
->
type
->
protocol
;
mp_int_t
addr
=
mp_obj_get_int
(
args
[
1
]);
mp_buffer_info_t
bufinfo
;
mp_get_buffer_raise
(
buf_in
,
&
bufinfo
,
MP_BUFFER_WRITE
);
int
ret
=
i2c_p
->
readfrom
(
self
,
mp_obj_get_int
(
addr_in
),
bufinfo
.
buf
,
bufinfo
.
len
,
true
);
mp_get_buffer_raise
(
args
[
2
],
&
bufinfo
,
MP_BUFFER_WRITE
);
bool
stop
=
(
n_args
==
3
)
?
true
:
mp_obj_is_true
(
args
[
3
]);
int
ret
=
i2c_p
->
readfrom
(
self
,
addr
,
bufinfo
.
buf
,
bufinfo
.
len
,
stop
);
if
(
ret
<
0
)
{
mp_raise_OSError
(
-
ret
);
}
return
mp_const_none
;
}
MP_DEFINE_CONST_FUN_OBJ_
3
(
machine_i2c_readfrom_into_obj
,
machine_i2c_readfrom_into
);
MP_DEFINE_CONST_FUN_OBJ_
VAR_BETWEEN
(
machine_i2c_readfrom_into_obj
,
3
,
4
,
machine_i2c_readfrom_into
);
STATIC
mp_obj_t
machine_i2c_writeto
(
mp_obj_t
self_in
,
mp_obj_t
addr_in
,
mp_obj_t
buf_in
)
{
mp_obj_base_t
*
self
=
(
mp_obj_base_t
*
)
MP_OBJ_TO_PTR
(
self_in
);
STATIC
mp_obj_t
machine_i2c_writeto
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
mp_obj_base_t
*
self
=
(
mp_obj_base_t
*
)
MP_OBJ_TO_PTR
(
args
[
0
]
);
mp_machine_i2c_p_t
*
i2c_p
=
(
mp_machine_i2c_p_t
*
)
self
->
type
->
protocol
;
mp_int_t
addr
=
mp_obj_get_int
(
args
[
1
]);
mp_buffer_info_t
bufinfo
;
mp_get_buffer_raise
(
buf_in
,
&
bufinfo
,
MP_BUFFER_READ
);
int
ret
=
i2c_p
->
writeto
(
self
,
mp_obj_get_int
(
addr_in
),
bufinfo
.
buf
,
bufinfo
.
len
,
true
);
mp_get_buffer_raise
(
args
[
2
],
&
bufinfo
,
MP_BUFFER_READ
);
bool
stop
=
(
n_args
==
3
)
?
true
:
mp_obj_is_true
(
args
[
3
]);
int
ret
=
i2c_p
->
writeto
(
self
,
addr
,
bufinfo
.
buf
,
bufinfo
.
len
,
stop
);
if
(
ret
<
0
)
{
mp_raise_OSError
(
-
ret
);
}
// return number of acks received
return
MP_OBJ_NEW_SMALL_INT
(
ret
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_
3
(
machine_i2c_writeto_obj
,
machine_i2c_writeto
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_
VAR_BETWEEN
(
machine_i2c_writeto_obj
,
3
,
4
,
machine_i2c_writeto
);
STATIC
int
read_mem
(
mp_obj_t
self_in
,
uint16_t
addr
,
uint32_t
memaddr
,
uint8_t
addrsize
,
uint8_t
*
buf
,
size_t
len
)
{
mp_obj_base_t
*
self
=
(
mp_obj_base_t
*
)
MP_OBJ_TO_PTR
(
self_in
);
...
...
Write
Preview
Supports
Markdown
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