summaryrefslogtreecommitdiffstats
path: root/drivers/avr/apa102.c
diff options
context:
space:
mode:
authorAldehir Rojas <hello@aldehir.com>2020-12-29 18:28:49 -0600
committerGitHub <noreply@github.com>2020-12-30 00:28:49 +0000
commit4f2f21dc05c70451593ba83ed7a0956c771850c2 (patch)
tree266942c390a6b8d78d6f7c2994039a5f8b2eba98 /drivers/avr/apa102.c
parent7dd99f2b22a34143c0443154d9cd97540443b096 (diff)
Rewrite APA102 support (#10894)
* Rewrite APA102 support The APA102 source was broken by commit 16a15c1cfcbfd0feb2c2cf1383676747e2f97d73 as it did not include the quantum header. This commit addresses that, as well as other issues with transferring bytes over the SPI interface, i.e. it was not setting the clock pin back to low after sending a bit. The deviation when sending the end frame is kept, but updated to the latest from the referenced project. Finally, these changes expose the global LED brightness parameter of the APA102. Brightness values are configurable through `APA102_DEFAULT_BRIGHTNESS` and `APA102_MAX_BRIGHTNESS`. * Fix typo in led brightness extern * Move driver out of AVR directory and add delay for ARM * Experimental APA102 support on AVR and ARM Co-authored-by: Alde Rojas <hello@alde.io> * Refactor apa102_send_byte() calls to a loop * Implement io_wait function for ARM * Move APA102 drivers to own directory, fix copyright notice * Add APA102 keymap to handwired/onekey * Simplify RGBLIGHT_ENABLE/DRIVER option handling Co-authored-by: Mikkel Jeppesen <2756925+Duckle29@users.noreply.github.com>
Diffstat (limited to 'drivers/avr/apa102.c')
-rw-r--r--drivers/avr/apa102.c96
1 files changed, 0 insertions, 96 deletions
diff --git a/drivers/avr/apa102.c b/drivers/avr/apa102.c
deleted file mode 100644
index 740acb5739..0000000000
--- a/drivers/avr/apa102.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * APA102 lib V1.0a
- *
- * Controls APA102 RGB-LEDs
- * Author: Mikkel (Duckle29 on GitHub)
- *
- * Dec 22th, 2017 v1.0a Initial Version
- *
- * 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, see <http://www.gnu.org/licenses/>.
- */
-
-#include "apa102.h"
-#include <avr/interrupt.h>
-#include <avr/io.h>
-#include <util/delay.h>
-#include "debug.h"
-
-// Setleds for standard RGB
-void inline apa102_setleds(LED_TYPE *ledarray, uint16_t leds) { apa102_setleds_pin(ledarray, leds, _BV(RGB_DI_PIN & 0xF), _BV(RGB_CLK_PIN & 0xF)); }
-
-void static inline apa102_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask_DI, uint8_t pinmask_CLK) {
- setPinOutput(RGB_DI_PIN);
- setPinOutput(RGB_CLK_PIN);
-
- apa102_send_array((uint8_t *)ledarray, leds)
-}
-
-void apa102_send_array(uint8_t *data, uint16_t leds) { // Data is struct of 3 bytes. RGB - leds is number of leds in data
- apa102_start_frame();
- while (leds--) {
- apa102_send_frame(0xFF000000 | (data->b << 16) | (data->g << 8) | data->r);
- data++;
- }
- apa102_end_frame(leds);
-}
-
-void apa102_send_frame(uint32_t frame) {
- for (uint32_t i = 0xFF; i > 0;) {
- apa102_send_byte(frame & i);
- i = i << 8;
- }
-}
-
-void apa102_start_frame() { apa102_send_frame(0); }
-
-void apa102_end_frame(uint16_t leds) {
- // This function has been taken from: https://github.com/pololu/apa102-arduino/blob/master/APA102.h
- // and adapted. The code is MIT licensed. I think thats compatible?
-
- // We need to send some more bytes to ensure that all the LEDs in the
- // chain see their new color and start displaying it.
- //
- // The data stream seen by the last LED in the chain will be delayed by
- // (count - 1) clock edges, because each LED before it inverts the clock
- // line and delays the data by one clock edge. Therefore, to make sure
- // the last LED actually receives the data we wrote, the number of extra
- // edges we send at the end of the frame must be at least (count - 1).
- // For the APA102C, that is sufficient.
- //
- // The SK9822 only updates after it sees 32 zero bits followed by one more
- // rising edge. To avoid having the update time depend on the color of
- // the last LED, we send a dummy 0xFF byte. (Unfortunately, this means
- // that partial updates of the beginning of an LED strip are not possible;
- // the LED after the last one you are trying to update will be black.)
- // After that, to ensure that the last LED in the chain sees 32 zero bits
- // and a rising edge, we need to send at least 65 + (count - 1) edges. It
- // is sufficent and simpler to just send (5 + count/16) bytes of zeros.
- //
- // We are ignoring the specification for the end frame in the APA102/SK9822
- // datasheets because it does not actually ensure that all the LEDs will
- // start displaying their new colors right away.
-
- apa102_send_byte(0xFF);
- for (uint16_t i = 0; i < 5 + leds / 16; i++) {
- apa102_send_byte(0);
- }
-}
-
-void apa102_send_byte(uint8_t byte) {
- uint8_t i;
- for (i = 0; i < 8; i++) {
- writePin(RGB_DI_PIN, !!(byte & (1 << (7 - i))));
- writePinHigh(RGB_CLK_PIN);
- }
-}