Exemple #1
0
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;
}
Exemple #2
0
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;
}
Exemple #3
0
void cmd_init_slave(int argc, char **argv)
{
    int res;
    spi_master = -1;
    if (parse_spi_dev(argc, argv) < 0) {
        return;
    }
    res = spi_init_slave(spi_dev, spi_mode, slave_on_data);
    if (res < 0) {
        printf("spi_init_slave: error initializing SPI_%i device (code: %i)\n", spi_dev, res);
    }
    res = gpio_init_int(spi_cs, GPIO_NOPULL, GPIO_FALLING, slave_on_cs, 0);
    if (res < 0){
        printf("gpio_init_int: error initializing GPIO_%i as CS line (code %i)\n", spi_cs, res);
    }
    spi_master = 0;
    printf("SPI_%i successfully initialized as slave, cs: GPIO_%i, mode: %i\n",
            spi_dev, spi_cs, spi_mode);
    return;
}
Exemple #4
0
void cmd_init_master(int argc, char **argv)
{
    int res;
    spi_master = -1;
    if (parse_spi_dev(argc, argv) < 0) {
        return;
    }
    res = spi_init_master(spi_dev, spi_mode, spi_speed);
    if (res < 0) {
        printf("spi_init_master: error initializing SPI_%i device (code %i)\n", spi_dev, res);
    }
    res = gpio_init_out(spi_cs, GPIO_PULLUP);
    if (res < 0){
        printf("gpio_init_out: error initializing GPIO_%i as CS line (code %i)\n", spi_cs, res);
    }
    gpio_set(spi_cs);
    spi_master = 1;
    printf("SPI_%i successfully initialized as master, cs: GPIO_%i, mode: %i, speed: %i\n",
            spi_dev, spi_cs, spi_mode, spi_speed);
    return;
}