usbcpower  2.1.0.0
usbcpower.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef USBCPOWER_H
29 #define USBCPOWER_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define USBCPOWER_REG_MODE 0x03
60 #define USBCPOWER_MODE_REG_SIZE 5
61 #define USBCPOWER_REG_TYPE 0x04
62 #define USBCPOWER_TYPE_REG_SIZE 5
63 #define USBCPOWER_REG_CUSTUSE 0x06
64 #define USBCPOWER_CUSTUSE_REG_SIZE 9
65 #define USBCPOWER_REG_CMD1 0x08
66 #define USBCPOWER_CMD1_REG_SIZE 5
67 #define USBCPOWER_REG_DATA 0x09
68 #define USBCPOWER_DATA_REG_SIZE 65
69 #define USBCPOWER_REG_DEVICE_CAP 0x0D
70 #define USBCPOWER_DEVICE_CAP_REG_SIZE 5
71 #define USBCPOWER_REG_VERSION 0x0F
72 #define USBCPOWER_VERSION_REG_SIZE 5
73 #define USBCPOWER_REG_INT_EVENT1 0x14
74 #define USBCPOWER_INT_EVENT1_REG_SIZE 15
75 #define USBCPOWER_REG_INT_MASK1 0x16
76 #define USBCPOWER_INT_MASK1_REG_SIZE 12
77 #define USBCPOWER_REG_INT_CLEAR1 0x18
78 #define USBCPOWER_INT_CLEAR1_REG_SIZE 12
79 #define USBCPOWER_REG_STATUS 0x1A
80 #define USBCPOWER_STATUS_REG_SIZE 6
81 #define USBCPOWER_REG_POWER_PATH_STATUS 0x26
82 #define USBCPOWER_POWER_PATH_STATUS_REG_SIZE 6
83 #define USBCPOWER_REG_PORT_CONTROL 0x29
84 #define USBCPOWER_PORT_CONTROL_REG_SIZE 5
85 #define USBCPOWER_REG_BOOT_STATUS 0x2D
86 #define USBCPOWER_BOOT_STATUS_REG_SIZE 6
87 #define USBCPOWER_REG_BUILD_DESC 0x2E
88 #define USBCPOWER_BUILD_DESC_SIZE 50
89 #define USBCPOWER_REG_DEVICE_INFO 0x2F
90 #define USBCPOWER_DEVICE_INFO_REG_SIZE 41
91 #define USBCPOWER_REG_RX_SOURCE_CAPS 0x30
92 #define USBCPOWER_RX_SOURCE_CAPS_REG_SIZE 30
93 #define USBCPOWER_REG_RX_SINK_CAPS 0x31
94 #define USBCPOWER_RX_SINK_CAPS_REG_SIZE 30
95 #define USBCPOWER_REG_TX_SOURCE_CAPS 0x32
96 #define USBCPOWER_TX_SOURCE_CAPS_REG_SIZE 32
97 #define USBCPOWER_REG_TX_SINK_CAPS 0x33
98 #define USBCPOWER_TX_SINK_CAPS_REG_SIZE 30
99 #define USBCPOWER_REG_ACTIVE_CONTRACT_PDO 0x34
100 #define USBCPOWER_ACTIVE_CONTRACT_PDO_REG_SIZE 7
101 #define USBCPOWER_REG_ACTIVE_CONTRACT_RDO 0x35
102 #define USBCPOWER_ACTIVE_CONTRACT_RDO_REG_SIZE 5
103 #define USBCPOWER_REG_POWER_STATUS 0x3F
104 #define USBCPOWER_POWER_STATUS_REG_SIZE 3
105 #define USBCPOWER_REG_PD_STATUS 0x40
106 #define USBCPOWER_PD_STATUS_REG_SIZE 5
107 #define USBCPOWER_REG_TYPEC_STATE 0x69
108 #define USBCPOWER_TYPEC_STATE_REG_SIZE 5
109 #define USBCPOWER_REG_GPIO_STATUS 0x72
110 #define USBCPOWER_GPIO_STATUS_REG_SIZE 9
111  // usbcpower_reg
113 
128 #define USBCPOWER_CAP_POWER_ROLE_M 0x03
129 #define USBCPOWER_CAP_USBPD_CAP_M 0x04
130 #define USBCPOWER_CAP_I2CMLEVEL_VOLT_M 0x80
131 
136 #define USBCPOWER_STATUS_PLUG_PRESENT_M 0x01
137 #define USBCPOWER_STATUS_CONN_STATE_M 0x0E
138 #define USBCPOWER_STATUS_PLUG_OR_M 0x10
139 #define USBCPOWER_STATUS_PORT_ROLE_M 0x20
140 #define USBCPOWER_STATUS_DATA_ROLE_M 0x40
141 #define USBCPOWER_STATUS_VBUS_STATUS_M 0x30
142 #define USBCPOWER_STATUS_USB_HOST_PRSNT_M 0xC0
143 #define USBCPOWER_STATUS_ACT_LEGACY_M 0x03
144 #define USBCPOWER_STATUS_BIST_M 0x08
145 
150 #define USBCPOWER_RSP_OK 0x00
151 #define USBCPOWER_RSP_PBMs "PBMs"
152 #define USBCPOWER_RSP_PTCH "PTCH"
153 #define USBCPOWER_RSP_APP "APP "
154 #define USBCPOWER_RSP_BOOT "BOOT"
155 #define USBCPOWER_RSP_DEVICE_INFO_NAME "TPS65992"
156 
161 #define USBCPOWER_CMD_SWSk "4SWSk"
162 #define USBCPOWER_CMD_SWSr "4SWSr"
163 #define USBCPOWER_CMD_SWDF "4SWDF"
164 #define USBCPOWER_CMD_SWUF "4SWUF"
165 #define USBCPOWER_CMD_GSkC "4GSkC"
166 #define USBCPOWER_CMD_GSrC "4GSrC"
167 #define USBCPOWER_CMD_SSrC "4SSrC"
168 #define USBCPOWER_CMD_PTCH "4PTCH"
169 #define USBCPOWER_CMD_GO2P "4GO2P"
170 #define USBCPOWER_CMD_PBMs "4PBMs"
171 #define USBCPOWER_CMD_PBMc "4PBMc"
172 #define USBCPOWER_CMD_PBMe "4PBMe"
173 
178 #define USBCPOWER_MODE_PTCH 0x00
179 #define USBCPOWER_MODE_APP 0x01
180 #define USBCPOWER_MODE_BOOT 0x02
181 #define USBCPOWER_MODE_UNKNOWN 0x03
182 #define USBCPOWER_PD_CON_MODE_SOURCE 0x00
183 #define USBCPOWER_PD_CON_MODE_SINK 0x01
184 #define USBCPOWER_PD_MODE_SELECTOR USBCPOWER_PD_CON_MODE_SOURCE
185 
190 #define USBCPOWER_STATUS_NO_CONNECTION 0x00
191 #define USBCPOWER_STATUS_PORT_DISABLED 0x01
192 #define USBCPOWER_STATUS_AUDIO_CONNECTION 0x02
193 #define USBCPOWER_STATUS_DEBUG_CONNECTION 0x03
194 #define USBCPOWER_STATUS_NO_CONNECTION_Ra 0x04
195 #define USBCPOWER_STATUS_RESERVED 0x05
196 #define USBCPOWER_STATUS_CONNECT_NO_Ra 0x06
197 #define USBCPOWER_PWR_STATUS_USB 0x00
198 #define USBCPOWER_PWR_STATUS_TYPE_C_1_5A 0x01
199 #define USBCPOWER_PWR_STATUS_TYPE_C_3_0A 0x02
200 #define USBCPOWER_PWR_STATUS_CHG_ADV_DISABLE 0x00
201 #define USBCPOWER_PWR_STATUS_CHG_ADV_PROCESS 0x01
202 #define USBCPOWER_PWR_STATUS_CHG_ADV_COMPLETE 0x02
203 
209 #define USBCPOWER_DEVICE_ADDRESS 0x21
210  // usbcpower_set
212 
227 #define USBCPOWER_MAP_MIKROBUS( cfg, mikrobus ) \
228  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
229  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
230  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
231  // usbcpower_map // usbcpower
234 
239 typedef struct
240 {
241  // Input pins
242  digital_in_t int_pin;
244  // Modules
245  i2c_master_t i2c;
247  // I2C slave address
248  uint8_t slave_address;
250 } usbcpower_t;
251 
256 typedef struct
257 {
258  pin_name_t scl;
259  pin_name_t sda;
261  pin_name_t int_pin;
263  uint32_t i2c_speed;
264  uint8_t i2c_address;
267 
273 typedef struct
274 {
275  uint32_t bundle_size;
277  uint8_t timeout_value;
278 
280 
285 typedef struct
286 {
287  uint8_t plug_present;
288  uint8_t conn_state;
290  uint8_t port_role;
291  uint8_t data_role;
292  uint8_t vbus_status;
295  uint8_t bist;
296 
298 
303 typedef struct
304 {
306  uint8_t pp1_switch;
307  uint8_t pp3_switch;
309  uint8_t pp_cable1_ovc;
310  uint8_t power_source;
311 
313 
318 typedef struct
319 {
324  uint8_t master_tsd;
326  uint8_t rev_id;
327 
329 
334 typedef struct
335 {
336  uint8_t num_src_pdos;
337  uint32_t source_pdo[ 8 ];
338  uint8_t num_sink_pdos;
339  uint32_t sink_pdo[ 8 ];
340 
342 
347 typedef struct
348 {
349  uint8_t pwr_conn;
350  uint8_t src_sink;
351  uint8_t type_c_current;
352  uint8_t charger_detect;
354 
356 
361 typedef struct
362 {
363  uint8_t cc_pull_up;
364  uint8_t port_type;
365  uint8_t pd_role;
366  uint8_t soft_rst_dets;
367  uint8_t hard_rst_dets;
368  uint8_t err_rec_dets;
369  uint8_t data_rst_dets;
370 
372 
373 
378 typedef enum
379 {
381  USBCPOWER_ERROR = -1
382 
384 
401 
416 
430 
445 err_t usbcpower_generic_write ( usbcpower_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
446 
461 err_t usbcpower_generic_read ( usbcpower_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
462 
477 err_t usbcpower_get_device_mode ( usbcpower_t *ctx, uint8_t *device_mode );
478 
493 err_t usbcpower_get_device_capabilities ( usbcpower_t *ctx, uint8_t *device_cap );
494 
510 err_t usbcpower_device_info ( usbcpower_t *ctx, uint8_t *device_info );
511 
527 err_t usbcpower_set_patch_mode ( usbcpower_t *ctx, uint32_t *response );
528 
549 err_t usbcpower_start_patch_burst_mode ( usbcpower_t *ctx, usbcpower_pbms_cfg_t pbms_cfg, uint32_t *response );
550 
569 err_t usbcpower_complete_patch_burst_mode ( usbcpower_t *ctx, uint32_t *response );
570 
587 err_t usbcpower_exit_patch_burst_mode ( usbcpower_t *ctx, uint32_t *response );
588 
607 err_t usbcpower_get_selected_mode ( usbcpower_t *ctx, uint8_t *sel_mode );
608 
630 
647 
664 
681 
698 
715 
732 
747 
748 #ifdef __cplusplus
749 }
750 #endif
751 #endif // USBCPOWER_H
752  // usbcpower
754 
755 // ------------------------------------------------------------------------ END
usbcpower_boot_status_t::rev_id
uint8_t rev_id
Definition: usbcpower.h:326
usbcpower_boot_status_t::master_tsd
uint8_t master_tsd
Definition: usbcpower.h:324
usbcpower_boot_status_t::patch_downloader
uint8_t patch_downloader
Definition: usbcpower.h:323
usbcpower_status_t::acting_as_legacy
uint8_t acting_as_legacy
Definition: usbcpower.h:294
usbcpower_device_info
err_t usbcpower_device_info(usbcpower_t *ctx, uint8_t *device_info)
USB-C Power device info function.
usbcpower_complete_patch_burst_mode
err_t usbcpower_complete_patch_burst_mode(usbcpower_t *ctx, uint32_t *response)
USB-C Power complete the patch burst mode function.
usbcpower_pd_status_t::pd_role
uint8_t pd_role
Definition: usbcpower.h:365
usbcpower_get_pwr_status
err_t usbcpower_get_pwr_status(usbcpower_t *ctx, usbcpower_pwr_status_t *pwr_status)
USB-C Power gets PWR status function.
usbcpower_cfg_t::sda
pin_name_t sda
Definition: usbcpower.h:259
usbcpower_pwr_status_t::type_c_current
uint8_t type_c_current
Definition: usbcpower.h:351
usbcpower_get_int_pin
uint8_t usbcpower_get_int_pin(usbcpower_t *ctx)
USB-C Power gets interrupt function.
usbcpower_get_device_mode
err_t usbcpower_get_device_mode(usbcpower_t *ctx, uint8_t *device_mode)
USB-C Power get device mode function.
usbcpower_pwr_path_status_t::pp_cable1_ovc
uint8_t pp_cable1_ovc
Definition: usbcpower.h:309
usbcpower_get_status
err_t usbcpower_get_status(usbcpower_t *ctx, usbcpower_status_t *status)
USB-C Power gets status function.
usbcpower_pd_status_t::port_type
uint8_t port_type
Definition: usbcpower.h:364
usbcpower_boot_status_t::dead_battery_flag
uint8_t dead_battery_flag
Definition: usbcpower.h:321
usbcpower_get_pd_status
err_t usbcpower_get_pd_status(usbcpower_t *ctx, usbcpower_pd_status_t *pd_status)
USB-C Power gets PD status function.
usbcpower_rx_caps_t
USB-C Power Click rx source/sink caps object.
Definition: usbcpower.h:335
usbcpower_generic_write
err_t usbcpower_generic_write(usbcpower_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
USB-C Power I2C writing function.
usbcpower_init
err_t usbcpower_init(usbcpower_t *ctx, usbcpower_cfg_t *cfg)
USB-C Power initialization function.
usbcpower_status_t::bist
uint8_t bist
Definition: usbcpower.h:295
usbcpower_pwr_status_t::charger_detect
uint8_t charger_detect
Definition: usbcpower.h:352
usbcpower_status_t::port_role
uint8_t port_role
Definition: usbcpower.h:290
usbcpower_pbms_cfg_t::eeprom_slave_address
uint8_t eeprom_slave_address
Definition: usbcpower.h:276
usbcpower_pwr_path_status_t
USB-C Power Click power path status object.
Definition: usbcpower.h:304
usbcpower_t::int_pin
digital_in_t int_pin
Definition: usbcpower.h:242
usbcpower_status_t::conn_state
uint8_t conn_state
Definition: usbcpower.h:288
usbcpower_boot_status_t
USB-C Power Click boot path status object.
Definition: usbcpower.h:319
usbcpower_pd_status_t
USB-C Power Click PD status object.
Definition: usbcpower.h:362
usbcpower_update_patch_bundle
err_t usbcpower_update_patch_bundle(usbcpower_t *ctx, usbcpower_pbms_cfg_t pbms_cfg)
USB-C Power update patch bundle function.
usbcpower_exit_patch_burst_mode
err_t usbcpower_exit_patch_burst_mode(usbcpower_t *ctx, uint32_t *response)
USB-C Power exit the patch burst mode function.
usbcpower_pd_status_t::hard_rst_dets
uint8_t hard_rst_dets
Definition: usbcpower.h:367
usbcpower_pd_status_t::data_rst_dets
uint8_t data_rst_dets
Definition: usbcpower.h:369
usbcpower_t::slave_address
uint8_t slave_address
Definition: usbcpower.h:248
usbcpower_return_value_t
usbcpower_return_value_t
USB-C Power Click return value data.
Definition: usbcpower.h:379
usbcpower_pwr_path_status_t::pp_cable1_switch
uint8_t pp_cable1_switch
Definition: usbcpower.h:305
usbcpower_status_t::plug_orientation
uint8_t plug_orientation
Definition: usbcpower.h:289
usbcpower_cfg_t::int_pin
pin_name_t int_pin
Definition: usbcpower.h:261
usbcpower_pbms_cfg_t
USB-C Power Click PBMs configuration object.
Definition: usbcpower.h:274
usbcpower_cfg_setup
void usbcpower_cfg_setup(usbcpower_cfg_t *cfg)
USB-C Power configuration object setup function.
usbcpower_start_patch_burst_mode
err_t usbcpower_start_patch_burst_mode(usbcpower_t *ctx, usbcpower_pbms_cfg_t pbms_cfg, uint32_t *response)
USB-C Power starts the patch burst mode function.
usbcpower_boot_status_t::i2c_eeprom_present
uint8_t i2c_eeprom_present
Definition: usbcpower.h:322
usbcpower_pwr_status_t::pwr_conn
uint8_t pwr_conn
Definition: usbcpower.h:349
usbcpower_rx_caps_t::num_src_pdos
uint8_t num_src_pdos
Definition: usbcpower.h:336
usbcpower_boot_status_t::patch_cfg_source
uint8_t patch_cfg_source
Definition: usbcpower.h:325
usbcpower_status_t::vbus_status
uint8_t vbus_status
Definition: usbcpower.h:292
usbcpower_get_rx_caps
err_t usbcpower_get_rx_caps(usbcpower_t *ctx, usbcpower_rx_caps_t *rx_caps)
USB-C Power gets RX caps function.
usbcpower_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: usbcpower.h:263
usbcpower_set_patch_mode
err_t usbcpower_set_patch_mode(usbcpower_t *ctx, uint32_t *response)
USB-C Power set patch mode function.
usbcpower_status_t::usb_hos_tpresent
uint8_t usb_hos_tpresent
Definition: usbcpower.h:293
usbcpower_status_t::data_role
uint8_t data_role
Definition: usbcpower.h:291
usbcpower_pwr_path_status_t::pp1_switch
uint8_t pp1_switch
Definition: usbcpower.h:306
usbcpower_boot_status_t::patch_header_err
uint8_t patch_header_err
Definition: usbcpower.h:320
usbcpower_get_selected_mode
err_t usbcpower_get_selected_mode(usbcpower_t *ctx, uint8_t *sel_mode)
USB-C Power gets selected mode function.
usbcpower_pd_status_t::err_rec_dets
uint8_t err_rec_dets
Definition: usbcpower.h:368
usbcpower_generic_read
err_t usbcpower_generic_read(usbcpower_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
USB-C Power I2C reading function.
usbcpower_status_t
USB-C Power Click status information object.
Definition: usbcpower.h:286
usbcpower_cfg_t::i2c_address
uint8_t i2c_address
Definition: usbcpower.h:264
usbcpower_pwr_path_status_t::pp1_overcurrent
uint8_t pp1_overcurrent
Definition: usbcpower.h:308
usbcpower_pwr_path_status_t::pp3_switch
uint8_t pp3_switch
Definition: usbcpower.h:307
usbcpower_cfg_t
USB-C Power Click configuration object.
Definition: usbcpower.h:257
usbcpower_pwr_status_t
USB-C Power Click power status object.
Definition: usbcpower.h:348
usbcpower_status_t::plug_present
uint8_t plug_present
Definition: usbcpower.h:287
usbcpower_t
USB-C Power Click context object.
Definition: usbcpower.h:240
usbcpower_pwr_status_t::charger_advertise
uint8_t charger_advertise
Definition: usbcpower.h:353
usbcpower_pd_status_t::cc_pull_up
uint8_t cc_pull_up
Definition: usbcpower.h:363
usbcpower_default_cfg
err_t usbcpower_default_cfg(usbcpower_t *ctx)
USB-C Power default configuration function.
usbcpower_get_boot_status
err_t usbcpower_get_boot_status(usbcpower_t *ctx, usbcpower_boot_status_t *boot_status)
USB-C Power gets boot status function.
usbcpower_pwr_status_t::src_sink
uint8_t src_sink
Definition: usbcpower.h:350
usbcpower_pd_status_t::soft_rst_dets
uint8_t soft_rst_dets
Definition: usbcpower.h:366
usbcpower_get_device_capabilities
err_t usbcpower_get_device_capabilities(usbcpower_t *ctx, uint8_t *device_cap)
USB-C Power get device capabilities function.
usbcpower_pbms_cfg_t::bundle_size
uint32_t bundle_size
Definition: usbcpower.h:275
usbcpower_get_pwr_path_status
err_t usbcpower_get_pwr_path_status(usbcpower_t *ctx, usbcpower_pwr_path_status_t *pp_status)
USB-C Power gets power path status function.
usbcpower_rx_caps_t::num_sink_pdos
uint8_t num_sink_pdos
Definition: usbcpower.h:338
USBCPOWER_OK
@ USBCPOWER_OK
Definition: usbcpower.h:380
usbcpower_pbms_cfg_t::timeout_value
uint8_t timeout_value
Definition: usbcpower.h:277
usbcpower_t::i2c
i2c_master_t i2c
Definition: usbcpower.h:245
usbcpower_cfg_t::scl
pin_name_t scl
Definition: usbcpower.h:258
usbcpower_pwr_path_status_t::power_source
uint8_t power_source
Definition: usbcpower.h:310
USBCPOWER_ERROR
@ USBCPOWER_ERROR
Definition: usbcpower.h:381