Skip to content

Commit

Permalink
Define desc for rest of registers used in start foo
Browse files Browse the repository at this point in the history
  • Loading branch information
abobija committed Sep 11, 2024
1 parent 3ed57ff commit e67537d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
51 changes: 42 additions & 9 deletions include/rc522/registers.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,22 @@ typedef enum
*/
typedef enum
{
RX_GAIN_2 = BIT6,
RX_GAIN_1 = BIT5,
RX_GAIN_0 = BIT4,
RC522_RX_GAIN_2 = BIT6,
RC522_RX_GAIN_1 = BIT5,
RC522_RX_GAIN_0 = BIT4,
} rc522_rf_cfg_reg_bit_t;

/**
* Receiver (antenna) gain
*/
typedef enum
{
RC522_RX_GAIN_18_DB = (RX_GAIN_1), /* 18 dB */
RC522_RX_GAIN_23_DB = (RX_GAIN_1 | RX_GAIN_0), /* 23 dB */
RC522_RX_GAIN_33_DB = (RX_GAIN_2), /* 33 dB */
RC522_RX_GAIN_38_DB = (RX_GAIN_2 | RX_GAIN_0), /* 38 dB */
RC522_RX_GAIN_43_DB = (RX_GAIN_2 | RX_GAIN_1), /* 43 dB */
RC522_RX_GAIN_48_DB = (RX_GAIN_2 | RX_GAIN_1 | RX_GAIN_0), /* 48 dB */
RC522_RX_GAIN_18_DB = (RC522_RX_GAIN_1), /* 18 dB */
RC522_RX_GAIN_23_DB = (RC522_RX_GAIN_1 | RC522_RX_GAIN_0), /* 23 dB */
RC522_RX_GAIN_33_DB = (RC522_RX_GAIN_2), /* 33 dB */
RC522_RX_GAIN_38_DB = (RC522_RX_GAIN_2 | RC522_RX_GAIN_0), /* 38 dB */
RC522_RX_GAIN_43_DB = (RC522_RX_GAIN_2 | RC522_RX_GAIN_1), /* 43 dB */
RC522_RX_GAIN_48_DB = (RC522_RX_GAIN_2 | RC522_RX_GAIN_1 | RC522_RX_GAIN_0), /* 48 dB */
} rc522_rx_gain_t;

typedef enum
Expand Down Expand Up @@ -180,3 +180,36 @@ typedef enum
*/
RC522_T_AUTO = BIT7,
} rc522_timer_mode_reg_bit_t;

typedef enum
{
/**
* Forces a 100 % ASK modulation independent of the ModGsPReg register setting
*/
RC522_FORCE_100_ASK = BIT6,
} rc522_tx_ask_reg_bit_t;

typedef enum
{
// Transmitter can only be started if an RF field is generated
RC522_TX_WAIT_RF = BIT5,

/**
* Defines the polarity of pin MFIN
*
* 1 - Polarity of pin MFIN is active HIGH
* 0 - Polarity of pin MFIN is active LOW
*/
RC522_POL_MFIN = BIT3,

RC522_CRC_PRESET_1 = BIT1,
RC522_CRC_PRESET_0 = BIT0,
} rc522_mode_reg_bit_t;

typedef enum
{
RC522_CRC_PRESET_0000H = (0x00), /* 0000h */
RC522_CRC_PRESET_6363H = (RC522_CRC_PRESET_0), /* 6363h */
RC522_CRC_PRESET_A671H = (RC522_CRC_PRESET_1), /* A671h */
RC522_CRC_PRESET_FFFFH = (RC522_CRC_PRESET_1 | RC522_CRC_PRESET_0), /* FFFFh */
} rc522_crc_preset_value_t;
16 changes: 6 additions & 10 deletions src/rc522.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,24 +494,20 @@ esp_err_t rc522_start(rc522_handle_t rc522)
ESP_RETURN_ON_ERROR(rc522_soft_reset(rc522), TAG, ""); // TODO: Short delay to wait for reset?
ESP_RETURN_ON_ERROR(rc522_configure_timer(rc522, RC522_T_AUTO, 3390), TAG, "");
ESP_RETURN_ON_ERROR(rc522_set_timer_reload_value(rc522, 30), TAG, "");

const uint8_t map[][2] = {
{ RC522_TX_ASK_REG, 0x40 },
{ RC522_MODE_REG, 0x3D },
};

ESP_RETURN_ON_ERROR(rc522_write_map(rc522, map, sizeof(map) / sizeof(uint8_t) / 2),
ESP_RETURN_ON_ERROR(rc522_write(rc522, RC522_TX_ASK_REG, RC522_FORCE_100_ASK), TAG, "");
ESP_RETURN_ON_ERROR(
rc522_write(rc522, RC522_MODE_REG, (RC522_TX_WAIT_RF | RC522_POL_MFIN | RC522_CRC_PRESET_6363H)),
TAG,
"Failed to write initialization map");

"");
ESP_RETURN_ON_ERROR(rc522_antenna_on(rc522, RC522_RX_GAIN_43_DB), TAG, "Unable to turn on antenna");

uint8_t fw_ver;
ESP_RETURN_ON_ERROR(rc522_firmware(rc522, &fw_ver), TAG, "Failed to get firmware version");
ESP_LOGI(TAG, "Scanning started (firmware=%d.0)", fw_ver);

rc522->state = RC522_STATE_SCANNING;

ESP_LOGI(TAG, "Scanning started (firmware=%d.0)", fw_ver);

return ESP_OK;
}

Expand Down

0 comments on commit e67537d

Please sign in to comment.