8b29921479fa1abd056032bcd7653f260972b88f
[mTask.git] / int / nucleo-f767-blinky / src / interface.h
1 #ifndef MAIN_H
2 #define MAIN_H
3
4 #include <stdbool.h>
5 #include <stdint.h>
6 #include <stdio.h>
7 #include <string.h>
8
9 #ifdef STM32F767xx
10 #include "stm32f7xx_hal.h"
11 #include "gpio.h"
12 #include "usart.h"
13 #endif
14
15 #ifdef STM32F767xx
16 extern volatile char uartf;
17 extern char buf[128];
18 #else
19 extern int gargc;
20 extern char **gargv;
21 #endif
22 extern uint8_t bt;
23
24 uint8_t read_byte();
25 void write_byte(uint8_t b);
26
27 void write_dpin(uint8_t i, bool b);
28 bool read_dpin(uint8_t i);
29
30 void write_apin(uint8_t i, uint8_t a);
31 uint8_t read_apin(uint8_t i);
32
33 long millis();
34 bool input_available();
35 void delay(long ms);
36
37 void setup();
38
39 #define read16() 256*read_byte() + read_byte()
40 #ifdef STM32F767xx
41 #define debug(s, ...) {\
42 sprintf(buf, "m" s "\r\n", ##__VA_ARGS__);\
43 HAL_UART_Transmit(&huart3, (uint8_t*)buf, strlen(buf), 1000);\
44 }
45 #define pdie(s) ;
46 #define die(s, ...) ;
47 #else
48
49 #ifdef DEBUG
50 #define debug(s, ...) printf(s "\n", ##__VA_ARGS__);
51 #else
52 #define debug(s, ...) ;
53 #endif
54
55 #define pdie(s) {perror(s); exit(1);}
56 #define die(s, ...) {fprintf(stderr, s "\n", ##__VA_ARGS__); exit(1);}
57 #endif
58
59 #endif