Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sun May 14 23:18:57 2017 +0000
Revision:
18:6a4db94011d3
Publishing again

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 18:6a4db94011d3 1 /* mbed Microcontroller Library
sahilmgandhi 18:6a4db94011d3 2 * Copyright (c) 2015-2016 Nuvoton
sahilmgandhi 18:6a4db94011d3 3 *
sahilmgandhi 18:6a4db94011d3 4 * Licensed under the Apache License, Version 2.0 (the "License");
sahilmgandhi 18:6a4db94011d3 5 * you may not use this file except in compliance with the License.
sahilmgandhi 18:6a4db94011d3 6 * You may obtain a copy of the License at
sahilmgandhi 18:6a4db94011d3 7 *
sahilmgandhi 18:6a4db94011d3 8 * http://www.apache.org/licenses/LICENSE-2.0
sahilmgandhi 18:6a4db94011d3 9 *
sahilmgandhi 18:6a4db94011d3 10 * Unless required by applicable law or agreed to in writing, software
sahilmgandhi 18:6a4db94011d3 11 * distributed under the License is distributed on an "AS IS" BASIS,
sahilmgandhi 18:6a4db94011d3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sahilmgandhi 18:6a4db94011d3 13 * See the License for the specific language governing permissions and
sahilmgandhi 18:6a4db94011d3 14 * limitations under the License.
sahilmgandhi 18:6a4db94011d3 15 */
sahilmgandhi 18:6a4db94011d3 16
sahilmgandhi 18:6a4db94011d3 17 #ifndef NU_BIT_UTIL_H
sahilmgandhi 18:6a4db94011d3 18 #define NU_BIT_UTIL_H
sahilmgandhi 18:6a4db94011d3 19
sahilmgandhi 18:6a4db94011d3 20 #include "cmsis.h"
sahilmgandhi 18:6a4db94011d3 21
sahilmgandhi 18:6a4db94011d3 22 #ifdef __cplusplus
sahilmgandhi 18:6a4db94011d3 23 extern "C" {
sahilmgandhi 18:6a4db94011d3 24 #endif
sahilmgandhi 18:6a4db94011d3 25
sahilmgandhi 18:6a4db94011d3 26 __STATIC_INLINE int nu_clz(uint32_t x)
sahilmgandhi 18:6a4db94011d3 27 {
sahilmgandhi 18:6a4db94011d3 28 return __CLZ(x);
sahilmgandhi 18:6a4db94011d3 29 }
sahilmgandhi 18:6a4db94011d3 30
sahilmgandhi 18:6a4db94011d3 31 __STATIC_INLINE int nu_clo(uint32_t x)
sahilmgandhi 18:6a4db94011d3 32 {
sahilmgandhi 18:6a4db94011d3 33 return nu_clz(~x);
sahilmgandhi 18:6a4db94011d3 34 }
sahilmgandhi 18:6a4db94011d3 35
sahilmgandhi 18:6a4db94011d3 36 __STATIC_INLINE int nu_ctz(uint32_t x)
sahilmgandhi 18:6a4db94011d3 37 {
sahilmgandhi 18:6a4db94011d3 38 int c = __CLZ(x & -x);
sahilmgandhi 18:6a4db94011d3 39 return x ? 31 - c : c;
sahilmgandhi 18:6a4db94011d3 40 }
sahilmgandhi 18:6a4db94011d3 41
sahilmgandhi 18:6a4db94011d3 42 __STATIC_INLINE int nu_cto(uint32_t x)
sahilmgandhi 18:6a4db94011d3 43 {
sahilmgandhi 18:6a4db94011d3 44 return nu_ctz(~x);
sahilmgandhi 18:6a4db94011d3 45 }
sahilmgandhi 18:6a4db94011d3 46
sahilmgandhi 18:6a4db94011d3 47
sahilmgandhi 18:6a4db94011d3 48 __STATIC_INLINE uint16_t nu_get16_le(const uint8_t *pos)
sahilmgandhi 18:6a4db94011d3 49 {
sahilmgandhi 18:6a4db94011d3 50 uint16_t val;
sahilmgandhi 18:6a4db94011d3 51
sahilmgandhi 18:6a4db94011d3 52 val = *pos ++;
sahilmgandhi 18:6a4db94011d3 53 val += (*pos << 8);
sahilmgandhi 18:6a4db94011d3 54
sahilmgandhi 18:6a4db94011d3 55 return val;
sahilmgandhi 18:6a4db94011d3 56 }
sahilmgandhi 18:6a4db94011d3 57
sahilmgandhi 18:6a4db94011d3 58 __STATIC_INLINE void nu_set16_le(uint8_t *pos, uint16_t val)
sahilmgandhi 18:6a4db94011d3 59 {
sahilmgandhi 18:6a4db94011d3 60 *pos ++ = val & 0xFF;
sahilmgandhi 18:6a4db94011d3 61 *pos = val >> 8;
sahilmgandhi 18:6a4db94011d3 62 }
sahilmgandhi 18:6a4db94011d3 63
sahilmgandhi 18:6a4db94011d3 64 __STATIC_INLINE uint32_t nu_get32_le(const uint8_t *pos)
sahilmgandhi 18:6a4db94011d3 65 {
sahilmgandhi 18:6a4db94011d3 66 uint32_t val;
sahilmgandhi 18:6a4db94011d3 67
sahilmgandhi 18:6a4db94011d3 68 val = *pos ++;
sahilmgandhi 18:6a4db94011d3 69 val += (*pos ++ << 8);
sahilmgandhi 18:6a4db94011d3 70 val += (*pos ++ << 16);
sahilmgandhi 18:6a4db94011d3 71 val += (*pos ++ << 24);
sahilmgandhi 18:6a4db94011d3 72
sahilmgandhi 18:6a4db94011d3 73 return val;
sahilmgandhi 18:6a4db94011d3 74 }
sahilmgandhi 18:6a4db94011d3 75
sahilmgandhi 18:6a4db94011d3 76 __STATIC_INLINE void nu_set32_le(uint8_t *pos, uint32_t val)
sahilmgandhi 18:6a4db94011d3 77 {
sahilmgandhi 18:6a4db94011d3 78 *pos ++ = val & 0xFF;
sahilmgandhi 18:6a4db94011d3 79 *pos ++ = (val >> 8) & 0xFF;
sahilmgandhi 18:6a4db94011d3 80 *pos ++ = (val >> 16) & 0xFF;
sahilmgandhi 18:6a4db94011d3 81 *pos = (val >> 24) & 0xFF;
sahilmgandhi 18:6a4db94011d3 82 }
sahilmgandhi 18:6a4db94011d3 83
sahilmgandhi 18:6a4db94011d3 84 __STATIC_INLINE uint16_t nu_get16_be(const uint8_t *pos)
sahilmgandhi 18:6a4db94011d3 85 {
sahilmgandhi 18:6a4db94011d3 86 uint16_t val;
sahilmgandhi 18:6a4db94011d3 87
sahilmgandhi 18:6a4db94011d3 88 val = *pos ++;
sahilmgandhi 18:6a4db94011d3 89 val <<= 8;
sahilmgandhi 18:6a4db94011d3 90 val += *pos;
sahilmgandhi 18:6a4db94011d3 91
sahilmgandhi 18:6a4db94011d3 92 return val;
sahilmgandhi 18:6a4db94011d3 93 }
sahilmgandhi 18:6a4db94011d3 94
sahilmgandhi 18:6a4db94011d3 95 __STATIC_INLINE void nu_set16_be(uint8_t *pos, uint16_t val)
sahilmgandhi 18:6a4db94011d3 96 {
sahilmgandhi 18:6a4db94011d3 97 *pos ++ = val >> 8;
sahilmgandhi 18:6a4db94011d3 98 *pos = (val & 0xFF);
sahilmgandhi 18:6a4db94011d3 99 }
sahilmgandhi 18:6a4db94011d3 100
sahilmgandhi 18:6a4db94011d3 101 __STATIC_INLINE uint32_t nu_get32_be(const uint8_t *pos)
sahilmgandhi 18:6a4db94011d3 102 {
sahilmgandhi 18:6a4db94011d3 103 uint32_t val;
sahilmgandhi 18:6a4db94011d3 104
sahilmgandhi 18:6a4db94011d3 105 val = *pos ++;
sahilmgandhi 18:6a4db94011d3 106 val <<= 8;
sahilmgandhi 18:6a4db94011d3 107 val += *pos ++;
sahilmgandhi 18:6a4db94011d3 108 val <<= 8;
sahilmgandhi 18:6a4db94011d3 109 val += *pos ++;
sahilmgandhi 18:6a4db94011d3 110 val <<= 8;
sahilmgandhi 18:6a4db94011d3 111 val += *pos;
sahilmgandhi 18:6a4db94011d3 112
sahilmgandhi 18:6a4db94011d3 113 return val;
sahilmgandhi 18:6a4db94011d3 114 }
sahilmgandhi 18:6a4db94011d3 115
sahilmgandhi 18:6a4db94011d3 116 __STATIC_INLINE void nu_set32_be(uint8_t *pos, uint32_t val)
sahilmgandhi 18:6a4db94011d3 117 {
sahilmgandhi 18:6a4db94011d3 118 *pos ++ = val >> 24;
sahilmgandhi 18:6a4db94011d3 119 *pos ++ = val >> 16;
sahilmgandhi 18:6a4db94011d3 120 *pos ++ = val >> 8;
sahilmgandhi 18:6a4db94011d3 121 *pos ++ = (val & 0xFF);
sahilmgandhi 18:6a4db94011d3 122 }
sahilmgandhi 18:6a4db94011d3 123
sahilmgandhi 18:6a4db94011d3 124 #ifdef __cplusplus
sahilmgandhi 18:6a4db94011d3 125 }
sahilmgandhi 18:6a4db94011d3 126 #endif
sahilmgandhi 18:6a4db94011d3 127
sahilmgandhi 18:6a4db94011d3 128 #endif