diff --git a/firmware/Include/bd3491.h b/firmware/Include/bd3491.h index 1786a7b..2def415 100644 --- a/firmware/Include/bd3491.h +++ b/firmware/Include/bd3491.h @@ -20,9 +20,9 @@ int bd_set_gain(I2C_HandleTypeDef * handle, uint8_t gain_in_db); uint8_t bd_set_attenuation(I2C_HandleTypeDef * handle, uint8_t right_channel, uint8_t attenuation_in_db); // when gain == 0, cut bass boost -void bd_set_bass_boost(I2C_HandleTypeDef * handle, uint8_t gain); +uint8_t bd_set_bass_boost(I2C_HandleTypeDef * handle, uint8_t gain); // when gain == 0, cut treble boost -void bd_set_treble_boost(I2C_HandleTypeDef * handle, uint8_t gain); +uint8_t bd_set_treble_boost(I2C_HandleTypeDef * handle, uint8_t gain); enum BD_SOURROUND_GAIN { BD_SOURROUND_OFF = 0, diff --git a/firmware/Src/bd3491.c b/firmware/Src/bd3491.c index 7ff6e04..0cac892 100644 --- a/firmware/Src/bd3491.c +++ b/firmware/Src/bd3491.c @@ -70,13 +70,21 @@ uint8_t bd_set_attenuation(I2C_HandleTypeDef * handle, uint8_t right_channel, ui } // when gain == 0, cut bass boost -void bd_set_bass_boost(I2C_HandleTypeDef * handle, uint8_t gain) { +uint8_t bd_set_bass_boost(I2C_HandleTypeDef * handle, uint8_t gain) { + if (gain > 0x07) gain = 0x07; + bd_write_reg(handle, 0x51, (gain == 0)?(0x80):(0x00) | (gain&0x07) << 1); + + return gain; } // when gain == 0, cut treble boost -void bd_set_treble_boost(I2C_HandleTypeDef * handle, uint8_t gain) { +uint8_t bd_set_treble_boost(I2C_HandleTypeDef * handle, uint8_t gain) { + if (gain > 0x07) gain = 0x07; + bd_write_reg(handle, 0x57, (gain == 0)?(0x80):(0x00) | (gain&0x07) << 1); + + return gain; } void bd_set_sourround(I2C_HandleTypeDef * handle, enum BD_SOURROUND_GAIN gain) { diff --git a/firmware/Src/message_parser.c b/firmware/Src/message_parser.c index 85a11eb..d67e7ac 100644 --- a/firmware/Src/message_parser.c +++ b/firmware/Src/message_parser.c @@ -169,8 +169,21 @@ int parse_buffer() { } break; case 'B': - case 'T': + { + uint16_t boost; + if (next_arg_unsigned(&boost)) break; + printf("B%d\n", bd_set_bass_boost(&hi2c1, boost)); + } + break; + case 'T': + { + uint16_t boost; + if (next_arg_unsigned(&boost)) break; + + printf("T%d\n", bd_set_treble_boost(&hi2c1, boost)); + } + break; default: printf("E\n"); }