Skip to content

Commit

Permalink
Merge branch 'revision-cmd'
Browse files Browse the repository at this point in the history
  • Loading branch information
edy555 committed Jun 26, 2018
2 parents ccdd91d + 08a7b11 commit 4900877
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 41 deletions.
21 changes: 12 additions & 9 deletions NANOSDR_STM32_F303/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

/* on-board */

#define GPIOA_PUSH_BUTTON 0
#define GPIOA_USART2_TX 2
#define GPIOA_USART2_RX 3
#define GPIOA_DAC1 4
Expand All @@ -58,6 +59,8 @@
#define GPIOA_JTMS 13
#define GPIOA_JTCK 14

#define GPIOB_ENC_PHASEA 1
#define GPIOB_ENC_PHASEB 2
#define GPIOB_SPI3_SCK 3
#define GPIOB_SPI3_MISO 4
#define GPIOB_SPI3_MOSI 5
Expand Down Expand Up @@ -115,7 +118,7 @@
* PA14 - SWCLK (alternate 0).
*/
#define VAL_GPIOA_MODER (PIN_MODE_INPUT(0U) | \
PIN_MODE_INPUT(1U) | \
PIN_MODE_OUTPUT(1U) | \
PIN_MODE_ALTERNATE(GPIOA_USART2_TX) | \
PIN_MODE_ALTERNATE(GPIOA_USART2_RX) | \
PIN_MODE_INPUT(4U) | \
Expand Down Expand Up @@ -146,8 +149,8 @@
PIN_OTYPE_PUSHPULL(GPIOA_JTMS) | \
PIN_OTYPE_PUSHPULL(GPIOA_JTCK) | \
PIN_OTYPE_PUSHPULL(15))
#define VAL_GPIOA_OSPEEDR (PIN_OSPEED_100M(0) | \
PIN_OSPEED_100M(1) | \
#define VAL_GPIOA_OSPEEDR (PIN_OSPEED_2M(0) | \
PIN_OSPEED_2M(1) | \
PIN_OSPEED_50M(GPIOA_USART2_TX) | \
PIN_OSPEED_50M(GPIOA_USART2_RX) | \
PIN_OSPEED_100M(4) | \
Expand All @@ -162,8 +165,8 @@
PIN_OSPEED_100M(GPIOA_JTMS) | \
PIN_OSPEED_100M(GPIOA_JTCK) | \
PIN_OSPEED_100M(15))
#define VAL_GPIOA_PUPDR (PIN_PUPDR_PULLDOWN(0) | \
PIN_PUPDR_PULLDOWN(1) | \
#define VAL_GPIOA_PUPDR (PIN_PUPDR_PULLDOWN(0) | \
PIN_PUPDR_FLOATING(1) | \
PIN_PUPDR_FLOATING(GPIOA_USART2_TX) | \
PIN_PUPDR_FLOATING(GPIOA_USART2_RX) | \
PIN_PUPDR_PULLUP(4) | \
Expand Down Expand Up @@ -224,7 +227,7 @@
* PB14 - I2S2_MISO (alternate 5).
* PB15 - I2S2_MOSI (alternate 5).
*/
#define VAL_GPIOB_MODER (PIN_MODE_INPUT(0) | \
#define VAL_GPIOB_MODER (PIN_MODE_OUTPUT(0) | \
PIN_MODE_INPUT(1) | \
PIN_MODE_INPUT(2) | \
PIN_MODE_ALTERNATE(GPIOB_SPI3_SCK) | \
Expand Down Expand Up @@ -256,7 +259,7 @@
PIN_OTYPE_PUSHPULL(GPIOB_I2S2_BCLK) | \
PIN_OTYPE_PUSHPULL(GPIOB_I2S2_MISO) | \
PIN_OTYPE_PUSHPULL(GPIOB_I2S2_MOSI))
#define VAL_GPIOB_OSPEEDR (PIN_OSPEED_100M(0) | \
#define VAL_GPIOB_OSPEEDR (PIN_OSPEED_2M(0) | \
PIN_OSPEED_100M(1) | \
PIN_OSPEED_100M(2) | \
PIN_OSPEED_100M(3) | \
Expand All @@ -272,10 +275,10 @@
PIN_OSPEED_100M(GPIOB_I2S2_BCLK) | \
PIN_OSPEED_100M(GPIOB_I2S2_MISO) | \
PIN_OSPEED_100M(GPIOB_I2S2_MOSI))
#define VAL_GPIOB_PUPDR (PIN_PUPDR_PULLDOWN(0) | \
#define VAL_GPIOB_PUPDR (PIN_PUPDR_FLOATING(0) | \
PIN_PUPDR_PULLDOWN(1) | \
PIN_PUPDR_PULLDOWN(2) | \
PIN_PUPDR_PULLUP(3) | \
PIN_PUPDR_PULLUP(3) | \
PIN_PUPDR_PULLUP(4) | \
PIN_PUPDR_PULLUP(5) | \
PIN_PUPDR_PULLUP(6) | \
Expand Down
82 changes: 72 additions & 10 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <stm32f303xc.h>



static struct {
int32_t rms[2];
int16_t ave[2];
Expand Down Expand Up @@ -169,7 +168,9 @@ config_t config = {
{ 11330000, MOD_USB },
{ 13273000, MOD_USB },
{ 17904000, MOD_USB }
}
},
.button_polarity = 0x01,
.freq_inverse = -1
};

struct {
Expand Down Expand Up @@ -441,7 +442,6 @@ static void cmd_stat(BaseSequentialStream *chp, int argc, char *argv[])
#endif
}


static void cmd_power(BaseSequentialStream *chp, int argc, char *argv[])
{
(void)argc;
Expand All @@ -465,18 +465,22 @@ static void cmd_impedance(BaseSequentialStream *chp, int argc, char *argv[])
static void cmd_gain(BaseSequentialStream *chp, int argc, char *argv[])
{
int gain;
if (argc != 1 && argc != 2) {
chprintf(chp, "usage: gain {pga gain(0-95)} {digital gain(-24-40)}\r\n");
if (argc != 1 && argc != 2 && argc != 3) {
chprintf(chp, "usage: gain {pga gain(0-95)} [digital gain(-24-40)] [adjust]\r\n");
return;
}

gain = atoi(argv[0]);
tlv320aic3204_set_gain(gain);
tlv320aic3204_set_gain(gain, gain);
uistat.rfgain = gain;

if (argc == 2) {
if (argc >= 2) {
int adjust = 0;
gain = atoi(argv[1]);
tlv320aic3204_set_digital_gain(gain);
if (argc == 3) {
adjust = atoi(argv[2]);
}
tlv320aic3204_set_digital_gain(gain, gain + adjust);
uistat.rfgain += gain;
}

Expand All @@ -495,6 +499,30 @@ static void cmd_phase(BaseSequentialStream *chp, int argc, char *argv[])
tlv320aic3204_set_adc_phase_adjust(value);
}

static void cmd_finegain(BaseSequentialStream *chp, int argc, char *argv[])
{
int g1 = 0, g2 = 0;
if (argc != 1 && argc != 2) {
chprintf(chp, "usage: gainadjust {gain1 gain2} (0 - -4)\r\n");
return;
}
g1 = atoi(argv[0]);
if (argc == 2) {
g2 = atoi(argv[1]);
}
tlv320aic3204_set_adc_fine_gain_adjust(g1, g2);
}

static void cmd_iqbal(BaseSequentialStream *chp, int argc, char *argv[])
{
if (argc != 1) {
chprintf(chp, "usage: iqbal {coeff}\r\n");
return;
}
double value = config.freq_inverse - (double)atoi(argv[0]) / 10000.0;
tlv320aic3204_config_adc_filter2(value);
}

static void cmd_volume(BaseSequentialStream *chp, int argc, char *argv[])
{
int gain;
Expand Down Expand Up @@ -750,6 +778,28 @@ static void cmd_channel(BaseSequentialStream *chp, int argc, char *argv[])
}
}

static void cmd_revision(BaseSequentialStream *chp, int argc, char *argv[])
{
if (argc == 0) {
chprintf(chp, "usage: revision {rev}\r\n");
return;
}
int rev = atoi(argv[0]);
switch (rev) {
case 0:
config.freq_inverse = 1;
config.button_polarity = 0x00;
break;
case 1:
config.freq_inverse = -1;
config.button_polarity = 0x01;
break;
default:
chprintf(chp, "unknown revision\r\n");
break;
}
}

static void cmd_save(BaseSequentialStream *chp, int argc, char *argv[])
{
(void)argc;
Expand Down Expand Up @@ -807,6 +857,7 @@ static const ShellCommand commands[] =
{ "gain", cmd_gain },
{ "volume", cmd_volume },
{ "agc", cmd_agc },
{ "iqbal", cmd_iqbal },
{ "dcreject", cmd_dcreject },
{ "imp", cmd_impedance },
{ "mode", cmd_mode },
Expand All @@ -815,9 +866,11 @@ static const ShellCommand commands[] =
{ "show", cmd_show },
{ "power", cmd_power },
{ "channel", cmd_channel },
{ "revision", cmd_revision },
{ "save", cmd_save },
{ "clearconfig", cmd_clearconfig },
{ "phase", cmd_phase },
{ "finegain", cmd_finegain },
{ NULL, NULL }
};

Expand Down Expand Up @@ -876,6 +929,12 @@ int __attribute__((noreturn)) main(void)
/* restore config */
config_recall();

if (config.button_polarity != 0) {
// pullup for revision 1 board
palSetGroupMode(GPIOA, 1, 0, PAL_MODE_INPUT_PULLUP);
palSetGroupMode(GPIOB, 6, 0, PAL_MODE_INPUT_PULLUP);
}

// copy uistat from uistat
uistat = config.uistat;

Expand Down Expand Up @@ -917,6 +976,7 @@ int __attribute__((noreturn)) main(void)
* I2S Initialize
*/
tlv320aic3204_init();

i2sInit();
i2sObjectInit(&I2SD2);
i2sStart(&I2SD2, &i2sconfig);
Expand All @@ -942,7 +1002,6 @@ int __attribute__((noreturn)) main(void)
* Shell manager initialization.
*/
shellInit();
tlv320aic3204_config_adc_filter(1); // enable DC reject

/*
* Creates the blinker thread.
Expand All @@ -952,7 +1011,10 @@ int __attribute__((noreturn)) main(void)
#if 1
ui_init();
#endif


tlv320aic3204_config_adc_filter2(config.freq_inverse /* + 0.129 */); // enable DC reject
//tlv320aic3204_config_adc_filter(1); // enable DC reject

/*
* Creates the button thread.
*/
Expand Down
9 changes: 6 additions & 3 deletions nanosdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,22 @@ typedef struct {
} tlv320aic3204_agc_config_t;

extern void tlv320aic3204_init(void);
extern void tlv320aic3204_set_gain(int gain);
extern void tlv320aic3204_set_digital_gain(int gain);
extern void tlv320aic3204_set_gain(int g1, int g2);
extern void tlv320aic3204_set_digital_gain(int g1, int g2);
extern void tlv320aic3204_set_volume(int gain);
extern void tlv320aic3204_agc_config(tlv320aic3204_agc_config_t *conf);
extern void tlv320aic3204_set_fs(int fs);
extern void tlv320aic3204_stop(void);

extern void tlv320aic3204_config_adc_filter(int enable);
extern void tlv320aic3204_config_adc_filter2(double iqbal);
extern void tlv320aic3204_set_impedance(int imp);

extern int tlv320aic3204_get_sticky_flag_register(void);
extern int8_t tlv320aic3204_get_left_agc_gain(void);
extern int8_t tlv320aic3204_get_right_agc_gain(void);
extern void tlv320aic3204_set_adc_phase_adjust(int8_t adjust);
extern void tlv320aic3204_set_adc_fine_gain_adjust(int8_t g1, int8_t g2);

extern void tlv320aic3204_beep(void);

Expand Down Expand Up @@ -263,6 +265,8 @@ typedef struct {
tlv320aic3204_agc_config_t agc;
channel_t channels[CHANNEL_MAX];
uistat_t uistat;
int8_t freq_inverse;
uint8_t button_polarity;
int32_t checksum;
} config_t;

Expand All @@ -275,5 +279,4 @@ int config_recall(void);

void clear_all_config_prop_data(void);


/*EOF*/
Loading

0 comments on commit 4900877

Please sign in to comment.