esp32s2: Add rgbmatrix support

This commit is contained in:
Jeff Epler 2021-05-13 11:19:55 -05:00
parent 0d7f257eae
commit 11288c1c28
10 changed files with 143 additions and 8 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

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

@ -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) {
@ -73,8 +74,25 @@ void peripherals_timer_init(const timer_config_t *config, timer_index_t *timer)
// 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

@ -35,8 +35,9 @@ typedef struct {
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

@ -104,17 +104,17 @@ 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_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);
}
// common_hal_mcu_enable_interrupts();
// if (stat == PROTOMATTER_OK) {
// }
}
if (stat != PROTOMATTER_OK) {