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.
|
* @brief Enables the SERIAL subsystem.
|
||||||
*/
|
*/
|
||||||
#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
|
#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
|
||||||
#define HAL_USE_SERIAL TRUE
|
#define HAL_USE_SERIAL FALSE
|
||||||
#endif
|
#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[])
|
static void cmd_capture(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
// read pixel count at one time (PART*2 bytes required for read buffer)
|
// read pixel count at one time (PART*2 bytes required for read buffer)
|
||||||
#define PART 320
|
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
chMtxLock(&mutex);
|
chMtxLock(&mutex);
|
||||||
|
|
||||||
// use uint16_t spi_buffer[1024] (defined in ili9341) for read buffer
|
// read 2 row pixel time (read buffer limit by 2/3 + 1 from spi_buffer size)
|
||||||
uint16_t *buf = &spi_buffer[0];
|
for (int y=0; y < 240; y+=2)
|
||||||
int len = 320 * 240;
|
{
|
||||||
int i;
|
// use uint16_t spi_buffer[1024] (defined in ili9341) for read buffer
|
||||||
ili9341_read_memory(0, 0, 320, 240, PART, buf);
|
uint8_t *buf = (uint8_t *)spi_buffer;
|
||||||
for (i = 0; i < PART; i++) {
|
ili9341_read_memory(0, y, 320, 2, 2*320, spi_buffer);
|
||||||
streamPut(chp, buf[i] >> 8);
|
for (int i = 0; i < 4*320; i++) {
|
||||||
streamPut(chp, buf[i] & 0xff);
|
streamPut(chp, *buf++);
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
len -= PART;
|
|
||||||
}
|
}
|
||||||
//*/
|
|
||||||
|
|
||||||
chMtxUnlock(&mutex);
|
chMtxUnlock(&mutex);
|
||||||
}
|
}
|
||||||
|
|
@ -602,10 +591,10 @@ static void cmd_sample(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
config_t config = {
|
config_t config = {
|
||||||
.magic = CONFIG_MAGIC,
|
.magic = CONFIG_MAGIC,
|
||||||
.dac_value = 1922,
|
.dac_value = 1922,
|
||||||
.grid_color = 0x1084,
|
.grid_color = DEFAULT_GRID_COLOR,
|
||||||
.menu_normal_color = 0xffff,
|
.menu_normal_color = DEFAULT_MENU_COLOR,
|
||||||
.menu_active_color = 0x7777,
|
.menu_active_color = DEFAULT_MENU_ACTIVE_COLOR,
|
||||||
.trace_color = { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) },
|
.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 = { 693, 605, 124, 171 }, // 2.4 inch LCD panel
|
||||||
.touch_cal = { 338, 522, 153, 192 }, // 2.8 inch LCD panel
|
.touch_cal = { 338, 522, 153, 192 }, // 2.8 inch LCD panel
|
||||||
.default_loadcal = 0,
|
.default_loadcal = 0,
|
||||||
|
|
@ -618,10 +607,10 @@ properties_t current_props = {
|
||||||
._frequency1 = 900000000, // end = 900MHz
|
._frequency1 = 900000000, // end = 900MHz
|
||||||
._sweep_points = 101,
|
._sweep_points = 101,
|
||||||
._trace = {/*enable, type, channel, polar, scale, refpos*/
|
._trace = {/*enable, type, channel, polar, scale, refpos*/
|
||||||
{ 1, TRC_LOGMAG, 0, 0, 1.0, 7.0 },
|
{ 1, TRC_LOGMAG, 0, 0, 1.0, 9.0 },
|
||||||
{ 1, TRC_LOGMAG, 1, 0, 1.0, 7.0 },
|
{ 1, TRC_LOGMAG, 1, 0, 1.0, 9.0 },
|
||||||
{ 1, TRC_SMITH, 0, 1, 1.0, 0.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 = {
|
._markers = {
|
||||||
{ 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
|
{ 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
|
||||||
|
|
@ -1431,17 +1420,17 @@ const struct {
|
||||||
uint16_t refpos;
|
uint16_t refpos;
|
||||||
float scale_unit;
|
float scale_unit;
|
||||||
} trace_info[] = {
|
} trace_info[] = {
|
||||||
{ "LOGMAG", 7, 10 },
|
{ "LOGMAG", 9, 10 },
|
||||||
{ "PHASE", 4, 90 },
|
{ "PHASE", 5, 90 },
|
||||||
{ "DELAY", 4, 1e-9 },
|
{ "DELAY", 5, 1e-9 },
|
||||||
{ "SMITH", 0, 1 },
|
{ "SMITH", 0, 1 },
|
||||||
{ "POLAR", 0, 1 },
|
{ "POLAR", 0, 1 },
|
||||||
{ "LINEAR", 0, 0.125 },
|
{ "LINEAR", 0, 0.125 },
|
||||||
{ "SWR", 0, 1 },
|
{ "SWR", 0, 1 },
|
||||||
{ "REAL", 4, 0.25 },
|
{ "REAL", 5, 0.25 },
|
||||||
{ "IMAG", 4, 0.25 },
|
{ "IMAG", 5, 0.25 },
|
||||||
{ "R", 0, 100 },
|
{ "R", 0, 100 },
|
||||||
{ "X", 4, 100 }
|
{ "X", 5, 100 }
|
||||||
};
|
};
|
||||||
|
|
||||||
const char * const trc_channel_name[] = {
|
const char * const trc_channel_name[] = {
|
||||||
|
|
@ -1552,6 +1541,11 @@ my_atof(const char *p)
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *tracename;
|
||||||
|
uint8_t type;
|
||||||
|
} type_list;
|
||||||
|
|
||||||
static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int t;
|
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);
|
chprintf(chp, "%d %s %s\r\n", t, type, channel);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
if (strcmp(argv[1], "logmag") == 0) {
|
static const type_list t_list[] = {
|
||||||
set_trace_type(t, TRC_LOGMAG);
|
{"logmag", TRC_LOGMAG},
|
||||||
} else if (strcmp(argv[1], "phase") == 0) {
|
{"phase", TRC_PHASE},
|
||||||
set_trace_type(t, TRC_PHASE);
|
{"polar", TRC_POLAR},
|
||||||
} else if (strcmp(argv[1], "polar") == 0) {
|
{"smith", TRC_SMITH},
|
||||||
set_trace_type(t, TRC_POLAR);
|
{"delay", TRC_DELAY},
|
||||||
} else if (strcmp(argv[1], "smith") == 0) {
|
{"linear", TRC_LINEAR},
|
||||||
set_trace_type(t, TRC_SMITH);
|
{"swr", TRC_SWR},
|
||||||
} else if (strcmp(argv[1], "delay") == 0) {
|
{"real", TRC_REAL},
|
||||||
set_trace_type(t, TRC_DELAY);
|
{"imag", TRC_IMAG},
|
||||||
} else if (strcmp(argv[1], "linear") == 0) {
|
{"r", TRC_R},
|
||||||
set_trace_type(t, TRC_LINEAR);
|
{"x", TRC_X},
|
||||||
} else if (strcmp(argv[1], "swr") == 0) {
|
{"off", TRC_OFF},
|
||||||
set_trace_type(t, TRC_SWR);
|
};
|
||||||
} else if (strcmp(argv[1], "real") == 0) {
|
for (uint16_t i=0; i<sizeof(t_list)/sizeof(type_list); i++){
|
||||||
set_trace_type(t, TRC_REAL);
|
if (strcmp(argv[1], t_list[i].tracename) == 0) {
|
||||||
} else if (strcmp(argv[1], "imag") == 0) {
|
set_trace_type(t, t_list[i].type);
|
||||||
set_trace_type(t, TRC_IMAG);
|
goto check_ch_num;
|
||||||
} else if (strcmp(argv[1], "r") == 0) {
|
}
|
||||||
set_trace_type(t, TRC_R);
|
}
|
||||||
} else if (strcmp(argv[1], "x") == 0) {
|
if (strcmp(argv[1], "scale") == 0 && argc >= 3) {
|
||||||
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) {
|
|
||||||
//trace[t].scale = my_atof(argv[2]);
|
//trace[t].scale = my_atof(argv[2]);
|
||||||
set_trace_scale(t, my_atof(argv[2]));
|
set_trace_scale(t, my_atof(argv[2]));
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
@ -1625,16 +1614,17 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[])
|
||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
check_ch_num:
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
int src = atoi(argv[2]);
|
int src = atoi(argv[2]);
|
||||||
if (src != 0 && src != 1)
|
if (src != 0 && src != 1)
|
||||||
goto usage;
|
goto usage;
|
||||||
trace[t].channel = src;
|
trace[t].channel = src;
|
||||||
}
|
}
|
||||||
exit:
|
exit:
|
||||||
return;
|
return;
|
||||||
usage:
|
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");
|
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_BUSY_TIMEOUT 50
|
||||||
#define STM32_I2C_I2C1_IRQ_PRIORITY 3
|
#define STM32_I2C_I2C1_IRQ_PRIORITY 3
|
||||||
#define STM32_I2C_I2C2_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_I2C1_DMA_PRIORITY 1
|
||||||
#define STM32_I2C_I2C2_DMA_PRIORITY 1
|
#define STM32_I2C_I2C2_DMA_PRIORITY 1
|
||||||
#define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
|
#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"
|
#include "ch.h"
|
||||||
|
|
||||||
|
// Need enable HAL_USE_SPI in halconf.h
|
||||||
|
#define __USE_DISPLAY_DMA__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* main.c
|
* main.c
|
||||||
*/
|
*/
|
||||||
|
|
@ -129,7 +132,12 @@ extern void tlv320aic3204_select(int channel);
|
||||||
#define OFFSETX 15
|
#define OFFSETX 15
|
||||||
#define OFFSETY 0
|
#define OFFSETY 0
|
||||||
#define WIDTH 291
|
#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 CELLOFFSETX 5
|
||||||
#define AREA_WIDTH_NORMAL (WIDTH + CELLOFFSETX*2)
|
#define AREA_WIDTH_NORMAL (WIDTH + CELLOFFSETX*2)
|
||||||
|
|
@ -137,21 +145,29 @@ extern void tlv320aic3204_select(int channel);
|
||||||
extern int area_width;
|
extern int area_width;
|
||||||
extern int area_height;
|
extern int area_height;
|
||||||
|
|
||||||
#define GRIDY 29
|
#define GRIDY 23
|
||||||
|
|
||||||
// font
|
// font
|
||||||
|
|
||||||
extern const uint8_t x5x7_bits [];
|
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_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_PI "\034"
|
||||||
#define S_MICRO "\035"
|
#define S_MICRO "\035"
|
||||||
#define S_OHM "\036"
|
#define S_OHM "\036"
|
||||||
#define S_DEGREE "\037"
|
|
||||||
#define S_LARROW "\032"
|
|
||||||
#define S_RARROW "\033"
|
|
||||||
|
|
||||||
// trace
|
// trace
|
||||||
|
|
||||||
#define TRACES_MAX 4
|
#define TRACES_MAX 4
|
||||||
|
|
@ -261,34 +277,46 @@ extern int16_t vbat;
|
||||||
/*
|
/*
|
||||||
* ili9341.c
|
* 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 {
|
#define DEFAULT_FG_COLOR RGB565(255,255,255)
|
||||||
uint16_t width;
|
#define DEFAULT_BG_COLOR RGB565( 0, 0, 0)
|
||||||
uint16_t height;
|
#define DEFAULT_GRID_COLOR RGB565(128,128,128)
|
||||||
uint16_t scaley;
|
#define DEFAULT_MENU_COLOR RGB565(255,255,255)
|
||||||
uint16_t slide;
|
#define DEFAULT_MENU_TEXT_COLOR RGB565( 0, 0, 0)
|
||||||
const uint8_t *bitmap;
|
#define DEFAULT_MENU_ACTIVE_COLOR RGB565(180,255,180)
|
||||||
} font_t;
|
#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];
|
extern uint16_t spi_buffer[1024];
|
||||||
|
|
||||||
void ili9341_init(void);
|
void ili9341_init(void);
|
||||||
|
//void ili9341_setRotation(uint8_t r);
|
||||||
void ili9341_test(int mode);
|
void ili9341_test(int mode);
|
||||||
void ili9341_bulk(int x, int y, int w, int h);
|
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_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 setForegroundColor(uint16_t fg);
|
||||||
void ili9341_drawstring_5x7(const char *str, int x, int y, uint16_t fg, uint16_t bg);
|
void setBackgroundColor(uint16_t fg);
|
||||||
void ili9341_drawstring_5x7_inv(const char *str, int x, int y, uint16_t fg, uint16_t bg, bool inv);
|
void blit8BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *bitmap);
|
||||||
void ili9341_drawchar_size(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg, uint8_t size);
|
void blit16BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *bitmap);
|
||||||
void ili9341_drawstring_size(const char *str, int x, int y, uint16_t fg, uint16_t bg, uint8_t size);
|
void ili9341_drawchar(uint8_t ch, int x, int y);
|
||||||
void ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg);
|
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(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);
|
||||||
void ili9341_line(int x0, int y0, int x1, int y1, uint16_t fg);
|
void show_version(void);
|
||||||
|
void show_logo(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* flash.c
|
* 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)
|
#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*/
|
/*EOF*/
|
||||||
|
|
|
||||||
1086
numfont20x22.c
1086
numfont20x22.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue