From 26391ab9536c32336556c03421967173c66df2ce Mon Sep 17 00:00:00 2001 From: Vergil_Wong Date: Sun, 26 Nov 2023 15:09:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86RGB=E7=81=AF?= =?UTF-8?q?=E5=B8=A6=E7=9A=84=E5=B9=BB=E5=BD=A9=E6=B8=90=E5=8F=98=E6=95=88?= =?UTF-8?q?=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app_hsv_cycle_per_rgb_example/Makefile | 24 ++++++++++ .../src/core/xua_conf.h | 26 +++++++++++ .../src/hsv_cycle_per_rgb_example.c | 45 +++++++++++++++++++ .../app_hsv_cycle_per_rgb_example/src/main.xc | 32 +++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 examples/app_hsv_cycle_per_rgb_example/Makefile create mode 100644 examples/app_hsv_cycle_per_rgb_example/src/core/xua_conf.h create mode 100644 examples/app_hsv_cycle_per_rgb_example/src/hsv_cycle_per_rgb_example.c create mode 100644 examples/app_hsv_cycle_per_rgb_example/src/main.xc 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,表示程序正常结束 +}