diff --git a/Config.h b/Config.h index 6df0d82..56f3cd7 100644 --- a/Config.h +++ b/Config.h @@ -110,9 +110,6 @@ // Use the modem as a serial repeater for Nextion displays // #define SERIAL_REPEATER -// Use the modem as an I2C repeater for an OLED display on I2C1 -#define I2C_REPEATER - // To reduce CPU load, you can remove the DC blocker by commenting out the next line #define USE_DCBLOCKER diff --git a/Globals.h b/Globals.h index 7e33a67..07e6123 100644 --- a/Globals.h +++ b/Globals.h @@ -148,10 +148,6 @@ extern CIO io; extern CI2COLED oled; #endif -#if defined(I2C_REPEATER) -extern CI2CPort i2C1; -#endif - #if defined(MODE_DSTAR) extern CDStarRX dstarRX; extern CDStarTX dstarTX; diff --git a/I2COLED.cpp b/I2COLED.cpp index 1b7e2fd..93a1960 100644 --- a/I2COLED.cpp +++ b/I2COLED.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 by Jonathan Naylor G4KLX + * Copyright (C) 2020,2021 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 @@ -305,7 +305,7 @@ const uint8_t FONT[] = { CI2COLED::CI2COLED() : -m_i2c(3U), +m_i2c(), m_oledBuffer(NULL) { m_oledBuffer = new uint8_t[OLED_BUFFER_SIZE]; diff --git a/I2CPort.cpp b/I2CPort.cpp index f0f0ff0..fde3215 100644 --- a/I2CPort.cpp +++ b/I2CPort.cpp @@ -18,7 +18,7 @@ #include "Config.h" -#if defined(MODE_OLED) || defined(I2C_REPEATER) +#if defined(MODE_OLED) #include "I2CPort.h" @@ -26,77 +26,39 @@ const uint16_t MAX_NBYTES_SIZE = 255U; -CI2CPort::CI2CPort(uint8_t n) : -m_port(NULL), -m_clock(0x00U), -m_ok(true), -m_addr(0x00U) +CI2CPort::CI2CPort() { - switch (n) { - case 1U: - m_port = I2C1; - m_clock = RCC_APB1Periph_I2C1; - m_busSCL = RCC_AHB1Periph_GPIOB; - m_busSDA = RCC_AHB1Periph_GPIOB; - m_af = GPIO_AF4_I2C1; - m_gpioSCL = GPIOB; - m_gpioSDA = GPIOB; - m_pinSCL = GPIO_Pin_8; - m_pinSDA = GPIO_Pin_9; - m_pinSourceSCL = GPIO_PinSource8; - m_pinSourceSDA = GPIO_PinSource9; - break; - case 3U: - m_port = I2C3; - m_clock = RCC_APB1Periph_I2C3; - m_busSCL = RCC_AHB1Periph_GPIOA; - m_busSDA = RCC_AHB1Periph_GPIOC; - m_af = GPIO_AF4_I2C3; - m_gpioSCL = GPIOA; - m_gpioSDA = GPIOC; - m_pinSCL = GPIO_Pin_8; - m_pinSDA = GPIO_Pin_9; - m_pinSourceSCL = GPIO_PinSource8; - m_pinSourceSDA = GPIO_PinSource9; - break; - default: - m_ok = false; - break; - } } bool CI2CPort::init() { - if (!m_ok) - return false; - - // Enable I2C - RCC_APB1PeriphClockCmd(m_clock, ENABLE); + // Enable I2C3 + RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C3, ENABLE); // Reset the Peripheral - RCC_APB1PeriphResetCmd(m_clock, ENABLE); - RCC_APB1PeriphResetCmd(m_clock, DISABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C3, ENABLE); + RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C3, DISABLE); // Enable the GPIOs for the SCL/SDA Pins - RCC_AHB1PeriphClockCmd(m_busSCL | m_busSDA, ENABLE); + RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC, ENABLE); // Configure and initialize the GPIOs GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.GPIO_Pin = m_pinSCL; + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_High_Speed; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_Init(m_gpioSCL, &GPIO_InitStructure); + GPIO_Init(GPIOA, &GPIO_InitStructure); - GPIO_InitStructure.GPIO_Pin = m_pinSDA; - GPIO_Init(m_gpioSDA, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; + GPIO_Init(GPIOC, &GPIO_InitStructure); - // Connect GPIO pins to peripheral - GPIO_PinAFConfig(m_gpioSCL, m_pinSourceSCL, m_af); - GPIO_PinAFConfig(m_gpioSDA, m_pinSourceSDA, m_af); + // Connect GPIO pins to I2C3 + GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF4_I2C3); + GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF4_I2C3); - // Configure and Initialize the I2C + // Configure and Initialize I2C3 I2C_InitTypeDef I2C_InitStructure; I2C_InitStructure.I2C_Timing = 0x0010061AU; // 400kHz (Fast Mode) I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable; @@ -107,21 +69,16 @@ bool CI2CPort::init() I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; // Initialize the Peripheral - I2C_Init(m_port, &I2C_InitStructure); + I2C_Init(I2C3, &I2C_InitStructure); // I2C Peripheral Enable - I2C_Cmd(m_port, ENABLE); - - m_ok = true; + I2C_Cmd(I2C3, ENABLE); return true; } uint8_t CI2CPort::write(uint8_t addr, const uint8_t* data, uint16_t length) { - if (!m_ok) - return 6U; - // Wait for the I2C transmitter to become free if (waitISRFlagsSet(I2C_ISR_BUSY)) return 6U; @@ -141,7 +98,7 @@ uint8_t CI2CPort::write(uint8_t addr, const uint8_t* data, uint16_t length) return 6U; // Write the byte to the TXDR - m_port->TXDR = *data++; + I2C3->TXDR = *data++; length--; size--; @@ -158,9 +115,9 @@ uint8_t CI2CPort::write(uint8_t addr, const uint8_t* data, uint16_t length) if (waitISRFlagsSet(I2C_ISR_STOPF)) return 6U; - m_port->ISR &= ~I2C_ISR_STOPF; + I2C3->ISR &= ~I2C_ISR_STOPF; - m_port->CR2 &= (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_HEAD10R | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_RD_WRN)); + I2C3->CR2 &= (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_HEAD10R | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_RD_WRN)); return 0U; } @@ -171,7 +128,7 @@ bool CI2CPort::waitISRFlagsSet(uint32_t flags) // More than 1 Flag can be "or"ed. uint32_t timeOut = HSI_VALUE; - while ((m_port->ISR & flags) != flags) { + while ((I2C3->ISR & flags) != flags) { if (!(timeOut--)) return false; } @@ -181,14 +138,14 @@ bool CI2CPort::waitISRFlagsSet(uint32_t flags) void CI2CPort::configureDataTransfer(uint8_t size) { - m_port->CR2 &= ~(I2C_CR2_SADD | + I2C3->CR2 &= ~(I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | (I2C_CR2_RD_WRN & (uint32_t)(I2C_Generate_Start_Write >> (31U - I2C_CR2_RD_WRN_Pos))) | I2C_CR2_START | I2C_CR2_STOP); - m_port->CR2 |= (uint32_t)(((uint32_t)m_addr & I2C_CR2_SADD) | + I2C3->CR2 |= (uint32_t)(((uint32_t)m_addr & I2C_CR2_SADD) | (((uint32_t)size << I2C_CR2_NBYTES_Pos) & I2C_CR2_NBYTES) | (uint32_t)I2C_CR2_RELOAD | (uint32_t)I2C_Generate_Start_Write); diff --git a/I2CPort.h b/I2CPort.h index b395d39..2096999 100644 --- a/I2CPort.h +++ b/I2CPort.h @@ -18,7 +18,7 @@ #include "Config.h" -#if defined(MODE_OLED) || defined(I2C_REPEATER) +#if defined(MODE_OLED) #if !defined(I2CPORT_H) #define I2CPORT_H @@ -31,27 +31,13 @@ class CI2CPort { public: - CI2CPort(uint8_t n); + CI2CPort(); bool init(); uint8_t write(uint8_t addr, const uint8_t* data, uint16_t length); private: - I2C_TypeDef* m_port; - uint32_t m_clock; - uint32_t m_busSCL; - uint32_t m_busSDA; - uint8_t m_af; - GPIO_TypeDef* m_gpioSCL; - GPIO_TypeDef* m_gpioSDA; - uint32_t m_pinSCL; - uint32_t m_pinSDA; - uint16_t m_pinSourceSCL; - uint16_t m_pinSourceSDA; - bool m_ok; - uint8_t m_addr; - bool waitISRFlagsSet(uint32_t flags); void configureDataTransfer(uint8_t size); }; diff --git a/IOSTM.cpp b/IOSTM.cpp index ab5570c..2eccd3d 100644 --- a/IOSTM.cpp +++ b/IOSTM.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 2016 by Jim McLaughlin KI6ZUM * Copyright (C) 2016,2017,2018 by Andy Uribe CA6JAU - * Copyright (C) 2017,2018,2020 by Jonathan Naylor G4KLX + * Copyright (C) 2017,2018,2020,2021 by Jonathan Naylor G4KLX * Copyright (C) 2019,2020 by BG5HHP * * This program is free software; you can redistribute it and/or modify @@ -194,10 +194,6 @@ void CIO::initInt() #if defined(MODE_OLED) oled.init(); #endif - -#if defined(I2C_REPEATER) - i2C1.init(); -#endif } void CIO::startInt() diff --git a/IOSTM_CMSIS.cpp b/IOSTM_CMSIS.cpp index a9c7136..d3a562a 100644 --- a/IOSTM_CMSIS.cpp +++ b/IOSTM_CMSIS.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 2016 by Jim McLaughlin KI6ZUM * Copyright (C) 2016, 2017 by Andy Uribe CA6JAU - * Copyright (C) 2017,2018,2020 by Jonathan Naylor G4KLX + * Copyright (C) 2017,2018,2020,2021 by Jonathan Naylor G4KLX * Copyright (C) 2017 by Wojciech Krutnik N0CALL * * This program is free software; you can redistribute it and/or modify @@ -362,9 +362,6 @@ void CIO::initInt() #if defined(MODE_OLED) oled.init(); #endif -#if defined(I2C_REPEATER) - i2c1.init(); -#endif } void CIO::startInt() diff --git a/MMDVM.cpp b/MMDVM.cpp index f1ce58a..29bc30d 100644 --- a/MMDVM.cpp +++ b/MMDVM.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016,2017,2018,2020 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX * Copyright (C) 2016 by Mathis Schmieder DB9MAT * Copyright (C) 2016 by Colin Durbridge G4EML * @@ -45,10 +45,6 @@ bool m_dcd = false; CI2COLED oled; #endif -#if defined(I2C_REPEATER) -CI2CPort i2C1(1U); -#endif - #if defined(MODE_DSTAR) CDStarRX dstarRX; CDStarTX dstarTX; diff --git a/SerialPort.cpp b/SerialPort.cpp index 67d9aa8..3250e01 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -84,7 +84,6 @@ const uint8_t MMDVM_ACK = 0x70U; const uint8_t MMDVM_NAK = 0x7FU; const uint8_t MMDVM_SERIAL_DATA = 0x80U; -const uint8_t MMDVM_I2C_DATA = 0x81U; const uint8_t MMDVM_TRANSPARENT = 0x90U; const uint8_t MMDVM_QSO_INFO = 0x91U; @@ -1342,17 +1341,6 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l break; #endif -#if defined(I2C_REPEATER) - case MMDVM_I2C_DATA: { - err = i2C1.write(buffer[0U], buffer + 1U, length - 1U); - if (err != 0U) { - DEBUG2("Received invalid I2C data", err); - sendNAK(err); - } - } - break; -#endif - default: // Handle this, send a NAK back sendNAK(1U); diff --git a/mmdvmmenu.sh b/mmdvmmenu.sh deleted file mode 100755 index 7c31b4a..0000000 --- a/mmdvmmenu.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/bash - -############################################################################### -# -# mmdvmmenu.sh -# -# Copyright (C) 2016 by Paul Nannery KC2VRJ -# -# 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. -# -############################################################################### -# -# On a Linux based system, such as a Raspberry Pi, this script will perform -# Modification of the Config.h file for most options. It makes a Back up when -# you start the script if none is present. You must recompile and load firmware -# onto the Arduino Due if changes are made. -# -############################################################################### -# -# CONFIGURATION -# -# Location of Config.h -conf=Config.h -#Location of backup file -confbak=Config.h.bak - -################################################################################ -# -# Do not edit below here -# -############################################################################### - - - -# Check for backup file and make one if not present - -if [ ! -f $confbak ];then - -cp -f $conf $confbak - -fi - -while : -do - clear - cat< $conf.tmp && mv -f $conf.tmp $conf && echo "12.000 MHz clock enabled";; - "2") sed -e 's/\/\/ #define EXTERNAL_OSC 12288000/#define EXTERNAL_OSC 12288000/' $conf > $conf.tmp && mv -f $conf.tmp $conf && echo "12.288 MHz clock enabled";; - "3") sed -e 's/\/\/ #define EXTERNAL_OSC 14400000/#define EXTERNAL_OSC 14400000/' $conf > $conf.tmp && mv -f $conf.tmp $conf && echo "14.400 MHz clock enabled";; - "4") sed -e 's/\/\/ #define EXTERNAL_OSC 19200000/#define EXTERNAL_OSC 19200000/' $conf > $conf.tmp && mv -f $conf.tmp $conf && echo "19.200 MHz clock enabled";; - "5") sed -e 's/\/\/ #define USE_COS_AS_LOCKOUT /#define USE_COS_AS_LOCKOUT/' $conf > $conf.tmp && mv -f $conf.tmp $conf && echo "COS as Lockout enabled";; - "6") sed -e 's/\/\/ #define MODE_LEDS/#define MODE_LEDS/' $conf > $conf.tmp && mv -f $conf.tmp $conf && echo "Mode pins enabled";; - "7") sed -e 's/\/\/ #define ARDUINO_DUE_PAPA/#define ARDUINO_DUE_PAPA/' $conf > $conf.tmp && mv -f $conf.tmp $conf && echo "Layout for the PAPA board enabled";; - "8") sed -e 's/\/\/ #define ARDUINO_DUE_ZUM_V10/#define ARDUINO_DUE_ZUM_V10/' $conf > $conf.tmp && mv -f $conf.tmp $conf && echo "Layout for ZUM V1.0 and V1.0.1 boards enabled";; - "9") sed -e 's/\/\/ #define ARDUINO_DUE_NTH/#define ARDUINO_DUE_NTH/' $conf > $conf.tmp && mv -f $conf.tmp $conf && echo "Layout for SP8NTH board enabled";; - "0") sed -e 's/\/\/ #define SERIAL_REPEATER/#define SERIAL_REPEATER/' $conf > $conf.tmp && mv -f $conf.tmp $conf && echo "Modem display driver enabled";; - "A") mv -f $confbak $conf ;; - "a") mv -f $confbak $conf ;; - "Q") echo "If any changes are made you need to (re-)upload the firmware to MMDVM" && exit;; - "q") echo "If any changes are made you need to (re-)upload the firmware to MMDVM" && exit;; - * ) echo "invalid option" ;; - esac - sleep 1 -done