add external libraries and update stm version
[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
23 uint8_t read_byte();
24 void write_byte(uint8_t b);
25
26 void write_dpin(uint8_t i, bool b);
27 bool read_dpin(uint8_t i);
28
29 void write_apin(uint8_t i, uint8_t a);
30 uint8_t read_apin(uint8_t i);
31
32 long millis();
33 bool input_available();
34 void delay(long ms);
35
36 void setup();
37
38 #define read16() 256*read_byte() + read_byte()
39 #ifdef STM32F767xx
40 #define debug(s, ...) {\
41 sprintf(buf, s, ##__VA_ARGS__);\
42 HAL_UART_Transmit(&huart3, (uint8_t*)buf, strlen(buf), 1000);\
43 }
44 #define pdie(s) ;
45 #define die(s, ...) ;
46 #else
47
48 #ifdef DEBUG
49 #define debug(s, ...) printf(s, ##__VA_ARGS__);
50 #else
51 #define debug(s, ...) ;
52 #endif
53
54 #define pdie(s) {perror(s); exit(1);}
55 #define die(s, ...) {fprintf(stderr, s, ##__VA_ARGS__); exit(1);}
56 #endif
57
58 #endif