LibDriver X9CXX
Loading...
Searching...
No Matches
driver_x9cxx_output_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static x9cxx_handle_t gs_handle;
41
52uint8_t x9cxx_output_test(x9cxx_type_t type, x9cxx_bool_t store_enable, uint32_t times)
53{
54 uint8_t res;
55 uint8_t counter;
56 uint8_t step;
57 uint32_t i;
58 float ohm;
59 float ohm_check;
60 x9cxx_info_t info;
61
62 /* link functions */
76
77 /* x9cxx info */
78 res = x9cxx_info(&info);
79 if (res != 0)
80 {
81 x9cxx_interface_debug_print("x9cxx: get info failed.\n");
82
83 return 1;
84 }
85 else
86 {
87 /* print chip information */
88 x9cxx_interface_debug_print("x9cxx: chip is %s.\n", info.chip_name);
89 x9cxx_interface_debug_print("x9cxx: manufacturer is %s.\n", info.manufacturer_name);
90 x9cxx_interface_debug_print("x9cxx: interface is %s.\n", info.interface);
91 x9cxx_interface_debug_print("x9cxx: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
92 x9cxx_interface_debug_print("x9cxx: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
93 x9cxx_interface_debug_print("x9cxx: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
94 x9cxx_interface_debug_print("x9cxx: max current is %0.2fmA.\n", info.max_current_ma);
95 x9cxx_interface_debug_print("x9cxx: max temperature is %0.1fC.\n", info.temperature_max);
96 x9cxx_interface_debug_print("x9cxx: min temperature is %0.1fC.\n", info.temperature_min);
97 }
98
99 /* start output test */
100 x9cxx_interface_debug_print("x9cxx: start output test.\n");
101
102 /* set chip type */
103 res = x9cxx_set_type(&gs_handle, type);
104 if (res != 0)
105 {
106 x9cxx_interface_debug_print("x9cxx: set type failed.\n");
107
108 return 1;
109 }
110
111 /* x9cxx init */
112 res = x9cxx_init(&gs_handle);
113 if (res != 0)
114 {
115 x9cxx_interface_debug_print("x9cxx: init failed.\n");
116
117 return 1;
118 }
119
120 /* reset to min */
121 res = x9cxx_reset_to_min(&gs_handle, store_enable);
122 if (res != 0)
123 {
124 x9cxx_interface_debug_print("x9cxx: reset to min failed.\n");
125 (void)x9cxx_deinit(&gs_handle);
126
127 return 1;
128 }
129
130 for (i = 0; i < times; i++)
131 {
132 /* increment */
133 res = x9cxx_increment(&gs_handle, 1, store_enable);
134 if (res != 0)
135 {
136 x9cxx_interface_debug_print("x9cxx: increment failed.\n");
137 (void)x9cxx_deinit(&gs_handle);
138
139 return 1;
140 }
141
142 /* get step counter */
143 res = x9cxx_get_step_counter(&gs_handle, &counter);
144 if (res != 0)
145 {
146 x9cxx_interface_debug_print("x9cxx: get step counter failed.\n");
147 (void)x9cxx_deinit(&gs_handle);
148
149 return 1;
150 }
151
152 /* output */
153 x9cxx_interface_debug_print("x9cxx: increment and current step counter is %d.\n", counter);
154
155 /* 5000ms */
157 }
158
159 /* reset to max */
160 res = x9cxx_reset_to_max(&gs_handle, store_enable);
161 if (res != 0)
162 {
163 x9cxx_interface_debug_print("x9cxx: reset to max failed.\n");
164 (void)x9cxx_deinit(&gs_handle);
165
166 return 1;
167 }
168
169 for (i = 0; i < times; i++)
170 {
171 /* decrement */
172 res = x9cxx_decrement(&gs_handle, 1, store_enable);
173 if (res != 0)
174 {
175 x9cxx_interface_debug_print("x9cxx: decrement failed.\n");
176 (void)x9cxx_deinit(&gs_handle);
177
178 return 1;
179 }
180
181 /* get step counter */
182 res = x9cxx_get_step_counter(&gs_handle, &counter);
183 if (res != 0)
184 {
185 x9cxx_interface_debug_print("x9cxx: get step counter failed.\n");
186 (void)x9cxx_deinit(&gs_handle);
187
188 return 1;
189 }
190
191 /* output */
192 x9cxx_interface_debug_print("x9cxx: decrement and current step counter is %d.\n", counter);
193
194 /* 5000ms */
196 }
197
198 counter = rand() % 100;
199 res = x9cxx_set_absolute_step_counter(&gs_handle, counter, store_enable);
200 if (res != 0)
201 {
202 x9cxx_interface_debug_print("x9cxx: set absolute step counter failed.\n");
203 (void)x9cxx_deinit(&gs_handle);
204
205 return 1;
206 }
207 x9cxx_interface_debug_print("x9cxx: set absolute step counter %d.\n", counter);
208
209 /* resistor convert to register */
210 ohm = (float)(rand() % 1000) / 10.0f;
211 res = x9cxx_resistor_convert_to_register(&gs_handle, ohm, &step);
212 if (res != 0)
213 {
214 x9cxx_interface_debug_print("x9cxx: resistor convert to register failed.\n");
215 (void)x9cxx_deinit(&gs_handle);
216
217 return 1;
218 }
219 res = x9cxx_resistor_convert_to_data(&gs_handle, step, &ohm_check);
220 if (res != 0)
221 {
222 x9cxx_interface_debug_print("x9cxx: resistor convert to data failed.\n");
223 (void)x9cxx_deinit(&gs_handle);
224
225 return 1;
226 }
227 x9cxx_interface_debug_print("x9cxx: ohm is %0.2f and converted ohm is %0.2f.\n", ohm, ohm_check);
228
229 /* finish output test */
230 x9cxx_interface_debug_print("x9cxx: finish output test.\n");
231 (void)x9cxx_deinit(&gs_handle);
232
233 return 0;
234}
driver x9cxx output test header file
struct x9cxx_handle_s x9cxx_handle_t
x9cxx handle structure definition
uint8_t x9cxx_set_absolute_step_counter(x9cxx_handle_t *handle, uint8_t counter, x9cxx_bool_t store_enable)
set absolute step counter
uint8_t x9cxx_increment(x9cxx_handle_t *handle, uint8_t step, x9cxx_bool_t store_enable)
increment
struct x9cxx_info_s x9cxx_info_t
x9cxx information structure definition
uint8_t x9cxx_set_type(x9cxx_handle_t *handle, x9cxx_type_t type)
set chip type
x9cxx_type_t
x9cxx type enumeration definition
uint8_t x9cxx_get_step_counter(x9cxx_handle_t *handle, uint8_t *counter)
get step counter
uint8_t x9cxx_decrement(x9cxx_handle_t *handle, uint8_t step, x9cxx_bool_t store_enable)
decrement
uint8_t x9cxx_resistor_convert_to_register(x9cxx_handle_t *handle, float ohm, uint8_t *step)
resistor convert to register
uint8_t x9cxx_reset_to_min(x9cxx_handle_t *handle, x9cxx_bool_t store_enable)
reset to min
x9cxx_bool_t
x9cxx bool enumeration definition
uint8_t x9cxx_info(x9cxx_info_t *info)
get chip's information
uint8_t x9cxx_init(x9cxx_handle_t *handle)
initialize the chip
uint8_t x9cxx_resistor_convert_to_data(x9cxx_handle_t *handle, uint8_t step, float *ohm)
resistor convert to data
uint8_t x9cxx_reset_to_max(x9cxx_handle_t *handle, x9cxx_bool_t store_enable)
reset to max
uint8_t x9cxx_deinit(x9cxx_handle_t *handle)
close the chip
void x9cxx_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t x9cxx_interface_inc_gpio_init(void)
interface inc gpio init
uint8_t x9cxx_interface_cs_gpio_write(uint8_t value)
interface cs gpio write
uint8_t x9cxx_interface_cs_gpio_init(void)
interface cs gpio init
uint8_t x9cxx_interface_inc_gpio_deinit(void)
interface inc gpio deinit
uint8_t x9cxx_interface_up_down_gpio_write(uint8_t value)
interface up down gpio write
uint8_t x9cxx_interface_up_down_gpio_deinit(void)
interface up down gpio deinit
void x9cxx_interface_delay_us(uint32_t us)
interface delay us
uint8_t x9cxx_interface_up_down_gpio_init(void)
interface up down gpio init
uint8_t x9cxx_interface_inc_gpio_write(uint8_t value)
interface inc gpio write
void x9cxx_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t x9cxx_interface_cs_gpio_deinit(void)
interface cs gpio deinit
uint8_t x9cxx_output_test(x9cxx_type_t type, x9cxx_bool_t store_enable, uint32_t times)
output test
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]