Skip to content

Commit 319e909

Browse files
bkuengdagar
authored andcommitted
output_groups_from_timer_config.py: fix timer index
The implementation assumed timers are defined in the same order as used in the channels. This could lead to a mismatch between TIMx param and actual timer config. Now we use the actual array index, same as in the code.
1 parent 183ab8b commit 319e909

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Tools/module_config/output_groups_from_timer_config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ def get_timer_groups(timer_config_file, verbose=False):
6666
raise Exception('"{:}" not found in {:}'.format(timers_start_marker, timer_config_file))
6767
timer_config = timer_config[timers_start:]
6868
open_idx, close_idx = find_matching_brackets(('{', '}'), timer_config, verbose)
69-
timers = timer_config[open_idx:close_idx]
70-
for line in timers.splitlines():
69+
timers_str = timer_config[open_idx:close_idx]
70+
timers = []
71+
for line in timers_str.splitlines():
7172
line = line.strip()
7273
if len(line) == 0 or line.startswith('//'):
7374
continue
@@ -76,6 +77,7 @@ def get_timer_groups(timer_config_file, verbose=False):
7677
if timer:
7778
if verbose: print('found timer def: {:}'.format(timer))
7879
dshot_support[timer] = 'DMA' in line
80+
timers.append(timer)
7981
else:
8082
# Make sure we don't miss anything (e.g. for different syntax) or misparse (e.g. multi-line comments)
8183
raise Exception('Unparsed timer in line: {:}'.format(line))
@@ -112,7 +114,7 @@ def get_timer_groups(timer_config_file, verbose=False):
112114
if len(channel_timers) == 0:
113115
raise Exception('No channels found in "{:}"'.format(channels))
114116

115-
groups = [(len(list(g)), dshot_support[k]) for k, g in groupby(channel_timers)]
117+
groups = [(timers.index(k), len(list(g)), dshot_support[k]) for k, g in groupby(channel_timers)]
116118
outputs = {
117119
'types': channel_types,
118120
'groups': groups
@@ -132,9 +134,8 @@ def get_output_groups(timer_groups, param_prefix="PWM_MAIN",
132134
instance_start = 1
133135
output_groups = []
134136
timer_params = {}
135-
timer_index = 0
136137
instance_start_label = [ 1, 1 ]
137-
for group_count, dshot_support in timer_groups['groups']:
138+
for timer_index, group_count, dshot_support in timer_groups['groups']:
138139

139140
# check for capture vs normal pins for the label
140141
types = timer_groups['types'][instance_start-1:instance_start+group_count-1]
@@ -181,7 +182,6 @@ def get_output_groups(timer_groups, param_prefix="PWM_MAIN",
181182
timer_params[param_prefix+'_TIM'+str(timer_index)] = pwm_timer_param_cp
182183
instance_start += group_count
183184
instance_start_label[channel_type_idx] += group_count
184-
timer_index += 1
185185
return (output_groups, timer_params)
186186

187187
if __name__ == '__main__':

0 commit comments

Comments
 (0)