2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
26 #if defined(USE_BOARD_INFO)
29 #if !defined(BOARD_NAME)
30 static bool boardInformationSet
= false;
31 static char manufacturerId
[MAX_MANUFACTURER_ID_LENGTH
+ 1];
32 static char boardName
[MAX_BOARD_NAME_LENGTH
+ 1];
33 static bool boardInformationWasUpdated
= false;
36 static bool signatureSet
= false;
37 static uint8_t signature
[SIGNATURE_LENGTH
];
39 void initBoardInformation(void)
41 #if !defined(BOARD_NAME)
42 boardInformationSet
= boardConfig()->boardInformationSet
;
43 if (boardInformationSet
) {
44 strncpy(manufacturerId
, boardConfig()->manufacturerId
, MAX_MANUFACTURER_ID_LENGTH
+ 1);
45 strncpy(boardName
, boardConfig()->boardName
, MAX_BOARD_NAME_LENGTH
+ 1);
49 signatureSet
= boardConfig()->signatureSet
;
51 memcpy(signature
, boardConfig()->signature
, SIGNATURE_LENGTH
);
55 const char *getManufacturerId(void)
57 #if defined(MANUFACTURER_ID) && defined(BOARD_NAME)
58 return STR(MANUFACTURER_ID
);
59 #elif defined(BOARD_NAME)
62 return manufacturerId
;
66 const char *getBoardName(void)
68 #if defined(BOARD_NAME)
69 return STR(BOARD_NAME
);
75 bool boardInformationIsSet(void)
77 #if defined(BOARD_NAME)
80 return boardInformationSet
;
84 bool setManufacturerId(const char *newManufacturerId
)
86 #if !defined(BOARD_NAME)
87 if (!boardInformationSet
|| strlen(manufacturerId
) == 0) {
88 strncpy(manufacturerId
, newManufacturerId
, MAX_MANUFACTURER_ID_LENGTH
+ 1);
90 boardInformationWasUpdated
= true;
97 UNUSED(newManufacturerId
);
102 bool setBoardName(const char *newBoardName
)
104 #if !defined(BOARD_NAME)
105 if (!boardInformationSet
|| strlen(boardName
) == 0) {
106 strncpy(boardName
, newBoardName
, MAX_BOARD_NAME_LENGTH
+ 1);
108 boardInformationWasUpdated
= true;
115 UNUSED(newBoardName
);
120 bool persistBoardInformation(void)
122 #if !defined(BOARD_NAME)
123 if (boardInformationWasUpdated
) {
124 strncpy(boardConfigMutable()->manufacturerId
, manufacturerId
, MAX_MANUFACTURER_ID_LENGTH
+ 1);
125 strncpy(boardConfigMutable()->boardName
, boardName
, MAX_BOARD_NAME_LENGTH
+ 1);
126 boardConfigMutable()->boardInformationSet
= true;
128 initBoardInformation();
139 #if defined(USE_SIGNATURE)
140 const uint8_t *getSignature(void)
145 bool signatureIsSet(void)
150 bool setSignature(const uint8_t *newSignature
)
153 memcpy(signature
, newSignature
, SIGNATURE_LENGTH
);
161 bool persistSignature(void)
164 memcpy(boardConfigMutable()->signature
, signature
, SIGNATURE_LENGTH
);
165 boardConfigMutable()->signatureSet
= true;
167 initBoardInformation();
175 #endif // USE_BOARD_INFO