Skip to content

Commit 70d3939

Browse files
committed
Replace broad include file <Arduino.h> with only the required include files, inline functions to prevent linker errors, and define static constants so that the compiler can place them in memory. All of those changes broaden adoption.
1 parent 27a7b07 commit 70d3939

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

api/CanMsg.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This file is free software; you can redistribute it and/or modify
3+
* it under the terms of either the GNU General Public License version 2
4+
* or the GNU Lesser General Public License version 2.1, both as
5+
* published by the Free Software Foundation.
6+
*/
7+
8+
/**************************************************************************************
9+
* INCLUDE
10+
**************************************************************************************/
11+
12+
#include "CanMsg.h"
13+
14+
/**************************************************************************************
15+
* NAMESPACE
16+
**************************************************************************************/
17+
18+
namespace arduino
19+
{
20+
21+
/**************************************************************************************
22+
* STATIC CONST DEFINITION
23+
**************************************************************************************/
24+
25+
size_t const CanMsg::MAX_DATA_LENGTH;
26+
uint32_t const CanMsg::CAN_EFF_FLAG;
27+
uint32_t const CanMsg::CAN_SFF_MASK;
28+
uint32_t const CanMsg::CAN_EFF_MASK;
29+
30+
/**************************************************************************************
31+
* NAMESPACE
32+
**************************************************************************************/
33+
34+
} /* arduino */

api/CanMsg.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
#include <stdint.h>
1616
#include <string.h>
1717

18-
#include <Arduino.h>
18+
#include "Print.h"
19+
#include "Printable.h"
20+
#include "Common.h"
1921

2022
/**************************************************************************************
2123
* NAMESPACE
@@ -112,20 +114,20 @@ class CanMsg : public Printable
112114
* |- Bit 29 : reserved (future error frame flag)
113115
* |- Bit 0-28 : CAN identifier (11/29 bit)
114116
*/
115-
uint32_t id;
116-
uint8_t data_length;
117-
uint8_t data[MAX_DATA_LENGTH];
117+
private: uint32_t id;
118+
public: uint8_t data_length;
119+
public: uint8_t data[MAX_DATA_LENGTH];
118120
};
119121

120122
/**************************************************************************************
121123
* FREE FUNCTIONS
122124
**************************************************************************************/
123125

124-
static uint32_t CanStandardId(uint32_t const id) {
126+
inline uint32_t CanStandardId(uint32_t const id) {
125127
return (id & CanMsg::CAN_SFF_MASK);
126128
}
127129

128-
static uint32_t CanExtendedId(uint32_t const id) {
130+
inline uint32_t CanExtendedId(uint32_t const id) {
129131
return (CanMsg::CAN_EFF_FLAG | (id & CanMsg::CAN_EFF_MASK));
130132
}
131133

0 commit comments

Comments
 (0)