Skip to content

Commit

Permalink
Merge pull request #5 from maciejbocianski/fix_conversion
Browse files Browse the repository at this point in the history
fix integer to enum conversion
  • Loading branch information
paul-szczepanek-arm committed Sep 20, 2019
2 parents 9ced51b + 559aa98 commit b713ebd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions m24sr_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace ST {
#define MAX_PAYLOAD 241

/** value returned by the NFC chip when a command is successfully completed */
#define NFC_COMMAND_SUCCESS 0x9000
static constexpr const uint16_t NFC_COMMAND_SUCCESS = 0x9000;
/** I2C nfc address */
#define M24SR_ADDR 0xAC

Expand Down Expand Up @@ -174,7 +174,7 @@ static uint16_t compute_crc(uint8_t *data, uint8_t length) {
*/
static M24srError_t is_correct_crc_residue(uint8_t *data, uint8_t length) {
uint16_t res_crc = 0x0000;
M24srError_t status;
uint16_t status;

/* check the CRC16 Residue */
if (length != 0) {
Expand All @@ -183,8 +183,8 @@ static M24srError_t is_correct_crc_residue(uint8_t *data, uint8_t length) {

if (res_crc == 0x0000) {
/* Good CRC, but error status from M24SR */
status = (M24srError_t) (((data[length - UB_STATUS_OFFSET] << 8) & 0xFF00)
| (data[length - LB_STATUS_OFFSET] & 0x00FF));
status = ((data[length - UB_STATUS_OFFSET] << 8) & 0xFF00)
| (data[length - LB_STATUS_OFFSET] & 0x00FF);
} else {
res_crc = 0x0000;
res_crc = compute_crc(data, 5);
Expand All @@ -193,15 +193,15 @@ static M24srError_t is_correct_crc_residue(uint8_t *data, uint8_t length) {
return M24SR_IO_ERROR_CRC;
} else {
/* Good CRC, but error status from M24SR */
status = (M24srError_t) (((data[1] << 8) & 0xFF00) | (data[2] & 0x00FF));
status = ((data[1] << 8) & 0xFF00) | (data[2] & 0x00FF);
}
}

if (status == NFC_COMMAND_SUCCESS) {
status = M24SR_SUCCESS;
return M24SR_SUCCESS;
}

return status;
return (M24srError_t)status;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion m24sr_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct R_APDU {
uint8_t SW2; /**< Command Processing qualification */
};

enum M24srError_t {
enum M24srError_t : uint16_t {
M24SR_SUCCESS = 0,
M24SR_ERROR = 0x6F00,
M24SR_FILE_OVERFLOW_LE = 0x6280,
Expand Down

0 comments on commit b713ebd

Please sign in to comment.