Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

tests/driver_dac_dds: fix output of sine and saw functions #19251

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions tests/driver_dac_dds/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,17 @@ typedef void (*sample_gen_t)(uint8_t *dst, size_t len, uint16_t period);

static void _fill_saw_samples_8(uint8_t *buf, size_t len, uint16_t period)
{
uint8_t x = 0;
unsigned step = 0xFF / period;

for (uint16_t i = 0; i < len; ++i) {
x += step;
buf[i] = x;
buf[i] = (i * 0xFFUL) / period;
}
}

static void _fill_saw_samples_16(uint8_t *buf, size_t len, uint16_t period)
{
uint16_t x = 0;
unsigned step = 0xFFFF / period;

for (uint16_t i = 0; i < len; ++i) {
x += step;
buf[i] = x;
buf[++i] = x >> 8;
uint16_t y = (i * 0xFFFFUL) / period;
buf[i] = y;
buf[++i] = y >> 8;
}
}

Expand All @@ -126,8 +119,7 @@ static void _fill_sine_samples_8(uint8_t *buf, size_t len, uint16_t period)

for (uint16_t i = 0; i < period; ++i) {
x += step;
buf[i] = isin(x) >> 5;
buf[i] += INT8_MAX + 1;
buf[i] = (isin(x) + 4096) >> 6;
}

for (uint16_t i = period; i < len; i += period) {
Expand All @@ -145,8 +137,7 @@ static void _fill_sine_samples_16(uint8_t *buf, size_t len, uint16_t period)
for (uint16_t i = 0; i < period; ++i) {
x += step;

uint16_t y = isin(x);
y += INT16_MAX + 1;
uint16_t y = (isin(x) + 4096) << 2;
buf[i] = y;
buf[++i] = y >> 8;
}
Expand Down