本文整理汇总了C++中SPI_SELECT函数的典型用法代码示例。如果您正苦于以下问题:C++ SPI_SELECT函数的具体用法?C++ SPI_SELECT怎么用?C++ SPI_SELECT使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SPI_SELECT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: adxl345_getreg8
uint8_t adxl345_getreg8(FAR struct adxl345_dev_s *priv, uint8_t regaddr)
{
uint8_t regval;
/* If SPI bus is shared then lock and configure it */
#ifndef CONFIG_SPI_OWNBUS
(void)SPI_LOCK(priv->spi, true);
adxl345_configspi(priv->spi);
#endif
/* Select the ADXL345 */
SPI_SELECT(priv->spi, SPIDEV_GSENSOR, true);
/* Send register to read and get the next byte */
(void)SPI_SEND(priv->spi, regaddr);
SPI_RECVBLOCK(priv->spi, ®val, 1);
/* Deselect the ADXL345 */
SPI_SELECT(priv->spi, SPIDEV_GSENSOR, false);
/* Unlock bus */
#ifndef CONFIG_SPI_OWNBUS
(void)SPI_LOCK(priv->spi, false);
#endif
#ifdef CONFIG_ADXL345_REGDEBUG
dbg("%02x->%02x\n", regaddr, regval);
#endif
return regval;
}
示例2: SPI_LOCK
int
SPI::transfer(uint8_t *send, uint8_t *recv, unsigned len)
{
if ((send == nullptr) && (recv == nullptr))
return -EINVAL;
/* do common setup */
if (!up_interrupt_context())
SPI_LOCK(_dev, true);
SPI_SETFREQUENCY(_dev, _frequency);
SPI_SETMODE(_dev, _mode);
SPI_SETBITS(_dev, 8);
SPI_SELECT(_dev, _device, true);
/* do the transfer */
SPI_EXCHANGE(_dev, send, recv, len);
/* and clean up */
SPI_SELECT(_dev, _device, false);
if (!up_interrupt_context())
SPI_LOCK(_dev, false);
return OK;
}
示例3: ramtron_waitwritecomplete
static void ramtron_waitwritecomplete(struct ramtron_dev_s *priv)
{
uint8_t status;
/* Select this FLASH part */
SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
/* Send "Read Status Register (RDSR)" command */
(void)SPI_SEND(priv->dev, RAMTRON_RDSR);
/* Loop as long as the memory is busy with a write cycle */
do
{
/* Send a dummy byte to generate the clock needed to shift out the status */
status = SPI_SEND(priv->dev, RAMTRON_DUMMY);
}
while ((status & RAMTRON_SR_WIP) != 0);
/* Deselect the FLASH */
SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
fvdbg("Complete\n");
}
示例4: ads7843e_sendcmd
static uint16_t ads7843e_sendcmd(FAR struct ads7843e_dev_s *priv, uint8_t cmd)
{
uint8_t buffer[2];
uint16_t result;
/* Select the ADS7843E */
SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true);
/* Send the command */
(void)SPI_SEND(priv->spi, cmd);
ads7843e_waitbusy(priv);
/* Read the data */
SPI_RECVBLOCK(priv->spi, buffer, 2);
SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false);
result = ((uint16_t)buffer[0] << 8) | (uint16_t)buffer[1];
result = result >> 4;
ivdbg("cmd:%02x response:%04x\n", cmd, result);
return result;
}
示例5: ads7843e_sendcmd
static uint16_t ads7843e_sendcmd(FAR struct ads7843e_dev_s *priv, uint8_t cmd)
{
uint8_t buffer[2];
uint16_t result;
/* Select the ADS7843E */
SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true);
/* Send the command */
(void)SPI_SEND(priv->spi, cmd);
/* Wait a tiny amount to make sure that the aquisition time is complete */
up_udelay(3); /* 3 microseconds */
/* Read the 12-bit data (LS 4 bits will be padded with zero) */
SPI_RECVBLOCK(priv->spi, buffer, 2);
SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false);
result = ((uint16_t)buffer[0] << 8) | (uint16_t)buffer[1];
result = result >> 4;
ivdbg("cmd:%02x response:%04x\n", cmd, result);
return result;
}
示例6: max11802_sendcmd
static uint16_t max11802_sendcmd(FAR struct max11802_dev_s *priv,
uint8_t cmd, int *tags)
{
uint8_t buffer[2];
uint16_t result;
/* Select the MAX11802 */
SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, true);
/* Send the command */
(void)SPI_SEND(priv->spi, cmd);
/* Read the data */
SPI_RECVBLOCK(priv->spi, buffer, 2);
SPI_SELECT(priv->spi, SPIDEV_TOUCHSCREEN, false);
result = ((uint16_t)buffer[0] << 8) | (uint16_t)buffer[1];
*tags = result & 0xF;
result >>= 4; /* Get rid of tags */
iinfo("cmd:%02x response:%04x\n", cmd, result);
return result;
}
示例7: adxl345_putreg8
void adxl345_putreg8(FAR struct adxl345_dev_s *priv, uint8_t regaddr,
uint8_t regval)
{
#ifdef CONFIG_ADXL345_REGDEBUG
dbg("%02x<-%02x\n", regaddr, regval);
#endif
/* If SPI bus is shared then lock and configure it */
#ifndef CONFIG_SPI_OWNBUS
(void)SPI_LOCK(priv->spi, true);
adxl345_configspi(priv->spi);
#endif
/* Select the ADXL345 */
SPI_SELECT(priv->spi, SPIDEV_GSENSOR, true);
/* Send register address and set the value */
(void)SPI_SEND(priv->spi, regaddr);
(void)SPI_SEND(priv->spi, regval);
/* Deselect the ADXL345 */
SPI_SELECT(priv->spi, SPIDEV_GSENSOR, false);
/* Unlock bus */
#ifndef CONFIG_SPI_OWNBUS
(void)SPI_LOCK(priv->spi, false);
#endif
}
示例8: read_fifo
static bool
read_fifo(uint16_t *data)
{
struct { /* status register and data as read back from the device */
uint8_t cmd;
uint8_t status;
int16_t x;
int16_t y;
int16_t z;
} __attribute__((packed)) report;
report.cmd = ADDR_STATUS_REG | DIR_READ | ADDR_INCREMENT;
/* exchange the report structure with the device */
SPI_LOCK(lis331_dev.spi, true);
SPI_SELECT(lis331_dev.spi, lis331_dev.spi_id, true);
SPI_EXCHANGE(lis331_dev.spi, &report, &report, sizeof(report));
SPI_SELECT(lis331_dev.spi, lis331_dev.spi_id, false);
SPI_LOCK(lis331_dev.spi, false);
data[0] = report.x;
data[1] = report.y;
data[2] = report.z;
return report.status & STATUS_ZYXDA;
}
示例9: mpu6000_read_fifo
static int
mpu6000_read_fifo(int16_t *data)
{
// struct { /* status register and data as read back from the device */
// uint8_t cmd;
// uint8_t temp;
// uint8_t status;
// int16_t x;
// int16_t y;
// int16_t z;
// } __attribute__((packed)) report;
//
// report.cmd = ADDR_OUT_TEMP | DIR_READ | ADDR_INCREMENT;
//
// /* exchange the report structure with the device */
// SPI_LOCK(mpu6000_dev.spi, true);
//
// SPI_SELECT(mpu6000_dev.spi, mpu6000_dev.spi_id, true);
//
// read_reg(ADDR_WHO_AM_I);
//
// SPI_EXCHANGE(mpu6000_dev.spi, &report, &report, sizeof(report));
// SPI_SELECT(mpu6000_dev.spi, mpu6000_dev.spi_id, false);
//
// SPI_LOCK(mpu6000_dev.spi, false);
//
//
//
//
// Device has MSB first at lower address (big endian)
struct { /* status register and data as read back from the device */
uint8_t cmd;
uint8_t int_status;
int16_t xacc;
int16_t yacc;
int16_t zacc;
int8_t temp;
int16_t rollspeed;
int16_t pitchspeed;
int16_t yawspeed;
} __attribute__((packed)) report;
report.cmd = 0x26 | DIR_READ | ADDR_INCREMENT;
SPI_LOCK(mpu6000_dev.spi, true);
SPI_SELECT(mpu6000_dev.spi, PX4_SPIDEV_MPU, true);
SPI_EXCHANGE(mpu6000_dev.spi, &report, &report, sizeof(report));
SPI_SELECT(mpu6000_dev.spi, PX4_SPIDEV_MPU, false);
SPI_LOCK(mpu6000_dev.spi, false);
data[0] = report.xacc;
data[1] = report.yacc;
data[2] = report.zacc;
return (report.int_status & 0x01);
}
示例10: ramtron_readid
static inline int ramtron_readid(struct ramtron_dev_s *priv)
{
uint16_t manufacturer, memory, capacity, part;
int i;
fvdbg("priv: %p\n", priv);
/* Lock the SPI bus, configure the bus, and select this FLASH part. */
ramtron_lock(priv);
SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
/* Send the "Read ID (RDID)" command and read the first three ID bytes */
(void)SPI_SEND(priv->dev, RAMTRON_RDID);
for (i = 0; i < 6; i++)
{
manufacturer = SPI_SEND(priv->dev, RAMTRON_DUMMY);
/*
* Fujitsu parts such as MB85RS1MT only have 1-byte for the manufacturer
* ID. The manufacturer code is "0x4".
*/
if (manufacturer == 0x4)
break;
}
memory = SPI_SEND(priv->dev, RAMTRON_DUMMY);
capacity = SPI_SEND(priv->dev, RAMTRON_DUMMY); // fram.id1
part = SPI_SEND(priv->dev, RAMTRON_DUMMY); // fram.id2
/* Deselect the FLASH and unlock the bus */
SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
ramtron_unlock(priv->dev);
/* Select part from the part list */
for (priv->part = ramtron_parts;
priv->part->name != NULL && !(priv->part->id1 == capacity && priv->part->id2 == part);
priv->part++);
if (priv->part->name)
{
fvdbg("RAMTRON %s of size %d bytes (mf:%02x mem:%02x cap:%02x part:%02x)\n",
priv->part->name, priv->part->size, manufacturer, memory, capacity, part);
priv->sectorshift = RAMTRON_EMULATE_SECTOR_SHIFT;
priv->nsectors = priv->part->size / (1 << RAMTRON_EMULATE_SECTOR_SHIFT);
priv->pageshift = RAMTRON_EMULATE_PAGE_SHIFT;
priv->npages = priv->part->size / (1 << RAMTRON_EMULATE_PAGE_SHIFT);
priv->speed = priv->part->speed;
return OK;
}
fvdbg("RAMTRON device not found\n");
return -ENODEV;
}
示例11: bma180_write_reg
static void
bma180_write_reg(uint8_t address, uint8_t data)
{
uint8_t cmd[2] = { address | DIR_WRITE, data };
SPI_SELECT(bma180_dev.spi, bma180_dev.spi_id, true);
SPI_SNDBLOCK(bma180_dev.spi, &cmd, sizeof(cmd));
SPI_SELECT(bma180_dev.spi, bma180_dev.spi_id, false);
}
示例12: write_reg
static void
write_reg(uint8_t address, uint8_t data)
{
uint8_t cmd[2] = { address | DIR_WRITE, data };
SPI_SELECT(lis331_dev.spi, PX4_SPIDEV_ACCEL, true);
SPI_SNDBLOCK(lis331_dev.spi, &cmd, sizeof(cmd));
SPI_SELECT(lis331_dev.spi, PX4_SPIDEV_ACCEL, false);
}
示例13: nrf24l01_configspi
static inline void nrf24l01_configspi(FAR struct spi_dev_s *spi)
{
/* Configure SPI for the NRF24L01 module. */
SPI_SELECT(spi, SPIDEV_WIRELESS, true); /* Useful ? */
SPI_SETMODE(spi, SPIDEV_MODE0);
SPI_SETBITS(spi, 8);
(void)SPI_HWFEATURES(spi, 0);
(void)SPI_SETFREQUENCY(spi, NRF24L01_SPIFREQ);
SPI_SELECT(spi, SPIDEV_WIRELESS, false);
}
示例14: nrf24l01_configspi
static inline void nrf24l01_configspi(FAR struct spi_dev_s *spi)
{
/* Configure SPI for the NRF24L01 module.
* As we own the SPI bus this method is called just once.
*/
SPI_SELECT(spi, SPIDEV_WIRELESS, true); // Useful ?
SPI_SETMODE(spi, SPIDEV_MODE0);
SPI_SETBITS(spi, 8);
SPI_SETFREQUENCY(spi, NRF24L01_SPIFREQ);
SPI_SELECT(spi, SPIDEV_WIRELESS, false);
}
示例15: pga11x_write
static void pga11x_write(FAR struct spi_dev_s *spi, uint16_t cmd)
{
spivdbg("cmd %04x\n", cmd);
/* Lock, select, send the 16-bit command, de-select, and un-lock. */
pga11x_lock(spi);
SPI_SELECT(spi, SPIDEV_MUX, true);
pga11x_send16(spi, cmd);
SPI_SELECT(spi, SPIDEV_MUX, false);
pga11x_unlock(spi);
}