7 typedef unsigned int uint;
12 void debug_putc(int c)
16 while (!LL_USART_IsActiveFlag_TXE(USART2))
18 LL_USART_TransmitData8(USART2, c);
21 void debug_puts(const char *s)
35 static void printf_string(const char *s, uint width, uint flags)
38 uint pad = (len < width) ? width - len : 0;
39 char pad_char = (flags & PF_ZERO_PAD) ? '0' : ' ';
45 if (!(flags & PF_LEFT))
49 static void printf_number(uint i, uint width, uint flags, uint base)
52 char *w = buf + sizeof(buf);
54 if (flags & PF_SIGNED)
66 uint digit = i % base;
70 *--w = ((flags & PF_UPPERCASE) ? 'A' : 'a') + digit - 10;
75 if (flags & PF_NEGATIVE)
78 printf_string(w, width, flags);
81 void debug_printf(const char *fmt, ...)
107 flags |= PF_ZERO_PAD;
110 while (*fmt >= '0' && *fmt <= '9')
111 width = 10*width + *fmt++ - '0';
117 printf_number(va_arg(args, int), width, flags | PF_SIGNED, 10);
120 printf_number(va_arg(args, int), width, flags, 10);
123 flags |= PF_UPPERCASE;
126 printf_number(va_arg(args, int), width, flags, 16);
129 printf_string(va_arg(args, char *), width, flags);
140 void decide_set(int n){
143 LL_GPIO_SetOutputPin(MEGGY1_GPIO_Port, MEGGY1_Pin);
146 LL_GPIO_SetOutputPin(MEGGY2_GPIO_Port, MEGGY2_Pin);
149 LL_GPIO_SetOutputPin(MEGGY3_GPIO_Port, MEGGY3_Pin);
152 LL_GPIO_SetOutputPin(MEGGY4_GPIO_Port, MEGGY4_Pin);
157 void decide_reset(int n){
160 LL_GPIO_ResetOutputPin(MEGGY1_GPIO_Port, MEGGY1_Pin);
163 LL_GPIO_ResetOutputPin(MEGGY2_GPIO_Port, MEGGY2_Pin);
166 LL_GPIO_ResetOutputPin(MEGGY3_GPIO_Port, MEGGY3_Pin);
169 LL_GPIO_ResetOutputPin(MEGGY4_GPIO_Port, MEGGY4_Pin);
174 byte recognize(int n){
183 static const char mtree[]="**ETIANMSURWDKGOHVF*L*PJBXCYZQ**";
188 LL_GPIO_SetOutputPin(LD2_GPIO_Port, LD2_Pin);
190 while (!LL_GPIO_IsInputPinSet(BLUE_BUTTON_GPIO_Port, BLUE_BUTTON_Pin)){
194 LL_GPIO_ResetOutputPin(LD2_GPIO_Port, LD2_Pin);
195 // debug_printf(">>> %d\n", cnt);
196 letter=(letter<<1)+recognize(cnt);
198 while (LL_GPIO_IsInputPinSet(BLUE_BUTTON_GPIO_Port, BLUE_BUTTON_Pin)){
202 debug_putc(mtree[letter]);
205 if (cnt==1500) debug_putc(' ');
206 if (cnt==4000) debug_putc('\n');
210 for (int i=0;i<4;i++){
211 if (cnt2&(1<<i)) decide_set((i+1)%4);
212 else decide_reset((i+1)%4);