trennfix/sw: Register variables, restructuring, whatever
[eisenbahn.git] / trennfix / sw / mm / include / mm / mm_switch.h
1 #ifndef MM_SWITCH_H
2 #define MM_SWITCH_H
3
4 #include <stdint.h>
5
6 enum mm_recstate {
7 MM_IDLE = 0,
8 MM_FIRST_FAST_SAMPLE,
9 MM_FIRST_SLOW_SAMPLE, /* If clock arrives, we stay on the fast path! */
10 MM_FAST_SAMPLE,
11 MM_FAST_WAIT_FOR_CLOCK,
12 MM_SLOW_SAMPLE,
13 MM_SLOW_WAIT_FOR_CLOCK,
14 };
15
16 #ifdef MM_USE_REGISTER_VARS
17
18 uint8_t register shift_command asm("r2");
19 uint8_t register shift_function asm("r3");
20 uint8_t register shift_address asm("r4");
21 uint8_t register recstate asm("r5");
22 uint8_t register bitno asm("r6");
23
24 static void inline __attribute((unused)) mm_init(void)
25 {
26 bitno = 0;
27 recstate = MM_IDLE;
28 }
29
30 #else
31
32 #define mm_init(...)
33
34 #endif
35
36 /*
37 * mm_switch_command - Callback function!
38 *
39 * This function must be defined whenever the mm_switch module is used.
40 * It will be called from interrupt context whenever a new valid command
41 * has arrived.
42 *
43 * decoder is in the range from 1 to 25. Other values will not occur.
44 *
45 * key is in the range from 0 to 8:
46 *
47 * 1 - key1 green pressed
48 * 2 - key1 red pressed
49 * 3 - key2 green pressed
50 * 4 - key2 red pressed
51 * ...
52 * 0 - all keys up
53 *
54 */
55 void mm_switch_command(uint8_t decoder, uint8_t key);
56
57 /*
58 * empty comment :-)
59 */
60 void mm_switch_drive_cb(uint8_t address, uint8_t speed, uint8_t functions, uint8_t flags);
61
62 void mm_switch_drive(uint8_t decoder, uint8_t function, uint8_t command);
63
64 void mm_pinchange_handler(void);
65
66
67 #endif