Chromium Code Reviews| 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 { | |
|
gkalsi
2016/03/09 21:13:37
DEBUG_ASSERT(fb)
cdotstout
2016/03/09 22:48:00
Done.
| |
| 126 if (!default_fb.image.pixels) { | |
| 127 switch (MLCD_FORMAT) { | |
| 128 case DISPLAY_FORMAT_RGB_111: | |
| 129 // Use closest match format supported by gfx lib | |
| 130 default_fb.image.format = IMAGE_FORMAT_RGB_332; | |
| 131 default_fb.image.rowbytes = MLCD_WIDTH; | |
| 132 break; | |
| 133 case DISPLAY_FORMAT_MONO_1: | |
| 134 default_fb.image.format = IMAGE_FORMAT_MONO_1; | |
| 135 default_fb.image.rowbytes = (MLCD_WIDTH + 7) >> 3; | |
| 136 break; | |
| 137 default: | |
| 138 DEBUG_ASSERT(false); | |
| 139 return ERR_NOT_SUPPORTED; | |
| 140 } | |
| 141 default_fb.image.pixels = malloc(MLCD_HEIGHT * default_fb.image.rowbytes ); | |
| 142 default_fb.image.width = MLCD_WIDTH; | |
| 143 default_fb.image.height = MLCD_HEIGHT; | |
| 144 default_fb.flush = mlcd_flush; | |
| 145 default_fb.format = MLCD_FORMAT; | |
| 146 } | |
| 147 *fb = default_fb; | |
| 148 return NO_ERROR; | |
| 149 } | |
| 150 | |
| 151 status_t display_present(struct display_image *image, uint starty, uint endy) | |
| 152 { | |
| 153 status_t status = NO_ERROR; | |
| 121 chip_select(true); | 154 chip_select(true); |
| 122 | 155 |
| 123 static uint8_t localbuf[MLCD_BUF_SIZE]; | 156 static uint8_t localbuf[MLCD_BUF_SIZE]; |
| 124 uint8_t *bufptr = localbuf; | 157 uint8_t *bufptr = localbuf; |
| 125 uint8_t trailer = 0; | 158 uint8_t trailer = 0; |
| 126 | 159 |
| 127 // The first line is preceeded with a write command. | 160 // The first line is preceeded with a write command. |
| 128 *bufptr++ = MLCD_WR | vcom_state; | 161 *bufptr++ = MLCD_WR | vcom_state; |
| 129 | 162 |
| 130 vcom_state = vcom_state == VCOM_HI ? VCOM_LO : VCOM_HI; | 163 vcom_state = vcom_state == VCOM_HI ? VCOM_LO : VCOM_HI; |
| 131 | 164 |
| 132 // Send the image data. | 165 // Send the image data. |
| 133 for (uint j = starty; j <= endy; ++j) { | 166 for (uint j = starty; j <= endy; ++j) { |
| 134 *bufptr++ = (j + 1); | 167 *bufptr++ = (j + 1); |
| 135 | 168 |
| 136 bufptr += lcd_get_line(framebuffer, j, bufptr); | 169 bufptr += lcd_get_line(image, j, bufptr); |
| 137 | 170 |
| 138 // 8 bit trailer per line | 171 // 8 bit trailer per line |
| 139 *bufptr++ = trailer; | 172 *bufptr++ = trailer; |
| 140 if (j == endy) { | 173 if (j == endy) { |
| 141 // 16 bit trailer on the last line | 174 // 16 bit trailer on the last line |
| 142 *bufptr++ = trailer; | 175 *bufptr++ = trailer; |
| 143 } | 176 } |
| 144 | 177 |
| 145 if (HAL_SPI_Transmit(&SpiHandle, localbuf, bufptr - localbuf, HAL_MAX_DE LAY) != HAL_OK) { | 178 if (HAL_SPI_Transmit(&SpiHandle, localbuf, bufptr - localbuf, HAL_MAX_DE LAY) != HAL_OK) { |
| 179 status = ERR_GENERIC; | |
| 146 goto finish; | 180 goto finish; |
| 147 } | 181 } |
| 148 | 182 |
| 149 bufptr = localbuf; | 183 bufptr = localbuf; |
| 150 } | 184 } |
| 151 | 185 |
| 152 finish: | 186 finish: |
| 153 chip_select(false); | 187 chip_select(false); |
| 188 | |
| 189 return status; | |
| 154 } | 190 } |
| 155 | 191 |
| 156 status_t display_get_info(struct display_info *info) | 192 status_t display_get_info(struct display_info *info) |
| 157 { | 193 { |
| 158 LTRACEF("display_info %p\n", info); | 194 LTRACEF("display_info %p\n", info); |
| 159 | 195 |
| 160 info->framebuffer = (void *)framebuffer; | 196 info->format = MLCD_FORMAT; |
| 161 info->format = FB_FORMAT; | |
| 162 info->width = MLCD_WIDTH; | 197 info->width = MLCD_WIDTH; |
| 163 info->height = MLCD_HEIGHT; | 198 info->height = MLCD_HEIGHT; |
| 164 info->stride = FB_STRIDE; | |
| 165 info->flush = mlcd_flush; | |
| 166 | 199 |
| 167 return NO_ERROR; | 200 return NO_ERROR; |
| 168 } | 201 } |
| OLD | NEW |