diff options
| author | tmk <nobody@nowhere> | 2012-10-06 02:23:12 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2012-10-17 15:55:37 +0900 |
| commit | 4ae979f6ef8dbf9e1d1f35be15322ad6d02e2958 (patch) | |
| tree | 9f5132005c27ef04ae793b77d4699cb285479466 /common/util.c | |
| parent | 93e33fb8f694c9685accd72ed0458a2cf3d3f04a (diff) | |
| download | qmk_firmware-4ae979f6ef8dbf9e1d1f35be15322ad6d02e2958.tar.gz qmk_firmware-4ae979f6ef8dbf9e1d1f35be15322ad6d02e2958.zip | |
Initial version of new code for layer switch is added.
Diffstat (limited to 'common/util.c')
| -rw-r--r-- | common/util.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/common/util.c b/common/util.c index 36afdd447..644301fe8 100644 --- a/common/util.c +++ b/common/util.c | |||
| @@ -17,19 +17,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 17 | 17 | ||
| 18 | #include "util.h" | 18 | #include "util.h" |
| 19 | 19 | ||
| 20 | // bit population | 20 | // bit population - return number of on-bit |
| 21 | int bitpop(uint8_t bits) | 21 | uint8_t bitpop(uint8_t bits) |
| 22 | { | 22 | { |
| 23 | int c; | 23 | uint8_t c; |
| 24 | for (c = 0; bits; c++) | 24 | for (c = 0; bits; c++) |
| 25 | bits &= bits -1; | 25 | bits &= bits -1; |
| 26 | return c; | 26 | return c; |
| 27 | /* | ||
| 28 | const uint8_t bit_count[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; | ||
| 29 | return bit_count[bits>>4] + bit_count[bits&0x0F] | ||
| 30 | */ | ||
| 27 | } | 31 | } |
| 28 | 32 | ||
| 29 | // most significant on-bit | 33 | // most significant on-bit - return highest location of on-bit |
| 30 | int biton(uint8_t bits) | 34 | uint8_t biton(uint8_t bits) |
| 31 | { | 35 | { |
| 32 | int n = 0; | 36 | uint8_t n = 0; |
| 33 | if (bits >> 4) { bits >>= 4; n += 4;} | 37 | if (bits >> 4) { bits >>= 4; n += 4;} |
| 34 | if (bits >> 2) { bits >>= 2; n += 2;} | 38 | if (bits >> 2) { bits >>= 2; n += 2;} |
| 35 | if (bits >> 1) { bits >>= 1; n += 1;} | 39 | if (bits >> 1) { bits >>= 1; n += 1;} |
