Skip to content

Commit

Permalink
Add firmware versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
kkonradpl committed Aug 3, 2024
1 parent ee51d03 commit edbe641
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
35 changes: 30 additions & 5 deletions src/Controllers/Tuner/TEF668X/TEF668X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,38 @@ TEF668X::setBandwidth(uint32_t value)
return false;
}

const uint8_t module = (this->mode == MODE_FM) ? MODULE_FM : MODULE_AM;
const uint8_t command = (this->mode == MODE_FM) ? FM_Set_Bandwidth : AM_Set_Bandwidth;
const uint16_t *table = (this->mode == MODE_FM) ? LITHIO_BANDWIDTH_FM : LITHIO_BANDWIDTH_AM;
const uint16_t bandwidth = Bandwidth::lookup(table, value / 1000, NULL);
const uint16_t controlSensitivity = 100;
const uint16_t lowLevelSensitivity = 100;

const uint16_t mode = (this->mode == MODE_FM && value == 0) ? 1 : 0;

const uint16_t *table = (this->mode == MODE_FM) ? LITHIO_BANDWIDTH_FM : LITHIO_BANDWIDTH_AM;
uint16_t bandwidth = Bandwidth::lookup(table, value / 1000, NULL);
i2c.write(module, command, 4, mode, bandwidth * 10, 1000, 1000);
if (this->mode == MODE_AM)
{
const uint16_t mode = 0;
i2c.write(MODULE_AM, AM_Set_Bandwidth, 4,
mode,
bandwidth * 10,
controlSensitivity * 10,
lowLevelSensitivity * 10);
}
else if (this->mode == MODE_FM)
{
const uint16_t mode = (value == 0) ? 1 : 0;
const uint16_t minBandwidth = 56;
const uint16_t nominalBandwidth = 236;
const uint16_t controlAttack = 300;

i2c.write(MODULE_FM, FM_Set_Bandwidth, 7,
mode,
bandwidth * 10,
controlSensitivity * 10,
lowLevelSensitivity * 10,
minBandwidth * 10,
nominalBandwidth * 10,
controlAttack);
}

this->bandwidth = (mode == 0 ? (uint32_t)bandwidth * 1000 : 0);
return true;
Expand Down
2 changes: 2 additions & 0 deletions src/Controllers/Tuner/TEF668X/TEF668X.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class TEF668X : public TunerDriver
static constexpr Timer::Interval qualityInterval = (TUNER_I2C_CLOCK >= 200000L) ? 2 : 4;
AvgData<int16_t, int32_t, uint8_t, 100 / qualityInterval> rssi;
AvgData<uint16_t, uint32_t, uint8_t, 300 / qualityInterval> cci;
AvgData<int16_t, int32_t, uint8_t, 300 / qualityInterval> offset;
AvgData<uint16_t, uint32_t, uint8_t, 300 / qualityInterval> qBandwidth;

Timer timerQuality;
#if TUNER_TEF668X_RDS_DAVN == false
Expand Down
6 changes: 5 additions & 1 deletion src/Platform/Stm32/tud_descriptor_cb.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifdef ARDUINO_ARCH_STM32
#include <tusb.h>
#include "SerialNumber.h"
#include "../../Version.hpp"

enum
{
Expand Down Expand Up @@ -60,6 +61,9 @@ static char* const strings[] =
CFG_TUD_AUDIO * FMDX_AUDIO_DESC_LEN + \
CFG_TUD_CDC * TUD_CDC_DESC_LEN)

#define BCD_CONVERT(x) ((x) / 10 * 16 + (x) % 10)
#define BCD_VERSION (BCD_CONVERT(FMDX_TUNER_VERSION_MAJOR) << 8) | \
(BCD_CONVERT(FMDX_TUNER_VERSION_MINOR))

uint8_t const*
tud_descriptor_device_cb(void)
Expand All @@ -77,7 +81,7 @@ tud_descriptor_device_cb(void)

.idVendor = 0x1234,
.idProduct = 0x6687,
.bcdDevice = 0x0100,
.bcdDevice = BCD_VERSION,

.iManufacturer = 0x01,
.iProduct = 0x02,
Expand Down
24 changes: 24 additions & 0 deletions src/Version.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
*
* FM-DX Tuner
* Copyright (C) 2024 Konrad Kosmatka
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

#ifndef FMDX_TUNER_VERSION_H
#define FMDX_TUNER_VERSION_H

#define FMDX_TUNER_VERSION_MAJOR 1
#define FMDX_TUNER_VERSION_MINOR 0
#define FMDX_TUNER_VERSION_PATCH 0

#endif

0 comments on commit edbe641

Please sign in to comment.