summaryrefslogtreecommitdiff
path: root/ports/raspberrypi/common-hal
diff options
context:
space:
mode:
Diffstat (limited to 'ports/raspberrypi/common-hal')
-rw-r--r--ports/raspberrypi/common-hal/busio/I2C.c2
-rw-r--r--ports/raspberrypi/common-hal/microcontroller/Processor.c10
-rw-r--r--ports/raspberrypi/common-hal/microcontroller/Processor.h4
-rw-r--r--ports/raspberrypi/common-hal/microcontroller/__init__.c13
-rw-r--r--ports/raspberrypi/common-hal/neopixel_write/__init__.c5
-rw-r--r--ports/raspberrypi/common-hal/pwmio/PWMOut.c4
-rw-r--r--ports/raspberrypi/common-hal/rp2pio/StateMachine.c26
-rwxr-xr-xports/raspberrypi/common-hal/supervisor/Runtime.c4
8 files changed, 47 insertions, 21 deletions
diff --git a/ports/raspberrypi/common-hal/busio/I2C.c b/ports/raspberrypi/common-hal/busio/I2C.c
index fa49e375e..26a7f3807 100644
--- a/ports/raspberrypi/common-hal/busio/I2C.c
+++ b/ports/raspberrypi/common-hal/busio/I2C.c
@@ -90,7 +90,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
if (!gpio_get(sda->number) || !gpio_get(scl->number)) {
reset_pin_number(sda->number);
reset_pin_number(scl->number);
- mp_raise_RuntimeError(translate("SDA or SCL needs a pull up"));
+ mp_raise_RuntimeError(translate("No pull up found on SDA or SCL; check your wiring"));
}
#endif
diff --git a/ports/raspberrypi/common-hal/microcontroller/Processor.c b/ports/raspberrypi/common-hal/microcontroller/Processor.c
index 0ad3a51e2..e22286ca3 100644
--- a/ports/raspberrypi/common-hal/microcontroller/Processor.c
+++ b/ports/raspberrypi/common-hal/microcontroller/Processor.c
@@ -25,6 +25,7 @@
*/
#include <math.h>
+#include <string.h>
#include "py/mphal.h"
#include "common-hal/microcontroller/Processor.h"
@@ -53,12 +54,9 @@ uint32_t common_hal_mcu_processor_get_frequency(void) {
}
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
- // TODO: get the unique id from the flash. The chip itself doesn't have one.
- // for (int i=0; i<4; i++) {
- // for (int k=0; k<4; k++) {
- // raw_id[4 * i + k] = (*(id_addresses[i]) >> k * 8) & 0xff;
- // }
- // }
+ pico_unique_board_id_t retrieved_id;
+ pico_get_unique_board_id(&retrieved_id);
+ memcpy(raw_id, retrieved_id.id, COMMON_HAL_MCU_PROCESSOR_UID_LENGTH);
}
mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) {
diff --git a/ports/raspberrypi/common-hal/microcontroller/Processor.h b/ports/raspberrypi/common-hal/microcontroller/Processor.h
index b7c86e850..afb43f9bd 100644
--- a/ports/raspberrypi/common-hal/microcontroller/Processor.h
+++ b/ports/raspberrypi/common-hal/microcontroller/Processor.h
@@ -27,7 +27,9 @@
#ifndef MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
#define MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H
-#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 16
+#include "src/rp2_common/pico_unique_id/include/pico/unique_id.h"
+
+#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH PICO_UNIQUE_BOARD_ID_SIZE_BYTES
#include "py/obj.h"
diff --git a/ports/raspberrypi/common-hal/microcontroller/__init__.c b/ports/raspberrypi/common-hal/microcontroller/__init__.c
index 85bfc329d..bfea8b2d9 100644
--- a/ports/raspberrypi/common-hal/microcontroller/__init__.c
+++ b/ports/raspberrypi/common-hal/microcontroller/__init__.c
@@ -35,12 +35,16 @@
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/microcontroller/Processor.h"
+#include "supervisor/filesystem.h"
+#include "supervisor/port.h"
#include "supervisor/shared/safe_mode.h"
#include "supervisor/shared/translate.h"
#include "src/rp2040/hardware_structs/include/hardware/structs/sio.h"
#include "src/rp2_common/hardware_sync/include/hardware/sync.h"
+#include "hardware/watchdog.h"
+
void common_hal_mcu_delay_us(uint32_t delay) {
mp_hal_delay_us(delay);
}
@@ -66,8 +70,11 @@ void common_hal_mcu_enable_interrupts(void) {
asm volatile ("cpsie i" : : : "memory");
}
+static bool next_reset_to_bootloader = false;
+
void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
if (runmode == RUNMODE_BOOTLOADER) {
+ next_reset_to_bootloader = true;
} else {
}
if (runmode == RUNMODE_SAFE_MODE) {
@@ -76,6 +83,12 @@ void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) {
}
void common_hal_mcu_reset(void) {
+ filesystem_flush();
+ if (next_reset_to_bootloader) {
+ reset_to_bootloader();
+ } else {
+ reset_cpu();
+ }
}
// The singleton microcontroller.Processor object, bound to microcontroller.cpu
diff --git a/ports/raspberrypi/common-hal/neopixel_write/__init__.c b/ports/raspberrypi/common-hal/neopixel_write/__init__.c
index 10462b5a3..561d438e2 100644
--- a/ports/raspberrypi/common-hal/neopixel_write/__init__.c
+++ b/ports/raspberrypi/common-hal/neopixel_write/__init__.c
@@ -29,6 +29,7 @@
#include "bindings/rp2pio/StateMachine.h"
#include "common-hal/rp2pio/StateMachine.h"
#include "shared-bindings/microcontroller/__init__.h"
+#include "shared-bindings/digitalio/DigitalInOut.h"
#include "supervisor/port.h"
@@ -89,7 +90,11 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
// Use a private deinit of the state machine that doesn't reset the pin.
rp2pio_statemachine_deinit(&state_machine, true);
+
+ // Reset the pin and release it from the PIO
gpio_init(digitalinout->pin->number);
+ common_hal_digitalio_digitalinout_switch_to_output((digitalio_digitalinout_obj_t*)digitalinout, false, DRIVE_MODE_PUSH_PULL);
+
// Update the next start.
next_start_raw_ticks = port_get_raw_ticks(NULL) + 1;
}
diff --git a/ports/raspberrypi/common-hal/pwmio/PWMOut.c b/ports/raspberrypi/common-hal/pwmio/PWMOut.c
index 567ec5ef5..3d8979a03 100644
--- a/ports/raspberrypi/common-hal/pwmio/PWMOut.c
+++ b/ports/raspberrypi/common-hal/pwmio/PWMOut.c
@@ -107,7 +107,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self,
if (variable_frequency) {
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
}
- // If the other user wants to change frequency then we can't share either.
+ // If the other user wants a variable frequency then we can't share either.
if ((slice_fixed_frequency & (1 << slice)) != 0) {
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
}
@@ -119,7 +119,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self,
self->slice = slice;
self->channel = channel;
channel_use |= channel_use_mask;
- if (!variable_frequency) {
+ if (variable_frequency) {
slice_fixed_frequency |= 1 << slice;
}
diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c
index 6510410b0..90c48130e 100644
--- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c
+++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c
@@ -546,15 +546,23 @@ static bool _transfer(rp2pio_statemachine_obj_t *self,
size_t tx_remaining = out_len;
while (rx_remaining || tx_remaining) {
- if (tx_remaining && !pio_sm_is_tx_fifo_full(self->pio, self->state_machine)) {
- *tx_destination = *data_out;
- data_out++;
- --tx_remaining;
- }
- if (rx_remaining && !pio_sm_is_rx_fifo_empty(self->pio, self->state_machine)) {
- *data_in = (uint8_t) *rx_source;
- data_in++;
- --rx_remaining;
+ for (int i=0; i<32; i++) {
+ bool did_transfer = false;
+ if (tx_remaining && !pio_sm_is_tx_fifo_full(self->pio, self->state_machine)) {
+ *tx_destination = *data_out;
+ data_out++;
+ --tx_remaining;
+ did_transfer = true;
+ }
+ if (rx_remaining && !pio_sm_is_rx_fifo_empty(self->pio, self->state_machine)) {
+ *data_in = (uint8_t) *rx_source;
+ data_in++;
+ --rx_remaining;
+ did_transfer = true;
+ }
+ if (!did_transfer) {
+ break;
+ }
}
RUN_BACKGROUND_TASKS;
if (mp_hal_is_interrupted()) {
diff --git a/ports/raspberrypi/common-hal/supervisor/Runtime.c b/ports/raspberrypi/common-hal/supervisor/Runtime.c
index 6be38f216..974f26cec 100755
--- a/ports/raspberrypi/common-hal/supervisor/Runtime.c
+++ b/ports/raspberrypi/common-hal/supervisor/Runtime.c
@@ -28,10 +28,10 @@
#include "shared-bindings/supervisor/Runtime.h"
#include "supervisor/serial.h"
-bool common_hal_get_serial_connected(void) {
+bool common_hal_supervisor_runtime_get_serial_connected(void) {
return (bool) serial_connected();
}
-bool common_hal_get_serial_bytes_available(void) {
+bool common_hal_supervisor_runtime_get_serial_bytes_available(void) {
return (bool) serial_bytes_available();
}