1 Star 2 Fork 0

Pinno/drv_ws2812b

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
drv_ws2812b.h 2.53 KB
一键复制 编辑 原始数据 按行查看 历史
#ifndef __WS2812B_H__
#define __WS2812B_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**************************************************************
*
* @brief 驱动WS2812B的方式
*
* ************************************************************/
#define WS2812B_DRV_MODE_SPI 0
#define WS2812B_DRV_MODE_RMT 1
#define WS2812B_DRV_MODE_PWM 2
#define WS2812B_DRV_MODE WS2812B_DRV_MODE_RMT
#define WS2812B_PIXEL_NUM 1
#define WS2812B_GRB 24
#define WS2812B_BREATHING_RATIO 4
#define WS2812B_BREATHING_LEVEL (510*WS2812B_BREATHING_RATIO)
/**************************************************************
*
* @brief spi驱动WS2812B
*
* ************************************************************/
#if (WS2812B_DRV_MODE == WS2812B_DRV_MODE_SPI)
#define WS2812B_SPI_HOST SPI3_HOST
#define WS2812B_SPI_DMA_CHANNEL 3
#define WS2812B_SPI_MOSI_PIN 14
#define WS2812B_SPI_TH 0xF8 //11111000
#define WS2812B_SPI_TL 0XE0 //11100000
#define WS2812B_SPI_RST 0X00 //00000000
void ws2812b_spi_init(uint32_t pin_mosi, uint32_t dma_ch);
/**************************************************************
*
* @brief RMT驱动WS2812B
*
* ************************************************************/
#elif (WS2812B_DRV_MODE == WS2812B_DRV_MODE_RMT)
#include "driver/rmt.h"
#define WS2812B_RMT_CHANNEL RMT_CHANNEL_0
#define WS2812B_RMT_PIN 14
#define WS2812B_RMT_CLK_DIV 2 /*!< RMT counter clock divider */
//#define RMT_TICK_1_NS (1/(80000000/RMT_CLK_DIV)) /*!< RMT counter value for 10 us.(Source clock is APB clock) */
// APB_CLK 80MHz, clock_cycle = 1/80/RMT_CLK_DIV = 25ns
#define WS2812B_RMT_T0H 14 // 0 bit high
#define WS2812B_RMT_T1H 28 // 1 bit high time
#define WS2812B_RMT_T0L 32 // low time for either bit
#define WS2812B_RMT_T1L 24 // low time for either bit
void ws2812b_rmt_init(uint32_t pin_rmt, uint32_t rmt_ch);
#elif (WS2812B_DRV_MODE == WS2812B_DRV_MODE_PWM)
#endif
/**************************************************************
*
* @brief WS2812B api
*
* ************************************************************/
void ws2812b_set_breathing0(uint32_t rgb, uint8_t wait);
void ws2812b_set_breathing1(uint32_t rgb);
void ws2812b_rainbow(uint8_t wait);
void ws2812b_set_pixel_rgb(uint32_t n, uint32_t rgb);
void ws2812b_set_pixel_grb(uint32_t n, uint32_t grb);
void ws2812b_fill_color(uint32_t rgb);
void ws2812b_close_all(void);
#ifdef __cplusplus
}
#endif
#endif //end of file
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pinno/drv_ws2812b.git
git@gitee.com:pinno/drv_ws2812b.git
pinno
drv_ws2812b
drv_ws2812b
master

搜索帮助