1 //-----------------------------------------------------------------------------
2 // Copyright (C) Jonathan Westhues, Aug 2005
3 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
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.
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 //-----------------------------------------------------------------------------
25 // PRIx64 definition missing with gcc-arm-none-eabi v8?
33 #define SHORT_COIL() LOW(GPIO_SSC_DOUT)
37 #define OPEN_COIL() HIGH(GPIO_SSC_DOUT)
41 #define BYTEx(x, n) (((x) >> (n * 8)) & 0xff )
44 // Proxmark3 RDV4.0 and Proxmark Easy LEDs
51 #ifndef LED_ORDER_PM3EASY
52 // Proxmark3 historical LEDs
53 #define LED_ORANGE LED_A
54 #define LED_GREEN LED_B
56 #define LED_RED2 LED_D
58 // Proxmark3 Easy LEDs
59 #define LED_GREEN LED_A
61 #define LED_ORANGE LED_C
62 #define LED_RED2 LED_D
66 #define BUTTON_NO_CLICK 0
67 #define BUTTON_SINGLE_CLICK -1
68 #define BUTTON_DOUBLE_CLICK -2
69 #define BUTTON_ERROR -99
73 #define BIT32(x,n) ((((x)[(n)>>5])>>((n)))&1)
77 #define INV32(x,i,n) ((x)[(i)>>5]^=((uint32_t)(n))<<((i)&31))
81 #define ROTL64(x, n) ((((uint64_t)(x))<<((n)&63))+(((uint64_t)(x))>>((0-(n))&63)))
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
);
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);