1 /*
2  * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3  */
4 
5 #include <stdint.h>
6 /*#include "aos/i2c.h"*/
7 #include "pca9544.h"
8 #if AOS_COMP_CLI
9 #include "aos/cli.h"
10 #endif
11 
pca9544_comp_example(int argc,char ** argv)12 static void pca9544_comp_example(int argc, char **argv)
13 {
14     (void)argc;
15     (void)argv;
16 
17     int          ret;
18     uint8_t      data[7]     = { 8, 25, 18, 7, 3, 1, 21 };
19     uint8_t      data_rtn[7] = { 0 };
20     uint16_t     size        = 7;
21     PCA9544_CH_E test_chan   = PCA9544_CH1;
22     PCA9544_CH_E read_chan   = PCA9544_CH_NULL;
23     uint8_t      reg_rtn;
24     uint8_t      chan_mask = 0x05;
25 
26     i2c_dev_t         i2c;
27     PCA9544_DEV_CFG_T dev_cfg;
28 
29     dev_cfg.dev_addr    = PCA9544_BASE_ADDR;
30     dev_cfg.pca9544_ch  = test_chan;
31     dev_cfg.subdev_addr = 0x32;
32     dev_cfg.reg_addr    = 0x10;
33 
34     i2c.port                 = 1;
35     i2c.config.address_width = 8;
36     i2c.config.freq          = I2C_BUS_BIT_RATES_100K;
37     i2c.config.dev_addr      = dev_cfg.dev_addr;
38 
39     ret = pca9544_init(&i2c, &dev_cfg);
40     if (ret) {
41         printf("=====I2C Muxer PCA9544 test: init fail =====\r\n");
42         return -1;
43     }
44 
45     /* chan select */
46     printf("=====I2C Muxer PCA9544 test: set chan 2[%d] of PCA9544=====\r\n", test_chan);
47     ret = pca9544_set_chan(test_chan);
48 
49     /*aos_sleep(2);*/
50 
51     read_chan = pca9544_read_chan();
52 
53     printf("=====I2C Muxer PCA9544 test: read chan val of PCA9544 is %d=====\r\n", read_chan);
54 
55     /*aos_sleep(2);*/
56     if (test_chan == read_chan) {
57         printf("=====I2C Muxer PCA9544 test: PCA9544 test:  PASS=====\r\n");
58     } else {
59         printf("=====I2C Muxer PCA9544 test: PCA9544 test:  FAIL=====\r\n");
60         pca9544_deinit();
61         ret = -1;
62     }
63 
64     pca9544_deinit();
65     printf("pca9544 comp test success!\r\n");
66     return;
67 }
68 
69 #if AOS_COMP_CLI
70 /* reg args: fun, cmd, description*/
71 ALIOS_CLI_CMD_REGISTER(pca9544_comp_example, pca9544_example, pca9544 component example)
72 #endif
73