From ca206ca00711abf2a7db8f2bbd41202e4151512d Mon Sep 17 00:00:00 2001 From: Serge Bazanski <q3k@q3k.org> Date: Fri, 4 Aug 2023 20:27:24 +0200 Subject: [PATCH] st3m, flow3r_bsp: use floats, prepare for impicit float literals --- components/flow3r_bsp/flow3r_bsp_imu.c | 4 ++-- components/st3m/st3m_audio.c | 6 +++--- components/st3m/st3m_colors.c | 6 +++--- components/st3m/st3m_colors.h | 6 +++--- components/st3m/st3m_gfx.c | 5 +++-- components/st3m/st3m_leds.c | 6 +++--- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/components/flow3r_bsp/flow3r_bsp_imu.c b/components/flow3r_bsp/flow3r_bsp_imu.c index 5fb1a09724..e4439465f0 100644 --- a/components/flow3r_bsp/flow3r_bsp_imu.c +++ b/components/flow3r_bsp/flow3r_bsp_imu.c @@ -791,7 +791,7 @@ static int8_t set_bmp_config( static float lsb_to_mps(int16_t val, float g_range, uint8_t bit_width) { double power = 2; - float half_scale = (float)((pow((double)power, (double)bit_width) / 2.0f)); + float half_scale = powf(power, bit_width) / 2.0f; return (GRAVITY_EARTH * val * g_range) / half_scale; } @@ -801,7 +801,7 @@ static float lsb_to_mps(int16_t val, float g_range, uint8_t bit_width) { static float lsb_to_dps(int16_t val, float dps, uint8_t bit_width) { double power = 2; - float half_scale = (float)((pow((double)power, (double)bit_width) / 2.0f)); + float half_scale = powf(power, bit_width) / 2.0f; return (dps / (half_scale)) * (val); } diff --git a/components/st3m/st3m_audio.c b/components/st3m/st3m_audio.c index 2fef99f376..d8d66aafda 100644 --- a/components/st3m/st3m_audio.c +++ b/components/st3m/st3m_audio.c @@ -145,7 +145,7 @@ static void _audio_headphones_apply(st3m_audio_output_t *out) { float software_volume_dB = vol_dB - hardware_volume_dB; if (software_volume_dB > 0) software_volume_dB = 0; out->volume_software = - (int32_t)(32768 * exp(software_volume_dB * NAT_LOG_DB)); + (int32_t)(32768 * expf(software_volume_dB * NAT_LOG_DB)); } // Output apply function for speaker. @@ -167,7 +167,7 @@ static void _audio_speaker_apply(st3m_audio_output_t *out) { float software_volume_dB = vol_dB - hardware_volume_dB; if (software_volume_dB > 0) software_volume_dB = 0; out->volume_software = - (int32_t)(32768. * exp(software_volume_dB * NAT_LOG_DB)); + (int32_t)(32768. * expf(software_volume_dB * NAT_LOG_DB)); } // Global state structure. Guarded by state_mutex. @@ -446,7 +446,7 @@ void st3m_audio_input_thru_set_mute(bool mute) { float st3m_audio_input_thru_set_volume_dB(float vol_dB) { if (vol_dB > 0) vol_dB = 0; LOCK; - state.input_thru_vol_int = (int32_t)(32768. * exp(vol_dB * NAT_LOG_DB)); + state.input_thru_vol_int = (int32_t)(32768. * expf(vol_dB * NAT_LOG_DB)); state.input_thru_vol = vol_dB; UNLOCK; return vol_dB; diff --git a/components/st3m/st3m_colors.c b/components/st3m/st3m_colors.c index 9069755e38..d1b231ab7a 100644 --- a/components/st3m/st3m_colors.c +++ b/components/st3m/st3m_colors.c @@ -3,7 +3,7 @@ #include <math.h> st3m_rgb_t st3m_hsv_to_rgb(st3m_hsv_t hsv) { - double r = 0, g = 0, b = 0; + float r = 0, g = 0, b = 0; if (hsv.s == 0) { r = hsv.v; @@ -11,14 +11,14 @@ st3m_rgb_t st3m_hsv_to_rgb(st3m_hsv_t hsv) { b = hsv.v; } else { int i; - double f, p, q, t; + float f, p, q, t; if (hsv.h == 360) hsv.h = 0; else hsv.h = hsv.h / 60; - i = (int)trunc(hsv.h); + i = (int)truncf(hsv.h); f = hsv.h - i; p = hsv.v * (1.0 - hsv.s); diff --git a/components/st3m/st3m_colors.h b/components/st3m/st3m_colors.h index 450218be76..3495e7edcd 100644 --- a/components/st3m/st3m_colors.h +++ b/components/st3m/st3m_colors.h @@ -13,9 +13,9 @@ typedef struct { typedef struct { // From 0.0 to 1.0. - double h; - double s; - double v; + float h; + float s; + float v; } st3m_hsv_t; // Convert an HSV colour to an RGB colour. diff --git a/components/st3m/st3m_gfx.c b/components/st3m/st3m_gfx.c index 8e26c1860e..b22da033c6 100644 --- a/components/st3m/st3m_gfx.c +++ b/components/st3m/st3m_gfx.c @@ -104,7 +104,7 @@ static void st3m_gfx_crtc_task(void *_arg) { ESP_LOGD( TAG, "blitting: %.3f/sec, read %.3fms, work %.3fms, write %.3fms", - rate, read, work, write); + (double)rate, (double)read, (double)work, (double)write); } } } @@ -160,7 +160,8 @@ static void st3m_gfx_rast_task(void *_arg) { ESP_LOGD(TAG, "rasterization: %.3f/sec, read fb %.3fms, read dctx " "%.3fms, work %.3fms, write %.3fms", - rate, read_fb, read_dctx, work, write); + (double)rate, (double)read_fb, (double)read_dctx, + (double)work, (double)write); } } } diff --git a/components/st3m/st3m_leds.c b/components/st3m/st3m_leds.c index 304b3a51b8..0a69726550 100644 --- a/components/st3m/st3m_leds.c +++ b/components/st3m/st3m_leds.c @@ -226,9 +226,9 @@ void st3m_leds_set_gamma(float red, float green, float blue) { state.gamma_blue.lut[i] = 0; } float step = ((float)i) / 255.; - state.gamma_red.lut[i] = (uint8_t)(254. * (pow(step, red)) + 1); - state.gamma_green.lut[i] = (uint8_t)(254. * (pow(step, green)) + 1); - state.gamma_blue.lut[i] = (uint8_t)(254. * (pow(step, blue)) + 1); + state.gamma_red.lut[i] = (uint8_t)(254. * (powf(step, red)) + 1); + state.gamma_green.lut[i] = (uint8_t)(254. * (powf(step, green)) + 1); + state.gamma_blue.lut[i] = (uint8_t)(254. * (powf(step, blue)) + 1); } UNLOCK; } -- GitLab