-
-
Notifications
You must be signed in to change notification settings - Fork 896
/
Copy pathMyHwSTM32.cpp
156 lines (132 loc) · 3.3 KB
/
MyHwSTM32.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <[email protected]>
* Copyright (C) 2013-2020 Sensnology AB
* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*/
#include "MyHwSTM32.h"
/*
* Pinout STM32F103C8 dev board:
* http://wiki.stm32duino.com/images/a/ae/Bluepillpinout.gif
*
* Wiring
* --------------------------------------------------
RFM69 CLK MISO MOSI CSN CE IRQ
SPI1 PA5 PA6 PA7 PA4 NA PA3 (default)
RF24 CLK MISO MOSI CSN CE IRQ
SPI1 PA5 PA6 PA7 PA4 PB0 NA
*/
bool hwInit(void)
{
#if !defined(MY_DISABLED_SERIAL)
MY_SERIALDEVICE.begin(MY_BAUD_RATE);
#if defined(MY_GATEWAY_SERIAL)
while (!MY_SERIALDEVICE) {}
#endif
#endif
return true;
}
void hwReadConfigBlock(void *buf, void *addr, size_t length)
{
uint8_t *dst = static_cast<uint8_t *>(buf);
int offs = reinterpret_cast<int>(addr);
eeprom_buffer_fill();
while (length-- > 0) {
*dst++ = eeprom_buffered_read_byte(offs++);
}
}
void hwWriteConfigBlock(void *buf, void *addr, size_t length)
{
uint8_t *src = static_cast<uint8_t *>(buf);
int offs = reinterpret_cast<int>(addr);
while (length-- > 0) {
eeprom_buffered_write_byte(offs++, *src++);
}
eeprom_buffer_flush();
}
uint8_t hwReadConfig(const int addr)
{
uint8_t value;
hwReadConfigBlock(&value, reinterpret_cast<void *>(addr), 1);
return value;
}
void hwWriteConfig(const int addr, uint8_t value)
{
if (hwReadConfig(addr) != value) {
hwWriteConfigBlock(&value, reinterpret_cast<void *>(addr), 1);
}
}
int8_t hwSleep(uint32_t ms)
{
// TODO: Not supported!
(void)ms;
return MY_SLEEP_NOT_POSSIBLE;
}
int8_t hwSleep(const uint8_t interrupt, const uint8_t mode, uint32_t ms)
{
// TODO: Not supported!
(void)interrupt;
(void)mode;
(void)ms;
return MY_SLEEP_NOT_POSSIBLE;
}
int8_t hwSleep(const uint8_t interrupt1, const uint8_t mode1, const uint8_t interrupt2,
const uint8_t mode2,
uint32_t ms)
{
// TODO: Not supported!
(void)interrupt1;
(void)mode1;
(void)interrupt2;
(void)mode2;
(void)ms;
return MY_SLEEP_NOT_POSSIBLE;
}
bool hwUniqueID(unique_id_t *uniqueID)
{
// Fill ID with FF
(void)memset((uint8_t *)uniqueID, 0xFF, 16);
// Read device ID
(void)memcpy((uint8_t *)uniqueID, (uint32_t *)UID_BASE, 12);
return true;
}
uint16_t hwCPUVoltage(void)
{
//Not yet implemented
return FUNCTION_NOT_SUPPORTED;
}
uint16_t hwCPUFrequency(void)
{
return HAL_RCC_GetSysClockFreq()/1000000UL;
}
int8_t hwCPUTemperature(void)
{
return FUNCTION_NOT_SUPPORTED;
}
uint16_t hwFreeMem(void)
{
//Not yet implemented
return FUNCTION_NOT_SUPPORTED;
}
void hwWatchdogReset(void)
{
IWatchdog.reload();
}
void hwReboot(void)
{
NVIC_SystemReset();
while (true)
;
}