Skip to content

Commit 1eb412b

Browse files
authored
Merge pull request adafruit#845 from matt-land/feature-default-serial
Feature: default UART (serial)
2 parents 8581ee3 + 06b293a commit 1eb412b

File tree

38 files changed

+102
-4
lines changed

38 files changed

+102
-4
lines changed

ports/atmel-samd/board_busses.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include "shared-bindings/busio/I2C.h"
2828
#include "shared-bindings/busio/SPI.h"
29+
#include "shared-bindings/busio/UART.h"
30+
2931
#include "shared-bindings/microcontroller/Pin.h"
3032
#include "mpconfigboard.h"
3133
#include "pins.h"
@@ -34,13 +36,10 @@
3436

3537

3638
#if !defined(DEFAULT_I2C_BUS_SDA) || !defined(DEFAULT_I2C_BUS_SCL)
37-
3839
STATIC mp_obj_t board_i2c(void) {
39-
//board_i2c_obj = NULL;
4040
mp_raise_NotImplementedError("No default I2C bus");
4141
return NULL;
4242
}
43-
4443
#else
4544
STATIC mp_obj_t i2c_singleton = NULL;
4645

@@ -59,7 +58,6 @@
5958

6059
}
6160
#endif
62-
6361
MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
6462

6563
#if !defined(DEFAULT_SPI_BUS_SCK) || !defined(DEFAULT_SPI_BUS_MISO) || !defined(DEFAULT_SPI_BUS_MOSI)
@@ -88,3 +86,30 @@ MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
8886
}
8987
#endif
9088
MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi);
89+
90+
#if !defined(DEFAULT_UART_BUS_RX) || !defined(DEFAULT_UART_BUS_TX)
91+
STATIC mp_obj_t board_uart(void) {
92+
mp_raise_NotImplementedError("No default UART bus");
93+
return NULL;
94+
}
95+
#else
96+
STATIC mp_obj_t uart_singleton = NULL;
97+
98+
STATIC mp_obj_t board_uart(void) {
99+
if (uart_singleton == NULL) {
100+
busio_uart_obj_t *self = m_new_obj(busio_uart_obj_t);
101+
self->base.type = &busio_uart_type;
102+
103+
assert_pin_free(DEFAULT_UART_BUS_RX);
104+
assert_pin_free(DEFAULT_UART_BUS_TX);
105+
106+
const mcu_pin_obj_t* rx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RX);
107+
const mcu_pin_obj_t* tx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_TX);
108+
109+
common_hal_busio_uart_construct(self, tx, rx, 9600, 8, PARITY_NONE, 1, 1000, 64);
110+
uart_singleton = (mp_obj_t)self;
111+
}
112+
return uart_singleton;
113+
}
114+
#endif
115+
MP_DEFINE_CONST_FUN_OBJ_0(board_uart_obj, board_uart);

ports/atmel-samd/board_busses.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ extern mp_obj_fun_builtin_fixed_t board_i2c_obj;
3333
void board_spi(void);
3434
extern mp_obj_fun_builtin_fixed_t board_spi_obj;
3535

36+
void board_uart(void);
37+
extern mp_obj_fun_builtin_fixed_t board_uart_obj;
38+
3639
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_BUSSES_H

ports/atmel-samd/boards/arduino_zero/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@
2121
#define DEFAULT_SPI_BUS_SCK (&pin_PB11)
2222
#define DEFAULT_SPI_BUS_MOSI (&pin_PB10)
2323
#define DEFAULT_SPI_BUS_MISO (&pin_PA12)
24+
25+
#define DEFAULT_UART_BUS_RX (&pin_PA11)
26+
#define DEFAULT_UART_BUS_TX (&pin_PA10)

ports/atmel-samd/boards/arduino_zero/pins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
3434
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) },
3535
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
3636
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
37+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
3738
};
3839
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,6 @@
6565
#define DEFAULT_SPI_BUS_SCK (&pin_PA05)
6666
#define DEFAULT_SPI_BUS_MOSI (&pin_PA07)
6767
#define DEFAULT_SPI_BUS_MISO (&pin_PA06)
68+
69+
#define DEFAULT_UART_BUS_RX (&pin_PB09)
70+
#define DEFAULT_UART_BUS_TX (&pin_PB08)

ports/atmel-samd/boards/circuitplayground_express/pins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
5959
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA06) },
6060
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
6161
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
62+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
6263
};
6364
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
#define DEFAULT_SPI_BUS_SCK (&pin_PB11)
2020
#define DEFAULT_SPI_BUS_MOSI (&pin_PB10)
2121
#define DEFAULT_SPI_BUS_MISO (&pin_PA12)
22+
23+
#define DEFAULT_UART_BUS_RX (&pin_PA11)
24+
#define DEFAULT_UART_BUS_TX (&pin_PA10)

ports/atmel-samd/boards/feather_m0_adalogger/pins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
3333
{ MP_ROM_QSTR(MP_QSTR_RED_LED), MP_ROM_PTR(&pin_PA17) },
3434
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
3535
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
36+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
3637
};
3738
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@
2020
#define DEFAULT_SPI_BUS_SCK (&pin_PB11)
2121
#define DEFAULT_SPI_BUS_MOSI (&pin_PB10)
2222
#define DEFAULT_SPI_BUS_MISO (&pin_PA12)
23+
24+
#define DEFAULT_UART_BUS_RX (&pin_PA11)
25+
#define DEFAULT_UART_BUS_TX (&pin_PA10)

ports/atmel-samd/boards/feather_m0_basic/pins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
2626
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) },
2727
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
2828
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
29+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
2930
};
3031
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy