Porting ElectroSmash PedalShield Uno Code to R4 Minima

Hi all,
I've had a go at porting the example code for the ElectroSmash PedalShield Uno to the R4 Minima. For now, I'm taking baby steps and just focusing on the ADC part. I was hoping to output to Serial as an intermediate step. Reading the from the ADC140.ADDR0 register in loop() and adding a delay works, but I'd like this to work in the callback. I feel like I'm close and am just missing one thing. I haven't fully grokked the Event Link Controller aspect and I'm not sure if that's the missing piece here. Here's the code:

#include "Arduino.h"

// System Clock
// §8.2.1
#define SYSTEM 0x40010000
#define SYSTEM_SCKDIVCR ((volatile unsigned int *)(SYSTEM + 0xE020))

// Module Stop Control Registers
// §10.2.4 Register Description
#define MSTP 0x40040000 
#define MSTP_MSTPCRD   ((volatile unsigned int *)(MSTP + 0x7008))      // Module Stop Control Register D §10.2.5
#define MSTPD16 16 // ADC140 - 14-Bit A/D Converter Module

// ========== ICU ==========
// 13.2.4 (Table 13.4)
#define ICUBASE 0x40000000
#define ICU_IELSR06 ((volatile unsigned int *)(ICUBASE + 0x6300 + (4*6)))

// =========== IRQ Event Numbers ==========
//
#define IRQ_ADC140_ADI 0x29

// =========== ELC =========
// 18.2.3 Register Descriptions
#define ELSRBASE 0x40040000
#define ELC_ELSR8 ((volatile unsigned short *)(ELSRBASE + 0x1030)) // ADC14A (module) ELC_ADC00 (event name)

// =========== ADC14 ============
// 35.2 Register Descriptions
#define ADCBASE 0x40050000 /* ADC Base */

#define ADC140_ADCSR   ((volatile unsigned short *)(ADCBASE + 0xC000)) // A/D Control Register
#define ADC140_ADANSA0 ((volatile unsigned short *)(ADCBASE + 0xC004)) // A/D Channel Select Register A0
#define ADC140_ADANSA1 ((volatile unsigned short *)(ADCBASE + 0xC006)) // A/D Channel Select Register A1
#define ADC140_ADADS0  ((volatile unsigned short *)(ADCBASE + 0xC008)) // A/D-Converted Value Addition/Average Channel Select Register 0
#define ADC140_ADADS1  ((volatile unsigned short *)(ADCBASE + 0xC00A)) // A/D-Converted Value Addition/Average Channel Select Register 1
#define ADC140_ADCER   ((volatile unsigned short *)(ADCBASE + 0xC00E)) // A/D Control Extended Register 
#define ADC140_ADSTRGR ((volatile unsigned short *)(ADCBASE + 0xC010)) // A/D Conversion Start Trigger Select Register
#define ADC140_ADEXICR ((volatile unsigned short *)(ADCBASE + 0xC012)) // A/D Conversion Extended Input Control Register
#define ADC140_ADANSB0 ((volatile unsigned short *)(ADCBASE + 0xC014)) // A/D Channel Select Register B0
#define ADC140_ADANSB1 ((volatile unsigned short *)(ADCBASE + 0xC016)) // A/D Channel Select Register B1
#define ADC140_ADTSDR  ((volatile unsigned short *)(ADCBASE + 0xC01A)) // A/D conversion result of temperature sensor output
#define ADC140_ADOCDR  ((volatile unsigned short *)(ADCBASE + 0xC01C)) // A/D result of internal reference voltage
#define ADC140_ADRD    ((volatile unsigned short *)(ADCBASE + 0xC01E)) // A/D Self-Diagnosis Data Register

#define ADC140_ADDR00 ((volatile unsigned short *)(ADCBASE + 0xC020))      // A1 (P000 AN00 AMP+)
#define ADC140_ADDR01 ((volatile unsigned short *)(ADCBASE + 0xC020 +  2)) // A2 (P001 AN01 AMP-) 
#define ADC140_ADDR02 ((volatile unsigned short *)(ADCBASE + 0xC020 +  4)) // A3 (P002 AN02 AMPO) 
#define ADC140_ADDR05 ((volatile unsigned short *)(ADCBASE + 0xC020 + 10)) // Aref (P010 AN05 VrefH0)
#define ADC140_ADDR09 ((volatile unsigned short *)(ADCBASE + 0xC020 + 18)) // A0 (P014 AN09 DAC)
#define ADC140_ADDR21 ((volatile unsigned short *)(ADCBASE + 0xC040 + 10)) // A4 (P101 AN21 SDA) 
#define ADC140_ADDR22 ((volatile unsigned short *)(ADCBASE + 0xC040 + 12)) // A5 (P100 AN20 SCL) 

#define ADC140_ADHVREFCNT ((volatile unsigned char  *)(ADCBASE + 0xC08A)) // A/D High-Potential/Low-Potential Reference Voltage Control Register
#define ADC140_ADADC      ((volatile unsigned char  *)(ADCBASE + 0xC00C)) // A/D-Converted Value Addition/Average Count Select Register
#define ADC140_ADSSTR00 ((volatile unsigned char *)(ADCBASE + 0xC0E0)) // AN000 A/D Sampling State Register

// Port Pin Function Select Register (PmnPFS with m 0..9 and n 00..15)
// used to set pin functions to something other than default pin I/O
// These are for the R4 Minima

#define PORTBASE 0x40040000 // Port Base 
#define P000PFS 0x0800 // Port 0 Pin Function Select Register
#define PFS_P000PFS ((volatile unsigned int *)(PORTBASE + P000PFS)) // A1/D15 - AN00 - AMP0+ - IRQ6
#define PFS_P001PFS ((volatile unsigned int *)(PORTBASE + P000PFS + (1*4))) // A2/D16 - AN01 - AMP0- - IRQ7

// Maybe there's something in DeltaG's rewrite of the TimerOne library
// https://forum.arduino.cc/t/is-there-a-good-replacement-for-timerone/1182956

// Apparently this can be set up with the FSP configurator or with the following, from
// https://community.renesas.com/mcu-mpu/ra/f/forum/29775/gpt-trigger-adc-without-using-fsp

// Copied from https://github.com/TriodeGirl/Arduino-UNO-R4-code-DAC-ADC-Ints-Fast_Pins

uint16_t adc_val;

void setup() {
  Serial.begin(115200);
  while(!Serial){}; // Wait for Serial port

  attachInterrupt(15,adc_complete_interrupt,FALLING); // Set callback for pin A1/D15
  *PFS_P000PFS = 0x00000000; // Clear the A1/D15 ISEL pin in the Interrupt Table
  *ICU_IELSR06 = IRQ_ADC140_ADI; // Assign slot 06 to the ADC140_ADI

  setup_adc();
  
  *ADC140_ADCSR   |= (0x01 << 15);   // Start an ADC conversion §35.2.3
}

void loop() {
}
  
void adc_complete_interrupt(void) {
  adc_val = *ADC140_ADDR00; // Read from ADC140.ADDR0
  Serial.println(adc_val); // Doesn't write anything to Serial out
}

void setup_adc()
{
  // Trying to map the intent of the ElectroSmash PedalShield Uno code from here:
  // https://www.electrosmash.com/pedalshield-uno
  // Things the R3 code does
  // * Set ADC to left-adjust
  // * Set reference to internal voltage (5V)
  // * Turn on the ADC
  // * Start ADC conversion
  // * Enable auto conversion
  // * Set auto conversion trigger to Timer 1
  // * Set the division factor/clock prescaler to 32 (16 MHz -> 500kHz)
  // * Turn off digital inputs for A0
  // Also see http://wiki.openmusiclabs.com/wiki/PWMDAC for how this worked on the ATmega328p

  // Set the ADC conversion clock to 64 MHz/8 = 8 MHz
  // Need to set the Peripheral bus clock (PCKB) as well, and the ratio of
  // PCKB to PCKC is constrained to certain values in the manual
  *SYSTEM_SCKDIVCR = 0x330; // Set the ADC clock (PCKC) to 1/8 and Peripheral Clock to 1/8, a 1:1 ratio
  // Now, set the sampling state register to 16, this yields a sampling time of
  // 64 MHz/8 = 8 MHz/16 states = 1 sample every 500 kHz. See §35.2.14
  *ADC140_ADSSTR00 = 0x10; // Set channel AN000 to 16 states

  // Set up A/D Converter
  *MSTP_MSTPCRD &= (0xFFFFFFFF - (0x01 << MSTPD16));  // Enable ADC140 module (Table 35.2)
  *ADC140_ADCER = 0x06;              // Turn off automatic cleaning, bit 5 §35.2.11
  // Setting bit 15 (using 0x8006) in ADCER sets flush left A/D data register format
  *ADC140_ADCSR = 0x4000;             // Set bit 14 and zero everthing else to enable Continuous Scan mode
  // In continous scan mode, ADC140_ADI is the ELC event generated at the end of the selected channel scan
  // ADC14_ADI is event number 0x29
  *ADC140_ADANSA0 |= (0x01 << 0);    // Set b0 to select ANSA00 = AN000 = A1 as ADC §35.2.4
  // Enable averaging
  *ADC140_ADADC    = 0x83;           // Average mode - 4x §35.2.10 (b7 enables average mode, b0,1 enable 4x)
  *ADC140_ADADS0  |= (0x01 << 0);    // Enable Averaging for ANSA00 §35.2.8
  *ADC140_ADHVREFCNT = 0x2; // Set the internal reference voltage as the high-potential reference voltage

  // Now set up the Event Link Register (Do we need to drag the Event Link Register in here at all?)
  //*ELC_ELSR8 = 0x29; // Set ADC14A Module to the A/D scan end interrupt (Table 18.3)
  //*ICU_IELSR8 = 0x29; // Set the ICU Event Link to the ADC140_ADI Interrupt
  // Not sure if I then need to do DTC activation (set bit 24)
  // Do I need to set the IRQCR to pick the sampling clock?
}

I have the output from the "input stage" of the PedalShield attached to pin A1.