Skip to content

Commit 567dedf

Browse files
author
Roman Beranek
committed
select proper linkage for each 'inline' function
As the 'inline' designation is merely a hint for a compiler, an inline function might likely actually end up being compiled on its own, in which case, the linkage specifiers become significant. Therefore, one has to be prepared for such eventuality: you can either declare the function 'static' and have it be compiled in each translation unit separately, or redeclare it with 'extern' in one translation unit. Another option is to inline it forcefully with `always_inline` attribute. Either way, it has to be dealt with. Note: the `inline` keyword behaves differently in C++ than in C99/C11. Fixes #181, #185
1 parent 0f42139 commit 567dedf

File tree

6 files changed

+32
-11
lines changed

6 files changed

+32
-11
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ set(SOURCES
6060
MM-control-01/motion.cpp
6161
MM-control-01/stepper.cpp
6262
MM-control-01/main.cpp
63+
MM-control-01/pins.c
64+
MM-control-01/spi.c
6365
MM-control-01/tmc2130.c
6466
MM-control-01/permanent_storage.cpp
6567
MM-control-01/Buttons.cpp

MM-control-01/abtn3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ uint8_t abtn_state = 0;
1010
uint8_t abtn_click = 0;
1111

1212

13-
inline uint8_t abtn3_sample(void)
13+
static inline uint8_t abtn3_sample(void)
1414
{
1515
int raw = adc_val[0];
1616
// Button 1 - 0

MM-control-01/pins.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <avr/io.h>
2+
#include "pins.h"
3+
4+
const uint8_t selector_step_pin = 0x10;
5+
const uint8_t idler_step_pin = 0x40;
6+
const uint8_t pulley_step_pin = 0x10;
7+
8+
extern inline void selector_step_pin_init();
9+
extern inline void selector_step_pin_set();
10+
extern inline void selector_step_pin_reset();
11+
extern inline void idler_step_pin_init();
12+
extern inline void idler_step_pin_set();
13+
extern inline void idler_step_pin_reset();
14+
extern inline void pulley_step_pin_init();
15+
extern inline void pulley_step_pin_set();
16+
extern inline void pulley_step_pin_reset();

MM-control-01/pins.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
#include <stdint.h>
77

8-
const uint8_t selector_step_pin = 0x10;
8+
extern const uint8_t selector_step_pin;
9+
extern const uint8_t idler_step_pin;
10+
extern const uint8_t pulley_step_pin;
911

1012
inline void selector_step_pin_init()
1113
{
@@ -20,8 +22,6 @@ inline void selector_step_pin_reset()
2022
PORTD &= ~selector_step_pin;
2123
}
2224

23-
const uint8_t idler_step_pin = 0x40;
24-
2525
inline void idler_step_pin_init()
2626
{
2727
DDRD |= idler_step_pin;
@@ -35,8 +35,6 @@ inline void idler_step_pin_reset()
3535
PORTD &= ~idler_step_pin;
3636
}
3737

38-
const uint8_t pulley_step_pin = 0x10;
39-
4038
inline void pulley_step_pin_init()
4139
{
4240
DDRB |= pulley_step_pin;

MM-control-01/spi.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "spi.h"
2+
3+
extern inline void spi_init();
4+
extern inline void spi_setup(uint8_t spcr, uint8_t spsr);
5+
extern inline uint8_t spi_txrx(uint8_t tx);

MM-control-01/tmc2130.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ int8_t tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint
125125
return 0;
126126
}
127127

128-
inline uint16_t __tcoolthrs(uint8_t axis)
128+
static inline uint16_t __tcoolthrs(uint8_t axis)
129129
{
130130
switch (axis)
131131
{
@@ -136,7 +136,7 @@ inline uint16_t __tcoolthrs(uint8_t axis)
136136
return TMC2130_TCOOLTHRS;
137137
}
138138

139-
inline int8_t __sg_thr(uint8_t axis)
139+
static inline int8_t __sg_thr(uint8_t axis)
140140
{
141141
switch (axis)
142142
{
@@ -147,7 +147,7 @@ inline int8_t __sg_thr(uint8_t axis)
147147
return TMC2130_SG_THR;
148148
}
149149

150-
inline int8_t __res(uint8_t axis)
150+
static inline int8_t __res(uint8_t axis)
151151
{
152152
switch (axis)
153153
{
@@ -269,7 +269,7 @@ uint16_t tmc2130_read_sg(uint8_t axis)
269269
}
270270

271271

272-
inline void tmc2130_cs_low(uint8_t axis)
272+
static inline void tmc2130_cs_low(uint8_t axis)
273273
{
274274
switch (axis)
275275
{
@@ -279,7 +279,7 @@ inline void tmc2130_cs_low(uint8_t axis)
279279
}
280280
}
281281

282-
inline void tmc2130_cs_high(uint8_t axis)
282+
static inline void tmc2130_cs_high(uint8_t axis)
283283
{
284284
switch (axis)
285285
{

0 commit comments

Comments
 (0)