sidestep
[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 #include "serial.h"
14
15 #define SET_LED_RED GPIOB->BSRR = GPIO_PIN_14
16 #define RESET_LED_RED GPIOB->BSRR = GPIO_PIN_14 << 16
17
18 #define SET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7
19 #define RESET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7 << 16
20
21 #define SET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0
22 #define RESET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0 << 16
23
24 #endif
25
26 #ifdef STM32F767xx
27 extern char buf[128];
28 #else
29 extern int gargc;
30 extern char **gargv;
31 #endif
32
33 uint8_t read_byte();
34 void write_byte(uint8_t b);
35
36 void write_dpin(uint8_t i, bool b);
37 bool read_dpin(uint8_t i);
38
39 void write_apin(uint8_t i, uint8_t a);
40 uint8_t read_apin(uint8_t i);
41
42 long millis();
43 bool input_available();
44 void delay(long ms);
45
46 void setup();
47
48 #define read16() 256*read_byte() + read_byte()
49 #ifdef STM32F767xx
50 #define debug(s, ...) ;
51 //#define debug(s, ...) {\
52 // sprintf(buf, "m" s "\n", ##__VA_ARGS__);\
53 // for(int _i = 0; _i<strlen(buf); _i++){\
54 // write_byte(buf[_i]);\
55 // }\
56 // }
57 #define pdie(s) ;
58 #define die(s, ...) ;
59 #else
60
61 #ifdef DEBUG
62 #define debug(s, ...) printf(s "\n", ##__VA_ARGS__);
63 #else
64 #define debug(s, ...) ;
65 #endif
66
67 #define pdie(s) {perror(s); exit(1);}
68 #define die(s, ...) {fprintf(stderr, s "\n", ##__VA_ARGS__); exit(1);}
69 #endif
70
71 #endif