From 3cdcbeea3e2891f4a10c79b272da144f37ff24f3 Mon Sep 17 00:00:00 2001 From: Dave Hibberd Date: Tue, 12 Sep 2023 21:38:15 +0100 Subject: New upstream version 0.67 --- LinuxBits.c | 311 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 LinuxBits.c (limited to 'LinuxBits.c') diff --git a/LinuxBits.c b/LinuxBits.c new file mode 100644 index 0000000..75cb84b --- /dev/null +++ b/LinuxBits.c @@ -0,0 +1,311 @@ +/* +Copyright (C) 2019-2020 Andrei Kopanchuk UZ7HO + +This file is part of QtSoundModem + +QtSoundModem 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 3 of the License, or +(at your option) any later version. + +QtSoundModem 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 QtSoundModem. If not, see http://www.gnu.org/licenses + +*/ + +//#define TXSILENCE + +// UZ7HO Soundmodem Port by John Wiseman G8BPQ +// +// Audio interface Routine + +// Passes audio samples to/from the sound interface + +// As this is platform specific it also has the main() routine, which does +// platform specific initialisation before calling ardopmain() + +// This is ALSASound.c for Linux +// Windows Version is Waveout.c + + + + +void gpioSetMode(unsigned gpio, unsigned mode); +void gpioWrite(unsigned gpio, unsigned level); +int _memicmp(unsigned char *a, unsigned char *b, int n); +int stricmp(const unsigned char * pStr1, const unsigned char *pStr2); +int gpioInitialise(void); + +void Sleep(int mS) +{ + usleep(mS * 1000); + return; +} + + + + +// GPIO access stuff for PTT on PI + +#ifdef __ARM_ARCH + +/* + tiny_gpio.c + 2016-04-30 + Public Domain +*/ +#include +#include +#include +#include +#include +#include +#include +#include + +#define GPSET0 7 +#define GPSET1 8 + +#define GPCLR0 10 +#define GPCLR1 11 + +#define GPLEV0 13 +#define GPLEV1 14 + +#define GPPUD 37 +#define GPPUDCLK0 38 +#define GPPUDCLK1 39 + +unsigned piModel; +unsigned piRev; + +static volatile uint32_t *gpioReg = MAP_FAILED; + +#define PI_BANK (gpio>>5) +#define PI_BIT (1<<(gpio&0x1F)) + +/* gpio modes. */ + +// PTT via GPIO code + +#ifdef __ARM_ARCH + +#define PI_INPUT 0 +#define PI_OUTPUT 1 +#define PI_ALT0 4 +#define PI_ALT1 5 +#define PI_ALT2 6 +#define PI_ALT3 7 +#define PI_ALT4 3 +#define PI_ALT5 2 + +// Set GPIO pin as output and set low + +void SetupGPIOPTT() +{ + +} +#endif + + + +void gpioSetMode(unsigned gpio, unsigned mode) +{ + int reg, shift; + + reg = gpio/10; + shift = (gpio%10) * 3; + + gpioReg[reg] = (gpioReg[reg] & ~(7<> shift) & 7; +} + +/* Values for pull-ups/downs off, pull-down and pull-up. */ + +#define PI_PUD_OFF 0 +#define PI_PUD_DOWN 1 +#define PI_PUD_UP 2 + +void gpioSetPullUpDown(unsigned gpio, unsigned pud) +{ + *(gpioReg + GPPUD) = pud; + + usleep(20); + + *(gpioReg + GPPUDCLK0 + PI_BANK) = PI_BIT; + + usleep(20); + + *(gpioReg + GPPUD) = 0; + + *(gpioReg + GPPUDCLK0 + PI_BANK) = 0; +} + +int gpioRead(unsigned gpio) +{ + if ((*(gpioReg + GPLEV0 + PI_BANK) & PI_BIT) != 0) return 1; + else return 0; +} +void gpioWrite(unsigned gpio, unsigned level) +{ + if (level == 0) + *(gpioReg + GPCLR0 + PI_BANK) = PI_BIT; + else + *(gpioReg + GPSET0 + PI_BANK) = PI_BIT; +} + +void gpioTrigger(unsigned gpio, unsigned pulseLen, unsigned level) +{ + if (level == 0) *(gpioReg + GPCLR0 + PI_BANK) = PI_BIT; + else *(gpioReg + GPSET0 + PI_BANK) = PI_BIT; + + usleep(pulseLen); + + if (level != 0) *(gpioReg + GPCLR0 + PI_BANK) = PI_BIT; + else *(gpioReg + GPSET0 + PI_BANK) = PI_BIT; +} + +/* Bit (1<