X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fsamd21%2Fao_neopixel.c;fp=src%2Fsamd21%2Fao_neopixel.c;h=818910cab74f9a0e396c622daec26a2676e021fa;hp=0000000000000000000000000000000000000000;hb=c1708f3fa4ff412da8817ba0fa58d05fe7ef44f5;hpb=414ad2696bbe2a2f245ae7bb2ec8f57bc8cc0097 diff --git a/src/samd21/ao_neopixel.c b/src/samd21/ao_neopixel.c new file mode 100644 index 00000000..818910ca --- /dev/null +++ b/src/samd21/ao_neopixel.c @@ -0,0 +1,100 @@ +/* + * Copyright © 2019 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include + +void +ao_snek_neopixel_write(void *gpio, uint8_t pin, int npixel, const struct snek_neopixel *pixels) +{ + volatile uint32_t *outtgl = &(((struct samd21_port *) gpio)->outtgl); + uint32_t value = ((uint32_t) 1 << pin); + + while (npixel--) { + int32_t p = pixels->p; + uint8_t bit; + pixels++; + + ao_arch_block_interrupts(); + for (bit = 0; bit < 24; bit++) { + *outtgl = value; + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + if (p < 0) { + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + + *outtgl = value; + } else { + *outtgl = value; + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + + } + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + ao_arch_nop(); + + ao_arch_nop(); + + p <<= 1; + } + ao_arch_release_interrupts(); + } +}