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
bb29bde1
Commit
bb29bde1
authored
May 08, 2019
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nrf/machine/i2c: Update to support new C-level I2C API.
parent
38ac697b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
26 deletions
+11
-26
ports/nrf/modules/machine/i2c.c
ports/nrf/modules/machine/i2c.c
+11
-26
No files found.
ports/nrf/modules/machine/i2c.c
View file @
bb29bde1
...
...
@@ -99,35 +99,20 @@ mp_obj_t machine_hard_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz
return
MP_OBJ_FROM_PTR
(
self
);
}
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_single
(
mp_obj_base_t
*
self_in
,
uint16_t
addr
,
size_t
len
,
uint8_t
*
buf
,
unsigned
int
flags
)
{
machine_hard_i2c_obj_t
*
self
=
(
machine_hard_i2c_obj_t
*
)
self_in
;
nrfx_twi_enable
(
&
self
->
p_twi
);
nrfx_err_t
err_code
=
nrfx_twi_rx
(
&
self
->
p_twi
,
addr
,
dest
,
len
);
if
(
err_code
!=
NRFX_SUCCESS
)
{
if
(
err_code
==
NRFX_ERROR_DRV_TWI_ERR_ANACK
)
{
return
-
MP_ENODEV
;
}
else
if
(
err_code
==
NRFX_ERROR_DRV_TWI_ERR_DNACK
)
{
return
-
MP_EIO
;
}
return
-
MP_ETIMEDOUT
;
nrfx_err_t
err_code
;
int
transfer_ret
=
0
;
if
(
flags
&
MP_MACHINE_I2C_FLAG_READ
)
{
err_code
=
nrfx_twi_rx
(
&
self
->
p_twi
,
addr
,
buf
,
len
);
}
else
{
err_code
=
nrfx_twi_tx
(
&
self
->
p_twi
,
addr
,
buf
,
len
,
(
flags
&
MP_MACHINE_I2C_FLAG_STOP
)
==
0
);
transfer_ret
=
len
;
}
nrfx_twi_disable
(
&
self
->
p_twi
);
return
0
;
}
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
=
(
machine_hard_i2c_obj_t
*
)
self_in
;
nrfx_twi_enable
(
&
self
->
p_twi
);
nrfx_err_t
err_code
=
nrfx_twi_tx
(
&
self
->
p_twi
,
addr
,
src
,
len
,
!
stop
);
if
(
err_code
!=
NRFX_SUCCESS
)
{
if
(
err_code
==
NRFX_ERROR_DRV_TWI_ERR_ANACK
)
{
return
-
MP_ENODEV
;
...
...
@@ -140,12 +125,12 @@ int machine_hard_i2c_writeto(mp_obj_base_t *self_in, uint16_t addr, const uint8_
nrfx_twi_disable
(
&
self
->
p_twi
);
return
len
;
return
transfer_ret
;
}
STATIC
const
mp_machine_i2c_p_t
machine_hard_i2c_p
=
{
.
readfrom
=
machine_hard_i2c_readfrom
,
.
writeto
=
machine_hard_i2c_writeto
,
.
transfer
=
mp_machine_i2c_transfer_adaptor
,
.
transfer_single
=
machine_hard_i2c_transfer_single
,
};
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