summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-02-21 16:30:26 -0500
committerDan Halbert <halbert@halwitz.org>2018-02-21 17:18:49 -0500
commit9b4477e1dc088d18127838310b828514cb33edea (patch)
treec15d3c890b0186e5e7a68748d7d245b86d8796dc /shared-bindings
parentfd9d3de208e8d5994916e3365cc3f5dea57e19de (diff)
Implement UART for 3.0 + related fixes.
1. UART: ported to ASF4. Allow rx-only and tx-only. Add .baudrate r/w property. 2. Make NeoPixel timing deterministic by turning off caches during NeoPixel writes. 3. Incorporate asf4 updates: a. async USART driver b. bringing Atmel START configuration closer to what we use c. Clock initialization order now specified by CIRCUITPY_GCLK_INIT_1ST and _LAST. 4. supervisor/port.c: Move commented-out clock-test pin setting to correct location.
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/busio/UART.c39
-rw-r--r--shared-bindings/busio/UART.h4
-rw-r--r--shared-bindings/busio/__init__.c8
3 files changed, 43 insertions, 8 deletions
diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c
index 3a3cb4246..1b63d8d0e 100644
--- a/shared-bindings/busio/UART.c
+++ b/shared-bindings/busio/UART.c
@@ -33,6 +33,7 @@
#include "lib/utils/context_manager_helpers.h"
#include "py/ioctl.h"
+#include "py/objproperty.h"
#include "py/runtime.h"
#include "py/stream.h"
@@ -48,11 +49,11 @@
//| A common bidirectional serial protocol that uses an an agreed upon speed
//| rather than a shared clock line.
//|
-//| :param ~microcontroller.Pin tx: the pin to transmit with
-//| :param ~microcontroller.Pin rx: the pin to receive on
-//| :param int baudrate: the transmit and receive speed
+//| :param ~microcontroller.Pin tx: the pin to transmit with, or ``None`` if this ``UART`` is receive-only.
+//| :param ~microcontroller.Pin rx: the pin to receive on, or ``None`` if this ``UART`` is transmit-only.
+//| :param int baudrate: the transmit and receive speed.
/// :param int bits: the number of bits per byte, 7, 8 or 9.
-/// :param Parity parity: the parity used for error checking
+/// :param Parity parity: the parity used for error checking.
/// :param int stop: the number of stop bits, 1 or 2.
/// :param int timeout: the timeout in milliseconds to wait for the first character and between subsequent characters.
/// :param int receiver_buffer_size: the character length of the read buffer (0 to disable). (When a character is 9 bits the buffer will be 2 * receiver_buffer_size bytes.)
@@ -220,6 +221,33 @@ STATIC mp_uint_t busio_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t
return ret;
}
+//| .. attribute:: baudrate
+//|
+//| The current baudrate.
+//|
+STATIC mp_obj_t busio_uart_obj_get_baudrate(mp_obj_t self_in) {
+ busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ raise_error_if_deinited(common_hal_busio_uart_deinited(self));
+ return MP_OBJ_NEW_SMALL_INT(common_hal_busio_uart_get_baudrate(self));
+}
+MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_get_baudrate_obj, busio_uart_obj_get_baudrate);
+
+STATIC mp_obj_t busio_uart_obj_set_baudrate(mp_obj_t self_in, mp_obj_t baudrate) {
+ busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
+ raise_error_if_deinited(common_hal_busio_uart_deinited(self));
+ common_hal_busio_uart_set_baudrate(self, mp_obj_get_int(baudrate));
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_2(busio_uart_set_baudrate_obj, busio_uart_obj_set_baudrate);
+
+
+const mp_obj_property_t busio_uart_baudrate_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&busio_uart_get_baudrate_obj,
+ (mp_obj_t)&busio_uart_set_baudrate_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
//| .. class:: busio.UART.Parity
//|
//| Enum-like class to define the parity used to verify correct data transfer.
@@ -274,6 +302,9 @@ STATIC const mp_rom_map_elem_t busio_uart_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
+ // Properties
+ { MP_ROM_QSTR(MP_QSTR_baudrate), MP_ROM_PTR(&busio_uart_baudrate_obj) },
+
// Nested Enum-like Classes.
{ MP_ROM_QSTR(MP_QSTR_Parity), MP_ROM_PTR(&busio_uart_parity_type) },
};
diff --git a/shared-bindings/busio/UART.h b/shared-bindings/busio/UART.h
index 28196931a..fa39d8ad5 100644
--- a/shared-bindings/busio/UART.h
+++ b/shared-bindings/busio/UART.h
@@ -55,6 +55,10 @@ extern size_t common_hal_busio_uart_read(busio_uart_obj_t *self,
extern size_t common_hal_busio_uart_write(busio_uart_obj_t *self,
const uint8_t *data, size_t len, int *errcode);
+extern uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self);
+extern void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate);
+
+
extern uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self);
extern bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self);
diff --git a/shared-bindings/busio/__init__.c b/shared-bindings/busio/__init__.c
index 6956e3c3d..958ee062a 100644
--- a/shared-bindings/busio/__init__.c
+++ b/shared-bindings/busio/__init__.c
@@ -32,9 +32,9 @@
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/busio/__init__.h"
#include "shared-bindings/busio/I2C.h"
-//xxxx #include "shared-bindings/busio/OneWire.h"
+#include "shared-bindings/busio/OneWire.h"
#include "shared-bindings/busio/SPI.h"
-//xxxx #include "shared-bindings/busio/UART.h"
+#include "shared-bindings/busio/UART.h"
#include "shared-bindings/busio/__init__.h"
#include "py/runtime.h"
@@ -89,8 +89,8 @@ STATIC const mp_rom_map_elem_t busio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_busio) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&busio_i2c_type) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&busio_spi_type) },
- //xxxx { MP_ROM_QSTR(MP_QSTR_OneWire), MP_ROM_PTR(&busio_onewire_type) },
- //xxxx { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&busio_uart_type) },
+ { MP_ROM_QSTR(MP_QSTR_OneWire), MP_ROM_PTR(&busio_onewire_type) },
+ { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&busio_uart_type) },
};
STATIC MP_DEFINE_CONST_DICT(busio_module_globals, busio_module_globals_table);