In ili9341.c remove tabs, add palette mode blit function

In plot.c prepare for 8bit/pixel mode (test, allow increase cell buffer size by use 4 or 8bit/pixel mode, but not need for now)
main.c little change wait execute shell command in sweep thread
This commit is contained in:
DiSlord 2020-03-13 22:42:28 +03:00
parent 8bdb650212
commit 88617a31fe
5 changed files with 475 additions and 454 deletions

View file

@ -23,8 +23,8 @@
uint16_t spi_buffer[SPI_BUFFER_SIZE];
// Default foreground & background colors
uint16_t foreground_color=DEFAULT_FG_COLOR;
uint16_t background_color=DEFAULT_BG_COLOR;
uint16_t foreground_color=0;
uint16_t background_color=0;
// Display width and height definition
#define ILI9341_WIDTH 320
@ -223,7 +223,7 @@ static void spi_init(void)
SPI1->CR1 = SPI_CR1_MSTR // SPI is MASTER
| SPI_CR1_SSM // Software slave management (The external NSS pin is free for other application uses)
| SPI_CR1_SSI; // Internal slave select (This bit has an effect only when the SSM bit is set. Allow use NSS pin as I/O)
// | SPI_CR1_BR_1; // Baud rate control
// | SPI_CR1_BR_1; // Baud rate control
SPI1->CR2 = SPI_CR2_8BIT // SPI data size, set to 8 bit
| SPI_CR2_FRXTH; // SPI_SR_RXNE generated every 8 bit data
@ -247,7 +247,7 @@ static void spi_init(void)
static void __attribute__ ((noinline)) send_command(uint8_t cmd, uint8_t len, const uint8_t *data)
{
CS_LOW;
// while (SPI_TX_IS_NOT_EMPTY);
//while (SPI_TX_IS_NOT_EMPTY);
DC_CMD;
SPI_WRITE_8BIT(cmd);
// Need wait transfer complete and set data bit
@ -301,13 +301,13 @@ static const uint8_t ili9341_init_seq[] = {
// gamma set for curve 01/2/04/08
ILI9341_GAMMA_SET, 1, 0x01,
// positive gamma correction
// ILI9341_POSITIVE_GAMMA_CORRECTION, 15, 0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0x87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00,
//ILI9341_POSITIVE_GAMMA_CORRECTION, 15, 0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0x87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00,
// negativ gamma correction
// ILI9341_NEGATIVE_GAMMA_CORRECTION, 15, 0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F,
//ILI9341_NEGATIVE_GAMMA_CORRECTION, 15, 0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F,
// Column Address Set
// ILI9341_COLUMN_ADDRESS_SET, 4, 0x00, 0x00, 0x01, 0x3f, // width 320
//ILI9341_COLUMN_ADDRESS_SET, 4, 0x00, 0x00, 0x01, 0x3f, // width 320
// Page Address Set
// ILI9341_PAGE_ADDRESS_SET, 4, 0x00, 0x00, 0x00, 0xef, // height 240
//ILI9341_PAGE_ADDRESS_SET, 4, 0x00, 0x00, 0x00, 0xef, // height 240
// entry mode
ILI9341_ENTRY_MODE_SET, 1, 0x06,
// display function control
@ -343,8 +343,8 @@ void ili9341_init(void)
#ifndef __USE_DISPLAY_DMA__
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) };
// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
//uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
//uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
uint32_t xx = __REV16(x|((x+w-1)<<16));
uint32_t yy = __REV16(y|((y+h-1)<<16));
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t*)&xx);
@ -359,8 +359,8 @@ void ili9341_fill(int x, int y, int w, int h, int color)
void ili9341_bulk(int x, int y, int w, int h)
{
// uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
//uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
//uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
uint16_t *buf = spi_buffer;
uint32_t xx = __REV16(x|((x+w-1)<<16));
uint32_t yy = __REV16(y|((y+h-1)<<16));
@ -385,8 +385,8 @@ static uint8_t ssp_sendrecvdata(void)
void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
{
// uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
//uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
//uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
uint32_t xx = __REV16(x|((x+w-1)<<16));
uint32_t yy = __REV16(y|((y+h-1)<<16));
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t*)&xx);
@ -425,6 +425,23 @@ void ili9341_fill(int x, int y, int w, int h, int color)
dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD);
dmaStreamFlush(w * h);
}
void ili9341_bulk_8bit(int x, int y, int w, int h, uint16_t *palette){
uint32_t xx = __REV16(x|((x+w-1)<<16));
uint32_t yy = __REV16(y|((y+h-1)<<16));
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t*)&xx);
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy);
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
uint8_t *buf = (uint8_t *)spi_buffer;
int32_t len = w * h;
while (len-- > 0){
uint16_t color = palette[*buf++];
while (SPI_TX_IS_NOT_EMPTY);
SPI_WRITE_16BIT(color);
}
}
// Copy spi_buffer to region
void ili9341_bulk(int x, int y, int w, int h)
{

7
main.c
View file

@ -518,7 +518,7 @@ VNA_SHELL_FUNCTION(cmd_dac)
"current value: %d\r\n", config.dac_value);
return;
}
value = my_atoi(argv[0]);
value = my_atoui(argv[0]);
config.dac_value = value;
dacPutChannelX(&DACD2, 0, value);
}
@ -2177,8 +2177,9 @@ static void VNAShell_executeLine(char *line){
if (scp->flags&CMD_WAIT_MUTEX){
shell_function= scp->sc_function;
// Wait execute command in sweep thread
while(shell_function)
osalThreadSleepMilliseconds(100);
do{
osalThreadSleepMilliseconds(100);}
while(shell_function);
}
else
scp->sc_function(shell_nargs-1, &shell_args[1]);

View file

@ -27,6 +27,7 @@
*/
#define START_MIN 50000
#define STOP_MAX 2700000000U
#define SPEED_OF_LIGHT 299792458
#define POINTS_COUNT 101
extern float measured[2][POINTS_COUNT][2];
@ -211,6 +212,7 @@ typedef struct trace {
#define FREQ_MODE_START_STOP 0x0
#define FREQ_MODE_CENTER_SPAN 0x1
#define FREQ_MODE_DOTTED_GRID 0x2
typedef struct config {
int32_t magic;

43
plot.c
View file

@ -8,13 +8,17 @@
static void cell_draw_marker_info(int x0, int y0);
static void draw_battery_status(void);
int16_t grid_offset;
int16_t grid_width;
static int16_t grid_offset;
static int16_t grid_width;
int16_t area_width = AREA_WIDTH_NORMAL;
int16_t area_height = AREA_HEIGHT_NORMAL;
// Depends from spi_buffer size, CELLWIDTH*CELLHEIGHT <= sizeof(spi_buffer)
// Cell render use spi buffer
typedef uint16_t pixel;
pixel *cell_buffer = (pixel *)spi_buffer;
// Cell size
// Depends from spi_buffer size, CELLWIDTH*CELLHEIGHT*sizeof(pixel) <= sizeof(spi_buffer)
#define CELLWIDTH (64)
#define CELLHEIGHT (32)
// Check buffer size
@ -46,7 +50,6 @@ static index_t trace_index[TRACES_MAX][POINTS_COUNT];
#define INDEX(x, y) ((((index_t)x)<<16)|(((index_t)y)))
#define CELL_X(i) (int)(((i)>>16))
#define CELL_Y(i) (int)(((i)&0xFFFF))
//#define CELL_P(i, x, y) (((((x)&0x03e0UL)<<22) | (((y)&0x03e0UL)<<17)) == ((i)&0xffc00000UL))
//#define floatToInt(v) ((int)(v))
static int
@ -755,7 +758,6 @@ static float time_of_index(int idx) {
}
static float distance_of_index(int idx) {
#define SPEED_OF_LIGHT 299792458
float distance = ((float)idx * (float)SPEED_OF_LIGHT) / ( (float)(frequencies[1] - frequencies[0]) * (float)FFT_SIZE * 2.0);
return distance * velocity_factor;
}
@ -852,7 +854,7 @@ cell_drawline(int x0, int y0, int x1, int y1, int c)
while (1){
if (y0>=0 && y0<CELLHEIGHT && x0>=0 && x0<CELLWIDTH)
spi_buffer[y0*CELLWIDTH+x0]|= c;
cell_buffer[y0*CELLWIDTH+x0]|= c;
if (x0 == x1 && y0 == y1)
return;
int e2 = err;
@ -928,7 +930,7 @@ draw_refpos(int x, int y, int c)
uint8_t bits = reference_bitmap[j];
while (bits){
if (x0 >= 0 && x0 < CELLWIDTH)
spi_buffer[y0*CELLWIDTH+x0] = (bits&0x80) ? c : DEFAULT_BG_COLOR;
cell_buffer[y0*CELLWIDTH+x0] = (bits&0x80) ? c : DEFAULT_BG_COLOR;
x0++;
bits<<=1;
}
@ -999,9 +1001,9 @@ draw_marker(int x, int y, int c, int ch)
force_color = true;
if (x0 >= 0 && x0 < CELLWIDTH && y0 >= 0 && y0 < CELLHEIGHT){
if (bits&0x80)
spi_buffer[y0*CELLWIDTH+x0] = c;
cell_buffer[y0*CELLWIDTH+x0] = c;
else if (force_color)
spi_buffer[y0*CELLWIDTH+x0] = DEFAULT_BG_COLOR;
cell_buffer[y0*CELLWIDTH+x0] = DEFAULT_BG_COLOR;
}
x0++;
bits<<=1;
@ -1153,7 +1155,6 @@ search_nearest_index(int x, int y, int t)
min_i = i;
}
}
return min_i;
}
@ -1210,8 +1211,8 @@ draw_cell(int m, int n)
#error "CELLWIDTH % 8 should be == 0 for speed, or need rewrite cell cleanup"
#endif
// Set DEFAULT_BG_COLOR for 8 pixels in one cycle
int count = h*CELLWIDTH / 8;
uint32_t *p = (uint32_t *)spi_buffer;
int count = h*CELLWIDTH / (16/sizeof(pixel));
uint32_t *p = (uint32_t *)cell_buffer;
while (count--) {
p[0] = DEFAULT_BG_COLOR|(DEFAULT_BG_COLOR<<16);
p[1] = DEFAULT_BG_COLOR|(DEFAULT_BG_COLOR<<16);
@ -1234,14 +1235,14 @@ draw_cell(int m, int n)
for (x = 0; x < w; x++) {
if (rectangular_grid_x(x+x0)){
for (y = 0; y < h; y++)
spi_buffer[y * CELLWIDTH + x] = c;
cell_buffer[y * CELLWIDTH + x] = c;
}
}
for (y = 0; y < h; y++) {
if (rectangular_grid_y(y+y0)){
for (x = 0; x < w; x++)
if (x+x0 >= CELLOFFSETX && x+x0 <= WIDTH+CELLOFFSETX)
spi_buffer[y * CELLWIDTH + x] = c;
cell_buffer[y * CELLWIDTH + x] = c;
}
}
}
@ -1250,14 +1251,14 @@ draw_cell(int m, int n)
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
if (smith_grid(x+x0, y+y0))
spi_buffer[y * CELLWIDTH + x] = c;
cell_buffer[y * CELLWIDTH + x] = c;
}
// Polar greed line (800 system ticks for all screen calls)
else if(trace_type&(1<<TRC_POLAR)){
for (y = 0; y < h; y++)
for (x = 0; x < w; x++)
if (polar_grid(x+x0, y+y0))
spi_buffer[y * CELLWIDTH + x] = c;
cell_buffer[y * CELLWIDTH + x] = c;
}
#if 0
else if(trace_type&(1<<TRC_ADMIT)){
@ -1265,7 +1266,7 @@ draw_cell(int m, int n)
for (x = 0; x < w; x++)
if (smith_grid3(x+x0, y+y0)
// smith_grid2(x+x0, y+y0, 0.5))
spi_buffer[y * CELLWIDTH + x] = c;
cell_buffer[y * CELLWIDTH + x] = c;
}
#endif
#endif
@ -1337,8 +1338,8 @@ draw_cell(int m, int n)
// Need right clip cell render (25 system ticks for all screen calls)
#if 1
if (w < CELLWIDTH){
uint16_t *src = spi_buffer+CELLWIDTH;
uint16_t *dst = spi_buffer+w;
pixel *src = cell_buffer+CELLWIDTH;
pixel *dst = cell_buffer+w;
for (y=h; --y; src+=CELLWIDTH-w)
for(x=w;x--;)
*dst++=*src++;
@ -1440,7 +1441,7 @@ cell_drawchar(uint8_t ch, int x, int y)
continue;
for (r = 0; r < ch_size; r++) {
if ((x+r) >= 0 && (x+r) < CELLWIDTH && (0x80 & bits))
spi_buffer[(y+c)*CELLWIDTH + (x+r)] = foreground_color;
cell_buffer[(y+c)*CELLWIDTH + (x+r)] = foreground_color;
bits <<= 1;
}
}
@ -1578,7 +1579,7 @@ cell_draw_marker_info(int x0, int y0)
cell_drawstring(S_SARROW, xpos, ypos);
xpos += 5;
float light_speed_ps = 299792458e-12; //(m/ps)
float light_speed_ps = SPEED_OF_LIGHT*1e-12; //(m/ps)
plot_printf(buf, sizeof buf, "Edelay %Fs %Fm", electrical_delay * 1e-12,
electrical_delay * light_speed_ps * velocity_factor);
cell_drawstring(buf, xpos, ypos);

View file

@ -41,7 +41,7 @@ static uint32_t current_freq = 0;
// Minimum value is 2, freq change apply at next dsp measure, and need skip it
#define DELAY_NORMAL 2
// Delay for bands (depend set band 1 more fast (can change before next dsp bufer ready, need wait additional interval)
// Delay for bands (depend set band 1 more fast (can change before next dsp buffer ready, need wait additional interval)
#define DELAY_BAND_1 3
#define DELAY_BAND_2 2
// Band changes need set delay after reset PLL