summaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-09-18 15:38:12 -0400
committerDan Halbert <halbert@halwitz.org>2018-09-18 15:38:12 -0400
commitbc510e714f4fde7af949c525ced5c8a4db53bce0 (patch)
tree40be4302742b016cc98f4f3966058e84756b7f99 /ports
parent53fcc5a3a207d606c7e3ee2c0c877295a0fb4e2f (diff)
parent2dd9407f2125e724b4b9a1cdd4d0d0cc01284b31 (diff)
merge 3.0.2 to master
Diffstat (limited to 'ports')
-rw-r--r--ports/atmel-samd/Makefile2
-rw-r--r--ports/atmel-samd/board_busses.c131
-rw-r--r--ports/atmel-samd/board_busses.h2
-rw-r--r--ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h2
-rw-r--r--ports/atmel-samd/common-hal/busio/UART.c23
-rw-r--r--ports/atmel-samd/common-hal/busio/UART.h4
-rw-r--r--ports/atmel-samd/common-hal/neopixel_write/__init__.c12
-rw-r--r--ports/atmel-samd/common-hal/pulseio/PWMOut.c11
-rw-r--r--ports/atmel-samd/supervisor/port.c3
-rw-r--r--ports/atmel-samd/usb.c2
-rw-r--r--ports/esp8266/common-hal/busio/UART.c3
-rw-r--r--ports/nrf/common-hal/busio/UART.c4
12 files changed, 121 insertions, 78 deletions
diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile
index 11b9a0de6..f8e5051c2 100644
--- a/ports/atmel-samd/Makefile
+++ b/ports/atmel-samd/Makefile
@@ -113,7 +113,7 @@ else
# -finline-limit=80 or so is similar to not having it on.
# There is no simple default value, though.
ifdef INTERNAL_FLASH_FILESYSTEM
- CFLAGS += -finline-limit=55
+ CFLAGS += -finline-limit=50
endif
ifdef CFLAGS_INLINE_LIMIT
CFLAGS += -finline-limit=$(CFLAGS_INLINE_LIMIT)
diff --git a/ports/atmel-samd/board_busses.c b/ports/atmel-samd/board_busses.c
index e36541ca9..424c9cc08 100644
--- a/ports/atmel-samd/board_busses.c
+++ b/ports/atmel-samd/board_busses.c
@@ -34,81 +34,96 @@
#include "samd/pins.h"
#include "py/runtime.h"
-#if !defined(DEFAULT_I2C_BUS_SDA) || !defined(DEFAULT_I2C_BUS_SCL)
- STATIC mp_obj_t board_i2c(void) {
- mp_raise_NotImplementedError(translate("No default I2C bus"));
- return NULL;
- }
-#else
- STATIC mp_obj_t i2c_singleton = NULL;
+#define BOARD_I2C (defined(DEFAULT_I2C_BUS_SDA) && defined(DEFAULT_I2C_BUS_SCL))
+#define BOARD_SPI (defined(DEFAULT_SPI_BUS_SCK) && defined(DEFAULT_SPI_BUS_MISO) && defined(DEFAULT_SPI_BUS_MOSI))
+#define BOARD_UART (defined(DEFAULT_UART_BUS_RX) && defined(DEFAULT_UART_BUS_TX))
- STATIC mp_obj_t board_i2c(void) {
+#if BOARD_I2C
+STATIC mp_obj_t i2c_singleton = NULL;
- if (i2c_singleton == NULL) {
- busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t);
- self->base.type = &busio_i2c_type;
+STATIC mp_obj_t board_i2c(void) {
- assert_pin_free(DEFAULT_I2C_BUS_SDA);
- assert_pin_free(DEFAULT_I2C_BUS_SCL);
- common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000, 0);
- i2c_singleton = (mp_obj_t)self;
- }
- return i2c_singleton;
+ if (i2c_singleton == NULL) {
+ busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t);
+ self->base.type = &busio_i2c_type;
+ assert_pin_free(DEFAULT_I2C_BUS_SDA);
+ assert_pin_free(DEFAULT_I2C_BUS_SCL);
+ common_hal_busio_i2c_construct(self, DEFAULT_I2C_BUS_SCL, DEFAULT_I2C_BUS_SDA, 400000, 0);
+ i2c_singleton = (mp_obj_t)self;
}
+ return i2c_singleton;
+}
+#else
+STATIC mp_obj_t board_i2c(void) {
+ mp_raise_NotImplementedError(translate("No default I2C bus"));
+ return NULL;
+}
#endif
MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
-#if !defined(DEFAULT_SPI_BUS_SCK) || !defined(DEFAULT_SPI_BUS_MISO) || !defined(DEFAULT_SPI_BUS_MOSI)
- STATIC mp_obj_t board_spi(void) {
- mp_raise_NotImplementedError(translate("No default SPI bus"));
- return NULL;
+#if BOARD_SPI
+STATIC mp_obj_t spi_singleton = NULL;
+
+STATIC mp_obj_t board_spi(void) {
+ if (spi_singleton == NULL) {
+ busio_spi_obj_t *self = m_new_obj(busio_spi_obj_t);
+ self->base.type = &busio_spi_type;
+ assert_pin_free(DEFAULT_SPI_BUS_SCK);
+ assert_pin_free(DEFAULT_SPI_BUS_MOSI);
+ assert_pin_free(DEFAULT_SPI_BUS_MISO);
+ const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_SCK);
+ const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI);
+ const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO);
+ common_hal_busio_spi_construct(self, clock, mosi, miso);
+ spi_singleton = (mp_obj_t)self;
}
+ return spi_singleton;
+}
#else
- STATIC mp_obj_t spi_singleton = NULL;
-
- STATIC mp_obj_t board_spi(void) {
-
- if (spi_singleton == NULL) {
- busio_spi_obj_t *self = m_new_obj(busio_spi_obj_t);
- self->base.type = &busio_spi_type;
- assert_pin_free(DEFAULT_SPI_BUS_SCK);
- assert_pin_free(DEFAULT_SPI_BUS_MOSI);
- assert_pin_free(DEFAULT_SPI_BUS_MISO);
- const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_SCK);
- const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MOSI);
- const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(DEFAULT_SPI_BUS_MISO);
- common_hal_busio_spi_construct(self, clock, mosi, miso);
- spi_singleton = (mp_obj_t)self;
- }
- return spi_singleton;
- }
+STATIC mp_obj_t board_spi(void) {
+ mp_raise_NotImplementedError(translate("No default SPI bus"));
+ return NULL;
+}
#endif
MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi);
-#if !defined(DEFAULT_UART_BUS_RX) || !defined(DEFAULT_UART_BUS_TX)
- STATIC mp_obj_t board_uart(void) {
- mp_raise_NotImplementedError(translate("No default UART bus"));
- return NULL;
- }
-#else
- STATIC mp_obj_t uart_singleton = NULL;
+#if BOARD_UART
+STATIC mp_obj_t uart_singleton = NULL;
- STATIC mp_obj_t board_uart(void) {
- if (uart_singleton == NULL) {
- busio_uart_obj_t *self = m_new_obj(busio_uart_obj_t);
- self->base.type = &busio_uart_type;
+STATIC mp_obj_t board_uart(void) {
+ if (uart_singleton == NULL) {
+ busio_uart_obj_t *self = m_new_obj(busio_uart_obj_t);
+ self->base.type = &busio_uart_type;
- assert_pin_free(DEFAULT_UART_BUS_RX);
- assert_pin_free(DEFAULT_UART_BUS_TX);
+ assert_pin_free(DEFAULT_UART_BUS_RX);
+ assert_pin_free(DEFAULT_UART_BUS_TX);
- const mcu_pin_obj_t* rx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RX);
- const mcu_pin_obj_t* tx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_TX);
+ const mcu_pin_obj_t* rx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RX);
+ const mcu_pin_obj_t* tx = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_TX);
- common_hal_busio_uart_construct(self, tx, rx, 9600, 8, PARITY_NONE, 1, 1000, 64);
- uart_singleton = (mp_obj_t)self;
- }
- return uart_singleton;
+ common_hal_busio_uart_construct(self, tx, rx, 9600, 8, PARITY_NONE, 1, 1000, 64);
+ uart_singleton = (mp_obj_t)self;
}
+ return uart_singleton;
+}
+#else
+STATIC mp_obj_t board_uart(void) {
+ mp_raise_NotImplementedError(translate("No default UART bus"));
+ return NULL;
+}
#endif
MP_DEFINE_CONST_FUN_OBJ_0(board_uart_obj, board_uart);
+
+
+void reset_board_busses(void) {
+#if BOARD_I2C
+ i2c_singleton = NULL;
+#endif
+#if BOARD_SPI
+ spi_singleton = NULL;
+#endif
+#if BOARD_UART
+ uart_singleton = NULL;
+#endif
+}
diff --git a/ports/atmel-samd/board_busses.h b/ports/atmel-samd/board_busses.h
index a368885a5..08dd1aae1 100644
--- a/ports/atmel-samd/board_busses.h
+++ b/ports/atmel-samd/board_busses.h
@@ -36,4 +36,6 @@ extern mp_obj_fun_builtin_fixed_t board_spi_obj;
void board_uart(void);
extern mp_obj_fun_builtin_fixed_t board_uart_obj;
+void reset_board_busses(void);
+
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_BUSSES_H
diff --git a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h
index 977ba183f..8450882b9 100644
--- a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h
+++ b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h
@@ -62,4 +62,4 @@
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
-#define CIRCUITPY_DISPLAYIO
+#define CIRCUITPY_DISPLAYIO (1)
diff --git a/ports/atmel-samd/common-hal/busio/UART.c b/ports/atmel-samd/common-hal/busio/UART.c
index 005f1897e..71db7a8af 100644
--- a/ports/atmel-samd/common-hal/busio/UART.c
+++ b/ports/atmel-samd/common-hal/busio/UART.c
@@ -133,7 +133,13 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
if (rx && receiver_buffer_size > 0) {
self->buffer_length = receiver_buffer_size;
- self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false, false);
+ // Initially allocate the UART's buffer in the long-lived part of the
+ // heap. UARTs are generally long-lived objects, but the "make long-
+ // lived" machinery is incapable of moving internal pointers like
+ // self->buffer, so do it manually. (However, as long as internal
+ // pointers like this are NOT moved, allocating the buffer
+ // in the long-lived pool is not strictly necessary)
+ self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false, true);
if (self->buffer == NULL) {
common_hal_busio_uart_deinit(self);
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
#ifdef MICROPY_VM_HOOK_LOOP
MICROPY_VM_HOOK_LOOP
#endif
- // If we are zero timeout, make sure we don't loop again (in the event
+ // If we are zero timeout, make sure we don't loop again (in the event
// we read in under 1ms)
if (self->timeout_ms == 0)
break;
@@ -344,7 +350,18 @@ void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrat
}
uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) {
- return self->buffer_size;
+ // This assignment is only here because the usart_async routines take a *const argument.
+ struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc;
+ struct usart_async_status async_status;
+ usart_async_get_status(usart_desc_p, &async_status);
+ return async_status.rxcnt;
+}
+
+void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self) {
+ // This assignment is only here because the usart_async routines take a *const argument.
+ struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc;
+ usart_async_flush_rx_buffer(usart_desc_p);
+
}
bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) {
diff --git a/ports/atmel-samd/common-hal/busio/UART.h b/ports/atmel-samd/common-hal/busio/UART.h
index 685755a5d..f94df040f 100644
--- a/ports/atmel-samd/common-hal/busio/UART.h
+++ b/ports/atmel-samd/common-hal/busio/UART.h
@@ -42,10 +42,6 @@ typedef struct {
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;
diff --git a/ports/atmel-samd/common-hal/neopixel_write/__init__.c b/ports/atmel-samd/common-hal/neopixel_write/__init__.c
index 42813707c..b30ad47d4 100644
--- a/ports/atmel-samd/common-hal/neopixel_write/__init__.c
+++ b/ports/atmel-samd/common-hal/neopixel_write/__init__.c
@@ -109,16 +109,16 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
asm("nop; nop;");
#endif
#ifdef SAMD51
- delay_cycles(3);
+ delay_cycles(2);
#endif
- if(p & bitMask) {
+ if((p & bitMask) != 0) {
// This is the high delay unique to a one bit.
// For the SK6812 its 0.3us
#ifdef SAMD21
asm("nop; nop; nop; nop; nop; nop; nop;");
#endif
#ifdef SAMD51
- delay_cycles(11);
+ delay_cycles(3);
#endif
*clr = pinMask;
} else {
@@ -129,7 +129,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
asm("nop; nop;");
#endif
#ifdef SAMD51
- delay_cycles(3);
+ delay_cycles(2);
#endif
}
if((bitMask >>= 1) != 0) {
@@ -140,7 +140,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
asm("nop; nop; nop; nop; nop;");
#endif
#ifdef SAMD51
- delay_cycles(20);
+ delay_cycles(4);
#endif
} else {
if(ptr >= end) break;
@@ -151,7 +151,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
// above operations take.
// For the SK6812 its 0.6us +- 0.15us
#ifdef SAMD51
- delay_cycles(15);
+ delay_cycles(3);
#endif
}
}
diff --git a/ports/atmel-samd/common-hal/pulseio/PWMOut.c b/ports/atmel-samd/common-hal/pulseio/PWMOut.c
index a115a0b73..825bdd181 100644
--- a/ports/atmel-samd/common-hal/pulseio/PWMOut.c
+++ b/ports/atmel-samd/common-hal/pulseio/PWMOut.c
@@ -52,10 +52,10 @@ uint8_t tcc_refcount[TCC_INST_NUM];
// This bitmask keeps track of which channels of a TCC are currently claimed.
#ifdef SAMD21
-uint8_t tcc_channels[3] = {0xf0, 0xfc, 0xfc};
+uint8_t tcc_channels[3]; // Set by pwmout_reset() to {0xf0, 0xfc, 0xfc} initially.
#endif
#ifdef SAMD51
-uint8_t tcc_channels[5] = {0xc0, 0xf0, 0xf8, 0xfc, 0xfc};
+uint8_t tcc_channels[5]; // Set by pwmout_reset() to {0xc0, 0xf0, 0xf8, 0xfc, 0xfc} initially.
#endif
void pwmout_reset(void) {
@@ -76,7 +76,7 @@ void pwmout_reset(void) {
for (uint8_t j = 0; j < tcc_cc_num[i]; j++) {
mask <<= 1;
}
- tcc_channels[i] = 0xf0;
+ tcc_channels[i] = mask;
tccs[i]->CTRLA.bit.SWRST = 1;
}
Tc *tcs[TC_INST_NUM] = TC_INSTS;
@@ -123,7 +123,7 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
// Figure out which timer we are using.
// First see if a tcc is already going with the frequency we want and our
- // channel is unused. tc's don't have neough channels to share.
+ // channel is unused. tc's don't have enough channels to share.
const pin_timer_t* timer = NULL;
uint8_t mux_position = 0;
if (!variable_frequency) {
@@ -140,6 +140,9 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
if (tcc->CTRLA.bit.ENABLE == 1 && channel_ok(t)) {
timer = t;
mux_position = j;
+ // Claim channel.
+ tcc_channels[timer->index] |= (1 << tcc_channel(timer));
+
}
}
}
diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c
index f6d968a1c..2349a7418 100644
--- a/ports/atmel-samd/supervisor/port.c
+++ b/ports/atmel-samd/supervisor/port.c
@@ -61,6 +61,7 @@
#include "samd/external_interrupts.h"
#include "samd/dma.h"
#include "shared-bindings/rtc/__init__.h"
+#include "board_busses.h"
#include "tick.h"
#include "usb.h"
@@ -278,6 +279,8 @@ void reset_port(void) {
reset_all_pins();
+ reset_board_busses();
+
// Output clocks for debugging.
// not supported by SAMD51G; uncomment for SAMD51J or update for 51G
// #ifdef SAMD51
diff --git a/ports/atmel-samd/usb.c b/ports/atmel-samd/usb.c
index f32d81e19..1f1ba550f 100644
--- a/ports/atmel-samd/usb.c
+++ b/ports/atmel-samd/usb.c
@@ -288,7 +288,7 @@ void usb_write(const char* buffer, uint32_t len) {
return;
}
uint8_t * output_buffer;
- uint8_t output_len;
+ uint32_t output_len;
while (len > 0) {
while (usb_transmitting) {}
output_buffer = (uint8_t *) buffer;
diff --git a/ports/esp8266/common-hal/busio/UART.c b/ports/esp8266/common-hal/busio/UART.c
index 7a4ca6e0d..e68e739f3 100644
--- a/ports/esp8266/common-hal/busio/UART.c
+++ b/ports/esp8266/common-hal/busio/UART.c
@@ -138,6 +138,9 @@ uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) {
return 0;
}
+void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self) {
+}
+
bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) {
return true;
}
diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c
index f05949e15..270c92f47 100644
--- a/ports/nrf/common-hal/busio/UART.c
+++ b/ports/nrf/common-hal/busio/UART.c
@@ -82,6 +82,10 @@ uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) {
return 0;
}
+void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self) {
+ mp_raise_NotImplementedError("busio.UART not yet implemented");
+}
+
bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) {
mp_raise_NotImplementedError(translate("busio.UART not yet implemented"));
return false;