Skip to content

Commit 5f101f3

Browse files
committed
Add dummy UART implementation to nrf so it builds with UART turned on. Also add OneWire.
1 parent 9b4477e commit 5f101f3

File tree

4 files changed

+177
-3
lines changed

4 files changed

+177
-3
lines changed

ports/nrf/Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ SRC_COMMON_HAL += \
202202
busio/__init__.c\
203203
busio/I2C.c \
204204
busio/SPI.c \
205+
busio/UART.c \
205206
pulseio/__init__.c \
206207
pulseio/PulseIn.c \
207208
pulseio/PulseOut.c \
@@ -211,6 +212,7 @@ SRC_COMMON_HAL += \
211212
# These don't have corresponding files in each port but are still located in
212213
# shared-bindings to make it clear what the contents of the modules are.
213214
SRC_BINDINGS_ENUMS = \
215+
busio/OneWire.c \
214216
digitalio/Direction.c \
215217
digitalio/DriveMode.c \
216218
digitalio/Pull.c \
@@ -234,10 +236,10 @@ SRC_SHARED_MODULE = \
234236
bitbangio/__init__.c \
235237
bitbangio/I2C.c \
236238
bitbangio/OneWire.c \
237-
bitbangio/SPI.c
239+
bitbangio/SPI.c \
240+
busio/OneWire.c \
238241

239-
# busio/OneWire.c \
240-
uheap/__init__.c \
242+
# uheap/__init__.c \
241243
ustack/__init__.c
242244

243245
SRC_SHARED_BINDINGS = \

ports/nrf/common-hal/busio/OneWire.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Scott Shawcroft
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_ONEWIRE_H
28+
#define MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_ONEWIRE_H
29+
30+
// Use bitbangio.
31+
#include "shared-module/busio/OneWire.h"
32+
33+
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_ONEWIRE_H

ports/nrf/common-hal/busio/UART.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Damien P. George
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "shared-bindings/microcontroller/__init__.h"
28+
#include "shared-bindings/busio/UART.h"
29+
30+
#include "mpconfigport.h"
31+
#include "py/gc.h"
32+
#include "py/mperrno.h"
33+
#include "py/runtime.h"
34+
#include "py/stream.h"
35+
36+
#include "tick.h"
37+
38+
#include "pins.h"
39+
40+
void common_hal_busio_uart_construct(busio_uart_obj_t *self,
41+
const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate,
42+
uint8_t bits, uart_parity_t parity, uint8_t stop, uint32_t timeout,
43+
uint8_t receiver_buffer_size) {
44+
mp_raise_NotImplementedError("busio.UART not yet implemented");
45+
}
46+
47+
bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) {
48+
mp_raise_NotImplementedError("busio.UART not yet implemented");
49+
}
50+
51+
void common_hal_busio_uart_deinit(busio_uart_obj_t *self) {
52+
mp_raise_NotImplementedError("busio.UART not yet implemented");
53+
if (common_hal_busio_uart_deinited(self)) {
54+
return;
55+
}
56+
// Do deinit;
57+
}
58+
59+
// Read characters.
60+
size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t len, int *errcode) {
61+
mp_raise_NotImplementedError("busio.UART not yet implemented");
62+
return 0;
63+
}
64+
65+
// Write characters.
66+
size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data, size_t len, int *errcode) {
67+
mp_raise_NotImplementedError("busio.UART not yet implemented");
68+
return 0;
69+
}
70+
71+
uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self) {
72+
mp_raise_NotImplementedError("busio.UART not yet implemented");
73+
return self->baudrate;
74+
}
75+
76+
void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate) {
77+
mp_raise_NotImplementedError("busio.UART not yet implemented");
78+
self->baudrate = baudrate;
79+
}
80+
81+
uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) {
82+
mp_raise_NotImplementedError("busio.UART not yet implemented");
83+
return 0;
84+
}
85+
86+
bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) {
87+
mp_raise_NotImplementedError("busio.UART not yet implemented");
88+
return false;
89+
}

ports/nrf/common-hal/busio/UART.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Scott Shawcroft
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_UART_H
28+
#define MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_UART_H
29+
30+
#include "common-hal/microcontroller/Pin.h"
31+
32+
#include "py/obj.h"
33+
34+
typedef struct {
35+
mp_obj_base_t base;
36+
uint8_t rx_pin;
37+
uint8_t tx_pin;
38+
uint8_t character_bits;
39+
bool rx_error;
40+
uint32_t baudrate;
41+
uint32_t timeout_ms;
42+
// Index of the oldest received character.
43+
uint32_t buffer_start;
44+
// Index of the next available spot to store a character.
45+
uint32_t buffer_size;
46+
uint32_t buffer_length;
47+
uint8_t* buffer;
48+
} busio_uart_obj_t;
49+
50+
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_UART_H

0 commit comments

Comments
 (0)