Skip to content

Commit e42d0fb

Browse files
committed
moved/changed how to handle core platform functions - define funcs in core toolkit, provide impl in platform specific driver - better than the namespace thing
1 parent 749c052 commit e42d0fb

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

src/sfeTk/sfeToolkit.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,3 @@ uint32_t sfeToolkit::byte_swap(uint32_t i)
7373
return ((i << 24) & 0xff000000) | ((i << 8) & 0x00ff0000) | ((i >> 8) & 0x0000ff00) | ((i >> 24) & 0x000000ff);
7474
#endif
7575
}
76-
77-
void sfeToolkit::delay_ms(uint32_t ms)
78-
{
79-
// right now we use the Arduino delay function - future we need to abstract out a driver
80-
81-
#if defined(ARDUINO)
82-
delay(ms);
83-
#else
84-
#error // we need to implement a delay function
85-
// we need to implement a delay function
86-
#endif
87-
}
88-
89-
uint32_t sfeToolkit::ticks_ms(void)
90-
{
91-
#if defined(ARDUINO)
92-
return millis();
93-
#else
94-
#error // we need to implement a delay function
95-
// we need to implement a delay function
96-
#endif
97-
return 0;
98-
}

src/sfeTk/sfeToolkit.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ uint8_t byte_swap(uint8_t i);
5252
uint16_t byte_swap(uint16_t i);
5353
uint32_t byte_swap(uint32_t i);
5454

55-
void delay_ms(uint32_t ms);
56-
uint32_t ticks_ms(void);
55+
}; // namespace sfeToolkit
5756

58-
}; // namespace sfeToolkit
57+
// Area for platform specific implementations. The interface/functions are
58+
// defined here, with the expectation that the platform provides the implementation.
59+
60+
// delay in milliseconds
61+
void sfeTk_delay_ms(uint32_t ms);
62+
63+
// ticks in milliseconds
64+
uint32_t sfeTk_ticks_ms(void);

src/sfeTkArduino.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
@brief sfeTkArduino.cpp
3+
4+
The MIT License (MIT)
5+
6+
Copyright (c) 2023 SparkFun Electronics
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a
9+
copy of this software and associated documentation files (the "Software"),
10+
to deal in the Software without restriction, including without limitation
11+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
12+
and/or sell copies of the Software, and to permit persons to whom the
13+
Software is furnished to do so, subject to the following conditions: The
14+
above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
16+
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
17+
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
18+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
23+
*/
24+
25+
#include <Arduino.h>
26+
27+
// Implements the sfeToolkit functions for the Arduino platform
28+
29+
void sfeTk_delay_ms(uint32_t ms)
30+
{
31+
delay(ms);
32+
}
33+
34+
uint32_t sfeTk_ticks_ms(void)
35+
{
36+
return millis();
37+
}

0 commit comments

Comments
 (0)