mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
clean unused code, add drawing frequencies
This commit is contained in:
parent
b2e3fe770d
commit
314ca70b31
275
ili9431.c
275
ili9431.c
|
|
@ -1,6 +1,7 @@
|
|||
#include <math.h>
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
#include "chprintf.h"
|
||||
#include "nanovna.h"
|
||||
|
||||
#define RESET_ASSERT palClearPad(GPIOA, 15)
|
||||
|
|
@ -10,10 +11,11 @@
|
|||
#define DC_CMD palClearPad(GPIOB, 7)
|
||||
#define DC_DATA palSetPad(GPIOB, 7)
|
||||
|
||||
#define RGB565(r,g,b) ( (((r)<<8)&0xf800) | (((g)<<3)&0x07e0) | ((b)&0x001f) )
|
||||
#define RGB565(r,g,b) ( (((r)<<8)&0xf800) | (((g)<<3)&0x07e0) | (((b)>>3)&0x001f) )
|
||||
|
||||
uint16_t spi_buffer[1024];
|
||||
|
||||
void draw_frequencies(void);
|
||||
|
||||
|
||||
static const SPIConfig spicfg = {
|
||||
|
|
@ -210,6 +212,8 @@ void ili9341_pixel(int x, int y, int color)
|
|||
//send_command16(0x2C, color);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ili9341_fill(int x, int y, int w, int h, int color)
|
||||
{
|
||||
uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
||||
|
|
@ -358,6 +362,9 @@ int32_t fgrid = 50000000;
|
|||
#define WIDTH 291
|
||||
#define HEIGHT 233
|
||||
|
||||
//#define GRID_COLOR 0x0863
|
||||
uint16_t grid_color = 0x1084;
|
||||
|
||||
void set_sweep(int32_t start, int stop)
|
||||
{
|
||||
int32_t gdigit = 100000000;
|
||||
|
|
@ -368,17 +375,19 @@ void set_sweep(int32_t start, int stop)
|
|||
|
||||
while (gdigit > 100) {
|
||||
grid = 5 * gdigit;
|
||||
if (fspan / grid >= 5)
|
||||
if (fspan / grid >= 4)
|
||||
break;
|
||||
grid = 2 * gdigit;
|
||||
if (fspan / grid >= 5)
|
||||
if (fspan / grid >= 4)
|
||||
break;
|
||||
grid = gdigit;
|
||||
if (fspan / grid >= 5)
|
||||
if (fspan / grid >= 4)
|
||||
break;
|
||||
gdigit /= 10;
|
||||
}
|
||||
fgrid = grid;
|
||||
|
||||
draw_frequencies();
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -396,7 +405,7 @@ int
|
|||
smith_grid(int x, int y)
|
||||
{
|
||||
int d = circle_inout(x-146, y-116, 116);
|
||||
int c = 0x7bef;
|
||||
int c = grid_color;
|
||||
if (d < 0)
|
||||
return 0;
|
||||
else if (d == 0)
|
||||
|
|
@ -431,12 +440,14 @@ int
|
|||
rectangular_grid(int x, int y)
|
||||
{
|
||||
#define FREQ(x) (((x) * (fspan / 1000) / (WIDTH-1)) * 1000 + fstart)
|
||||
int c = 0x7bef;
|
||||
int c = grid_color;
|
||||
int32_t n = FREQ(x-1) / fgrid;
|
||||
int32_t m = FREQ(x) / fgrid;
|
||||
if ((m - n) > 0)
|
||||
//if (((x * 6) % (WIDTH-1)) < 6)
|
||||
return c;
|
||||
if (x == 0 || x == (WIDTH-1))
|
||||
return c;
|
||||
if ((y % 29) == 0)
|
||||
return c;
|
||||
return 0;
|
||||
|
|
@ -449,9 +460,8 @@ set_strut_grid(int x)
|
|||
int y;
|
||||
|
||||
for (y = 0; y < HEIGHT; y++) {
|
||||
int c = 0;
|
||||
int c = rectangular_grid(x, y);
|
||||
c |= smith_grid(x, y);
|
||||
c |= rectangular_grid(x, y);
|
||||
*buf++ = c;
|
||||
}
|
||||
return y;
|
||||
|
|
@ -484,7 +494,7 @@ struct {
|
|||
uint16_t color;
|
||||
} trace[2] = {
|
||||
{ 0, 0, 0, RGB565(0,255,255) },
|
||||
{ 0, 0, 0, RGB565(255,0,255) }
|
||||
{ 0, 0, 0, RGB565(255,0,40) }
|
||||
};
|
||||
|
||||
float logmag(float *v)
|
||||
|
|
@ -535,177 +545,10 @@ void sweep_tail()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
void
|
||||
spi_dma_setup()
|
||||
ili9341_drawchar_5x7(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg)
|
||||
{
|
||||
GPDMA_Init();
|
||||
LPC_GPDMA->CONFIG = 0x01; /* Enable DMA channels, little endian */
|
||||
while ( !(LPC_GPDMA->CONFIG & 0x01) );
|
||||
//NVIC_EnableIRQ(DMA_IRQn);
|
||||
}
|
||||
|
||||
void
|
||||
spi_dma_transfer(void *data, int length)
|
||||
{
|
||||
#if 0
|
||||
GPDMA_Channel_CFG_Type ssp_dma_cfg;
|
||||
ssp_dma_cfg.ChannelNum = 0;
|
||||
ssp_dma_cfg.SrcMemAddr = data;
|
||||
ssp_dma_cfg.DstConn = GPDMA_CONN_SSP1_Tx;
|
||||
ssp_dma_cfg.DstMemAddr = &LPC_SSP1->DR;
|
||||
ssp_dma_cfg.TransferSize = length;
|
||||
ssp_dma_cfg.TransferWidth = GPDMA_WIDTH_HALFWORD;
|
||||
//ssp_dma_cfg.TransferWidth = GPDMA_WIDTH_WORD;
|
||||
//ssp_dma_cfg.TransferType = GPDMA_TRANSFERTYPE_M2P_CONTROLLER_PERIPHERAL;
|
||||
ssp_dma_cfg.TransferType = GPDMA_TRANSFERTYPE_M2P_CONTROLLER_DMA;
|
||||
ssp_dma_cfg.DMALLI = 0;
|
||||
GPDMA_Setup(&ssp_dma_cfg);
|
||||
GPDMA_ChannelCmd(0, ENABLE);
|
||||
#endif
|
||||
|
||||
#define GPDMA_SSP1_TX_CHANNEL 12
|
||||
//LPC_CREG->DMAMUX &= ~3<<(GPDMA_SSP1_TX_CHANNEL*2);
|
||||
//LPC_CREG->DMAMUX |= 0<<(GPDMA_SSP1_TX_CHANNEL*2);
|
||||
LPC_GPDMA->C0SRCADDR = (uint32_t)data;
|
||||
LPC_GPDMA->C0DESTADDR = (uint32_t)&LPC_SSP1->DR;
|
||||
LPC_GPDMA->C0LLI = 0;
|
||||
LPC_GPDMA->C0CONTROL = (length >> 1) | // Transfersize (does not matter when flow control is handled by peripheral)
|
||||
(0x2 << 12) | // Source Burst Size
|
||||
(0x1 << 15) | // Destination Burst Size
|
||||
//(0x0 << 15) | // Destination Burst Size
|
||||
(0x2 << 18) | // Source width // 32 bit width
|
||||
(0x1 << 21) | // Destination width // 16 bits
|
||||
(0x0 << 24) | // Source AHB master 0 / 1
|
||||
(0x1 << 25) | // Dest AHB master 0 / 1
|
||||
(0x1 << 26) | // Source increment(LAST Sample)
|
||||
(0x0 << 27) | // Destination increment
|
||||
(0x1UL << 31); // Terminal count interrupt disabled
|
||||
LPC_GPDMA->C0CONFIG = (0x1) | // Enable bit
|
||||
(0x0 << 1) | // SRCPERIPHERAL - memory
|
||||
(GPDMA_SSP1_TX_CHANNEL << 6) | // Destination peripheral - memory - no setting
|
||||
(0x1 << 11) | // Flow control - peripheral to memory - DMA control
|
||||
// (0x5 << 11) | // Flow control - peripheral to memory - peripheral control
|
||||
(0x0 << 14) | // Int error mask
|
||||
(0x1 << 15); // ITC - term count error mask
|
||||
SSP_DMACmd(LPC_SSP1, SSP_DMA_TX, ENABLE);
|
||||
|
||||
// software trigger
|
||||
LPC_GPDMA->SOFTBREQ = 1<<GPDMA_SSP1_TX_CHANNEL;
|
||||
}
|
||||
|
||||
void
|
||||
spi_dma_sync()
|
||||
{
|
||||
while (!LPC_GPDMA->INTTCSTAT & GPDMA_DMACIntTCStat_Ch(0))
|
||||
;
|
||||
LPC_GPDMA->INTTCCLEAR = GPDMA_DMACIntTCClear_Ch(0);
|
||||
}
|
||||
|
||||
void
|
||||
spi_dma_stop()
|
||||
{
|
||||
SSP_DMACmd(LPC_SSP1, SSP_DMA_TX, DISABLE);
|
||||
}
|
||||
|
||||
void DMA_IRQHandler (void)
|
||||
{
|
||||
if (LPC_GPDMA->INTERRSTAT & GPDMA_DMACIntErrStat_Ch(0))
|
||||
{
|
||||
LPC_GPDMA->INTERRCLR = GPDMA_DMACIntErrClr_Ch(0);
|
||||
}
|
||||
|
||||
if (LPC_GPDMA->INTTCSTAT & GPDMA_DMACIntTCStat_Ch(0))
|
||||
{
|
||||
LPC_GPDMA->INTTCCLEAR = GPDMA_DMACIntTCClear_Ch(0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ili9341_dma_test()
|
||||
{
|
||||
int sx = 40, ex = 200;
|
||||
uint8_t xx[4] = { sx >> 8, sx, ex >> 8, ex };
|
||||
int x;
|
||||
int y = 0;
|
||||
spi_dma_setup();
|
||||
|
||||
//while (1) {
|
||||
for (y = 0; y < 320; y++) {
|
||||
int sy = y, ey = sy + 1;
|
||||
uint8_t yy[4] = { sy >> 8, sy, ey >> 8, ey };
|
||||
for (x = 0; x < 160; x++) {
|
||||
//int c = ((~x & 0x7) ? 0x7 : 0x0) | (~x & ~0x7);
|
||||
//spi_buffer[x] = (y<<8)|(c&0xff);
|
||||
spi_buffer[x] = (x<<8)|y;
|
||||
}
|
||||
|
||||
ssp_databit8();
|
||||
send_command(0x2A, 4, xx);
|
||||
send_command(0x2B, 4, yy);
|
||||
send_command(0x2C, 0, NULL);
|
||||
ssp_databit16();
|
||||
spi_dma_transfer(spi_buffer, 240);
|
||||
spi_dma_sync();
|
||||
}
|
||||
//chThdSleepMilliseconds(100);
|
||||
//}
|
||||
spi_dma_stop();
|
||||
}
|
||||
|
||||
extern const UNS_16 x5x7_bits [];
|
||||
extern const uint32_t numfont20x24[][24];
|
||||
extern const uint32_t numfont32x24[][24];
|
||||
|
||||
typedef struct {
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint16_t scaley;
|
||||
uint16_t slide;
|
||||
const uint32_t *bitmap;
|
||||
} font_t;
|
||||
|
||||
const font_t NF20x24 = { 20, 24, 1, 24, (const uint32_t *)numfont20x24 };
|
||||
const font_t NF32x24 = { 32, 24, 1, 24, (const uint32_t *)numfont32x24 };
|
||||
const font_t NF32x48 = { 32, 48, 2, 24, (const uint32_t *)numfont32x24 };
|
||||
|
||||
void
|
||||
ili9341_drawfont(uint8_t ch, const font_t *font, int x, int y, uint16_t fg, uint16_t bg)
|
||||
{
|
||||
int ex = x + font->width-1;
|
||||
int ey = y + font->height-1;
|
||||
uint8_t xx[4] = { x >> 8, x, ex >> 8, ex };
|
||||
uint8_t yy[4] = { y >> 8, y, ey >> 8, ey };
|
||||
uint16_t *buf = spi_buffer;
|
||||
uint32_t bits;
|
||||
const uint32_t *bitmap = &font->bitmap[font->slide * ch];
|
||||
int c, r, j;
|
||||
|
||||
for (c = 0; c < font->slide; c++) {
|
||||
for (j = 0; j < font->scaley; j++) {
|
||||
bits = bitmap[c];
|
||||
for (r = 0; r < font->width; r++) {
|
||||
*buf++ = (0x80000000UL & bits) ? fg : bg;
|
||||
bits <<= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
send_command(0x2A, 4, xx);
|
||||
send_command(0x2B, 4, yy);
|
||||
send_command(0x2C, 0, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
ili9341_drawchar_dma(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg)
|
||||
{
|
||||
int ex = x + 4;
|
||||
int ey = y + 7;
|
||||
uint8_t xx[4] = { x >> 8, x, ex >> 8, ex };
|
||||
uint8_t yy[4] = { y >> 8, y, ey >> 8, ey };
|
||||
uint16_t *buf = spi_buffer;
|
||||
|
||||
uint16_t bits;
|
||||
int c, r;
|
||||
for(c = 0; c < 7; c++) {
|
||||
|
|
@ -715,79 +558,39 @@ ili9341_drawchar_dma(uint8_t ch, int x, int y, uint16_t fg, uint16_t bg)
|
|||
bits <<= 1;
|
||||
}
|
||||
}
|
||||
ssp_databit8();
|
||||
send_command(0x2A, 4, xx);
|
||||
send_command(0x2B, 4, yy);
|
||||
send_command(0x2C, 0, NULL);
|
||||
ssp_databit16();
|
||||
spi_dma_transfer(spi_buffer, 35);
|
||||
spi_dma_sync();
|
||||
ili9341_bulk(x, y, 5, 7);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
void
|
||||
ili9341_drawstring_dma(char *str, int x, int y, uint16_t fg, uint16_t bg)
|
||||
ili9341_drawstring_5x7(char *str, int x, int y, uint16_t fg, uint16_t bg)
|
||||
{
|
||||
spi_dma_setup();
|
||||
while (*str) {
|
||||
ili9341_drawchar_dma(*str, x, y, fg, bg);
|
||||
ili9341_drawchar_5x7(*str, x, y, fg, bg);
|
||||
x += 5;
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ili9341_drawstring(char *str, int x, int y, uint16_t fg, uint16_t bg)
|
||||
draw_frequencies(void)
|
||||
{
|
||||
while (*str) {
|
||||
ili9341_drawchar(*str, x, y, fg, bg);
|
||||
x += 5;
|
||||
str++;
|
||||
}
|
||||
char buf[24];
|
||||
chsnprintf(buf, 24, "START%3d.%03d %03d MHz",
|
||||
(int)(fstart / 1000000),
|
||||
(int)((fstart / 1000) % 1000),
|
||||
(int)(fstart % 1000));
|
||||
ili9341_drawstring_5x7(buf, OFFSETX, 233, 0xffff, 0x0000);
|
||||
chsnprintf(buf, 24, "STOP %3d.%03d %03d MHz",
|
||||
(int)(fstop / 1000000),
|
||||
(int)((fstop / 1000) % 1000),
|
||||
(int)(fstop % 1000));
|
||||
ili9341_drawstring_5x7(buf, 205, 233, 0xffff, 0x0000);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
void
|
||||
ili9341_bulk_test()
|
||||
redraw(void)
|
||||
{
|
||||
int x, y;
|
||||
while (1) {
|
||||
for(y = 0; y < 320; y++) {
|
||||
int sx = 0, ex = 240;
|
||||
int sy = y, ey = y+1;
|
||||
uint8_t xx[4] = { sx >> 8, sx, ex >> 8, ex };
|
||||
uint8_t yy[4] = { sy >> 8, sy, ey >> 8, ey };
|
||||
ssp_databit8();
|
||||
send_command(0x2A, 4, xx);
|
||||
send_command(0x2B, 4, yy);
|
||||
send_command(0x2C, 0, NULL);
|
||||
ssp_databit16();
|
||||
for (x = 0; x < 240; x++)
|
||||
ssp_senddata((y<<8)|x);
|
||||
}
|
||||
chThdSleepMilliseconds(100);
|
||||
}
|
||||
ili9341_fill(0, 0, 320, 240, 0);
|
||||
draw_frequencies();
|
||||
}
|
||||
|
||||
int test(void)
|
||||
{
|
||||
char buf[16];
|
||||
int i;
|
||||
|
||||
spi_init();
|
||||
//spi_test();
|
||||
ili9341_init();
|
||||
//ili9341_test();
|
||||
ili9341_dma_test();
|
||||
//ili9341_bulk_test();
|
||||
ili9341_drawstring_dma("Hello", 100, 100, 0xffff, 0x0000);
|
||||
for (i = 0; i < 10; i++)
|
||||
ili9341_drawfont_dma(i, &NF20x24, i*20, 120, 0xffff, 0x0000);
|
||||
for (i = 0; i < 5; i++)
|
||||
ili9341_drawfont_dma(i, &NF32x48, i*32, 144, 0xffff, 0x0000);
|
||||
for (i = 0; i < 5; i++)
|
||||
ili9341_drawfont_dma(i+5, &NF32x48, i*32, 192, 0xffff, 0x0000);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
3
main.c
3
main.c
|
|
@ -348,7 +348,6 @@ void scan_lcd(void)
|
|||
|
||||
freq = freq_start;
|
||||
step = (freq_stop - freq_start) / (sweep_points-1);
|
||||
set_sweep(freq_start, freq_stop);
|
||||
delay = set_frequency(freq);
|
||||
delay += 2;
|
||||
for (i = 0; i < sweep_points; i++) {
|
||||
|
|
@ -421,6 +420,7 @@ static void cmd_sweep(BaseSequentialStream *chp, int argc, char *argv[])
|
|||
}
|
||||
sweep_points = x;
|
||||
}
|
||||
set_sweep(freq_start, freq_stop);
|
||||
}
|
||||
|
||||
static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[])
|
||||
|
|
@ -598,6 +598,7 @@ int main(void)
|
|||
* SPI LCD Initialize
|
||||
*/
|
||||
ili9341_init();
|
||||
redraw();
|
||||
|
||||
/*
|
||||
* I2S Initialize
|
||||
|
|
|
|||
Loading…
Reference in a new issue