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 #include <err.h> | 24 #include <err.h> |
25 #include <debug.h> | 25 #include <debug.h> |
26 #include <trace.h> | 26 #include <trace.h> |
27 #include <rand.h> | 27 #include <rand.h> |
| 28 #include <stdlib.h> |
| 29 #include <assert.h> |
28 | 30 |
29 #include <dev/display.h> | 31 #include <dev/display.h> |
30 #include <platform/gpio.h> | 32 #include <platform/gpio.h> |
31 #include <target/memory_lcd.h> | 33 #include <target/memory_lcd.h> |
32 | 34 |
33 #if defined (LCD_LS013B7DH06) | 35 #if defined (LCD_LS013B7DH06) |
34 #include <target/display/LS013B7DH06.h> | 36 #include <target/display/LS013B7DH06.h> |
35 #elif defined (LCD_LS027B7DH01) | 37 #elif defined (LCD_LS027B7DH01) |
36 #include <target/display/LS027B7DH01.h> | 38 #include <target/display/LS027B7DH01.h> |
37 #elif defined (LCD_LS013B7DH03) | 39 #elif defined (LCD_LS013B7DH03) |
38 #include <target/display/LS013B7DH03.h> | 40 #include <target/display/LS013B7DH03.h> |
39 #endif | 41 #endif |
40 | 42 |
41 #define LOCAL_TRACE 0 | 43 #define LOCAL_TRACE 0 |
42 | 44 |
43 SPI_HandleTypeDef SpiHandle; | 45 SPI_HandleTypeDef SpiHandle; |
44 | 46 |
45 #define MLCD_WR 0x01 // LCD Write Command | 47 #define MLCD_WR 0x01 // LCD Write Command |
46 #define MLCD_CM 0x04 // LCD Clear Memory Command | 48 #define MLCD_CM 0x04 // LCD Clear Memory Command |
47 #define MLCD_NO 0x00 // LCD No-op command | 49 #define MLCD_NO 0x00 // LCD No-op command |
48 | 50 |
49 // 5 bytes used as control bytes, MLCD_BYTES_LINE bytes used to data | 51 // 5 bytes used as control bytes, MLCD_BYTES_LINE bytes used to data |
50 #define MLCD_BUF_SIZE (MLCD_BYTES_LINE + 5) | 52 #define MLCD_BUF_SIZE (MLCD_BYTES_LINE + 5) |
51 | 53 |
52 #define VCOM_HI 0x02 | 54 #define VCOM_HI 0x02 |
53 #define VCOM_LO 0x00 | 55 #define VCOM_LO 0x00 |
54 | 56 |
55 static uint8_t framebuffer[MLCD_HEIGHT * FB_STRIDE]; | 57 static struct display_framebuffer default_fb; |
56 static uint8_t vcom_state; | 58 static uint8_t vcom_state; |
57 | 59 |
58 static void chip_select(bool s) | 60 static void chip_select(bool s) |
59 { | 61 { |
60 if (s) { | 62 if (s) { |
61 gpio_set(GPIO(GPIO_PORT_B, 12), GPIO_PIN_SET); | 63 gpio_set(GPIO(GPIO_PORT_B, 12), GPIO_PIN_SET); |
62 } else { | 64 } else { |
63 gpio_set(GPIO(GPIO_PORT_B, 12), GPIO_PIN_RESET); | 65 gpio_set(GPIO(GPIO_PORT_B, 12), GPIO_PIN_RESET); |
64 } | 66 } |
65 } | 67 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 109 |
108 vcom_state = VCOM_LO; | 110 vcom_state = VCOM_LO; |
109 | 111 |
110 lcd_power(true); | 112 lcd_power(true); |
111 | 113 |
112 mlcd_clear(); | 114 mlcd_clear(); |
113 | 115 |
114 return NO_ERROR; | 116 return NO_ERROR; |
115 } | 117 } |
116 | 118 |
117 | |
118 | |
119 static void mlcd_flush(uint starty, uint endy) | 119 static void mlcd_flush(uint starty, uint endy) |
120 { | 120 { |
| 121 display_present(&default_fb.image, starty, endy); |
| 122 } |
| 123 |
| 124 status_t display_get_framebuffer(struct display_framebuffer *fb) |
| 125 { |
| 126 DEBUG_ASSERT(fb); |
| 127 if (!default_fb.image.pixels) { |
| 128 switch (MLCD_FORMAT) { |
| 129 // Use closest match format supported by gfx lib |
| 130 case DISPLAY_FORMAT_RGB_111: |
| 131 default_fb.image.format = IMAGE_FORMAT_RGB_332; |
| 132 default_fb.image.stride = MLCD_WIDTH; |
| 133 default_fb.image.rowbytes = MLCD_WIDTH; |
| 134 break; |
| 135 case DISPLAY_FORMAT_MONO_1: |
| 136 default_fb.image.format = IMAGE_FORMAT_MONO_8; |
| 137 default_fb.image.stride = MLCD_WIDTH; |
| 138 default_fb.image.rowbytes = MLCD_WIDTH; |
| 139 break; |
| 140 default: |
| 141 DEBUG_ASSERT(false); |
| 142 return ERR_NOT_SUPPORTED; |
| 143 } |
| 144 default_fb.image.pixels = malloc(MLCD_HEIGHT * |
| 145 default_fb.image.rowbytes); |
| 146 default_fb.image.width = MLCD_WIDTH; |
| 147 default_fb.image.height = MLCD_HEIGHT; |
| 148 default_fb.flush = mlcd_flush; |
| 149 default_fb.format = MLCD_FORMAT; |
| 150 } |
| 151 *fb = default_fb; |
| 152 return NO_ERROR; |
| 153 } |
| 154 |
| 155 status_t display_present(struct display_image *image, uint starty, uint endy) |
| 156 { |
| 157 DEBUG_ASSERT(image); |
| 158 status_t status = NO_ERROR; |
121 chip_select(true); | 159 chip_select(true); |
122 | 160 |
123 static uint8_t localbuf[MLCD_BUF_SIZE]; | 161 static uint8_t localbuf[MLCD_BUF_SIZE]; |
124 uint8_t *bufptr = localbuf; | 162 uint8_t *bufptr = localbuf; |
125 uint8_t trailer = 0; | 163 uint8_t trailer = 0; |
126 | 164 |
127 // The first line is preceeded with a write command. | 165 // The first line is preceeded with a write command. |
128 *bufptr++ = MLCD_WR | vcom_state; | 166 *bufptr++ = MLCD_WR | vcom_state; |
129 | 167 |
130 vcom_state = vcom_state == VCOM_HI ? VCOM_LO : VCOM_HI; | 168 vcom_state = vcom_state == VCOM_HI ? VCOM_LO : VCOM_HI; |
131 | 169 |
132 // Send the image data. | 170 // Send the image data. |
133 for (uint j = starty; j <= endy; ++j) { | 171 for (uint j = starty; j <= endy; ++j) { |
134 *bufptr++ = (j + 1); | 172 *bufptr++ = (j + 1); |
135 | 173 |
136 bufptr += lcd_get_line(framebuffer, j, bufptr); | 174 bufptr += lcd_get_line(image, j, bufptr); |
137 | 175 |
138 // 8 bit trailer per line | 176 // 8 bit trailer per line |
139 *bufptr++ = trailer; | 177 *bufptr++ = trailer; |
140 if (j == endy) { | 178 if (j == endy) { |
141 // 16 bit trailer on the last line | 179 // 16 bit trailer on the last line |
142 *bufptr++ = trailer; | 180 *bufptr++ = trailer; |
143 } | 181 } |
144 | 182 |
145 if (HAL_SPI_Transmit(&SpiHandle, localbuf, bufptr - localbuf, HAL_MAX_DE
LAY) != HAL_OK) { | 183 if (HAL_SPI_Transmit(&SpiHandle, localbuf, bufptr - localbuf, |
| 184 HAL_MAX_DELAY) != HAL_OK) { |
| 185 status = ERR_GENERIC; |
146 goto finish; | 186 goto finish; |
147 } | 187 } |
148 | 188 |
149 bufptr = localbuf; | 189 bufptr = localbuf; |
150 } | 190 } |
151 | 191 |
152 finish: | 192 finish: |
153 chip_select(false); | 193 chip_select(false); |
| 194 |
| 195 return status; |
154 } | 196 } |
155 | 197 |
156 status_t display_get_info(struct display_info *info) | 198 status_t display_get_info(struct display_info *info) |
157 { | 199 { |
| 200 DEBUG_ASSERT(info); |
158 LTRACEF("display_info %p\n", info); | 201 LTRACEF("display_info %p\n", info); |
159 | 202 |
160 info->framebuffer = (void *)framebuffer; | 203 info->format = MLCD_FORMAT; |
161 info->format = FB_FORMAT; | |
162 info->width = MLCD_WIDTH; | 204 info->width = MLCD_WIDTH; |
163 info->height = MLCD_HEIGHT; | 205 info->height = MLCD_HEIGHT; |
164 info->stride = FB_STRIDE; | |
165 info->flush = mlcd_flush; | |
166 | 206 |
167 return NO_ERROR; | 207 return NO_ERROR; |
168 } | 208 } |
OLD | NEW |