Skip to content

Commit 3f672ca

Browse files
committed
Add MagTag 2025
1 parent 3512e66 commit 3f672ca

File tree

5 files changed

+270
-0
lines changed

5 files changed

+270
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "supervisor/board.h"
8+
9+
#include "mpconfigboard.h"
10+
#include "shared-bindings/busio/SPI.h"
11+
#include "shared-bindings/fourwire/FourWire.h"
12+
#include "shared-bindings/microcontroller/Pin.h"
13+
#include "shared-module/displayio/__init__.h"
14+
#include "supervisor/shared/board.h"
15+
16+
#include "esp_log.h"
17+
18+
// static const char *TAG = "board";
19+
20+
#define DELAY 0x80
21+
22+
// This is an SSD1680 control chip. The display is a 2.9" grayscale EInk.
23+
const uint8_t display_start_sequence[] = {
24+
0x12, DELAY, 0x00, 0x14, // soft reset and wait 20ms
25+
0x11, 0x00, 0x01, 0x03, // Ram data entry mode
26+
0x3c, 0x00, 0x01, 0x03, // border color
27+
0x2c, 0x00, 0x01, 0x28, // Set vcom voltage
28+
0x03, 0x00, 0x01, 0x17, // Set gate voltage
29+
0x04, 0x00, 0x03, 0x41, 0xae, 0x32, // Set source voltage
30+
0x4e, 0x00, 0x01, 0x01, // ram x count
31+
0x4f, 0x00, 0x02, 0x00, 0x00, // ram y count
32+
0x01, 0x00, 0x03, 0x27, 0x01, 0x00, // set display size
33+
0x32, 0x00, 0x99, // Update waveforms
34+
0x2a, 0x60, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L0
35+
0x20, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L1
36+
0x28, 0x60, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L2
37+
0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L3
38+
0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // VS L4
39+
0x00, 0x02, 0x00, 0x05, 0x14, 0x00, 0x00, // TP, SR, RP of Group0
40+
0x1E, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x01, // TP, SR, RP of Group1
41+
0x00, 0x02, 0x00, 0x05, 0x14, 0x00, 0x00, // TP, SR, RP of Group2
42+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group3
43+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group4
44+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group5
45+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group6
46+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group7
47+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group8
48+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group9
49+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group10
50+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // TP, SR, RP of Group11
51+
0x24, 0x22, 0x22, 0x22, 0x23, 0x32, 0x00, 0x00, 0x00, // FR, XON
52+
0x22, 0x00, 0x01, 0xc7 // display update mode
53+
};
54+
55+
const uint8_t display_stop_sequence[] = {
56+
0x10, DELAY, 0x01, 0x01, 0x64
57+
};
58+
59+
const uint8_t refresh_sequence[] = {
60+
0x20, 0x00, 0x00
61+
};
62+
63+
void board_init(void) {
64+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
65+
busio_spi_obj_t *spi = &bus->inline_bus;
66+
common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, false);
67+
common_hal_busio_spi_never_reset(spi);
68+
69+
bus->base.type = &fourwire_fourwire_type;
70+
common_hal_fourwire_fourwire_construct(bus,
71+
spi,
72+
&pin_GPIO7, // EPD_DC Command or data
73+
&pin_GPIO8, // EPD_CS Chip select
74+
&pin_GPIO6, // EPD_RST Reset
75+
4000000, // Baudrate
76+
0, // Polarity
77+
0); // Phase
78+
79+
epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display;
80+
display->base.type = &epaperdisplay_epaperdisplay_type;
81+
common_hal_epaperdisplay_epaperdisplay_construct(
82+
display,
83+
bus,
84+
display_start_sequence, sizeof(display_start_sequence),
85+
0, // start up time
86+
display_stop_sequence, sizeof(display_stop_sequence),
87+
296, // width
88+
128, // height
89+
250, // ram_width
90+
296, // ram_height
91+
0, // colstart
92+
0, // rowstart
93+
270, // rotation
94+
0x44, // set_column_window_command
95+
0x45, // set_row_window_command
96+
0x4e, // set_current_column_command
97+
0x4f, // set_current_row_command
98+
0x24, // write_black_ram_command
99+
false, // black_bits_inverted
100+
0x26, // write_color_ram_command
101+
false, // color_bits_inverted
102+
0x000000, // highlight_color
103+
refresh_sequence, sizeof(refresh_sequence),
104+
1.0, // refresh_time
105+
&pin_GPIO5, // busy_pin
106+
true, // busy_state
107+
5.0, // seconds_per_frame
108+
false, // always_toggle_chip_select
109+
true, // grayscale
110+
false, // acep
111+
false, // spectra6
112+
true, // two_byte_sequence_length
113+
true); // address_little_endian
114+
}
115+
116+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
117+
// Pin 16 is speaker enable and it's pulled down on the board. We don't want
118+
// to pull it high because then we'll compete with the external pull down.
119+
// So, reset without any pulls internally.
120+
if (pin_number == 16) {
121+
gpio_config_t cfg = {
122+
.pin_bit_mask = BIT64(16),
123+
.mode = GPIO_MODE_DISABLE,
124+
// The pin is externally pulled down, so we don't need to pull it.
125+
.pull_up_en = false,
126+
.pull_down_en = false,
127+
.intr_type = GPIO_INTR_DISABLE,
128+
};
129+
gpio_config(&cfg);
130+
return true;
131+
}
132+
// Pin 4 is used for voltage monitoring, so don't reset
133+
if (pin_number == 4) {
134+
return true;
135+
}
136+
return false;
137+
}
138+
139+
void board_deinit(void) {
140+
epaperdisplay_epaperdisplay_obj_t *display = &displays[0].epaper_display;
141+
if (display->base.type == &epaperdisplay_epaperdisplay_type) {
142+
size_t i = 0;
143+
while (common_hal_epaperdisplay_epaperdisplay_get_busy(display)) {
144+
RUN_BACKGROUND_TASKS;
145+
i++;
146+
}
147+
}
148+
common_hal_displayio_release_displays();
149+
}
150+
151+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
// Micropython setup
10+
11+
#define MICROPY_HW_BOARD_NAME "Adafruit MagTag 2025"
12+
#define MICROPY_HW_MCU_NAME "ESP32S2"
13+
14+
#define MICROPY_HW_NEOPIXEL (&pin_GPIO1)
15+
#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO21)
16+
#define CIRCUITPY_STATUS_LED_POWER_INVERTED (1)
17+
#define MICROPY_HW_NEOPIXEL_COUNT (4)
18+
19+
#define MICROPY_HW_LED_STATUS (&pin_GPIO13)
20+
21+
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO34)
22+
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO33)
23+
24+
#define DOUBLE_TAP_PIN (&pin_GPIO38)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
USB_VID = 0x239A
2+
USB_PID = 0x80E6
3+
USB_PRODUCT = "MagTag 2025"
4+
USB_MANUFACTURER = "Adafruit"
5+
6+
IDF_TARGET = esp32s2
7+
8+
CIRCUITPY_ESP_FLASH_MODE = qio
9+
CIRCUITPY_ESP_FLASH_FREQ = 80m
10+
CIRCUITPY_ESP_FLASH_SIZE = 4MB
11+
12+
CIRCUITPY_ESP_PSRAM_SIZE = 2MB
13+
CIRCUITPY_ESP_PSRAM_MODE = qio
14+
CIRCUITPY_ESP_PSRAM_FREQ = 80m
15+
16+
CIRCUITPY_PARALLELDISPLAYBUS = 0
17+
18+
# Include these Python libraries in firmware.
19+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_ConnectionManager
20+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_PortalBase
21+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_FakeRequests
22+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests
23+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
24+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Display_Text
25+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "shared-bindings/board/__init__.h"
8+
9+
#include "shared-module/displayio/__init__.h"
10+
11+
static const mp_rom_map_elem_t board_module_globals_table[] = {
12+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
13+
14+
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO10) },
15+
16+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO18) },
17+
// Previous name from schematic.
18+
{ MP_ROM_QSTR(MP_QSTR_AD1), MP_ROM_PTR(&pin_GPIO18) },
19+
20+
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) },
21+
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) },
22+
23+
{ MP_ROM_QSTR(MP_QSTR_SPEAKER), MP_ROM_PTR(&pin_GPIO17) },
24+
{ MP_ROM_QSTR(MP_QSTR_SPEAKER_ENABLE), MP_ROM_PTR(&pin_GPIO16) },
25+
26+
{ MP_ROM_QSTR(MP_QSTR_EPD_BUSY), MP_ROM_PTR(&pin_GPIO5) },
27+
{ MP_ROM_QSTR(MP_QSTR_EPD_RESET), MP_ROM_PTR(&pin_GPIO6) },
28+
{ MP_ROM_QSTR(MP_QSTR_EPD_DC), MP_ROM_PTR(&pin_GPIO7) },
29+
{ MP_ROM_QSTR(MP_QSTR_EPD_CS), MP_ROM_PTR(&pin_GPIO8) },
30+
{ MP_ROM_QSTR(MP_QSTR_EPD_MOSI), MP_ROM_PTR(&pin_GPIO35) },
31+
{ MP_ROM_QSTR(MP_QSTR_EPD_SCK), MP_ROM_PTR(&pin_GPIO36) },
32+
{ MP_ROM_QSTR(MP_QSTR_EPD_MISO), MP_ROM_PTR(&pin_GPIO37) },
33+
34+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_A), MP_ROM_PTR(&pin_GPIO15) },
35+
{ MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO15) },
36+
37+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_B), MP_ROM_PTR(&pin_GPIO14) },
38+
{ MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO14) },
39+
40+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_C), MP_ROM_PTR(&pin_GPIO12) },
41+
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12) },
42+
43+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_D), MP_ROM_PTR(&pin_GPIO11) },
44+
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO11) },
45+
46+
{ MP_ROM_QSTR(MP_QSTR_BOOT0), MP_ROM_PTR(&pin_GPIO0) },
47+
48+
{ MP_ROM_QSTR(MP_QSTR_LIGHT), MP_ROM_PTR(&pin_GPIO3) },
49+
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO3) },
50+
51+
{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO4) },
52+
{ MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO4) },
53+
54+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO33) },
55+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO34) },
56+
57+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER_INVERTED), MP_ROM_PTR(&pin_GPIO21) },
58+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO21) },
59+
60+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO1) },
61+
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) },
62+
63+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
64+
{ MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) },
65+
66+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].epaper_display)},
67+
68+
{ MP_ROM_QSTR(MP_QSTR_ACCELEROMETER_INTERRUPT), MP_ROM_PTR(&pin_GPIO9) },
69+
};
70+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

ports/espressif/boards/adafruit_magtag_2.9_grayscale_2025/sdkconfig

Whitespace-only changes.

0 commit comments

Comments
 (0)