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
e77abc26
Commit
e77abc26
authored
Sep 11, 2015
by
Daniel Campora
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cc3200: Default peripheral ID support on I2C.
parent
c69642a4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
30 deletions
+46
-30
cc3200/mods/pybi2c.c
cc3200/mods/pybi2c.c
+35
-30
cc3200/qstrdefsport.h
cc3200/qstrdefsport.h
+1
-0
tests/wipy/i2c.py
tests/wipy/i2c.py
+7
-0
tests/wipy/i2c.py.exp
tests/wipy/i2c.py.exp
+2
-0
tests/wipy/uart.py
tests/wipy/uart.py
+1
-0
No files found.
cc3200/mods/pybi2c.c
View file @
e77abc26
...
...
@@ -279,19 +279,7 @@ STATIC void pyb_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
}
}
/// \method init()
STATIC
const
mp_arg_t
pyb_i2c_init_args
[]
=
{
{
MP_QSTR_mode
,
MP_ARG_INT
,
{.
u_int
=
PYBI2C_MASTER
}
},
{
MP_QSTR_baudrate
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
100000
}
},
{
MP_QSTR_pins
,
MP_ARG_KW_ONLY
|
MP_ARG_OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
};
#define PYB_I2C_INIT_NUM_ARGS MP_ARRAY_SIZE(pyb_i2c_init_args)
STATIC
mp_obj_t
pyb_i2c_init_helper
(
pyb_i2c_obj_t
*
self
,
mp_uint_t
n_args
,
const
mp_obj_t
*
pos_args
,
mp_map_t
*
kw_args
)
{
// parse args
mp_arg_val_t
args
[
PYB_I2C_INIT_NUM_ARGS
];
mp_arg_parse_all
(
n_args
,
pos_args
,
kw_args
,
PYB_I2C_INIT_NUM_ARGS
,
pyb_i2c_init_args
,
args
);
STATIC
mp_obj_t
pyb_i2c_init_helper
(
pyb_i2c_obj_t
*
self
,
mp_arg_val_t
*
args
)
{
// verify that mode is master
if
(
args
[
0
].
u_int
!=
PYBI2C_MASTER
)
{
goto
invalid_args
;
...
...
@@ -329,32 +317,49 @@ invalid_args:
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_ValueError
,
mpexception_value_invalid_arguments
));
}
/// \classmethod \constructor(bus, ...)
STATIC
mp_obj_t
pyb_i2c_make_new
(
mp_obj_t
type_in
,
mp_uint_t
n_args
,
mp_uint_t
n_kw
,
const
mp_obj_t
*
args
)
{
// check arguments
mp_arg_check_num
(
n_args
,
n_kw
,
1
,
MP_OBJ_FUN_ARGS_MAX
,
true
);
// setup the object
pyb_i2c_obj_t
*
self
=
&
pyb_i2c_obj
;
self
->
base
.
type
=
&
pyb_i2c_type
;
STATIC
const
mp_arg_t
pyb_i2c_init_args
[]
=
{
{
MP_QSTR_id
,
MP_ARG_OBJ
,
{.
u_obj
=
mp_const_none
}
},
{
MP_QSTR_mode
,
MP_ARG_INT
,
{.
u_int
=
PYBI2C_MASTER
}
},
{
MP_QSTR_baudrate
,
MP_ARG_KW_ONLY
|
MP_ARG_INT
,
{.
u_int
=
100000
}
},
{
MP_QSTR_pins
,
MP_ARG_KW_ONLY
|
MP_ARG_OBJ
,
{.
u_obj
=
MP_OBJ_NULL
}
},
};
#define PYB_I2C_INIT_NUM_ARGS MP_ARRAY_SIZE(pyb_i2c_init_args)
STATIC
mp_obj_t
pyb_i2c_make_new
(
mp_obj_t
type_in
,
mp_uint_t
n_args
,
mp_uint_t
n_kw
,
const
mp_obj_t
*
all_args
)
{
// parse args
mp_map_t
kw_args
;
mp_map_init_fixed_table
(
&
kw_args
,
n_kw
,
all_args
+
n_args
);
mp_arg_val_t
args
[
MP_ARRAY_SIZE
(
pyb_i2c_init_args
)];
mp_arg_parse_all
(
n_args
,
all_args
,
&
kw_args
,
MP_ARRAY_SIZE
(
args
),
pyb_i2c_init_args
,
args
);
// work out the uart id
uint8_t
i2c_id
;
if
(
args
[
0
].
u_obj
==
mp_const_none
)
{
// default id
i2c_id
=
0
;
}
else
{
i2c_id
=
mp_obj_get_int
(
args
[
0
].
u_obj
);
}
// check the peripheral id
if
(
mp_obj_get_int
(
args
[
0
])
!=
0
)
{
if
(
i2c_id
!=
0
)
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_OSError
,
mpexception_os_resource_not_avaliable
));
}
if
(
n_args
>
1
||
n_kw
>
0
)
{
// start the peripheral
mp_map_t
kw_args
;
mp_map_init_fixed_table
(
&
kw_args
,
n_kw
,
args
+
n_args
);
pyb_i2c_init_helper
(
self
,
n_args
-
1
,
args
+
1
,
&
kw_args
);
}
// setup the object
pyb_i2c_obj_t
*
self
=
&
pyb_i2c_obj
;
self
->
base
.
type
=
&
pyb_i2c_type
;
// start the peripheral
pyb_i2c_init_helper
(
self
,
&
args
[
1
]);
return
(
mp_obj_t
)
self
;
}
STATIC
mp_obj_t
pyb_i2c_init
(
mp_uint_t
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kw_args
)
{
return
pyb_i2c_init_helper
(
args
[
0
],
n_args
-
1
,
args
+
1
,
kw_args
);
STATIC
mp_obj_t
pyb_i2c_init
(
mp_uint_t
n_args
,
const
mp_obj_t
*
pos_args
,
mp_map_t
*
kw_args
)
{
// parse args
mp_arg_val_t
args
[
MP_ARRAY_SIZE
(
pyb_i2c_init_args
)
-
1
];
mp_arg_parse_all
(
n_args
-
1
,
pos_args
+
1
,
kw_args
,
MP_ARRAY_SIZE
(
args
),
&
pyb_i2c_init_args
[
1
],
args
);
return
pyb_i2c_init_helper
(
pos_args
[
0
],
args
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_KW
(
pyb_i2c_init_obj
,
1
,
pyb_i2c_init
);
...
...
cc3200/qstrdefsport.h
View file @
e77abc26
...
...
@@ -153,6 +153,7 @@ Q(RX_ANY)
// for I2C class
Q
(
I2C
)
Q
(
id
)
Q
(
mode
)
Q
(
baudrate
)
Q
(
pins
)
...
...
tests/wipy/i2c.py
View file @
e77abc26
...
...
@@ -16,6 +16,13 @@ elif 'WiPy' in machine:
else
:
raise
Exception
(
'Board not supported!'
)
i2c
=
I2C
(
0
,
I2C
.
MASTER
,
baudrate
=
400000
)
# try initing without the peripheral id
i2c
=
I2C
()
print
(
i2c
)
i2c
=
I2C
(
mode
=
I2C
.
MASTER
,
baudrate
=
50000
,
pins
=
i2c_pins
)
print
(
i2c
)
i2c
=
I2C
(
0
,
I2C
.
MASTER
,
baudrate
=
100000
)
print
(
i2c
)
i2c
=
I2C
(
0
,
mode
=
I2C
.
MASTER
,
baudrate
=
400000
)
...
...
tests/wipy/i2c.py.exp
View file @
e77abc26
I2C(0, I2C.MASTER, baudrate=100000)
I2C(0, I2C.MASTER, baudrate=50000)
I2C(0, I2C.MASTER, baudrate=100000)
I2C(0, I2C.MASTER, baudrate=400000)
I2C(0, I2C.MASTER, baudrate=400000)
104
...
...
tests/wipy/uart.py
View file @
e77abc26
...
...
@@ -30,6 +30,7 @@ for uart_id in uart_id_range:
uart
=
UART
(
baudrate
=
1000000
)
uart
.
sendbreak
()
uart
=
UART
(
baudrate
=
1000000
)
uart
=
UART
()
print
(
uart
)
uart
=
UART
(
baudrate
=
38400
,
pins
=
(
'GP12'
,
'GP13'
))
...
...
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