{"id":70030,"date":"2026-02-01T13:49:37","date_gmt":"2026-02-01T05:49:37","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/70030.html"},"modified":"2026-02-01T13:49:37","modified_gmt":"2026-02-01T05:49:37","slug":"spi-%e9%a9%b1%e5%8a%a8-ws2812-gd32%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/70030.html","title":{"rendered":"SPI \u9a71\u52a8 WS2812 GD32\u65b9\u6848"},"content":{"rendered":"<p>\u9047\u5230\u7684\u5927\u5751&#xff1a;<br \/>\n<span style=\"color:#fe2c24\">1.spi\u4e00\u5b9a\u8981\u9009&#xff1a;\u00a0\u8df3\u53d8\u6cbf\u9009\u7b2c\u4e8c\u4e2a&#xff08;2Edge&#xff09;\u6a21\u5f0f<\/span><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"37\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201054936-697ee97037d25.png\" width=\"682\" \/><\/p>\n<p>\u56e0\u4e3a\u8df3\u53d8\u6cbf\u4e3a 1 \u7684\u8bdd&#xff0c;MOSI \u7684\u7a7a\u95f2\u7535\u5e73\u4e3a\u9ad8\u7535\u5e73&#xff0c;\u4e3a 2 \u7684\u8bdd\u5219\u4f1a\u5ef6\u7eed\u4e0a\u6b21\u53d1\u9001\u7684\u6700\u540e\u7535\u5e73&#xff0c;\u6211\u4eec\u53d1\u9001\u6570\u636e\u7684\u672b\u5c3e\u90fd\u662f\u4f4e\u7535\u5e73&#xff0c;\u8fd9\u6837 WS2812 \u4e0d\u4f1a\u8bef\u5224<\/p>\n<\/p>\n<p>2.\u5176\u5b9e\u4f60\u7684\u9a71\u52a8\u6ce2\u5f62\u6839\u672c\u4e0d\u9700\u8981\u90a3\u4e48\u4e25\u683c&#xff0c;\u624b\u518c\u89c4\u5b9a\u7684\u65f6\u95f4\u4ee5\u5916\u8fd8\u6709\u4f59\u91cf&#xff0c;\u6211\u5c31\u662f\u672c\u6765\u8981\u6c42560ns-1us\u6211\u5c31\u5230\u00b71us\u4f46\u662f\u989c\u8272\u4e0d\u5bf9\u4e22\u6570\u636e\u4e86&#xff0c;\u6700\u540e\u8bc1\u5b9e\u53ea\u662f\u56e0\u4e3a1.\u4e2d\u8df3\u53d8\u6cbf\u9009\u7b2c\u4e8c\u4e2a&#xff08;2Edge&#xff09;\u6a21\u5f0f\u6ca1\u9009\u5bf9\u5bfc\u81f4\u521a\u5f00\u59cb\u6ce2\u5f62\u9519\u8bef&#xff0c;<span style=\"color:#fe2c24\">\u8fd9\u4e5f\u662f\u6700\u91cd\u8981\u7684&#xff0c;\u4f60\u521a\u5f00\u59cb\u7ed9\u9ad8\u7535\u5e73\u5176\u5b9e\u662f\u771f\u7684\u4f1a\u9519<\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u4ee5\u540e\u9047\u5230\u4efb\u4f55\u9a71\u52a8\u53ea\u8981\u4f60\u7684\u65f6\u5e8f\u5dee\u5979\u624b\u518c\u7684\u6781\u9650\u51e0\u7eb3\u79d2\u4e00\u70b9\u90fd\u662f\u6ca1\u4e8b\u7684<\/span><\/p>\n<p>3.\u624b\u518c\u6709\u4e9b\u4eba\u7684\u662f\u9519\u7684\u6211\u53bb\u5609\u7acb\u521b\u62ff\u7684\u4e5f\u662f\u9519\u7684\u4e0b\u6b21\u5199\u9a71\u52a8\u5f97\u591a\u53c2\u8003\u4ef7\u770b\u51e0\u4efd\u6210\u529f\u7ecf\u5386<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"352\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201054936-697ee97043fea.png\" width=\"599\" \/><\/p>\n<p>spi\u5c31\u884c\u4e0d\u7528dma\u4e5f\u53ef\u4ee5\u56e0\u4e3a\u6700\u5feb\u5c31\u90a3\u6837&#xff0c;\u4f60\u4f7f\u7528dma\u53ef\u4ee5\u8282\u7ea6cpu\u8d44\u6e90\u4f46\u5bf9\u6211\u6765\u8bf4\u6ca1\u5565\u7528<\/p>\n<p>gpio&#043;nop&#xff08;&#xff09;\u4e5f\u80fd\u9a71\u52a8\u5c31\u662f\u53ef\u80fd\u4f1a\u6709\u51e0\u7387\u663e\u793a\u9519\u8bef<\/p>\n<\/p>\n<p>\u5177\u4f53\u914d\u7f6e\u4e3a&#xff1a;<\/p>\n<p>\u5185\u90e8\u65f6\u949f\u500d\u9891\u523072m\u4e3b\u9891\u00a0 spi 8\u5206\u9891\u00a0<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"150\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201054936-697ee97056274.png\" width=\"731\" \/><\/p>\n<p>\u4ea7\u751f\u6ce2\u5f62&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"151\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201054936-697ee97060cea.png\" width=\"522\" \/><\/p>\n<\/p>\n<p>\u53c2\u8003\u4ee3\u7801&#xff1a;<\/p>\n<p>\u00a0<\/p>\n<p>\/*!<br \/>\n    \\\\file    main.c<br \/>\n    \\\\brief   USART DMA receive by IDLE interrupt &#043; SPI\u9a71\u52a8WS2812B<\/p>\n<p>    \\\\version 2025-01-01, V3.7.0, firmware update for GD32F1x0(x&#061;3,5)<br \/>\n*\/<\/p>\n<p>\/*<br \/>\n    Copyright (c) 2025, GigaDevice Semiconductor Inc.<\/p>\n<p>    Redistribution and use in source and binary forms, with or without modification,<br \/>\nare permitted provided that the following conditions are met:<\/p>\n<p>    1. Redistributions of source code must retain the above copyright notice, this<br \/>\n       list of conditions and the following disclaimer.<br \/>\n    2. Redistributions in binary form must reproduce the above copyright notice,<br \/>\n       this list of conditions and the following disclaimer in the documentation<br \/>\n       and\/or other materials provided with the distribution.<br \/>\n    3. Neither the name of the copyright holder nor the names of its contributors<br \/>\n       may be used to endorse or promote products derived from this software without<br \/>\n       specific prior written permission.<\/p>\n<p>    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &#034;AS IS&#034;<br \/>\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED<br \/>\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.<br \/>\nIN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,<br \/>\nINDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT<br \/>\nNOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR<br \/>\nPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,<br \/>\nWHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br \/>\nARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY<br \/>\nOF SUCH DAMAGE.<br \/>\n*\/<\/p>\n<p>#include &#034;gd32f1x0.h&#034;<br \/>\n#include &lt;stdio.h&gt;<br \/>\n#include &#034;gd32f1x0r_eval.h&#034;<br \/>\n#include &#034;systick.h&#034;<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u7c7b\u578b\u5b9a\u4e49<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\ntypedef struct {<br \/>\n    uint8_t green;<br \/>\n    uint8_t red;<br \/>\n    uint8_t blue;<br \/>\n} WS2812B_Color;<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u7cfb\u7edf\u65f6\u949f\u914d\u7f6e (72MHz)<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n#define SYSTEM_CLOCK    72000000    \/\/ \u7cfb\u7edf\u4e3b\u989172MHz<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ WS2812B SPI\u9a71\u52a8\u914d\u7f6e (72MHz\u7cfb\u7edf\u65f6\u949f)<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n#define SPI_CLOCK_DIV              SPI_PSC_8      \/\/ \u9884\u5206\u98918&#xff0c;\u5f97\u52309MHz SPI\u65f6\u949f<br \/>\n#define SPI_CLOCK_FREQ             9000000        \/\/ 9MHz SPI\u65f6\u949f<br \/>\n#define SPI_BIT_TIME_NS            111            \/\/ \u6bcf\u4e2aSPI\u4f4d\u7ea6111ns<\/p>\n<p>\/\/ WS2812B SPI\u7f16\u7801&#xff08;\u57fa\u4e8e9MHz SPI\u65f6\u949f&#xff09;<br \/>\n#define WS2812B_SPI_0_CODE         0xC0    \/\/ 0\u7801: 11000000 &#8211; \u9ad8\u7535\u5e73222ns(2bits)&#xff0c;\u4f4e\u7535\u5e73667ns(6bits)<br \/>\n#define WS2812B_SPI_1_CODE         0xF8    \/\/ 1\u7801: 11111000 &#8211; \u9ad8\u7535\u5e73556ns(5bits)&#xff0c;\u4f4e\u7535\u5e73333ns(3bits)<\/p>\n<p>#define WS2812B_SPI_RESET_US       300     \/\/ \u590d\u4f4d\u65f6\u95f4300us<br \/>\n#define WS2812B_SPI_RESET_BYTES    270<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ LED\u914d\u7f6e<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n#define MAX_LED_COUNT              100     \/\/ \u6700\u5927LED\u6570\u91cf<br \/>\n#define DEFAULT_LED_COUNT          40      \/\/ \u9ed8\u8ba4LED\u6570\u91cf<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u6a21\u5f0f\u5b9a\u4e49&#xff08;\u6839\u636e\u4f60\u7684\u4e0a\u4f4d\u673a\u8c03\u6574&#xff09;<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n#define MODE_STATIC_COLOR          0       \/\/ \u9759\u6001\u989c\u8272\u6a21\u5f0f&#xff08;\u4e0a\u4f4d\u673a\u5f53\u524d\u4f7f\u7528&#xff09;<br \/>\n#define MODE_RAINBOW_BREATH        1       \/\/ \u5f69\u8679\u547c\u5438\u706f\u6a21\u5f0f<br \/>\n#define MODE_RAINBOW_FLOW          2       \/\/ \u5f69\u8679\u6d41\u6c34\u706f\u6a21\u5f0f<br \/>\n#define MODE_RAINBOW_WAVE          3       \/\/ \u5f69\u8679\u6ce2\u6d6a\u6a21\u5f0f<br \/>\n#define MODE_COLOR_WIPE            4       \/\/ \u989c\u8272\u626b\u9664\u6a21\u5f0f<br \/>\n#define MODE_THEATER_CHASE         5       \/\/ \u5267\u573a\u8ffd\u9010\u6a21\u5f0f<br \/>\n#define MODE_SINGLE_COLOR_BREATH   6       \/\/ \u5355\u8272\u547c\u5438\u706f\u6a21\u5f0f<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u6307\u4ee4\u5b57\u8282\u7d22\u5f15\u5b9a\u4e49&#xff08;\u9002\u914d\u4f60\u768422\u5b57\u8282\u6307\u4ee4&#xff09;<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n#define CMD_HEADER_0              0        \/\/ DD<br \/>\n#define CMD_HEADER_1              1        \/\/ 55<br \/>\n#define CMD_HEADER_2              2        \/\/ EE<br \/>\n#define CMD_MODE_SELECT           3        \/\/ \u6a21\u5f0f\u9009\u62e9&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u4e3a00&#xff09;<br \/>\n#define CMD_EFFECT_SPEED          4        \/\/ \u6548\u679c\u901f\u5ea6&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u4e3a00&#xff09;<br \/>\n#define CMD_EFFECT_BRIGHTNESS     5        \/\/ \u6548\u679c\u4eae\u5ea6&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u4e3a00&#xff09;<br \/>\n#define CMD_EFFECT_PARAM1         6        \/\/ \u53c2\u65701&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u4e3a01&#xff09;<br \/>\n#define CMD_EFFECT_PARAM2         7        \/\/ \u53c2\u65702&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u4e3a00&#xff09;<br \/>\n#define CMD_EFFECT_PARAM3         8        \/\/ \u53c2\u65703&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u4e3a99&#xff09;<br \/>\n#define CMD_EFFECT_PARAM4         9        \/\/ \u53c2\u65704&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u4e3a01&#xff09;<br \/>\n#define CMD_EFFECT_PARAM5         10       \/\/ \u53c2\u65705&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u4e3a00&#xff09;<br \/>\n#define CMD_EFFECT_PARAM6         11       \/\/ \u53c2\u65706&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u4e3a00&#xff09;<br \/>\n#define CMD_EFFECT_PARAM7         12       \/\/ \u53c2\u65707&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u4e3a00&#xff09;<br \/>\n#define CMD_EFFECT_PARAM8         13       \/\/ \u53c2\u65708&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u4e3a03&#xff09;<br \/>\n#define CMD_EFFECT_PARAM9         14       \/\/ \u53c2\u65709&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u4e3a00&#xff09;<br \/>\n#define CMD_LED_COUNT             15       \/\/ LED\u6570\u91cf&#xff08;\u4f60\u7684\u6307\u4ee4\u7d22\u5f1515&#xff09;<br \/>\n#define CMD_COLOR_R               16       \/\/ \u989c\u8272R&#xff08;\u4f60\u7684\u6307\u4ee4\u7d22\u5f1516&#xff09;<br \/>\n#define CMD_COLOR_G               17       \/\/ \u989c\u8272G&#xff08;\u4f60\u7684\u6307\u4ee4\u7d22\u5f1517&#xff09;<br \/>\n#define CMD_COLOR_B               18       \/\/ \u989c\u8272B&#xff08;\u4f60\u7684\u6307\u4ee4\u7d22\u5f1518&#xff09;<br \/>\n#define CMD_CHECKSUM_1            19       \/\/ \u6821\u9a8c\u78011 AA<br \/>\n#define CMD_CHECKSUM_2            20       \/\/ \u6821\u9a8c\u78012 BB<\/p>\n<p>#define CMD_TOTAL_LENGTH          21       \/\/ \u603b\u6307\u4ee4\u957f\u5ea6&#xff08;\u4f60\u7684\u6307\u4ee4\u662f22\u5b57\u8282&#xff09;<br \/>\n#define CMD_MIN_LENGTH            21       \/\/ \u6700\u5c0f\u6307\u4ee4\u957f\u5ea6<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u5168\u5c40\u53d8\u91cf<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nWS2812B_Color led_buffer[MAX_LED_COUNT];<br \/>\nuint8_t current_led_count &#061; DEFAULT_LED_COUNT;<\/p>\n<p>\/\/ \u7279\u6548\u76f8\u5173\u53d8\u91cf<br \/>\nuint8_t effect_mode &#061; MODE_STATIC_COLOR;       \/\/ \u5f53\u524d\u6a21\u5f0f<br \/>\nuint8_t effect_speed &#061; 30;                     \/\/ \u7279\u6548\u901f\u5ea6(ms)<br \/>\nuint8_t effect_brightness &#061; 150;               \/\/ \u7279\u6548\u4eae\u5ea6(0-255)<\/p>\n<p>\/\/ \u7279\u6548\u4e13\u7528\u53d8\u91cf<br \/>\nuint8_t breath_direction &#061; 1;                 \/\/ \u547c\u5438\u65b9\u5411 0:\u51cf\u5f31 1:\u589e\u5f3a<br \/>\nuint8_t breath_current_brightness &#061; 100;      \/\/ \u5f53\u524d\u547c\u5438\u4eae\u5ea6<br \/>\nWS2812B_Color current_color &#061; {0, 255, 0};    \/\/ \u5f53\u524d\u989c\u8272&#xff08;\u9ed8\u8ba4\u7eff\u8272&#xff09;<br \/>\nuint16_t rainbow_hue &#061; 0;                     \/\/ \u8272\u8c03 (0-359)<br \/>\nuint16_t flow_position &#061; 0;                   \/\/ \u6d41\u6c34\u4f4d\u7f6e<br \/>\nuint16_t wave_offset &#061; 0;                     \/\/ \u6ce2\u6d6a\u504f\u79fb<br \/>\nuint8_t wipe_position &#061; 0;                    \/\/ \u626b\u9664\u4f4d\u7f6e<br \/>\nuint8_t theater_position &#061; 0;                 \/\/ \u8ffd\u9010\u4f4d\u7f6e<br \/>\nuint8_t theater_color_index &#061; 0;              \/\/ \u989c\u8272\u7d22\u5f15<\/p>\n<p>\/\/ \u4e32\u53e3\u63a5\u6536\u76f8\u5173<br \/>\nuint8_t rxbuffer[256];<br \/>\nuint8_t rx_count &#061; 0;<br \/>\nuint8_t receive_flag &#061; 0;<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u51fd\u6570\u58f0\u660e<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nvoid dma_config(void);<br \/>\nvoid usart_config(void);<br \/>\nvoid nvic_config(void);<br \/>\nvoid spi_ws2812b_config(void);<br \/>\nvoid ws2812b_init(void);<br \/>\nvoid ws2812b_set_led(uint16_t led_num, WS2812B_Color color);<br \/>\nvoid ws2812b_update(void);<br \/>\nvoid ws2812b_clear_all(void);<br \/>\nvoid spi_send_data_blocking(uint8_t *data, uint32_t length);<br \/>\nvoid ws2812b_color_to_spi(uint8_t r, uint8_t g, uint8_t b, uint8_t *spi_buffer);<br \/>\nvoid ws2812b_send_pixel_spi(uint8_t r, uint8_t g, uint8_t b);<br \/>\nvoid ws2812b_send_reset_spi(void);<br \/>\nvoid ws2812b_update_spi(void);<\/p>\n<p>\/\/ \u7279\u6548\u51fd\u6570<br \/>\nWS2812B_Color hsv_to_rgb(uint16_t h, uint8_t s, uint8_t v);<br \/>\nvoid rainbow_breathing_effect(void);<br \/>\nvoid single_color_breathing_effect(void);<br \/>\nvoid rainbow_flow_effect(void);<br \/>\nvoid rainbow_wave_effect(void);<br \/>\nvoid color_wipe_effect(void);<br \/>\nvoid theater_chase_effect(void);<br \/>\nvoid process_effects(void);<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ WS2812B SPI\u914d\u7f6e\u51fd\u6570<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nvoid spi_ws2812b_config(void)<br \/>\n{<br \/>\n    spi_parameter_struct spi_init_struct;<\/p>\n<p>    \/\/ \u542f\u7528GPIO\u548cSPI\u65f6\u949f<br \/>\n    rcu_periph_clock_enable(RCU_GPIOA);<br \/>\n    rcu_periph_clock_enable(RCU_SPI0);<\/p>\n<p>    \/\/ \u914d\u7f6eSPI\u5f15\u811a&#xff08;PA5&#061;SCK, PA7&#061;MOSI&#xff09;<br \/>\n    gpio_af_set(GPIOA, GPIO_AF_0, GPIO_PIN_5 | GPIO_PIN_7);<br \/>\n    gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_5 | GPIO_PIN_7);<br \/>\n    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_5 | GPIO_PIN_7);<\/p>\n<p>    \/\/ \u521d\u59cb\u5316SPI<br \/>\n    spi_i2s_deinit(SPI0);<br \/>\n    spi_struct_para_init(&amp;spi_init_struct);<\/p>\n<p>    spi_init_struct.trans_mode           &#061; SPI_TRANSMODE_BDTRANSMIT;<br \/>\n    spi_init_struct.device_mode          &#061; SPI_MASTER;<br \/>\n    spi_init_struct.frame_size           &#061; SPI_FRAMESIZE_8BIT;<br \/>\n    spi_init_struct.clock_polarity_phase &#061; SPI_CK_PL_LOW_PH_2EDGE;<br \/>\n    spi_init_struct.nss                  &#061; SPI_NSS_SOFT;<br \/>\n    spi_init_struct.prescale             &#061; SPI_CLOCK_DIV;<br \/>\n    spi_init_struct.endian               &#061; SPI_ENDIAN_MSB;<\/p>\n<p>    spi_init(SPI0, &amp;spi_init_struct);<br \/>\n    spi_enable(SPI0);<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ SPI\u6570\u636e\u53d1\u9001\u51fd\u6570<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nvoid spi_send_data_blocking(uint8_t *data, uint32_t length)<br \/>\n{<br \/>\n    for (uint32_t i &#061; 0; i &lt; length; i&#043;&#043;) {<br \/>\n        while(spi_i2s_flag_get(SPI0, SPI_FLAG_TBE) &#061;&#061; RESET);<br \/>\n        spi_i2s_data_transmit(SPI0, data[i]);<br \/>\n    }<br \/>\n    while(spi_i2s_flag_get(SPI0, SPI_FLAG_TRANS) &#061;&#061; RESET);<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ WS2812B\u989c\u8272\u8f6c\u6362\u51fd\u6570<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nvoid ws2812b_color_to_spi(uint8_t r, uint8_t g, uint8_t b, uint8_t *spi_buffer)<br \/>\n{<br \/>\n    uint32_t color &#061; ((uint32_t)g &lt;&lt; 16) | ((uint32_t)r &lt;&lt; 8) | b;<br \/>\n    uint8_t *ptr &#061; spi_buffer;<\/p>\n<p>    for (int32_t i &#061; 23; i &gt;&#061; 0; i&#8211;) {<br \/>\n        if (color &amp; (1 &lt;&lt; i)) {<br \/>\n            *ptr&#043;&#043; &#061; WS2812B_SPI_1_CODE;<br \/>\n        } else {<br \/>\n            *ptr&#043;&#043; &#061; WS2812B_SPI_0_CODE;<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ WS2812B SPI\u9a71\u52a8\u6838\u5fc3\u51fd\u6570<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nvoid ws2812b_send_pixel_spi(uint8_t r, uint8_t g, uint8_t b)<br \/>\n{<br \/>\n    uint8_t spi_buffer[24];<br \/>\n    ws2812b_color_to_spi(r, g, b, spi_buffer);<br \/>\n    spi_send_data_blocking(spi_buffer, 24);<br \/>\n}<\/p>\n<p>void ws2812b_send_reset_spi(void)<br \/>\n{<br \/>\n    static uint8_t reset_buffer[WS2812B_SPI_RESET_BYTES] &#061; {0};<br \/>\n    spi_send_data_blocking(reset_buffer, WS2812B_SPI_RESET_BYTES);<br \/>\n}<\/p>\n<p>void ws2812b_update_spi(void)<br \/>\n{<br \/>\n    for (uint16_t i &#061; 0; i &lt; current_led_count; i&#043;&#043;) {<br \/>\n        ws2812b_send_pixel_spi(led_buffer[i].red, led_buffer[i].green, led_buffer[i].blue);<br \/>\n    }<br \/>\n    ws2812b_send_reset_spi();<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ HSV\u8f6cRGB\u51fd\u6570<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nWS2812B_Color hsv_to_rgb(uint16_t h, uint8_t s, uint8_t v)<br \/>\n{<br \/>\n    WS2812B_Color rgb &#061; {0, 0, 0};<br \/>\n    uint8_t region, remainder, p, q, t;<\/p>\n<p>    if (s &#061;&#061; 0) {<br \/>\n        rgb.red &#061; v;<br \/>\n        rgb.green &#061; v;<br \/>\n        rgb.blue &#061; v;<br \/>\n        return rgb;<br \/>\n    }<\/p>\n<p>    region &#061; h \/ 60;<br \/>\n    remainder &#061; (h % 60) * 4;<\/p>\n<p>    p &#061; (v * (255 &#8211; s)) &gt;&gt; 8;<br \/>\n    q &#061; (v * (255 &#8211; ((s * remainder) &gt;&gt; 8))) &gt;&gt; 8;<br \/>\n    t &#061; (v * (255 &#8211; ((s * (255 &#8211; remainder)) &gt;&gt; 8))) &gt;&gt; 8;<\/p>\n<p>    switch (region) {<br \/>\n        case 0:<br \/>\n            rgb.red &#061; v; rgb.green &#061; t; rgb.blue &#061; p;<br \/>\n            break;<br \/>\n        case 1:<br \/>\n            rgb.red &#061; q; rgb.green &#061; v; rgb.blue &#061; p;<br \/>\n            break;<br \/>\n        case 2:<br \/>\n            rgb.red &#061; p; rgb.green &#061; v; rgb.blue &#061; t;<br \/>\n            break;<br \/>\n        case 3:<br \/>\n            rgb.red &#061; p; rgb.green &#061; q; rgb.blue &#061; v;<br \/>\n            break;<br \/>\n        case 4:<br \/>\n            rgb.red &#061; t; rgb.green &#061; p; rgb.blue &#061; v;<br \/>\n            break;<br \/>\n        default:<br \/>\n            rgb.red &#061; v; rgb.green &#061; p; rgb.blue &#061; q;<br \/>\n            break;<br \/>\n    }<\/p>\n<p>    return rgb;<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u5f69\u8679\u547c\u5438\u706f\u6548\u679c<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nvoid rainbow_breathing_effect(void)<br \/>\n{<br \/>\n    rainbow_hue &#043;&#061; 1;<br \/>\n    if (rainbow_hue &gt;&#061; 360) {<br \/>\n        rainbow_hue &#061; 0;<br \/>\n    }<\/p>\n<p>    if (breath_direction) {<br \/>\n        breath_current_brightness &#043;&#061; 2;<br \/>\n        if (breath_current_brightness &gt;&#061; effect_brightness) {<br \/>\n            breath_direction &#061; 0;<br \/>\n            breath_current_brightness &#061; effect_brightness;<br \/>\n        }<br \/>\n    } else {<br \/>\n        breath_current_brightness -&#061; 2;<br \/>\n        if (breath_current_brightness &lt;&#061; 50) {<br \/>\n            breath_direction &#061; 1;<br \/>\n            breath_current_brightness &#061; 50;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    WS2812B_Color rainbow_color &#061; hsv_to_rgb(rainbow_hue, 255, breath_current_brightness);<\/p>\n<p>    for (uint16_t i &#061; 0; i &lt; current_led_count; i&#043;&#043;) {<br \/>\n        led_buffer[i] &#061; rainbow_color;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u5355\u8272\u547c\u5438\u706f\u6548\u679c<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nvoid single_color_breathing_effect(void)<br \/>\n{<br \/>\n    if (breath_direction) {<br \/>\n        breath_current_brightness &#043;&#061; 2;<br \/>\n        if (breath_current_brightness &gt;&#061; effect_brightness) {<br \/>\n            breath_direction &#061; 0;<br \/>\n            breath_current_brightness &#061; effect_brightness;<br \/>\n        }<br \/>\n    } else {<br \/>\n        breath_current_brightness -&#061; 2;<br \/>\n        if (breath_current_brightness &lt;&#061; 50) {<br \/>\n            breath_direction &#061; 1;<br \/>\n            breath_current_brightness &#061; 50;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    WS2812B_Color current_color_adj;<br \/>\n    current_color_adj.red &#061; (current_color.red * breath_current_brightness) \/ effect_brightness;<br \/>\n    current_color_adj.green &#061; (current_color.green * breath_current_brightness) \/ effect_brightness;<br \/>\n    current_color_adj.blue &#061; (current_color.blue * breath_current_brightness) \/ effect_brightness;<\/p>\n<p>    for (uint16_t i &#061; 0; i &lt; current_led_count; i&#043;&#043;) {<br \/>\n        led_buffer[i] &#061; current_color_adj;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u5f69\u8679\u6d41\u6c34\u706f\u6548\u679c<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nvoid rainbow_flow_effect(void)<br \/>\n{<br \/>\n    flow_position&#043;&#043;;<br \/>\n    if (flow_position &gt;&#061; current_led_count) {<br \/>\n        flow_position &#061; 0;<br \/>\n    }<\/p>\n<p>    WS2812B_Color black &#061; {0, 0, 0};<br \/>\n    for (uint16_t i &#061; 0; i &lt; current_led_count; i&#043;&#043;) {<br \/>\n        led_buffer[i] &#061; black;<br \/>\n    }<\/p>\n<p>    for (uint8_t i &#061; 0; i &lt; 3; i&#043;&#043;) {<br \/>\n        uint16_t pos &#061; (flow_position &#043; i) % current_led_count;<br \/>\n        uint16_t hue &#061; (rainbow_hue &#043; i * 30) % 360;<br \/>\n        WS2812B_Color color &#061; hsv_to_rgb(hue, 255, effect_brightness);<br \/>\n        led_buffer[pos] &#061; color;<br \/>\n    }<\/p>\n<p>    rainbow_hue &#043;&#061; 3;<br \/>\n    if (rainbow_hue &gt;&#061; 360) {<br \/>\n        rainbow_hue &#061; 0;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u5f69\u8679\u6ce2\u6d6a\u6548\u679c<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nvoid rainbow_wave_effect(void)<br \/>\n{<br \/>\n    wave_offset &#043;&#061; 3;<br \/>\n    if (wave_offset &gt;&#061; 360) {<br \/>\n        wave_offset &#061; 0;<br \/>\n    }<\/p>\n<p>    for (uint16_t i &#061; 0; i &lt; current_led_count; i&#043;&#043;) {<br \/>\n        uint16_t hue &#061; (wave_offset &#043; i * 360 \/ current_led_count) % 360;<br \/>\n        WS2812B_Color color &#061; hsv_to_rgb(hue, 255, effect_brightness);<br \/>\n        led_buffer[i] &#061; color;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u989c\u8272\u626b\u9664\u6548\u679c<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nvoid color_wipe_effect(void)<br \/>\n{<br \/>\n    wipe_position&#043;&#043;;<br \/>\n    if (wipe_position &gt;&#061; current_led_count) {<br \/>\n        wipe_position &#061; 0;<br \/>\n    }<\/p>\n<p>    led_buffer[wipe_position] &#061; current_color;<\/p>\n<p>    static uint8_t last_position &#061; 0;<br \/>\n    if (wipe_position !&#061; last_position) {<br \/>\n        led_buffer[last_position] &#061; (WS2812B_Color){0, 0, 0};<br \/>\n        last_position &#061; wipe_position;<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u5267\u573a\u8ffd\u9010\u6548\u679c<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nvoid theater_chase_effect(void)<br \/>\n{<br \/>\n    theater_position &#061; (theater_position &#043; 1) % 3;<\/p>\n<p>    WS2812B_Color chase_colors[3] &#061; {<br \/>\n        {0, 255, 0},    \/\/ \u7eff\u8272<br \/>\n        {0, 0, 255},    \/\/ \u84dd\u8272<br \/>\n        {255, 0, 0}     \/\/ \u7ea2\u8272<br \/>\n    };<\/p>\n<p>    theater_color_index &#061; (theater_color_index &#043; 1) % 3;<\/p>\n<p>    for (uint16_t i &#061; 0; i &lt; current_led_count; i&#043;&#043;) {<br \/>\n        if ((i &#043; theater_position) % 3 &#061;&#061; 0) {<br \/>\n            led_buffer[i] &#061; chase_colors[theater_color_index];<br \/>\n        } else {<br \/>\n            led_buffer[i] &#061; (WS2812B_Color){0, 0, 0};<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u5904\u7406\u7279\u6548<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nvoid process_effects(void)<br \/>\n{<br \/>\n    switch (effect_mode) {<br \/>\n        case MODE_RAINBOW_BREATH:<br \/>\n            rainbow_breathing_effect();<br \/>\n            break;<\/p>\n<p>        case MODE_SINGLE_COLOR_BREATH:<br \/>\n            single_color_breathing_effect();<br \/>\n            break;<\/p>\n<p>        case MODE_RAINBOW_FLOW:<br \/>\n            rainbow_flow_effect();<br \/>\n            break;<\/p>\n<p>        case MODE_RAINBOW_WAVE:<br \/>\n            rainbow_wave_effect();<br \/>\n            break;<\/p>\n<p>        case MODE_COLOR_WIPE:<br \/>\n            color_wipe_effect();<br \/>\n            break;<\/p>\n<p>        case MODE_THEATER_CHASE:<br \/>\n            theater_chase_effect();<br \/>\n            break;<\/p>\n<p>        case MODE_STATIC_COLOR:<br \/>\n        default:<br \/>\n            return;<br \/>\n    }<\/p>\n<p>    ws2812b_update();<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ WS2812B\u7528\u6237API\u51fd\u6570<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nvoid ws2812b_init(void)<br \/>\n{<br \/>\n    spi_ws2812b_config();<br \/>\n    ws2812b_clear_all();<br \/>\n}<\/p>\n<p>void ws2812b_set_led(uint16_t led_num, WS2812B_Color color)<br \/>\n{<br \/>\n    if (led_num &gt; 0 &amp;&amp; led_num &lt;&#061; current_led_count) {<br \/>\n        led_buffer[led_num &#8211; 1] &#061; color;<br \/>\n    }<br \/>\n}<\/p>\n<p>void ws2812b_update(void)<br \/>\n{<br \/>\n    ws2812b_update_spi();<br \/>\n}<\/p>\n<p>void ws2812b_clear_all(void)<br \/>\n{<br \/>\n    WS2812B_Color black &#061; {0, 0, 0};<\/p>\n<p>    for (uint16_t i &#061; 0; i &lt; MAX_LED_COUNT; i&#043;&#043;) {<br \/>\n        led_buffer[i] &#061; black;<br \/>\n    }<\/p>\n<p>    ws2812b_update();<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u4e32\u53e3DMA\u914d\u7f6e\u51fd\u6570<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n#define USART0_RDATA_ADDRESS      ((uint32_t)&amp;USART_RDATA(USART0))<\/p>\n<p>void dma_config(void)<br \/>\n{<br \/>\n    dma_parameter_struct dma_init_struct;<\/p>\n<p>    rcu_periph_clock_enable(RCU_DMA);<\/p>\n<p>    dma_deinit(DMA_CH2);<br \/>\n    dma_init_struct.direction    &#061; DMA_PERIPHERAL_TO_MEMORY;<br \/>\n    dma_init_struct.memory_addr  &#061; (uint32_t)rxbuffer;<br \/>\n    dma_init_struct.memory_inc   &#061; DMA_MEMORY_INCREASE_ENABLE;<br \/>\n    dma_init_struct.memory_width &#061; DMA_MEMORY_WIDTH_8BIT;<br \/>\n    dma_init_struct.number       &#061; 256;<br \/>\n    dma_init_struct.periph_addr  &#061; (uint32_t)USART0_RDATA_ADDRESS;<br \/>\n    dma_init_struct.periph_inc   &#061; DMA_PERIPH_INCREASE_DISABLE;<br \/>\n    dma_init_struct.periph_width &#061; DMA_PERIPHERAL_WIDTH_8BIT;<br \/>\n    dma_init_struct.priority  &#061; DMA_PRIORITY_ULTRA_HIGH;<br \/>\n    dma_init(DMA_CH2, &amp;dma_init_struct);<br \/>\n    dma_circulation_disable(DMA_CH2);<br \/>\n    dma_channel_enable(DMA_CH2);<br \/>\n}<\/p>\n<p>void usart_config(void)<br \/>\n{<br \/>\n    rcu_periph_clock_enable(RCU_GPIOA);<br \/>\n    rcu_periph_clock_enable(RCU_USART0);<\/p>\n<p>    gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_9);<br \/>\n    gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_10);<\/p>\n<p>    gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_9);<br \/>\n    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_9);<\/p>\n<p>    gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_10);<br \/>\n    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_10);<\/p>\n<p>    usart_deinit(USART0);<br \/>\n    usart_baudrate_set(USART0, 115200U);<br \/>\n    usart_receive_config(USART0, USART_RECEIVE_ENABLE);<br \/>\n    usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);<br \/>\n    usart_dma_receive_config(USART0, USART_DENR_ENABLE);<br \/>\n    usart_dma_transmit_config(USART0, USART_DENR_ENABLE);<br \/>\n    usart_enable(USART0);<br \/>\n}<\/p>\n<p>void nvic_config(void)<br \/>\n{<br \/>\n    nvic_irq_enable(USART0_IRQn, 0, 0);<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u4e3b\u51fd\u6570&#xff08;\u9002\u914d\u4f60\u768422\u5b57\u8282\u6307\u4ee4&#xff09;<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\nint main(void)<br \/>\n{<br \/>\n    systick_config();<br \/>\n    nvic_config();<br \/>\n    dma_config();<br \/>\n    usart_config();<br \/>\n    ws2812b_init();<br \/>\n    ws2812b_clear_all();<\/p>\n<p>    while(RESET &#061;&#061; usart_flag_get(USART0, USART_FLAG_IDLE));<br \/>\n    usart_flag_clear(USART0, USART_FLAG_IDLE);<br \/>\n    usart_interrupt_enable(USART0, USART_INT_IDLE);<\/p>\n<p>    printf(&#034;\\\\n\\\\rWS2812B Driver Ready (22-byte command mode)\\\\n\\\\r&#034;);<br \/>\n    printf(&#034;Default command: DD 55 EE 00 00 00 01 00 99 01 00 00 00 03 00 [LED] [R] [G] [B] AA BB&#034;);<\/p>\n<p>    while(1) {<br \/>\n        if(1 &#061;&#061; receive_flag) {<br \/>\n            \/\/ \u68c0\u67e5\u6307\u4ee4\u957f\u5ea6\u662f\u5426\u4e3a22\u5b57\u8282<br \/>\n            if (rx_count &gt;&#061; CMD_MIN_LENGTH) {<br \/>\n                \/\/ \u68c0\u67e5\u6570\u636e\u5934<br \/>\n                if (rxbuffer[CMD_HEADER_0] &#061;&#061; 0xDD &amp;&amp;<br \/>\n                    rxbuffer[CMD_HEADER_1] &#061;&#061; 0x55 &amp;&amp;<br \/>\n                    rxbuffer[CMD_HEADER_2] &#061;&#061; 0xEE) {<\/p>\n<p>                    \/\/ \u63d0\u53d6\u6a21\u5f0f&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u4e3a00&#xff09;<br \/>\n                    uint8_t mode &#061; rxbuffer[CMD_MODE_SELECT];<\/p>\n<p>                    \/\/ \u63d0\u53d6\u53c2\u6570&#xff08;\u4f60\u7684\u4e0a\u4f4d\u673a\u56fa\u5b9a\u503c&#xff0c;\u53ef\u6682\u65f6\u5ffd\u7565&#xff09;<br \/>\n                    effect_speed &#061; rxbuffer[CMD_EFFECT_SPEED];<br \/>\n                    effect_brightness &#061; rxbuffer[CMD_EFFECT_BRIGHTNESS];<\/p>\n<p>                    \/\/ \u63d0\u53d6LED\u6570\u91cf&#xff08;\u4f60\u7684\u6307\u4ee4\u7d22\u5f1515&#xff09;<br \/>\n                    uint8_t new_led_count &#061; rxbuffer[CMD_LED_COUNT];<\/p>\n<p>                    \/\/ \u68c0\u67e5LED\u6570\u91cf\u662f\u5426\u6709\u6548<br \/>\n                    if (new_led_count &gt; 0 &amp;&amp; new_led_count &lt;&#061; MAX_LED_COUNT) {<br \/>\n                        current_led_count &#061; new_led_count;<br \/>\n                        printf(&#034;LED count updated to: %d\\\\n\\\\r&#034;, current_led_count);<br \/>\n                    } else {<br \/>\n                        printf(&#034;Error: Invalid LED count: %d\\\\n\\\\r&#034;, new_led_count);<br \/>\n                    }<\/p>\n<p>                    \/\/ \u63d0\u53d6\u989c\u8272\u503c&#xff08;\u4f60\u7684\u6307\u4ee4\u7d22\u5f1516-18&#xff09;<br \/>\n                    uint8_t cmd_R &#061; rxbuffer[CMD_COLOR_R];<br \/>\n                    uint8_t cmd_G &#061; rxbuffer[CMD_COLOR_G];<br \/>\n                    uint8_t cmd_B &#061; rxbuffer[CMD_COLOR_B];<\/p>\n<p>                    printf(&#034;Color: R&#061;%d, G&#061;%d, B&#061;%d\\\\n\\\\r&#034;, cmd_R, cmd_G, cmd_B);<\/p>\n<p>                    \/\/ \u4fdd\u5b58\u989c\u8272<br \/>\n                    current_color.red &#061; cmd_R;<br \/>\n                    current_color.green &#061; cmd_G;<br \/>\n                    current_color.blue &#061; cmd_B;<\/p>\n<p>                    \/\/ \u6839\u636e\u6a21\u5f0f\u5904\u7406<br \/>\n                    effect_mode &#061; mode;<\/p>\n<p>                    if (mode &#061;&#061; MODE_STATIC_COLOR) {<br \/>\n                        \/\/ \u9759\u6001\u989c\u8272\u6a21\u5f0f &#8211; \u9002\u914d\u4f60\u7684\u4e0a\u4f4d\u673a<br \/>\n                        WS2812B_Color target_color &#061; {cmd_G, cmd_R, cmd_B};  \/\/ WS2812B\u4f7f\u7528GRB\u987a\u5e8f<\/p>\n<p>                        \/\/ \u8bbe\u7f6e\u6240\u6709LED\u7684\u989c\u8272<br \/>\n                        for (uint16_t i &#061; 0; i &lt; current_led_count; i&#043;&#043;) {<br \/>\n                            ws2812b_set_led(i &#043; 1, target_color);<br \/>\n                        }<\/p>\n<p>                        \/\/ \u66f4\u65b0LED\u663e\u793a<br \/>\n                        ws2812b_update();<br \/>\n                        printf(&#034;Static color mode applied\\\\n\\\\r&#034;);<\/p>\n<p>                    } else if (mode &#061;&#061; MODE_SINGLE_COLOR_BREATH) {<br \/>\n                        \/\/ \u5355\u8272\u547c\u5438\u706f\u6a21\u5f0f<br \/>\n                        breath_current_brightness &#061; 100;<br \/>\n                        breath_direction &#061; 1;<br \/>\n                        printf(&#034;Single color breath mode activated\\\\n\\\\r&#034;);<\/p>\n<p>                    } else if (mode &#061;&#061; MODE_RAINBOW_BREATH) {<br \/>\n                        \/\/ \u5f69\u8679\u547c\u5438\u706f\u6a21\u5f0f<br \/>\n                        breath_current_brightness &#061; 100;<br \/>\n                        breath_direction &#061; 1;<br \/>\n                        rainbow_hue &#061; 0;<br \/>\n                        printf(&#034;Rainbow breath mode activated\\\\n\\\\r&#034;);<\/p>\n<p>                    } else if (mode &#061;&#061; MODE_RAINBOW_FLOW) {<br \/>\n                        \/\/ \u5f69\u8679\u6d41\u6c34\u706f\u6a21\u5f0f<br \/>\n                        flow_position &#061; 0;<br \/>\n                        rainbow_hue &#061; 0;<br \/>\n                        printf(&#034;Rainbow flow mode activated\\\\n\\\\r&#034;);<\/p>\n<p>                    } else if (mode &#061;&#061; MODE_RAINBOW_WAVE) {<br \/>\n                        \/\/ \u5f69\u8679\u6ce2\u6d6a\u6a21\u5f0f<br \/>\n                        wave_offset &#061; 0;<br \/>\n                        printf(&#034;Rainbow wave mode activated\\\\n\\\\r&#034;);<\/p>\n<p>                    } else if (mode &#061;&#061; MODE_COLOR_WIPE) {<br \/>\n                        \/\/ \u989c\u8272\u626b\u9664\u6a21\u5f0f<br \/>\n                        wipe_position &#061; 0;<br \/>\n                        printf(&#034;Color wipe mode activated\\\\n\\\\r&#034;);<\/p>\n<p>                    } else if (mode &#061;&#061; MODE_THEATER_CHASE) {<br \/>\n                        \/\/ \u5267\u573a\u8ffd\u9010\u6a21\u5f0f<br \/>\n                        theater_position &#061; 0;<br \/>\n                        theater_color_index &#061; 0;<br \/>\n                        printf(&#034;Theater chase mode activated\\\\n\\\\r&#034;);<\/p>\n<p>                    } else {<br \/>\n                        \/\/ \u672a\u77e5\u6a21\u5f0f&#xff0c;\u9ed8\u8ba4\u4f7f\u7528\u9759\u6001\u989c\u8272<br \/>\n                        effect_mode &#061; MODE_STATIC_COLOR;<br \/>\n                        WS2812B_Color target_color &#061; {cmd_G, cmd_R, cmd_B};<\/p>\n<p>                        for (uint16_t i &#061; 0; i &lt; current_led_count; i&#043;&#043;) {<br \/>\n                            ws2812b_set_led(i &#043; 1, target_color);<br \/>\n                        }<br \/>\n                        ws2812b_update();<\/p>\n<p>                        printf(&#034;Unknown mode %d, using static color\\\\n\\\\r&#034;, mode);<br \/>\n                    }<\/p>\n<p>                } else {<br \/>\n                    printf(&#034;Error: Invalid data header: %02X %02X %02X\\\\n\\\\r&#034;,<br \/>\n                           rxbuffer[0], rxbuffer[1], rxbuffer[2]);<br \/>\n                }<br \/>\n            } else {<br \/>\n                printf(&#034;Error: Received data too short: %d bytes (expected %d)\\\\n\\\\r&#034;,<br \/>\n                       rx_count, CMD_MIN_LENGTH);<br \/>\n            }<\/p>\n<p>            receive_flag &#061; 0;<br \/>\n        }<\/p>\n<p>        \/\/ \u5904\u7406\u7279\u6548\u6a21\u5f0f<br \/>\n        if (effect_mode !&#061; MODE_STATIC_COLOR) {<br \/>\n            process_effects();<br \/>\n            delay_1ms(effect_speed);<br \/>\n        } else {<br \/>\n            \/\/ \u9759\u6001\u6a21\u5f0f&#xff0c;\u5c0f\u5ef6\u65f6<br \/>\n            delay_1ms(10);<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n\/\/ \u4e32\u53e3\u8f93\u51fa\u91cd\u5b9a\u5411<br \/>\n\/\/ &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n#ifdef GD_ECLIPSE_GCC<br \/>\nint __io_putchar(int ch)<br \/>\n{<br \/>\n    usart_data_transmit(EVAL_COM0, (uint8_t)ch);<br \/>\n    while(RESET &#061;&#061; usart_flag_get(EVAL_COM0, USART_FLAG_TBE));<br \/>\n    return ch;<br \/>\n}<br \/>\n#else<br \/>\nint fputc(int ch, FILE *f)<br \/>\n{<br \/>\n    usart_data_transmit(EVAL_COM0, (uint8_t)ch);<br \/>\n    while(RESET &#061;&#061; usart_flag_get(EVAL_COM0, USART_FLAG_TBE));<br \/>\n    return ch;<br \/>\n}<br \/>\n#endif \/* GD_ECLIPSE_GCC *\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9047\u5230\u7684\u5927\u5751&#xff1a;<br \/>\n1.spi\u4e00\u5b9a\u8981\u9009&#xff1a;\u00a0\u8df3\u53d8\u6cbf\u9009\u7b2c\u4e8c\u4e2a&#xff08;2Edge&#xff09;\u6a21\u5f0f\u56e0\u4e3a\u8df3\u53d8\u6cbf\u4e3a 1 \u7684\u8bdd&#xff0c;MOSI \u7684\u7a7a\u95f2\u7535\u5e73\u4e3a\u9ad8\u7535\u5e73&#xff0c;\u4e3a 2 \u7684\u8bdd\u5219\u4f1a\u5ef6\u7eed\u4e0a\u6b21\u53d1\u9001\u7684\u6700\u540e\u7535\u5e73&#xff0c;\u6211\u4eec\u53d1\u9001\u6570\u636e\u7684\u672b\u5c3e\u90fd\u662f\u4f4e\u7535\u5e73&#xff0c;\u8fd9\u6837 WS2812 \u4e0d\u4f1a\u8bef\u52242.\u5176\u5b9e\u4f60\u7684\u9a71\u52a8\u6ce2\u5f62\u6839\u672c\u4e0d\u9700\u8981\u90a3\u4e48\u4e25\u683c&#xff0c;\u624b\u518c\u89c4\u5b9a\u7684\u65f6\u95f4\u4ee5\u5916\u8fd8\u6709\u4f59\u91cf&#xff0c;\u6211\u5c31\u662f\u672c\u6765\u8981\u6c42560ns-1us\u6211\u5c31\u5230\u00b71us\u4f46\u662f\u989c<\/p>\n","protected":false},"author":2,"featured_media":70026,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[269],"topic":[],"class_list":["post-70030","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-269"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SPI \u9a71\u52a8 WS2812 GD32\u65b9\u6848 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/70030.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SPI \u9a71\u52a8 WS2812 GD32\u65b9\u6848 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u9047\u5230\u7684\u5927\u5751&#xff1a; 1.spi\u4e00\u5b9a\u8981\u9009&#xff1a;\u00a0\u8df3\u53d8\u6cbf\u9009\u7b2c\u4e8c\u4e2a&#xff08;2Edge&#xff09;\u6a21\u5f0f\u56e0\u4e3a\u8df3\u53d8\u6cbf\u4e3a 1 \u7684\u8bdd&#xff0c;MOSI \u7684\u7a7a\u95f2\u7535\u5e73\u4e3a\u9ad8\u7535\u5e73&#xff0c;\u4e3a 2 \u7684\u8bdd\u5219\u4f1a\u5ef6\u7eed\u4e0a\u6b21\u53d1\u9001\u7684\u6700\u540e\u7535\u5e73&#xff0c;\u6211\u4eec\u53d1\u9001\u6570\u636e\u7684\u672b\u5c3e\u90fd\u662f\u4f4e\u7535\u5e73&#xff0c;\u8fd9\u6837 WS2812 \u4e0d\u4f1a\u8bef\u52242.\u5176\u5b9e\u4f60\u7684\u9a71\u52a8\u6ce2\u5f62\u6839\u672c\u4e0d\u9700\u8981\u90a3\u4e48\u4e25\u683c&#xff0c;\u624b\u518c\u89c4\u5b9a\u7684\u65f6\u95f4\u4ee5\u5916\u8fd8\u6709\u4f59\u91cf&#xff0c;\u6211\u5c31\u662f\u672c\u6765\u8981\u6c42560ns-1us\u6211\u5c31\u5230\u00b71us\u4f46\u662f\u989c\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/70030.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-01T05:49:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201054936-697ee97037d25.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/70030.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/70030.html\",\"name\":\"SPI \u9a71\u52a8 WS2812 GD32\u65b9\u6848 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-01T05:49:37+00:00\",\"dateModified\":\"2026-02-01T05:49:37+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/70030.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/70030.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/70030.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SPI \u9a71\u52a8 WS2812 GD32\u65b9\u6848\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SPI \u9a71\u52a8 WS2812 GD32\u65b9\u6848 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/70030.html","og_locale":"zh_CN","og_type":"article","og_title":"SPI \u9a71\u52a8 WS2812 GD32\u65b9\u6848 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u9047\u5230\u7684\u5927\u5751&#xff1a; 1.spi\u4e00\u5b9a\u8981\u9009&#xff1a;\u00a0\u8df3\u53d8\u6cbf\u9009\u7b2c\u4e8c\u4e2a&#xff08;2Edge&#xff09;\u6a21\u5f0f\u56e0\u4e3a\u8df3\u53d8\u6cbf\u4e3a 1 \u7684\u8bdd&#xff0c;MOSI \u7684\u7a7a\u95f2\u7535\u5e73\u4e3a\u9ad8\u7535\u5e73&#xff0c;\u4e3a 2 \u7684\u8bdd\u5219\u4f1a\u5ef6\u7eed\u4e0a\u6b21\u53d1\u9001\u7684\u6700\u540e\u7535\u5e73&#xff0c;\u6211\u4eec\u53d1\u9001\u6570\u636e\u7684\u672b\u5c3e\u90fd\u662f\u4f4e\u7535\u5e73&#xff0c;\u8fd9\u6837 WS2812 \u4e0d\u4f1a\u8bef\u52242.\u5176\u5b9e\u4f60\u7684\u9a71\u52a8\u6ce2\u5f62\u6839\u672c\u4e0d\u9700\u8981\u90a3\u4e48\u4e25\u683c&#xff0c;\u624b\u518c\u89c4\u5b9a\u7684\u65f6\u95f4\u4ee5\u5916\u8fd8\u6709\u4f59\u91cf&#xff0c;\u6211\u5c31\u662f\u672c\u6765\u8981\u6c42560ns-1us\u6211\u5c31\u5230\u00b71us\u4f46\u662f\u989c","og_url":"https:\/\/www.wsisp.com\/helps\/70030.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-01T05:49:37+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260201054936-697ee97037d25.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"13 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/70030.html","url":"https:\/\/www.wsisp.com\/helps\/70030.html","name":"SPI \u9a71\u52a8 WS2812 GD32\u65b9\u6848 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-01T05:49:37+00:00","dateModified":"2026-02-01T05:49:37+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/70030.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/70030.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/70030.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"SPI \u9a71\u52a8 WS2812 GD32\u65b9\u6848"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/70030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=70030"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/70030\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/70026"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=70030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=70030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=70030"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=70030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}