separate bulb and border adressing
petaflot

petaflot commited on 2019-08-27 18:26:24
Showing 1 changed files, with 182 additions and 13 deletions.


also added an "alternating" fade function
... ...
@@ -43,6 +43,8 @@
43 43
 .def    CNT                     =       r18
44 44
 .def    DATA                    =       r19
45 45
 .def    GRAY                    =       r20
46
+.def    BULB                    =       r24
47
+.def    BORDER                  =       r25
46 48
 
47 49
 ; current mode
48 50
 .def    MODE                    =       r21
... ...
@@ -285,8 +287,8 @@ CLEAR_LOOP:
285 287
 
286 288
 
287 289
 
288
-; set frame to solid color
289
-; input: DATA = value (0..15)
290
+; set frame to solid color (all the same)
291
+; input: DATA = value (0..15) intensity for all LEDs
290 292
 ; output: -
291 293
 ; changes: X, FRAME
292 294
 ; time: short
... ...
@@ -301,6 +303,37 @@ SET_COLOR_LOOP:
301 303
 ; done
302 304
         ret
303 305
 
306
+; set bulb to solid color
307
+; input: BULB = value (0..15) intensity for all bulb LEDs except spark (28-40)
308
+; output: -
309
+; changes: X, BULB
310
+; time: short
311
+BULB_COLOR:
312
+        ldi     XL,low(FRAME+26)        ; ptr to pixel data
313
+                                        ;   XH not there on ATtiny2313
314
+BULB_COLOR_LOOP:
315
+        st      X+,BULB                 ; set pixel value
316
+        cpi     XL,low(FRAME)+41        ; bottom of loop
317
+                                        ;   XH not there on ATtiny2313
318
+        brne    BULB_COLOR_LOOP
319
+; done
320
+        ret
321
+
322
+; set border to solid color
323
+; input: BORDER = value (0..15) intensity for all border LEDs
324
+; output: -
325
+; changes: X, BORDER
326
+; time: short
327
+BORDER_COLOR:
328
+        ldi     XL,low(FRAME)           ; ptr to pixel data
329
+                                        ;   XH not there on ATtiny2313
330
+BORDER_COLOR_LOOP:
331
+        st      X+,BORDER               ; set pixel value
332
+        cpi     XL,low(FRAME)+28        ; bottom of loop
333
+                                        ;   XH not there on ATtiny2313
334
+        brne    BORDER_COLOR_LOOP
335
+; done
336
+        ret
304 337
 
305 338
 
306 339
 ; set pixel
... ...
@@ -425,6 +458,95 @@ ANIM_FADE_DOWN:
425 458
 ; done
426 459
         ret
427 460
 
461
+; fade up and down animation, bulb and frame are in opposite phase
462
+; input: -
463
+; output: -
464
+; changes: X, FRAME, CNT, BULB, BORDER, TMP, TMP2
465
+INVERTED_FADE:
466
+; fade up
467
+        ;rcall   CLEAR                   ; clear
468
+        ldi     BORDER,15               ; start bright
469
+        ldi     BULB,0                  ; start dark
470
+INVERTED_FADE_BACK:;EVEN                     ; relative to the bulb
471
+        rcall   BORDER_COLOR            ; paint border (to darker)
472
+        rcall   BULB_COLOR              ; paint bulb (to brighter)
473
+        ldi     TMP,10                  ; show frame 60 ms
474
+        rcall   OUT_FRAME_TIME
475
+        dec     BORDER                  ; fade down, 0-27
476
+        inc     BULB                    ; fade up, 28-41
477
+        cpi     BORDER,255              ; loop until full off
478
+        cpi     BULB,15                 ; loop until almost full on
479
+        brne    INVERTED_FADE_BACK
480
+INVERTED_FADE_FORTH:;ODD
481
+        rcall   BORDER_COLOR            ; paint border (to brighter)
482
+        rcall   BULB_COLOR              ; paint bulb (to darker)
483
+        ldi     TMP,10                  ; show frame 60 ms
484
+        rcall   OUT_FRAME_TIME
485
+        inc     BORDER                  ; fade up, 28-41
486
+        dec     BULB                    ; fade down, 0-27
487
+        cpi     BORDER,15               ; loop until almost full on
488
+        cpi     BULB,255                ; loop until full off
489
+        brne    INVERTED_FADE_FORTH
490
+; done
491
+        ret
492
+
493
+
494
+; border (frame around bulb) blink animation
495
+; input: -
496
+; output: -
497
+; changes: X, FRAME, CNT, BORDER, TMP, TMP2
498
+ANIM_FRAMEBLINK:
499
+        rcall   CLEAR
500
+; off
501
+        ldi     BORDER,0                ; minimum color
502
+        rcall   BORDER_COLOR            ; paint
503
+        ldi     TMP,100                 ; show frame 600 ms
504
+        rcall   OUT_FRAME_TIME
505
+; on
506
+        ldi     BORDER,15               ; maximum color
507
+        rcall   BORDER_COLOR            ; paint
508
+        ldi     TMP,100                 ; show frame 600 ms
509
+        rcall   OUT_FRAME_TIME
510
+; done
511
+        ret
512
+
513
+; bulb blink animation, fast
514
+; input: -
515
+; output: -
516
+; changes: X, FRAME, CNT, BULB, TMP, TMP2
517
+ANIM_BULBFAST:
518
+        rcall   CLEAR
519
+; off
520
+        ldi     BULB,0                ; minimum color
521
+        rcall   BULB_COLOR            ; paint
522
+        ldi     TMP,10                 ; show frame 20 ms
523
+        rcall   OUT_FRAME_TIME
524
+; on
525
+        ldi     BULB,15               ; maximum color
526
+        rcall   BULB_COLOR            ; paint
527
+        ldi     TMP,10                 ; show frame 20 ms
528
+        rcall   OUT_FRAME_TIME
529
+; done
530
+        ret
531
+
532
+; bulb blink animation, slow
533
+; input: -
534
+; output: -
535
+; changes: X, FRAME, CNT, BULB, TMP, TMP2
536
+ANIM_BULBSLOW:
537
+        rcall   CLEAR
538
+; off
539
+        ldi     BULB,0                ; minimum color
540
+        rcall   BULB_COLOR            ; paint
541
+        ldi     TMP,200
542
+        rcall   OUT_FRAME_TIME
543
+; on
544
+        ldi     BULB,15               ; maximum color
545
+        rcall   BULB_COLOR            ; paint
546
+        ldi     TMP,200
547
+        rcall   OUT_FRAME_TIME
548
+; done
549
+        ret
428 550
 
429 551
 
430 552
 ; flicker animation
... ...
@@ -435,13 +557,15 @@ ANIM_FLICKER:
435 557
 ; even pixels
436 558
         rcall   CLEAR                   ; clear
437 559
         ldi     DATA,15                 ; even pixels to maximum
560
+        ldi     DATA,0xf
561
+        sts     FRAME+41,DATA                 ; set pixel, go back
438 562
         ldi     CNT,0
439 563
 ANIM_FLICKER_EVEN:
440 564
         rcall   SET_PIXEL
441 565
         subi    CNT,-2                  ; move two pixels
442 566
         cpi     CNT,42                  ; loop
443 567
         brlo    ANIM_FLICKER_EVEN
444
-        ldi     TMP,40                  ; show frame 240 ms
568
+        ldi     TMP,20                  ; show frame 120 ms
445 569
         rcall   OUT_FRAME_TIME
446 570
 ; odd pixels
447 571
         rcall   CLEAR                   ; clear
... ...
@@ -452,11 +576,24 @@ ANIM_FLICKER_ODD:
452 576
         subi    CNT,-2                  ; move two pixels
453 577
         cpi     CNT,42                  ; loop
454 578
         brlo    ANIM_FLICKER_ODD
455
-        ldi     TMP,40                  ; show frame 240 ms
579
+        ldi     TMP,20                  ; show frame 120 ms
456 580
         rcall   OUT_FRAME_TIME
457 581
 ; done
458 582
         ret
459 583
 
584
+ANIM_IDLE:
585
+        rcall   CLEAR                   ; clear
586
+        ldi     TMP,500                 ; show frame 3000 ms
587
+        rcall   OUT_FRAME_TIME
588
+
589
+        ldi     DATA,0xf
590
+        sts     FRAME+41,DATA                 ; set pixel, go back
591
+
592
+        ldi     TMP,10                  ; show frame 60 ms
593
+        rcall   OUT_FRAME_TIME
594
+        ret
595
+
596
+
460 597
 
461 598
 
462 599
 ; wobble animation
... ...
@@ -618,22 +755,54 @@ MODE_READ_NOT_0_TO_1:
618 755
 
619 756
 ; animation table: animation function, iteration count (<= 255)
620 757
 ANIM_TAB:
621
-        .dw     ANIM_BLINK
758
+        .dw     ANIM_FRAMEBLINK
759
+        .dw     5
760
+        .dw     ANIM_BULBFAST
622 761
         .dw     3
623 762
         .dw     ANIM_WORM
624
-        .dw     3
625
-        .dw     ANIM_FLICKER
763
+        .dw     1
764
+        .dw     ANIM_IDLE
626 765
         .dw     10
627 766
         .dw     ANIM_BW_RUN
628
-        .dw     3
629
-        .dw     ANIM_FADE
630
-        .dw     2
767
+        .dw     4
768
+        .dw     ANIM_IDLE
769
+        .dw     10
770
+        ;.dw     ANIM_FADE
771
+        ;.dw     5
631 772
         .dw     ANIM_BW_WORM
632
-        .dw     3
633
-        .dw     ANIM_WOBBLE
773
+        .dw     1
774
+        .dw     INVERTED_FADE
775
+        .dw     15
776
+        .dw     ANIM_IDLE
777
+        .dw     20
778
+        ;.dw     ANIM_WOBBLE
779
+        ;.dw     5
780
+        ;.dw     ANIM_RUN
781
+        ;.dw     3
782
+        .dw     ANIM_WORM
783
+        .dw     1
784
+        .dw     ANIM_FLICKER
785
+        .dw     10
786
+        .dw     ANIM_BW_WORM
787
+        .dw     1
788
+        .dw     ANIM_IDLE
789
+        .dw     20
790
+        .dw     ANIM_FRAMEBLINK
634 791
         .dw     5
635
-        .dw     ANIM_RUN
792
+        .dw     ANIM_IDLE
793
+        .dw     20
794
+        .dw     ANIM_FRAMEBLINK
795
+        .dw     5
796
+        .dw     ANIM_BULBSLOW
636 797
         .dw     3
798
+        .dw     ANIM_IDLE
799
+        .dw     20
800
+        .dw     ANIM_WORM
801
+        .dw     1
802
+        .dw     INVERTED_FADE
803
+        .dw     15
804
+        .dw     ANIM_IDLE
805
+        .dw     20
637 806
 ANIM_TAB_END:
638 807
 
639 808
 
640 809