mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
Merge pull request #113 from DiSlord/master
Change font size, more compact and faster code for LCD
This commit is contained in:
commit
836ed2a7fb
|
|
@ -132,7 +132,7 @@
|
|||
* @brief Enables the SERIAL subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_SERIAL TRUE
|
||||
#define HAL_USE_SERIAL FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
|||
112
main.c
112
main.c
|
|
@ -533,32 +533,21 @@ static void cmd_dump(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
static void cmd_capture(BaseSequentialStream *chp, int argc, char *argv[])
|
||||
{
|
||||
// read pixel count at one time (PART*2 bytes required for read buffer)
|
||||
#define PART 320
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
chMtxLock(&mutex);
|
||||
|
||||
// use uint16_t spi_buffer[1024] (defined in ili9341) for read buffer
|
||||
uint16_t *buf = &spi_buffer[0];
|
||||
int len = 320 * 240;
|
||||
int i;
|
||||
ili9341_read_memory(0, 0, 320, 240, PART, buf);
|
||||
for (i = 0; i < PART; i++) {
|
||||
streamPut(chp, buf[i] >> 8);
|
||||
streamPut(chp, buf[i] & 0xff);
|
||||
}
|
||||
|
||||
len -= PART;
|
||||
while (len > 0) {
|
||||
ili9341_read_memory_continue(PART, buf);
|
||||
for (i = 0; i < PART; i++) {
|
||||
streamPut(chp, buf[i] >> 8);
|
||||
streamPut(chp, buf[i] & 0xff);
|
||||
// read 2 row pixel time (read buffer limit by 2/3 + 1 from spi_buffer size)
|
||||
for (int y=0; y < 240; y+=2)
|
||||
{
|
||||
// use uint16_t spi_buffer[1024] (defined in ili9341) for read buffer
|
||||
uint8_t *buf = (uint8_t *)spi_buffer;
|
||||
ili9341_read_memory(0, y, 320, 2, 2*320, spi_buffer);
|
||||
for (int i = 0; i < 4*320; i++) {
|
||||
streamPut(chp, *buf++);
|
||||
}
|
||||
len -= PART;
|
||||
}
|
||||
//*/
|
||||
|
||||
chMtxUnlock(&mutex);
|
||||
}
|
||||
|
|
@ -602,10 +591,10 @@ static void cmd_sample(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
config_t config = {
|
||||
.magic = CONFIG_MAGIC,
|
||||
.dac_value = 1922,
|
||||
.grid_color = 0x1084,
|
||||
.menu_normal_color = 0xffff,
|
||||
.menu_active_color = 0x7777,
|
||||
.trace_color = { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) },
|
||||
.grid_color = DEFAULT_GRID_COLOR,
|
||||
.menu_normal_color = DEFAULT_MENU_COLOR,
|
||||
.menu_active_color = DEFAULT_MENU_ACTIVE_COLOR,
|
||||
.trace_color = { DEFAULT_TRACE_1_COLOR, DEFAULT_TRACE_2_COLOR, DEFAULT_TRACE_3_COLOR, DEFAULT_TRACE_4_COLOR },
|
||||
// .touch_cal = { 693, 605, 124, 171 }, // 2.4 inch LCD panel
|
||||
.touch_cal = { 338, 522, 153, 192 }, // 2.8 inch LCD panel
|
||||
.default_loadcal = 0,
|
||||
|
|
@ -618,10 +607,10 @@ properties_t current_props = {
|
|||
._frequency1 = 900000000, // end = 900MHz
|
||||
._sweep_points = 101,
|
||||
._trace = {/*enable, type, channel, polar, scale, refpos*/
|
||||
{ 1, TRC_LOGMAG, 0, 0, 1.0, 7.0 },
|
||||
{ 1, TRC_LOGMAG, 1, 0, 1.0, 7.0 },
|
||||
{ 1, TRC_LOGMAG, 0, 0, 1.0, 9.0 },
|
||||
{ 1, TRC_LOGMAG, 1, 0, 1.0, 9.0 },
|
||||
{ 1, TRC_SMITH, 0, 1, 1.0, 0.0 },
|
||||
{ 1, TRC_PHASE, 1, 0, 1.0, 4.0 }
|
||||
{ 1, TRC_PHASE, 1, 0, 1.0, 5.0 }
|
||||
},
|
||||
._markers = {
|
||||
{ 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
|
||||
|
|
@ -1431,17 +1420,17 @@ const struct {
|
|||
uint16_t refpos;
|
||||
float scale_unit;
|
||||
} trace_info[] = {
|
||||
{ "LOGMAG", 7, 10 },
|
||||
{ "PHASE", 4, 90 },
|
||||
{ "DELAY", 4, 1e-9 },
|
||||
{ "LOGMAG", 9, 10 },
|
||||
{ "PHASE", 5, 90 },
|
||||
{ "DELAY", 5, 1e-9 },
|
||||
{ "SMITH", 0, 1 },
|
||||
{ "POLAR", 0, 1 },
|
||||
{ "LINEAR", 0, 0.125 },
|
||||
{ "SWR", 0, 1 },
|
||||
{ "REAL", 4, 0.25 },
|
||||
{ "IMAG", 4, 0.25 },
|
||||
{ "REAL", 5, 0.25 },
|
||||
{ "IMAG", 5, 0.25 },
|
||||
{ "R", 0, 100 },
|
||||
{ "X", 4, 100 }
|
||||
{ "X", 5, 100 }
|
||||
};
|
||||
|
||||
const char * const trc_channel_name[] = {
|
||||
|
|
@ -1552,6 +1541,11 @@ my_atof(const char *p)
|
|||
return x;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char *tracename;
|
||||
uint8_t type;
|
||||
} type_list;
|
||||
|
||||
static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
||||
{
|
||||
int t;
|
||||
|
|
@ -1586,34 +1580,29 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
chprintf(chp, "%d %s %s\r\n", t, type, channel);
|
||||
return;
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
if (strcmp(argv[1], "logmag") == 0) {
|
||||
set_trace_type(t, TRC_LOGMAG);
|
||||
} else if (strcmp(argv[1], "phase") == 0) {
|
||||
set_trace_type(t, TRC_PHASE);
|
||||
} else if (strcmp(argv[1], "polar") == 0) {
|
||||
set_trace_type(t, TRC_POLAR);
|
||||
} else if (strcmp(argv[1], "smith") == 0) {
|
||||
set_trace_type(t, TRC_SMITH);
|
||||
} else if (strcmp(argv[1], "delay") == 0) {
|
||||
set_trace_type(t, TRC_DELAY);
|
||||
} else if (strcmp(argv[1], "linear") == 0) {
|
||||
set_trace_type(t, TRC_LINEAR);
|
||||
} else if (strcmp(argv[1], "swr") == 0) {
|
||||
set_trace_type(t, TRC_SWR);
|
||||
} else if (strcmp(argv[1], "real") == 0) {
|
||||
set_trace_type(t, TRC_REAL);
|
||||
} else if (strcmp(argv[1], "imag") == 0) {
|
||||
set_trace_type(t, TRC_IMAG);
|
||||
} else if (strcmp(argv[1], "r") == 0) {
|
||||
set_trace_type(t, TRC_R);
|
||||
} else if (strcmp(argv[1], "x") == 0) {
|
||||
set_trace_type(t, TRC_X);
|
||||
} else if (strcmp(argv[1], "linear") == 0) {
|
||||
set_trace_type(t, TRC_LINEAR);
|
||||
} else if (strcmp(argv[1], "off") == 0) {
|
||||
set_trace_type(t, TRC_OFF);
|
||||
} else if (strcmp(argv[1], "scale") == 0 && argc >= 3) {
|
||||
static const type_list t_list[] = {
|
||||
{"logmag", TRC_LOGMAG},
|
||||
{"phase", TRC_PHASE},
|
||||
{"polar", TRC_POLAR},
|
||||
{"smith", TRC_SMITH},
|
||||
{"delay", TRC_DELAY},
|
||||
{"linear", TRC_LINEAR},
|
||||
{"swr", TRC_SWR},
|
||||
{"real", TRC_REAL},
|
||||
{"imag", TRC_IMAG},
|
||||
{"r", TRC_R},
|
||||
{"x", TRC_X},
|
||||
{"off", TRC_OFF},
|
||||
};
|
||||
for (uint16_t i=0; i<sizeof(t_list)/sizeof(type_list); i++){
|
||||
if (strcmp(argv[1], t_list[i].tracename) == 0) {
|
||||
set_trace_type(t, t_list[i].type);
|
||||
goto check_ch_num;
|
||||
}
|
||||
}
|
||||
if (strcmp(argv[1], "scale") == 0 && argc >= 3) {
|
||||
//trace[t].scale = my_atof(argv[2]);
|
||||
set_trace_scale(t, my_atof(argv[2]));
|
||||
goto exit;
|
||||
|
|
@ -1625,16 +1614,17 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
goto usage;
|
||||
}
|
||||
}
|
||||
check_ch_num:
|
||||
if (argc > 2) {
|
||||
int src = atoi(argv[2]);
|
||||
if (src != 0 && src != 1)
|
||||
goto usage;
|
||||
trace[t].channel = src;
|
||||
}
|
||||
}
|
||||
exit:
|
||||
return;
|
||||
usage:
|
||||
chprintf(chp, "trace {0|1|2|3|all} [logmag|phase|smith|linear|delay|swr|real|imag|r|x|off] [src]\r\n");
|
||||
chprintf(chp, "trace {0|1|2|3|all} [logmag|phase|polar|smith|linear|delay|swr|real|imag|r|x|off] [src]\r\n");
|
||||
chprintf(chp, "trace {0|1|2|3} {scale|refpos} {value}\r\n");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -117,7 +117,9 @@
|
|||
#define STM32_I2C_BUSY_TIMEOUT 50
|
||||
#define STM32_I2C_I2C1_IRQ_PRIORITY 3
|
||||
#define STM32_I2C_I2C2_IRQ_PRIORITY 3
|
||||
#define STM32_I2C_USE_DMA TRUE
|
||||
|
||||
// I2C1 rx operation use DMA3, some as SPI1 DMA Tx used by LCD
|
||||
#define STM32_I2C_USE_DMA FALSE
|
||||
#define STM32_I2C_I2C1_DMA_PRIORITY 1
|
||||
#define STM32_I2C_I2C2_DMA_PRIORITY 1
|
||||
#define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
|
||||
|
|
|
|||
88
nanovna.h
88
nanovna.h
|
|
@ -19,6 +19,9 @@
|
|||
*/
|
||||
#include "ch.h"
|
||||
|
||||
// Need enable HAL_USE_SPI in halconf.h
|
||||
#define __USE_DISPLAY_DMA__
|
||||
|
||||
/*
|
||||
* main.c
|
||||
*/
|
||||
|
|
@ -129,7 +132,12 @@ extern void tlv320aic3204_select(int channel);
|
|||
#define OFFSETX 15
|
||||
#define OFFSETY 0
|
||||
#define WIDTH 291
|
||||
#define HEIGHT 233
|
||||
#define HEIGHT 230
|
||||
|
||||
// Smith/polar chart
|
||||
#define P_CENTER_X 145
|
||||
#define P_CENTER_Y 115
|
||||
#define P_RADIUS 115
|
||||
|
||||
#define CELLOFFSETX 5
|
||||
#define AREA_WIDTH_NORMAL (WIDTH + CELLOFFSETX*2)
|
||||
|
|
@ -137,21 +145,29 @@ extern void tlv320aic3204_select(int channel);
|
|||
extern int area_width;
|
||||
extern int area_height;
|
||||
|
||||
#define GRIDY 29
|
||||
#define GRIDY 23
|
||||
|
||||
// font
|
||||
|
||||
extern const uint8_t x5x7_bits [];
|
||||
extern const uint8_t numfont20x22[][22 * 3];
|
||||
#define FONT_GET_DATA(ch) (&x5x7_bits[ch*7])
|
||||
#define FONT_GET_WIDTH(ch) (7-(x5x7_bits[ch*7]&3))
|
||||
#define FONT_GET_HEIGHT 7
|
||||
|
||||
extern const uint16_t numfont16x22[];
|
||||
#define NUM_FONT_GET_DATA(ch) (&numfont16x22[ch*22])
|
||||
#define NUM_FONT_GET_WIDTH 16
|
||||
#define NUM_FONT_GET_HEIGHT 22
|
||||
|
||||
#define S_DELTA "\004"
|
||||
#define S_DEGREE "\037"
|
||||
#define S_SARROW "\030"
|
||||
#define S_INFINITY "\031"
|
||||
#define S_LARROW "\032"
|
||||
#define S_RARROW "\033"
|
||||
#define S_PI "\034"
|
||||
#define S_MICRO "\035"
|
||||
#define S_OHM "\036"
|
||||
#define S_DEGREE "\037"
|
||||
#define S_LARROW "\032"
|
||||
#define S_RARROW "\033"
|
||||
|
||||
// trace
|
||||
|
||||
#define TRACES_MAX 4
|
||||
|
|
@ -261,34 +277,46 @@ extern int16_t vbat;
|
|||
/*
|
||||
* ili9341.c
|
||||
*/
|
||||
#define RGB565(b,r,g) ( (((b)<<8)&0xfc00) | (((r)<<2)&0x03e0) | (((g)>>3)&0x001f) )
|
||||
// SPI bus revert byte order
|
||||
//gggBBBbb RRRrrGGG
|
||||
#define RGB565(r,g,b) ( (((g)&0x1c)<<11) | (((b)&0xf8)<<5) | ((r)&0xf8) | (((g)&0xe0)>>5) )
|
||||
#define RGBHEX(hex) ( (((hex)&0x001c00)<<3) | (((hex)&0x0000f8)<<5) | (((hex)&0xf80000)>>16) | (((hex)&0x00e000)>>13) )
|
||||
|
||||
typedef struct {
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint16_t scaley;
|
||||
uint16_t slide;
|
||||
const uint8_t *bitmap;
|
||||
} font_t;
|
||||
#define DEFAULT_FG_COLOR RGB565(255,255,255)
|
||||
#define DEFAULT_BG_COLOR RGB565( 0, 0, 0)
|
||||
#define DEFAULT_GRID_COLOR RGB565(128,128,128)
|
||||
#define DEFAULT_MENU_COLOR RGB565(255,255,255)
|
||||
#define DEFAULT_MENU_TEXT_COLOR RGB565( 0, 0, 0)
|
||||
#define DEFAULT_MENU_ACTIVE_COLOR RGB565(180,255,180)
|
||||
#define DEFAULT_TRACE_1_COLOR RGB565( 0,255,255)
|
||||
#define DEFAULT_TRACE_2_COLOR RGB565(255, 0, 40)
|
||||
#define DEFAULT_TRACE_3_COLOR RGB565( 0, 0,255)
|
||||
#define DEFAULT_TRACE_4_COLOR RGB565( 50,255, 0)
|
||||
|
||||
extern const font_t NF20x22;
|
||||
extern uint16_t foreground_color;
|
||||
extern uint16_t background_color;
|
||||
|
||||
extern uint16_t spi_buffer[1024];
|
||||
|
||||
void ili9341_init(void);
|
||||
//void ili9341_setRotation(uint8_t r);
|
||||
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_drawstring_5x7_inv(const char *str, int x, int y, uint16_t fg, uint16_t bg, bool inv);
|
||||
void ili9341_drawchar_size(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg, uint8_t size);
|
||||
void ili9341_drawstring_size(const char *str, int x, int y, uint16_t fg, uint16_t bg, uint8_t size);
|
||||
void ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg);
|
||||
void setForegroundColor(uint16_t fg);
|
||||
void setBackgroundColor(uint16_t fg);
|
||||
void blit8BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *bitmap);
|
||||
void blit16BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *bitmap);
|
||||
void ili9341_drawchar(uint8_t ch, int x, int y);
|
||||
void ili9341_drawstring(const char *str, int x, int y);
|
||||
void ili9341_drawstringV(const char *str, int x, int y);
|
||||
int ili9341_drawchar_size(uint8_t ch, int x, int y, uint8_t size);
|
||||
void ili9341_drawstring_size(const char *str, int x, int y, uint8_t size);
|
||||
void ili9341_drawfont(uint8_t ch, int x, int y);
|
||||
void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t* out);
|
||||
void ili9341_read_memory_continue(int len, uint16_t* out);
|
||||
void ili9341_line(int x0, int y0, int x1, int y1, uint16_t fg);
|
||||
|
||||
void ili9341_line(int x0, int y0, int x1, int y1);
|
||||
void show_version(void);
|
||||
void show_logo(void);
|
||||
|
||||
/*
|
||||
* flash.c
|
||||
|
|
@ -405,14 +433,4 @@ int16_t adc_vbat_read(ADC_TypeDef *adc);
|
|||
*/
|
||||
#define PULSE do { palClearPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);} while(0)
|
||||
|
||||
// convert vbat [mV] to battery indicator
|
||||
static inline uint8_t vbat2bati(int16_t vbat)
|
||||
{
|
||||
if (vbat < 3200) return 0;
|
||||
if (vbat < 3450) return 25;
|
||||
if (vbat < 3700) return 50;
|
||||
if (vbat < 4100) return 75;
|
||||
return 100;
|
||||
}
|
||||
|
||||
/*EOF*/
|
||||
|
|
|
|||
1086
numfont20x22.c
1086
numfont20x22.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue