ponyprog/SrcPony/spi-bus.h

139 lines
3.3 KiB
C
Raw Normal View History

2000-02-05 22:37:44 +00:00
//=========================================================================//
// //
// PonyProg - Serial Device Programmer //
// //
2020-02-05 17:23:29 +01:00
// Copyright (C) 1997-2020 Claudio Lanconelli //
2000-02-05 22:37:44 +00:00
// //
// http://ponyprog.sourceforge.net //
2000-02-05 22:37:44 +00:00
// //
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
// as published by the Free Software Foundation; either version2 of //
// the License, or (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
// General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program (see LICENSE); if not, write to the //
2000-02-05 22:37:44 +00:00
// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
// //
//=========================================================================//
2017-04-18 01:25:22 +02:00
#ifndef _SPIBUS_H
#define _SPIBUS_H
2000-02-05 22:37:44 +00:00
#include "busio.h"
#include "pgminter.h"
class SPIBus : public BusIO
{
public:
SPIBus(BusInterface *ptr = 0, bool cpha = false, bool cpol = false);
2000-02-05 22:37:44 +00:00
virtual ~SPIBus();
virtual int Reset();
void SetDelay();
2008-01-27 23:39:11 +00:00
void SetFallingPhase(bool cpha)
2017-04-18 01:25:22 +02:00
{
m_cpha = cpha;
}
bool GetFallingPhase()
{
return m_cpha;
}
void SetClockPolarity(bool cpol)
{
m_cpol = cpol;
}
bool GetClockPolarity()
{
return m_cpol;
}
void SetMode(int mode)
{
m_cpol = ((mode & SPIMODE_CPOL) != 0);
m_cpha = ((mode & SPIMODE_CPHA) != 0);
}
void SetMode(bool cpha, bool cpol)
{
m_cpol = cpol;
m_cpha = cpha;
}
int GetMode()
{
int mode = 0;
if (m_cpol)
{
mode |= SPIMODE_CPOL;
}
if (m_cpha)
{
mode |= SPIMODE_CPHA;
}
return mode;
2017-04-18 01:25:22 +02:00
}
2000-02-05 22:37:44 +00:00
protected:
2000-02-05 22:37:44 +00:00
int SendDataByte(int by);
int RecDataByte();
void SetReset()
2017-04-18 01:25:22 +02:00
{
busI->SetControlLine(1);
}
2000-02-05 22:37:44 +00:00
void ClearReset()
2017-04-18 01:25:22 +02:00
{
busI->SetControlLine(0);
}
2000-02-05 22:37:44 +00:00
void setSCK()
2017-04-18 01:25:22 +02:00
{
busI->SetClock(1);
}
2000-02-05 22:37:44 +00:00
void clearSCK()
2017-04-18 01:25:22 +02:00
{
busI->SetClock(0);
}
2000-02-05 22:37:44 +00:00
int SendDataBit(int b);
int RecDataBit();
2017-04-29 01:56:50 +02:00
private:
2000-02-05 22:37:44 +00:00
void bitMOSI(int b)
2017-04-18 01:25:22 +02:00
{
busI->SetDataOut(b);
}
2000-02-05 22:37:44 +00:00
void setMOSI()
2017-04-18 01:25:22 +02:00
{
busI->SetDataOut(1);
}
2000-02-05 22:37:44 +00:00
void clearMOSI()
2017-04-18 01:25:22 +02:00
{
busI->SetDataOut(0);
}
2000-02-05 22:37:44 +00:00
int getMISO() const
2017-04-18 01:25:22 +02:00
{
return busI->GetDataIn();
}
bool m_cpol; //clock polarity
bool m_cpha; //rising edge vs fall edge sample
2000-02-05 22:37:44 +00:00
};
#endif