dip_switch.h
1804 bytes
1/*
2 * Copyright 2018 Jack Humbert <jack.humb@gmail.com>
3 * Copyright 2018 Drashna Jaelre (Christopher Courtney) <drashna@live.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include <stdbool.h>
22#include <stdint.h>
23#include "gpio.h"
24#include "util.h"
25
26#if defined(DIP_SWITCH_PINS)
27# define NUM_DIP_SWITCHES ARRAY_SIZE(((pin_t[])DIP_SWITCH_PINS))
28#elif defined(DIP_SWITCH_MATRIX_GRID)
29typedef struct matrix_intersection_t {
30 uint8_t row;
31 uint8_t col;
32} matrix_intersection_t;
33# define NUM_DIP_SWITCHES ARRAY_SIZE(((matrix_intersection_t[])DIP_SWITCH_MATRIX_GRID))
34#endif
35
36#ifndef NUM_DIP_SWITCHES
37# define NUM_DIP_SWITCHES 0
38#endif
39
40bool dip_switch_update_kb(uint8_t index, bool active);
41bool dip_switch_update_user(uint8_t index, bool active);
42bool dip_switch_update_mask_user(uint32_t state);
43bool dip_switch_update_mask_kb(uint32_t state);
44
45void dip_switch_read(bool forced);
46
47void dip_switch_init(void);
48void dip_switch_task(void);
49
50#ifdef DIP_SWITCH_MAP_ENABLE
51# define NUM_DIP_STATES 2
52# define DIP_SWITCH_OFF_ON(off, on) \
53 { (off), (on) }
54extern const uint16_t dip_switch_map[NUM_DIP_SWITCHES][NUM_DIP_STATES];
55#endif // DIP_SWITCH_MAP_ENABLE