Skip to content

Commit 7412fa1

Browse files
committed
sys: require float_math feature where needed
In some modules some functions are disabled when no floating point arithmetics is available instead of blocking the whole module. The API doc has been extended, so that users know why a function may fail to link.
1 parent 15ad17e commit 7412fa1

File tree

7 files changed

+41
-13
lines changed

7 files changed

+41
-13
lines changed

sys/Makefile.dep

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ ifneq (,$(filter auto_init_sock_dns,$(USEMODULE)))
2929
endif
3030
endif
3131

32+
ifneq (,$(filter color,$(USEMODULE)))
33+
FEATURES_REQUIRED += float_math
34+
endif
35+
3236
ifneq (,$(filter congure_%,$(USEMODULE)))
3337
USEMODULE += congure
3438
endif
@@ -259,6 +263,10 @@ ifneq (,$(filter posix_sockets,$(USEMODULE)))
259263
USEMODULE += posix_headers
260264
endif
261265

266+
ifneq (,$(filter printf_float,$(USEMODULE)))
267+
FEATURES_REQUIRED += float_math
268+
endif
269+
262270
ifneq (,$(filter shell_cmd%,$(USEMODULE)))
263271
# each and every command is a submodule of shell_cmds
264272
USEMODULE += shell_cmds

sys/analog_util/adc_util.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ int32_t adc_util_map(int sample, adc_res_t res, int32_t min, int32_t max)
6666
return (min + scaled);
6767
}
6868

69+
/* only pro adc_util_mapf if float_math is in use */
70+
#if MODULE_FLOAT_MATH
6971
float adc_util_mapf(int sample, adc_res_t res, float min, float max)
7072
{
7173
return ((((max - min) * sample) / ((int32_t)1L << _adc_res_bits(res))) + min);
7274
}
75+
#endif

sys/analog_util/dac_util.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ uint16_t dac_util_map(int value, int min, int max)
2727
return (uint16_t)(((value - min) * UINT16_MAX) / (max - min));
2828
}
2929

30+
/* only provide dac_util_mapf when floating point arithmetics is available */
31+
#if MODULE_FLOAT_MATH
3032
uint16_t dac_util_mapf(float value, float min, float max)
3133
{
3234
return (uint16_t)(((value - min) * UINT16_MAX) / (max - min));
3335
}
36+
#endif

sys/fmt/fmt.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,6 @@ extern ssize_t stdio_write(const void* buffer, size_t len);
3737
NONSTRING
3838
static const char _hex_chars[16] = "0123456789ABCDEF";
3939

40-
static const uint32_t _tenmap[] = {
41-
0,
42-
10LU,
43-
100LU,
44-
1000LU,
45-
10000LU,
46-
100000LU,
47-
1000000LU,
48-
10000000LU,
49-
};
50-
51-
#define TENMAP_SIZE ARRAY_SIZE(_tenmap)
52-
5340
static inline char _to_lower(char c)
5441
{
5542
return 'a' + (c - 'A');
@@ -377,6 +364,21 @@ size_t fmt_s32_dfp(char *out, int32_t val, int scale)
377364

378365
return pos;
379366
}
367+
368+
#if MODULE_FLOAT_MATH
369+
static const uint32_t _tenmap[] = {
370+
0,
371+
10LU,
372+
100LU,
373+
1000LU,
374+
10000LU,
375+
100000LU,
376+
1000000LU,
377+
10000000LU,
378+
};
379+
380+
#define TENMAP_SIZE ARRAY_SIZE(_tenmap)
381+
380382
/* this is very probably not the most efficient implementation, as it at least
381383
* pulls in floating point math. But it works, and it's always nice to have
382384
* low hanging fruits when optimizing. (Kaspar)
@@ -415,6 +417,7 @@ size_t fmt_float(char *out, float f, unsigned precision)
415417

416418
return res;
417419
}
420+
#endif
418421

419422
size_t fmt_lpad(char *out, size_t in_len, size_t pad_len, char pad_char)
420423
{

sys/include/analog_util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ int32_t adc_util_map(int sample, adc_res_t res, int32_t min, int32_t max);
4747
* @brief Map a sampled ADC value to a given range (using floating point
4848
* arithmetic)
4949
*
50+
* @warning This function is only available when the features `float_math`
51+
* is used.
52+
*
5053
* @see adc_util_map
5154
*
5255
* @param[in] sample sampled ADC value
@@ -75,6 +78,9 @@ uint16_t dac_util_map(int value, int min, int max);
7578
/**
7679
* @brief Helper function to map a given float value range to a valid DAC value.
7780
*
81+
* @warning This function is only available when the features `float_math`
82+
* is used.
83+
*
7884
* @see dac_util_map
7985
*
8086
* @param[in] value value to map to a DAC set value

sys/include/fmt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ size_t fmt_s32_dfp(char *out, int32_t val, int scale);
326326
/**
327327
* @brief Format float to string
328328
*
329+
* @warning This function is only available when the features `float_math`
330+
* is used.
331+
*
329332
* Converts float value @p f to string
330333
*
331334
* If @p out is NULL, will only return the number of characters that would have

sys/senml/Makefile.dep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
FEATURES_REQUIRED += float_math
2+
13
ifneq (,$(filter senml_saul,$(USEMODULE)))
24
USEMODULE += senml_cbor
35
USEMODULE += senml_phydat

0 commit comments

Comments
 (0)