-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmuses_72323_test.c
185 lines (148 loc) · 5.72 KB
/
muses_72323_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <stdio.h>
#include <assert.h>
#include "muses_72323.h"
void
test_configure ()
{
muses_72323_zero_window_t zero_window = 0;
muses_72323_soft_step_clock_divider_t clock_divider = 0;
muses_72323_soft_step_clock_source_t soft_step_clock =
MUSES_72323_SOFT_STEP_CLOCK_EXTERNAL;
muses_72323_command_t command;
muses_72323_error_t error;
muses_72323_chip_address_t chip_address = 0x00;
error = muses_72323_configure (&command, chip_address, zero_window,
clock_divider, soft_step_clock);
assert(error == MUSES_72323_ERROR_NONE);
assert(command == 0b0000000000001100);
soft_step_clock = MUSES_72323_SOFT_STEP_CLOCK_INTERNAL;
error = muses_72323_configure (&command, chip_address, zero_window,
clock_divider, soft_step_clock);
assert(error == MUSES_72323_ERROR_NONE);
assert(command == 0b0000001000001100);
zero_window = 3;
error = muses_72323_configure (&command, chip_address, zero_window,
clock_divider, soft_step_clock);
assert(error == MUSES_72323_ERROR_NONE);
assert(command == 0b0110001000001100);
error = muses_72323_configure (&command, chip_address,
MUSES_72323_MAX_ZERO_WINDOW + 1, clock_divider,
soft_step_clock);
assert(error == MUSES_72323_ERROR_ZERO_WINDOW_GREATER_THAN_MAX);
error = muses_72323_configure (&command, chip_address, zero_window,
MUSES_72323_MAX_CLOCK_DIVIDER + 1,
soft_step_clock);
assert(error == MUSES_72323_ERROR_CLOCK_DIVIDER_GREATER_THAN_MAX);
error = muses_72323_configure (&command, MUSES_72323_MAX_CHIP_ADDR + 1,
zero_window, clock_divider, soft_step_clock);
assert(error == MUSES_72323_ERROR_CHIP_ADDRESS_GREATER_THAN_MAX);
}
void
test_set_gain ()
{
bool link_channels = false;
bool use_zero_crossing = true;
muses_72323_command_t command;
muses_72323_error_t error;
muses_72323_chip_address_t chip_address = 0x00;
muses_72323_attenuation_t left, right;
left = right = 0;
error = muses_72323_set_gain (&command, chip_address, left, right,
link_channels, use_zero_crossing);
assert(error == MUSES_72323_ERROR_NONE);
assert(command == 0b0000000000001000);
left = right = 1;
error = muses_72323_set_gain (&command, chip_address, left, right,
link_channels, use_zero_crossing);
assert(error == MUSES_72323_ERROR_NONE);
assert(command == 0b0001001000001000);
left = right = 0b111;
error = muses_72323_set_gain (&command, chip_address, left, right,
link_channels, use_zero_crossing);
assert(error == MUSES_72323_ERROR_NONE);
assert(command == 0b0111111000001000);
link_channels = true;
error = muses_72323_set_gain (&command, chip_address, left, right,
link_channels, use_zero_crossing);
assert(error == MUSES_72323_ERROR_NONE);
assert(command == 0b1111111000001000);
error = muses_72323_set_gain (&command, chip_address,
MUSES_72323_MAX_CHANNEL_GAIN + 1, right,
link_channels, use_zero_crossing);
assert(error == MUSES_72323_ERROR_CHANNEL_GAIN_GREATER_THAN_MAX);
error = muses_72323_set_gain (&command, chip_address, left,
MUSES_72323_MAX_CHANNEL_GAIN + 1, link_channels,
use_zero_crossing);
assert(error == MUSES_72323_ERROR_CHANNEL_GAIN_GREATER_THAN_MAX);
error = muses_72323_set_gain (&command, MUSES_72323_MAX_CHIP_ADDR + 1, left,
right, link_channels, use_zero_crossing);
assert(error == MUSES_72323_ERROR_CHIP_ADDRESS_GREATER_THAN_MAX);
}
void
test_set_volume ()
{
muses_72323_chip_address_t chip_address = 0x00;
muses_72323_channel_t channel = MUSES_72323_CHANNEL_LEFT;
muses_72323_attenuation_t attenuation = 0;
bool use_soft_step = false;
muses_72323_command_t command;
muses_72323_error_t error;
attenuation = 0;
error = muses_72323_set_volume (&command, chip_address, channel, attenuation,
use_soft_step);
assert(error == MUSES_72323_ERROR_NONE);
assert(command == 0b0001000000000000);
attenuation = MUSES_72323_MAX_ATTENUATION;
error = muses_72323_set_volume (&command, chip_address, channel, attenuation,
use_soft_step);
assert(error == MUSES_72323_ERROR_NONE);
assert(command == 0b1110111110000000);
for (muses_72323_attenuation_t att = 0; att < 448; att++)
{
error = muses_72323_set_volume (&command, chip_address, channel, att,
use_soft_step);
assert(error == MUSES_72323_ERROR_NONE);
}
use_soft_step = true;
error = muses_72323_set_volume (&command, chip_address, channel, attenuation,
use_soft_step);
assert(error == MUSES_72323_ERROR_NONE);
assert(command == 0b1110111110010000);
chip_address = 0x02;
error = muses_72323_set_volume (&command, chip_address, channel, attenuation,
use_soft_step);
assert(error == MUSES_72323_ERROR_NONE);
assert(command == 0b1110111110010010);
error = muses_72323_set_volume (&command, chip_address, channel,
MUSES_72323_MAX_ATTENUATION + 1,
use_soft_step);
assert(error == MUSES_72323_ERROR_ATTENUTION_GREATER_THAN_MAX);
error = muses_72323_set_volume (&command, MUSES_72323_MAX_CHIP_ADDR + 1,
channel, attenuation, use_soft_step);
assert(error == MUSES_72323_ERROR_CHIP_ADDRESS_GREATER_THAN_MAX);
}
void
test_mute (void)
{
muses_72323_chip_address_t chip_address = 0x00;
muses_72323_channel_t channel = MUSES_72323_CHANNEL_LEFT;
bool soft_step = false;
muses_72323_command_t command;
muses_72323_error_t error;
error = muses_72323_mute (&command, chip_address, channel, soft_step);
assert(error == MUSES_72323_ERROR_NONE);
assert(command == 0b1111111110000000);
error = muses_72323_mute (&command, MUSES_72323_MAX_CHIP_ADDR + 1, channel,
soft_step);
assert(error == MUSES_72323_ERROR_CHIP_ADDRESS_GREATER_THAN_MAX);
}
int
main (void)
{
fprintf (stderr, "Starting tests ...\n");
test_configure ();
test_set_gain ();
test_set_volume ();
test_mute ();
fprintf (stderr, "... all good\n");
}