-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathzyncontrol_v5.c
179 lines (155 loc) · 5.38 KB
/
zyncontrol_v5.c
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
/*
* ******************************************************************
* ZYNTHIAN PROJECT: Zyncontrol Library for Zynthian Kit V5
*
* Initialize & configure control hardware for Zynthian Kit V5
*
* Copyright (C) 2015-2023 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.
*
* ******************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include "gpiod_callback.h"
#include "zynpot.h"
#include "zyncoder.h"
#include "tpa6130.h"
//-----------------------------------------------------------------------------
// Zynface V5
//-----------------------------------------------------------------------------
#ifdef ZYNAPTIK_CONFIG
#include "zynaptik.h"
#else
#define RBPI_GPIO_EXT1 24 // wiringPi 4
#define RBPI_GPIO_EXT2 23 // wiringPi 5
#endif
//-----------------------------------------------------------------------------
// GPIO Expander 1
//-----------------------------------------------------------------------------
#define MCP23017_1_BASE_PIN 100
#define MCP23017_1_I2C_ADDRESS 0x20
#define MCP23017_1_INTA_PIN 5 // wiringPi 21
#define MCP23017_1_INTB_PIN 6 // wiringPi 22
void zynmcp23017_ISR_bankA_1() {
zynmcp23017_ISR(0, 0);
}
void zynmcp23017_ISR_bankB_1() {
zynmcp23017_ISR(0, 1);
}
void (*zynmcp23017_ISRs_1[2]) = {
zynmcp23017_ISR_bankA_1,
zynmcp23017_ISR_bankB_1
};
//-----------------------------------------------------------------------------
// GPIO Expander 2
//-----------------------------------------------------------------------------
#define MCP23017_2_BASE_PIN 200
#define MCP23017_2_I2C_ADDRESS 0x21
#define MCP23017_2_INTA_PIN 17 // wiringPi 0
#define MCP23017_2_INTB_PIN 27 // wiringPi 2
void zynmcp23017_ISR_bankA_2() {
zynmcp23017_ISR(1, 0);
}
void zynmcp23017_ISR_bankB_2() {
zynmcp23017_ISR(1, 1);
}
void (*zynmcp23017_ISRs_2[2]) = {
zynmcp23017_ISR_bankA_2,
zynmcp23017_ISR_bankB_2
};
//-----------------------------------------------------------------------------
// 2 x zynmcp23017
//-----------------------------------------------------------------------------
void init_zynmcp23017s() {
reset_zynmcp23017s();
setup_zynmcp23017(0, MCP23017_1_BASE_PIN, MCP23017_1_I2C_ADDRESS, MCP23017_1_INTA_PIN, MCP23017_1_INTB_PIN, zynmcp23017_ISRs_1);
setup_zynmcp23017(1, MCP23017_2_BASE_PIN, MCP23017_2_I2C_ADDRESS, MCP23017_2_INTA_PIN, MCP23017_2_INTB_PIN, zynmcp23017_ISRs_2);
}
//-----------------------------------------------------------------------------
// 30 x ZynSwitches (16 on MCP23017_1, 8 on MCP23017_2)
//-----------------------------------------------------------------------------
extern uint16_t num_zynswitches;
void init_zynswitches() {
reset_zynswitches();
int i;
fprintf(stderr, "ZynCore: Setting-up 20+4 x Zynswitches...\n");
for (i=0;i<16;i++) setup_zynswitch(4+i, MCP23017_1_BASE_PIN + i, 1);
for (i=0;i<8;i++) setup_zynswitch(20+i, MCP23017_2_BASE_PIN + i, 1);
num_zynswitches = 28;
#ifndef ZYNAPTIK_CONFIG
fprintf(stderr, "ZynCore: Setting-up 2 x Zynswitches in RBPi GPIO...\n");
setup_zynswitch(num_zynswitches, RBPI_GPIO_EXT1, 1);
setup_zynswitch(num_zynswitches + 1, RBPI_GPIO_EXT2, 1);
num_zynswitches += 2;
#endif
}
//-----------------------------------------------------------------------------
// 4 x Zynpòts (Analog Encoder RV112)
//-----------------------------------------------------------------------------
void init_zynpots() {
reset_zyncoders();
reset_zynpots();
fprintf(stderr, "ZynCore: Setting-up Zynpots => 4 x PEC11 ...\n");
setup_zyncoder(0, MCP23017_2_BASE_PIN + 8, MCP23017_2_BASE_PIN + 9);
setup_zyncoder(1, MCP23017_2_BASE_PIN + 10, MCP23017_2_BASE_PIN + 11);
setup_zyncoder(2, MCP23017_2_BASE_PIN + 12, MCP23017_2_BASE_PIN + 13);
setup_zyncoder(3, MCP23017_2_BASE_PIN + 14, MCP23017_2_BASE_PIN + 15);
int i;
for (i=0;i<4;i++) {
setup_zynpot(i,ZYNPOT_ZYNCODER,i);
}
}
void end_zynpots() {
reset_zynpots();
}
//-----------------------------------------------------------------------------
// Zyncontrol Initialization
//-----------------------------------------------------------------------------
#ifdef TPA6130_DRIVER
uint8_t set_hpvol(uint8_t vol) { return tpa6130_set_volume(vol); }
uint8_t get_hpvol() { return tpa6130_get_volume(); }
uint8_t get_hpvol_max() { return tpa6130_get_volume_max(); }
#endif
int init_zyncontrol() {
gpiod_init_callbacks();
#ifdef TPA6130_DRIVER
tpa6130_init();
#endif
init_zynmcp23017s();
init_zynswitches();
init_zynpots();
#ifdef ZYNAPTIK_CONFIG
init_zynaptik();
#endif
gpiod_start_callbacks();
return 1;
}
int end_zyncontrol() {
gpiod_stop_callbacks();
#ifdef ZYNAPTIK_CONFIG
end_zynaptik();
#endif
end_zynpots();
reset_zyncoders();
reset_zynswitches();
reset_zynmcp23017s();
#ifdef TPA6130_DRIVER
tpa6130_end();
#endif
return 1;
}
//-----------------------------------------------------------------------------