-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
388d8ef
commit f84755b
Showing
13 changed files
with
1,333 additions
and
562 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "bitutils.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
#if !defined(BITUTILS_H) | ||
# define BITUTILS_H | ||
|
||
template <uint8_t msb, uint8_t lsb = msb> | ||
uint8_t get_bit_field(const uint8_t value) | ||
{ | ||
static_assert(msb >= lsb); | ||
constexpr const uint8_t mask = (2 << (msb - lsb)) - 1; | ||
return (value >> lsb) & mask; | ||
} | ||
|
||
template <uint8_t msb, uint8_t lsb = msb> | ||
uint8_t set_bit_field(const uint8_t src, const uint8_t value) | ||
{ | ||
static_assert(msb >= lsb); | ||
constexpr const uint8_t mask = (2 << (msb - lsb)) - 1; | ||
return (src & ~(mask << lsb)) | (value << lsb); | ||
} | ||
|
||
template <typename T> | ||
constexpr T bit_set_or_res(const T val, const T mask, bool cond) | ||
{ | ||
return cond ? (val | mask) : (val & ~mask); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.