2020-12-01 08:40:50 +00:00
|
|
|
/***************************************************************************
|
2022-06-02 07:56:05 +00:00
|
|
|
* Copyright (C) 2020 - 2022 by Federico Amedeo Izzo IU2NUO, *
|
|
|
|
* Niccolò Izzo IU2KIN *
|
|
|
|
* Frederik Saraci IU2NRO *
|
|
|
|
* Silvano Seva IU2KWO *
|
2020-12-01 08:40:50 +00:00
|
|
|
* *
|
|
|
|
* 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/> *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2020-12-24 15:24:35 +00:00
|
|
|
#include <interfaces/platform.h>
|
2021-01-23 18:30:36 +00:00
|
|
|
#include <interfaces/nvmem.h>
|
2021-04-12 17:10:13 +00:00
|
|
|
#include <interfaces/audio.h>
|
2020-12-24 15:24:35 +00:00
|
|
|
#include <interfaces/gpio.h>
|
2021-01-23 18:30:36 +00:00
|
|
|
#include <calibInfo_GDx.h>
|
|
|
|
#include <ADC0_GDx.h>
|
2021-02-01 20:27:31 +00:00
|
|
|
#include <string.h>
|
2021-01-23 18:30:36 +00:00
|
|
|
#include <I2C0.h>
|
2021-03-10 12:31:49 +00:00
|
|
|
#include <pthread.h>
|
2021-04-10 12:12:15 +00:00
|
|
|
#include <backlight.h>
|
2020-12-01 08:40:50 +00:00
|
|
|
#include "hwconfig.h"
|
|
|
|
|
2021-03-10 12:31:49 +00:00
|
|
|
pthread_mutex_t adc_mutex;
|
2020-12-22 14:29:32 +00:00
|
|
|
|
2021-01-23 18:30:36 +00:00
|
|
|
gdxCalibration_t calibration;
|
2021-02-01 20:27:31 +00:00
|
|
|
hwInfo_t hwInfo;
|
2021-01-23 18:30:36 +00:00
|
|
|
|
2020-12-01 08:40:50 +00:00
|
|
|
void platform_init()
|
|
|
|
{
|
|
|
|
/* Configure GPIOs */
|
|
|
|
gpio_setMode(GREEN_LED, OUTPUT);
|
2020-12-18 17:28:00 +00:00
|
|
|
gpio_setMode(RED_LED, OUTPUT);
|
2020-12-04 09:22:57 +00:00
|
|
|
|
2020-12-18 17:28:00 +00:00
|
|
|
gpio_setMode(PTT_SW, INPUT);
|
2020-12-21 11:55:34 +00:00
|
|
|
|
2022-03-05 08:09:25 +00:00
|
|
|
#ifndef RUNNING_TESTSUITE
|
2021-02-19 10:51:05 +00:00
|
|
|
gpio_setMode(PWR_SW, OUTPUT);
|
2022-01-03 13:49:25 +00:00
|
|
|
#endif
|
2021-02-19 10:51:05 +00:00
|
|
|
|
2021-04-12 17:10:13 +00:00
|
|
|
backlight_init(); /* Initialise backlight driver */
|
|
|
|
audio_init(); /* Initialise audio management module */
|
|
|
|
adc0_init(); /* Initialise ADC */
|
2021-03-10 12:31:49 +00:00
|
|
|
pthread_mutex_init(&adc_mutex, NULL);
|
2021-01-23 18:30:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise I2C driver, once for all the modules
|
|
|
|
*/
|
|
|
|
gpio_setMode(I2C_SDA, OPEN_DRAIN);
|
|
|
|
gpio_setMode(I2C_SCL, OPEN_DRAIN);
|
|
|
|
gpio_setAlternateFunction(I2C_SDA, 3);
|
|
|
|
gpio_setAlternateFunction(I2C_SCL, 3);
|
|
|
|
i2c0_init();
|
|
|
|
|
|
|
|
/*
|
2021-03-14 16:08:12 +00:00
|
|
|
* Initialise non volatile memory manager and zero calibration data.
|
|
|
|
* Actual loading of calibration data is deferred to the first call of
|
|
|
|
* platform_getCalibrationData().
|
2021-01-23 18:30:36 +00:00
|
|
|
*/
|
|
|
|
nvm_init();
|
2021-03-14 16:08:12 +00:00
|
|
|
memset(&calibration, 0x00, sizeof(gdxCalibration_t));
|
2021-02-01 20:27:31 +00:00
|
|
|
|
|
|
|
/* Initialise hardware information structure */
|
2021-06-05 09:27:20 +00:00
|
|
|
hwInfo.vhf_maxFreq = 174;
|
|
|
|
hwInfo.vhf_minFreq = 136;
|
2021-02-01 20:27:31 +00:00
|
|
|
hwInfo.vhf_band = 1;
|
2021-06-05 09:27:20 +00:00
|
|
|
hwInfo.uhf_maxFreq = 470;
|
|
|
|
hwInfo.uhf_minFreq = 400;
|
|
|
|
hwInfo.uhf_band = 1;
|
2021-02-01 20:27:31 +00:00
|
|
|
hwInfo.lcd_type = 0;
|
|
|
|
memcpy(hwInfo.name, "GD-77", 5);
|
|
|
|
hwInfo.name[5] = '\0';
|
2020-12-01 08:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void platform_terminate()
|
|
|
|
{
|
2021-04-10 12:12:15 +00:00
|
|
|
/* Shut down backlight */
|
|
|
|
backlight_terminate();
|
|
|
|
|
2020-12-18 17:28:00 +00:00
|
|
|
gpio_clearPin(RED_LED);
|
|
|
|
gpio_clearPin(GREEN_LED);
|
2020-12-22 14:29:32 +00:00
|
|
|
|
|
|
|
adc0_terminate();
|
2021-03-10 12:31:49 +00:00
|
|
|
pthread_mutex_destroy(&adc_mutex);
|
2021-02-19 10:51:05 +00:00
|
|
|
|
2021-03-14 10:45:15 +00:00
|
|
|
i2c0_terminate();
|
2021-04-12 17:10:13 +00:00
|
|
|
audio_terminate();
|
2021-03-14 10:45:15 +00:00
|
|
|
|
2021-02-19 10:51:05 +00:00
|
|
|
/* Finally, remove power supply */
|
2021-02-19 10:58:43 +00:00
|
|
|
gpio_clearPin(PWR_SW);
|
2020-12-01 08:40:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-14 10:47:21 +00:00
|
|
|
uint16_t platform_getVbat()
|
2020-12-01 08:40:50 +00:00
|
|
|
{
|
2021-03-10 12:31:49 +00:00
|
|
|
pthread_mutex_lock(&adc_mutex);
|
2021-08-13 19:57:32 +00:00
|
|
|
uint16_t value = adc0_getMeasurement(1);
|
2021-03-10 12:31:49 +00:00
|
|
|
pthread_mutex_unlock(&adc_mutex);
|
2020-12-22 14:29:32 +00:00
|
|
|
|
2021-08-14 10:47:21 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
return value * 3;
|
2020-12-01 08:40:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 19:57:32 +00:00
|
|
|
uint8_t platform_getMicLevel()
|
2020-12-01 08:40:50 +00:00
|
|
|
{
|
2021-03-10 12:31:49 +00:00
|
|
|
pthread_mutex_lock(&adc_mutex);
|
2021-08-13 19:57:32 +00:00
|
|
|
uint16_t value = adc0_getRawSample(3);
|
2021-03-10 12:31:49 +00:00
|
|
|
pthread_mutex_unlock(&adc_mutex);
|
2020-12-22 14:29:32 +00:00
|
|
|
|
2021-08-13 19:57:32 +00:00
|
|
|
/* Value from ADC is 12 bit wide: shift right by four to get 0 - 255 */
|
|
|
|
return value >> 4;
|
2020-12-01 08:40:50 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 19:57:32 +00:00
|
|
|
uint8_t platform_getVolumeLevel()
|
2020-12-01 08:40:50 +00:00
|
|
|
{
|
|
|
|
/* TODO */
|
2021-08-13 19:57:32 +00:00
|
|
|
return 0;
|
2020-12-01 08:40:50 +00:00
|
|
|
}
|
|
|
|
|
2021-04-03 07:28:27 +00:00
|
|
|
int8_t platform_getChSelector()
|
2020-12-01 08:40:50 +00:00
|
|
|
{
|
2020-12-18 17:28:00 +00:00
|
|
|
/* GD77 does not have a channel selector */
|
2020-12-01 08:40:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool platform_getPttStatus()
|
|
|
|
{
|
2020-12-18 17:28:00 +00:00
|
|
|
/* PTT line has a pullup resistor with PTT switch closing to ground */
|
|
|
|
return (gpio_readPin(PTT_SW) == 0) ? true : false;
|
2020-12-01 08:40:50 +00:00
|
|
|
}
|
|
|
|
|
2021-04-11 10:38:20 +00:00
|
|
|
bool platform_pwrButtonStatus()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* When power knob is set to off, battery voltage measurement returns 0V.
|
2021-04-11 16:18:58 +00:00
|
|
|
* Here we set the threshold to 1V since, with knob in off position, there
|
|
|
|
* is always a bit of noise in the ADC measurement making the returned
|
|
|
|
* voltage not to be exactly zero.
|
2021-04-11 10:38:20 +00:00
|
|
|
*/
|
2021-04-11 16:18:58 +00:00
|
|
|
return (platform_getVbat() > 1.0f) ? true : false;
|
2021-04-11 10:38:20 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 08:40:50 +00:00
|
|
|
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 */
|
2020-12-18 17:28:00 +00:00
|
|
|
|
2020-12-01 08:40:50 +00:00
|
|
|
(void) freq;
|
|
|
|
}
|
|
|
|
|
|
|
|
void platform_beepStop()
|
|
|
|
{
|
|
|
|
/* TODO */
|
|
|
|
}
|
|
|
|
|
2021-01-23 18:30:36 +00:00
|
|
|
const void *platform_getCalibrationData()
|
|
|
|
{
|
2021-03-14 16:08:12 +00:00
|
|
|
/* The first time this function is called, load calibration data from flash */
|
|
|
|
if(calibration.vhfCalPoints[0] == 0)
|
|
|
|
{
|
|
|
|
nvm_readCalibData(&calibration);
|
|
|
|
}
|
|
|
|
|
2021-01-23 18:30:36 +00:00
|
|
|
return ((const void *) &calibration);
|
|
|
|
}
|
2021-02-01 20:27:31 +00:00
|
|
|
|
|
|
|
const hwInfo_t *platform_getHwInfo()
|
|
|
|
{
|
|
|
|
return &hwInfo;
|
|
|
|
}
|
2021-04-10 12:12:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: implementation of this API function is provided in
|
|
|
|
* platform/drivers/backlight/backlight_GDx.c
|
|
|
|
*/
|
|
|
|
// void platform_setBacklightLevel(uint8_t level)
|