OpenRTX/platform/targets/MD-9600/platform.c

169 lines
4.8 KiB
C

/***************************************************************************
* Copyright (C) 2021 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 <http://www.gnu.org/licenses/> *
***************************************************************************/
#include <interfaces/gpio.h>
#include <interfaces/nvmem.h>
#include <interfaces/platform.h>
#include <hwconfig.h>
#include <string.h>
#include <backlight.h>
#include <ADC1_MDx.h>
#include <calibInfo_MDx.h>
#include <toneGenerator_MDx.h>
#include <interfaces/rtc.h>
#include <SPI2.h>
#include <chSelector.h>
hwInfo_t hwInfo;
void platform_init()
{
gpio_setMode(CH_SELECTOR_0, INPUT_PULL_UP);
gpio_setMode(CH_SELECTOR_1, INPUT_PULL_UP);
gpio_setMode(PTT_SW, INPUT);
gpio_setMode(PWR_SW, OUTPUT);
gpio_setPin(PWR_SW);
/*
* Initialise ADC1, for vbat, RSSI, ...
* Configuration of corresponding GPIOs in analog input mode is done inside
* the driver.
*/
adc1_init();
/*
* Initialise SPI2 for external flash and LCD
*/
gpio_setMode(SPI2_CLK, ALTERNATE);
gpio_setMode(SPI2_SDO, ALTERNATE);
gpio_setMode(SPI2_SDI, ALTERNATE);
gpio_setAlternateFunction(SPI2_CLK, 5); /* SPI2 is on AF5 */
gpio_setAlternateFunction(SPI2_SDO, 5);
gpio_setAlternateFunction(SPI2_SDI, 5);
spi2_init();
/* TODO temporary initialisation */
memset(&hwInfo, 0x00, sizeof(hwInfo));
hwInfo.uhf_maxFreq = FREQ_LIMIT_UHF_HI/1000000;
hwInfo.uhf_minFreq = FREQ_LIMIT_UHF_LO/1000000;
hwInfo.vhf_maxFreq = FREQ_LIMIT_VHF_HI/1000000;
hwInfo.vhf_minFreq = FREQ_LIMIT_VHF_LO/1000000;
hwInfo.uhf_band = 1;
hwInfo.vhf_band = 1;
hwInfo.lcd_type = 0;
memcpy(hwInfo.name, "MD-9600", 7);
hwInfo.name[8] = '\0';
nvm_init(); /* Initialise non volatile memory manager */
toneGen_init(); /* Initialise tone generator */
rtc_init(); /* Initialise RTC */
backlight_init(); /* Initialise backlight driver */
chSelector_init(); /* Initialise channel selector handler */
}
void platform_terminate()
{
/* Shut down backlight */
backlight_terminate();
/* Shut down all the modules */
adc1_terminate();
toneGen_terminate();
rtc_terminate();
chSelector_terminate();
/* Finally, remove power supply */
gpio_clearPin(PWR_SW);
}
float platform_getVbat()
{
/*
* Battery voltage is measured through an 1:5.7 voltage divider and
* adc1_getMeasurement returns a value in mV. Thus, to have effective
* battery voltage multiply by the ratio and divide by 1000
*/
return (adc1_getMeasurement(ADC_VBAT_CH)*5.7f)/1000.0f;
}
float platform_getMicLevel()
{
return 0.0f;
}
float platform_getVolumeLevel()
{
return 0.0f;
}
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)
{
/* No LEDs on this platform */
(void) led;
}
void platform_ledOff(led_t led)
{
/* No LEDs on this platform */
(void) led;
}
void platform_beepStart(uint16_t freq)
{
/* TODO */
(void) freq;
}
void platform_beepStop()
{
/* TODO */
}
const void *platform_getCalibrationData()
{
return NULL;
}
const hwInfo_t *platform_getHwInfo()
{
return &hwInfo;
}
/*
* NOTE: implementation of this API function is provided in
* platform/drivers/chSelector/chSelector_MD9600.c
*/
// int8_t platform_getChSelector()
/*
* NOTE: implementation of this API function is provided in
* platform/drivers/backlight/backlight_MDx.c
*/
// void platform_setBacklightLevel(uint8_t level)