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; }
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; }
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; }
static uint8_t nrf24l01_access(FAR struct nrf24l01_dev_s *dev, nrf24l01_access_mode_t mode, uint8_t cmd, FAR uint8_t *buf, int length) { uint8_t status; /* Prepare SPI */ nrf24l01_select(dev); /* Transfer */ status = SPI_SEND(dev->spi, cmd); switch (mode) { case MODE_WRITE: if (length > 0) { SPI_SNDBLOCK(dev->spi, buf, length); } break; case MODE_READ: SPI_RECVBLOCK(dev->spi, buf, length); break; } nrf24l01_deselect(dev); return status; }
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; }
int pn532_read_more(struct pn532_dev_s *dev, uint8_t *buff, uint8_t n) { pn532_lock(dev->spi); pn532_select(dev); SPI_RECVBLOCK(dev->spi, buff, n); pn532_deselect(dev); pn532_unlock(dev->spi); tracerx("read_more", buff, n); return n; }
int pn532_read(struct pn532_dev_s *dev, uint8_t *buff, uint8_t n) { pn532_lock(dev->spi); pn532_select(dev); SPI_SEND(dev->spi, PN532_SPI_DATAREAD); SPI_RECVBLOCK(dev->spi, buff, n); pn532_deselect(dev); pn532_unlock(dev->spi); tracerx("read", buff, n); return n; }
static ssize_t max31855_read(FAR struct file *filep, FAR char *buffer, size_t buflen) { FAR struct inode *inode = filep->f_inode; FAR struct max31855_dev_s *priv = inode->i_private; FAR uint16_t *temp = (FAR uint16_t *) buffer; int ret = 2; int32_t regmsb; int32_t regval; /* Check for issues */ if (!buffer) { sndbg("Buffer is null\n"); return -EINVAL; } if (buflen != 2) { sndbg("You can't read something other than 16 bits (2 bytes)\n"); return -EINVAL; } /* Enable MAX31855's chip select */ SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE, true); /* Read temperature */ SPI_RECVBLOCK(priv->spi, ®msb, 4); /* Disable MAX31855's chip select */ SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE, false); regval = (regmsb & 0xFF000000) >> 24; regval |= (regmsb & 0xFF0000) >> 8; regval |= (regmsb & 0xFF00) << 8; regval |= (regmsb & 0xFF) << 24; sndbg("Read from MAX31855 = 0x%08X\n", regval); /* If negative, fix signal bits */ if (regval & 0x80000000) { *temp = 0xc000 | (regval >> 18); }
int cc1101_access(struct cc1101_dev_s * dev, uint8_t addr, uint8_t *buf, int length) { int stabyte; /* Address cannot explicitly define READ command while length WRITE. * Also access to these cells is only permitted as one byte, eventhough * transfer is marked as BURST! */ if ((addr & CC1101_READ_SINGLE) && length != 1) return ERROR; /* Prepare SPI */ cc1101_access_begin(dev); if (length>1 || length < -1) SPI_SETFREQUENCY(dev->spi, CC1101_SPIFREQ_BURST); else SPI_SETFREQUENCY(dev->spi, CC1101_SPIFREQ_SINGLE); /* Transfer */ if (length <= 0) { /* 0 length are command strobes */ if (length < -1) addr |= CC1101_WRITE_BURST; stabyte = SPI_SEND(dev->spi, addr); if (length) { SPI_SNDBLOCK(dev->spi, buf, -length); } } else { addr |= CC1101_READ_SINGLE; if (length > 1) addr |= CC1101_READ_BURST; stabyte = SPI_SEND(dev->spi, addr); SPI_RECVBLOCK(dev->spi, buf, length); } cc1101_access_end(dev); return stabyte; }
static char spi_read(int port, int addr, int frequency, int bits, int conf) { unsigned char buf[2]; buf[0] = addr | 0x80; SPI_LOCK(spi_dev, true); SPI_SETFREQUENCY(spi_dev, frequency); SPI_SETBITS(spi_dev, bits); SPI_SETMODE(spi_dev, conf); SPI_SELECT(spi_dev, port, true); SPI_RECVBLOCK(spi_dev, buf, 2); SPI_SELECT(spi_dev, port, false); SPI_LOCK(spi_dev, false); return buf[1]; }
static ssize_t max6675_read(FAR struct file *filep, FAR char *buffer, size_t buflen) { FAR struct inode *inode = filep->f_inode; FAR struct max6675_dev_s *priv = inode->i_private; FAR uint16_t *temp = (FAR uint16_t *) buffer; int ret = 2; int16_t regmsb; int16_t regval; /* Check for issues */ if (!buffer) { snerr("ERROR: Buffer is null\n"); return -EINVAL; } if (buflen != 2) { snerr("ERROR: You can't read something other than 16 bits (2 bytes)\n"); return -EINVAL; } /* Enable MAX6675's chip select */ max6675_lock(priv->spi); SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE(0), true); /* Read temperature */ SPI_RECVBLOCK(priv->spi, ®msb, 2); /* Disable MAX6675's chip select */ SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE(0), false); max6675_unlock(priv->spi); regval = (regmsb & 0xFF00) >> 8; regval |= (regmsb & 0xFF) << 8; sninfo("Read from MAX6675 = 0x%04X\n", regval); /* Verify if the device ID bit is really zero */ if (regval & MAX6675_DEV_ID) { snerr("ERROR: The Device ID bit needs to be 0 !\n"); ret = -EINVAL; } /* Detect if termocople input is open */ if (regval & MAX6675_OPEN_CIRCUIT) { snerr("ERROR: The thermocouple input is not connected!\n"); ret = -EINVAL; } /* Feed sensor data to entropy pool */ add_sensor_randomness(regval); /* Get the temperature */ *temp = (regval & MAX6675_TEMP_COUPLE) >> 3; /* Return two bytes, the temperature is fixed point Q10.2, then divide by 4 * in your application in order to get real temperature in Celsius degrees. */ return ret; }