Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit12e881b

Browse files
fix(board): Update variant.cpp for senseBox MCU-S2 ESP32-S2 (#11532)
* fix(board): Update variant.cpp for senseBox MCU-S2 ESP32-S2* fix(board): translate comments* ci(pre-commit): Apply automatic fixes* fix(board): translate comments* ci(pre-commit): Apply automatic fixes---------Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent33c8438 commit12e881b

File tree

4 files changed

+331
-28
lines changed

4 files changed

+331
-28
lines changed

‎boards.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40993,7 +40993,7 @@ sensebox_mcu_esp32s2.menu.PartitionScheme.tinyuf2=TinyUF2 4MB (1.3MB APP/960KB F
4099340993
sensebox_mcu_esp32s2.menu.PartitionScheme.tinyuf2.build.custom_bootloader=bootloader-tinyuf2
4099440994
sensebox_mcu_esp32s2.menu.PartitionScheme.tinyuf2.build.custom_partitions=partitions-4MB-tinyuf2
4099540995
sensebox_mcu_esp32s2.menu.PartitionScheme.tinyuf2.upload.maximum_size=1441792
40996-
sensebox_mcu_esp32s2.menu.PartitionScheme.tinyuf2.upload.extra_flags=0x2d0000 "{runtime.platform.path}/variants/{build.variant}/tinyuf2.bin"
40996+
sensebox_mcu_esp32s2.menu.PartitionScheme.tinyuf2.upload.extra_flags=0x2d0000 "{runtime.platform.path}/variants/{build.variant}/tinyuf2.bin" 0x170000 "{runtime.platform.path}/variants/{build.variant}/APOTA.bin"
4099740997
sensebox_mcu_esp32s2.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS)
4099840998
sensebox_mcu_esp32s2.menu.PartitionScheme.default.build.partitions=default
4099940999
sensebox_mcu_esp32s2.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS)
765 KB
Binary file not shown.
Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
#defineDISPLAY_ENABLED
2+
3+
#include<WiFi.h>
4+
#include<WebServer.h>
5+
#include<ESPmDNS.h>
6+
#include<WiFiAP.h>
7+
#include<Update.h>
8+
#include<Wire.h>
9+
#ifdef DISPLAY_ENABLED
10+
#defineSCREEN_WIDTH128
11+
#defineSCREEN_HEIGHT64
12+
#defineOLED_RESET -1
13+
#include<Adafruit_GFX.h>
14+
#include<Adafruit_SSD1306.h>
15+
Adafruit_SSD1306display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
16+
#include<Adafruit_NeoPixel.h>
17+
Adafruit_NeoPixel rgb_led_1 = Adafruit_NeoPixel(1,1, NEO_GRB + NEO_KHZ800);
18+
19+
#endif
20+
#include"esp_partition.h"
21+
#include"esp_ota_ops.h"
22+
#include"esp_system.h"
23+
24+
String ssid;
25+
uint8_t mac[6];
26+
27+
// Create an instance of the server
28+
WebServerserver(80);
29+
bool displayEnabled;
30+
31+
constint BUTTON_PIN =0;// GPIO for the button
32+
volatileunsignedlong lastPressTime =0;// Time of last button press
33+
volatilebool doublePressDetected =false;// Flag for double press
34+
constunsignedlong doublePressInterval =500;// Max. time (in ms) between two presses for double press
35+
volatileint pressCount =0;// Counts the button presses
36+
37+
constunsignedchar epd_bitmap_wifi[] PROGMEM = {
38+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
39+
0x00,0x00,0x1f,0x80,0x00,0x00,0x00,0x01,0xff,0xf0,0x00,0x00,0x00,0x07,0xff,0xfc,0x00,0x00,0x00,0x1f,0xe0,0xff,0x00,0x00,
40+
0x00,0x3f,0x00,0x0f,0x80,0x00,0x00,0x7c,0x00,0x03,0xe0,0x00,0x00,0xf0,0x00,0x01,0xf0,0x00,0x01,0xe0,0x00,0x00,0x78,0x00,
41+
0x03,0xc0,0x00,0x00,0x38,0x00,0x07,0x80,0x00,0x00,0x1c,0x00,0x0f,0x00,0x06,0x00,0x0e,0x00,0x0e,0x00,0x7f,0xe0,0x0e,0x00,
42+
0x0c,0x01,0xff,0xf0,0x06,0x00,0x00,0x07,0xff,0xfc,0x02,0x00,0x00,0x0f,0x80,0x3e,0x00,0x00,0x00,0x1f,0x00,0x0f,0x00,0x00,
43+
0x00,0x1c,0x00,0x07,0x80,0x00,0x00,0x38,0x00,0x03,0xc0,0x00,0x00,0x70,0x00,0x01,0xc0,0x00,0x00,0x70,0x00,0x00,0xc0,0x00,
44+
0x00,0x20,0x00,0x00,0x40,0x00,0x00,0x00,0x1f,0x80,0x00,0x00,0x00,0x00,0x7f,0xc0,0x00,0x00,0x00,0x00,0xff,0xe0,0x00,0x00,
45+
0x00,0x01,0xe0,0xf0,0x00,0x00,0x00,0x01,0xc0,0x78,0x00,0x00,0x00,0x03,0x80,0x38,0x00,0x00,0x00,0x01,0x00,0x10,0x00,0x00,
46+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
47+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
48+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
49+
};
50+
51+
// 'checkmark', 44x44px
52+
constunsignedchar epd_bitmap_checkmark[] PROGMEM = {
53+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
54+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
55+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
56+
0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x0f,0x00,0x00,
57+
0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x0e,0x00,0xf0,0x00,0x00,
58+
0x00,0x0f,0x01,0xe0,0x00,0x00,0x00,0x0f,0x83,0xc0,0x00,0x00,0x00,0x07,0xc7,0x80,0x00,0x00,0x00,0x03,0xef,0x00,0x00,0x00,
59+
0x00,0x01,0xfe,0x00,0x00,0x00,0x00,0x00,0xfc,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,
60+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
61+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
62+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
63+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
64+
};
65+
66+
void IRAM_ATTRhandleButtonPress() {
67+
unsignedlong currentTime =millis();// Get current time
68+
69+
// Debounce: If the current press is too close to the last one, ignore it
70+
if (currentTime - lastPressTime >50) {
71+
pressCount++;// Count the button press
72+
73+
// Check if this is the second press within the double-press interval
74+
if (pressCount ==2 && (currentTime - lastPressTime <= doublePressInterval)) {
75+
doublePressDetected =true;// Double press detected
76+
pressCount =0;// Reset counter
77+
}
78+
79+
lastPressTime = currentTime;// Update the time of the last press
80+
}
81+
}
82+
83+
// Function to switch the boot partition to OTA1
84+
voidsetBootPartitionToOTA0() {
85+
constesp_partition_t *ota0_partition =esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_0,NULL);
86+
87+
if (ota0_partition) {
88+
// Set OTA1 as new boot partition
89+
esp_ota_set_boot_partition(ota0_partition);
90+
Serial.println("Boot partition changed to OTA0. Restarting...");
91+
92+
// Restart to boot from the new partition
93+
esp_restart();
94+
}else {
95+
Serial.println("OTA1 partition not found!");
96+
}
97+
}
98+
99+
voidsetupDisplay() {
100+
displayEnabled = display.begin(SSD1306_SWITCHCAPVCC,0x3D);
101+
if (displayEnabled) {
102+
display.display();
103+
delay(100);
104+
display.clearDisplay();
105+
}
106+
}
107+
108+
voiddisplayStatusBar(int progress) {
109+
display.clearDisplay();
110+
display.setCursor(24,8);
111+
display.println("Sketch wird");
112+
display.setCursor(22,22);
113+
display.println("hochgeladen!");
114+
115+
display.fillRect(0, SCREEN_HEIGHT -24, SCREEN_WIDTH -4,8, BLACK);// Clear status bar area
116+
display.drawRect(0, SCREEN_HEIGHT -24, SCREEN_WIDTH -4,8, WHITE);// Draw border
117+
int filledWidth = (progress * SCREEN_WIDTH -4) /100;// Calculate progress width
118+
display.fillRect(1, SCREEN_HEIGHT -23, filledWidth -4,6, WHITE);// Fill progress bar
119+
120+
display.setCursor((SCREEN_WIDTH /2) -12, SCREEN_HEIGHT -10);
121+
display.setTextSize(1);
122+
display.setTextColor(WHITE, BLACK);
123+
display.print(progress);
124+
display.println(" %");
125+
display.display();
126+
}
127+
128+
voiddisplayWelcomeScreen() {
129+
display.clearDisplay();
130+
131+
// Draw WiFi symbol
132+
display.drawBitmap(0,12, epd_bitmap_wifi,44,44, WHITE);
133+
134+
// Display SSID text
135+
display.setCursor(40,13);
136+
display.setTextSize(1);
137+
display.setTextColor(WHITE, BLACK);
138+
display.println("Verbinde dich");// "Connect"
139+
display.setCursor(60,27);
140+
display.println("mit:");// "with"
141+
142+
// Display SSID
143+
display.setCursor(40,43);
144+
display.setTextSize(1);// Larger text for SSID
145+
display.print(ssid);
146+
147+
display.display();
148+
}
149+
150+
voiddisplaySuccessScreen() {
151+
display.clearDisplay();
152+
153+
// Draw WiFi symbol
154+
display.drawBitmap(0,12, epd_bitmap_checkmark,44,44, WHITE);
155+
156+
// Display SSID text
157+
display.setCursor(48,22);
158+
display.setTextSize(1);
159+
display.setTextColor(WHITE, BLACK);
160+
display.println("Erfolgreich");// "Successfully"
161+
display.setCursor(48,36);
162+
display.println("hochgeladen!");// "uploaded!"
163+
164+
display.display();
165+
}
166+
167+
voidwipeDisplay() {
168+
display.clearDisplay();
169+
display.println("");
170+
display.display();
171+
}
172+
173+
voidsetupWiFi() {
174+
WiFi.macAddress(mac);
175+
char macLastFour[5];
176+
snprintf(macLastFour,sizeof(macLastFour),"%02X%02X", mac[4], mac[5]);
177+
ssid ="senseBox:" +String(macLastFour);
178+
179+
// Define the IP address, gateway, and subnet mask
180+
IPAddresslocal_IP(192,168,1,1);// The new IP address
181+
IPAddressgateway(192,168,1,1);// Gateway address (can be the same as the AP's IP)
182+
IPAddresssubnet(255,255,255,0);// Subnet mask
183+
184+
// Set the IP address, gateway, and subnet mask of the access point
185+
WiFi.softAPConfig(local_IP, gateway, subnet);
186+
187+
// Start the access point
188+
WiFi.softAP(ssid.c_str());
189+
}
190+
191+
voidsetupOTA() {
192+
// Handle updating process
193+
server.on(
194+
"/sketch", HTTP_POST,
195+
[]() {
196+
server.sendHeader("Connection","close");
197+
server.send(200,"text/plain", (Update.hasError()) ?"FAIL" :"OK");
198+
ESP.restart();
199+
},
200+
[]() {
201+
HTTPUpload &upload = server.upload();
202+
203+
if (upload.status == UPLOAD_FILE_START) {
204+
Serial.setDebugOutput(true);
205+
size_t fsize = UPDATE_SIZE_UNKNOWN;
206+
if (server.clientContentLength() >0) {
207+
fsize = server.clientContentLength();
208+
}
209+
Serial.printf("Receiving Update: %s, Size: %d\n", upload.filename.c_str(), fsize);
210+
211+
Serial.printf("Update: %s\n", upload.filename.c_str());
212+
if (!Update.begin(fsize)) {//start with max available size
213+
Update.printError(Serial);
214+
}
215+
}elseif (upload.status == UPLOAD_FILE_WRITE) {
216+
/* flashing firmware to ESP*/
217+
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
218+
Update.printError(Serial);
219+
}else {
220+
int progress = (Update.progress() *100) / Update.size();
221+
displayStatusBar(progress);// Update progress on status bar
222+
}
223+
}elseif (upload.status == UPLOAD_FILE_END) {
224+
if (Update.end(true)) {//true to set the size to the current progress
225+
displaySuccessScreen();
226+
delay(3000);
227+
wipeDisplay();
228+
}else {
229+
Update.printError(Serial);
230+
}
231+
Serial.setDebugOutput(false);
232+
}
233+
yield();
234+
}
235+
);
236+
}
237+
238+
voidsetup() {
239+
// Start Serial communication
240+
Serial.begin(115200);
241+
rgb_led_1.begin();
242+
rgb_led_1.setBrightness(30);
243+
rgb_led_1.setPixelColor(0, rgb_led_1.Color(51,51,255));
244+
rgb_led_1.show();
245+
246+
// Configure button pin as input
247+
pinMode(BUTTON_PIN, INPUT_PULLUP);
248+
249+
// Interrupt for the button
250+
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), handleButtonPress, FALLING);
251+
252+
#ifdef DISPLAY_ENABLED
253+
setupDisplay();
254+
#endif
255+
setupWiFi();
256+
// Set the ESP32 as an access point
257+
setupOTA();
258+
server.begin();
259+
}
260+
261+
voidloop() {
262+
// Handle client requests
263+
server.handleClient();
264+
265+
#ifdef DISPLAY_ENABLED
266+
displayWelcomeScreen();
267+
#endif
268+
269+
if (doublePressDetected) {
270+
Serial.println("Doppeldruck erkannt!");// "Double press detected!"
271+
setBootPartitionToOTA0();
272+
#ifdef DISPLAY_ENABLED
273+
display.setCursor(0,0);
274+
display.setTextSize(1);
275+
display.setTextColor(WHITE, BLACK);
276+
display.println("");
277+
display.display();
278+
delay(50);
279+
#endif
280+
// Restart to boot from the new partition
281+
esp_restart();
282+
}
283+
}
Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
1-
/*
2-
* The MIT License (MIT)
3-
*
4-
* Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries
5-
*
6-
* Permission is hereby granted, free of charge, to any person obtaining a copy
7-
* of this software and associated documentation files (the "Software"), to deal
8-
* in the Software without restriction, including without limitation the rights
9-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
* copies of the Software, and to permit persons to whom the Software is
11-
* furnished to do so, subject to the following conditions:
12-
*
13-
* The above copyright notice and this permission notice shall be included in
14-
* all copies or substantial portions of the Software.
15-
*
16-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22-
* THE SOFTWARE.
23-
*/
24-
251
#include"esp32-hal-gpio.h"
262
#include"pins_arduino.h"
3+
#include"esp_partition.h"
4+
#include"esp_system.h"
5+
#include"esp_ota_ops.h"
6+
#include"esp_log.h"
7+
#include<esp_chip_info.h>
278

289
extern"C" {
2910

@@ -41,12 +22,51 @@ void initVariant(void) {
4122
pinMode(PIN_XB1_ENABLE, OUTPUT);
4223
digitalWrite(PIN_XB1_ENABLE, LOW);
4324

44-
//enable UART by default
45-
pinMode(PIN_UART_ENABLE, OUTPUT);
46-
digitalWrite(PIN_UART_ENABLE, LOW);
25+
//enable UART only for chip without PSRAM
26+
esp_chip_info_t chip_info;
27+
esp_chip_info(&chip_info);
28+
if (chip_info.revision <=0) {
29+
pinMode(PIN_UART_ENABLE, OUTPUT);
30+
digitalWrite(PIN_UART_ENABLE, LOW);
31+
}
4732

4833
//enable PD-Sensor by default
4934
pinMode(PD_ENABLE, OUTPUT);
5035
digitalWrite(PD_ENABLE, HIGH);
36+
37+
// define button pin
38+
constint PIN_BUTTON =0;
39+
pinMode(PIN_BUTTON, INPUT_PULLUP);
40+
41+
// keep button pressed
42+
unsignedlong pressStartTime =0;
43+
bool buttonPressed =false;
44+
45+
// Wait 5 seconds for the button to be pressed
46+
unsignedlong startTime =millis();
47+
48+
// Check if button is pressed
49+
while (millis() - startTime <5000) {
50+
if (digitalRead(PIN_BUTTON) == LOW) {
51+
if (!buttonPressed) {
52+
// The button was pressed
53+
buttonPressed =true;
54+
}
55+
}elseif (buttonPressed) {
56+
// When the button is pressed and then released, boot into the OTA1 partition
57+
constesp_partition_t *ota1_partition =esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1,NULL);
58+
59+
if (ota1_partition) {
60+
esp_err_t err =esp_ota_set_boot_partition(ota1_partition);
61+
if (err == ESP_OK) {
62+
esp_restart();// restart, to boot OTA1 partition
63+
}else {
64+
ESP_LOGE("OTA","Error setting OTA1 partition: %s",esp_err_to_name(err));
65+
}
66+
}
67+
// Abort after releasing the button
68+
break;
69+
}
70+
}
5171
}
5272
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp