Use this method to fully configure an endpoint
(
index: usize,
tx_config: Option<EndpointConfig>,
rx_config: Option<EndpointConfig>,
)
| 282 | |
| 283 | /// Use this method to fully configure an endpoint |
| 284 | pub fn usb_setup_endpoint( |
| 285 | index: usize, |
| 286 | tx_config: Option<EndpointConfig>, |
| 287 | rx_config: Option<EndpointConfig>, |
| 288 | ) { |
| 289 | let tx_qh = usb_get_queuehead(index, true); |
| 290 | let rx_qh = usb_get_queuehead(index, false); |
| 291 | let ep_control_addr = USB + 0x1C0 + (index as u32) * 4; |
| 292 | |
| 293 | let isochornous = 1; |
| 294 | let bulk = 2; |
| 295 | let interrupt = 3; |
| 296 | let tx_enable_bit = 1 << 23; |
| 297 | let rx_enable_bit = 1 << 7; |
| 298 | |
| 299 | if tx_config.is_some() { |
| 300 | let config = tx_config.unwrap(); |
| 301 | |
| 302 | let mut config_bits = (config.size as u32) << 16; |
| 303 | if config.zlt { |
| 304 | config_bits |= 1 << 29; |
| 305 | } |
| 306 | |
| 307 | configure_ep(tx_qh, config_bits, config.callback); |
| 308 | match config.endpoint_type { |
| 309 | EndpointType::ISOCHRONOUS => { |
| 310 | assign( |
| 311 | ep_control_addr, |
| 312 | read_word(ep_control_addr) | (isochornous << 18) | tx_enable_bit, |
| 313 | ); |
| 314 | } |
| 315 | EndpointType::BULK => { |
| 316 | assign( |
| 317 | ep_control_addr, |
| 318 | read_word(ep_control_addr) | (bulk << 18) | tx_enable_bit, |
| 319 | ); |
| 320 | } |
| 321 | EndpointType::INTERRUPT => { |
| 322 | assign( |
| 323 | ep_control_addr, |
| 324 | read_word(ep_control_addr) | (interrupt << 18) | tx_enable_bit, |
| 325 | ); |
| 326 | } |
| 327 | } |
| 328 | } else { |
| 329 | // Unusued endpoints cannot remain CONTROL type |
| 330 | assign(ep_control_addr, read_word(ep_control_addr) | (bulk << 18)); |
| 331 | } |
| 332 | |
| 333 | if rx_config.is_some() { |
| 334 | let config = rx_config.unwrap(); |
| 335 | |
| 336 | let mut config_bits = (config.size as u32) << 16; |
| 337 | if config.zlt { |
| 338 | config_bits |= 1 << 29; |
| 339 | } |
| 340 | |
| 341 | configure_ep(rx_qh, config_bits, config.callback); |
no test coverage detected