Merge pull request #589 from XPila/MK3-V3_2
New SPI, LiquidCrystal renamed
This commit is contained in:
commit
dba2fd7e75
13 changed files with 191 additions and 58 deletions
|
@ -690,7 +690,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
|
|||
|
||||
//#define LCD_I2C_SAINSMART_YWROBOT
|
||||
#ifdef LCD_I2C_SAINSMART_YWROBOT
|
||||
// This uses the LiquidCrystal_I2C library ( https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home )
|
||||
// This uses the LiquidCrystal_I2C library ( https://bitbucket.org/fmalpartida/new-LiquidCrystal_Prusa/wiki/Home )
|
||||
// Make sure it is placed in the Arduino libraries directory.
|
||||
#define LCD_I2C_TYPE_PCF8575
|
||||
#define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander
|
||||
|
@ -745,7 +745,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
|
|||
// Shift register panels
|
||||
// ---------------------
|
||||
// 2 wire Non-latching LCD SR from:
|
||||
// https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection
|
||||
// https://bitbucket.org/fmalpartida/new-LiquidCrystal_Prusa/wiki/schematics#!shiftregister-connection
|
||||
|
||||
//#define SAV_3DLCD
|
||||
#ifdef SAV_3DLCD
|
||||
|
|
|
@ -107,6 +107,9 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o
|
|||
// New XYZ calibration
|
||||
#define NEW_XYZCAL
|
||||
|
||||
// Do not use Arduino SPI
|
||||
#define NEW_SPI
|
||||
|
||||
// Watchdog support
|
||||
#define WATCHDOG
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#elif defined(DOGLCD)
|
||||
#include <U8glib.h> // library for graphics LCD by Oli Kraus (https://code.google.com/p/u8glib/)
|
||||
#else
|
||||
#include "LiquidCrystal.h" // library for character LCD
|
||||
#include "LiquidCrystal_Prusa.h" // library for character LCD
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "LiquidCrystal.h"
|
||||
#include "LiquidCrystal_Prusa.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -22,35 +22,35 @@
|
|||
//
|
||||
// Note, however, that resetting the Arduino doesn't reset the LCD, so we
|
||||
// can't assume that it's in that state when a sketch starts (and the
|
||||
// LiquidCrystal constructor is called).
|
||||
// LiquidCrystal_Prusa constructor is called).
|
||||
|
||||
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
LiquidCrystal_Prusa::LiquidCrystal_Prusa(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
||||
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
|
||||
{
|
||||
init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7);
|
||||
}
|
||||
|
||||
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable,
|
||||
LiquidCrystal_Prusa::LiquidCrystal_Prusa(uint8_t rs, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
||||
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
|
||||
{
|
||||
init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7);
|
||||
}
|
||||
|
||||
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
LiquidCrystal_Prusa::LiquidCrystal_Prusa(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
|
||||
{
|
||||
init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable,
|
||||
LiquidCrystal_Prusa::LiquidCrystal_Prusa(uint8_t rs, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
|
||||
{
|
||||
init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
void LiquidCrystal_Prusa::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
||||
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
|
||||
{
|
||||
|
@ -82,7 +82,7 @@ void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t en
|
|||
begin(16, 1);
|
||||
}
|
||||
|
||||
void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
|
||||
void LiquidCrystal_Prusa::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
|
||||
if (lines > 1) {
|
||||
_displayfunction |= LCD_2LINE;
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
|
|||
|
||||
|
||||
|
||||
void LiquidCrystal::begin_noclear(uint8_t cols, uint8_t lines, uint8_t dotsize) {
|
||||
void LiquidCrystal_Prusa::begin_noclear(uint8_t cols, uint8_t lines, uint8_t dotsize) {
|
||||
if (lines > 1) {
|
||||
_displayfunction |= LCD_2LINE;
|
||||
}
|
||||
|
@ -253,21 +253,21 @@ void LiquidCrystal::begin_noclear(uint8_t cols, uint8_t lines, uint8_t dotsize)
|
|||
|
||||
|
||||
/********** high level commands, for the user! */
|
||||
void LiquidCrystal::clear()
|
||||
void LiquidCrystal_Prusa::clear()
|
||||
{
|
||||
command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero
|
||||
delayMicroseconds(1600); // this command takes a long time
|
||||
|
||||
}
|
||||
|
||||
void LiquidCrystal::home()
|
||||
void LiquidCrystal_Prusa::home()
|
||||
{
|
||||
command(LCD_RETURNHOME); // set cursor position to zero
|
||||
delayMicroseconds(1600); // this command takes a long time!
|
||||
|
||||
}
|
||||
|
||||
void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
|
||||
void LiquidCrystal_Prusa::setCursor(uint8_t col, uint8_t row)
|
||||
{
|
||||
int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
|
||||
if ( row >= _numlines ) {
|
||||
|
@ -278,70 +278,70 @@ void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
|
|||
}
|
||||
|
||||
// Turn the display on/off (quickly)
|
||||
void LiquidCrystal::noDisplay() {
|
||||
void LiquidCrystal_Prusa::noDisplay() {
|
||||
_displaycontrol &= ~LCD_DISPLAYON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
void LiquidCrystal::display() {
|
||||
void LiquidCrystal_Prusa::display() {
|
||||
_displaycontrol |= LCD_DISPLAYON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
|
||||
// Turns the underline cursor on/off
|
||||
void LiquidCrystal::noCursor() {
|
||||
void LiquidCrystal_Prusa::noCursor() {
|
||||
_displaycontrol &= ~LCD_CURSORON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
void LiquidCrystal::cursor() {
|
||||
void LiquidCrystal_Prusa::cursor() {
|
||||
_displaycontrol |= LCD_CURSORON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
|
||||
// Turn on and off the blinking cursor
|
||||
void LiquidCrystal::noBlink() {
|
||||
void LiquidCrystal_Prusa::noBlink() {
|
||||
_displaycontrol &= ~LCD_BLINKON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
void LiquidCrystal::blink() {
|
||||
void LiquidCrystal_Prusa::blink() {
|
||||
_displaycontrol |= LCD_BLINKON;
|
||||
command(LCD_DISPLAYCONTROL | _displaycontrol);
|
||||
}
|
||||
|
||||
// These commands scroll the display without changing the RAM
|
||||
void LiquidCrystal::scrollDisplayLeft(void) {
|
||||
void LiquidCrystal_Prusa::scrollDisplayLeft(void) {
|
||||
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
|
||||
}
|
||||
void LiquidCrystal::scrollDisplayRight(void) {
|
||||
void LiquidCrystal_Prusa::scrollDisplayRight(void) {
|
||||
command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
|
||||
}
|
||||
|
||||
// This is for text that flows Left to Right
|
||||
void LiquidCrystal::leftToRight(void) {
|
||||
void LiquidCrystal_Prusa::leftToRight(void) {
|
||||
_displaymode |= LCD_ENTRYLEFT;
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
}
|
||||
|
||||
// This is for text that flows Right to Left
|
||||
void LiquidCrystal::rightToLeft(void) {
|
||||
void LiquidCrystal_Prusa::rightToLeft(void) {
|
||||
_displaymode &= ~LCD_ENTRYLEFT;
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
}
|
||||
|
||||
// This will 'right justify' text from the cursor
|
||||
void LiquidCrystal::autoscroll(void) {
|
||||
void LiquidCrystal_Prusa::autoscroll(void) {
|
||||
_displaymode |= LCD_ENTRYSHIFTINCREMENT;
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
}
|
||||
|
||||
// This will 'left justify' text from the cursor
|
||||
void LiquidCrystal::noAutoscroll(void) {
|
||||
void LiquidCrystal_Prusa::noAutoscroll(void) {
|
||||
_displaymode &= ~LCD_ENTRYSHIFTINCREMENT;
|
||||
command(LCD_ENTRYMODESET | _displaymode);
|
||||
}
|
||||
|
||||
// Allows us to fill the first 8 CGRAM locations
|
||||
// with custom characters
|
||||
void LiquidCrystal::createChar(uint8_t location, uint8_t charmap[]) {
|
||||
void LiquidCrystal_Prusa::createChar(uint8_t location, uint8_t charmap[]) {
|
||||
location &= 0x7; // we only have 8 locations 0-7
|
||||
command(LCD_SETCGRAMADDR | (location << 3));
|
||||
for (int i=0; i<8; i++) {
|
||||
|
@ -351,11 +351,11 @@ void LiquidCrystal::createChar(uint8_t location, uint8_t charmap[]) {
|
|||
|
||||
/*********** mid level commands, for sending data/cmds */
|
||||
|
||||
inline void LiquidCrystal::command(uint8_t value) {
|
||||
inline void LiquidCrystal_Prusa::command(uint8_t value) {
|
||||
send(value, LOW);
|
||||
}
|
||||
|
||||
inline size_t LiquidCrystal::write(uint8_t value) {
|
||||
inline size_t LiquidCrystal_Prusa::write(uint8_t value) {
|
||||
if (_escape[0] || (value == 0x1b))
|
||||
return escape_write(value);
|
||||
send(value, HIGH);
|
||||
|
@ -368,7 +368,7 @@ inline size_t LiquidCrystal::write(uint8_t value) {
|
|||
//CursorShow "\x1b[?25h"
|
||||
//CursorHide "\x1b[?25l"
|
||||
|
||||
inline size_t LiquidCrystal::escape_write(uint8_t chr)
|
||||
inline size_t LiquidCrystal_Prusa::escape_write(uint8_t chr)
|
||||
{
|
||||
#define escape_cnt (_escape[0]) //escape character counter
|
||||
#define is_num_msk (_escape[1]) //numeric character bit mask
|
||||
|
@ -502,7 +502,7 @@ end:
|
|||
/************ low level data pushing commands **********/
|
||||
|
||||
// write either command or data, with automatic 4/8-bit selection
|
||||
void LiquidCrystal::send(uint8_t value, uint8_t mode) {
|
||||
void LiquidCrystal_Prusa::send(uint8_t value, uint8_t mode) {
|
||||
digitalWrite(_rs_pin, mode);
|
||||
|
||||
// if there is a RW pin indicated, set it low to Write
|
||||
|
@ -518,7 +518,7 @@ void LiquidCrystal::send(uint8_t value, uint8_t mode) {
|
|||
}
|
||||
}
|
||||
|
||||
void LiquidCrystal::pulseEnable(void) {
|
||||
void LiquidCrystal_Prusa::pulseEnable(void) {
|
||||
digitalWrite(_enable_pin, LOW);
|
||||
delayMicroseconds(1);
|
||||
digitalWrite(_enable_pin, HIGH);
|
||||
|
@ -527,7 +527,7 @@ void LiquidCrystal::pulseEnable(void) {
|
|||
delayMicroseconds(100); // commands need > 37us to settle
|
||||
}
|
||||
|
||||
void LiquidCrystal::write4bits(uint8_t value) {
|
||||
void LiquidCrystal_Prusa::write4bits(uint8_t value) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
pinMode(_data_pins[i], OUTPUT);
|
||||
digitalWrite(_data_pins[i], (value >> i) & 0x01);
|
||||
|
@ -536,7 +536,7 @@ void LiquidCrystal::write4bits(uint8_t value) {
|
|||
pulseEnable();
|
||||
}
|
||||
|
||||
void LiquidCrystal::write8bits(uint8_t value) {
|
||||
void LiquidCrystal_Prusa::write8bits(uint8_t value) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
pinMode(_data_pins[i], OUTPUT);
|
||||
digitalWrite(_data_pins[i], (value >> i) & 0x01);
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef LiquidCrystal_h
|
||||
#define LiquidCrystal_h
|
||||
#ifndef LiquidCrystal_Prusa_h
|
||||
#define LiquidCrystal_Prusa_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "Print.h"
|
||||
|
@ -42,17 +42,17 @@
|
|||
#define LCD_5x10DOTS 0x04
|
||||
#define LCD_5x8DOTS 0x00
|
||||
|
||||
class LiquidCrystal : public Print {
|
||||
class LiquidCrystal_Prusa : public Print {
|
||||
public:
|
||||
LiquidCrystal(uint8_t rs, uint8_t enable,
|
||||
LiquidCrystal_Prusa(uint8_t rs, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
||||
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
|
||||
LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
LiquidCrystal_Prusa(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
||||
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
|
||||
LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
LiquidCrystal_Prusa(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
|
||||
LiquidCrystal(uint8_t rs, uint8_t enable,
|
||||
LiquidCrystal_Prusa(uint8_t rs, uint8_t enable,
|
||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
|
||||
|
||||
void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
|
|
@ -65,6 +65,10 @@
|
|||
#include "swspi.h"
|
||||
#endif //SWSPI
|
||||
|
||||
#ifdef NEW_SPI
|
||||
#include "spi.h"
|
||||
#endif //NEW_SPI
|
||||
|
||||
#ifdef SWI2C
|
||||
#include "swi2c.h"
|
||||
#endif //SWI2C
|
||||
|
@ -806,8 +810,8 @@ void factory_reset(char level, bool quiet)
|
|||
|
||||
|
||||
}
|
||||
#include "LiquidCrystal.h"
|
||||
extern LiquidCrystal lcd;
|
||||
#include "LiquidCrystal_Prusa.h"
|
||||
extern LiquidCrystal_Prusa lcd;
|
||||
|
||||
FILE _lcdout = {0};
|
||||
|
||||
|
@ -1106,6 +1110,10 @@ void setup()
|
|||
|
||||
#endif //TMC2130
|
||||
|
||||
#ifdef NEW_SPI
|
||||
spi_init();
|
||||
#endif //NEW_SPI
|
||||
|
||||
st_init(); // Initialize stepper, this enables interrupts!
|
||||
|
||||
#ifdef TMC2130
|
||||
|
|
|
@ -11,5 +11,11 @@
|
|||
//SM4 configuration
|
||||
#define SM4_DEFDELAY 500 //default step delay [us]
|
||||
|
||||
//TMC2130 - Trinamic stepper driver
|
||||
//pinout - hardcoded
|
||||
//spi:
|
||||
#define TMC2130_SPI_RATE 0 // fosc/4 = 4MHz
|
||||
#define TMC2130_SPCR SPI_SPCR(TMC2130_SPI_RATE, 1, 1, 1, 0)
|
||||
#define TMC2130_SPSR SPI_SPSR(TMC2130_SPI_RATE)
|
||||
|
||||
#endif //_CONFIG_H
|
||||
|
|
|
@ -42,11 +42,11 @@
|
|||
/* Russian language not supported yet, needs custom font
|
||||
|
||||
#ifdef LANGUAGE_RU
|
||||
#include "LiquidCrystalRus.h"
|
||||
#define LCD_CLASS LiquidCrystalRus
|
||||
#include "LiquidCrystal_Rus.h"
|
||||
#define LCD_CLASS LiquidCrystal_Rus
|
||||
#else
|
||||
#include <LiquidCrystal.h>
|
||||
#define LCD_CLASS LiquidCrystal
|
||||
#include <LiquidCrystal_Prusa.h>
|
||||
#define LCD_CLASS LiquidCrystal_Prusa
|
||||
#endif
|
||||
*/
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
#include "fastio.h"
|
||||
#include "cmdqueue.h"
|
||||
|
||||
//#include "LiquidCrystal.h"
|
||||
//extern LiquidCrystal lcd;
|
||||
//#include "LiquidCrystal_Prusa.h"
|
||||
//extern LiquidCrystal_Prusa lcd;
|
||||
|
||||
|
||||
#define FSENSOR_ERR_MAX 5 //filament sensor max error count
|
||||
|
|
8
Firmware/spi.c
Normal file
8
Firmware/spi.c
Normal file
|
@ -0,0 +1,8 @@
|
|||
//spi.c - hardware SPI
|
||||
//#ifdef __SPI
|
||||
|
||||
#include "spi.h"
|
||||
#include <avr/io.h>
|
||||
|
||||
|
||||
//#endif //__SPI
|
41
Firmware/spi.h
Normal file
41
Firmware/spi.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
//spi.h - hardware SPI
|
||||
#ifndef SPI_H
|
||||
#define SPI_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <avr/io.h>
|
||||
#include "config.h"
|
||||
|
||||
|
||||
#define SPI_SPCR(rat, pha, pol, mst, dor) ((rat & 3) | (pha?(1<<CPHA):0) | (pol?(1<<CPOL):0) | (mst?(1<<MSTR):0) | (dor?(1<<DORD):0) | (1<<SPE))
|
||||
#define SPI_SPSR(rat) ((rat & 4)?(1<<SPI2X):0)
|
||||
|
||||
#define DD_SS 0
|
||||
#define DD_SCK 1
|
||||
#define DD_MOSI 2
|
||||
#define DD_MISO 3
|
||||
|
||||
inline void spi_init()
|
||||
{
|
||||
DDRB &= ~((1 << DD_SCK) | (1 << DD_MOSI) | (1 << DD_MISO));
|
||||
DDRB |= (1 << DD_SS) | (1 << DD_SCK) | (1 << DD_MOSI);
|
||||
PORTB &= ~((1 << DD_SCK) | (1 << DD_MOSI) | (1 << DD_MISO));
|
||||
PORTB |= (1 << DD_SS);
|
||||
SPCR = SPI_SPCR(0, 0, 0, 1, 0); //SPE=1, MSTR=1 (0x50)
|
||||
SPSR = 0x00;
|
||||
}
|
||||
|
||||
inline void spi_setup(uint8_t spcr, uint8_t spsr)
|
||||
{
|
||||
SPCR = spcr;
|
||||
SPSR = spsr;
|
||||
}
|
||||
|
||||
inline uint8_t spi_txrx(uint8_t tx)
|
||||
{
|
||||
SPDR = tx;
|
||||
while (!(SPSR & (1 << SPIF)));
|
||||
return SPDR;
|
||||
}
|
||||
|
||||
#endif //SPI_H
|
|
@ -3,11 +3,16 @@
|
|||
#ifdef TMC2130
|
||||
|
||||
#include "tmc2130.h"
|
||||
#include <SPI.h>
|
||||
#include "LiquidCrystal.h"
|
||||
#include "LiquidCrystal_Prusa.h"
|
||||
#include "ultralcd.h"
|
||||
#ifndef NEW_SPI
|
||||
#include <SPI.h>
|
||||
#else //NEW_SPI
|
||||
#include "spi.h"
|
||||
#endif //NEW_SPI
|
||||
|
||||
extern LiquidCrystal lcd;
|
||||
|
||||
extern LiquidCrystal_Prusa lcd;
|
||||
|
||||
#define TMC2130_GCONF_NORMAL 0x00000000 // spreadCycle
|
||||
#define TMC2130_GCONF_SGSENS 0x00003180 // spreadCycle with stallguard (stall activates DIAG0 and DIAG1 [pushpull])
|
||||
|
@ -143,7 +148,9 @@ void tmc2130_init()
|
|||
SET_INPUT(Y_TMC2130_DIAG);
|
||||
SET_INPUT(Z_TMC2130_DIAG);
|
||||
SET_INPUT(E0_TMC2130_DIAG);
|
||||
#ifndef NEW_SPI
|
||||
SPI.begin();
|
||||
#endif //NEW_SPI
|
||||
for (int axis = 0; axis < 2; axis++) // X Y axes
|
||||
{
|
||||
tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
|
||||
|
@ -594,11 +601,15 @@ inline void tmc2130_cs_high(uint8_t axis)
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef NEW_SPI
|
||||
|
||||
uint8_t tmc2130_tx(uint8_t axis, uint8_t addr, uint32_t wval)
|
||||
{
|
||||
//datagram1 - request
|
||||
printf_P(PSTR("tmc2130_tx %d 0x%02hhx, 0x%08lx\n"), axis, addr, wval);
|
||||
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3));
|
||||
printf_P(PSTR(" SPCR = 0x%02hhx\n"), SPCR);
|
||||
printf_P(PSTR(" SPSR = 0x%02hhx\n"), SPSR);
|
||||
tmc2130_cs_low(axis);
|
||||
SPI.transfer(addr); // address
|
||||
SPI.transfer((wval >> 24) & 0xff); // MSB
|
||||
|
@ -636,6 +647,62 @@ uint8_t tmc2130_rx(uint8_t axis, uint8_t addr, uint32_t* rval)
|
|||
return stat;
|
||||
}
|
||||
|
||||
#else //NEW_SPI
|
||||
|
||||
//Arduino SPI
|
||||
//#define TMC2130_SPI_ENTER() SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3))
|
||||
//#define TMC2130_SPI_TXRX SPI.transfer
|
||||
//#define TMC2130_SPI_LEAVE SPI.endTransaction
|
||||
|
||||
//spi
|
||||
#define TMC2130_SPI_ENTER() spi_setup(TMC2130_SPCR, TMC2130_SPSR)
|
||||
#define TMC2130_SPI_TXRX spi_txrx
|
||||
#define TMC2130_SPI_LEAVE()
|
||||
|
||||
uint8_t tmc2130_tx(uint8_t axis, uint8_t addr, uint32_t wval)
|
||||
{
|
||||
//datagram1 - request
|
||||
TMC2130_SPI_ENTER();
|
||||
tmc2130_cs_low(axis);
|
||||
TMC2130_SPI_TXRX(addr); // address
|
||||
TMC2130_SPI_TXRX((wval >> 24) & 0xff); // MSB
|
||||
TMC2130_SPI_TXRX((wval >> 16) & 0xff);
|
||||
TMC2130_SPI_TXRX((wval >> 8) & 0xff);
|
||||
TMC2130_SPI_TXRX(wval & 0xff); // LSB
|
||||
tmc2130_cs_high(axis);
|
||||
TMC2130_SPI_LEAVE();
|
||||
}
|
||||
|
||||
uint8_t tmc2130_rx(uint8_t axis, uint8_t addr, uint32_t* rval)
|
||||
{
|
||||
//datagram1 - request
|
||||
TMC2130_SPI_ENTER();
|
||||
tmc2130_cs_low(axis);
|
||||
TMC2130_SPI_TXRX(addr); // address
|
||||
TMC2130_SPI_TXRX(0); // MSB
|
||||
TMC2130_SPI_TXRX(0);
|
||||
TMC2130_SPI_TXRX(0);
|
||||
TMC2130_SPI_TXRX(0); // LSB
|
||||
tmc2130_cs_high(axis);
|
||||
TMC2130_SPI_LEAVE();
|
||||
//datagram2 - response
|
||||
TMC2130_SPI_ENTER();
|
||||
tmc2130_cs_low(axis);
|
||||
uint8_t stat = TMC2130_SPI_TXRX(0); // status
|
||||
uint32_t val32 = 0;
|
||||
val32 = TMC2130_SPI_TXRX(0); // MSB
|
||||
val32 = (val32 << 8) | TMC2130_SPI_TXRX(0);
|
||||
val32 = (val32 << 8) | TMC2130_SPI_TXRX(0);
|
||||
val32 = (val32 << 8) | TMC2130_SPI_TXRX(0); // LSB
|
||||
tmc2130_cs_high(axis);
|
||||
TMC2130_SPI_LEAVE();
|
||||
if (rval != 0) *rval = val32;
|
||||
return stat;
|
||||
}
|
||||
|
||||
#endif //NEW_SPI
|
||||
|
||||
|
||||
void tmc2130_eeprom_load_config()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ extern volatile uint16_t buttons; //an extended version of the last checked but
|
|||
LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT);
|
||||
|
||||
// 2 wire Non-latching LCD SR from:
|
||||
// https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection
|
||||
// https://bitbucket.org/fmalpartida/new-LiquidCrystal_Prusa/wiki/schematics#!shiftregister-connection
|
||||
#elif defined(SR_LCD_2W_NL)
|
||||
|
||||
extern "C" void __cxa_pure_virtual() { while (1); }
|
||||
|
@ -206,11 +206,11 @@ extern volatile uint16_t buttons; //an extended version of the last checked but
|
|||
#else
|
||||
// Standard directly connected LCD implementations
|
||||
#ifdef LANGUAGE_RU
|
||||
#include "LiquidCrystalRus.h"
|
||||
#define LCD_CLASS LiquidCrystalRus
|
||||
#include "LiquidCrystal_Rus.h"
|
||||
#define LCD_CLASS LiquidCrystal_Rus
|
||||
#else
|
||||
#include "LiquidCrystal.h"
|
||||
#define LCD_CLASS LiquidCrystal
|
||||
#include "LiquidCrystal_Prusa.h"
|
||||
#define LCD_CLASS LiquidCrystal_Prusa
|
||||
#endif
|
||||
LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue