2017-02-01 05:33:31 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2015, 2016 by Jonathan Naylor G4KLX
|
|
|
|
|
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
|
|
|
|
|
*
|
|
|
|
|
* 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(ARDUINO)
|
|
|
|
|
|
|
|
|
|
#if defined (__STM32F1__)
|
|
|
|
|
|
|
|
|
|
// STM32F1 pin definitions, using STM32duino
|
2017-02-15 22:18:10 +01:00
|
|
|
|
|
|
|
|
#if defined(PI_HAT_7021_REV_02)
|
|
|
|
|
|
|
|
|
|
#define PIN_SCLK PB4
|
2017-02-16 13:15:29 +01:00
|
|
|
#define PIN_SREAD PB5
|
|
|
|
|
#define PIN_SDATA PB6
|
2017-02-15 22:18:10 +01:00
|
|
|
#define PIN_SLE PB7
|
|
|
|
|
#define PIN_CE PC14
|
|
|
|
|
#define PIN_RXD PB3
|
|
|
|
|
#define PIN_TXD PA15
|
|
|
|
|
#define PIN_CLKOUT PA14
|
|
|
|
|
#define PIN_LED PC13
|
|
|
|
|
#define PIN_DEB PA11
|
|
|
|
|
#define PIN_DSTAR_LED PB14
|
|
|
|
|
#define PIN_DMR_LED PB15
|
|
|
|
|
#define PIN_YSF_LED PA13
|
|
|
|
|
#define PIN_P25_LED PA12
|
|
|
|
|
#define PIN_PTT_LED PB12
|
|
|
|
|
#define PIN_COS_LED PB13
|
|
|
|
|
|
2017-03-15 01:17:33 +01:00
|
|
|
#elif defined(PI_HAT_7021_REV_03)
|
|
|
|
|
|
|
|
|
|
#define PIN_SCLK PB5
|
|
|
|
|
#define PIN_SREAD PB6
|
|
|
|
|
#define PIN_SDATA PB7
|
|
|
|
|
#define PIN_SLE PB8
|
|
|
|
|
#define PIN_CE PC14
|
|
|
|
|
#define PIN_RXD PB4
|
|
|
|
|
#define PIN_TXD PB3
|
|
|
|
|
#define PIN_CLKOUT PA15
|
|
|
|
|
#define PIN_LED PC13
|
|
|
|
|
#define PIN_DEB PB9
|
|
|
|
|
#define PIN_DSTAR_LED PB12
|
|
|
|
|
#define PIN_DMR_LED PB13
|
|
|
|
|
#define PIN_YSF_LED PB1
|
|
|
|
|
#define PIN_P25_LED PB0
|
|
|
|
|
#define PIN_PTT_LED PB14
|
|
|
|
|
#define PIN_COS_LED PB15
|
|
|
|
|
|
|
|
|
|
#elif defined(ADF7021_CARRIER_BOARD)
|
2017-02-15 22:18:10 +01:00
|
|
|
|
2017-02-01 05:33:31 +01:00
|
|
|
#define PIN_SCLK PB5
|
|
|
|
|
#define PIN_SREAD PB7
|
|
|
|
|
#define PIN_SDATA PB6
|
|
|
|
|
#define PIN_SLE PB8
|
2017-02-14 12:49:22 +01:00
|
|
|
#define PIN_CE PC14
|
2017-02-01 05:33:31 +01:00
|
|
|
#define PIN_RXD PB4
|
|
|
|
|
#define PIN_TXD PB3
|
2017-02-09 02:36:33 +01:00
|
|
|
#define PIN_CLKOUT PA15
|
2017-02-01 05:33:31 +01:00
|
|
|
#define PIN_LED PC13
|
|
|
|
|
#define PIN_DEB PB9
|
|
|
|
|
#define PIN_DSTAR_LED PB12
|
|
|
|
|
#define PIN_DMR_LED PB13
|
|
|
|
|
#define PIN_YSF_LED PB1
|
|
|
|
|
#define PIN_P25_LED PB0
|
|
|
|
|
#define PIN_PTT_LED PB14
|
|
|
|
|
#define PIN_COS_LED PB15
|
|
|
|
|
|
2017-02-15 22:18:10 +01:00
|
|
|
#else
|
|
|
|
|
#error "Either PI_HAT_7021_REV_02, PI_HAT_7021_REV_03, or ADF7021_CARRIER_BOARD need to be defined"
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-02-01 05:33:31 +01:00
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
// Arduino pin definitions (Due and Zero)
|
|
|
|
|
#define PIN_SCLK 3
|
|
|
|
|
#define PIN_SDATA 4 // 2 in Arduino Zero Pro
|
|
|
|
|
#define PIN_SREAD 5
|
|
|
|
|
#define PIN_SLE 6
|
2017-02-14 12:49:22 +01:00
|
|
|
#define PIN_CE 12
|
2017-02-01 05:33:31 +01:00
|
|
|
#define PIN_RXD 7
|
|
|
|
|
#define PIN_TXD 8
|
2017-02-09 02:36:33 +01:00
|
|
|
#define PIN_CLKOUT 2 // 4 in Arduino Zero Pro
|
2017-02-01 05:33:31 +01:00
|
|
|
#define PIN_LED 13
|
|
|
|
|
#define PIN_DEB 11
|
|
|
|
|
#define PIN_DSTAR_LED 14
|
|
|
|
|
#define PIN_DMR_LED 15
|
|
|
|
|
#define PIN_YSF_LED 16
|
|
|
|
|
#define PIN_P25_LED 17
|
|
|
|
|
#define PIN_PTT_LED 9
|
|
|
|
|
#define PIN_COS_LED 10
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
void EXT_IRQHandler(void) {
|
|
|
|
|
io.interrupt();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CIO::delay_rx() {
|
2017-02-07 17:24:03 +01:00
|
|
|
#if defined (__STM32F1__)
|
|
|
|
|
delayMicroseconds(290);
|
|
|
|
|
#else
|
|
|
|
|
delayMicroseconds(150);
|
|
|
|
|
#endif
|
2017-02-01 05:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
2017-02-02 05:31:33 +01:00
|
|
|
void CIO::dlybit(void)
|
|
|
|
|
{
|
|
|
|
|
delayMicroseconds(1);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 05:33:31 +01:00
|
|
|
void CIO::Init()
|
|
|
|
|
{
|
2017-02-15 22:18:10 +01:00
|
|
|
#if defined (__STM32F1__)
|
|
|
|
|
|
|
|
|
|
#if defined(PI_HAT_7021_REV_02)
|
|
|
|
|
afio_cfg_debug_ports(AFIO_DEBUG_NONE);
|
|
|
|
|
#elif defined(PI_HAT_7021_REV_03) || defined(ADF7021_CARRIER_BOARD)
|
2017-02-01 05:33:31 +01:00
|
|
|
afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY);
|
2017-02-15 22:18:10 +01:00
|
|
|
#endif
|
|
|
|
|
|
2017-02-01 05:33:31 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
pinMode(PIN_SCLK, OUTPUT);
|
|
|
|
|
pinMode(PIN_SDATA, OUTPUT);
|
2017-02-10 18:03:14 +01:00
|
|
|
pinMode(PIN_SREAD, INPUT);
|
2017-02-01 05:33:31 +01:00
|
|
|
pinMode(PIN_SLE, OUTPUT);
|
2017-02-14 12:49:22 +01:00
|
|
|
pinMode(PIN_CE, OUTPUT);
|
2017-02-01 05:33:31 +01:00
|
|
|
pinMode(PIN_RXD, INPUT);
|
2017-02-09 02:36:33 +01:00
|
|
|
pinMode(PIN_CLKOUT, INPUT);
|
2017-02-01 05:33:31 +01:00
|
|
|
pinMode(PIN_LED, OUTPUT);
|
|
|
|
|
pinMode(PIN_DEB, OUTPUT);
|
|
|
|
|
pinMode(PIN_DSTAR_LED, OUTPUT);
|
|
|
|
|
pinMode(PIN_DMR_LED, OUTPUT);
|
|
|
|
|
pinMode(PIN_YSF_LED, OUTPUT);
|
|
|
|
|
pinMode(PIN_P25_LED, OUTPUT);
|
|
|
|
|
pinMode(PIN_PTT_LED, OUTPUT);
|
|
|
|
|
pinMode(PIN_COS_LED, OUTPUT);
|
2017-02-09 02:36:33 +01:00
|
|
|
|
|
|
|
|
#if defined(BIDIR_DATA_PIN)
|
|
|
|
|
pinMode(PIN_TXD, INPUT);
|
|
|
|
|
#else
|
|
|
|
|
pinMode(PIN_TXD, OUTPUT);
|
|
|
|
|
#endif
|
2017-02-03 02:08:59 +01:00
|
|
|
|
2017-02-01 05:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
2017-02-03 02:08:59 +01:00
|
|
|
void CIO::startInt()
|
2017-02-01 05:33:31 +01:00
|
|
|
{
|
2017-02-09 02:36:33 +01:00
|
|
|
#if defined(BIDIR_DATA_PIN)
|
|
|
|
|
|
|
|
|
|
// TXD pin is TxRxCLK of ADF7021, standard TX/RX data interface
|
|
|
|
|
#if defined (__STM32F1__)
|
2017-03-28 07:29:02 +02:00
|
|
|
attachInterrupt(PIN_TXD, EXT_IRQHandler, CHANGE);
|
2017-02-09 02:36:33 +01:00
|
|
|
#else
|
2017-03-28 07:29:02 +02:00
|
|
|
attachInterrupt(digitalPinToInterrupt(PIN_TXD), EXT_IRQHandler, CHANGE);
|
2017-02-09 02:36:33 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
2017-02-01 05:33:31 +01:00
|
|
|
#if defined (__STM32F1__)
|
2017-03-28 07:29:02 +02:00
|
|
|
attachInterrupt(PIN_CLKOUT, EXT_IRQHandler, CHANGE);
|
2017-02-01 05:33:31 +01:00
|
|
|
#else
|
2017-03-28 07:29:02 +02:00
|
|
|
attachInterrupt(digitalPinToInterrupt(PIN_CLKOUT), EXT_IRQHandler, CHANGE);
|
2017-02-01 05:33:31 +01:00
|
|
|
#endif
|
2017-02-09 02:36:33 +01:00
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if defined(BIDIR_DATA_PIN)
|
|
|
|
|
// RXD pin is bidirectional in standard interfaces
|
|
|
|
|
void CIO::Data_dir_out(bool dir)
|
|
|
|
|
{
|
|
|
|
|
if(dir)
|
|
|
|
|
pinMode(PIN_RXD, OUTPUT);
|
|
|
|
|
else
|
|
|
|
|
pinMode(PIN_RXD, INPUT);
|
2017-02-01 05:33:31 +01:00
|
|
|
}
|
2017-02-09 02:36:33 +01:00
|
|
|
#endif
|
2017-02-01 05:33:31 +01:00
|
|
|
|
|
|
|
|
void CIO::SCLK_pin(bool on)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(PIN_SCLK, on ? HIGH : LOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CIO::SDATA_pin(bool on)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(PIN_SDATA, on ? HIGH : LOW);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-10 18:03:14 +01:00
|
|
|
bool CIO::SREAD_pin()
|
|
|
|
|
{
|
|
|
|
|
return digitalRead(PIN_SREAD) == HIGH;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 05:33:31 +01:00
|
|
|
void CIO::SLE_pin(bool on)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(PIN_SLE, on ? HIGH : LOW);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-14 12:49:22 +01:00
|
|
|
void CIO::CE_pin(bool on)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(PIN_CE, on ? HIGH : LOW);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 05:33:31 +01:00
|
|
|
bool CIO::RXD_pin()
|
|
|
|
|
{
|
|
|
|
|
return digitalRead(PIN_RXD) == HIGH;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-28 07:29:02 +02:00
|
|
|
bool CIO::CLK_pin()
|
|
|
|
|
{
|
|
|
|
|
return digitalRead(PIN_TXD) == HIGH;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-09 02:36:33 +01:00
|
|
|
#if defined(BIDIR_DATA_PIN)
|
|
|
|
|
void CIO::RXD_pin_write(bool on)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(PIN_RXD, on ? HIGH : LOW);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-02-01 05:33:31 +01:00
|
|
|
void CIO::TXD_pin(bool on)
|
|
|
|
|
{
|
2017-03-28 07:29:02 +02:00
|
|
|
#if defined(BIDIR_DATA_PIN)
|
2017-02-01 05:33:31 +01:00
|
|
|
digitalWrite(PIN_TXD, on ? HIGH : LOW);
|
2017-03-28 07:29:02 +02:00
|
|
|
#else
|
|
|
|
|
digitalWrite(PIN_CLKOUT, on ? HIGH : LOW);
|
|
|
|
|
#endif
|
2017-02-01 05:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CIO::LED_pin(bool on)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(PIN_LED, on ? HIGH : LOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CIO::DEB_pin(bool on)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(PIN_DEB, on ? HIGH : LOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CIO::DSTAR_pin(bool on)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(PIN_DSTAR_LED, on ? HIGH : LOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CIO::DMR_pin(bool on)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(PIN_DMR_LED, on ? HIGH : LOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CIO::YSF_pin(bool on)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(PIN_YSF_LED, on ? HIGH : LOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CIO::P25_pin(bool on)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(PIN_P25_LED, on ? HIGH : LOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CIO::PTT_pin(bool on)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(PIN_PTT_LED, on ? HIGH : LOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CIO::COS_pin(bool on)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(PIN_COS_LED, on ? HIGH : LOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|