本文整理汇总了C++中spi_write_then_read函数的典型用法代码示例。如果您正苦于以下问题:C++ spi_write_then_read函数的具体用法?C++ spi_write_then_read怎么用?C++ spi_write_then_read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spi_write_then_read函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ms5611_spi_read_adc_temp_and_pressure
static int ms5611_spi_read_adc_temp_and_pressure(struct device *dev,
s32 *temp, s32 *pressure)
{
int ret;
struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev));
const struct ms5611_osr *osr = st->temp_osr;
/*
* Warning: &osr->cmd MUST be aligned on a word boundary since used as
* 2nd argument (void*) of spi_write_then_read.
*/
ret = spi_write_then_read(st->client, &osr->cmd, 1, NULL, 0);
if (ret < 0)
return ret;
usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL));
ret = ms5611_spi_read_adc(dev, temp);
if (ret < 0)
return ret;
osr = st->pressure_osr;
ret = spi_write_then_read(st->client, &osr->cmd, 1, NULL, 0);
if (ret < 0)
return ret;
usleep_range(osr->conv_usec, osr->conv_usec + (osr->conv_usec / 10UL));
return ms5611_spi_read_adc(dev, pressure);
}
开发者ID:AlexShiLucky,项目名称:linux,代码行数:28,代码来源:ms5611_spi.c
示例2: ds1302_rtc_set_time
static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *time)
{
struct spi_device *spi = dev_get_drvdata(dev);
u8 buf[1 + RTC_CLCK_LEN];
u8 *bp = buf;
int status;
/* Enable writing */
bp = buf;
*bp++ = RTC_ADDR_CTRL << 1 | RTC_CMD_WRITE;
*bp++ = RTC_CMD_WRITE_ENABLE;
status = spi_write_then_read(spi, buf, 2,
NULL, 0);
if (status)
return status;
/* Write registers starting at the first time/date address. */
bp = buf;
*bp++ = RTC_CLCK_BURST << 1 | RTC_CMD_WRITE;
*bp++ = bin2bcd(time->tm_sec);
*bp++ = bin2bcd(time->tm_min);
*bp++ = bin2bcd(time->tm_hour);
*bp++ = bin2bcd(time->tm_mday);
*bp++ = bin2bcd(time->tm_mon + 1);
*bp++ = time->tm_wday + 1;
*bp++ = bin2bcd(time->tm_year % 100);
*bp++ = RTC_CMD_WRITE_DISABLE;
/* use write-then-read since dma from stack is nonportable */
return spi_write_then_read(spi, buf, sizeof(buf),
NULL, 0);
}
开发者ID:513855417,项目名称:linux,代码行数:34,代码来源:rtc-ds1302.c
示例3: ds1305_get_alarm
/*
* Context: caller holds rtc->ops_lock (to protect ds1305->ctrl)
*/
static int ds1305_get_alarm(struct device *dev, struct rtc_wkalrm *alm)
{
struct ds1305 *ds1305 = dev_get_drvdata(dev);
struct spi_device *spi = ds1305->spi;
u8 addr;
int status;
u8 buf[DS1305_ALM_LEN];
/* Refresh control register cache BEFORE reading ALM0 registers,
* since reading alarm registers acks any pending IRQ. That
* makes returning "pending" status a bit of a lie, but that bit
* of EFI status is at best fragile anyway (given IRQ handlers).
*/
addr = DS1305_CONTROL;
status = spi_write_then_read(spi, &addr, sizeof addr,
ds1305->ctrl, sizeof ds1305->ctrl);
if (status < 0)
return status;
alm->enabled = !!(ds1305->ctrl[0] & DS1305_AEI0);
alm->pending = !!(ds1305->ctrl[1] & DS1305_AEI0);
/* get and check ALM0 registers */
addr = DS1305_ALM0(DS1305_SEC);
status = spi_write_then_read(spi, &addr, sizeof addr,
buf, sizeof buf);
if (status < 0)
return status;
dev_vdbg(dev, "%s: %02x %02x %02x %02x\n",
"alm0 read", buf[DS1305_SEC], buf[DS1305_MIN],
buf[DS1305_HOUR], buf[DS1305_WDAY]);
if ((DS1305_ALM_DISABLE & buf[DS1305_SEC])
|| (DS1305_ALM_DISABLE & buf[DS1305_MIN])
|| (DS1305_ALM_DISABLE & buf[DS1305_HOUR]))
return -EIO;
/* Stuff these values into alm->time and let RTC framework code
* fill in the rest ... and also handle rollover to tomorrow when
* that's needed.
*/
alm->time.tm_sec = bcd2bin(buf[DS1305_SEC]);
alm->time.tm_min = bcd2bin(buf[DS1305_MIN]);
alm->time.tm_hour = bcd2hour(buf[DS1305_HOUR]);
alm->time.tm_mday = -1;
alm->time.tm_mon = -1;
alm->time.tm_year = -1;
/* next three fields are unused by Linux */
alm->time.tm_wday = -1;
alm->time.tm_mday = -1;
alm->time.tm_isdst = -1;
return 0;
}
开发者ID:openube,项目名称:android_kernel_sony_c2305,代码行数:58,代码来源:rtc-ds1305.c
示例4: eeprom_status
/* eeprom_status - read the status register */
char eeprom_status()
{
char byte;
EE_CS = 0; /* active eeprom */
spi_write_then_read(EE_RDSR); /* send read-status-register
instruction to the eeprom */
byte = spi_write_then_read(0);
EE_CS = 1; /* inactive eeprom */
return byte;
}
开发者ID:xwaynec,项目名称:eplab,代码行数:12,代码来源:eeprom.c
示例5: eeprom_read
/* eeprom_read - read single byte from specified address
* @addr: target address
*/
char eeprom_read(unsigned int addr)
{
char byte = 0;
while (eeprom_status() & 0x01) /* wait until write cycle done */
;
EE_CS = 0; /* active eeprom */
spi_write_then_read(EE_READ); /* read instruction */
spi_write_then_read(addr >> 8); /* higher byte of addr */
spi_write_then_read(addr & 0xff); /* lower byte */
byte = spi_write_then_read(0); /* read data */
EE_CS = 1; /* inactive eeprom */
return byte;
}
开发者ID:xwaynec,项目名称:eplab,代码行数:16,代码来源:eeprom.c
示例6: max6902_read_time
static int max6902_read_time(struct device *dev, struct rtc_time *dt)
{
int err, century;
struct spi_device *spi = to_spi_device(dev);
unsigned char buf[8];
buf[0] = 0xbf; /* Burst read */
err = spi_write_then_read(spi, buf, 1, buf, 8);
if (err != 0)
return err;
/* The chip sends data in this order:
* Seconds, Minutes, Hours, Date, Month, Day, Year */
dt->tm_sec = bcd2bin(buf[0]);
dt->tm_min = bcd2bin(buf[1]);
dt->tm_hour = bcd2bin(buf[2]);
dt->tm_mday = bcd2bin(buf[3]);
dt->tm_mon = bcd2bin(buf[4]) - 1;
dt->tm_wday = bcd2bin(buf[5]);
dt->tm_year = bcd2bin(buf[6]);
/* Read century */
err = max6902_get_reg(dev, MAX6902_REG_CENTURY, &buf[0]);
if (err != 0)
return err;
century = bcd2bin(buf[0]) * 100;
dt->tm_year += century;
dt->tm_year -= 1900;
return rtc_valid_tm(dt);
}
开发者ID:020gzh,项目名称:linux,代码行数:34,代码来源:rtc-max6902.c
示例7: ds1305_ioctl
/*
* Context: caller holds rtc->ops_lock (to protect ds1305->ctrl)
*/
static int ds1305_ioctl(struct device *dev, unsigned cmd, unsigned long arg)
{
struct ds1305 *ds1305 = dev_get_drvdata(dev);
u8 buf[2];
int status = -ENOIOCTLCMD;
buf[0] = DS1305_WRITE | DS1305_CONTROL;
buf[1] = ds1305->ctrl[0];
switch (cmd) {
case RTC_AIE_OFF:
status = 0;
if (!(buf[1] & DS1305_AEI0))
goto done;
buf[1] &= ~DS1305_AEI0;
break;
case RTC_AIE_ON:
status = 0;
if (ds1305->ctrl[0] & DS1305_AEI0)
goto done;
buf[1] |= DS1305_AEI0;
break;
}
if (status == 0) {
status = spi_write_then_read(ds1305->spi, buf, sizeof buf,
NULL, 0);
if (status >= 0)
ds1305->ctrl[0] = buf[1];
}
done:
return status;
}
开发者ID:325116067,项目名称:semc-qsd8x50,代码行数:37,代码来源:rtc-ds1305.c
示例8: rs5c348_rtc_set_time
static int
rs5c348_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct spi_device *spi = to_spi_device(dev);
struct rs5c348_plat_data *pdata = spi->dev.platform_data;
u8 txbuf[5+7], *txp;
int ret;
txp = txbuf;
txbuf[0] = RS5C348_CMD_R(RS5C348_REG_CTL2);
txbuf[1] = 0;
txbuf[2] = RS5C348_CMD_R(RS5C348_REG_CTL2);
txbuf[3] = 0;
txbuf[4] = RS5C348_CMD_MW(RS5C348_REG_SECS);
txp = &txbuf[5];
txp[RS5C348_REG_SECS] = bin2bcd(tm->tm_sec);
txp[RS5C348_REG_MINS] = bin2bcd(tm->tm_min);
if (pdata->rtc_24h) {
txp[RS5C348_REG_HOURS] = bin2bcd(tm->tm_hour);
} else {
txp[RS5C348_REG_HOURS] = bin2bcd((tm->tm_hour + 11) % 12 + 1) |
(tm->tm_hour >= 12 ? RS5C348_BIT_PM : 0);
}
txp[RS5C348_REG_WDAY] = bin2bcd(tm->tm_wday);
txp[RS5C348_REG_DAY] = bin2bcd(tm->tm_mday);
txp[RS5C348_REG_MONTH] = bin2bcd(tm->tm_mon + 1) |
(tm->tm_year >= 100 ? RS5C348_BIT_Y2K : 0);
txp[RS5C348_REG_YEAR] = bin2bcd(tm->tm_year % 100);
ret = spi_write_then_read(spi, txbuf, sizeof(txbuf), NULL, 0);
udelay(62);
return ret;
}
开发者ID:DirtyDroidX,项目名称:android_kernel_htc_m8ul,代码行数:35,代码来源:rtc-rs5c348.c
示例9: adt7316_spi_multi_read
static int adt7316_spi_multi_read(void *client, u8 reg, u8 count, u8 *data)
{
struct spi_device *spi_dev = client;
u8 cmd[2];
int ret = 0;
if (count > ADT7316_REG_MAX_ADDR)
count = ADT7316_REG_MAX_ADDR;
cmd[0] = ADT7316_SPI_CMD_WRITE;
cmd[1] = reg;
ret = spi_write(spi_dev, cmd, 2);
if (ret < 0) {
dev_err(&spi_dev->dev, "SPI fail to select reg\n");
return ret;
}
cmd[0] = ADT7316_SPI_CMD_READ;
ret = spi_write_then_read(spi_dev, cmd, 1, data, count);
if (ret < 0) {
dev_err(&spi_dev->dev, "SPI read data error\n");
return ret;
}
return 0;
}
开发者ID:AD5GB,项目名称:kernel_n5_3.10-experimental,代码行数:28,代码来源:adt7316-spi.c
示例10: ds1302_rtc_get_time
static int ds1302_rtc_get_time(struct device *dev, struct rtc_time *time)
{
struct spi_device *spi = dev_get_drvdata(dev);
u8 addr = RTC_CLCK_BURST << 1 | RTC_CMD_READ;
u8 buf[RTC_CLCK_LEN - 1];
int status;
/* Use write-then-read to get all the date/time registers
* since dma from stack is nonportable
*/
status = spi_write_then_read(spi, &addr, sizeof(addr),
buf, sizeof(buf));
if (status < 0)
return status;
/* Decode the registers */
time->tm_sec = bcd2bin(buf[RTC_ADDR_SEC]);
time->tm_min = bcd2bin(buf[RTC_ADDR_MIN]);
time->tm_hour = bcd2bin(buf[RTC_ADDR_HOUR]);
time->tm_wday = buf[RTC_ADDR_DAY] - 1;
time->tm_mday = bcd2bin(buf[RTC_ADDR_DATE]);
time->tm_mon = bcd2bin(buf[RTC_ADDR_MON]) - 1;
time->tm_year = bcd2bin(buf[RTC_ADDR_YEAR]) + 100;
/* Time may not be set */
return rtc_valid_tm(time);
}
开发者ID:513855417,项目名称:linux,代码行数:27,代码来源:rtc-ds1302.c
示例11: pcf2123_rtc_read_time
static int pcf2123_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct spi_device *spi = to_spi_device(dev);
u8 txbuf[1], rxbuf[7];
int ret;
txbuf[0] = PCF2123_READ | PCF2123_REG_SC;
ret = spi_write_then_read(spi, txbuf, sizeof(txbuf),
rxbuf, sizeof(rxbuf));
if (ret < 0)
return ret;
pcf2123_delay_trec();
tm->tm_sec = bcd2bin(rxbuf[0] & 0x7F);
tm->tm_min = bcd2bin(rxbuf[1] & 0x7F);
tm->tm_hour = bcd2bin(rxbuf[2] & 0x3F); /* rtc hr 0-23 */
tm->tm_mday = bcd2bin(rxbuf[3] & 0x3F);
tm->tm_wday = rxbuf[4] & 0x07;
tm->tm_mon = bcd2bin(rxbuf[5] & 0x1F) - 1; /* rtc mn 1-12 */
tm->tm_year = bcd2bin(rxbuf[6]);
if (tm->tm_year < 70)
tm->tm_year += 100; /* assume we are in 1970...2069 */
dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
"mday=%d, mon=%d, year=%d, wday=%d\n",
__func__,
tm->tm_sec, tm->tm_min, tm->tm_hour,
tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
return rtc_valid_tm(tm);
}
开发者ID:DenisLug,项目名称:mptcp,代码行数:31,代码来源:rtc-pcf2123.c
示例12: aic32x4_read
static unsigned int aic32x4_read(struct snd_soc_codec *codec, unsigned int reg)
{
struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec);
unsigned int page = reg / 128;
unsigned int fixed_reg = reg % 128;
int ret;
u8 buffer;
if (aic32x4->page_no != page) {
ret = aic32x4_change_page(codec, page);
if (ret != 0)
return ret;
}
if (aic32x4->control_type == SND_SOC_SPI) {
buffer = (fixed_reg<<1) | 0x01;
ret = spi_write_then_read(codec->control_data, &buffer, 1, &buffer, 1);
if (ret) {
dev_err(codec->dev, "AIC32x4 reg read error\n");
return -EIO;
}
return (unsigned int)buffer;
} else
return i2c_smbus_read_byte_data(codec->control_data, fixed_reg & 0xff);
}
开发者ID:darcyg,项目名称:ap_project_v2,代码行数:25,代码来源:tlv320aic32x4.c
示例13: rf_send
/* radio_send - send payload to specified address
* @*addr: receiver's address
* @addr_len: receiver's address length (in bytes)
* @*payload: payload to receiver
* @pl_len: payload to receiver length (in bytes)
*/
void rf_send(char *addr, unsigned char addr_len,
char *payload, unsigned char pl_len)
{
unsigned char i;
CE = 1; /* enter transmit mode */
/* send address */
for (i = 0; i < addr_len; i++)
spi_write_then_read(*(addr + i));
/* send payload */
for (i = 0; i < pl_len; i++)
spi_write_then_read(*(payload + i));
CE = 0; /* back to standby mode */
}
开发者ID:xwaynec,项目名称:eplab,代码行数:22,代码来源:rf.c
示例14: cxd2880_spi_read_ts_buffer_info
static int cxd2880_spi_read_ts_buffer_info(struct spi_device *spi,
struct cxd2880_ts_buf_info *info)
{
u8 send_data = 0x20;
u8 recv_data[2];
int ret;
if (!spi || !info) {
pr_err("invalid arg\n");
return -EINVAL;
}
ret = spi_write_then_read(spi, &send_data, 1,
recv_data, sizeof(recv_data));
if (ret)
pr_err("spi_write_then_read failed\n");
info->read_ready = (recv_data[0] & 0x80) ? 1 : 0;
info->almost_full = (recv_data[0] & 0x40) ? 1 : 0;
info->almost_empty = (recv_data[0] & 0x20) ? 1 : 0;
info->overflow = (recv_data[0] & 0x10) ? 1 : 0;
info->underflow = (recv_data[0] & 0x08) ? 1 : 0;
info->pkt_num = ((recv_data[0] & 0x07) << 8) | recv_data[1];
return ret;
}
开发者ID:Anjali05,项目名称:linux,代码行数:26,代码来源:cxd2880-spi.c
示例15: qtft_spi_write_then_read
int qtft_spi_write_then_read(const void *tbuf, size_t tn, void *rbuf, size_t rn)
{
if(current_device)
return spi_write_then_read(current_device, tbuf, tn, rbuf, rn);
else
return -ENODEV;
}
开发者ID:dujiepeng,项目名称:module,代码行数:7,代码来源:qtft_spi.c
示例16: ad9363_spi_write
/*----------------------------------------------------------------------------
* name : ad9363_spi_write
* function : ad9363 spi write interface
* author version date note
* feller 1.0 20151229
*----------------------------------------------------------------------------
*/
int ad9363_spi_write(struct spi_device *spi, unsigned short reg, unsigned char val)
{
unsigned char buf[3];
int ret;
unsigned short cmd;
cmd = AD9363_WRITE |(reg);
buf[0] = cmd >> 8;
buf[1] = cmd & 0xFF;
buf[2] = val;
ret = spi_write_then_read(spi, buf, 3, NULL, 0);
if (ret < 0) {
dev_err(&spi->dev, "Write Error %d", ret);
return ret;
}
dev_dbg(&spi->dev, "reg 0x%X val 0x%X\n", reg, buf[2]);
return 0;
}
开发者ID:shenbokeji,项目名称:SinoMT,代码行数:32,代码来源:ad9363.c
示例17: ds1390_read_time
static int ds1390_read_time(struct device *dev, struct rtc_time *dt)
{
struct spi_device *spi = to_spi_device(dev);
struct ds1390 *chip = dev_get_drvdata(dev);
int status;
/* build the message */
chip->txrx_buf[0] = DS1390_REG_SECONDS;
/* do the i/o */
status = spi_write_then_read(spi, chip->txrx_buf, 1, chip->txrx_buf, 8);
if (status != 0)
return status;
/* The chip sends data in this order:
* Seconds, Minutes, Hours, Day, Date, Month / Century, Year */
dt->tm_sec = bcd2bin(chip->txrx_buf[0]);
dt->tm_min = bcd2bin(chip->txrx_buf[1]);
dt->tm_hour = bcd2bin(chip->txrx_buf[2]);
dt->tm_wday = bcd2bin(chip->txrx_buf[3]);
dt->tm_mday = bcd2bin(chip->txrx_buf[4]);
/* mask off century bit */
dt->tm_mon = bcd2bin(chip->txrx_buf[5] & 0x7f) - 1;
/* adjust for century bit */
dt->tm_year = bcd2bin(chip->txrx_buf[6]) + ((chip->txrx_buf[5] & 0x80) ? 100 : 0);
return rtc_valid_tm(dt);
}
开发者ID:AD5GB,项目名称:kernel_n5_3.10-experimental,代码行数:28,代码来源:rtc-ds1390.c
示例18: ms5611_spi_reset
static int ms5611_spi_reset(struct device *dev)
{
u8 cmd = MS5611_RESET;
struct ms5611_state *st = iio_priv(dev_to_iio_dev(dev));
return spi_write_then_read(st->client, &cmd, 1, NULL, 0);
}
开发者ID:AlexShiLucky,项目名称:linux,代码行数:7,代码来源:ms5611_spi.c
示例19: codec_spi_read
static int codec_spi_read(unsigned char addr, unsigned char *data, bool flag)
{
int rc;
u8 buffer[2] = { 0, 0 };
u8 result[2] = { 0, 0 };
codec_spi_dev->bits_per_word = 16;
buffer[1] = addr << 1 | 1; /* high byte because 16bit word */
/*AUD_DBG("before read: buf[1]:0x%02X buf[0]:0x%02X res[1]:0x%02X res[0]:0x%02X \n",
buffer[1], buffer[0], result[1], result[0]);*/
/* because aic3008 does symmetric SPI write and read */
rc = spi_write_then_read(codec_spi_dev, buffer, 2, result, 2);
if (rc < 0)
return rc;
if(flag)
{
AUD_DBG("read: reg: 0x%02X , data: 0x%02X \n", addr, result[0]);
}
*data = result[0]; /* seems address on high byte, data on low byte */
return 0;
}
开发者ID:chriscpritchard,项目名称:android_kernel_htc_endeavor,代码行数:25,代码来源:tlv320aic3008.c
示例20: ds1305_alarm_irq_enable
static int ds1305_alarm_irq_enable(struct device *dev, unsigned int enabled)
{
struct ds1305 *ds1305 = dev_get_drvdata(dev);
u8 buf[2];
long err = -EINVAL;
buf[0] = DS1305_WRITE | DS1305_CONTROL;
buf[1] = ds1305->ctrl[0];
if (enabled) {
if (ds1305->ctrl[0] & DS1305_AEI0)
goto done;
buf[1] |= DS1305_AEI0;
} else {
if (!(buf[1] & DS1305_AEI0))
goto done;
buf[1] &= ~DS1305_AEI0;
}
err = spi_write_then_read(ds1305->spi, buf, sizeof buf, NULL, 0);
if (err >= 0)
ds1305->ctrl[0] = buf[1];
done:
return err;
}
开发者ID:openube,项目名称:android_kernel_sony_c2305,代码行数:25,代码来源:rtc-ds1305.c
注:本文中的spi_write_then_read函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论