| 1936 | #define BYTE_BITS 10U |
| 1937 | |
| 1938 | bool RCOutput::serial_setup_output(uint8_t chan, uint32_t baudrate, uint32_t chanmask) |
| 1939 | { |
| 1940 | osalDbgAssert(hal.scheduler->in_main_thread(), "serial_setup_output(): not called from main thread"); |
| 1941 | // account for IOMCU channels |
| 1942 | chan -= chan_offset; |
| 1943 | chanmask >>= chan_offset; |
| 1944 | pwm_group *new_serial_group = nullptr; |
| 1945 | uint8_t new_serial_chan = 0; |
| 1946 | |
| 1947 | // find the channel group for the next output |
| 1948 | for (auto &group : pwm_group_list) { |
| 1949 | if (group.current_mode == MODE_PWM_BRUSHED) { |
| 1950 | // can't do serial output with brushed motors |
| 1951 | continue; |
| 1952 | } |
| 1953 | if (group.ch_mask & (1U<<chan)) { |
| 1954 | new_serial_group = &group; |
| 1955 | for (uint8_t j=0; j<4; j++) { |
| 1956 | if (group.chan[j] == chan) { |
| 1957 | new_serial_chan = j; |
| 1958 | } |
| 1959 | } |
| 1960 | break; |
| 1961 | } |
| 1962 | } |
| 1963 | |
| 1964 | // couldn't find a group, shutdown everything |
| 1965 | if (!new_serial_group) { |
| 1966 | if (in_soft_serial()) { |
| 1967 | // shutdown old group |
| 1968 | serial_end(chanmask); |
| 1969 | } |
| 1970 | return false; |
| 1971 | } |
| 1972 | |
| 1973 | #if RCOU_SERIAL_TIMING_DEBUG |
| 1974 | hal.gpio->pinMode(54, 1); |
| 1975 | hal.gpio->pinMode(55, 1); |
| 1976 | #endif |
| 1977 | |
| 1978 | // stop further dshot output before we reconfigure the DMA |
| 1979 | serial_group = new_serial_group; |
| 1980 | serial_group->serial.chan = new_serial_chan; |
| 1981 | |
| 1982 | // setup the unconfigured groups for serial output. We ask for a bit width of 1, which gets modified by the |
| 1983 | // we setup all groups so they all are setup with the right polarity, and to make switching between |
| 1984 | // channels in blheli pass-thru fast |
| 1985 | for (auto &group : pwm_group_list) { |
| 1986 | if ((group.ch_mask & chanmask) && !(group.ch_mask & serial_chanmask)) { |
| 1987 | const uint32_t pulse_time_us = 1000000UL * 10 / baudrate; |
| 1988 | if (!setup_group_DMA(group, baudrate, 10, false, DSHOT_BUFFER_LENGTH, pulse_time_us, false)) { |
| 1989 | serial_end(chanmask); |
| 1990 | return false; |
| 1991 | } |
| 1992 | } |
| 1993 | } |
| 1994 | // mask of channels currently configured |
| 1995 | serial_chanmask |= chanmask; |
no test coverage detected