summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-02-13 19:04:24 +0000
committerDamien George <damien.p.george@gmail.com>2015-02-13 19:04:24 +0000
commitbaafb290ada10c7b8ba0b4b31fb4c5ec8282be88 (patch)
tree6b64ea0125190e0abd0cf0a56adb5ec4e9fa79ba
parent089c3f321e1bfe86864b6d4b2ac91074ea282c54 (diff)
downloadmicropython-baafb290ada10c7b8ba0b4b31fb4c5ec8282be88.tar.gz
micropython-baafb290ada10c7b8ba0b4b31fb4c5ec8282be88.zip
stmhal: Add uart.sendbreak() method, to send a break condition.
-rw-r--r--docs/library/pyb.UART.rst6
-rw-r--r--stmhal/qstrdefsport.h1
-rw-r--r--stmhal/uart.c9
-rw-r--r--tests/pyb/uart.py3
4 files changed, 19 insertions, 0 deletions
diff --git a/docs/library/pyb.UART.rst b/docs/library/pyb.UART.rst
index a636e65e30..257a9f281b 100644
--- a/docs/library/pyb.UART.rst
+++ b/docs/library/pyb.UART.rst
@@ -134,3 +134,9 @@ Methods
Write a single character on the bus. ``char`` is an integer to write.
Return value: ``None``.
+
+.. method:: uart.sendbreak()
+
+ Send a break condition on the bus. This drives the bus low for a duration
+ of 13 bits.
+ Return value: ``None``.
diff --git a/stmhal/qstrdefsport.h b/stmhal/qstrdefsport.h
index 3aecb7acfa..85ab206756 100644
--- a/stmhal/qstrdefsport.h
+++ b/stmhal/qstrdefsport.h
@@ -186,6 +186,7 @@ Q(any)
Q(writechar)
Q(readchar)
Q(readinto)
+Q(sendbreak)
Q(RTS)
Q(CTS)
diff --git a/stmhal/uart.c b/stmhal/uart.c
index 23eba45b87..d888358b36 100644
--- a/stmhal/uart.c
+++ b/stmhal/uart.c
@@ -614,6 +614,14 @@ STATIC mp_obj_t pyb_uart_readchar(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_readchar_obj, pyb_uart_readchar);
+// uart.sendbreak()
+STATIC mp_obj_t pyb_uart_sendbreak(mp_obj_t self_in) {
+ pyb_uart_obj_t *self = self_in;
+ self->uart.Instance->CR1 |= USART_CR1_SBK;
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_uart_sendbreak_obj, pyb_uart_sendbreak);
+
STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = {
// instance methods
@@ -634,6 +642,7 @@ STATIC const mp_map_elem_t pyb_uart_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_writechar), (mp_obj_t)&pyb_uart_writechar_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_readchar), (mp_obj_t)&pyb_uart_readchar_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_sendbreak), (mp_obj_t)&pyb_uart_sendbreak_obj },
// class constants
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTS), MP_OBJ_NEW_SMALL_INT(UART_HWCONTROL_RTS) },
diff --git a/tests/pyb/uart.py b/tests/pyb/uart.py
index 288022fea4..c83d18349e 100644
--- a/tests/pyb/uart.py
+++ b/tests/pyb/uart.py
@@ -12,3 +12,6 @@ print(uart.any())
print(uart.write('123'))
print(uart.write(b'abcd'))
print(uart.writechar(1))
+
+# make sure this method exists
+uart.sendbreak()