-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynth-notes.txt
3447 lines (2618 loc) · 96.1 KB
/
synth-notes.txt
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
2017-01-06
Bode Plots
Notes on generating Bode plots.
http://www.onmyphd.com/?p=bode.plot
----------------------------------
2017-01-05
Color spaces
http://www.poynton.com/PDFs/ColorFAQ.pdf
https://blog.noctua-software.com/procedural-colors-for-game.html
http://devmag.org.za/2012/07/29/how-to-choose-colours-procedurally-algorithms/
http://www.tigercolor.com/color-lab/color-theory/color-theory-intro.htm
http://www.brucelindbloom.com/
R'G'B' is a standardized RGB based on D50 white.
CIE X'Y'Z' is the perceptual color space.
CIE L*u*v* maps it onto a cube.
CIE L*C*h° maps it onto a cylinder. Like perceptual HSV.
Xn, Yn, Zn = (1, 1, 1)
def RGB_to_XYZ(r, g, b):
def linearize_rgb(r, g, b):
ɣ = 2.2
κ = 903.3
def compand(v):
if V <= 0.08:
return 100 * V / κ
else:
return ((v + 0.055) / 1.055)**2.4
r, g, b = r**ɣ, g**ɣ, b**ɣ
r, g, b = [compand(v) for v in (r, g, b)]
return (r, g, b)
r, g, b = linearize_rgb(r, g, b)
M = [[0.412453, 0.357580, 0.180423],
[0.212671, 0.715160, 0.072169],
[0.019334, 0.119193, 0.939555]]
X, Y, Z = [sum(M[i][j] * R[j] for j in range(3)) for i in range(3)]
return (X, Y, Z)
def XYZ_to_Luv(X, Y, Z):
def L_star(Y):
if 0.008856 < Y / Yn:
return 116 * (Y / Yn)**(1/3) - 16
else:
return 903.3 * (Y / Yn)
def u_prime(X, Y, Z):
return 4 * X / (X + 15 * Y + 3 * Z)
def v_prime(X, Y, Z):
return 9 * Y / (X + 15 * Y + 3 * Z)
upn, vpn = u_prime(Xn, Yn, Zn), v_prime(Xn, Yn, Zn)
up, vp = u_prime(X, Y, Z ), v_prime(X, Y, Z )
L = L_star(Y)
u = 13 * L * (up - upn)
v = 13 * L * (vp - vpn)
def XYZ_to_Lab(X, Y, Z):
L, u, v = XYZ_to_Luv(X, Y, Z)
a = 500 * ((X / Xn)**(1/3) - (Y / Yn)**(1/3))
b = 200 * ((Y / Yn)**(1/3) - (Z / Zn)**(1/3))
return (L, a, b)
def Lab_to_LCh(L, a, b):
C = sqrt(a**2 + b**2)
h = atan(b / a)
return (L, C, h)
----------------------------------
2016-12-16
Hand-editing KiCad PCBs
This command will remove all traces and vias.
sed -i.bak -e '/(segment /d' -e '/(via /d' [^_]*.kicad_pcb
----------------------------------
2016-12-16
I/O Daughter Board revisions
The IODB v1.0 does not work. Time to make v1.1.
Desired changes:
- change solder mask clearance to keep from exposing ground plane.
- change ground plane clearances to match 1bitsy or bmp.
1Bitsy clearances:
Solder mask clearance: 0.05mm
Solder paste clearance: 0
Zones (all):
Clearance: 0.15mm
Minimum width: 0.15mm
Antipad clearance: 0.15mm
Spoke width: 0.16mm
Segments: 16
BMPMv2.1b clearances:
Solder mask clearance: ?
Solder paste clearance: ?
GND zone F.cu:
Clearance: 0.2
Minimum width: 0.2
Antipad clearance: 0.2
Spoke width: 0.21
GND zone B.cu:
Clearance: 0.2
Minimum width: 0.2
Antipad clearance: 0.2
Spoke width: 0.25
- move J1 beside J2.
- relabel J1 and J2.
- J1 pad has no solder paste cutout.
- use a different connector for J2.
Hirose FH12A-40S-0.5SH(55)
HFK140CT-ND
- use bigger chips for U11 and U12.
SN74LV1T34DBVR
296-37176-1-ND
- increment the version number.
- order board
- order more parts...
J2 HFK140CT-ND
U3-U9 568-8285-5-ND
U6 497-8387-1-ND
U11 U12 296-37176-1-ND
buttons 732-7004-1-ND
10K 0603 311-10KGRTR-ND
- order stencil
----------------------------------
2016-11-28
I/O Daughter Board silkscreen
72 dpi mockup:
mockup is too big! board is 472 px high, should be 66 mm.
scale = 2.522.
"Minimum Viable Synth" - Jupiter 90 pix, each line indented 5 spaces
"V1.0", URL - Jupiter 15 pix.
"Viable" - border, 1 pix.
Align baseline of "V1.0" with descender of Synth
Align left edge of "V1.0" with left edge of "Minimum"
3600 DPI actual artwork:
90 * 50 / scale = 1783
15 * 50 / scale = 297
border width 16.
----------------------------------
2016-11-14
I/O Daughter Board Errata
As of commit e53f5b, I see eleven errors in the schematic.
* LED_K is also called BKLT_K.
* LED_A is also called BKLT_A.
* CTOUCH_INT is not connected to the master.
* CTOUCH_WAKE is not connected to the master.
* SLV5A_MISO is also called SLV5A_MISO_Fred.
* PWR_SENS is not connected to the master.
* There are no power flags.
* Vdd on Master port P1 should probably not be a power rail.
* There are no bypass capacitors on the SPI crossbar chips.
* There are no bypass capacitors on the STMPE811.
* There are no bypass capacitors on the MIDI level converters.
----------------------------------
2016-11-13
MIDI board
Preliminary notes on the MIDI board.
The MIDI board will be all 5V. Level converters are on the I/O Daughterboard.
MIDI in/out/through. Nobody implements through! Nobody spells it "through"!
(CA-033) MIDI 1.0 Electrical Specification Update [2014]
Olivier Pichenettes says "Prefer 6N137 Opto."
http://mutable-instruments.net/forum/discussion/5276/midi-input-with-optocouplers/p1
Octopart shows a zillion variations on "ferrite bead 1K@100MHz", even
from the same manufacturer. Need to understand why. The MMA spec
says the beads are optional, so the part selection is probably not
critical.
The MIDI spec mentions MMZ1608Y102BT for the beads.
----------------------------------
2016-11-10
I/O Daughter Board - Sections
Power
Video
Slaves
MIDI
Touch
----------------------------------
2016-11-09
Parts
Barrel Jack
Adafruit #373
CUI PJ-102AH
5 on hand
64 pin headers
Digi-Key SAM1212-32-ND
Samtec SSW-132-01-T-D
4 on hand; need 6
LCD FPC Connector
Digi-Key A100229CT-ND
TE Connectivity AMP 4-1734839-0
4 on hand
# Slave SPI Headers
# Digi-Key 455-1738-1-ND
# JST B6B-PH-SM4-TB
# need 48
Slave SPI Headers
Digi-Key WM1735-ND
Molex PicoBlade 0530470610
need 48
# Serial Midi Header
# Digi-Key 455-1736-1-ND
# JST B4B-PH-SM4-TB
# Need 6
Serial Midi Header
Digi-Key WM1733-ND
Molex PicoBlade 0530470410
Need 6
Capacitive Touch Header
Digi-Key OR748CT-ND
Omron XF2L-0625-1A
need 3
Capacitive Touch Alt. Header 1
BuyDesign.com CON06HT-1
ordered 1
3v3 Regulator
Digi-Key 1016-1873-1-ND
Exar SPX3819M5-L-3-3/TR
LCD Backlight Driver
Digi-Key FAN5333BSXCT-ND
Fairchild FAN5333BSX
need 3
LCD Backlight Inductor
Digi-Key 587-2028-1-ND
Taiyo Yuden NR6012T100ME
need 3
LCD Backlight Diode
Digi-Key MBR0540CT-ND
Fairchild MBR0540
need 3
LCD Backlight Zener
Digi-Key MM3Z24VT1GOSCT-ND
ON Semi MM3Z24VT1G
need 3
Resistive Touch Controller
Digi-Key 497-8387-1-ND
ST STMPE811QTR
need 3
SPI Buffers
Digi-Key 568-8285-5-ND
NXP 74HC244PW,112
20 on hand
MIDI level shifters
Digi-Key 296-37177-1-ND
TI SN74LV1T34DCKR
need 9 (6 on this board, 3 on MIDI board)
Filter capacitors for 24V section
Digi-Key 1276-3010-1-ND
Samsung CL21F105ZBFNNNE
need 6
Pushbuttons
Digi-Key 732-7004-1-ND
Würth 430182043816
need 2
More parts
# Slave SPI Connectors
# JST PHR-6
# 9 on hand; need 16
Slave SPI Connectors
Digi-Key WM1724-ND
Molex PicoBlade 0510210600
need 16
Slave Connectors, Slave End
Digi-Key A33380-ND
TE 5-102393-1
# MIDI connectors
# Digi-Key 455-1164-ND
# JST PHR-4
# 10 on hand
MIDI connectors
Digi-Key WM1722-ND
Molex PicoBlade 0510210400
need 2
# Slave SPI, MIDI Contacts
# Digi-Key 455-2148-1-ND
# JST SPH-002T-P0.5L
# 85 on hand; need 96 + 24
Cables
need 11 red, 11 black, 44 colored
Red
Digi-Key 0500588000-12-R1-ND
Black
Digi-Key 0500588000-12-B1-ND
Brown
Digi-Key 0500588000-12-N1-ND
Blue
Digi-Key 0500588000-12-L1-ND
Orange
Digi-Key 0500588000-12-A1-ND
Yellow
Digi-Key 0500588000-12-Y1-ND
need 66
Slave connectors
Digi-Key A33380-ND
TE 102393-1
need 11
w idc ca
ChuckM recommends these. 952-1900-ND
32 position: 952-2521-ND
----------------------------------
2016-11-08
Election Day
Components on the I/O Daughter Card
barrel jack for power
64 pin headers for master
FPC 40 pin for LCD
16 JST-PH connectors for slaves
header for serial MIDI
header for capacitive touch
FPC ZIF 6 position, 0.5mm pitch
Omron XF2L-0625-1A
3v3 regulator: SPX3819M5-L-3-3
22V Boost for backlight: FAN5333BSX
STMPE811 for resistive touch
6 74HC244PW octal buffers
misc. passives
Which 3v3 regulator?
Adafruit uses an MIC5225-3.3v on the TFT Friend. 150 mA.
Teensy 3.2-3.6 use LP38691SDX-3.3/NOPB. 500 mA.
Piotr uses SPX3819M5-L-3-3/TR.
Which backlight driver?
Adafruit uses FAN5333BSX on the TFT Friend
Piotr recommended the TPS61042.
Level Translator?
Piotr is using 568-9224-1-ND on BMPMv2.1.
Optocoupler
Olivier Pichenettes argues for the 6N137.
http://mutable-instruments.net/forum/discussion/5276/midi-input-with-optocouplers/p1
----------------------------------
2016-11-07
Master Daughter card
Functional Spec
Barrel connector for +5V.
16 connectors for slaves with buffers
LCD connector
40 pin FPC
36 pins for LCD
4 pins for touch
STMPE811 for resistive touch
external I2C header and 5V, 3.3V for capacitive touch
header for serial MIDI. 5V, serial in/out, ground.
header for 4 touch pins on FPC
Duplicate user and reset buttons.
----------------------------------
2016-11-07
Cross-checking STM32F429I-Discovery pinout.
Touch sensor (STMP#811) is missing. Needs I2C bus.
don't forget to connect the interrupt pin.
N.B., MB1075 schematic says "USB_OTF_FS" but actually uses _HS pins.
SWD pins are not in spreadsheet.
USB_OTG_HS pins are not in spreadsheet.
RCC_OSC pins are not in spreadsheet.
... and I ordered a panel with a capacitive touch sensor. It is
completely incompatible with the resistive sensor on the Adafruit
panels.
I think I will draw room on the board for the STMP3811 chip, but will
also have an external header for connecting the capacitive sensor.
I used PG2 for the STMPE811 touch interrupt.
----------------------------------
2016-11-04
Looking for switched line buffers.
74LVC4066 - actually an analog switch. Used in SiLabs dev board.
TS3A4751 - ditto
MC74VHC125 - quad bus buffer with 3 state control inputs
SN74AHC125 - quadruple 2-input positive-nand gates
SN74LVC1G125 - Single Bus Buffer Gate With 3-State Output
The last one is interesting. It's a single gate on a 5-pin chip.
Update 11/7: I already bought some NXP 74HC244PW chips. Octal buffer,
one enable line for every four lines. 20 pin TSSOP package.
Perfect.
----------------------------------
2016-09-17
If I'm tweaking a knob on a modulator, I want to see the modulator
parameters, but I also want to see how it affects the target module.
Do they both need to be visible side by side?
----------------------------------
2016-08-17
(Long time no update)
Let's list all the controls and think about what display we'd like to
see when each is changed.
Control: LFO1.waveform
Display: "LFO 1", "waveform", Scope of waveform.
Graph shows blue highlights (how?) if LFO1.speed or
LFO1.amount is being modified.
Control: LFO1.Speed
Display: "LFO 1", "Speed: 3.0 Hz", knob outline, graph of waveform.
Control: LFO1.Amount
Display: "LFO 1", "Amount: 0.5", knob outline, graph of waveform.
Control: LFO2.waveform, .speed, .amount
Display: as above.
Control: Osc1.waveform
Display: "Osc 1", "Pitch: +2 octaves, -2 semitones, +23 cents." or
"Pitch: 2 8va 2♭ +23¢", knob outline, graph of waveform.
Control: Osc1.waveform
Display: "Osc 1", "Width: 5%", knob outline, graph of waveform.
... seems to be a pattern..
----------------------------------
2016-03-05
Here's a silly macro to wrap critical sections.
#define WITH_INTERRUPTS_MASKED \
for (bool wim_interrupts_are_masked = cm_is_masked_interrupts(), \
wim_first_time = (cm_disable_interrupts(), true); \
wim_first_time; \
wim_interrupts_are_masked ? (void)0 : cm_enable_interrupts(), \
wim_first_time = false)
Use it like this.
WITH_INTERRUPTS_MASKED {
mutate_shared_state;
}
----------------------------------
2016-02-19
FPGA Fun
http://www.fpga4fun.com/
Algorithms
Sin and cos.
This calculates sin (or cos) theta using two lookup tables, one
for the high-order bits and another for the low-order bits. That
uses a smaller table than LERP, and has better resolution, at the
cost of two load and two MAC operations per sample. Probably
works well on an FPGA.
It uses these trig identities to decompose the angle.
sin (a + b) = sin a cos b + cos a sin b
cos (a + b) = cos a cos b - sin a sin b
http://www.embedded.com/design/configurable-systems/4007682/5/What-s-your-sine-Finding-the-right-algorithm-for-digital-frequency-synthesis-on-a-DSP
Here is the original paper.
Sunderland, D.A., et al., CMOS/SOS Frequency Synthesizer LSI Circuit
for Spread Spectrum Communications, IEEE Journal of Solid-State
Circuits Vol. SC-19, No. 4, pp 497-506, August 1984.
A similar trick would work for tanh, but would still require a
divide.
tanh (x + y) = (tanh x + tanh y) / (1 + tanh x tanh y)
Pink Noise Generator
http://stenzel.waldorfmusic.de/post/pink/
https://github.com/Stenzel/newshadeofpink
This is a new pink noise generator. It is fairly
incomprehensible, but it looks well-suited to an FPGA. The
claimed spectrum is awesomely flat. Paul Stoffregen uses it
in the Teensy Audio Library.
----------------------------------
2016-02-06
Bugs
Here are the outstanding bugs, so I can stop thinking about them.
FIXED The CTLRs module needs to be flashed.
FIXED Animations for assignment destinations are bad.
FIXED Knobs are too sensitive to noise.
FIXED The display needs to follow the power-on protocol.
USB writes hang when nothing is listening for them.
FIXED Need to move SPI Group B Slave Select to a higher-current pin.
FIXED gpio module doesn't support OSPEED, open collector, etc.
FIXED slave self-test mode leaves choice LEDs on.
libopencm3 should be a submodule.
FIXED Remove "#if 0" dead code.
FIXED CTLRs module needs to have missing pot wiper tied to ground.
----------------------------------
2016-01-18
The enclosure
The enclosure is supposed to be 3u rack mountable. But I don't
actually plan to put it into a rack. Instead, I'll put wooden end
pieces on it to prop it up at an angle. I made an animated GIF.
Tomorrow I'm meeting a friend to fabricate two pieces of aluminum.
I'm calling them the inner and outer covers. The inner cover is a
thin aluminum sheet, 0.019" (0.48 mm). It wraps around the ends of
the electronics. The front panel will rest on it at the ends. It
will have holes on the ends and M5 nuts epoxied on so that end caps
(or rack ears) can be screwed on.
The outer cover is a very nice copper colored brushed aluminum that I
found at Home Depot.[1] It wraps around the top and bottom of the
electronics and around the panel.
Since I like the copper color so much, I'm thinking about decorative
end caps. I considered Plasti-Dip, tile, cut glass, stone, faux stone
finishes, bamboo, hardwood (cherry, mahogany or walnut). I think I've
decided I want to paint MDF with a high gloss finish. I'm looking
into candy paint now.
Ure-Kem has good information here.[2]
[1] http://www.homedepot.com/p/MD-Building-Products-12-in-x-24-in-Copper-Aluminum-Sheet-57525/205518999
[2] http://www.urekem-paints.com/candy-paint-colors
----------------------------------
2015-12-09
Going back to 2015-08-16 Color Indications, I had some big ideas about
animation. To achieve that, I'm going to need at least one state
machine.
enum AssignmentState {
AS_INACTIVE,
AS_ACTIVE,
AS_CONFIRMING, // when the confirming animation runs.
};
Also need some other state.
size_t current_assignment_source; // module index or source index
uint32_t assignment_start_time; // milliseconds
uint32_t assignment_confirm_time; // milliseconds
I'm also going to need some predicates.
bool module_is_current(size_t module_index);
bool module_is_active(size_t module_index);
bool knob_is_working(size_t module_index, size_t knob_index);
It would be good to make these fast...
module_is_current() is easy -- always record the last modified module and
compare.
knob_is_working() is easy: kn_exported_value == ks_actual_value.
module_is_active() is hard. Each module depends on a different set of
knobs. Ideally, I'll have a list: Osc 1 depends on Osc1.Amount,
Filter.Cutoff, Env3.MasterVolume, Env3.Attack, Env3.Decay, and
Env3.Sustain. (And maybe I missed a couple.) Create an inverse map
that maps every control onto the set of modules it can affect, and
whenever that control is changed, reevaluate whether the module is
active.
----------------------------------
2015-12-09
MIDI-USB driver
I've read a little about how MIDI is encapsulated in USB, and I've
read a little of libopencm3's MIDI code.
USB-MIDI chops a MIDI data stream into 4 byte packets. Each packet
has one byte of header and up to 3 bytes of MIDI. The header has
a four bit Cable Number (up to 16 MIDI cables on a single USB
endpoint) and a four bit Code Index Number (CIN). The CIN partially
duplicates the MIDI status byte. E.g., CIN 9 means the packet
is a Note On message, which must start with a 0x9# byte.
So my plan to assemble packets in the MIDI layer and just pass them
through in the USB-MIDI layer is not so good.
EDIT: Oops, disregard. It worked out fine.
----------------------------------
2015-12-05
There is another piece needed.
There is a module that handles HID events from the SPI-proto driver.
Call it Giraffe for now.
Giraffe_SPI_handler(slave_status const *ss)
{
if choice button,
increment choice according to rules;
send MIDI CC message;
if assign button,
decide what it means;
...
for each knob button,
decide what it means;
...
for each knob,
...
}
This is where double clicks and more complex sequences are processed.
Either Giraffe or another module, Gazelle, handles incoming USB
requests.
Gazelle_MIDI_SYSEX_handler(...)
{
if message is set_preset,
...;
if message is get_preset,
...;
// or something. I don't really understand what SYSEX
// messages are needed yet.
// We probably want to handle Program Change messages too.
}
Names for Giraffe? Maybe it's the HID module or Gestures module?
In a traditional widget framework, it would be buried inside some
widget's implementation. What does IOS call the thing that turns
raw touchscreen data into gestures? (answer: Gesture Recognizers)
Gazelle is the high level MIDI responder. MIDI foo. MIDI manager.
MIDI executive (-:. Or something.
When the touchscreen is implemented, I'll need a real gesture
recognizer.
----------------------------------
2015-12-04
Event-driven SPI driver
Let's think of an API.
typedef void SPI_slave_state_handler(const slave_state *, void *user_data);
void SPI_events_setup(void);
void SPI_register_slave_state_handler(SPI_slave_state_handler);
void SPI_handle_systick(void);
void SPI_report_and_clear_stats(void);
Let's think of an implementation.
typedef enum SPI_state {
SS_IDLE,
SS_START,
SS_GROUP_DONE,
} SPI_state;
typedef struct SPI_stats {
uint32_t ok_count[MOD_COUNT];
uint32_t fail_count[MOD_COUNT];
} SPI_stats;
static volatile SPI_state state;
static volatile int current_grp_idx;
static spi_buf outgoing_packets[MOD_COUNT];
static spi_buf incoming_packets[MOD_COUNT];
static slave_state slave_states[MOD_COUNT];
The systick handler would look like this.
void SPI_handle_systick(void)
{
if (state == IDLE) {
state = START;
nvic_generate_software_interrupt(NVIC_EXTI0_IRQ);
}
}
The DMA ISRs would look like this.
void dmaX_streamY_isr(void)
{
state.active_bus_mask &= ~(1 << something);
if (state.active_bus_mask == 0) {
state = GROUP_DONE;
nvic_generate_software_interrupt(NVIC_EXTI0_IRQ);
}
}
The soft interrupt does all the work.
void exti0_isr(void)
{
switch (state) {
case START:
current_grp_idx = -1;
/* FALLTHRU */
case GROUP_DONE:
int prev_grp_idx = current_grp_idx;
current_grp_idx++;
int current_grp = active_spi_groups(current_grp_idx);
if (current_grp == NO_GROUP) {
state = POSTPROCESSING;
postprocess_SPI();
state = IDLE;
} else {
state = ACTIVE;
start_SPI_group(current_grp);
}
if (prev_grp_idx != -1) {
int prev_grp = active_spi-groups(prev_grp_idx);
process_SPI_group(prev_grp);
}
break;
case ACTIVE:
case IDLE:
case POSTPROCESSING:
assert(!"Unexpected SPI state");
break;
}
}
static void start_SPI_group(int grp)
{
int bus;
for (int i = 0; (bus = active_spi_buses(grp, i)) != NO_BUS; i++) {
size_t mod_idx = spi_to_module(grp, bus);
const module_config *mod = &sc.sc_modules[mod_index];
uint32_t msec = system_millis;
size_t bytes_out =
assemble_outgoing_packet(outgoing_packets[mod_idx],
msec, mod);
spi_start_transfer(bus,
outgoing_packets[mod],
incoming_packets[mod],
bytes_out);
}
}
static void process_SPI_group(int grp)
{
int bus;
for (int i = 0; (bus = active_spi_buses(grp, i)) != NO_BUS; i++) {
size_t mod_idx = spi_to_module(grp, bus);
const module_config *mod = &sc.sc_modules[mod_index];
bool ok = parse_incoming_packet(incoming_packets[mod_index],
sizeof incoming_packets[mod_index],
mod_index,
&slave_state[mod_index]);
if (ok)
SPI_stats.ok_count[mod_idx]++;
else
SPI_stats.fail_count[mod_idx]++;
}
}
static void postprocess_SPI(void)
{
for all modules,
(*slave_state_handler)(&slave_states[i]);
}
----------------------------------
2015-12-04
USB-MIDI driver
Let's think of an API.
void USB_MIDI_setup(void);
// return 0 on success or an error code
int USB_MIDI_enqueue(uint8_t *msg, size_t size);
// This may receive more than one packet at a time.
typedef void USB_MIDI_handler(uint8_t *pkt, size_t size, void *user_data);
// returns the previous handler or NULL if none.
USB_MIDI_HANDLER *USB_MIDI_register_handler(USB_MIDI_HANDLER *cb);
And then there could be some "porcelain" layers above that. First,
drop the USB_ prefix. At some point in the future, this could route
to USB or serial MIDI or both.
void MIDI_setup(void);
// return 0 on success or an error code
int MIDI_enqueue(uint8_t *pkt, size_t size);
typedef void MIDI_handler(uint8_t *pkt, size_t size, void *user_data);
// returns the previous handler or NULL if none.
MIDI_HANDLER *MIDI_register_handler(MIDI_HANDLER *cb);
Then specialize the send function on the various messages types.
MIDI_send_note_off (uint8_t channel, uint8_t note, uint8_t velocity);
MIDI_send_note_on (uint8_t channel, uint8_t note, uint8_t velocity);
MIDI_send_poly_pressure (uint8_t channel, uint8_t note, uint8_t pressure);
MIDI_send_control_change (uint8_t channel, uint8_t control, uint8_t value);
MIDI_send_program_change (uint8_t channel, uint8_t patch);
MIDI_send_channel_pressure (uint8_t channel, uint8_t value);
MIDI_send_pitch_bend (uint8_t channel, uint16_t value);
// Message must include leading 0xF0 byte
MIDI_send_raw_SYSEX (uint8_t const *message, size_t size);
MIDI_send_MTC_quarter (uint8_t type, uint8_t values);
MIDI_send_song_position (uint16_t beat);
MIDI_send_song_select (uint8_t song);
MIDI_send_tune_request (void);
MIDI_send_timing_clock (void);
MIDI_send_start (void);
MIDI_send_continue (void);
MIDI_send_stop (void);
MIDI_send_active_sensing (void);
MIDI_send_reset (void);
And similarly for receive.
typedef void MIDI_note_off_handler (uint8_t channel,
uint8_t note,
uint8_t velocity);
typedef void MIDI_note_on_handler (uint8_t channel,
uint8_t note,
uint8_t velocity);
typedef void MIDI_poly_pressure_handler (uint8_t channel,
uint8_t note,
uint8_t pressure);
typedef void MIDI_control_change_handler (uint8_t channel,
uint8_t control,
uint8_t value);
typedef void MIDI_program_change_handler (uint8_t channel,
uint8_t patch);
typedef void MIDI_channel_pressure_handler (uint8_t channel,
uint8_t value);
typedef void MIDI_pitch_bend_handler (uint8_t channel,
uint16_t value);
typedef void MIDI_SYSEX_handler (uint8_t const *message,
size_t size);
typedef void MIDI_MTC_quarter_handler (uint8_t type, uint8_t values);
typedef void MIDI_song_position_handler (uint16_t beat);
typedef void MIDI_song_select_handler (uint8_t song);
typedef void MIDI_tune_request_handler (void);
typedef void MIDI_timing_clock_handler (void);
typedef void MIDI_start_handler (void);
typedef void MIDI_continue_handler (void);
typedef void MIDI_stop_handler (void);
typedef void MIDI_active_sensing_handler (void);
typedef void MIDI_reset_handler (void);
#define REGISTER_HANDLER(type) \
MIDI_##type##_handler MIDI_register_##type##_handler(MIDI_##type##_handler);
REGISTER_HANDLER(note_off);
REGISTER_HANDLER(note_on);
REGISTER_HANDLER(poly_pressure);
REGISTER_HANDLER(control_change);
REGISTER_HANDLER(program_change);
REGISTER_HANDLER(channel_pressure);
REGISTER_HANDLER(pitch_bend);
REGISTER_HANDLER(SYSEX);
REGISTER_HANDLER(MTC_quarter);
REGISTER_HANDLER(song_position);
REGISTER_HANDLER(song_select);
REGISTER_HANDLER(tune_request);
REGISTER_HANDLER(timing_clock);
REGISTER_HANDLER(start);
REGISTER_HANDLER(continue);
REGISTER_HANDLER(stop);
REGISTER_HANDLER(active_sensing);
REGISTER_HANDLER(reset);
And then specialize on all the channel control messages and RPNs and
NRPNs. Also specialize on all the Universal SYSEX messages. But I'm
going to stop typing here.
----------------------------------
2015-12-04
Master Firmware
The firmware on the master MCU (STM32) needs to have some tasks and
some interrupts.
There are lots of things happening.
Based on a timer, the master polls the slaves through SPI.
Some SPI responses cause MIDI-USB packets to be sent.
MIDI-USB packets are received asynchronously.
Some MIDI-USB packets causes MIDI-USB replies to be sent.
The screen is updated often.
The Chrom-Art accelerator has a queue of bit blts to do.
I see a bunch of interrupts and service routines, and three main
tasks. From highest to lowest priority,