MySensors Library & Examples  2.3.2-62-ge298769
PJON_ZEPHYR_Interface.h
1 #pragma once
2 
3 #if defined(__ZEPHYR__)
4 
5 #define OUTPUT GPIO_OUTPUT
6 
7 #include <drivers/gpio.h>
8 #include <zephyr.h>
9 #include <stdint.h>
10 #include <string>
11 
12 int serial_get_char(struct device* dev);
13 bool serial_char_available(struct device* dev);
14 void uart_irq_callback(struct device *dev);
15 int serial_put_char(struct device* dev, uint8_t byte);
16 struct device* serial_open(const char* dt_label);
17 void serial_close(const char* dt_label);
18 void digitalWrite(int pin, bool state);
19 void pinMode(int pin, int mode);
20 void serial_flush(struct device* dev);
21 
22 #if defined CONFIG_PJON_STRATEGY_THROUGHSERIAL
23 #ifndef PJON_ZEPHYR_SEPARATE_DEFINITION
24 #include "PJON_ZEPHYR_Interface.inl"
25 #endif
26 #endif
27 // deal with randomness
28 
29 #ifndef PJON_RANDOM
30 #define PJON_RANDOM(randMax) (int)((1.0 + randMax) * rand() / ( RAND_MAX + 1.0 ))
31 #endif
32 
33 #ifndef PJON_RANDOM_SEED
34 #define PJON_RANDOM_SEED srand
35 #endif
36 
37 #ifndef A0
38 #define A0 0
39 #endif
40 
41 #ifndef PJON_ANALOG_READ
42 #define PJON_ANALOG_READ(P) 0
43 #endif
44 
45 // delay and timing functions
46 
47 #ifndef PJON_DELAY
48 #define PJON_DELAY(x) (k_sleep(K_MSEC(x)))
49 #endif
50 
51 #ifndef PJON_DELAY_MICROSECONDS
52 #define PJON_DELAY_MICROSECONDS(x) (k_sleep(K_USEC(x)))
53 #endif
54 
55 #ifndef PJON_MILLIS
56 #define PJON_MILLIS k_uptime_get
57 #endif
58 
59 #ifndef PJON_MICROS
60 #define PJON_MICROS 1000*k_uptime_get
61 #endif
62 
63 // serial port handling
64 
65 #ifndef PJON_SERIAL_TYPE
66 #define PJON_SERIAL_TYPE struct device*
67 #endif
68 
69 #ifndef PJON_SERIAL_AVAILABLE
70 #define PJON_SERIAL_AVAILABLE(S) serial_char_available(S)
71 #endif
72 
73 #ifndef PJON_SERIAL_READ
74 #define PJON_SERIAL_READ(S) serial_get_char(S)
75 #endif
76 
77 #ifndef PJON_SERIAL_WRITE
78 #define PJON_SERIAL_WRITE(S, C) serial_put_char(S, C)
79 #endif
80 
81 #ifndef PJON_SERIAL_FLUSH
82 #define PJON_SERIAL_FLUSH(S) serial_flush(S)
83 #endif
84 
85 // io pin handling (for setting the rs485 txe pin) is not needed since we use the auto-direction
86 // feature of the rs485 transceiver
87 
88 #ifndef PJON_IO_WRITE
89 #define PJON_IO_WRITE digitalWrite
90 #endif
91 
92 #ifndef PJON_IO_MODE
93 #define PJON_IO_MODE pinMode
94 #endif
95 
96 #ifndef LOW
97 #define LOW 0
98 #endif
99 
100 #ifndef HIGH
101 #define HIGH 1
102 #endif
103 
104 #endif