|
|
@ -32,7 +32,7 @@ void SBUS::begin(void) { |
|
|
|
// swSer1.begin(100000, SWSERIAL_8E2, SBUS_PORT, SBUS_PORT);
|
|
|
|
swSer1.begin(200000, SWSERIAL_8E2, SBUS_PORT, SBUS_PORT); |
|
|
|
swSer1.enableTx(true); |
|
|
|
swSer1.enableIntTx(true); |
|
|
|
// swSer1.enableIntTx(true);
|
|
|
|
|
|
|
|
// Initialize to 1000
|
|
|
|
for(uint8_t i = 0; i < SBUS_CHANNEL_NUMBER; i++) { |
|
|
@ -49,133 +49,26 @@ uint32_t total_low = 0; |
|
|
|
|
|
|
|
// Sending SBUS packets
|
|
|
|
void SBUS::writePackets(void) { |
|
|
|
// if((uint32_t)(millis() - sbusTime) > SBUS_UPDATE_RATE) {
|
|
|
|
if(signalNotOK) { |
|
|
|
// DEBUG ONLY...later put back to 900
|
|
|
|
// rcChannels[2] = 900;
|
|
|
|
// rcChannels[3] = 900;
|
|
|
|
// rcChannels[1] = 900;
|
|
|
|
// rcChannels[0] = 900;
|
|
|
|
rcCommand[2] = 900; |
|
|
|
rcCommand[3] = 900; |
|
|
|
rcCommand[1] = 900; |
|
|
|
rcCommand[0] = 900; |
|
|
|
} |
|
|
|
|
|
|
|
// sbusPreparePacket(sbusPacket, rcChannels, signalNotOK, false);
|
|
|
|
if((uint32_t)millis() - last_sent > SBUS_UPDATE_RATE) { |
|
|
|
sbusPreparePacket(rcCommand, signalNotOK, false); |
|
|
|
// Serial2.write(sbusPacket, SBUS_PACKET_LENGTH);
|
|
|
|
swSer1.write(sbusPacket, SBUS_PACKET_LENGTH); |
|
|
|
sbus_packets_sent_raw++; |
|
|
|
last_sent = millis(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// // Looping through the bytes - Generating Parity Bits
|
|
|
|
// // Is using SBUS_FAST (200000 Baud), 8E2 (Even Parity and 2 bits stop
|
|
|
|
// // For sending at 200000 baud, each bit used about 5uS
|
|
|
|
// // Profiling each bits timing before sending
|
|
|
|
// uint32_t clock_cycles = 0;
|
|
|
|
//
|
|
|
|
if((uint32_t)(millis() - last_profile) > 500) { |
|
|
|
// DEBUG ONLY
|
|
|
|
if((uint32_t)(millis() - last_profile) > 1000) { |
|
|
|
Serial.printf("Cmd: %d Signal: %d Sent: %d NRF: %d\r\n", rcCommand[2], signalNotOK, sbus_packets_sent, nrf_packets_received); |
|
|
|
last_profile = millis(); |
|
|
|
} |
|
|
|
//
|
|
|
|
// total_high = 0;
|
|
|
|
// total_low = 0;
|
|
|
|
//
|
|
|
|
// // bool tx_state = true;
|
|
|
|
// uint8_t parity_count = 0;
|
|
|
|
// int8_t data_bits = 0;
|
|
|
|
// bool current_bit = 0;
|
|
|
|
//
|
|
|
|
// // Now we roughly know how much per clock cycles per microseconds
|
|
|
|
// for(uint8_t pos = 0; pos < SBUS_PACKET_LENGTH; pos++) {
|
|
|
|
// // Now we are going to send the data from LSB and with EVEN parity on each byte with 2 bits stop.
|
|
|
|
// // Looping through each bytes with:
|
|
|
|
// // START BIT | DATA FRAME | PARITY BITS | STOP BITS
|
|
|
|
//
|
|
|
|
// // START BIT - For 1 clock cycle = 5uS = clock_per_micro
|
|
|
|
// // Set to LOW as start bit
|
|
|
|
// GPOC = (1 << SBUS_PORT);
|
|
|
|
// delay_cycles(PULSE_BIT_TIME);
|
|
|
|
//
|
|
|
|
// GPOS = (1 << SBUS_PORT);
|
|
|
|
// delay_cycles(PULSE_GAP);
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// // DATA FRAME
|
|
|
|
// // Reading the data sending it byte by byte
|
|
|
|
// ///// for(data_bits = 7; data_bits >= 0; data_bits--) {
|
|
|
|
// for(data_bits = 0; data_bits < 8; data_bits++) {
|
|
|
|
// current_bit = (sbusPacket[pos] >> data_bits) & 0x01;
|
|
|
|
//
|
|
|
|
// // Sending it out...
|
|
|
|
// if(current_bit == 0x01) {
|
|
|
|
// parity_count++;
|
|
|
|
//
|
|
|
|
// total_high++;
|
|
|
|
//
|
|
|
|
// // HIGH
|
|
|
|
// GPOS = (1 << SBUS_PORT);
|
|
|
|
// delay_cycles(PULSE_BIT_TIME);
|
|
|
|
//
|
|
|
|
// } else {
|
|
|
|
//
|
|
|
|
// // LOW
|
|
|
|
// total_low++;
|
|
|
|
//
|
|
|
|
// GPOC = (1 << SBUS_PORT);
|
|
|
|
// delay_cycles(PULSE_BIT_TIME);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // GAP
|
|
|
|
// GPOS = (1 << SBUS_PORT);
|
|
|
|
// delay_cycles(PULSE_GAP);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // PARITY BITS
|
|
|
|
// // Parity Calculation
|
|
|
|
// if((parity_count & 0x01) == 0x01) {
|
|
|
|
// // ODD
|
|
|
|
// // Need to make it EVEN....
|
|
|
|
// // HIGH
|
|
|
|
// GPOS = (1 << SBUS_PORT);
|
|
|
|
// delay_cycles(PULSE_BIT_TIME);
|
|
|
|
//
|
|
|
|
// } else {
|
|
|
|
// // EVEN
|
|
|
|
// // Nothing needs to be set
|
|
|
|
// // LOW
|
|
|
|
// GPOC = (1 << SBUS_PORT);
|
|
|
|
// delay_cycles(PULSE_BIT_TIME);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // GAP
|
|
|
|
// GPOS = (1 << SBUS_PORT);
|
|
|
|
// delay_cycles(PULSE_GAP);
|
|
|
|
//
|
|
|
|
// // STOP BITS
|
|
|
|
// // LOW
|
|
|
|
// GPOC = (1 << SBUS_PORT);
|
|
|
|
// delay_cycles(PULSE_BIT_TIME);
|
|
|
|
//
|
|
|
|
// // GAP
|
|
|
|
// GPOS = (1 << SBUS_PORT);
|
|
|
|
// delay_cycles(PULSE_GAP);
|
|
|
|
//
|
|
|
|
// // LOW
|
|
|
|
// GPOC = (1 << SBUS_PORT);
|
|
|
|
// delay_cycles(PULSE_BIT_TIME);
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// // GAP
|
|
|
|
// GPOS = (1 << SBUS_PORT);
|
|
|
|
// delay_cycles(PULSE_GAP);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
|
|
|
|
// Wait for next round
|
|
|
|
// sbusTime = millis();
|
|
|
|
// }
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|