39#ifdef PREINIT_SUPPORTED
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_analog_in.h"
52#include "drv_i2c_master.h"
74#define USBCSINK2_CMD_SRCPDO 0x00
75#define USBCSINK2_CMD_PDONUM 0x1C
76#define USBCSINK2_CMD_STATUS 0x1D
77#define USBCSINK2_CMD_MASK 0x1E
78#define USBCSINK2_CMD_VOLTAGE 0x20
79#define USBCSINK2_CMD_CURRENT 0x21
80#define USBCSINK2_CMD_TEMP 0x22
81#define USBCSINK2_CMD_OCPTHR 0x23
82#define USBCSINK2_CMD_OTPTHR 0x24
83#define USBCSINK2_CMD_DRTHR 0x25
84#define USBCSINK2_CMD_TR25 0x28
85#define USBCSINK2_CMD_TR50 0x2A
86#define USBCSINK2_CMD_TR75 0x2C
87#define USBCSINK2_CMD_TR100 0x2E
88#define USBCSINK2_CMD_RDO 0x30
106#define USBCSINK2_SRCPDO_LENGTH 28
107#define USBCSINK2_RDO_LENGTH 4
113#define USBCSINK2_RDO_REQ_SUCCESS 0x03
119#define USBCSINK2_SENS_VTG_MV 80.0f
120#define USBCSINK2_SENS_CURRENT_MA 24.0f
126#define USBCSINK2_ADC_RESOLUTION 0x0FFF
127#define USBCSINK2_VREF_3V3 3.3
128#define USBCSINK2_VREF_5V 5.0
135#define USBCSINK2_SET_DEV_ADDR 0x51
153#define USBCSINK2_MAP_MIKROBUS( cfg, mikrobus ) \
154 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
155 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
156 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
157 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
177 uint8_t pdo_data[ 28 ];
err_t usbcsink2_read_status(usbcsink2_t *ctx, uint8_t *status)
USB-C Sink 2 status reading function.
err_t usbcsink2_get_temperature(usbcsink2_t *ctx, uint8_t *temperature)
USB-C Sink 2 get the temperature function.
void usbcsink2_cfg_setup(usbcsink2_cfg_t *cfg)
USB-C Sink 2 configuration object setup function.
err_t usbcsink2_read_raw_adc(usbcsink2_t *ctx, uint16_t *raw_adc)
USB-C Sink 2 read raw ADC value function.
err_t usbcsink2_set_vref(usbcsink2_t *ctx, float vref)
USB-C Sink 2 set vref function.
err_t usbcsink2_get_pdo_current(usbcsink2_t *ctx, float *current_ma)
USB-C Sink 2 get the current function.
err_t usbcsink2_write_rdo(usbcsink2_t *ctx, uint8_t *rdo)
USB-C Sink 2 write the RDO function.
err_t usbcsink2_read_voltage(usbcsink2_t *ctx, float *voltage)
USB-C Sink 2 read voltage level function.
err_t usbcsink2_read_pdo(usbcsink2_t *ctx, uint8_t *pdo)
USB-C Sink 2 PDO data reading function.
err_t usbcsink2_get_pdo_num(usbcsink2_t *ctx, uint8_t *pdo_num)
USB-C Sink 2 PDO number reading function.
err_t usbcsink2_default_cfg(usbcsink2_t *ctx)
USB-C Sink 2 default configuration function.
err_t usbcsink2_reset(usbcsink2_t *ctx)
USB-C Sink 2 hard reset the RDO function.
err_t usbcsink2_init(usbcsink2_t *ctx, usbcsink2_cfg_t *cfg)
USB-C Sink 2 initialization function.
err_t usbcsink2_wait_rdo_req_success(usbcsink2_t *ctx)
USB-C Sink 2 wait RDO request function.
err_t usbcsink2_generic_write(usbcsink2_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len)
USB-C Sink 2 data writing function.
err_t usbcsink2_get_pdo_voltage(usbcsink2_t *ctx, float *voltage_mv)
USB-C Sink 2 get the voltage function.
err_t usbcsink2_generic_read(usbcsink2_t *ctx, uint8_t cmd, uint8_t *data_out, uint8_t len)
USB-C Sink 2 data reading function.
uint8_t usbcsink2_get_interrupt(usbcsink2_t *ctx)
USB-C Sink 2 get interrupt function.
USB-C Sink 2 Click configuration object.
Definition usbcsink2.h:186
analog_in_resolution_t resolution
Definition usbcsink2.h:193
float vref
Definition usbcsink2.h:194
uint32_t i2c_speed
Definition usbcsink2.h:196
pin_name_t scl
Definition usbcsink2.h:188
pin_name_t int_pin
Definition usbcsink2.h:191
pin_name_t sda
Definition usbcsink2.h:189
pin_name_t an
Definition usbcsink2.h:187
uint8_t i2c_address
Definition usbcsink2.h:197
USB-C Sink 2 Click context object.
Definition usbcsink2.h:167
float vref
Definition usbcsink2.h:174
digital_in_t int_pin
Definition usbcsink2.h:168
i2c_master_t i2c
Definition usbcsink2.h:171
uint8_t slave_address
Definition usbcsink2.h:173
uint8_t number_of_valid_pdo
Definition usbcsink2.h:176
analog_in_t adc
Definition usbcsink2.h:170
usbcsink2_return_value_t
USB-C Sink 2 Click return value data.
Definition usbcsink2.h:206
@ USBCSINK2_ERROR
Definition usbcsink2.h:208
@ USBCSINK2_OK
Definition usbcsink2.h:207