Add skeleton I2C files.

This commit is contained in:
Jonathan Naylor 2020-11-18 20:21:36 +00:00
parent 2285f9bd82
commit f0804b46e5
10 changed files with 125 additions and 21 deletions

View File

@ -146,8 +146,10 @@ extern CIO io;
#if defined(MODE_OLED) #if defined(MODE_OLED)
extern CI2COLED oled; extern CI2COLED oled;
extern CI2CPort i2C1; #endif
extern CI2CPort i2C3;
#if defined(I2C_REPEATER)
extern CI2CPort i2c1;
#endif #endif
#if defined(MODE_DSTAR) #if defined(MODE_DSTAR)

40
I2COLED.cpp Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright (C) 2020 by Jonathan Naylor G4KLX
*
* 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 version 2 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; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Config.h"
#if defined(MODE_OLED)
#include "I2COLED.h"
CI2COLED::CI2COLED() :
i2c(3U)
{
}
bool CI2COLED::init()
{
return i2c.init();
}
void CI2COLED::setMode(uint8_t state)
{
}
#endif

View File

@ -23,15 +23,20 @@
#if !defined(I2COLED_H) #if !defined(I2COLED_H)
#define I2COLED_H #define I2COLED_H
#include "Globals.h" #include <cstdint>
#include "I2CPort.h"
class CI2COLED { class CI2COLED {
public: public:
CI2COLED(); CI2COLED();
void setMode(MMDVM_STATE state); bool init();
void setMode(uint8_t state);
private: private:
CI2CPort i2c;
}; };
#endif #endif

46
I2CPort.cpp Normal file
View File

@ -0,0 +1,46 @@
/*
* Copyright (C) 2020 by Jonathan Naylor G4KLX
*
* 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 version 2 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; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Config.h"
#if defined(MODE_OLED) || defined(I2C_REPEATER)
#include "I2CPort.h"
CI2CPort::CI2CPort(uint8_t n) :
m_ok(false)
{
}
bool CI2CPort::init()
{
return false;
}
uint8_t CI2CPort::writeCommand(const uint8_t* data, uint8_t length)
{
return 6U;
}
uint8_t CI2CPort::writeData(const uint8_t* data, uint8_t length)
{
return 6U;
}
#endif

View File

@ -23,11 +23,12 @@
#if !defined(I2CPORT_H) #if !defined(I2CPORT_H)
#define I2CPORT_H #define I2CPORT_H
#include "Globals.h" #include <cstdint>
class CI2CPort { class CI2CPort {
public: public:
CI2CPort(); CI2CPort(uint8_t n);
bool init(); bool init();
@ -36,6 +37,7 @@ public:
uint8_t writeData(const uint8_t* data, uint8_t length); uint8_t writeData(const uint8_t* data, uint8_t length);
private: private:
bool m_ok;
}; };
#endif #endif

View File

@ -192,11 +192,11 @@ void CIO::initInt()
#endif #endif
#if defined(MODE_OLED) #if defined(MODE_OLED)
I2C3Init(); oled.init();
#endif #endif
#if defined(I2C_REPEATER) #if defined(I2C_REPEATER)
I2C1Init(); i2c1.init();
#endif #endif
} }

View File

@ -217,6 +217,7 @@ static inline void GPIOInit()
GPIOConfigPin(PORT_LED, PIN_LED, GPIO_CRL_MODE0_1); GPIOConfigPin(PORT_LED, PIN_LED, GPIO_CRL_MODE0_1);
GPIOConfigPin(PORT_COS, PIN_COS, GPIO_CRL_CNF0_1); GPIOConfigPin(PORT_COS, PIN_COS, GPIO_CRL_CNF0_1);
#if defined(MODE_LEDS)
GPIOConfigPin(PORT_DSTAR, PIN_DSTAR, GPIO_CRL_MODE0_1); GPIOConfigPin(PORT_DSTAR, PIN_DSTAR, GPIO_CRL_MODE0_1);
GPIOConfigPin(PORT_DMR, PIN_DMR, GPIO_CRL_MODE0_1); GPIOConfigPin(PORT_DMR, PIN_DMR, GPIO_CRL_MODE0_1);
GPIOConfigPin(PORT_YSF, PIN_YSF, GPIO_CRL_MODE0_1); GPIOConfigPin(PORT_YSF, PIN_YSF, GPIO_CRL_MODE0_1);
@ -229,6 +230,7 @@ static inline void GPIOInit()
#endif #endif
#if !defined(USE_ALTERNATE_POCSAG_LEDS) #if !defined(USE_ALTERNATE_POCSAG_LEDS)
GPIOConfigPin(PORT_POCSAG, PIN_POCSAG, GPIO_CRL_MODE0_1); GPIOConfigPin(PORT_POCSAG, PIN_POCSAG, GPIO_CRL_MODE0_1);
#endif
#endif #endif
GPIOConfigPin(PORT_RX, PIN_RX, 0); GPIOConfigPin(PORT_RX, PIN_RX, 0);
@ -358,10 +360,10 @@ void CIO::initInt()
FancyLEDEffect(); FancyLEDEffect();
#endif #endif
#if defined(MODE_OLED) #if defined(MODE_OLED)
I2C3Init(); oled.init();
#endif #endif
#if defined(I2C_REPEATER) #if defined(I2C_REPEATER)
I2C1Init(); i2c1.init();
#endif #endif
} }
@ -427,6 +429,7 @@ void CIO::setCOSInt(bool on)
BB_COSLED = !!on; BB_COSLED = !!on;
} }
#if defined(MODE_LEDS)
void CIO::setDStarInt(bool on) void CIO::setDStarInt(bool on)
{ {
BB_DSTAR = !!on; BB_DSTAR = !!on;
@ -484,6 +487,7 @@ void CIO::setFMInt(bool on)
BB_YSF = !!on; BB_YSF = !!on;
#endif #endif
} }
#endif
void CIO::delayInt(unsigned int dly) void CIO::delayInt(unsigned int dly)
{ {

View File

@ -43,8 +43,10 @@ bool m_dcd = false;
#if defined(MODE_OLED) #if defined(MODE_OLED)
CI2COLED oled; CI2COLED oled;
CI2CPort i2C1; #endif
CI2CPort i2C3;
#if defined(I2C_REPEATER)
CI2CPort i2c1(1U);
#endif #endif
#if defined(MODE_DSTAR) #if defined(MODE_DSTAR)

View File

@ -40,8 +40,10 @@ bool m_dcd = false;
#if defined(MODE_OLED) #if defined(MODE_OLED)
CI2COLED oled; CI2COLED oled;
CI2CPort i2C1; #endif
CI2CPort i2C3;
#if defined(I2C_REPEATER)
CI2CPort i2C1(1U);
#endif #endif
#if defined(MODE_DSTAR) #if defined(MODE_DSTAR)

View File

@ -350,7 +350,7 @@ void CSerialPort::getVersion()
reply[6U] = io.getCPU(); reply[6U] = io.getCPU();
// Reserve 16 bytes for the UDID // Reserve 16 bytes for the UDID
::memcpy(reply + 7U, 0x00U, 16U); ::memset(reply + 7U, 0x00U, 16U);
io.getUDID(reply + 7U); io.getUDID(reply + 7U);
uint8_t count = 23U; uint8_t count = 23U;
@ -1317,19 +1317,20 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
#if defined(I2C_REPEATER) #if defined(I2C_REPEATER)
case MMDVM_I2C_DATA: { case MMDVM_I2C_DATA: {
uint8_t type = buffer[0U]; uint8_t type = buffer[0U];
uint8_t err = 4U;
switch (type) { switch (type) {
case I2C_COMMAND: case I2C_COMMAND:
err = i2C1.writeCommand(buffer + 1U, length - 1U); err = i2c1.writeCommand(buffer + 1U, length - 1U);
break; break;
case I2C_DATA: case I2C_DATA:
err = i2C1.writeData(buffer + 1U, length - 1U); err = i2c1.writeData(buffer + 1U, length - 1U);
break;
default:
DEBUG2("Received invalid I2C type", type);
err = 4U;
break; break;
} }
if (err != 0U) { if (err != 0U)
DEBUG2("Received invalid I2C data", err);
sendNAK(err); sendNAK(err);
}
} }
break; break;
#endif #endif