-
Notifications
You must be signed in to change notification settings - Fork 0
/
fss.asm
2360 lines (1944 loc) · 54.9 KB
/
fss.asm
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
#
# University of Utah, Computer Design Laboratory ECE 3710, FSSPrototype
#
# Create Date: 12/04/2021
# Name: fss
# Description: This is the main program for the FSS prototype written in our custom assembly code,
# compiled with our custom assembler, and running our custom CompactRISC16 processor. This code
# will load onto an FPGA to drive the I2C protocol communication with the device hardware via GPIO
# pins. Data is read from various buttons and rotary encoders on the FSS, and processed data is
# written to a series of SMD LEDs that are driven with daisy-chained shift register LED drivers.
# Authors: Nate Hansen, Jacob Peterson, Brady Hartog, Isabella Gilman
#
#
# BEGIN: Program init and main function
#
`define STACK_PTR_LOWER 0xFF
`define STACK_PTR_UPPER 0x0F
##
# The program initialization routine.
#
# @return void
##
.init
# Initialize stack pointer
MOVIL rsp STACK_PTR_LOWER
MOVIU rsp STACK_PTR_UPPER
##
# The main function.
#
# @return void
##
.main
CALL .animation_sequence_startup
JUC .run
#
# END: Program init and main function
#
#
# BEGIN: Program run functions
#
#
# BEGIN: Static memory definitions
#
# The following is an array of length 8 with the following index mapping:
# | Index | Description |
# | 0 | 1st ring display value (must be 0 - 19, 0 is off) |
# | 1 | 2nd ring display value (must be 0 - 19, 0 is off) |
# | 2 | 3rd ring display value (must be 0 - 19, 0 is off) |
# | 3 | Save indicator value (must be 0 or 1) |
# | 4 | Program1 indicator value (must be 0 or 1) |
# | 5 | Program2 indicator value (must be 0 or 1) |
# | 6 | Program3 indicator value (must be 0 or 1) |
# | 7 | Play/Pause indicator value (must be 0 or 1) |
.display_values_active
0
0
0
0
0
0
0
0
# The following are arrays of length 3 with the following index mapping:
# | Index | Description |
# | 0 | 1st ring display value (must be 0 - 19, 0 is off) |
# | 1 | 2nd ring display value (must be 0 - 19, 0 is off) |
# | 2 | 3rd ring display value (must be 0 - 19, 0 is off) |
.display_values_program_1
9
9
9
.display_values_program_2
2
17
8
.display_values_program_3
11
15
19
# Define a memory location for the current "Play/Pause" button sequence index
.button_playpause_pressed_sequence_index
0x0001
# Define a memory location for the '.rotary_encoder_decode' function for the rotary encoders
.rotary_encoder_1
0x0000
.rotary_encoder_2
0x0000
.rotary_encoder_3
0x0000
#
# END: Static memory definitions
#
##
# Runs the FSS prototype program. This function runs indefinitely.
#
# @return void
##
.run
# Copy program 1 display values into active values
MOV r11 .display_values_program_1
MOV r12 .display_values_active
MOVIL r13 3
MOVIU r13 0x00
CALL .array_copy
# Indicate program 1 is active
MOVIL r11 0b0000_0010
MOVIU r11 0x00
CALL .set_display_values_active_indicators
# Display active values
MOV r11 .display_values_active
CALL .set_ring_display_and_indicator_values
.run:loop
CALL .handle_buttons
CALL .handle_rotary_encoders
JUC .run:loop
# Handle button press events
##
# Polls and processes the buttons on the FSS prototype.
#
# @return void
##
.handle_buttons
CALL .button_get_values
PUSH r10 # Push caller-saved registers
# Check if "Save" button is pressed
MOV r11 r10
CALL .button_is_save_pressed
CMPI r10 1
JNE .handle_buttons:skip_button_save_pressed
CALL .button_save_pressed
.handle_buttons:skip_button_save_pressed
POP r10 # Pop caller-saved registers
PUSH r10 # Push caller-saved registers
# Check if "Program" button is pressed
MOV r11 r10
CALL .button_is_program_pressed
CMPI r10 0
JEQ .handle_buttons:skip_button_program_pressed
MOV r11 r10
CALL .button_program_pressed
.handle_buttons:skip_button_program_pressed
POP r10 # Pop caller-saved registers
PUSH r10 # Push caller-saved registers
# Check if "Play/Pause" button is pressed
MOV r11 r10
CALL .button_is_playpause_pressed
CMPI r10 1
JNE .handle_buttons:button_playpause_pressed
CALL .button_playpause_pressed
.handle_buttons:button_playpause_pressed
POP r10 # Pop caller-saved registers
RET
##
# Polls and processes the rotary encoders on the FSS prototype.
#
# @return void
##
.handle_rotary_encoders
CALL .rotary_encoder_get_values
# Push caller-saved registers
PUSH r10
# Process rotary encoder 1
MOV r11 .rotary_encoder_1
MOV r12 r10
ANDI r12 0b0000_00011
MOV r13 .display_values_active
CALL .process_rotary_encoder
# Pop caller-saved registers
POP r10
# Push caller-saved registers
PUSH r10
# Process rotary encoder 2
MOV r11 .rotary_encoder_2
MOV r12 r10
RSHI r12 2
ANDI r12 0b0000_00011
MOV r13 .display_values_active
ADDI r13 1
CALL .process_rotary_encoder
# Pop caller-saved registers
POP r10
# Push caller-saved registers
PUSH r10
# Process rotary encoder 3
MOV r11 .rotary_encoder_3
MOV r12 r10
RSHI r12 4
ANDI r12 0b0000_00011
MOV r13 .display_values_active
ADDI r13 2
CALL .process_rotary_encoder
# Pop caller-saved registers
POP r10
RET
##
# Processes the data polled from a given rotary encoder on the FSS prototype.
#
# @param r11 - a pointer to a boolean value in memory containing whether or not this decode
# function observed the following pattern: Channel A = 0 && Channel B = 0
# @param r12 - the current encoder channel binary values with the following mapping:
# | Bit Index | Channel Mapping |
# | 0 | Channel A binary value (must be 0 or 1) |
# | 1 | Channel B binary value (must be 0 or 1) |
# @param r13 - a pointer to the ring display value in the display value array
#
# @return void
##
.process_rotary_encoder
# Push caller-saved registers
PUSH r13
# Decode the given rotary encoder input
CALL .rotary_encoder_decode
# Pop caller-saved registers
POP r13
CMPI r10 1
JEQ .process_rotary_encoder:handle_cw
CMPI r10 -1
JEQ .process_rotary_encoder:handle_ccw
# If neither 1 or -1 was returned by 'rotary_encoder_decode', then return
RET
.process_rotary_encoder:handle_cw
# Increment if value is not greater than 19
LOAD r1 r13
ADDI r1 1
CMPI r1 19
JGT .process_rotary_encoder:unchanged_ret
STORE r13 r1
JUC .process_rotary_encoder:changed_ret
.process_rotary_encoder:handle_ccw
# Decrement if value is not less than to 0
LOAD r1 r13
SUBI r1 1
CMPI r1 0
JLT .process_rotary_encoder:unchanged_ret
STORE r13 r1
JUC .process_rotary_encoder:changed_ret
.process_rotary_encoder:changed_ret
# Turn on the "Save" indicator
MOV r1 .display_values_active
ADDI r1 3
MOVIL r0 1
MOVIU r0 0x00
STORE r1 r0
# Display active values
MOV r11 .display_values_active
CALL .set_ring_display_and_indicator_values
RET
.process_rotary_encoder:unchanged_ret
RET
##
# Sets the indicator values in the '.display_values_active'.
#
# @param r11 - the one-hot encoded indicator display values with the following bit mapping:
# | Bit Index | Mapping |
# | 0 | Save indicator value (must be 0 or 1) |
# | 1 | Program1 indicator value (must be 0 or 1) |
# | 2 | Program2 indicator value (must be 0 or 1) |
# | 3 | Program3 indicator value (must be 0 or 1) |
# | 4 | Play/Pause indicator value (must be 0 or 1) |
#
# @return void
##
.set_display_values_active_indicators
MOV r2 .display_values_active
ADDI r2 3
MOVIL r0 0x00
MOVIU r0 0x00
.set_display_values_active_indicators:loop
MOV r1 r11
RSH r1 r0
ANDI r1 0x01
STORE r2 r1
ADDI r2 1
ADDI r0 1
CMPI r0 5
JLO .set_display_values_active_indicators:loop
RET
##
# Gets a pointer to the currently selected program display values.
#
# @return r10 - a pointer to the currently selected program display values
##
.get_pointer_to_current_program_display_values
MOV r1 .display_values_active
ADDI r1 4
LOAD r0 r1
CMPI r0 1
JNE .get_pointer_to_current_program_display_values:after_program_1
MOV r10 .display_values_program_1
RET
.get_pointer_to_current_program_display_values:after_program_1
ADDI r1 1 # Go to next "indicator" address in '.display_values_active'
LOAD r0 r1
CMPI r0 1
JNE .get_pointer_to_current_program_display_values:after_program_2
MOV r10 .display_values_program_2
RET
.get_pointer_to_current_program_display_values:after_program_2
ADDI r1 1 # Go to next "indicator" address in '.display_values_active'
LOAD r0 r1
CMPI r0 1
JNE .get_pointer_to_current_program_display_values:after_program_3
MOV r10 .display_values_program_3
RET
.get_pointer_to_current_program_display_values:after_program_3
# If this line is ever reached, then there is no active program selected, which should never
# happen...
RET
##
# Handles the "Save" button press.
#
# @return void
##
.button_save_pressed
CALL .get_pointer_to_current_program_display_values
MOV r2 r10
# Copy from active values to desired program
MOV r11 .display_values_active
MOV r12 r2
MOVIL r13 3
MOVIU r13 0x00
CALL .array_copy
# Turn off the "Save" indicator
MOV r1 .display_values_active
ADDI r1 3
MOVIL r0 0
MOVIU r0 0x00
STORE r1 r0
# Display active values
MOV r11 .display_values_active
CALL .set_ring_display_and_indicator_values
# Busy-wait while the "Save" button is being pressed
.button_save_pressed:busy_wait
CALL .button_get_values
MOV r11 r10
CALL .button_is_save_pressed
CMPI r10 1
JEQ .button_save_pressed:busy_wait
# Display active values
MOV r11 .display_values_active
CALL .set_ring_display_and_indicator_values
RET
##
# Handles the "Program" button press.
#
# @param r11 - the program button index (1 - 3)
#
# @return void
##
.button_program_pressed
# Set 'r0' to address of desired program display values
CMPI r11 1
JNE .button_program_pressed:after_program_1
MOV r0 .display_values_program_1
.button_program_pressed:after_program_1
CMPI r11 2
JNE .button_program_pressed:after_program_2
MOV r0 .display_values_program_2
.button_program_pressed:after_program_2
CMPI r11 3
JNE .button_program_pressed:after_program_3
MOV r0 .display_values_program_3
.button_program_pressed:after_program_3
# Push caller-saved registers
PUSH r11
# Copy given program display values into active values
MOV r11 r0
MOV r12 .display_values_active
MOVIL r13 3
MOVIU r13 0x00
CALL .array_copy
# Pop caller-saved registers
POP r0
# Indicate given program is active
MOVIL r11 0b0000_0001
MOVIU r11 0x00
LSH r11 r0
CALL .set_display_values_active_indicators
# Display active values
MOV r11 .display_values_active
CALL .set_ring_display_and_indicator_values
RET
##
# Handles the "Play/Pause" button press. This function runs until the "Play/Pause" button is toggled off.
#
# @return void
##
.button_playpause_pressed
# Set all indicator values to 0 and all ring display values to 0
MOVIL r1 0x00
MOVIU r1 0x00
PUSH r1
PUSH r1
PUSH r1
PUSH r1
PUSH r1
PUSH r1
PUSH r1
PUSH r1
MOV r11 rsp
ADDI r11 1
CALL .set_ring_display_and_indicator_values
# Pop all display values off the stack
POP r0
POP r0
POP r0
POP r0
POP r0
POP r0
POP r0
POP r0
# Busy-wait while the "Play/Pause" button is being pressed
.button_playpause_pressed:busy_wait_pressed_before
CALL .button_get_values
MOV r11 r10
CALL .button_is_playpause_pressed
CMPI r10 1
JEQ .button_playpause_pressed:busy_wait_pressed_before
.button_playpause_pressed:loop
MOV r0 .button_playpause_pressed_sequence_index
LOAD r0 r0
CMPI r0 1
BNE 1
CALL .animation_sequence_idle_1
CMPI r0 2
BNE 1
CALL .animation_sequence_idle_2
CMPI r0 3
BNE 1
CALL .animation_sequence_idle_3
CMPI r0 4
BNE 1
CALL .animation_sequence_idle_4
# Check if "Play/Pause" button is pressed to toggle idle animation off
CALL .button_get_values
MOV r11 r10
CALL .button_is_playpause_pressed
CMPI r10 1
JNE .button_playpause_pressed:loop
# Set '.button_playpause_pressed_sequence_number' to next sequence number
MOV r0 .button_playpause_pressed_sequence_index
LOAD r1 r0
ADDI r1 1
STORE r0 r1
CMPI r1 4
JLE .button_playpause_pressed:skip_sequence_reset
# Reset animation sequence to '1'
MOVIL r1 1
MOVIU r1 0x00
STORE r0 r1
.button_playpause_pressed:skip_sequence_reset
# Display active values
MOV r11 .display_values_active
CALL .set_ring_display_and_indicator_values
# Busy-wait while the "Play/Pause" button is being pressed
.button_playpause_pressed:busy_wait_pressed_after
CALL .button_get_values
MOV r11 r10
CALL .button_is_playpause_pressed
CMPI r10 1
JEQ .button_playpause_pressed:busy_wait_pressed_after
RET
#
# END: Program run functions
#
#
# BEGIN: Animation sequence functions
#
##
# Executes a given animation sequence.
#
# An animation sequence uses a compressed frame structure stored in a static place in memory.
# The compressed frame structure is mapped as follows:
#
# | Bit Range | Mapping |
# | [4:0] | 1st ring display value |
# | [9:5] | 2nd ring display value |
# | [14:10] | 3rd ring display value |
#
# Note that LED indicators (for push buttons) are not a part of the frame structure and are
# programmed in the below "frame loop" (and by default are always on during the animation
# playback).
#
# @return r11 - the number of frames in the animation sequence
# @return r12 - a pointer to a sequence of frames for the animation
#
# @return void
##
.execute_animation_sequence
# The following 'r1' register assignment sets number of frames in the animation sequence
MOV r1 r11
# 'r0' is the current frame address of the animation sequency
MOV r0 r12
# 'r1' will now contain the stop address of the animation sequence frames
ADD r1 r0
.execute_animation_sequence:frame_loop
# Push caller-saved registers
PUSH r0
PUSH r1
# Set LED indicator button lights to always be on
MOVIL r1 0x01
MOVIU r1 0x00
PUSH r1
PUSH r1
PUSH r1
PUSH r1
PUSH r1
# Load the compressed frame data
LOAD r0 r0
# Decode 3rd ring display value and push onto stack
MOV r1 r0
RSHI r1 10
ANDI r1 0b11111
PUSH r1
# Decode 2nd ring display value and push onto stack
MOV r1 r0
RSHI r1 5
ANDI r1 0b11111
PUSH r1
# Decode 1st ring display value and push onto stack
MOV r1 r0
ANDI r1 0b11111
PUSH r1
MOV r11 rsp
ADDI r11 1
CALL .set_ring_display_and_indicator_values
# Pop all display values off the stack
POP r0
POP r0
POP r0
POP r0
POP r0
POP r0
POP r0
POP r0
# Delay 2 milliseconds for next frame
MOVIL r11 0xD0
MOVIU r11 0x07
MOVIL r12 0x00
MOVIU r12 0x00
MOVIL r13 0x00
MOVIU r13 0x00
CALL .sleep_48bit
# Pop caller-saved registers
POP r1
POP r0
ADDI r0 1
CMP r0 r1
JLO .execute_animation_sequence:frame_loop
RET
##
# Executes the startup animation sequence.
#
# @return void
##
.animation_sequence_startup
MOVIL r11 87
MOVIU r11 0x00
MOV r12 .startup_animation_sequence_frames
CALL .execute_animation_sequence
RET
##
# Executes the idle animation sequence 1.
#
# @return void
##
.animation_sequence_idle_1
# Shift in several 1s into the LED driver shift register
MOVIL r0 0x00
MOVIU r0 0x00
.animation_sequence_idle_1:shift_1s
# Push caller-saved registers
PUSH r0
MOVIL r11 0x01
MOVIU r11 0x00
CALL .led_shift_value
CALL .led_latch_enable
# Delay 35 milliseconds for next frame
MOVIL r11 0xB8
MOVIU r11 0x88
MOVIL r12 0x00
MOVIU r12 0x00
MOVIL r13 0x00
MOVIU r13 0x00
CALL .sleep_48bit
# Pop caller-saved registers
POP r0
ADDI r0 1
CMPI r0 5
JLO .animation_sequence_idle_1:shift_1s
# Shift in several 0s into the LED driver shift register
MOVIL r0 0x00
MOVIU r0 0x00
.animation_sequence_idle_1:shift_0s
# Push caller-saved registers
PUSH r0
MOVIL r11 0x00
MOVIU r11 0x00
CALL .led_shift_value
CALL .led_latch_enable
# Delay 35 milliseconds for next frame
MOVIL r11 0xB8
MOVIU r11 0x88
MOVIL r12 0x00
MOVIU r12 0x00
MOVIL r13 0x00
MOVIU r13 0x00
CALL .sleep_48bit
# Pop caller-saved registers
POP r0
ADDI r0 1
CMPI r0 5
JLO .animation_sequence_idle_1:shift_0s
RET
##
# Executes the idle animation sequence 2.
#
# @return void
##
.animation_sequence_idle_2
# Shift in and latch a 1 into the LED driver shift register
MOVIL r11 0x01
MOVIU r11 0x00
CALL .led_shift_value
CALL .led_latch_enable
# Delay 200 milliseconds for next frame
MOVIL r11 0x40
MOVIU r11 0x0D
MOVIL r12 0x03
MOVIU r12 0x00
MOVIL r13 0x00
MOVIU r13 0x00
CALL .sleep_48bit
# Shift in and latch a 0 into the LED driver shift register
MOVIL r11 0x00
MOVIU r11 0x00
CALL .led_shift_value
CALL .led_latch_enable
# Delay 200 milliseconds for next frame
MOVIL r11 0x40
MOVIU r11 0x0D
MOVIL r12 0x03
MOVIU r12 0x00
MOVIL r13 0x00
MOVIU r13 0x00
CALL .sleep_48bit
RET
##
# Executes the idle animation sequence 3.
#
# @return void
##
.animation_sequence_idle_3
# Shift and latch a 1 into the LED driver shift register
MOVIL r11 0x01
MOVIU r11 0x00
CALL .led_shift_value
CALL .led_latch_enable
# Incrementally shift in and latch 0s into the LED driver shift register
MOVIL r0 0x00
MOVIU r0 0x00
.animation_sequence_idle_3:shift_0s_loop
# Push caller-saved registers
PUSH r0
MOVIL r11 0x00
MOVIU r11 0x00
CALL .led_shift_value
CALL .led_latch_enable
# Delay 11 milliseconds for next frame
MOVIL r11 0xF8
MOVIU r11 0x2A
MOVIL r12 0x00
MOVIU r12 0x00
MOVIL r13 0x00
MOVIU r13 0x00
CALL .sleep_48bit
# Pop caller-saved registers
POP r0
ADDI r0 1
CMPI r0 56
JLO .animation_sequence_idle_3:shift_0s_loop
# Finally, set all indicator values to 0 and all ring display values to 0
MOVIL r1 0x00
MOVIU r1 0x00
PUSH r1
PUSH r1
PUSH r1
PUSH r1
PUSH r1
PUSH r1
PUSH r1
PUSH r1
MOV r11 rsp
ADDI r11 1
CALL .set_ring_display_and_indicator_values
# Pop all display values off the stack
POP r0
POP r0
POP r0
POP r0
POP r0
POP r0
POP r0
POP r0
RET
##
# Executes the idle animation sequence 4.
#
# @return void
##
.animation_sequence_idle_4
MOVIL r11 40
MOVIU r11 0x00
MOV r12 .animation_sequence_idle_4_frames
CALL .execute_animation_sequence
RET
#
# END: Animation sequence functions
#
#
# BEGIN: Hardware interfacing functions
#
# TODO: The functions in this section do not account for when reading or writing to the I2C
# chips return an error. Implement a fallback to handle errors later if there is time.
# Notes on FSS prototype Main PCB hardware interfacing:
#
# I/O Port Expander I2C Addresses:
# U10: 0x38
# U11: 0x39
#
# Port mapping for I/O Port Expander U10 (used for LED driver shift register and push buttons):
# P7 P6 P5 P4 P3 P2 P1 P0
# Play/Pause Program3 Program2 Program1 Save LE CLK SDI
#
# Port mapping for I/O Port Expander U11 (used for reading quadrature-encoded rotary encoders):
# P7 P6 P5 P4 P3 P2 P1 P0
# N/A N/A SW3B SW3A SW2B SW2A SW1B SW1A
#
# U10 MUST have upper 5 bits driven high always as they are used as inputs for the push buttons.
# Similarly, U11 MUST have all bits driven high always as they are used as inputs for the rotary
# encoders. The I2C Port Expander Chip ports will be driven low via the pull-down push buttons
# and rotary encoder configurations on the Main PCB.
#
#
# BEGIN: Hardware I2C address defines
#
`define U10_I2C_ADDRESS_LOWER 0x38
`define U10_I2C_ADDRESS_UPPER 0x00
`define U11_I2C_ADDRESS_LOWER 0x39
`define U11_I2C_ADDRESS_UPPER 0x00
#
# END: Hardware I2C address defines
#
#
# BEGIN: LED driver interfacing functions
#
##
# Sets the ring display values and the button indicator values on the FSS prototype.
#
# @param r11 - a pointer to an array of length 8 with the following index mapping:
# | Index | Description |
# | 0 | 1st ring display value (must be 0 - 19, 0 is off) |
# | 1 | 2nd ring display value (must be 0 - 19, 0 is off) |
# | 2 | 3rd ring display value (must be 0 - 19, 0 is off) |
# | 3 | Save indicator value (must be 0 or 1) |
# | 4 | Program1 indicator value (must be 0 or 1) |
# | 5 | Program2 indicator value (must be 0 or 1) |
# | 6 | Program3 indicator value (must be 0 or 1) |
# | 7 | Play/Pause indicator value (must be 0 or 1) |
#
# @return void
##
.set_ring_display_and_indicator_values
# Index pointer to last value in given array
ADDI r11 7
#
# BEGIN: Write indicator values from array into LED shift register
#
MOVIL r0 0x00
MOVIU r0 0x00
# Loop through all LED indicators in array
.set_ring_display_and_indicator_values:indicator_loop
# Push caller-saved registers
PUSH r0
PUSH r11
# Call '.led_shift_value' with loaded value from array
LOAD r11 r11
CALL .led_shift_value
# Pop caller-saved registers
POP r11
POP r0
# Move index pointer to next value
SUBI r11 1
ADDI r0 1
CMPI r0 5
JLO .set_ring_display_and_indicator_values:indicator_loop
#
# END: Write indicator values from array into LED shift register
#
#
# BEGIN: Write ring display values from array into LED shift register
#
MOVIL r0 0x00
MOVIU r0 0x00
# Loop through each LED ring in array
.set_ring_display_and_indicator_values:ring_loop
# Push caller-saved registers
PUSH r0
PUSH r11
MOVIL r0 19
MOVIU r0 0x00
# Load the LED ring value
LOAD r1 r11
# Shift 'r1' number of ones into LED shift register as indicated by the loaded LED ring value,
# then shift the remaining number of zeros into LED shift register so that 19 values are
# shifted in.
.set_ring_display_and_indicator_values:ring_value_loop
# Push caller-saved registers
PUSH r0
PUSH r1
# Call '.led_shift_value' with a binary 1 if the loop index ('r0') is less than 'r1', 0 otherwise
MOVIL r11 0x00
MOVIU r11 0x00