-
Notifications
You must be signed in to change notification settings - Fork 23
/
zyncontrol_mini_v2.c
144 lines (122 loc) · 4.42 KB
/
zyncontrol_mini_v2.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
/*
* ******************************************************************
* ZYNTHIAN PROJECT: Zyncontrol Library for Zynthian Kit MINI V2
*
* Initialize & configure control hardware for Zynthian Kit MINI V2
*
* 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"
//-----------------------------------------------------------------------------
// 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;
}
//-----------------------------------------------------------------------------
// 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 + 9, MCP23017_2_BASE_PIN + 8);
setup_zyncoder(1, MCP23017_2_BASE_PIN + 11, MCP23017_2_BASE_PIN + 10);
setup_zyncoder(2, MCP23017_2_BASE_PIN + 13, MCP23017_2_BASE_PIN + 12);
setup_zyncoder(3, MCP23017_2_BASE_PIN + 15, MCP23017_2_BASE_PIN + 14);
int i;
for (i=0;i<4;i++) {
setup_zynpot(i,ZYNPOT_ZYNCODER,i);
}
}
void end_zynpots() {
reset_zynpots();
}
//-----------------------------------------------------------------------------
// Zyncontrol Initialization
//-----------------------------------------------------------------------------
int init_zyncontrol() {
gpiod_init_callbacks();
init_zynmcp23017s();
init_zynswitches();
init_zynpots();
gpiod_start_callbacks();
return 1;
}
int end_zyncontrol() {
gpiod_stop_callbacks();
end_zynpots();
reset_zyncoders();
reset_zynswitches();
reset_zynmcp23017s();
return 1;
}
//-----------------------------------------------------------------------------