MySensors Library & Examples  2.3.2-82-gc3fc0ff4
MyHwSTM32.h
1 /*
2  * The MySensors Arduino library handles the wireless radio link and protocol
3  * between your home built sensors/actuators and HA controller of choice.
4  * The sensors forms a self healing radio network with optional repeaters. Each
5  * repeater and gateway builds a routing tables in EEPROM which keeps track of the
6  * network topology allowing messages to be routed to nodes.
7  *
8  * Created by Henrik Ekblad <[email protected]>
9  * Copyright (C) 2013-2025 Sensnology AB
10  * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
11  *
12  * Documentation: http://www.mysensors.org
13  * Support Forum: http://forum.mysensors.org
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * version 2 as published by the Free Software Foundation.
18  */
19 
20 #ifndef MyHwSTM32_h
21 #define MyHwSTM32_h
22 
23 #include <SPI.h>
24 #include <EEPROM.h>
25 
26 #ifdef __cplusplus
27 #include <Arduino.h>
28 #endif
29 
30 // Crypto endianness
31 #define CRYPTO_LITTLE_ENDIAN
32 
37 #ifndef MY_SERIALDEVICE
38 #define MY_SERIALDEVICE Serial
39 #endif
40 
44 #ifndef MY_DEBUGDEVICE
45 #define MY_DEBUGDEVICE MY_SERIALDEVICE
46 #endif
47 
52 #ifndef MY_STM32_TEMPERATURE_OFFSET
53 #define MY_STM32_TEMPERATURE_OFFSET (0.0f)
54 #endif
55 
59 #ifndef MY_STM32_TEMPERATURE_GAIN
60 #define MY_STM32_TEMPERATURE_GAIN (1.0f)
61 #endif
62 
63 // Printf format string compatibility
64 // Note: STM32duino core already defines these in avr/pgmspace.h
65 #ifndef snprintf_P
66 #define snprintf_P(s, n, ...) snprintf((s), (n), __VA_ARGS__)
67 #endif
68 #ifndef vsnprintf_P
69 #define vsnprintf_P(s, n, ...) vsnprintf((s), (n), __VA_ARGS__)
70 #endif
71 
72 // redefine 8 bit types of inttypes.h
73 #undef PRId8
74 #undef PRIi8
75 #undef PRIo8
76 #undef PRIu8
77 #undef PRIx8
78 #undef PRIX8
79 #define PRId8 "d"
80 #define PRIi8 "i"
81 #define PRIo8 "o"
82 #define PRIu8 "u"
83 #define PRIx8 "x"
84 #define PRIX8 "X"
85 
86 // Digital I/O macros - wrap Arduino functions
87 #define hwDigitalWrite(__pin, __value) digitalWrite(__pin, __value)
88 #define hwDigitalRead(__pin) digitalRead(__pin)
89 #define hwPinMode(__pin, __value) pinMode(__pin, __value)
90 
91 // Timing functions
92 #define hwMillis() millis()
93 #define hwGetSleepRemaining() (0ul)
94 
99 bool hwInit(void);
100 
104 void hwWatchdogReset(void);
105 
109 void hwReboot(void);
110 
115 void hwRandomNumberInit(void);
116 
123 void hwReadConfigBlock(void *buf, void *addr, size_t length);
124 
131 void hwWriteConfigBlock(void *buf, void *addr, size_t length);
132 
138 void hwWriteConfig(const int addr, uint8_t value);
139 
145 uint8_t hwReadConfig(const int addr);
146 
152 bool hwUniqueID(unique_id_t *uniqueID);
153 
158 uint16_t hwCPUVoltage(void);
159 
164 uint16_t hwCPUFrequency(void);
165 
170 int8_t hwCPUTemperature(void);
171 
176 uint16_t hwFreeMem(void);
177 
184 int8_t hwSleep(uint32_t ms);
185 
194 int8_t hwSleep(const uint8_t interrupt, const uint8_t mode, uint32_t ms);
195 
206 int8_t hwSleep(const uint8_t interrupt1, const uint8_t mode1,
207  const uint8_t interrupt2, const uint8_t mode2, uint32_t ms);
208 
209 // SPI configuration
210 #ifdef MY_SOFTSPI
211 #error Soft SPI is not available on this architecture!
212 #endif
213 #define hwSPI SPI
214 
215 
219 static __inline__ uint8_t __disableIntsRetVal(void)
220 {
221  __disable_irq();
222  return 1;
223 }
224 
225 static __inline__ void __priMaskRestore(const uint32_t *priMask)
226 {
227  __set_PRIMASK(*priMask);
228 }
229 
230 #ifndef DOXYGEN
231 #define MY_CRITICAL_SECTION for ( uint32_t __savePriMask __attribute__((__cleanup__(__priMaskRestore))) = __get_PRIMASK(), __ToDo = __disableIntsRetVal(); __ToDo ; __ToDo = 0 )
232 #endif /* DOXYGEN */
233 
234 #endif // MyHwSTM32_h
hwFreeMem
uint16_t hwFreeMem(void)
hwUniqueID
bool hwUniqueID(unique_id_t *uniqueID)
hwCPUTemperature
int8_t hwCPUTemperature(void)
unique_id_t
uint8_t unique_id_t[16]
unique ID
Definition: MyHwHAL.h:81
hwSleep
int8_t hwSleep(uint32_t ms)
hwCPUVoltage
uint16_t hwCPUVoltage(void)
hwCPUFrequency
uint16_t hwCPUFrequency(void)