[avr] inline htob and btoh functions
This commit is contained in:
parent
65db2fe1dd
commit
9c47f71514
|
@ -1,27 +0,0 @@
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
// hex to binary/byte decoding
|
|
||||||
uint8_t htob(uint16_t hex)
|
|
||||||
{
|
|
||||||
uint8_t low_hex = (uint8_t) hex;
|
|
||||||
uint8_t high_hex = (uint8_t) (hex >> 8);
|
|
||||||
uint8_t byte;
|
|
||||||
|
|
||||||
byte = (high_hex > 0x40) ? (high_hex & 0x0F) + 9 : high_hex & 0x0F;
|
|
||||||
byte = byte << 4;
|
|
||||||
byte |= (low_hex > 0x40) ? (low_hex & 0x0F) + 9 : low_hex & 0x0F;
|
|
||||||
return byte;
|
|
||||||
}
|
|
||||||
|
|
||||||
// binary/byte to hex encoding
|
|
||||||
uint16_t btoh(uint8_t byte)
|
|
||||||
{
|
|
||||||
uint8_t low_nibble = (byte & 0x0F);
|
|
||||||
uint8_t high_nibble = (byte & 0xF0) >> 4;
|
|
||||||
uint16_t hex;
|
|
||||||
|
|
||||||
hex = (high_nibble > 0x09) ? high_nibble - 9 + 0x60 : high_nibble + 0x30;
|
|
||||||
hex = hex << 8;
|
|
||||||
hex |= (low_nibble > 0x09) ? low_nibble - 9 + 0x60 : low_nibble + 0x30;
|
|
||||||
return hex;
|
|
||||||
}
|
|
|
@ -1,2 +1,27 @@
|
||||||
uint8_t htob(uint16_t hex);
|
#include <stdint.h>
|
||||||
uint16_t btoh(uint8_t byte);
|
|
||||||
|
// hex to binary/byte decoding
|
||||||
|
static inline uint8_t htob(uint16_t hex)
|
||||||
|
{
|
||||||
|
uint8_t low_hex = (uint8_t) hex;
|
||||||
|
uint8_t high_hex = (uint8_t) (hex >> 8);
|
||||||
|
uint8_t byte;
|
||||||
|
|
||||||
|
byte = (high_hex > 0x40) ? (high_hex & 0x0F) + 9 : high_hex & 0x0F;
|
||||||
|
byte = byte << 4;
|
||||||
|
byte |= (low_hex > 0x40) ? (low_hex & 0x0F) + 9 : low_hex & 0x0F;
|
||||||
|
return byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
// binary/byte to hex encoding
|
||||||
|
static inline uint16_t btoh(uint8_t byte)
|
||||||
|
{
|
||||||
|
uint8_t low_nibble = (byte & 0x0F);
|
||||||
|
uint8_t high_nibble = (byte & 0xF0) >> 4;
|
||||||
|
uint16_t hex;
|
||||||
|
|
||||||
|
hex = (high_nibble > 0x09) ? high_nibble - 9 + 0x60 : high_nibble + 0x30;
|
||||||
|
hex = hex << 8;
|
||||||
|
hex |= (low_nibble > 0x09) ? low_nibble - 9 + 0x60 : low_nibble + 0x30;
|
||||||
|
return hex;
|
||||||
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ TARGET = main
|
||||||
|
|
||||||
|
|
||||||
# List C source files here. (C dependencies are automatically generated.)
|
# List C source files here. (C dependencies are automatically generated.)
|
||||||
SRC = $(TARGET).c buffer.c uart.c spi.c ctrl.c encode.c
|
SRC = $(TARGET).c buffer.c uart.c spi.c ctrl.c
|
||||||
|
|
||||||
|
|
||||||
# List Assembler source files here.
|
# List Assembler source files here.
|
||||||
|
@ -119,6 +119,9 @@ CDEFS = -DF_CPU=$(F_CPU)UL
|
||||||
DBG = 0
|
DBG = 0
|
||||||
CDEFS += -D DBG=$(DBG)
|
CDEFS += -D DBG=$(DBG)
|
||||||
|
|
||||||
|
# Warn when a function marked for inlining could not be substituted
|
||||||
|
CDEFS += -Winline
|
||||||
|
|
||||||
# uncomment and adapt these line if you want different UART library buffer size
|
# uncomment and adapt these line if you want different UART library buffer size
|
||||||
CDEFS += -DUART_RX_BUFFER_SIZE=64
|
CDEFS += -DUART_RX_BUFFER_SIZE=64
|
||||||
CDEFS += -DUART_TX_BUFFER_SIZE=64
|
CDEFS += -DUART_TX_BUFFER_SIZE=64
|
||||||
|
|
Loading…
Reference in New Issue