PAT9125 I2C, hardware SG homing
separate pin configuration file for each board changed board codes: RAMBO =100, MiniRambo1.0 =200, MiniRambo1.3 = 203, Einy03 =303, Einy04 =304
This commit is contained in:
parent
a7477673de
commit
683784c4c7
22 changed files with 1260 additions and 890 deletions
Firmware
|
@ -1,108 +1,93 @@
|
|||
#include "swspi.h"
|
||||
|
||||
|
||||
#ifdef SWSPI_RPI
|
||||
#include <bcm2835.h>
|
||||
#define GPIO_INP(gpio) bcm2835_gpio_fsel(gpio, BCM2835_GPIO_FSEL_INPT)
|
||||
#define GPIO_OUT(gpio) bcm2835_gpio_fsel(gpio, BCM2835_GPIO_FSEL_OUTP)
|
||||
#define GPIO_SET(gpio) bcm2835_gpio_write(gpio, HIGH)
|
||||
#define GPIO_CLR(gpio) bcm2835_gpio_write(gpio, LOW)
|
||||
#define GPIO_GET(gpio) (bcm2835_gpio_lev(gpio) != LOW)
|
||||
#define DELAY(delay) usleep(delay)
|
||||
#endif //SWSPI_RPI
|
||||
|
||||
#ifdef SWSPI_AVR
|
||||
//#include "Arduino.h"
|
||||
#include "Marlin.h"
|
||||
#define GPIO_INP(gpio) pinMode(gpio, INPUT)
|
||||
#define GPIO_OUT(gpio) pinMode(gpio, OUTPUT)
|
||||
#define GPIO_SET(gpio) digitalWrite(gpio, HIGH)
|
||||
#define GPIO_CLR(gpio) digitalWrite(gpio, LOW)
|
||||
#define GPIO_GET(gpio) (digitalRead(gpio) != LOW)
|
||||
#define DELAY(delay) delayMicroseconds(delay)
|
||||
#endif //SWSPI_AVR
|
||||
|
||||
#if (SWSPI_POL != 0)
|
||||
#define SWSPI_SCK_UP GPIO_CLR(SWSPI_SCK)
|
||||
#define SWSPI_SCK_DN GPIO_SET(SWSPI_SCK)
|
||||
#else
|
||||
#define SWSPI_SCK_UP GPIO_SET(SWSPI_SCK)
|
||||
#define SWSPI_SCK_DN GPIO_CLR(SWSPI_SCK)
|
||||
#endif
|
||||
|
||||
|
||||
void swspi_init()
|
||||
{
|
||||
GPIO_INP(SWSPI_MISO);
|
||||
GPIO_OUT(SWSPI_MOSI);
|
||||
GPIO_OUT(SWSPI_SCK);
|
||||
GPIO_OUT(SWSPI_CS);
|
||||
GPIO_CLR(SWSPI_MOSI);
|
||||
SWSPI_SCK_DN;
|
||||
GPIO_SET(SWSPI_CS);
|
||||
}
|
||||
|
||||
#if (SWSPI_MOSI == SWSPI_MISO)
|
||||
|
||||
void swspi_tx(unsigned char tx)
|
||||
{
|
||||
GPIO_OUT(SWSPI_MOSI);
|
||||
unsigned char i = 0; for (; i < 8; i++)
|
||||
{
|
||||
if (tx & 0x80) GPIO_SET(SWSPI_MOSI);
|
||||
else GPIO_CLR(SWSPI_MOSI);
|
||||
DELAY(SWSPI_DEL);
|
||||
SWSPI_SCK_UP;
|
||||
DELAY(SWSPI_DEL);
|
||||
SWSPI_SCK_DN;
|
||||
tx <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char swspi_rx()
|
||||
{
|
||||
GPIO_INP(SWSPI_MISO);
|
||||
unsigned char rx = 0;
|
||||
unsigned char i = 0; for (; i < 8; i++)
|
||||
{
|
||||
rx <<= 1;
|
||||
DELAY(SWSPI_DEL);
|
||||
SWSPI_SCK_UP;
|
||||
DELAY(SWSPI_DEL);
|
||||
rx |= GPIO_GET(SWSPI_MISO)?1:0;
|
||||
SWSPI_SCK_DN;
|
||||
}
|
||||
return rx;
|
||||
}
|
||||
|
||||
#else //(SWSPI_MOSI == SWSPI_MISO)
|
||||
|
||||
unsigned char swspi_txrx(unsigned char tx)
|
||||
{
|
||||
unsigned char rx = 0;
|
||||
unsigned char i = 0; for (; i < 8; i++)
|
||||
{
|
||||
rx <<= 1;
|
||||
if (tx & 0x80) GPIO_SET(SWSPI_MOSI);
|
||||
else GPIO_CLR(SWSPI_MOSI);
|
||||
DELAY(SWSPI_DEL);
|
||||
SWSPI_SCK_UP;
|
||||
DELAY(SWSPI_DEL);
|
||||
rx |= GPIO_GET(SWSPI_MISO)?1:0;
|
||||
SWSPI_SCK_DN;
|
||||
tx <<= 1;
|
||||
}
|
||||
return rx;
|
||||
}
|
||||
|
||||
#endif //(SWSPI_MOSI == SWSPI_MISO)
|
||||
|
||||
void swspi_start()
|
||||
{
|
||||
GPIO_CLR(SWSPI_CS);
|
||||
}
|
||||
|
||||
void swspi_stop()
|
||||
{
|
||||
GPIO_SET(SWSPI_CS);
|
||||
}
|
||||
#include "uni_avr_rpi.h"
|
||||
|
||||
#ifdef __SWSPI
|
||||
#include "swspi.h"
|
||||
|
||||
#ifdef __RPI
|
||||
//#define swspi_miso 9
|
||||
#define swspi_miso 10
|
||||
#define swspi_mosi 10
|
||||
#define swspi_sck 11
|
||||
#define SWSPI_CS 7
|
||||
#endif //__RPI
|
||||
|
||||
|
||||
#define SWSPI_DEL 0x0f //delay mask (0-3. bit, delay = 1 << DEL [us])
|
||||
#define SWSPI_POL 0x10 //polarity mask (4. bit, 1=inverted)
|
||||
#define SWSPI_PHA 0x20 //phase mask (5. bit)
|
||||
#define SWSPI_DOR 0x40 //data order mask (6. bit, 0=MSB first, 1=LSB first)
|
||||
|
||||
#define SWSPI_SCK_UP if (swspi_cfg & SWSPI_POL) GPIO_CLR(swspi_sck); else GPIO_SET(swspi_sck);
|
||||
#define SWSPI_SCK_DN if (swspi_cfg & SWSPI_POL) GPIO_SET(swspi_sck); else GPIO_CLR(swspi_sck);
|
||||
|
||||
unsigned char swspi_miso = 0;
|
||||
unsigned char swspi_mosi = 0;
|
||||
unsigned char swspi_sck = 0;
|
||||
unsigned char swspi_cfg = 0;
|
||||
|
||||
void swspi_init(unsigned char miso, unsigned char mosi, unsigned char sck, unsigned char cfg)
|
||||
{
|
||||
swspi_miso = miso;
|
||||
swspi_mosi = mosi;
|
||||
swspi_sck = sck;
|
||||
swspi_cfg = cfg;
|
||||
GPIO_INP(swspi_miso);
|
||||
GPIO_OUT(swspi_mosi);
|
||||
GPIO_OUT(swspi_sck);
|
||||
GPIO_CLR(swspi_mosi);
|
||||
SWSPI_SCK_DN;
|
||||
}
|
||||
|
||||
void swspi_tx(unsigned char tx)
|
||||
{
|
||||
int delay = 1 << (swspi_cfg & SWSPI_DEL));
|
||||
if (swspi_miso == swspi_mosi) GPIO_OUT(swspi_mosi);
|
||||
unsigned char i = 0; for (; i < 8; i++)
|
||||
{
|
||||
if (tx & 0x80) GPIO_SET(swspi_mosi);
|
||||
else GPIO_CLR(swspi_mosi);
|
||||
DELAY(delay);
|
||||
SWSPI_SCK_UP;
|
||||
DELAY(delay);
|
||||
SWSPI_SCK_DN;
|
||||
tx <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char swspi_rx()
|
||||
{
|
||||
int delay = 1 << (swspi_cfg & SWSPI_DEL));
|
||||
if (swspi_miso == swspi_mosi) GPIO_OUT(swspi_mosi);
|
||||
unsigned char rx = 0;
|
||||
unsigned char i = 0; for (; i < 8; i++)
|
||||
{
|
||||
rx <<= 1;
|
||||
DELAY(delay);
|
||||
SWSPI_SCK_UP;
|
||||
DELAY(delay);
|
||||
rx |= GPIO_GET(swspi_miso)?1:0;
|
||||
SWSPI_SCK_DN;
|
||||
}
|
||||
return rx;
|
||||
}
|
||||
|
||||
unsigned char swspi_txrx(unsigned char tx)
|
||||
{
|
||||
int delay = 1 << (swspi_cfg & SWSPI_DEL));
|
||||
unsigned char rx = 0;
|
||||
unsigned char i = 0; for (; i < 8; i++)
|
||||
{
|
||||
rx <<= 1;
|
||||
if (tx & 0x80) GPIO_SET(swspi_mosi);
|
||||
else GPIO_CLR(swspi_mosi);
|
||||
DELAY(delay);
|
||||
SWSPI_SCK_UP;
|
||||
DELAY(delay);
|
||||
rx |= GPIO_GET(swspi_miso)?1:0;
|
||||
SWSPI_SCK_DN;
|
||||
tx <<= 1;
|
||||
}
|
||||
return rx;
|
||||
}
|
||||
|
||||
#endif //__SWSPI
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue