initial beta support for esp32...

pull/19/head
midilab 1 year ago
parent 64667b865e
commit 9fa22a3210
  1. 76
      examples/ESP32UsbMasterMidiClock/ESP32UsbMasterMidiClock.ino
  2. 14
      examples/ESP32UsbMasterMidiClock/debug.cfg
  3. 19
      examples/ESP32UsbMasterMidiClock/debug_custom.json
  4. 46087
      examples/ESP32UsbMasterMidiClock/esp32.svd
  5. 6
      library.properties
  6. 25
      src/uClock.cpp
  7. 5
      src/uClock.h

@ -0,0 +1,76 @@
/* USB MIDI Sync Box
*
* This example demonstrates how to change the USB MIDI
* device name on ESP32 family.
*
* This example code is in the public domain.
*
* ...
*
*/
//#include <Adafruit_TinyUSB.h>
//#include <MIDI.h>
//Adafruit_USBD_MIDI usb_midi;
//MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI_USB);
//MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
#include <uClock.h>
// the blue led
int LED_BUILTIN = 2;
uint8_t bpm_blink_timer = 1;
void handle_bpm_led(uint32_t tick)
{
// BPM led indicator
if ( !(tick % (96)) || (tick == 1) ) { // first compass step will flash longer
bpm_blink_timer = 8;
digitalWrite(LED_BUILTIN, HIGH);
} else if ( !(tick % (24)) ) { // each quarter led on
bpm_blink_timer = 1;
digitalWrite(LED_BUILTIN, HIGH);
} else if ( !(tick % bpm_blink_timer) ) { // get led off
digitalWrite(LED_BUILTIN, LOW);
}
}
// Internal clock handlers
void ClockOut96PPQN(uint32_t tick) {
// Send MIDI_CLOCK to external gears
//MIDI_USB.sendRealTime(midi::Clock);
handle_bpm_led(tick);
}
void onClockStart() {
//MIDI_USB.sendRealTime(midi::Start);
}
void onClockStop() {
//MIDI_USB.sendRealTime(midi::Stop);
}
void setup() {
//MIDI_USB.begin(MIDI_CHANNEL_OMNI);
// A led to count bpms
pinMode(LED_BUILTIN, OUTPUT);
// Setup our clock system
// Inits the clock
uClock.init();
// Set the callback function for the clock output to send MIDI Sync message.
uClock.setClock96PPQNOutput(ClockOut96PPQN);
// Set the callback function for MIDI Start and Stop messages.
uClock.setOnClockStartOutput(onClockStart);
uClock.setOnClockStopOutput(onClockStop);
// Set the clock BPM to 126 BPM
uClock.setTempo(126);
// Starts the clock, tick-tac-tick-tac...
uClock.start();
}
// Do it whatever to interface with Clock.stop(), Clock.start(), Clock.setTempo() and integrate your environment...
void loop() {
}

@ -0,0 +1,14 @@
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Example OpenOCD configuration file for ESP32-WROVER-KIT board.
#
# For example, OpenOCD can be started for ESP32 debugging on
#
# openocd -f board/esp32-wrover-kit-3.3v.cfg
#
# Source the JTAG interface configuration file
source [find interface/ftdi/esp32_devkitj_v1.cfg]
set ESP32_FLASH_VOLTAGE 3.3
# Source the ESP32 configuration file
source [find target/esp32.cfg]

@ -0,0 +1,19 @@
{
"name":"Arduino on ESP32",
"toolchainPrefix":"xtensa-esp32-elf",
"svdFile":"esp32.svd",
"request":"attach",
"postAttachCommands":[
"set remote hardware-watchpoint-limit 2",
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
],
"overrideRestartCommands":[
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
]
}

File diff suppressed because it is too large Load Diff

@ -1,10 +1,10 @@
name=uClock name=uClock
version=1.1.4 version=1.2.0
author=Romulo Silva <contact@midilab.co> author=Romulo Silva <contact@midilab.co>
maintainer=Romulo Silva <contact@midilab.co> maintainer=Romulo Silva <contact@midilab.co>
sentence=BPM clock generator for Arduino platform. sentence=BPM clock generator for Arduino platform.
paragraph=A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(Teensy and Seedstudio XIAO M0) paragraph=A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(Teensy, Seedstudio XIAO M0 and ESP32)
category=Timing category=Timing
url=https://github.com/midilab/uClock url=https://github.com/midilab/uClock
architectures=avr,arm,samd architectures=avr,arm,samd,esp32
includes=uClock.h includes=uClock.h

@ -1,8 +1,8 @@
/*! /*!
* @file uClock.cpp * @file uClock.cpp
* Project BPM clock generator for Arduino * Project BPM clock generator for Arduino
* @brief A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(Teensy and Seedstudio XIAO M0) * @brief A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(Teensy, Seedstudio XIAO M0 and ESP32)
* @version 1.1.4 * @version 1.2.0
* @author Romulo Silva * @author Romulo Silva
* @date 10/06/2017 * @date 10/06/2017
* @license MIT - (c) 2022 - Romulo Silva - contact@midilab.co * @license MIT - (c) 2022 - Romulo Silva - contact@midilab.co
@ -44,6 +44,10 @@ IntervalTimer _uclockTimer;
//#include <TimerTC3.h> //#include <TimerTC3.h>
// uses TimerTc3 // uses TimerTc3
#endif #endif
// ESP32 family
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP32)
hw_timer_t * _uclockTimer = NULL;
#endif
#if defined(ARDUINO_ARCH_AVR) #if defined(ARDUINO_ARCH_AVR)
void uclockInitTimer() void uclockInitTimer()
@ -87,6 +91,19 @@ void uclockInitTimer()
// attach to generic uclock ISR // attach to generic uclock ISR
TimerTcc0.attachInterrupt(uclockISR); TimerTcc0.attachInterrupt(uclockISR);
#endif #endif
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP32)
_uclockTimer = timerBegin(0, 80, true);
// attach to generic uclock ISR
timerAttachInterrupt(_uclockTimer, &uclockISR, true);
// init clock tick time
timerAlarmWrite(_uclockTimer, init_clock, true);
// activate it!
timerAlarmEnable(_uclockTimer);
#endif
} }
#endif #endif
@ -213,6 +230,10 @@ void uClockClass::setTimerTempo(float bpm)
#if defined(SEEED_XIAO_M0) #if defined(SEEED_XIAO_M0)
TimerTcc0.setPeriod(tick_us_interval); TimerTcc0.setPeriod(tick_us_interval);
#endif #endif
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP32)
timerAlarmWrite(_uclockTimer, tick_us_interval, true);
#endif
#endif #endif
} }

@ -1,8 +1,8 @@
/*! /*!
* @file uClock.h * @file uClock.h
* Project BPM clock generator for Arduino * Project BPM clock generator for Arduino
* @brief A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(Teensy and Seedstudio XIAO M0) * @brief A Library to implement BPM clock tick calls using hardware interruption. Supported and tested on AVR boards(ATmega168/328, ATmega16u4/32u4 and ATmega2560) and ARM boards(Teensy, Seedstudio XIAO M0 and ESP32)
* @version 1.1.4 * @version 1.2.0
* @author Romulo Silva * @author Romulo Silva
* @date 10/06/2017 * @date 10/06/2017
* @license MIT - (c) 2022 - Romulo Silva - contact@midilab.co * @license MIT - (c) 2022 - Romulo Silva - contact@midilab.co
@ -44,6 +44,7 @@ namespace umodular { namespace clock {
#define MAX_BPM 300 #define MAX_BPM 300
// want a different avr clock support? // want a different avr clock support?
// TODO: we should do this using macro guards for avrs different clocks
#define AVR_CLOCK_FREQ 16000000 #define AVR_CLOCK_FREQ 16000000
#define PHASE_FACTOR 16 #define PHASE_FACTOR 16

Loading…
Cancel
Save