Skip to content

Commit ff819d6

Browse files
author
Eric Thieme-Garmann
committed
added ota support for sensebox s2
1 parent e27a050 commit ff819d6

File tree

3 files changed

+57
-40
lines changed

3 files changed

+57
-40
lines changed

boards.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39146,7 +39146,7 @@ sensebox_mcu_esp32s2.menu.PartitionScheme.tinyuf2=TinyUF2 4MB (1.3MB APP/960KB F
3914639146
sensebox_mcu_esp32s2.menu.PartitionScheme.tinyuf2.build.custom_bootloader=bootloader-tinyuf2
3914739147
sensebox_mcu_esp32s2.menu.PartitionScheme.tinyuf2.build.custom_partitions=partitions-4MB-tinyuf2
3914839148
sensebox_mcu_esp32s2.menu.PartitionScheme.tinyuf2.upload.maximum_size=1441792
39149-
sensebox_mcu_esp32s2.menu.PartitionScheme.tinyuf2.upload.extra_flags=0x2d0000 "{runtime.platform.path}/variants/{build.variant}/tinyuf2.bin"
39149+
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"
3915039150
sensebox_mcu_esp32s2.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS)
3915139151
sensebox_mcu_esp32s2.menu.PartitionScheme.default.build.partitions=default
3915239152
sensebox_mcu_esp32s2.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS)
764 KB
Binary file not shown.
Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,69 @@
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+
8+
// Globale Variable zur Kommunikation mit dem Hauptprogramm
9+
bool buttonWasPressed = false;
2710

2811
extern "C" {
2912

3013
// Initialize variant/board, called before setup()
3114
void initVariant(void) {
32-
//enable IO Pins by default
33-
pinMode(IO_ENABLE, OUTPUT);
34-
digitalWrite(IO_ENABLE, LOW);
15+
// Initialisiere Pins wie vorher
16+
pinMode(IO_ENABLE, OUTPUT);
17+
digitalWrite(IO_ENABLE, LOW);
18+
19+
pinMode(PIN_NEOPIXEL, OUTPUT);
20+
digitalWrite(PIN_NEOPIXEL, LOW);
21+
22+
pinMode(PIN_XB1_ENABLE, OUTPUT);
23+
digitalWrite(PIN_XB1_ENABLE, LOW);
24+
25+
pinMode(PIN_UART_ENABLE, OUTPUT);
26+
digitalWrite(PIN_UART_ENABLE, LOW);
3527

36-
//reset RGB
37-
pinMode(PIN_RGB_LED, OUTPUT);
38-
digitalWrite(PIN_RGB_LED, LOW);
28+
pinMode(PD_ENABLE, OUTPUT);
29+
digitalWrite(PD_ENABLE, HIGH);
3930

40-
//enable XBEE by default
41-
pinMode(PIN_XB1_ENABLE, OUTPUT);
42-
digitalWrite(PIN_XB1_ENABLE, LOW);
31+
// Neuen Button-Pin definieren (z.B. GPIO 0 als Beispiel)
32+
const int PIN_BUTTON = 0;
33+
pinMode(PIN_BUTTON, INPUT_PULLUP);
4334

44-
//enable UART by default
45-
pinMode(PIN_UART_ENABLE, OUTPUT);
46-
digitalWrite(PIN_UART_ENABLE, LOW);
35+
// Button gedrückt halten
36+
unsigned long pressStartTime = 0;
37+
bool buttonPressed = false;
4738

48-
//enable PD-Sensor by default
49-
pinMode(PD_ENABLE, OUTPUT);
50-
digitalWrite(PD_ENABLE, HIGH);
39+
// Warten auf Button-Eingabe für 5 Sekunden
40+
unsigned long startTime = millis();
41+
42+
// Überprüfen, ob der Button gedrückt wird
43+
while (millis() - startTime < 5000) {
44+
if (digitalRead(PIN_BUTTON) == LOW) {
45+
if (!buttonPressed) {
46+
// Der Button wurde gerade gedrückt
47+
buttonPressed = true;
48+
}
49+
} else if (buttonPressed) {
50+
// Wenn der Button gedrückt und dann losgelassen wird, in OTA1-Partition booten
51+
const esp_partition_t* ota1_partition = esp_partition_find_first(
52+
ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL);
53+
54+
if (ota1_partition) {
55+
esp_err_t err = esp_ota_set_boot_partition(ota1_partition);
56+
if (err == ESP_OK) {
57+
esp_restart(); // Neustarten, um die OTA1-Partition zu booten
58+
} else {
59+
// Fehler beim Setzen der Boot-Partition
60+
ESP_LOGE("OTA", "Fehler beim Setzen der OTA1-Partition: %s", esp_err_to_name(err));
61+
}
62+
}
63+
// Nach dem Loslassen des Buttons abbrechen
64+
break;
65+
}
66+
}
5167
}
68+
5269
}

0 commit comments

Comments
 (0)