Skip to content

Commit aaca3ec

Browse files
committed
samd: PDMIn: Reduce code unrolling on samd21 only
Instead of unrolling the code 16 times, unroll it 4 times and loop over it 4 times. This gives the same 16 iterations, but at an expense of less flash space.
1 parent b2b8520 commit aaca3ec

File tree

1 file changed

+6
-2
lines changed
  • ports/atmel-samd/common-hal/audiobusio

1 file changed

+6
-2
lines changed

ports/atmel-samd/common-hal/audiobusio/PDMIn.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,11 @@ const uint16_t sinc_filter [OVERSAMPLING] = {
337337
94, 63, 39, 21, 9, 2, 0, 0
338338
};
339339

340-
#define REPEAT_16_TIMES(X) X X X X X X X X X X X X X X X X
340+
#ifdef SAMD21
341+
#define REPEAT_16_TIMES(X) do { for(uint8_t j=0; j<4; j++) { X X X X } } while (0)
342+
#else
343+
#define REPEAT_16_TIMES(X) do { X X X X X X X X X X X X X X X X } while(0)
344+
#endif
341345

342346
static uint16_t filter_sample(uint32_t pdm_samples[4]) {
343347
uint16_t running_sum = 0;
@@ -354,7 +358,7 @@ static uint16_t filter_sample(uint32_t pdm_samples[4]) {
354358
filter_ptr++;
355359
pdm_sample <<= 1;
356360
}
357-
)
361+
);
358362
}
359363
return running_sum;
360364
}

0 commit comments

Comments
 (0)