diff --git a/Globals.h b/Globals.h index 32b0396..1e0b04c 100644 --- a/Globals.h +++ b/Globals.h @@ -146,8 +146,10 @@ extern CIO io; #if defined(MODE_OLED) extern CI2COLED oled; -extern CI2CPort i2C1; -extern CI2CPort i2C3; +#endif + +#if defined(I2C_REPEATER) +extern CI2CPort i2c1; #endif #if defined(MODE_DSTAR) diff --git a/I2COLED.cpp b/I2COLED.cpp new file mode 100644 index 0000000..96616a5 --- /dev/null +++ b/I2COLED.cpp @@ -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 + diff --git a/I2COLED.h b/I2COLED.h index 2f63e08..f46ff85 100644 --- a/I2COLED.h +++ b/I2COLED.h @@ -23,15 +23,20 @@ #if !defined(I2COLED_H) #define I2COLED_H -#include "Globals.h" +#include + +#include "I2CPort.h" class CI2COLED { public: CI2COLED(); - void setMode(MMDVM_STATE state); + bool init(); + + void setMode(uint8_t state); private: + CI2CPort i2c; }; #endif diff --git a/I2CPort.cpp b/I2CPort.cpp new file mode 100644 index 0000000..6f366a1 --- /dev/null +++ b/I2CPort.cpp @@ -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 + diff --git a/I2CPort.h b/I2CPort.h index 5fd4dd3..01cb7d8 100644 --- a/I2CPort.h +++ b/I2CPort.h @@ -23,11 +23,12 @@ #if !defined(I2CPORT_H) #define I2CPORT_H -#include "Globals.h" +#include + class CI2CPort { public: - CI2CPort(); + CI2CPort(uint8_t n); bool init(); @@ -36,6 +37,7 @@ public: uint8_t writeData(const uint8_t* data, uint8_t length); private: + bool m_ok; }; #endif diff --git a/IOSTM.cpp b/IOSTM.cpp index f5b13ea..62f6582 100644 --- a/IOSTM.cpp +++ b/IOSTM.cpp @@ -192,11 +192,11 @@ void CIO::initInt() #endif #if defined(MODE_OLED) - I2C3Init(); + oled.init(); #endif #if defined(I2C_REPEATER) - I2C1Init(); + i2c1.init(); #endif } diff --git a/IOSTM_CMSIS.cpp b/IOSTM_CMSIS.cpp index 2a0baa9..a9c7136 100644 --- a/IOSTM_CMSIS.cpp +++ b/IOSTM_CMSIS.cpp @@ -217,6 +217,7 @@ static inline void GPIOInit() GPIOConfigPin(PORT_LED, PIN_LED, GPIO_CRL_MODE0_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_DMR, PIN_DMR, GPIO_CRL_MODE0_1); GPIOConfigPin(PORT_YSF, PIN_YSF, GPIO_CRL_MODE0_1); @@ -229,6 +230,7 @@ static inline void GPIOInit() #endif #if !defined(USE_ALTERNATE_POCSAG_LEDS) GPIOConfigPin(PORT_POCSAG, PIN_POCSAG, GPIO_CRL_MODE0_1); +#endif #endif GPIOConfigPin(PORT_RX, PIN_RX, 0); @@ -358,10 +360,10 @@ void CIO::initInt() FancyLEDEffect(); #endif #if defined(MODE_OLED) - I2C3Init(); + oled.init(); #endif #if defined(I2C_REPEATER) - I2C1Init(); + i2c1.init(); #endif } @@ -427,6 +429,7 @@ void CIO::setCOSInt(bool on) BB_COSLED = !!on; } +#if defined(MODE_LEDS) void CIO::setDStarInt(bool on) { BB_DSTAR = !!on; @@ -484,6 +487,7 @@ void CIO::setFMInt(bool on) BB_YSF = !!on; #endif } +#endif void CIO::delayInt(unsigned int dly) { diff --git a/MMDVM.cpp b/MMDVM.cpp index c023828..a4a3593 100644 --- a/MMDVM.cpp +++ b/MMDVM.cpp @@ -43,8 +43,10 @@ bool m_dcd = false; #if defined(MODE_OLED) CI2COLED oled; -CI2CPort i2C1; -CI2CPort i2C3; +#endif + +#if defined(I2C_REPEATER) +CI2CPort i2c1(1U); #endif #if defined(MODE_DSTAR) diff --git a/MMDVM.ino b/MMDVM.ino index 7b049a6..cd63b42 100644 --- a/MMDVM.ino +++ b/MMDVM.ino @@ -40,8 +40,10 @@ bool m_dcd = false; #if defined(MODE_OLED) CI2COLED oled; -CI2CPort i2C1; -CI2CPort i2C3; +#endif + +#if defined(I2C_REPEATER) +CI2CPort i2C1(1U); #endif #if defined(MODE_DSTAR) diff --git a/SerialPort.cpp b/SerialPort.cpp index a2a75f3..64c5b80 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -350,7 +350,7 @@ void CSerialPort::getVersion() reply[6U] = io.getCPU(); // Reserve 16 bytes for the UDID - ::memcpy(reply + 7U, 0x00U, 16U); + ::memset(reply + 7U, 0x00U, 16U); io.getUDID(reply + 7U); 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) case MMDVM_I2C_DATA: { uint8_t type = buffer[0U]; - uint8_t err = 4U; switch (type) { case I2C_COMMAND: - err = i2C1.writeCommand(buffer + 1U, length - 1U); + err = i2c1.writeCommand(buffer + 1U, length - 1U); break; 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; } - if (err != 0U) { - DEBUG2("Received invalid I2C data", err); + if (err != 0U) sendNAK(err); - } } break; #endif