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_i2c_master.h"
52#include "drv_spi_master.h"
54#include "drv_analog_in.h"
76#define USBCSINK3_REG_INPUT_PORT 0x00
77#define USBCSINK3_REG_OUTPUT_PORT 0x01
78#define USBCSINK3_REG_POLARITY_INV 0x02
79#define USBCSINK3_REG_CONFIG 0x03
80#define USBCSINK3_REG_SPECIAL_FUNC 0x50
93#define USBCSINK3_CMD_SEL_NONE 0x00
94#define USBCSINK3_CMD_SEL_DATA_WRITE 0x10
95#define USBCSINK3_CMD_SEL_SHUTDOWN 0x20
101#define USBCSINK3_POT_SEL_DUMMY_CODE 0x00
102#define USBCSINK3_POT_SEL_DIGI_POT_1 0x01
103#define USBCSINK3_POT_SEL_DIGI_POT_2 0x02
104#define USBCSINK3_POT_SEL_DIGI_POT_BOTH 0x03
122#define USBCSINK3_NO_PIN_BIT_MASK 0x00
123#define USBCSINK3_PIN_0_BIT_MASK 0x01
124#define USBCSINK3_PIN_1_BIT_MASK 0x02
125#define USBCSINK3_PIN_2_BIT_MASK 0x04
126#define USBCSINK3_PIN_3_BIT_MASK 0x08
127#define USBCSINK3_ALL_PINS_BIT_MASK 0xF0
133#define USBCSINK3_DIRECTION_OUTPUT 0x00
134#define USBCSINK3_DIRECTION_INPUT 0x01
140#define USBCSINK3_VSEL0_DISABLE 0x00
141#define USBCSINK3_VSEL0_ENABLE 0x01
142#define USBCSINK3_VSEL0_PIN_BIT_MASK 0x0E
143#define USBCSINK3_VSEL1_DISABLE 0x00
144#define USBCSINK3_VSEL1_ENABLE 0x02
145#define USBCSINK3_VSEL1_PIN_BIT_MASK 0x0D
146#define USBCSINK3_VSEL2_DISABLE 0x00
147#define USBCSINK3_VSEL2_ENABLE 0x04
148#define USBCSINK3_VSEL2_PIN_BIT_MASK 0x0B
154#define USBCSINK3_SPEC_FUNC_P3_AS_INT 0x80
155#define USBCSINK3_SPEC_FUNC_PU_DISABLED 0x40
161#define USBCSINK3_VBUS_VTG_0V 0.0f
162#define USBCSINK3_VBUS_VTG_5V 5.0f
163#define USBCSINK3_VBUS_VTG_9V 9.0f
164#define USBCSINK3_VBUS_VTG_15V 15.0f
165#define USBCSINK3_VBUS_VTG_20V 20.3f
166#define USBCSINK3_VBUS_VTG_4_3V 4.3f
167#define USBCSINK3_VBUS_VTG_8_6V 8.6f
168#define USBCSINK3_VBUS_VTG_12_9V 12.9f
169#define USBCSINK3_VBUS_VTG_17_2V 17.2f
175#define USBCSINK3_WIPER_POS_MAX 255
176#define USBCSINK3_RES_6_8_KOHM 6.8f
177#define USBCSINK3_RES_16_KOHM 16.0f
178#define USBCSINK3_RES_27_KOHM 27.0f
179#define USBCSINK3_RES_36_KOHM 36.0f
180#define USBCSINK3_RES_45_3_KOHM 45.3f
181#define USBCSINK3_RES_56_KOHM 56.0f
182#define USBCSINK3_RES_64_9_KOHM 64.9f
183#define USBCSINK3_RES_75_KOHM 75.0f
184#define USBCSINK3_RES_82_KOHM 82.0f
185#define USBCSINK3_RES_91_KOHM 91.0f
186#define USBCSINK3_RES_100_KOHM 100.0f
187#define USBCSINK3_VBUS_R11_RES_73_2_KOHM 73.2f
188#define USBCSINK3_VBUS_R13_RES_10_KOHM 10.0f
194#define USBCSINK3_ADC_RESOLUTION 0x0FFF
195#define USBCSINK3_VREF_3V3 3.3
196#define USBCSINK3_VREF_5V 5.0
203#define USBCSINK3_DEVICE_ADDRESS 0x41
213#define USBCSINK3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
214#define USBCSINK3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
232#define USBCSINK3_MAP_MIKROBUS( cfg, mikrobus ) \
233 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
234 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
235 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
236 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
237 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
238 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
239 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
err_t usbcsink3_set_power(usbcsink3_t *ctx, usbcsink3_pwr_sel_t power)
USB-C Sink 3 set the power function.
err_t usbcsink3_set_vref(usbcsink3_t *ctx, float vref)
USB-C Sink 3 set vref function.
err_t usbcsink3_i2c_read(usbcsink3_t *ctx, uint8_t reg, uint8_t *data_out)
USB-C Sink 3 I2C reading function.
err_t usbcsink3_read_voltage(usbcsink3_t *ctx, float *voltage)
USB-C Sink 3 read voltage level function.
err_t usbcsink3_i2c_write(usbcsink3_t *ctx, uint8_t reg, uint8_t data_in)
USB-C Sink 3 I2C writing function.
err_t usbcsink3_set_resistence(usbcsink3_t *ctx, float resistence)
USB-C Sink 3 set the resistance function.
err_t usbcsink3_read_raw_adc(usbcsink3_t *ctx, uint16_t *raw_adc)
USB-C Sink 3 read raw ADC value function.
void usbcsink3_cfg_setup(usbcsink3_cfg_t *cfg)
USB-C Sink 3 configuration object setup function.
err_t usbcsink3_init(usbcsink3_t *ctx, usbcsink3_cfg_t *cfg)
USB-C Sink 3 initialization function.
err_t usbcsink3_set_wiper(usbcsink3_t *ctx, uint8_t wiper_pos)
USB-C Sink 3 set the wiper position function.
err_t usbcsink3_set_voltage(usbcsink3_t *ctx, usbcsink3_vtg_sel_t voltage)
USB-C Sink 3 set the voltage function.
err_t usbcsink3_default_cfg(usbcsink3_t *ctx)
USB-C Sink 3 default configuration function.
err_t usbcsink3_spi_write(usbcsink3_t *ctx, uint8_t reg, uint8_t data_in)
USB-C Sink 3 SPI writing function.
err_t usbcsink3_get_vbus(usbcsink3_t *ctx, float *vbus)
USB-C Sink 3 get VBUS function.
This file contains SPI specific macros, functions, etc.
USB-C Sink 3 Click configuration object.
Definition usbcsink3.h:267
analog_in_resolution_t resolution
Definition usbcsink3.h:276
float vref
Definition usbcsink3.h:277
uint32_t i2c_speed
Definition usbcsink3.h:279
spi_master_chip_select_polarity_t cs_polarity
Definition usbcsink3.h:284
pin_name_t sck
Definition usbcsink3.h:272
spi_master_mode_t spi_mode
Definition usbcsink3.h:283
pin_name_t mosi
Definition usbcsink3.h:271
uint32_t spi_speed
Definition usbcsink3.h:282
pin_name_t scl
Definition usbcsink3.h:268
pin_name_t miso
Definition usbcsink3.h:270
pin_name_t sda
Definition usbcsink3.h:269
pin_name_t an
Definition usbcsink3.h:274
pin_name_t cs
Definition usbcsink3.h:273
uint8_t i2c_address
Definition usbcsink3.h:280
USB-C Sink 3 Click context object.
Definition usbcsink3.h:250
spi_master_t spi
Definition usbcsink3.h:255
float vref
Definition usbcsink3.h:252
i2c_master_t i2c
Definition usbcsink3.h:254
uint8_t slave_address
Definition usbcsink3.h:257
pin_name_t chip_select
Definition usbcsink3.h:258
analog_in_t adc
Definition usbcsink3.h:251
usbcsink3_return_value_t
USB-C Sink 3 Click return value data.
Definition usbcsink3.h:293
@ USBCSINK3_ERROR
Definition usbcsink3.h:295
@ USBCSINK3_OK
Definition usbcsink3.h:294
struct usbcsink3_s usbcsink3_t
USB-C Sink 3 Click context object.
usbcsink3_vtg_sel_t
USB-C Sink 3 Click voltage selection value data.
Definition usbcsink3.h:304
@ USBCSINK3_VTG_SEL_9V
Definition usbcsink3.h:306
@ USBCSINK3_VTG_SEL_4_3V
Definition usbcsink3.h:309
@ USBCSINK3_VTG_SEL_15V
Definition usbcsink3.h:307
@ USBCSINK3_VTG_SEL_20V
Definition usbcsink3.h:308
@ USBCSINK3_VTG_SEL_17_2V
Definition usbcsink3.h:312
@ USBCSINK3_VTG_SEL_8_6V
Definition usbcsink3.h:310
@ USBCSINK3_VTG_SEL_5V
Definition usbcsink3.h:305
@ USBCSINK3_VTG_SEL_12_9V
Definition usbcsink3.h:311
usbcsink3_pwr_sel_t
USB-C Sink 3 Click power selection value data.
Definition usbcsink3.h:321
@ USBCSINK3_PWR_SEL_45W
Definition usbcsink3.h:328
@ USBCSINK3_PWR_SEL_100W
Definition usbcsink3.h:331
@ USBCSINK3_PWR_SEL_27W
Definition usbcsink3.h:326
@ USBCSINK3_PWR_SEL_90W
Definition usbcsink3.h:330
@ USBCSINK3_PWR_SEL_60W
Definition usbcsink3.h:329
@ USBCSINK3_PWR_SEL_36W
Definition usbcsink3.h:327
@ USBCSINK3_PWR_SEL_15W
Definition usbcsink3.h:323
@ USBCSINK3_PWR_SEL_20W
Definition usbcsink3.h:325
@ USBCSINK3_PWR_SEL_12W
Definition usbcsink3.h:322
@ USBCSINK3_PWR_SEL_18W
Definition usbcsink3.h:324