LibDriver PCA9548A
Loading...
Searching...
No Matches
driver_pca9548a_register_test.c
Go to the documentation of this file.
1
36
38
39static pca9548a_handle_t gs_handle;
40
50{
51 uint8_t res;
52 uint8_t i;
53 pca9548a_bool_t enable;
54 pca9548a_info_t info;
55
56 /* link functions */
71
72 /* pca9548a info */
73 res = pca9548a_info(&info);
74 if (res != 0)
75 {
76 pca9548a_interface_debug_print("pca9548a: get info failed.\n");
77
78 return 1;
79 }
80 else
81 {
82 /* print chip information */
83 pca9548a_interface_debug_print("pca9548a: chip is %s.\n", info.chip_name);
84 pca9548a_interface_debug_print("pca9548a: manufacturer is %s.\n", info.manufacturer_name);
85 pca9548a_interface_debug_print("pca9548a: interface is %s.\n", info.interface);
86 pca9548a_interface_debug_print("pca9548a: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
87 pca9548a_interface_debug_print("pca9548a: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
88 pca9548a_interface_debug_print("pca9548a: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
89 pca9548a_interface_debug_print("pca9548a: max current is %0.2fmA.\n", info.max_current_ma);
90 pca9548a_interface_debug_print("pca9548a: max temperature is %0.1fC.\n", info.temperature_max);
91 pca9548a_interface_debug_print("pca9548a: min temperature is %0.1fC.\n", info.temperature_min);
92 }
93
94 /* set addr pin */
95 res = pca9548a_set_addr_pin(&gs_handle, addr);
96 if (res != 0)
97 {
98 pca9548a_interface_debug_print("pca9548a: set addr pin failed.\n");
99
100 return 1;
101 }
102
103 /* start register test */
104 pca9548a_interface_debug_print("pca9548a: start register test.\n");
105
106 /* pca9548a init */
107 res = pca9548a_init(&gs_handle);
108 if (res != 0)
109 {
110 pca9548a_interface_debug_print("pca9548a: init failed.\n");
111
112 return 1;
113 }
114
115 /* pca9548a_set_channel/pca9548a_get_channel test */
116 pca9548a_interface_debug_print("pca9548a: pca9548a_set_channel/pca9548a_get_channel test.\n");
117
118 for (i = 0; i < 8; i++)
119 {
120 pca9548a_channel_t channel;
121
122 if (i == 0)
123 {
124 channel = PCA9548A_CHANNEL_0;
125 }
126 else if (i == 1)
127 {
128 channel = PCA9548A_CHANNEL_1;
129 }
130 else if (i == 2)
131 {
132 channel = PCA9548A_CHANNEL_2;
133 }
134 else if (i == 3)
135 {
136 channel = PCA9548A_CHANNEL_3;
137 }
138 else if (i == 4)
139 {
140 channel = PCA9548A_CHANNEL_4;
141 }
142 else if (i == 5)
143 {
144 channel = PCA9548A_CHANNEL_5;
145 }
146 else if (i == 6)
147 {
148 channel = PCA9548A_CHANNEL_6;
149 }
150 else
151 {
152 channel = PCA9548A_CHANNEL_7;
153 }
154
155 /* enable channel x */
156 res = pca9548a_set_channel(&gs_handle, channel, PCA9548A_BOOL_TRUE);
157 if (res != 0)
158 {
159 pca9548a_interface_debug_print("pca9548a: set channel failed.\n");
160 (void)pca9548a_deinit(&gs_handle);
161
162 return 1;
163 }
164 pca9548a_interface_debug_print("pca9548a: enable channel %d.\n", i);
165 res = pca9548a_get_channel(&gs_handle, channel, &enable);
166 if (res != 0)
167 {
168 pca9548a_interface_debug_print("pca9548a: get channel failed.\n");
169 (void)pca9548a_deinit(&gs_handle);
170
171 return 1;
172 }
173 pca9548a_interface_debug_print("pca9548a: check channel %s.\n", (enable == PCA9548A_BOOL_TRUE) ? "ok" : "error");
174
175 /* disable channel x */
176 res = pca9548a_set_channel(&gs_handle, channel, PCA9548A_BOOL_FALSE);
177 if (res != 0)
178 {
179 pca9548a_interface_debug_print("pca9548a: set channel failed.\n");
180 (void)pca9548a_deinit(&gs_handle);
181
182 return 1;
183 }
184 pca9548a_interface_debug_print("pca9548a: disable channel %d.\n", i);
185 res = pca9548a_get_channel(&gs_handle, channel, &enable);
186 if (res != 0)
187 {
188 pca9548a_interface_debug_print("pca9548a: get channel failed.\n");
189 (void)pca9548a_deinit(&gs_handle);
190
191 return 1;
192 }
193 pca9548a_interface_debug_print("pca9548a: check channel %s.\n", (enable == PCA9548A_BOOL_FALSE) ? "ok" : "error");
194 }
195
196 /* pca9548a_reset_bus test */
197 pca9548a_interface_debug_print("pca9548a: pca9548a_reset_bus test.\n");
198
199 /* reset bus */
200 res = pca9548a_reset_bus(&gs_handle);
201 if (res != 0)
202 {
203 pca9548a_interface_debug_print("pca9548a: reset bus failed.\n");
204 (void)pca9548a_deinit(&gs_handle);
205
206 return 1;
207 }
208 pca9548a_interface_debug_print("pca9548a: check reset bus %s.\n", (res == 0) ? "ok" : "error");
209
210 /* finish register test */
211 pca9548a_interface_debug_print("pca9548a: finish register test.\n");
212 (void)pca9548a_deinit(&gs_handle);
213
214 return 0;
215}
driver pca9548a register test header file
uint8_t pca9548a_get_channel(pca9548a_handle_t *handle, pca9548a_channel_t channel, pca9548a_bool_t *enable)
get channel
uint8_t pca9548a_set_channel(pca9548a_handle_t *handle, pca9548a_channel_t channel, pca9548a_bool_t enable)
set channel
uint8_t pca9548a_init(pca9548a_handle_t *handle)
initialize the chip
uint8_t pca9548a_reset_bus(pca9548a_handle_t *handle)
reset bus
pca9548a_channel_t
pca9548a channel enumeration definition
pca9548a_address_t
pca9548a address enumeration definition
uint8_t pca9548a_set_addr_pin(pca9548a_handle_t *handle, pca9548a_address_t addr_pin)
set the address pin
struct pca9548a_info_s pca9548a_info_t
pca9548a information structure definition
pca9548a_bool_t
pca9548a bool enumeration definition
uint8_t pca9548a_info(pca9548a_info_t *info)
get chip's information
uint8_t pca9548a_deinit(pca9548a_handle_t *handle)
close the chip
struct pca9548a_handle_s pca9548a_handle_t
pca9548a handle structure definition
@ PCA9548A_CHANNEL_0
@ PCA9548A_CHANNEL_1
@ PCA9548A_CHANNEL_2
@ PCA9548A_CHANNEL_3
@ PCA9548A_CHANNEL_7
@ PCA9548A_CHANNEL_4
@ PCA9548A_CHANNEL_5
@ PCA9548A_CHANNEL_6
@ PCA9548A_BOOL_FALSE
@ PCA9548A_BOOL_TRUE
void pca9548a_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t pca9548a_interface_reset_gpio_write(uint8_t level)
interface reset gpio write
uint8_t pca9548a_interface_iic_deinit(void)
interface iic bus deinit
uint8_t pca9548a_interface_iic_init(void)
interface iic bus init
uint8_t pca9548a_interface_iic_read_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus read with 16 bits register address
uint8_t pca9548a_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command
uint8_t pca9548a_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
uint8_t pca9548a_interface_reset_gpio_deinit(void)
interface reset gpio deinit
uint8_t pca9548a_interface_reset_gpio_init(void)
interface reset gpio init
void pca9548a_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t pca9548a_interface_iic_write_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus write with 16 bits register address
uint8_t pca9548a_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t pca9548a_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t pca9548a_register_test(pca9548a_address_t addr)
register test
char manufacturer_name[32]