HR_C6000: add method to read 16-bit addressed registers

Acked-by: Silvano Seva <silseva@fastwebnet.it>
This commit is contained in:
Ryan Turner 2025-09-27 18:32:44 -05:00 committed by Silvano Seva
parent 00a4dbb063
commit 35788b9c1c
2 changed files with 32 additions and 2 deletions

View File

@ -103,7 +103,7 @@ private:
{
uint8_t data[4];
data[0] = static_cast< uint8_t >(opMode) | 0x40;
data[0] = SPI_FLAGS_EXTD | static_cast< uint8_t >(opMode);
data[2] = (addr >> 8) & 0x07;
data[1] = addr & 0xFF;
data[3] = value;
@ -111,6 +111,30 @@ private:
ScopedChipSelect cs(uSpi, uCs);
spi_send(uSpi, data, 4);
}
/**
* Read a register with 16-bit address.
*
* @param opMode: "operating mode" specifier, see datasheet for details.
* @param addr: register address.
* @return: value read from the register.
*/
uint8_t readReg16(const C6000_SpiOpModes opMode, const uint16_t addr)
{
uint8_t data[3];
uint8_t value[1];
data[0] = SPI_FLAGS_READ | SPI_FLAGS_EXTD
| static_cast< uint8_t >(opMode);
data[2] = (addr >> 8) & 0x07;
data[1] = addr & 0xFF;
ScopedChipSelect cs(uSpi, uCs);
spi_send(uSpi, data, sizeof(data));
spi_receive(uSpi, value, 1);
return value[0];
}
};
#endif /* HRC6000_H */

View File

@ -240,7 +240,7 @@ private:
uint8_t cmd[3];
uint8_t ret[3];
cmd[0] = 0x80 | static_cast< uint8_t >(opMode);
cmd[0] = SPI_FLAGS_READ | static_cast< uint8_t >(opMode);
cmd[1] = addr;
cmd[2] = 0x00;
@ -265,6 +265,12 @@ private:
protected:
enum SpiFlags
{
SPI_FLAGS_READ = 0x80, ///< Do a read transaction
SPI_FLAGS_EXTD = 0x40, ///< Use 16-bit addressing (HR_C6000 only)
};
const struct spiDevice *uSpi;
const struct gpioPin uCs;
};