MySensors Library & Examples  2.3.2-95-g0c695e3e
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-2026 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 #ifdef __cplusplus
24 #include <Arduino.h>
25 #endif
26 
27 #include <SPI.h>
28 #include <EEPROM.h>
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 
53 #ifndef MY_STM32_TEMPERATURE_OFFSET
54 #define MY_STM32_TEMPERATURE_OFFSET (0)
55 #endif
56 
61 #ifndef MY_STM32_TEMPERATURE_GAIN
62 #define MY_STM32_TEMPERATURE_GAIN (100)
63 #endif
64 
65 // Printf format string compatibility
66 // Note: STM32duino core already defines these in avr/pgmspace.h
67 #ifndef snprintf_P
68 #define snprintf_P(s, n, ...) snprintf((s), (n), __VA_ARGS__)
69 #endif
70 #ifndef vsnprintf_P
71 #define vsnprintf_P(s, n, ...) vsnprintf((s), (n), __VA_ARGS__)
72 #endif
73 
74 // redefine 8 bit types of inttypes.h
75 #undef PRId8
76 #undef PRIi8
77 #undef PRIo8
78 #undef PRIu8
79 #undef PRIx8
80 #undef PRIX8
81 #define PRId8 "d"
82 #define PRIi8 "i"
83 #define PRIo8 "o"
84 #define PRIu8 "u"
85 #define PRIx8 "x"
86 #define PRIX8 "X"
87 
88 // Digital I/O macros - wrap Arduino functions
89 #define hwDigitalWrite(__pin, __value) digitalWrite(__pin, __value)
90 #define hwDigitalRead(__pin) digitalRead(__pin)
91 #define hwPinMode(__pin, __value) pinMode(__pin, __value)
92 
93 // Timing functions
94 #define hwMillis() millis()
95 
100 uint32_t hwGetSleepRemaining(void);
101 
106 bool hwInit(void);
107 
111 void hwWatchdogReset(void);
112 
116 void hwReboot(void);
117 
125 int32_t hwReadInternalTemp(void);
126 
131 void hwRandomNumberInit(void);
132 
139 void hwReadConfigBlock(void *buf, void *addr, size_t length);
140 
147 void hwWriteConfigBlock(void *buf, void *addr, size_t length);
148 
154 void hwWriteConfig(const int addr, uint8_t value);
155 
161 uint8_t hwReadConfig(const int addr);
162 
168 bool hwUniqueID(unique_id_t *uniqueID);
169 
174 uint16_t hwCPUVoltage(void);
175 
180 uint16_t hwCPUFrequency(void);
181 
186 int8_t hwCPUTemperature(void);
187 
192 uint16_t hwFreeMem(void);
193 
202 int8_t hwSleep(uint32_t ms);
203 
213 int8_t hwSleep(const uint8_t interrupt, const uint8_t mode, uint32_t ms);
214 
226 int8_t hwSleep(const uint8_t interrupt1, const uint8_t mode1,
227  const uint8_t interrupt2, const uint8_t mode2, uint32_t ms);
228 
229 // SPI configuration
230 #ifdef MY_SOFTSPI
231 #error Soft SPI is not available on this architecture!
232 #endif
233 #define hwSPI SPI
234 
235 
239 static __inline__ uint8_t __disableIntsRetVal(void)
240 {
241  __disable_irq();
242  return 1;
243 }
244 
245 static __inline__ void __priMaskRestore(const uint32_t *priMask)
246 {
247  __set_PRIMASK(*priMask);
248 }
249 
250 #ifndef DOXYGEN
251 #define MY_CRITICAL_SECTION for ( uint32_t __savePriMask __attribute__((__cleanup__(__priMaskRestore))) = __get_PRIMASK(), __ToDo = __disableIntsRetVal(); __ToDo ; __ToDo = 0 )
252 #endif /* DOXYGEN */
253 
254 #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)