summaryrefslogtreecommitdiffstats
path: root/m168_firmware/main.h
blob: bfb92e2d389007fb4f6ba31c2a6b577c1c3cfde3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef WIFI_MAIN_H_
#define WIFI_MAIN_H_

#include "util.h"

/* User buttons */
#define KEYS_PORT	PORTB
#define KEYS_PIN	PINB
#define KEYS_DDR	DDRB
#define KEY_NEXT	(1 << 0)
#define KEY_PREV	(1 << 1)
#define KEY_SCAN	(1 << 2)
#define KEYS_MASK	(KEY_NEXT | KEY_PREV | KEY_SCAN)

static inline bool key_is_pressed(uint8_t key_mask)
{
	return !(KEYS_PIN & key_mask);
}
void key_debounce(uint8_t key_mask, uint8_t delay);

void emergency_shutdown(void);

/* Jiffies timing helpers derived from the Linux Kernel sources.
 * These inlines deal with timer wrapping correctly.
 *
 * time_after(a, b) returns true if the time a is after time b.
 *
 * Do this with "<0" and ">=0" to only test the sign of the result. A
 * good compiler would generate better code (and a really good compiler
 * wouldn't care). Gcc is currently neither.
 */
#define time_after(a, b)	((int8_t)(b) - (int8_t)(a) < 0)
#define time_before(a, b)	time_after(b, a)

#endif /* WIFI_MAIN_H_ */
bues.ch cgit interface