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
8332044f
Commit
8332044f
authored
Sep 13, 2015
by
Daniel Campora
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cc3200: Add UART.ODD and UART.EVEN to select parity.
parent
d5ec336e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
8 deletions
+16
-8
cc3200/mods/pybuart.c
cc3200/mods/pybuart.c
+8
-2
cc3200/qstrdefsport.h
cc3200/qstrdefsport.h
+2
-0
docs/library/pyb.UART.rst
docs/library/pyb.UART.rst
+2
-2
tests/wipy/uart.py
tests/wipy/uart.py
+4
-4
No files found.
cc3200/mods/pybuart.c
View file @
8332044f
...
...
@@ -343,7 +343,7 @@ STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k
if
((
self
->
config
&
UART_CONFIG_PAR_MASK
)
==
UART_CONFIG_PAR_NONE
)
{
mp_print_str
(
print
,
", parity=None"
);
}
else
{
mp_printf
(
print
,
", parity=
%u"
,
(
self
->
config
&
UART_CONFIG_PAR_MASK
)
==
UART_CONFIG_PAR_EVEN
?
0
:
1
);
mp_printf
(
print
,
", parity=
UART.%q"
,
(
self
->
config
&
UART_CONFIG_PAR_MASK
)
==
UART_CONFIG_PAR_EVEN
?
MP_QSTR_EVEN
:
MP_QSTR_ODD
);
}
mp_printf
(
print
,
", stop=%u)"
,
(
self
->
config
&
UART_CONFIG_STOP_MASK
)
==
UART_CONFIG_STOP_ONE
?
1
:
2
);
}
...
...
@@ -380,7 +380,11 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_arg_val_t *args) {
if
(
args
[
2
].
u_obj
==
mp_const_none
)
{
config
|=
UART_CONFIG_PAR_NONE
;
}
else
{
config
|=
((
mp_obj_get_int
(
args
[
2
].
u_obj
)
&
1
)
?
UART_CONFIG_PAR_ODD
:
UART_CONFIG_PAR_EVEN
);
uint
parity
=
mp_obj_get_int
(
args
[
2
].
u_obj
);
if
(
parity
!=
UART_CONFIG_PAR_ODD
&&
parity
!=
UART_CONFIG_PAR_EVEN
)
{
goto
error
;
}
config
|=
parity
;
}
// stop bits
config
|=
(
args
[
3
].
u_int
==
1
?
UART_CONFIG_STOP_ONE
:
UART_CONFIG_STOP_TWO
);
...
...
@@ -575,6 +579,8 @@ STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = {
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_write
),
(
mp_obj_t
)
&
mp_stream_write_obj
},
// class constants
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_EVEN
),
MP_OBJ_NEW_SMALL_INT
(
UART_CONFIG_PAR_EVEN
)
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_ODD
),
MP_OBJ_NEW_SMALL_INT
(
UART_CONFIG_PAR_ODD
)
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_RX_ANY
),
MP_OBJ_NEW_SMALL_INT
(
E_UART_TRIGGER_RX_ANY
)
},
};
...
...
cc3200/qstrdefsport.h
View file @
8332044f
...
...
@@ -148,6 +148,8 @@ Q(bits)
Q
(
stop
)
Q
(
parity
)
Q
(
pins
)
Q
(
EVEN
)
Q
(
ODD
)
Q
(
RX_ANY
)
// for I2C class
...
...
docs/library/pyb.UART.rst
View file @
8332044f
...
...
@@ -24,7 +24,7 @@ UART objects can be created and initialised using::
.. only:: port_wipy
Bits can be 5, 6, 7, 8. Parity can be
None, 0 (even) or 1 (odd)
. Stop can be 1 or 2.
Bits can be 5, 6, 7, 8. Parity can be
``None``, ``UART.EVEN`` or ``UART.ODD``
. Stop can be 1 or 2.
A UART object acts like a stream object and reading and writing is done
...
...
@@ -122,7 +122,7 @@ Methods
- ``baudrate`` is the clock rate.
- ``bits`` is the number of bits per character, 7, 8 or 9.
- ``parity`` is the parity, ``None``,
0 (even) or 1 (odd)
.
- ``parity`` is the parity, ``None``,
``UART.EVEN`` or ``UART.ODD``
.
- ``stop`` is the number of stop bits, 1 or 2.
- ``pins`` is a 4 or 2 item list indicating the TX, RX, RTS and CTS pins (in that order).
Any of the pins can be None if one wants the UART to operate with limited functionality.
...
...
tests/wipy/uart.py
View file @
8332044f
...
...
@@ -25,8 +25,8 @@ for uart_id in uart_id_range:
uart
=
UART
(
uart_id
,
38400
)
print
(
uart
)
uart
.
init
(
57600
,
8
,
None
,
1
,
pins
=
uart_pins
[
uart_id
][
0
])
uart
.
init
(
baudrate
=
9600
,
stop
=
2
,
parity
=
0
,
pins
=
uart_pins
[
uart_id
][
1
])
uart
.
init
(
baudrate
=
115200
,
parity
=
1
,
stop
=
1
,
pins
=
uart_pins
[
uart_id
][
0
])
uart
.
init
(
baudrate
=
9600
,
stop
=
2
,
parity
=
UART
.
EVEN
,
pins
=
uart_pins
[
uart_id
][
1
])
uart
.
init
(
baudrate
=
115200
,
parity
=
UART
.
ODD
,
stop
=
0
,
pins
=
uart_pins
[
uart_id
][
0
])
uart
=
UART
(
baudrate
=
1000000
)
uart
.
sendbreak
()
...
...
@@ -111,12 +111,12 @@ for i in range (0, 1000):
# next ones must raise
try
:
UART
(
0
,
9600
,
parity
=
2
,
pins
=
(
'GP12'
,
'GP13'
,
'GP7'
))
UART
(
0
,
9600
,
parity
=
None
,
pins
=
(
'GP12'
,
'GP13'
,
'GP7'
))
except
Exception
:
print
(
'Exception'
)
try
:
UART
(
0
,
9600
,
parity
=
2
,
pins
=
(
'GP12'
,
'GP7'
))
UART
(
0
,
9600
,
parity
=
UART
.
ODD
,
pins
=
(
'GP12'
,
'GP7'
))
except
Exception
:
print
(
'Exception'
)
...
...
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