diff --git a/firmware/Include/bd3491.h b/firmware/Include/bd3491.h index d603bbe..1786a7b 100644 --- a/firmware/Include/bd3491.h +++ b/firmware/Include/bd3491.h @@ -6,6 +6,11 @@ #include "stm32f1xx_hal.h" +#define BD_INPUT_MUTE (1<<4) +#define BD_INPUT_ALL (1<<5) + +// number can either be 0-5 (meaning CHANNEL1 to CHANNEL 6) +// or BD_INPUT_MUTE or BD_INPUT_SHORT void bd_set_input(I2C_HandleTypeDef * handle, uint8_t number); #define BD_MAX_GAIN 20 // gain in db diff --git a/firmware/Src/bd3491.c b/firmware/Src/bd3491.c index b753bb8..7ff6e04 100644 --- a/firmware/Src/bd3491.c +++ b/firmware/Src/bd3491.c @@ -17,12 +17,24 @@ void bd_write_reg(I2C_HandleTypeDef * handle, uint8_t reg, uint8_t data) { HAL_I2C_Master_Transmit(handle, 0b10000010, out, sizeof(out), HAL_MAX_DELAY); } -void bd_set_input(I2C_HandleTypeDef * handle, uint8_t number) { - if (number > 5) { - return; - } - bd_write_reg(handle, 0x04, number); +#define BD_INPUT_TABLE(a) \ + a(0, 0) \ + a(1, 1) \ + a(2, 2) \ + a(3, 3) \ + a(4, 4) \ + a(5, 6) \ + a(BD_INPUT_ALL, 5) \ + a(BD_INPUT_MUTE, 7) + + +void bd_set_input(I2C_HandleTypeDef * handle, uint8_t number) { +#define INPUT_CASE(num, out) case num: bd_write_reg(handle, 0x04, out); break; + switch(number) { + BD_INPUT_TABLE(INPUT_CASE) + } +#undef INPUT_CASE } #define BD_GAIN_TABLE(a) \