attenuator: Add convenience functions for setting all stages
This commit is contained in:
parent
5d2e32e4b8
commit
627ead7b21
|
@ -120,6 +120,62 @@ int attenuator_stage_get(uint8_t channel, uint8_t stage, enum attenuator_value a
|
|||
}
|
||||
}
|
||||
|
||||
/* set an overall attenuation value for an entire channel */
|
||||
int attenuator_chan_set(uint8_t channel, uint8_t val_qdb, bool split_equal)
|
||||
{
|
||||
uint8_t val_a, val_b;
|
||||
|
||||
if (!g_att_cfg)
|
||||
return -ENODEV;
|
||||
|
||||
if (channel >= g_att_cfg->num_channels)
|
||||
return -ENODEV;
|
||||
|
||||
if (val_qdb/4 > 0x3f)
|
||||
return -ERANGE;
|
||||
|
||||
if (split_equal) {
|
||||
/* first max out one of the two, then start using the other */
|
||||
val_a = val_qdb / 2;
|
||||
} else {
|
||||
/* first max out one of the two, then start using the other */
|
||||
if (val_qdb < 31*4)
|
||||
val_a = val_qdb;
|
||||
else
|
||||
val_a = 31*4;
|
||||
}
|
||||
val_b = val_qdb - val_a; /* account for odd values */
|
||||
|
||||
printf("Setting CH%u to %02u + %02u = %03u dB\r\n", channel, val_a/4, val_b/4, val_qdb/4);
|
||||
|
||||
_attenuator_stage_set(channel, 0, val_a);
|
||||
_attenuator_stage_set(channel, 1, val_b);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get the cumulative attenuation of all stages within one channel */
|
||||
int attenuator_chan_get(uint8_t channel, enum attenuator_value av)
|
||||
{
|
||||
uint8_t stage;
|
||||
int res;
|
||||
|
||||
if (!g_att_cfg)
|
||||
return -ENODEV;
|
||||
|
||||
if (channel >= g_att_cfg->num_channels)
|
||||
return -ENODEV;
|
||||
|
||||
for (stage = 0; stage < g_att_cfg->channels[channel].num_stages; stage++) {
|
||||
int rc = attenuator_stage_get(channel, stage, av);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
res += rc;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/* initialize the attenuator driver */
|
||||
void attenuator_init(const struct attenuator_cfg *cfg,
|
||||
struct attenuator_state **state)
|
||||
|
|
|
@ -43,3 +43,6 @@ int attenuator_stage_set(uint8_t channel, uint8_t stage, uint8_t val_qdb);
|
|||
int attenuator_stage_get(uint8_t channel, uint8_t stage, enum attenuator_value av);
|
||||
void attenuator_init(const struct attenuator_cfg *cfg,
|
||||
struct attenuator_state **state);
|
||||
|
||||
int attenuator_chan_set(uint8_t channel, uint8_t val_qdb, bool split_equal);
|
||||
int attenuator_chan_get(uint8_t channel, enum attenuator_value av);
|
||||
|
|
Loading…
Reference in New Issue