diff --git a/README.md b/README.md
index 8f70d75..37aeefc 100644
--- a/README.md
+++ b/README.md
@@ -1,58 +1,75 @@
# RGB灯条驱动库
-
+
## 简介
`lib_rgb` 是一个用于控制RGB灯条的C语言库,提供了一系列功能,比如颜色渐变、呼吸灯效果和色调循环等。它支持通过RGB和HSV颜色空间来控制灯条的颜色输出。
## 功能
-- **颜色渐变**:通过逐步调整RGB值来模拟呼吸灯效果。
-- **色调循环**:在HSV颜色空间中循环改变色调以实现颜色渐变。
+### 组件
-- **颜色转换**:将HSV颜色值转换为RGB颜色值。
+| 功能 | 示例 | 备注 |
+| ------------ | ------------------------------------ | ------------------------------------------------------------ |
+| **颜色渐变** | `app_rgb_cycle_breathing_example` | 通过逐步调整RGB值来模拟呼吸灯效果。 |
+| **色调循环** | `app_hsv_cycle_example` | 在HSV颜色空间中循环改变色调以实现颜色渐变。 |
+| **颜色转换** | `app_test_HSV_to_RGB` | 将HSV颜色值转换为RGB颜色值。 |
+| **颜色填充** | `app_test_fill_gradient_with_groups` | 将单一颜色填充到整个RGB条中,也可以将RGB条分组,同时输出不同的颜色或响应。 |
+| **幻彩渐变** | `app_hsv_cycle_per_rgb_example` | 每个灯珠独立的HSV渐变,以获得颜色流动的效果。 |
-- **颜色填充**:将单一颜色填充到整个RGB条中,也可以将RGB条分组,同时输出不同的颜色或响应
+### 高级应用
-- **音量响应**:根据响度值(-xdB~0dB),获取音量等级,以实现响度可视化
-
-- **RGB灯条驱动**:启动一个永久循环,持续更新RGB灯条的颜色。
-
-- **HSV颜色循环驱动**:驱动HSV颜色空间中的颜色循环,以实现连续的颜色渐变效果。
-
-
+| 功能 | 示例 | 备注 |
+| -------------------------- | --------------------------------------- | ----------------------------------------------------- |
+| **响度可视化** | 待补充 | 通过检测音频样本中的响度,实现RGB跟随音量大小跳动 |
+| **色调循环&音量响应** | `app_cycleHSV_vol_level_example` | 根据响度值(-xdB~0dB),获取音量等级。 |
+| **平滑&音量响应** | `app_vol_level_smooth_example` | 一种过渡效果,当响度下降时,逐级熄灭RGB,而不是突变。 |
+| **平滑&色调循环&音量响应** | `app_cycleHSV_vol_level_smooth_example` | 结合了HSV颜色渐变,平滑过渡,以及音量响应 |
## 使用方法
### 包含头文件
-在你的项目中包含`rgb_effect.h`文件。
+
+在你的项目中包含`rgb_effect.h`文件,它是较高等级的灯效头文件,用于实现各种灯效,以及向RGB输出灯效
```c
#include "rgb_effect.h"
```
+或者直接包含`visualize_volume.h`,它是最高等级的应用头文件,用于实现可视化的响度。你需要为它创建一个线程,并向它的缓存中写入音频样本,以驱动RGB。
+
+```c
+#include "visualize_volume.h"
+```
+
+//TODO: 后续我们会创建一个例程,帮助你快速构建一个线程安全的应用。
+
### 快速开始
-如果你想要一个开箱即用的持续的颜色渐变效果,可以使用`cycleRGB_driver`或`cycleHSV_driver`函数。
+如果你想要尝试开箱即用的持续的颜色渐变效果,可以使用`examples/app_hsv_cycle_example/src/hsv_cycle_example.c`中的`hsv_cycle_example`函数,具体的用法可以参考该示例。
注意:当前用于驱动LED组的默认的IO,定义在`Tile[1]`的`4A3`端口上,因此你需要添加对tile的声明。
```c
-par
-{
- // 启动RGB颜色渐变驱动
- on tile[1]: cycleRGB_driver();
-}
-```
+#include // 包含对封装的定义,引用以使用 on tile[] 语法
-或者:
-
-```c
-par
+extern "C"
{
- // 启动HSV颜色循环驱动
- on tile[1]: cycleHSV_driver();
+ void hsv_cycle_example();
}
+
+int main() // 定义主函数
+{
+ par
+ {
+ on tile[1]:
+ {
+ hsv_cycle_example();
+ }
+ }
+ return 0; // 返回0,表示程序正常结束
+}
+
```
### 初始化颜色和方向
@@ -93,17 +110,16 @@ output_rgb_array(rgb_array, 3);
## 路线图
-- [ ] 当RGB_MAX等值超限时,raise error
-- [ ] 为绘制RGB的函数添加可合并选项,以减少资源占用
-- [ ] 添加更多应用光效
+- [x] 为绘制RGB的函数添加可合并选项,以减少资源占用
+- [x] 添加更多应用光效
- [x] RGB渐变
- [x] HSV渐变
- - [ ] 每个灯珠独立的HSV渐变
-
+ - [x] 每个灯珠独立的HSV渐变
- [x] 音频响度响应
- [ ] 使用fp/s32以增加`HSV_to_RGB`的计算效率
+- [ ] 提供音频响度响应的例程与说明
## 贡献
-如果你有任何改进意见或者发现了bug,请通过issues或pull requests来提交。
+如果你有任何改进意见或者发现了bug,请通过issues或pull requests来提交或贡献。
感谢使用`lib_rgb`!
\ No newline at end of file
diff --git a/examples/Makefile b/examples/Makefile
index b37c7ed..585c6d5 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -1,10 +1,7 @@
# This variable should contain a space separated list of all
# the directories containing buildable applications (usually
# prefixed with the app_ prefix)
-BUILD_SUBDIRS = ./app_rgb_cycle_breathing_example \
- ./app_hsv_cycle_example \
- ./app_test_cycleHSV_with_vol_level_example \
- ./app_test_fill_gradient_with_groups \
+BUILD_SUBDIRS := $(wildcard ./app_*)
# This variable should contain a space separated list of all
# the directories containing buildable plugins (usually
diff --git a/examples/app_test_cycleHSV_with_vol_level_example/Makefile b/examples/app_cycleHSV_vol_level_example/Makefile
similarity index 93%
rename from examples/app_test_cycleHSV_with_vol_level_example/Makefile
rename to examples/app_cycleHSV_vol_level_example/Makefile
index 2b38775..9c186d4 100644
--- a/examples/app_test_cycleHSV_with_vol_level_example/Makefile
+++ b/examples/app_cycleHSV_vol_level_example/Makefile
@@ -8,7 +8,7 @@ TARGET = XCORE-AI-EXPLORER
# report: 打开编译报告
# g: 生成调试信息
# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink)
-BUILD_FLAGS = -O2 -g -DDEBUG_PRINT_ENABLE=1 -report -fxscope
+BUILD_FLAGS = -O2 -g -report -fxscope
USED_MODULES = lib_rgb
diff --git a/examples/app_test_cycleHSV_with_vol_level_example/src/test_cycleHSV_with_vol_level_example.c b/examples/app_cycleHSV_vol_level_example/src/cycleHSV_vol_level_example.c
similarity index 96%
rename from examples/app_test_cycleHSV_with_vol_level_example/src/test_cycleHSV_with_vol_level_example.c
rename to examples/app_cycleHSV_vol_level_example/src/cycleHSV_vol_level_example.c
index 269c211..dea75ac 100644
--- a/examples/app_test_cycleHSV_with_vol_level_example/src/test_cycleHSV_with_vol_level_example.c
+++ b/examples/app_cycleHSV_vol_level_example/src/cycleHSV_vol_level_example.c
@@ -4,7 +4,7 @@
#include "samples_to_levels.h"
#include "rgb_effect.h"
#include "timer.h"
-void test_cycleHSV_with_vol_level_example()
+void cycleHSV_vol_level_example()
{
uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区,大小由NUM_RGBS宏确定
uint32_t current_hue = 0; // 从红色开始的当前色相值
diff --git a/examples/app_test_cycleHSV_with_vol_level_example/src/main.xc b/examples/app_cycleHSV_vol_level_example/src/main.xc
similarity index 88%
rename from examples/app_test_cycleHSV_with_vol_level_example/src/main.xc
rename to examples/app_cycleHSV_vol_level_example/src/main.xc
index d29ec3a..9e43de8 100644
--- a/examples/app_test_cycleHSV_with_vol_level_example/src/main.xc
+++ b/examples/app_cycleHSV_vol_level_example/src/main.xc
@@ -13,7 +13,7 @@
#include // 包含对封装的定义,引用以使用 on tile[] 语法
extern "C"{
- void test_cycleHSV_with_vol_level_example();
+ void cycleHSV_vol_level_example();
}
int main() // 定义主函数
@@ -22,7 +22,7 @@ int main() // 定义主函数
{
on tile[1]:
{
- test_cycleHSV_with_vol_level_example();
+ cycleHSV_vol_level_example();
}
}
return 0; // 返回0,表示程序正常结束
diff --git a/examples/app_cycleHSV_vol_level_smooth_example/Makefile b/examples/app_cycleHSV_vol_level_smooth_example/Makefile
new file mode 100644
index 0000000..9c186d4
--- /dev/null
+++ b/examples/app_cycleHSV_vol_level_smooth_example/Makefile
@@ -0,0 +1,24 @@
+# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。
+
+TARGET = XCORE-AI-EXPLORER
+
+# 编译选项
+# 构建应用程序时传递给 xcc 的参数
+# O2: xcc编译器优化等级2
+# report: 打开编译报告
+# g: 生成调试信息
+# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink)
+BUILD_FLAGS = -O2 -g -report -fxscope
+
+USED_MODULES = lib_rgb
+
+XCC_FLAGS = $(BUILD_FLAGS)
+
+XMOS_MODULE_PATH = ../../..
+XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1
+
+#=============================================================================
+# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。
+
+XMOS_MAKE_PATH ?= ../..
+include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
\ No newline at end of file
diff --git a/examples/app_cycleHSV_vol_level_smooth_example/src/cycleHSV_vol_level_smooth_example.c b/examples/app_cycleHSV_vol_level_smooth_example/src/cycleHSV_vol_level_smooth_example.c
new file mode 100644
index 0000000..a0fdbe7
--- /dev/null
+++ b/examples/app_cycleHSV_vol_level_smooth_example/src/cycleHSV_vol_level_smooth_example.c
@@ -0,0 +1,56 @@
+#include
+#include
+#include // 包含基本的输入输出函数
+#include "rgb_effect.h"
+#include "timer.h"
+#define DELAY_DECREASE 40 // 降低亮度时的额外延迟
+
+// 该函数用于平滑过渡HSV颜色和音量级别
+void cycleHSV_vol_level_smooth_example()
+{
+ uint32_t buf[NUM_RGBS]; // 存储RGB值的缓冲区
+ uint32_t current_hue = 0; // 当前色调
+ uint32_t current_color[NUM_RGB_GROUPS] = {0x000000, 0x000000}; // 当前颜色数组
+ size_t random_levels[NUM_RGB_GROUPS]; // 随机音量级别数组
+ size_t previous_levels[NUM_RGB_GROUPS] = {0}; // 存储先前的音量级别
+
+ srand(1); // 设置随机数种子
+
+ while (1) // 无限循环
+ {
+ for (size_t i = 0; i < NUM_RGB_GROUPS; i++) // 遍历RGB组
+ {
+ // 获取新的随机音量级别
+ random_levels[i] = get_volume_level(rand() % 101 - 100);
+ // 如果新的级别低于之前的级别,逐渐降低
+ while (previous_levels[i] > random_levels[i])
+ {
+ previous_levels[i]--; // 降低当前级别
+ // 用当前颜色和级别填充渐变
+ fill_gradient_with_groups(buf, current_color, previous_levels);
+ delay_milliseconds(DELAY_DECREASE); // 延迟
+ // 更新每一步的RGB颜色
+ for (size_t j = 0; j < NUM_RGB_GROUPS; j++)
+ {
+ current_color[j] = cycleHSV(¤t_hue);
+ }
+ }
+ }
+
+ // 用随机颜色和级别填充渐变
+ fill_gradient_with_groups(buf, current_color, random_levels);
+ delay_milliseconds(DELAY_TIME_RGB); // 延迟
+
+ // 更新当前颜色
+ for (size_t i = 0; i < NUM_RGB_GROUPS; i++)
+ {
+ current_color[i] = cycleHSV(¤t_hue);
+ }
+
+ // 更新先前的音量级别
+ for (size_t i = 0; i < NUM_RGB_GROUPS; i++)
+ {
+ previous_levels[i] = random_levels[i];
+ }
+ }
+}
diff --git a/examples/app_cycleHSV_vol_level_smooth_example/src/main.xc b/examples/app_cycleHSV_vol_level_smooth_example/src/main.xc
new file mode 100644
index 0000000..155ed3a
--- /dev/null
+++ b/examples/app_cycleHSV_vol_level_smooth_example/src/main.xc
@@ -0,0 +1,24 @@
+/** @brief 平滑过渡&HSV循环&模拟音量响应
+ * @author Vergil Wong
+ * @date 2023-11-25
+ * @param
+ * @return
+ */
+
+#include // 包含对封装的定义,引用以使用 on tile[] 语法
+
+extern "C"{
+ void cycleHSV_vol_level_smooth_example();
+}
+
+int main() // 定义主函数
+{
+ par
+ {
+ on tile[1]:
+ {
+ cycleHSV_vol_level_smooth_example();
+ }
+ }
+ return 0; // 返回0,表示程序正常结束
+}
diff --git a/examples/app_hsv_cycle_example/Makefile b/examples/app_hsv_cycle_example/Makefile
index cd4d4c4..7d58c58 100644
--- a/examples/app_hsv_cycle_example/Makefile
+++ b/examples/app_hsv_cycle_example/Makefile
@@ -8,7 +8,7 @@ TARGET = XCORE-AI-EXPLORER
# report: 打开编译报告
# g: 生成调试信息
# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink)
-BUILD_FLAGS = -O2 -g -DDEBUG_PRINT_ENABLE=1 -report -fxscope
+BUILD_FLAGS = -O2 -g -report -fxscope
USED_MODULES = lib_rgb lib_xcore_math
diff --git a/examples/app_hsv_cycle_example/src/hsv_cycle_example.c b/examples/app_hsv_cycle_example/src/hsv_cycle_example.c
index 6479eb6..a9cb75b 100644
--- a/examples/app_hsv_cycle_example/src/hsv_cycle_example.c
+++ b/examples/app_hsv_cycle_example/src/hsv_cycle_example.c
@@ -12,7 +12,7 @@ void hsv_cycle_example()
while (1)
{
// 用当前渐变颜色填充RGB数组,然后发送给rgb阵列
- fill_gradient(buf, NUM_RGBS, current_color);
+ fill_gradient(buf, current_color, NUM_RGBS);
// 延迟以控制显示持续时间
delay_milliseconds(DELAY_TIME_RGB);
diff --git a/examples/app_hsv_cycle_per_rgb_example/Makefile b/examples/app_hsv_cycle_per_rgb_example/Makefile
new file mode 100644
index 0000000..87cb5a7
--- /dev/null
+++ b/examples/app_hsv_cycle_per_rgb_example/Makefile
@@ -0,0 +1,24 @@
+# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。
+
+TARGET = XCORE-AI-EXPLORER
+
+# 编译选项
+# 构建应用程序时传递给 xcc 的参数
+# O2: xcc编译器优化等级2
+# report: 打开编译报告
+# g: 生成调试信息
+# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink)
+BUILD_FLAGS = -O2 -g -report -fxscope -D_XUA_CONF_H_EXISTS_
+
+USED_MODULES = lib_rgb lib_xcore_math
+
+XCC_FLAGS = $(BUILD_FLAGS)
+
+XMOS_MODULE_PATH = ../../..
+XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1
+
+#=============================================================================
+# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。
+
+XMOS_MAKE_PATH ?= ../..
+include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
\ No newline at end of file
diff --git a/examples/app_hsv_cycle_per_rgb_example/src/core/xua_conf.h b/examples/app_hsv_cycle_per_rgb_example/src/core/xua_conf.h
new file mode 100644
index 0000000..9cc6aae
--- /dev/null
+++ b/examples/app_hsv_cycle_per_rgb_example/src/core/xua_conf.h
@@ -0,0 +1,26 @@
+/**
+ * @file xua_conf.h
+ * @brief Defines relating to device configuration and customisation.
+ * For PXUA-XU316-MC-MAX
+ */
+#ifndef _XUA_CONF_H_
+#define _XUA_CONF_H_
+
+/* Defines relating to feature placement regarding tiles */
+#ifndef RGB_TILE
+#define RGB_TILE (1)
+#endif
+
+#ifndef DELAY_TIME_RGB
+#define DELAY_TIME_RGB (60)
+#endif
+
+#ifndef RGB_MAX
+#define RGB_MAX (20)
+#endif
+
+#ifndef HUE_STEP
+#define HUE_STEP (10)
+#endif
+
+#endif
diff --git a/examples/app_hsv_cycle_per_rgb_example/src/hsv_cycle_per_rgb_example.c b/examples/app_hsv_cycle_per_rgb_example/src/hsv_cycle_per_rgb_example.c
new file mode 100644
index 0000000..33d9bc3
--- /dev/null
+++ b/examples/app_hsv_cycle_per_rgb_example/src/hsv_cycle_per_rgb_example.c
@@ -0,0 +1,45 @@
+#include
+#include
+#include // 包含基本的输入输出函数
+#include "rgb_effect.h"
+#include "timer.h"
+#include "xmath/xmath.h"
+#include
+
+void init_colors(uint32_t *current_colors, uint32_t *previous_colors, uint32_t current_hue){
+ for (size_t i = 0; i < NUM_RGBS; i++)
+ {
+ *(current_colors + i) = cycleHSV(¤t_hue);
+ }
+ // TODO: 当使用xs3_memcpy时,复制的后几个数据看起来是随机的
+ memcpy(previous_colors, current_colors, NUM_RGBS * sizeof(uint32_t));
+}
+
+void hsv_cycle_per_rgb_example()
+{
+ uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区,大小由NUM_RGBS宏确定
+ uint32_t current_hue = 0; // 从红色开始的当前色相值
+ uint32_t WORD_ALIGNED current_colors[NUM_RGBS]; //用于存储当前颜色值的数组。
+ uint32_t WORD_ALIGNED previous_colors[NUM_RGBS];//用于存储上一组颜色值的数组
+ size_t levels[NUM_RGB_GROUPS]; //指定每个RGB组亮灯的个数
+ init_colors(current_colors, previous_colors, current_hue); //初始化颜色
+ while (1)
+ {
+
+ for (size_t i = 0; i < NUM_RGB_GROUPS; i++)
+ {
+ *(levels + i) = (NUM_RGBS / NUM_RGB_GROUPS)-1;
+ }
+ // 用当前渐变颜色填充RGB数组,然后发送给rgb阵列
+ fill_gradient_with_groups_colorful(buf, current_colors, levels);
+
+ // 延迟以控制显示持续时间
+ delay_milliseconds(DELAY_TIME_RGB);
+ // 更改下一组颜色,其中每个灯继承上一个灯的颜色,第一个灯通过cycleHSV计算出新的颜色
+ memcpy(current_colors+1, previous_colors, (NUM_RGBS-1) * sizeof(uint32_t));
+ current_colors[0] = cycleHSV(¤t_hue);
+
+ // 保留本轮颜色的记录
+ memcpy(previous_colors, current_colors, NUM_RGBS * sizeof(uint32_t));
+ }
+}
\ No newline at end of file
diff --git a/examples/app_hsv_cycle_per_rgb_example/src/main.xc b/examples/app_hsv_cycle_per_rgb_example/src/main.xc
new file mode 100644
index 0000000..ce6eabb
--- /dev/null
+++ b/examples/app_hsv_cycle_per_rgb_example/src/main.xc
@@ -0,0 +1,32 @@
+/** @brief RGB灯条HSV循环渐变
+ *
+ * 此函数使用初始色相值初始化两个颜色数组current_colors和preview_colors。
+ * 它通过调用'cycleHSV'函数为每个颜色位置生成一个基于当前色相的颜色值。
+ * 然后,它在一个无限循环中,使用'fill_gradient_with_groups_colorful'函数
+ * 将颜色渐变填充到一个RGB缓冲区,并通过'output_rgb_array'函数输出。
+ * 在每次循环的末尾,颜色数组会更新,为下一次迭代准备新的颜色。
+ *
+ * @author Vergil Wong
+ * @date 2023-11-26
+ * @param
+ * @return
+ */
+
+#include // 包含对封装的定义,引用以使用 on tile[] 语法
+
+extern "C"
+{
+ void hsv_cycle_per_rgb_example();
+}
+
+int main() // 定义主函数
+{
+ par
+ {
+ on tile[1]:
+ {
+ hsv_cycle_per_rgb_example();
+ }
+ }
+ return 0; // 返回0,表示程序正常结束
+}
diff --git a/examples/app_rgb_cycle_breathing_example/Makefile b/examples/app_rgb_cycle_breathing_example/Makefile
index 1760f2e..514af0b 100644
--- a/examples/app_rgb_cycle_breathing_example/Makefile
+++ b/examples/app_rgb_cycle_breathing_example/Makefile
@@ -8,7 +8,7 @@ TARGET = XCORE-AI-EXPLORER
# report: 打开编译报告
# g: 生成调试信息
# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink)
-BUILD_FLAGS = -O2 -g -DDEBUG_PRINT_ENABLE=1 -report -fxscope
+BUILD_FLAGS = -O2 -g -report -fxscope
USED_MODULES = lib_rgb
diff --git a/examples/app_rgb_cycle_breathing_example/src/rgb_cycle_breathing_example.c b/examples/app_rgb_cycle_breathing_example/src/rgb_cycle_breathing_example.c
index 8d445b1..be1de2c 100644
--- a/examples/app_rgb_cycle_breathing_example/src/rgb_cycle_breathing_example.c
+++ b/examples/app_rgb_cycle_breathing_example/src/rgb_cycle_breathing_example.c
@@ -11,7 +11,7 @@ void rgb_cycle_breathing_example()
while (1)
{
// 用当前渐变颜色填充RGB数组
- fill_gradient(buf, NUM_RGBS, current_color);
+ fill_gradient(buf, current_color, NUM_RGBS);
// 延迟以控制显示持续时间
delay_milliseconds(DELAY_TIME_RGB);
// 更改下一个渐变的基色
diff --git a/examples/app_test_HSV_to_RGB/Makefile b/examples/app_test_HSV_to_RGB/Makefile
index 2b38775..9c186d4 100644
--- a/examples/app_test_HSV_to_RGB/Makefile
+++ b/examples/app_test_HSV_to_RGB/Makefile
@@ -8,7 +8,7 @@ TARGET = XCORE-AI-EXPLORER
# report: 打开编译报告
# g: 生成调试信息
# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink)
-BUILD_FLAGS = -O2 -g -DDEBUG_PRINT_ENABLE=1 -report -fxscope
+BUILD_FLAGS = -O2 -g -report -fxscope
USED_MODULES = lib_rgb
diff --git a/examples/app_test_HSV_to_RGB/src/test_hsv_to_rgb.c b/examples/app_test_HSV_to_RGB/src/test_hsv_to_rgb.c
index d997cac..e0d9349 100644
--- a/examples/app_test_HSV_to_RGB/src/test_hsv_to_rgb.c
+++ b/examples/app_test_HSV_to_RGB/src/test_hsv_to_rgb.c
@@ -1,4 +1,5 @@
#include
+#include
#include "rgb_effect.h"
void test_hsv_to_rgb()
{
@@ -12,5 +13,5 @@ void test_hsv_to_rgb()
color = HSV_to_RGB(&hue, &sat, &value);
- printf("GRB color is: 0x%06X\n", color);
+ printf("GRB color is: 0x%06lX\n", color);
}
\ No newline at end of file
diff --git a/examples/app_test_config_rgb_port/Makefile b/examples/app_test_config_rgb_port/Makefile
new file mode 100644
index 0000000..9ee29aa
--- /dev/null
+++ b/examples/app_test_config_rgb_port/Makefile
@@ -0,0 +1,25 @@
+# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。
+
+TARGET = PXUA-316-MC-MAX.xn
+
+# 编译选项
+# 构建应用程序时传递给 xcc 的参数
+# O2: xcc编译器优化等级2
+# report: 打开编译报告
+# g: 生成调试信息
+# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink)
+# _XUA_CONF_H_EXISTS_: 提示编译器,编译部分文件时包含xua_conf.h
+BUILD_FLAGS = -O2 -g -report -fxscope -D_XUA_CONF_H_EXISTS_
+
+USED_MODULES = lib_rgb
+
+XCC_FLAGS = $(BUILD_FLAGS)
+
+XMOS_MODULE_PATH = ../../..
+XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1
+
+#=============================================================================
+# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。
+
+XMOS_MAKE_PATH ?= ../..
+include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
\ No newline at end of file
diff --git a/examples/app_test_config_rgb_port/src/core/PXUA-316-MC-MAX.xn b/examples/app_test_config_rgb_port/src/core/PXUA-316-MC-MAX.xn
new file mode 100644
index 0000000..c7a918a
--- /dev/null
+++ b/examples/app_test_config_rgb_port/src/core/PXUA-316-MC-MAX.xn
@@ -0,0 +1,106 @@
+
+
+ Board
+ PXUA-316-MC-MAX
+
+ tileref tile[2]
+ tileref usb_tile
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/app_test_config_rgb_port/src/core/xua_conf.h b/examples/app_test_config_rgb_port/src/core/xua_conf.h
new file mode 100644
index 0000000..dd936e1
--- /dev/null
+++ b/examples/app_test_config_rgb_port/src/core/xua_conf.h
@@ -0,0 +1,14 @@
+/**
+ * @file xua_conf.h
+ * @brief Defines relating to device configuration and customisation.
+ * For PXUA-XU316-MC-MAX
+ */
+#ifndef _XUA_CONF_H_
+#define _XUA_CONF_H_
+
+/* Defines relating to feature placement regarding tiles */
+#ifndef RGB_TILE
+#define RGB_TILE (1)
+#endif
+
+#endif
diff --git a/examples/app_test_config_rgb_port/src/main.xc b/examples/app_test_config_rgb_port/src/main.xc
new file mode 100644
index 0000000..b4cc7e5
--- /dev/null
+++ b/examples/app_test_config_rgb_port/src/main.xc
@@ -0,0 +1,26 @@
+/** @brief 测试output_rgb_array
+ *
+ * @author Vergil Wong
+ * @date 2023-11-25
+ * @param
+ * @return
+ */
+
+#include // 包含对封装的定义,引用以使用 on tile[] 语法
+
+extern "C"
+{
+ void test_output_rgb_array_example();
+}
+
+int main() // 定义主函数
+{
+ par
+ {
+ on tile[1]:
+ {
+ test_output_rgb_array_example();
+ }
+ }
+ return 0; // 返回0,表示程序正常结束
+}
diff --git a/examples/app_test_config_rgb_port/src/test_config_rgb_port.c b/examples/app_test_config_rgb_port/src/test_config_rgb_port.c
new file mode 100644
index 0000000..e9f8c64
--- /dev/null
+++ b/examples/app_test_config_rgb_port/src/test_config_rgb_port.c
@@ -0,0 +1,16 @@
+#include
+#include
+#include "rgb_effect.h"
+void test_output_rgb_array_example()
+{
+ uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区,大小由NUM_RGBS宏确定
+ uint32_t num_rgbs = 12;
+
+ // Initialize the buffer with example RGB values
+ for (uint32_t i = 0; i < num_rgbs; ++i) {
+ buf[i] = (i << 16) | (i << 8) | i; // Just an example pattern for RGB values
+ }
+
+ // Call the function with the test buffer and number of RGBs
+ output_rgb_array(buf, num_rgbs);
+}
\ No newline at end of file
diff --git a/examples/app_test_fill_gradient_with_groups/Makefile b/examples/app_test_fill_gradient_with_groups/Makefile
index 2b38775..9c186d4 100644
--- a/examples/app_test_fill_gradient_with_groups/Makefile
+++ b/examples/app_test_fill_gradient_with_groups/Makefile
@@ -8,7 +8,7 @@ TARGET = XCORE-AI-EXPLORER
# report: 打开编译报告
# g: 生成调试信息
# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink)
-BUILD_FLAGS = -O2 -g -DDEBUG_PRINT_ENABLE=1 -report -fxscope
+BUILD_FLAGS = -O2 -g -report -fxscope
USED_MODULES = lib_rgb
diff --git a/examples/app_test_fill_gradient_with_groups/src/main.xc b/examples/app_test_fill_gradient_with_groups/src/main.xc
index d9d76bf..7312d9a 100644
--- a/examples/app_test_fill_gradient_with_groups/src/main.xc
+++ b/examples/app_test_fill_gradient_with_groups/src/main.xc
@@ -1,8 +1,6 @@
/** @brief 测试 fill_gradient_with_groups 函数
* 此测试函数创建一个缓冲区,并定义两种颜色和每组的填充数量,然后调用
- * fill_gradient_with_groups 函数来填充缓冲区。之后,它会验证缓冲区中的颜色
- * 是否符合预期:每组的前N个LED应该是指定的颜色,剩余的LED应该是关闭的(黑色)。
- * 如果所有LED的颜色都正确,测试通过;否则,输出错误信息并标记测试失败。
+ * fill_gradient_with_groups 函数来填充缓冲区,并渲染RGB。
* @author Vergil Wong
* @date 2023-11-25
* @param
diff --git a/examples/app_test_fill_gradient_with_groups/src/test_fill_gradient_with_groups.c b/examples/app_test_fill_gradient_with_groups/src/test_fill_gradient_with_groups.c
index 5e13859..506ec16 100644
--- a/examples/app_test_fill_gradient_with_groups/src/test_fill_gradient_with_groups.c
+++ b/examples/app_test_fill_gradient_with_groups/src/test_fill_gradient_with_groups.c
@@ -1,37 +1,14 @@
#include
#include // 包含基本的输入输出函数
#include // 包含对封装的定义,引用以使用 on tile[] 语法
-#include "samples_to_levels.h"
+
#include "rgb_effect.h"
#include "timer.h"
-
void test_fill_gradient_with_groups()
{
uint32_t buffer[NUM_RGBS];
- uint32_t colors[] = {0xFF0000, 0x00FF00}; // 红,绿
- size_t num_filled_rgb[] = {2, 3}; // 每组填充数量
- size_t num_groups = sizeof(colors) / sizeof(colors[0]);
- int success = 1; // 使用int代替bool,1代表true,0代表false
+ uint32_t colors[] = {0x110000, 0x001100, 0x000011}; // 红,绿,蓝
+ size_t num_filled_rgb[] = {4, 4, 4}; // 每组填充数量
fill_gradient_with_groups(buffer, colors, num_filled_rgb);
- // 延迟以控制显示持续时间
- delay_milliseconds(DELAY_TIME_RGB);
- // 验证
- for (size_t i = 0; i < NUM_RGBS; i++)
- {
- size_t group = i / (NUM_RGBS / num_groups);
- size_t group_led_start = group * (NUM_RGBS / num_groups);
- uint32_t expected_color = (i < group_led_start + num_filled_rgb[group]) ? colors[group] : 0x000000;
- if (buffer[i] != expected_color)
- {
- success = 0; // 设置为false
- printf("Test failed at LED %zu: expected 0x%06lX, got 0x%06lX\n", i, expected_color, buffer[i]);
- break;
- }
- }
-
- if (success)
- {
- printf("Test passed: All LEDs are correctly set.\n");
- }
}
\ No newline at end of file
diff --git a/examples/app_test_vol_to_level/Makefile b/examples/app_test_vol_to_level/Makefile
new file mode 100644
index 0000000..9c186d4
--- /dev/null
+++ b/examples/app_test_vol_to_level/Makefile
@@ -0,0 +1,24 @@
+# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。
+
+TARGET = XCORE-AI-EXPLORER
+
+# 编译选项
+# 构建应用程序时传递给 xcc 的参数
+# O2: xcc编译器优化等级2
+# report: 打开编译报告
+# g: 生成调试信息
+# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink)
+BUILD_FLAGS = -O2 -g -report -fxscope
+
+USED_MODULES = lib_rgb
+
+XCC_FLAGS = $(BUILD_FLAGS)
+
+XMOS_MODULE_PATH = ../../..
+XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1
+
+#=============================================================================
+# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。
+
+XMOS_MAKE_PATH ?= ../..
+include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
\ No newline at end of file
diff --git a/examples/app_test_vol_to_level/src/main.xc b/examples/app_test_vol_to_level/src/main.xc
new file mode 100644
index 0000000..424a75b
--- /dev/null
+++ b/examples/app_test_vol_to_level/src/main.xc
@@ -0,0 +1,22 @@
+/** @brief 测试不同的响度值转化为音量等级
+ * @author Vergil Wong
+ * @date 2023-11-25
+ * @param
+ * @return
+ */
+
+#include // 包含对封装的定义,引用以使用 on tile[] 语法
+
+extern "C"
+{
+ void test_vol_to_level();
+}
+
+int main() // 定义主函数
+{
+ par
+ {
+ on tile[1]: test_vol_to_level();
+ }
+ return 0; // 返回0,表示程序正常结束
+}
diff --git a/examples/app_test_vol_to_level/src/test_vol_to_level.c b/examples/app_test_vol_to_level/src/test_vol_to_level.c
new file mode 100644
index 0000000..8adc97c
--- /dev/null
+++ b/examples/app_test_vol_to_level/src/test_vol_to_level.c
@@ -0,0 +1,15 @@
+#include
+#include
+#include "rgb_effect.h"
+void test_vol_to_level()
+{
+ // 测试不同的响度值
+ uint32_t test_loudness_values[] = {1, 0, -2, -5, -8, -20, -30, -40, -60, -62, -70, };
+ int num_tests = sizeof(test_loudness_values) / sizeof(test_loudness_values[0]);
+
+ for (int i = 0; i < num_tests; ++i) {
+ printf("Loudness: %lu dB, Volume Level: %u\n",
+ test_loudness_values[i],
+ get_volume_level((int)test_loudness_values[i]));
+ }
+}
\ No newline at end of file
diff --git a/examples/app_vol_level_smooth_example/Makefile b/examples/app_vol_level_smooth_example/Makefile
new file mode 100644
index 0000000..9c186d4
--- /dev/null
+++ b/examples/app_vol_level_smooth_example/Makefile
@@ -0,0 +1,24 @@
+# `TARGET` 变量决定了应用程序编译的目标系统。它可以引用源目录中的一个 XN 文件,或者是在编译时作为 `--target` 选项的一个有效参数。
+
+TARGET = XCORE-AI-EXPLORER
+
+# 编译选项
+# 构建应用程序时传递给 xcc 的参数
+# O2: xcc编译器优化等级2
+# report: 打开编译报告
+# g: 生成调试信息
+# fxscope: 使用 xSCOPE,对代码进行跟踪(默认使用xlink)
+BUILD_FLAGS = -O2 -g -report -fxscope
+
+USED_MODULES = lib_rgb
+
+XCC_FLAGS = $(BUILD_FLAGS)
+
+XMOS_MODULE_PATH = ../../..
+XCOMMON_DISABLE_AUTO_MODULE_SEARCH = 1
+
+#=============================================================================
+# 下面部分的 Makefile 包含了用于编译 XMOS 应用程序的公共构建基础设施。你无需编辑此处以下的内容。
+
+XMOS_MAKE_PATH ?= ../..
+include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common
\ No newline at end of file
diff --git a/examples/app_vol_level_smooth_example/src/main.xc b/examples/app_vol_level_smooth_example/src/main.xc
new file mode 100644
index 0000000..07e63b7
--- /dev/null
+++ b/examples/app_vol_level_smooth_example/src/main.xc
@@ -0,0 +1,28 @@
+/** @brief 音量响应&平滑过渡
+ *
+ * 每个颜色组都会根据音量水平的随机值来更新其亮度。每次循环后,将当前颜色
+ * 应用到RGB条的相应组中。此函数旨在模拟实时音乐响应的灯光效果,并实现平滑过渡下降
+ * 与app_cy
+ * @author Vergil Wong
+ * @date 2023-11-25
+ * @param
+ * @return
+ */
+
+#include // 包含对封装的定义,引用以使用 on tile[] 语法
+
+extern "C"{
+ void vol_level_smooth_example();
+}
+
+int main() // 定义主函数
+{
+ par
+ {
+ on tile[1]:
+ {
+ vol_level_smooth_example();
+ }
+ }
+ return 0; // 返回0,表示程序正常结束
+}
diff --git a/examples/app_vol_level_smooth_example/src/vol_level_smooth_example.c b/examples/app_vol_level_smooth_example/src/vol_level_smooth_example.c
new file mode 100644
index 0000000..5448a51
--- /dev/null
+++ b/examples/app_vol_level_smooth_example/src/vol_level_smooth_example.c
@@ -0,0 +1,42 @@
+#include
+#include
+#include // 包含基本的输入输出函数
+#include "rgb_effect.h"
+#include "timer.h"
+
+#define DELAY_DECREASE 40 // 降低亮度时的额外延迟
+void vol_level_smooth_example()
+{
+ uint32_t buf[NUM_RGBS]; // 定义一个用于存储RGB值的缓冲区,大小由NUM_RGBS宏确定
+ uint32_t current_color[NUM_RGB_GROUPS] = {0xFF0000, 0xFF0000};
+
+ srand(1); // 初始化随机数种子
+ size_t random_levels[NUM_RGB_GROUPS];
+ size_t previous_levels[NUM_RGB_GROUPS] = {0}; // 存储先前的音量级别
+ while (1)
+ {
+ for (size_t i = 0; i < NUM_RGB_GROUPS; i++)
+ {
+ *(random_levels + i) = get_volume_level(rand() % 101 - 100);
+ // 如果新的级别低于之前的级别,逐渐降低
+ while (previous_levels[i] > random_levels[i])
+ {
+ previous_levels[i]--; // 降低当前级别
+ // 用当前颜色和级别填充渐变
+ fill_gradient_with_groups(buf, current_color, previous_levels);
+ delay_milliseconds(DELAY_DECREASE); // 延迟
+ }
+ }
+
+ // 用当前渐变颜色填充RGB数组,然后发送给rgb阵列
+ fill_gradient_with_groups(buf, current_color, random_levels);
+ // 延迟以控制显示持续时间
+ delay_milliseconds(DELAY_TIME_RGB);
+
+ // 更新先前的音量级别
+ for (size_t i = 0; i < NUM_RGB_GROUPS; i++)
+ {
+ previous_levels[i] = random_levels[i];
+ }
+ }
+}
\ No newline at end of file
diff --git a/lib_rgb/api/misc_utils.h b/lib_rgb/api/misc_utils.h
index 8af0251..0141dbb 100644
--- a/lib_rgb/api/misc_utils.h
+++ b/lib_rgb/api/misc_utils.h
@@ -1,5 +1,5 @@
-#ifndef _MISC_UTILS_H
-#define _MISC_UTILS_H
+#ifndef MISC_UTILS_H
+#define MISC_UTILS_H
#include
#include
@@ -15,4 +15,4 @@
* 直到到达中心点,完成反转过程。
*/
void reverse_buf(uint32_t *start, size_t count);
-#endif // _MISC_UTILS_H
\ No newline at end of file
+#endif // MISC_UTILS_H
\ No newline at end of file
diff --git a/lib_rgb/api/rgb_driver.h b/lib_rgb/api/rgb_driver.h
index 21fccac..bbf43e3 100644
--- a/lib_rgb/api/rgb_driver.h
+++ b/lib_rgb/api/rgb_driver.h
@@ -1,7 +1,22 @@
-#ifndef _RGB_DRIVER_H
-#define _RGB_DRIVER_H
-
+#ifndef RGB_DRIVER_H
+#define RGB_DRIVER_H
#include
+#include
+#include "misc_utils.h"
+//TODO: 在XUA工程环境中测试
+
+// 在Makefile中定义编译选项,以使用xua配置项覆盖定义
+#ifdef _XUA_CONF_H_EXISTS_
+ #include "xua_conf.h"
+#endif
+
+#ifndef RGB_TILE
+#define RGB_TILE (1)
+#endif
+
+#ifndef PORT_RGB_DAISY_CHAIN
+#define PORT_RGB_DAISY_CHAIN XS1_PORT_4A
+#endif
/** 串行输出24位值。
*
@@ -29,4 +44,4 @@ void output_24bit_value_serially(uint32_t value);
*/
void output_rgb_array(uint32_t buf[], uint32_t num_rgbs);
-#endif // _RGB_DRIVER_H
+#endif // RGB_DRIVER_H
diff --git a/lib_rgb/api/rgb_effect.h b/lib_rgb/api/rgb_effect.h
index 712d5e0..ad3c0ee 100644
--- a/lib_rgb/api/rgb_effect.h
+++ b/lib_rgb/api/rgb_effect.h
@@ -1,12 +1,16 @@
#ifndef RGB_EFFECT_H
#define RGB_EFFECT_H
-
#include
#include
#include "rgb_driver.h"
#include "samples_to_levels.h"
#include "misc_utils.h"
+// 在Makefile中定义编译选项,以使用xua配置项覆盖定义
+#ifdef _XUA_CONF_H_EXISTS_
+ #include "xua_conf.h"
+#endif
+
// RGB灯的数量
#ifndef NUM_RGBS
#define NUM_RGBS (12)
@@ -49,6 +53,10 @@
#define DELAY_TIME_RGB (1000 / RGB_MAX)
#endif
+// 控制cycleHSV中,HUE递增的步进值,该步进值应能整除360,且不超过它
+#ifndef HUE_STEP
+#define HUE_STEP (1)
+#endif
/**
* 定义渐变方向的枚举类型。
*
@@ -141,7 +149,7 @@ uint32_t HSV_to_RGB(uint32_t *hue, uint32_t *sat, uint32_t *value);
* \param buf 指向存储RGB值的缓冲区的指针,每个元素代表RGB条中一个颜色单元的颜色值。
* \param color 要填充的统一颜色值。
*/
-void fill_gradient(uint32_t *buf, size_t num_filled_rgb, uint32_t color);
+void fill_gradient(uint32_t *buf, uint32_t color, size_t num_filled_rgb);
/**
* 将多种颜色分组填充到RGB条中,并控制显示颜色的时间长度。
@@ -157,4 +165,5 @@ void fill_gradient(uint32_t *buf, size_t num_filled_rgb, uint32_t color);
*/
void fill_gradient_with_groups(uint32_t *buf, uint32_t *colors, size_t *num_filled_rgb);
+void fill_gradient_with_groups_colorful(uint32_t *buf, uint32_t *colors, size_t *num_filled_rgb);
#endif //RGB_EFFECT_H
\ No newline at end of file
diff --git a/lib_rgb/api/samples_to_levels.h b/lib_rgb/api/samples_to_levels.h
index f5cefa8..c0a2c7e 100644
--- a/lib_rgb/api/samples_to_levels.h
+++ b/lib_rgb/api/samples_to_levels.h
@@ -31,14 +31,6 @@
*/
size_t get_volume_level(int loudness_value);
-/**
- * 测试不同响度值对应的音量等级。
- *
- * 此函数定义了一系列响度值,并使用 get_volume_level 函数
- * 来获取每个响度值对应的音量等级,然后打印出来。
- */
-void volume_level_test();
-
/**
* 将音频样本转换为音量级别。
*
diff --git a/lib_rgb/api/visualize_volume.h b/lib_rgb/api/visualize_volume.h
index 46d59b5..959221e 100644
--- a/lib_rgb/api/visualize_volume.h
+++ b/lib_rgb/api/visualize_volume.h
@@ -1,7 +1,6 @@
#ifndef CACHE_OPERATIONS_H
#define CACHE_OPERATIONS_H
#include
-#include "samples_to_levels.h"
#include "rgb_effect.h"
/**
* \brief 初始化缓存缓冲区。
@@ -40,5 +39,4 @@ void write_to_inactive_cache(int address, int16_t data);
* current_hue作为当前色调值,用于生成下一个颜色。
*/
void visualize_loudness_driver();
-#endif // CACHE_OPERATIONS_H
-// TODO: Refact this shit
\ No newline at end of file
+#endif // CACHE_OPERATIONS_H
\ No newline at end of file
diff --git a/lib_rgb/module_build_info b/lib_rgb/module_build_info
index e41f7c8..517b192 100644
--- a/lib_rgb/module_build_info
+++ b/lib_rgb/module_build_info
@@ -1,8 +1,8 @@
-VERSION = 0.0.4
+VERSION = 0.1.0
DEPENDENT_MODULES = lib_xcore_math(>=2.1.0) \
-MODULE_XCC_FLAGS = $(XCC_FLAGS) -g -O3 -Wall
+MODULE_XCC_FLAGS = $(XCC_FLAGS) -g -O3 -Wall -Wextra -Werror
EXPORT_INCLUDE_DIRS = api
diff --git a/lib_rgb/src/rgb_driver.xc b/lib_rgb/src/rgb_driver.xc
index d424811..7645e67 100644
--- a/lib_rgb/src/rgb_driver.xc
+++ b/lib_rgb/src/rgb_driver.xc
@@ -4,17 +4,18 @@
#include
#include "xclib.h"
#include
+#include "rgb_driver.h"
// 如果灯的显示没有出现问题,不要修改这些宏
-#define MICROSECONDS 100
-#define RT23_RST_DELAY (MICROSECONDS * 200000) // 200 ms 当前没有使用,因为引脚通常自动拉低
-#define T0H_DELAY (33) // 0.3 μs, assuming MICROSECONDS is 100 times the actual microsecond count
+#define RT23_RST_DELAY (MICRO_SECOND * 200000) // 200 ms 当前没有使用,因为引脚通常自动拉低
+#define T0H_DELAY (33) // 0.3 μs, assuming MICRO_SECOND is 100 times the actual microsecond count
#define T1H_DELAY (63) // 0.6 μs
#define T0L_DELAY (93) // 0.9 μs
#define T1L_DELAY (63) // 0.6 μs
+// RGB_TILE 通常为0/1,PORT_RGB_DAISY_CHAIN为4bit port
+on tile[RGB_TILE]: out port p_rgb_4bit = PORT_RGB_DAISY_CHAIN;
-on tile[1] : out port p_rgb_rgb = XS1_PORT_4A; // 注意:当前代码仅适用于4bit端口
timer tmr;
// 向4A3写时序,点亮RT23
@@ -22,19 +23,19 @@ uint32_t output_bit_on_4th_pin(uint32_t bit, uint32_t fall_time)
{
if (bit == 1)
{
- p_rgb_rgb<:0xff; // 输出到4位端口
+ p_rgb_4bit<:0xff; // 输出到4位端口
tmr when timerafter(fall_time + T1H_DELAY):> fall_time; // 等待T1H时长
// printf("[x]fall_time: %u\n", fall_time);
- p_rgb_rgb<:0x00; // 将第4位设置为低电平
+ p_rgb_4bit<:0x00; // 将第4位设置为低电平
tmr when timerafter(fall_time + T1L_DELAY):> fall_time; // 等待T1L时长
// printf("[x]fall_time: %u\n", fall_time);
}
else if (bit == 0)
{
- p_rgb_rgb<:0xff; // 输出到4位端口
+ p_rgb_4bit<:0xff; // 输出到4位端口
tmr when timerafter(fall_time + T0H_DELAY):> fall_time; // 等待T0H时长
// printf("[x]fall_time: %u\n", fall_time);
- p_rgb_rgb<:0x00; // 将第4位设置为低电平
+ p_rgb_4bit<:0x00; // 将第4位设置为低电平
tmr when timerafter(fall_time + T0L_DELAY):> fall_time; // 等待T0L时长
// printf("[x]fall_time: %u\n", fall_time);
}
@@ -52,7 +53,7 @@ void output_24bit_value_serially(uint32_t value)
uint32_t fall_time = 0;
tmr:> fall_time;
// // 重置 RT23,由于引脚默认为低,此处不做重置
- // p_rgb_rgb <: 0x000000;
+ // p_rgb_4bit <: 0x000000;
// tmr when timerafter(fall_time + RT23_RST_DELAY):> fall_time;
value = value << 8;
diff --git a/lib_rgb/src/rgb_effect.c b/lib_rgb/src/rgb_effect.c
index 7b2ecd4..39085a0 100644
--- a/lib_rgb/src/rgb_effect.c
+++ b/lib_rgb/src/rgb_effect.c
@@ -5,7 +5,7 @@
#include "rgb_driver.h"
#include "samples_to_levels.h"
#include "misc_utils.h"
-#include "rgb_effect.h"
+#include "rgb_effect.h"
// 检查HSV值是否在有效范围内,如果溢出则将值设为最大值,并打印报错
void is_HSV_valid(uint32_t *hue, uint32_t *sat, uint32_t *value)
@@ -33,9 +33,9 @@ uint32_t HSV_to_RGB(uint32_t *hue, uint32_t *sat, uint32_t *value)
{
#ifdef HSV_VALID_CHECK
- #if HSV_VALID_CHECK == 0
- (is_HSV_valid(hue, sat, value));
- #endif
+#if HSV_VALID_CHECK == 0
+ (is_HSV_valid(hue, sat, value));
+#endif
#endif
uint32_t g; // 现在G是最高8位
@@ -89,7 +89,6 @@ uint32_t HSV_to_RGB(uint32_t *hue, uint32_t *sat, uint32_t *value)
return (g << 16) | (r << 8) | b;
}
-
// 逐步遍历RGB颜色空间,实现呼吸灯效果
uint32_t cycleRGB(uint32_t color, GradientDirection *direction)
{
@@ -134,7 +133,7 @@ uint32_t cycleHSV(uint32_t *hue)
uint32_t value = 100;
if (*hue < 359)
{
- (*hue) += 1;
+ (*hue) += HUE_STEP;
// printf("hue is: 0x%06X\n", *hue);
}
else
@@ -142,11 +141,11 @@ uint32_t cycleHSV(uint32_t *hue)
(*hue) = 0;
// printf("--------hue is: 0x%06X----------\n", *hue);
}
- return(HSV_to_RGB(hue, &sat, &value));
+ return (HSV_to_RGB(hue, &sat, &value));
}
// 将单一颜色填充到整个RGB条中,并控制显示颜色的时间长度
-void fill_gradient(uint32_t *buf, size_t num_filled_rgb, uint32_t color)
+void fill_gradient(uint32_t *buf, uint32_t color, size_t num_filled_rgb)
{
// 遍历缓冲区的每个元素,将其设置为提供的颜色值
for (size_t i = 0; i < num_filled_rgb; i++)
@@ -165,30 +164,63 @@ void fill_gradient(uint32_t *buf, size_t num_filled_rgb, uint32_t color)
delay_milliseconds(DELAY_TIME_RGB);
}
-// 将多种颜色分组填充到RGB条中,并控制显示颜色的时间长度。
+// 将多种颜色按分组填充到RGB条中
void fill_gradient_with_groups(uint32_t *buf, uint32_t *colors, size_t *num_filled_rgb)
{
size_t max_leds_per_group = NUM_RGBS / NUM_RGB_GROUPS;
- for (size_t group = 0; group < NUM_RGB_GROUPS; group++) {
- // 填充每个组的LED
+ for (size_t group = 0; group < NUM_RGB_GROUPS; group++)
+ {
+ // 填充每个组的RGB
uint32_t *group_buf = buf + group * max_leds_per_group;
- for (size_t i = 0; i < num_filled_rgb[group]; i++) {
+ for (size_t i = 0; i < num_filled_rgb[group]; i++)
+ {
*(group_buf + i) = colors[group];
}
- // 熄灭该组剩余的LED
- for (size_t i = num_filled_rgb[group]; i < max_leds_per_group; i++) {
+ // 熄灭该组剩余的RGB
+ for (size_t i = num_filled_rgb[group]; i < max_leds_per_group; i++)
+ {
*(group_buf + i) = 0x000000;
}
// 如果组号为奇数,翻转该组对应的buffer元素
- if (group % 2 != 0) {
+ if (group % 2 != 0)
+ {
reverse_buf(group_buf, max_leds_per_group);
}
}
// 将缓冲区输出到RGB条
output_rgb_array(buf, NUM_RGBS);
+}
+// 将多种颜色按RGB的数量,分组填充到RGB条中
+void fill_gradient_with_groups_colorful(uint32_t *buf, uint32_t *colors, size_t *num_filled_rgb)
+{
+ size_t max_leds_per_group = NUM_RGBS / NUM_RGB_GROUPS;
+
+ for (size_t group = 0; group < NUM_RGB_GROUPS; group++)
+ {
+ // 填充每个组的RGB,其中每个RGB的颜色是独立赋值的
+ uint32_t *group_buf = buf + group * max_leds_per_group;
+ for (size_t i = 0; i < num_filled_rgb[group]; i++)
+ {
+ *(group_buf + i) = colors[i + group * max_leds_per_group];
+ }
+
+ // 熄灭该组剩余的RGB
+ for (size_t i = num_filled_rgb[group]; i < max_leds_per_group; i++)
+ {
+ *(group_buf + i) = 0x000000;
+ }
+
+ // 如果组号为奇数,翻转该组对应的buffer元素
+ if (group % 2 != 0)
+ {
+ reverse_buf(group_buf, max_leds_per_group);
+ }
+ }
+ // 将缓冲区输出到RGB条
+ output_rgb_array(buf, NUM_RGBS);
}
\ No newline at end of file
diff --git a/lib_rgb/src/samples_to_levels.c b/lib_rgb/src/samples_to_levels.c
index aeec7e2..c5237bf 100644
--- a/lib_rgb/src/samples_to_levels.c
+++ b/lib_rgb/src/samples_to_levels.c
@@ -101,17 +101,4 @@ void samples_to_levels(int16_t sample_in[], size_t levels[])
levels[i] = get_volume_level(rms);
// printf("rms[%d]: %d \n", i, rms);
}
-}
-
-// 测试不同响度值对应的音量等级是否符合预期
-void volume_level_test() {
- // 测试不同的响度值
- uint32_t test_loudness_values[] = {1, 0, -2, -5, -8, -20, -30, -40, -60, -62, -70, };
- int num_tests = sizeof(test_loudness_values) / sizeof(test_loudness_values[0]);
-
- for (int i = 0; i < num_tests; ++i) {
- printf("Loudness: %lu dB, Volume Level: %u\n",
- test_loudness_values[i],
- get_volume_level((size_t)test_loudness_values[i]));
- }
}
\ No newline at end of file
diff --git a/lib_rgb/src/visualize_volume.c b/lib_rgb/src/visualize_volume.c
index 6bc8865..25bdfd3 100644
--- a/lib_rgb/src/visualize_volume.c
+++ b/lib_rgb/src/visualize_volume.c
@@ -45,7 +45,7 @@ uint32_t current_hue = 0; // 从红色开始的当前色相值
uint32_t current_color[NUM_RGB_GROUPS] = {0x000000, 0x000000};
-// 根据音频的响度,点亮不同数量的rgb灯
+// 根据音频的响度,点亮不同数量的rgb灯,实现响度可视化
void visualize_loudness_driver()
{
// 响度对应的RGB灯等级