int board_power_off(void) { uint16_t tx; struct spi_dev_s *spi = up_spiinitialize(0); SPI_SETBITS(spi, 16); tx = (1 << 6) | (1 << 1); SPI_SNDBLOCK(spi, &tx, 1); tx = (1 << 6) | (30 << 1); SPI_SNDBLOCK(spi, &tx, 1); return 0; }
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; }
static void ssd1351_write(FAR struct ssd1351_dev_s *priv, uint8_t cmd, FAR const uint8_t *data, size_t datlen) { size_t i; /* Sanity check */ DEBUGASSERT(priv != NULL); DEBUGASSERT((data == NULL && datlen == 0) || (data != NULL && datlen > 0)); DEBUGASSERT(datlen <= SSD1351_STRIDE); /* Copy the command into the line buffer */ priv->rowbuffer[0] = (uint16_t)cmd | SSD1351_SPICMD; /* Copy any data after the command into the line buffer */ for (i = 0; i < datlen; i++) { priv->rowbuffer[i+1] = (uint16_t)data[i] | SSD1351_SPIDATA; } /* Send the line buffer */ (void)SPI_SNDBLOCK(priv->spi, priv->rowbuffer, datlen+1); }
static void ssd1351_write(FAR struct ssd1351_dev_s *priv, uint8_t cmd, FAR const uint8_t *data, size_t datlen) { FAR struct spi_dev_s *spi = priv->spi; /* Sanity check */ DEBUGASSERT(priv != NULL); DEBUGASSERT((data == NULL && datlen == 0) || (data != NULL && datlen > 0)); /* Select command transfer */ (void)SPI_CMDDATA(spi, SPIDEV_DISPLAY, true); /* Send the command */ (void)SPI_SEND(spi, cmd); /* Do we have any data to send? */ if (datlen > 0) { /* Yes, select data transfer */ (void)SPI_CMDDATA(spi, SPIDEV_DISPLAY, false); /* Transfer all of the data */ (void)SPI_SNDBLOCK(spi, data, datlen); } }
int board_power_off(int status) { struct spi_dev_s *spi = calypso_spibus_initialize(0); uint16_t tx; SPI_SETBITS(spi, 16); (void)SPI_HWFEATURES(spi, 0); tx = (1 << 6) | (1 << 1); SPI_SNDBLOCK(spi, &tx, 1); tx = (1 << 6) | (30 << 1); SPI_SNDBLOCK(spi, &tx, 1); return 0; }
int pn532_write_frame(struct pn532_dev_s *dev, struct pn532_frame *f) { int res = OK; pn532_lock(dev->spi); pn532_select(dev); nxsig_usleep(2000); SPI_SEND(dev->spi, PN532_SPI_DATAWRITE); SPI_SNDBLOCK(dev->spi, f, FRAME_SIZE(f)); pn532_deselect(dev); pn532_unlock(dev->spi); tracetx("WriteFrame", (uint8_t *) f, FRAME_SIZE(f)); /* Wait ACK frame */ res = pn532_wait_rx_ready(dev, 30); if (res == OK) { if (!pn532_read_ack(dev)) { pn532err("ERROR: command FAILED\n"); res = -EIO; } } return res; }
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); }
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); }
static void spi_write(int port, int addr, int frequency, int bits, int conf, char value) { unsigned char buf[2]; buf[0] = addr; buf[1] = value; 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_SNDBLOCK(spi_dev, buf, 2); SPI_SELECT(spi_dev, port, false); SPI_LOCK(spi_dev, false); }
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 void pn532_writecommand(struct pn532_dev_s *dev, uint8_t cmd) { char cmd_buffer[16]; struct pn532_frame *f = (struct pn532_frame *) cmd_buffer; pn532_frame_init(f, cmd); pn532_frame_finish(f); pn532_lock(dev->spi); pn532_select(dev); nxsig_usleep(10000); SPI_SEND(dev->spi, PN532_SPI_DATAWRITE); SPI_SNDBLOCK(dev->spi, f, FRAME_SIZE(f)); pn532_deselect(dev); pn532_unlock(dev->spi); tracetx("command sent", (uint8_t *) f, FRAME_SIZE(f)); }