35 OutCode ComputeOutCode(
int x,
int y)
41 if (
x < 0) code |= LEFT;
42 else if (
x >= TFTWIDTH) code |= RIGHT;
43 if (y < 0) code |= TOP;
44 else if (y >= TFTHEIGHT) code |= BOTTOM;
51 void oledc_drawLinePrimative(
int x0,
int y0,
int x1,
int y1,
unsigned int color)
55 switch (TFTROTATION) {
59 x0 = TFTWIDTH - x0 - 1;
60 x1 = TFTWIDTH - x1 - 1;
66 x0 = TFTWIDTH - x0 - 1;
67 y0 = TFTHEIGHT - y0 - 1;
68 x1 = TFTWIDTH - x1 - 1;
69 y1 = TFTHEIGHT - y1 - 1;
74 y0 = TFTHEIGHT - y0 - 1;
75 y1 = TFTHEIGHT - y1 - 1;
86 OutCode outcode0 = ComputeOutCode(x0, y0);
87 OutCode outcode1 = ComputeOutCode(x1, y1);
91 if (!(outcode0 | outcode1)) {
94 }
else if (outcode0 & outcode1) {
102 OutCode outcodeOut = outcode0 ? outcode0 : outcode1;
106 if (outcodeOut & TOP) {
107 x = x0 + (x1 - x0) * (0 - y0) / (y1 - y0);
109 }
else if (outcodeOut & BOTTOM) {
110 x = x0 + (x1 - x0) * (TFTHEIGHT - y0 - 1) / (y1 - y0);
112 }
else if (outcodeOut & RIGHT) {
113 y = y0 + (y1 - y0) * (TFTWIDTH - x0 - 1) / (x1 - x0);
115 }
else if (outcodeOut & LEFT) {
116 y = y0 + (y1 - y0) * (0 - x0) / (x1 - x0);
122 if (outcodeOut == outcode0) {
125 outcode0 = ComputeOutCode(x0, y0);
129 outcode1 = ComputeOutCode(x1, y1);
136 oledc_writeCommand(SSD1331_CMD_DRAWLINE, 0);
138 oledc_writeCommand(x0, 0);
139 oledc_writeCommand(y0, 0);
140 oledc_writeCommand(x1, 0);
141 oledc_writeCommand(y1, 0);
143 oledc_writeCommand((color >> 11) << 1, 0);
144 oledc_writeCommand((color >> 5) & 0x3F, 0);
145 oledc_writeCommand((color << 1) & 0x3F, 0);
148 while (_tMark >
CNT);
154 void oledc_drawLine(
int x0,
int y0,
int x1,
int y1,
unsigned int color)
156 while (oledc_screenLock());
157 oledc_screenLockSet();
159 oledc_drawLinePrimative(x0, y0, x1, y1,color);
161 oledc_screenLockClr();