Skip to content

Commit 6cc41fc

Browse files
authored
Merge branch 'espressif:master' into main
2 parents c16f376 + 7ecde87 commit 6cc41fc

27 files changed

+578
-10
lines changed

.github/workflows/boards.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ jobs:
4545
- name: Checkout repository
4646
uses: actions/checkout@v3
4747

48+
- name: Check if build.board is uppercase
49+
run: |
50+
board_name=$(echo ${{ matrix.fqbn }} | awk -F':' '{print $NF}')
51+
if grep -q "^$board_name.build.board=[A-Z0-9_]*$" boards.txt; then
52+
echo "$board_name.build.board is valid.";
53+
else
54+
echo "Error: $board_name.build.board is not uppercase!";
55+
exit 1;
56+
fi
57+
4858
- name: Compile sketch
4959
uses: P-R-O-C-H-Y/compile-sketches@main
5060
with:

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ set(LIBRARY_SRCS
9797
libraries/Update/src/Updater.cpp
9898
libraries/Update/src/HttpsOTAUpdate.cpp
9999
libraries/USB/src/USBHID.cpp
100+
libraries/USB/src/USBMIDI.cpp
100101
libraries/USB/src/USBHIDMouse.cpp
101102
libraries/USB/src/USBHIDKeyboard.cpp
102103
libraries/USB/src/USBHIDGamepad.cpp

boards.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ esp32c6.menu.PartitionScheme.custom.upload.maximum_size=16777216
430430

431431
esp32c6.menu.CPUFreq.160=160MHz (WiFi)
432432
esp32c6.menu.CPUFreq.160.build.f_cpu=160000000L
433+
esp32c6.menu.CPUFreq.120=120MHz (WiFi)
434+
esp32c6.menu.CPUFreq.120.build.f_cpu=120000000L
433435
esp32c6.menu.CPUFreq.80=80MHz (WiFi)
434436
esp32c6.menu.CPUFreq.80.build.f_cpu=80000000L
435437
esp32c6.menu.CPUFreq.40=40MHz
@@ -17110,7 +17112,7 @@ heltec_wifi_kit_32.build.target=esp32
1711017112
heltec_wifi_kit_32.build.mcu=esp32
1711117113
heltec_wifi_kit_32.build.core=esp32
1711217114
heltec_wifi_kit_32.build.variant=heltec_wifi_kit_32
17113-
heltec_wifi_kit_32.build.board=heltec_wifi_kit_32
17115+
heltec_wifi_kit_32.build.board=HELTEC_WIFI_KIT_32
1711417116

1711517117
heltec_wifi_kit_32.build.f_cpu=240000000L
1711617118
heltec_wifi_kit_32.build.flash_size=4MB
@@ -17199,7 +17201,7 @@ heltec_wifi_kit_32_V3.build.target=esp32s3
1719917201
heltec_wifi_kit_32_V3.build.mcu=esp32s3
1720017202
heltec_wifi_kit_32_V3.build.core=esp32
1720117203
heltec_wifi_kit_32_V3.build.variant=heltec_wifi_kit_32_V3
17202-
heltec_wifi_kit_32_V3.build.board=heltec_wifi_kit_32_V3
17204+
heltec_wifi_kit_32_V3.build.board=HELTEC_WIFI_KIT_32_V3
1720317205

1720417206
heltec_wifi_kit_32_V3.build.usb_mode=1
1720517207
heltec_wifi_kit_32_V3.build.cdc_on_boot=0
@@ -17298,7 +17300,7 @@ heltec_wifi_lora_32.build.target=esp32
1729817300
heltec_wifi_lora_32.build.mcu=esp32
1729917301
heltec_wifi_lora_32.build.core=esp32
1730017302
heltec_wifi_lora_32.build.variant=heltec_wifi_lora_32
17301-
heltec_wifi_lora_32.build.board=heltec_wifi_lora_32
17303+
heltec_wifi_lora_32.build.board=HELTEC_WIFI_LORA_32
1730217304

1730317305
heltec_wifi_lora_32.build.f_cpu=240000000L
1730417306
heltec_wifi_lora_32.build.flash_size=4MB
@@ -17435,7 +17437,7 @@ heltec_wifi_lora_32_V2.build.target=esp32
1743517437
heltec_wifi_lora_32_V2.build.mcu=esp32
1743617438
heltec_wifi_lora_32_V2.build.core=esp32
1743717439
heltec_wifi_lora_32_V2.build.variant=heltec_wifi_lora_32_V2
17438-
heltec_wifi_lora_32_V2.build.board=heltec_wifi_lora_32_V2
17440+
heltec_wifi_lora_32_V2.build.board=HELTEC_WIFI_LORA_32_V2
1743917441

1744017442
heltec_wifi_lora_32_V2.build.f_cpu=240000000L
1744117443
heltec_wifi_lora_32_V2.build.flash_size=8MB
@@ -17551,7 +17553,7 @@ heltec_wifi_lora_32_V3.build.target=esp32s3
1755117553
heltec_wifi_lora_32_V3.build.mcu=esp32s3
1755217554
heltec_wifi_lora_32_V3.build.core=esp32
1755317555
heltec_wifi_lora_32_V3.build.variant=heltec_wifi_lora_32_V3
17554-
heltec_wifi_lora_32_V3.build.board=heltec_wifi_32_lora_V3
17556+
heltec_wifi_lora_32_V3.build.board=HELTEC_WIFI_LORA_32_V3
1755517557

1755617558
heltec_wifi_lora_32_V3.build.usb_mode=1
1755717559
heltec_wifi_lora_32_V3.build.cdc_on_boot=0
@@ -17693,7 +17695,7 @@ heltec_wireless_stick.build.target=esp32
1769317695
heltec_wireless_stick.build.mcu=esp32
1769417696
heltec_wireless_stick.build.core=esp32
1769517697
heltec_wireless_stick.build.variant=heltec_wireless_stick
17696-
heltec_wireless_stick.build.board=heltec_wireless_stick
17698+
heltec_wireless_stick.build.board=HELTEC_WIRELESS_STICK
1769717699

1769817700
heltec_wireless_stick.build.f_cpu=240000000L
1769917701
heltec_wireless_stick.build.flash_size=8MB
@@ -17806,7 +17808,7 @@ heltec_wireless_stick_lite.build.target=esp32
1780617808
heltec_wireless_stick_lite.build.mcu=esp32
1780717809
heltec_wireless_stick_lite.build.core=esp32
1780817810
heltec_wireless_stick_lite.build.variant=heltec_wireless_stick_lite
17809-
heltec_wireless_stick_lite.build.board=heltec_wireless_stick_LITE
17811+
heltec_wireless_stick_lite.build.board=HELTEC_WIRELESS_STICK_LITE
1781017812

1781117813
heltec_wireless_stick_lite.build.f_cpu=240000000L
1781217814
heltec_wireless_stick_lite.build.flash_size=4MB

cores/esp32/esp32-hal-cpu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz){
188188
}
189189
#endif
190190
#ifndef CONFIG_IDF_TARGET_ESP32H2
191-
if(cpu_freq_mhz > xtal && cpu_freq_mhz != 240 && cpu_freq_mhz != 160 && cpu_freq_mhz != 80){
191+
if(cpu_freq_mhz > xtal && cpu_freq_mhz != 240 && cpu_freq_mhz != 160 && cpu_freq_mhz != 120 && cpu_freq_mhz != 80){
192192
if(xtal >= RTC_XTAL_FREQ_40M){
193-
log_e("Bad frequency: %u MHz! Options are: 240, 160, 80, %u, %u and %u MHz", cpu_freq_mhz, xtal, xtal/2, xtal/4);
193+
log_e("Bad frequency: %u MHz! Options are: 240, 160, 120, 80, %u, %u and %u MHz", cpu_freq_mhz, xtal, xtal/2, xtal/4);
194194
} else {
195-
log_e("Bad frequency: %u MHz! Options are: 240, 160, 80, %u and %u MHz", cpu_freq_mhz, xtal, xtal/2);
195+
log_e("Bad frequency: %u MHz! Options are: 240, 160, 120, 80, %u and %u MHz", cpu_freq_mhz, xtal, xtal/2);
196196
}
197197
return false;
198198
}

libraries/USB/examples/MIDI/MidiController/.skip.esp32

Whitespace-only changes.

libraries/USB/examples/MIDI/MidiController/.skip.esp32c3

Whitespace-only changes.

libraries/USB/examples/MIDI/MidiController/.skip.esp32c6

Whitespace-only changes.

libraries/USB/examples/MIDI/MidiController/.skip.esp32h2

Whitespace-only changes.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
This is an example of a Simple MIDI Controller using an ESP32 with a native USB support stack (S2, S3,
3+
etc.).
4+
5+
For a hookup guide and more information on reading the ADC, please see:
6+
https://randomnerdtutorials.com/esp32-adc-analog-read-arduino-ide/ (Note: This sketch uses GPIO05)
7+
8+
For best results, it is recommended to add an extra offset resistor between VCC and the potentiometer.
9+
(For a standard 10kOhm potentiometer, 3kOhm - 4kOhm will do.)
10+
11+
View this sketch in action on YouTube: https://youtu.be/Y9TLXs_3w1M
12+
*/
13+
#if ARDUINO_USB_MODE
14+
#warning This sketch should be used when USB is in OTG mode
15+
void setup() {}
16+
void loop() {}
17+
#else
18+
19+
#include <math.h>
20+
21+
#include "USB.h"
22+
#include "USBMIDI.h"
23+
USBMIDI MIDI;
24+
25+
#define MIDI_NOTE_C4 64
26+
27+
#define MIDI_CC_CUTOFF 74
28+
29+
///// ADC & Controller Input Handling /////
30+
31+
#define CONTROLLER_PIN 5
32+
33+
// ESP32 ADC needs a ton of smoothing
34+
#define SMOOTHING_VALUE 1000
35+
static double controllerInputValue = 0;
36+
37+
void updateControllerInputValue() {
38+
controllerInputValue =
39+
(controllerInputValue * (SMOOTHING_VALUE - 1) + analogRead(CONTROLLER_PIN)) / SMOOTHING_VALUE;
40+
}
41+
42+
void primeControllerInputValue() {
43+
for (int i = 0; i < SMOOTHING_VALUE; i++) {
44+
updateControllerInputValue();
45+
}
46+
}
47+
48+
uint16_t readControllerValue() {
49+
// Lower ADC input amplitude to get a stable value
50+
return round(controllerInputValue / 12);
51+
}
52+
53+
///// Button Handling /////
54+
55+
#define BUTTON_PIN 0
56+
57+
// Simple button state transition function with debounce
58+
// (See also: https://tinyurl.com/simple-debounce)
59+
#define PRESSED 0xff00
60+
#define RELEASED 0xfe1f
61+
uint16_t getButtonEvent() {
62+
static uint16_t state = 0;
63+
state = (state << 1) | digitalRead(BUTTON_PIN) | 0xfe00;
64+
return state;
65+
}
66+
67+
///// Arduino Hooks /////
68+
69+
void setup() {
70+
Serial.begin(115200);
71+
MIDI.begin();
72+
USB.begin();
73+
74+
primeControllerInputValue();
75+
}
76+
77+
void loop() {
78+
uint16_t newControllerValue = readControllerValue();
79+
static uint16_t lastControllerValue = 0;
80+
81+
// Auto-calibrate the controller range
82+
static uint16_t maxControllerValue = 0;
83+
static uint16_t minControllerValue = 0xFFFF;
84+
85+
if (newControllerValue < minControllerValue) {
86+
minControllerValue = newControllerValue;
87+
}
88+
if (newControllerValue > maxControllerValue) {
89+
maxControllerValue = newControllerValue;
90+
}
91+
92+
// Send update if the controller value has changed
93+
if (lastControllerValue != newControllerValue) {
94+
lastControllerValue = newControllerValue;
95+
96+
// Can't map if the range is zero
97+
if (minControllerValue != maxControllerValue) {
98+
MIDI.controlChange(MIDI_CC_CUTOFF,
99+
map(newControllerValue, minControllerValue, maxControllerValue, 0, 127));
100+
}
101+
}
102+
103+
updateControllerInputValue();
104+
105+
// Hook Button0 to a MIDI note so that we can observe
106+
// the CC effect without the need for a MIDI keyboard.
107+
switch (getButtonEvent()) {
108+
case PRESSED:
109+
MIDI.noteOn(MIDI_NOTE_C4, 64);
110+
break;
111+
case RELEASED:
112+
MIDI.noteOff(MIDI_NOTE_C4, 0);
113+
break;
114+
default:
115+
break;
116+
}
117+
}
118+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/MIDI/MidiInterface/.skip.esp32

Whitespace-only changes.

libraries/USB/examples/MIDI/MidiInterface/.skip.esp32c3

Whitespace-only changes.

libraries/USB/examples/MIDI/MidiInterface/.skip.esp32c6

Whitespace-only changes.

libraries/USB/examples/MIDI/MidiInterface/.skip.esp32h2

Whitespace-only changes.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
This is an example of using an ESP32 with a native USB support stack (S2, S3, etc.) as a Serial MIDI to
3+
USB MIDI bridge (AKA "A MIDI Interface").
4+
5+
View this sketch in action on YouTube: https://youtu.be/BXG5i55I9s0
6+
7+
Receiving and decoding USB MIDI 1.0 packets is a more advanced topic than sending MIDI over USB,
8+
please refer to the other examples in this library for a more basic example of sending MIDI over USB.
9+
10+
This example should still be self explanatory, please refer to the USB MIDI 1.0 specification (the spec)
11+
for a more in-depth explanation of the packet format.
12+
13+
For the spec please visit: https://www.midi.org/specifications-old/item/usb-midi-1-0-specification
14+
15+
Note: Because ESP32 works at VCC=3.3v normal schematics for Serial MIDI connections will not suffice,
16+
Please refer to the Updated MIDI 1.1 Electrical Specification [1] for information on how to hookup
17+
Serial MIDI for 3.3v devices.
18+
19+
[1] - https://www.midi.org/specifications/midi-transports-specifications/5-pin-din-electrical-specs
20+
*/
21+
#if ARDUINO_USB_MODE
22+
#warning This sketch should be used when USB is in OTG mode
23+
void setup() {}
24+
void loop() {}
25+
#else
26+
27+
#include "USB.h"
28+
#include "USBMIDI.h"
29+
USBMIDI MIDI;
30+
31+
#define MIDI_RX 39
32+
#define MIDI_TX 40
33+
34+
void setup() {
35+
// USBCDC Serial
36+
Serial.begin(115200);
37+
38+
// HW UART Serial
39+
Serial1.begin(31250, SERIAL_8N1, MIDI_RX, MIDI_TX);
40+
41+
MIDI.begin();
42+
USB.begin();
43+
}
44+
45+
void loop() {
46+
// MIDI Serial 1.0 to USB MIDI 1.0
47+
if (Serial1.available()) {
48+
byte data = Serial1.read();
49+
MIDI.write(data);
50+
}
51+
52+
// USB MIDI 1.0 to MIDI Serial 1.0
53+
midiEventPacket_t midi_packet_in = {0};
54+
// See Chapter 4: USB-MIDI Event Packets (page 16) of the spec.
55+
int8_t cin_to_midix_size[16] = {-1, -1, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1};
56+
57+
if (MIDI.readPacket(&midi_packet_in)) {
58+
midi_code_index_number_t code_index_num = MIDI_EP_HEADER_CIN_GET(midi_packet_in.header);
59+
int8_t midix_size = cin_to_midix_size[code_index_num];
60+
61+
// We skip Misc and Cable Events for simplicity
62+
if (code_index_num >= 0x2) {
63+
for (int i = 0; i < midix_size; i++) {
64+
Serial1.write(((uint8_t *)&midi_packet_in)[i + 1]);
65+
}
66+
Serial1.flush();
67+
}
68+
}
69+
}
70+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/MIDI/MidiMusicBox/.skip.esp32

Whitespace-only changes.

libraries/USB/examples/MIDI/MidiMusicBox/.skip.esp32c3

Whitespace-only changes.

libraries/USB/examples/MIDI/MidiMusicBox/.skip.esp32c6

Whitespace-only changes.

libraries/USB/examples/MIDI/MidiMusicBox/.skip.esp32h2

Whitespace-only changes.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
This is an example of a MIDI Music Box using an ESP32 with a native USB support stack (S2, S3, etc.).
3+
4+
Every time the button on the ESP32 board (attached to pin 0) is pressed the next note of a melody is
5+
played. It is up to the user to get the timing of the button presses right.
6+
7+
One simple way of running this sketch is to download the Pianoteq evaluation version, because upon
8+
application start it automatically listens to the first MIDI Input on Channel 1, which is the case,
9+
if the ESP32 is the only MIDI device attached.
10+
11+
View this sketch in action on YouTube: https://youtu.be/JFrc-wSmcus
12+
*/
13+
#if ARDUINO_USB_MODE
14+
#warning This sketch should be used when USB is in OTG mode
15+
void setup() {}
16+
void loop() {}
17+
#else
18+
19+
#include "USB.h"
20+
#include "USBMIDI.h"
21+
USBMIDI MIDI;
22+
23+
#define END_OF_SONG 255
24+
uint8_t notes[] = {END_OF_SONG, 71, 76, 79, 78, 76, 83, 81, 78, 76, 79, 78, 75, 77, 71};
25+
uint8_t noteIndex = 0; // From 0 to sizeof(notes)
26+
#define SONG_LENGTH (sizeof(notes) - 1) // END_OF_SONG does not attribute to the length.
27+
28+
#define BUTTON_PIN 0
29+
30+
// Simple button press check with debounce
31+
// (See also: https://tinyurl.com/simple-debounce)
32+
bool isButtonPressed() {
33+
static uint16_t state = 0;
34+
state = (state << 1) | digitalRead(BUTTON_PIN) | 0xfe00;
35+
return (state == 0xff00);
36+
}
37+
38+
void setup() {
39+
Serial.begin(115200);
40+
// Make the BUTTON_PIN an input:
41+
pinMode(BUTTON_PIN, INPUT_PULLUP);
42+
43+
MIDI.begin();
44+
USB.begin();
45+
}
46+
47+
void loop() {
48+
if (isButtonPressed()) {
49+
// Stop current note
50+
MIDI.noteOff(notes[noteIndex]);
51+
52+
// Play next note
53+
noteIndex = noteIndex < SONG_LENGTH ? noteIndex + 1 : 0;
54+
if (notes[noteIndex] != END_OF_SONG) {
55+
MIDI.noteOn(notes[noteIndex], 64);
56+
}
57+
}
58+
}
59+
#endif /* ARDUINO_USB_MODE */

libraries/USB/examples/MIDI/ReceiveMidi/.skip.esp32

Whitespace-only changes.

libraries/USB/examples/MIDI/ReceiveMidi/.skip.esp32c3

Whitespace-only changes.

libraries/USB/examples/MIDI/ReceiveMidi/.skip.esp32c6

Whitespace-only changes.

libraries/USB/examples/MIDI/ReceiveMidi/.skip.esp32h2

Whitespace-only changes.

0 commit comments

Comments
 (0)