#ifndef LDC1612_H
#define LDC1612_H

#include <stdbool.h>
#include <stdint.h>

#include "stm32g0xx_hal.h"

/* ADDR is tied to GND, therefore the 7-bit I2C address is 0x2A. */
#define LDC1612_ADDRESS 0x2AU

/* Only registers used by this bring-up test are listed. Addresses come from
   data sheet table 13; keeping them here makes every access visible. */
enum {
  LDC1612_REG_DATA0_MSB = 0x00,
  LDC1612_REG_DATA0_LSB = 0x01,
  LDC1612_REG_RCOUNT0 = 0x08,
  LDC1612_REG_SETTLECOUNT0 = 0x10,
  LDC1612_REG_CLOCK_DIVIDERS0 = 0x14,
  LDC1612_REG_STATUS = 0x18,
  LDC1612_REG_ERROR_CONFIG = 0x19,
  LDC1612_REG_CONFIG = 0x1A,
  LDC1612_REG_MUX_CONFIG = 0x1B,
  LDC1612_REG_RESET_DEV = 0x1C,
  LDC1612_REG_DRIVE_CURRENT0 = 0x1E,
  LDC1612_REG_MANUFACTURER_ID = 0x7E,
  LDC1612_REG_DEVICE_ID = 0x7F,
};

HAL_StatusTypeDef ldc1612_write_register(
    I2C_HandleTypeDef *i2c,
    uint8_t reg,
    uint16_t value);

HAL_StatusTypeDef ldc1612_read_register(
    I2C_HandleTypeDef *i2c,
    uint8_t reg,
    uint16_t *value);

uint32_t ldc1612_spurious_berr_count(void);

#endif
