diff options
| author | Dan Halbert <halbert@halwitz.org> | 2018-02-21 22:52:33 -0500 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2018-02-21 22:53:17 -0500 |
| commit | 5f101f3535d29f0a522440e6529525e642856696 (patch) | |
| tree | 6cee41e3351d554616248ed076e7b5cbf482f798 | |
| parent | 9b4477e1dc088d18127838310b828514cb33edea (diff) | |
Add dummy UART implementation to nrf so it builds with UART turned on. Also add OneWire.
| -rw-r--r-- | ports/nrf/Makefile | 8 | ||||
| -rw-r--r-- | ports/nrf/common-hal/busio/OneWire.h | 33 | ||||
| -rw-r--r-- | ports/nrf/common-hal/busio/UART.c | 89 | ||||
| -rw-r--r-- | ports/nrf/common-hal/busio/UART.h | 50 |
4 files changed, 177 insertions, 3 deletions
diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index c1bef4672..7ed14aa47 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -202,6 +202,7 @@ SRC_COMMON_HAL += \ busio/__init__.c\ busio/I2C.c \ busio/SPI.c \ + busio/UART.c \ pulseio/__init__.c \ pulseio/PulseIn.c \ pulseio/PulseOut.c \ @@ -211,6 +212,7 @@ SRC_COMMON_HAL += \ # These don't have corresponding files in each port but are still located in # shared-bindings to make it clear what the contents of the modules are. SRC_BINDINGS_ENUMS = \ + busio/OneWire.c \ digitalio/Direction.c \ digitalio/DriveMode.c \ digitalio/Pull.c \ @@ -234,10 +236,10 @@ SRC_SHARED_MODULE = \ bitbangio/__init__.c \ bitbangio/I2C.c \ bitbangio/OneWire.c \ - bitbangio/SPI.c + bitbangio/SPI.c \ + busio/OneWire.c \ -# busio/OneWire.c \ - uheap/__init__.c \ +# uheap/__init__.c \ ustack/__init__.c SRC_SHARED_BINDINGS = \ diff --git a/ports/nrf/common-hal/busio/OneWire.h b/ports/nrf/common-hal/busio/OneWire.h new file mode 100644 index 000000000..821cc64c1 --- /dev/null +++ b/ports/nrf/common-hal/busio/OneWire.h @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_ONEWIRE_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_ONEWIRE_H + +// Use bitbangio. +#include "shared-module/busio/OneWire.h" + +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_ONEWIRE_H diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c new file mode 100644 index 000000000..dbc6a8533 --- /dev/null +++ b/ports/nrf/common-hal/busio/UART.c @@ -0,0 +1,89 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "shared-bindings/microcontroller/__init__.h" +#include "shared-bindings/busio/UART.h" + +#include "mpconfigport.h" +#include "py/gc.h" +#include "py/mperrno.h" +#include "py/runtime.h" +#include "py/stream.h" + +#include "tick.h" + +#include "pins.h" + +void common_hal_busio_uart_construct(busio_uart_obj_t *self, + const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate, + uint8_t bits, uart_parity_t parity, uint8_t stop, uint32_t timeout, + uint8_t receiver_buffer_size) { + mp_raise_NotImplementedError("busio.UART not yet implemented"); +} + +bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) { + mp_raise_NotImplementedError("busio.UART not yet implemented"); +} + +void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { + mp_raise_NotImplementedError("busio.UART not yet implemented"); + if (common_hal_busio_uart_deinited(self)) { + return; + } + // Do deinit; +} + +// Read characters. +size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t len, int *errcode) { + mp_raise_NotImplementedError("busio.UART not yet implemented"); + return 0; +} + +// Write characters. +size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data, size_t len, int *errcode) { + mp_raise_NotImplementedError("busio.UART not yet implemented"); + return 0; +} + +uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self) { + mp_raise_NotImplementedError("busio.UART not yet implemented"); + return self->baudrate; +} + +void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate) { + mp_raise_NotImplementedError("busio.UART not yet implemented"); + self->baudrate = baudrate; +} + +uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) { + mp_raise_NotImplementedError("busio.UART not yet implemented"); + return 0; +} + +bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) { + mp_raise_NotImplementedError("busio.UART not yet implemented"); + return false; +} diff --git a/ports/nrf/common-hal/busio/UART.h b/ports/nrf/common-hal/busio/UART.h new file mode 100644 index 000000000..7c0493e37 --- /dev/null +++ b/ports/nrf/common-hal/busio/UART.h @@ -0,0 +1,50 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_UART_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_UART_H + +#include "common-hal/microcontroller/Pin.h" + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + uint8_t rx_pin; + uint8_t tx_pin; + uint8_t character_bits; + bool rx_error; + uint32_t baudrate; + uint32_t timeout_ms; + // Index of the oldest received character. + uint32_t buffer_start; + // Index of the next available spot to store a character. + uint32_t buffer_size; + uint32_t buffer_length; + uint8_t* buffer; +} busio_uart_obj_t; + +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_UART_H |
