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