diff --git a/meson.build b/meson.build index 647642d9..4782d0ba 100644 --- a/meson.build +++ b/meson.build @@ -185,7 +185,8 @@ gdx_src = ['platform/targets/GDx/platform.c', 'platform/drivers/keyboard/keyboard_GDx.c', 'platform/drivers/audio/audio_GDx.c', 'platform/drivers/SPI/spi_custom.c', - 'platform/drivers/SPI/spi_bitbang.c'] + 'platform/drivers/SPI/spi_bitbang.c', + 'platform/drivers/SPI/spi_mk22.c'] gdx_inc = ['platform/targets/GDx'] diff --git a/platform/drivers/baseband/HR_C6000_GDx.cpp b/platform/drivers/baseband/HR_C6000_GDx.cpp index 54a8faef..4afb1a0b 100644 --- a/platform/drivers/baseband/HR_C6000_GDx.cpp +++ b/platform/drivers/baseband/HR_C6000_GDx.cpp @@ -162,54 +162,3 @@ void HR_Cx000< M >::startAnalogTx(const TxAudioSource source, const FmConfig cfg (void) cfg; } template< class M > void HR_Cx000< M >::stopAnalogTx() { } - -/* - * SPI interface driver - */ -template< class M > -void HR_Cx000< M >::uSpi_init() -{ - gpio_setMode(DMR_CS, OUTPUT); - gpio_setMode(DMR_CLK, OUTPUT | ALTERNATE_FUNC(2)); - gpio_setMode(DMR_MOSI, OUTPUT | ALTERNATE_FUNC(2)); - gpio_setMode(DMR_MISO, INPUT | ALTERNATE_FUNC(2)); - - SIM->SCGC6 |= SIM_SCGC6_SPI0_MASK; - - SPI0->MCR &= ~SPI_MCR_MDIS_MASK; // Enable the SPI0 module - SPI0->MCR |= SPI_MCR_MSTR_MASK // Master mode - | SPI_MCR_PCSIS_MASK // CS high when inactive - | SPI_MCR_DIS_RXF_MASK // Disable RX FIFO - | SPI_MCR_DIS_TXF_MASK // Disable TX FIFO - | SPI_MCR_HALT_MASK; // Stop transfers - - SPI0->CTAR[0] = SPI_CTAR_FMSZ(7) // 8bit frame size - | SPI_CTAR_CPHA_MASK // CPHA = 1 - | SPI_CTAR_PBR(2) // CLK prescaler divide by 5 - | SPI_CTAR_BR(3) // CLK scaler divide by 8 - | SPI_CTAR_PCSSCK(1) - | SPI_CTAR_PASC(1) - | SPI_CTAR_CSSCK(4) - | SPI_CTAR_ASC(4); -} - -template< class M > -uint8_t HR_Cx000< M >::uSpi_sendRecv(const uint8_t value) -{ - SPI0->MCR &= ~SPI_MCR_HALT_MASK; // Start transfer - - SPI0->MCR |= SPI_MCR_CLR_TXF_MASK | SPI_MCR_CLR_RXF_MASK; - - while((SPI0->SR & SPI_SR_TFFF_MASK) == 0) ; - - SPI0->PUSHR = SPI_PUSHR_EOQ_MASK | value; - - SPI0->SR |= SPI_SR_TFFF_MASK; - - while((SPI0->SR & SPI_SR_RFDF_MASK) == 0) ; - SPI0->SR |= SPI_SR_RFDF_MASK; - - SPI0->MCR |= SPI_MCR_HALT_MASK; // Start transfer - - return SPI0->POPR; -} diff --git a/platform/drivers/baseband/radio_GDx.cpp b/platform/drivers/baseband/radio_GDx.cpp index 62681190..59175731 100644 --- a/platform/drivers/baseband/radio_GDx.cpp +++ b/platform/drivers/baseband/radio_GDx.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include "radioUtils.h" @@ -38,7 +39,7 @@ static uint16_t apcVoltage = 0; // APC voltage for TX output po static enum opstatus radioStatus; // Current operating status -static HR_C6000& C6000 = HR_C6000::instance(); // HR_C5000 driver +static HR_C6000 C6000(&c6000_spi, { DMR_CS }); // HR_C6000 driver static AT1846S& at1846s = AT1846S::instance(); // AT1846S driver void radio_init(const rtxStatus_t *rtxState) @@ -64,6 +65,11 @@ void radio_init(const rtxStatus_t *rtxState) gpio_clearPin(RX_AUDIO_MUX); // Audio out to HR_C6000 gpio_clearPin(TX_AUDIO_MUX); // Audio in to microphone + gpio_setMode(DMR_CLK, OUTPUT | ALTERNATE_FUNC(2)); + gpio_setMode(DMR_MOSI, OUTPUT | ALTERNATE_FUNC(2)); + gpio_setMode(DMR_MISO, INPUT | ALTERNATE_FUNC(2)); + spiMk22_init(&c6000_spi, 2, 3, SPI_FLAG_CPHA); + /* * Enable and configure DAC for PA drive control */ diff --git a/platform/targets/GDx/hwconfig.c b/platform/targets/GDx/hwconfig.c index 495f9395..e6b0975d 100644 --- a/platform/targets/GDx/hwconfig.c +++ b/platform/targets/GDx/hwconfig.c @@ -20,6 +20,7 @@ #include #include +#include #include static const struct spiConfig spiFlashCfg = @@ -32,3 +33,4 @@ static const struct spiConfig spiFlashCfg = }; SPI_BITBANG_DEVICE_DEFINE(nvm_spi, spiFlashCfg, NULL) +SPI_MK22_DEVICE_DEFINE(c6000_spi, SPI0, NULL) diff --git a/platform/targets/GDx/hwconfig.h b/platform/targets/GDx/hwconfig.h index d1fdf61a..17104afb 100644 --- a/platform/targets/GDx/hwconfig.h +++ b/platform/targets/GDx/hwconfig.h @@ -34,6 +34,7 @@ extern "C" { #endif extern const struct spiCustomDevice nvm_spi; +extern const struct spiDevice c6000_spi; /* Screen dimensions */ #define CONFIG_SCREEN_WIDTH 128 diff --git a/platform/targets/GDx/pinmap_DM1801.h b/platform/targets/GDx/pinmap_DM1801.h index 2ed3bda5..e1bd8f1f 100644 --- a/platform/targets/GDx/pinmap_DM1801.h +++ b/platform/targets/GDx/pinmap_DM1801.h @@ -79,7 +79,7 @@ /* HR_C6000 control interface */ #define DMR_RESET GPIOE,2 #define DMR_SLEEP GPIOE,3 -#define DMR_CS GPIOD,0 +#define DMR_CS &GpioD,0 #define DMR_CLK GPIOD,1 #define DMR_MOSI GPIOD,2 #define DMR_MISO GPIOD,3 diff --git a/platform/targets/GDx/pinmap_GD77.h b/platform/targets/GDx/pinmap_GD77.h index cb1cabe2..b3df082a 100644 --- a/platform/targets/GDx/pinmap_GD77.h +++ b/platform/targets/GDx/pinmap_GD77.h @@ -79,7 +79,7 @@ /* HR_C6000 control interface */ #define DMR_RESET GPIOE,0 #define DMR_SLEEP GPIOE,1 -#define DMR_CS GPIOD,0 +#define DMR_CS &GpioD,0 #define DMR_CLK GPIOD,1 #define DMR_MOSI GPIOD,2 #define DMR_MISO GPIOD,3