Go to the documentation of this file.
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
59 #define USBCSINK_REG_BCD_TYPEC_REV_LOW 0x06
60 #define USBCSINK_REG_BCD_TYPEC_REV_HIGH 0x07
61 #define USBCSINK_REG_BCD_USBPD_REV_LOW 0x08
62 #define USBCSINK_REG_BCD_USBPD_REV_HIGH 0x09
63 #define USBCSINK_REG_DEVICE_CAPAB_HIGH 0x0A
64 #define USBCSINK_REG_ALERT_STAT_1 0x0B
65 #define USBCSINK_REG_ALERT_STAT_1_MASK 0x0C
66 #define USBCSINK_REG_PORT_STAT_0 0x0D
67 #define USBCSINK_REG_PORT_STAT_1 0x0E
68 #define USBCSINK_REG_TYPEC_MON_STAT_0 0x0F
69 #define USBCSINK_REG_TYPEC_MON_STAT_1 0x10
70 #define USBCSINK_REG_CC_STAT 0x11
71 #define USBCSINK_REG_CC_HW_FAULT_STAT_0 0x12
72 #define USBCSINK_REG_CC_HW_FAULT_STAT_1 0x13
73 #define USBCSINK_REG_PD_TYPEC_STAT 0x14
74 #define USBCSINK_REG_TYPEC_STAT 0x15
75 #define USBCSINK_REG_PRT_STAT 0x16
76 #define USBCSINK_REG_PD_CMD_CTL 0x1A
77 #define USBCSINK_REG_MON_CTL_0 0x20
78 #define USBCSINK_REG_MON_CTL_2 0x22
79 #define USBCSINK_REG_RESET_CTL 0x23
80 #define USBCSINK_REG_VBUS_DISCH_TIME_CTL 0x25
81 #define USBCSINK_REG_VBUS_DISCH_CTL 0x26
82 #define USBCSINK_REG_VBUS_CTL 0x27
83 #define USBCSINK_REG_GPIO3_SW_GPIO 0x2D
84 #define USBCSINK_REG_DEV_ID 0x2F
85 #define USBCSINK_REG_RX_HEADER_LOW 0x31
86 #define USBCSINK_REG_RX_HEADER_HIGH 0x32
87 #define USBCSINK_REG_RX_DATA_OBJ1_0 0x33
88 #define USBCSINK_REG_RX_DATA_OBJ1_1 0x34
89 #define USBCSINK_REG_RX_DATA_OBJ1_2 0x35
90 #define USBCSINK_REG_RX_DATA_OBJ1_3 0x36
91 #define USBCSINK_REG_RX_DATA_OBJ2_0 0x37
92 #define USBCSINK_REG_RX_DATA_OBJ2_1 0x38
93 #define USBCSINK_REG_RX_DATA_OBJ2_2 0x39
94 #define USBCSINK_REG_RX_DATA_OBJ2_3 0x3A
95 #define USBCSINK_REG_RX_DATA_OBJ3_0 0x3B
96 #define USBCSINK_REG_RX_DATA_OBJ3_1 0x3C
97 #define USBCSINK_REG_RX_DATA_OBJ3_2 0x3D
98 #define USBCSINK_REG_RX_DATA_OBJ3_3 0x3E
99 #define USBCSINK_REG_RX_DATA_OBJ4_0 0x3F
100 #define USBCSINK_REG_RX_DATA_OBJ4_1 0x40
101 #define USBCSINK_REG_RX_DATA_OBJ4_2 0x41
102 #define USBCSINK_REG_RX_DATA_OBJ4_3 0x42
103 #define USBCSINK_REG_RX_DATA_OBJ5_0 0x43
104 #define USBCSINK_REG_RX_DATA_OBJ5_1 0x44
105 #define USBCSINK_REG_RX_DATA_OBJ5_2 0x45
106 #define USBCSINK_REG_RX_DATA_OBJ5_3 0x46
107 #define USBCSINK_REG_RX_DATA_OBJ6_0 0x47
108 #define USBCSINK_REG_RX_DATA_OBJ6_1 0x48
109 #define USBCSINK_REG_RX_DATA_OBJ6_2 0x49
110 #define USBCSINK_REG_RX_DATA_OBJ6_3 0x4A
111 #define USBCSINK_REG_RX_DATA_OBJ7_0 0x4B
112 #define USBCSINK_REG_RX_DATA_OBJ7_1 0x4C
113 #define USBCSINK_REG_RX_DATA_OBJ7_2 0x4D
114 #define USBCSINK_REG_RX_DATA_OBJ7_3 0x4E
115 #define USBCSINK_REG_TX_HEADER_LOW 0x51
116 #define USBCSINK_REG_TX_HEADER_HIGH 0x52
117 #define USBCSINK_REG_DPM_PDO_NUMB 0x70
118 #define USBCSINK_REG_DPM_SNK_PDO1_0 0x85
119 #define USBCSINK_REG_DPM_SNK_PDO1_1 0x86
120 #define USBCSINK_REG_DPM_SNK_PDO1_2 0x87
121 #define USBCSINK_REG_DPM_SNK_PDO1_3 0x88
122 #define USBCSINK_REG_DPM_SNK_PDO2_0 0x89
123 #define USBCSINK_REG_DPM_SNK_PDO2_1 0x8A
124 #define USBCSINK_REG_DPM_SNK_PDO2_2 0x8B
125 #define USBCSINK_REG_DPM_SNK_PDO2_3 0x8C
126 #define USBCSINK_REG_DPM_SNK_PDO3_0 0x8D
127 #define USBCSINK_REG_DPM_SNK_PDO3_1 0x8E
128 #define USBCSINK_REG_DPM_SNK_PDO3_2 0x8F
129 #define USBCSINK_REG_DPM_SNK_PDO3_3 0x90
130 #define USBCSINK_REG_DPM_REQ_RDO3_0 0x91
131 #define USBCSINK_REG_DPM_REQ_RDO3_1 0x92
132 #define USBCSINK_REG_DPM_REQ_RDO3_2 0x93
133 #define USBCSINK_REG_DPM_REQ_RDO3_3 0x94
134 #define USBCSINK_REG_DEF 0xFF
135 #define USBCSINK_REG_FTP_CUST_PWD_REG 0x95
136 #define USBCSINK_REG_FTP_CTL_0 0x96
137 #define USBCSINK_REG_FTP_CTL_1 0x97
138 #define USBCSINK_REG_RW_BUF 0x53
140 #define USBCSINK_FTP_CUST_PWR 0x80
141 #define USBCSINK_FTP_CUST_RST_N 0x40
142 #define USBCSINK_FTP_CUST_REQ 0x10
143 #define USBCSINK_FTP_CUST_SECT 0x07
145 #define USBCSINK_FTP_CUST_SER 0xF8
146 #define USBCSINK_FTP_CUST_OPCODE 0x07
148 #define USBCSINK_SEC_0 0x01
149 #define USBCSINK_SEC_1 0x02
150 #define USBCSINK_SEC_2 0x04
151 #define USBCSINK_SEC_3 0x08
152 #define USBCSINK_SEC_4 0x10
175 #define USBCSINK_FTP_CUST_PWD 0x47
181 #define USBCSINK_SW_RESET_ON 0x01
182 #define USBCSINK_SW_RESET_OFF 0x00
188 #define USBCSINK_READ 0x00
189 #define USBCSINK_WRITE_PL 0x01
190 #define USBCSINK_WRITE_SER 0x02
191 #define USBCSINK_ERASE_SEC 0x05
192 #define USBCSINK_PROG_SEC 0x06
193 #define USBCSINK_SOFT_PROG_SEC 0x07
199 #define USBCSINK_SET_PDO_1 0x01
200 #define USBCSINK_SET_PDO_2 0x02
201 #define USBCSINK_SET_PDO_3 0x03
203 #define USBCSINK_UPLOAD_NEW_DATA_VAL 0x00
204 #define USBCSINK_UPLOAD_DEFAULT 0x01
211 #define USBCSINK_SLAVE_ADR_0 0x28
212 #define USBCSINK_SLAVE_ADR_1 0x29
213 #define USBCSINK_SLAVE_ADR_2 0x2A
214 #define USBCSINK_SLAVE_ADR_3 0x2B
232 #define USBCSINK_MAP_MIKROBUS( cfg, mikrobus ) \
233 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
234 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
235 cfg.po3 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
236 cfg.po2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
237 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
238 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:274
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:275
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:277
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:261
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:276
digital_out_t rst
Definition: usbcsink.h:250
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:279
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:270
digital_in_t po2
Definition: usbcsink.h:254
uint8_t usbcsink_get_ext_pow(void)
Get the external source of power function.
USB-C Sink Click context object.
Definition: usbcsink.h:248
uint8_t i2c_address
Definition: usbcsink.h:280
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:271
uint8_t usbcsink_get_usb_com_cap(void)
Get the USB capable function.
@ USBCSINK_ERROR
Definition: usbcsink.h:291
uint8_t usbcsink_get_pdo2(usbcsink_t *ctx)
Get PO2 pin state function.
@ USBCSINK_OK
Definition: usbcsink.h:290
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:272
uint8_t usbcsink_get_pdo_num(void)
Get the number of sink function.
digital_in_t int_pin
Definition: usbcsink.h:255
void usbcsink_set_req_src_current(uint8_t value)
Set the request operating current function.
digital_in_t po3
Definition: usbcsink.h:253
void usbcsink_set_pdo_num(uint8_t pdo_numb)
Set the number of sink function.
i2c_master_t i2c
Definition: usbcsink.h:258
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:289
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.