ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
wire.c
Go to the documentation of this file.
1 
23 #include "user_config.h"
24 
25 #include <stdint.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <math.h>
29 
30 #include "display/ili9341.h"
31 #include "cordic/cordic.h"
32 #include "wire/wire_types.h"
33 #include "wire/wire.h"
34 
35 /*
36  @brief convert fixed point coordinate to floating point
37  @param [in] *in: fixed point coordinate
38  @param [out] *out: floating point coordinate
39  @return void
40 */
41 void wire2fp(wire_p *in, point *out)
42 {
43  // Point
44  out->x = WIRE_2FP(in->x);
45  out->y = WIRE_2FP(in->y);
46  out->z = WIRE_2FP(in->z);
47 }
48 
49 /*
50  @brief Draw a wireframe
51  @param [in] *wire: fixed point points
52  @param [in] *edge: fixed point edges - optional or NULL
53  @param [in] *view: view point
54  @param [in] x: X offset
55  @param [in] y: Y offsetfactor
56  @param [in] scale: scale factor
57  @param [in] color: color
58  @return void
59 */
60 void wire_draw(window *win, const wire_p *wire, const wire_e *edge, point *view, int x, int y, double scale, uint16_t color)
61 {
62  int i;
63  int last = WIRE_SEP;
64  int x0 = 0;
65  int y0 = 0;
66  int x1 = 0;
67  int y1 = 0;
68  int z = 0;
69  wire_p W;
70  wire_e E;
71  point P,R;
72 
73  W.x = 0;
74  W.y = 0;
75  W.z = 0;
76 
77  if(edge != NULL )
78  {
79  for (i = 0;; i++)
80  {
81  // E = edge[i];
82  cpy_flash((uint8_t *) &edge[i], (uint8_t *) &E, sizeof(E));
83  if(E.p1 == -1)
84  break;
85 
86  // P1
87  cpy_flash((uint8_t *) &wire[E.p1], (uint8_t *) &W, sizeof(W));
88  wire2fp(&W, &P);
89  // CORDIC Rotate
90  rotate(&P,view);
91 
92  // CORDIC Perspective Projection Offset and Scale
93  PerspectiveProjection(&P, scale, x,y);
94  x0 = P.x;
95  y0 = P.y;
96 
97  // P2
98  cpy_flash((uint8_t *) &wire[E.p2], (uint8_t *) &W, sizeof(W));
99  wire2fp(&W, &P);
100  // CORDIC Rotate
101  rotate(&P,view);
102 
103 
104  // CORDIC Perspective Projection Offset and Scale
105  PerspectiveProjection(&P, scale, x,y);
106  x1 = P.x;
107  y1 = P.y;
108 
109  // Draw line
110  tft_drawLine(win, x0, y0, x1, y1, color);
111 //printf("i:%d (x:%d,y:%d),(x1:%d,y1:%d),color:%04x\n", i,(int)x0, (int)y0, (int)x1, (int)y1, (int)color);
112 
113  optimistic_yield(1000);
114  wdt_reset();
115  }
116  return;
117  }
118 
119  /* edge == NULL */
120  /* We have a list of connected points and no edge data */
121  for (i = 0; ; i++)
122  {
123  // W = wire[i];
124  cpy_flash((uint8_t *) &wire[i], (uint8_t *) &W, sizeof(W));
125 
126  if(W.x == WIRE_END)
127  {
128  break;
129  }
130  if(W.x == WIRE_SEP)
131  {
132  last = WIRE_SEP;
133  continue;
134  }
135 
136  // Get next point
137  wire2fp(&W, &P);
138 
139  // CORDIC Rotate
140  rotate(&P,view);
141 
142  // FIXME - Add proper hidden line removal
143  // add a flag for this
144  // Observation: for a sphere we can cut a plain parallel to the view plain
145  // intersecting the objects center at 0,0,0 point.
146  // We then skip points below this plain (ie. away from the viewer).
147 #if 0
148  if(P.z >= 0.0)
149  {
150  // force restart, we have no points
151  last = WIRE_SEP;
152  continue;
153  }
154 #endif
155 
156  // CORDIC Perspective Projection Offset and Scale
157  PerspectiveProjection(&P, scale, x,y);
158 
159  if(last == WIRE_SEP)
160  {
161  // first point in list ??
162  x0 = P.x;
163  y0 = P.y;
164  last = 0;
165  continue;
166  }
167  x1 = P.x;
168  y1 = P.y;
169  last = 0;
170 
171  //printf("i:%d,x:%d,y:%d-x1:%d,y1:%d,color:%04x", i,(int)x0, (int)y0, (int)x1, (int)y1, (int)color);
172 
173  // Draw line
174  tft_drawLine(win, x0, y0, x1, y1, color);
175 
176  // First is Next
177  x0 = x1;
178  y0 = y1;
179 
180  optimistic_yield(1000);
181  wdt_reset();
182  }
183 //printf("i:%d,done\n",(int) i);
184 }
unsigned short uint16_t
Definition: send.c:18
Master include file for project Includes all project includes and defines here.
void cpy_flash(uint8_t *src, uint8_t *dest, int size)
Copy data from Flash to Ram Uses flash_read8() to avoid alighnment problems.
Definition: flash.c:89
void wire2fp(wire_p *in, point *out)
Definition: wire.c:41
int16_t y[XYSTACK+2]
Definition: ili9341.c:372
wire_t z
Definition: wire_types.h:31
#define WIRE_SEP
Definition: wire_types.h:42
void optimistic_yield(uint32_t interval_us)
Definition: user_task.c:102
int16_t x[XYSTACK+2]
Definition: ili9341.c:371
#define NULL
Definition: cpu.h:55
MEMSPACE void PerspectiveProjection(point *P, double scale, int x, int y)
Definition: cordic.c:310
double y
Definition: cordic.h:40
Cordic Routines Handle angle outside of the first quadrant Added standalone test to verify CORDIC aga...
wire_t p1
Definition: wire_types.h:35
#define WIRE_2FP(a)
Definition: wire_types.h:44
wire_t x
Definition: wire_types.h:29
void tft_drawLine(window *win, int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
Draw line From my blit test code testit.c 1984 - 1985 Mike Gore.
Definition: ili9341.c:1389
wire_t p2
Definition: wire_types.h:36
double x
Definition: cordic.h:39
Point definition.
Definition: cordic.h:37
MEMSPACE void wdt_reset(void)
reset watchdog
Definition: system.c:190
wireframe view code
Definition: ili9341.h:34
void wire_draw(window *win, const wire_p *wire, const wire_e *edge, point *view, int x, int y, double scale, uint16_t color)
Definition: wire.c:60
wire_t y
Definition: wire_types.h:30
wireframe view code
ili9341 driver inspired by Adafruit ili9341 code All code in this file has been rewritten by Mike Gor...
unsigned char uint8_t
Definition: send.c:17
#define WIRE_END
Definition: wire_types.h:43
double z
Definition: cordic.h:41
MEMSPACE void rotate(point *P, point *V)
Rotate point P by View point.
Definition: cordic.c:265