-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathzynaptik.h
193 lines (155 loc) · 5.63 KB
/
zynaptik.h
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
* ******************************************************************
* ZYNTHIAN PROJECT: Zynaptik Library
*
* Library for interfacing external sensors and actuators.
* It implements interfaces with extra MCP23017, ADS1115, etc.
*
* Copyright (C) 2015-2019 Fernando Moyano <[email protected]>
*
* ******************************************************************
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the LICENSE.txt file.
*
* ******************************************************************
*/
#ifndef ZYNNAPTIK_H
#define ZYNANPTIK_H
#include <stdint.h>
#include <unistd.h>
#include <pthread.h>
#include <stdbool.h>
#include <jack/jack.h>
#include <jack/midiport.h>
#include "zynads1115.h"
#include <MCP4728.h>
//-----------------------------------------------------------------------------
// MCP23017 Stuff
//-----------------------------------------------------------------------------
//Default config for Zynaptik's MCP23017
#if !defined(ZYNAPTIK_MCP23017_I2C_ADDRESS)
#define ZYNAPTIK_MCP23017_I2C_ADDRESS 0x21
#endif
#if !defined(ZYNAPTIK_MCP23017_BASE_PIN)
#define ZYNAPTIK_MCP23017_BASE_PIN 200
#endif
#if !defined(ZYNAPTIK_MCP23017_INTA_PIN)
#define ZYNAPTIK_MCP23017_INTA_PIN 27
#endif
#if !defined(ZYNAPTIK_MCP23017_INTB_PIN)
#define ZYNAPTIK_MCP23017_INTB_PIN 25
#endif
//-----------------------------------------------------------------------------
// ADS1115 Stuff
//-----------------------------------------------------------------------------
//Default config for Zynaptik's ADS1115
#if !defined(ZYNAPTIK_ADS1115_I2C_ADDRESS)
#define ZYNAPTIK_ADS1115_I2C_ADDRESS 0x48
#endif
#if !defined(ZYNAPTIK_ADS1115_BASE_PIN)
#define ZYNAPTIK_ADS1115_BASE_PIN 300
#endif
//-----------------------------------------------------------------------------
// MCP4728 Stuff
//-----------------------------------------------------------------------------
//Default config for Zynaptik's MCP4728
#if !defined(ZYNAPTIK_MCP4728_I2C_ADDRESS)
#if ZYNAPTIK_VERSION==1
#define ZYNAPTIK_MCP4728_I2C_ADDRESS 0x60
#else
#define ZYNAPTIK_MCP4728_I2C_ADDRESS 0x61
#endif
#endif
//-----------------------------------------------------------------------------
// CV-IN: Generate MIDI from Analog Inputs: CC, Pitchbend, Channel Pressure
//-----------------------------------------------------------------------------
#define MAX_NUM_ZYNCVINS 4
#define K_CVIN_VOLT_OCTAVE (12.0 * 6.144 / 32767.0)
#if !defined(ZYNAPTIK_CVIN_VOLTS_OCTAVE)
#define ZYNAPTIK_CVIN_VOLTS_OCTAVE 1.0
#endif
#if !defined(ZYNAPTIK_CVIN_NOTE0)
#define ZYNAPTIK_CVIN_NOTE0 0
#endif
struct zyncvin_st {
uint8_t enabled;
int midi_evt;
uint8_t midi_chan;
uint8_t midi_num;
uint16_t midi_val;
};
void zynaptik_cvin_set_volts_octave(float vo);
float zynaptik_cvin_get_volts_octave();
void zynaptik_cvin_set_note0(int note0);
int zynaptik_cvin_get_note0();
void zynaptik_setup_cvin(uint8_t i, int midi_evt, uint8_t midi_chan, uint8_t midi_num);
void zynaptik_disable_cvin(uint8_t i);
int32_t zynaptik_get_cvin(uint8_t i);
void zynaptik_cvin_to_midi(uint8_t i, uint16_t val);
//CV-IN Polling interval
#define POLL_ZYNAPTIK_CVINS_US 40000
pthread_t init_poll_zynaptik_cvins();
//-----------------------------------------------------------------------------
// CV-OUT: Set Analog Outputs from MIDI: CC, Notes (velocity+pitchbend)
//-----------------------------------------------------------------------------
#define MAX_NUM_ZYNCVOUTS 4
#define K_CVOUT_VOLT_OCTAVE (60.0 / (127.0 * 0.97))
#if !defined(ZYNAPTIK_CVOUT_VOLTS_OCTAVE)
#define ZYNAPTIK_CVOUT_VOLTS_OCTAVE 1.0
#endif
#if !defined(ZYNAPTIK_CVOUT_NOTE0)
#define ZYNAPTIK_CVOUT_NOTE0 0
#endif
struct zyncvout_st {
uint8_t enabled;
int midi_evt;
uint8_t midi_chan;
uint8_t midi_num;
uint8_t note[128];
uint16_t midi_event_temp;
uint16_t midi_event_mask;
uint16_t val;
};
void zynaptik_cvout_set_volts_octave(float vo);
float zynaptik_cvout_get_volts_octave();
void zynaptik_cvout_set_note0(int note0);
int zynaptik_cvout_get_note0();
void zynaptik_setup_cvout(uint8_t i, int midi_evt, uint8_t midi_chan, uint8_t midi_num);
void zynaptik_disable_cvout(uint8_t i);
void zynaptik_midi_to_cvout(jack_midi_event_t *ev);
void zynaptik_set_cvout(int i, uint16_t val);
void zynaptik_refresh_cvouts();
//CV-OUT Refresh interval
#define REFRESH_ZYNAPTIK_CVOUTS_US 40000
//-----------------------------------------------------------------------------
// GATE-OUT: Set Digital Outputs from MIDI Notes
//-----------------------------------------------------------------------------
#define MAX_NUM_ZYNGATEOUTS 36
struct zyngateout_st {
uint8_t enabled;
int midi_evt;
uint8_t midi_chan;
uint8_t midi_num;
uint16_t midi_event_temp;
uint16_t midi_event_mask;
};
void zynaptik_setup_gateout(uint8_t i, int midi_evt, uint8_t midi_chan, uint8_t midi_num);
void zynaptik_disable_gateout(uint8_t i);
void zynaptik_midi_to_gateout(jack_midi_event_t *ev);
//-----------------------------------------------------------------------------
// Zynaptik Library Initialization
//-----------------------------------------------------------------------------
int init_zynaptik();
int end_zynaptik();
//-----------------------------------------------------------------------------
#endif