2026-03-29 14:47:13 +02:00

99 lines
5.5 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
// VersaPad v2 SAMD21G18A Custom Variant
// Arduino pin assignments for the custom PCB
#define ARDUINO_SAMD_VARIANT_COMPLIANCE 10610
#include <WVariant.h>
// ─── Pin count ────────────────────────────────────────────────────────────────
// D0D9 : Button matrix (COL_04, ROW_04)
// D10D17 : Rotary encoders A/B (ENC0ENC3), all on EIC
// D18D20 : SPI for WS2812 (SERCOM5: MOSI, SCK, MISO)
// D21D22 : USB D/D+ (internal, not exposed)
// D23D25 : Fader ADC inputs (A0A2)
// ─────────────────────────────────────────────────────────────────────────────
#define PINS_COUNT (26u)
#define NUM_DIGITAL_PINS (23u) // D0D22 usable as digital
#define NUM_ANALOG_INPUTS (3u) // A0A2 = D23D25
#define NUM_ANALOG_OUTPUTS (0u)
#define analogInputToDigitalPin(p) ((p < NUM_ANALOG_INPUTS) ? (p) + 23u : -1)
// digitalPinToInterrupt is defined by Arduino.h as (P).
// attachInterrupt() then internally looks up ulExtInt via g_APinDescription.
// ─── Button Matrix ────────────────────────────────────────────────────────────
// Columns (driven LOW one at a time)
#define PIN_COL0 (4u) // PB10 also encoder SW column
#define PIN_COL1 (3u) // PA11
#define PIN_COL2 (2u) // PA10
#define PIN_COL3 (1u) // PA09
#define PIN_COL4 (0u) // PA08
// Rows (read with internal pull-up)
#define PIN_ROW0 (5u) // PB11
#define PIN_ROW1 (6u) // PA12
#define PIN_ROW2 (7u) // PA13
#define PIN_ROW3 (8u) // PA14
#define PIN_ROW4 (9u) // PA15
// ─── Rotary Encoders ──────────────────────────────────────────────────────────
// All on EIC (External Interrupt Controller) for hardware quadrature
#define PIN_ENC0_A (16u) // PA22 EIC EXTINT6
#define PIN_ENC0_B (17u) // PA23 EIC EXTINT7
#define PIN_ENC1_A (14u) // PA20 EIC EXTINT4
#define PIN_ENC1_B (15u) // PA21 EIC EXTINT5
#define PIN_ENC2_A (12u) // PA18 EIC EXTINT2
#define PIN_ENC2_B (13u) // PA19 EIC EXTINT3
#define PIN_ENC3_A (10u) // PA16 EIC EXTINT0
#define PIN_ENC3_B (11u) // PA17 EIC EXTINT1
// ─── WS2812 SPI (SERCOM5) ─────────────────────────────────────────────────────
#define PIN_SPI_MOSI (18u) // PB22 SERCOM5 PAD2 ← LED data line
#define PIN_SPI_SCK (19u) // PB23 SERCOM5 PAD3
#define PIN_SPI_MISO (20u) // PB03 SERCOM5 PAD1 (unused for WS2812)
#define PERIPH_SPI sercom5
#define PAD_SPI_TX SPI_PAD_2_SCK_3 // MOSI=PAD2, SCK=PAD3
#define PAD_SPI_RX SERCOM_RX_PAD_1 // MISO=PAD1
// ─── Faders (ADC) ─────────────────────────────────────────────────────────────
#define PIN_A0 (23u) // PA02 ADC AIN[0]
#define PIN_A1 (24u) // PA03 ADC AIN[1] (also VREFA)
#define PIN_A2 (25u) // PB08 ADC AIN[2]
#define PIN_FADER0 PIN_A0
#define PIN_FADER1 PIN_A1
#define PIN_FADER2 PIN_A2
static const uint8_t A0 = PIN_A0;
static const uint8_t A1 = PIN_A1;
static const uint8_t A2 = PIN_A2;
// ─── USB (internal) ───────────────────────────────────────────────────────────
#define PIN_USB_DM (21u) // PA24
#define PIN_USB_DP (22u) // PA25
#define PIN_USB_HOST_ENABLE (21u) // unused, required by core
// ─── SPI ──────────────────────────────────────────────────────────────────────
#define SPI_INTERFACES_COUNT 0 // SPI-Objekt wird in src/hal/spi.cpp definiert
// ─── Serial / UART ────────────────────────────────────────────────────────────
// No hardware UART exposed; USB CDC is used as Serial
#define SERIAL_INTERFACES_COUNT 0
// ─── I2C ──────────────────────────────────────────────────────────────────────
// Not used on this board, stubs required by core
#define WIRE_INTERFACES_COUNT 0
#define PIN_WIRE_SDA (16u) // PA22 (reused, I2C not enabled)
#define PIN_WIRE_SCL (17u) // PA23
// ─── ADC reference ────────────────────────────────────────────────────────────
#define ADC_RESOLUTION 12
// ─── Clock ────────────────────────────────────────────────────────────────────
// Required by cores/arduino/delay.c (micros / delayMicroseconds)
#define VARIANT_MCK (48000000ul)
#define VARIANT_MAINOSC (32768ul)