Parent directory

programmable_button.c

1807 bytes
 1/*
 2Copyright 2021 Thomas Weißschuh <thomas@t-8ch.de>
 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#include "programmable_button.h"
19#include "host.h"
20
21#define REPORT_BIT(index) (((uint32_t)1) << (index - 1))
22
23static uint32_t programmable_button_report = 0;
24
25void programmable_button_clear(void) {
26    programmable_button_report = 0;
27    programmable_button_flush();
28}
29
30void programmable_button_add(uint8_t index) {
31    programmable_button_report |= REPORT_BIT(index);
32}
33
34void programmable_button_remove(uint8_t index) {
35    programmable_button_report &= ~REPORT_BIT(index);
36}
37
38void programmable_button_register(uint8_t index) {
39    programmable_button_add(index);
40    programmable_button_flush();
41}
42
43void programmable_button_unregister(uint8_t index) {
44    programmable_button_remove(index);
45    programmable_button_flush();
46}
47
48bool programmable_button_is_on(uint8_t index) {
49    return !!(programmable_button_report & REPORT_BIT(index));
50}
51
52void programmable_button_flush(void) {
53    host_programmable_button_send(programmable_button_report);
54}
55
56uint32_t programmable_button_get_report(void) {
57    return programmable_button_report;
58}
59
60void programmable_button_set_report(uint32_t report) {
61    programmable_button_report = report;
62}