summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Epler <jeff@adafruit.com>2021-03-02 19:01:37 -0600
committerGitHub <noreply@github.com>2021-03-02 19:01:37 -0600
commitefc2667b5f087480b1b3233ae00ab1529a442f9f (patch)
treebd685b27f4f17567e39b14c86a7310951e12e96e
parent15615effc2f8a9f991ace105f8a9f7bb51982059 (diff)
parent238484ec261af55b90a39a8dcfc9fcdd6cb4390c (diff)
Merge pull request #4186 from jepler/update-protomatter-rp2
Enable protomatter on RP2040 builds
m---------lib/protomatter0
-rw-r--r--ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.c2
-rw-r--r--ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.h4
-rw-r--r--ports/nrf/common-hal/rgbmatrix/RGBMatrix.c2
-rw-r--r--ports/nrf/common-hal/rgbmatrix/RGBMatrix.h4
-rw-r--r--ports/raspberrypi/common-hal/pwmio/PWMOut.c78
-rw-r--r--ports/raspberrypi/common-hal/pwmio/PWMOut.h5
-rw-r--r--ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.c70
-rw-r--r--ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.h37
-rw-r--r--ports/raspberrypi/common-hal/rgbmatrix/__init__.c0
-rw-r--r--ports/raspberrypi/mpconfigport.mk2
-rw-r--r--ports/stm/common-hal/rgbmatrix/RGBMatrix.c2
-rw-r--r--ports/stm/common-hal/rgbmatrix/RGBMatrix.h4
-rw-r--r--shared-bindings/pwmio/PWMOut.h2
-rw-r--r--shared-module/rgbmatrix/RGBMatrix.c4
-rw-r--r--shared-module/rgbmatrix/RGBMatrix.h1
16 files changed, 181 insertions, 36 deletions
diff --git a/lib/protomatter b/lib/protomatter
-Subproject 5e925cea7a55273e375a6129761cb29b4e750d4
+Subproject c2c81ded118484f8925bf81e270b416739cd72d
diff --git a/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.c b/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.c
index 55b0c2f12..6daf20aea 100644
--- a/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.c
+++ b/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.c
@@ -31,7 +31,7 @@
#include "samd/timers.h"
#include "timer_handler.h"
-void *common_hal_rgbmatrix_timer_allocate() {
+void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) {
uint8_t timer_index = find_free_timer();
if (timer_index == 0xff) {
return NULL;
diff --git a/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.h b/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.h
index 48de4dcb2..2378cf173 100644
--- a/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.h
+++ b/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.h
@@ -27,7 +27,9 @@
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_RGBMATRIX_RGBMATRIX_H
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_RGBMATRIX_RGBMATRIX_H
-void *common_hal_rgbmatrix_timer_allocate(void);
+#include "shared-module/rgbmatrix/RGBMatrix.h"
+
+void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self);
void common_hal_rgbmatrix_timer_enable(void*);
void common_hal_rgbmatrix_timer_disable(void*);
void common_hal_rgbmatrix_timer_free(void*);
diff --git a/ports/nrf/common-hal/rgbmatrix/RGBMatrix.c b/ports/nrf/common-hal/rgbmatrix/RGBMatrix.c
index e13b761ab..d8289f56f 100644
--- a/ports/nrf/common-hal/rgbmatrix/RGBMatrix.c
+++ b/ports/nrf/common-hal/rgbmatrix/RGBMatrix.c
@@ -32,7 +32,7 @@
extern void _PM_IRQ_HANDLER(void);
-void *common_hal_rgbmatrix_timer_allocate() {
+void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) {
nrfx_timer_t *timer = nrf_peripherals_allocate_timer_or_throw();
nrf_peripherals_timer_never_reset(timer);
return timer->p_reg;
diff --git a/ports/nrf/common-hal/rgbmatrix/RGBMatrix.h b/ports/nrf/common-hal/rgbmatrix/RGBMatrix.h
index 24d86f177..6cf7354fc 100644
--- a/ports/nrf/common-hal/rgbmatrix/RGBMatrix.h
+++ b/ports/nrf/common-hal/rgbmatrix/RGBMatrix.h
@@ -27,7 +27,9 @@
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_RGBMATRIX_RGBMATRIX_H
#define MICROPY_INCLUDED_NRF_COMMON_HAL_RGBMATRIX_RGBMATRIX_H
-void *common_hal_rgbmatrix_timer_allocate(void);
+#include "shared-module/rgbmatrix/RGBMatrix.h"
+
+void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self);
void common_hal_rgbmatrix_timer_enable(void*);
void common_hal_rgbmatrix_timer_disable(void*);
void common_hal_rgbmatrix_timer_free(void*);
diff --git a/ports/raspberrypi/common-hal/pwmio/PWMOut.c b/ports/raspberrypi/common-hal/pwmio/PWMOut.c
index f690528ae..9ca31a35e 100644
--- a/ports/raspberrypi/common-hal/pwmio/PWMOut.c
+++ b/ports/raspberrypi/common-hal/pwmio/PWMOut.c
@@ -61,14 +61,22 @@ static uint32_t _mask(uint8_t slice, uint8_t channel) {
return 1 << (slice * CHANNELS_PER_SLICE + channel);
}
+void pwmout_never_reset(uint8_t slice, uint8_t channel) {
+ never_reset_channel |= _mask(slice, channel);
+}
+
+void pwmout_reset_ok(uint8_t slice, uint8_t channel) {
+ never_reset_channel &= ~_mask(slice, channel);
+}
+
void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) {
- never_reset_channel |= _mask(self->slice, self->channel);
+ pwmout_never_reset(self->slice, self->channel);
never_reset_pin_number(self->pin->number);
}
void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) {
- never_reset_channel &= ~_mask(self->slice, self->channel);
+ pwmout_reset_ok(self->slice, self->channel);
}
void pwmout_reset(void) {
@@ -92,21 +100,7 @@ void pwmout_reset(void) {
}
}
-pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self,
- const mcu_pin_obj_t* pin,
- uint16_t duty,
- uint32_t frequency,
- bool variable_frequency) {
- self->pin = pin;
- self->variable_frequency = variable_frequency;
- self->duty_cycle = duty;
-
- if (frequency == 0 || frequency > (common_hal_mcu_processor_get_frequency() / 2)) {
- return PWMOUT_INVALID_FREQUENCY;
- }
-
- uint8_t slice = pwm_gpio_to_slice_num(pin->number);
- uint8_t channel = pwm_gpio_to_channel(pin->number);
+pwmout_result_t pwmout_allocate(uint8_t slice, uint8_t channel, bool variable_frequency, uint32_t frequency) {
uint32_t channel_use_mask = _mask(slice, channel);
// Check the channel first.
@@ -128,14 +122,39 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self,
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
}
}
- self->slice = slice;
- self->channel = channel;
channel_use |= channel_use_mask;
if (variable_frequency) {
slice_variable_frequency |= 1 << slice;
}
+ return PWMOUT_OK;
+}
+
+pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self,
+ const mcu_pin_obj_t* pin,
+ uint16_t duty,
+ uint32_t frequency,
+ bool variable_frequency) {
+ self->pin = pin;
+ self->variable_frequency = variable_frequency;
+ self->duty_cycle = duty;
+
+ if (frequency == 0 || frequency > (common_hal_mcu_processor_get_frequency() / 2)) {
+ return PWMOUT_INVALID_FREQUENCY;
+ }
+
+ uint8_t slice = pwm_gpio_to_slice_num(pin->number);
+ uint8_t channel = pwm_gpio_to_channel(pin->number);
+
+ int r = pwmout_allocate(slice, channel, variable_frequency, frequency);
+ if (r != PWMOUT_OK) {
+ return r;
+ }
+
+ self->slice = slice;
+ self->channel = channel;
+
if (target_slice_frequencies[slice] != frequency) {
// Reset the counter and compare values.
pwm_hw->slice[slice].ctr = PWM_CH0_CTR_RESET;
@@ -157,20 +176,23 @@ bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t* self) {
return self->pin == NULL;
}
-void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) {
- if (common_hal_pwmio_pwmout_deinited(self)) {
- return;
- }
- uint32_t channel_mask = _mask(self->slice, self->channel);
+void pwmout_free(uint8_t slice, uint8_t channel) {
+ uint32_t channel_mask = _mask(slice, channel);
channel_use &= ~channel_mask;
never_reset_channel &= ~channel_mask;
- uint32_t slice_mask = ((1 << CHANNELS_PER_SLICE) - 1) << (self->slice * CHANNELS_PER_SLICE);
+ uint32_t slice_mask = ((1 << CHANNELS_PER_SLICE) - 1) << (slice * CHANNELS_PER_SLICE);
if ((channel_use & slice_mask) == 0) {
- target_slice_frequencies[self->slice] = 0;
- slice_variable_frequency &= ~(1 << self->slice);
- pwm_set_enabled(self->slice, false);
+ target_slice_frequencies[slice] = 0;
+ slice_variable_frequency &= ~(1 << slice);
+ pwm_set_enabled(slice, false);
}
+}
+void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) {
+ if (common_hal_pwmio_pwmout_deinited(self)) {
+ return;
+ }
+ pwmout_free(self->slice, self->channel);
reset_pin_number(self->pin->number);
self->pin = NULL;
}
diff --git a/ports/raspberrypi/common-hal/pwmio/PWMOut.h b/ports/raspberrypi/common-hal/pwmio/PWMOut.h
index 0070e188b..8221bef17 100644
--- a/ports/raspberrypi/common-hal/pwmio/PWMOut.h
+++ b/ports/raspberrypi/common-hal/pwmio/PWMOut.h
@@ -45,5 +45,10 @@ typedef struct {
void pwmout_reset(void);
// Private API for AudioPWMOut.
void pwmio_pwmout_set_top(pwmio_pwmout_obj_t* self, uint16_t top);
+// Private APIs for RGBMatrix
+enum pwmout_result_t pwmout_allocate(uint8_t slice, uint8_t channel, bool variable_frequency, uint32_t frequency);
+void pwmout_free(uint8_t slice, uint8_t channel);
+void pwmout_never_reset(uint8_t slice, uint8_t channel);
+void pwmout_reset_ok(uint8_t slice, uint8_t channel);
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PWMIO_PWMOUT_H
diff --git a/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.c b/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.c
new file mode 100644
index 000000000..657c7f0a6
--- /dev/null
+++ b/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.c
@@ -0,0 +1,70 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Jeff Epler for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stddef.h>
+
+#include "py/mphal.h"
+
+#include "common-hal/rgbmatrix/RGBMatrix.h"
+#include "shared-bindings/pwmio/PWMOut.h"
+#include "shared-module/rgbmatrix/RGBMatrix.h"
+
+#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h"
+
+void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) {
+ // Choose a PWM channel based on the first RGB pin
+ uint8_t slice = pwm_gpio_to_slice_num(self->rgb_pins[0]);
+ uint8_t channel = pwm_gpio_to_channel(self->rgb_pins[0]);
+ int result = pwmout_allocate(slice, channel, true, 125000000/3);
+ if (result == PWMOUT_OK) {
+ // return value must be nonzero (but slice and channel can both be
+ // zero), so set bit 16...
+ pwmout_never_reset(slice, channel);
+ return (void*)(intptr_t)(slice | (channel << 8) | 0x10000);
+ }
+ return NULL;
+}
+
+void common_hal_rgbmatrix_timer_enable(void* ptr) {
+ int8_t slice = ((intptr_t)ptr) & 0xff;
+ pwm_set_enabled(slice, false);
+ pwm_clear_irq(slice);
+ pwm_set_enabled(slice, true);
+}
+
+void common_hal_rgbmatrix_timer_disable(void* ptr) {
+ int8_t slice = ((intptr_t)ptr) & 0xff;
+ pwm_set_enabled(slice, false);
+}
+
+void common_hal_rgbmatrix_timer_free(void* ptr) {
+ intptr_t value = (intptr_t)ptr;
+ uint8_t slice = value & 0xff;
+ uint8_t channel = value >> 8;
+ pwm_set_enabled(slice, false);
+ pwmout_free(slice, channel);
+ return;
+}
diff --git a/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.h b/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.h
new file mode 100644
index 000000000..2378cf173
--- /dev/null
+++ b/ports/raspberrypi/common-hal/rgbmatrix/RGBMatrix.h
@@ -0,0 +1,37 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Jeff Epler for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_RGBMATRIX_RGBMATRIX_H
+#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_RGBMATRIX_RGBMATRIX_H
+
+#include "shared-module/rgbmatrix/RGBMatrix.h"
+
+void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self);
+void common_hal_rgbmatrix_timer_enable(void*);
+void common_hal_rgbmatrix_timer_disable(void*);
+void common_hal_rgbmatrix_timer_free(void*);
+
+#endif
diff --git a/ports/raspberrypi/common-hal/rgbmatrix/__init__.c b/ports/raspberrypi/common-hal/rgbmatrix/__init__.c
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/ports/raspberrypi/common-hal/rgbmatrix/__init__.c
diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk
index b3b925e55..4e55b0a09 100644
--- a/ports/raspberrypi/mpconfigport.mk
+++ b/ports/raspberrypi/mpconfigport.mk
@@ -23,9 +23,11 @@ else
CIRCUITPY_NEOPIXEL_WRITE = 0
endif
+CIRCUITPY_FRAMEBUFFERIO = 1
CIRCUITPY_FULL_BUILD = 1
CIRCUITPY_BITOPS = 1
CIRCUITPY_PWMIO = 1
+CIRCUITPY_RGBMATRIX = 1
# Things that need to be implemented.
CIRCUITPY_COUNTIO = 0 # Use PWM interally
diff --git a/ports/stm/common-hal/rgbmatrix/RGBMatrix.c b/ports/stm/common-hal/rgbmatrix/RGBMatrix.c
index 2826cf53e..36ed6d018 100644
--- a/ports/stm/common-hal/rgbmatrix/RGBMatrix.c
+++ b/ports/stm/common-hal/rgbmatrix/RGBMatrix.c
@@ -33,7 +33,7 @@
extern void _PM_IRQ_HANDLER(void);
-void *common_hal_rgbmatrix_timer_allocate() {
+void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) {
TIM_TypeDef * timer = stm_peripherals_find_timer();
stm_peripherals_timer_reserve(timer);
stm_peripherals_timer_never_reset(timer);
diff --git a/ports/stm/common-hal/rgbmatrix/RGBMatrix.h b/ports/stm/common-hal/rgbmatrix/RGBMatrix.h
index 323878d20..2debb6a76 100644
--- a/ports/stm/common-hal/rgbmatrix/RGBMatrix.h
+++ b/ports/stm/common-hal/rgbmatrix/RGBMatrix.h
@@ -27,7 +27,9 @@
#ifndef MICROPY_INCLUDED_STM_COMMON_HAL_RGBMATRIX_RGBMATRIX_H
#define MICROPY_INCLUDED_STM_COMMON_HAL_RGBMATRIX_RGBMATRIX_H
-void *common_hal_rgbmatrix_timer_allocate(void);
+#include "shared-module/rgbmatrix/RGBMatrix.h"
+
+void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self);
void common_hal_rgbmatrix_timer_enable(void*);
void common_hal_rgbmatrix_timer_disable(void*);
void common_hal_rgbmatrix_timer_free(void*);
diff --git a/shared-bindings/pwmio/PWMOut.h b/shared-bindings/pwmio/PWMOut.h
index 1a99914ea..de2ebd1cf 100644
--- a/shared-bindings/pwmio/PWMOut.h
+++ b/shared-bindings/pwmio/PWMOut.h
@@ -32,7 +32,7 @@
extern const mp_obj_type_t pwmio_pwmout_type;
-typedef enum {
+typedef enum pwmout_result_t {
PWMOUT_OK,
PWMOUT_INVALID_PIN,
PWMOUT_INVALID_FREQUENCY,
diff --git a/shared-module/rgbmatrix/RGBMatrix.c b/shared-module/rgbmatrix/RGBMatrix.c
index b8db0d893..a688d7fd6 100644
--- a/shared-module/rgbmatrix/RGBMatrix.c
+++ b/shared-module/rgbmatrix/RGBMatrix.c
@@ -56,7 +56,7 @@ void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, i
self->tile = tile;
self->serpentine = serpentine;
- self->timer = timer ? timer : common_hal_rgbmatrix_timer_allocate();
+ self->timer = timer ? timer : common_hal_rgbmatrix_timer_allocate(self);
if (self->timer == NULL) {
mp_raise_ValueError(translate("No timer available"));
}
@@ -68,6 +68,8 @@ void common_hal_rgbmatrix_rgbmatrix_construct(rgbmatrix_rgbmatrix_obj_t *self, i
}
void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self, mp_obj_t framebuffer) {
+ self->paused = 1;
+
common_hal_rgbmatrix_timer_disable(self->timer);
if (framebuffer) {
self->framebuffer = framebuffer;
diff --git a/shared-module/rgbmatrix/RGBMatrix.h b/shared-module/rgbmatrix/RGBMatrix.h
index 4a0e9235e..65bfc9799 100644
--- a/shared-module/rgbmatrix/RGBMatrix.h
+++ b/shared-module/rgbmatrix/RGBMatrix.h
@@ -26,6 +26,7 @@
#pragma once
+#include "py/obj.h"
#include "lib/protomatter/src/core.h"
extern const mp_obj_type_t rgbmatrix_RGBMatrix_type;