Go to the documentation of this file.
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 USBCSINK_REG_BCD_TYPEC_REV_LOW 0x06
74 #define USBCSINK_REG_BCD_TYPEC_REV_HIGH 0x07
75 #define USBCSINK_REG_BCD_USBPD_REV_LOW 0x08
76 #define USBCSINK_REG_BCD_USBPD_REV_HIGH 0x09
77 #define USBCSINK_REG_DEVICE_CAPAB_HIGH 0x0A
78 #define USBCSINK_REG_ALERT_STAT_1 0x0B
79 #define USBCSINK_REG_ALERT_STAT_1_MASK 0x0C
80 #define USBCSINK_REG_PORT_STAT_0 0x0D
81 #define USBCSINK_REG_PORT_STAT_1 0x0E
82 #define USBCSINK_REG_TYPEC_MON_STAT_0 0x0F
83 #define USBCSINK_REG_TYPEC_MON_STAT_1 0x10
84 #define USBCSINK_REG_CC_STAT 0x11
85 #define USBCSINK_REG_CC_HW_FAULT_STAT_0 0x12
86 #define USBCSINK_REG_CC_HW_FAULT_STAT_1 0x13
87 #define USBCSINK_REG_PD_TYPEC_STAT 0x14
88 #define USBCSINK_REG_TYPEC_STAT 0x15
89 #define USBCSINK_REG_PRT_STAT 0x16
90 #define USBCSINK_REG_PD_CMD_CTL 0x1A
91 #define USBCSINK_REG_MON_CTL_0 0x20
92 #define USBCSINK_REG_MON_CTL_2 0x22
93 #define USBCSINK_REG_RESET_CTL 0x23
94 #define USBCSINK_REG_VBUS_DISCH_TIME_CTL 0x25
95 #define USBCSINK_REG_VBUS_DISCH_CTL 0x26
96 #define USBCSINK_REG_VBUS_CTL 0x27
97 #define USBCSINK_REG_GPIO3_SW_GPIO 0x2D
98 #define USBCSINK_REG_DEV_ID 0x2F
99 #define USBCSINK_REG_RX_HEADER_LOW 0x31
100 #define USBCSINK_REG_RX_HEADER_HIGH 0x32
101 #define USBCSINK_REG_RX_DATA_OBJ1_0 0x33
102 #define USBCSINK_REG_RX_DATA_OBJ1_1 0x34
103 #define USBCSINK_REG_RX_DATA_OBJ1_2 0x35
104 #define USBCSINK_REG_RX_DATA_OBJ1_3 0x36
105 #define USBCSINK_REG_RX_DATA_OBJ2_0 0x37
106 #define USBCSINK_REG_RX_DATA_OBJ2_1 0x38
107 #define USBCSINK_REG_RX_DATA_OBJ2_2 0x39
108 #define USBCSINK_REG_RX_DATA_OBJ2_3 0x3A
109 #define USBCSINK_REG_RX_DATA_OBJ3_0 0x3B
110 #define USBCSINK_REG_RX_DATA_OBJ3_1 0x3C
111 #define USBCSINK_REG_RX_DATA_OBJ3_2 0x3D
112 #define USBCSINK_REG_RX_DATA_OBJ3_3 0x3E
113 #define USBCSINK_REG_RX_DATA_OBJ4_0 0x3F
114 #define USBCSINK_REG_RX_DATA_OBJ4_1 0x40
115 #define USBCSINK_REG_RX_DATA_OBJ4_2 0x41
116 #define USBCSINK_REG_RX_DATA_OBJ4_3 0x42
117 #define USBCSINK_REG_RX_DATA_OBJ5_0 0x43
118 #define USBCSINK_REG_RX_DATA_OBJ5_1 0x44
119 #define USBCSINK_REG_RX_DATA_OBJ5_2 0x45
120 #define USBCSINK_REG_RX_DATA_OBJ5_3 0x46
121 #define USBCSINK_REG_RX_DATA_OBJ6_0 0x47
122 #define USBCSINK_REG_RX_DATA_OBJ6_1 0x48
123 #define USBCSINK_REG_RX_DATA_OBJ6_2 0x49
124 #define USBCSINK_REG_RX_DATA_OBJ6_3 0x4A
125 #define USBCSINK_REG_RX_DATA_OBJ7_0 0x4B
126 #define USBCSINK_REG_RX_DATA_OBJ7_1 0x4C
127 #define USBCSINK_REG_RX_DATA_OBJ7_2 0x4D
128 #define USBCSINK_REG_RX_DATA_OBJ7_3 0x4E
129 #define USBCSINK_REG_TX_HEADER_LOW 0x51
130 #define USBCSINK_REG_TX_HEADER_HIGH 0x52
131 #define USBCSINK_REG_DPM_PDO_NUMB 0x70
132 #define USBCSINK_REG_DPM_SNK_PDO1_0 0x85
133 #define USBCSINK_REG_DPM_SNK_PDO1_1 0x86
134 #define USBCSINK_REG_DPM_SNK_PDO1_2 0x87
135 #define USBCSINK_REG_DPM_SNK_PDO1_3 0x88
136 #define USBCSINK_REG_DPM_SNK_PDO2_0 0x89
137 #define USBCSINK_REG_DPM_SNK_PDO2_1 0x8A
138 #define USBCSINK_REG_DPM_SNK_PDO2_2 0x8B
139 #define USBCSINK_REG_DPM_SNK_PDO2_3 0x8C
140 #define USBCSINK_REG_DPM_SNK_PDO3_0 0x8D
141 #define USBCSINK_REG_DPM_SNK_PDO3_1 0x8E
142 #define USBCSINK_REG_DPM_SNK_PDO3_2 0x8F
143 #define USBCSINK_REG_DPM_SNK_PDO3_3 0x90
144 #define USBCSINK_REG_DPM_REQ_RDO3_0 0x91
145 #define USBCSINK_REG_DPM_REQ_RDO3_1 0x92
146 #define USBCSINK_REG_DPM_REQ_RDO3_2 0x93
147 #define USBCSINK_REG_DPM_REQ_RDO3_3 0x94
148 #define USBCSINK_REG_DEF 0xFF
149 #define USBCSINK_REG_FTP_CUST_PWD_REG 0x95
150 #define USBCSINK_REG_FTP_CTL_0 0x96
151 #define USBCSINK_REG_FTP_CTL_1 0x97
152 #define USBCSINK_REG_RW_BUF 0x53
154 #define USBCSINK_FTP_CUST_PWR 0x80
155 #define USBCSINK_FTP_CUST_RST_N 0x40
156 #define USBCSINK_FTP_CUST_REQ 0x10
157 #define USBCSINK_FTP_CUST_SECT 0x07
159 #define USBCSINK_FTP_CUST_SER 0xF8
160 #define USBCSINK_FTP_CUST_OPCODE 0x07
162 #define USBCSINK_SEC_0 0x01
163 #define USBCSINK_SEC_1 0x02
164 #define USBCSINK_SEC_2 0x04
165 #define USBCSINK_SEC_3 0x08
166 #define USBCSINK_SEC_4 0x10
189 #define USBCSINK_FTP_CUST_PWD 0x47
195 #define USBCSINK_SW_RESET_ON 0x01
196 #define USBCSINK_SW_RESET_OFF 0x00
202 #define USBCSINK_READ 0x00
203 #define USBCSINK_WRITE_PL 0x01
204 #define USBCSINK_WRITE_SER 0x02
205 #define USBCSINK_ERASE_SEC 0x05
206 #define USBCSINK_PROG_SEC 0x06
207 #define USBCSINK_SOFT_PROG_SEC 0x07
213 #define USBCSINK_SET_PDO_1 0x01
214 #define USBCSINK_SET_PDO_2 0x02
215 #define USBCSINK_SET_PDO_3 0x03
217 #define USBCSINK_UPLOAD_NEW_DATA_VAL 0x00
218 #define USBCSINK_UPLOAD_DEFAULT 0x01
225 #define USBCSINK_SLAVE_ADR_0 0x28
226 #define USBCSINK_SLAVE_ADR_1 0x29
227 #define USBCSINK_SLAVE_ADR_2 0x2A
228 #define USBCSINK_SLAVE_ADR_3 0x2B
246 #define USBCSINK_MAP_MIKROBUS( cfg, mikrobus ) \
247 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
248 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
249 cfg.po3 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
250 cfg.po2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
251 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
252 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
void usbcsink_write_byte(usbcsink_t *ctx, uint8_t reg, uint8_t tx_data)
Write byte function.
pin_name_t po3
Definition: usbcsink.h:288
void usbcsink_cfg_setup(usbcsink_cfg_t *cfg)
USB-C Sink configuration object setup function.
uint8_t usbcsink_get_pdo3(usbcsink_t *ctx)
Get PO3 pin state function.
pin_name_t po2
Definition: usbcsink.h:289
void usbcsink_set_current(uint8_t pdo_numb, float curr)
Set the current function.
void usbcsink_set_usb_com_capa(uint8_t value)
Set the USB capable function.
uint8_t usbcsink_get_cfg_ok_gpio(void)
Get the config OK GPIO function.
err_t usbcsink_cust_wr_sec(usbcsink_t *ctx, uint8_t sec_num, uint8_t *sec_data)
Write sector function.
err_t usbcsink_generic_read(usbcsink_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
USB-C Sink I2C reading function.
pin_name_t int_pin
Definition: usbcsink.h:291
void usbcsink_set_ext_pow(uint8_t value)
Set the external source of power function.
void usbcsink_load_data(usbcsink_t *ctx)
Load data function.
uint8_t slave_address
Definition: usbcsink.h:275
err_t usbcsink_init(usbcsink_t *ctx, usbcsink_cfg_t *cfg)
USB-C Sink initialization function.
void usbcsink_set_voltage(uint8_t pdo_numb, float volt)
Set the voltage function.
pin_name_t rst
Definition: usbcsink.h:290
digital_out_t rst
Definition: usbcsink.h:264
uint8_t usbcsink_read_byte(usbcsink_t *ctx, uint8_t reg)
Read byte function.
void usbcsink_set_flx_curr(float value)
Set the flexible current function.
uint8_t usbcsink_get_up_volt_limit(uint8_t pdo_numb)
Get the over voltage limit function.
uint32_t i2c_speed
Definition: usbcsink.h:293
void usbcsink_set_pow_above_5v_only(uint8_t value)
Set the power only above 5V function.
uint8_t usbcsink_get_interrupt(usbcsink_t *ctx)
Get INT pin state function.
float usbcsink_get_flx_curr(void)
Get the flexible current function.
void usbcsink_set_lo_volt_limit(uint8_t pdo_numb, uint8_t value)
Set the lower voltage limit function.
err_t usbcsink_generic_write(usbcsink_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
USB-C Sink I2C writing function.
USB-C Sink Click configuration object.
Definition: usbcsink.h:284
digital_in_t po2
Definition: usbcsink.h:268
uint8_t usbcsink_get_ext_pow(void)
Get the external source of power function.
USB-C Sink Click context object.
Definition: usbcsink.h:262
uint8_t i2c_address
Definition: usbcsink.h:294
uint8_t usbcsink_get_req_src_curr(void)
Get the request operating current function.
void usbcsink_upload_new_data(usbcsink_t *ctx, uint8_t def_vals)
Upload data function.
void usbcsink_hw_reset(usbcsink_t *ctx)
HW reset function.
uint8_t usbcsink_get_pow_above_5v_only(void)
Get the power only above 5V function.
uint8_t usbcsink_get_lo_volt_limit(uint8_t pdo_numb)
Get the lower voltage limit function.
uint8_t usbcsink_dev_chk(usbcsink_t *ctx)
Check device communication function.
pin_name_t scl
Definition: usbcsink.h:285
uint8_t usbcsink_get_usb_com_cap(void)
Get the USB capable function.
@ USBCSINK_ERROR
Definition: usbcsink.h:305
uint8_t usbcsink_get_pdo2(usbcsink_t *ctx)
Get PO2 pin state function.
@ USBCSINK_OK
Definition: usbcsink.h:304
err_t usbcsink_cust_ent_wr_mode(usbcsink_t *ctx, uint8_t er_sec)
Enter the write mode function.
float usbcsink_get_current(uint8_t pdo_numb)
Get the current function.
uint8_t usbcsink_get_gpio_ctl(void)
Get the config CTRL GPIO function.
void usbcsink_set_gpio_ctl(uint8_t value)
Set the config CTRL GPIO function.
pin_name_t sda
Definition: usbcsink.h:286
uint8_t usbcsink_get_pdo_num(void)
Get the number of sink function.
digital_in_t int_pin
Definition: usbcsink.h:269
void usbcsink_set_req_src_current(uint8_t value)
Set the request operating current function.
digital_in_t po3
Definition: usbcsink.h:267
void usbcsink_set_pdo_num(uint8_t pdo_numb)
Set the number of sink function.
i2c_master_t i2c
Definition: usbcsink.h:272
void usbcsink_set_cfg_ok_gpio(uint8_t value)
Set the config OK GPIO function.
float usbcsink_get_voltage(uint8_t pdo_numb)
Get the voltage function.
usbcsink_return_value_t
USB-C Sink Click return value data.
Definition: usbcsink.h:303
err_t usbcsink_cust_ext_test_mode(usbcsink_t *ctx)
Exit write mode function.
void usbcsink_set_up_volt_limit(uint8_t pdo_numb, uint8_t value)
Set the upper voltage limit function.