Skip to content

Commit 6ee9acc

Browse files
authored
Merge pull request #4755 from jepler/esp32s2-protomatter
Esp32s2 protomatter
2 parents a94b8cf + 9ff6ccb commit 6ee9acc

File tree

13 files changed

+156
-10
lines changed

13 files changed

+156
-10
lines changed

ports/esp32s2/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
222222
$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
223223
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os
224224

225+
$(BUILD)/lib/protomatter/src/core.o: CFLAGS += -DESP32
226+
225227
# List of sources for qstr extraction
226228
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
227229
# Sources that only hold QSTRs after pre-processing.

ports/esp32s2/common-hal/microcontroller/Pin.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ STATIC void floating_gpio_reset(gpio_num_t pin_number) {
5151
}
5252

5353
void never_reset_pin_number(gpio_num_t pin_number) {
54-
if (pin_number == -1) {
54+
if (pin_number == NO_PIN) {
5555
return;
5656
}
5757
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) {
6363

6464
// Mark pin as free and return it to a quiescent state.
6565
void reset_pin_number(gpio_num_t pin_number) {
66-
if (pin_number == -1) {
66+
if (pin_number == NO_PIN) {
6767
return;
6868
}
6969
never_reset_pins[pin_number / 32] &= ~(1 << pin_number % 32);
@@ -72,6 +72,10 @@ void reset_pin_number(gpio_num_t pin_number) {
7272
floating_gpio_reset(pin_number);
7373
}
7474

75+
void common_hal_mcu_pin_reset_number(uint8_t i) {
76+
reset_pin_number((gpio_num_t)i);
77+
}
78+
7579
void common_hal_reset_pin(const mcu_pin_obj_t *pin) {
7680
if (pin == NULL) {
7781
return;
@@ -109,3 +113,7 @@ bool pin_number_is_free(gpio_num_t pin_number) {
109113
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
110114
return pin_number_is_free(pin->number);
111115
}
116+
117+
uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t *pin) {
118+
return pin ? pin->number : NO_PIN;
119+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2021 Jeff Epler for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include <stddef.h>
28+
29+
#include "common-hal/rgbmatrix/RGBMatrix.h"
30+
31+
#include "peripherals/timer.h"
32+
33+
void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) {
34+
const timer_config_t config = {
35+
.alarm_en = false,
36+
.counter_en = false,
37+
.intr_type = TIMER_INTR_LEVEL,
38+
.counter_dir = TIMER_COUNT_UP,
39+
.auto_reload = true,
40+
.divider = 2 // 40MHz
41+
};
42+
43+
timer_index_t *timer = malloc(sizeof(timer_index_t));
44+
bool res = peripherals_timer_init(&config, timer);
45+
if (!res) {
46+
return NULL;
47+
}
48+
peripherals_timer_never_reset(timer);
49+
return timer;
50+
}
51+
52+
extern bool _PM_esp32timerCallback(void *arg);
53+
54+
void common_hal_rgbmatrix_timer_enable(void *ptr) {
55+
}
56+
57+
void common_hal_rgbmatrix_timer_disable(void *ptr) {
58+
timer_index_t *timer = (timer_index_t *)ptr;
59+
if (timer->idx == TIMER_MAX) {
60+
return;
61+
}
62+
timer_pause(timer->group, timer->idx);
63+
timer_disable_intr(timer->group, timer->idx);
64+
timer_isr_callback_remove(timer->group, timer->idx);
65+
}
66+
67+
void common_hal_rgbmatrix_timer_free(void *ptr) {
68+
timer_index_t *timer = (timer_index_t *)ptr;
69+
if (timer->idx == TIMER_MAX) {
70+
return;
71+
}
72+
common_hal_rgbmatrix_timer_disable(ptr);
73+
peripherals_timer_deinit(timer);
74+
timer->idx = TIMER_MAX;
75+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* This file is part of the Micro Python project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Jeff Epler for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_RGBMATRIX_RGBMATRIX_H
28+
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_RGBMATRIX_RGBMATRIX_H
29+
30+
#include "shared-module/rgbmatrix/RGBMatrix.h"
31+
32+
void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self);
33+
void common_hal_rgbmatrix_timer_enable(void *);
34+
void common_hal_rgbmatrix_timer_disable(void *);
35+
void common_hal_rgbmatrix_timer_free(void *);
36+
37+
#endif

ports/esp32s2/common-hal/rgbmatrix/__init__.c

Whitespace-only changes.

ports/esp32s2/common-hal/rgbmatrix/__init__.h

Whitespace-only changes.

ports/esp32s2/mpconfigport.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ CIRCUITPY_AUDIOIO = 0
2121
CIRCUITPY_CANIO = 1
2222
CIRCUITPY_COUNTIO = 1
2323
CIRCUITPY_DUALBANK = 1
24+
CIRCUITPY_FRAMEBUFFERIO = 1
2425
CIRCUITPY_FREQUENCYIO = 1
2526
CIRCUITPY_I2CPERIPHERAL = 0
27+
CIRCUITPY_RGBMATRIX = 1
2628
CIRCUITPY_ROTARYIO = 1
2729
CIRCUITPY_NVM = 1
2830
CIRCUITPY_PS2IO ?= 1

ports/esp32s2/peripherals/pins.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,6 @@ extern const mcu_pin_obj_t pin_GPIO44;
9191
extern const mcu_pin_obj_t pin_GPIO45;
9292
extern const mcu_pin_obj_t pin_GPIO46;
9393

94+
#define NO_PIN (GPIO_NUM_NC)
95+
9496
#endif // MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PINS_H

ports/esp32s2/peripherals/timer.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "peripherals/timer.h"
2828

29+
#define TIMER_NEVER_RESET 2
2930
#define TIMER_FREE 1
3031
#define TIMER_BUSY 0
3132

@@ -45,7 +46,7 @@ void peripherals_timer_reset(void) {
4546
}
4647
}
4748

48-
void peripherals_timer_init(const timer_config_t *config, timer_index_t *timer) {
49+
bool peripherals_timer_init(const timer_config_t *config, timer_index_t *timer) {
4950
bool break_loop = false;
5051

5152
// get free timer
@@ -60,19 +61,38 @@ void peripherals_timer_init(const timer_config_t *config, timer_index_t *timer)
6061
} else if (i == 1 && j == 1) {
6162
timer->idx = TIMER_MAX;
6263
timer->group = TIMER_GROUP_MAX;
63-
return;
64+
return false;
6465
}
6566
}
6667
if (break_loop) {
6768
break;
6869
}
6970
}
7071

72+
timer->hw = (timer->group == 0) ? &TIMERG0 : &TIMERG1;
73+
7174
// initialize timer module
7275
timer_init(timer->group, timer->idx, config);
7376
timer_set_counter_value(timer->group, timer->idx, 0);
77+
78+
return true;
7479
}
7580

7681
void peripherals_timer_deinit(timer_index_t *timer) {
82+
if (timer->group == TIMER_GROUP_MAX || timer->idx == TIMER_MAX) {
83+
return;
84+
}
85+
timer_deinit(timer->group, timer->idx);
86+
int i = timer->group;
87+
int j = timer->idx;
88+
timer->group = TIMER_GROUP_MAX;
89+
timer->idx = TIMER_MAX;
90+
timer_state[i][j] = TIMER_FREE;
91+
}
92+
93+
void peripherals_timer_never_reset(timer_index_t *timer) {
7794
timer_deinit(timer->group, timer->idx);
95+
int i = timer->group;
96+
int j = timer->idx;
97+
timer_state[i][j] = TIMER_NEVER_RESET;
7898
}

0 commit comments

Comments
 (0)