bitters13
  • master
  • v0.9
  • v0.9.6
  • v1.0.0
      Bitters
      Bitters

      Bitters makes it easy to port vendor driver to Raspberry PI user space.

      It provide access to linux GPIO, SPI, and I2C using the same kind of API that can be found for micro-controller. It relies on linux ioctl for portability and performance (no devmem, no sysfs).

      Below a short example of toggling a reset-pin and performing an SPI transfer.

      example.c
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      
      #include "bitters.h"
      #include "bitters/rpi.h"
      #include "bitters/gpio.h"
      #include "bitters/spi.h"
      
      int main() {
        /* Device configuration (GPIO/SPI)*/
        struct bitters_gpio_cfg reset_cfg  = { .dir       = BITTERS_GPIO_DIR_OUT,
                                               .defval    = 1,
                                               .label     = "reset",              };
      
        struct bitters_spi_cfg spi0_cfg    = { .mode      = BITTERS_SPI_MODE_0,
                                               .transfert = BITTERS_SPI_TRANSFERT_MSB,
                                               .word      = BITTERS_SPI_WORDSIZE(8),
                                               .speed     =  3000000,             };
      
        /* Get device handler */
        bitters_gpio_pin_t reset = BITTERS_GPIO_PIN_INITIALIZER(BITTERS_RPI_GPIO_CHIP,
                                                                BITTERS_RPI_P1_15);
        bitters_spi_t spi0       = BITTERS_SPI_INITIALIZER(BITTERS_RPI_SPI0, 0);
      
        /* Initialise library and enable devices */
        bitters_init();
        bitters_gpio_pin_enable(&reset , &reset_cfg);
        bitters_spi_enable(&spi0, &spi0_cfg);
      
        /* Send a reset pulse */
        bitters_gpio_pin_write(&reset, 1);
        bitters_delay_us(100);
        bitters_gpio_pin_write(&reset, 0);
        
        /* Perform SPI transfert */
        uint8_t data[8];
        const struct bitters_spi_transfert xfr[] = {
          { .tx = "cmd", .len = 3            },
          { .rx = data,  .len = sizeof(data) }
        };
        bitters_spi_transfert(spi->dev, xfr, 2);
      
        return 0;
      }