Skip to content

Commit 97dd5c6

Browse files
committed
added bswaps for int16 and int32
1 parent 353fc38 commit 97dd5c6

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/sfTk/sfToolkit.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @author SparkFun Electronics
99
* @date 2024-2025
1010
* @copyright Copyright (c) 2024-2025, SparkFun Electronics Inc. This project is released under the MIT License.
11-
*
11+
*
1212
* SPDX-License-Identifier: MIT
1313
*/
1414

@@ -38,7 +38,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3838
*/
3939
#include "sfToolkit.h"
4040

41-
4241
#ifdef ARDUINO
4342
#include <Arduino.h>
4443
#endif
@@ -87,3 +86,23 @@ uint32_t sftk_byte_swap(uint32_t i)
8786
return ((i << 24) & 0xff000000) | ((i << 8) & 0x00ff0000) | ((i >> 8) & 0x0000ff00) | ((i >> 24) & 0x000000ff);
8887
#endif
8988
}
89+
90+
//---------------------------------------------------------------------------------
91+
/**
92+
* @brief function - Byte swap an int 16
93+
*/
94+
int16_t sftk_byte_swap(int16_t i)
95+
{
96+
uint16_t tmp = sftk_byte_swap(*(uint16_t *)&i);
97+
return *(int16_t *)&tmp;
98+
}
99+
100+
//---------------------------------------------------------------------------------
101+
/**
102+
* @brief function - Byte swap an int 32
103+
*/
104+
int32_t sftk_byte_swap(int32_t i)
105+
{
106+
uint32_t tmp = sftk_byte_swap(*(uint32_t *)&i);
107+
return *(int32_t *)&tmp;
108+
}

src/sfTk/sfToolkit.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
* @author SparkFun Electronics
1010
* @date 2024-2025
1111
* @copyright Copyright (c) 2024-2025, SparkFun Electronics Inc. This project is released under the MIT License.
12-
*
12+
*
1313
* SPDX-License-Identifier: MIT
1414
*/
1515

16-
1716
#pragma once
1817

1918
#include <stdint.h>
@@ -23,7 +22,6 @@
2322
*/
2423
#include "sfTkError.h"
2524

26-
2725
// byte order types/enum
2826
enum class sfTkByteOrder : uint8_t
2927
{
@@ -39,9 +37,10 @@ sfTkByteOrder sftk_system_byteorder(void);
3937
uint8_t sftk_byte_swap(uint8_t i);
4038
uint16_t sftk_byte_swap(uint16_t i);
4139
uint32_t sftk_byte_swap(uint32_t i);
40+
int16_t sftk_byte_swap(int16_t i);
41+
int32_t sftk_byte_swap(int32_t i);
4242

43-
44-
// Area for platform specific implementations. The interface/functions are
43+
// Area for platform specific implementations. The interface/functions are
4544
// defined here, with the expectation that the platform provides the implementation.
4645

4746
// delay in milliseconds

0 commit comments

Comments
 (0)