Refactoring code of HR_C5000 driver, adding documentation and sharpening its API.

replace/34a6fd490f9d646e020706ac36c4d5fa3d6da20e
Silvano Seva 2020-11-17 17:13:09 +01:00
rodzic bd9a258541
commit 29f5b82488
4 zmienionych plików z 65 dodań i 47 usunięć

Wyświetl plik

@ -94,8 +94,6 @@ void _sendSequence(const uint8_t *seq, uint8_t len)
gpio_setPin(DMR_CS);
}
OS_ERR e;
void C5000_init()
{
gpio_setMode(DMR_CS, OUTPUT);
@ -110,7 +108,8 @@ void C5000_init()
_writeReg(0x00, 0x0A, 0x80); // Internal clock connected to crystal
_writeReg(0x00, 0x0B, 0x28); // PLL M register (multiplier)
_writeReg(0x00, 0x0C, 0x33); // PLL input and output dividers
OSTimeDly(1, OS_OPT_TIME_DLY, &e);
OS_ERR err;
OSTimeDly(1, OS_OPT_TIME_DLY, &err);
_writeReg(0x00, 0x0A, 0x00); // Internal clock connected to PLL
_writeReg(0x00, 0xBA, 0x22); // Built-in codec clock freq. (HR_C6000)
_writeReg(0x00, 0xBB, 0x11); // Output clock operating freq. (HR_C6000)
@ -126,6 +125,18 @@ void C5000_terminate()
gpio_setMode(DMR_SLEEP, INPUT);
}
void C5000_setModOffset(uint8_t offset)
{
/*
* Original TYT MD-380 code does this, both for DMR and FM.
*/
uint8_t offUpper = (offset < 0x80) ? 0x00 : 0x03;
uint8_t offLower = offset - 0x7F;
_writeReg(0x00, 0x48, offUpper); // Two-point bias, upper value
_writeReg(0x00, 0x47, offLower); // Two-point bias, lower value
}
void C5000_dmrMode()
{
// _writeReg(0x00, 0x0A, 0x80);
@ -144,11 +155,13 @@ void C5000_dmrMode()
_writeReg(0x00, 0x09, 0x00);
_writeReg(0x00, 0x06, 0x21);
_sendSequence(initSeq1, sizeof(initSeq1));
_writeReg(0x00, 0x48, 0x00);
_writeReg(0x00, 0x47, 0x1F); // This is 0x7F - freq_adj_mid */
// _writeReg(0x00, 0x48, 0x00);
// _writeReg(0x00, 0x47, 0x1F); // This is 0x7F - freq_adj_mid */
_sendSequence(initSeq2, sizeof(initSeq2));
_writeReg(0x00, 0x00, 0x28);
OSTimeDly(1, OS_OPT_TIME_DLY, &e);
OS_ERR err;
OSTimeDly(1, OS_OPT_TIME_DLY, &err);
_writeReg(0x00, 0x14, 0x59);
_writeReg(0x00, 0x15, 0xF5);
@ -197,8 +210,6 @@ void C5000_fmMode()
_sendSequence(initSeq1, sizeof(initSeq1));
_writeReg(0x00, 0x06, 0x00); // VoCoder control
_sendSequence(initSeq2, sizeof(initSeq2));
_writeReg(0x00, 0x48, 0x00); // Two-point bias, upper value
_writeReg(0x00, 0x47, 0x1F); // Two-point bias. This is 0x7F - freq_adj_mid */
_writeReg(0x00, 0x0D, 0x8C); // Codec control
_writeReg(0x00, 0x0E, 0x44); // Mute HPout and enable MIC 1
_writeReg(0x00, 0x0F, 0xC8); // ADLinVol, mic volume
@ -211,7 +222,7 @@ void C5000_fmMode()
_writeReg(0x00, 0x00, 0x28); // Reset register
}
void C5000_activateAnalogTx()
void C5000_startAnalogTx()
{
_writeReg(0x00, 0x0D, 0x8C); // Codec control
_writeReg(0x00, 0x0E, 0x44); // Mute HPout and enable MIC 1
@ -231,7 +242,7 @@ void C5000_activateAnalogTx()
_writeReg(0x00, 0x60, 0x80); // Enable analog voice transmission
}
void C5000_shutdownAnalogTx()
void C5000_stopAnalogTx()
{
_writeReg(0x00, 0x60, 0x00); // Disable both analog and DMR transmission
}

Wyświetl plik

@ -45,32 +45,35 @@ void C5000_init();
void C5000_terminate();
/**
*
* Set value for two-point modulation offset adjustment. This value usually is
* stored in radio calibration data.
* @param offset: value for modulation offset adjustment.
*/
void C5000_setModOffset(uint8_t offset);
/**
* Configure HR_C5000 chipset for DMR operation.
*/
void C5000_dmrMode();
/**
*
* Configure HR_C5000 chipset for analog FM operation.
*/
void C5000_fmMode();
/**
*
* Start analog FM transmission.
*/
void C5000_activateAnalogTx();
void C5000_startAnalogTx();
/**
*
* Stop analog FM transmission.
*/
void C5000_shutdownAnalogTx();
void C5000_stopAnalogTx();
/**
*
*/
void C5000_writeReg(uint8_t reg, uint8_t val);
/**
*
* Check if SPI common to HR_C5000 and PLL is in use by this driver.
* @retur true if SPI lines are being used by this driver.
*/
bool C5000_spiInUse();

Wyświetl plik

@ -31,11 +31,6 @@ const freq_t IF_FREQ = 49950000.0f; /* Intermediate frequency: 49.95MHz */
freq_t rxFreq = 430000000.0f;
freq_t txFreq = 430000000.0f;
void _setMod2Bias(uint16_t value)
{
DAC->DHR12R2 = value;
}
void _setApcTv(uint16_t value)
{
DAC->DHR12R1 = value;
@ -51,7 +46,6 @@ void rtx_init()
gpio_setMode(DMR_SW, OUTPUT);
gpio_setMode(WN_SW, OUTPUT);
gpio_setMode(FM_SW, OUTPUT);
// gpio_setMode(V_CS, OUTPUT);
gpio_setMode(RF_APC_SW, OUTPUT);
gpio_setMode(TX_STG_EN, OUTPUT);
gpio_setMode(RX_STG_EN, OUTPUT);
@ -61,7 +55,6 @@ void rtx_init()
gpio_clearPin(WN_SW); /* 25kHz band (?) */
gpio_clearPin(DMR_SW); /* Disconnect HR_C5000 input IF signal and audio out */
gpio_clearPin(FM_SW); /* Disconnect analog FM audio path */
// gpio_setPin(V_CS);
gpio_clearPin(RF_APC_SW); /* Disable RF power control */
gpio_clearPin(TX_STG_EN); /* Disable TX power stage */
gpio_clearPin(RX_STG_EN); /* Disable RX input stage */
@ -87,6 +80,13 @@ void rtx_init()
* Configure HR_C5000
*/
C5000_init();
/*
* Modulation bias settings
*/
const uint8_t mod2_bias = 0x60; /* TODO use calibration */
DAC->DHR12R2 = mod2_bias*4 + 0x600; /* Original FW does this */
C5000_setModOffset(mod2_bias);
}
void rtx_terminate()
@ -130,7 +130,6 @@ void rtx_setFuncmode(enum funcmode mode)
gpio_clearPin(RF_APC_SW);
gpio_setPin(VCOVCC_SW);
pll_setFrequency(rxFreq - IF_FREQ, 5);
_setMod2Bias(0x60*4 + 0x600); /* TODO use calibration */
_setApcTv(0x956); /* TODO use calibration */
gpio_setPin(RX_STG_EN);
@ -143,7 +142,6 @@ void rtx_setFuncmode(enum funcmode mode)
gpio_clearPin(VCOVCC_SW);
pll_setFrequency(txFreq, 5);
_setMod2Bias(0x60*4 + 0x600); /* TODO use calibration */
_setApcTv(0x02);
gpio_setPin(TX_STG_EN);

Wyświetl plik

@ -20,13 +20,12 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <os.h>
#include "gpio.h"
#include "delays.h"
#include "rtx.h"
#include "ADC1_MDxx380.h"
#include "graphics.h"
#include "platform.h"
#include "hwconfig.h"
#include "HR-C5000_MD3x0.h"
@ -34,7 +33,7 @@
int main(void)
{
// platform_init();
platform_init();
// toneGen_init();
// toneGen_setToneFreq(77.0f);
@ -52,24 +51,31 @@ int main(void)
rtx_setOpmode(FM);
rtx_setFuncmode(OFF);
gpio_setMode(GPIOE, 0, OUTPUT);
gpio_setMode(GPIOA, 14, OUTPUT);
gpio_setMode(GPIOA, 14, OUTPUT); /* Micpwr_sw */
gpio_setPin(GPIOA, 14);
bool txActive = false;
while (1)
{
OS_ERR err;
gpio_setPin(GPIOE, 0);
if(platform_getPttStatus() && (txActive == false))
{
rtx_setFuncmode(TX);
C5000_activateAnalogTx();
// toneGen_toneOn();
OSTimeDlyHMSM(0u, 0u, 1u, 0u, OS_OPT_TIME_HMSM_STRICT, &err);
// toneGen_toneOff();
C5000_shutdownAnalogTx();
rtx_setFuncmode(OFF);
gpio_clearPin(GPIOE, 0);
C5000_startAnalogTx();
platform_ledOn(RED);
txActive = true;
}
OSTimeDlyHMSM(0u, 0u, 3u, 0u, OS_OPT_TIME_HMSM_STRICT, &err);
if(!platform_getPttStatus() && (txActive == true))
{
rtx_setFuncmode(OFF);
C5000_stopAnalogTx();
platform_ledOff(RED);
txActive = false;
}
OS_ERR err;
OSTimeDlyHMSM(0u, 0u, 0u, 10u, OS_OPT_TIME_HMSM_STRICT, &err);
}
return 0;