MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / touch_send_then_recv

Function touch_send_then_recv

bsp/loongson/ls1cdev/drivers/touch.c:134–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132static struct rtgui_touch_device *touch = RT_NULL;
133
134static rt_err_t touch_send_then_recv(struct rt_spi_device *device,
135 const void *send_buf,
136 rt_size_t send_length,
137 void *recv_buf,
138 rt_size_t recv_length)
139{
140 rt_err_t result;
141 struct rt_spi_message message;
142 rt_uint8_t dummy[128] ;
143
144 rt_memset(dummy, DUMMY, sizeof(dummy));
145
146 RT_ASSERT(device != RT_NULL);
147 RT_ASSERT(device->bus != RT_NULL);
148
149 result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER);
150 if (result == RT_EOK)
151 {
152 if (device->bus->owner != device)
153 {
154 /* not the same owner as current, re-configure SPI bus */
155 result = device->bus->ops->configure(device, &device->config);
156 if (result == RT_EOK)
157 {
158 /* set SPI bus owner */
159 device->bus->owner = device;
160 }
161 else
162 {
163 /* configure SPI bus failed */
164 result = -RT_EIO;
165 goto __exit;
166 }
167 }
168
169 /* send data */
170 message.send_buf = send_buf;
171 message.recv_buf = RT_NULL;
172 message.length = send_length;
173 message.cs_take = 1;
174 message.cs_release = 0;
175 message.next = RT_NULL;
176
177 result = device->bus->ops->xfer(device, &message);
178 if (result == 0)
179 {
180 result = -RT_EIO;
181 goto __exit;
182 }
183
184 /* recv data */
185 message.send_buf = dummy;
186 message.recv_buf = recv_buf;
187 message.length = recv_length;
188 message.cs_take = 0;
189 message.cs_release = 1;
190 message.next = RT_NULL;
191

Callers 2

rtgui_touch_calculateFunction · 0.85
rtgui_touch_initFunction · 0.85

Calls 3

rt_memsetFunction · 0.85
rt_mutex_takeFunction · 0.85
rt_mutex_releaseFunction · 0.85

Tested by

no test coverage detected