| 132 | static struct rtgui_touch_device *touch = RT_NULL; |
| 133 | |
| 134 | static 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 |
no test coverage detected