Skip to content

Commit 8c092df

Browse files
committed
Use SPI interface
1 parent bdedb50 commit 8c092df

File tree

2 files changed

+178
-310
lines changed

2 files changed

+178
-310
lines changed

src/TMCStepper.h

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,30 +1105,15 @@ class TMC2224Stepper : public TMC2208Stepper {
11051105

11061106
class TMC2240Stepper {
11071107
public:
1108-
TMC2240Stepper(Stream * SerialPort):TMC2240Stepper(SerialPort, TMC2240_SLAVE_ADDR){};
1109-
TMC2240Stepper(Stream * SerialPort, uint8_t addr, uint16_t mul_pin1, uint16_t mul_pin2);
1108+
TMC2240Stepper(uint16_t pinCS, int8_t link_index = -1);
1109+
TMC2240Stepper(uint16_t pinCS, uint16_t pinMOSI, uint16_t pinMISO, uint16_t pinSCK, int8_t link_index = -1);
11101110

1111-
#if SW_CAPABLE_PLATFORM
1112-
TMC2240Stepper(uint16_t SW_RX_pin, uint16_t SW_TX_pin) : TMC2240Stepper(SW_RX_pin, SW_TX_pin,TMC2240_SLAVE_ADDR){};
1113-
1114-
// __attribute__((deprecated("Boolean argument has been deprecated and does nothing")))
1115-
// TMC2240Stepper(uint16_t SW_RX_pin, uint16_t SW_TX_pin, uint8_t) :
1116-
// TMC2240Stepper(SW_RX_pin, SW_TX_pin, TMC2240_SLAVE_ADDR)
1117-
// {};
1118-
#else
1119-
TMC2240Stepper(uint16_t, uint16_t, float) = delete; // Your platform does not currently support Software Serial
1120-
#endif
1121-
1122-
void defaults();
1123-
void push();
11241111
void begin();
1125-
#if SW_CAPABLE_PLATFORM
1126-
void beginSerial(uint32_t baudrate) __attribute__((weak));
1127-
#else
1128-
void beginSerial(uint32_t) = delete; // Your platform does not currently support Software Serial
1129-
#endif
1130-
1112+
void defaults();
1113+
void setSPISpeed(uint32_t speed);
1114+
void switchCSpin(bool state);
11311115
bool isEnabled();
1116+
void push();
11321117

11331118
// RW: GCONF
11341119
void GCONF(uint32_t input);
@@ -1202,13 +1187,16 @@ class TMC2240Stepper {
12021187
uint8_t silicon_rv();
12031188
uint8_t version();
12041189

1205-
12061190
// W: DRV_CONF
12071191
void DRV_CONF(uint32_t input);
12081192
void current_range(uint8_t);
12091193
void slope_control(uint8_t);
12101194
uint32_t DRV_CONF();
12111195

1196+
void GLOBAL_SCALER(uint8_t input);
1197+
uint32_t GLOBAL_SCALER();
1198+
void global_scaler(uint8_t B);
1199+
uint8_t global_scaler();
12121200

12131201
// W: IHOLD_IRUN
12141202
void IHOLD_IRUN(uint32_t input);
@@ -1222,7 +1210,13 @@ class TMC2240Stepper {
12221210
uint8_t iholddelay();
12231211
uint8_t irundelay();
12241212

1213+
// W: TCOOLTHRS
1214+
uint32_t TCOOLTHRS();
1215+
void TCOOLTHRS( uint32_t input);
12251216

1217+
// W: THIGH
1218+
uint32_t THIGH();
1219+
void THIGH( uint32_t input);
12261220

12271221
// RW: CHOPCONF
12281222
void CHOPCONF(uint32_t input);
@@ -1266,14 +1260,14 @@ class TMC2240Stepper {
12661260
void semax(uint8_t B);
12671261
void sedn(uint8_t B);
12681262
void seimin(bool B);
1269-
void sgt(uint16_t B);
1263+
void sgt(int8_t B);
12701264
void sfilt(bool B);
12711265
uint8_t semin();
12721266
uint8_t seup();
12731267
uint8_t semax();
12741268
uint8_t sedn();
12751269
bool seimin();
1276-
uint16_t sgt();
1270+
int8_t sgt();
12771271
bool sfilt();
12781272

12791273
// RW: PWMCONF
@@ -1348,10 +1342,7 @@ class TMC2240Stepper {
13481342
uint8_t TPOWERDOWN();
13491343
void TPOWERDOWN(uint8_t input);
13501344

1351-
static constexpr uint8_t TMC_READ = 0x00,
1352-
1353-
TMC_WRITE = 0x80;
1354-
static constexpr uint8_t TMC2240_SLAVE_ADDR = 0x00;
1345+
uint8_t status_response;
13551346
protected:
13561347
INIT2240_REGISTER(GCONF) {{.sr=0}};
13571348
INIT2240_REGISTER(DRV_CONF) {{.sr=0}};
@@ -1368,38 +1359,33 @@ class TMC2240Stepper {
13681359
float calc_IFS_current_RMS(int8_t range, uint32_t Rref);
13691360
uint32_t set_globalscaler(float current, float IFS_current_RMS);
13701361

1371-
TMC2240Stepper(Stream * SerialPort, uint8_t addr);
1372-
#if SW_CAPABLE_PLATFORM
1373-
TMC2240Stepper(uint16_t SW_RX_pin, uint16_t SW_TX_pin, uint8_t addr);
1374-
#endif
1375-
1376-
Stream * HWSerial = nullptr;
1377-
#if SW_CAPABLE_PLATFORM
1378-
SoftwareSerial * SWSerial = nullptr;
1379-
const uint16_t RXTX_pin = 0; // Half duplex
1380-
#endif
1362+
void beginTransaction();
1363+
void endTransaction();
1364+
uint8_t transfer(const uint8_t data);
1365+
void transferEmptyBytes(const uint8_t n);
1366+
void write(uint8_t addressByte, uint32_t config);
1367+
uint32_t read(uint8_t addressByte);
13811368

1369+
static constexpr uint8_t TMC_READ = 0x00,
1370+
TMC_WRITE = 0x80;
13821371

13831372
SSwitch *sswitch = nullptr;
13841373

1385-
int available();
1386-
void preWriteCommunication();
1387-
void preReadCommunication();
1388-
int16_t serial_read();
1389-
uint8_t serial_write(const uint8_t data);
1390-
void postWriteCommunication();
1391-
void postReadCommunication();
1392-
void write(uint8_t, uint32_t);
1393-
uint32_t read(uint8_t);
1394-
const uint8_t slave_address;
1395-
uint8_t calcCRC(uint8_t datagram[], uint8_t len);
13961374
static constexpr uint8_t TMC2240_SYNC = 0x05;
13971375
static constexpr uint8_t replyDelay = 2;
13981376
static constexpr uint8_t abort_window = 5;
13991377
static constexpr uint8_t max_retries = 2;
14001378

14011379
uint64_t _sendDatagram(uint8_t [], const uint8_t, uint16_t);
14021380
float holdMultiplier = 0.5;
1381+
1382+
static uint32_t spi_speed; // Default 2MHz
1383+
const uint16_t _pinCS;
1384+
SW_SPIClass * TMC_SW_SPI = nullptr;
1385+
static constexpr float default_RS = 0.11;
1386+
1387+
int8_t link_index;
1388+
static int8_t chain_length;
14031389
};
14041390

14051391
class TMC2660Stepper {

0 commit comments

Comments
 (0)