From d28508f7bf8bfa8ac7681f8983aba01c0430c2ba Mon Sep 17 00:00:00 2001 From: Julian Daube Date: Mon, 21 Oct 2019 23:05:00 +0200 Subject: [PATCH] firmware: fix input numberingch5 was shorting all inputs --- firmware/Include/bd3491.h | 5 +++++ firmware/Src/bd3491.c | 22 +++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) 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) \