27 lines
675 B
C
27 lines
675 B
C
#include "encode.h"
|
|
#include "parity.h"
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
|
|
void encode_get_nibbles(uint8_t value, uint8_t* high, uint8_t* low) {
|
|
if (high == NULL || low == NULL) {
|
|
return;
|
|
}
|
|
*high = (value >> 4) & 0x0F; // bits 7-4
|
|
*low = value & 0x0F; // bits 3-0
|
|
}
|
|
|
|
void encode_value(uint8_t input, uint8_t* high, uint8_t* low) {
|
|
if (high == NULL || low == NULL) {
|
|
return;
|
|
}
|
|
|
|
uint8_t nibble_high, nibble_low;
|
|
|
|
// Splits input-byte in twee nibbles
|
|
encode_get_nibbles(input, &nibble_high, &nibble_low);
|
|
|
|
// Voeg pariteitsbits toe
|
|
*high = add_parity(nibble_high);
|
|
*low = add_parity(nibble_low);
|
|
} |