Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
8b74048d
Commit
8b74048d
authored
8 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
extmod/machine_i2c: Expose soft I2C obj and readfrom/writeto funcs.
For external use by ports if needed.
parent
4c905616
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
extmod/machine_i2c.c
+5
-11
5 additions, 11 deletions
extmod/machine_i2c.c
extmod/machine_i2c.h
+12
-0
12 additions, 0 deletions
extmod/machine_i2c.h
with
17 additions
and
11 deletions
extmod/machine_i2c.c
+
5
−
11
View file @
8b74048d
...
...
@@ -35,13 +35,7 @@
#if MICROPY_PY_MACHINE_I2C
typedef
struct
_machine_i2c_obj_t
{
mp_obj_base_t
base
;
uint32_t
us_delay
;
uint32_t
us_timeout
;
mp_hal_pin_obj_t
scl
;
mp_hal_pin_obj_t
sda
;
}
machine_i2c_obj_t
;
typedef
mp_machine_soft_i2c_obj_t
machine_i2c_obj_t
;
STATIC
void
mp_hal_i2c_delay
(
machine_i2c_obj_t
*
self
)
{
// We need to use an accurate delay to get acceptable I2C
...
...
@@ -188,7 +182,7 @@ STATIC int mp_hal_i2c_read_byte(machine_i2c_obj_t *self, uint8_t *val, int nack)
// return value:
// >=0 - number of acks received
// <0 - error, with errno being the negative of the return value
STATIC
int
mp_machine_soft_i2c_writeto
(
mp_obj_base_t
*
self_in
,
uint16_t
addr
,
const
uint8_t
*
src
,
size_t
len
,
bool
stop
)
{
int
mp_machine_soft_i2c_writeto
(
mp_obj_base_t
*
self_in
,
uint16_t
addr
,
const
uint8_t
*
src
,
size_t
len
,
bool
stop
)
{
machine_i2c_obj_t
*
self
=
(
machine_i2c_obj_t
*
)
self_in
;
// start the I2C transaction
...
...
@@ -234,7 +228,7 @@ STATIC int mp_machine_soft_i2c_writeto(mp_obj_base_t *self_in, uint16_t addr, co
// return value:
// 0 - success
// <0 - error, with errno being the negative of the return value
STATIC
int
mp_machine_soft_i2c_readfrom
(
mp_obj_base_t
*
self_in
,
uint16_t
addr
,
uint8_t
*
dest
,
size_t
len
,
bool
stop
)
{
int
mp_machine_soft_i2c_readfrom
(
mp_obj_base_t
*
self_in
,
uint16_t
addr
,
uint8_t
*
dest
,
size_t
len
,
bool
stop
)
{
machine_i2c_obj_t
*
self
=
(
machine_i2c_obj_t
*
)
self_in
;
// start the I2C transaction
...
...
@@ -582,7 +576,7 @@ STATIC const mp_rom_map_elem_t machine_i2c_locals_dict_table[] = {
{
MP_ROM_QSTR
(
MP_QSTR_writeto_mem
),
MP_ROM_PTR
(
&
machine_i2c_writeto_mem_obj
)
},
};
STATIC
MP_DEFINE_CONST_DICT
(
machine_i2c_locals_dict
,
machine_i2c_locals_dict_table
);
MP_DEFINE_CONST_DICT
(
mp_
machine_
soft_
i2c_locals_dict
,
machine_i2c_locals_dict_table
);
int
mp_machine_soft_i2c_read
(
mp_obj_base_t
*
self_in
,
uint8_t
*
dest
,
size_t
len
,
bool
nack
)
{
machine_i2c_obj_t
*
self
=
(
machine_i2c_obj_t
*
)
self_in
;
...
...
@@ -625,7 +619,7 @@ const mp_obj_type_t machine_i2c_type = {
.
name
=
MP_QSTR_I2C
,
.
make_new
=
machine_i2c_make_new
,
.
protocol
=
&
mp_machine_soft_i2c_p
,
.
locals_dict
=
(
mp_obj_dict_t
*
)
&
machine_i2c_locals_dict
,
.
locals_dict
=
(
mp_obj_dict_t
*
)
&
mp_
machine_
soft_
i2c_locals_dict
,
};
#endif // MICROPY_PY_MACHINE_I2C
This diff is collapsed.
Click to expand it.
extmod/machine_i2c.h
+
12
−
0
View file @
8b74048d
...
...
@@ -40,6 +40,18 @@ typedef struct _mp_machine_i2c_p_t {
int
(
*
writeto
)(
mp_obj_base_t
*
obj
,
uint16_t
addr
,
const
uint8_t
*
src
,
size_t
len
,
bool
stop
);
}
mp_machine_i2c_p_t
;
typedef
struct
_mp_machine_soft_i2c_obj_t
{
mp_obj_base_t
base
;
uint32_t
us_delay
;
uint32_t
us_timeout
;
mp_hal_pin_obj_t
scl
;
mp_hal_pin_obj_t
sda
;
}
mp_machine_soft_i2c_obj_t
;
extern
const
mp_obj_type_t
machine_i2c_type
;
extern
const
mp_obj_dict_t
mp_machine_soft_i2c_locals_dict
;
int
mp_machine_soft_i2c_readfrom
(
mp_obj_base_t
*
self_in
,
uint16_t
addr
,
uint8_t
*
dest
,
size_t
len
,
bool
stop
);
int
mp_machine_soft_i2c_writeto
(
mp_obj_base_t
*
self_in
,
uint16_t
addr
,
const
uint8_t
*
src
,
size_t
len
,
bool
stop
);
#endif // __MICROPY_INCLUDED_EXTMOD_MACHINE_I2C_H__
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