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"
73#define USBCSOURCE_REG_ALERT_STATUS_REG 0x0B
74#define USBCSOURCE_REG_ALERT_STATUS_MASK_CTRL 0x0C
75#define USBCSOURCE_REG_CC_CONNECTION_STATUS_TRANS 0x0D
76#define USBCSOURCE_REG_CC_CONNECTION_STATUS_1 0x0E
77#define USBCSOURCE_REG_MONITORING_STATUS_TRANS 0x0F
78#define USBCSOURCE_REG_MONITORING_STATUS 0x10
79#define USBCSOURCE_REG_CC_CONNECTION_STATUS_2 0x11
80#define USBCSOURCE_REG_HW_FAULT_STATUS_TRANS 0x12
81#define USBCSOURCE_REG_HW_FAULT_STATUS 0x13
82#define USBCSOURCE_REG_CC_CAPABILITY_CTRL 0x18
83#define USBCSOURCE_REG_RESET_CTRL 0x23
84#define USBCSOURCE_REG_VBUS_DISCHARGE_TIME_CTRL 0x25
85#define USBCSOURCE_REG_VBUS_DISCHARGE_STATUS 0x26
86#define USBCSOURCE_REG_VBUS_ENABLE_STATUS 0x27
87#define USBCSOURCE_REG_VBUS_MONITORING_CTRL 0x2E
89#define USBCSOURCE_REG_SRC_PDO1 0x71
90#define USBCSOURCE_REG_SRC_PDO2 0x75
91#define USBCSOURCE_REG_SRC_PDO3 0x79
92#define USBCSOURCE_REG_SRC_PDO4 0x7D
93#define USBCSOURCE_REG_SRC_PDO5 0x81
116#define USBCSOURCE_SEL_PDO1 0x01
117#define USBCSOURCE_SEL_PDO2 0x02
118#define USBCSOURCE_SEL_PDO3 0x03
119#define USBCSOURCE_SEL_PDO4 0x04
120#define USBCSOURCE_SEL_PDO5 0x05
126#define USBCSOURCE_PDO_NVM_VOLT_CFG_9_V 0x00
127#define USBCSOURCE_PDO_NVM_VOLT_CFG_15_V 0x01
128#define USBCSOURCE_PDO_NVM_VOLT_CFG_FLEX_V1 0x02
129#define USBCSOURCE_PDO_NVM_VOLT_CFG_FLEX_V2 0x03
135#define USBCSOURCE_PDO_NVM_CUR_FLEX_I 0x00
136#define USBCSOURCE_PDO_NVM_CUR_1_50_A 0x01
137#define USBCSOURCE_PDO_NVM_CUR_1_75_A 0x02
138#define USBCSOURCE_PDO_NVM_CUR_2_00_A 0x03
139#define USBCSOURCE_PDO_NVM_CUR_2_25_A 0x04
140#define USBCSOURCE_PDO_NVM_CUR_2_50_A 0x05
141#define USBCSOURCE_PDO_NVM_CUR_2_75_A 0x06
142#define USBCSOURCE_PDO_NVM_CUR_3_00_A 0x07
143#define USBCSOURCE_PDO_NVM_CUR_3_25_A 0x08
144#define USBCSOURCE_PDO_NVM_CUR_3_50_A 0x09
145#define USBCSOURCE_PDO_NVM_CUR_3_75_A 0x0A
146#define USBCSOURCE_PDO_NVM_CUR_4_00_A 0x0B
147#define USBCSOURCE_PDO_NVM_CUR_4_25_A 0x0C
148#define USBCSOURCE_PDO_NVM_CUR_4_50_A 0x0D
149#define USBCSOURCE_PDO_NVM_CUR_4_75_A 0x0E
150#define USBCSOURCE_PDO_NVM_CUR_5_00_A 0x0F
156#define USBCSOURCE_RESET_DIS 0x00
157#define USBCSOURCE_RESET_EN 0x01
163#define USBCSOURCE_ALERT_STAT_HARD_RESET_AL 0x80
164#define USBCSOURCE_ALERT_STAT_PORT_STAT_AL 0x40
165#define USBCSOURCE_ALERT_STAT_TYPEC_MON_AL 0x20
166#define USBCSOURCE_ALERT_STAT_CC_HW_FAULT_AL 0x10
167#define USBCSOURCE_ALERT_STAT_DPM_STAT_AL 0x08
168#define USBCSOURCE_ALERT_STAT_PE_STAT_AL 0x04
169#define USBCSOURCE_ALERT_STAT_PRT_STAT_AL 0x02
170#define USBCSOURCE_ALERT_STAT_PHY_STAT_AL 0x01
176#define USBCSOURCE_ATTACHED_DEVICE_NONE_ATT 0x00
177#define USBCSOURCE_ATTACHED_DEVICE_SNK_ATT 0x01
178#define USBCSOURCE_ATTACHED_DEVICE_SRC_ATT 0x02
179#define USBCSOURCE_ATTACHED_DEVICE_DBG_ATT 0x03
180#define USBCSOURCE_ATTACHED_DEVICE_AUD_ATT 0x04
181#define USBCSOURCE_ATTACHED_DEVICE_POW_ACC_ATT 0x05
187#define USBCSOURCE_LOW_POWER_STANDBY_OFF 0x00
188#define USBCSOURCE_LOW_POWER_STANDBY_ON 0x01
194#define USBCSOURCE_POWER_MODE_SNK 0x00
195#define USBCSOURCE_POWER_MODE_SRC 0x01
201#define USBCSOURCE_DATA_MODE_UFP 0x00
202#define USBCSOURCE_DATA_MODE_DFP 0x01
208#define USBCSOURCE_CONN_UNATTACHED 0x00
209#define USBCSOURCE_CONN_ATTACHED 0x01
215#define USBCSOURCE_VBUS_READY_DISCONNECTED 0x00
216#define USBCSOURCE_VBUS_READY_CONNECTED 0x01
218#define USBCSOURCE_VBUS_VSAFE0V_0_8V_HIGHER 0x00
219#define USBCSOURCE_VBUS_VSAFE0V_0_8V_LOWER 0x01
221#define USBCSOURCE_VBUS_VALID_3_9V_LOWER 0x00
222#define USBCSOURCE_VBUS_VALID_3_9V_HIGHER 0x01
228#define USBCSOURCE_STATUS_ERROR 0x00
229#define USBCSOURCE_STATUS_SUCCESS 0x01
236#define USBCSOURCE_I2C_SLAVE_ADR_GND 0x28
237#define USBCSOURCE_I2C_SLAVE_ADR_VCC 0x29
255#define USBCSOURCE_MAP_MIKROBUS( cfg, mikrobus ) \
256 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
257 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
258 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
259 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
void usbcsource_hw_reset(usbcsource_t *ctx)
HW reset function.
void usbcsource_get_fault_status(usbcsource_t *ctx, fault_status_t *fault_data)
Get fault status function.
uint8_t usbcsource_check_attach_trans(usbcsource_t *ctx)
Check attach trans function.
void usbcsource_get_connection_status(usbcsource_t *ctx, connection_status_t *conn_data)
Get connection status function.
uint8_t usbcsource_read_byte(usbcsource_t *ctx, uint8_t reg)
Generic read function.
err_t usbcsource_init(usbcsource_t *ctx, usbcsource_cfg_t *cfg)
USB-C Source initialization function.
void usbcsource_default_config(usbcsource_t *ctx)
Default configuration function.
uint8_t usbcsource_set_pdo_config(usbcsource_t *ctx, pdo_config_t pdo_cfg_data)
Set PDO configuration function.
void usbcsource_cfg_setup(usbcsource_cfg_t *cfg)
USB-C Source configuration object setup function.
err_t usbcsource_generic_read(usbcsource_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
USB-C Source I2C reading function.
void usbcsource_get_monitoring_status(usbcsource_t *ctx, monitor_status_t *monitor_status_data)
Get monitoring status function.
err_t usbcsource_generic_write(usbcsource_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
USB-C Source I2C writing function.
uint8_t usbcsource_int_pin_state(usbcsource_t *ctx)
Get INT pin state function.
void usbcsource_get_alert_status(usbcsource_t *ctx, alert_status_t *alert_status_data)
Get alert status function.
void usbcsource_get_port_status(usbcsource_t *ctx, port_status_t *port_status_data)
Get port status function.
void usbcsource_sw_reset(usbcsource_t *ctx)
SW reset function.
void usbcsource_set_alert_status(usbcsource_t *ctx, alert_status_t alert_status_data)
Set alert status function.
void usbcsource_write_byte(usbcsource_t *ctx, uint8_t reg, uint8_t tx_data)
Generic write function.
uint8_t usbcsource_get_pdo_config(usbcsource_t *ctx, uint8_t pdo_numb, pdo_config_t *pdo_cfg_data)
Get PDO configuration function.
USB-C Source Click alert status object.
Definition usbcsource.h:306
uint8_t prt_status_al
Definition usbcsource.h:311
uint8_t cc_hw_fault_status_al
Definition usbcsource.h:310
uint8_t typec_monitoring_status_al
Definition usbcsource.h:309
uint8_t port_status_al
Definition usbcsource.h:308
uint8_t hard_reset_al
Definition usbcsource.h:307
uint8_t phy_status_al
Definition usbcsource.h:312
USB-C Source Click connection status object.
Definition usbcsource.h:347
uint8_t snk_power_level
Definition usbcsource.h:349
uint8_t typec_fsm_state
Definition usbcsource.h:350
uint8_t cc_reverse
Definition usbcsource.h:348
USB-C Source Click fault status object.
Definition usbcsource.h:358
uint8_t vconn_sw_rvp_fault_cc2
Definition usbcsource.h:368
uint8_t vpu_valid
Definition usbcsource.h:366
uint8_t th_145_status
Definition usbcsource.h:359
uint8_t vpu_ovp_fault_trans
Definition usbcsource.h:360
uint8_t vconn_sw_ocp_fault_cc1
Definition usbcsource.h:369
uint8_t vconn_sw_ocp_fault_trans
Definition usbcsource.h:363
uint8_t vconn_sw_ovp_fault_cc1
Definition usbcsource.h:371
uint8_t vpu_valid_trans
Definition usbcsource.h:361
uint8_t vconn_sw_rvp_fault_cc1
Definition usbcsource.h:367
uint8_t vconn_sw_ocp_fault_cc2
Definition usbcsource.h:370
uint8_t vconn_sw_rvp_fault_trans
Definition usbcsource.h:362
uint8_t vconn_sw_ovp_fault_trans
Definition usbcsource.h:364
uint8_t vconn_sw_ovp_fault_cc2
Definition usbcsource.h:372
uint8_t vpu_ovp_fault
Definition usbcsource.h:365
USB-C Source Click monitor status object.
Definition usbcsource.h:334
uint8_t vconn_valid
Definition usbcsource.h:339
uint8_t vbus_vsafe0v
Definition usbcsource.h:337
uint8_t pd_typec_hand_check
Definition usbcsource.h:335
uint8_t vbus_ready
Definition usbcsource.h:336
uint8_t vbus_valid
Definition usbcsource.h:338
USB-C Source Click PDO config object.
Definition usbcsource.h:380
uint8_t pdo_number
Definition usbcsource.h:381
uint8_t usb_suspend_support
Definition usbcsource.h:384
uint8_t usb_commun_capable
Definition usbcsource.h:386
uint8_t dual_role_data
Definition usbcsource.h:387
float curr_data
Definition usbcsource.h:391
uint8_t dual_role_power
Definition usbcsource.h:383
uint8_t unconstr_power
Definition usbcsource.h:385
uint8_t peak_current
Definition usbcsource.h:389
uint8_t unch_exd_mesg_support
Definition usbcsource.h:388
uint8_t fixed_supply
Definition usbcsource.h:382
float vtg_data
Definition usbcsource.h:390
USB-C Source Click port status object.
Definition usbcsource.h:320
uint8_t attached_device
Definition usbcsource.h:321
uint8_t data_mode
Definition usbcsource.h:324
uint8_t vconn_mode
Definition usbcsource.h:325
uint8_t power_mode
Definition usbcsource.h:323
uint8_t attach
Definition usbcsource.h:326
uint8_t low_power_standby
Definition usbcsource.h:322
USB-C Source Click configuration object.
Definition usbcsource.h:289
uint32_t i2c_speed
Definition usbcsource.h:296
pin_name_t scl
Definition usbcsource.h:290
pin_name_t int_pin
Definition usbcsource.h:294
pin_name_t sda
Definition usbcsource.h:291
pin_name_t rst
Definition usbcsource.h:293
uint8_t i2c_address
Definition usbcsource.h:297
USB-C Source Click context object.
Definition usbcsource.h:269
digital_in_t int_pin
Definition usbcsource.h:274
i2c_master_t i2c
Definition usbcsource.h:277
digital_out_t rst
Definition usbcsource.h:271
uint8_t slave_address
Definition usbcsource.h:280
usbcsource_return_value_t
USB-C Source Click return value data.
Definition usbcsource.h:399
@ USBCSOURCE_OK
Definition usbcsource.h:400
@ USBCSOURCE_ERROR
Definition usbcsource.h:401