| 1 | #ifndef MM_SWITCH_H |
| 2 | #define MM_SWITCH_H |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | #include <config/hardware.h> |
| 6 | |
| 7 | #define MM_FLAVOR_DRIVE 0 |
| 8 | #define MM_FLAVOR_SWITCH 1 |
| 9 | |
| 10 | #ifdef MM_USE_REGISTER_VARS |
| 11 | |
| 12 | uint8_t register shift_command asm("r2"); |
| 13 | uint8_t register shift_function asm("r3"); |
| 14 | uint8_t register shift_address asm("r4"); |
| 15 | uint8_t register mm_polarity asm("r5"); |
| 16 | uint8_t register mm_bitno asm("r6"); |
| 17 | uint8_t register mm_time_h asm("r9"); |
| 18 | uint8_t register mm_time_l asm("r10"); |
| 19 | uint8_t register mm_bit_val asm("r11"); |
| 20 | uint8_t register mm_flavor asm("r14"); |
| 21 | |
| 22 | static void inline __attribute((unused)) mm_init(void) |
| 23 | { |
| 24 | mm_bitno = 0; |
| 25 | mm_time_h = 0; |
| 26 | mm_bit_val = 23; |
| 27 | mm_polarity = 1; |
| 28 | } |
| 29 | |
| 30 | #else |
| 31 | |
| 32 | #define mm_init(...) |
| 33 | |
| 34 | #endif |
| 35 | |
| 36 | #ifdef MM_USE_CALLBACK |
| 37 | |
| 38 | /* |
| 39 | * mm_key_cb - Callback function! |
| 40 | * |
| 41 | * This function must be defined whenever the mm_switch module is used. |
| 42 | * It will be called from interrupt context whenever a new valid command |
| 43 | * has arrived. |
| 44 | * |
| 45 | * decoder is in the range from 1 to 25. Other values will not occur. |
| 46 | * |
| 47 | * key is in the range from 0 to 8: |
| 48 | * |
| 49 | * 1 - key1 green pressed |
| 50 | * 2 - key1 red pressed |
| 51 | * 3 - key2 green pressed |
| 52 | * 4 - key2 red pressed |
| 53 | * ... |
| 54 | * 0 - all keys up |
| 55 | * |
| 56 | */ |
| 57 | void mm_key_cb(uint8_t decoder, uint8_t function, uint8_t key); |
| 58 | void mm_drive_cb(uint8_t decoder, uint8_t function, uint8_t command); |
| 59 | |
| 60 | #endif |
| 61 | |
| 62 | void mm_pinchange_callback(void); |
| 63 | |
| 64 | enum mm_recmode { |
| 65 | __MM_INIT, |
| 66 | __MM_ARMED, |
| 67 | MM_SLOW, |
| 68 | MM_FAST, |
| 69 | }; |
| 70 | |
| 71 | #ifdef MM_USE_QUEUE |
| 72 | |
| 73 | struct mm_command { |
| 74 | enum mm_recmode recmode; /* Only MM_FAST or MM_SLOW! */ |
| 75 | uint8_t address; /* Undecoded loco/decoder address */ |
| 76 | uint8_t function; /* The two function bits */ |
| 77 | uint8_t command; /* Button/Speed/Functions */ |
| 78 | }; |
| 79 | |
| 80 | struct mm_command *mm_get(void); |
| 81 | |
| 82 | #endif /* MM_USE_QUEUE */ |
| 83 | |
| 84 | #endif |