Corrected touch cal bug and code squeezing

master
erikkaashoek 5 years ago
parent 73ae3f901d
commit 29c10161dd

@ -22,6 +22,7 @@
#include "nanovna.h" #include "nanovna.h"
#include "spi.h" #include "spi.h"
// Allow enable DMA for read display data // Allow enable DMA for read display data
//#define __USE_DISPLAY_DMA_RX__ //#define __USE_DISPLAY_DMA_RX__
@ -666,7 +667,7 @@ void ili9341_drawstringV(const char *str, int x, int y)
ili9341_drawstring(str, ILI9341_HEIGHT-y, x); ili9341_drawstring(str, ILI9341_HEIGHT-y, x);
ili9341_set_rotation(DISPLAY_ROTATION_0); ili9341_set_rotation(DISPLAY_ROTATION_0);
} }
#ifndef wFONT_GET_DATA
int ili9341_drawchar_size(uint8_t ch, int x, int y, uint8_t size) int ili9341_drawchar_size(uint8_t ch, int x, int y, uint8_t size)
{ {
uint16_t *buf = spi_buffer; uint16_t *buf = spi_buffer;
@ -684,17 +685,19 @@ int ili9341_drawchar_size(uint8_t ch, int x, int y, uint8_t size)
return w*size; return w*size;
} }
void ili9341_drawstring_size(const char *str, int x, int y, uint8_t size)
{
while (*str)
x += ili9341_drawchar_size(*str++, x, y, size);
}
#endif
void ili9341_drawfont(uint8_t ch, int x, int y) void ili9341_drawfont(uint8_t ch, int x, int y)
{ {
blit8BitWidthBitmap(x, y, NUM_FONT_GET_WIDTH, NUM_FONT_GET_HEIGHT, blit8BitWidthBitmap(x, y, NUM_FONT_GET_WIDTH, NUM_FONT_GET_HEIGHT,
NUM_FONT_GET_DATA(ch)); NUM_FONT_GET_DATA(ch));
} }
void ili9341_drawstring_size(const char *str, int x, int y, uint8_t size)
{
while (*str)
x += ili9341_drawchar_size(*str++, x, y, size);
}
#if 0 #if 0
static void ili9341_pixel(int x, int y, uint16_t color) static void ili9341_pixel(int x, int y, uint16_t color)
{ {
@ -710,21 +713,21 @@ static void ili9341_pixel(int x, int y, uint16_t color)
void ili9341_line(int x0, int y0, int x1, int y1) void ili9341_line(int x0, int y0, int x1, int y1)
{ {
SWAP(foreground_color, background_color);
#if 0 #if 0
// modifed Bresenham's line algorithm, see https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm // modified Bresenham's line algorithm, see https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
int dx = x1 - x0, sx = 1; if (dx < 0) {dx = -dx; sx = -1;} int dx = x1 - x0, sx = 1; if (dx < 0) {dx = -dx; sx = -1;}
int dy = y1 - y0, sy = 1; if (dy < 0) {dy = -dy; sy = -1;} int dy = y1 - y0, sy = 1; if (dy < 0) {dy = -dy; sy = -1;}
int err = (dx > dy ? dx : -dy) / 2; int err = (dx > dy ? dx : -dy) / 2;
while (1) { while (1) {
ili9341_pixel(x0, y0, DEFAULT_FG_COLOR); ili9341_fill(x0, y0, 1, 1);
if (x0 == x1 && y0 == y1) if (x0 == x1 && y0 == y1)
break; break;
int e2 = err; int e2 = err;
if (e2 > -dx) { err -= dy; x0 += sx; } if (e2 > -dx) { err -= dy; x0 += sx; }
if (e2 < dy) { err += dx; y0 += sy; } if (e2 < dy) { err += dx; y0 += sy; }
} }
#endif #else
SWAP(foreground_color, background_color);
if (x0 > x1) { if (x0 > x1) {
SWAP(x0, x1); SWAP(x0, x1);
SWAP(y0, y1); SWAP(y0, y1);
@ -755,6 +758,7 @@ void ili9341_line(int x0, int y0, int x1, int y1)
x0 += dx; x0 += dx;
y0 += dy; y0 += dy;
} }
#endif
SWAP(foreground_color, background_color); SWAP(foreground_color, background_color);
} }

@ -22,7 +22,7 @@
#include "stdlib.h" #include "stdlib.h"
#pragma GCC push_options #pragma GCC push_options
#pragma GCC optimize ("Og") #pragma GCC optimize ("Os")
//#define __DEBUG_AGC__ If set the AGC value will be shown in the stored trace and FAST_SWEEP rmmode will be disabled //#define __DEBUG_AGC__ If set the AGC value will be shown in the stored trace and FAST_SWEEP rmmode will be disabled

26
ui.c

@ -25,6 +25,9 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#pragma GCC push_options
#pragma GCC optimize ("Os")
uistat_t uistat = { uistat_t uistat = {
digit: 6, digit: 6,
current_trace: 0, current_trace: 0,
@ -76,7 +79,6 @@ enum {
#endif #endif
#define NUMINPUT_LEN 10 #define NUMINPUT_LEN 10
static uint8_t ui_mode = UI_NORMAL; static uint8_t ui_mode = UI_NORMAL;
static uint8_t keypad_mode; static uint8_t keypad_mode;
static uint8_t keypads_last_index; static uint8_t keypads_last_index;
@ -125,7 +127,6 @@ typedef struct {
#define EVT_TOUCH_PRESSED 2 #define EVT_TOUCH_PRESSED 2
#define EVT_TOUCH_RELEASED 3 #define EVT_TOUCH_RELEASED 3
#define EVT_TOUCH_LONGPRESS 4 #define EVT_TOUCH_LONGPRESS 4
static int8_t last_touch_status = EVT_TOUCH_NONE; static int8_t last_touch_status = EVT_TOUCH_NONE;
static int16_t last_touch_x; static int16_t last_touch_x;
static int16_t last_touch_y; static int16_t last_touch_y;
@ -320,13 +321,21 @@ touch_wait_release(void)
while (touch_check() != EVT_TOUCH_NONE) while (touch_check() != EVT_TOUCH_NONE)
chThdSleepMilliseconds(20); chThdSleepMilliseconds(20);
} }
#if 0
static inline void static inline void
touch_wait_pressed(void) touch_wait_pressed(void)
{ {
while (touch_check() != EVT_TOUCH_PRESSED) while (touch_check() != EVT_TOUCH_PRESSED)
; ;
} }
#endif
static inline void
touch_wait_released(void)
{
while (touch_check() != EVT_TOUCH_RELEASED)
;
}
void void
touch_cal_exec(void) touch_cal_exec(void)
@ -341,8 +350,8 @@ touch_cal_exec(void)
ili9341_line(0, 0, 32, 0); ili9341_line(0, 0, 32, 0);
ili9341_line(0, 0, 32, 32); ili9341_line(0, 0, 32, 32);
ili9341_drawstring("TOUCH UPPER LEFT", 40, 40); ili9341_drawstring("TOUCH UPPER LEFT", 40, 40);
touch_wait_released();
touch_wait_release(); // touch_wait_release();
x1 = last_touch_x; x1 = last_touch_x;
y1 = last_touch_y; y1 = last_touch_y;
@ -352,7 +361,8 @@ touch_cal_exec(void)
ili9341_line(LCD_WIDTH-1, LCD_HEIGHT-1, LCD_WIDTH-32, LCD_HEIGHT-32); ili9341_line(LCD_WIDTH-1, LCD_HEIGHT-1, LCD_WIDTH-32, LCD_HEIGHT-32);
ili9341_drawstring("TOUCH LOWER RIGHT", 210, 200); ili9341_drawstring("TOUCH LOWER RIGHT", 210, 200);
touch_wait_release(); touch_wait_released();
// touch_wait_release();
x2 = last_touch_x; x2 = last_touch_x;
y2 = last_touch_y; y2 = last_touch_y;
@ -2826,3 +2836,7 @@ int check_touched(void)
touch_start_watchdog(); touch_start_watchdog();
return touched; return touched;
} }
#pragma GCC pop_options

@ -16,8 +16,6 @@
* the Free Software Foundation, Inc., 51 Franklin Street, * the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#pragma GCC push_options
#pragma GCC optimize ("Os")
#define FORM_ICON_WIDTH 16 #define FORM_ICON_WIDTH 16
@ -2632,6 +2630,3 @@ redraw_cal_status:
} }
} }
#pragma GCC pop_options

Loading…
Cancel
Save

Powered by TurnKey Linux.