Browse Source

20190713 add cmd __input_gain and __dac_gain

master
zhaijunyuan 5 years ago
parent
commit
669f813e1a
  1. 43
      lib/a3k.c
  2. 2
      lib/cmd.c
  3. 3
      targets/xc_ppf1901/ad9779.c
  4. 8
      targets/xc_ppf1901/can.c
  5. 2
      targets/xc_ppf1901/can.h
  6. 8
      targets/xc_ppf1901/lmk.c
  7. 4
      targets/xc_ppf1901/main.c

43
lib/a3k.c

@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "serial.h"
@ -8,9 +9,14 @@
#include "a3k.h"
#include "tick.h"
#include "cmd.h"
#define WAIT_TIMEOUT (100) /* 100ms */
#define RATE_PINS (6)
static uint8_t __dac_gain = 0x63;
static uint8_t __input_gain = 0x2;
struct fifo_tag {
char *pnew; /* points to newest fifo element */
char *pold; /* points to oldest fifo element */
@ -438,7 +444,8 @@ static int config_a3k(a3k_t interface, short ratet, char input_gain, char outpu
return 0;
}
static int config_a3k_codec(a3k_t interface )
static int config_a3k_codec(a3k_t interface)
{
char packet[128];
char *p = packet+4;
@ -446,17 +453,17 @@ static int config_a3k_codec(a3k_t interface )
short INPUT_GAIN;
short INPUT_SEL;
short ADCGAIN, DACGAIN;
INPUT_GAIN = 0x0;
INPUT_GAIN = __input_gain;
// INPUT_GAIN = 0x3b; // mute,24db
INPUT_SEL = 0x2;
INPUT_SEL = 0x1;
ADCGAIN = 0x3e; //20 dB
// ADCGAIN = 0x34; //10 dB
// DACGAIN = 0x7e; //20db
DACGAIN = 0x74; //6db
DACGAIN = __dac_gain; //-10db
// DACGAIN = 0x74; //0db
#if 0
/*
@ -957,3 +964,29 @@ void a3k_reset(a3k_t a3k, int baudrate)
config_a3k_codec(a3k);
start_a3k_codec(a3k, 0, 0, 0);
}
#if (TARGET_HAS_A3K_0) && (TARGET_HAS_A3K_1)
static int do_codec_dac(cmd_tbl_t s, int argc, char *argv[])
{
__dac_gain = strtoul(argv[1], NULL, 0);
a3k_setup(&a3k0, -1);
a3k_setup(&a3k1, -1);
printf("dac_gain = %x\r\n", __dac_gain);
return 0;
}
static int do_codec_ipt(cmd_tbl_t s, int argc, char *argv[])
{
__input_gain = strtoul(argv[1], NULL, 0);
a3k_setup(&a3k0, -1);
a3k_setup(&a3k1, -1);
printf("input_gain = %x\r\n",__input_gain);
return 0;
}
CON_CMD(dac, "config the dac_gain of codec", NULL, do_codec_dac);
CON_CMD(ipt, "config the input_gain of codec", NULL, do_codec_ipt);
#endif

2
lib/cmd.c

@ -28,7 +28,7 @@ enum KEY_ACTION {
TAB = 9, /* Tab */
CTRL_K = 11, /* Ctrl+k */
CTRL_L = 12, /* Ctrl+l */
ENTER = 13, /* Enter */
ENTER = 13, /* Enter */
CTRL_N = 14, /* Ctrl-n */
CTRL_P = 16, /* Ctrl-p */
CTRL_T = 20, /* Ctrl-t */

3
targets/xc_ppf1901/ad9779.c

@ -282,7 +282,8 @@ static void callback(struct timer_list *it, void *user)
if (strcmp(ca->argv[0], "adr") == 0) {
do_9779_read(NULL, ca->argc, ca->argv);
} else {
} else if(strcmp(ca->argv[0], "9361_r") == 0){
do_9361_read(NULL, ca->argc, ca->argv);
}
}

8
targets/xc_ppf1901/can.c

@ -132,8 +132,12 @@ void __can_setup()
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
CAN_InitStructure.CAN_BS1 = CAN_BS1_3tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_1tq;
//CAN_InitStructure.CAN_BS1 = CAN_BS1_3tq;
//CAN_InitStructure.CAN_BS2 = CAN_BS2_1tq;
//CAN_InitStructure.CAN_Prescaler = 9;
CAN_InitStructure.CAN_BS1 = 2;
CAN_InitStructure.CAN_BS2 = 0;
CAN_InitStructure.CAN_Prescaler = 9;
printf("IN BS1=%d, BS2=%d, prescaler=%d\r\n", CAN_InitStructure.CAN_BS1, CAN_InitStructure.CAN_BS2, CAN_InitStructure.CAN_Prescaler);

2
targets/xc_ppf1901/can.h

@ -1,7 +1,7 @@
#ifndef CAN_H
#define CAN_H
void can_setup();
void __can_setup();
int can_test();
#endif

8
targets/xc_ppf1901/lmk.c

@ -23,7 +23,7 @@ static reg_cfg_t lmk1regs[] = {
{0x0006, 0x00},
{0x000C, 0x51},
{0x000D, 0x04},
{0x0100, 0x06},
{0x0100, 0x03},
{0x0101, 0x65},
{0x0102, 0x55},
{0x0103, 0x01},
@ -63,14 +63,14 @@ static reg_cfg_t lmk1regs[] = {
{0x0125, 0x00},
{0x0126, 0x00},
{0x0127, 0x11},
{0x0128, 0x0c},
{0x0128, 0x06},
{0x0129, 0x55},
{0x012A, 0x55},
{0x012B, 0x00},
{0x012C, 0x22},
{0x012D, 0x00},
{0x012E, 0x40},
{0x012F, 0x11},
{0x012F, 0x15},
{0x0130, 0x1E},
{0x0131, 0x55},
{0x0132, 0x55},
@ -82,7 +82,7 @@ static reg_cfg_t lmk1regs[] = {
{0x0138, 0x26},
{0x0139, 0x03},
{0x013A, 0x00},
{0x013B, 0x18},
{0x013B, 0xc0},
{0x013C, 0x00},
{0x013D, 0x00},
{0x013E, 0x00},

4
targets/xc_ppf1901/main.c

@ -80,7 +80,7 @@ int main()
max6884_init();
/******************************************/
// __can_setup();
__can_setup();
ad9779_init();
while (1) {
@ -110,7 +110,7 @@ int main()
}
/***************************************************************/
// can_test();
can_test();
#endif
prev = now;
}

Loading…
Cancel
Save