Skip to content

Commit 390e5e6

Browse files
committed
fix(senseBox): change partition on button press and only UART if no PSRAM
1 parent 422e526 commit 390e5e6

File tree

1 file changed

+50
-28
lines changed

1 file changed

+50
-28
lines changed
Lines changed: 50 additions & 28 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,53 @@ 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+
// Neuen Button-Pin definieren (z.B. GPIO 0 als Beispiel)
38+
const int PIN_BUTTON = 0;
39+
pinMode(PIN_BUTTON, INPUT_PULLUP);
40+
41+
// Button gedrückt halten
42+
unsigned long pressStartTime = 0;
43+
bool buttonPressed = false;
44+
45+
// Wait 5 seconds for the button to be pressed
46+
unsigned long 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+
} else if (buttonPressed) {
56+
// When the button is pressed and then released, boot into the OTA1 partition
57+
const esp_partition_t* ota1_partition = esp_partition_find_first(
58+
ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL);
59+
60+
if (ota1_partition) {
61+
esp_err_t err = esp_ota_set_boot_partition(ota1_partition);
62+
if (err == ESP_OK) {
63+
esp_restart(); // restart, to boot OTA1 partition
64+
} else {
65+
ESP_LOGE("OTA", "Error setting OTA1 partition: %s", esp_err_to_name(err));
66+
}
67+
}
68+
// Abort after releasing the button
69+
break;
70+
}
71+
}
5172
}
52-
}
73+
74+
}

0 commit comments

Comments
 (0)