Merge pull request #4755 from jepler/esp32s2-protomatter

Esp32s2 protomatter
This commit is contained in:
Scott Shawcroft 2021-06-01 13:32:34 -07:00 committed by GitHub
commit 6ee9acc900
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 156 additions and 10 deletions

@ -1 +1 @@
Subproject commit 98017c57349e259fab70c6a7830436b19a55f6f4
Subproject commit 7fe6406affb1376193102cf76ded06e61316d7e6

View File

@ -222,6 +222,8 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os
$(BUILD)/lib/protomatter/src/core.o: CFLAGS += -DESP32
# List of sources for qstr extraction
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
# Sources that only hold QSTRs after pre-processing.

View File

@ -51,7 +51,7 @@ STATIC void floating_gpio_reset(gpio_num_t pin_number) {
}
void never_reset_pin_number(gpio_num_t pin_number) {
if (pin_number == -1) {
if (pin_number == NO_PIN) {
return;
}
never_reset_pins[pin_number / 32] |= 1 << pin_number % 32;
@ -63,7 +63,7 @@ void common_hal_never_reset_pin(const mcu_pin_obj_t *pin) {
// Mark pin as free and return it to a quiescent state.
void reset_pin_number(gpio_num_t pin_number) {
if (pin_number == -1) {
if (pin_number == NO_PIN) {
return;
}
never_reset_pins[pin_number / 32] &= ~(1 << pin_number % 32);
@ -72,6 +72,10 @@ void reset_pin_number(gpio_num_t pin_number) {
floating_gpio_reset(pin_number);
}
void common_hal_mcu_pin_reset_number(uint8_t i) {
reset_pin_number((gpio_num_t)i);
}
void common_hal_reset_pin(const mcu_pin_obj_t *pin) {
if (pin == NULL) {
return;
@ -109,3 +113,7 @@ bool pin_number_is_free(gpio_num_t pin_number) {
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
return pin_number_is_free(pin->number);
}
uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t *pin) {
return pin ? pin->number : NO_PIN;
}

View File

@ -0,0 +1,75 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 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 "common-hal/rgbmatrix/RGBMatrix.h"
#include "peripherals/timer.h"
void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) {
const timer_config_t config = {
.alarm_en = false,
.counter_en = false,
.intr_type = TIMER_INTR_LEVEL,
.counter_dir = TIMER_COUNT_UP,
.auto_reload = true,
.divider = 2 // 40MHz
};
timer_index_t *timer = malloc(sizeof(timer_index_t));
bool res = peripherals_timer_init(&config, timer);
if (!res) {
return NULL;
}
peripherals_timer_never_reset(timer);
return timer;
}
extern bool _PM_esp32timerCallback(void *arg);
void common_hal_rgbmatrix_timer_enable(void *ptr) {
}
void common_hal_rgbmatrix_timer_disable(void *ptr) {
timer_index_t *timer = (timer_index_t *)ptr;
if (timer->idx == TIMER_MAX) {
return;
}
timer_pause(timer->group, timer->idx);
timer_disable_intr(timer->group, timer->idx);
timer_isr_callback_remove(timer->group, timer->idx);
}
void common_hal_rgbmatrix_timer_free(void *ptr) {
timer_index_t *timer = (timer_index_t *)ptr;
if (timer->idx == TIMER_MAX) {
return;
}
common_hal_rgbmatrix_timer_disable(ptr);
peripherals_timer_deinit(timer);
timer->idx = TIMER_MAX;
}

View File

@ -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

View File

@ -21,8 +21,10 @@ CIRCUITPY_AUDIOIO = 0
CIRCUITPY_CANIO = 1
CIRCUITPY_COUNTIO = 1
CIRCUITPY_DUALBANK = 1
CIRCUITPY_FRAMEBUFFERIO = 1
CIRCUITPY_FREQUENCYIO = 1
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_RGBMATRIX = 1
CIRCUITPY_ROTARYIO = 1
CIRCUITPY_NVM = 1
CIRCUITPY_PS2IO ?= 1

View File

@ -91,4 +91,6 @@ extern const mcu_pin_obj_t pin_GPIO44;
extern const mcu_pin_obj_t pin_GPIO45;
extern const mcu_pin_obj_t pin_GPIO46;
#define NO_PIN (GPIO_NUM_NC)
#endif // MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PINS_H

View File

@ -26,6 +26,7 @@
#include "peripherals/timer.h"
#define TIMER_NEVER_RESET 2
#define TIMER_FREE 1
#define TIMER_BUSY 0
@ -45,7 +46,7 @@ void peripherals_timer_reset(void) {
}
}
void peripherals_timer_init(const timer_config_t *config, timer_index_t *timer) {
bool peripherals_timer_init(const timer_config_t *config, timer_index_t *timer) {
bool break_loop = false;
// get free timer
@ -60,7 +61,7 @@ void peripherals_timer_init(const timer_config_t *config, timer_index_t *timer)
} else if (i == 1 && j == 1) {
timer->idx = TIMER_MAX;
timer->group = TIMER_GROUP_MAX;
return;
return false;
}
}
if (break_loop) {
@ -68,11 +69,30 @@ void peripherals_timer_init(const timer_config_t *config, timer_index_t *timer)
}
}
timer->hw = (timer->group == 0) ? &TIMERG0 : &TIMERG1;
// initialize timer module
timer_init(timer->group, timer->idx, config);
timer_set_counter_value(timer->group, timer->idx, 0);
return true;
}
void peripherals_timer_deinit(timer_index_t *timer) {
if (timer->group == TIMER_GROUP_MAX || timer->idx == TIMER_MAX) {
return;
}
timer_deinit(timer->group, timer->idx);
int i = timer->group;
int j = timer->idx;
timer->group = TIMER_GROUP_MAX;
timer->idx = TIMER_MAX;
timer_state[i][j] = TIMER_FREE;
}
void peripherals_timer_never_reset(timer_index_t *timer) {
timer_deinit(timer->group, timer->idx);
int i = timer->group;
int j = timer->idx;
timer_state[i][j] = TIMER_NEVER_RESET;
}

View File

@ -30,12 +30,14 @@
#include "driver/timer.h"
typedef struct {
timg_dev_t *hw;
timer_idx_t idx;
timer_group_t group;
} timer_index_t;
extern void peripherals_timer_init(const timer_config_t *config, timer_index_t *timer);
extern bool peripherals_timer_init(const timer_config_t *config, timer_index_t *timer);
extern void peripherals_timer_deinit(timer_index_t *timer);
extern void peripherals_timer_reset(void);
extern void peripherals_timer_never_reset(timer_index_t *timer);
#endif // MICROPY_INCLUDED_ESP32S2_PERIPHERALS_TIMER_HANDLER_H

View File

@ -185,6 +185,8 @@ void reset_displays(void) {
rgbmatrix_rgbmatrix_obj_t *pm = &displays[i].rgbmatrix;
if (!any_display_uses_this_framebuffer(&pm->base)) {
common_hal_rgbmatrix_rgbmatrix_deinit(pm);
} else {
common_hal_rgbmatrix_rgbmatrix_set_paused(pm, true);
}
#endif
#if CIRCUITPY_SHARPDISPLAY

View File

@ -104,15 +104,11 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t *self,
if (stat == PROTOMATTER_OK) {
_PM_protoPtr = &self->protomatter;
common_hal_mcu_disable_interrupts();
common_hal_rgbmatrix_timer_enable(self->timer);
stat = _PM_begin(&self->protomatter);
if (stat == PROTOMATTER_OK) {
_PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width);
}
common_hal_mcu_enable_interrupts();
if (stat == PROTOMATTER_OK) {
_PM_swapbuffer_maybe(&self->protomatter);
}
}