Merge pull request #2616 from jmichelp/fix14b
[RRG-proxmark3.git] / armsrc / util.h
blobfd99ac73eaedad3fa7c223fb0ab189cb6beb38bc
1 //-----------------------------------------------------------------------------
2 // Copyright (C) Jonathan Westhues, Aug 2005
3 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // See LICENSE.txt for the text of the license.
16 //-----------------------------------------------------------------------------
17 // Utility functions used in many places, not specific to any piece of code.
18 //-----------------------------------------------------------------------------
20 #ifndef __UTIL_H
21 #define __UTIL_H
23 #include "common.h"
25 // PRIx64 definition missing with gcc-arm-none-eabi v8?
26 #ifndef PRIx64
27 #define PRIx64 "llx"
28 #endif
30 // Basic macros
32 #ifndef SHORT_COIL
33 #define SHORT_COIL() LOW(GPIO_SSC_DOUT)
34 #endif
36 #ifndef OPEN_COIL
37 #define OPEN_COIL() HIGH(GPIO_SSC_DOUT)
38 #endif
40 #ifndef BYTEx
41 #define BYTEx(x, n) (((x) >> (n * 8)) & 0xff )
42 #endif
44 // Proxmark3 RDV4.0 and Proxmark Easy LEDs
45 #define LED_A 1
46 #define LED_B 2
47 #define LED_C 4
48 #define LED_D 8
51 #ifndef LED_ORDER_PM3EASY
52 // Proxmark3 historical LEDs
53 #define LED_ORANGE LED_A
54 #define LED_GREEN LED_B
55 #define LED_RED LED_C
56 #define LED_RED2 LED_D
57 #else
58 // Proxmark3 Easy LEDs
59 #define LED_GREEN LED_A
60 #define LED_RED LED_B
61 #define LED_ORANGE LED_C
62 #define LED_RED2 LED_D
63 #endif
65 #define BUTTON_HOLD 1
66 #define BUTTON_NO_CLICK 0
67 #define BUTTON_SINGLE_CLICK -1
68 #define BUTTON_DOUBLE_CLICK -2
69 #define BUTTON_ERROR -99
72 #ifndef BIT32
73 #define BIT32(x,n) ((((x)[(n)>>5])>>((n)))&1)
74 #endif
76 #ifndef INV32
77 #define INV32(x,i,n) ((x)[(i)>>5]^=((uint32_t)(n))<<((i)&31))
78 #endif
80 #ifndef ROTL64
81 #define ROTL64(x, n) ((((uint64_t)(x))<<((n)&63))+(((uint64_t)(x))>>((0-(n))&63)))
82 #endif
84 size_t nbytes(size_t nbits);
85 uint8_t hex2int(char x);
87 int hex2binarray(char *target, const char *source);
88 int hex2binarray_n(char *target, const char *source, int sourcelen);
89 int binarray2hex(const uint8_t *bs, int bs_len, uint8_t *hex);
91 void convertToHexArray(uint32_t num, uint8_t *partialkey);
93 void LED(int led, int ms);
94 void LEDsoff(void);
95 void SpinOff(uint32_t pause);
96 void SpinErr(uint8_t led, uint32_t speed, uint8_t times);
97 void SpinDown(uint32_t speed);
98 void SpinUp(uint32_t speed);
100 int BUTTON_CLICKED(int ms);
101 int BUTTON_HELD(int ms);
102 bool data_available(void);
103 bool data_available_fast(void);
105 uint32_t flash_size_from_cidr(uint32_t cidr);
106 uint32_t get_flash_size(void);
108 #endif