Skip to content

Commit 3b8ce48

Browse files
Added LAN8670_Read_PHY_DevAddr()
1 parent c9d989d commit 3b8ce48

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

general/include/lan8670.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,12 @@ int32_t LAN8670_Read_PHY_ID1(lan8670_t *lan, uint16_t *data);
226226
*/
227227
int32_t LAN8670_Read_Model_Number(lan8670_t *lan, uint8_t *data);
228228

229+
/**
230+
* @brief Returns the PHY's device address according to the STRAP_CTRL0 register. This is a 5-bit value and should be consistent with how the device address is configured via the hardware pins.
231+
*
232+
* @param lan Pointer to the lan8670_t instance.
233+
* @param data Buffer for the value.
234+
* @return Status.
235+
*/
236+
int32_t LAN8670_Read_PHY_DevAddr(lan8670_t *lan, uint8_t *data);
229237
// clang-format on

general/src/lan8670.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,4 +595,19 @@ int32_t LAN8670_Read_Model_Number(lan8670_t *lan, uint8_t *data) {
595595
return LAN8670_STATUS_OK;
596596
}
597597

598+
/* Returns the 5-bit PHY device address. */
599+
int32_t LAN8670_Read_PHY_DevAddr(lan8670_t *lan, uint8_t *data) {
600+
// Read bits 4:0 of the STRAP_CTRL0 register (containing the DevAddr configured by the hardware pins).
601+
uint32_t buffer = 0;
602+
int32_t status = read_register_field(lan, REG_STRAP_CTRL0, 0, 4, &buffer);
603+
if(status != 0) {
604+
PRINTLN_ERROR("Failed to call read_register_field() to read the STRAP_CTRL0 register (Status: %d).", status);
605+
return LAN8670_STATUS_READ_ERROR;
606+
}
607+
608+
// Store the value
609+
*data = (uint8_t)buffer;
610+
return LAN8670_STATUS_OK;
611+
}
612+
598613
// clang-format on

0 commit comments

Comments
 (0)