From 95a9eb6b3078915a2686c7ec55320273ef429838 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 10 Jul 2023 11:56:04 -0600 Subject: refactored how channel modes are defined, and converted emisar-2ch build --- spaghetti-monster/fsm-channels.h | 136 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 spaghetti-monster/fsm-channels.h (limited to 'spaghetti-monster/fsm-channels.h') diff --git a/spaghetti-monster/fsm-channels.h b/spaghetti-monster/fsm-channels.h new file mode 100644 index 0000000..b86e9ba --- /dev/null +++ b/spaghetti-monster/fsm-channels.h @@ -0,0 +1,136 @@ +// fsm-channels.h: Channel mode functions for SpaghettiMonster. +// Copyright (C) 2023 Selene ToyKeeper +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +// always enable channel modes, even if there is only one +#define USE_CHANNEL_MODES + +// typedefs +typedef void SetLevelFunc(uint8_t level); +typedef SetLevelFunc * SetLevelFuncPtr; + +typedef bool GradualTickFunc(uint8_t gt); +typedef GradualTickFunc * GradualTickFuncPtr; + +typedef struct Channel { + SetLevelFuncPtr set_level; + #ifdef USE_SET_LEVEL_GRADUALLY + GradualTickFuncPtr gradual_tick; + #endif + #ifdef USE_CHANNEL_MODE_ARGS + bool has_args; + //uint8_t arg; // is in the config struct, not here + #endif +} Channel; + +Channel channels[]; // values are defined in the hwdef-*.c + +// TODO: size-optimize the case with only 1 channel mode? +// (the arrays and stuff shouldn't be needed) + +#ifdef USE_CFG + #define CH_MODE cfg.channel_mode +#else + // current multi-channel mode + uint8_t channel_mode = DEFAULT_CHANNEL_MODE; + #define CH_MODE channel_mode +#endif + +// FIXME: remove this? +#if NUM_CHANNEL_MODES > 1 +#define USE_CHANNEL_MODES +#endif + +#ifdef USE_CUSTOM_CHANNEL_3H_MODES +// different 3H behavior per channel? +// TODO: move to progmem +// TODO: move to Anduril, not FSM +StatePtr channel_3H_modes[NUM_CHANNEL_MODES]; +#endif + +//#ifdef USE_CHANNEL_MODE_TOGGLES +#if NUM_CHANNEL_MODES > 1 +// user can take unwanted modes out of the rotation +// bitmask +#ifdef USE_CFG + #define channel_mode_enabled(n) ((cfg.channel_modes_enabled >> n) & 1) + #define channel_mode_enable(n) cfg.channel_modes_enabled |= (1 << n) + #define channel_mode_disable(n) cfg.channel_modes_enabled &= ((1 << n) ^ 0xff) +#else + uint16_t channel_modes_enabled = CHANNEL_MODES_ENABLED; + #define channel_mode_enabled(n) ((channel_modes_enabled >> n) & 1) + #define channel_mode_enable(n) channel_modes_enabled |= (1 << n) + #define channel_mode_disable(n) channel_modes_enabled &= ((1 << n) ^ 0xff) + #endif +#endif + +#ifdef USE_CHANNEL_MODE_ARGS + #ifndef USE_CFG + // one byte of extra data per channel mode, like for tint value + uint8_t channel_mode_args[NUM_CHANNEL_MODES] = { CHANNEL_MODE_ARGS }; + #endif + // which modes respond to their "arg", and which don't? + //const uint8_t channel_has_args = CHANNEL_HAS_ARGS; + //#define channel_has_args(n) ((CHANNEL_HAS_ARGS >> n) & 1) + // struct member + #define channel_has_args(n) (channels[n].has_args) +#endif + +void set_channel_mode(uint8_t mode); + +#ifdef USE_CALC_2CH_BLEND +void calc_2ch_blend( + PWM_DATATYPE *warm, + PWM_DATATYPE *cool, + PWM_DATATYPE brightness, + PWM_DATATYPE top, + uint8_t blend); +#endif + +#ifdef USE_HSV2RGB +typedef struct RGB_t { + uint8_t r; + uint8_t g; + uint8_t b; +} RGB_t; +RGB_t hsv2rgb(uint8_t h, uint8_t s, uint8_t v); +#endif // ifdef USE_HSV2RGB + + +#ifdef USE_SET_LEVEL_1CH +// TODO: remove this +void set_level_1ch(uint8_t level); +#endif + +#ifdef USE_SET_LEVEL_2CH_STACKED +// TODO: remove this +void set_level_2ch_stacked(uint8_t level); +#endif + +#ifdef USE_SET_LEVEL_3CH_STACKED +// TODO: remove this +void set_level_3ch_stacked(uint8_t level); +#endif + +#if defined(USE_TINT_RAMPING) && (!defined(TINT_RAMP_TOGGLE_ONLY)) +// TODO: remove this +void set_level_2ch_blend(); +#endif + +#ifdef USE_GRADUAL_TICK_1CH +// TODO: remove this +void gradual_tick_1ch(); +#endif + +#ifdef USE_GRADUAL_TICK_2CH_STACKED +// TODO: remove this +void gradual_tick_2ch_stacked(); +#endif + +#ifdef USE_GRADUAL_TICK_3CH_STACKED +// TODO: remove this +void gradual_tick_3ch_stacked(); +#endif + -- cgit v1.2.3 From 6c7c99b1be9a684e3a6ccc533f46979b39f7a529 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 18 Jul 2023 14:44:40 -0600 Subject: converted Emisar D4 and BLF Q8 to multi-channel, and enabled previously-removed tactical mode on the Q8 since there seems to be enough space now (also lowercased their hwdef files) --- spaghetti-monster/fsm-channels.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'spaghetti-monster/fsm-channels.h') diff --git a/spaghetti-monster/fsm-channels.h b/spaghetti-monster/fsm-channels.h index b86e9ba..ba2d3fa 100644 --- a/spaghetti-monster/fsm-channels.h +++ b/spaghetti-monster/fsm-channels.h @@ -14,11 +14,19 @@ typedef SetLevelFunc * SetLevelFuncPtr; typedef bool GradualTickFunc(uint8_t gt); typedef GradualTickFunc * GradualTickFuncPtr; +// TODO: implement custom 3H handlers +typedef void ChannelArgFunc(); +typedef ChannelArgFunc * ChannelArgFuncPtr; + typedef struct Channel { SetLevelFuncPtr set_level; #ifdef USE_SET_LEVEL_GRADUALLY GradualTickFuncPtr gradual_tick; #endif + #ifdef USE_CUSTOM_3H_HANDLERS + // TODO: implement custom 3H handlers + ChannelArgFuncPtr ramp_channel_arg; + #endif #ifdef USE_CHANNEL_MODE_ARGS bool has_args; //uint8_t arg; // is in the config struct, not here @@ -30,7 +38,7 @@ Channel channels[]; // values are defined in the hwdef-*.c // TODO: size-optimize the case with only 1 channel mode? // (the arrays and stuff shouldn't be needed) -#ifdef USE_CFG +#if defined(USE_CFG) && (NUM_CHANNEL_MODES > 1) #define CH_MODE cfg.channel_mode #else // current multi-channel mode -- cgit v1.2.3 From 04a48e44b25d1c42dc26f837586a7503bb74b749 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 24 Aug 2023 17:08:01 -0600 Subject: added channel mode per strobe mode, and made FSM channel mode more flexible, and fixed issue in tactical mode where strobes wouldn't stop on button release --- spaghetti-monster/fsm-channels.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'spaghetti-monster/fsm-channels.h') diff --git a/spaghetti-monster/fsm-channels.h b/spaghetti-monster/fsm-channels.h index ba2d3fa..55fc826 100644 --- a/spaghetti-monster/fsm-channels.h +++ b/spaghetti-monster/fsm-channels.h @@ -38,17 +38,10 @@ Channel channels[]; // values are defined in the hwdef-*.c // TODO: size-optimize the case with only 1 channel mode? // (the arrays and stuff shouldn't be needed) -#if defined(USE_CFG) && (NUM_CHANNEL_MODES > 1) - #define CH_MODE cfg.channel_mode -#else +#if NUM_CHANNEL_MODES > 1 + #define USE_CHANNEL_MODES // current multi-channel mode uint8_t channel_mode = DEFAULT_CHANNEL_MODE; - #define CH_MODE channel_mode -#endif - -// FIXME: remove this? -#if NUM_CHANNEL_MODES > 1 -#define USE_CHANNEL_MODES #endif #ifdef USE_CUSTOM_CHANNEL_3H_MODES -- cgit v1.2.3 From d34d0e7acb1f1e49d21af7cf1c9e08161ce95dd4 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 17 Sep 2023 04:37:25 -0600 Subject: fixed builds which weren't using set_level_zero() yet... - emisar-d4 - emisar-d4v2 - emisar-d4v2-nofet - emisar-d4sv2 - emisar-2ch - emisar-2ch-fet - noctigon-dm11-boost - noctigon-k1 - noctigon-kr4 - noctigon-kr4-nofet - sofirn-lt1s-pro ... and removed old build targets for d4sv2-tintramp, because it was replaced by emisar-2ch a while ago. --- spaghetti-monster/fsm-channels.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spaghetti-monster/fsm-channels.h') diff --git a/spaghetti-monster/fsm-channels.h b/spaghetti-monster/fsm-channels.h index 55fc826..113a85c 100644 --- a/spaghetti-monster/fsm-channels.h +++ b/spaghetti-monster/fsm-channels.h @@ -42,6 +42,8 @@ Channel channels[]; // values are defined in the hwdef-*.c #define USE_CHANNEL_MODES // current multi-channel mode uint8_t channel_mode = DEFAULT_CHANNEL_MODE; +#else + #define channel_mode 0 #endif #ifdef USE_CUSTOM_CHANNEL_3H_MODES @@ -79,7 +81,9 @@ StatePtr channel_3H_modes[NUM_CHANNEL_MODES]; #define channel_has_args(n) (channels[n].has_args) #endif +#if NUM_CHANNEL_MODES > 1 void set_channel_mode(uint8_t mode); +#endif #ifdef USE_CALC_2CH_BLEND void calc_2ch_blend( -- cgit v1.2.3 From 1fdec464891262b06d19f53d1f152a560effa576 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 13 Oct 2023 14:29:57 -0600 Subject: rewrote emisar-d4k-3ch to use delta-sigma modulation (PWM + DSM), which gives much better resolution, especially for the 8-bit channel. Also... - set_channel_mode() aborts when going from/to the same channel, to avoid unnecessary flicker - hsv2rgb() uses 16-bit R/G/B and V now - changed default channel to All - reduced default channel modes to just A, B, C, and All - smooth ramp floor defaults to 1/150 - raised level when aux LEDs turn on high during use (for better compatibility with red main LEDs) --- spaghetti-monster/fsm-channels.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spaghetti-monster/fsm-channels.h') diff --git a/spaghetti-monster/fsm-channels.h b/spaghetti-monster/fsm-channels.h index 113a85c..218f4f5 100644 --- a/spaghetti-monster/fsm-channels.h +++ b/spaghetti-monster/fsm-channels.h @@ -96,11 +96,11 @@ void calc_2ch_blend( #ifdef USE_HSV2RGB typedef struct RGB_t { - uint8_t r; - uint8_t g; - uint8_t b; + uint16_t r; + uint16_t g; + uint16_t b; } RGB_t; -RGB_t hsv2rgb(uint8_t h, uint8_t s, uint8_t v); +RGB_t hsv2rgb(uint8_t h, uint8_t s, uint16_t v); #endif // ifdef USE_HSV2RGB -- cgit v1.2.3