// Define the baud rate used to send/receive data to/from the drivers.
// If we assume a worst case clock frequency of 8MHz then the maximum baud rate is 8MHz/16 = 500kbaud.
// We send data via a 1K series resistor. Even if we assume a 200pF load on the shared UART line, this gives a 200ns time constant, which is much less than the 2us bit time @ 500kbaud.
// To write a register we need to send 8 bytes. To read a register we send 4 bytes and receive 8 bytes after a programmable delay.
// So at 500kbaud it takes about 128us to write a register, and 192us+ to read a register.
// In testing I found that 500kbaud was not reliable on the Duet Maestro, so now using 200kbaud.
constexpr uint32_t DriversBaudRate = 200000;
constexpr uint32_t TransferTimeout = 10; // any transfer should complete within 10 ticks @ 1ms/tick
constexpr uint32_t Tmc2240CurrentRange = 0x01; // which current range we set the TMC2240 to (2A)
constexpr uint32_t Tmc2240SlopeControl = 0x01; // which slope control we set the TMC2240 to (200V/us)
constexpr float DriverFullScaleCurrent = 24000/Tmc2240Rref; // in mA, assuming we set the range bits in the DRV_CONF register to 0x01
constexpr float DriverCsMultiplier = 32.0/DriverFullScaleCurrent; // with RRef = 15K this works out as 1.6A so this is the maximum current we can ask for
constexpr Pin MfmPin = NumRealPins + SUPPORT_LIS3DH + SUPPORT_LDC1612; // pin number when the user selects magnetic filament monitor on I2C bus
#endif
#if SUPPORT_TCA6408A
constexpr Pin MfmButtonPin = NumRealPins + SUPPORT_LIS3DH + SUPPORT_LDC1612 + 1; // pin number when the user selects magnetic filament monitor button on I2C bus
#endif
// Timer/counter used to generate step pulses and other sub-millisecond timings
// Timer/counter used to generate step pulses and other sub-millisecond timings
TcCount32 * const StepTc = &(TC0->COUNT32);
TcCount32 * const StepTc = &(TC0->COUNT32);
constexpr IRQn StepTcIRQn = TC0_IRQn;
constexpr IRQn StepTcIRQn = TC0_IRQn;
constexpr unsigned int StepTcNumber = 0;
constexpr unsigned int StepTcNumber = 0;
#define STEP_TC_HANDLER TC0_Handler
#define STEP_TC_HANDLER TC0_Handler
// Available UART ports
// Available UART ports
#define NUM_SERIAL_PORTS 0
#define NUM_SERIAL_PORTS 0
// DMA channel assignments
// DMA channel assignments
constexpr DmaChannel DmacChanTmcTx = 0;
constexpr DmaChannel DmacChanTmcTx = 0;
constexpr DmaChannel DmacChanTmcRx = 1;
constexpr DmaChannel DmacChanTmcRx = 1;
constexpr DmaChannel DmacChanAdc0Rx = 2;
constexpr DmaChannel DmacChanAdc0Rx = 2;
constexpr DmaChannel DmacChanLedTx = 3;
constexpr DmaChannel DmacChanLedTx = 3;
constexpr unsigned int NumDmaChannelsUsed = 4; // must be at least the number of channels used, may be larger. Max 12 on the SAME5x.
constexpr unsigned int NumDmaChannelsUsed = 4; // must be at least the number of channels used, may be larger. Max 12 on the SAME5x.
constexpr DmaPriority DmacPrioTmcTx = 0;
constexpr DmaPriority DmacPrioTmcTx = 0;
constexpr DmaPriority DmacPrioTmcRx = 3;
constexpr DmaPriority DmacPrioTmcRx = 3;
constexpr DmaPriority DmacPrioAdcRx = 2;
constexpr DmaPriority DmacPrioAdcRx = 2;
constexpr DmaPriority DmacPrioLed = 1;
constexpr DmaPriority DmacPrioLed = 1;
// Interrupt priorities, lower means higher priority. 0-2 can't make RTOS calls.
// Interrupt priorities, lower means higher priority. 0-2 can't make RTOS calls.
const NvicPriority NvicPriorityStep = 3; // step interrupt is next highest, it can preempt most other interrupts
const NvicPriority NvicPriorityStep = 3; // step interrupt is next highest, it can preempt most other interrupts
const NvicPriority NvicPriorityUart = 3; // serial driver makes RTOS calls
const NvicPriority NvicPriorityUart = 3; // serial driver makes RTOS calls