27
27
#include " hex_print.h"
28
28
#include " ../core/serial.h"
29
29
30
- static char _hex[] = " 0x00000000" ;
30
+ static char _hex[] = " 0x00000000" ; // 0:adr32 2:long 4:adr16 6:word 8:byte
31
31
32
32
inline void __hex_byte (const uint8_t b, const uint8_t o=8 ) {
33
33
_hex[o + 0 ] = hex_nybble (b >> 4 );
34
34
_hex[o + 1 ] = hex_nybble (b);
35
35
}
36
36
inline void __hex_word (const uint16_t w, const uint8_t o=6 ) {
37
- __hex_byte (w >> 2 , o + 0 );
38
- __hex_byte (w >> 0 , o + 2 );
37
+ __hex_byte (w >> 8 , o + 0 );
38
+ __hex_byte (w , o + 2 );
39
39
}
40
- inline void __hex_long (const uint16_t w) {
41
- __hex_word (w >> 4 , 2 );
42
- __hex_word (w >> 0 , 6 );
40
+ inline void __hex_long (const uint32_t w) {
41
+ __hex_word (w >> 16 , 2 );
42
+ __hex_word (w , 6 );
43
43
}
44
44
45
45
char * hex_byte (const uint8_t b) { __hex_byte (b); return &_hex[8 ]; }
@@ -51,15 +51,15 @@ char* hex_address(const void * const a) {
51
51
(void )_hex_long ((uintptr_t )a);
52
52
return _hex;
53
53
#else
54
- hex [4 ] = ' 0' ; hex [5 ] = ' x' ;
54
+ _hex [4 ] = ' 0' ; _hex [5 ] = ' x' ;
55
55
(void )_hex_word ((uintptr_t )a);
56
56
return &_hex[4 ];
57
57
#endif
58
58
}
59
59
60
60
void print_hex_nybble (const uint8_t n) { SERIAL_CHAR (hex_nybble (n)); }
61
61
void print_hex_byte (const uint8_t b) { SERIAL_ECHO (hex_byte (b)); }
62
- void print_hex_word (const uint16_t w) { SERIAL_ECHO (hex_word (w)); }
62
+ void print_hex_word (const uint16_t w) { SERIAL_ECHO (_hex_word (w)); }
63
63
void print_hex_address (const void * const w) { SERIAL_ECHO (hex_address (w)); }
64
64
65
65
void print_hex_long (const uint32_t w, const char delimiter/* ='\0'*/ , const bool prefix/* =false*/ ) {
0 commit comments