MySensors Library & Examples  2.3.2
MyHwSAMD.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-2019 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 #ifndef MyHwSAMD_h
20 #define MyHwSAMD_h
21 
22 #include <SPI.h>
23 #include <avr/dtostrf.h>
24 
25 #ifdef __cplusplus
26 #include <Arduino.h>
27 #endif
28 
29 #define CRYPTO_LITTLE_ENDIAN
30 
31 #ifndef MY_SERIALDEVICE
32 #define MY_SERIALDEVICE SerialUSB
33 #endif
34 
35 #ifndef MY_DEBUGDEVICE
36 #define MY_DEBUGDEVICE MY_SERIALDEVICE
37 #endif
38 
39 #ifndef MY_SAMD_TEMPERATURE_OFFSET
40 #define MY_SAMD_TEMPERATURE_OFFSET (0.0f)
41 #endif
42 
43 #ifndef MY_SAMD_TEMPERATURE_GAIN
44 #define MY_SAMD_TEMPERATURE_GAIN (1.0f)
45 #endif
46 
47 // defines for sensebender gw variant.h
48 #define MY_EXT_EEPROM_I2C_ADDRESS (0x50u)
49 #define MY_EXT_EEPROM_SIZE (kbits_512)
50 #define MY_EXT_EEPROM_PAGE_SIZE (32u)
51 
52 extEEPROM eep(MY_EXT_EEPROM_SIZE, 1, MY_EXT_EEPROM_PAGE_SIZE,
53  MY_EXT_EEPROM_I2C_ADDRESS); //device size, number of devices, page size
54 
55 #define MY_EXT_EEPROM_TWI_CLOCK (eep.twiClock100kHz) // can be set to 400kHz with precaution if other i2c devices on bus
56 
57 #define snprintf_P(s, f, ...) snprintf((s), (f), __VA_ARGS__)
58 #define vsnprintf_P(s, n, f, ...) vsnprintf((s), (n), (f), __VA_ARGS__)
59 
60 // redefine 8 bit types of inttypes.h (as of SAMD board defs 1.8.1)
61 #undef PRId8
62 #undef PRIi8
63 #undef PRIo8
64 #undef PRIu8
65 #undef PRIx8
66 #undef PRIX8
67 #undef PRIdLEAST8
68 #undef PRIiLEAST8
69 #undef PRIoLEAST8
70 #undef PRIuLEAST8
71 #undef PRIxLEAST8
72 #undef PRIXLEAST8
73 #undef PRIdFAST8
74 #undef PRIiFAST8
75 #undef PRIoFAST8
76 #undef PRIuFAST8
77 #undef PRIxFAST8
78 #undef PRIXFAST8
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 #define PRIdLEAST8 "d"
86 #define PRIiLEAST8 "i"
87 #define PRIoLEAST8 "o"
88 #define PRIuLEAST8 "u"
89 #define PRIxLEAST8 "x"
90 #define PRIXLEAST8 "X"
91 #define PRIdFAST8 "d"
92 #define PRIiFAST8 "i"
93 #define PRIoFAST8 "o"
94 #define PRIuFAST8 "u"
95 #define PRIxFAST8 "x"
96 #define PRIXFAST8 "X"
97 
98 // Define these as macros to save valuable space
99 #define hwDigitalWrite(__pin, __value) digitalWrite(__pin, __value)
100 #define hwDigitalRead(__pin) digitalRead(__pin)
101 #define hwPinMode(__pin, __value) pinMode(__pin, __value)
102 #define hwMillis() millis()
103 #define hwRandomNumberInit() randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN))
104 #define hwGetSleepRemaining() (0ul)
105 
106 bool hwInit(void);
107 void hwWatchdogReset(void);
108 void hwReboot(void);
109 void hwReadConfigBlock(void *buf, void *addr, size_t length);
110 void hwWriteConfigBlock(void *buf, void *addr, size_t length);
111 void hwWriteConfig(const int addr, uint8_t value);
112 uint8_t hwReadConfig(const int addr);
113 
114 // SOFTSPI
115 #ifdef MY_SOFTSPI
116 #error Soft SPI is not available on this architecture!
117 #endif
118 #define hwSPI SPI
119 
120 
125 static __inline__ uint8_t __disableIntsRetVal(void)
126 {
127  __disable_irq();
128  return 1;
129 }
130 
135 static __inline__ void __priMaskRestore(const uint32_t *priMask)
136 {
137  __set_PRIMASK(*priMask);
138 }
139 
140 #ifndef DOXYGEN
141 #define MY_CRITICAL_SECTION for ( uint32_t __savePriMask __attribute__((__cleanup__(__priMaskRestore))) = __get_PRIMASK(), __ToDo = __disableIntsRetVal(); __ToDo ; __ToDo = 0 )
142 #endif /* DOXYGEN */
143 
144 #endif // #ifdef ARDUINO_ARCH_SAMD
extEEPROM
Definition: extEEPROM.h:87