arrange code, add notice at head of each file

This commit is contained in:
TT 2017-01-01 20:03:21 +09:00
parent 1c3f2df97a
commit 74cfdb93a3
12 changed files with 350 additions and 276 deletions

19
adc.c
View file

@ -1,3 +1,22 @@
/*
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
* All rights reserved.
*
* This 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, or (at your option)
* any later version.
*
* The software 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "ch.h"
#include "hal.h"
#include "nanovna.h"

64
dsp.c
View file

@ -1,12 +1,41 @@
/*
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
* All rights reserved.
*
* This 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, or (at your option)
* any later version.
*
* The software 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include <arm_math.h>
#include "nanovna.h"
int16_t ref_state[STATE_LEN];
int16_t ref_buf[SAMPLE_LEN];
//int16_t refq_buf[SAMPLE_LEN];
int16_t refiq_buf[AUDIO_BUFFER_LEN];
/*
* (I2S DMA)
* |
* [capture]
* | \
* [ref_state,ref_buf] [samp_buf]
* | hilbert_transform
* [refiq_buf]
*/
int16_t samp_buf[SAMPLE_LEN];
int16_t ref_state[STATE_LEN];
int16_t ref_buf[SAMPLE_LEN];
int16_t refiq_buf[AUDIO_BUFFER_LEN];
#if 0
// Bi-Quad IIR Filter state
@ -32,7 +61,6 @@ static void
hilbert_transform(void)
{
__SIMD32_TYPE *src = __SIMD32_CONST(ref_state);
//__SIMD32_TYPE *dst = __SIMD32_CONST(refq_buf);
__SIMD32_TYPE *dst = __SIMD32_CONST(refiq_buf);
int j;
@ -76,31 +104,6 @@ hilbert_transform(void)
}
void calculate_gamma(float *gamma)
#if 0
{
__SIMD32_TYPE *r = __SIMD32_CONST(refiq_buf);
__SIMD32_TYPE *s = __SIMD32_CONST(samp_buf);
q31_t acc_r = 0;
q31_t acc_i = 0;
q31_t acc_ref = 0;
int i;
for (i = 0; i < SAMPLE_LEN/2; i++) {
__SIMD32_TYPE s0 = *s++;
__SIMD32_TYPE r0 = *r++;
__SIMD32_TYPE r1 = *r++;
__SIMD32_TYPE rr = __PKHBT(r1, r0, 16);
__SIMD32_TYPE ri = __PKHTB(r0, r1, 16);
acc_r = __SMLAD(rr, s0, acc_r);
acc_i = __SMLAD(ri, s0, acc_i);
acc_ref = __SMLAD(r0, r0, acc_ref);
acc_ref = __SMLAD(r1, r1, acc_ref);
}
//acc_ref = sqrt(acc_ref / SAMPLE_LEN) / 65536;
gamma_real = acc_r / 65536;
gamma_imag = acc_i / 65536;
}
#else
{
int16_t *r = refiq_buf;
int16_t *s = samp_buf;
@ -143,7 +146,6 @@ void calculate_gamma(float *gamma)
gamma[0] = -acc_r / rn;
gamma[1] = -acc_i / rn;
}
#endif
void
dsp_process(int16_t *capture, size_t length)

19
flash.c
View file

@ -1,3 +1,22 @@
/*
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
* All rights reserved.
*
* This 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, or (at your option)
* any later version.
*
* The software 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "ch.h"
#include "hal.h"
#include "nanovna.h"

View file

@ -1,3 +1,22 @@
/*
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
* All rights reserved.
*
* This 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, or (at your option)
* any later version.
*
* The software 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "ch.h"
#include "hal.h"
#include "nanovna.h"

108
main.c
View file

@ -1,3 +1,23 @@
/*
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
* All rights reserved.
*
* This 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, or (at your option)
* any later version.
*
* The software 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "ch.h"
#include "hal.h"
#include "usbcfg.h"
@ -11,64 +31,26 @@
#include <ctype.h>
#include <math.h>
RTCDateTime timespec;
static void apply_error_term(void);
static const I2CConfig i2ccfg = {
0x00300506, //voodoo magic 400kHz @ HSI 8MHz
//0x00902025, //voodoo magic
//0x00420F13, // 100kHz @ 72MHz
0,
0
};
void I2CWrite(int addr, uint8_t d0, uint8_t d1)
{
uint8_t buf[] = { d0, d1 };
i2cAcquireBus(&I2CD1);
(void)i2cMasterTransmitTimeout(&I2CD1, addr, buf, 2, NULL, 0, 1000);
i2cReleaseBus(&I2CD1);
}
int I2CRead(int addr, uint8_t d0)
{
uint8_t buf[] = { d0 };
i2cAcquireBus(&I2CD1);
i2cMasterTransmitTimeout(&I2CD1, addr, buf, 1, buf, 1, 1000);
i2cReleaseBus(&I2CD1);
return buf[0];
}
void scan_lcd(void);
static MUTEX_DECL(mutex);
int32_t frequency_offset = 5000;
int32_t frequency = 10000000;
uint8_t drive_strength = SI5351_CLK_DRIVE_STRENGTH_2MA;
static THD_WORKING_AREA(waThread1, 440);
static THD_FUNCTION(Thread1, arg)
{
(void)arg;
chRegSetThreadName("blink");
//palSetPadMode(GPIOC, 13, PAL_MODE_OUTPUT_PUSHPULL);
while (1)
{
#if 0
systime_t time = 500;
if (serusbcfg.usbp->state != USB_ACTIVE)
palClearPad(GPIOC, 13);
chThdSleepMilliseconds(time);
palSetPad(GPIOC, 13);
chThdSleepMilliseconds(time);
#else
while (1) {
chMtxLock(&mutex);
scan_lcd();
chMtxUnlock(&mutex);
//ui_process();
#endif
}
}
@ -112,27 +94,17 @@ static void cmd_reset(BaseSequentialStream *chp, int argc, char *argv[])
WWDG->CFR = 0x60;
WWDG->CR = 0xff;
/* wait forever */
while (1)
;
;
}
int32_t frequency_offset = 5000;
int32_t frequency = 10000000;
uint8_t drive_strength = SI5351_CLK_DRIVE_STRENGTH_2MA;
int set_frequency(int freq)
{
#if 0
si5351_set_frequency(0, freq + frequency_offset);
si5351_set_frequency(1, freq);
frequency = freq;
#else
int delay;
delay = si5351_set_frequency_with_offset(freq, frequency_offset, drive_strength);
frequency = freq;
return delay;
#endif
}
static void cmd_offset(BaseSequentialStream *chp, int argc, char *argv[])
@ -145,7 +117,6 @@ static void cmd_offset(BaseSequentialStream *chp, int argc, char *argv[])
set_frequency(frequency);
}
static void cmd_freq(BaseSequentialStream *chp, int argc, char *argv[])
{
int freq;
@ -168,10 +139,9 @@ static void cmd_power(BaseSequentialStream *chp, int argc, char *argv[])
set_frequency(frequency);
}
static void cmd_time(BaseSequentialStream *chp, int argc, char *argv[])
{
RTCDateTime timespec;
(void)argc;
(void)argv;
rtcGetTime(&RTCD1, &timespec);
@ -179,12 +149,6 @@ static void cmd_time(BaseSequentialStream *chp, int argc, char *argv[])
}
static const DACConfig dac1cfg1 = {
//init: 2047U,
init: 1922U,
datamode: DAC_DHRM_12BIT_RIGHT
};
static void cmd_dac(BaseSequentialStream *chp, int argc, char *argv[])
{
int value;
@ -1322,6 +1286,18 @@ static const ShellConfig shell_cfg1 =
commands
};
static const I2CConfig i2ccfg = {
0x00300506, //voodoo magic 400kHz @ HSI 8MHz
0,
0
};
static const DACConfig dac1cfg1 = {
//init: 2047U,
init: 1922U,
datamode: DAC_DHRM_12BIT_RIGHT
};
int main(void)
{
halInit();
@ -1397,16 +1373,12 @@ int main(void)
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
//set_frequency(10000000);
while (1) {
if (SDU1.config->usbp->state == USB_ACTIVE) {
//palSetPad(GPIOC, GPIOC_LED);
thread_t *shelltp = chThdCreateStatic(waThread2, sizeof(waThread2),
NORMALPRIO + 1,
shellThread, (void *)&shell_cfg1);
chThdWait(shelltp); /* Waiting termination. */
//palClearPad(GPIOC, GPIOC_LED);
}
chThdSleepMilliseconds(1000);

157
nanovna.h
View file

@ -1,29 +1,63 @@
/*
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
* All rights reserved.
*
* This 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, or (at your option)
* any later version.
*
* The software 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "ch.h"
/*
* tlv320aic3204.c
* main.c
*/
extern void I2CWrite(int addr, uint8_t d0, uint8_t d1);
extern float measured[2][101][2];
typedef struct {
int target_level;
int gain_hysteresis;
int attack;
int attack_scale;
int decay;
int decay_scale;
} tlv320aic3204_agc_config_t;
#define CAL_LOAD 0
#define CAL_OPEN 1
#define CAL_SHORT 2
#define CAL_THRU 3
#define CAL_ISOLN 4
extern void tlv320aic3204_init(void);
extern void tlv320aic3204_set_gain(int lgain, int rgain);
extern void tlv320aic3204_set_digital_gain(int gain);
extern void tlv320aic3204_set_volume(int gain);
extern void tlv320aic3204_agc_config(tlv320aic3204_agc_config_t *conf);
extern void tlv320aic3204_select_in1(void);
extern void tlv320aic3204_select_in3(void);
extern void tlv320aic3204_adc_filter_enable(int enable);
#define CALSTAT_LOAD (1<<0)
#define CALSTAT_OPEN (1<<1)
#define CALSTAT_SHORT (1<<2)
#define CALSTAT_THRU (1<<3)
#define CALSTAT_ISOLN (1<<4)
#define CALSTAT_ES (1<<5)
#define CALSTAT_ER (1<<6)
#define CALSTAT_ET (1<<7)
#define CALSTAT_ED CALSTAT_LOAD
#define CALSTAT_EX CALSTAT_ISOLN
#define CALSTAT_APPLY (1<<8)
#define ETERM_ED 0 /* error term directivity */
#define ETERM_ES 1 /* error term source match */
#define ETERM_ER 2 /* error term refrection tracking */
#define ETERM_ET 3 /* error term transmission tracking */
#define ETERM_EX 4 /* error term isolation */
void cal_collect(int type);
void cal_done(void);
enum {
ST_START, ST_STOP, ST_CENTER, ST_SPAN, ST_CW
};
void set_sweep_frequency(int type, int frequency);
float my_atof(const char *p);
/*
* ui.c
@ -55,30 +89,27 @@ void calculate_gamma(float *gamma);
int si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength);
#define RGB565(b,r,g) ( (((b)<<8)&0xfc00) | (((r)<<2)&0x03e0) | (((g)>>3)&0x001f) )
/*
* ili9341.c
* tlv320aic3204.c
*/
typedef struct {
uint16_t width;
uint16_t height;
uint16_t scaley;
uint16_t slide;
const uint32_t *bitmap;
} font_t;
int target_level;
int gain_hysteresis;
int attack;
int attack_scale;
int decay;
int decay_scale;
} tlv320aic3204_agc_config_t;
extern const font_t NF20x24;
extern uint16_t spi_buffer[1024];
void ili9341_init(void);
void ili9341_test(int mode);
void ili9341_bulk(int x, int y, int w, int h);
void ili9341_fill(int x, int y, int w, int h, int color);
void ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg);
void ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg);
void ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg);
extern void tlv320aic3204_init(void);
extern void tlv320aic3204_set_gain(int lgain, int rgain);
extern void tlv320aic3204_set_digital_gain(int gain);
extern void tlv320aic3204_set_volume(int gain);
extern void tlv320aic3204_agc_config(tlv320aic3204_agc_config_t *conf);
extern void tlv320aic3204_select_in1(void);
extern void tlv320aic3204_select_in3(void);
extern void tlv320aic3204_adc_filter_enable(int enable);
/*
@ -167,44 +198,30 @@ void markmap_all_markers(void);
/*
* main.c
* ili9341.c
*/
extern float measured[2][101][2];
#define RGB565(b,r,g) ( (((b)<<8)&0xfc00) | (((r)<<2)&0x03e0) | (((g)>>3)&0x001f) )
#define CAL_LOAD 0
#define CAL_OPEN 1
#define CAL_SHORT 2
#define CAL_THRU 3
#define CAL_ISOLN 4
typedef struct {
uint16_t width;
uint16_t height;
uint16_t scaley;
uint16_t slide;
const uint32_t *bitmap;
} font_t;
#define CALSTAT_LOAD (1<<0)
#define CALSTAT_OPEN (1<<1)
#define CALSTAT_SHORT (1<<2)
#define CALSTAT_THRU (1<<3)
#define CALSTAT_ISOLN (1<<4)
#define CALSTAT_ES (1<<5)
#define CALSTAT_ER (1<<6)
#define CALSTAT_ET (1<<7)
#define CALSTAT_ED CALSTAT_LOAD
#define CALSTAT_EX CALSTAT_ISOLN
#define CALSTAT_APPLY (1<<8)
extern const font_t NF20x24;
#define ETERM_ED 0 /* error term directivity */
#define ETERM_ES 1 /* error term source match */
#define ETERM_ER 2 /* error term refrection tracking */
#define ETERM_ET 3 /* error term transmission tracking */
#define ETERM_EX 4 /* error term isolation */
extern uint16_t spi_buffer[1024];
void cal_collect(int type);
void cal_done(void);
void ili9341_init(void);
void ili9341_test(int mode);
void ili9341_bulk(int x, int y, int w, int h);
void ili9341_fill(int x, int y, int w, int h, int color);
void ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg);
void ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg);
void ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg);
enum {
ST_START, ST_STOP, ST_CENTER, ST_SPAN, ST_CW
};
void set_sweep_frequency(int type, int frequency);
float my_atof(const char *p);
/*
* flash.c

89
plot.c
View file

@ -15,14 +15,22 @@ void markmap_all_markers(void);
//#define GRID_COLOR 0x0863
uint16_t grid_color = 0x1084;
#if 0
trace_t trace[TRACES_MAX] = {
{ 1, TRC_LOGMAG, 0, 1.0, RGB565(0,255,255), 0 },
{ 1, TRC_LOGMAG, 1, 1.0, RGB565(255,0,40), 0 },
{ 1, TRC_SMITH, 0, 1.0, RGB565(0,0,255), 1 },
{ 1, TRC_PHASE, 1, 1.0, RGB565(50,255,0), 1 }
};
#endif
/* indicate dirty cells */
uint16_t markmap[2][8];
uint16_t current_mappage = 0;
int32_t fgrid = 50000000;
int16_t grid_offset;
int16_t grid_width;
int area_width = WIDTH;
int area_height = HEIGHT;
#define GRID_RECTANGULAR (1<<0)
#define GRID_SMITH (1<<1)
#define GRID_ADMIT (1<<2)
#define GRID_POLAR (1<<3)
#define CELLWIDTH 32
#define CELLHEIGHT 32
@ -49,23 +57,6 @@ uint32_t trace_index[TRACES_MAX][101];
#define CELL_P(i, x, y) (((((x)&0x03e0UL)<<22) | (((y)&0x03e0UL)<<17)) == ((i)&0xffc00000UL))
/* indicate dirty cells */
uint16_t markmap[2][8];
uint16_t current_mappage = 0;
#if 0
marker_t markers[4] = {
{ 1, 30 }, { 0, 40 }, { 0, 60 }, { 0, 80 }
};
int active_marker = 0;
#endif
int32_t fgrid = 50000000;
int16_t grid_offset;
int16_t grid_width;
void update_grid(void)
{
@ -185,7 +176,6 @@ smith_grid(int x, int y)
// shift circle center to right origin
x -= P_RADIUS;
// Constant Reactance Circle: 2j : R/2 = 58
if (circle_inout(x, y+58, 58) == 0)
return c;
@ -641,46 +631,6 @@ trace_get_info(int t, char *buf, int len)
}
}
#if 0
void insertionsort(uint32_t *arr, int start, int end)
{
int i;
for (i = start + 1; i < end; i++) {
uint32_t val = arr[i];
int j = i - 1;
while (j >= start && val > arr[j]) {
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = val;
}
}
void quicksort(uint32_t *arr, int beg, int end)
{
if (end - beg <= 1)
return;
else if (end - beg < 10) {
insertionsort(arr, beg, end);
} else {
int l = beg;
int r = end-1;
uint32_t piv = arr[(beg + end) / 2];
while (l < r) {
while (arr[l] < piv)
l++;
while (arr[r] > piv)
r--;
if (l < r)
SWAP(arr[l], arr[r]);
}
quicksort(arr, beg, l);
quicksort(arr, r, end);
}
}
#endif
static inline void
mark_map(int x, int y)
{
@ -990,13 +940,6 @@ markmap_all_markers(void)
markmap_upperarea();
}
int area_width = WIDTH;
int area_height = HEIGHT;
#define GRID_RECTANGULAR (1<<0)
#define GRID_SMITH (1<<1)
#define GRID_ADMIT (1<<2)
#define GRID_POLAR (1<<3)
void
draw_cell(int m, int n)

View file

@ -1,10 +1,27 @@
/*
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
* All rights reserved.
*
* This 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, or (at your option)
* any later version.
*
* The software 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "hal.h"
#include "si5351.h"
#define SI5351_I2C_ADDR (0x60<<1)
extern int I2CWrite(int addr, char d0, char d1);
static void
si5351_write(uint8_t reg, uint8_t dat)
{

View file

@ -1,3 +1,22 @@
/*
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
* All rights reserved.
*
* This 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, or (at your option)
* any later version.
*
* The software 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#define SI5351_PLL_A 0
#define SI5351_PLL_B 1

View file

@ -1,3 +1,22 @@
/*
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
* All rights reserved.
*
* This 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, or (at your option)
* any later version.
*
* The software 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "hal.h"
#include "si5351.h"

View file

@ -1,7 +1,25 @@
/*
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
* All rights reserved.
*
* This 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, or (at your option)
* any later version.
*
* The software 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "hal.h"
#include "nanovna.h"
#define REFCLK_8000KHZ
#define AIC3204_ADDR 0x18
@ -9,6 +27,14 @@
void tlv320aic3204_config_adc_filter(void);
static void I2CWrite(int addr, uint8_t d0, uint8_t d1)
{
uint8_t buf[] = { d0, d1 };
i2cAcquireBus(&I2CD1);
(void)i2cMasterTransmitTimeout(&I2CD1, addr, buf, 2, NULL, 0, 1000);
i2cReleaseBus(&I2CD1);
}
void tlv320aic3204_init(void)
{
I2CWrite(AIC3204_ADDR, 0x00, 0x00); /* Initialize to Page 0 */

64
ui.c
View file

@ -23,12 +23,14 @@
#include "nanovna.h"
#include <stdlib.h>
struct {
int digit; /* 0~5 */
int current_trace; /* 0..3 */
} uistat;
#define NO_EVENT 0
#define EVT_BUTTON_SINGLE_CLICK 0x01
#define EVT_BUTTON_DOUBLE_CLICK 0x02
@ -69,21 +71,46 @@ uint8_t ui_mode = UI_NORMAL;
uint8_t keypad_mode;
uint8_t selection = 0;
void ui_mode_normal(void);
void ui_mode_menu(void);
void ui_mode_keypad(int _keypad_mode);
void draw_menu(void);
void erase_menu_buttons(void);
typedef struct {
uint8_t type;
char *label;
const void *reference;
} menuitem_t;
int8_t last_touch_status = FALSE;
int16_t last_touch_x;
int16_t last_touch_y;
//int16_t touch_cal[4] = { 1000, 1000, 10*16, 12*16 };
int16_t touch_cal[4] = { 620, 600, 130, 180 };
#define EVT_TOUCH_NONE 0
#define EVT_TOUCH_DOWN 1
#define EVT_TOUCH_PRESSED 2
#define EVT_TOUCH_RELEASED 3
int awd_count;
int touch_x, touch_y;
#define NUMINPUT_LEN 10
#define KP_CONTINUE 0
#define KP_DONE 1
#define KP_CANCEL 2
char kp_buf[11];
int8_t kp_index = 0;
void ui_mode_normal(void);
void ui_mode_menu(void);
void ui_mode_keypad(int _keypad_mode);
void draw_menu(void);
void erase_menu_buttons(void);
void ui_process_keypad(void);
static void menu_push_submenu(const menuitem_t *submenu);
static int btn_check(void)
{
int cur_button = READ_PORT() & BUTTON_MASK;
@ -214,16 +241,6 @@ touch_status(void)
return adc_single_read(ADC1, ADC_CHSELR_CHSEL7) > TOUCH_THRESHOLD;
}
int8_t last_touch_status = FALSE;
int16_t last_touch_x;
int16_t last_touch_y;
//int16_t touch_cal[4] = { 1000, 1000, 10*16, 12*16 };
int16_t touch_cal[4] = { 620, 600, 130, 180 };
#define EVT_TOUCH_NONE 0
#define EVT_TOUCH_DOWN 1
#define EVT_TOUCH_PRESSED 2
#define EVT_TOUCH_RELEASED 3
int touch_check(void)
{
int stat = touch_status();
@ -427,8 +444,6 @@ choose_active_marker(void)
active_marker = -1;
}
void ui_process_keypad(void);
static void
menu_scale_cb(int item)
{
@ -910,14 +925,6 @@ ui_process_menu(void)
}
}
#define NUMINPUT_LEN 10
#define KP_CONTINUE 0
#define KP_DONE 1
#define KP_CANCEL 2
char kp_buf[11];
int8_t kp_index = 0;
int
keypad_click(int selection)
@ -1059,7 +1066,6 @@ ui_process_lever(void)
void ui_process_touch(void)
{
extern int awd_count;
awd_count++;
adc_stop(ADC1);
@ -1129,10 +1135,6 @@ static const EXTConfig extcfg = {
}
};
int awd_count;
int touch_x, touch_y;
static const GPTConfig gpt3cfg = {
1000, /* 1kHz timer clock.*/
NULL, /* Timer callback.*/