MySensors Library & Examples  2.3.2
MyHwAVR.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 
20 #ifndef MyHwAVR_h
21 #define MyHwAVR_h
22 
23 #include <avr/eeprom.h>
24 #include <avr/pgmspace.h>
25 #include <avr/sleep.h>
26 #include <avr/power.h>
27 #include <avr/interrupt.h>
28 #include <avr/wdt.h>
29 #include <avr/boot.h>
30 #include <util/atomic.h>
31 #include <SPI.h>
32 
33 // Fast IO driver
34 #include "drivers/DigitalWriteFast/digitalWriteFast.h"
35 
36 // SOFTSPI
37 #ifdef MY_SOFTSPI
39 #endif
40 
41 #ifdef __cplusplus
42 #include <Arduino.h>
43 #endif
44 
45 #define CRYPTO_LITTLE_ENDIAN
46 
47 #ifndef MY_SERIALDEVICE
48 #define MY_SERIALDEVICE Serial
49 #endif
50 
51 #ifndef MY_DEBUGDEVICE
52 #define MY_DEBUGDEVICE MY_SERIALDEVICE
53 #endif
54 
55 // AVR temperature calibration reference: http://ww1.microchip.com/downloads/en/AppNotes/Atmel-8108-Calibration-of-the-AVRs-Internal-Temperature-Reference_ApplicationNote_AVR122.pdf
56 #ifndef MY_AVR_TEMPERATURE_OFFSET
57 #define MY_AVR_TEMPERATURE_OFFSET (324.31f)
58 #endif
59 
60 #ifndef MY_AVR_TEMPERATURE_GAIN
61 #define MY_AVR_TEMPERATURE_GAIN (1.22f)
62 #endif
63 
64 // Define these as macros to save valuable space
65 #define hwDigitalWrite(__pin, __value) digitalWriteFast(__pin, __value)
66 #define hwDigitalRead(__pin) digitalReadFast(__pin)
67 #define hwPinMode(__pin, __value) pinModeFast(__pin, __value)
68 
69 bool hwInit(void);
70 
71 #define hwWatchdogReset() wdt_reset()
72 #define hwReboot() wdt_enable(WDTO_15MS); while (1)
73 #define hwMillis() millis()
74 #define hwReadConfig(__pos) eeprom_read_byte((const uint8_t *)__pos)
75 #define hwWriteConfig(__pos, __val) eeprom_update_byte((uint8_t *)__pos, (uint8_t)__val)
76 #define hwReadConfigBlock(__buf, __pos, __length) eeprom_read_block((void *)__buf, (const void *)__pos, (uint32_t)__length)
77 #define hwWriteConfigBlock(__buf, __pos, __length) eeprom_update_block((const void *)__buf, (void *)__pos, (uint32_t)__length)
78 
79 inline void hwRandomNumberInit(void);
80 uint32_t hwInternalSleep(uint32_t ms);
81 
82 #if defined(MY_SOFTSPI)
84 #else
85 #define hwSPI SPI
86 #endif
87 
88 #ifndef DOXYGEN
89 #define MY_CRITICAL_SECTION ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
90 #endif /* DOXYGEN */
91 
92 #endif
DigitalIO.h
Fast Digital I/O functions.
SoftSPI
Fast software SPI.
Definition: SoftSPI.h:50