Skip to content

Commit bc510e7

Browse files
committed
merge 3.0.2 to master
2 parents 53fcc5a + 2dd9407 commit bc510e7

File tree

16 files changed

+177
-90
lines changed

16 files changed

+177
-90
lines changed

.travis.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ compiler:
55
- gcc
66
git:
77
depth: 1
8+
9+
# Put a representative board from each port or sub-port near the top
10+
# to determine more quickly whether that port is going to build or not.
811
env:
912
- TRAVIS_TEST=unix
1013
- TRAVIS_TEST=docs
@@ -15,24 +18,25 @@ env:
1518
- TRAVIS_BOARD=trinket_m0
1619
- TRAVIS_BOARD=feather_m4_express
1720
- TRAVIS_BOARD=grandcentral_m4_express
18-
- TRAVIS_BOARD=feather_radiofruit_zigbee
1921
- TRAVIS_BOARD=arduino_zero
2022
- TRAVIS_BOARD=circuitplayground_express_crickit
21-
- TRAVIS_BOARD=feather_m0_basic
2223
- TRAVIS_BOARD=feather_m0_adalogger
23-
- TRAVIS_BOARD=feather_m0_rfm69
24-
- TRAVIS_BOARD=feather_m0_rfm9x
24+
- TRAVIS_BOARD=feather_m0_basic
2525
- TRAVIS_BOARD=feather_m0_express
2626
- TRAVIS_BOARD=feather_m0_express_crickit
27+
- TRAVIS_BOARD=feather_m0_rfm69
28+
- TRAVIS_BOARD=feather_m0_rfm9x
29+
- TRAVIS_BOARD=feather_nrf52832
30+
- TRAVIS_BOARD=feather_nrf52840_express
31+
- TRAVIS_BOARD=feather_radiofruit_zigbee
32+
- TRAVIS_BOARD=gemma_m0
33+
- TRAVIS_BOARD=hallowing_m0_express
2734
- TRAVIS_BOARD=itsybitsy_m0_express
2835
- TRAVIS_BOARD=itsybitsy_m4_express
2936
- TRAVIS_BOARD=metro_m0_express
3037
- TRAVIS_BOARD=metro_m4_express
38+
- TRAVIS_BOARD=pca10059
3139
- TRAVIS_BOARD=pirkey_m0
32-
- TRAVIS_BOARD=gemma_m0
33-
- TRAVIS_BOARD=hallowing_m0_express
34-
- TRAVIS_BOARD=feather_nrf52832
35-
- TRAVIS_BOARD=feather_nrf52840_express
3640
- TRAVIS_BOARD=trellis_m4_express
3741

3842
addons:

ports/atmel-samd/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ else
113113
# -finline-limit=80 or so is similar to not having it on.
114114
# There is no simple default value, though.
115115
ifdef INTERNAL_FLASH_FILESYSTEM
116-
CFLAGS += -finline-limit=55
116+
CFLAGS += -finline-limit=50
117117
endif
118118
ifdef CFLAGS_INLINE_LIMIT
119119
CFLAGS += -finline-limit=$(CFLAGS_INLINE_LIMIT)

ports/atmel-samd/board_busses.c

Lines changed: 73 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -34,81 +34,96 @@
3434
#include "samd/pins.h"
3535
#include "py/runtime.h"
3636

37-
#if !defined(DEFAULT_I2C_BUS_SDA) || !defined(DEFAULT_I2C_BUS_SCL)
38-
STATIC mp_obj_t board_i2c(void) {
39-
mp_raise_NotImplementedError(translate("No default I2C bus"));
40-
return NULL;
41-
}
42-
#else
43-
STATIC mp_obj_t i2c_singleton = NULL;
37+
#define BOARD_I2C (defined(DEFAULT_I2C_BUS_SDA) && defined(DEFAULT_I2C_BUS_SCL))
38+
#define BOARD_SPI (defined(DEFAULT_SPI_BUS_SCK) && defined(DEFAULT_SPI_BUS_MISO) && defined(DEFAULT_SPI_BUS_MOSI))
39+
#define BOARD_UART (defined(DEFAULT_UART_BUS_RX) && defined(DEFAULT_UART_BUS_TX))
4440

45-
STATIC mp_obj_t board_i2c(void) {
41+
#if BOARD_I2C
42+
STATIC mp_obj_t i2c_singleton = NULL;
4643

47-
if (i2c_singleton == NULL) {
48-
busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t);
49-
self->base.type = &busio_i2c_type;
44+
STATIC mp_obj_t board_i2c(void) {
5045

51-
assert_pin_free(DEFAULT_I2C_BUS_SDA);
52-
assert_pin_free(DEFAULT_I2C_BUS_SCL);
53-
common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000, 0);
54-
i2c_singleton = (mp_obj_t)self;
55-
}
56-
return i2c_singleton;
46+
if (i2c_singleton == NULL) {
47+
busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t);
48+
self->base.type = &busio_i2c_type;
5749

50+
assert_pin_free(DEFAULT_I2C_BUS_SDA);
51+
assert_pin_free(DEFAULT_I2C_BUS_SCL);
52+
common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000, 0);
53+
i2c_singleton = (mp_obj_t)self;
5854
}
55+
return i2c_singleton;
56+
}
57+
#else
58+
STATIC mp_obj_t board_i2c(void) {
59+
mp_raise_NotImplementedError(translate("No default I2C bus"));
60+
return NULL;
61+
}
5962
#endif
6063
MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
6164

62-
#if !defined(DEFAULT_SPI_BUS_SCK) || !defined(DEFAULT_SPI_BUS_MISO) || !defined(DEFAULT_SPI_BUS_MOSI)
63-
STATIC mp_obj_t board_spi(void) {
64-
mp_raise_NotImplementedError(translate("No default SPI bus"));
65-
return NULL;
65+
#if BOARD_SPI
66+
STATIC mp_obj_t spi_singleton = NULL;
67+
68+
STATIC mp_obj_t board_spi(void) {
69+
if (spi_singleton == NULL) {
70+
busio_spi_obj_t *self = m_new_obj(busio_spi_obj_t);
71+
self->base.type = &busio_spi_type;
72+
assert_pin_free(DEFAULT_SPI_BUS_SCK);
73+
assert_pin_free(DEFAULT_SPI_BUS_MOSI);
74+
assert_pin_free(DEFAULT_SPI_BUS_MISO);
75+
const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_SCK);
76+
const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI);
77+
const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO);
78+
common_hal_busio_spi_construct(self, clock, mosi, miso);
79+
spi_singleton = (mp_obj_t)self;
6680
}
81+
return spi_singleton;
82+
}
6783
#else
68-
STATIC mp_obj_t spi_singleton = NULL;
69-
70-
STATIC mp_obj_t board_spi(void) {
71-
72-
if (spi_singleton == NULL) {
73-
busio_spi_obj_t *self = m_new_obj(busio_spi_obj_t);
74-
self->base.type = &busio_spi_type;
75-
assert_pin_free(DEFAULT_SPI_BUS_SCK);
76-
assert_pin_free(DEFAULT_SPI_BUS_MOSI);
77-
assert_pin_free(DEFAULT_SPI_BUS_MISO);
78-
const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_SCK);
79-
const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI);
80-
const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO);
81-
common_hal_busio_spi_construct(self, clock, mosi, miso);
82-
spi_singleton = (mp_obj_t)self;
83-
}
84-
return spi_singleton;
85-
}
84+
STATIC mp_obj_t board_spi(void) {
85+
mp_raise_NotImplementedError(translate("No default SPI bus"));
86+
return NULL;
87+
}
8688
#endif
8789
MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi);
8890

89-
#if !defined(DEFAULT_UART_BUS_RX) || !defined(DEFAULT_UART_BUS_TX)
90-
STATIC mp_obj_t board_uart(void) {
91-
mp_raise_NotImplementedError(translate("No default UART bus"));
92-
return NULL;
93-
}
94-
#else
95-
STATIC mp_obj_t uart_singleton = NULL;
91+
#if BOARD_UART
92+
STATIC mp_obj_t uart_singleton = NULL;
9693

97-
STATIC mp_obj_t board_uart(void) {
98-
if (uart_singleton == NULL) {
99-
busio_uart_obj_t *self = m_new_obj(busio_uart_obj_t);
100-
self->base.type = &busio_uart_type;
94+
STATIC mp_obj_t board_uart(void) {
95+
if (uart_singleton == NULL) {
96+
busio_uart_obj_t *self = m_new_obj(busio_uart_obj_t);
97+
self->base.type = &busio_uart_type;
10198

102-
assert_pin_free(DEFAULT_UART_BUS_RX);
103-
assert_pin_free(DEFAULT_UART_BUS_TX);
99+
assert_pin_free(DEFAULT_UART_BUS_RX);
100+
assert_pin_free(DEFAULT_UART_BUS_TX);
104101

105-
const mcu_pin_obj_t* rx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RX);
106-
const mcu_pin_obj_t* tx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_TX);
102+
const mcu_pin_obj_t* rx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RX);
103+
const mcu_pin_obj_t* tx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_TX);
107104

108-
common_hal_busio_uart_construct(self, tx, rx, 9600, 8, PARITY_NONE, 1, 1000, 64);
109-
uart_singleton = (mp_obj_t)self;
110-
}
111-
return uart_singleton;
105+
common_hal_busio_uart_construct(self, tx, rx, 9600, 8, PARITY_NONE, 1, 1000, 64);
106+
uart_singleton = (mp_obj_t)self;
112107
}
108+
return uart_singleton;
109+
}
110+
#else
111+
STATIC mp_obj_t board_uart(void) {
112+
mp_raise_NotImplementedError(translate("No default UART bus"));
113+
return NULL;
114+
}
113115
#endif
114116
MP_DEFINE_CONST_FUN_OBJ_0(board_uart_obj, board_uart);
117+
118+
119+
void reset_board_busses(void) {
120+
#if BOARD_I2C
121+
i2c_singleton = NULL;
122+
#endif
123+
#if BOARD_SPI
124+
spi_singleton = NULL;
125+
#endif
126+
#if BOARD_UART
127+
uart_singleton = NULL;
128+
#endif
129+
}

ports/atmel-samd/board_busses.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ extern mp_obj_fun_builtin_fixed_t board_spi_obj;
3636
void board_uart(void);
3737
extern mp_obj_fun_builtin_fixed_t board_uart_obj;
3838

39+
void reset_board_busses(void);
40+
3941
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_BUSSES_H

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@
6262
#define IGNORE_PIN_PA24 1
6363
#define IGNORE_PIN_PA25 1
6464

65-
#define CIRCUITPY_DISPLAYIO
65+
#define CIRCUITPY_DISPLAYIO (1)

ports/atmel-samd/common-hal/busio/UART.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
133133

134134
if (rx && receiver_buffer_size > 0) {
135135
self->buffer_length = receiver_buffer_size;
136-
self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false, false);
136+
// Initially allocate the UART's buffer in the long-lived part of the
137+
// heap. UARTs are generally long-lived objects, but the "make long-
138+
// lived" machinery is incapable of moving internal pointers like
139+
// self->buffer, so do it manually. (However, as long as internal
140+
// pointers like this are NOT moved, allocating the buffer
141+
// in the long-lived pool is not strictly necessary)
142+
self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false, true);
137143
if (self->buffer == NULL) {
138144
common_hal_busio_uart_deinit(self);
139145
mp_raise_msg(&mp_type_MemoryError, translate("Failed to allocate RX buffer"));
@@ -268,7 +274,7 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
268274
#ifdef MICROPY_VM_HOOK_LOOP
269275
MICROPY_VM_HOOK_LOOP
270276
#endif
271-
// If we are zero timeout, make sure we don't loop again (in the event
277+
// If we are zero timeout, make sure we don't loop again (in the event
272278
// we read in under 1ms)
273279
if (self->timeout_ms == 0)
274280
break;
@@ -344,7 +350,18 @@ void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrat
344350
}
345351

346352
uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) {
347-
return self->buffer_size;
353+
// This assignment is only here because the usart_async routines take a *const argument.
354+
struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc;
355+
struct usart_async_status async_status;
356+
usart_async_get_status(usart_desc_p, &async_status);
357+
return async_status.rxcnt;
358+
}
359+
360+
void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self) {
361+
// This assignment is only here because the usart_async routines take a *const argument.
362+
struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc;
363+
usart_async_flush_rx_buffer(usart_desc_p);
364+
348365
}
349366

350367
bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) {

ports/atmel-samd/common-hal/busio/UART.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ typedef struct {
4242
bool rx_error;
4343
uint32_t baudrate;
4444
uint32_t timeout_ms;
45-
// Index of the oldest received character.
46-
uint32_t buffer_start;
47-
// Index of the next available spot to store a character.
48-
uint32_t buffer_size;
4945
uint32_t buffer_length;
5046
uint8_t* buffer;
5147
} busio_uart_obj_t;

ports/atmel-samd/common-hal/neopixel_write/__init__.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,16 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
109109
asm("nop; nop;");
110110
#endif
111111
#ifdef SAMD51
112-
delay_cycles(3);
112+
delay_cycles(2);
113113
#endif
114-
if(p & bitMask) {
114+
if((p & bitMask) != 0) {
115115
// This is the high delay unique to a one bit.
116116
// For the SK6812 its 0.3us
117117
#ifdef SAMD21
118118
asm("nop; nop; nop; nop; nop; nop; nop;");
119119
#endif
120120
#ifdef SAMD51
121-
delay_cycles(11);
121+
delay_cycles(3);
122122
#endif
123123
*clr = pinMask;
124124
} else {
@@ -129,7 +129,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
129129
asm("nop; nop;");
130130
#endif
131131
#ifdef SAMD51
132-
delay_cycles(3);
132+
delay_cycles(2);
133133
#endif
134134
}
135135
if((bitMask >>= 1) != 0) {
@@ -140,7 +140,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
140140
asm("nop; nop; nop; nop; nop;");
141141
#endif
142142
#ifdef SAMD51
143-
delay_cycles(20);
143+
delay_cycles(4);
144144
#endif
145145
} else {
146146
if(ptr >= end) break;
@@ -151,7 +151,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
151151
// above operations take.
152152
// For the SK6812 its 0.6us +- 0.15us
153153
#ifdef SAMD51
154-
delay_cycles(15);
154+
delay_cycles(3);
155155
#endif
156156
}
157157
}

ports/atmel-samd/common-hal/pulseio/PWMOut.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ uint8_t tcc_refcount[TCC_INST_NUM];
5252

5353
// This bitmask keeps track of which channels of a TCC are currently claimed.
5454
#ifdef SAMD21
55-
uint8_t tcc_channels[3] = {0xf0, 0xfc, 0xfc};
55+
uint8_t tcc_channels[3]; // Set by pwmout_reset() to {0xf0, 0xfc, 0xfc} initially.
5656
#endif
5757
#ifdef SAMD51
58-
uint8_t tcc_channels[5] = {0xc0, 0xf0, 0xf8, 0xfc, 0xfc};
58+
uint8_t tcc_channels[5]; // Set by pwmout_reset() to {0xc0, 0xf0, 0xf8, 0xfc, 0xfc} initially.
5959
#endif
6060

6161
void pwmout_reset(void) {
@@ -76,7 +76,7 @@ void pwmout_reset(void) {
7676
for (uint8_t j = 0; j < tcc_cc_num[i]; j++) {
7777
mask <<= 1;
7878
}
79-
tcc_channels[i] = 0xf0;
79+
tcc_channels[i] = mask;
8080
tccs[i]->CTRLA.bit.SWRST = 1;
8181
}
8282
Tc *tcs[TC_INST_NUM] = TC_INSTS;
@@ -123,7 +123,7 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
123123
// Figure out which timer we are using.
124124

125125
// First see if a tcc is already going with the frequency we want and our
126-
// channel is unused. tc's don't have neough channels to share.
126+
// channel is unused. tc's don't have enough channels to share.
127127
const pin_timer_t* timer = NULL;
128128
uint8_t mux_position = 0;
129129
if (!variable_frequency) {
@@ -140,6 +140,9 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
140140
if (tcc->CTRLA.bit.ENABLE == 1 && channel_ok(t)) {
141141
timer = t;
142142
mux_position = j;
143+
// Claim channel.
144+
tcc_channels[timer->index] |= (1 << tcc_channel(timer));
145+
143146
}
144147
}
145148
}

ports/atmel-samd/supervisor/port.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "samd/external_interrupts.h"
6262
#include "samd/dma.h"
6363
#include "shared-bindings/rtc/__init__.h"
64+
#include "board_busses.h"
6465
#include "tick.h"
6566
#include "usb.h"
6667

@@ -278,6 +279,8 @@ void reset_port(void) {
278279

279280
reset_all_pins();
280281

282+
reset_board_busses();
283+
281284
// Output clocks for debugging.
282285
// not supported by SAMD51G; uncomment for SAMD51J or update for 51G
283286
// #ifdef SAMD51

0 commit comments

Comments
 (0)