forked from paulocode/picostation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.cpp
348 lines (289 loc) · 8.77 KB
/
cmd.cpp
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#include "cmd.h"
#include <stdio.h>
#include <stdint.h>
#include "hardware/pio.h"
#include "pico/stdlib.h"
#include "logging.h"
#include "main.pio.h"
#include "utils.h"
#include "values.h"
#if DEBUG_CMD
#define DEBUG_PRINT(...) printf(__VA_ARGS__)
#else
#define DEBUG_PRINT(...) while (0)
#endif
namespace Command
{
enum : uint
{
FOCUS_CONTROL = 0x0,
TRACKING_MODE = 0x2,
AUTO_SEQUENCE = 0x4,
JUMP_COUNT = 0x7,
MODE_SPEC = 0x8,
FUNC_SPEC = 0x9,
MONITOR_COUNT = 0xb,
SPINDLE = 0xe,
CUSTOM = 0xf
};
}
namespace Spindle
{
enum : uint
{
STOP = 0b0000, // 0
KICK = 0b1000, // 8
BRAKE = 0b1010, // A
CLVS = 0b1110, // E
CLVH = 0b1100, // C
CLVP = 0b1111, // F
CLVA = 0b0110, // 6
};
}
extern uint g_latched;
extern uint g_countTrack;
extern int g_track;
extern int g_originalTrack;
extern int g_sledMoveDirection;
extern uint64_t g_sledTimer;
extern volatile int g_sector;
extern int g_sectorForTrackUpdate;
extern int g_targetPlaybackSpeed;
extern volatile bool g_sensData[16];
extern volatile bool g_subqDelay;
extern volatile bool g_soctEnabled;
extern uint g_soctOffset;
extern volatile uint g_imageIndex;
static int s_autoSeqTrack = 0;
static int s_jumpTrack = 0;
static alarm_id_t s_autoSeqAlarmID = 0;
void setSens(uint what, bool new_value);
inline void autoSequence() // $4X
{
const uint sub_command = (g_latched & 0x0F0000) >> 16;
const bool reverse_jump = sub_command & 0x1;
// const uint timer_range = (g_latched & 0x8) >> 3;
// const uint cancel_timer = (g_latched & 0xF) >> 4;
int tracks_to_move = 0;
g_sensData[SENS::XBUSY] = (sub_command != 0);
if (sub_command == 0x7) // Focus-On
{
DEBUG_PRINT("Focus-On\n");
return;
}
switch (sub_command & 0xe)
{
case 0x0: // Cancel
DEBUG_PRINT("Cancel\n");
return;
case 0x4: // Fine search
tracks_to_move = s_jumpTrack;
DEBUG_PRINT("Fine search%d\n", g_track);
break;
case 0x8: // 1 Track Jump
tracks_to_move = 1;
DEBUG_PRINT("1 Track Jump%d\n", g_track);
break;
case 0xA: // 10 Track Jump
tracks_to_move = 10;
DEBUG_PRINT("10 Track Jump%d\n", g_track);
break;
case 0xC: // 2N Track Jump
tracks_to_move = (2 * s_jumpTrack);
DEBUG_PRINT("2N Track Jump%d\n", g_track);
break;
case 0xE: // M Track Move
tracks_to_move = s_jumpTrack;
DEBUG_PRINT("M Track Move%d\n", g_track);
break;
default:
DEBUG_PRINT("Unsupported command: %x\n", sub_command);
break;
}
if (reverse_jump)
{
s_autoSeqTrack = g_track - tracks_to_move;
}
else
{
s_autoSeqTrack = g_track + tracks_to_move;
}
if (!s_autoSeqAlarmID)
{
s_autoSeqAlarmID = add_alarm_in_ms(15, [](alarm_id_t id, void *user_data) -> int64_t
{
const int track = *(int *)user_data;
s_autoSeqAlarmID = 0;
g_track = clamp(track, 0, c_trackMax);
g_sector = trackToSector(g_track);
g_sectorForTrackUpdate = g_sector;
setSens(SENS::XBUSY, 0);
return 0; }, &s_autoSeqTrack, true);
}
}
inline void funcSpec() // $9X
{
// const bool flfc = g_latched & (1 << 13);
// const bool biligl_sub = g_latched & (1 << 14);
// const bool biligl_main = g_latched & (1 << 15);
// const bool dpll = g_latched & (1 << 16);
// const bool aseq = g_latched & (1 << 17);
const bool dspb = g_latched & (1 << 18);
// const bool dclv = g_latched & (1 << 19);
if (!dspb) // DSPB = 0 Normal-speed playback, DSPB = 1 Double-speed playback
{
g_targetPlaybackSpeed = 1;
}
else
{
g_targetPlaybackSpeed = 2;
}
}
inline void modeSpec() // $8X
{
const bool soct = g_latched & (1 << 13);
// const bool ashs = g_latched & (1 << 14);
// const bool vco_sel = g_latched & (1 << 15);
// const bool wsel = g_latched & (1 << 16);
// const bool dout_mutef = g_latched & (1 << 17);
// const bool dout_mute = g_latched & (1 << 18);
// const bool cdrom = g_latched & (1 << 19);
if (soct)
{
g_soctEnabled = true;
pio_sm_set_enabled(pio0, SM::SUBQ, false);
soct_program_init(pio1, SM::SOCT, g_soctOffset, Pin::SQSO, Pin::SQCK);
pio_sm_set_enabled(pio1, SM::SOCT, true);
pio_sm_put_blocking(pio1, SM::SOCT, 0xFFFFFFF);
}
}
inline void trackingMode() // $2X
{
const uint subcommand_tracking = (g_latched & 0x0C0000) >> 16;
switch (subcommand_tracking) // Tracking servo
{
case 8: // Forward track jump
g_track = clamp(g_track + 1, 0, c_trackMax);
g_sector = trackToSector(g_track);
g_sectorForTrackUpdate = g_sector;
break;
case 0xC: // Reverse track jump
g_track = clamp(g_track - 1, 0, c_trackMax);
g_sector = trackToSector(g_track);
g_sectorForTrackUpdate = g_sector;
break;
}
const uint subcommand_sled = (g_latched & 0x030000) >> 16;
switch (subcommand_sled) // Sled servo
{
case 2: // Forward sled move
g_sledMoveDirection = SledMove::FORWARD;
g_originalTrack = g_track;
break;
case 3: // Reverse sled move
g_sledMoveDirection = SledMove::REVERSE;
g_originalTrack = g_track;
break;
default: // case 0: case 1: // sled servo off/on
if (g_sledMoveDirection != SledMove::STOP)
{
g_sector = trackToSector(g_track);
g_sectorForTrackUpdate = g_sector;
}
g_sledMoveDirection = SledMove::STOP;
return;
}
g_sledTimer = time_us_64();
}
inline void spindle()
{
const uint sub_command = (g_latched & 0x0F0000) >> 16;
g_sensData[SENS::GFS] = (sub_command == Spindle::CLVA);
if (!g_sensData[SENS::GFS])
{
g_subqDelay = false;
}
/*switch (sub_command)
{
case Spindle::STOP: // 0
DEBUG_PRINT("Stop spindle\n");
break;
case Spindle::KICK: // 8
DEBUG_PRINT("Kick spindle\n"); // Forward rotation
break;
case Spindle::BRAKE: // A
DEBUG_PRINT("Brake spindle\n"); // Reverse rotation
break;
case Spindle::CLVS: // E
DEBUG_PRINT("CLVS\n"); // Rough servo mode
break;
case Spindle::CLVH: // C
DEBUG_PRINT("CLVH\n"); // ?
break;
case Spindle::CLVP: // F
DEBUG_PRINT("CLVP\n"); // PLL servo mode
break;
case Spindle::CLVA: // 6
// DEBUG_PRINT("CLVA\n"); // Automatic CLVS/CLVP switching mode
break;
}*/
}
void __time_critical_func(interrupt_xlat)(uint gpio, uint32_t events)
{
const uint command = (g_latched & 0xF00000) >> 20;
const uint latched = g_latched & 0xFFFFF;
switch (command)
{
case Command::TRACKING_MODE: // $2X commands - Tracking and sled servo control
trackingMode();
break;
case Command::AUTO_SEQUENCE: // $4X commands
autoSequence();
break;
case Command::JUMP_COUNT: // $7X commands - Auto sequence track jump count setting
s_jumpTrack = (g_latched & 0xFFFF0) >> 4;
DEBUG_PRINT("jump: %d\n", s_jumpTrack);
break;
case Command::MODE_SPEC: // $8X commands - MODE specification
modeSpec();
break;
case Command::FUNC_SPEC: // $9X commands - Function specification
funcSpec();
break;
/*case 0xA: // $AX commands - Audio CTRL
// printf("Audio CTRL %x\n", g_latched);
break;*/
case Command::MONITOR_COUNT: // $BX commands - This command sets the traverse monitor count.
g_countTrack = (g_latched & 0xFFFF0) >> 4;
DEBUG_PRINT("count: %d\n", g_countTrack);
break;
case Command::SPINDLE: // $EX commands - Spindle motor control
spindle();
break;
/*
case Command::FOCUS_CONTROL: // $0X commands - Focus control
case 0x1:
case 0x3:
case 0x5: // Blind/brake
case 0x6: // Kick
break;
case Command::CUSTOM: // picostation
switch ((g_latched & 0x0F0000) >> 16)
{
case 0x0: // Iamge 0
DEBUG_PRINT("Image 0 command!\n");
g_imageIndex = 0;
break;
case 0x1: // Previous Image
DEBUG_PRINT("Previous Image command!\n");
g_imageIndex = (g_imageIndex - 1) % NUM_IMAGES;
break;
case 0x2: // Next Image
DEBUG_PRINT("Next Image command!\n");
g_imageIndex = (g_imageIndex + 1) % NUM_IMAGES;
break;
}
break;*/
}
g_latched = 0;
}