RogiStandard-hal
STM32 向けサークル共通ライブラリ
読み取り中…
検索中…
一致する文字列を見つけられません
WS2815B.hpp
[詳解]
1#pragma once
2
3#include "main.h"
4#ifndef HAL_TIM_MODULE_ENABLED
5#error "NeoPixel には TIM が必要です。CubeMX で TIM を有効にしてコードを再生成してください。"
6#endif
7#ifndef HAL_DMA_MODULE_ENABLED
8#error "NeoPixel には DMA が必要です。CubeMX で DMA を有効にしてコードを再生成してください。"
9#endif
10#include <stdint.h>
11
12class WS2815B {
13private:
14#define RST 250
15#define LED_NUM 50 // LEDの数
16#define HIGH 67
17#define LOW 34
18 uint32_t TIM_CHANNEL_X;
19 TIM_HandleTypeDef *HTIM;
20 uint8_t rgb_buf[LED_NUM][3];
21 uint16_t pwm_buf[RST + ((LED_NUM + 1) * 24)];
22 bool dma_busy = false;
23 // smooth_color_transitionのステートマシン用
24 bool anim_playing; // アニメーション再生中フラグ
25 int anim_k; // 外側ループカウンタ (0〜11)
26 int anim_i; // 内側ループカウンタ (0〜NUM_LEDS)
27 uint32_t anim_last_tick; // 最後に更新したHAL_GetTick()値
28
29public:
30 WS2815B(TIM_HandleTypeDef *htim, uint32_t tim_channel_x);
32 void set_rgb(uint16_t PIXEL_NUM, uint8_t red, uint8_t green, uint8_t blue);
33 void show();
34 void init();
35 void execute();
36 void clear();
37 void hsv_to_rgb(float h, float s, float v, int *r, int *g, int *b);
38 // ブロッキング処理を含むため、smooth_color_transition(); は非推奨。
40
41 void start_fanfare(); // アニメーション開始
42 bool update_fanfare(); // loop()から呼ぶ:trueを返したら完了
43 bool is_fanfare_playing() const { return anim_playing; }
44 void stop_fanfare();
45
47};
#define LED_NUM
Definition WS2815B.hpp:15
#define RST
Definition WS2815B.hpp:14
bool is_fanfare_playing() const
Definition WS2815B.hpp:43
void smooth_color_transition()
Definition WS2815B.cpp:114
void hsv_to_rgb(float h, float s, float v, int *r, int *g, int *b)
Definition WS2815B.cpp:79
void show()
Definition WS2815B.cpp:23
void start_fanfare()
Definition WS2815B.cpp:145
void clear()
Definition WS2815B.cpp:69
void dma_complete_callback()
Definition WS2815B.cpp:194
void execute()
Definition WS2815B.cpp:25
uint8_t pwm_buf_status
Definition WS2815B.hpp:31
bool update_fanfare()
Definition WS2815B.cpp:153
void init()
Definition WS2815B.cpp:55
void set_rgb(uint16_t PIXEL_NUM, uint8_t red, uint8_t green, uint8_t blue)
Definition WS2815B.cpp:14
void stop_fanfare()
Definition WS2815B.cpp:192