Skip to content

Commit

Permalink
vfx: update display modes
Browse files Browse the repository at this point in the history
  • Loading branch information
redchenjs committed Mar 6, 2021
1 parent bacc93f commit a6e82b6
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 291 deletions.
4 changes: 2 additions & 2 deletions components/ugfx/drivers/gdisp/CUBE0414/gdisp_lld_CUBE0414.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
uint16_t pos = write_y * g->g.Width + write_x;
LLDCOLOR_TYPE c = gdispColor2Native(g->p.color);
#ifdef CONFIG_LED_COLOR_GRB
#ifdef CONFIG_LED_COLOR_ORDER_GRB
*((uint8_t *)g->priv + pos * 3 + 0) = c >> 8;
*((uint8_t *)g->priv + pos * 3 + 1) = c >> 16;
*((uint8_t *)g->priv + pos * 3 + 2) = c;
Expand Down Expand Up @@ -170,7 +170,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
}
LLDSPEC color_t gdisp_lld_read_color(GDisplay *g) {
uint16_t pos = read_y * g->g.Width + read_x;
#ifdef CONFIG_LED_COLOR_GRB
#ifdef CONFIG_LED_COLOR_ORDER_GRB
LLDCOLOR_TYPE c = (*((uint8_t *)g->priv + pos * 3 + 0) << 8)
| (*((uint8_t *)g->priv + pos * 3 + 1) << 16)
| (*((uint8_t *)g->priv + pos * 3 + 2));
Expand Down
2 changes: 1 addition & 1 deletion components/ugfx/drivers/gdisp/WS2812/gdisp_lld_WS2812.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
LLDSPEC void gdisp_lld_write_color(GDisplay *g) {
uint16_t pos = write_y * g->g.Width + write_x;
LLDCOLOR_TYPE c = gdispColor2Native(g->p.color);
#ifdef CONFIG_LED_COLOR_GRB
#ifdef CONFIG_LED_COLOR_ORDER_GRB
uint8_t red = c >> 16;
uint8_t green = c >> 8;
uint8_t blue = c;
Expand Down
6 changes: 3 additions & 3 deletions components/ugfx/gfxconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@
// #define GDISP_INCLUDE_USER_FONTS FALSE

// #define GDISP_NEED_IMAGE TRUE
// #define GDISP_NEED_IMAGE_NATIVE TRUE
// #define GDISP_NEED_IMAGE_GIF TRUE
// #define GDISP_IMAGE_GIF_BLIT_BUFFER_SIZE 32
// #define GDISP_NEED_IMAGE_NATIVE TRUE
// #define GDISP_NEED_IMAGE_GIF TRUE
// #define GDISP_IMAGE_GIF_BLIT_BUFFER_SIZE 32
// #define GDISP_NEED_IMAGE_BMP TRUE
// #define GDISP_NEED_IMAGE_BMP_1 TRUE
// #define GDISP_NEED_IMAGE_BMP_4 TRUE
Expand Down
65 changes: 38 additions & 27 deletions main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -204,43 +204,54 @@ config LCD_ROTATION_DEGREE
default 90 if LCD_ORIENTATION_NORMAL
default 270 if LCD_ORIENTATION_UPSIDE_DOWN

choice LED_COLOR_ORDER
prompt "LED Color Order"
default LED_COLOR_ORDER_RGB
depends on ENABLE_VFX && (VFX_OUTPUT_WS2812 || VFX_OUTPUT_CUBE0414)
help
Select LED color order.

config LED_COLOR_ORDER_RGB
bool "R-G-B"
config LED_COLOR_ORDER_GRB
bool "G-R-B"
endchoice

choice LED_LAYER_DIR
prompt "LED Layer Direction"
default LED_LAYER_H
default LED_LAYER_DIR_XYZ
depends on ENABLE_VFX && (VFX_OUTPUT_WS2812 || VFX_OUTPUT_CUBE0414)
help
Select LED layer direction.

config LED_LAYER_H
bool "Horizontal"
config LED_LAYER_H_ZI
bool "Horizontal Z-Inverted"
config LED_LAYER_H_XYI
bool "Horizontal XY-Inverted"
config LED_LAYER_H_XYZI
bool "Horizontal XYZ-Inverted"
config LED_LAYER_V
bool "Vertical"
config LED_LAYER_V_ZI
bool "Vertical Z-Inverted"
config LED_LAYER_V_XYI
bool "Vertical XY-Inverted"
config LED_LAYER_V_XYZI
bool "Vertical XYZ-Inverted"
config LED_LAYER_DIR_XYZ
bool "X-Y-Z"
config LED_LAYER_DIR_XZY
bool "X-Z-Y"
config LED_LAYER_DIR_YXZ
bool "Y-X-Z"
config LED_LAYER_DIR_YZX
bool "Y-Z-X"
config LED_LAYER_DIR_ZXY
bool "Z-X-Y"
config LED_LAYER_DIR_ZYX
bool "Z-Y-X"
endchoice

choice LED_COLOR_ORDER
prompt "LED Color Order"
default LED_COLOR_RGB
config LED_LAYER_INV_X
bool "LED Layer X-Inverted"
default n
depends on ENABLE_VFX && (VFX_OUTPUT_WS2812 || VFX_OUTPUT_CUBE0414)
help
Select LED color order.

config LED_COLOR_RGB
bool "RGB"
config LED_COLOR_GRB
bool "GRB"
endchoice
config LED_LAYER_INV_Y
bool "LED Layer Y-Inverted"
default n
depends on ENABLE_VFX && (VFX_OUTPUT_WS2812 || VFX_OUTPUT_CUBE0414)

config LED_LAYER_INV_Z
bool "LED Layer Z-Inverted"
default n
depends on ENABLE_VFX && (VFX_OUTPUT_WS2812 || VFX_OUTPUT_CUBE0414)

choice CUBE0414_REVISION
prompt "CUBE0414 Revision"
Expand Down
13 changes: 5 additions & 8 deletions main/inc/user/fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@

#define TWO_PI (6.2831853f)

#define BAND_N (12)
#define BAND_FADE (2)
#define BAND_DELAY (2)

#define FFT_N (256)
#define FFT_OUT_N (64)
#define FFT_BLOCK_SIZE (FFT_N * 8)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
Expand All @@ -29,9 +24,11 @@ typedef enum {
FFT_CHANNEL_LR = 0x02
} fft_channel_t;

extern void fft_compute_lin(uint16_t *data_out, uint16_t max_val, uint16_t min_val);
extern void fft_compute_log(uint16_t *data_out, uint16_t max_val, uint16_t min_val);
extern void fft_compute_bands(uint16_t *data_out, uint16_t max_val, uint16_t min_val);
extern void fft_compute_lin(uint16_t *data_out, uint16_t num, uint16_t step, uint16_t max_val, uint16_t min_val);
extern void fft_compute_log(uint16_t *data_out, uint16_t num, uint16_t step, uint16_t max_val, uint16_t min_val);

extern void fft_compute_bands(uint16_t *data_out, const float *xscale, uint16_t bands, uint16_t *delay, uint16_t max_val, uint16_t min_val);
extern void fft_compute_xscale(float *xscale, uint16_t bands);

extern void fft_execute(float scale_factor);
extern void fft_load_data(const uint8_t *data_in, fft_channel_t channel);
Expand Down
42 changes: 21 additions & 21 deletions main/src/user/fft.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ static float window[FFT_N * 2] = {0.0};
static float complex root[FFT_N] = {0.0};
static float complex data[FFT_N] = {0.0};

static float xscale[BAND_N + 1] = {0.0};

static bool generated = false;

static int bit_reverse(int x)
Expand Down Expand Up @@ -51,14 +49,9 @@ static void compute_fft_tables(void)
for (int i = 0; i < FFT_N; i++) {
root[i] = cexpf(-I * i * TWO_PI / (FFT_N * 2));
}

// log xscale
for (int i = 0; i <= BAND_N; i++) {
xscale[i] = powf(FFT_N, (float)i / BAND_N) - 0.5;
}
}

static float compute_freq_lin(const float *freq, int step, int idx)
static float compute_freq_lin(const float *freq, uint16_t step, uint16_t idx)
{
float n = 0.0;

Expand All @@ -69,7 +62,7 @@ static float compute_freq_lin(const float *freq, int step, int idx)
return n / step * 2.0;
}

static float compute_freq_band(const float *freq, const float *xscale, int band)
static float compute_freq_band(const float *freq, const float *xscale, uint16_t bands, uint16_t band)
{
float n = 0.0;

Expand All @@ -92,13 +85,13 @@ static float compute_freq_band(const float *freq, const float *xscale, int band)
}
}

return 20 * log10f(n * BAND_N / FFT_N / 12.0);
return 20 * log10f(n * bands / FFT_N / 12.0);
}

void fft_compute_lin(uint16_t *data_out, uint16_t max_val, uint16_t min_val)
void fft_compute_lin(uint16_t *data_out, uint16_t num, uint16_t step, uint16_t max_val, uint16_t min_val)
{
for (int i = 0; i < FFT_OUT_N; i++) {
data_out[i] += compute_freq_lin(freq, FFT_N / FFT_OUT_N, i) * (max_val / 40.0);
for (int i = 0; i < num; i++) {
data_out[i] += compute_freq_lin(freq, step, i) * (max_val / 40.0);
data_out[i] /= 2.0;

if (data_out[i] > max_val) {
Expand All @@ -109,10 +102,10 @@ void fft_compute_lin(uint16_t *data_out, uint16_t max_val, uint16_t min_val)
}
}

void fft_compute_log(uint16_t *data_out, uint16_t max_val, uint16_t min_val)
void fft_compute_log(uint16_t *data_out, uint16_t num, uint16_t step, uint16_t max_val, uint16_t min_val)
{
for (int i = 0; i < FFT_OUT_N; i++) {
data_out[i] += 20 * log10f(1 + compute_freq_lin(freq, FFT_N / FFT_OUT_N, i)) * (max_val / 40.0);
for (int i = 0; i < num; i++) {
data_out[i] += 20 * log10f(1 + compute_freq_lin(freq, step, i)) * (max_val / 40.0);
data_out[i] /= 2.0;

if (data_out[i] > max_val) {
Expand All @@ -123,12 +116,12 @@ void fft_compute_log(uint16_t *data_out, uint16_t max_val, uint16_t min_val)
}
}

void fft_compute_bands(uint16_t *data_out, uint16_t max_val, uint16_t min_val)
void fft_compute_bands(uint16_t *data_out, const float *xscale, uint16_t bands, uint16_t *delay, uint16_t max_val, uint16_t min_val)
{
static char delay[BAND_N] = {0};
enum { BAND_FADE = 2, BAND_DELAY = 2 };

for (int i = 0; i < BAND_N; i++) {
float x = (40 + compute_freq_band(freq, xscale, i)) * (max_val / 64.0);
for (int i = 0; i < bands; i++) {
float x = (40 + compute_freq_band(freq, xscale, bands, i)) * (max_val / 64.0);

data_out[i] = MAX(0, data_out[i] - (BAND_FADE - delay[i]));

Expand All @@ -137,7 +130,7 @@ void fft_compute_bands(uint16_t *data_out, uint16_t max_val, uint16_t min_val)
}

if (x > data_out[i]) {
data_out[i]= x;
data_out[i] = x;

delay[i] = BAND_DELAY;
}
Expand All @@ -150,6 +143,13 @@ void fft_compute_bands(uint16_t *data_out, uint16_t max_val, uint16_t min_val)
}
}

void fft_compute_xscale(float *xscale, uint16_t bands)
{
for (int i = 0; i <= bands; i++) {
xscale[i] = powf(FFT_N, (float)i / bands) - 0.5;
}
}

void fft_execute(float scale_factor)
{
float complex even = 0, odd = 0;
Expand Down
Loading

0 comments on commit a6e82b6

Please sign in to comment.