Fortschrittspeichern funktionstüchtig.
[hackover2013-badge-firmware.git] / badge / ui / display.h
1 #ifndef INCLUDED_BADGE2013_MOCKUP_DISPLAY_H
2 #define INCLUDED_BADGE2013_MOCKUP_DISPLAY_H
3
4 #include <stdint.h>
5 #include <stddef.h>
6 #include <string.h>
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 enum {
13 BADGE_DISPLAY_WIDTH = 96,
14 BADGE_DISPLAY_HEIGHT = 68,
15
16 BADGE_DISPLAY_STRIPE_HEIGHT = 8,
17 BADGE_DISPLAY_STRIPE_COUNT = (BADGE_DISPLAY_HEIGHT - 1) / BADGE_DISPLAY_STRIPE_HEIGHT + 1
18 };
19
20 typedef uint8_t badge_display_stripe[BADGE_DISPLAY_WIDTH];
21 typedef struct {
22 badge_display_stripe data[BADGE_DISPLAY_STRIPE_COUNT];
23 } badge_framebuffer;
24
25 void badge_display_init(void);
26 void badge_framebuffer_flush(badge_framebuffer const *fb);
27
28 static inline void badge_framebuffer_clear(badge_framebuffer *fb) {
29 memset(fb, 0, sizeof(*fb));
30 }
31
32 static inline uint8_t badge_framebuffer_pixel(badge_framebuffer *fb,
33 uint8_t x,
34 uint8_t y) {
35 return fb->data[y / BADGE_DISPLAY_STRIPE_HEIGHT][x] >> (y % BADGE_DISPLAY_STRIPE_HEIGHT) & 1;
36 }
37
38 static inline void badge_framebuffer_pixel_on(badge_framebuffer *fb,
39 uint8_t x,
40 uint8_t y) {
41 fb->data[y / BADGE_DISPLAY_STRIPE_HEIGHT][x] |= 1 << (y % BADGE_DISPLAY_STRIPE_HEIGHT);
42 }
43
44 static inline void badge_framebuffer_pixel_off(badge_framebuffer *fb,
45 uint8_t x,
46 uint8_t y) {
47 fb->data[y / BADGE_DISPLAY_STRIPE_HEIGHT][x] &= ~(1 << (y % BADGE_DISPLAY_STRIPE_HEIGHT));
48 }
49
50 static inline void badge_framebuffer_pixel_flip(badge_framebuffer *fb,
51 uint8_t x,
52 uint8_t y) {
53 fb->data[y / BADGE_DISPLAY_STRIPE_HEIGHT][x] ^= 1 << (y % BADGE_DISPLAY_STRIPE_HEIGHT);
54 }
55
56 static inline void badge_framebuffer_pixel_set(badge_framebuffer *fb,
57 uint8_t x,
58 uint8_t y,
59 uint8_t val) {
60 if(val) {
61 badge_framebuffer_pixel_on (fb, x, y);
62 } else {
63 badge_framebuffer_pixel_off(fb, x, y);
64 }
65 }
66
67 #ifdef __cplusplus
68 }
69 #endif
70
71 #endif
This page took 0.049286 seconds and 5 git commands to generate.