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
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define USBCPOWER_REG_MODE 0x03
74#define USBCPOWER_MODE_REG_SIZE 5
75#define USBCPOWER_REG_TYPE 0x04
76#define USBCPOWER_TYPE_REG_SIZE 5
77#define USBCPOWER_REG_CUSTUSE 0x06
78#define USBCPOWER_CUSTUSE_REG_SIZE 9
79#define USBCPOWER_REG_CMD1 0x08
80#define USBCPOWER_CMD1_REG_SIZE 5
81#define USBCPOWER_REG_DATA 0x09
82#define USBCPOWER_DATA_REG_SIZE 65
83#define USBCPOWER_REG_DEVICE_CAP 0x0D
84#define USBCPOWER_DEVICE_CAP_REG_SIZE 5
85#define USBCPOWER_REG_VERSION 0x0F
86#define USBCPOWER_VERSION_REG_SIZE 5
87#define USBCPOWER_REG_INT_EVENT1 0x14
88#define USBCPOWER_INT_EVENT1_REG_SIZE 15
89#define USBCPOWER_REG_INT_MASK1 0x16
90#define USBCPOWER_INT_MASK1_REG_SIZE 12
91#define USBCPOWER_REG_INT_CLEAR1 0x18
92#define USBCPOWER_INT_CLEAR1_REG_SIZE 12
93#define USBCPOWER_REG_STATUS 0x1A
94#define USBCPOWER_STATUS_REG_SIZE 6
95#define USBCPOWER_REG_POWER_PATH_STATUS 0x26
96#define USBCPOWER_POWER_PATH_STATUS_REG_SIZE 6
97#define USBCPOWER_REG_PORT_CONTROL 0x29
98#define USBCPOWER_PORT_CONTROL_REG_SIZE 5
99#define USBCPOWER_REG_BOOT_STATUS 0x2D
100#define USBCPOWER_BOOT_STATUS_REG_SIZE 6
101#define USBCPOWER_REG_BUILD_DESC 0x2E
102#define USBCPOWER_BUILD_DESC_SIZE 50
103#define USBCPOWER_REG_DEVICE_INFO 0x2F
104#define USBCPOWER_DEVICE_INFO_REG_SIZE 41
105#define USBCPOWER_REG_RX_SOURCE_CAPS 0x30
106#define USBCPOWER_RX_SOURCE_CAPS_REG_SIZE 30
107#define USBCPOWER_REG_RX_SINK_CAPS 0x31
108#define USBCPOWER_RX_SINK_CAPS_REG_SIZE 30
109#define USBCPOWER_REG_TX_SOURCE_CAPS 0x32
110#define USBCPOWER_TX_SOURCE_CAPS_REG_SIZE 32
111#define USBCPOWER_REG_TX_SINK_CAPS 0x33
112#define USBCPOWER_TX_SINK_CAPS_REG_SIZE 30
113#define USBCPOWER_REG_ACTIVE_CONTRACT_PDO 0x34
114#define USBCPOWER_ACTIVE_CONTRACT_PDO_REG_SIZE 7
115#define USBCPOWER_REG_ACTIVE_CONTRACT_RDO 0x35
116#define USBCPOWER_ACTIVE_CONTRACT_RDO_REG_SIZE 5
117#define USBCPOWER_REG_POWER_STATUS 0x3F
118#define USBCPOWER_POWER_STATUS_REG_SIZE 3
119#define USBCPOWER_REG_PD_STATUS 0x40
120#define USBCPOWER_PD_STATUS_REG_SIZE 5
121#define USBCPOWER_REG_TYPEC_STATE 0x69
122#define USBCPOWER_TYPEC_STATE_REG_SIZE 5
123#define USBCPOWER_REG_GPIO_STATUS 0x72
124#define USBCPOWER_GPIO_STATUS_REG_SIZE 9
125
126 // usbcpower_reg
127
142#define USBCPOWER_CAP_POWER_ROLE_M 0x03
143#define USBCPOWER_CAP_USBPD_CAP_M 0x04
144#define USBCPOWER_CAP_I2CMLEVEL_VOLT_M 0x80
145
150#define USBCPOWER_STATUS_PLUG_PRESENT_M 0x01
151#define USBCPOWER_STATUS_CONN_STATE_M 0x0E
152#define USBCPOWER_STATUS_PLUG_OR_M 0x10
153#define USBCPOWER_STATUS_PORT_ROLE_M 0x20
154#define USBCPOWER_STATUS_DATA_ROLE_M 0x40
155#define USBCPOWER_STATUS_VBUS_STATUS_M 0x30
156#define USBCPOWER_STATUS_USB_HOST_PRSNT_M 0xC0
157#define USBCPOWER_STATUS_ACT_LEGACY_M 0x03
158#define USBCPOWER_STATUS_BIST_M 0x08
159
164#define USBCPOWER_RSP_OK 0x00
165#define USBCPOWER_RSP_PBMs "PBMs"
166#define USBCPOWER_RSP_PTCH "PTCH"
167#define USBCPOWER_RSP_APP "APP "
168#define USBCPOWER_RSP_BOOT "BOOT"
169#define USBCPOWER_RSP_DEVICE_INFO_NAME "TPS65992"
170
175#define USBCPOWER_CMD_SWSk "4SWSk"
176#define USBCPOWER_CMD_SWSr "4SWSr"
177#define USBCPOWER_CMD_SWDF "4SWDF"
178#define USBCPOWER_CMD_SWUF "4SWUF"
179#define USBCPOWER_CMD_GSkC "4GSkC"
180#define USBCPOWER_CMD_GSrC "4GSrC"
181#define USBCPOWER_CMD_SSrC "4SSrC"
182#define USBCPOWER_CMD_PTCH "4PTCH"
183#define USBCPOWER_CMD_GO2P "4GO2P"
184#define USBCPOWER_CMD_PBMs "4PBMs"
185#define USBCPOWER_CMD_PBMc "4PBMc"
186#define USBCPOWER_CMD_PBMe "4PBMe"
187
192#define USBCPOWER_MODE_PTCH 0x00
193#define USBCPOWER_MODE_APP 0x01
194#define USBCPOWER_MODE_BOOT 0x02
195#define USBCPOWER_MODE_UNKNOWN 0x03
196#define USBCPOWER_PD_CON_MODE_SOURCE 0x00
197#define USBCPOWER_PD_CON_MODE_SINK 0x01
198#define USBCPOWER_PD_MODE_SELECTOR USBCPOWER_PD_CON_MODE_SOURCE
199
204#define USBCPOWER_STATUS_NO_CONNECTION 0x00
205#define USBCPOWER_STATUS_PORT_DISABLED 0x01
206#define USBCPOWER_STATUS_AUDIO_CONNECTION 0x02
207#define USBCPOWER_STATUS_DEBUG_CONNECTION 0x03
208#define USBCPOWER_STATUS_NO_CONNECTION_Ra 0x04
209#define USBCPOWER_STATUS_RESERVED 0x05
210#define USBCPOWER_STATUS_CONNECT_NO_Ra 0x06
211#define USBCPOWER_PWR_STATUS_USB 0x00
212#define USBCPOWER_PWR_STATUS_TYPE_C_1_5A 0x01
213#define USBCPOWER_PWR_STATUS_TYPE_C_3_0A 0x02
214#define USBCPOWER_PWR_STATUS_CHG_ADV_DISABLE 0x00
215#define USBCPOWER_PWR_STATUS_CHG_ADV_PROCESS 0x01
216#define USBCPOWER_PWR_STATUS_CHG_ADV_COMPLETE 0x02
217
223#define USBCPOWER_DEVICE_ADDRESS 0x21
224
225 // usbcpower_set
226
241#define USBCPOWER_MAP_MIKROBUS( cfg, mikrobus ) \
242 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
243 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
244 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
245
246 // usbcpower_map
247 // usbcpower
248
253typedef struct
254{
255 // Input pins
256 digital_in_t int_pin;
258 // Modules
259 i2c_master_t i2c;
261 // I2C slave address
265
270typedef struct
271{
272 pin_name_t scl;
273 pin_name_t sda;
275 pin_name_t int_pin;
277 uint32_t i2c_speed;
278 uint8_t i2c_address;
281
287typedef struct
288{
289 uint32_t bundle_size;
292
294
299typedef struct
300{
302 uint8_t conn_state;
304 uint8_t port_role;
305 uint8_t data_role;
306 uint8_t vbus_status;
309 uint8_t bist;
310
312
317typedef struct
318{
320 uint8_t pp1_switch;
321 uint8_t pp3_switch;
325
327
343
348typedef struct
349{
351 uint32_t source_pdo[ 8 ];
353 uint32_t sink_pdo[ 8 ];
354
356
361typedef struct
362{
363 uint8_t pwr_conn;
364 uint8_t src_sink;
368
370
375typedef struct
376{
377 uint8_t cc_pull_up;
378 uint8_t port_type;
379 uint8_t pd_role;
384
386
387
398
415
430
444
459err_t usbcpower_generic_write ( usbcpower_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
460
475err_t usbcpower_generic_read ( usbcpower_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
476
491err_t usbcpower_get_device_mode ( usbcpower_t *ctx, uint8_t *device_mode );
492
507err_t usbcpower_get_device_capabilities ( usbcpower_t *ctx, uint8_t *device_cap );
508
524err_t usbcpower_device_info ( usbcpower_t *ctx, uint8_t *device_info );
525
541err_t usbcpower_set_patch_mode ( usbcpower_t *ctx, uint32_t *response );
542
563err_t usbcpower_start_patch_burst_mode ( usbcpower_t *ctx, usbcpower_pbms_cfg_t pbms_cfg, uint32_t *response );
564
583err_t usbcpower_complete_patch_burst_mode ( usbcpower_t *ctx, uint32_t *response );
584
601err_t usbcpower_exit_patch_burst_mode ( usbcpower_t *ctx, uint32_t *response );
602
621err_t usbcpower_get_selected_mode ( usbcpower_t *ctx, uint8_t *sel_mode );
622
644
661
678
695
712
729
746
761
762#ifdef __cplusplus
763}
764#endif
765#endif // USBCPOWER_H
766
767 // usbcpower
768
769// ------------------------------------------------------------------------ END
err_t usbcpower_get_pd_status(usbcpower_t *ctx, usbcpower_pd_status_t *pd_status)
USB-C Power gets PD status function.
err_t usbcpower_update_patch_bundle(usbcpower_t *ctx, usbcpower_pbms_cfg_t pbms_cfg)
USB-C Power update patch bundle function.
err_t usbcpower_init(usbcpower_t *ctx, usbcpower_cfg_t *cfg)
USB-C Power initialization function.
err_t usbcpower_get_pwr_status(usbcpower_t *ctx, usbcpower_pwr_status_t *pwr_status)
USB-C Power gets PWR status function.
uint8_t usbcpower_get_int_pin(usbcpower_t *ctx)
USB-C Power gets interrupt function.
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.
err_t usbcpower_exit_patch_burst_mode(usbcpower_t *ctx, uint32_t *response)
USB-C Power exit the patch burst mode function.
err_t usbcpower_get_device_mode(usbcpower_t *ctx, uint8_t *device_mode)
USB-C Power get device mode function.
void usbcpower_cfg_setup(usbcpower_cfg_t *cfg)
USB-C Power configuration object setup function.
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.
err_t usbcpower_get_rx_caps(usbcpower_t *ctx, usbcpower_rx_caps_t *rx_caps)
USB-C Power gets RX caps function.
err_t usbcpower_device_info(usbcpower_t *ctx, uint8_t *device_info)
USB-C Power device info function.
err_t usbcpower_get_boot_status(usbcpower_t *ctx, usbcpower_boot_status_t *boot_status)
USB-C Power gets boot status function.
err_t usbcpower_get_device_capabilities(usbcpower_t *ctx, uint8_t *device_cap)
USB-C Power get device capabilities function.
err_t usbcpower_default_cfg(usbcpower_t *ctx)
USB-C Power default configuration function.
err_t usbcpower_generic_read(usbcpower_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
USB-C Power I2C reading function.
err_t usbcpower_set_patch_mode(usbcpower_t *ctx, uint32_t *response)
USB-C Power set patch mode function.
err_t usbcpower_complete_patch_burst_mode(usbcpower_t *ctx, uint32_t *response)
USB-C Power complete the patch burst mode function.
err_t usbcpower_generic_write(usbcpower_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
USB-C Power I2C writing function.
err_t usbcpower_get_selected_mode(usbcpower_t *ctx, uint8_t *sel_mode)
USB-C Power gets selected mode function.
err_t usbcpower_get_status(usbcpower_t *ctx, usbcpower_status_t *status)
USB-C Power gets status function.
USB-C Power Click boot path status object.
Definition usbcpower.h:333
uint8_t dead_battery_flag
Definition usbcpower.h:335
uint8_t master_tsd
Definition usbcpower.h:338
uint8_t rev_id
Definition usbcpower.h:340
uint8_t i2c_eeprom_present
Definition usbcpower.h:336
uint8_t patch_cfg_source
Definition usbcpower.h:339
uint8_t patch_header_err
Definition usbcpower.h:334
uint8_t patch_downloader
Definition usbcpower.h:337
USB-C Power Click configuration object.
Definition usbcpower.h:271
uint32_t i2c_speed
Definition usbcpower.h:277
pin_name_t scl
Definition usbcpower.h:272
pin_name_t int_pin
Definition usbcpower.h:275
pin_name_t sda
Definition usbcpower.h:273
uint8_t i2c_address
Definition usbcpower.h:278
USB-C Power Click PBMs configuration object.
Definition usbcpower.h:288
uint32_t bundle_size
Definition usbcpower.h:289
uint8_t timeout_value
Definition usbcpower.h:291
uint8_t eeprom_slave_address
Definition usbcpower.h:290
USB-C Power Click PD status object.
Definition usbcpower.h:376
uint8_t port_type
Definition usbcpower.h:378
uint8_t hard_rst_dets
Definition usbcpower.h:381
uint8_t data_rst_dets
Definition usbcpower.h:383
uint8_t err_rec_dets
Definition usbcpower.h:382
uint8_t pd_role
Definition usbcpower.h:379
uint8_t cc_pull_up
Definition usbcpower.h:377
uint8_t soft_rst_dets
Definition usbcpower.h:380
USB-C Power Click power path status object.
Definition usbcpower.h:318
uint8_t power_source
Definition usbcpower.h:324
uint8_t pp3_switch
Definition usbcpower.h:321
uint8_t pp_cable1_switch
Definition usbcpower.h:319
uint8_t pp1_switch
Definition usbcpower.h:320
uint8_t pp_cable1_ovc
Definition usbcpower.h:323
uint8_t pp1_overcurrent
Definition usbcpower.h:322
USB-C Power Click power status object.
Definition usbcpower.h:362
uint8_t charger_detect
Definition usbcpower.h:366
uint8_t src_sink
Definition usbcpower.h:364
uint8_t charger_advertise
Definition usbcpower.h:367
uint8_t pwr_conn
Definition usbcpower.h:363
uint8_t type_c_current
Definition usbcpower.h:365
USB-C Power Click rx source/sink caps object.
Definition usbcpower.h:349
uint8_t num_sink_pdos
Definition usbcpower.h:352
uint8_t num_src_pdos
Definition usbcpower.h:350
USB-C Power Click status information object.
Definition usbcpower.h:300
uint8_t data_role
Definition usbcpower.h:305
uint8_t usb_hos_tpresent
Definition usbcpower.h:307
uint8_t plug_present
Definition usbcpower.h:301
uint8_t vbus_status
Definition usbcpower.h:306
uint8_t acting_as_legacy
Definition usbcpower.h:308
uint8_t port_role
Definition usbcpower.h:304
uint8_t bist
Definition usbcpower.h:309
uint8_t plug_orientation
Definition usbcpower.h:303
uint8_t conn_state
Definition usbcpower.h:302
USB-C Power Click context object.
Definition usbcpower.h:254
digital_in_t int_pin
Definition usbcpower.h:256
i2c_master_t i2c
Definition usbcpower.h:259
uint8_t slave_address
Definition usbcpower.h:262
usbcpower_return_value_t
USB-C Power Click return value data.
Definition usbcpower.h:393
@ USBCPOWER_ERROR
Definition usbcpower.h:395
@ USBCPOWER_OK
Definition usbcpower.h:394