LibDriver TTP229
Loading...
Searching...
No Matches
driver_ttp229_read_test.c
Go to the documentation of this file.
1
36
38
39static ttp229_handle_t gs_handle;
40
51uint8_t ttp229_read_test(ttp229_interface_t interface, ttp229_active_t active_level, uint32_t times)
52{
53 uint8_t res;
54 uint32_t i;
55 ttp229_info_t info;
56
57 /* link interface function */
67
68 /* get ttp229 info */
69 res = ttp229_info(&info);
70 if (res != 0)
71 {
72 ttp229_interface_debug_print("ttp229: get info failed.\n");
73
74 return 1;
75 }
76 else
77 {
78 /* print ttp229 */
79 ttp229_interface_debug_print("ttp229: chip is %s.\n", info.chip_name);
80 ttp229_interface_debug_print("ttp229: manufacturer is %s.\n", info.manufacturer_name);
81 ttp229_interface_debug_print("ttp229: interface is %s.\n", info.interface);
82 ttp229_interface_debug_print("ttp229: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
83 ttp229_interface_debug_print("ttp229: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
84 ttp229_interface_debug_print("ttp229: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
85 ttp229_interface_debug_print("ttp229: max current is %0.2fmA.\n", info.max_current_ma);
86 ttp229_interface_debug_print("ttp229: max temperature is %0.1fC.\n", info.temperature_max);
87 ttp229_interface_debug_print("ttp229: min temperature is %0.1fC.\n", info.temperature_min);
88 }
89
90 /* start read test */
91 ttp229_interface_debug_print("ttp229: start read test.\n");
92
93 /* set interface */
94 res = ttp229_set_interface(&gs_handle, interface);
95 if (res != 0)
96 {
97 ttp229_interface_debug_print("ttp229: set interface failed.\n");
98
99 return 1;
100 }
101
102 /* init */
103 res = ttp229_init(&gs_handle);
104 if (res != 0)
105 {
106 ttp229_interface_debug_print("ttp229: init failed.\n");
107
108 return 1;
109 }
110
111 /* set active */
112 res = ttp229_set_active(&gs_handle, active_level);
113 if (res != 0)
114 {
115 ttp229_interface_debug_print("ttp229: set active failed.\n");
116 (void)ttp229_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 /* read 16 keys test */
122 ttp229_interface_debug_print("ttp229: read 16 keys test.\n");
123
124 /* loop */
125 for (i = 0; i < times; i++)
126 {
127 uint8_t keys[16];
128
129 /* read 16 keys */
130 res = ttp229_read_16_keys(&gs_handle, keys);
131 if (res != 0)
132 {
133 ttp229_interface_debug_print("ttp229: read 16 keys failed.\n");
134 (void)ttp229_deinit(&gs_handle);
135
136 return 1;
137 }
138
139 /* delay 1000ms */
141
142 /* output */
143 ttp229_interface_debug_print("ttp229: key[0] key[1] key[2] key[3] is %d %d %d %d.\n", keys[0], keys[1], keys[2], keys[3]);
144 ttp229_interface_debug_print("ttp229: key[4] key[5] key[6] key[7] is %d %d %d %d.\n", keys[4], keys[5], keys[6], keys[7]);
145 ttp229_interface_debug_print("ttp229: key[8] key[9] key[10] key[11] is %d %d %d %d.\n", keys[8], keys[9], keys[10], keys[11]);
146 ttp229_interface_debug_print("ttp229: key[12] key[13] key[14] key[15] is %d %d %d %d.\n", keys[12], keys[13], keys[14], keys[15]);
147 ttp229_interface_debug_print("----------------------------------------------------\n");
148 }
149
150 /* read 8 keys test */
151 ttp229_interface_debug_print("ttp229: read 8 keys test.\n");
152
153 /* loop */
154 for (i = 0; i < times; i++)
155 {
156 uint8_t keys[8];
157
158 /* read 8 keys */
159 res = ttp229_read_8_keys(&gs_handle, keys);
160 if (res != 0)
161 {
162 ttp229_interface_debug_print("ttp229: read 8 keys failed.\n");
163 (void)ttp229_deinit(&gs_handle);
164
165 return 1;
166 }
167
168 /* delay 1000ms */
170
171 /* output */
172 ttp229_interface_debug_print("ttp229: key[0] key[1] key[2] key[3] is %d %d %d %d.\n", keys[0], keys[1], keys[2], keys[3]);
173 ttp229_interface_debug_print("ttp229: key[4] key[5] key[6] key[7] is %d %d %d %d.\n", keys[4], keys[5], keys[6], keys[7]);
174 ttp229_interface_debug_print("------------------------------------------------\n");
175 }
176
177 /* finish read test */
178 ttp229_interface_debug_print("ttp229: finish read test.\n");
179 (void)ttp229_deinit(&gs_handle);
180
181 return 0;
182}
driver ttp229 read test header file
ttp229_active_t
ttp229 active enumeration definition
uint8_t ttp229_init(ttp229_handle_t *handle)
initialize the chip
struct ttp229_info_s ttp229_info_t
ttp229 information structure definition
ttp229_interface_t
ttp229 interface enumeration definition
uint8_t ttp229_set_active(ttp229_handle_t *handle, ttp229_active_t active_level)
set the active level
uint8_t ttp229_deinit(ttp229_handle_t *handle)
close the chip
uint8_t ttp229_read_8_keys(ttp229_handle_t *handle, uint8_t keys[8])
read 8 keys
uint8_t ttp229_info(ttp229_info_t *info)
get chip's information
uint8_t ttp229_read_16_keys(ttp229_handle_t *handle, uint8_t keys[16])
read 16 keys
uint8_t ttp229_set_interface(ttp229_handle_t *handle, ttp229_interface_t interface)
set the interface
struct ttp229_handle_s ttp229_handle_t
ttp229 handle structure definition
uint8_t ttp229_interface_spi_init(void)
interface spi bus init
uint8_t ttp229_interface_spi_read_cmd(uint8_t *buf, uint16_t len)
interface spi bus read command
uint8_t ttp229_interface_iic_init(void)
interface iic bus init
void ttp229_interface_debug_print(const char *const fmt,...)
interface print format data
void ttp229_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ttp229_interface_iic_deinit(void)
interface iic bus deinit
uint8_t ttp229_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
uint8_t ttp229_interface_spi_deinit(void)
interface spi bus deinit
uint8_t ttp229_read_test(ttp229_interface_t interface, ttp229_active_t active_level, uint32_t times)
read test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]