forked from bluerange-io/bluerange-mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoardconfig.cpp
138 lines (121 loc) · 4.94 KB
/
Boardconfig.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
////////////////////////////////////////////////////////////////////////////////
// /****************************************************************************
// **
// ** Copyright (C) 2015-2022 M-Way Solutions GmbH
// ** Contact: https://www.blureange.io/licensing
// **
// ** This file is part of the Bluerange/FruityMesh implementation
// **
// ** $BR_BEGIN_LICENSE:GPL-EXCEPT$
// ** Commercial License Usage
// ** Licensees holding valid commercial Bluerange licenses may use this file in
// ** accordance with the commercial license agreement provided with the
// ** Software or, alternatively, in accordance with the terms contained in
// ** a written agreement between them and M-Way Solutions GmbH.
// ** For licensing terms and conditions see https://www.bluerange.io/terms-conditions. For further
// ** information use the contact form at https://www.bluerange.io/contact.
// **
// ** GNU General Public License Usage
// ** Alternatively, this file may be used under the terms of the GNU
// ** General Public License version 3 as published by the Free Software
// ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
// ** included in the packaging of this file. Please review the following
// ** information to ensure the GNU General Public License requirements will
// ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
// **
// ** $BR_END_LICENSE$
// **
// ****************************************************************************/
////////////////////////////////////////////////////////////////////////////////
#include <FmTypes.h>
#include <Boardconfig.h>
#include <Config.h>
#include <GlobalState.h>
#include <RecordStorage.h>
//At compile time, we choose a default boardId depending on the chipset
//This is usually the boardId of the development kit for this chipset
//If no boardId is specified in the UICR, this id will be used
#ifdef BOARD_TYPE
// The board type can also be defined through the featureset.h at compile time
#elif defined(NRF52832)
#define BOARD_TYPE 4
#elif defined(NRF52833)
#define BOARD_TYPE 39
#elif defined(NRF52840)
#define BOARD_TYPE 18
#elif defined(SIM_ENABLED)
#define BOARD_TYPE 19
#elif defined(ARM_TEMPLATE)
#define BOARD_TYPE 1 // just for now
#else
#error "No defined BOARD_TYPE"
#endif
extern void SetBoard_4(BoardConfiguration* c);
extern void SetBoard_18(BoardConfiguration* c);
extern void SetBoard_19(BoardConfiguration* c);
extern void SetBoard_39(BoardConfiguration* c);
void* fmBoardConfigPtr;
Boardconf::Boardconf()
{
configuration = {};
}
//A dummy so that we cannot have nullptr access issues
void SetCustomPins_dummy(CustomPins* pinConfig) {
}
void Boardconf::ResetToDefaultConfiguration()
{
//Set a default boardType for all different platforms in case we do not have the boardType in UICR
configuration.boardType = BOARD_TYPE;
DeviceConfiguration config;
//If there is data in the DeviceConfiguration, we use the boardType from there
ErrorType err = FruityHal::GetDeviceConfiguration(config);
if (err == ErrorType::SUCCESS) {
if (config.boardType != EMPTY_WORD) configuration.boardType = config.boardType;
}
//Set everything else to safe defaults
configuration.boardName = nullptr;
configuration.led1Pin = -1;
configuration.led2Pin = -1;
configuration.led3Pin = -1;
configuration.ledActiveHigh = false;
configuration.button1Pin = -1;
configuration.buttonsActiveHigh = false;
configuration.uartRXPin = -1;
configuration.uartTXPin = -1;
configuration.uartCTSPin = -1;
configuration.uartRTSPin = -1;
configuration.uartBaudRate = (u32)FruityHal::UartBaudRate::BAUDRATE_1M;
configuration.dBmRX = -90;
configuration.calibratedTX = -60;
configuration.lfClockSource = (u8)FruityHal::ClockSource::CLOCK_SOURCE_RC;
configuration.lfClockAccuracy = (u8)FruityHal::ClockAccuracy::CLOCK_ACCURACY_500_PPM; //Use a safe default if this is not given
configuration.displayWidth = 400;
configuration.displayHeight = 300;
configuration.batteryAdcInputPin = -1;
configuration.batteryMeasurementEnablePin = -1;
configuration.voltageDividerR1 = 0;
configuration.voltageDividerR2 = 0;
configuration.dcDcEnabled = false;
configuration.powerOptimizationEnabled = false;
configuration.getCustomPinset = &SetCustomPins_dummy;
//Now, we load all Default boards (nRf Development kits)
SetBoard_4(&configuration);
SetBoard_18(&configuration);
SetBoard_39(&configuration);
#ifdef SIM_ENABLED
SetBoard_19(&configuration);
#endif
//We call our featureset to check if additional boards are available and if they should be set
//Each featureset can include a number of boards that it can run on
SET_BOARD_CONFIGURATION(&configuration);
}
Boardconf & Boardconf::GetInstance()
{
return GS->boardconf;
}
void Boardconf::Initialize()
{
ResetToDefaultConfiguration();
//Can be used from C code to access the config
fmBoardConfigPtr = (void*)&(configuration.boardType);
}