backlight.h
2537 bytes
1/*
2Copyright 2013 Mathias Andersson <wraul@dbox.se>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#pragma once
19
20#include <stdint.h>
21#include <stdbool.h>
22
23#ifndef BACKLIGHT_LEVELS
24# define BACKLIGHT_LEVELS 3
25#elif BACKLIGHT_LEVELS > 31
26# error "Maximum value of BACKLIGHT_LEVELS is 31"
27#endif
28
29#ifndef BACKLIGHT_ON_STATE
30# define BACKLIGHT_ON_STATE 1
31#endif
32
33#ifndef BREATHING_PERIOD
34# define BREATHING_PERIOD 6
35#endif
36
37typedef union {
38 uint8_t raw;
39 struct {
40 bool enable : 1;
41 bool breathing : 1;
42 bool valid : 1;
43 uint8_t level : 5;
44 };
45} backlight_config_t;
46
47_Static_assert(sizeof(backlight_config_t) == sizeof(uint8_t), "Backlight EECONFIG out of spec.");
48
49void backlight_init(void);
50void backlight_toggle(void);
51void backlight_enable(void);
52void backlight_disable(void);
53bool is_backlight_enabled(void);
54void backlight_step(void);
55void backlight_increase(void);
56void backlight_decrease(void);
57void backlight_level_noeeprom(uint8_t level);
58void backlight_level(uint8_t level);
59uint8_t get_backlight_level(void);
60
61uint8_t eeconfig_read_backlight(void);
62void eeconfig_update_backlight(uint8_t val);
63void eeconfig_update_backlight_current(void);
64void eeconfig_update_backlight_default(void);
65
66// implementation specific
67void backlight_init_ports(void);
68void backlight_set(uint8_t level);
69void backlight_task(void);
70
71#ifdef BACKLIGHT_BREATHING
72
73void backlight_toggle_breathing(void);
74void backlight_enable_breathing(void);
75void backlight_disable_breathing(void);
76bool is_backlight_breathing(void);
77
78void breathing_period_set(uint8_t value);
79uint8_t get_breathing_period(void);
80void breathing_period_default(void);
81void breathing_period_inc(void);
82void breathing_period_dec(void);
83
84void breathing_toggle(void);
85
86// implementation specific
87void breathing_enable(void);
88void breathing_disable(void);
89bool is_breathing(void);
90void breathing_pulse(void);
91#endif