mirror of
https://github.com/g4klx/MMDVM.git
synced 2026-10-16 00:34:12 +02:00
Compare commits
46
Commits
PlatformIO
..
I2C
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73866ab591 | ||
|
|
ed84db6ee4 | ||
|
|
406a60d787 | ||
|
|
f06774aadd | ||
|
|
e32f13d3df | ||
|
|
7db7bbb02e | ||
|
|
794acf1df8 | ||
|
|
02ba20401b | ||
|
|
ee3ab88b2a | ||
|
|
a5d4295cce | ||
|
|
1e97e7c2a0 | ||
|
|
246539526d | ||
|
|
3c6a1f262a | ||
|
|
51b275d4c7 | ||
|
|
639caa03ee | ||
|
|
4f3e6935d2 | ||
|
|
a3e0ad82e2 | ||
|
|
4aa30664b9 | ||
|
|
c83879d89d | ||
|
|
683c5afccb | ||
|
|
c70540a8ac | ||
|
|
93115c8931 | ||
|
|
2ae731e78c | ||
|
|
f033fea2fb | ||
|
|
4539f48af2 | ||
|
|
8747794e27 | ||
|
|
e94f5bb13a | ||
|
|
28a0910638 | ||
|
|
2dd8b74346 | ||
|
|
2190dc1042 | ||
|
|
9b76867548 | ||
|
|
df749d3286 | ||
|
|
5e8e0577da | ||
|
|
6c8cf7a838 | ||
|
|
112a136060 | ||
|
|
b4ff147a19 | ||
|
|
757c3ce0d5 | ||
|
|
a119311d93 | ||
|
|
7f7ce2072a | ||
|
|
1978b2b357 | ||
|
|
6f1fe8d4b9 | ||
|
|
f0804b46e5 | ||
|
|
2285f9bd82 | ||
|
|
53b5659639 | ||
|
|
864dfa9221 | ||
|
|
335c32c540 |
+5
-3
@@ -1,3 +1,5 @@
|
||||
.pio
|
||||
.vscode
|
||||
|
||||
*.o
|
||||
obj/
|
||||
bin/
|
||||
GitVersion.h
|
||||
build/
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
[submodule "STM32F4XX_Lib"]
|
||||
path = STM32F4XX_Lib
|
||||
url = https://github.com/juribeparada/STM32F4XX_Lib.git
|
||||
[submodule "STM32F10X_Lib"]
|
||||
path = STM32F10X_Lib
|
||||
url = https://github.com/shawnchain/STM32F10X_Lib.git
|
||||
[submodule "STM32F7XX_Lib"]
|
||||
path = STM32F7XX_Lib
|
||||
url = https://github.com/g4klx/STM32F7XX_Lib.git
|
||||
|
||||
@@ -25,11 +25,12 @@
|
||||
#include "AX25Demodulator.h"
|
||||
#include "AX25Defines.h"
|
||||
|
||||
const uint32_t SYMBOL_RATE = 1200U;
|
||||
const float32_t SAMPLE_RATE = 24000.0F;
|
||||
const float32_t SYMBOL_RATE = 1200.0F;
|
||||
|
||||
const uint16_t DELAY_LEN = 11U;
|
||||
|
||||
const float32_t SAMPLES_PER_SYMBOL = float32_t(SAMPLE_RATE / SYMBOL_RATE);
|
||||
const float32_t SAMPLES_PER_SYMBOL = SAMPLE_RATE / SYMBOL_RATE;
|
||||
const float32_t PLL_LIMIT = SAMPLES_PER_SYMBOL / 2.0F;
|
||||
|
||||
const uint32_t LPF_FILTER_LEN = 48U;
|
||||
@@ -193,7 +193,7 @@ void CAX25RX::initRand() //Can also be used to seed the rng with more entropy du
|
||||
{
|
||||
m_a = (m_a ^ m_c ^ m_x);
|
||||
m_b = (m_b + m_a);
|
||||
m_c = (m_c + ((m_b >> 1) ^ m_a));
|
||||
m_c = (m_c + (m_b >> 1) ^ m_a);
|
||||
}
|
||||
|
||||
uint8_t CAX25RX::rand()
|
||||
@@ -202,7 +202,7 @@ uint8_t CAX25RX::rand()
|
||||
|
||||
m_a = (m_a ^ m_c ^ m_x); //note the mix of addition and XOR
|
||||
m_b = (m_b + m_a); //And the use of very few instructions
|
||||
m_c = (m_c + ((m_b >> 1) ^ m_a)); //the right shift is to ensure that high-order bits from b can affect
|
||||
m_c = (m_c + (m_b >> 1) ^ m_a); //the right shift is to ensure that high-order bits from b can affect
|
||||
|
||||
return uint8_t(m_c); //low order bits of other variables
|
||||
}
|
||||
@@ -160,7 +160,7 @@ void CAX25TX::writeBit(bool b)
|
||||
m_tablePtr += 11U;
|
||||
}
|
||||
|
||||
buffer[i] = value >> 1;
|
||||
buffer[i] = value;
|
||||
|
||||
if (m_tablePtr >= AUDIO_TABLE_LEN)
|
||||
m_tablePtr -= AUDIO_TABLE_LEN;
|
||||
@@ -0,0 +1,125 @@
|
||||
In order to build MMDVM, you need to tell the Arduino GUI to link with the
|
||||
CMSIS DSP library, which is doesn't do by default.
|
||||
|
||||
My development is on Windows and so I can vouch for the following instructions.
|
||||
|
||||
For Arduino 1.6.3 with SAM 1.6.4
|
||||
--------------------------------
|
||||
|
||||
1. Go to the where the platform.txt file is located. On my Windows machine it's
|
||||
in:
|
||||
|
||||
C:\Users\Jonathan\AppData\Roaming\Arduino15\packages\arduino\hardware\sam\1.6.4
|
||||
|
||||
On Mac OS X it's located in:
|
||||
|
||||
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/sam
|
||||
Or
|
||||
~/Library/Arduino15/packages/arduino/hardware/sam/1.6.6
|
||||
|
||||
2. You'll need to open the file in a text editor and find the line:
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc
|
||||
|
||||
In my version it's line 73.
|
||||
|
||||
3. Modify it to read as follows:
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mcpu={build.mcu} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group "{build.path}/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.system.path}/CMSIS/CMSIS/Lib/ARM/arm_cortexM3l_math.lib" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc
|
||||
|
||||
The change is near the end, and is the addition of:
|
||||
|
||||
"{build.system.path}/CMSIS/CMSIS/Lib/ARM/arm_cortexM3l_math.lib"
|
||||
|
||||
Which is the CMSIS AMR3 DSP library for little-endian operation.
|
||||
|
||||
4. Save the file and start up the Arduino GUI and build MMDVM.
|
||||
|
||||
I would like to get instructions for doing the same on a Linux platform. As a
|
||||
starter find the relevent platform.txt and try adding:
|
||||
|
||||
"{build.system.path}/CMSIS/CMSIS/Lib/ARM/libarm_cortexM3l_math.a"
|
||||
|
||||
or maybe:
|
||||
|
||||
"{build.variant.path}/libarm_cortexM3l_math.a"
|
||||
|
||||
Likely on Linux
|
||||
|
||||
"{build.system.path}/CMSIS/CMSIS/Lib/GCC/libarm_cortexM3l_math.a"
|
||||
|
||||
As with Arduino 1.6.7 with SAM 1.6.6, see below.
|
||||
|
||||
|
||||
For Arduino 1.6.7 with SAM 1.6.6
|
||||
--------------------------------
|
||||
(checked OK on Arduino 1.6.11 and SAM 1.6.9)
|
||||
|
||||
1. Go to the where the platform.txt file is located. On my Windows machine it's
|
||||
in:
|
||||
|
||||
C:\Users\Jonathan\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.6
|
||||
|
||||
On Mac OS X it's located in:
|
||||
|
||||
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/sam
|
||||
|
||||
On Linux, it's located in my home directory, downloaded and extracted from Arduino website, but must be installed.
|
||||
|
||||
/home/m1geo/arduino-1.6.7/hardware/arduino/sam
|
||||
|
||||
or
|
||||
|
||||
/home/m1geo/.arduino15/packages/arduino/hardware/sam/1.6.9 (if you let the board/library manager install SAM)
|
||||
|
||||
|
||||
I (M1GEO) found it was necessary to download SAM-1.6.6 outside of the Arduino IDE, and manually extract the files.
|
||||
The Board Manager didn't seem to install the SAM files correctly. Here's how I did it:
|
||||
|
||||
a) wget http://downloads.arduino.cc/cores/sam-1.6.6.tar.bz2 -O /tmp/sam-1.6.6.tar.bz2 (download and save in /tmp)
|
||||
b) cd arduino-1.6.7/hardware/arduino/ (Arduino root, here, in my home directory)
|
||||
c) tar xvfj /tmp/sam-1.6.6.tar.bz2
|
||||
|
||||
2. You'll need to open the file (platform.txt) in a text editor and find the line:
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -mcpu={build.mcu} -mthumb {compiler.c.elf.flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group "{build.path}/core/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc
|
||||
|
||||
In my version it's line 73.
|
||||
|
||||
3. Modify it to read as follows:
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -mcpu={build.mcu} -mthumb {compiler.c.elf.flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group "{build.path}/core/syscalls_sam3.c.o" {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.system.path}/CMSIS/CMSIS/Lib/ARM/arm_cortexM3l_math.lib" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc
|
||||
|
||||
The change is near the end, and is the addition of:
|
||||
|
||||
"{build.system.path}/CMSIS/CMSIS/Lib/ARM/arm_cortexM3l_math.lib"
|
||||
|
||||
On Linux, the path was found to differ slightly (GCC instead of ARM):
|
||||
|
||||
"{build.system.path}/CMSIS/CMSIS/Lib/GCC/libarm_cortexM3l_math.a"
|
||||
|
||||
Which is the CMSIS AMR3 DSP library for little-endian operation.
|
||||
|
||||
4. Save the file and start up the Arduino GUI and build MMDVM.
|
||||
|
||||
For Arduino 1.6.9 with SAM 1.6.8
|
||||
--------------------------------
|
||||
|
||||
1. Locate platform.txt. On Ubuntu 14.04 LTS x86_64 OS it is in:
|
||||
|
||||
/home/$user/.arduino15/packages/arduino/hardware/sam/1.6.8/
|
||||
|
||||
2. Open the file in a text editor and change the line:
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -mcpu={build.mcu} -mthumb {compiler.c.elf.flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group {compiler.combine.flags} {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc
|
||||
|
||||
to
|
||||
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" -mcpu={build.mcu} -mthumb {compiler.c.elf.flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group {compiler.combine.flags} {object_files} "{build.variant.path}/{build.variant_system_lib}" "{build.system.path}/CMSIS/CMSIS/Lib/GCC/libarm_cortexM3l_math.a" "{build.path}/{archive_file}" -Wl,--end-group -lm -gcc
|
||||
|
||||
3. Save the file, open the Arduino IDE and build MMDVM
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (C) 2015,2016,2017,2018,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.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_H)
|
||||
#define CONFIG_H
|
||||
|
||||
// Allow for the selection of which modes to compile into the firmware. This is particularly useful for processors
|
||||
// which have limited code space and processing power like the STM32F103, which is found on older/cheaper boards.
|
||||
|
||||
// Enable D-Star support.
|
||||
#define MODE_DSTAR
|
||||
|
||||
// Enable DMR support.
|
||||
#define MODE_DMR
|
||||
|
||||
// Enable System Fusion support.
|
||||
#define MODE_YSF
|
||||
|
||||
// Enable P25 phase 1 support.
|
||||
#define MODE_P25
|
||||
|
||||
// Enable NXDN support, the boxcar filter sometimes improves the performance of NXDN receive on some systems.
|
||||
#define MODE_NXDN
|
||||
#define USE_NXDN_BOXCAR
|
||||
|
||||
// Enable M17 support.
|
||||
#define MODE_M17
|
||||
|
||||
// Enable POCSAG support.
|
||||
#define MODE_POCSAG
|
||||
|
||||
// Enable FM support.
|
||||
#define MODE_FM
|
||||
|
||||
// Enable AX.25 support, this is only enabled if FM is also enabled.
|
||||
#define MODE_AX25
|
||||
|
||||
// Allow for the use of high quality external clock oscillators
|
||||
// The number is the frequency of the oscillator in Hertz.
|
||||
//
|
||||
// The frequency of the TCXO must be an integer multiple of 48000.
|
||||
// Frequencies such as 12.0 Mhz (48000 * 250) and 14.4 Mhz (48000 * 300) are suitable.
|
||||
// Frequencies such as 10.0 Mhz (48000 * 208.333) or 20 Mhz (48000 * 416.666) are not suitable.
|
||||
//
|
||||
// For 12 MHz
|
||||
// #define EXTERNAL_OSC 12000000
|
||||
// For 12.288 MHz
|
||||
// #define EXTERNAL_OSC 12288000
|
||||
// For 14.4 MHz
|
||||
// #define EXTERNAL_OSC 14400000
|
||||
// For 19.2 MHz
|
||||
// #define EXTERNAL_OSC 19200000
|
||||
|
||||
// Use a higher baudrate for host communication. Required for FM network !
|
||||
// #define SERIAL_SPEED 115200 //suitable for most older boards (Arduino, Due STM32F1_POG etc). External FM will NOT work with this !
|
||||
// #define SERIAL_SPEED 230400 // Only works on newer board M4, M7, Teensy. External FM might work with this
|
||||
#define SERIAL_SPEED 460800 // Only works on newer board M4, M7, Teensy. External FM should work with this
|
||||
|
||||
// Allow the use of the COS line to lockout the modem
|
||||
// #define USE_COS_AS_LOCKOUT
|
||||
|
||||
// Use pins to output the current mode via LEDs
|
||||
// #define MODE_LEDS
|
||||
|
||||
// Use an OLED to show the current mode via a small screen (64x32) on I2C3
|
||||
#define MODE_OLED
|
||||
|
||||
// For the original Arduino Due pin layout
|
||||
// #define ARDUINO_DUE_PAPA
|
||||
|
||||
#if defined(STM32F1)
|
||||
// For the SQ6POG board
|
||||
#define STM32F1_POG
|
||||
#else
|
||||
// For the ZUM V1.0 and V1.0.1 boards pin layout
|
||||
// #define ARDUINO_DUE_ZUM_V10
|
||||
#endif
|
||||
|
||||
// For the SP8NTH board
|
||||
// #define ARDUINO_DUE_NTH
|
||||
|
||||
// For ST Nucleo-64 STM32F446RE board
|
||||
// #define STM32F4_NUCLEO_MORPHO_HEADER
|
||||
// #define STM32F4_NUCLEO_ARDUINO_HEADER
|
||||
|
||||
// Use separate mode pins to switch external channel/filters/bandwidth for example
|
||||
// #define MODE_PINS
|
||||
|
||||
// For the VK6MST Pi3 Shield communicating over i2c. i2c address & speed defined in i2cTeensy.cpp
|
||||
// #define VK6MST_TEENSY_PI3_SHIELD_I2C
|
||||
|
||||
// Pass RSSI information to the host
|
||||
#define SEND_RSSI_DATA
|
||||
|
||||
// Use the modem as a serial repeater for Nextion displays
|
||||
// #define SERIAL_REPEATER
|
||||
|
||||
// To reduce CPU load, you can remove the DC blocker by commenting out the next line
|
||||
#define USE_DCBLOCKER
|
||||
|
||||
// Constant Service LED once repeater is running
|
||||
// Do not use if employing an external hardware watchdog
|
||||
// #define CONSTANT_SRV_LED
|
||||
|
||||
// Use the YSF and P25 LEDs for NXDN
|
||||
// #define USE_ALTERNATE_NXDN_LEDS
|
||||
|
||||
// Use the D-Star and P25 LEDs for M17
|
||||
// #define USE_ALTERNATE_M17_LEDS
|
||||
|
||||
// Use the D-Star and DMR LEDs for POCSAG
|
||||
// #define USE_ALTERNATE_POCSAG_LEDS
|
||||
|
||||
// Use the D-Star and YSF LEDs for FM
|
||||
// #define USE_ALTERNATE_FM_LEDS
|
||||
|
||||
#if defined(MODE_OLED)
|
||||
#undef MODE_LEDS
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+13
-183
@@ -28,6 +28,13 @@ const uint16_t FM_SERIAL_BLOCK_SIZE = 80U;//this is the number of sample pairs t
|
||||
//three times this value shall never exceed 252
|
||||
const uint16_t FM_SERIAL_BLOCK_SIZE_BYTES = FM_SERIAL_BLOCK_SIZE * 3U;
|
||||
|
||||
/*
|
||||
* Access Mode values are:
|
||||
* 0 - Carrier access with COS
|
||||
* 1 - CTCSS only access without COS
|
||||
* 2 - CTCSS only access with COS
|
||||
* 3 - CTCSS only access with COS to start, then carrier access with COS
|
||||
*/
|
||||
|
||||
CFM::CFM() :
|
||||
m_callsign(),
|
||||
@@ -56,7 +63,6 @@ m_filterStage2(32768, 0,-32768, 32768, -50339, 19052),
|
||||
m_filterStage3(32768, -65536, 32768, 32768, -64075, 31460),
|
||||
m_blanking(),
|
||||
m_accessMode(1U),
|
||||
m_linkMode(false),
|
||||
m_cosInvert(false),
|
||||
m_noiseSquelch(false),
|
||||
m_rfAudioBoost(1U),
|
||||
@@ -66,9 +72,7 @@ m_extEnabled(false),
|
||||
m_rxLevel(1),
|
||||
m_inputRFRB(2401U), // 100ms of audio + 1 sample
|
||||
m_outputRFRB(2400U), // 100ms of audio
|
||||
m_inputExtRB(),
|
||||
m_rfSignal(false),
|
||||
m_extSignal(false)
|
||||
m_inputExtRB()
|
||||
{
|
||||
m_statusTimer.setTimeout(1U, 0U);
|
||||
m_reverseTimer.setTimeout(0U, 150U);
|
||||
@@ -77,14 +81,6 @@ m_extSignal(false)
|
||||
}
|
||||
|
||||
void CFM::samples(bool cos, q15_t* samples, uint8_t length)
|
||||
{
|
||||
if (m_linkMode)
|
||||
linkSamples(cos, samples, length);
|
||||
else
|
||||
repeaterSamples(cos, samples, length);
|
||||
}
|
||||
|
||||
void CFM::repeaterSamples(bool cos, q15_t* samples, uint8_t length)
|
||||
{
|
||||
if (m_cosInvert)
|
||||
cos = !cos;
|
||||
@@ -223,108 +219,6 @@ void CFM::repeaterSamples(bool cos, q15_t* samples, uint8_t length)
|
||||
}
|
||||
}
|
||||
|
||||
void CFM::linkSamples(bool cos, q15_t* samples, uint8_t length)
|
||||
{
|
||||
if (m_cosInvert)
|
||||
cos = !cos;
|
||||
|
||||
clock(length);
|
||||
|
||||
uint8_t i = 0U;
|
||||
for (; i < length; i++) {
|
||||
// ARMv7-M has hardware integer division
|
||||
q15_t currentRFSample = q15_t((q31_t(samples[i]) << 8) / m_rxLevel);
|
||||
|
||||
if (m_noiseSquelch)
|
||||
cos = m_squelch.process(currentRFSample);
|
||||
|
||||
q15_t currentExtSample;
|
||||
bool inputExt = m_inputExtRB.getSample(currentExtSample);//always consume the external input data so it does not overflow
|
||||
inputExt = inputExt && m_extEnabled;
|
||||
|
||||
switch (m_accessMode) {
|
||||
case 0U:
|
||||
if (!inputExt && !cos && m_modemState != STATE_FM)
|
||||
continue;
|
||||
else
|
||||
stateMachine(cos, inputExt);
|
||||
break;
|
||||
|
||||
case 1U: {
|
||||
bool ctcss = m_ctcssRX.process(currentRFSample);
|
||||
|
||||
// Delay the audio by 100ms to better match the CTCSS detector output
|
||||
m_inputRFRB.put(currentRFSample);
|
||||
m_inputRFRB.get(currentRFSample);
|
||||
|
||||
if (!inputExt && !ctcss && m_modemState != STATE_FM) {
|
||||
// No CTCSS detected, just carry on
|
||||
continue;
|
||||
} else if ((inputExt || ctcss) && m_modemState != STATE_FM) {
|
||||
// We had CTCSS or external input
|
||||
stateMachine(ctcss, inputExt);
|
||||
if (m_state == FS_LISTENING)
|
||||
continue;
|
||||
} else {
|
||||
stateMachine(ctcss, inputExt);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 2U: {
|
||||
bool ctcss = m_ctcssRX.process(currentRFSample);
|
||||
if (!inputExt && !ctcss && m_modemState != STATE_FM) {
|
||||
// No CTCSS detected, just carry on
|
||||
continue;
|
||||
} else if ((inputExt || (ctcss && cos)) && m_modemState != STATE_FM) {
|
||||
// We had CTCSS or external input
|
||||
stateMachine(ctcss && cos, inputExt);
|
||||
if (m_state == FS_LISTENING)
|
||||
continue;
|
||||
} else {
|
||||
stateMachine(ctcss && cos, inputExt);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default: {
|
||||
bool ctcss = m_ctcssRX.process(currentRFSample);
|
||||
if (!inputExt && !ctcss && m_modemState != STATE_FM) {
|
||||
// No CTCSS detected, just carry on
|
||||
continue;
|
||||
} else if ((inputExt || (ctcss && cos)) && m_modemState != STATE_FM) {
|
||||
// We had CTCSS or external input
|
||||
stateMachine(ctcss && cos, inputExt);
|
||||
if (m_state == FS_LISTENING)
|
||||
continue;
|
||||
} else {
|
||||
stateMachine(cos, inputExt);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_modemState != STATE_FM)
|
||||
continue;
|
||||
|
||||
if (m_rfSignal && m_extEnabled) {
|
||||
q15_t currentSample = m_blanking.process(currentRFSample);
|
||||
m_downSampler.addSample(currentSample);
|
||||
}
|
||||
|
||||
if (!m_extSignal)
|
||||
continue;
|
||||
|
||||
q15_t currentSample = currentExtSample * m_extAudioBoost;
|
||||
|
||||
currentSample = m_filterStage3.filter(m_filterStage2.filter(m_filterStage1.filter(currentSample)));
|
||||
|
||||
currentSample += m_ctcssTX.getAudio(m_reverseTimer.isRunning());
|
||||
|
||||
m_outputRFRB.put(currentSample);
|
||||
}
|
||||
}
|
||||
|
||||
void CFM::process()
|
||||
{
|
||||
uint16_t space = io.getSpace();
|
||||
@@ -393,8 +287,6 @@ void CFM::reset()
|
||||
m_squelch.reset();
|
||||
|
||||
m_needReverse = false;
|
||||
m_rfSignal = false;
|
||||
m_extSignal = false;
|
||||
}
|
||||
|
||||
uint8_t CFM::setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, uint8_t time, uint8_t holdoff, uint8_t highLevel, uint8_t lowLevel, bool callsignAtStart, bool callsignAtEnd, bool callsignAtLatch)
|
||||
@@ -425,10 +317,9 @@ uint8_t CFM::setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_
|
||||
return m_rfAck.setParams(rfAck, speed, frequency, level, level);
|
||||
}
|
||||
|
||||
uint8_t CFM::setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssHighThreshold, uint8_t ctcssLowThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime, uint8_t accessMode, bool linkMode, bool cosInvert, bool noiseSquelch, uint8_t squelchHighThreshold, uint8_t squelchLowThreshold, uint8_t rfAudioBoost, uint8_t maxDev, uint8_t rxLevel)
|
||||
uint8_t CFM::setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssHighThreshold, uint8_t ctcssLowThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime, uint8_t accessMode, bool cosInvert, bool noiseSquelch, uint8_t squelchHighThreshold, uint8_t squelchLowThreshold, uint8_t rfAudioBoost, uint8_t maxDev, uint8_t rxLevel)
|
||||
{
|
||||
m_accessMode = accessMode;
|
||||
m_linkMode = linkMode;
|
||||
m_cosInvert = cosInvert;
|
||||
m_noiseSquelch = noiseSquelch;
|
||||
|
||||
@@ -465,14 +356,10 @@ uint8_t CFM::setExt(const char* ack, uint8_t audioBoost, uint8_t speed, uint16_t
|
||||
|
||||
void CFM::stateMachine(bool validRFSignal, bool validExtSignal)
|
||||
{
|
||||
if (m_linkMode) {
|
||||
linkStateMachine(validRFSignal, validExtSignal);
|
||||
} else {
|
||||
if (m_duplex)
|
||||
duplexStateMachine(validRFSignal, validExtSignal);
|
||||
else
|
||||
simplexStateMachine(validRFSignal, validExtSignal);
|
||||
}
|
||||
if (m_duplex)
|
||||
duplexStateMachine(validRFSignal, validExtSignal);
|
||||
else
|
||||
simplexStateMachine(validRFSignal, validExtSignal);
|
||||
}
|
||||
|
||||
void CFM::simplexStateMachine(bool validRFSignal, bool validExtSignal)
|
||||
@@ -1122,63 +1009,6 @@ void CFM::timeoutExtWaitStateSimplex(bool validSignal)
|
||||
}
|
||||
}
|
||||
|
||||
void CFM::linkStateMachine(bool validRFSignal, bool validExtSignal)
|
||||
{
|
||||
if (validRFSignal && !m_rfSignal) {
|
||||
io.setDecode(true);
|
||||
io.setADCDetection(true);
|
||||
|
||||
if (!m_extSignal) {
|
||||
DEBUG1("State to RELAYING_RF");
|
||||
m_state = FS_RELAYING_RF;
|
||||
m_statusTimer.start();
|
||||
serial.writeFMStatus(m_state);
|
||||
}
|
||||
|
||||
m_rfSignal = true;
|
||||
}
|
||||
|
||||
if (validExtSignal && !m_extSignal) {
|
||||
if (!m_rfSignal) {
|
||||
DEBUG1("State to RELAYING_EXT");
|
||||
m_state = FS_RELAYING_EXT;
|
||||
m_statusTimer.start();
|
||||
serial.writeFMStatus(m_state);
|
||||
}
|
||||
|
||||
insertSilence(50U);
|
||||
|
||||
m_extSignal = true;
|
||||
}
|
||||
|
||||
if (!validRFSignal && m_rfSignal) {
|
||||
io.setDecode(false);
|
||||
io.setADCDetection(false);
|
||||
|
||||
if (!m_extSignal) {
|
||||
DEBUG1("State to LISTENING");
|
||||
m_state = FS_LISTENING;
|
||||
m_statusTimer.stop();
|
||||
}
|
||||
|
||||
m_rfSignal = false;
|
||||
|
||||
if (m_extEnabled)
|
||||
serial.writeFMEOT();
|
||||
}
|
||||
|
||||
if (!validExtSignal && m_extSignal) {
|
||||
if (!m_rfSignal) {
|
||||
DEBUG1("State to LISTENING");
|
||||
m_state = FS_LISTENING;
|
||||
m_statusTimer.stop();
|
||||
}
|
||||
|
||||
m_needReverse = true;
|
||||
m_extSignal = false;
|
||||
}
|
||||
}
|
||||
|
||||
void CFM::sendCallsign()
|
||||
{
|
||||
if (m_holdoffTimer.isRunning()) {
|
||||
+2
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020,2021 by Jonathan Naylor G4KLX
|
||||
* 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
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
|
||||
uint8_t setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, uint8_t time, uint8_t holdoff, uint8_t highLevel, uint8_t lowLevel, bool callsignAtStart, bool callsignAtEnd, bool callsignAtLatch);
|
||||
uint8_t setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_t minTime, uint16_t delay, uint8_t level);
|
||||
uint8_t setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssHighThreshold, uint8_t ctcssLowThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime, uint8_t accessMode, bool linkMode, bool cosInvert, bool noiseSquelch, uint8_t squelchHighThreshold, uint8_t squelchLowThreshold, uint8_t rfAudioBoost, uint8_t maxDev, uint8_t rxLevel);
|
||||
uint8_t setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssHighThreshold, uint8_t ctcssLowThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime, uint8_t accessMode, bool cosInvert, bool noiseSquelch, uint8_t squelchHighThreshold, uint8_t squelchLowThreshold, uint8_t rfAudioBoost, uint8_t maxDev, uint8_t rxLevel);
|
||||
uint8_t setExt(const char* ack, uint8_t audioBoost, uint8_t speed, uint16_t frequency, uint8_t level);
|
||||
|
||||
uint8_t getSpace() const;
|
||||
@@ -97,7 +97,6 @@ private:
|
||||
CFMDirectFormI m_filterStage3;
|
||||
CFMBlanking m_blanking;
|
||||
uint8_t m_accessMode;
|
||||
bool m_linkMode;
|
||||
bool m_cosInvert;
|
||||
bool m_noiseSquelch;
|
||||
q15_t m_rfAudioBoost;
|
||||
@@ -108,14 +107,9 @@ private:
|
||||
CRingBuffer<q15_t> m_inputRFRB;
|
||||
CRingBuffer<q15_t> m_outputRFRB;
|
||||
CFMUpSampler m_inputExtRB;
|
||||
bool m_rfSignal;
|
||||
bool m_extSignal;
|
||||
|
||||
void stateMachine(bool validRFSignal, bool validExtSignal);
|
||||
|
||||
void repeaterSamples(bool cos, q15_t* samples, uint8_t length);
|
||||
void linkSamples(bool cos, q15_t* samples, uint8_t length);
|
||||
|
||||
void duplexStateMachine(bool validRFSignal, bool validExtSignal);
|
||||
void listeningStateDuplex(bool validRFSignal, bool validExtSignal);
|
||||
void kerchunkRFStateDuplex(bool validSignal);
|
||||
@@ -141,8 +135,6 @@ private:
|
||||
void timeoutExtStateSimplex(bool validSignal);
|
||||
void timeoutExtWaitStateSimplex(bool validSignal);
|
||||
|
||||
void linkStateMachine(bool validRFSignal, bool validExtSignal);
|
||||
|
||||
void clock(uint8_t length);
|
||||
|
||||
void sendCallsign();
|
||||
@@ -42,7 +42,8 @@ class CFMDirectFormI
|
||||
public:
|
||||
|
||||
// convenience function which takes the a0 argument but ignores it!
|
||||
CFMDirectFormI(const q31_t b0, const q31_t b1, const q31_t b2, const q31_t, const q31_t a1, const q31_t a2)
|
||||
CFMDirectFormI(const q31_t b0, const q31_t b1, const q31_t b2,
|
||||
const q31_t, const q31_t a1, const q31_t a2)
|
||||
{
|
||||
// FIR coefficients
|
||||
c_b0 = b0;
|
||||
@@ -56,21 +57,21 @@ public:
|
||||
|
||||
CFMDirectFormI(const CFMDirectFormI &my)
|
||||
{
|
||||
// delay line
|
||||
// delay line
|
||||
m_x2 = my.m_x2; // x[n-2]
|
||||
m_y2 = my.m_y2; // y[n-2]
|
||||
m_x1 = my.m_x1; // x[n-1]
|
||||
m_y1 = my.m_y1; // y[n-1]
|
||||
|
||||
// coefficients
|
||||
// coefficients
|
||||
c_b0 = my.c_b0;
|
||||
c_b1 = my.c_b1;
|
||||
c_b2 = my.c_b2; // FIR
|
||||
c_a1 = my.c_a1;
|
||||
c_a2 = my.c_a2; // IIR
|
||||
}
|
||||
}
|
||||
|
||||
void reset()
|
||||
void reset ()
|
||||
{
|
||||
m_x1 = 0;
|
||||
m_x2 = 0;
|
||||
@@ -82,7 +83,11 @@ public:
|
||||
inline q15_t filter(const q15_t in)
|
||||
{
|
||||
// calculate the output
|
||||
q31_t out_upscaled = c_b0 * in + c_b1 * m_x1 + c_b2 * m_x2 - c_a1 * m_y1 - c_a2 * m_y2;
|
||||
register q31_t out_upscaled = c_b0 * in
|
||||
+ c_b1 * m_x1
|
||||
+ c_b2 * m_x2
|
||||
- c_a1 * m_y1
|
||||
- c_a2 * m_y2;
|
||||
|
||||
q15_t out = __SSAT(out_upscaled >> 15, 15);
|
||||
|
||||
+54
-36
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2015,2016,2017,2018,2020,2021,2024 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2015,2016,2017,2018,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
|
||||
@@ -19,8 +19,27 @@
|
||||
#if !defined(GLOBALS_H)
|
||||
#define GLOBALS_H
|
||||
|
||||
#if defined(STM32F4XX)
|
||||
#include "stm32f4xx.h"
|
||||
#elif defined(STM32F7XX)
|
||||
#include "stm32f7xx.h"
|
||||
#elif defined(STM32F105xC)
|
||||
#include "stm32f1xx.h"
|
||||
#include "STM32Utils.h"
|
||||
#else
|
||||
#include <Arduino.h>
|
||||
#undef PI //Undefine PI to get rid of annoying warning as it is also defined in arm_math.h.
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__) || defined(STM32F105xC)
|
||||
#define ARM_MATH_CM3
|
||||
#elif defined(STM32F7XX)
|
||||
#define ARM_MATH_CM7
|
||||
#elif defined(STM32F4XX) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
||||
#define ARM_MATH_CM4
|
||||
#else
|
||||
#error "Unknown processor type"
|
||||
#endif
|
||||
|
||||
#include <arm_math.h>
|
||||
|
||||
@@ -53,43 +72,42 @@ enum MMDVM_STATE {
|
||||
STATE_FMCAL15K = 104,
|
||||
STATE_FMCAL20K = 105,
|
||||
STATE_FMCAL25K = 106,
|
||||
STATE_FMCAL30K = 107,
|
||||
STATE_M17CAL = 108
|
||||
STATE_FMCAL30K = 107
|
||||
};
|
||||
|
||||
#include "SerialPort.h"
|
||||
|
||||
#include "POCSAG/CalPOCSAG.h"
|
||||
#include "DStar/CalDStarRX.h"
|
||||
#include "DStar/CalDStarTX.h"
|
||||
#include "POCSAG/POCSAGTX.h"
|
||||
#include "DStar/DStarRX.h"
|
||||
#include "DStar/DStarTX.h"
|
||||
#include "DMR/DMRIdleRX.h"
|
||||
#include "DMR/DMRDMORX.h"
|
||||
#include "DMR/DMRDMOTX.h"
|
||||
#include "NXDN/CalNXDN.h"
|
||||
#include "NXDN/NXDNRX.h"
|
||||
#include "NXDN/NXDNTX.h"
|
||||
#include "AX25/AX25RX.h"
|
||||
#include "AX25/AX25TX.h"
|
||||
#include "DMR/CalDMR.h"
|
||||
#include "P25/CalP25.h"
|
||||
#include "M17/CalM17.h"
|
||||
#include "DMR/DMRRX.h"
|
||||
#include "DMR/DMRTX.h"
|
||||
#include "YSF/YSFRX.h"
|
||||
#include "YSF/YSFTX.h"
|
||||
#include "P25/P25RX.h"
|
||||
#include "P25/P25TX.h"
|
||||
#include "M17/M17RX.h"
|
||||
#include "M17/M17TX.h"
|
||||
#include "FM/CalFM.h"
|
||||
#include "DMRIdleRX.h"
|
||||
#include "DMRDMORX.h"
|
||||
#include "DMRDMOTX.h"
|
||||
#include "DStarRX.h"
|
||||
#include "DStarTX.h"
|
||||
#include "DMRRX.h"
|
||||
#include "DMRTX.h"
|
||||
#include "YSFRX.h"
|
||||
#include "YSFTX.h"
|
||||
#include "P25RX.h"
|
||||
#include "P25TX.h"
|
||||
#include "M17RX.h"
|
||||
#include "M17TX.h"
|
||||
#include "NXDNRX.h"
|
||||
#include "NXDNTX.h"
|
||||
#include "POCSAGTX.h"
|
||||
#include "CalDStarRX.h"
|
||||
#include "CalDStarTX.h"
|
||||
#include "CalFM.h"
|
||||
#include "CalDMR.h"
|
||||
#include "CalP25.h"
|
||||
#include "CalNXDN.h"
|
||||
#include "CalPOCSAG.h"
|
||||
#include "CalRSSI.h"
|
||||
#include "I2COLED.h"
|
||||
#include "CWIdTX.h"
|
||||
#include "FM/FM.h"
|
||||
#include "AX25RX.h"
|
||||
#include "AX25TX.h"
|
||||
#include "Debug.h"
|
||||
#include "I2C3.h"
|
||||
#include "IO.h"
|
||||
#include "FM.h"
|
||||
|
||||
const uint8_t MARK_SLOT1 = 0x08U;
|
||||
const uint8_t MARK_SLOT2 = 0x04U;
|
||||
@@ -100,9 +118,7 @@ const uint16_t RX_BLOCK_SIZE = 2U;
|
||||
const uint16_t TX_RINGBUFFER_SIZE = 500U;
|
||||
const uint16_t RX_RINGBUFFER_SIZE = 600U;
|
||||
|
||||
const uint32_t SAMPLE_RATE = 24000U;
|
||||
|
||||
#if defined(__MK20DX256__)
|
||||
#if defined(STM32F105xC) || defined(__MK20DX256__)
|
||||
const uint16_t TX_BUFFER_LEN = 2000U;
|
||||
#else
|
||||
const uint16_t TX_BUFFER_LEN = 4000U;
|
||||
@@ -128,6 +144,10 @@ extern bool m_dcd;
|
||||
extern CSerialPort serial;
|
||||
extern CIO io;
|
||||
|
||||
#if defined(MODE_OLED)
|
||||
extern CI2COLED oled;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_DSTAR)
|
||||
extern CDStarRX dstarRX;
|
||||
extern CDStarTX dstarTX;
|
||||
@@ -174,8 +194,6 @@ extern CCalPOCSAG calPOCSAG;
|
||||
#if defined(MODE_M17)
|
||||
extern CM17RX m17RX;
|
||||
extern CM17TX m17TX;
|
||||
|
||||
extern CCalM17 calM17;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_FM)
|
||||
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* 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
|
||||
* 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 "I2C3.h"
|
||||
|
||||
#include "Globals.h"
|
||||
|
||||
|
||||
#define I2C_WRITE_REG(REG, VAL) ((REG) = (VAL))
|
||||
#define I2C_READ_REG(REG) ((REG))
|
||||
|
||||
#define I2C_CLEAR_FLAG(__FLAG__) (((__FLAG__) == I2C_FLAG_TXE) ? (I2C3->ISR |= (__FLAG__)) : (I2C3->ICR = (__FLAG__)))
|
||||
#define I2C_GET_FLAG(__FLAG__) ((((I2C3->ISR) & (__FLAG__)) == (__FLAG__)) ? SET : RESET)
|
||||
|
||||
#define I2C_RESET_CR2() (I2C3->CR2 &= (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_HEAD10R | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_RD_WRN)))
|
||||
|
||||
#define I2C_MODIFY_REG(REG, CLEARMASK, SETMASK) I2C_WRITE_REG((REG), (((I2C_READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
|
||||
|
||||
#define TIMING_CLEAR_MASK (0xF0FFFFFFU)
|
||||
|
||||
#define I2C_DUALADDRESS_DISABLE (0x00000000U)
|
||||
#define I2C_DUALADDRESS_ENABLE I2C_OAR2_OA2EN
|
||||
|
||||
#define I2C_GENERALCALL_DISABLE (0x00000000U)
|
||||
|
||||
#define I2C_NOSTRETCH_DISABLE (0x00000000U)
|
||||
|
||||
#define I2C_ANALOGFILTER_ENABLE 0x00000000U
|
||||
|
||||
#define RCC_I2C3CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
|
||||
|
||||
#define I2C_OA2_NOMASK ((uint8_t)0x00U)
|
||||
|
||||
#define GPIO_MODE_AF_OD ((uint32_t)0x00000012U)
|
||||
|
||||
#define GPIO_OUTPUT_TYPE ((uint32_t)0x00000010U)
|
||||
|
||||
#define GPIO_MODE ((uint32_t)0x00000003U)
|
||||
|
||||
#define GPIO_NUMBER (16U)
|
||||
|
||||
#define I2C_ENABLE() (SET_BIT(I2C3->CR1, I2C_CR1_PE))
|
||||
|
||||
#define I2C_DISABLE() (CLEAR_BIT(I2C3->CR1, I2C_CR1_PE))
|
||||
|
||||
#define RCC_GPIOA_CLK_ENABLE() do { \
|
||||
__IO uint32_t tmpreg; \
|
||||
SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOAEN);\
|
||||
tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOAEN);\
|
||||
} while(0)
|
||||
|
||||
#define RCC_GPIOC_CLK_ENABLE() do { \
|
||||
__IO uint32_t tmpreg; \
|
||||
SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);\
|
||||
tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);\
|
||||
} while(0)
|
||||
|
||||
#define RCC_I2C3_CLK_ENABLE() do { \
|
||||
__IO uint32_t tmpreg; \
|
||||
SET_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C3EN);\
|
||||
tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C3EN);\
|
||||
} while(0)
|
||||
|
||||
CI2C3::CI2C3()
|
||||
{
|
||||
}
|
||||
|
||||
void CI2C3::init()
|
||||
{
|
||||
// Enable the I2C3 clock
|
||||
I2C_MODIFY_REG(RCC->DCKCFGR2, RCC_DCKCFGR2_I2C3SEL, RCC_I2C3CLKSOURCE_PCLK1);
|
||||
|
||||
// Enable the GPIOs for the SCL/SDA Pins
|
||||
RCC_GPIOC_CLK_ENABLE();
|
||||
RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
initI2C3();
|
||||
|
||||
// Configure Analogue filter
|
||||
configAnalogFilter(I2C_ANALOGFILTER_ENABLE);
|
||||
|
||||
// Configure Digital filter
|
||||
configDigitalFilter(0U);
|
||||
}
|
||||
|
||||
void CI2C3::write(uint16_t addr, const uint8_t* data, uint8_t length)
|
||||
{
|
||||
DEBUG2("OLED Data", addr);
|
||||
DEBUG_DUMP(data, length);
|
||||
|
||||
// Shift the address to the left
|
||||
addr <<= 3;
|
||||
|
||||
// Wait for the I2C transmitter to become free
|
||||
while (I2C_GET_FLAG(I2C_FLAG_BUSY) == SET)
|
||||
;
|
||||
|
||||
// Configure the data transfer
|
||||
transferConfig(addr, length, I2C_CR2_AUTOEND, I2C_Generate_Start_Write);
|
||||
|
||||
// Start Writing Data
|
||||
for (uint16_t i = 0U; i < length; i++) {
|
||||
// Wait for the TXIS flag to be set
|
||||
while (I2C_GET_FLAG(I2C_FLAG_TXIS) == RESET)
|
||||
;
|
||||
|
||||
// Write the byte to the TXDR
|
||||
I2C3->TXDR = data[i];
|
||||
}
|
||||
|
||||
// No need to Check TC flag, with AUTOEND mode the stop is automatically generated Wait until STOPF flag is set
|
||||
while (I2C_GET_FLAG(I2C_FLAG_STOPF) == RESET)
|
||||
;
|
||||
|
||||
// Clear STOP flag
|
||||
I2C_CLEAR_FLAG(I2C_FLAG_STOPF);
|
||||
|
||||
// Clear Configuration Register 2
|
||||
I2C_RESET_CR2();
|
||||
}
|
||||
|
||||
void CI2C3::transferConfig(uint16_t addr, uint8_t length, uint32_t mode, uint32_t request)
|
||||
{
|
||||
// Update CR2 register
|
||||
I2C_MODIFY_REG(I2C3->CR2, ((I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | \
|
||||
(I2C_CR2_RD_WRN & (uint32_t)(request >> (31U - I2C_CR2_RD_WRN_Pos))) | I2C_CR2_START | I2C_CR2_STOP)), \
|
||||
(uint32_t)(((uint32_t)addr & I2C_CR2_SADD) |
|
||||
(((uint32_t)length << I2C_CR2_NBYTES_Pos) & I2C_CR2_NBYTES) | (uint32_t)mode | (uint32_t)request));
|
||||
}
|
||||
|
||||
void CI2C3::configAnalogFilter(uint32_t AnalogFilter)
|
||||
{
|
||||
// Disable the selected I2C peripheral
|
||||
I2C_DISABLE();
|
||||
|
||||
// Reset I2Cx ANOFF bit
|
||||
I2C3->CR1 &= ~(I2C_CR1_ANFOFF);
|
||||
|
||||
// Set analog filter bit
|
||||
I2C3->CR1 |= AnalogFilter;
|
||||
|
||||
I2C_ENABLE();
|
||||
}
|
||||
|
||||
void CI2C3::configDigitalFilter(uint32_t DigitalFilter)
|
||||
{
|
||||
// Disable the selected I2C peripheral
|
||||
I2C_DISABLE();
|
||||
|
||||
// Get the old register value
|
||||
uint32_t tmpreg = I2C3->CR1;
|
||||
|
||||
// Reset I2Cx DNF bits [11:8]
|
||||
tmpreg &= ~(I2C_CR1_DNF);
|
||||
|
||||
// Set I2Cx DNF coefficient
|
||||
tmpreg |= DigitalFilter << 8U;
|
||||
|
||||
// Store the new register value
|
||||
I2C3->CR1 = tmpreg;
|
||||
|
||||
I2C_ENABLE();
|
||||
}
|
||||
|
||||
void CI2C3::initI2C3()
|
||||
{
|
||||
initMSP();
|
||||
|
||||
/* Disable the selected I2C peripheral */
|
||||
I2C_DISABLE();
|
||||
|
||||
/*---------------------------- I2Cx TIMINGR Configuration ------------------*/
|
||||
/* Configure I2Cx: Frequency range */
|
||||
I2C3->TIMINGR = 0x0010061AU & TIMING_CLEAR_MASK;
|
||||
|
||||
/*---------------------------- I2Cx OAR1 Configuration ---------------------*/
|
||||
/* Disable Own Address1 before set the Own Address1 configuration */
|
||||
I2C3->OAR1 &= ~I2C_OAR1_OA1EN;
|
||||
|
||||
/* Configure I2Cx: Own Address1 and ack own address1 mode */
|
||||
I2C3->OAR1 = (I2C_OAR1_OA1EN | 0U);
|
||||
|
||||
/*---------------------------- I2Cx CR2 Configuration ----------------------*/
|
||||
/* Enable the AUTOEND by default, and enable NACK (should be disable only during Slave process */
|
||||
I2C3->CR2 |= (I2C_CR2_AUTOEND | I2C_CR2_NACK);
|
||||
|
||||
/*---------------------------- I2Cx OAR2 Configuration ---------------------*/
|
||||
/* Disable Own Address2 before set the Own Address2 configuration */
|
||||
I2C3->OAR2 &= ~I2C_DUALADDRESS_ENABLE;
|
||||
|
||||
/* Configure I2Cx: Dual mode and Own Address2 */
|
||||
I2C3->OAR2 = (I2C_DUALADDRESS_DISABLE | 0U | (I2C_OA2_NOMASK << 8));
|
||||
|
||||
/*---------------------------- I2Cx CR1 Configuration ----------------------*/
|
||||
/* Configure I2Cx: Generalcall and NoStretch mode */
|
||||
I2C3->CR1 = (I2C_GENERALCALL_DISABLE | I2C_NOSTRETCH_DISABLE);
|
||||
|
||||
/* Enable the selected I2C peripheral */
|
||||
I2C_ENABLE();
|
||||
}
|
||||
|
||||
void CI2C3::initMSP()
|
||||
{
|
||||
RCC_GPIOC_CLK_ENABLE();
|
||||
RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
/* I2C3 GPIO Configuration
|
||||
PC9 ------> I2C3_SDA
|
||||
PA8 ------> I2C3_SCL
|
||||
*/
|
||||
initGPIO(GPIOC, GPIO_Pin_9);
|
||||
initGPIO(GPIOA, GPIO_Pin_8);
|
||||
|
||||
// Peripheral clock enable
|
||||
RCC_I2C3_CLK_ENABLE();
|
||||
}
|
||||
|
||||
void CI2C3::initGPIO(GPIO_TypeDef* GPIOx, uint32_t Pin)
|
||||
{
|
||||
// Configure the port pins
|
||||
for (uint32_t position = 0U; position < GPIO_NUMBER; position++)
|
||||
{
|
||||
// Get the IO position
|
||||
uint32_t ioposition = ((uint32_t)0x01) << position;
|
||||
|
||||
// Get the current IO position
|
||||
uint32_t iocurrent = Pin & ioposition;
|
||||
|
||||
if (iocurrent == ioposition)
|
||||
{
|
||||
// Configure the IO Speed
|
||||
uint32_t temp = GPIOx->OSPEEDR;
|
||||
temp &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2));
|
||||
temp |= (GPIO_High_Speed << (position * 2));
|
||||
GPIOx->OSPEEDR = temp;
|
||||
|
||||
// Configure the IO Output Type
|
||||
temp = GPIOx->OTYPER;
|
||||
temp &= ~(GPIO_OTYPER_OT_0 << position) ;
|
||||
temp |= (((GPIO_MODE_AF_OD & GPIO_OUTPUT_TYPE) >> 4) << position);
|
||||
GPIOx->OTYPER = temp;
|
||||
|
||||
// Activate the Pull Up resistor for the current IO
|
||||
temp = GPIOx->PUPDR;
|
||||
temp &= ~(GPIO_PUPDR_PUPDR0 << (position * 2));
|
||||
temp |= ((GPIO_PuPd_UP) << (position * 2));
|
||||
GPIOx->PUPDR = temp;
|
||||
|
||||
// Configure Alternate function mapped with the current IO
|
||||
temp = GPIOx->AFR[position >> 3];
|
||||
temp &= ~((uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ;
|
||||
temp |= ((uint32_t)(GPIO_AF4_I2C3) << (((uint32_t)position & (uint32_t)0x07) * 4));
|
||||
GPIOx->AFR[position >> 3] = temp;
|
||||
|
||||
// Configure IO Direction mode (Input, Output, Alternate or Analog)
|
||||
temp = GPIOx->MODER;
|
||||
temp &= ~(GPIO_MODER_MODER0 << (position * 2));
|
||||
temp |= ((GPIO_MODE_AF_OD & GPIO_MODE) << (position * 2));
|
||||
GPIOx->MODER = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+19
-10
@@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2009-2015,2020,2021 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2016 by Colin Durbridge G4EML
|
||||
* 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
|
||||
@@ -19,22 +18,32 @@
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#if defined(MODE_M17)
|
||||
#if defined(MODE_OLED)
|
||||
|
||||
#if !defined(CALM17_H)
|
||||
#define CALM17_H
|
||||
#if !defined(I2C3_H)
|
||||
#define I2C3_H
|
||||
|
||||
#if defined(STM32F7XX)
|
||||
#include "stm32f7xx.h"
|
||||
#include "stm32f7xx_i2c.h"
|
||||
#endif
|
||||
|
||||
|
||||
class CCalM17 {
|
||||
class CI2C3 {
|
||||
public:
|
||||
CCalM17();
|
||||
CI2C3();
|
||||
|
||||
void process();
|
||||
void init();
|
||||
|
||||
uint8_t write(const uint8_t* data, uint16_t length);
|
||||
void write(uint16_t addr, const uint8_t* data, uint8_t length);
|
||||
|
||||
private:
|
||||
bool m_transmit;
|
||||
void transferConfig(uint16_t addr, uint8_t length, uint32_t mode, uint32_t request);
|
||||
void configAnalogFilter(uint32_t AnalogFilter);
|
||||
void configDigitalFilter(uint32_t DigitalFilter);
|
||||
void initI2C3();
|
||||
void initMSP();
|
||||
void initGPIO(GPIO_TypeDef* GPIOx, uint32_t Pin);
|
||||
};
|
||||
|
||||
#endif
|
||||
+509
@@ -0,0 +1,509 @@
|
||||
/*
|
||||
* 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
|
||||
* 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"
|
||||
#include "I2C3.h"
|
||||
|
||||
#include "Globals.h"
|
||||
|
||||
const uint8_t OLED_ADDRESS = 0x78U;
|
||||
|
||||
const uint8_t OLED_WIDTH = 64U;
|
||||
const uint8_t OLED_HEIGHT = 32U;
|
||||
const uint16_t OLED_BUFFER_SIZE = (OLED_HEIGHT * OLED_WIDTH) / 8U;
|
||||
|
||||
const uint8_t SSD_Command_Mode = 0x00U; /* C0 and DC bit are 0 */
|
||||
const uint8_t SSD_Data_Mode = 0x40U; /* C0 bit is 0 and DC bit is 1 */
|
||||
|
||||
const uint8_t SSD1306_Set_Lower_Column_Start_Address = 0x00U;
|
||||
const uint8_t SSD1306_Set_Higher_Column_Start_Address = 0x10U;
|
||||
const uint8_t SSD1306_Set_Start_Line = 0x40U;
|
||||
|
||||
const uint8_t CHAR_HEIGHT = 5U;
|
||||
const uint8_t CHAR_WIDTH = 7U;
|
||||
|
||||
// Standard ascii 5x7 font
|
||||
const uint8_t FONT[] = {
|
||||
0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
|
||||
0x3EU, 0x5BU, 0x4FU, 0x5BU, 0x3EU,
|
||||
0x3EU, 0x6BU, 0x4FU, 0x6BU, 0x3EU,
|
||||
0x1CU, 0x3EU, 0x7CU, 0x3EU, 0x1CU,
|
||||
0x18U, 0x3CU, 0x7EU, 0x3CU, 0x18U,
|
||||
0x1CU, 0x57U, 0x7DU, 0x57U, 0x1CU,
|
||||
0x1CU, 0x5EU, 0x7FU, 0x5EU, 0x1CU,
|
||||
0x00U, 0x18U, 0x3CU, 0x18U, 0x00U,
|
||||
0xFFU, 0xE7U, 0xC3U, 0xE7U, 0xFFU,
|
||||
0x00U, 0x18U, 0x24U, 0x18U, 0x00U,
|
||||
0xFFU, 0xE7U, 0xDBU, 0xE7U, 0xFFU,
|
||||
0x30U, 0x48U, 0x3AU, 0x06U, 0x0EU,
|
||||
0x26U, 0x29U, 0x79U, 0x29U, 0x26U,
|
||||
0x40U, 0x7FU, 0x05U, 0x05U, 0x07U,
|
||||
0x40U, 0x7FU, 0x05U, 0x25U, 0x3FU,
|
||||
0x5AU, 0x3CU, 0xE7U, 0x3CU, 0x5AU,
|
||||
0x7FU, 0x3EU, 0x1CU, 0x1CU, 0x08U,
|
||||
0x08U, 0x1CU, 0x1CU, 0x3EU, 0x7FU,
|
||||
0x14U, 0x22U, 0x7FU, 0x22U, 0x14U,
|
||||
0x5FU, 0x5FU, 0x00U, 0x5FU, 0x5FU,
|
||||
0x06U, 0x09U, 0x7FU, 0x01U, 0x7FU,
|
||||
0x00U, 0x66U, 0x89U, 0x95U, 0x6AU,
|
||||
0x60U, 0x60U, 0x60U, 0x60U, 0x60U,
|
||||
0x94U, 0xA2U, 0xFFU, 0xA2U, 0x94U,
|
||||
0x08U, 0x04U, 0x7EU, 0x04U, 0x08U,
|
||||
0x10U, 0x20U, 0x7EU, 0x20U, 0x10U,
|
||||
0x08U, 0x08U, 0x2AU, 0x1CU, 0x08U,
|
||||
0x08U, 0x1CU, 0x2AU, 0x08U, 0x08U,
|
||||
0x1EU, 0x10U, 0x10U, 0x10U, 0x10U,
|
||||
0x0CU, 0x1EU, 0x0CU, 0x1EU, 0x0CU,
|
||||
0x30U, 0x38U, 0x3EU, 0x38U, 0x30U,
|
||||
0x06U, 0x0EU, 0x3EU, 0x0EU, 0x06U,
|
||||
0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
|
||||
0x00U, 0x00U, 0x5FU, 0x00U, 0x00U,
|
||||
0x00U, 0x07U, 0x00U, 0x07U, 0x00U,
|
||||
0x14U, 0x7FU, 0x14U, 0x7FU, 0x14U,
|
||||
0x24U, 0x2AU, 0x7FU, 0x2AU, 0x12U,
|
||||
0x23U, 0x13U, 0x08U, 0x64U, 0x62U,
|
||||
0x36U, 0x49U, 0x56U, 0x20U, 0x50U,
|
||||
0x00U, 0x08U, 0x07U, 0x03U, 0x00U,
|
||||
0x00U, 0x1CU, 0x22U, 0x41U, 0x00U,
|
||||
0x00U, 0x41U, 0x22U, 0x1CU, 0x00U,
|
||||
0x2AU, 0x1CU, 0x7FU, 0x1CU, 0x2AU,
|
||||
0x08U, 0x08U, 0x3EU, 0x08U, 0x08U,
|
||||
0x00U, 0x80U, 0x70U, 0x30U, 0x00U,
|
||||
0x08U, 0x08U, 0x08U, 0x08U, 0x08U,
|
||||
0x00U, 0x00U, 0x60U, 0x60U, 0x00U,
|
||||
0x20U, 0x10U, 0x08U, 0x04U, 0x02U,
|
||||
0x3EU, 0x51U, 0x49U, 0x45U, 0x3EU,
|
||||
0x00U, 0x42U, 0x7FU, 0x40U, 0x00U,
|
||||
0x72U, 0x49U, 0x49U, 0x49U, 0x46U,
|
||||
0x21U, 0x41U, 0x49U, 0x4DU, 0x33U,
|
||||
0x18U, 0x14U, 0x12U, 0x7FU, 0x10U,
|
||||
0x27U, 0x45U, 0x45U, 0x45U, 0x39U,
|
||||
0x3CU, 0x4AU, 0x49U, 0x49U, 0x31U,
|
||||
0x41U, 0x21U, 0x11U, 0x09U, 0x07U,
|
||||
0x36U, 0x49U, 0x49U, 0x49U, 0x36U,
|
||||
0x46U, 0x49U, 0x49U, 0x29U, 0x1EU,
|
||||
0x00U, 0x00U, 0x14U, 0x00U, 0x00U,
|
||||
0x00U, 0x40U, 0x34U, 0x00U, 0x00U,
|
||||
0x00U, 0x08U, 0x14U, 0x22U, 0x41U,
|
||||
0x14U, 0x14U, 0x14U, 0x14U, 0x14U,
|
||||
0x00U, 0x41U, 0x22U, 0x14U, 0x08U,
|
||||
0x02U, 0x01U, 0x59U, 0x09U, 0x06U,
|
||||
0x3EU, 0x41U, 0x5DU, 0x59U, 0x4EU,
|
||||
0x7CU, 0x12U, 0x11U, 0x12U, 0x7CU,
|
||||
0x7FU, 0x49U, 0x49U, 0x49U, 0x36U,
|
||||
0x3EU, 0x41U, 0x41U, 0x41U, 0x22U,
|
||||
0x7FU, 0x41U, 0x41U, 0x41U, 0x3EU,
|
||||
0x7FU, 0x49U, 0x49U, 0x49U, 0x41U,
|
||||
0x7FU, 0x09U, 0x09U, 0x09U, 0x01U,
|
||||
0x3EU, 0x41U, 0x41U, 0x51U, 0x73U,
|
||||
0x7FU, 0x08U, 0x08U, 0x08U, 0x7FU,
|
||||
0x00U, 0x41U, 0x7FU, 0x41U, 0x00U,
|
||||
0x20U, 0x40U, 0x41U, 0x3FU, 0x01U,
|
||||
0x7FU, 0x08U, 0x14U, 0x22U, 0x41U,
|
||||
0x7FU, 0x40U, 0x40U, 0x40U, 0x40U,
|
||||
0x7FU, 0x02U, 0x1CU, 0x02U, 0x7FU,
|
||||
0x7FU, 0x04U, 0x08U, 0x10U, 0x7FU,
|
||||
0x3EU, 0x41U, 0x41U, 0x41U, 0x3EU,
|
||||
0x7FU, 0x09U, 0x09U, 0x09U, 0x06U,
|
||||
0x3EU, 0x41U, 0x51U, 0x21U, 0x5EU,
|
||||
0x7FU, 0x09U, 0x19U, 0x29U, 0x46U,
|
||||
0x26U, 0x49U, 0x49U, 0x49U, 0x32U,
|
||||
0x03U, 0x01U, 0x7FU, 0x01U, 0x03U,
|
||||
0x3FU, 0x40U, 0x40U, 0x40U, 0x3FU,
|
||||
0x1FU, 0x20U, 0x40U, 0x20U, 0x1FU,
|
||||
0x3FU, 0x40U, 0x38U, 0x40U, 0x3FU,
|
||||
0x63U, 0x14U, 0x08U, 0x14U, 0x63U,
|
||||
0x03U, 0x04U, 0x78U, 0x04U, 0x03U,
|
||||
0x61U, 0x59U, 0x49U, 0x4DU, 0x43U,
|
||||
0x00U, 0x7FU, 0x41U, 0x41U, 0x41U,
|
||||
0x02U, 0x04U, 0x08U, 0x10U, 0x20U,
|
||||
0x00U, 0x41U, 0x41U, 0x41U, 0x7FU,
|
||||
0x04U, 0x02U, 0x01U, 0x02U, 0x04U,
|
||||
0x40U, 0x40U, 0x40U, 0x40U, 0x40U,
|
||||
0x00U, 0x03U, 0x07U, 0x08U, 0x00U,
|
||||
0x20U, 0x54U, 0x54U, 0x78U, 0x40U,
|
||||
0x7FU, 0x28U, 0x44U, 0x44U, 0x38U,
|
||||
0x38U, 0x44U, 0x44U, 0x44U, 0x28U,
|
||||
0x38U, 0x44U, 0x44U, 0x28U, 0x7FU,
|
||||
0x38U, 0x54U, 0x54U, 0x54U, 0x18U,
|
||||
0x00U, 0x08U, 0x7EU, 0x09U, 0x02U,
|
||||
0x18U, 0xA4U, 0xA4U, 0x9CU, 0x78U,
|
||||
0x7FU, 0x08U, 0x04U, 0x04U, 0x78U,
|
||||
0x00U, 0x44U, 0x7DU, 0x40U, 0x00U,
|
||||
0x20U, 0x40U, 0x40U, 0x3DU, 0x00U,
|
||||
0x7FU, 0x10U, 0x28U, 0x44U, 0x00U,
|
||||
0x00U, 0x41U, 0x7FU, 0x40U, 0x00U,
|
||||
0x7CU, 0x04U, 0x78U, 0x04U, 0x78U,
|
||||
0x7CU, 0x08U, 0x04U, 0x04U, 0x78U,
|
||||
0x38U, 0x44U, 0x44U, 0x44U, 0x38U,
|
||||
0xFCU, 0x18U, 0x24U, 0x24U, 0x18U,
|
||||
0x18U, 0x24U, 0x24U, 0x18U, 0xFCU,
|
||||
0x7CU, 0x08U, 0x04U, 0x04U, 0x08U,
|
||||
0x48U, 0x54U, 0x54U, 0x54U, 0x24U,
|
||||
0x04U, 0x04U, 0x3FU, 0x44U, 0x24U,
|
||||
0x3CU, 0x40U, 0x40U, 0x20U, 0x7CU,
|
||||
0x1CU, 0x20U, 0x40U, 0x20U, 0x1CU,
|
||||
0x3CU, 0x40U, 0x30U, 0x40U, 0x3CU,
|
||||
0x44U, 0x28U, 0x10U, 0x28U, 0x44U,
|
||||
0x4CU, 0x90U, 0x90U, 0x90U, 0x7CU,
|
||||
0x44U, 0x64U, 0x54U, 0x4CU, 0x44U,
|
||||
0x00U, 0x08U, 0x36U, 0x41U, 0x00U,
|
||||
0x00U, 0x00U, 0x77U, 0x00U, 0x00U,
|
||||
0x00U, 0x41U, 0x36U, 0x08U, 0x00U,
|
||||
0x02U, 0x01U, 0x02U, 0x04U, 0x02U,
|
||||
0x3CU, 0x26U, 0x23U, 0x26U, 0x3CU,
|
||||
0x1EU, 0xA1U, 0xA1U, 0x61U, 0x12U,
|
||||
0x3AU, 0x40U, 0x40U, 0x20U, 0x7AU,
|
||||
0x38U, 0x54U, 0x54U, 0x55U, 0x59U,
|
||||
0x21U, 0x55U, 0x55U, 0x79U, 0x41U,
|
||||
0x21U, 0x54U, 0x54U, 0x78U, 0x41U,
|
||||
0x21U, 0x55U, 0x54U, 0x78U, 0x40U,
|
||||
0x20U, 0x54U, 0x55U, 0x79U, 0x40U,
|
||||
0x0CU, 0x1EU, 0x52U, 0x72U, 0x12U,
|
||||
0x39U, 0x55U, 0x55U, 0x55U, 0x59U,
|
||||
0x39U, 0x54U, 0x54U, 0x54U, 0x59U,
|
||||
0x39U, 0x55U, 0x54U, 0x54U, 0x58U,
|
||||
0x00U, 0x00U, 0x45U, 0x7CU, 0x41U,
|
||||
0x00U, 0x02U, 0x45U, 0x7DU, 0x42U,
|
||||
0x00U, 0x01U, 0x45U, 0x7CU, 0x40U,
|
||||
0xF0U, 0x29U, 0x24U, 0x29U, 0xF0U,
|
||||
0xF0U, 0x28U, 0x25U, 0x28U, 0xF0U,
|
||||
0x7CU, 0x54U, 0x55U, 0x45U, 0x00U,
|
||||
0x20U, 0x54U, 0x54U, 0x7CU, 0x54U,
|
||||
0x7CU, 0x0AU, 0x09U, 0x7FU, 0x49U,
|
||||
0x32U, 0x49U, 0x49U, 0x49U, 0x32U,
|
||||
0x32U, 0x48U, 0x48U, 0x48U, 0x32U,
|
||||
0x32U, 0x4AU, 0x48U, 0x48U, 0x30U,
|
||||
0x3AU, 0x41U, 0x41U, 0x21U, 0x7AU,
|
||||
0x3AU, 0x42U, 0x40U, 0x20U, 0x78U,
|
||||
0x00U, 0x9DU, 0xA0U, 0xA0U, 0x7DU,
|
||||
0x39U, 0x44U, 0x44U, 0x44U, 0x39U,
|
||||
0x3DU, 0x40U, 0x40U, 0x40U, 0x3DU,
|
||||
0x3CU, 0x24U, 0xFFU, 0x24U, 0x24U,
|
||||
0x48U, 0x7EU, 0x49U, 0x43U, 0x66U,
|
||||
0x2BU, 0x2FU, 0xFCU, 0x2FU, 0x2BU,
|
||||
0xFFU, 0x09U, 0x29U, 0xF6U, 0x20U,
|
||||
0xC0U, 0x88U, 0x7EU, 0x09U, 0x03U,
|
||||
0x20U, 0x54U, 0x54U, 0x79U, 0x41U,
|
||||
0x00U, 0x00U, 0x44U, 0x7DU, 0x41U,
|
||||
0x30U, 0x48U, 0x48U, 0x4AU, 0x32U,
|
||||
0x38U, 0x40U, 0x40U, 0x22U, 0x7AU,
|
||||
0x00U, 0x7AU, 0x0AU, 0x0AU, 0x72U,
|
||||
0x7DU, 0x0DU, 0x19U, 0x31U, 0x7DU,
|
||||
0x26U, 0x29U, 0x29U, 0x2FU, 0x28U,
|
||||
0x26U, 0x29U, 0x29U, 0x29U, 0x26U,
|
||||
0x30U, 0x48U, 0x4DU, 0x40U, 0x20U,
|
||||
0x38U, 0x08U, 0x08U, 0x08U, 0x08U,
|
||||
0x08U, 0x08U, 0x08U, 0x08U, 0x38U,
|
||||
0x2FU, 0x10U, 0xC8U, 0xACU, 0xBAU,
|
||||
0x2FU, 0x10U, 0x28U, 0x34U, 0xFAU,
|
||||
0x00U, 0x00U, 0x7BU, 0x00U, 0x00U,
|
||||
0x08U, 0x14U, 0x2AU, 0x14U, 0x22U,
|
||||
0x22U, 0x14U, 0x2AU, 0x14U, 0x08U,
|
||||
0xAAU, 0x00U, 0x55U, 0x00U, 0xAAU,
|
||||
0xAAU, 0x55U, 0xAAU, 0x55U, 0xAAU,
|
||||
0x00U, 0x00U, 0x00U, 0xFFU, 0x00U,
|
||||
0x10U, 0x10U, 0x10U, 0xFFU, 0x00U,
|
||||
0x14U, 0x14U, 0x14U, 0xFFU, 0x00U,
|
||||
0x10U, 0x10U, 0xFFU, 0x00U, 0xFFU,
|
||||
0x10U, 0x10U, 0xF0U, 0x10U, 0xF0U,
|
||||
0x14U, 0x14U, 0x14U, 0xFCU, 0x00U,
|
||||
0x14U, 0x14U, 0xF7U, 0x00U, 0xFFU,
|
||||
0x00U, 0x00U, 0xFFU, 0x00U, 0xFFU,
|
||||
0x14U, 0x14U, 0xF4U, 0x04U, 0xFCU,
|
||||
0x14U, 0x14U, 0x17U, 0x10U, 0x1FU,
|
||||
0x10U, 0x10U, 0x1FU, 0x10U, 0x1FU,
|
||||
0x14U, 0x14U, 0x14U, 0x1FU, 0x00U,
|
||||
0x10U, 0x10U, 0x10U, 0xF0U, 0x00U,
|
||||
0x00U, 0x00U, 0x00U, 0x1FU, 0x10U,
|
||||
0x10U, 0x10U, 0x10U, 0x1FU, 0x10U,
|
||||
0x10U, 0x10U, 0x10U, 0xF0U, 0x10U,
|
||||
0x00U, 0x00U, 0x00U, 0xFFU, 0x10U,
|
||||
0x10U, 0x10U, 0x10U, 0x10U, 0x10U,
|
||||
0x10U, 0x10U, 0x10U, 0xFFU, 0x10U,
|
||||
0x00U, 0x00U, 0x00U, 0xFFU, 0x14U,
|
||||
0x00U, 0x00U, 0xFFU, 0x00U, 0xFFU,
|
||||
0x00U, 0x00U, 0x1FU, 0x10U, 0x17U,
|
||||
0x00U, 0x00U, 0xFCU, 0x04U, 0xF4U,
|
||||
0x14U, 0x14U, 0x17U, 0x10U, 0x17U,
|
||||
0x14U, 0x14U, 0xF4U, 0x04U, 0xF4U,
|
||||
0x00U, 0x00U, 0xFFU, 0x00U, 0xF7U,
|
||||
0x14U, 0x14U, 0x14U, 0x14U, 0x14U,
|
||||
0x14U, 0x14U, 0xF7U, 0x00U, 0xF7U,
|
||||
0x14U, 0x14U, 0x14U, 0x17U, 0x14U,
|
||||
0x10U, 0x10U, 0x1FU, 0x10U, 0x1FU,
|
||||
0x14U, 0x14U, 0x14U, 0xF4U, 0x14U,
|
||||
0x10U, 0x10U, 0xF0U, 0x10U, 0xF0U,
|
||||
0x00U, 0x00U, 0x1FU, 0x10U, 0x1FU,
|
||||
0x00U, 0x00U, 0x00U, 0x1FU, 0x14U,
|
||||
0x00U, 0x00U, 0x00U, 0xFCU, 0x14U,
|
||||
0x00U, 0x00U, 0xF0U, 0x10U, 0xF0U,
|
||||
0x10U, 0x10U, 0xFFU, 0x10U, 0xFFU,
|
||||
0x14U, 0x14U, 0x14U, 0xFFU, 0x14U,
|
||||
0x10U, 0x10U, 0x10U, 0x1FU, 0x00U,
|
||||
0x00U, 0x00U, 0x00U, 0xF0U, 0x10U,
|
||||
0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
|
||||
0xF0U, 0xF0U, 0xF0U, 0xF0U, 0xF0U,
|
||||
0xFFU, 0xFFU, 0xFFU, 0x00U, 0x00U,
|
||||
0x00U, 0x00U, 0x00U, 0xFFU, 0xFFU,
|
||||
0x0FU, 0x0FU, 0x0FU, 0x0FU, 0x0FU,
|
||||
0x38U, 0x44U, 0x44U, 0x38U, 0x44U,
|
||||
0x7CU, 0x2AU, 0x2AU, 0x3EU, 0x14U,
|
||||
0x7EU, 0x02U, 0x02U, 0x06U, 0x06U,
|
||||
0x02U, 0x7EU, 0x02U, 0x7EU, 0x02U,
|
||||
0x63U, 0x55U, 0x49U, 0x41U, 0x63U,
|
||||
0x38U, 0x44U, 0x44U, 0x3CU, 0x04U,
|
||||
0x40U, 0x7EU, 0x20U, 0x1EU, 0x20U,
|
||||
0x06U, 0x02U, 0x7EU, 0x02U, 0x02U,
|
||||
0x99U, 0xA5U, 0xE7U, 0xA5U, 0x99U,
|
||||
0x1CU, 0x2AU, 0x49U, 0x2AU, 0x1CU,
|
||||
0x4CU, 0x72U, 0x01U, 0x72U, 0x4CU,
|
||||
0x30U, 0x4AU, 0x4DU, 0x4DU, 0x30U,
|
||||
0x30U, 0x48U, 0x78U, 0x48U, 0x30U,
|
||||
0xBCU, 0x62U, 0x5AU, 0x46U, 0x3DU,
|
||||
0x3EU, 0x49U, 0x49U, 0x49U, 0x00U,
|
||||
0x7EU, 0x01U, 0x01U, 0x01U, 0x7EU,
|
||||
0x2AU, 0x2AU, 0x2AU, 0x2AU, 0x2AU,
|
||||
0x44U, 0x44U, 0x5FU, 0x44U, 0x44U,
|
||||
0x40U, 0x51U, 0x4AU, 0x44U, 0x40U,
|
||||
0x40U, 0x44U, 0x4AU, 0x51U, 0x40U,
|
||||
0x00U, 0x00U, 0xFFU, 0x01U, 0x03U,
|
||||
0xE0U, 0x80U, 0xFFU, 0x00U, 0x00U,
|
||||
0x08U, 0x08U, 0x6BU, 0x6BU, 0x08U,
|
||||
0x36U, 0x12U, 0x36U, 0x24U, 0x36U,
|
||||
0x06U, 0x0FU, 0x09U, 0x0FU, 0x06U,
|
||||
0x00U, 0x00U, 0x18U, 0x18U, 0x00U,
|
||||
0x00U, 0x00U, 0x10U, 0x10U, 0x00U,
|
||||
0x30U, 0x40U, 0xFFU, 0x01U, 0x01U,
|
||||
0x00U, 0x1FU, 0x01U, 0x01U, 0x1EU,
|
||||
0x00U, 0x19U, 0x1DU, 0x17U, 0x12U,
|
||||
0x00U, 0x3CU, 0x3CU, 0x3CU, 0x3CU,
|
||||
0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
|
||||
|
||||
// Arduino Compatible Macro
|
||||
#define _BV(bit) (1 << (bit))
|
||||
|
||||
|
||||
|
||||
CI2COLED::CI2COLED() :
|
||||
m_i2c(),
|
||||
m_oledBuffer(NULL)
|
||||
{
|
||||
m_oledBuffer = new uint8_t[OLED_BUFFER_SIZE];
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
void CI2COLED::init()
|
||||
{
|
||||
m_i2c.init();
|
||||
|
||||
// Initialise the VG-6432TSWEG02 OLED display
|
||||
// Taken from https://datasheet.lcsc.com/szlcsc/1912111437_WiseChip-VG-6432TSWAG01-IIC-sh1106_C194312.pdf
|
||||
|
||||
sendCommand(0xAEU); // Display off
|
||||
|
||||
sendCommand(0x00U); // Set lower column address
|
||||
sendCommand(0x12U); // Set higher column address
|
||||
|
||||
sendCommand(0x00U); // Set display start line
|
||||
|
||||
sendCommand(0xB0U); // Set page address
|
||||
|
||||
sendCommand(0x81U, 0x4FU); // Contract control, 128
|
||||
|
||||
sendCommand(0xA1U); // Set segment remap
|
||||
|
||||
sendCommand(0xA6U); // Normal/reverse
|
||||
|
||||
sendCommand(0xA8U, 0x1FU); // Multiplex ratio, duty = 1/32
|
||||
|
||||
sendCommand(0xC8U); // Com scan direction
|
||||
|
||||
sendCommand(0xD3U, 0x00U); // Set display offset
|
||||
|
||||
sendCommand(0xD5U, 0x80U); // Set osc division
|
||||
|
||||
sendCommand(0xD9U, 0x1FU); // Set pre-charge period
|
||||
|
||||
sendCommand(0xDAU, 0x12U); // Set COM pins
|
||||
|
||||
sendCommand(0xDBU, 0x40U); // Set vcomh
|
||||
|
||||
sendCommand(0x8DU, 0x14U); // Set charge pump enable
|
||||
|
||||
sendCommand(0xAFU); // Display on
|
||||
}
|
||||
|
||||
void CI2COLED::setMode(int state)
|
||||
{
|
||||
clear();
|
||||
|
||||
switch (MMDVM_STATE(state)) {
|
||||
case STATE_IDLE:
|
||||
write("Idle");
|
||||
break;
|
||||
case STATE_DSTAR:
|
||||
write("D-Star");
|
||||
break;
|
||||
case STATE_DMR:
|
||||
write("DMR");
|
||||
break;
|
||||
case STATE_YSF:
|
||||
write("YSF");
|
||||
break;
|
||||
case STATE_P25:
|
||||
write("P25");
|
||||
break;
|
||||
case STATE_NXDN:
|
||||
write("NXDN");
|
||||
break;
|
||||
case STATE_FM:
|
||||
write("FM");
|
||||
break;
|
||||
case STATE_M17:
|
||||
write("M17");
|
||||
break;
|
||||
case STATE_POCSAG:
|
||||
write("POCSAG");
|
||||
break;
|
||||
case STATE_AX25:
|
||||
write("AX.25");
|
||||
break;
|
||||
default:
|
||||
write("Calibrate");
|
||||
break;
|
||||
}
|
||||
|
||||
display();
|
||||
}
|
||||
|
||||
void CI2COLED::sendCommand(uint8_t c0, uint8_t c1)
|
||||
{
|
||||
uint8_t buff[3U];
|
||||
|
||||
buff[0U] = SSD_Command_Mode;
|
||||
buff[1U] = c0;
|
||||
buff[2U] = c1;
|
||||
|
||||
// Write Data on I2C
|
||||
m_i2c.write(OLED_ADDRESS, buff, 3U);
|
||||
}
|
||||
|
||||
void CI2COLED::sendCommand(uint8_t c)
|
||||
{
|
||||
uint8_t buff[2U];
|
||||
|
||||
buff[0U] = SSD_Command_Mode;
|
||||
buff[1U] = c;
|
||||
|
||||
// Write Data on I2C
|
||||
m_i2c.write(OLED_ADDRESS, buff, 2U);
|
||||
}
|
||||
|
||||
void CI2COLED::sendData(const uint8_t* data, uint16_t length)
|
||||
{
|
||||
uint8_t buff[20U];
|
||||
|
||||
buff[0U] = SSD_Data_Mode;
|
||||
::memcpy(buff + 1U, data, length * sizeof(uint8_t));
|
||||
|
||||
// Write Data on I2C
|
||||
m_i2c.write(OLED_ADDRESS, buff, length + 1U);
|
||||
}
|
||||
|
||||
void CI2COLED::clear()
|
||||
{
|
||||
::memset(m_oledBuffer, 0x00U, OLED_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
void CI2COLED::write(const char* text)
|
||||
{
|
||||
size_t len = ::strlen(text);
|
||||
|
||||
uint16_t scale = OLED_WIDTH / (len * (CHAR_WIDTH + 1U));
|
||||
if (scale == 0U) scale = 1U;
|
||||
|
||||
uint8_t charHeight = CHAR_HEIGHT * scale;
|
||||
uint8_t charWidth = (CHAR_WIDTH + 1U) * scale;
|
||||
|
||||
uint8_t x = (OLED_HEIGHT - charHeight) / 2U;
|
||||
uint8_t y = (OLED_WIDTH - charWidth) / 2U;
|
||||
|
||||
for (size_t i = 0U; i < len; i++) {
|
||||
write(x, y, text[i], scale);
|
||||
y += charWidth;
|
||||
}
|
||||
}
|
||||
|
||||
void CI2COLED::write(uint8_t x, uint8_t y, char c, uint8_t size)
|
||||
{
|
||||
for (uint8_t i = 0U; i < 6U; i++) {
|
||||
uint8_t line;
|
||||
if (i == 5U)
|
||||
line = 0U;
|
||||
else
|
||||
line = FONT[(c * 5U) + i];
|
||||
|
||||
for (uint8_t j = 0U; j < 8U; j++) {
|
||||
if (line & 0x1U) {
|
||||
if (size == 1U) // default size
|
||||
drawPixel(x + i, y + j);
|
||||
else // big size
|
||||
fillRect(x + (i * size), y + (j * size), size, size);
|
||||
}
|
||||
|
||||
line >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CI2COLED::fillRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height)
|
||||
{
|
||||
for (uint8_t i = x; i < (x + height - 1U); i++) {
|
||||
for (uint8_t j = y; j < (y + width - 1U); j++)
|
||||
drawPixel(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
void CI2COLED::drawPixel(uint8_t x, uint8_t y)
|
||||
{
|
||||
// Get where to do the change in the buffer
|
||||
uint8_t* p = m_oledBuffer + (x + (y / 8U) * OLED_WIDTH);
|
||||
|
||||
// x is which column
|
||||
*p |= _BV((y % 8U));
|
||||
}
|
||||
|
||||
void CI2COLED::display()
|
||||
{
|
||||
sendCommand(SSD1306_Set_Lower_Column_Start_Address | 0x00U); // Low col = 0
|
||||
sendCommand(SSD1306_Set_Higher_Column_Start_Address | 0x00U); // High col = 0
|
||||
sendCommand(SSD1306_Set_Start_Line | 0x00U); // Line #0
|
||||
|
||||
// loop trough all OLED buffer and send a bunch of 16 data byte in one transmission
|
||||
for (uint16_t i = 0U; i < OLED_BUFFER_SIZE; i += 16U)
|
||||
sendData(m_oledBuffer + i, 16U);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+30
-15
@@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019,2020 by BG5HHP
|
||||
* Copyright (C) 2024 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
|
||||
@@ -17,24 +16,40 @@
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#if !defined(_IO_PINS_H)
|
||||
#define _IO_PINS_H
|
||||
#include "Config.h"
|
||||
|
||||
#if defined(ZUM_V09_PI)
|
||||
#include "pins/pins_zum_v09_pi.h"
|
||||
#if defined(MODE_OLED)
|
||||
|
||||
#elif defined(ZUM_V10_PI)
|
||||
#include "pins/pins_zum_v10_pi.h"
|
||||
#if !defined(I2COLED_H)
|
||||
#define I2COLED_H
|
||||
|
||||
#elif defined(RB_V3_PI)
|
||||
#include "pins/pins_rb_v3_pi.h"
|
||||
#include "I2C3.h"
|
||||
|
||||
#elif defined(RB_V5_PI)
|
||||
#include "pins/pins_rb_v5_pi.h"
|
||||
class CI2COLED {
|
||||
public:
|
||||
CI2COLED();
|
||||
|
||||
#else
|
||||
#error "A valid board type macro need to be defined."
|
||||
void init();
|
||||
|
||||
void setMode(int state);
|
||||
|
||||
private:
|
||||
CI2C3 m_i2c;
|
||||
uint8_t* m_oledBuffer;
|
||||
|
||||
void write(const char* text);
|
||||
void write(uint8_t x, uint8_t y, char c, uint8_t size);
|
||||
void drawPixel(uint8_t x, uint8_t y);
|
||||
void fillRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height);
|
||||
void clear();
|
||||
void display();
|
||||
|
||||
void sendCommand(uint8_t c);
|
||||
void sendCommand(uint8_t c0, uint8_t c1);
|
||||
void sendData(const uint8_t* c, uint16_t length);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif //#ifndef _IO_PINS_H
|
||||
+98
-296
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2015,2016,2017,2018,2020,2021,2024 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2015,2016,2017,2018,2020 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2015 by Jim Mclaughlin KI6ZUM
|
||||
* Copyright (C) 2016 by Colin Durbridge G4EML
|
||||
*
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include "Config.h"
|
||||
#include "Globals.h"
|
||||
#include "IOPins.h"
|
||||
#include "IO.h"
|
||||
|
||||
#if defined(USE_DCBLOCKER)
|
||||
@@ -80,7 +79,6 @@ const uint16_t BOXCAR5_FILTER_LEN = 6U;
|
||||
const uint16_t DC_OFFSET = 2048U;
|
||||
|
||||
CIO::CIO() :
|
||||
m_timer(TIM2),
|
||||
m_started(false),
|
||||
m_rxBuffer(RX_RINGBUFFER_SIZE),
|
||||
m_txBuffer(TX_RINGBUFFER_SIZE),
|
||||
@@ -93,13 +91,9 @@ m_dcState(),
|
||||
m_gaussianFilter(),
|
||||
m_gaussianState(),
|
||||
#endif
|
||||
#if defined(MODE_DMR)
|
||||
m_rrc02Filter1(),
|
||||
m_rrc02State1(),
|
||||
#endif
|
||||
#if defined(MODE_YSF)
|
||||
m_rrc02Filter2(),
|
||||
m_rrc02State2(),
|
||||
#if defined(MODE_DMR) || defined(MODE_YSF)
|
||||
m_rrc02Filter(),
|
||||
m_rrc02State(),
|
||||
#endif
|
||||
#if defined(MODE_P25)
|
||||
m_boxcar5Filter(),
|
||||
@@ -144,7 +138,7 @@ m_watchdog(0U),
|
||||
m_lockout(false)
|
||||
{
|
||||
#if defined(USE_DCBLOCKER)
|
||||
::memset(m_dcState, 0x00U, 4U * sizeof(q31_t));
|
||||
::memset(m_dcState, 0x00U, 4U * sizeof(q31_t));
|
||||
m_dcFilter.numStages = DC_FILTER_STAGES;
|
||||
m_dcFilter.pState = m_dcState;
|
||||
m_dcFilter.pCoeffs = DC_FILTER;
|
||||
@@ -158,18 +152,11 @@ m_lockout(false)
|
||||
m_gaussianFilter.pCoeffs = GAUSSIAN_0_5_FILTER;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_DMR)
|
||||
::memset(m_rrc02State1, 0x00U, 70U * sizeof(q15_t));
|
||||
m_rrc02Filter1.numTaps = RRC_0_2_FILTER_LEN;
|
||||
m_rrc02Filter1.pState = m_rrc02State1;
|
||||
m_rrc02Filter1.pCoeffs = RRC_0_2_FILTER;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_YSF)
|
||||
::memset(m_rrc02State2, 0x00U, 70U * sizeof(q15_t));
|
||||
m_rrc02Filter2.numTaps = RRC_0_2_FILTER_LEN;
|
||||
m_rrc02Filter2.pState = m_rrc02State2;
|
||||
m_rrc02Filter2.pCoeffs = RRC_0_2_FILTER;
|
||||
#if defined(MODE_DMR) || defined(MODE_YSF)
|
||||
::memset(m_rrc02State, 0x00U, 70U * sizeof(q15_t));
|
||||
m_rrc02Filter.numTaps = RRC_0_2_FILTER_LEN;
|
||||
m_rrc02Filter.pState = m_rrc02State;
|
||||
m_rrc02Filter.pCoeffs = RRC_0_2_FILTER;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_P25)
|
||||
@@ -206,7 +193,7 @@ m_lockout(false)
|
||||
m_rrc05Filter.pCoeffs = RRC_0_5_FILTER;
|
||||
#endif
|
||||
|
||||
initHardware();
|
||||
initInt();
|
||||
|
||||
selfTest();
|
||||
}
|
||||
@@ -219,106 +206,106 @@ void CIO::selfTest()
|
||||
ledValue = !ledValue;
|
||||
|
||||
// We exclude PTT to avoid trigger the transmitter
|
||||
setLED(ledValue);
|
||||
setCOS(ledValue);
|
||||
setLEDInt(ledValue);
|
||||
setCOSInt(ledValue);
|
||||
#if defined(MODE_LEDS)
|
||||
setDStar(ledValue);
|
||||
setDMR(ledValue);
|
||||
setYSF(ledValue);
|
||||
setP25(ledValue);
|
||||
setDStarInt(ledValue);
|
||||
setDMRInt(ledValue);
|
||||
setYSFInt(ledValue);
|
||||
setP25Int(ledValue);
|
||||
#if !defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
setNXDN(ledValue);
|
||||
setNXDNInt(ledValue);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_M17_LEDS)
|
||||
setM17(ledValue);
|
||||
setM17Int(ledValue);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
setPOCSAG(ledValue);
|
||||
setPOCSAGInt(ledValue);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_FM_LEDS)
|
||||
setFM(ledValue);
|
||||
setFMInt(ledValue);
|
||||
#endif
|
||||
#endif
|
||||
::delay(250);
|
||||
delayInt(250);
|
||||
}
|
||||
|
||||
#if defined(MODE_LEDS)
|
||||
setDStar(false);
|
||||
setDMR(false);
|
||||
setYSF(false);
|
||||
setP25(false);
|
||||
setDStarInt(false);
|
||||
setDMRInt(false);
|
||||
setYSFInt(false);
|
||||
setP25Int(false);
|
||||
#if !defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
setNXDN(false);
|
||||
setNXDNInt(false);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_M17_LEDS)
|
||||
setM17(false);
|
||||
setM17Int(false);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
setPOCSAG(false);
|
||||
setPOCSAGInt(false);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_FM_LEDS)
|
||||
setFM(false);
|
||||
setFMInt(false);
|
||||
#endif
|
||||
setDStar(true);
|
||||
setDStarInt(true);
|
||||
|
||||
::delay(250);
|
||||
setDMR(true);
|
||||
delayInt(250);
|
||||
setDMRInt(true);
|
||||
|
||||
::delay(250);
|
||||
setYSF(true);
|
||||
delayInt(250);
|
||||
setYSFInt(true);
|
||||
|
||||
::delay(250);
|
||||
setP25(true);
|
||||
delayInt(250);
|
||||
setP25Int(true);
|
||||
|
||||
#if !defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
::delay(250);
|
||||
setNXDN(true);
|
||||
delayInt(250);
|
||||
setNXDNInt(true);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_ALTERNATE_M17_LEDS)
|
||||
::delay(250);
|
||||
setM17(true);
|
||||
delayInt(250);
|
||||
setM17Int(true);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
::delay(250);
|
||||
setPOCSAG(true);
|
||||
delayInt(250);
|
||||
setPOCSAGInt(true);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_ALTERNATE_FM_LEDS)
|
||||
::delay(250);
|
||||
setFM(true);
|
||||
delayInt(250);
|
||||
setFMInt(true);
|
||||
|
||||
::delay(250);
|
||||
setFM(false);
|
||||
delayInt(250);
|
||||
setFMInt(false);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
::delay(250);
|
||||
setPOCSAG(false);
|
||||
delayInt(250);
|
||||
setPOCSAGInt(false);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_ALTERNATE_M17_LEDS)
|
||||
::delay(250);
|
||||
setM17(false);
|
||||
delayInt(250);
|
||||
setM17Int(false);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
::delay(250);
|
||||
setNXDN(false);
|
||||
delayInt(250);
|
||||
setNXDNInt(false);
|
||||
#endif
|
||||
|
||||
::delay(250);
|
||||
setP25(false);
|
||||
delayInt(250);
|
||||
setP25Int(false);
|
||||
|
||||
::delay(250);
|
||||
setYSF(false);
|
||||
delayInt(250);
|
||||
setYSFInt(false);
|
||||
|
||||
::delay(250);
|
||||
setDMR(false);
|
||||
delayInt(250);
|
||||
setDMRInt(false);
|
||||
|
||||
::delay(250);
|
||||
setDStar(false);
|
||||
delayInt(250);
|
||||
setDStarInt(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -327,7 +314,7 @@ void CIO::start()
|
||||
if (m_started)
|
||||
return;
|
||||
|
||||
startHardware();
|
||||
startInt();
|
||||
|
||||
m_started = true;
|
||||
|
||||
@@ -336,6 +323,7 @@ void CIO::start()
|
||||
|
||||
void CIO::process()
|
||||
{
|
||||
m_ledCount++;
|
||||
if (m_started) {
|
||||
// Two seconds timeout
|
||||
if (m_watchdog >= 48000U) {
|
||||
@@ -351,31 +339,30 @@ void CIO::process()
|
||||
}
|
||||
|
||||
#if defined(CONSTANT_SRV_LED)
|
||||
setLED(true);
|
||||
setLEDInt(true);
|
||||
#else
|
||||
if (m_ledCount >= 24000U) {
|
||||
m_ledCount = 0U;
|
||||
m_ledValue = !m_ledValue;
|
||||
setLED(m_ledValue);
|
||||
setLEDInt(m_ledValue);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
m_ledCount++;
|
||||
if (m_ledCount >= 240000U) {
|
||||
m_ledCount = 0U;
|
||||
m_ledValue = !m_ledValue;
|
||||
setLED(m_ledValue);
|
||||
setLEDInt(m_ledValue);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_useCOSAsLockout)
|
||||
m_lockout = getCOS();
|
||||
m_lockout = getCOSInt();
|
||||
|
||||
// Switch off the transmitter if needed
|
||||
if (m_txBuffer.getData() == 0U && m_tx) {
|
||||
m_tx = false;
|
||||
setPTT(m_pttInvert ? true : false);
|
||||
setPTTInt(m_pttInvert ? true : false);
|
||||
DEBUG1("TX OFF");
|
||||
}
|
||||
|
||||
@@ -471,7 +458,7 @@ void CIO::process()
|
||||
#if defined(MODE_DMR)
|
||||
if (m_dmrEnable) {
|
||||
q15_t DMRVals[RX_BLOCK_SIZE];
|
||||
::arm_fir_fast_q15(&m_rrc02Filter1, samples, DMRVals, RX_BLOCK_SIZE);
|
||||
::arm_fir_fast_q15(&m_rrc02Filter, samples, DMRVals, RX_BLOCK_SIZE);
|
||||
|
||||
if (m_duplex)
|
||||
dmrIdleRX.samples(DMRVals, RX_BLOCK_SIZE);
|
||||
@@ -484,9 +471,9 @@ void CIO::process()
|
||||
if (m_ysfEnable) {
|
||||
q15_t YSFVals[RX_BLOCK_SIZE];
|
||||
#if defined(USE_DCBLOCKER)
|
||||
::arm_fir_fast_q15(&m_rrc02Filter2, dcSamples, YSFVals, RX_BLOCK_SIZE);
|
||||
::arm_fir_fast_q15(&m_rrc02Filter, dcSamples, YSFVals, RX_BLOCK_SIZE);
|
||||
#else
|
||||
::arm_fir_fast_q15(&m_rrc02Filter2, samples, YSFVals, RX_BLOCK_SIZE);
|
||||
::arm_fir_fast_q15(&m_rrc02Filter, samples, YSFVals, RX_BLOCK_SIZE);
|
||||
#endif
|
||||
ysfRX.samples(YSFVals, rssi, RX_BLOCK_SIZE);
|
||||
}
|
||||
@@ -506,7 +493,7 @@ void CIO::process()
|
||||
|
||||
#if defined(MODE_FM)
|
||||
if (m_fmEnable) {
|
||||
bool cos = getCOS();
|
||||
bool cos = getCOSInt();
|
||||
#if defined(USE_DCBLOCKER)
|
||||
fm.samples(cos, dcSamples, RX_BLOCK_SIZE);
|
||||
#else
|
||||
@@ -544,7 +531,7 @@ void CIO::process()
|
||||
else if (m_modemState == STATE_DMR) {
|
||||
if (m_dmrEnable) {
|
||||
q15_t DMRVals[RX_BLOCK_SIZE];
|
||||
::arm_fir_fast_q15(&m_rrc02Filter1, samples, DMRVals, RX_BLOCK_SIZE);
|
||||
::arm_fir_fast_q15(&m_rrc02Filter, samples, DMRVals, RX_BLOCK_SIZE);
|
||||
|
||||
if (m_duplex) {
|
||||
// If the transmitter isn't on, use the DMR idle RX to detect the wakeup CSBKs
|
||||
@@ -564,9 +551,9 @@ void CIO::process()
|
||||
if (m_ysfEnable) {
|
||||
q15_t YSFVals[RX_BLOCK_SIZE];
|
||||
#if defined(USE_DCBLOCKER)
|
||||
::arm_fir_fast_q15(&m_rrc02Filter2, dcSamples, YSFVals, RX_BLOCK_SIZE);
|
||||
::arm_fir_fast_q15(&m_rrc02Filter, dcSamples, YSFVals, RX_BLOCK_SIZE);
|
||||
#else
|
||||
::arm_fir_fast_q15(&m_rrc02Filter2, samples, YSFVals, RX_BLOCK_SIZE);
|
||||
::arm_fir_fast_q15(&m_rrc02Filter, samples, YSFVals, RX_BLOCK_SIZE);
|
||||
#endif
|
||||
ysfRX.samples(YSFVals, rssi, RX_BLOCK_SIZE);
|
||||
}
|
||||
@@ -627,7 +614,7 @@ void CIO::process()
|
||||
|
||||
#if defined(MODE_FM)
|
||||
else if (m_modemState == STATE_FM) {
|
||||
bool cos = getCOS();
|
||||
bool cos = getCOSInt();
|
||||
#if defined(USE_DCBLOCKER)
|
||||
fm.samples(cos, dcSamples, RX_BLOCK_SIZE);
|
||||
|
||||
@@ -672,7 +659,7 @@ void CIO::write(MMDVM_STATE mode, q15_t* samples, uint16_t length, const uint8_t
|
||||
// Switch the transmitter on if needed
|
||||
if (!m_tx) {
|
||||
m_tx = true;
|
||||
setPTT(m_pttInvert ? false : true);
|
||||
setPTTInt(m_pttInvert ? false : true);
|
||||
DEBUG1("TX ON");
|
||||
}
|
||||
|
||||
@@ -734,7 +721,7 @@ uint16_t CIO::getSpace() const
|
||||
void CIO::setDecode(bool dcd)
|
||||
{
|
||||
if (dcd != m_dcd)
|
||||
setCOS(dcd ? true : false);
|
||||
setCOSInt(dcd ? true : false);
|
||||
|
||||
m_dcd = dcd;
|
||||
}
|
||||
@@ -751,30 +738,32 @@ void CIO::setMode(MMDVM_STATE state)
|
||||
|
||||
#if defined(MODE_LEDS)
|
||||
switch (m_modemState) {
|
||||
case STATE_DSTAR: setDStar(false); break;
|
||||
case STATE_DMR: setDMR(false); break;
|
||||
case STATE_YSF: setYSF(false); break;
|
||||
case STATE_P25: setP25(false); break;
|
||||
case STATE_NXDN: setNXDN(false); break;
|
||||
case STATE_M17: setM17(false); break;
|
||||
case STATE_POCSAG: setPOCSAG(false); break;
|
||||
case STATE_FM: setFM(false); break;
|
||||
default: break;
|
||||
case STATE_DSTAR: setDStarInt(false); break;
|
||||
case STATE_DMR: setDMRInt(false); break;
|
||||
case STATE_YSF: setYSFInt(false); break;
|
||||
case STATE_P25: setP25Int(false); break;
|
||||
case STATE_NXDN: setNXDNInt(false); break;
|
||||
case STATE_M17: setM17Int(false); break;
|
||||
case STATE_POCSAG: setPOCSAGInt(false); break;
|
||||
case STATE_FM: setFMInt(false); break;
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case STATE_DSTAR: setDStar(true); break;
|
||||
case STATE_DMR: setDMR(true); break;
|
||||
case STATE_YSF: setYSF(true); break;
|
||||
case STATE_P25: setP25(true); break;
|
||||
case STATE_NXDN: setNXDN(true); break;
|
||||
case STATE_M17: setM17(true); break;
|
||||
case STATE_POCSAG: setPOCSAG(true); break;
|
||||
case STATE_FM: setFM(true); break;
|
||||
default: break;
|
||||
case STATE_DSTAR: setDStarInt(true); break;
|
||||
case STATE_DMR: setDMRInt(true); break;
|
||||
case STATE_YSF: setYSFInt(true); break;
|
||||
case STATE_P25: setP25Int(true); break;
|
||||
case STATE_NXDN: setNXDNInt(true); break;
|
||||
case STATE_M17: setM17Int(true); break;
|
||||
case STATE_POCSAG: setPOCSAGInt(true); break;
|
||||
case STATE_FM: setFMInt(true); break;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MODE_OLED)
|
||||
oled.setMode(state);
|
||||
#endif
|
||||
|
||||
m_modemState = state;
|
||||
}
|
||||
|
||||
@@ -846,190 +835,3 @@ bool CIO::hasLockout() const
|
||||
{
|
||||
return m_lockout;
|
||||
}
|
||||
|
||||
void IRQHandler()
|
||||
{
|
||||
io.interrupt();
|
||||
}
|
||||
|
||||
void CIO::interrupt()
|
||||
{
|
||||
TSample sample = {DC_OFFSET, MARK_NONE};
|
||||
uint16_t rawRSSI = 0U;
|
||||
|
||||
m_txBuffer.get(sample);
|
||||
::analogWrite(PIN_TX, sample.sample);
|
||||
|
||||
sample.sample = ::analogRead(PIN_RX);
|
||||
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
rawRSSI = ::analogRead(PIN_RSSI);
|
||||
#endif
|
||||
|
||||
m_rxBuffer.put(sample);
|
||||
m_rssiBuffer.put(rawRSSI);
|
||||
|
||||
m_ledCount++;
|
||||
m_watchdog++;
|
||||
}
|
||||
|
||||
void CIO::initHardware()
|
||||
{
|
||||
#if defined(PIN_COS)
|
||||
::pinMode(PIN_COS, INPUT);
|
||||
#endif
|
||||
|
||||
#if defined(PIN_LED)
|
||||
::pinMode(PIN_LED, OUTPUT);
|
||||
#endif
|
||||
#if defined(PIN_PTT)
|
||||
::pinMode(PIN_PTT, OUTPUT);
|
||||
#endif
|
||||
#if defined(PIN_COSLED)
|
||||
::pinMode(PIN_COSLED, OUTPUT);
|
||||
#endif
|
||||
|
||||
#if defined(MODE_LEDS)
|
||||
#if defined(PIN_DSTAR)
|
||||
::pinMode(PIN_DSTAR, OUTPUT);
|
||||
#endif
|
||||
#if defined(PIN_DMR)
|
||||
::pinMode(PIN_DMR, OUTPUT);
|
||||
#endif
|
||||
#if defined(PIN_YSF)
|
||||
::pinMode(PIN_YSF, OUTPUT);
|
||||
#endif
|
||||
#if defined(PIN_P25)
|
||||
::pinMode(PIN_P25, OUTPUT);
|
||||
#endif
|
||||
#if defined(PIN_NXDN) && !defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
::pinMode(PIN_NXDN, OUTPUT);
|
||||
#endif
|
||||
#if defined(PIN_POCSAG) && !defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
::pinMode(PIN_POCSAG, OUTPUT);
|
||||
#endif
|
||||
#if defined(PIN_FM) && !defined(USE_ALTERNATE_FM_LEDS)
|
||||
::pinMode(PIN_FM, OUTPUT);
|
||||
#endif
|
||||
#if defined(PIN_M17) && !defined(USE_ALTERNATE_M17_LEDS)
|
||||
::pinMode(PIN_M17, OUTPUT);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
::analogReadResolution(12);
|
||||
::analogWriteResolution(12);
|
||||
|
||||
m_timer.setPrescaleFactor((SystemCoreClock / (6 * SAMPLE_RATE)) - 1);
|
||||
m_timer.setOverflow(2);
|
||||
m_timer.attachInterrupt(IRQHandler);
|
||||
m_timer.refresh(); // Make register changes take effect
|
||||
}
|
||||
|
||||
void CIO::startHardware()
|
||||
{
|
||||
m_timer.resume();
|
||||
}
|
||||
|
||||
bool CIO::getCOS()
|
||||
{
|
||||
return ::digitalRead(PIN_COS) == HIGH;
|
||||
}
|
||||
|
||||
void CIO::setLED(bool on)
|
||||
{
|
||||
::digitalWrite(PIN_LED, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setPTT(bool on)
|
||||
{
|
||||
::digitalWrite(PIN_PTT, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setCOS(bool on)
|
||||
{
|
||||
::digitalWrite(PIN_COSLED, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setDStar(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS) && defined(PIN_DSTAR)
|
||||
::digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setDMR(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS) && defined(PIN_DMR)
|
||||
::digitalWrite(PIN_DMR, on ? HIGH : LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setYSF(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS) && defined(PIN_YSF)
|
||||
::digitalWrite(PIN_YSF, on ? HIGH : LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setP25(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS) && defined(PIN_P25)
|
||||
::digitalWrite(PIN_P25, on ? HIGH : LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setNXDN(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS)
|
||||
#if defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
::digitalWrite(PIN_YSF, on ? HIGH : LOW);
|
||||
::digitalWrite(PIN_P25, on ? HIGH : LOW);
|
||||
#else
|
||||
#if defined(PIN_NXDN)
|
||||
::digitalWrite(PIN_NXDN, on ? HIGH : LOW);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setM17(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS)
|
||||
#if defined(USE_ALTERNATE_M17_LEDS)
|
||||
::digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
|
||||
::digitalWrite(PIN_P25, on ? HIGH : LOW);
|
||||
#else
|
||||
#if defined(PIN_M17)
|
||||
::digitalWrite(PIN_M17, on ? HIGH : LOW);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setPOCSAG(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS)
|
||||
#if defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
::digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
|
||||
::digitalWrite(PIN_DMR, on ? HIGH : LOW);
|
||||
#else
|
||||
#if defined(PIN_POCSAG)
|
||||
::digitalWrite(PIN_POCSAG, on ? HIGH : LOW);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setFM(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS)
|
||||
#if defined(USE_ALTERNATE_FM_LEDS)
|
||||
::digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
|
||||
::digitalWrite(PIN_YSF, on ? HIGH : LOW);
|
||||
#else
|
||||
#if defined(PIN_FM)
|
||||
::digitalWrite(PIN_FM, on ? HIGH : LOW);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
+25
-26
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2015,2016,2017,2018,2020,2021,2024 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2015,2016,2017,2018,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
|
||||
@@ -58,11 +58,13 @@ public:
|
||||
void resetWatchdog();
|
||||
uint32_t getWatchdog();
|
||||
|
||||
uint8_t getCPU() const;
|
||||
|
||||
void getUDID(uint8_t* buffer);
|
||||
|
||||
void selfTest();
|
||||
|
||||
private:
|
||||
HardwareTimer m_timer;
|
||||
|
||||
bool m_started;
|
||||
|
||||
CRingBuffer<TSample> m_rxBuffer;
|
||||
@@ -79,14 +81,9 @@ private:
|
||||
q15_t m_gaussianState[40U]; // NoTaps + BlockSize - 1, 12 + 20 - 1 plus some spare
|
||||
#endif
|
||||
|
||||
#if defined(MODE_DMR)
|
||||
arm_fir_instance_q15 m_rrc02Filter1;
|
||||
q15_t m_rrc02State1[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare
|
||||
#endif
|
||||
|
||||
#if defined(MODE_YSF)
|
||||
arm_fir_instance_q15 m_rrc02Filter2;
|
||||
q15_t m_rrc02State2[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare
|
||||
#if defined(MODE_DMR) || defined(MODE_YSF)
|
||||
arm_fir_instance_q15 m_rrc02Filter;
|
||||
q15_t m_rrc02State[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare
|
||||
#endif
|
||||
|
||||
#if defined(MODE_P25)
|
||||
@@ -141,24 +138,26 @@ private:
|
||||
|
||||
bool m_lockout;
|
||||
|
||||
// Hardware access routines
|
||||
void initHardware();
|
||||
void startHardware();
|
||||
// Hardware specific routines
|
||||
void initInt();
|
||||
void startInt();
|
||||
|
||||
bool getCOS();
|
||||
bool getCOSInt();
|
||||
|
||||
void setLED(bool on);
|
||||
void setPTT(bool on);
|
||||
void setCOS(bool on);
|
||||
void setLEDInt(bool on);
|
||||
void setPTTInt(bool on);
|
||||
void setCOSInt(bool on);
|
||||
|
||||
void setDStar(bool on);
|
||||
void setDMR(bool on);
|
||||
void setYSF(bool on);
|
||||
void setP25(bool on);
|
||||
void setNXDN(bool on);
|
||||
void setPOCSAG(bool on);
|
||||
void setM17(bool on);
|
||||
void setFM(bool on);
|
||||
void setDStarInt(bool on);
|
||||
void setDMRInt(bool on);
|
||||
void setYSFInt(bool on);
|
||||
void setP25Int(bool on);
|
||||
void setNXDNInt(bool on);
|
||||
void setPOCSAGInt(bool on);
|
||||
void setM17Int(bool on);
|
||||
void setFMInt(bool on);
|
||||
|
||||
void delayInt(unsigned int dly);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,323 @@
|
||||
/*
|
||||
* Copyright (C) 2015,2016,2017,2018,2020 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2015 by Jim Mclaughlin KI6ZUM
|
||||
* Copyright (C) 2016 by Colin Durbridge G4EML
|
||||
*
|
||||
* 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"
|
||||
#include "Globals.h"
|
||||
#include "IO.h"
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
|
||||
// An Arduino Due
|
||||
#if defined(ARDUINO_DUE_PAPA)
|
||||
#define PIN_COS 7
|
||||
#define PIN_PTT 8
|
||||
#define PIN_COSLED 11
|
||||
#define PIN_DSTAR 16
|
||||
#define PIN_DMR 17
|
||||
#define PIN_YSF 18
|
||||
#define PIN_P25 19
|
||||
#define PIN_NXDN 20
|
||||
#define PIN_POCSAG 4
|
||||
#define PIN_FM 5
|
||||
#define ADC_CHER_Chan (1<<7) // ADC on Due pin A0 - Due AD7 - (1 << 7)
|
||||
#define ADC_ISR_EOC_Chan ADC_ISR_EOC7
|
||||
#define ADC_CDR_Chan 7
|
||||
#define DACC_MR_USER_SEL_Chan DACC_MR_USER_SEL_CHANNEL0 // DAC on Due DAC0
|
||||
#define DACC_CHER_Chan DACC_CHER_CH0
|
||||
#elif defined(ARDUINO_DUE_ZUM_V10)
|
||||
#define PIN_COS 52
|
||||
#define PIN_PTT 23
|
||||
#define PIN_COSLED 22
|
||||
#define PIN_DSTAR 9
|
||||
#define PIN_DMR 8
|
||||
#define PIN_YSF 7
|
||||
#define PIN_P25 6
|
||||
#define PIN_NXDN 5
|
||||
#define PIN_POCSAG 4
|
||||
#define PIN_FM 3
|
||||
#define ADC_CHER_Chan (1<<13) // ADC on Due pin A11 - Due AD13 - (1 << 13)
|
||||
#define ADC_ISR_EOC_Chan ADC_ISR_EOC13
|
||||
#define ADC_CDR_Chan 13
|
||||
#define DACC_MR_USER_SEL_Chan DACC_MR_USER_SEL_CHANNEL1 // DAC on Due DAC1
|
||||
#define DACC_CHER_Chan DACC_CHER_CH1
|
||||
#define RSSI_CHER_Chan (1<<1) // ADC on Due pin A6 - Due AD1 - (1 << 1)
|
||||
#define RSSI_CDR_Chan 1
|
||||
#elif defined(ARDUINO_DUE_NTH)
|
||||
#define PIN_COS A7
|
||||
#define PIN_PTT A8
|
||||
#define PIN_COSLED A11
|
||||
#define PIN_DSTAR 9
|
||||
#define PIN_DMR 8
|
||||
#define PIN_YSF 7
|
||||
#define PIN_P25 6
|
||||
#define PIN_NXDN 5
|
||||
#define PIN_POCSAG 4
|
||||
#define PIN_FM 3
|
||||
#define ADC_CHER_Chan (1<<7) // ADC on Due pin A0 - Due AD7 - (1 << 7)
|
||||
#define ADC_ISR_EOC_Chan ADC_ISR_EOC7
|
||||
#define ADC_CDR_Chan 7
|
||||
#define DACC_MR_USER_SEL_Chan DACC_MR_USER_SEL_CHANNEL0 // DAC on Due DAC0
|
||||
#define DACC_CHER_Chan DACC_CHER_CH0
|
||||
#define RSSI_CHER_Chan (1<<1) // ADC on Due pin A6 - Due AD1 - (1 << 1)
|
||||
#define RSSI_CDR_Chan 1
|
||||
#else
|
||||
#error "Either ARDUINO_DUE_PAPA, ARDUINO_DUE_ZUM_V10, or ARDUINO_DUE_NTH need to be defined"
|
||||
#endif
|
||||
|
||||
const uint16_t DC_OFFSET = 2048U;
|
||||
|
||||
extern "C" {
|
||||
void ADC_Handler()
|
||||
{
|
||||
io.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
void CIO::initInt()
|
||||
{
|
||||
// Set up the TX, COS and LED pins
|
||||
pinMode(PIN_PTT, OUTPUT);
|
||||
pinMode(PIN_COSLED, OUTPUT);
|
||||
pinMode(PIN_LED, OUTPUT);
|
||||
pinMode(PIN_COS, INPUT);
|
||||
|
||||
#if defined(MODE_LEDS)
|
||||
// Set up the mode output pins
|
||||
pinMode(PIN_DSTAR, OUTPUT);
|
||||
pinMode(PIN_DMR, OUTPUT);
|
||||
pinMode(PIN_YSF, OUTPUT);
|
||||
pinMode(PIN_P25, OUTPUT);
|
||||
#if !defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
pinMode(PIN_NXDN, OUTPUT);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_M17_LEDS)
|
||||
pinMode(PIN_M17, OUTPUT);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
pinMode(PIN_POCSAG, OUTPUT);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
pinMode(PIN_FM, OUTPUT);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::startInt()
|
||||
{
|
||||
if (ADC->ADC_ISR & ADC_ISR_EOC_Chan) // Ensure there was an End-of-Conversion and we read the ISR reg
|
||||
io.interrupt();
|
||||
|
||||
// Set up the ADC
|
||||
NVIC_EnableIRQ(ADC_IRQn); // Enable ADC interrupt vector
|
||||
ADC->ADC_IDR = 0xFFFFFFFF; // Disable interrupts
|
||||
ADC->ADC_IER = ADC_CHER_Chan; // Enable End-Of-Conv interrupt
|
||||
ADC->ADC_CHDR = 0xFFFF; // Disable all channels
|
||||
ADC->ADC_CHER = ADC_CHER_Chan; // Enable rx input channel
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
ADC->ADC_CHER |= RSSI_CHER_Chan; // and RSSI input
|
||||
#endif
|
||||
ADC->ADC_CGR = 0x15555555; // All gains set to x1
|
||||
ADC->ADC_COR = 0x00000000; // All offsets off
|
||||
ADC->ADC_MR = (ADC->ADC_MR & 0xFFFFFFF0) | (1 << 1) | ADC_MR_TRGEN; // 1 = trig source TIO from TC0
|
||||
|
||||
#if defined(EXTERNAL_OSC)
|
||||
// Set up the external clock input on PA4 = AI5
|
||||
REG_PIOA_ODR = 0x10; // Set pin as input
|
||||
REG_PIOA_PDR = 0x10; // Disable PIO A bit 4
|
||||
REG_PIOA_ABSR &= ~0x10; // Select A peripheral = TCLK1 Input
|
||||
#endif
|
||||
|
||||
// Set up the timer
|
||||
pmc_enable_periph_clk(TC_INTERFACE_ID + 0*3+0) ; // Clock the TC0 channel 0
|
||||
TcChannel* t = &(TC0->TC_CHANNEL)[0]; // Pointer to TC0 registers for its channel 0
|
||||
t->TC_CCR = TC_CCR_CLKDIS; // Disable internal clocking while setup regs
|
||||
t->TC_IDR = 0xFFFFFFFF; // Disable interrupts
|
||||
t->TC_SR; // Read int status reg to clear pending
|
||||
#if defined(EXTERNAL_OSC)
|
||||
t->TC_CMR = TC_CMR_TCCLKS_XC1 | // Use XC1 = TCLK1 external clock
|
||||
#else
|
||||
t->TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1 | // Use TCLK1 (prescale by 2, = 42MHz)
|
||||
#endif
|
||||
TC_CMR_WAVE | // Waveform mode
|
||||
TC_CMR_WAVSEL_UP_RC | // Count-up PWM using RC as threshold
|
||||
TC_CMR_EEVT_XC0 | // Set external events from XC0 (this setup TIOB as output)
|
||||
TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_CLEAR |
|
||||
TC_CMR_BCPB_CLEAR | TC_CMR_BCPC_CLEAR;
|
||||
#if defined(EXTERNAL_OSC)
|
||||
t->TC_RC = EXTERNAL_OSC / 24000; // Counter resets on RC, so sets period in terms of the external clock
|
||||
t->TC_RA = EXTERNAL_OSC / 48000; // Roughly square wave
|
||||
#else
|
||||
t->TC_RC = 1750; // Counter resets on RC, so sets period in terms of 42MHz internal clock
|
||||
t->TC_RA = 880; // Roughly square wave
|
||||
#endif
|
||||
t->TC_CMR = (t->TC_CMR & 0xFFF0FFFF) | TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_SET; // Set clear and set from RA and RC compares
|
||||
t->TC_CCR = TC_CCR_CLKEN | TC_CCR_SWTRG; // re-enable local clocking and switch to hardware trigger source.
|
||||
|
||||
// Set up the DAC
|
||||
pmc_enable_periph_clk(DACC_INTERFACE_ID); // Start clocking DAC
|
||||
DACC->DACC_CR = DACC_CR_SWRST; // Reset DAC
|
||||
DACC->DACC_MR =
|
||||
DACC_MR_TRGEN_EN | DACC_MR_TRGSEL(1) | // Trigger 1 = TIO output of TC0
|
||||
DACC_MR_USER_SEL_Chan | // Select channel
|
||||
(24 << DACC_MR_STARTUP_Pos); // 24 = 1536 cycles which I think is in range 23..45us since DAC clock = 42MHz
|
||||
DACC->DACC_IDR = 0xFFFFFFFF; // No interrupts
|
||||
DACC->DACC_CHER = DACC_CHER_Chan; // Enable channel
|
||||
|
||||
digitalWrite(PIN_PTT, m_pttInvert ? HIGH : LOW);
|
||||
digitalWrite(PIN_COSLED, LOW);
|
||||
digitalWrite(PIN_LED, HIGH);
|
||||
}
|
||||
|
||||
void CIO::interrupt()
|
||||
{
|
||||
if ((ADC->ADC_ISR & ADC_ISR_EOC_Chan) == ADC_ISR_EOC_Chan) { // Ensure there was an End-of-Conversion and we read the ISR reg
|
||||
TSample sample = {DC_OFFSET, MARK_NONE};
|
||||
|
||||
m_txBuffer.get(sample);
|
||||
DACC->DACC_CDR = sample.sample;
|
||||
|
||||
sample.sample = ADC->ADC_CDR[ADC_CDR_Chan];
|
||||
m_rxBuffer.put(sample);
|
||||
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
m_rssiBuffer.put(ADC->ADC_CDR[RSSI_CDR_Chan]);
|
||||
#else
|
||||
m_rssiBuffer.put(0U);
|
||||
#endif
|
||||
|
||||
m_watchdog++;
|
||||
}
|
||||
}
|
||||
|
||||
bool CIO::getCOSInt()
|
||||
{
|
||||
return digitalRead(PIN_COS) == HIGH;
|
||||
}
|
||||
|
||||
void CIO::setLEDInt(bool on)
|
||||
{
|
||||
digitalWrite(PIN_LED, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setPTTInt(bool on)
|
||||
{
|
||||
digitalWrite(PIN_PTT, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setCOSInt(bool on)
|
||||
{
|
||||
digitalWrite(PIN_COSLED, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setDStarInt(bool on)
|
||||
{
|
||||
digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setDMRInt(bool on)
|
||||
{
|
||||
digitalWrite(PIN_DMR, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setYSFInt(bool on)
|
||||
{
|
||||
digitalWrite(PIN_YSF, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setP25Int(bool on)
|
||||
{
|
||||
digitalWrite(PIN_P25, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setNXDNInt(bool on)
|
||||
{
|
||||
#if defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
digitalWrite(PIN_YSF, on ? HIGH : LOW);
|
||||
digitalWrite(PIN_P25, on ? HIGH : LOW);
|
||||
#else
|
||||
digitalWrite(PIN_NXDN, on ? HIGH : LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setM17Int(bool on)
|
||||
{
|
||||
#if defined(USE_ALTERNATE_M17_LEDS)
|
||||
digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
|
||||
digitalWrite(PIN_P25, on ? HIGH : LOW);
|
||||
#else
|
||||
digitalWrite(PIN_M17, on ? HIGH : LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setPOCSAGInt(bool on)
|
||||
{
|
||||
#if defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
|
||||
digitalWrite(PIN_DMR, on ? HIGH : LOW);
|
||||
#else
|
||||
digitalWrite(PIN_POCSAG, on ? HIGH : LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setFMInt(bool on)
|
||||
{
|
||||
#if defined(USE_ALTERNATE_FM_LEDS)
|
||||
digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
|
||||
digitalWrite(PIN_YSF, on ? HIGH : LOW);
|
||||
#else
|
||||
digitalWrite(PIN_FM, on ? HIGH : LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::delayInt(unsigned int dly)
|
||||
{
|
||||
delay(dly);
|
||||
}
|
||||
|
||||
uint8_t CIO::getCPU() const
|
||||
{
|
||||
return 0U;
|
||||
}
|
||||
|
||||
// Code taken from https://github.com/emagii/at91sam3s/blob/master/examples/eefc_uniqueid/main.c
|
||||
void CIO::getUDID(uint8_t* buffer)
|
||||
{
|
||||
uint32_t status;
|
||||
|
||||
EFC1->EEFC_FCR = (0x5A << 24) | EFC_FCMD_STUI;
|
||||
do {
|
||||
status = EFC1->EEFC_FSR;
|
||||
} while ( (status & EEFC_FSR_FRDY) == EEFC_FSR_FRDY );
|
||||
|
||||
for (uint8_t i = 0; i < 16; i+=4) {
|
||||
buffer[i + 0] = *(uint32_t *)(IFLASH1_ADDR + i) >> 24;
|
||||
buffer[i + 1] = *(uint32_t *)(IFLASH1_ADDR + i) >> 16;
|
||||
buffer[i + 2] = *(uint32_t *)(IFLASH1_ADDR + i) >> 8;
|
||||
buffer[i + 3] = *(uint32_t *)(IFLASH1_ADDR + i) >> 0;
|
||||
}
|
||||
|
||||
EFC1->EEFC_FCR = (0x5A << 24) | EFC_FCMD_SPUI;
|
||||
do {
|
||||
status = EFC1->EEFC_FSR;
|
||||
} while ( (status & EEFC_FSR_FRDY) != EEFC_FSR_FRDY );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2019,2020 by BG5HHP
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _IO_PINS_H
|
||||
#define _IO_PINS_H
|
||||
|
||||
#if !defined(CONFIG_H)
|
||||
#error "Requires Config.h to be included first!"
|
||||
#endif
|
||||
|
||||
#if defined(STM32F4_RPT_HAT_TGO)
|
||||
#include "pins/pins_f4_rpt_tgo.h"
|
||||
|
||||
#elif defined(STM32F4_DISCOVERY)
|
||||
#include "pins/pins_f4_discovery.h"
|
||||
|
||||
#elif defined(STM32F4_PI)
|
||||
#include "pins/pins_f4_pi.h"
|
||||
|
||||
#elif defined(STM32F722_PI)
|
||||
#include "pins/pins_f7_pi.h"
|
||||
|
||||
#elif defined(STM32F4_F4M)
|
||||
#include "pins/pins_f4_f4m.h"
|
||||
|
||||
#elif defined(STM32F722_F7M)
|
||||
#include "pins/pins_f7_f7m.h"
|
||||
|
||||
#elif defined(STM32F722_RPT_HAT)
|
||||
#include "pins/pins_f7_rpt_hat.h"
|
||||
|
||||
#elif defined(STM32F4_NUCLEO)
|
||||
#if defined(STM32F4_NUCLEO_MORPHO_HEADER)
|
||||
#include "pins/pins_f4_nucleo_morpho.h"
|
||||
#elif defined(STM32F4_NUCLEO_ARDUINO_HEADER)
|
||||
#include "pins/pins_f4_nucleo_arduino.h"
|
||||
#else
|
||||
#error "Either STM32F4_NUCLEO_MORPHO_HEADER or STM32F4_NUCLEO_ARDUINO_HEADER need to be defined"
|
||||
#endif
|
||||
|
||||
#elif defined(STM32F7_NUCLEO)
|
||||
#include "pins/pins_f7_nucleo.h"
|
||||
|
||||
#elif defined(STM32F4_DVM)
|
||||
#include "pins/pins_f4_stm32dvm_v3.h"
|
||||
|
||||
#elif defined(STM32F7_DVM)
|
||||
#include "pins/pins_f7_stm32dvm_v5.h"
|
||||
|
||||
#elif defined(DRCC_DVM_NQF)
|
||||
#include "pins/pins_f4_drcc_nqf.h"
|
||||
|
||||
#elif defined(DRCC_DVM_HHP446)
|
||||
#include "pins/pins_f4_drcc_hhp446.h"
|
||||
|
||||
#elif defined(STM32F4_EDA_405) || defined(STM32F4_EDA_446)
|
||||
#include "pins/pins_f4_stm32eda.h"
|
||||
|
||||
#else
|
||||
#error "A valid board type macro need to be defined."
|
||||
|
||||
#endif
|
||||
|
||||
#endif //#ifndef _IO_PINS_H
|
||||
@@ -0,0 +1,569 @@
|
||||
/*
|
||||
* Copyright (C) 2016 by Jim McLaughlin KI6ZUM
|
||||
* Copyright (C) 2016,2017,2018 by Andy Uribe CA6JAU
|
||||
* 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
|
||||
* 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"
|
||||
#include "Globals.h"
|
||||
#include "IO.h"
|
||||
|
||||
#if defined(STM32F4XX) || defined(STM32F7XX)
|
||||
#include "IOPins.h"
|
||||
|
||||
|
||||
const uint16_t DC_OFFSET = 2048U;
|
||||
|
||||
// Sampling frequency
|
||||
#define SAMP_FREQ 24000
|
||||
|
||||
extern "C" {
|
||||
void TIM2_IRQHandler() {
|
||||
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) {
|
||||
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
|
||||
io.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CIO::initInt()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
GPIO_StructInit(&GPIO_InitStruct);
|
||||
GPIO_InitStruct.GPIO_Speed = GPIO_Fast_Speed;
|
||||
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN;
|
||||
|
||||
// PTT pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_PTT, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_PTT;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_PTT, &GPIO_InitStruct);
|
||||
|
||||
// COSLED pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_COSLED, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_COSLED;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_COSLED, &GPIO_InitStruct);
|
||||
|
||||
// LED pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_LED, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_LED;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_LED, &GPIO_InitStruct);
|
||||
|
||||
// Init the input pins PIN_COS
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_COS, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_COS;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_Init(PORT_COS, &GPIO_InitStruct);
|
||||
|
||||
#if defined(MODE_LEDS)
|
||||
// DSTAR pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_DSTAR, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_DSTAR;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_DSTAR, &GPIO_InitStruct);
|
||||
|
||||
// DMR pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_DMR, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_DMR;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_DMR, &GPIO_InitStruct);
|
||||
|
||||
// YSF pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_YSF, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_YSF;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_YSF, &GPIO_InitStruct);
|
||||
|
||||
// P25 pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_P25, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_P25;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_P25, &GPIO_InitStruct);
|
||||
|
||||
#if !defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
// NXDN pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_NXDN, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_NXDN;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_NXDN, &GPIO_InitStruct);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_ALTERNATE_M17_LEDS)
|
||||
// M17 pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_M17, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_M17;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_M17, &GPIO_InitStruct);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
// POCSAG pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_POCSAG, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_POCSAG;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_POCSAG, &GPIO_InitStruct);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_ALTERNATE_FM_LEDS)
|
||||
// FM pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_FM, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_FM;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_FM, &GPIO_InitStruct);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(MODE_PINS) && defined(STM32F4_NUCLEO_MORPHO_HEADER) && (defined(STM32F4_NUCLEO) || defined(STM32F722_RPT_HAT))
|
||||
// DSTAR mode pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_MDSTAR, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_MDSTAR;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_MDSTAR, &GPIO_InitStruct);
|
||||
|
||||
// DMR mode pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_MDMR, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_MDMR;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_MDMR, &GPIO_InitStruct);
|
||||
|
||||
// YSF mode pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_MYSF, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_MYSF;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_MYSF, &GPIO_InitStruct);
|
||||
|
||||
// P25 mode pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_MP25, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_MP25;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_MP25, &GPIO_InitStruct);
|
||||
|
||||
#if !defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
// NXDN mode pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_MNXDN, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_MNXDN;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_MNXDN, &GPIO_InitStruct);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_ALTERNATE_M17_LEDS)
|
||||
// M17 mode pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_MM17, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_MM17;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_MM17, &GPIO_InitStruct);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
// POCSAG mode pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_MPOCSAG, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_MPOCSAG;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_MPOCSAG, &GPIO_InitStruct);
|
||||
#endif
|
||||
|
||||
#if !defined(USE_ALTERNATE_FM_LEDS)
|
||||
// FM mode pin
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_MFM, ENABLE);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_MFM;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PORT_MFM, &GPIO_InitStruct);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(MODE_OLED)
|
||||
oled.init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::startInt()
|
||||
{
|
||||
if ((ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) != RESET))
|
||||
io.interrupt();
|
||||
|
||||
// Init the ADC
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
ADC_InitTypeDef ADC_InitStructure;
|
||||
ADC_CommonInitTypeDef ADC_CommonInitStructure;
|
||||
|
||||
GPIO_StructInit(&GPIO_InitStruct);
|
||||
ADC_CommonStructInit(&ADC_CommonInitStructure);
|
||||
ADC_StructInit(&ADC_InitStructure);
|
||||
|
||||
// Enable ADC1 clock
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_RX, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
|
||||
// Enable ADC1 GPIO
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_RX;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
|
||||
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL ;
|
||||
GPIO_Init(PORT_RX, &GPIO_InitStruct);
|
||||
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
// Enable ADC2 clock
|
||||
RCC_AHB1PeriphClockCmd(RCC_Per_RSSI, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);
|
||||
// Enable ADC2 GPIO
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_RSSI;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
|
||||
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL ;
|
||||
GPIO_Init(PORT_RSSI, &GPIO_InitStruct);
|
||||
#endif
|
||||
|
||||
// Init ADCs in dual mode (RSSI), div clock by two
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult;
|
||||
#else
|
||||
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
|
||||
#endif
|
||||
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
|
||||
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
|
||||
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
|
||||
ADC_CommonInit(&ADC_CommonInitStructure);
|
||||
|
||||
// Init ADC1 and ADC2: 12bit, single-conversion
|
||||
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
|
||||
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
|
||||
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
|
||||
ADC_InitStructure.ADC_ExternalTrigConvEdge = 0;
|
||||
ADC_InitStructure.ADC_ExternalTrigConv = 0;
|
||||
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
||||
ADC_InitStructure.ADC_NbrOfConversion = 1;
|
||||
|
||||
ADC_Init(ADC1, &ADC_InitStructure);
|
||||
|
||||
ADC_EOCOnEachRegularChannelCmd(ADC1, ENABLE);
|
||||
ADC_RegularChannelConfig(ADC1, PIN_RX_CH, 1, ADC_SampleTime_3Cycles);
|
||||
|
||||
// Enable ADC1
|
||||
ADC_Cmd(ADC1, ENABLE);
|
||||
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
ADC_Init(ADC2, &ADC_InitStructure);
|
||||
|
||||
ADC_EOCOnEachRegularChannelCmd(ADC2, ENABLE);
|
||||
ADC_RegularChannelConfig(ADC2, PIN_RSSI_CH, 1, ADC_SampleTime_3Cycles);
|
||||
|
||||
// Enable ADC2
|
||||
ADC_Cmd(ADC2, ENABLE);
|
||||
#endif
|
||||
|
||||
// Init the DAC
|
||||
DAC_InitTypeDef DAC_InitStructure;
|
||||
|
||||
GPIO_StructInit(&GPIO_InitStruct);
|
||||
DAC_StructInit(&DAC_InitStructure);
|
||||
|
||||
// GPIOA clock enable
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
||||
|
||||
// DAC Periph clock enable
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
|
||||
|
||||
// GPIO CONFIGURATION of DAC Pin
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_TX;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
|
||||
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
|
||||
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
|
||||
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
|
||||
DAC_Init(PIN_TX_CH, &DAC_InitStructure);
|
||||
DAC_Cmd(PIN_TX_CH, ENABLE);
|
||||
|
||||
// Init the timer
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
||||
|
||||
#if defined(EXTERNAL_OSC) && !(defined(STM32F4_PI) || defined(STM32F722_PI))
|
||||
// Configure a GPIO as external TIM2 clock source
|
||||
GPIO_PinAFConfig(PORT_EXT_CLK, SRC_EXT_CLK, GPIO_AF_TIM2);
|
||||
GPIO_InitStruct.GPIO_Pin = PIN_EXT_CLK;
|
||||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_Init(PORT_EXT_CLK, &GPIO_InitStruct);
|
||||
#endif
|
||||
|
||||
TIM_TimeBaseInitTypeDef timerInitStructure;
|
||||
TIM_TimeBaseStructInit (&timerInitStructure);
|
||||
|
||||
// TIM2 output frequency
|
||||
#if defined(EXTERNAL_OSC) && !(defined(STM32F4_PI) || defined(STM32F722_PI))
|
||||
timerInitStructure.TIM_Prescaler = (uint16_t) ((EXTERNAL_OSC/(2*SAMP_FREQ)) - 1);
|
||||
timerInitStructure.TIM_Period = 1;
|
||||
#else
|
||||
timerInitStructure.TIM_Prescaler = (uint16_t) ((SystemCoreClock/(6*SAMP_FREQ)) - 1);
|
||||
timerInitStructure.TIM_Period = 2;
|
||||
#endif
|
||||
|
||||
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
timerInitStructure.TIM_RepetitionCounter = 0;
|
||||
TIM_TimeBaseInit(TIM2, &timerInitStructure);
|
||||
|
||||
#if defined(EXTERNAL_OSC) && !(defined(STM32F4_PI) || defined(STM32F722_PI))
|
||||
// Enable external clock
|
||||
TIM_ETRClockMode2Config(TIM2, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0x00);
|
||||
#else
|
||||
// Enable internal clock
|
||||
TIM_InternalClockConfig(TIM2);
|
||||
#endif
|
||||
|
||||
// Enable TIM2
|
||||
TIM_Cmd(TIM2, ENABLE);
|
||||
// Enable TIM2 interrupt
|
||||
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
|
||||
|
||||
NVIC_InitTypeDef nvicStructure;
|
||||
nvicStructure.NVIC_IRQChannel = TIM2_IRQn;
|
||||
nvicStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
nvicStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
nvicStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&nvicStructure);
|
||||
|
||||
GPIO_ResetBits(PORT_COSLED, PIN_COSLED);
|
||||
GPIO_SetBits(PORT_LED, PIN_LED);
|
||||
}
|
||||
|
||||
void CIO::interrupt()
|
||||
{
|
||||
TSample sample = {DC_OFFSET, MARK_NONE};
|
||||
uint16_t rawRSSI = 0U;
|
||||
|
||||
m_txBuffer.get(sample);
|
||||
|
||||
// Send the value to the DAC
|
||||
#if defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)
|
||||
DAC_SetChannel2Data(DAC_Align_12b_R, sample.sample);
|
||||
#else
|
||||
DAC_SetChannel1Data(DAC_Align_12b_R, sample.sample);
|
||||
#endif
|
||||
|
||||
// Read value from ADC1 and ADC2
|
||||
if ((ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET)) {
|
||||
// shouldn't be still in reset at this point so null the sample value?
|
||||
sample.sample = 0U;
|
||||
} else {
|
||||
sample.sample = ADC_GetConversionValue(ADC1);
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
rawRSSI = ADC_GetConversionValue(ADC2);
|
||||
#endif
|
||||
}
|
||||
|
||||
// trigger next ADC1
|
||||
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
|
||||
ADC_SoftwareStartConv(ADC1);
|
||||
|
||||
m_rxBuffer.put(sample);
|
||||
m_rssiBuffer.put(rawRSSI);
|
||||
|
||||
m_watchdog++;
|
||||
}
|
||||
|
||||
bool CIO::getCOSInt()
|
||||
{
|
||||
return GPIO_ReadInputDataBit(PORT_COS, PIN_COS) == Bit_SET;
|
||||
}
|
||||
|
||||
void CIO::setLEDInt(bool on)
|
||||
{
|
||||
GPIO_WriteBit(PORT_LED, PIN_LED, on ? Bit_SET : Bit_RESET);
|
||||
}
|
||||
|
||||
void CIO::setPTTInt(bool on)
|
||||
{
|
||||
GPIO_WriteBit(PORT_PTT, PIN_PTT, on ? Bit_SET : Bit_RESET);
|
||||
}
|
||||
|
||||
void CIO::setCOSInt(bool on)
|
||||
{
|
||||
GPIO_WriteBit(PORT_COSLED, PIN_COSLED, on ? Bit_SET : Bit_RESET);
|
||||
}
|
||||
|
||||
void CIO::setDStarInt(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS)
|
||||
GPIO_WriteBit(PORT_DSTAR, PIN_DSTAR, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
#if defined(MODE_PINS) && defined(STM32F4_NUCLEO_MORPHO_HEADER) && (defined(STM32F4_NUCLEO) || defined(STM32F722_RPT_HAT))
|
||||
GPIO_WriteBit(PORT_MDSTAR, PIN_MDSTAR, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setDMRInt(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS)
|
||||
GPIO_WriteBit(PORT_DMR, PIN_DMR, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
#if defined(MODE_PINS) && defined(STM32F4_NUCLEO_MORPHO_HEADER) && (defined(STM32F4_NUCLEO) || defined(STM32F722_RPT_HAT))
|
||||
GPIO_WriteBit(PORT_MDMR, PIN_MDMR, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setYSFInt(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS)
|
||||
GPIO_WriteBit(PORT_YSF, PIN_YSF, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
#if defined(MODE_PINS) && defined(STM32F4_NUCLEO_MORPHO_HEADER) && (defined(STM32F4_NUCLEO) || defined(STM32F722_RPT_HAT))
|
||||
GPIO_WriteBit(PORT_MYSF, PIN_MYSF, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setP25Int(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS)
|
||||
GPIO_WriteBit(PORT_P25, PIN_P25, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
#if defined(MODE_PINS) && defined(STM32F4_NUCLEO_MORPHO_HEADER) && (defined(STM32F4_NUCLEO) || defined(STM32F722_RPT_HAT))
|
||||
GPIO_WriteBit(PORT_MP25, PIN_MP25, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setNXDNInt(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS)
|
||||
#if defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
GPIO_WriteBit(PORT_YSF, PIN_YSF, on ? Bit_SET : Bit_RESET);
|
||||
GPIO_WriteBit(PORT_P25, PIN_P25, on ? Bit_SET : Bit_RESET);
|
||||
#else
|
||||
GPIO_WriteBit(PORT_NXDN, PIN_NXDN, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MODE_PINS) && defined(STM32F4_NUCLEO_MORPHO_HEADER) && (defined(STM32F4_NUCLEO) || defined(STM32F722_RPT_HAT))
|
||||
#if defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
GPIO_WriteBit(PORT_MYSF, PIN_MYSF, on ? Bit_SET : Bit_RESET);
|
||||
GPIO_WriteBit(PORT_MP25, PIN_MP25, on ? Bit_SET : Bit_RESET);
|
||||
#else
|
||||
GPIO_WriteBit(PORT_MNXDN, PIN_MNXDN, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setM17Int(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS)
|
||||
#if defined(USE_ALTERNATE_M17_LEDS)
|
||||
GPIO_WriteBit(PORT_DSTAR, PIN_DSTAR, on ? Bit_SET : Bit_RESET);
|
||||
GPIO_WriteBit(PORT_P25, PIN_P25, on ? Bit_SET : Bit_RESET);
|
||||
#else
|
||||
GPIO_WriteBit(PORT_M17, PIN_M17, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MODE_PINS) && defined(STM32F4_NUCLEO_MORPHO_HEADER) && (defined(STM32F4_NUCLEO) || defined(STM32F722_RPT_HAT))
|
||||
#if defined(USE_ALTERNATE_M17_LEDS)
|
||||
GPIO_WriteBit(PORT_MDSTAR, PIN_MDSTAR, on ? Bit_SET : Bit_RESET);
|
||||
GPIO_WriteBit(PORT_MP25, PIN_MP25, on ? Bit_SET : Bit_RESET);
|
||||
#else
|
||||
GPIO_WriteBit(PORT_MM17, PIN_MM17, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setPOCSAGInt(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS)
|
||||
#if defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
GPIO_WriteBit(PORT_DSTAR, PIN_DSTAR, on ? Bit_SET : Bit_RESET);
|
||||
GPIO_WriteBit(PORT_DMR, PIN_DMR, on ? Bit_SET : Bit_RESET);
|
||||
#else
|
||||
GPIO_WriteBit(PORT_POCSAG, PIN_POCSAG, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MODE_PINS) && defined(STM32F4_NUCLEO_MORPHO_HEADER) && (defined(STM32F4_NUCLEO) || defined(STM32F722_RPT_HAT))
|
||||
#if defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
GPIO_WriteBit(PORT_MDSTAR, PIN_MDSTAR, on ? Bit_SET : Bit_RESET);
|
||||
GPIO_WriteBit(PORT_MDMR, PIN_MDMR, on ? Bit_SET : Bit_RESET);
|
||||
#else
|
||||
GPIO_WriteBit(PORT_MPOCSAG, PIN_MPOCSAG, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setFMInt(bool on)
|
||||
{
|
||||
#if defined(MODE_LEDS)
|
||||
#if defined(USE_ALTERNATE_FM_LEDS)
|
||||
GPIO_WriteBit(PORT_DSTAR, PIN_DSTAR, on ? Bit_SET : Bit_RESET);
|
||||
GPIO_WriteBit(PORT_YSF, PIN_YSF, on ? Bit_SET : Bit_RESET);
|
||||
#else
|
||||
GPIO_WriteBit(PORT_FM, PIN_FM, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MODE_PINS) && defined(STM32F4_NUCLEO_MORPHO_HEADER) && (defined(STM32F4_NUCLEO) || defined(STM32F722_RPT_HAT))
|
||||
#if defined(USE_ALTERNATE_FM_LEDS)
|
||||
GPIO_WriteBit(PORT_MDSTAR, PIN_MDSTAR, on ? Bit_SET : Bit_RESET);
|
||||
GPIO_WriteBit(PORT_MYSF, PIN_MYSF, on ? Bit_SET : Bit_RESET);
|
||||
#else
|
||||
GPIO_WriteBit(PORT_MFM, PIN_MFM, on ? Bit_SET : Bit_RESET);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
// Simple delay function for STM32
|
||||
// Example from: http://thehackerworkshop.com/?p=1209
|
||||
void CIO::delayInt(unsigned int dly)
|
||||
{
|
||||
#if defined(STM32F7XX)
|
||||
unsigned int loopsPerMillisecond = (SystemCoreClock/1000);
|
||||
#else
|
||||
unsigned int loopsPerMillisecond = (SystemCoreClock/1000) / 3;
|
||||
#endif
|
||||
|
||||
for (; dly > 0; dly--)
|
||||
{
|
||||
asm volatile //this routine waits (approximately) one millisecond
|
||||
(
|
||||
"mov r3, %[loopsPerMillisecond] \n\t" //load the initial loop counter
|
||||
"loop: \n\t"
|
||||
"subs r3, #1 \n\t"
|
||||
"bne loop \n\t"
|
||||
|
||||
: //empty output list
|
||||
: [loopsPerMillisecond] "r" (loopsPerMillisecond) //input to the asm routine
|
||||
: "r3", "cc" //clobber list
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t CIO::getCPU() const
|
||||
{
|
||||
return 2U;
|
||||
}
|
||||
|
||||
void CIO::getUDID(uint8_t* buffer)
|
||||
{
|
||||
#if defined(STM32F4XX)
|
||||
::memcpy(buffer, (void *)0x1FFF7A10, 12U);
|
||||
#elif defined(STM32F722xx)
|
||||
::memcpy(buffer, (void *)0x1FF07A10, 12U);
|
||||
#elif defined(STM32F767xx)
|
||||
::memcpy(buffer, (void *)0x1FF0F420, 12U);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+507
@@ -0,0 +1,507 @@
|
||||
/*
|
||||
* Copyright (C) 2016 by Jim McLaughlin KI6ZUM
|
||||
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
|
||||
* 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
|
||||
* 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"
|
||||
#include "Globals.h"
|
||||
#include "IO.h"
|
||||
|
||||
#if defined(STM32F1)
|
||||
|
||||
#if defined(STM32F1_POG)
|
||||
/*
|
||||
Pin definitions for STM32F1 POG Board:
|
||||
|
||||
PTT PB12 output
|
||||
COSLED PB5 output
|
||||
LED PB4 output
|
||||
COS PB13 input/PD
|
||||
|
||||
DSTAR PB7 output
|
||||
DMR PB6 output
|
||||
YSF PB8 output
|
||||
P25 PB9 output
|
||||
NXDN PB10 output
|
||||
POCSAG PB11 output
|
||||
|
||||
RX PB0 analog input (ADC1_8)
|
||||
RSSI PB1 analog input (ADC2_9)
|
||||
TX PA4 analog output (DAC_OUT1)
|
||||
|
||||
EXT_CLK PA15 input (AF: TIM2_CH1_ETR)
|
||||
|
||||
USART1_TXD PA9 output (AF)
|
||||
USART1_RXD PA10 input (AF)
|
||||
|
||||
*/
|
||||
|
||||
#define PIN_PTT 12
|
||||
#define PORT_PTT GPIOB
|
||||
#define BB_PTT *((bitband_t)BITBAND_PERIPH(&PORT_PTT->ODR, PIN_PTT))
|
||||
#define PIN_COSLED 5
|
||||
#define PORT_COSLED GPIOB
|
||||
#define BB_COSLED *((bitband_t)BITBAND_PERIPH(&PORT_COSLED->ODR, PIN_COSLED))
|
||||
#define PIN_LED 4
|
||||
#define PORT_LED GPIOB
|
||||
#define BB_LED *((bitband_t)BITBAND_PERIPH(&PORT_LED->ODR, PIN_LED))
|
||||
#define PIN_COS 13
|
||||
#define PORT_COS GPIOB
|
||||
#define BB_COS *((bitband_t)BITBAND_PERIPH(&PORT_COS->IDR, PIN_COS))
|
||||
|
||||
#define PIN_DSTAR 7
|
||||
#define PORT_DSTAR GPIOB
|
||||
#define BB_DSTAR *((bitband_t)BITBAND_PERIPH(&PORT_DSTAR->ODR, PIN_DSTAR))
|
||||
#define PIN_DMR 6
|
||||
#define PORT_DMR GPIOB
|
||||
#define BB_DMR *((bitband_t)BITBAND_PERIPH(&PORT_DMR->ODR, PIN_DMR))
|
||||
#define PIN_YSF 8
|
||||
#define PORT_YSF GPIOB
|
||||
#define BB_YSF *((bitband_t)BITBAND_PERIPH(&PORT_YSF->ODR, PIN_YSF))
|
||||
#define PIN_P25 9
|
||||
#define PORT_P25 GPIOB
|
||||
#define BB_P25 *((bitband_t)BITBAND_PERIPH(&PORT_P25->ODR, PIN_P25))
|
||||
#define PIN_NXDN 10
|
||||
#define PORT_NXDN GPIOB
|
||||
#define BB_NXDN *((bitband_t)BITBAND_PERIPH(&PORT_NXDN->ODR, PIN_NXDN))
|
||||
#define PIN_POCSAG 11
|
||||
#define PORT_POCSAG GPIOB
|
||||
#define BB_POCSAG *((bitband_t)BITBAND_PERIPH(&PORT_POCSAG->ODR, PIN_POCSAG))
|
||||
|
||||
#define PIN_RX 0
|
||||
#define PIN_RX_ADC_CH 8
|
||||
#define PORT_RX GPIOB
|
||||
#define PIN_RSSI 1
|
||||
#define PIN_RSSI_ADC_CH 9
|
||||
#define PORT_RSSI GPIOB
|
||||
#define PIN_TX 4
|
||||
#define PIN_TX_DAC_CH 1
|
||||
#define PORT_TX GPIOA
|
||||
|
||||
#define PIN_EXT_CLK 15
|
||||
#define SRC_EXT_CLK 15
|
||||
#define PORT_EXT_CLK GPIOA
|
||||
|
||||
#define PIN_USART1_TXD 9
|
||||
#define PORT_USART1_TXD GPIOA
|
||||
#define PIN_USART1_RXD 10
|
||||
#define PORT_USART1_RXD GPIOA
|
||||
|
||||
#else // defined(STM32F1_POG)
|
||||
#error "Either STM32F1_POG, or sth need to be defined"
|
||||
#endif // defined(STM32F1_POG)
|
||||
|
||||
const uint16_t DC_OFFSET = 2048U;
|
||||
|
||||
// Sampling frequency
|
||||
#define SAMP_FREQ 24000
|
||||
|
||||
extern "C" {
|
||||
void TIM2_IRQHandler() {
|
||||
if ((TIM2->SR & TIM_SR_UIF) == TIM_SR_UIF) {
|
||||
TIM2->SR = ~TIM_SR_UIF; // clear UI flag
|
||||
io.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void delay(uint32_t cnt)
|
||||
{
|
||||
while(cnt--)
|
||||
asm("nop");
|
||||
}
|
||||
|
||||
// source: http://www.freddiechopin.info/
|
||||
void GPIOConfigPin(GPIO_TypeDef *port_ptr, uint32_t pin, uint32_t mode_cnf_value)
|
||||
{
|
||||
volatile uint32_t *cr_ptr;
|
||||
uint32_t cr_value;
|
||||
|
||||
cr_ptr = &port_ptr->CRL; // configuration of pins [0,7] is in CRL
|
||||
|
||||
if (pin >= 8) // is pin in [8; 15]?
|
||||
{ // configuration of pins [8,15] is in CRH
|
||||
cr_ptr++; // advance to next struct element CRL -> CRH
|
||||
pin -= 8; // crop the pin number
|
||||
}
|
||||
|
||||
cr_value = *cr_ptr; // localize the CRL / CRH value
|
||||
|
||||
cr_value &= ~(0xF << (pin * 4)); // clear the MODE and CNF fields (now that pin is an analog input)
|
||||
cr_value |= (mode_cnf_value << (pin * 4)); // save new MODE and CNF value for desired pin
|
||||
|
||||
*cr_ptr = cr_value; // save localized value to CRL / CRL
|
||||
}
|
||||
|
||||
#if defined(STM32F1_POG)
|
||||
void FancyLEDEffect()
|
||||
{
|
||||
bitband_t foo[] = {&BB_LED, &BB_COSLED, &BB_PTT, &BB_DMR, &BB_DSTAR, &BB_YSF, &BB_P25};
|
||||
|
||||
for(int i=0; i<7; i++){
|
||||
*foo[i] = 0x01;
|
||||
}
|
||||
GPIOConfigPin(PORT_USART1_TXD, PIN_USART1_TXD, GPIO_CRL_MODE0_1);
|
||||
*((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x00;
|
||||
delay(SystemCoreClock/1000*100);
|
||||
for(int i=0; i<7; i++){
|
||||
*foo[i] = 0x00;
|
||||
}
|
||||
*((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x01;
|
||||
delay(SystemCoreClock/1000*20);
|
||||
*((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x00;
|
||||
delay(SystemCoreClock/1000*10);
|
||||
*((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x01;
|
||||
|
||||
*foo[0] = 0x01;
|
||||
for(int i=1; i<7; i++){
|
||||
delay(SystemCoreClock/1000*10);
|
||||
*foo[i-1] = 0x00;
|
||||
*foo[i] = 0x01;
|
||||
}
|
||||
for(int i=5; i>=0; i--){
|
||||
delay(SystemCoreClock/1000*10);
|
||||
*foo[i+1] = 0x00;
|
||||
*foo[i] = 0x01;
|
||||
}
|
||||
delay(SystemCoreClock/1000*10);
|
||||
*foo[5+1-6] = 0x00;
|
||||
*((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x00;
|
||||
delay(SystemCoreClock/1000*10);
|
||||
*((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x01;
|
||||
GPIOConfigPin(PORT_USART1_TXD, PIN_USART1_TXD, GPIO_CRL_MODE0_1|GPIO_CRL_CNF0_1);
|
||||
delay(SystemCoreClock/1000*50);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void GPIOInit()
|
||||
{
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN
|
||||
| RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN
|
||||
| RCC_APB2ENR_AFIOEN; // enable all GPIOs
|
||||
|
||||
// set all ports to input with pull-down
|
||||
GPIOA->CRL = 0x88888888;
|
||||
GPIOA->CRH = 0x88888888;
|
||||
GPIOA->ODR = 0;
|
||||
GPIOB->CRL = 0x88888888;
|
||||
GPIOB->CRH = 0x88888888;
|
||||
GPIOB->ODR = 0;
|
||||
GPIOC->CRL = 0x88888888;
|
||||
GPIOC->CRH = 0x88888888;
|
||||
GPIOC->ODR = 0;
|
||||
GPIOD->CRL = 0x88888888;
|
||||
GPIOD->CRH = 0x88888888;
|
||||
GPIOD->ODR = 0;
|
||||
|
||||
// configure ports
|
||||
GPIOConfigPin(PORT_PTT, PIN_PTT, GPIO_CRL_MODE0_1);
|
||||
GPIOConfigPin(PORT_COSLED, PIN_COSLED, GPIO_CRL_MODE0_1);
|
||||
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);
|
||||
GPIOConfigPin(PORT_P25, PIN_P25, GPIO_CRL_MODE0_1);
|
||||
#if !defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
GPIOConfigPin(PORT_NXDN, PIN_NXDN, GPIO_CRL_MODE0_1);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_M17_LEDS)
|
||||
GPIOConfigPin(PORT_M17, PIN_M17, GPIO_CRL_MODE0_1);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
GPIOConfigPin(PORT_POCSAG, PIN_POCSAG, GPIO_CRL_MODE0_1);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
GPIOConfigPin(PORT_RX, PIN_RX, 0);
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
GPIOConfigPin(PORT_RSSI, PIN_RSSI, 0);
|
||||
#endif
|
||||
GPIOConfigPin(PORT_TX, PIN_TX, 0);
|
||||
|
||||
#if defined(EXTERNAL_OSC)
|
||||
#if defined(STM32F1_POG)
|
||||
GPIOConfigPin(PORT_EXT_CLK, PIN_EXT_CLK, GPIO_CRL_CNF0_0);
|
||||
AFIO->MAPR = (AFIO->MAPR & ~AFIO_MAPR_TIM2_REMAP) | AFIO_MAPR_TIM2_REMAP_0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
GPIOConfigPin(PORT_USART1_TXD, PIN_USART1_TXD, GPIO_CRL_MODE0_1|GPIO_CRL_CNF0_1);
|
||||
GPIOConfigPin(PORT_USART1_RXD, PIN_USART1_RXD, GPIO_CRL_CNF0_0);
|
||||
|
||||
AFIO->MAPR = (AFIO->MAPR & ~AFIO_MAPR_SWJ_CFG) | AFIO_MAPR_SWJ_CFG_1;
|
||||
}
|
||||
|
||||
|
||||
static inline void ADCInit()
|
||||
{
|
||||
RCC->CFGR = (RCC->CFGR & ~RCC_CFGR_ADCPRE_Msk)
|
||||
| RCC_CFGR_ADCPRE_DIV6; // ADC clock divided by 6 (72MHz/6 = 12MHz)
|
||||
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
RCC->APB2ENR |= RCC_APB2ENR_ADC2EN;
|
||||
#endif
|
||||
|
||||
// Init ADCs in dual mode (RSSI)
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
ADC1->CR1 = ADC_CR1_DUALMOD_1|ADC_CR1_DUALMOD_2; // Regular simultaneous mode
|
||||
#endif
|
||||
|
||||
// Set sampling time to 7.5 cycles
|
||||
if (PIN_RX_ADC_CH < 10) {
|
||||
ADC1->SMPR2 = ADC_SMPR2_SMP0_0 << (3*PIN_RX_ADC_CH);
|
||||
} else {
|
||||
ADC1->SMPR1 = ADC_SMPR1_SMP10_0 << (3*PIN_RX_ADC_CH);
|
||||
}
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
if (PIN_RSSI_ADC_CH < 10) {
|
||||
ADC2->SMPR2 = ADC_SMPR2_SMP0_0 << (3*PIN_RSSI_ADC_CH);
|
||||
} else {
|
||||
ADC2->SMPR1 = ADC_SMPR1_SMP10_0 << (3*PIN_RSSI_ADC_CH);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Set conversion channel (single conversion)
|
||||
ADC1->SQR3 = PIN_RX_ADC_CH;
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
ADC2->SQR3 = PIN_RSSI_ADC_CH;
|
||||
#endif
|
||||
|
||||
// Enable ADC
|
||||
ADC1->CR2 |= ADC_CR2_ADON;
|
||||
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
// Enable ADC2
|
||||
ADC2->CR2 |= ADC_CR2_ADON;
|
||||
#endif
|
||||
|
||||
// Start calibration
|
||||
delay(6*2);
|
||||
ADC1->CR2 |= ADC_CR2_CAL;
|
||||
while((ADC1->CR2 & ADC_CR2_CAL) == ADC_CR2_CAL)
|
||||
;
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
ADC2->CR2 |= ADC_CR2_CAL;
|
||||
while((ADC2->CR2 & ADC_CR2_CAL) == ADC_CR2_CAL)
|
||||
;
|
||||
#endif
|
||||
|
||||
// Trigger first conversion
|
||||
ADC1->CR2 |= ADC_CR2_ADON;
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
ADC2->CR2 |= ADC_CR2_ADON;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static inline void DACInit()
|
||||
{
|
||||
RCC->APB1ENR |= RCC_APB1ENR_DACEN;
|
||||
|
||||
DAC->CR = DAC_CR_EN1;
|
||||
}
|
||||
|
||||
|
||||
static inline void TimerInit()
|
||||
{
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
|
||||
|
||||
#if defined(EXTERNAL_OSC)
|
||||
// Enable external clock, prescaler /4
|
||||
TIM2->SMCR = TIM_SMCR_ECE | TIM_SMCR_ETPS_1;
|
||||
#endif
|
||||
|
||||
// TIM2 output frequency
|
||||
TIM2->PSC = 0;
|
||||
#if defined(EXTERNAL_OSC)
|
||||
// TimerCount = ExternalOsc
|
||||
// /4 (external clock prescaler)
|
||||
// /SAMP_FREQ
|
||||
TIM2->ARR = (uint16_t) ((EXTERNAL_OSC/(4*SAMP_FREQ)) - 1);
|
||||
#else
|
||||
TIM2->ARR = (uint16_t) ((SystemCoreClock/(SAMP_FREQ)) - 1);
|
||||
#endif
|
||||
|
||||
// Enable TIse 1%-tolerance comM2 interrupt
|
||||
TIM2->DIER = TIM_DIER_UIE;
|
||||
NVIC_EnableIRQ(TIM2_IRQn);
|
||||
|
||||
// Enable TIM2
|
||||
TIM2->CR1 |= TIM_CR1_CEN;
|
||||
}
|
||||
|
||||
|
||||
void CIO::initInt()
|
||||
{
|
||||
GPIOInit();
|
||||
ADCInit();
|
||||
DACInit();
|
||||
#if defined(STM32F1_POG)
|
||||
FancyLEDEffect();
|
||||
#endif
|
||||
#if defined(MODE_OLED)
|
||||
oled.init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::startInt()
|
||||
{
|
||||
TimerInit();
|
||||
|
||||
BB_COSLED = 0;
|
||||
BB_LED = 1;
|
||||
}
|
||||
|
||||
void CIO::interrupt()
|
||||
{
|
||||
TSample sample = {DC_OFFSET, MARK_NONE};
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
uint16_t rawRSSI = 0U;
|
||||
#endif
|
||||
bitband_t eoc = (bitband_t)BITBAND_PERIPH(&ADC1->SR, ADC_SR_EOS_Pos);
|
||||
bitband_t adon = (bitband_t)BITBAND_PERIPH(&ADC1->CR2, ADC_CR2_ADON_Pos);
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
bitband_t rssi_adon = (bitband_t)BITBAND_PERIPH(&ADC2->CR2, ADC_CR2_ADON_Pos);
|
||||
#endif
|
||||
|
||||
if (*eoc) {
|
||||
// trigger next conversion
|
||||
*adon = 1;
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
*rssi_adon = 1;
|
||||
#endif
|
||||
|
||||
m_txBuffer.get(sample);
|
||||
DAC->DHR12R1 = sample.sample; // Send the value to the DAC
|
||||
|
||||
// Read value from ADC1 and ADC2
|
||||
sample.sample = ADC1->DR; // read conversion result; EOC is cleared by this read
|
||||
m_rxBuffer.put(sample);
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
rawRSSI = ADC2->DR;
|
||||
m_rssiBuffer.put(rawRSSI);
|
||||
#endif
|
||||
|
||||
m_watchdog++;
|
||||
}
|
||||
}
|
||||
|
||||
bool CIO::getCOSInt()
|
||||
{
|
||||
return BB_COS;
|
||||
}
|
||||
|
||||
void CIO::setLEDInt(bool on)
|
||||
{
|
||||
BB_LED = !!on;
|
||||
}
|
||||
|
||||
void CIO::setPTTInt(bool on)
|
||||
{
|
||||
BB_PTT = !!on;
|
||||
}
|
||||
|
||||
void CIO::setCOSInt(bool on)
|
||||
{
|
||||
BB_COSLED = !!on;
|
||||
}
|
||||
|
||||
#if defined(MODE_LEDS)
|
||||
void CIO::setDStarInt(bool on)
|
||||
{
|
||||
BB_DSTAR = !!on;
|
||||
}
|
||||
|
||||
void CIO::setDMRInt(bool on)
|
||||
{
|
||||
BB_DMR = !!on;
|
||||
}
|
||||
|
||||
void CIO::setYSFInt(bool on)
|
||||
{
|
||||
BB_YSF = !!on;
|
||||
}
|
||||
|
||||
void CIO::setP25Int(bool on)
|
||||
{
|
||||
BB_P25 = !!on;
|
||||
}
|
||||
|
||||
void CIO::setNXDNInt(bool on)
|
||||
{
|
||||
#if defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
BB_YSF = !!on;
|
||||
BB_P25 = !!on;
|
||||
#else
|
||||
BB_NXDN = !!on;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setM17Int(bool on)
|
||||
{
|
||||
#if defined(USE_ALTERNATE_M17_LEDS)
|
||||
BB_DSTAR = !!on;
|
||||
BB_P25 = !!on;
|
||||
#else
|
||||
BB_M17 = !!on;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setPOCSAGInt(bool on)
|
||||
{
|
||||
#if defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
BB_DSTAR = !!on;
|
||||
BB_DMR = !!on;
|
||||
#else
|
||||
BB_POCSAG = !!on;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setFMInt(bool on)
|
||||
{
|
||||
#if defined(USE_ALTERNATE_FM_LEDS)
|
||||
BB_DSTAR = !!on;
|
||||
BB_YSF = !!on;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void CIO::delayInt(unsigned int dly)
|
||||
{
|
||||
delay(dly);
|
||||
}
|
||||
|
||||
uint8_t CIO::getCPU() const
|
||||
{
|
||||
return 2U;
|
||||
}
|
||||
|
||||
void CIO::getUDID(uint8_t* buffer)
|
||||
{
|
||||
#if defined(STM32F105xC)
|
||||
::memcpy(buffer, (void *)0x1FFFF7E8, 12U);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+289
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* Copyright (C) 2016,2017,2018,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"
|
||||
#include "Globals.h"
|
||||
#include "IO.h"
|
||||
|
||||
#if defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
||||
|
||||
#if defined(EXTERNAL_OSC)
|
||||
#define PIN_LED 3
|
||||
#else
|
||||
#define PIN_LED 13
|
||||
#endif
|
||||
#define PIN_COS 4
|
||||
#define PIN_PTT 5
|
||||
#define PIN_COSLED 6
|
||||
#define PIN_DSTAR 9
|
||||
#define PIN_DMR 10
|
||||
#define PIN_YSF 11
|
||||
#define PIN_P25 12
|
||||
#if defined(__MK20DX256__)
|
||||
#define PIN_NXDN 2
|
||||
#define PIN_POCSAG 3
|
||||
#define PIN_FM 4
|
||||
#else
|
||||
#define PIN_NXDN 24
|
||||
#define PIN_POCSAG 25
|
||||
#define PIN_FM 26
|
||||
#endif
|
||||
#define PIN_ADC 5 // A0, Pin 14
|
||||
#define PIN_RSSI 4 // Teensy 3.5/3.6, A16, Pin 35. Teensy 3.1/3.2, A17, Pin 28
|
||||
|
||||
#define PDB_CHnC1_TOS 0x0100
|
||||
#define PDB_CHnC1_EN 0x0001
|
||||
|
||||
const uint16_t DC_OFFSET = 2048U;
|
||||
|
||||
extern "C" {
|
||||
void adc0_isr()
|
||||
{
|
||||
io.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
void CIO::initInt()
|
||||
{
|
||||
// Set up the TX, COS and LED pins
|
||||
pinMode(PIN_PTT, OUTPUT);
|
||||
pinMode(PIN_COSLED, OUTPUT);
|
||||
pinMode(PIN_LED, OUTPUT);
|
||||
pinMode(PIN_COS, INPUT);
|
||||
|
||||
#if defined(MODE_LEDS)
|
||||
// Set up the mode output pins
|
||||
pinMode(PIN_DSTAR, OUTPUT);
|
||||
pinMode(PIN_DMR, OUTPUT);
|
||||
pinMode(PIN_YSF, OUTPUT);
|
||||
pinMode(PIN_P25, OUTPUT);
|
||||
#if !defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
pinMode(PIN_NXDN, OUTPUT);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_M17_LEDS)
|
||||
pinMode(PIN_M17, OUTPUT);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
pinMode(PIN_POCSAG, OUTPUT);
|
||||
#endif
|
||||
#if !defined(USE_ALTERNATE_FM_LEDS)
|
||||
pinMode(PIN_FM, OUTPUT);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::startInt()
|
||||
{
|
||||
// Initialise the DAC
|
||||
SIM_SCGC2 |= SIM_SCGC2_DAC0;
|
||||
DAC0_C0 = DAC_C0_DACEN | DAC_C0_DACRFS; // 3.3V VDDA is DACREF_2
|
||||
|
||||
// Initialise ADC0
|
||||
SIM_SCGC6 |= SIM_SCGC6_ADC0;
|
||||
ADC0_CFG1 = ADC_CFG1_ADIV(1) | ADC_CFG1_ADICLK(1) | // Single-ended 12 bits, long sample time
|
||||
ADC_CFG1_MODE(1) | ADC_CFG1_ADLSMP;
|
||||
ADC0_CFG2 = ADC_CFG2_MUXSEL | ADC_CFG2_ADLSTS(2); // Select channels ADxxxb
|
||||
ADC0_SC2 = ADC_SC2_REFSEL(0) | ADC_SC2_ADTRG; // Voltage ref external, hardware trigger
|
||||
ADC0_SC3 = ADC_SC3_AVGE | ADC_SC3_AVGS(0); // Enable averaging, 4 samples
|
||||
|
||||
ADC0_SC3 |= ADC_SC3_CAL;
|
||||
while (ADC0_SC3 & ADC_SC3_CAL) // Wait for calibration
|
||||
;
|
||||
|
||||
uint16_t sum0 = ADC0_CLPS + ADC0_CLP4 + ADC0_CLP3 + // Plus side gain
|
||||
ADC0_CLP2 + ADC0_CLP1 + ADC0_CLP0;
|
||||
sum0 = (sum0 / 2U) | 0x8000U;
|
||||
ADC0_PG = sum0;
|
||||
|
||||
ADC0_SC1A = ADC_SC1_AIEN | PIN_ADC; // Enable ADC interrupt, use A0
|
||||
NVIC_ENABLE_IRQ(IRQ_ADC0);
|
||||
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
// Initialise ADC1
|
||||
SIM_SCGC3 |= SIM_SCGC3_ADC1;
|
||||
ADC1_CFG1 = ADC_CFG1_ADIV(1) | ADC_CFG1_ADICLK(1) | // Single-ended 12 bits, long sample time
|
||||
ADC_CFG1_MODE(1) | ADC_CFG1_ADLSMP;
|
||||
ADC1_CFG2 = ADC_CFG2_MUXSEL | ADC_CFG2_ADLSTS(2); // Select channels ADxxxb
|
||||
ADC1_SC2 = ADC_SC2_REFSEL(0); // Voltage ref external, software trigger
|
||||
ADC1_SC3 = ADC_SC3_AVGE | ADC_SC3_AVGS(0); // Enable averaging, 4 samples
|
||||
|
||||
ADC1_SC3 |= ADC_SC3_CAL;
|
||||
while (ADC1_SC3 & ADC_SC3_CAL) // Wait for calibration
|
||||
;
|
||||
|
||||
uint16_t sum1 = ADC1_CLPS + ADC1_CLP4 + ADC1_CLP3 + // Plus side gain
|
||||
ADC1_CLP2 + ADC1_CLP1 + ADC1_CLP0;
|
||||
sum1 = (sum1 / 2U) | 0x8000U;
|
||||
ADC1_PG = sum1;
|
||||
#endif
|
||||
|
||||
#if defined(EXTERNAL_OSC)
|
||||
// Set ADC0 to trigger from the LPTMR at 24 kHz
|
||||
SIM_SOPT7 = SIM_SOPT7_ADC0ALTTRGEN | // Enable ADC0 alternate trigger
|
||||
SIM_SOPT7_ADC0TRGSEL(14); // Trigger ADC0 by LPTMR0
|
||||
|
||||
CORE_PIN13_CONFIG = PORT_PCR_MUX(3);
|
||||
|
||||
SIM_SCGC5 |= SIM_SCGC5_LPTIMER; // Enable Low Power Timer Access
|
||||
LPTMR0_CSR = 0; // Disable
|
||||
LPTMR0_PSR = LPTMR_PSR_PBYP; // Bypass prescaler/filter
|
||||
LPTMR0_CMR = (EXTERNAL_OSC / 24000) - 1; // Frequency divided by CMR + 1
|
||||
LPTMR0_CSR = LPTMR_CSR_TPS(2) | // Pin: 0=CMP0, 1=xtal, 2=pin13
|
||||
LPTMR_CSR_TMS; // Mode Select, 0=timer, 1=counter
|
||||
LPTMR0_CSR |= LPTMR_CSR_TEN; // Enable
|
||||
#else
|
||||
// Setup PDB for ADC0 at 24 kHz
|
||||
SIM_SCGC6 |= SIM_SCGC6_PDB; // Enable PDB clock
|
||||
PDB0_MOD = (F_BUS / 24000) - 1; // Timer period - 1
|
||||
PDB0_IDLY = 0; // Interrupt delay
|
||||
PDB0_CH0C1 = PDB_CHnC1_TOS | PDB_CHnC1_EN; // Enable pre-trigger for ADC0
|
||||
PDB0_SC = PDB_SC_TRGSEL(15) | PDB_SC_PDBEN | // SW trigger, enable interrupts, continuous mode
|
||||
PDB_SC_PDBIE | PDB_SC_CONT | PDB_SC_LDOK; // No prescaling
|
||||
PDB0_SC |= PDB_SC_SWTRIG; // Software trigger (reset and restart counter)
|
||||
#endif
|
||||
|
||||
digitalWrite(PIN_PTT, m_pttInvert ? HIGH : LOW);
|
||||
digitalWrite(PIN_COSLED, LOW);
|
||||
digitalWrite(PIN_LED, HIGH);
|
||||
}
|
||||
|
||||
void CIO::interrupt()
|
||||
{
|
||||
TSample sample = {DC_OFFSET, MARK_NONE};
|
||||
|
||||
m_txBuffer.get(sample);
|
||||
*(int16_t *)&(DAC0_DAT0L) = sample.sample;
|
||||
|
||||
if ((ADC0_SC1A & ADC_SC1_COCO) == ADC_SC1_COCO) {
|
||||
sample.sample = ADC0_RA;
|
||||
m_rxBuffer.put(sample);
|
||||
}
|
||||
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
if ((ADC1_SC1A & ADC_SC1_COCO) == ADC_SC1_COCO) {
|
||||
uint16_t rssi = ADC1_RA;
|
||||
m_rssiBuffer.put(rssi);
|
||||
} else {
|
||||
m_rssiBuffer.put(0U);
|
||||
}
|
||||
|
||||
ADC1_SC1A = PIN_RSSI; // Start the next RSSI conversion
|
||||
#else
|
||||
m_rssiBuffer.put(0U);
|
||||
#endif
|
||||
|
||||
m_watchdog++;
|
||||
}
|
||||
|
||||
bool CIO::getCOSInt()
|
||||
{
|
||||
return digitalRead(PIN_COS) == HIGH;
|
||||
}
|
||||
|
||||
void CIO::setLEDInt(bool on)
|
||||
{
|
||||
digitalWrite(PIN_LED, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setPTTInt(bool on)
|
||||
{
|
||||
digitalWrite(PIN_PTT, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setCOSInt(bool on)
|
||||
{
|
||||
digitalWrite(PIN_COSLED, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setDStarInt(bool on)
|
||||
{
|
||||
digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setDMRInt(bool on)
|
||||
{
|
||||
digitalWrite(PIN_DMR, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setYSFInt(bool on)
|
||||
{
|
||||
digitalWrite(PIN_YSF, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setP25Int(bool on)
|
||||
{
|
||||
digitalWrite(PIN_P25, on ? HIGH : LOW);
|
||||
}
|
||||
|
||||
void CIO::setNXDNInt(bool on)
|
||||
{
|
||||
#if defined(USE_ALTERNATE_NXDN_LEDS)
|
||||
digitalWrite(PIN_YSF, on ? HIGH : LOW);
|
||||
digitalWrite(PIN_P25, on ? HIGH : LOW);
|
||||
#else
|
||||
digitalWrite(PIN_NXDN, on ? HIGH : LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setM17Int(bool on)
|
||||
{
|
||||
#if defined(USE_ALTERNATE_M17_LEDS)
|
||||
digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
|
||||
digitalWrite(PIN_P25, on ? HIGH : LOW);
|
||||
#else
|
||||
digitalWrite(PIN_M17, on ? HIGH : LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setPOCSAGInt(bool on)
|
||||
{
|
||||
#if defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||
digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
|
||||
digitalWrite(PIN_DMR, on ? HIGH : LOW);
|
||||
#else
|
||||
digitalWrite(PIN_POCSAG, on ? HIGH : LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::setFMInt(bool on)
|
||||
{
|
||||
#if defined(USE_ALTERNATE_FM_LEDS)
|
||||
digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
|
||||
digitalWrite(PIN_YSF, on ? HIGH : LOW);
|
||||
#else
|
||||
digitalWrite(PIN_FM, on ? HIGH : LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CIO::delayInt(unsigned int dly)
|
||||
{
|
||||
delay(dly);
|
||||
}
|
||||
|
||||
uint8_t CIO::getCPU() const
|
||||
{
|
||||
return 1U;
|
||||
}
|
||||
|
||||
void CIO::getUDID(uint8_t* buffer)
|
||||
{
|
||||
::memcpy(buffer, (void *)0x4058, 16U);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2016,2017,2018,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
|
||||
@@ -27,17 +27,18 @@ const unsigned int M17_FRAME_LENGTH_SYMBOLS = M17_FRAME_LENGTH_BITS / 2U;
|
||||
const unsigned int M17_FRAME_LENGTH_SAMPLES = M17_FRAME_LENGTH_SYMBOLS * M17_RADIO_SYMBOL_LENGTH;
|
||||
|
||||
const unsigned int M17_SYNC_LENGTH_BITS = 16U;
|
||||
const unsigned int M17_SYNC_LENGTH_BYTES = M17_SYNC_LENGTH_BITS / 8U;
|
||||
const unsigned int M17_SYNC_LENGTH_SYMBOLS = M17_SYNC_LENGTH_BITS / 2U;
|
||||
const unsigned int M17_SYNC_LENGTH_SAMPLES = M17_SYNC_LENGTH_SYMBOLS * M17_RADIO_SYMBOL_LENGTH;
|
||||
|
||||
const uint8_t M17_LINK_SETUP_SYNC_BYTES[] = {0x55U, 0xF7U};
|
||||
const uint8_t M17_STREAM_SYNC_BYTES[] = {0xFFU, 0x5DU};
|
||||
const uint8_t M17_EOF_SYNC_BYTES[] = {0x55U, 0x5DU};
|
||||
const uint8_t M17_PACKET_SYNC_BYTES[] = {0x75U, 0xFFU};
|
||||
|
||||
const uint8_t M17_SYNC_BYTES_LENGTH = 2U;
|
||||
|
||||
const uint16_t M17_LINK_SETUP_SYNC_BITS = 0x55F7U;
|
||||
const uint16_t M17_STREAM_SYNC_BITS = 0xFF5DU;
|
||||
const uint16_t M17_EOF_SYNC_BITS = 0x555DU;
|
||||
const uint16_t M17_PACKET_SYNC_BITS = 0x75FFU;
|
||||
|
||||
// 5 5 F 7
|
||||
// 01 01 01 01 11 11 01 11
|
||||
@@ -55,13 +56,13 @@ const int8_t M17_STREAM_SYNC_SYMBOLS_VALUES[] = {-3, -3, -3, -3, +3, +3, -3, +3}
|
||||
|
||||
const uint8_t M17_STREAM_SYNC_SYMBOLS = 0x0DU;
|
||||
|
||||
// 5 5 5 D
|
||||
// 01 01 01 01 01 01 11 01
|
||||
// +3 +3 +3 +3 +3 +3 -3 +3
|
||||
// 7 5 F F
|
||||
// 01 11 01 01 11 11 11 11
|
||||
// +3 -3 +3 +3 -3 -3 -3 -3
|
||||
|
||||
const int8_t M17_EOF_SYNC_SYMBOLS_VALUES[] = {+3, +3, +3, +3, +3, +3, -3, +3};
|
||||
const int8_t M17_PACKET_SYNC_SYMBOLS_VALUES[] = {+3, -3, +3, +3, -3, -3, -3, -3};
|
||||
|
||||
const uint8_t M17_EOF_SYNC_SYMBOLS = 0xFDU;
|
||||
const uint8_t M17_PACKET_SYNC_SYMBOLS = 0xB0U;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -105,6 +105,7 @@ void CM17RX::samples(const q15_t* samples, uint16_t* rssi, uint8_t length)
|
||||
switch (m_state) {
|
||||
case M17RXS_LINK_SETUP:
|
||||
case M17RXS_STREAM:
|
||||
case M17RXS_PACKET:
|
||||
processData(sample);
|
||||
break;
|
||||
default:
|
||||
@@ -126,8 +127,9 @@ void CM17RX::processNone(q15_t sample)
|
||||
{
|
||||
bool ret1 = correlateSync(M17_LINK_SETUP_SYNC_SYMBOLS, M17_LINK_SETUP_SYNC_SYMBOLS_VALUES, M17_LINK_SETUP_SYNC_BYTES, MAX_SYNC_SYMBOL_START_ERRS, MAX_SYNC_BIT_START_ERRS);
|
||||
bool ret2 = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_START_ERRS, MAX_SYNC_BIT_START_ERRS);
|
||||
// bool ret3 = correlateSync(M17_PACKET_SYNC_SYMBOLS, M17_PACKET_SYNC_SYMBOLS_VALUES, M17_PACKET_SYNC_BYTES, MAX_SYNC_SYMBOL_START_ERRS, MAX_SYNC_BIT_START_ERRS);
|
||||
|
||||
if (ret1 || ret2) {
|
||||
if (ret1 || ret2 /* || ret3 */ ) {
|
||||
// On the first sync, start the countdown to the state change
|
||||
if (m_countdown == 0U) {
|
||||
m_rssiAccum = 0U;
|
||||
@@ -142,6 +144,7 @@ void CM17RX::processNone(q15_t sample)
|
||||
|
||||
if (ret1) m_nextState = M17RXS_LINK_SETUP;
|
||||
if (ret2) m_nextState = M17RXS_STREAM;
|
||||
// if (ret3) m_nextState = M17RXS_PACKET;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,42 +168,28 @@ void CM17RX::processNone(q15_t sample)
|
||||
|
||||
void CM17RX::processData(q15_t sample)
|
||||
{
|
||||
bool eof = false;
|
||||
|
||||
if (m_minSyncPtr < m_maxSyncPtr) {
|
||||
if (m_dataPtr >= m_minSyncPtr && m_dataPtr <= m_maxSyncPtr) {
|
||||
bool ret = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
|
||||
bool ret1 = correlateSync(M17_LINK_SETUP_SYNC_SYMBOLS, M17_LINK_SETUP_SYNC_SYMBOLS_VALUES, M17_LINK_SETUP_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
|
||||
bool ret2 = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
|
||||
// bool ret3 = correlateSync(M17_PACKET_SYNC_SYMBOLS, M17_PACKET_SYNC_SYMBOLS_VALUES, M17_PACKET_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
|
||||
|
||||
eof = correlateSync(M17_EOF_SYNC_SYMBOLS, M17_EOF_SYNC_SYMBOLS_VALUES, M17_EOF_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
|
||||
|
||||
if (ret) m_state = M17RXS_STREAM;
|
||||
if (ret1) m_state = M17RXS_LINK_SETUP;
|
||||
if (ret2) m_state = M17RXS_STREAM;
|
||||
// if (ret3) m_state = M17RXS_PACKET;
|
||||
}
|
||||
} else {
|
||||
if (m_dataPtr >= m_minSyncPtr || m_dataPtr <= m_maxSyncPtr) {
|
||||
bool ret = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
|
||||
bool ret1 = correlateSync(M17_LINK_SETUP_SYNC_SYMBOLS, M17_LINK_SETUP_SYNC_SYMBOLS_VALUES, M17_LINK_SETUP_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
|
||||
bool ret2 = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
|
||||
// bool ret3 = correlateSync(M17_PACKET_SYNC_SYMBOLS, M17_PACKET_SYNC_SYMBOLS_VALUES, M17_PACKET_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
|
||||
|
||||
eof = correlateSync(M17_EOF_SYNC_SYMBOLS, M17_EOF_SYNC_SYMBOLS_VALUES, M17_EOF_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
|
||||
|
||||
if (ret) m_state = M17RXS_STREAM;
|
||||
if (ret1) m_state = M17RXS_LINK_SETUP;
|
||||
if (ret2) m_state = M17RXS_STREAM;
|
||||
// if (ret3) m_state = M17RXS_PACKET;
|
||||
}
|
||||
}
|
||||
|
||||
if (eof) {
|
||||
DEBUG4("M17RX: eof sync found pos/centre/threshold", m_syncPtr, m_centreVal, m_thresholdVal);
|
||||
|
||||
io.setDecode(false);
|
||||
io.setADCDetection(false);
|
||||
|
||||
serial.writeM17EOT();
|
||||
|
||||
m_state = M17RXS_NONE;
|
||||
m_endPtr = NOENDPTR;
|
||||
m_averagePtr = NOAVEPTR;
|
||||
m_countdown = 0U;
|
||||
m_nextState = M17RXS_NONE;
|
||||
m_maxCorr = 0;
|
||||
}
|
||||
|
||||
if (m_dataPtr == m_endPtr) {
|
||||
// Only update the centre and threshold if they are from a good sync
|
||||
if (m_lostCount == MAX_SYNC_FRAMES) {
|
||||
@@ -222,8 +211,9 @@ void CM17RX::processData(q15_t sample)
|
||||
case M17RXS_STREAM:
|
||||
DEBUG4("M17RX: stream sync found pos/centre/threshold", m_syncPtr, m_centreVal, m_thresholdVal);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case M17RXS_PACKET:
|
||||
DEBUG4("M17RX: packet sync found pos/centre/threshold", m_syncPtr, m_centreVal, m_thresholdVal);
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t frame[M17_FRAME_LENGTH_BYTES + 3U];
|
||||
@@ -246,7 +236,8 @@ void CM17RX::processData(q15_t sample)
|
||||
m_nextState = M17RXS_NONE;
|
||||
m_maxCorr = 0;
|
||||
} else {
|
||||
frame[0U] = m_lostCount == (MAX_SYNC_FRAMES - 1U) ? 0x01U : 0x00U;
|
||||
frame[0U] = 0x00U;
|
||||
frame[0U] |= m_lostCount == (MAX_SYNC_FRAMES - 1U) ? 0x01U : 0x00U;
|
||||
|
||||
switch (m_state) {
|
||||
case M17RXS_LINK_SETUP:
|
||||
@@ -255,8 +246,9 @@ void CM17RX::processData(q15_t sample)
|
||||
case M17RXS_STREAM:
|
||||
writeRSSIStream(frame);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case M17RXS_PACKET:
|
||||
writeRSSIPacket(frame);
|
||||
break;
|
||||
}
|
||||
|
||||
m_maxCorr = 0;
|
||||
@@ -316,11 +308,11 @@ bool CM17RX::correlateSync(uint8_t syncSymbols, const int8_t* syncSymbolValues,
|
||||
if (startPtr >= M17_FRAME_LENGTH_SAMPLES)
|
||||
startPtr -= M17_FRAME_LENGTH_SAMPLES;
|
||||
|
||||
uint8_t sync[M17_SYNC_LENGTH_BYTES];
|
||||
uint8_t sync[M17_SYNC_BYTES_LENGTH];
|
||||
samplesToBits(startPtr, M17_SYNC_LENGTH_SYMBOLS, sync, 0U, m_centreVal, m_thresholdVal);
|
||||
|
||||
uint8_t errs = 0U;
|
||||
for (uint8_t i = 0U; i < M17_SYNC_LENGTH_BYTES; i++)
|
||||
for (uint8_t i = 0U; i < M17_SYNC_BYTES_LENGTH; i++)
|
||||
errs += countBits8(sync[i] ^ syncBytes[i]);
|
||||
|
||||
if (errs <= maxBitErrs) {
|
||||
@@ -445,8 +437,8 @@ void CM17RX::writeRSSILinkSetup(uint8_t* data)
|
||||
if (m_rssiCount > 0U) {
|
||||
uint16_t rssi = m_rssiAccum / m_rssiCount;
|
||||
|
||||
data[49U] = (rssi >> 8) & 0xFFU;
|
||||
data[50U] = (rssi >> 0) & 0xFFU;
|
||||
data[121U] = (rssi >> 8) & 0xFFU;
|
||||
data[122U] = (rssi >> 0) & 0xFFU;
|
||||
|
||||
serial.writeM17LinkSetup(data, M17_FRAME_LENGTH_BYTES + 3U);
|
||||
} else {
|
||||
@@ -466,8 +458,8 @@ void CM17RX::writeRSSIStream(uint8_t* data)
|
||||
if (m_rssiCount > 0U) {
|
||||
uint16_t rssi = m_rssiAccum / m_rssiCount;
|
||||
|
||||
data[49U] = (rssi >> 8) & 0xFFU;
|
||||
data[50U] = (rssi >> 0) & 0xFFU;
|
||||
data[121U] = (rssi >> 8) & 0xFFU;
|
||||
data[122U] = (rssi >> 0) & 0xFFU;
|
||||
|
||||
serial.writeM17Stream(data, M17_FRAME_LENGTH_BYTES + 3U);
|
||||
} else {
|
||||
@@ -481,5 +473,26 @@ void CM17RX::writeRSSIStream(uint8_t* data)
|
||||
m_rssiCount = 0U;
|
||||
}
|
||||
|
||||
void CM17RX::writeRSSIPacket(uint8_t* data)
|
||||
{
|
||||
#if defined(SEND_RSSI_DATA)
|
||||
if (m_rssiCount > 0U) {
|
||||
uint16_t rssi = m_rssiAccum / m_rssiCount;
|
||||
|
||||
data[121U] = (rssi >> 8) & 0xFFU;
|
||||
data[122U] = (rssi >> 0) & 0xFFU;
|
||||
|
||||
serial.writeM17Packet(data, M17_FRAME_LENGTH_BYTES + 3U);
|
||||
} else {
|
||||
serial.writeM17Packet(data, M17_FRAME_LENGTH_BYTES + 1U);
|
||||
}
|
||||
#else
|
||||
serial.writeM17Packet(data, M17_FRAME_LENGTH_BYTES + 1U);
|
||||
#endif
|
||||
|
||||
m_rssiAccum = 0U;
|
||||
m_rssiCount = 0U;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
enum M17RX_STATE {
|
||||
M17RXS_NONE,
|
||||
M17RXS_LINK_SETUP,
|
||||
M17RXS_STREAM
|
||||
M17RXS_STREAM,
|
||||
M17RXS_PACKET
|
||||
};
|
||||
|
||||
class CM17RX {
|
||||
@@ -69,6 +70,7 @@ private:
|
||||
void samplesToBits(uint16_t start, uint16_t count, uint8_t* buffer, uint16_t offset, q15_t centre, q15_t threshold);
|
||||
void writeRSSILinkSetup(uint8_t* data);
|
||||
void writeRSSIStream(uint8_t* data);
|
||||
void writeRSSIPacket(uint8_t* data);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2009-2018,2020,2021 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2009-2018,2020 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2017 by Andy Uribe CA6JAU
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -33,10 +33,10 @@ static q15_t RRC_0_5_FILTER[] = {0, 0, 0, 0, -290, -174, 142, 432, 438, 90, -387
|
||||
438, 432, 142, -174, -290}; // numTaps = 45, L = 5
|
||||
const uint16_t RRC_0_5_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L
|
||||
|
||||
const q15_t M17_LEVELA = 1481;
|
||||
const q15_t M17_LEVELB = 494;
|
||||
const q15_t M17_LEVELC = -494;
|
||||
const q15_t M17_LEVELD = -1481;
|
||||
const q15_t M17_LEVELA = 1683;
|
||||
const q15_t M17_LEVELB = 561;
|
||||
const q15_t M17_LEVELC = -561;
|
||||
const q15_t M17_LEVELD = -1683;
|
||||
|
||||
const uint8_t M17_START_SYNC = 0x77U;
|
||||
const uint8_t M17_END_SYNC = 0xFFU;
|
||||
@@ -18,6 +18,8 @@
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#if defined(STM32F4XX) || defined(STM32F7XX) || defined(STM32F105xC)
|
||||
|
||||
#include "Config.h"
|
||||
#include "Globals.h"
|
||||
|
||||
@@ -39,6 +41,10 @@ bool m_duplex = true;
|
||||
bool m_tx = false;
|
||||
bool m_dcd = false;
|
||||
|
||||
#if defined(MODE_OLED)
|
||||
CI2COLED oled;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_DSTAR)
|
||||
CDStarRX dstarRX;
|
||||
CDStarTX dstarTX;
|
||||
@@ -80,8 +86,6 @@ CCalNXDN calNXDN;
|
||||
#if defined(MODE_M17)
|
||||
CM17RX m17RX;
|
||||
CM17TX m17TX;
|
||||
|
||||
CCalM17 calM17;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_POCSAG)
|
||||
@@ -192,11 +196,6 @@ void loop()
|
||||
calNXDN.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_M17)
|
||||
if (m_modemState == STATE_M17CAL)
|
||||
calM17.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_POCSAG)
|
||||
if (m_modemState == STATE_POCSAGCAL)
|
||||
calPOCSAG.process();
|
||||
@@ -205,3 +204,13 @@ void loop()
|
||||
if (m_modemState == STATE_IDLE)
|
||||
cwIdTX.process();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
setup();
|
||||
|
||||
for (;;)
|
||||
loop();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright (C) 2015,2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX
|
||||
* Copyright (C) 2016 by Colin Durbridge G4EML
|
||||
*
|
||||
* 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"
|
||||
#include "Globals.h"
|
||||
|
||||
// Global variables
|
||||
MMDVM_STATE m_modemState = STATE_IDLE;
|
||||
|
||||
bool m_dstarEnable = true;
|
||||
bool m_dmrEnable = true;
|
||||
bool m_ysfEnable = true;
|
||||
bool m_p25Enable = true;
|
||||
bool m_nxdnEnable = true;
|
||||
bool m_m17Enable = true;
|
||||
bool m_pocsagEnable = true;
|
||||
bool m_fmEnable = true;
|
||||
bool m_ax25Enable = true;
|
||||
|
||||
bool m_duplex = true;
|
||||
|
||||
bool m_tx = false;
|
||||
bool m_dcd = false;
|
||||
|
||||
#if defined(MODE_OLED)
|
||||
CI2COLED oled;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_DSTAR)
|
||||
CDStarRX dstarRX;
|
||||
CDStarTX dstarTX;
|
||||
|
||||
CCalDStarRX calDStarRX;
|
||||
CCalDStarTX calDStarTX;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_DMR)
|
||||
CDMRIdleRX dmrIdleRX;
|
||||
CDMRRX dmrRX;
|
||||
CDMRTX dmrTX;
|
||||
|
||||
CDMRDMORX dmrDMORX;
|
||||
CDMRDMOTX dmrDMOTX;
|
||||
|
||||
CCalDMR calDMR;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_YSF)
|
||||
CYSFRX ysfRX;
|
||||
CYSFTX ysfTX;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_P25)
|
||||
CP25RX p25RX;
|
||||
CP25TX p25TX;
|
||||
|
||||
CCalP25 calP25;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_NXDN)
|
||||
CNXDNRX nxdnRX;
|
||||
CNXDNTX nxdnTX;
|
||||
|
||||
CCalNXDN calNXDN;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_M17)
|
||||
CM17RX m17RX;
|
||||
CM17TX m17TX;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_POCSAG)
|
||||
CPOCSAGTX pocsagTX;
|
||||
CCalPOCSAG calPOCSAG;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_FM)
|
||||
CFM fm;
|
||||
CCalFM calFM;
|
||||
#endif
|
||||
|
||||
#if defined(MODE_AX25)
|
||||
CAX25RX ax25RX;
|
||||
CAX25TX ax25TX;
|
||||
#endif
|
||||
|
||||
CCalRSSI calRSSI;
|
||||
|
||||
CCWIdTX cwIdTX;
|
||||
|
||||
CSerialPort serial;
|
||||
CIO io;
|
||||
|
||||
void setup()
|
||||
{
|
||||
serial.start();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
serial.process();
|
||||
|
||||
io.process();
|
||||
|
||||
// The following is for transmitting
|
||||
#if defined(MODE_DSTAR)
|
||||
if (m_dstarEnable && m_modemState == STATE_DSTAR)
|
||||
dstarTX.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_DMR)
|
||||
if (m_dmrEnable && m_modemState == STATE_DMR) {
|
||||
if (m_duplex)
|
||||
dmrTX.process();
|
||||
else
|
||||
dmrDMOTX.process();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MODE_YSF)
|
||||
if (m_ysfEnable && m_modemState == STATE_YSF)
|
||||
ysfTX.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_P25)
|
||||
if (m_p25Enable && m_modemState == STATE_P25)
|
||||
p25TX.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_NXDN)
|
||||
if (m_nxdnEnable && m_modemState == STATE_NXDN)
|
||||
nxdnTX.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_M17)
|
||||
if (m_m17Enable && m_modemState == STATE_M17)
|
||||
m17TX.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_POCSAG)
|
||||
if (m_pocsagEnable && (m_modemState == STATE_POCSAG || pocsagTX.busy()))
|
||||
pocsagTX.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_AX25)
|
||||
if (m_ax25Enable && (m_modemState == STATE_IDLE || m_modemState == STATE_FM))
|
||||
ax25TX.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_FM)
|
||||
if (m_fmEnable && m_modemState == STATE_FM)
|
||||
fm.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_DSTAR)
|
||||
if (m_modemState == STATE_DSTARCAL)
|
||||
calDStarTX.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_DMR)
|
||||
if (m_modemState == STATE_DMRCAL || m_modemState == STATE_LFCAL || m_modemState == STATE_DMRCAL1K || m_modemState == STATE_DMRDMO1K)
|
||||
calDMR.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_FM)
|
||||
if (m_modemState == STATE_FMCAL10K || m_modemState == STATE_FMCAL12K || m_modemState == STATE_FMCAL15K || m_modemState == STATE_FMCAL20K || m_modemState == STATE_FMCAL25K || m_modemState == STATE_FMCAL30K)
|
||||
calFM.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_P25)
|
||||
if (m_modemState == STATE_P25CAL1K)
|
||||
calP25.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_NXDN)
|
||||
if (m_modemState == STATE_NXDNCAL1K)
|
||||
calNXDN.process();
|
||||
#endif
|
||||
|
||||
#if defined(MODE_POCSAG)
|
||||
if (m_modemState == STATE_POCSAGCAL)
|
||||
calPOCSAG.process();
|
||||
#endif
|
||||
|
||||
if (m_modemState == STATE_IDLE)
|
||||
cwIdTX.process();
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,413 @@
|
||||
# Copyright (C) 2016,2017,2018 by Andy Uribe CA6JAU
|
||||
# Copyright (C) 2016 by Jim McLaughlin KI6ZUM
|
||||
|
||||
# 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.
|
||||
|
||||
# MMDVM source files
|
||||
MMDVM_PATH=.
|
||||
|
||||
# STM32 library paths
|
||||
F4_LIB_PATH=./STM32F4XX_Lib
|
||||
F7_LIB_PATH=./STM32F7XX_Lib
|
||||
|
||||
# MCU external clock frequency (Hz)
|
||||
CLK_MMDVM_PI=12000000
|
||||
CLK_NUCLEO=8000000
|
||||
CLK_12MHZ=12000000
|
||||
|
||||
# Directory Structure
|
||||
BINDIR=bin
|
||||
OBJDIR_F4=obj_f4
|
||||
OBJDIR_F7=obj_f7
|
||||
|
||||
# Output files
|
||||
BINELF_F4=mmdvm_f4.elf
|
||||
BINHEX_F4=mmdvm_f4.hex
|
||||
BINBIN_F4=mmdvm_f4.bin
|
||||
BINELF_F7=mmdvm_f7.elf
|
||||
BINHEX_F7=mmdvm_f7.hex
|
||||
BINBIN_F7=mmdvm_f7.bin
|
||||
|
||||
# Header directories
|
||||
INC_F4= . $(F4_LIB_PATH)/CMSIS/Include/ $(F4_LIB_PATH)/Device/ $(F4_LIB_PATH)/STM32F4xx_StdPeriph_Driver/include/
|
||||
INCLUDES_F4=$(INC_F4:%=-I%)
|
||||
INC_F7= . $(F7_LIB_PATH)/CMSIS/Include/ $(F7_LIB_PATH)/Device/ $(F7_LIB_PATH)/STM32F7xx_StdPeriph_Driver/inc/
|
||||
INCLUDES_F7=$(INC_F7:%=-I%)
|
||||
|
||||
# CMSIS libraries
|
||||
INCLUDES_LIBS_F4=$(F4_LIB_PATH)/CMSIS/Lib/GCC/libarm_cortexM4lf_math.a
|
||||
INCLUDES_LIBS_F7=$(F7_LIB_PATH)/CMSIS/Lib/GCC/libarm_cortexM7lfsp_math.a
|
||||
|
||||
# STM32F4 Standard Peripheral Libraries source path
|
||||
STD_LIB_F4=$(F4_LIB_PATH)/STM32F4xx_StdPeriph_Driver/source
|
||||
|
||||
# STM32F7 Standard Peripheral Libraries source path
|
||||
STD_LIB_F7=$(F7_LIB_PATH)/STM32F7xx_StdPeriph_Driver/src
|
||||
|
||||
# STM32F4 system source path
|
||||
SYS_DIR_F4=$(F4_LIB_PATH)/Device
|
||||
STARTUP_DIR_F4=$(F4_LIB_PATH)/Device/startup
|
||||
|
||||
# STM32F7 system source path
|
||||
SYS_DIR_F7=$(F7_LIB_PATH)/Device
|
||||
STARTUP_DIR_F7=$(F7_LIB_PATH)/Device/startup
|
||||
|
||||
# GNU ARM Embedded Toolchain
|
||||
CC=arm-none-eabi-gcc
|
||||
CXX=arm-none-eabi-g++
|
||||
LD=arm-none-eabi-ld
|
||||
AR=arm-none-eabi-ar
|
||||
AS=arm-none-eabi-as
|
||||
CP=arm-none-eabi-objcopy
|
||||
OD=arm-none-eabi-objdump
|
||||
NM=arm-none-eabi-nm
|
||||
SIZE=arm-none-eabi-size
|
||||
A2L=arm-none-eabi-addr2line
|
||||
|
||||
# "SystemRoot" is only defined in Windows
|
||||
ifdef SYSTEMROOT
|
||||
CLEANCMD=del /S *.o *.hex *.bin *.elf GitVersion.h
|
||||
MDDIRS=md $@
|
||||
else ifdef SystemRoot
|
||||
CLEANCMD=del /S *.o *.hex *.bin *.elf GitVersion.h
|
||||
MDDIRS=md $@
|
||||
else
|
||||
CLEANCMD=rm -f $(OBJ_F4) $(OBJ_F7) $(BINDIR)/*.hex $(BINDIR)/*.bin $(BINDIR)/*.elf GitVersion.h
|
||||
MDDIRS=mkdir $@
|
||||
endif
|
||||
|
||||
# Default reference oscillator frequencies
|
||||
ifndef $(OSC)
|
||||
ifeq ($(MAKECMDGOALS),pi)
|
||||
OSC=$(CLK_MMDVM_PI)
|
||||
else ifeq ($(MAKECMDGOALS),pi-f722)
|
||||
OSC=$(CLK_MMDVM_PI)
|
||||
else ifeq ($(MAKECMDGOALS),drcc_nqf)
|
||||
OSC=$(CLK_12MHZ)
|
||||
else
|
||||
OSC=$(CLK_NUCLEO)
|
||||
endif
|
||||
endif
|
||||
|
||||
# Build object lists
|
||||
CXXSRC=$(wildcard $(MMDVM_PATH)/*.cpp)
|
||||
CSRC_STD_F4=$(wildcard $(STD_LIB_F4)/*.c)
|
||||
SYS_F4=$(wildcard $(SYS_DIR_F4)/*.c)
|
||||
STARTUP_F4=$(wildcard $(STARTUP_DIR_F4)/*.c)
|
||||
CSRC_STD_F7=$(wildcard $(STD_LIB_F7)/*.c)
|
||||
SYS_F7=$(wildcard $(SYS_DIR_F7)/*.c)
|
||||
STARTUP_F7=$(wildcard $(STARTUP_DIR_F7)/*.c)
|
||||
OBJ_F4=$(CXXSRC:$(MMDVM_PATH)/%.cpp=$(OBJDIR_F4)/%.o) $(CSRC_STD_F4:$(STD_LIB_F4)/%.c=$(OBJDIR_F4)/%.o) $(SYS_F4:$(SYS_DIR_F4)/%.c=$(OBJDIR_F4)/%.o) $(STARTUP_F4:$(STARTUP_DIR_F4)/%.c=$(OBJDIR_F4)/%.o)
|
||||
OBJ_F7=$(CXXSRC:$(MMDVM_PATH)/%.cpp=$(OBJDIR_F7)/%.o) $(CSRC_STD_F7:$(STD_LIB_F7)/%.c=$(OBJDIR_F7)/%.o) $(SYS_F7:$(SYS_DIR_F7)/%.c=$(OBJDIR_F7)/%.o) $(STARTUP_F7:$(STARTUP_DIR_F7)/%.c=$(OBJDIR_F7)/%.o)
|
||||
|
||||
# MCU flags
|
||||
MCFLAGS_F4=-mcpu=cortex-m4 -mthumb -mlittle-endian -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb-interwork
|
||||
MCFLAGS_F7=-mcpu=cortex-m7 -mthumb -mlittle-endian -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mthumb-interwork
|
||||
|
||||
# Compile flags
|
||||
# STM32F4 Discovery board:
|
||||
DEFS_DIS=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F40_41xxx -DSTM32F4_DISCOVERY -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
# MMDVM-Pi board:
|
||||
DEFS_PI=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_PI -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
# MMDVM-F4M F0DEI board:
|
||||
DEFS_F4M=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_F4M -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
# STM32F4 Nucleo-64 F446RE board:
|
||||
DEFS_NUCLEO=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_NUCLEO -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
# STM32F7 Nucleo-144 F767ZI board:
|
||||
DEFS_NUCLEO_F767=-DUSE_HAL_DRIVER -DSTM32F767xx -DSTM32F7XX -DSTM32F7_NUCLEO -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
# MMDVM-Pi F722 board:
|
||||
DEFS_PI_F722=-DUSE_HAL_DRIVER -DSTM32F722xx -DSTM32F7XX -DSTM32F722_PI -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
# MMDVM-F7M F0DEI board:
|
||||
DEFS_F7M=-DUSE_HAL_DRIVER -DSTM32F722xx -DSTM32F7XX -DSTM32F722_F7M -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
# MMDVM_RPT_Hat F0DEI, DB9MAT, DF2ET board:
|
||||
DEFS_RPT_HAT=-DUSE_HAL_DRIVER -DSTM32F722xx -DSTM32F7XX -DSTM32F722_RPT_HAT -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
# RB STM32F4_DVM board:
|
||||
DEFS_DVM=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_DVM -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
# RB STM32F7 DVM board:
|
||||
DEFS_DVM722=-DUSE_HAL_DRIVER -DSTM32F722xx -DSTM32F7XX -DSTM32F7_DVM -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
# MMDVM_RPT_Hat BG4TGO, BG5HHP board:
|
||||
DEFS_RPT_HAT_TGO=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F40_41xxx -DSTM32F4_RPT_HAT_TGO -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
# DRCC_DVM BG7NQF board:
|
||||
DEFS_DRCC_DVM=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DDRCC_DVM -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
# WA0EDA F405 MTR2K, MASTR3 board:
|
||||
DEFS_EDA_405=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F40_41xxx -DSTM32F4_EDA_405 -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
# WA0EDA F446 MTR2K, MASTR3 board:
|
||||
DEFS_EDA_446=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_EDA_446 -DHSE_VALUE=$(OSC) -DMADEBYMAKEFILE
|
||||
|
||||
|
||||
# Build compiler flags
|
||||
CFLAGS_F4=-c $(MCFLAGS_F4) $(INCLUDES_F4)
|
||||
CXXFLAGS_F4=-c $(MCFLAGS_F4) $(INCLUDES_F4)
|
||||
CFLAGS_F7=-c $(MCFLAGS_F7) $(INCLUDES_F7)
|
||||
CXXFLAGS_F7=-c $(MCFLAGS_F7) $(INCLUDES_F7)
|
||||
|
||||
# Linker flags
|
||||
LDFLAGS_F4 =-T stm32f4xx_link.ld $(MCFLAGS_F4) --specs=nosys.specs $(INCLUDES_LIBS_F4)
|
||||
LDFLAGS_F767 =-T stm32f767_link.ld $(MCFLAGS_F7) --specs=nosys.specs $(INCLUDES_LIBS_F7)
|
||||
LDFLAGS_F722 =-T stm32f722_link.ld $(MCFLAGS_F7) --specs=nosys.specs $(INCLUDES_LIBS_F7)
|
||||
|
||||
# Common flags
|
||||
CFLAGS=-Os -ffunction-sections -fdata-sections -fno-builtin -Wno-implicit -DCUSTOM_NEW -DNO_EXCEPTIONS
|
||||
CXXFLAGS=-Os -fno-exceptions -ffunction-sections -fdata-sections -fno-builtin -fno-rtti -DCUSTOM_NEW -DNO_EXCEPTIONS
|
||||
LDFLAGS=-Os --specs=nano.specs -Wl,-Map=bin/mmdvm.map
|
||||
|
||||
# Build Rules
|
||||
.PHONY: all release dis pi pi-f722 f4m nucleo f767 dvm drcc_nqf clean
|
||||
|
||||
# Default target: Nucleo-64 F446RE board
|
||||
all: nucleo
|
||||
|
||||
pi: GitVersion.h
|
||||
pi: CFLAGS+=$(CFLAGS_F4) $(DEFS_PI)
|
||||
pi: CXXFLAGS+=$(CXXFLAGS_F4) $(DEFS_PI)
|
||||
pi: LDFLAGS+=$(LDFLAGS_F4)
|
||||
pi: release_f4
|
||||
|
||||
pi-f722: GitVersion.h
|
||||
pi-f722: CFLAGS+=$(CFLAGS_F7) $(DEFS_PI_F722)
|
||||
pi-f722: CXXFLAGS+=$(CXXFLAGS_F7) $(DEFS_PI_F722)
|
||||
pi-f722: LDFLAGS+=$(LDFLAGS_F722)
|
||||
pi-f722: release_f7
|
||||
|
||||
f4m: GitVersion.h
|
||||
f4m: CFLAGS+=$(CFLAGS_F4) $(DEFS_F4M)
|
||||
f4m: CXXFLAGS+=$(CXXFLAGS_F4) $(DEFS_F4M)
|
||||
f4m: LDFLAGS+=$(LDFLAGS_F4)
|
||||
f4m: release_f4
|
||||
|
||||
f7m: GitVersion.h
|
||||
f7m: CFLAGS+=$(CFLAGS_F7) $(DEFS_F7M)
|
||||
f7m: CXXFLAGS+=$(CXXFLAGS_F7) $(DEFS_F7M)
|
||||
f7m: LDFLAGS+=$(LDFLAGS_F722)
|
||||
f7m: release_f7
|
||||
|
||||
rpt_hat: GitVersion.h
|
||||
rpt_hat: CFLAGS+=$(CFLAGS_F7) $(DEFS_RPT_HAT)
|
||||
rpt_hat: CXXFLAGS+=$(CXXFLAGS_F7) $(DEFS_RPT_HAT)
|
||||
rpt_hat: LDFLAGS+=$(LDFLAGS_F722)
|
||||
rpt_hat: release_f7
|
||||
|
||||
rpt_hat_tgo: GitVersion.h
|
||||
rpt_hat_tgo: CFLAGS+=$(CFLAGS_F4) $(DEFS_RPT_HAT_TGO)
|
||||
rpt_hat_tgo: CXXFLAGS+=$(CXXFLAGS_F4) $(DEFS_RPT_HAT_TGO)
|
||||
rpt_hat_tgo: LDFLAGS+=$(LDFLAGS_F4)
|
||||
rpt_hat_tgo: release_f4
|
||||
|
||||
nucleo: GitVersion.h
|
||||
nucleo: CFLAGS+=$(CFLAGS_F4) $(DEFS_NUCLEO)
|
||||
nucleo: CXXFLAGS+=$(CXXFLAGS_F4) $(DEFS_NUCLEO)
|
||||
nucleo: LDFLAGS+=$(LDFLAGS_F4)
|
||||
nucleo: release_f4
|
||||
|
||||
dis: GitVersion.h
|
||||
dis: CFLAGS+=$(CFLAGS_F4) $(DEFS_DIS)
|
||||
dis: CXXFLAGS+=$(CXXFLAGS_F4) $(DEFS_DIS)
|
||||
dis: LDFLAGS+=$(LDFLAGS_F4)
|
||||
dis: release_f4
|
||||
|
||||
f767: GitVersion.h
|
||||
f767: CFLAGS+=$(CFLAGS_F7) $(DEFS_NUCLEO_F767)
|
||||
f767: CXXFLAGS+=$(CXXFLAGS_F7) $(DEFS_NUCLEO_F767)
|
||||
f767: LDFLAGS+=$(LDFLAGS_F767)
|
||||
f767: release_f7
|
||||
|
||||
dvm: GitVersion.h
|
||||
dvm: CFLAGS+=$(CFLAGS_F4) $(DEFS_DVM) -DDRCC_DVM_446
|
||||
dvm: CXXFLAGS+=$(CXXFLAGS_F4) $(DEFS_DVM) -DDRCC_DVM_446
|
||||
dvm: LDFLAGS+=$(LDFLAGS_F4)
|
||||
dvm: release_f4
|
||||
|
||||
dvm722: GitVersion.h
|
||||
dvm722: CFLAGS+=$(CFLAGS_F7) $(DEFS_DVM722) -DDRCC_DVM_722
|
||||
dvm722: CXXFLAGS+=$(CXXFLAGS_F7) $(DEFS_DVM722) -DDRCC_DVM_722
|
||||
dvm722: LDFLAGS+=$(LDFLAGS_F722)
|
||||
dvm722: release_f7
|
||||
|
||||
drcc_nqf: GitVersion.h
|
||||
drcc_nqf: CFLAGS+=$(CFLAGS_F4) $(DEFS_DRCC_DVM) -DDRCC_DVM_NQF
|
||||
drcc_nqf: CXXFLAGS+=$(CXXFLAGS_F4) $(DEFS_DRCC_DVM) -DDRCC_DVM_NQF
|
||||
drcc_nqf: LDFLAGS+=$(LDFLAGS_F4)
|
||||
drcc_nqf: release_f4
|
||||
|
||||
hhp446: GitVersion.h
|
||||
hhp446: CFLAGS+=$(CFLAGS_F4) $(DEFS_DRCC_DVM) -DDRCC_DVM_HHP446
|
||||
hhp446: CXXFLAGS+=$(CXXFLAGS_F4) $(DEFS_DRCC_DVM) -DDRCC_DVM_HHP446
|
||||
hhp446: LDFLAGS+=$(LDFLAGS_F4)
|
||||
hhp446: release_f4
|
||||
|
||||
eda405: GitVersion.h
|
||||
eda405: CFLAGS+=$(CFLAGS_F4) $(DEFS_EDA_405)
|
||||
eda405: CXXFLAGS+=$(CXXFLAGS_F4) $(DEFS_EDA_405)
|
||||
eda405: LDFLAGS+=$(LDFLAGS_F4)
|
||||
eda405: release_f4
|
||||
|
||||
eda446: GitVersion.h
|
||||
eda446: CFLAGS+=$(CFLAGS_F4) $(DEFS_EDA_446)
|
||||
eda446: CXXFLAGS+=$(CXXFLAGS_F4) $(DEFS_EDA_446)
|
||||
eda446: LDFLAGS+=$(LDFLAGS_F4)
|
||||
eda446: release_f4
|
||||
|
||||
release_f4: $(BINDIR)
|
||||
release_f4: $(OBJDIR_F4)
|
||||
release_f4: $(BINDIR)/$(BINHEX_F4)
|
||||
release_f4: $(BINDIR)/$(BINBIN_F4)
|
||||
|
||||
release_f7: $(BINDIR)
|
||||
release_f7: $(OBJDIR_F7)
|
||||
release_f7: $(BINDIR)/$(BINHEX_F7)
|
||||
release_f7: $(BINDIR)/$(BINBIN_F7)
|
||||
|
||||
$(BINDIR):
|
||||
$(MDDIRS)
|
||||
|
||||
$(OBJDIR_F4):
|
||||
$(MDDIRS)
|
||||
|
||||
$(OBJDIR_F7):
|
||||
$(MDDIRS)
|
||||
|
||||
$(BINDIR)/$(BINHEX_F4): $(BINDIR)/$(BINELF_F4)
|
||||
$(CP) -O ihex $< $@
|
||||
@echo "Objcopy from ELF to IHEX complete!\n"
|
||||
|
||||
$(BINDIR)/$(BINBIN_F4): $(BINDIR)/$(BINELF_F4)
|
||||
$(CP) -O binary $< $@
|
||||
@echo "Objcopy from ELF to BINARY complete!\n"
|
||||
|
||||
$(BINDIR)/$(BINELF_F4): $(OBJ_F4)
|
||||
$(CXX) $(OBJ_F4) $(LDFLAGS) -o $@
|
||||
@echo "Linking complete!\n"
|
||||
$(SIZE) $(BINDIR)/$(BINELF_F4)
|
||||
|
||||
$(BINDIR)/$(BINHEX_F7): $(BINDIR)/$(BINELF_F7)
|
||||
$(CP) -O ihex $< $@
|
||||
@echo "Objcopy from ELF to IHEX complete!\n"
|
||||
|
||||
$(BINDIR)/$(BINBIN_F7): $(BINDIR)/$(BINELF_F7)
|
||||
$(CP) -O binary $< $@
|
||||
@echo "Objcopy from ELF to BINARY complete!\n"
|
||||
|
||||
$(BINDIR)/$(BINELF_F7): $(OBJ_F7)
|
||||
$(CXX) $(OBJ_F7) $(LDFLAGS) -o $@
|
||||
@echo "Linking complete!\n"
|
||||
$(SIZE) $(BINDIR)/$(BINELF_F7)
|
||||
|
||||
$(OBJDIR_F4)/%.o: $(MMDVM_PATH)/%.cpp
|
||||
$(CXX) $(CXXFLAGS) $< -o $@
|
||||
@echo "Compiled "$<"!\n"
|
||||
|
||||
$(OBJDIR_F7)/%.o: $(MMDVM_PATH)/%.cpp
|
||||
$(CXX) $(CXXFLAGS) $< -o $@
|
||||
@echo "Compiled "$<"!\n"
|
||||
|
||||
$(OBJDIR_F4)/%.o: $(STD_LIB_F4)/%.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
@echo "Compiled "$<"!\n"
|
||||
|
||||
$(OBJDIR_F7)/%.o: $(STD_LIB_F7)/%.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
@echo "Compiled "$<"!\n"
|
||||
|
||||
$(OBJDIR_F4)/%.o: $(SYS_DIR_F4)/%.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
@echo "Compiled "$<"!\n"
|
||||
|
||||
$(OBJDIR_F4)/%.o: $(STARTUP_DIR_F4)/%.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
@echo "Compiled "$<"!\n"
|
||||
|
||||
$(OBJDIR_F7)/%.o: $(SYS_DIR_F7)/%.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
@echo "Compiled "$<"!\n"
|
||||
|
||||
$(OBJDIR_F7)/%.o: $(STARTUP_DIR_F7)/%.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
@echo "Compiled "$<"!\n"
|
||||
|
||||
clean:
|
||||
$(CLEANCMD)
|
||||
|
||||
deploy:
|
||||
ifneq ($(wildcard /usr/bin/openocd),)
|
||||
/usr/bin/openocd -f /usr/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/share/openocd/scripts/target/stm32f4x.cfg -c "program bin/$(BINELF_F4) verify reset exit"
|
||||
endif
|
||||
|
||||
ifneq ($(wildcard /usr/local/bin/openocd),)
|
||||
/usr/local/bin/openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/local/share/openocd/scripts/target/stm32f4x.cfg -c "program bin/$(BINELF_F4) verify reset exit"
|
||||
endif
|
||||
|
||||
ifneq ($(wildcard /opt/openocd/bin/openocd),)
|
||||
/opt/openocd/bin/openocd -f /opt/openocd/share/openocd/scripts/interface/stlink-v2-1.cfg -f /opt/openocd/share/openocd/scripts/target/stm32f4x.cfg -c "program bin/$(BINELF_F4) verify reset exit"
|
||||
endif
|
||||
|
||||
deploy-f7:
|
||||
ifneq ($(wildcard /usr/bin/openocd),)
|
||||
/usr/bin/openocd -f /usr/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/share/openocd/scripts/target/stm32f7x.cfg -c "program bin/$(BINELF_F7) verify reset exit"
|
||||
endif
|
||||
|
||||
ifneq ($(wildcard /usr/local/bin/openocd),)
|
||||
/usr/local/bin/openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/local/share/openocd/scripts/target/stm32f7x.cfg -c "program bin/$(BINELF_F7) verify reset exit"
|
||||
endif
|
||||
|
||||
ifneq ($(wildcard /opt/openocd/bin/openocd),)
|
||||
/opt/openocd/bin/openocd -f /opt/openocd/share/openocd/scripts/interface/stlink-v2-1.cfg -f /opt/openocd/share/openocd/scripts/target/stm32f7x.cfg -c "program bin/$(BINELF_F7) verify reset exit"
|
||||
endif
|
||||
|
||||
deploy-pi:
|
||||
ifneq ($(wildcard /usr/local/bin/stm32flash),)
|
||||
-/usr/local/bin/stm32flash -i 20,-21,21:-20,21 /dev/ttyAMA0
|
||||
/usr/local/bin/stm32flash -v -w bin/$(BINBIN_F4) -g 0x0 -R /dev/ttyAMA0
|
||||
endif
|
||||
|
||||
ifneq ($(wildcard /usr/bin/stm32flash),)
|
||||
-/usr/bin/stm32flash -i 20,-21,21:-20,21 /dev/ttyAMA0
|
||||
/usr/bin/stm32flash -v -w bin/$(BINBIN_F4) -g 0x0 -R /dev/ttyAMA0
|
||||
endif
|
||||
|
||||
deploy-f4m: deploy-pi
|
||||
deploy-dvm: deploy-pi
|
||||
deploy-eda405: deploy-pi
|
||||
deploy-eda446: deploy-pi
|
||||
|
||||
deploy-pi-f7:
|
||||
ifneq ($(wildcard /usr/local/bin/stm32flash),)
|
||||
-/usr/local/bin/stm32flash -i 20,-21,21:-20,21 /dev/ttyAMA0
|
||||
/usr/local/bin/stm32flash -v -w bin/$(BINBIN_F7) -g 0x0 -R /dev/ttyAMA0
|
||||
|
||||
else ifneq ($(wildcard /usr/bin/stm32flash),)
|
||||
-/usr/bin/stm32flash -i 20,-21,21:-20,21 /dev/ttyAMA0
|
||||
/usr/bin/stm32flash -v -w bin/$(BINBIN_F7) -g 0x0 -R /dev/ttyAMA0
|
||||
endif
|
||||
|
||||
deploy-f7m: deploy-pi-f7
|
||||
deploy-rpt_hat: deploy-pi-f7
|
||||
|
||||
# Export the current git version if the index file exists, else 000...
|
||||
GitVersion.h:
|
||||
ifdef SYSTEMROOT
|
||||
echo #define GITVERSION "0000000" > $@
|
||||
else ifdef SystemRoot
|
||||
echo #define GITVERSION "0000000" > $@
|
||||
else
|
||||
ifneq ("$(wildcard .git/index)","")
|
||||
echo "#define GITVERSION \"$(shell git rev-parse --short HEAD)\"" > $@
|
||||
else
|
||||
echo "#define GITVERSION \"0000000\"" > $@
|
||||
endif
|
||||
endif
|
||||
|
||||
flash_f4:
|
||||
@echo "flashing firmware..."
|
||||
st-flash write bin/$(BINBIN_F4) 0x8000000
|
||||
@@ -0,0 +1,189 @@
|
||||
#!/usr/bin/make
|
||||
# makefile for the arduino due (works with arduino IDE 1.6.12)
|
||||
#
|
||||
# The original file can be found at https://github.com/pauldreik/arduino-due-makefile
|
||||
#
|
||||
# USAGE: put this file in the same dir as your .ino file is.
|
||||
# configure the PORT variable and ADIR at the top of the file
|
||||
# to match your local configuration.
|
||||
# Type make upload to compile and upload.
|
||||
#
|
||||
|
||||
#user specific settings:
|
||||
#where to find the IDE
|
||||
ADIR:=$(HOME)/.arduino15
|
||||
#which serial port to use (add a file with SUBSYSTEMS=="usb",
|
||||
#ATTRS{product}=="Arduino Due Prog. Port", ATTRS{idProduct}=="003d",
|
||||
#ATTRS{idVendor}=="2341", SYMLINK+="arduino_due" in /etc/udev/rules.d/
|
||||
#to get this working). Do not prefix the port with /dev/, just take
|
||||
#the basename.
|
||||
PORT:=ttyACM0
|
||||
#if you want to verify the bossac upload, define this to -v
|
||||
VERIFY:=-v
|
||||
|
||||
|
||||
#end of user configuration.
|
||||
|
||||
|
||||
#then some general settings. They should not be necessary to modify.
|
||||
#CXX:=$(ADIR)/tools/g++_arm_none_eabi/bin/arm-none-eabi-g++
|
||||
CXX:=$(ADIR)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++
|
||||
#CC:=$(ADIR)/tools/g++_arm_none_eabi/bin/arm-none-eabi-gcc
|
||||
CC:=$(ADIR)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc
|
||||
OBJCOPY:=$(ADIR)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-objcopy
|
||||
|
||||
C:=$(CC)
|
||||
#SAM:=arduino/sam/
|
||||
SAM:=$(ADIR)/packages/arduino/hardware/sam/1.6.12
|
||||
#CMSIS:=arduino/sam/system/CMSIS/
|
||||
#LIBSAM:=arduino/sam/system/libsam
|
||||
TMPDIR:=$(PWD)/build
|
||||
AR:=$(ADIR)/tools/g++_arm_none_eabi/bin/arm-none-eabi-ar
|
||||
AR:=$(ADIR)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-ar
|
||||
|
||||
|
||||
#all these values are hard coded and should maybe be configured somehow else,
|
||||
#like olikraus does in his makefile.
|
||||
DEFINES:=-Dprintf=iprintf -DF_CPU=84000000 -DARDUINO=10611 -D__SAM3X8E__ -DUSB_PID=0x003e -DUSB_VID=0x2341 -DUSBCON \
|
||||
-DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM '-DUSB_MANUFACTURER="Arduino LLC"' '-DUSB_PRODUCT="Arduino Due"' \
|
||||
-DMADEBYMAKEFILE
|
||||
|
||||
INCLUDES:=-I$(SAM)/system/libsam -I$(SAM)/system/CMSIS/CMSIS/Include/ \
|
||||
-I$(SAM)/system/CMSIS/Device/ATMEL/ -I$(SAM)/cores/arduino \
|
||||
-I$(SAM)/variants/arduino_due_x
|
||||
|
||||
#also include the current dir for convenience
|
||||
INCLUDES += -I.
|
||||
|
||||
#compilation flags common to both c and c++
|
||||
COMMON_FLAGS:=-g -Os -w -ffunction-sections -fdata-sections -nostdlib \
|
||||
--param max-inline-insns-single=500 -mcpu=cortex-m3 -mthumb \
|
||||
-fno-threadsafe-statics
|
||||
#for compiling c (do not warn, this is not our code)
|
||||
CFLAGS:=$(COMMON_FLAGS) -std=gnu11
|
||||
#for compiling c++
|
||||
CXXFLAGS:=$(COMMON_FLAGS) -fno-rtti -fno-exceptions -std=gnu++11 -Wall -Wextra
|
||||
|
||||
#let the results be named after the project
|
||||
PROJNAME:=$(shell basename *.ino .ino)
|
||||
|
||||
#we will make a new mainfile from the ino file.
|
||||
NEWMAINFILE:=$(TMPDIR)/$(PROJNAME).ino.cpp
|
||||
|
||||
#our own sourcefiles is the (converted) ino file and any local cpp files
|
||||
MYSRCFILES:=$(NEWMAINFILE) $(shell ls *.cpp 2>/dev/null)
|
||||
MYOBJFILES:=$(addsuffix .o,$(addprefix $(TMPDIR)/,$(notdir $(MYSRCFILES))))
|
||||
|
||||
#These source files are the ones forming core.a
|
||||
CORESRCXX:=$(shell ls ${SAM}/cores/arduino/*.cpp ${SAM}/cores/arduino/USB/*.cpp ${SAM}/variants/arduino_due_x/variant.cpp)
|
||||
CORESRC:=$(shell ls ${SAM}/cores/arduino/*.c)
|
||||
|
||||
#hey this one is needed too: $(SAM)/cores/arduino/wiring_pulse_asm.S" add -x assembler-with-cpp
|
||||
#and this one: /1.6.11/cores/arduino/avr/dtostrf.c but it seems to work
|
||||
#anyway, probably because I do not use that functionality.
|
||||
|
||||
#convert the core source files to object files. assume no clashes.
|
||||
COREOBJSXX:=$(addprefix $(TMPDIR)/core/,$(notdir $(CORESRCXX)) )
|
||||
COREOBJSXX:=$(addsuffix .o,$(COREOBJSXX))
|
||||
COREOBJS:=$(addprefix $(TMPDIR)/core/,$(notdir $(CORESRC)) )
|
||||
COREOBJS:=$(addsuffix .o,$(COREOBJS))
|
||||
|
||||
default:
|
||||
@echo default rule, does nothing. Try make compile or make upload.
|
||||
|
||||
#This rule is good to just make sure stuff compiles, without having to wait
|
||||
#for bossac.
|
||||
compile: GitVersion.h $(TMPDIR)/$(PROJNAME).elf $(TMPDIR)/$(PROJNAME).bin
|
||||
|
||||
#This is a make rule template to create object files from the source files.
|
||||
# arg 1=src file
|
||||
# arg 2=object file
|
||||
# arg 3= XX if c++, empty if c
|
||||
define OBJ_template
|
||||
$(2): $(1)
|
||||
$(C$(3)) -MD -c $(C$(3)FLAGS) $(DEFINES) $(INCLUDES) $(1) -o $(2)
|
||||
endef
|
||||
#now invoke the template both for c++ sources
|
||||
$(foreach src,$(CORESRCXX), $(eval $(call OBJ_template,$(src),$(addsuffix .o,$(addprefix $(TMPDIR)/core/,$(notdir $(src)))),XX) ) )
|
||||
#...and for c sources:
|
||||
$(foreach src,$(CORESRC), $(eval $(call OBJ_template,$(src),$(addsuffix .o,$(addprefix $(TMPDIR)/core/,$(notdir $(src)))),) ) )
|
||||
|
||||
#and our own c++ sources
|
||||
$(foreach src,$(MYSRCFILES), $(eval $(call OBJ_template,$(src),$(addsuffix .o,$(addprefix $(TMPDIR)/,$(notdir $(src)))),XX) ) )
|
||||
|
||||
|
||||
clean:
|
||||
test ! -d $(TMPDIR) || rm -rf $(TMPDIR)
|
||||
$(RM) GitVersion.h
|
||||
|
||||
.PHONY: .FORCE upload default
|
||||
|
||||
$(TMPDIR):
|
||||
mkdir -p $(TMPDIR)
|
||||
|
||||
$(TMPDIR)/core:
|
||||
mkdir -p $(TMPDIR)/core
|
||||
|
||||
#creates the cpp file from the .ino file
|
||||
$(NEWMAINFILE): $(PROJNAME).ino
|
||||
cat $(SAM)/cores/arduino/main.cpp > $(NEWMAINFILE)
|
||||
cat $(PROJNAME).ino >> $(NEWMAINFILE)
|
||||
echo 'extern "C" void __cxa_pure_virtual() {while (true);}' >> $(NEWMAINFILE)
|
||||
|
||||
#include the dependencies for our own files
|
||||
-include $(MYOBJFILES:.o=.d)
|
||||
|
||||
#create the core library from the core objects. Do this EXACTLY as the
|
||||
#arduino IDE does it, seems *really* picky about this.
|
||||
#Sorry for the hard coding.
|
||||
$(TMPDIR)/core.a: $(TMPDIR)/core $(COREOBJS) $(COREOBJSXX)
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/wiring_shift.c.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/wiring_analog.c.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/itoa.c.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/cortex_handlers.c.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/hooks.c.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/wiring.c.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/WInterrupts.c.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/syscalls_sam3.c.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/iar_calls_sam3.c.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/wiring_digital.c.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/Print.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/USARTClass.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/WString.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/PluggableUSB.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/USBCore.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/CDC.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/wiring_pulse.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/UARTClass.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/main.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/new.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/watchdog.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/Stream.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/RingBuffer.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/IPAddress.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/Reset.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/WMath.cpp.o
|
||||
$(AR) rcs $(TMPDIR)/core.a $(TMPDIR)/core/variant.cpp.o
|
||||
|
||||
#link our own object files with core to form the elf file
|
||||
$(TMPDIR)/$(PROJNAME).elf: $(TMPDIR)/core.a $(TMPDIR)/core/syscalls_sam3.c.o $(MYOBJFILES)
|
||||
$(CC) -mcpu=cortex-m3 -mthumb -Os -Wl,--gc-sections -T$(SAM)/variants/arduino_due_x/linker_scripts/gcc/flash.ld -Wl,-Map,$(NEWMAINFILE).map -o $@ -L$(TMPDIR) -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group -u _sbrk -u link -u _close -u _fstat -u _isatty -u _lseek -u _read -u _write -u _exit -u kill -u _getpid $(MYOBJFILES) $(TMPDIR)/core/variant.cpp.o $(SAM)/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a $(SAM)/system/CMSIS/CMSIS/Lib/GCC/libarm_cortexM3l_math.a $(TMPDIR)/core.a -Wl,--end-group -lm -gcc
|
||||
|
||||
#copy from the hex to our bin file (why?)
|
||||
$(TMPDIR)/$(PROJNAME).bin: $(TMPDIR)/$(PROJNAME).elf
|
||||
$(OBJCOPY) -O binary $< $@
|
||||
|
||||
#upload to the arduino by first resetting it (stty) and the running bossac
|
||||
upload: compile
|
||||
stty -F /dev/$(PORT) cs8 1200 hupcl
|
||||
$(ADIR)/packages/arduino/tools/bossac/1.6.1-arduino/bossac -i --port=$(PORT) -U false -e -w $(VERIFY) -b $(TMPDIR)/$(PROJNAME).bin -R
|
||||
|
||||
# Export the current git version if the index file exists, else 000...
|
||||
GitVersion.h: .FORCE
|
||||
ifneq ("$(wildcard .git/index)","")
|
||||
echo "#define GITVERSION \"$(shell git rev-parse --short HEAD)\"" > $@
|
||||
else
|
||||
echo "#define GITVERSION \"0000000\"" > $@
|
||||
endif
|
||||
|
||||
.FORCE:
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
# The name for the project
|
||||
TARGET:=mmdvm
|
||||
|
||||
# The CPU architecture (will be used for -mcpu)
|
||||
MCPU:=cortex-m3
|
||||
MCU:=STM32F105xC
|
||||
|
||||
# The source files of the project
|
||||
CSRC:=
|
||||
CXXSRC:=$(wildcard *.cpp)
|
||||
|
||||
# Include directory for the system include files and system source file
|
||||
SYSDIR:=system_stm32f1xx
|
||||
SYSSRC:=$(SYSDIR)/system_stm32f1xx.c
|
||||
|
||||
# Other include directories
|
||||
INCDIR:=
|
||||
|
||||
# Definitions
|
||||
CDEFS:=
|
||||
CXXDEFS:=
|
||||
|
||||
# The name of the startup file which matches to the architecture (MCPU)
|
||||
STARTUP:=$(SYSDIR)/startup_stm32f105xc.S
|
||||
STARTUP_DEFS=
|
||||
|
||||
# Include directory for CMSIS
|
||||
CMSISDIR:=STM32F10X_Lib/CMSIS
|
||||
|
||||
# Libraries
|
||||
LIBDIR:=
|
||||
LIBS:=-larm_cortexM3l_math
|
||||
|
||||
# Name of the linker script
|
||||
LDSCRIPT:=$(SYSDIR)/gcc.ld
|
||||
|
||||
# Target objects and binaries directory
|
||||
OBJDIR:=obj
|
||||
BINDIR:=bin
|
||||
|
||||
# Port definition for programming via bootloader (using stm32flash)
|
||||
BL_PORT:=ttyUSB0
|
||||
|
||||
|
||||
|
||||
# Internal Variables
|
||||
ELF:=$(BINDIR)/$(TARGET).elf
|
||||
HEX:=$(BINDIR)/$(TARGET).hex
|
||||
DIS:=$(BINDIR)/$(TARGET).dis
|
||||
MAP:=$(BINDIR)/$(TARGET).map
|
||||
OBJ:=$(CSRC:%.c=$(OBJDIR)/%.o) $(CXXSRC:%.cpp=$(OBJDIR)/%.o)
|
||||
OBJ+=$(SYSSRC:$(SYSDIR)/%.c=$(OBJDIR)/%.o) $(STARTUP:$(SYSDIR)/%.S=$(OBJDIR)/%.o)
|
||||
|
||||
# Replace standard build tools by arm tools
|
||||
CC:=arm-none-eabi-gcc
|
||||
CXX:=arm-none-eabi-g++
|
||||
AS:=arm-none-eabi-gcc
|
||||
LD:=arm-none-eabi-g++
|
||||
OBJCOPY:=arm-none-eabi-objcopy
|
||||
OBJDUMP:=arm-none-eabi-objdump
|
||||
SIZE:=arm-none-eabi-size
|
||||
|
||||
# Common flags
|
||||
COMMON_FLAGS =-mthumb -mlittle-endian -mcpu=$(MCPU)
|
||||
COMMON_FLAGS+= -Wall
|
||||
COMMON_FLAGS+= -I. -I$(CMSISDIR)/Include -I$(CMSISDIR)/Device/ST/STM32F1xx/Include -I$(SYSDIR)
|
||||
COMMON_FLAGS+= $(addprefix -I,$(INCDIR))
|
||||
COMMON_FLAGS+= -D$(MCU) -DMADEBYMAKEFILE -DSTM32F1
|
||||
COMMON_FLAGS+= -Os -flto -ffunction-sections -fdata-sections
|
||||
COMMON_FLAGS+= -g
|
||||
# Assembler flags
|
||||
ASFLAGS:=$(COMMON_FLAGS)
|
||||
# C flags
|
||||
CFLAGS:=$(COMMON_FLAGS) $(addprefix -D,$(CDEFS))
|
||||
CFLAGS+= -std=gnu11 -nostdlib
|
||||
# CXX flags
|
||||
CXXFLAGS:=$(COMMON_FLAGS) $(addprefix -D,$(CXXDEFS))
|
||||
CXXFLAGS+= -nostdlib -fno-exceptions -fno-rtti
|
||||
# LD flags
|
||||
LDFLAGS:=$(COMMON_FLAGS) -Wl,--gc-sections -Wl,-Map=$(MAP) -Wl,--no-wchar-size-warning
|
||||
LDFLAGS+= --specs=nosys.specs --specs=nano.specs
|
||||
LDFLAGS+= -L$(CMSISDIR)/Lib/GCC/ $(addprefix -L,$(LIBDIR))
|
||||
LDLIBS:=-T$(LDSCRIPT) $(LIBS)
|
||||
|
||||
# Dependecies
|
||||
DEPENDS:=$(CSRC:%.c=$(OBJDIR)/%.d) $(CXXSRC:%.cpp=$(OBJDIR)/%.d)
|
||||
|
||||
|
||||
# Additional Suffixes
|
||||
.SUFFIXES: .elf .hex
|
||||
|
||||
# Targets
|
||||
.PHONY: all
|
||||
all: GitVersion.h $(DIS) $(HEX)
|
||||
$(SIZE) $(ELF)
|
||||
|
||||
.PHONY: program
|
||||
program: $(HEX) $(ELF)
|
||||
openocd -f openocd.cfg \
|
||||
-c "program $(HEX) verify reset exit"
|
||||
$(SIZE) $(ELF)
|
||||
|
||||
.PHONY: program_bl
|
||||
program_bl: $(HEX) $(ELF)
|
||||
stm32flash -w $(HEX) -v /dev/$(BL_PORT)
|
||||
$(SIZE) $(ELF)
|
||||
|
||||
.PHONY: run
|
||||
run: $(HEX) $(ELF)
|
||||
openocd -f openocd.cfg \
|
||||
-c "init" -c "reset" -c "exit"
|
||||
|
||||
.PHONY: debug
|
||||
debug: $(ELF)
|
||||
./debug.sh $(ELF)
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
$(RM) $(OBJ) $(HEX) $(ELF) $(DIS) $(MAP) $(DEPENDS) GitVersion.h
|
||||
|
||||
# implicit rules
|
||||
.elf.hex:
|
||||
$(OBJCOPY) -O ihex $< $@
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
$(CC) -MMD $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
$(CXX) -MMD $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/%.o: $(SYSDIR)/%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/%.o: $(SYSDIR)/%.S
|
||||
$(AS) $(ASFLAGS) -c $< -o $@
|
||||
|
||||
# explicit rules
|
||||
$(OBJDIR):
|
||||
mkdir -p $(OBJDIR)
|
||||
|
||||
$(BINDIR):
|
||||
mkdir -p $(BINDIR)
|
||||
|
||||
$(ELF): $(OBJDIR) $(BINDIR) $(OBJ)
|
||||
$(LD) $(OBJ) $(LDFLAGS) $(LDLIBS) -o $@
|
||||
|
||||
$(DIS): $(ELF)
|
||||
$(OBJDUMP) -S $< > $@
|
||||
|
||||
# include dependecies
|
||||
-include $(DEPENDS)
|
||||
|
||||
# Export the current git version if the index file exists, else 000...
|
||||
GitVersion.h:
|
||||
ifdef SYSTEMROOT
|
||||
echo #define GITVERSION "0000000" > $@
|
||||
else ifdef SystemRoot
|
||||
echo #define GITVERSION "0000000" > $@
|
||||
else
|
||||
ifneq ("$(wildcard .git/index)","")
|
||||
echo "#define GITVERSION \"$(shell git rev-parse --short HEAD)\"" > $@
|
||||
else
|
||||
echo "#define GITVERSION \"0000000\"" > $@
|
||||
endif
|
||||
endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user