1 #ifndef EAGLE_EBOARD_HELPLIB_NEOPIXEL 2 #define EAGLE_EBOARD_HELPLIB_NEOPIXEL 20 #define EBOARD_NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2)) 21 #define EBOARD_NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1)) 23 #define EBOARD_NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2)) 25 #define EBOARD_NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1)) 27 #define EBOARD_NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0)) 29 #define EBOARD_NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0)) 35 #define EBOARD_NEO_WRGB ((0 << 6) | (1 << 4) | (2 << 2) | (3)) 36 #define EBOARD_NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2)) 38 #define EBOARD_NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3)) 40 #define EBOARD_NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2)) 42 #define EBOARD_NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1)) 44 #define EBOARD_NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1)) 46 #define EBOARD_NEO_RWGB ((1 << 6) | (0 << 4) | (2 << 2) | (3)) 48 #define EBOARD_NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2)) 50 #define EBOARD_NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3)) 52 #define EBOARD_NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2)) 54 #define EBOARD_NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1)) 56 #define EBOARD_NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1)) 58 #define EBOARD_NEO_GWRB ((1 << 6) | (2 << 4) | (0 << 2) | (3)) 60 #define EBOARD_NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2)) 62 #define EBOARD_NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3)) 64 #define EBOARD_NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2)) 66 #define EBOARD_NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1)) 68 #define EBOARD_NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1)) 70 #define EBOARD_NEO_BWRG ((1 << 6) | (2 << 4) | (3 << 2) | (0)) 72 #define EBOARD_NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0)) 74 #define EBOARD_NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0)) 76 #define EBOARD_NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0)) 78 #define EBOARD_NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0)) 80 #define EBOARD_NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0)) 85 #define EBOARD_NEO_800KHZ 0x0000 86 #define EBOARD_NEO_400KHZ 0x0100 175 void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b);
184 void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w);
239 static inline uint32_t
Color(uint8_t r, uint8_t g, uint8_t b);
247 static inline uint32_t
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w);
280 #ifdef __AVR__ //not needed (rem?) 281 volatile uint8_t *port;
300 return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
304 return ((uint32_t)w << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
319 begun(false), brightness(0),
pixels(NULL), endTime(0) {
326 begun(false), numLEDs(0), numBytes(0), pin(-1), brightness(0),
pixels(NULL),
332 if(
pin >= 0) pinMode(
pin, INPUT);
337 pinMode(
pin, OUTPUT);
338 digitalWrite(
pin, LOW);
372 extern "C" void ICACHE_RAM_ATTR espShow(
373 uint8_t pin, uint8_t *
pixels, uint32_t numBytes, uint8_t type);
375 extern "C" void espShow(
376 uint8_t pin, uint8_t *
pixels, uint32_t numBytes, uint8_t type);
393 #if (F_CPU >= 7400000UL) && (F_CPU <= 9500000UL) 396 volatile uint8_t n1, n2 = 0;
399 #if defined(PORTB) || defined(PORTC) || defined(PORTF) 403 hi = PORTD | pinMask;
404 lo = PORTD & ~pinMask;
406 if(b & 0x80) n1 = hi;
411 "out %[port] , %[hi]" "\n\t" 412 "mov %[n2] , %[lo]" "\n\t" 413 "out %[port] , %[n1]" "\n\t" 415 "sbrc %[byte] , 6" "\n\t" 416 "mov %[n2] , %[hi]" "\n\t" 417 "out %[port] , %[lo]" "\n\t" 420 "out %[port] , %[hi]" "\n\t" 421 "mov %[n1] , %[lo]" "\n\t" 422 "out %[port] , %[n2]" "\n\t" 424 "sbrc %[byte] , 5" "\n\t" 425 "mov %[n1] , %[hi]" "\n\t" 426 "out %[port] , %[lo]" "\n\t" 429 "out %[port] , %[hi]" "\n\t" 430 "mov %[n2] , %[lo]" "\n\t" 431 "out %[port] , %[n1]" "\n\t" 433 "sbrc %[byte] , 4" "\n\t" 434 "mov %[n2] , %[hi]" "\n\t" 435 "out %[port] , %[lo]" "\n\t" 438 "out %[port] , %[hi]" "\n\t" 439 "mov %[n1] , %[lo]" "\n\t" 440 "out %[port] , %[n2]" "\n\t" 442 "sbrc %[byte] , 3" "\n\t" 443 "mov %[n1] , %[hi]" "\n\t" 444 "out %[port] , %[lo]" "\n\t" 447 "out %[port] , %[hi]" "\n\t" 448 "mov %[n2] , %[lo]" "\n\t" 449 "out %[port] , %[n1]" "\n\t" 451 "sbrc %[byte] , 2" "\n\t" 452 "mov %[n2] , %[hi]" "\n\t" 453 "out %[port] , %[lo]" "\n\t" 456 "out %[port] , %[hi]" "\n\t" 457 "mov %[n1] , %[lo]" "\n\t" 458 "out %[port] , %[n2]" "\n\t" 460 "sbrc %[byte] , 1" "\n\t" 461 "mov %[n1] , %[hi]" "\n\t" 462 "out %[port] , %[lo]" "\n\t" 465 "out %[port] , %[hi]" "\n\t" 466 "mov %[n2] , %[lo]" "\n\t" 467 "out %[port] , %[n1]" "\n\t" 469 "sbrc %[byte] , 0" "\n\t" 470 "mov %[n2] , %[hi]" "\n\t" 471 "out %[port] , %[lo]" "\n\t" 472 "sbiw %[count], 1" "\n\t" 474 "out %[port] , %[hi]" "\n\t" 475 "mov %[n1] , %[lo]" "\n\t" 476 "out %[port] , %[n2]" "\n\t" 477 "ld %[byte] , %a[ptr]+" "\n\t" 478 "sbrc %[byte] , 7" "\n\t" 479 "mov %[n1] , %[hi]" "\n\t" 480 "out %[port] , %[lo]" "\n\t" 486 : [port]
"I" (_SFR_IO_ADDR(PORTD)),
491 #if defined(PORTB) || defined(PORTC) || defined(PORTF) 496 #if defined(PORTD) || defined(PORTC) || defined(PORTF) 498 #endif // defined(PORTD/C/F) 499 hi = PORTB | pinMask;
500 lo = PORTB & ~pinMask;
502 if(b & 0x80) n1 = hi;
506 "out %[port] , %[hi]" "\n\t" 507 "mov %[n2] , %[lo]" "\n\t" 508 "out %[port] , %[n1]" "\n\t" 510 "sbrc %[byte] , 6" "\n\t" 511 "mov %[n2] , %[hi]" "\n\t" 512 "out %[port] , %[lo]" "\n\t" 514 "out %[port] , %[hi]" "\n\t" 515 "mov %[n1] , %[lo]" "\n\t" 516 "out %[port] , %[n2]" "\n\t" 518 "sbrc %[byte] , 5" "\n\t" 519 "mov %[n1] , %[hi]" "\n\t" 520 "out %[port] , %[lo]" "\n\t" 522 "out %[port] , %[hi]" "\n\t" 523 "mov %[n2] , %[lo]" "\n\t" 524 "out %[port] , %[n1]" "\n\t" 526 "sbrc %[byte] , 4" "\n\t" 527 "mov %[n2] , %[hi]" "\n\t" 528 "out %[port] , %[lo]" "\n\t" 530 "out %[port] , %[hi]" "\n\t" 531 "mov %[n1] , %[lo]" "\n\t" 532 "out %[port] , %[n2]" "\n\t" 534 "sbrc %[byte] , 3" "\n\t" 535 "mov %[n1] , %[hi]" "\n\t" 536 "out %[port] , %[lo]" "\n\t" 538 "out %[port] , %[hi]" "\n\t" 539 "mov %[n2] , %[lo]" "\n\t" 540 "out %[port] , %[n1]" "\n\t" 542 "sbrc %[byte] , 2" "\n\t" 543 "mov %[n2] , %[hi]" "\n\t" 544 "out %[port] , %[lo]" "\n\t" 546 "out %[port] , %[hi]" "\n\t" 547 "mov %[n1] , %[lo]" "\n\t" 548 "out %[port] , %[n2]" "\n\t" 550 "sbrc %[byte] , 1" "\n\t" 551 "mov %[n1] , %[hi]" "\n\t" 552 "out %[port] , %[lo]" "\n\t" 554 "out %[port] , %[hi]" "\n\t" 555 "mov %[n2] , %[lo]" "\n\t" 556 "out %[port] , %[n1]" "\n\t" 558 "sbrc %[byte] , 0" "\n\t" 559 "mov %[n2] , %[hi]" "\n\t" 560 "out %[port] , %[lo]" "\n\t" 561 "sbiw %[count], 1" "\n\t" 562 "out %[port] , %[hi]" "\n\t" 563 "mov %[n1] , %[lo]" "\n\t" 564 "out %[port] , %[n2]" "\n\t" 565 "ld %[byte] , %a[ptr]+" "\n\t" 566 "sbrc %[byte] , 7" "\n\t" 567 "mov %[n1] , %[hi]" "\n\t" 568 "out %[port] , %[lo]" "\n\t" 570 : [byte]
"+r" (b), [n1]
"+r" (n1), [n2]
"+r" (n2), [count]
"+w" (i)
571 : [port]
"I" (_SFR_IO_ADDR(PORTB)), [ptr]
"e" (ptr), [hi]
"r" (hi),
574 #if defined(PORTD) || defined(PORTC) || defined(PORTF) 577 #if defined(PORTC) || defined(PORTF) 583 #if defined(PORTD) || defined(PORTB) || defined(PORTF) 587 hi = PORTC | pinMask;
588 lo = PORTC & ~pinMask;
590 if(b & 0x80) n1 = hi;
594 "out %[port] , %[hi]" "\n\t" 595 "mov %[n2] , %[lo]" "\n\t" 596 "out %[port] , %[n1]" "\n\t" 598 "sbrc %[byte] , 6" "\n\t" 599 "mov %[n2] , %[hi]" "\n\t" 600 "out %[port] , %[lo]" "\n\t" 602 "out %[port] , %[hi]" "\n\t" 603 "mov %[n1] , %[lo]" "\n\t" 604 "out %[port] , %[n2]" "\n\t" 606 "sbrc %[byte] , 5" "\n\t" 607 "mov %[n1] , %[hi]" "\n\t" 608 "out %[port] , %[lo]" "\n\t" 610 "out %[port] , %[hi]" "\n\t" 611 "mov %[n2] , %[lo]" "\n\t" 612 "out %[port] , %[n1]" "\n\t" 614 "sbrc %[byte] , 4" "\n\t" 615 "mov %[n2] , %[hi]" "\n\t" 616 "out %[port] , %[lo]" "\n\t" 618 "out %[port] , %[hi]" "\n\t" 619 "mov %[n1] , %[lo]" "\n\t" 620 "out %[port] , %[n2]" "\n\t" 622 "sbrc %[byte] , 3" "\n\t" 623 "mov %[n1] , %[hi]" "\n\t" 624 "out %[port] , %[lo]" "\n\t" 626 "out %[port] , %[hi]" "\n\t" 627 "mov %[n2] , %[lo]" "\n\t" 628 "out %[port] , %[n1]" "\n\t" 630 "sbrc %[byte] , 2" "\n\t" 631 "mov %[n2] , %[hi]" "\n\t" 632 "out %[port] , %[lo]" "\n\t" 634 "out %[port] , %[hi]" "\n\t" 635 "mov %[n1] , %[lo]" "\n\t" 636 "out %[port] , %[n2]" "\n\t" 638 "sbrc %[byte] , 1" "\n\t" 639 "mov %[n1] , %[hi]" "\n\t" 640 "out %[port] , %[lo]" "\n\t" 642 "out %[port] , %[hi]" "\n\t" 643 "mov %[n2] , %[lo]" "\n\t" 644 "out %[port] , %[n1]" "\n\t" 646 "sbrc %[byte] , 0" "\n\t" 647 "mov %[n2] , %[hi]" "\n\t" 648 "out %[port] , %[lo]" "\n\t" 649 "sbiw %[count], 1" "\n\t" 650 "out %[port] , %[hi]" "\n\t" 651 "mov %[n1] , %[lo]" "\n\t" 652 "out %[port] , %[n2]" "\n\t" 653 "ld %[byte] , %a[ptr]+" "\n\t" 654 "sbrc %[byte] , 7" "\n\t" 655 "mov %[n1] , %[hi]" "\n\t" 656 "out %[port] , %[lo]" "\n\t" 658 : [byte]
"+r" (b), [n1]
"+r" (n1), [n2]
"+r" (n2), [count]
"+w" (i)
659 : [port]
"I" (_SFR_IO_ADDR(PORTC)), [ptr]
"e" (ptr), [hi]
"r" (hi),
662 #if defined(PORTD) || defined(PORTB) || defined(PORTF) 671 #if defined(PORTD) || defined(PORTB) || defined(PORTC) 673 #endif // defined(PORTD/B/C) 675 hi = PORTF | pinMask;
676 lo = PORTF & ~pinMask;
678 if(b & 0x80) n1 = hi;
682 "out %[port] , %[hi]" "\n\t" 683 "mov %[n2] , %[lo]" "\n\t" 684 "out %[port] , %[n1]" "\n\t" 686 "sbrc %[byte] , 6" "\n\t" 687 "mov %[n2] , %[hi]" "\n\t" 688 "out %[port] , %[lo]" "\n\t" 690 "out %[port] , %[hi]" "\n\t" 691 "mov %[n1] , %[lo]" "\n\t" 692 "out %[port] , %[n2]" "\n\t" 694 "sbrc %[byte] , 5" "\n\t" 695 "mov %[n1] , %[hi]" "\n\t" 696 "out %[port] , %[lo]" "\n\t" 698 "out %[port] , %[hi]" "\n\t" 699 "mov %[n2] , %[lo]" "\n\t" 700 "out %[port] , %[n1]" "\n\t" 702 "sbrc %[byte] , 4" "\n\t" 703 "mov %[n2] , %[hi]" "\n\t" 704 "out %[port] , %[lo]" "\n\t" 706 "out %[port] , %[hi]" "\n\t" 707 "mov %[n1] , %[lo]" "\n\t" 708 "out %[port] , %[n2]" "\n\t" 710 "sbrc %[byte] , 3" "\n\t" 711 "mov %[n1] , %[hi]" "\n\t" 712 "out %[port] , %[lo]" "\n\t" 714 "out %[port] , %[hi]" "\n\t" 715 "mov %[n2] , %[lo]" "\n\t" 716 "out %[port] , %[n1]" "\n\t" 718 "sbrc %[byte] , 2" "\n\t" 719 "mov %[n2] , %[hi]" "\n\t" 720 "out %[port] , %[lo]" "\n\t" 722 "out %[port] , %[hi]" "\n\t" 723 "mov %[n1] , %[lo]" "\n\t" 724 "out %[port] , %[n2]" "\n\t" 726 "sbrc %[byte] , 1" "\n\t" 727 "mov %[n1] , %[hi]" "\n\t" 728 "out %[port] , %[lo]" "\n\t" 730 "out %[port] , %[hi]" "\n\t" 731 "mov %[n2] , %[lo]" "\n\t" 732 "out %[port] , %[n1]" "\n\t" 734 "sbrc %[byte] , 0" "\n\t" 735 "mov %[n2] , %[hi]" "\n\t" 736 "out %[port] , %[lo]" "\n\t" 737 "sbiw %[count], 1" "\n\t" 738 "out %[port] , %[hi]" "\n\t" 739 "mov %[n1] , %[lo]" "\n\t" 740 "out %[port] , %[n2]" "\n\t" 741 "ld %[byte] , %a[ptr]+" "\n\t" 742 "sbrc %[byte] , 7" "\n\t" 743 "mov %[n1] , %[hi]" "\n\t" 744 "out %[port] , %[lo]" "\n\t" 746 : [byte]
"+r" (b), [n1]
"+r" (n1), [n2]
"+r" (n2), [count]
"+w" (i)
747 : [port]
"I" (_SFR_IO_ADDR(PORTF)), [ptr]
"e" (ptr), [hi]
"r" (hi),
750 #if defined(PORTD) || defined(PORTB) || defined(PORTC) 752 #endif // defined(PORTD/B/C) 753 #endif // defined(PORTF) 756 volatile uint8_t next, bit;
758 hi = *port | pinMask;
759 lo = *port & ~pinMask;
765 "st %a[port], %[hi]" "\n\t" 766 "sbrc %[byte] , 7" "\n\t" 767 "mov %[next], %[hi]" "\n\t" 768 "st %a[port], %[next]" "\n\t" 769 "mov %[next] , %[lo]" "\n\t" 771 "breq nextbyte20" "\n\t" 773 "st %a[port], %[lo]" "\n\t" 779 "st %a[port], %[lo]" "\n\t" 781 "ldi %[bit] , 8" "\n\t" 782 "ld %[byte] , %a[ptr]+" "\n\t" 783 "sbiw %[count], 1" "\n\t" 785 : [port]
"+e" (port),
794 #elif (F_CPU >= 11100000UL) && (F_CPU <= 14300000UL) 796 volatile uint8_t next;
801 #if defined(PORTB) || defined(PORTC) || defined(PORTF) 805 hi = PORTD | pinMask;
806 lo = PORTD & ~pinMask;
808 if(b & 0x80) next = hi;
811 "out %[port], %[hi]" "\n\t" 812 "rcall bitTimeD" "\n\t" 813 "out %[port], %[hi]" "\n\t" 814 "rcall bitTimeD" "\n\t" 815 "out %[port], %[hi]" "\n\t" 816 "rcall bitTimeD" "\n\t" 817 "out %[port], %[hi]" "\n\t" 818 "rcall bitTimeD" "\n\t" 819 "out %[port], %[hi]" "\n\t" 820 "rcall bitTimeD" "\n\t" 821 "out %[port], %[hi]" "\n\t" 822 "rcall bitTimeD" "\n\t" 823 "out %[port], %[hi]" "\n\t" 824 "rcall bitTimeD" "\n\t" 826 "out %[port] , %[hi]" "\n\t" 828 "ld %[byte] , %a[ptr]+" "\n\t" 829 "out %[port] , %[next]" "\n\t" 830 "mov %[next] , %[lo]" "\n\t" 831 "sbrc %[byte] , 7" "\n\t" 832 "mov %[next] , %[hi]" "\n\t" 834 "out %[port] , %[lo]" "\n\t" 835 "sbiw %[count], 1" "\n\t" 839 "out %[port], %[next]" "\n\t" 840 "mov %[next], %[lo]" "\n\t" 842 "sbrc %[byte], 7" "\n\t" 843 "mov %[next], %[hi]" "\n\t" 845 "out %[port], %[lo]" "\n\t" 851 : [port]
"I" (_SFR_IO_ADDR(PORTD)),
856 #if defined(PORTB) || defined(PORTC) || defined(PORTF) 862 #if defined(PORTD) || defined(PORTC) || defined(PORTF) 866 hi = PORTB | pinMask;
867 lo = PORTB & ~pinMask;
869 if(b & 0x80) next = hi;
873 "out %[port], %[hi]" "\n\t" 874 "rcall bitTimeB" "\n\t" 875 "out %[port], %[hi]" "\n\t" 876 "rcall bitTimeB" "\n\t" 877 "out %[port], %[hi]" "\n\t" 878 "rcall bitTimeB" "\n\t" 879 "out %[port], %[hi]" "\n\t" 880 "rcall bitTimeB" "\n\t" 881 "out %[port], %[hi]" "\n\t" 882 "rcall bitTimeB" "\n\t" 883 "out %[port], %[hi]" "\n\t" 884 "rcall bitTimeB" "\n\t" 885 "out %[port], %[hi]" "\n\t" 886 "rcall bitTimeB" "\n\t" 887 "out %[port] , %[hi]" "\n\t" 889 "ld %[byte] , %a[ptr]+" "\n\t" 890 "out %[port] , %[next]" "\n\t" 891 "mov %[next] , %[lo]" "\n\t" 892 "sbrc %[byte] , 7" "\n\t" 893 "mov %[next] , %[hi]" "\n\t" 895 "out %[port] , %[lo]" "\n\t" 896 "sbiw %[count], 1" "\n\t" 900 "out %[port], %[next]" "\n\t" 901 "mov %[next], %[lo]" "\n\t" 903 "sbrc %[byte], 7" "\n\t" 904 "mov %[next], %[hi]" "\n\t" 906 "out %[port], %[lo]" "\n\t" 909 : [byte]
"+r" (b), [next]
"+r" (next), [count]
"+w" (i)
910 : [port]
"I" (_SFR_IO_ADDR(PORTB)), [ptr]
"e" (ptr), [hi]
"r" (hi),
913 #if defined(PORTD) || defined(PORTC) || defined(PORTF) 916 #if defined(PORTC) || defined(PORTF) 922 #if defined(PORTD) || defined(PORTB) || defined(PORTF) 926 hi = PORTC | pinMask;
927 lo = PORTC & ~pinMask;
929 if(b & 0x80) next = hi;
933 "out %[port], %[hi]" "\n\t" 934 "rcall bitTimeC" "\n\t" 935 "out %[port], %[hi]" "\n\t" 936 "rcall bitTimeC" "\n\t" 937 "out %[port], %[hi]" "\n\t" 938 "rcall bitTimeC" "\n\t" 939 "out %[port], %[hi]" "\n\t" 940 "rcall bitTimeC" "\n\t" 941 "out %[port], %[hi]" "\n\t" 942 "rcall bitTimeC" "\n\t" 943 "out %[port], %[hi]" "\n\t" 944 "rcall bitTimeC" "\n\t" 945 "out %[port], %[hi]" "\n\t" 946 "rcall bitTimeC" "\n\t" 947 "out %[port] , %[hi]" "\n\t" 949 "ld %[byte] , %a[ptr]+" "\n\t" 950 "out %[port] , %[next]" "\n\t" 951 "mov %[next] , %[lo]" "\n\t" 952 "sbrc %[byte] , 7" "\n\t" 953 "mov %[next] , %[hi]" "\n\t" 955 "out %[port] , %[lo]" "\n\t" 956 "sbiw %[count], 1" "\n\t" 960 "out %[port], %[next]" "\n\t" 961 "mov %[next], %[lo]" "\n\t" 963 "sbrc %[byte], 7" "\n\t" 964 "mov %[next], %[hi]" "\n\t" 966 "out %[port], %[lo]" "\n\t" 969 : [byte]
"+r" (b), [next]
"+r" (next), [count]
"+w" (i)
970 : [port]
"I" (_SFR_IO_ADDR(PORTC)), [ptr]
"e" (ptr), [hi]
"r" (hi),
973 #if defined(PORTD) || defined(PORTB) || defined(PORTF) 982 #if defined(PORTD) || defined(PORTB) || defined(PORTC) 986 hi = PORTF | pinMask;
987 lo = PORTF & ~pinMask;
989 if(b & 0x80) next = hi;
993 "out %[port], %[hi]" "\n\t" 994 "rcall bitTimeC" "\n\t" 995 "out %[port], %[hi]" "\n\t" 996 "rcall bitTimeC" "\n\t" 997 "out %[port], %[hi]" "\n\t" 998 "rcall bitTimeC" "\n\t" 999 "out %[port], %[hi]" "\n\t" 1000 "rcall bitTimeC" "\n\t" 1001 "out %[port], %[hi]" "\n\t" 1002 "rcall bitTimeC" "\n\t" 1003 "out %[port], %[hi]" "\n\t" 1004 "rcall bitTimeC" "\n\t" 1005 "out %[port], %[hi]" "\n\t" 1006 "rcall bitTimeC" "\n\t" 1007 "out %[port] , %[hi]" "\n\t" 1009 "ld %[byte] , %a[ptr]+" "\n\t" 1010 "out %[port] , %[next]" "\n\t" 1011 "mov %[next] , %[lo]" "\n\t" 1012 "sbrc %[byte] , 7" "\n\t" 1013 "mov %[next] , %[hi]" "\n\t" 1015 "out %[port] , %[lo]" "\n\t" 1016 "sbiw %[count], 1" "\n\t" 1020 "out %[port], %[next]" "\n\t" 1021 "mov %[next], %[lo]" "\n\t" 1022 "rol %[byte]" "\n\t" 1023 "sbrc %[byte], 7" "\n\t" 1024 "mov %[next], %[hi]" "\n\t" 1026 "out %[port], %[lo]" "\n\t" 1029 : [byte]
"+r" (b), [next]
"+r" (next), [count]
"+w" (i)
1030 : [port]
"I" (_SFR_IO_ADDR(PORTF)), [ptr]
"e" (ptr), [hi]
"r" (hi),
1033 #if defined(PORTD) || defined(PORTB) || defined(PORTC) 1038 volatile uint8_t next, bit;
1040 hi = *port | pinMask;
1041 lo = *port & ~pinMask;
1047 "st %a[port], %[hi]" "\n\t" 1048 "sbrc %[byte] , 7" "\n\t" 1049 "mov %[next], %[hi]" "\n\t" 1051 "st %a[port], %[next]" "\n\t" 1056 "st %a[port], %[lo]" "\n\t" 1059 "breq nextbyte30" "\n\t" 1060 "rol %[byte]" "\n\t" 1064 "rjmp head30" "\n\t" 1065 "nextbyte30:" "\n\t" 1067 "ldi %[bit] , 8" "\n\t" 1068 "ld %[byte] , %a[ptr]+" "\n\t" 1069 "sbiw %[count], 1" "\n\t" 1071 : [port]
"+e" (port),
1080 #elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L) 1082 volatile uint8_t next, bit;
1084 hi = *port | pinMask;
1085 lo = *port & ~pinMask;
1091 "st %a[port], %[hi]" "\n\t" 1092 "sbrc %[byte], 7" "\n\t" 1093 "mov %[next], %[hi]" "\n\t" 1095 "st %a[port], %[next]" "\n\t" 1096 "mov %[next] , %[lo]" "\n\t" 1097 "breq nextbyte20" "\n\t" 1098 "rol %[byte]" "\n\t" 1101 "st %a[port], %[lo]" "\n\t" 1104 "rjmp head20" "\n\t" 1105 "nextbyte20:" "\n\t" 1106 "ldi %[bit] , 8" "\n\t" 1107 "ld %[byte] , %a[ptr]+" "\n\t" 1108 "st %a[port], %[lo]" "\n\t" 1110 "sbiw %[count], 1" "\n\t" 1112 : [port]
"+e" (port),
1122 volatile uint8_t next, bit;
1124 hi = *port | pinMask;
1125 lo = *port & ~pinMask;
1131 "st %a[port], %[hi]" "\n\t" 1132 "sbrc %[byte] , 7" "\n\t" 1133 "mov %[next] , %[hi]" "\n\t" 1136 "st %a[port], %[next]" "\n\t" 1142 "st %a[port], %[lo]" "\n\t" 1144 "mov %[next] , %[lo]" "\n\t" 1146 "breq nextbyte40" "\n\t" 1147 "rol %[byte]" "\n\t" 1154 "rjmp head40" "\n\t" 1155 "nextbyte40:" "\n\t" 1156 "ldi %[bit] , 8" "\n\t" 1157 "ld %[byte] , %a[ptr]+" "\n\t" 1159 "st %a[port], %[lo]" "\n\t" 1161 "sbiw %[count], 1" "\n\t" 1163 : [port]
"+e" (port),
1173 #error "CPU SPEED NOT SUPPORTED" 1175 #elif defined(__arm__) 1178 #if defined(TEENSYDUINO) && defined(KINETISK) // Teensy 3.0, 3.1, 3.2, 3.5, 3.6 1179 #define CYCLES_800_T0H (F_CPU / 4000000) 1180 #define CYCLES_800_T1H (F_CPU / 1250000) 1181 #define CYCLES_800 (F_CPU / 800000) 1182 #define CYCLES_400_T0H (F_CPU / 2000000) 1183 #define CYCLES_400_T1H (F_CPU / 833333) 1184 #define CYCLES_400 (F_CPU / 400000) 1188 volatile uint8_t *set = portSetRegister(
pin),
1189 *clr = portClearRegister(
pin);
1192 ARM_DEMCR |= ARM_DEMCR_TRCENA;
1193 ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA;
1196 cyc = ARM_DWT_CYCCNT + CYCLES_800;
1199 for(mask = 0x80; mask; mask >>= 1) {
1200 while(ARM_DWT_CYCCNT - cyc < CYCLES_800);
1201 cyc = ARM_DWT_CYCCNT;
1204 while(ARM_DWT_CYCCNT - cyc < CYCLES_800_T1H);
1206 while(ARM_DWT_CYCCNT - cyc < CYCLES_800_T0H);
1211 while(ARM_DWT_CYCCNT - cyc < CYCLES_800);
1213 cyc = ARM_DWT_CYCCNT + CYCLES_400;
1216 for(mask = 0x80; mask; mask >>= 1) {
1217 while(ARM_DWT_CYCCNT - cyc < CYCLES_400);
1218 cyc = ARM_DWT_CYCCNT;
1221 while(ARM_DWT_CYCCNT - cyc < CYCLES_400_T1H);
1223 while(ARM_DWT_CYCCNT - cyc < CYCLES_400_T0H);
1228 while(ARM_DWT_CYCCNT - cyc < CYCLES_400);
1231 #error "Sorry, only 48 MHz is supported, please set Tools > CPU Speed to 48 MHz" 1233 #elif defined(ESP8266) || defined(ESP32) 1237 #elif defined(__ARDUINO_ARC__) 1241 #define NOPx7 { __builtin_arc_nop(); \ 1242 __builtin_arc_nop(); __builtin_arc_nop(); \ 1243 __builtin_arc_nop(); __builtin_arc_nop(); \ 1244 __builtin_arc_nop(); __builtin_arc_nop(); } 1246 PinDescription *pindesc = &g_APinDescription[
pin];
1248 register uint8_t *p =
pixels;
1249 register uint32_t currByte = (uint32_t) (*p);
1250 register uint32_t currBit = 0x80 & currByte;
1251 register uint32_t bitCounter = 0;
1252 register uint32_t first = 1;
1254 if (pindesc->ulGPIOType == SS_GPIO) {
1255 register uint32_t reg = pindesc->ulGPIOBase + SS_GPIO_SWPORTA_DR;
1256 uint32_t reg_val = __builtin_arc_lr((
volatile uint32_t)reg);
1257 register uint32_t reg_bit_high = reg_val | (1 << pindesc->ulGPIOId);
1258 register uint32_t reg_bit_low = reg_val & ~(1 << pindesc->ulGPIOId);
1268 __builtin_arc_sr(first ? reg_bit_low : reg_bit_high, (
volatile uint32_t)reg);
1275 __builtin_arc_nop();
1278 __builtin_arc_sr(reg_bit_low, (
volatile uint32_t)reg);
1282 if(bitCounter >= 8) {
1284 currByte = (uint32_t) (*++p);
1287 currBit = 0x80 & currByte;
1290 }
else if(pindesc->ulGPIOType == SOC_GPIO) {
1291 register uint32_t reg = pindesc->ulGPIOBase + SOC_GPIO_SWPORTA_DR;
1292 uint32_t reg_val = MMIO_REG_VAL(reg);
1293 register uint32_t reg_bit_high = reg_val | (1 << pindesc->ulGPIOId);
1294 register uint32_t reg_bit_low = reg_val & ~(1 << pindesc->ulGPIOId);
1302 MMIO_REG_VAL(reg) = first ? reg_bit_low : reg_bit_high;
1306 __builtin_arc_nop();
1312 MMIO_REG_VAL(reg) = reg_bit_low;
1316 if(bitCounter >= 8) {
1318 currByte = (uint32_t) (*++p);
1321 currBit = 0x80 & currByte;
1327 #error Architecture not supported 1340 digitalWrite(p, LOW);
1343 port = portOutputRegister(digitalPinToPort(p));
1344 pinMask = digitalPinToBitMask(p);
1349 uint16_t n, uint8_t r, uint8_t g, uint8_t b) {
1371 uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
1396 r = (uint8_t)(c >> 16),
1397 g = (uint8_t)(c >> 8),
1408 uint8_t w = (uint8_t)(c >> 24);
1430 return ((uint32_t)p[
aOffset[0]] << 16) |
1431 ((uint32_t)p[
aOffset[1]] << 8) |
1442 return ((uint32_t)p[
aOffset[3]] << 24) |
1443 ((uint32_t)p[
aOffset[0]] << 16) |
1444 ((uint32_t)p[
aOffset[1]] << 8) |
1454 uint8_t newBrightness = b + 1;
1460 if(oldBrightness == 0) scale = 0;
1461 else if(b == 255) scale = 65535 / oldBrightness;
1462 else scale = (((uint16_t)newBrightness << 8) - 1) / oldBrightness;
1463 for(uint16_t i=0; i<
numBytes; i++) {
1465 *ptr++ = (c * scale) >> 8;
uint8_t * pixels
stores the pixels
int8_t pin
stores the pin -1 if the pin wasn't set
uint8_t aOffset[4]
stores the offsets in rgbw format
bool canShow(void)
this will determine if the next show is available [last show finished]
uint8_t getBrightness(void) const
returns the current set brightness
uint16_t numLEDs
stores the amount of LEDs
~NeoPixel(void)
the destructor [calling free on pixel and freeing input pin]
bool begun
true if NeoPixel::begin has been called
int8_t getPin(void)
this will return the set data pin
NeoPixel pixels
the NeoPixel-object we use
void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b)
sets the rgb color of a specific pixel
void updateLength(uint16_t n)
this changes the length of the connected LED stripe
uint16_t numBytes
stores the byte size [pixels] used internally
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b)
returns a color value that can be used with NeoPixel::setPixelColor()
void setPin(uint8_t p)
sets pin for communication
void clear(void)
this will reset all set pixels [won't call NeoPixel::show()]
uint8_t * getPixels(void) const
this will give you access to the pixels
void updateType(uint16_t t)
this changes the type of communication between arduino and LED stripe
NeoPixel(void)
the empty constructor
uint32_t endTime
stores the last call time of show for NeoPixel::canShow()
void setBrightness(uint8_t val)
changes the brightness for all further acceses via NeoPixel::setPixelColor()
uint8_t brightness
stores the brightness
#define EBOARD_NEO_800KHZ
bool is800KHz
determines the speed the communcation is working on
void begin(void)
this has to be called to start the communcation (you should call NeoPixel::setPin() before) ...
[NEO] this allows you to access Adafruit LED-stripes
uint32_t getPixelColor(uint16_t n) const
returns the color of a specific pixel
void show(void)
this will reveal the setPixels [via NeoPixel::setPixelColor() etc...]
uint16_t numPixels(void) const
returns the size of the LED stripe