Skip to content

Commit 1f4b5b4

Browse files
committed
Matrix Hardware Midi Out
1 parent 707b597 commit 1f4b5b4

4 files changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "Device.h"
2+
3+
namespace Device
4+
{
5+
namespace HWMidi
6+
{
7+
MidiPort* midiPort;
8+
TaskHandle_t portTaskHandle = NULL;
9+
uart_port_t uartChannel = UART_NUM_2;
10+
11+
void portTask(void* param) {
12+
MidiPort port = MidiPort("Midi Port", MIDI_PORT_PHYISCAL);
13+
midiPort = &port;
14+
MidiPacket packet;
15+
while (true)
16+
{
17+
if (port.Get(&packet, portMAX_DELAY))
18+
{ uart_write_bytes(uartChannel, packet.data, 3); }
19+
}
20+
}
21+
22+
void Init()
23+
{
24+
uart_config_t uart_config = {
25+
.baud_rate = 31250,
26+
.data_bits = UART_DATA_8_BITS,
27+
.parity = UART_PARITY_DISABLE,
28+
.stop_bits = UART_STOP_BITS_1,
29+
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
30+
.rx_flow_ctrl_thresh = 0,
31+
.source_clk = UART_SCLK_DEFAULT,
32+
};
33+
34+
int rx_buffer_size = 2048; // TODO: Optimize this value
35+
if(rx_gpio == GPIO_NUM_NC)
36+
{
37+
rx_buffer_size = 129; // Must be larger than 128, even though we don't use it
38+
}
39+
40+
ESP_ERROR_CHECK(uart_driver_install(uartChannel, rx_buffer_size, 0, 0, NULL, 0));
41+
ESP_ERROR_CHECK(uart_param_config(uartChannel, &uart_config));
42+
ESP_ERROR_CHECK(uart_set_pin(uartChannel, tx_gpio, rx_gpio, GPIO_NUM_NC, GPIO_NUM_NC));
43+
xTaskCreate(portTask, "Hardware Midi Port", configMINIMAL_STACK_SIZE * 2, NULL, configMAX_PRIORITIES - 2,&portTaskHandle);
44+
}
45+
}
46+
}

devices/MatrixBlock6_ESP32S3/Family.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ namespace Device
1717
NVS::Init();
1818
LED::Init();
1919
KeyPad::Init();
20+
2021

22+
HWMidi::Init();
2123
BLEMIDI::Init(name);
2224

2325
// WIFI::Init();

devices/MatrixBlock6_ESP32S3/Family.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include "esp_efuse_table.h"
1717
#include "esp_adc/adc_oneshot.h"
1818

19+
#include "driver/uart.h"
20+
#include "driver/gpio.h"
21+
1922
#include "nvs_flash.h"
2023

2124
#include "esp_private/system_internal.h"
@@ -88,6 +91,11 @@ namespace Device
8891
MidiPacket GetMidi();
8992
}
9093

94+
namespace HWMidi
95+
{
96+
void Init();
97+
}
98+
9199
namespace ESPNOW
92100
{
93101
extern bool started;

devices/MatrixBlock6_ESP32S3/Varients/MatrixPro/Config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ namespace Device
107107
}
108108
}
109109

110+
namespace HWMidi
111+
{
112+
inline gpio_num_t tx_gpio = GPIO_NUM_18;
113+
inline gpio_num_t rx_gpio = GPIO_NUM_NC;
114+
}
115+
110116
// LED
111117
#define MAX_LED_LAYERS 5
112118
inline gpio_num_t led_pin;

0 commit comments

Comments
 (0)