| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /**
- * @file WS2812_ATY.c
- *
- * @param Project DEVICE_GENERAL_ATY_LIB
- *
- * @author ATY
- *
- * @copyright
- * - Copyright 2017 - 2026 MZ-ATY
- * - This code follows:
- * - MZ-ATY Various Contents Joint Statement -
- * <a href="https://mengze.top/MZ-ATY_VCJS">
- * https://mengze.top/MZ-ATY_VCJS</a>
- * - CC 4.0 BY-NC-SA -
- * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
- * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
- * - Your use will be deemed to have accepted the terms of this statement.
- *
- * @brief functions of WS2812 for C platform (Dev-style)
- *
- * @version
- * - 1_01_251112 > ATY
- * -# Refactor to Dev-style; remove legacy global interfaces
- ********************************************************************************
- */
- #ifndef __WS2812_ATY_C
- #define __WS2812_ATY_C
- #include "WS2812_ATY.h"
- static void _ws2812_send_byte(struct WS2812_ATY_Dev* dev, uint8_t byte)
- {
- for (int i = 7; i >= 0; --i) {
- uint8_t bit = (byte >> i) & 0x01;
- dev->sendBit(bit);
- }
- }
- uint8_t WS2812_InitDev(struct WS2812_ATY_Dev* dev)
- {
- if (!dev || !dev->sendBit) return 1;
- if (dev->debugEnable == 1 && dev->LOG) dev->LOG("\r\nWS2812 init done.");
- return 0;
- }
- void WS2812_SendColorDev(struct WS2812_ATY_Dev* dev, uint8_t R, uint8_t G, uint8_t B)
- {
- __ATY_LOCK(dev);
- _ws2812_send_byte(dev, G);
- _ws2812_send_byte(dev, R);
- _ws2812_send_byte(dev, B);
- if (dev->reset_us) dev->reset_us(60);
- if (dev->debugEnable == 1 && dev->LOG) dev->LOG("\r\nWS2812 send color.");
- __ATY_UNLOCK(dev);
- }
- void WS2812_SendBufferDev(struct WS2812_ATY_Dev* dev, const uint8_t* rgb, uint16_t count)
- {
- __ATY_LOCK(dev);
- if (!dev || !dev->sendBit || !rgb) { __ATY_UNLOCK(dev); return; }
- for (uint16_t i = 0; i < count; ++i) {
- uint8_t R = rgb[i*3 + 0];
- uint8_t G = rgb[i*3 + 1];
- uint8_t B = rgb[i*3 + 2];
- _ws2812_send_byte(dev, G);
- _ws2812_send_byte(dev, R);
- _ws2812_send_byte(dev, B);
- }
- if (dev->reset_us) dev->reset_us(60);
- if (dev->debugEnable == 1 && dev->LOG) dev->LOG("\r\nWS2812 send buffer.");
- __ATY_UNLOCK(dev);
- }
- #endif /* __WS2812_ATY_C */
- /******************************** End Of File *********************************/
|