• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ spi_acquire函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中spi_acquire函数的典型用法代码示例。如果您正苦于以下问题:C++ spi_acquire函数的具体用法?C++ spi_acquire怎么用?C++ spi_acquire使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了spi_acquire函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: lis3dh_read_xyz

int lis3dh_read_xyz(const lis3dh_t *dev, lis3dh_data_t *acc_data)
{
    uint8_t i;
    /* Set READ MULTIPLE mode */
    static const uint8_t addr = (LIS3DH_REG_OUT_X_L | LIS3DH_SPI_READ_MASK | LIS3DH_SPI_MULTI_MASK);

    /* Acquire exclusive access to the bus. */
    spi_acquire(dev->spi);
    /* Perform the transaction */
    gpio_clear(dev->cs);

    if (spi_transfer_regs(dev->spi, addr, NULL, (char *)acc_data,
                          sizeof(lis3dh_data_t)) != sizeof(lis3dh_data_t)) {
        /* Transfer error */
        gpio_set(dev->cs);
        /* Release the bus for other threads. */
        spi_release(dev->spi);
        return -1;
    }

    gpio_set(dev->cs);
    /* Release the bus for other threads. */
    spi_release(dev->spi);

    /* Scale to milli-G */
    for (i = 0; i < 3; ++i) {
        int32_t tmp = (int32_t)(((int16_t *)acc_data)[i]);
        tmp *= dev->scale;
        tmp /= 32768;
        (((int16_t *)acc_data)[i]) = (int16_t)tmp;
    }

    return 0;
}
开发者ID:4dahalibut,项目名称:RIOT,代码行数:34,代码来源:lis3dh.c


示例2: lis3dh_read_regs

/**
 * @brief Read sequential registers from the LIS3DH.
 *
 * @param[in]  dev          Device descriptor
 * @param[in]  reg          The source register starting address
 * @param[in]  len          Number of bytes to read
 * @param[out] buf          The values of the source registers will be written here
 *
 * @return                  0 on success
 * @return                  -1 on error
 */
static int lis3dh_read_regs(const lis3dh_t *dev, const lis3dh_reg_t reg, const uint8_t len,
                            uint8_t *buf)
{
    /* Set READ MULTIPLE mode */
    uint8_t addr = (reg & LIS3DH_SPI_ADDRESS_MASK) | LIS3DH_SPI_READ_MASK | LIS3DH_SPI_MULTI_MASK;

    /* Acquire exclusive access to the bus. */
    spi_acquire(dev->spi);
    /* Perform the transaction */
    gpio_clear(dev->cs);

    if (spi_transfer_regs(dev->spi, addr, NULL, (char *)buf, len) < 0) {
        /* Transfer error */
        gpio_set(dev->cs);
        /* Release the bus for other threads. */
        spi_release(dev->spi);
        return -1;
    }

    gpio_set(dev->cs);
    /* Release the bus for other threads. */
    spi_release(dev->spi);

    return 0;
}
开发者ID:4dahalibut,项目名称:RIOT,代码行数:36,代码来源:lis3dh.c


示例3: kw2xrf_spi_transfer_head

void kw2xrf_spi_transfer_head(void)
{
#if KW2XRF_SHARED_SPI
    spi_acquire(kw2xrf_spi);
    gpio_clear(kw2xrf_cs_pin);
#endif
}
开发者ID:anishkt,项目名称:RIOT,代码行数:7,代码来源:kw2xrf_spi.c


示例4: kw2xrf_spi_init

int kw2xrf_spi_init(spi_t spi, spi_speed_t spi_speed,
                    gpio_t cs_pin)
{
    int res;
    kw2xrf_cs_pin = cs_pin;     /**< for later reference */
    kw2xrf_spi = spi;

#if KW2XRF_SHARED_SPI
    spi_acquire(kw2xrf_spi);
#endif
    res = spi_init_master(kw2xrf_spi, SPI_CONF_FIRST_RISING, spi_speed);
#if KW2XRF_SHARED_SPI
    spi_release(kw2xrf_spi);
    gpio_init_out(kw2xrf_cs_pin, GPIO_NOPULL);
    gpio_set(kw2xrf_cs_pin);
#endif

    if (res < 0) {
        DEBUG("kw2xrf_spi_init: error initializing SPI_%i device (code %i)\n",
              kw2xrf_spi, res);
        return -1;
    }

    return 0;
}
开发者ID:anishkt,项目名称:RIOT,代码行数:25,代码来源:kw2xrf_spi.c


示例5: cmd_init_master

int cmd_init_master(int argc, char **argv)
{
    int res;
    spi_master = -1;
    if (parse_spi_dev(argc, argv) < 0) {
        return 1;
    }
    spi_acquire(spi_dev);
    res = spi_init_master(spi_dev, spi_mode, spi_speed);
    spi_release(spi_dev);
    if (res < 0) {
        printf("spi_init_master: error initializing SPI_%i device (code %i)\n",
                spi_dev, res);
        return 1;
    }
    res = gpio_init(spi_cs, GPIO_OUT);
    if (res < 0){
        printf("gpio_init: error initializing GPIO_%ld as CS line (code %i)\n",
                (long)spi_cs, res);
        return 1;
    }
    gpio_set(spi_cs);
    spi_master = 1;
    printf("SPI_%i successfully initialized as master, cs: GPIO_%ld, mode: %i, speed: %i\n",
            spi_dev, (long)spi_cs, spi_mode, spi_speed);
    return 0;
}
开发者ID:AdamRLukaitis,项目名称:RIOT,代码行数:27,代码来源:main.c


示例6: cmd_init_slave

int cmd_init_slave(int argc, char **argv)
{
    int res;
    spi_master = -1;
    if (parse_spi_dev(argc, argv) < 0) {
        return 1;
    }
    spi_acquire(spi_dev);
    res = spi_init_slave(spi_dev, spi_mode, slave_on_data);
    spi_release(spi_dev);
    if (res < 0) {
        printf("spi_init_slave: error initializing SPI_%i device (code: %i)\n",
                spi_dev, res);
        return 1;
    }
    res = gpio_init_int(spi_cs, GPIO_IN, GPIO_FALLING, slave_on_cs, 0);
    if (res < 0){
        printf("gpio_init_int: error initializing GPIO_%ld as CS line (code %i)\n",
                (long)spi_cs, res);
        return 1;
    }
    spi_master = 0;
    printf("SPI_%i successfully initialized as slave, cs: GPIO_%ld, mode: %i\n",
            spi_dev, (long)spi_cs, spi_mode);
    return 0;
}
开发者ID:AdamRLukaitis,项目名称:RIOT,代码行数:26,代码来源:main.c


示例7: cmd

static void cmd(encx24j600_t *dev, char cmd) {
    spi_acquire(dev->spi);
    gpio_clear(dev->cs);
    spi_transfer_byte(dev->spi, cmd, NULL);
    gpio_set(dev->cs);
    spi_release(dev->spi);
}
开发者ID:WilsonWangTHU,项目名称:RIOT,代码行数:7,代码来源:encx24j600.c


示例8: nvram_spi_read_9bit_addr

static int nvram_spi_read_9bit_addr(nvram_t *dev, uint8_t *dst, uint32_t src, size_t len)
{
    nvram_spi_params_t *spi_dev = (nvram_spi_params_t *) dev->extra;
    int status;
    uint8_t cmd;
    uint8_t addr;
    cmd = NVRAM_SPI_CMD_READ;
    /* The upper address bit is mixed into the command byte on certain devices,
     * probably just to save a byte in the SPI transfer protocol. */
    if (src > 0xff) {
        cmd |= 0x08;
    }
    /* LSB of address */
    addr = (src & 0xff);
    spi_acquire(spi_dev->spi);
    gpio_clear(spi_dev->cs);
    /* Write command and address */
    status = spi_transfer_reg(spi_dev->spi, (char)cmd, addr, NULL);
    if (status < 0)
    {
        return status;
    }
    /* Keep holding CS and read data */
    status = spi_transfer_bytes(spi_dev->spi, NULL, (char *)dst, len);
    if (status < 0)
    {
        return status;
    }
    gpio_set(spi_dev->cs);
    spi_release(spi_dev->spi);
    /* status contains the number of bytes actually read from the SPI bus. */
    return status;
}
开发者ID:AdamRLukaitis,项目名称:RIOT,代码行数:33,代码来源:nvram-spi.c


示例9: u8x8_byte_riotos_hw_spi

uint8_t u8x8_byte_riotos_hw_spi(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
    spi_t dev = (spi_t) u8g2->dev;

    switch (msg) {
        case U8X8_MSG_BYTE_SEND:
            spi_transfer_bytes(dev, GPIO_UNDEF, true,
                               arg_ptr, NULL, (size_t)arg_int);
            break;
        case U8X8_MSG_BYTE_INIT:
            spi_init_pins(dev);
            break;
        case U8X8_MSG_BYTE_SET_DC:
            u8x8_gpio_SetDC(u8g2, arg_int);
            break;
        case U8X8_MSG_BYTE_START_TRANSFER:
            spi_acquire(dev, GPIO_UNDEF,
                        u8x8_spi_mode_to_spi_conf(u8g2->display_info->spi_mode),
                        u8x8_pulse_width_to_spi_speed(u8g2->display_info->sck_pulse_width_ns));

            u8x8_gpio_SetCS(u8g2, u8g2->display_info->chip_enable_level);
            u8g2->gpio_and_delay_cb(u8g2, U8X8_MSG_DELAY_NANO, u8g2->display_info->post_chip_enable_wait_ns, NULL);
            break;
        case U8X8_MSG_BYTE_END_TRANSFER:
            u8g2->gpio_and_delay_cb(u8g2, U8X8_MSG_DELAY_NANO, u8g2->display_info->pre_chip_disable_wait_ns, NULL);
            u8x8_gpio_SetCS(u8g2, u8g2->display_info->chip_disable_level);

            spi_release(dev);
            break;
        default:
            return 0;
    }

    return 1;
}
开发者ID:MichelRottleuthner,项目名称:RIOT,代码行数:35,代码来源:u8g2_riotos.c


示例10: cmdn

static void cmdn(encx24j600_t *dev, uint8_t cmd, char *out, char *in, int len) {
    spi_acquire(dev->spi);
    gpio_clear(dev->cs);
    spi_transfer_byte(dev->spi, cmd, NULL);
    spi_transfer_bytes(dev->spi, out, in, len);
    gpio_set(dev->cs);
    spi_release(dev->spi);
}
开发者ID:WilsonWangTHU,项目名称:RIOT,代码行数:8,代码来源:encx24j600.c


示例11: at86rf2xx_fb_start

void at86rf2xx_fb_start(const at86rf2xx_t *dev)
{
    spi_acquire(dev->spi);
    gpio_clear(dev->cs_pin);
    spi_transfer_byte(dev->spi,
                      AT86RF2XX_ACCESS_FB | AT86RF2XX_ACCESS_READ,
                      NULL);
}
开发者ID:biddyweb,项目名称:RIOT,代码行数:8,代码来源:at86rf2xx_internal.c


示例12: enc_spi_transfer

static inline void enc_spi_transfer(encx24j600_t *dev, char *out, char *in, int len)
{
    spi_acquire(dev->spi);
    gpio_clear(dev->cs);
    spi_transfer_bytes(dev->spi, out, in, len);
    gpio_set(dev->cs);
    spi_release(dev->spi);
}
开发者ID:WilsonWangTHU,项目名称:RIOT,代码行数:8,代码来源:encx24j600.c


示例13: cc2420_reg_read

uint16_t cc2420_reg_read(const cc2420_t *dev, const uint8_t addr)
{
    network_uint16_t tmp;

    spi_acquire(SPI_BUS, SPI_CS, SPI_MODE, SPI_CLK);
    spi_transfer_regs(SPI_BUS, SPI_CS, (CC2420_REG_READ | addr),NULL, &tmp, 2);
    spi_release(SPI_BUS);

    return byteorder_ntohs(tmp);
}
开发者ID:A-Paul,项目名称:RIOT,代码行数:10,代码来源:cc2420_internal.c


示例14: cc2420_reg_write

void cc2420_reg_write(const cc2420_t *dev,
                      const uint8_t addr,
                      const uint16_t value)
{
    uint16_t tmp = byteorder_htons(value).u16;

    spi_acquire(SPI_BUS, SPI_CS, SPI_MODE, SPI_CLK);
    spi_transfer_regs(SPI_BUS, SPI_CS, (CC2420_REG_WRITE | addr), &tmp, NULL, 2);
    spi_release(SPI_BUS);
}
开发者ID:A-Paul,项目名称:RIOT,代码行数:10,代码来源:cc2420_internal.c


示例15: ds3234_write_reg

/**
 * @brief Write a register value to the sensor
 *
 * @param[in]  dev    device descriptor
 * @param[in]  addr   register address
 * @param[in]  len    register size
 * @param[in]  buf    source buffer
 */
static void ds3234_write_reg(const ds3234_params_t *dev, uint8_t addr, size_t len, const uint8_t *buf)
{
    uint8_t command = DS3234_CMD_WRITE | addr;
    /* Acquire exclusive access to the bus. */
    spi_acquire(dev->spi, dev->cs, SPI_MODE_3, dev->clk);
    /* Perform the transaction */
    spi_transfer_regs(dev->spi, dev->cs, command, buf, NULL, len);
    /* Release the bus for other threads. */
    spi_release(dev->spi);
}
开发者ID:A-Paul,项目名称:RIOT,代码行数:18,代码来源:ds3234.c


示例16: cc2420_strobe

uint8_t cc2420_strobe(const cc2420_t *dev, const uint8_t command)
{
    uint8_t res;

    spi_acquire(SPI_BUS, SPI_CS, SPI_MODE, SPI_CLK);
    res = spi_transfer_byte(SPI_BUS, SPI_CS, false, command);
    spi_release(SPI_BUS);

    return res;
}
开发者ID:A-Paul,项目名称:RIOT,代码行数:10,代码来源:cc2420_internal.c


示例17: _write

static void _write(pcd8544_t *dev, uint8_t is_data, char data)
{
    /* set command or data mode */
    gpio_write(dev->mode, is_data);
    /* write byte to LCD */
    spi_acquire(dev->spi);
    gpio_clear(dev->cs);
    spi_transfer_byte(dev->spi, data, 0);
    gpio_set(dev->cs);
    spi_release(dev->spi);
}
开发者ID:Alex-Gramm,项目名称:RIOT,代码行数:11,代码来源:pcd8544.c


示例18: cc110x_writeburst_reg

void cc110x_writeburst_reg(uint8_t addr, char *src, uint8_t count)
{
    unsigned int cpsr;
    spi_acquire(CC110X_SPI);
    cpsr = disableIRQ();
    cc110x_cs();
    spi_transfer_regs(CC110X_SPI, addr | CC1100_WRITE_BURST, src, 0, count);
    gpio_set(CC110X_CS);
    restoreIRQ(cpsr);
    spi_release(CC110X_SPI);
}
开发者ID:Alex-Gramm,项目名称:RIOT,代码行数:11,代码来源:cc110x-spi.c


示例19: cc110x_write_reg

void cc110x_write_reg(uint8_t addr, uint8_t value)
{
    unsigned int cpsr;
    spi_acquire(CC110X_SPI);
    cpsr = disableIRQ();
    cc110x_cs();
    spi_transfer_reg(CC110X_SPI, addr, value, 0);
    gpio_set(CC110X_CS);
    restoreIRQ(cpsr);
    spi_release(CC110X_SPI);
}
开发者ID:Alex-Gramm,项目名称:RIOT,代码行数:11,代码来源:cc110x-spi.c


示例20: cc110x_write_reg

void cc110x_write_reg(cc110x_t *dev, uint8_t addr, uint8_t value)
{
    unsigned int cpsr;
    spi_acquire(dev->params.spi);
    cpsr = disableIRQ();
    cc110x_cs(dev);
    spi_transfer_reg(dev->params.spi, addr, value, 0);
    gpio_set(dev->params.cs);
    restoreIRQ(cpsr);
    spi_release(dev->params.spi);
}
开发者ID:JMR-b,项目名称:RIOT,代码行数:11,代码来源:cc110x-spi.c



注:本文中的spi_acquire函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ spi_bitbang_stop函数代码示例发布时间:2022-05-30
下一篇:
C++ spiWrite函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap