diff --git a/meson.build b/meson.build
index f43b5405..e1950dd5 100644
--- a/meson.build
+++ b/meson.build
@@ -223,6 +223,19 @@ mduv380_inc = inc + stm32f405_inc + ['platform/targets/MD-UV380']
mduv380_def = def + stm32f405_def + {'PLATFORM_MDUV380': ''}
+## TYT MD-UV380G
+mduv380g_src = src + stm32f405_src + ['platform/drivers/display/HX83XX_MDx.c',
+ 'platform/drivers/keyboard/keyboard_MDx.c',
+ 'platform/drivers/NVM/extFlash_MDx.c',
+ 'platform/drivers/NVM/nvmem_MDUV3x0G.c',
+ 'platform/drivers/ADC/ADC1_MDx.c',
+ 'platform/drivers/baseband/rtx_UV3x0.c',
+ 'platform/targets/MD-UV380G/platform.c']
+
+mduv380g_inc = inc + stm32f405_inc + ['platform/targets/MD-UV380G']
+mduv380g_def = def + stm32f405_def + {'PLATFORM_MDUV380G': ''}
+
+
## Radioddity GD77
gd77_src = src + mk22fn512_src + ['platform/targets/GD77/platform.c',
'platform/drivers/display/UC1701_GD77.c',
@@ -249,7 +262,7 @@ dm1801_def = def + mk22fn512_def + {'PLATFORM_DM1801': ''}
md9600_src = src + stm32f405_src + ['platform/targets/MD-9600/platform.c']
md9600_inc = inc + stm32f405_inc + ['platform/targets/MD-9600']
-md9600_def = def + stm32f405_def + {'PLATFORM_MDUV380': ''}
+md9600_def = def + stm32f405_def + {'PLATFORM_MD9600': ''}
##
@@ -299,6 +312,15 @@ foreach k, v : mduv380_def
endif
endforeach
+mduv380g_args = []
+foreach k, v : mduv380g_def
+ if v == ''
+ mduv380g_args += '-D@0@'.format(k)
+ else
+ mduv380g_args += '-D@0@=@1@'.format(k, v)
+ endif
+endforeach
+
gd77_args = []
foreach k, v : gd77_def
if v == ''
@@ -350,6 +372,12 @@ mduv380_opts = {'sources': mduv380_src,
'-Wl,--print-memory-usage'],
'include_directories': mduv380_inc}
+mduv380g_opts = {'sources': mduv380g_src,
+ 'c_args': mduv380g_args,
+ 'link_args' : ['-Wl,-T../platform/mcu/STM32F4xx/linker_script.ld',
+ '-Wl,--print-memory-usage'],
+ 'include_directories': mduv380g_inc}
+
gd77_opts = {'sources': gd77_src,
'c_args': gd77_args,
'link_args' : ['-Wl,-T../platform/mcu/MK22FN512xxx12/linker_script.ld',
@@ -389,11 +417,17 @@ targets = [
'wrap': 'MD390',
'load_addr': '0x0800C000'},
- {'name': 'mduv380g',
+ {'name': 'mduv380',
'opts': mduv380_opts,
'flashable': true,
'wrap': 'UV3X0',
'load_addr': '0x0800C000'},
+
+ {'name': 'mduv380g',
+ 'opts': mduv380g_opts,
+ 'flashable': true,
+ 'wrap': 'UV3X0',
+ 'load_addr': '0x0800C000'},
{'name': 'gd77',
'opts': gd77_opts,
diff --git a/platform/drivers/NVM/nvmem_MDUV3x0G.c b/platform/drivers/NVM/nvmem_MDUV3x0G.c
new file mode 100644
index 00000000..7c367b89
--- /dev/null
+++ b/platform/drivers/NVM/nvmem_MDUV3x0G.c
@@ -0,0 +1,278 @@
+/***************************************************************************
+ * Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, *
+ * Niccolò Izzo IU2KIN *
+ * Frederik Saraci IU2NRO *
+ * Silvano Seva IU2KWO *
+ * *
+ * 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. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, see *
+ ***************************************************************************/
+
+#include
+#include
+#include "calibInfo_MDx.h"
+#include "extFlash_MDx.h"
+
+/**
+ * \internal Data structure matching the one used by original MD3x0 firmware to
+ * manage channel data inside nonvolatile flash memory.
+ *
+ * Taken by dmrconfig repository: https://github.com/sergev/dmrconfig/blob/master/uv380.c
+ */
+typedef struct
+{
+ // Byte 0
+ uint8_t channel_mode : 2,
+ bandwidth : 2,
+ autoscan : 1,
+ _unused1 : 2,
+ lone_worker : 1;
+
+ // Byte 1
+ uint8_t _unused2 : 1,
+ rx_only : 1,
+ repeater_slot : 2,
+ colorcode : 4;
+
+ // Byte 2
+ uint8_t privacy_no : 4,
+ privacy : 2,
+ private_call_conf : 1,
+ data_call_conf : 1;
+
+ // Byte 3
+ uint8_t rx_ref_frequency : 2,
+ _unused3 : 1,
+ emergency_alarm_ack : 1,
+ _unused4 : 3,
+ display_pttid_dis : 1;
+
+ // Byte 4
+ uint8_t tx_ref_frequency : 2,
+ _unused5 : 2,
+ vox : 1,
+ _unused6 : 1,
+ admit_criteria : 2;
+
+ // Byte 5
+ uint8_t _unused7 : 4,
+ in_call_criteria : 2,
+ turn_off_freq : 2;
+
+ // Bytes 6-7
+ uint16_t contact_name_index;
+
+ // Bytes 8-9
+ uint8_t tot : 6,
+ _unused13 : 2;
+ uint8_t tot_rekey_delay;
+
+ // Bytes 10-11
+ uint8_t emergency_system_index;
+ uint8_t scan_list_index;
+
+ // Bytes 12-13
+ uint8_t group_list_index;
+ uint8_t _unused8;
+
+ // Bytes 14-15
+ uint8_t _unused9;
+ uint8_t squelch;
+
+ // Bytes 16-23
+ uint32_t rx_frequency;
+ uint32_t tx_frequency;
+
+ // Bytes 24-27
+ uint16_t ctcss_dcs_receive;
+ uint16_t ctcss_dcs_transmit;
+
+ // Bytes 28-29
+ uint8_t rx_signaling_syst;
+ uint8_t tx_signaling_syst;
+
+ // Byte 30
+ uint8_t power : 2,
+ _unused10 : 6;
+
+ // Byte 31
+ uint8_t _unused11 : 3,
+ dcdm_switch_dis : 1,
+ leader_ms : 1,
+ _unused12 : 3;
+
+ // Bytes 32-63
+ uint16_t name[16];
+}
+mduv3x0Channel_t;
+
+const uint32_t chDataBaseAddr = 0x110000; /**< Base address of channel data */
+const uint32_t maxNumChannels = 3000; /**< Maximum number of channels in memory */
+
+/**
+ * \internal Utility function to convert 4 byte BCD values into a 32-bit
+ * unsigned integer ones.
+ */
+uint32_t _bcd2bin(uint32_t bcd)
+{
+ return ((bcd >> 28) & 0x0F) * 10000000 +
+ ((bcd >> 24) & 0x0F) * 1000000 +
+ ((bcd >> 20) & 0x0F) * 100000 +
+ ((bcd >> 16) & 0x0F) * 10000 +
+ ((bcd >> 12) & 0x0F) * 1000 +
+ ((bcd >> 8) & 0x0F) * 100 +
+ ((bcd >> 4) & 0x0F) * 10 +
+ (bcd & 0x0F);
+}
+
+void nvm_init()
+{
+ extFlash_init();
+}
+
+void nvm_terminate()
+{
+ extFlash_terminate();
+}
+
+void nvm_readCalibData(void *buf)
+{
+ extFlash_wakeup();
+ delayUs(5);
+
+ mduv3x0Calib_t *calib = ((mduv3x0Calib_t *) buf);
+
+ /* Common calibration data */
+ (void) extFlash_readSecurityRegister(0x1000, (&calib->vox1), 6);
+
+ /* UHF-band calibration data */
+ (void) extFlash_readSecurityRegister(0x1009, (&calib->uhfCal.freqAdjustMid), 1);
+ (void) extFlash_readSecurityRegister(0x1010, calib->uhfCal.txHighPower, 9);
+ (void) extFlash_readSecurityRegister(0x2090, calib->uhfCal.txMidPower, 9);
+ (void) extFlash_readSecurityRegister(0x1020, calib->uhfCal.txLowPower, 9);
+ (void) extFlash_readSecurityRegister(0x1030, calib->uhfCal.rxSensitivity, 9);
+ (void) extFlash_readSecurityRegister(0x1040, calib->uhfCal.openSql9, 9);
+ (void) extFlash_readSecurityRegister(0x1050, calib->uhfCal.closeSql9, 9);
+ (void) extFlash_readSecurityRegister(0x1070, calib->uhfCal.closeSql1, 9);
+ (void) extFlash_readSecurityRegister(0x1060, calib->uhfCal.openSql1, 9);
+ (void) extFlash_readSecurityRegister(0x1090, calib->uhfCal.ctcss67Hz, 9);
+ (void) extFlash_readSecurityRegister(0x10a0, calib->uhfCal.ctcss151Hz, 9);
+ (void) extFlash_readSecurityRegister(0x10b0, calib->uhfCal.ctcss254Hz, 9);
+ (void) extFlash_readSecurityRegister(0x10d0, calib->uhfCal.dcsMod1, 9);
+ (void) extFlash_readSecurityRegister(0x2030, calib->uhfCal.sendIrange, 9);
+ (void) extFlash_readSecurityRegister(0x2040, calib->uhfCal.sendQrange, 9);
+ (void) extFlash_readSecurityRegister(0x2070, calib->uhfCal.analogSendIrange, 9);
+ (void) extFlash_readSecurityRegister(0x2080, calib->uhfCal.analogSendQrange, 9);
+
+ uint32_t freqs[18];
+ (void) extFlash_readSecurityRegister(0x20b0, ((uint8_t *) &freqs), 72);
+
+ for(uint8_t i = 0; i < 9; i++)
+ {
+ calib->uhfCal.rxFreq[i] = ((freq_t) _bcd2bin(freqs[2*i]));
+ calib->uhfCal.txFreq[i] = ((freq_t) _bcd2bin(freqs[2*i+1]));
+ }
+
+ /* VHF-band calibration data */
+ (void) extFlash_readSecurityRegister(0x100c, (&calib->vhfCal.freqAdjustMid), 1);
+ (void) extFlash_readSecurityRegister(0x1019, calib->vhfCal.txHighPower, 5);
+ (void) extFlash_readSecurityRegister(0x2099, calib->vhfCal.txMidPower, 5);
+ (void) extFlash_readSecurityRegister(0x1029, calib->vhfCal.txLowPower, 5);
+ (void) extFlash_readSecurityRegister(0x1039, calib->vhfCal.rxSensitivity, 5);
+ (void) extFlash_readSecurityRegister(0x109b, calib->vhfCal.ctcss67Hz, 5);
+ (void) extFlash_readSecurityRegister(0x10ab, calib->vhfCal.ctcss151Hz, 5);
+ (void) extFlash_readSecurityRegister(0x10bb, calib->vhfCal.ctcss254Hz, 5);
+ (void) extFlash_readSecurityRegister(0x10e0, calib->vhfCal.openSql9, 5);
+ (void) extFlash_readSecurityRegister(0x10e5, calib->vhfCal.closeSql9, 5);
+ (void) extFlash_readSecurityRegister(0x10ea, calib->vhfCal.closeSql1, 5);
+ (void) extFlash_readSecurityRegister(0x10ef, calib->vhfCal.openSql1, 5);
+ (void) extFlash_readSecurityRegister(0x10db, calib->vhfCal.dcsMod1, 5);
+ (void) extFlash_readSecurityRegister(0x2039, calib->vhfCal.sendIrange, 5);
+ (void) extFlash_readSecurityRegister(0x2049, calib->vhfCal.sendQrange, 5);
+ (void) extFlash_readSecurityRegister(0x2079, calib->uhfCal.analogSendIrange, 5);
+ (void) extFlash_readSecurityRegister(0x2089, calib->vhfCal.analogSendQrange, 5);
+
+ (void) extFlash_readSecurityRegister(0x2000, ((uint8_t *) &freqs), 40);
+ extFlash_sleep();
+
+ for(uint8_t i = 0; i < 5; i++)
+ {
+ calib->vhfCal.rxFreq[i] = ((freq_t) _bcd2bin(freqs[2*i]));
+ calib->vhfCal.txFreq[i] = ((freq_t) _bcd2bin(freqs[2*i+1]));
+ }
+}
+
+int nvm_readChannelData(channel_t *channel, uint16_t pos)
+{
+ if(pos > maxNumChannels) return -1;
+
+ extFlash_wakeup();
+ delayUs(5);
+
+ mduv3x0Channel_t chData;
+ uint32_t readAddr = chDataBaseAddr + pos * sizeof(mduv3x0Channel_t);
+ extFlash_readData(readAddr, ((uint8_t *) &chData), sizeof(mduv3x0Channel_t));
+ extFlash_sleep();
+
+ channel->mode = chData.channel_mode - 1;
+ channel->bandwidth = chData.bandwidth;
+ channel->admit_criteria = chData.admit_criteria;
+ channel->squelch = chData.squelch;
+ channel->rx_only = chData.rx_only;
+ channel->vox = chData.vox;
+ channel->rx_frequency = _bcd2bin(chData.rx_frequency);
+ channel->tx_frequency = _bcd2bin(chData.tx_frequency);
+ channel->tot = chData.tot;
+ channel->tot_rekey_delay = chData.tot_rekey_delay;
+ channel->emSys_index = chData.emergency_system_index;
+ channel->scanList_index = chData.scan_list_index;
+ channel->groupList_index = chData.group_list_index;
+
+ if(chData.power == 3)
+ {
+ channel->power = 5.0f; /* High power -> 5W */
+ }
+ else if(chData.power == 2)
+ {
+ channel->power = 2.5f; /* Mid power -> 2.5W */
+ }
+ else
+ {
+ channel->power = 1.0f; /* Low power -> 1W */
+ }
+
+ /*
+ * Brutally convert channel name from unicode to char by truncating the most
+ * significant byte
+ */
+ for(uint16_t i = 0; i < 16; i++)
+ {
+ channel->name[i] = ((char) (chData.name[i] & 0x00FF));
+ }
+
+ /* Load mode-specific parameters */
+ if(channel->mode == FM)
+ {
+ channel->fm.ctcDcs_rx = chData.ctcss_dcs_receive;
+ channel->fm.ctcDcs_tx = chData.ctcss_dcs_transmit;
+ }
+ else if(channel->mode == DMR)
+ {
+ channel->dmr.contactName_index = chData.contact_name_index;
+ channel->dmr.dmr_timeslot = chData.repeater_slot;
+ channel->dmr.rxColorCode = chData.colorcode;
+ channel->dmr.txColorCode = chData.colorcode;
+ }
+
+ return 0;
+}
diff --git a/platform/targets/MD-UV380G/hwconfig.h b/platform/targets/MD-UV380G/hwconfig.h
new file mode 100644
index 00000000..e2230c42
--- /dev/null
+++ b/platform/targets/MD-UV380G/hwconfig.h
@@ -0,0 +1,120 @@
+/***************************************************************************
+ * Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, *
+ * Niccolò Izzo IU2KIN, *
+ * Silvano Seva IU2KWO *
+ * *
+ * 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. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, see *
+ ***************************************************************************/
+
+#ifndef HWCONFIG_H
+#define HWCONFIG_H
+
+#include
+
+/* Device has a working real time clock */
+#define HAS_RTC
+
+/* Supported radio bands */
+#define BAND_VHF
+#define BAND_UHF
+
+/* Band limits in Hz */
+#define FREQ_LIMIT_VHF_LO 136000000
+#define FREQ_LIMIT_VHF_HI 174000000
+#define FREQ_LIMIT_UHF_LO 400000000
+#define FREQ_LIMIT_UHF_HI 480000000
+
+/* Screen dimensions */
+#define SCREEN_WIDTH 160
+#define SCREEN_HEIGHT 128
+
+/* Screen pixel format */
+#define PIX_FMT_RGB565
+
+/* Battery type */
+#define BAT_LIPO_2S
+
+/* Display */
+#define LCD_D0 GPIOD,14
+#define LCD_D1 GPIOD,15
+#define LCD_D2 GPIOD,0
+#define LCD_D3 GPIOD,1
+#define LCD_D4 GPIOE,7
+#define LCD_D5 GPIOE,8
+#define LCD_D6 GPIOE,9
+#define LCD_D7 GPIOE,10
+#define LCD_WR GPIOD,5
+#define LCD_RD GPIOD,4
+#define LCD_CS GPIOD,6
+#define LCD_RS GPIOD,12
+#define LCD_RST GPIOD,13
+#define LCD_BKLIGHT GPIOD,8
+
+/* Signalling LEDs */
+#define GREEN_LED GPIOE,0
+#define RED_LED GPIOE,1
+
+/* Analog inputs */
+#define AIN_VBAT GPIOA,1
+
+/* Channel selection rotary encoder */
+#define CH_SELECTOR_0 GPIOE,14
+#define CH_SELECTOR_1 GPIOB,11
+
+/* Push-to-talk switch */
+#define PTT_SW GPIOE,11
+
+/*
+ * Keyboard. Here we define only rows, since coloumn lines are the same as
+ * LCD_Dx. See also: https://www.qsl.net/dl4yhf/RT3/md380_hw.html#keyboard
+ *
+ * "Monitor" and "Function" buttons, on the other hand, are connected to
+ * keyboard row 3 and on LCD_D6 and LCD_D7. They are SWAPPED with respect to
+ * connections made on MD-380.
+ */
+#define KB_ROW1 GPIOA,6 /* K1 */
+#define KB_ROW2 GPIOD,2 /* K2 */
+#define KB_ROW3 GPIOD,3 /* K3 */
+#define MONI_SW LCD_D6
+#define FUNC_SW LCD_D7
+
+/* External flash */
+#define FLASH_CS GPIOD,7
+#define FLASH_CLK GPIOB,3
+#define FLASH_SDO GPIOB,4
+#define FLASH_SDI GPIOB,5
+
+/*
+ * To enable pwm for display backlight dimming uncomment this directive.
+ *
+ * WARNING: backlight pwm is disabled by default because it generates a
+ * continuous tone in the speaker and headphones.
+ *
+ * This issue cannot be solved in any way because it derives from how the
+ * MD-UV380 mcu pins are used: to have a noiseless backlight pwm, the control
+ * pin has to be connected to a mcu pin having between its alternate functions
+ * an output compare channel of one of the timers. With this configuration, the
+ * pwm signal can completely generated in hardware and its frequency can be well
+ * above 22kHz, which is the upper limit for human ears.
+ *
+ * In the MD-UV380 radio, display backlight is connected to PD8, which is not
+ * connected to any of the available output compare channels. Thus, the pwm
+ * signal generation is managed inside the TIM11 ISR by toggling the backlight
+ * pin and its frequency has to be low (~250Hz) to not put too much overehad on
+ * the processor due to timer ISR triggering at an high rate.
+ *
+ * #define ENABLE_BKLIGHT_DIMMING
+ */
+
+#endif
diff --git a/platform/targets/MD-UV380G/platform.c b/platform/targets/MD-UV380G/platform.c
new file mode 100644
index 00000000..10ddfc49
--- /dev/null
+++ b/platform/targets/MD-UV380G/platform.c
@@ -0,0 +1,236 @@
+/***************************************************************************
+ * Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, *
+ * Niccolò Izzo IU2KIN, *
+ * Silvano Seva IU2KWO *
+ * *
+ * 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. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, see *
+ ***************************************************************************/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+mduv3x0Calib_t calibration;
+
+#ifdef ENABLE_BKLIGHT_DIMMING
+void TIM1_TRG_COM_TIM11_IRQHandler()
+{
+ OSIntEnter();
+
+ if(TIM11->SR & TIM_SR_CC1IF)
+ {
+ gpio_clearPin(LCD_BKLIGHT); /* Clear pin on compare match */
+ }
+
+ if(TIM11->SR & TIM_SR_UIF)
+ {
+ gpio_setPin(LCD_BKLIGHT); /* Set pin on counter reload */
+ }
+
+ TIM11->SR = 0;
+
+ OSIntExit();
+}
+#endif
+
+void platform_init()
+{
+ /* Configure GPIOs */
+ gpio_setMode(GREEN_LED, OUTPUT);
+ gpio_setMode(RED_LED, OUTPUT);
+
+ gpio_setMode(LCD_BKLIGHT, OUTPUT);
+ gpio_clearPin(LCD_BKLIGHT);
+
+ gpio_setMode(CH_SELECTOR_0, INPUT);
+ gpio_setMode(CH_SELECTOR_1, INPUT);
+
+ gpio_setMode(PTT_SW, INPUT);
+
+ /*
+ * Initialise ADC1, for vbat, RSSI, ...
+ * Configuration of corresponding GPIOs in analog input mode is done inside
+ * the driver.
+ */
+ adc1_init();
+
+ nvm_init(); /* Initialise non volatile memory manager */
+ nvm_readCalibData(&calibration); /* Load calibration data */
+ rtc_init(); /* Initialise RTC */
+
+ #ifdef ENABLE_BKLIGHT_DIMMING
+ /*
+ * Configure TIM11 for backlight PWM: Fpwm = 256Hz, 8 bit of resolution.
+ * APB2 freq. is 84MHz but timer runs at twice this frequency, then:
+ * PSC = 2564 to have Ftick = 65.52kHz
+ * With ARR = 256, Fpwm is 256Hz;
+ */
+ RCC->APB2ENR |= RCC_APB2ENR_TIM11EN;
+ __DSB();
+
+ TIM11->ARR = 255;
+ TIM11->PSC = 2563;
+ TIM11->CNT = 0;
+ TIM11->CR1 |= TIM_CR1_ARPE;
+ TIM11->CCMR1 |= TIM_CCMR1_OC1M_2
+ | TIM_CCMR1_OC1M_1
+ | TIM_CCMR1_OC1PE;
+ TIM11->CCER |= TIM_CCER_CC1E;
+ TIM11->CCR1 = 0;
+ TIM11->EGR = TIM_EGR_UG; /* Update registers */
+ TIM11->SR = 0; /* Clear interrupt flags */
+ TIM11->DIER = TIM_DIER_CC1IE /* Interrupt on compare match */
+ | TIM_DIER_UIE; /* Interrupt on counter reload */
+ TIM11->CR1 |= TIM_CR1_CEN; /* Start timer */
+
+ NVIC_ClearPendingIRQ(TIM1_TRG_COM_TIM11_IRQn);
+ NVIC_SetPriority(TIM1_TRG_COM_TIM11_IRQn,15);
+ NVIC_EnableIRQ(TIM1_TRG_COM_TIM11_IRQn);
+ #endif
+}
+
+void platform_terminate()
+{
+ /* Shut down backlight */
+ gpio_clearPin(LCD_BKLIGHT);
+
+ #ifdef ENABLE_BKLIGHT_DIMMING
+ RCC->APB2ENR &= ~RCC_APB2ENR_TIM11EN;
+ __DSB();
+ #endif
+
+ /* Shut down LEDs */
+ gpio_clearPin(GREEN_LED);
+ gpio_clearPin(RED_LED);
+
+ /* Shut down all the modules */
+ adc1_terminate();
+ nvm_terminate();
+ rtc_terminate();
+}
+
+float platform_getVbat()
+{
+ /*
+ * Battery voltage is measured through an 1:3 voltage divider and
+ * adc1_getMeasurement returns a value in mV. Thus, to have effective
+ * battery voltage multiply by three and divide by 1000
+ */
+ return adc1_getMeasurement(0)*3.0f/1000.0f;
+}
+
+float platform_getMicLevel()
+{
+ return 0.0f;
+}
+
+float platform_getVolumeLevel()
+{
+ return 0.0f;
+}
+
+uint8_t platform_getChSelector()
+{
+ static const uint8_t rsPositions[] = { 1, 4, 2, 3};
+ int pos = gpio_readPin(CH_SELECTOR_0)
+ | (gpio_readPin(CH_SELECTOR_1) << 1);
+
+ return rsPositions[pos];
+}
+
+bool platform_getPttStatus()
+{
+ /* PTT line has a pullup resistor with PTT switch closing to ground */
+ return (gpio_readPin(PTT_SW) == 0) ? true : false;
+}
+
+void platform_ledOn(led_t led)
+{
+ switch(led)
+ {
+ case GREEN:
+ gpio_setPin(GREEN_LED);
+ break;
+
+ case RED:
+ gpio_setPin(RED_LED);
+ break;
+
+ default:
+ break;
+ }
+}
+
+void platform_ledOff(led_t led)
+{
+ switch(led)
+ {
+ case GREEN:
+ gpio_clearPin(GREEN_LED);
+ break;
+
+ case RED:
+ gpio_clearPin(RED_LED);
+ break;
+
+ default:
+ break;
+ }
+}
+
+void platform_beepStart(uint16_t freq)
+{
+ /* TODO */
+ (void) freq;
+}
+
+void platform_beepStop()
+{
+ /* TODO */
+}
+
+void platform_setBacklightLevel(uint8_t level)
+{
+ /*
+ * Little workaround for the following nasty behaviour: if CCR1 value is
+ * zero, a waveform with 99% duty cycle is generated. This is because we are
+ * emulating pwm with interrupts.
+ */
+ if(level > 1)
+ {
+ #ifdef ENABLE_BKLIGHT_DIMMING
+ TIM11->CCR1 = level;
+ TIM11->CR1 |= TIM_CR1_CEN;
+ #else
+ gpio_setPin(LCD_BKLIGHT);
+ #endif
+ }
+ else
+ {
+ #ifdef ENABLE_BKLIGHT_DIMMING
+ TIM11->CR1 &= ~TIM_CR1_CEN;
+ #endif
+ gpio_clearPin(LCD_BKLIGHT);
+ }
+}
+
+const void *platform_getCalibrationData()
+{
+ return ((const void *) &calibration);
+}