-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathhardware.h
More file actions
129 lines (101 loc) · 4.46 KB
/
hardware.h
File metadata and controls
129 lines (101 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (c) 2020-2026 Volker Fischer
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "Arduino.h"
#include "EEPROM.h"
#include "common.h"
#define MAX_EEPROM_SIZE 512 // bytes (Teensy 4.0: max 1024 bytes)
#define MAX_NUM_SET_PER_PAD 30 // maximum number of settings which can be stored per pad
// -----------------------------------------------------------------------------
// Teensy 4.0/4.1 --------------------------------------------------------------
// -----------------------------------------------------------------------------
#ifdef TEENSYDUINO
# include <ADC.h>
# define BOARD_LED_PIN 13 // pin number of the LED on the Teensy 4.0 board
# define ADC_MAX_RANGE 4096 // Teensy 4.0/4.1 ADC has 12 bits -> 0..4095
# define ADC_MAX_NOISE_AMPL 8 // highest assumed ADC noise amplitude in the ADC input range unit (measured)
class Edrumulus_hardware
{
public:
Edrumulus_hardware();
static int get_prototype_pins(int** analog_pins,
int** analog_pins_rimshot,
int* number_pins,
int* status_LED_pin);
void setup(const int conf_Fs,
const int number_pads,
const int number_inputs[],
int analog_pin[][MAX_NUM_PAD_INPUTS]);
void capture_samples(const int number_pads,
const int number_inputs[],
uint16_t sample_org[][MAX_NUM_PAD_INPUTS]);
void write_setting(const int pad_index, const int address, const byte value);
byte read_setting(const int pad_index, const int address);
protected:
int Fs;
IntervalTimer myTimer;
static void on_timer();
volatile bool timer_ready;
ADC adc_obj;
int total_number_inputs;
int input_pin[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
uint16_t input_sample[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
};
#endif
// -----------------------------------------------------------------------------
// ESP32 Dual Core -------------------------------------------------------------
// -----------------------------------------------------------------------------
#ifdef ESP_PLATFORM
# include "driver/adc.h"
# include "soc/sens_reg.h"
# ifdef CONFIG_IDF_TARGET_ESP32
# include "driver/dac.h"
# else // CONFIG_IDF_TARGET_ESP32S3
# include "hal/adc_hal.h"
# endif
# define BOARD_LED_PIN 2 // pin number of the LED on the ESP32 board
# define ADC_MAX_RANGE 4096 // ESP32 ADC has 12 bits -> 0..4095
# define ADC_MAX_NOISE_AMPL 8 // highest assumed ADC noise amplitude in the ADC input range unit (measured)
class Edrumulus_hardware
{
public:
Edrumulus_hardware();
static int get_prototype_pins(int** analog_pins,
int** analog_pins_rimshot,
int* number_pins,
int* status_LED_pin);
void setup(const int conf_Fs,
const int number_pads,
const int number_inputs[],
int analog_pin[][MAX_NUM_PAD_INPUTS]);
void capture_samples(const int number_pads,
const int number_inputs[],
uint16_t sample_org[][MAX_NUM_PAD_INPUTS]);
void write_setting(const int, const int, const byte) {}; // not supported
byte read_setting(const int, const int) { return 0; }; // not supported
protected:
int Fs;
EEPROMClass eeprom_settings;
volatile SemaphoreHandle_t timer_semaphore;
hw_timer_t* timer = nullptr;
static void IRAM_ATTR on_timer();
static void start_timer_core0_task(void* param);
void setup_timer();
void init_my_analogRead();
uint16_t my_analogRead(const uint8_t pin);
void my_analogRead_parallel(const uint32_t channel_adc1_bitval,
const uint32_t channel_adc2_bitval,
uint16_t& out_adc1,
uint16_t& out_adc2);
int total_number_inputs;
int input_pin[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
uint16_t input_sample[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
int num_pin_pairs;
int adc1_index[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
int adc2_index[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
uint32_t channel_adc1_bitval[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
uint32_t channel_adc2_bitval[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
int num_pin_single;
int single_index[MAX_NUM_PADS * MAX_NUM_PAD_INPUTS];
};
#endif