1 /*
2 * Copyright (c) 2016 Craig Stout <cstout@chromium.org>
3 *
4 * Use of this source code is governed by a MIT-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/MIT
7 */
8
9 #if defined (LCD_LS027B7DH01)
10 #include <target/display/LS027B7DH01.h>
11 #elif defined (LCD_LS013B7DH03)
12 #include <target/display/LS013B7DH03.h>
13 #else
14 #error Undefined display header
15 #endif
16
17 #include <string.h>
18 #include <assert.h>
19
20 #define SET_BIT(BUF, BITNUM) ((BUF)[(BITNUM) >> 3] |= (0x1 << ((BITNUM) & 0x07)))
21
lcd_get_line(struct display_image * image,uint8_t idx,uint8_t * result)22 uint8_t lcd_get_line(struct display_image *image, uint8_t idx, uint8_t *result) {
23 uint8_t *framebuffer = (uint8_t *) image->pixels + image->rowbytes * idx;
24
25 if (image->format == IMAGE_FORMAT_MONO_1) {
26 memcpy(result, framebuffer, MLCD_BYTES_LINE);
27 } else if (image->format == IMAGE_FORMAT_MONO_8) {
28 memset(result, 0, MLCD_BYTES_LINE);
29 for (uint i = 0; i < MLCD_WIDTH; ++i) {
30 if (framebuffer[i] > 128) {
31 SET_BIT(result, i);
32 }
33 }
34 } else {
35 DEBUG_ASSERT(false);
36 }
37 return MLCD_BYTES_LINE;
38 }
39