/* Write a value to an 8 bit register in the LIS3DH.  */
static int lis3dh_write_reg(const lis3dh_t *dev, const lis3dh_reg_t reg, const uint8_t value)
/* Write a value to an 8 bit register in the LIS3DH.  */
static int lis3dh_write_reg(const lis3dh_t *dev, const lis3dh_reg_t reg, const uint8_t value)
{
    uint8_t addr = (reg & LIS3DH_SPI_ADDRESS_MASK) | LIS3DH_SPI_WRITE_MASK | LIS3DH_SPI_SINGLE_MASK;
    spi_acquire(dev->spi);
    gpio_clear(dev->cs);
    if (spi_transfer_reg(dev->spi, addr, value, NULL) < 0) {
        gpio_set(dev->cs);
        spi_release(dev->spi);
        return -1;
    }
    gpio_set(dev->cs);
    spi_release(dev->spi);
    return 0;
}