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
8bcb552d
Commit
8bcb552d
authored
May 08, 2019
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extmod/machine_i2c: Remove need for temporary memory in writemem() call.
parent
647b27d0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
22 deletions
+12
-22
extmod/machine_i2c.c
extmod/machine_i2c.c
+12
-22
No files found.
extmod/machine_i2c.c
View file @
8bcb552d
...
...
@@ -496,35 +496,25 @@ STATIC int read_mem(mp_obj_t self_in, uint16_t addr, uint32_t memaddr, uint8_t a
return
mp_machine_i2c_readfrom
(
self
,
addr
,
buf
,
len
,
true
);
}
#define MAX_MEMADDR_SIZE (4)
#define BUF_STACK_SIZE (12)
STATIC
int
write_mem
(
mp_obj_t
self_in
,
uint16_t
addr
,
uint32_t
memaddr
,
uint8_t
addrsize
,
const
uint8_t
*
buf
,
size_t
len
)
{
mp_obj_base_t
*
self
=
(
mp_obj_base_t
*
)
MP_OBJ_TO_PTR
(
self_in
);
// need some memory to create the buffer to send; try to use stack if possible
uint8_t
buf2_stack
[
MAX_MEMADDR_SIZE
+
BUF_STACK_SIZE
];
uint8_t
*
buf2
;
size_t
buf2_alloc
=
0
;
if
(
len
<=
BUF_STACK_SIZE
)
{
buf2
=
buf2_stack
;
}
else
{
buf2_alloc
=
MAX_MEMADDR_SIZE
+
len
;
buf2
=
m_new
(
uint8_t
,
buf2_alloc
);
}
// create the buffer to send
// Create buffer with memory address
size_t
memaddr_len
=
0
;
uint8_t
memaddr_buf
[
4
];
for
(
int16_t
i
=
addrsize
-
8
;
i
>=
0
;
i
-=
8
)
{
buf2
[
memaddr_len
++
]
=
memaddr
>>
i
;
memaddr_buf
[
memaddr_len
++
]
=
memaddr
>>
i
;
}
memcpy
(
buf2
+
memaddr_len
,
buf
,
len
);
int
ret
=
mp_machine_i2c_writeto
(
self
,
addr
,
buf2
,
memaddr_len
+
len
,
true
);
if
(
buf2_alloc
!=
0
)
{
m_del
(
uint8_t
,
buf2
,
buf2_alloc
);
}
return
ret
;
// Create partial write buffers
mp_machine_i2c_buf_t
bufs
[
2
]
=
{
{.
len
=
memaddr_len
,
.
buf
=
memaddr_buf
},
{.
len
=
len
,
.
buf
=
(
uint8_t
*
)
buf
},
};
// Do I2C transfer
mp_machine_i2c_p_t
*
i2c_p
=
(
mp_machine_i2c_p_t
*
)
self
->
type
->
protocol
;
return
i2c_p
->
transfer
(
self
,
addr
,
2
,
bufs
,
MP_MACHINE_I2C_FLAG_STOP
);
}
STATIC
const
mp_arg_t
machine_i2c_mem_allowed_args
[]
=
{
...
...
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