OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 Gurjant Kalsi <me@gurjantkalsi.com> | 2 * Copyright (c) 2015 Gurjant Kalsi <me@gurjantkalsi.com> |
3 * | 3 * |
4 * Permission is hereby granted, free of charge, to any person obtaining | 4 * Permission is hereby granted, free of charge, to any person obtaining |
5 * a copy of this software and associated documentation files | 5 * a copy of this software and associated documentation files |
6 * (the "Software"), to deal in the Software without restriction, | 6 * (the "Software"), to deal in the Software without restriction, |
7 * including without limitation the rights to use, copy, modify, merge, | 7 * including without limitation the rights to use, copy, modify, merge, |
8 * publish, distribute, sublicense, and/or sell copies of the Software, | 8 * publish, distribute, sublicense, and/or sell copies of the Software, |
9 * and to permit persons to whom the Software is furnished to do so, | 9 * and to permit persons to whom the Software is furnished to do so, |
10 * subject to the following conditions: | 10 * subject to the following conditions: |
11 * | 11 * |
12 * The above copyright notice and this permission notice shall be | 12 * The above copyright notice and this permission notice shall be |
13 * included in all copies or substantial portions of the Software. | 13 * included in all copies or substantial portions of the Software. |
14 * | 14 * |
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 */ | 22 */ |
23 | 23 |
24 // 1.33 Inch 3-Bit RGB Sharp Color LCD | 24 // 1.33 Inch 3-Bit RGB Sharp Color LCD |
25 #include <target/display/LS013B7DH06.h> | 25 #include <target/display/LS013B7DH06.h> |
26 #include <string.h> | 26 #include <string.h> |
| 27 #include <assert.h> |
27 | 28 |
28 #define SET_BIT(BUF, BITNUM) ((BUF)[(BITNUM) >> 3] |= (0xff & (0x1 << ((BITNUM)
& 0x07)))) | 29 #define SET_BIT(BUF, BITNUM) ((BUF)[(BITNUM) >> 3] |= (0x1 << ((BITNUM) & 0x07))
) |
29 | 30 |
30 uint8_t lcd_get_line(uint8_t *framebuffer, uint8_t idx, uint8_t *result) | 31 uint8_t lcd_get_line(struct display_image *image, uint8_t idx, uint8_t *result) |
31 { | 32 { |
32 framebuffer += FB_STRIDE * idx; | 33 uint8_t *framebuffer = (uint8_t *)image->pixels + image->rowbytes * idx; |
33 | 34 |
34 memset(result, 0, MLCD_BYTES_LINE); | 35 memset(result, 0, MLCD_BYTES_LINE); |
35 | 36 |
36 #if FB_FORMAT == DISPLAY_FORMAT_RGB_332 | 37 if (image->format == IMAGE_FORMAT_RGB_332) { |
37 for (int i = 0; i < MLCD_WIDTH; ++i) { | 38 for (int i = 0; i < MLCD_WIDTH; ++i) { |
38 uint8_t inpix = framebuffer[i]; | 39 uint8_t inpix = framebuffer[i]; |
39 | 40 |
40 int j = i * 3; | 41 int j = i * 3; |
41 | 42 |
42 if (inpix & 0x80) { | 43 if (inpix & 0x80) { |
43 SET_BIT(result, j); | 44 SET_BIT(result, j); |
| 45 } |
| 46 if (inpix & 0x10) { |
| 47 SET_BIT(result, j + 1); |
| 48 } |
| 49 if (inpix & 0x02) { |
| 50 SET_BIT(result, j + 2); |
| 51 } |
44 } | 52 } |
45 if (inpix & 0x10) { | 53 } else if (image->format == IMAGE_FORMAT_RGB_x111) { |
46 SET_BIT(result, j + 1); | 54 int j = 0; |
| 55 for (uint i = 0; i < image->width; i += 2) { |
| 56 uint8_t val = *framebuffer++; |
| 57 uint8_t inpix = val & 0xf; |
| 58 |
| 59 if (inpix & 0x4) { |
| 60 SET_BIT(result, j); |
| 61 } |
| 62 if (inpix & 0x2) { |
| 63 SET_BIT(result, j + 1); |
| 64 } |
| 65 if (inpix & 0x1) { |
| 66 SET_BIT(result, j + 2); |
| 67 } |
| 68 |
| 69 inpix = val >> 4; |
| 70 if (inpix & 0x4) { |
| 71 SET_BIT(result, j + 3); |
| 72 } |
| 73 if (inpix & 0x2) { |
| 74 SET_BIT(result, j + 4); |
| 75 } |
| 76 if (inpix & 0x1) { |
| 77 SET_BIT(result, j + 5); |
| 78 } |
| 79 j += 6; |
47 } | 80 } |
48 if (inpix & 0x02) { | 81 if (image->width & 1) { |
49 SET_BIT(result, j + 2); | 82 uint8_t val = *framebuffer; |
| 83 uint8_t inpix = val & 0xf; |
| 84 |
| 85 if (inpix & 0x4) { |
| 86 SET_BIT(result, j); |
| 87 } |
| 88 if (inpix & 0x2) { |
| 89 SET_BIT(result, j + 1); |
| 90 } |
| 91 if (inpix & 0x1) { |
| 92 SET_BIT(result, j + 2); |
| 93 } |
50 } | 94 } |
| 95 } else { |
| 96 DEBUG_ASSERT(false); |
51 } | 97 } |
52 #elif FB_FORMAT == DISPLAY_FORMAT_RGB_x111 | |
53 for (int i = 0; i < FB_STRIDE; ++i) { | |
54 uint8_t val = framebuffer[i]; | |
55 uint8_t inpix; | |
56 | |
57 int j = i * 6; | |
58 | |
59 inpix = val & 0xf; | |
60 if (inpix & 0x4) { | |
61 SET_BIT(result, j); | |
62 } | |
63 if (inpix & 0x2) { | |
64 SET_BIT(result, j + 1); | |
65 } | |
66 if (inpix & 0x1) { | |
67 SET_BIT(result, j + 2); | |
68 } | |
69 | |
70 inpix = val >> 4; | |
71 if (inpix & 0x4) { | |
72 SET_BIT(result, j + 3); | |
73 } | |
74 if (inpix & 0x2) { | |
75 SET_BIT(result, j + 4); | |
76 } | |
77 if (inpix & 0x1) { | |
78 SET_BIT(result, j + 5); | |
79 } | |
80 } | |
81 #else | |
82 #error Unhandled FB_FORMAT | |
83 #endif | |
84 | 98 |
85 return MLCD_BYTES_LINE; | 99 return MLCD_BYTES_LINE; |
86 } | 100 } |
OLD | NEW |