From 1786d998f87651347a8e07e61373b8b0d706d33e Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 20 Jan 2016 13:43:59 +0100 Subject: [PATCH] [Horus] MP3 driver now OK. Still the volume to add --- radio/src/CMakeLists.txt | 1 - radio/src/audio_arm.cpp | 26 +- radio/src/audio_arm.h | 104 ++-- radio/src/cli.cpp | 2 - radio/src/targets/horus/audio_driver.cpp | 456 +++++++++++---- radio/src/targets/horus/board_horus.cpp | 4 +- radio/src/targets/horus/board_horus.h | 13 +- radio/src/targets/horus/delays.c | 48 +- radio/src/targets/horus/hal.h | 51 +- radio/src/targets/horus/mp3_driver.cpp | 598 -------------------- radio/src/targets/horus/pulses_driver.cpp | 66 +-- radio/src/targets/horus/pwr_driver.c | 6 +- radio/src/targets/simu/simpgmspace.cpp | 2 +- radio/src/targets/sky9x/audio_driver.cpp | 2 +- radio/src/targets/sky9x/audio_driver.h | 1 + radio/src/targets/taranis/audio_driver.cpp | 44 +- radio/src/targets/taranis/board_taranis.h | 7 +- radio/src/targets/taranis/hal.h | 20 +- radio/src/targets/taranis/i2c_driver.cpp | 6 +- radio/src/targets/taranis/pulses_driver.cpp | 66 +-- radio/src/targets/taranis/pwr_driver.c | 6 +- 21 files changed, 610 insertions(+), 919 deletions(-) delete mode 100644 radio/src/targets/horus/mp3_driver.cpp diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index 95967c211..100bd9b14 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -86,7 +86,6 @@ if(PCB STREQUAL HORUS) pwr_driver.c sdram_driver.c led_driver.cpp - # mp3_driver.cpp ) set(STM32LIB_SRC STM32F4xx_StdPeriph_Driver/src/stm32f4xx_sdio.c diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 969940fbb..f1a1183c1 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -497,7 +497,7 @@ void AudioQueue::start() #define CODEC_ID_PCM_MULAW 7 #if !defined(SIMU) -void audioTask(void* pdata) +void audioTask(void * pdata) { while (!audioQueue.started()) { CoTickDelay(1); @@ -521,13 +521,9 @@ void audioTask(void* pdata) } #endif -void mixSample(uint16_t * result, int sample, unsigned int fade) +void mixSample(audio_data_t * result, int sample, unsigned int fade) { -#if defined(SIMU_AUDIO) - *result = limit(0, *result + ((sample >> fade) ), 0xFFFF); -#else - *result = limit(0, *result + ((sample >> fade) >> 4), 4095); -#endif + *result = limit(AUDIO_DATA_MIN, *result + ((sample >> fade) >> (16-AUDIO_BITS_PER_SAMPLE)), AUDIO_DATA_MAX); } #if defined(SDCARD) @@ -595,7 +591,7 @@ int WavContext::mixBuffer(AudioBuffer *buffer, int volume, unsigned int fade) fragment.clear(); } - uint16_t * samples = buffer->data; + audio_data_t * samples = buffer->data; if (state.codec == CODEC_ID_PCM_S16LE) { read /= 2; for (uint32_t i=0; idata[i] = 0x8000; /* silence */ -#else - buffer->data[i] = 0x8000 >> 4; /* silence */ -#endif + buffer->data[i] = AUDIO_DATA_SILENCE; /* silence */ } // mix the priority context (only tones) @@ -786,7 +780,7 @@ void AudioQueue::wakeup() // TRACE("pushing buffer %d\n", bufferWIdx); bufferWIdx = nextBufferIdx(bufferWIdx); buffer->size = size; - buffer->state = dacQueue(buffer) ? AUDIO_BUFFER_PLAYING : AUDIO_BUFFER_FILLED; + buffer->state = audioPushBuffer(buffer) ? AUDIO_BUFFER_PLAYING : AUDIO_BUFFER_FILLED; __enable_irq(); } } diff --git a/radio/src/audio_arm.h b/radio/src/audio_arm.h index 1bc2a36bf..94f565171 100644 --- a/radio/src/audio_arm.h +++ b/radio/src/audio_arm.h @@ -1,52 +1,78 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * th9x - http://code.google.com/p/th9x - * er9x - http://code.google.com/p/er9x - * gruvin9x - http://code.google.com/p/gruvin9x - * - * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * 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. - */ - -#ifndef _AUDIO_ARM_H_ -#define _AUDIO_ARM_H_ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + */ + +#ifndef _AUDIO_ARM_H_ +#define _AUDIO_ARM_H_ #include #include "ff.h" -#define AUDIO_FILENAME_MAXLEN (42) //max length example: /SOUNDS/fr/123456789012/1234567890-off.wav -#define AUDIO_QUEUE_LENGTH (20) +#define AUDIO_FILENAME_MAXLEN (42) // max length (example: /SOUNDS/fr/123456789012/1234567890-off.wav) +#define AUDIO_QUEUE_LENGTH (20) + +#define AUDIO_SAMPLE_RATE (32000) +#define AUDIO_BUFFER_DURATION (10) +#define AUDIO_BUFFER_SIZE (AUDIO_SAMPLE_RATE*AUDIO_BUFFER_DURATION/1000) -#define AUDIO_SAMPLE_RATE (32000) -#define AUDIO_BUFFER_DURATION (10) -#define AUDIO_BUFFER_SIZE (AUDIO_SAMPLE_RATE*AUDIO_BUFFER_DURATION/1000) #if defined(SIMU_AUDIO) - #define AUDIO_BUFFER_COUNT (10) // simulator needs more buffers for smooth audio + #define AUDIO_BUFFER_COUNT (10) // simulator needs more buffers for smooth audio +#elif defined(PCBHORUS) + #define AUDIO_BUFFER_COUNT (2) #else - #define AUDIO_BUFFER_COUNT (3) + #define AUDIO_BUFFER_COUNT (3) #endif -#define BEEP_MIN_FREQ (150) -#define BEEP_DEFAULT_FREQ (2250) -#define BEEP_KEY_UP_FREQ (BEEP_DEFAULT_FREQ+150) -#define BEEP_KEY_DOWN_FREQ (BEEP_DEFAULT_FREQ-150) +#define BEEP_MIN_FREQ (150) +#define BEEP_DEFAULT_FREQ (2250) +#define BEEP_KEY_UP_FREQ (BEEP_DEFAULT_FREQ+150) +#define BEEP_KEY_DOWN_FREQ (BEEP_DEFAULT_FREQ-150) -#define AUDIO_BUFFER_FREE (0) -#define AUDIO_BUFFER_FILLED (1) -#define AUDIO_BUFFER_PLAYING (2) +enum AudioBufferState +{ + AUDIO_BUFFER_FREE, + AUDIO_BUFFER_FILLED, + AUDIO_BUFFER_PLAYING +}; + +#if defined(SIMU) + typedef uint16_t audio_data_t; + #define AUDIO_DATA_SILENCE 0x8000 + #define AUDIO_DATA_MIN 0 + #define AUDIO_DATA_MAX UINT16_MAX + #define AUDIO_BITS_PER_SAMPLE 16 +#elif defined(PCBHORUS) + typedef int16_t audio_data_t; + #define AUDIO_DATA_SILENCE 0 + #define AUDIO_DATA_MIN INT16_MIN + #define AUDIO_DATA_MAX INT16_MAX + #define AUDIO_BITS_PER_SAMPLE 16 +#else + typedef uint16_t audio_data_t; + #define AUDIO_DATA_SILENCE (0x8000 >> 4) + #define AUDIO_DATA_MIN 0 + #define AUDIO_DATA_MAX 0x0fff + #define AUDIO_BITS_PER_SAMPLE 12 +#endif struct AudioBuffer { - uint16_t data[AUDIO_BUFFER_SIZE]; + audio_data_t data[AUDIO_BUFFER_SIZE]; uint16_t size; uint8_t state; }; @@ -140,7 +166,7 @@ class MixedContext { int mixBuffer(AudioBuffer *buffer, int volume, unsigned int fade); }; -bool dacQueue(AudioBuffer *buffer); +bool audioPushBuffer(AudioBuffer * buffer); class AudioQueue { @@ -387,4 +413,4 @@ void referenceModelAudioFiles(); bool isAudioFileReferenced(uint32_t i, char * filename/*at least AUDIO_FILENAME_MAXLEN+1 long*/); -#endif // _AUDIO_ARM_H_ +#endif // _AUDIO_ARM_H_ diff --git a/radio/src/cli.cpp b/radio/src/cli.cpp index ce2ac8b21..6d1a7bb16 100644 --- a/radio/src/cli.cpp +++ b/radio/src/cli.cpp @@ -330,12 +330,10 @@ int cliDebugVars(const char ** argv) #if defined(PCBHORUS) && !defined(SIMU) extern uint32_t ioMutexReq, ioMutexRel; extern uint32_t sdReadRetries; - extern uint32_t audioBufferCount; serialPrint("ioMutexReq=%d", ioMutexReq); serialPrint("ioMutexRel=%d", ioMutexRel); serialPrint("sdReadRetries=%d", sdReadRetries); - serialPrint("audioBufferCount=%d", audioBufferCount); #endif return 0; } diff --git a/radio/src/targets/horus/audio_driver.cpp b/radio/src/targets/horus/audio_driver.cpp index 50deff5ea..50df42d5f 100644 --- a/radio/src/targets/horus/audio_driver.cpp +++ b/radio/src/targets/horus/audio_driver.cpp @@ -2,7 +2,7 @@ * Copyright (C) OpenTX * * Based on code named - * th9x - http://code.google.com/p/th9x + * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * @@ -20,125 +20,375 @@ #include "../../opentx.h" -uint32_t audioBufferCount = 0; +#define VS_WRITE_COMMAND 0x02 +#define VS_READ_COMMAND 0x03 -#if !defined(SIMU) -bool dacIdle = true; +#define SPI_MODE 0x00 +#define SPI_STATUS 0x01 +#define SPI_BASS 0x02 +#define SPI_CLOCKF 0x03 +#define SPI_DECODE_TIME 0x04 +#define SPI_AUDATA 0x05 +#define SPI_WRAM 0x06 +#define SPI_WRAMADDR 0x07 +#define SPI_HDAT0 0x08 +#define SPI_HDAT1 0x09 +#define SPI_AIADDR 0x0a +#define SPI_VOL 0x0b +#define SPI_AICTRL0 0x0c +#define SPI_AICTRL1 0x0d +#define SPI_AICTRL2 0x0e +#define SPI_AICTRL3 0x0f -void setSampleRate(uint32_t frequency) +#define SM_DIFF 0x01 +#define SM_LAYER12 0x02 +#define SM_RESET 0x04 +#define SM_CANCEL 0x08 +#define SM_EARSPEAKER_LO 0x10 +#define SM_TESTS 0x20 +#define SM_STREAM 0x40 +#define SM_EARSPEAKER_HI 0x80 +#define SM_DACT 0x100 +#define SM_SDIORD 0x200 +#define SM_SDISHARE 0x400 +#define SM_SDINEW 0x800 +#define SM_ADPCM 0x1000 +#define SM_LINE1 0x4000 +#define SM_CLK_RANGE 0x8000 + +#define SPI_SPEED_2 0 +#define SPI_SPEED_4 1 +#define SPI_SPEED_8 2 +#define SPI_SPEED_16 3 +#define SPI_SPEED_32 4 +#define SPI_SPEED_64 5 +#define SPI_SPEED_128 6 +#define SPI_SPEED_256 7 + +#define MP3_BUFFER_SIZE 32 + +#define CS_HIGH() do { AUDIO_CS_GPIO->BSRRL = AUDIO_CS_GPIO_PIN; } while (0) +#define CS_LOW() do { AUDIO_CS_GPIO->BSRRH = AUDIO_CS_GPIO_PIN; } while (0) +#define XDCS_HIGH() do { AUDIO_XDCS_GPIO->BSRRL = AUDIO_XDCS_GPIO_PIN; } while (0) +#define XDCS_LOW() do { AUDIO_XDCS_GPIO->BSRRH = AUDIO_XDCS_GPIO_PIN; } while (0) +#define RST_HIGH() do { AUDIO_RST_GPIO->BSRRL = AUDIO_RST_GPIO_PIN; } while (0) +#define RST_LOW() do { AUDIO_RST_GPIO->BSRRH = AUDIO_RST_GPIO_PIN; } while (0) + +#define READ_DREQ() (GPIO_ReadInputDataBit(AUDIO_DREQ_GPIO, AUDIO_DREQ_GPIO_PIN)) + +void audioSpiInit(void) { - register uint32_t timer = (PERI1_FREQUENCY * TIMER_MULT_APB1) / frequency - 1 ; // MCK/8 and 100 000 Hz + GPIO_InitTypeDef GPIO_InitStructure; + SPI_InitTypeDef SPI_InitStructure; - AUDIO_TIMER->CR1 &= ~TIM_CR1_CEN ; - AUDIO_TIMER->CNT = 0 ; - AUDIO_TIMER->ARR = limit(2, timer, 65535) ; - AUDIO_TIMER->CR1 |= TIM_CR1_CEN ; + GPIO_InitStructure.GPIO_Pin = AUDIO_SPI_MISO_GPIO_PIN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_Init(AUDIO_SPI_MISO_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = AUDIO_SPI_SCK_GPIO_PIN; + GPIO_Init(AUDIO_SPI_SCK_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = AUDIO_SPI_MOSI_GPIO_PIN; + GPIO_Init(AUDIO_SPI_MOSI_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = AUDIO_CS_GPIO_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; + GPIO_Init(AUDIO_CS_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = AUDIO_XDCS_GPIO_PIN; + GPIO_Init(AUDIO_XDCS_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = AUDIO_RST_GPIO_PIN; + GPIO_Init(AUDIO_RST_GPIO, &GPIO_InitStructure); + + GPIO_InitStructure.GPIO_Pin = AUDIO_DREQ_GPIO_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; + GPIO_Init(AUDIO_DREQ_GPIO, &GPIO_InitStructure); + + GPIO_PinAFConfig(AUDIO_SPI_SCK_GPIO, AUDIO_SPI_SCK_GPIO_PinSource, AUDIO_SPI_GPIO_AF); + GPIO_PinAFConfig(AUDIO_SPI_MISO_GPIO, AUDIO_SPI_MISO_GPIO_PinSource, AUDIO_SPI_GPIO_AF); + GPIO_PinAFConfig(AUDIO_SPI_MOSI_GPIO, AUDIO_SPI_MOSI_GPIO_PinSource, AUDIO_SPI_GPIO_AF); + + RCC_ClocksTypeDef RCC_Clocks; + RCC_GetClocksFreq(&RCC_Clocks); + + SPI_I2S_DeInit(AUDIO_SPI); + SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; + SPI_InitStructure.SPI_Mode = SPI_Mode_Master; + SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; + SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; + SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; + SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; + SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; + SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; + SPI_InitStructure.SPI_CRCPolynomial = 7; + SPI_Init(AUDIO_SPI, &SPI_InitStructure); + SPI_Cmd(AUDIO_SPI, ENABLE); + + SPI_I2S_ClearFlag(AUDIO_SPI, SPI_I2S_FLAG_RXNE); + SPI_I2S_ClearFlag(AUDIO_SPI, SPI_I2S_FLAG_TXE); } -// Start TIMER6 at 100000Hz, used for DAC trigger -void dacTimerInit() +void audioSpiSetSpeed(uint8_t speed) { - AUDIO_TIMER->PSC = 0 ; // Max speed - AUDIO_TIMER->ARR = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 100000 - 1 ; // 10 uS, 100 kHz - AUDIO_TIMER->CR2 = 0 ; - AUDIO_TIMER->CR2 = 0x20 ; - AUDIO_TIMER->CR1 = TIM_CR1_CEN ; + AUDIO_SPI->CR1 &= 0XFFC7; // Fsck=Fcpu/256 + switch(speed) { + case SPI_SPEED_2: + AUDIO_SPI->CR1 |= 0<<3; // Fsck=Fpclk/2=36Mhz + break; + case SPI_SPEED_4: + AUDIO_SPI->CR1 |= 1<<3; // Fsck=Fpclk/4=18Mhz + break; + case SPI_SPEED_8: + AUDIO_SPI->CR1 |= 2<<3; // Fsck=Fpclk/8=9Mhz + break; + case SPI_SPEED_16: + AUDIO_SPI->CR1 |= 3<<3; // Fsck=Fpclk/16=4.5Mhz + break; + case SPI_SPEED_32: + AUDIO_SPI->CR1 |= 4<<3; // Fsck=Fpclk/32=2.25Mhz + break; + case SPI_SPEED_64: + AUDIO_SPI->CR1 |= 5<<3; // Fsck=Fpclk/16=1.125Mhz + break; + case SPI_SPEED_128: + AUDIO_SPI->CR1 |= 6<<3; // Fsck=Fpclk/16=562.5Khz + break; + case SPI_SPEED_256: + AUDIO_SPI->CR1 |= 7<<3; // Fsck=Fpclk/16=281.25Khz + break; + } + AUDIO_SPI->CR1 |= 1<<6; } -void dacInit() +uint8_t audioSpiReadWriteByte(uint8_t value) { - dacTimerInit(); + uint16_t time_out = 0x0FFF; + while (SPI_I2S_GetFlagStatus(AUDIO_SPI, SPI_I2S_FLAG_TXE) == RESET) { + if (--time_out == 0) { + // reset SPI + SPI_Cmd(AUDIO_SPI, DISABLE); + SPI_I2S_ClearFlag(AUDIO_SPI, SPI_I2S_FLAG_OVR); + SPI_I2S_ClearFlag(AUDIO_SPI, SPI_I2S_FLAG_BSY); + SPI_I2S_ClearFlag(AUDIO_SPI, I2S_FLAG_UDR); + SPI_I2S_ClearFlag(AUDIO_SPI, SPI_I2S_FLAG_TIFRFE); + SPI_Cmd(AUDIO_SPI, ENABLE); + break; + } + } + SPI_I2S_SendData(AUDIO_SPI, value); - configure_pins( GPIO_Pin_4, PIN_ANALOG | PIN_PORTA ) ; - - // Chan 7, 16-bit wide, Medium priority, memory increments - DMA1_Stream5->CR &= ~DMA_SxCR_EN ; // Disable DMA - DMA1->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear bits - DMA1_Stream5->CR = DMA_SxCR_CHSEL_0 | DMA_SxCR_CHSEL_1 | DMA_SxCR_CHSEL_2 | DMA_SxCR_PL_0 | - DMA_SxCR_MSIZE_0 | DMA_SxCR_PSIZE_0 | DMA_SxCR_MINC | DMA_SxCR_DIR_0 | DMA_SxCR_CIRC ; - DMA1_Stream5->PAR = CONVERT_PTR_UINT(&DAC->DHR12R1); - // DMA1_Stream5->M0AR = CONVERT_PTR_UINT(Sine_values); - DMA1_Stream5->FCR = 0x05 ; //DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0 ; - // DMA1_Stream5->NDTR = 100 ; - - DAC->DHR12R1 = 2010 ; - DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag - DAC->CR = DAC_CR_TEN1 | DAC_CR_EN1 ; // Enable DAC - NVIC_EnableIRQ(AUDIO_TIMER_DAC_IRQn); // TODO needed? - NVIC_SetPriority(AUDIO_TIMER_DAC_IRQn, 7); - NVIC_EnableIRQ(DMA1_Stream5_IRQn); - NVIC_SetPriority(DMA1_Stream5_IRQn, 7); + time_out = 0x0FFF; + while (SPI_I2S_GetFlagStatus(AUDIO_SPI, SPI_I2S_FLAG_RXNE) == RESET) { + if (--time_out == 0) { + // reset SPI + SPI_Cmd(AUDIO_SPI, DISABLE); + SPI_I2S_ClearFlag(AUDIO_SPI, SPI_I2S_FLAG_OVR); + SPI_I2S_ClearFlag(AUDIO_SPI, SPI_I2S_FLAG_BSY); + SPI_I2S_ClearFlag(AUDIO_SPI, I2S_FLAG_UDR); + SPI_I2S_ClearFlag(AUDIO_SPI, SPI_I2S_FLAG_TIFRFE); + SPI_Cmd(AUDIO_SPI, ENABLE); + break; + } + } + return SPI_I2S_ReceiveData(AUDIO_SPI); } -bool dacQueue(AudioBuffer * buffer) +uint8_t audioWaitDreq(int32_t delay_us) { - if (dacIdle) { - audioBufferCount++; - dacIdle = false; - DMA1_Stream5->CR &= ~DMA_SxCR_EN ; // Disable DMA channel - DMA1->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear bits - DMA1_Stream5->M0AR = CONVERT_PTR_UINT(buffer->data); - DMA1_Stream5->NDTR = buffer->size; - DMA1_Stream5->CR |= DMA_SxCR_EN | DMA_SxCR_TCIE ; // Enable DMA channel and interrupt - DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag - DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1 ; // Enable DAC + while (READ_DREQ() == 0) { + if (delay_us-- == 0) return 0; + delay_01us(10); + } + return 1; +} + +uint16_t audioSpiReadReg(uint8_t address) +{ + if (!audioWaitDreq(100)) + return 0; + + audioSpiSetSpeed(SPI_SPEED_64); + XDCS_HIGH(); + CS_LOW(); + audioSpiReadWriteByte(VS_READ_COMMAND); + audioSpiReadWriteByte(address); + uint16_t result = audioSpiReadWriteByte(0xff) << 8; + result += audioSpiReadWriteByte(0xff); + delay_01us(100); // 10us + CS_HIGH(); + audioSpiSetSpeed(SPI_SPEED_8); + return result; +} + +uint16_t audioSpiReadCmd(uint8_t address) +{ + if (!audioWaitDreq(100)) + return 0; + + audioSpiSetSpeed(SPI_SPEED_64); + XDCS_HIGH(); + CS_LOW(); + audioSpiReadWriteByte(VS_READ_COMMAND); + audioSpiReadWriteByte(address); + uint16_t result = audioSpiReadWriteByte(0) << 8; + result |= audioSpiReadWriteByte(0); + delay_01us(50); // 5us + CS_HIGH(); + audioSpiSetSpeed(SPI_SPEED_8); + return result; +} + +uint8_t audioSpiWriteCmd(uint8_t address, uint16_t data) +{ + if (!audioWaitDreq(100)) + return 0; + + audioSpiSetSpeed(SPI_SPEED_64); + XDCS_HIGH(); + CS_LOW(); + audioSpiReadWriteByte(VS_WRITE_COMMAND); + audioSpiReadWriteByte(address); + audioSpiReadWriteByte(data >> 8); + audioSpiReadWriteByte(data); + delay_01us(50); // 5us + CS_HIGH(); + audioSpiSetSpeed(SPI_SPEED_8); + return 1; +} + +void audioResetDecodeTime(void) +{ + audioSpiWriteCmd(SPI_DECODE_TIME, 0x0000); + audioSpiWriteCmd(SPI_DECODE_TIME, 0x0000); +} + +uint8_t audioHardReset(void) +{ + XDCS_HIGH(); + CS_HIGH(); + RST_LOW(); + delay_ms(100); // 100ms + RST_HIGH(); + + if (!audioWaitDreq(100)) + return 0; + + delay_ms(20); // 20ms + return 1; +} + +uint8_t audioSoftReset(void) +{ + audioSpiSetSpeed(SPI_SPEED_64); + if (!audioWaitDreq(100)) + return 0; + + audioSpiReadWriteByte(0x00); // start the transfer + + audioSpiWriteCmd(SPI_MODE, 0x0816); // SOFT RESET, new model + if (!audioWaitDreq(100)) + return 0; + + // wait for set up successful + uint8_t retry = 0; + while (audioSpiReadReg(SPI_CLOCKF) != 0x9800 && retry < 100) { + retry++; + audioSpiWriteCmd(SPI_CLOCKF, 0x9800); + } + + audioResetDecodeTime(); // reset the decoding time + audioSpiSetSpeed(SPI_SPEED_8); + XDCS_LOW(); + audioSpiReadWriteByte(0X0); + audioSpiReadWriteByte(0X0); + audioSpiReadWriteByte(0X0); + audioSpiReadWriteByte(0X0); + delay_01us(100); // 10us + XDCS_HIGH(); + return 1; +} + +uint32_t audioSpiWriteData(const uint8_t * buffer, uint32_t size) +{ + uint32_t index = 0; + while (index < size && READ_DREQ() != 0) { + for (int i=0; i 0) { + uint32_t written = audioSpiWriteData(p, size); + p += written; + size -= written; + } +} + +const uint8_t RiffHeader[] = { + 0x52, 0x49, 0x46, 0x46, 0xff, 0xff, 0xff, 0xff, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, + 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x7d, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, + 0x02, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +void audioInit() +{ + audioSpiInit(); + audioHardReset(); + audioSoftReset(); + audioSpiSetSpeed(SPI_SPEED_8); + + delay_01us(10000); // 1ms + + XDCS_LOW(); + audioSpiWriteBuffer(RiffHeader, sizeof(RiffHeader)); +} + +uint8_t * currentBuffer = NULL; +uint32_t currentSize = 0; + +void audioSetCurrentBuffer(AudioBuffer * buffer) +{ + currentBuffer = (uint8_t *)buffer->data; + currentSize = buffer->size * 2; +} + +void audioConsumeCurrentBuffer() +{ + if (currentBuffer) { + uint32_t written = audioSpiWriteData(currentBuffer, currentSize); + currentBuffer += written; + currentSize -= written; + if (currentSize == 0) { + AudioBuffer * buffer = audioQueue.getNextFilledBuffer(); + if (buffer) { + audioSetCurrentBuffer(buffer); + } + else { + currentBuffer = NULL; + currentSize = 0; + } + } + } +} + +bool audioPushBuffer(AudioBuffer * buffer) +{ + if (!currentBuffer) { + audioSetCurrentBuffer(buffer); + audioConsumeCurrentBuffer(); return true; } else { return false; } } - -void dacStart() -{ - DMA1->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear bits - DMA1_Stream5->CR |= DMA_SxCR_CIRC | DMA_SxCR_EN ; // Enable DMA channel - DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag - DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1 ; // Enable DAC -} - -void dacStop() -{ - DMA1_Stream5->CR &= ~DMA_SxCR_CIRC ; -} - -// Sound routines -void audioInit() -{ - dacInit(); -} - -void audioEnd() -{ - DAC->CR = 0 ; - AUDIO_TIMER->CR1 = 0 ; - // Also need to turn off any possible interrupts - NVIC_DisableIRQ(AUDIO_TIMER_DAC_IRQn) ; - NVIC_DisableIRQ(DMA1_Stream5_IRQn) ; -} - -extern "C" void TIM6_DAC_IRQHandler() -{ - DAC->CR &= ~DAC_CR_DMAEN1 ; // Stop DMA requests - DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag -} - -extern "C" void DMA1_Stream5_IRQHandler() -{ - DMA1_Stream5->CR &= ~DMA_SxCR_TCIE ; // Stop interrupt - DMA1->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear flags - DMA1_Stream5->CR &= ~DMA_SxCR_EN ; // Disable DMA channel - - AudioBuffer *nextBuffer = audioQueue.getNextFilledBuffer(); - if (nextBuffer) { - DMA1_Stream5->M0AR = CONVERT_PTR_UINT(nextBuffer->data); - DMA1_Stream5->NDTR = nextBuffer->size; - DMA1->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear bits - DMA1_Stream5->CR |= DMA_SxCR_EN | DMA_SxCR_TCIE ; // Enable DMA channel - DAC->SR = DAC_SR_DMAUDR1; // Write 1 to clear flag - } - else { - dacIdle = true; - } -} -#endif // #if !defined(SIMU) diff --git a/radio/src/targets/horus/board_horus.cpp b/radio/src/targets/horus/board_horus.cpp index 691f53c28..61c4171ba 100644 --- a/radio/src/targets/horus/board_horus.cpp +++ b/radio/src/targets/horus/board_horus.cpp @@ -124,8 +124,8 @@ void pinCheck(GPIO_TypeDef * gpio, uint32_t pin, uint32_t RCC_AHB1Periph) void boardInit() { - RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | LCD_RCC_AHB1Periph | KEYS_RCC_AHB1Periph_GPIO | ADC_RCC_AHB1Periph | SERIAL_RCC_AHB1Periph | TELEMETRY_RCC_AHB1Periph | AUDIO_RCC_AHB1Periph | HAPTIC_RCC_AHB1Periph, ENABLE); - RCC_APB1PeriphClockCmd(INTERRUPT_5MS_APB1Periph | TIMER_2MHz_APB1Periph | SERIAL_RCC_APB1Periph | TELEMETRY_RCC_APB1Periph | AUDIO_RCC_APB1Periph, ENABLE); + RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | LCD_RCC_AHB1Periph | AUDIO_RCC_AHB1Periph | KEYS_RCC_AHB1Periph_GPIO | ADC_RCC_AHB1Periph | SERIAL_RCC_AHB1Periph | TELEMETRY_RCC_AHB1Periph | AUDIO_RCC_AHB1Periph | HAPTIC_RCC_AHB1Periph, ENABLE); + RCC_APB1PeriphClockCmd(INTERRUPT_5MS_APB1Periph | TIMER_2MHz_APB1Periph | AUDIO_RCC_APB1Periph | SERIAL_RCC_APB1Periph | TELEMETRY_RCC_APB1Periph | AUDIO_RCC_APB1Periph, ENABLE); RCC_APB2PeriphClockCmd(LCD_RCC_APB2Periph | ADC_RCC_APB2Periph | HAPTIC_RCC_APB2Periph, ENABLE); pwrInit(); diff --git a/radio/src/targets/horus/board_horus.h b/radio/src/targets/horus/board_horus.h index 82300a9f8..057d97434 100644 --- a/radio/src/targets/horus/board_horus.h +++ b/radio/src/targets/horus/board_horus.h @@ -110,6 +110,7 @@ extern "C" { #endif void delaysInit(void); void delay_01us(uint16_t nb); +void delay_ms(uint16_t nb); #ifdef __cplusplus } #endif @@ -147,14 +148,14 @@ uint32_t isFirmwareStart(const void * buffer); uint32_t isBootloaderStart(const void * buffer); // SDRAM driver -#define SDRAM_BANK_ADDR ((uint32_t)0xD0000000) +#define SDRAM_BANK_ADDR ((uint32_t)0xD0000000) void SDRAM_Init(void); void SDRAM_WriteBuffer(uint32_t* pBuffer, uint32_t uwWriteAddress, uint32_t uwBufferSize); void SDRAM_ReadBuffer(uint32_t* pBuffer, uint32_t uwReadAddress, uint32_t uwBufferSize); // Pulses driver -#define EXTERNAL_MODULE_ON() GPIO_SetBits(EXTMODULE_GPIO_PWR, EXTMODULE_GPIO_PIN_PWR) -#define EXTERNAL_MODULE_OFF() GPIO_ResetBits(EXTMODULE_GPIO_PWR, EXTMODULE_GPIO_PIN_PWR) +#define EXTERNAL_MODULE_ON() GPIO_SetBits(EXTMODULE_PWR_GPIO, EXTMODULE_PWR_GPIO_PIN) +#define EXTERNAL_MODULE_OFF() GPIO_ResetBits(EXTMODULE_PWR_GPIO, EXTMODULE_PWR_GPIO_PIN) void init_no_pulses(uint32_t port); void disable_no_pulses(uint32_t port); void init_ppm( uint32_t module_index ); @@ -276,10 +277,8 @@ void usbSerialPutc(uint8_t c); // Audio driver void audioInit(void); -void audioEnd(void); -void dacStart(void); -void dacStop(void); -void setSampleRate(uint32_t frequency); +void audioConsumeCurrentBuffer(void); +#define setSampleRate(freq) // Fake volume driver #define setScaledVolume(...) diff --git a/radio/src/targets/horus/delays.c b/radio/src/targets/horus/delays.c index 5c093f833..3431f9d3e 100644 --- a/radio/src/targets/horus/delays.c +++ b/radio/src/targets/horus/delays.c @@ -1,23 +1,23 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * th9x - http://code.google.com/p/th9x - * er9x - http://code.google.com/p/er9x - * gruvin9x - http://code.google.com/p/gruvin9x - * - * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * 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. - */ - +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + */ + #include "../horus/board_horus.h" void delaysInit(void) @@ -39,3 +39,11 @@ void delay_01us(uint16_t nb) while (TIM13->CNT < nb); TIM13->CR1 = 0x02; } + +void delay_ms(uint16_t nb) +{ + uint16_t i; + for (i=0; iBSRRL =GPIO_CS_PIN;}while(0) -#define CS_LOW() do{GPIOH->BSRRH =GPIO_CS_PIN;}while(0) - -#define XDCS_HIGH() do{GPIOI->BSRRL =GPIO_XDCS_PIN;}while(0) -#define XDCS_LOW() do{GPIOI->BSRRH =GPIO_XDCS_PIN;}while(0) - -#define RST_HIGH() do{GPIOH->BSRRL =GPIO_RST_PIN;}while(0) -#define RST_LOW() do{GPIOH->BSRRH =GPIO_RST_PIN;}while(0) - -#define READ_DREQ() (GPIO_ReadInputDataBit(GPIOH,GPIO_DREQ_PIN)) -#define VS_WRITE_COMMAND 0x02 // - -#define MP3_BUFFER_SIZE 32 - -#define SPI_SPEED_2 0 -#define SPI_SPEED_4 1 -#define SPI_SPEED_8 2 -#define SPI_SPEED_16 3 -#define SPI_SPEED_32 4 -#define SPI_SPEED_64 5 -#define SPI_SPEED_128 6 -#define SPI_SPEED_256 7 - - -//disable optimize -#define OPTIMIZE(level) __attribute__((optimize(level))) - -u8 VS10XX_ID=0; - -OPTIMIZE("O0") static void delay_spi(uint32_t nCount) -{ - __IO uint32_t index = 0; - for(index = (100000 * nCount); index != 0; --index) - { - asm("nop\n"); - } -} - -OPTIMIZE("O0") static void delay_us(uint32_t nCount) -{ - __IO uint32_t index = 0; - for(index = (100 * nCount); index != 0; --index) - { - asm("nop\n"); - } -} - - -OPTIMIZE("O0") u8 SPIy_ReadWriteByte(uint8_t value) -{ - u8 ret_val = 0; - - unsigned short time_out = 0x0FFF; - - while( SPI_I2S_GetFlagStatus(SPI, SPI_I2S_FLAG_TXE) == RESET ) - { - --time_out; - if (!time_out) - { - //reset SPI - SPI_Cmd(SPI,DISABLE); - - SPI_I2S_ClearFlag(SPI, SPI_I2S_FLAG_OVR); - SPI_I2S_ClearFlag(SPI, SPI_I2S_FLAG_BSY); - SPI_I2S_ClearFlag(SPI, I2S_FLAG_UDR); - SPI_I2S_ClearFlag(SPI, SPI_I2S_FLAG_TIFRFE); - - SPI_Cmd(SPI,ENABLE); - - break; - } - } - SPI_I2S_SendData(SPI, value); - - time_out = 0x0FFF; - - while(SPI_I2S_GetFlagStatus(SPI, SPI_I2S_FLAG_RXNE) == RESET) - { - --time_out; - if (!time_out) - { - //reset SPI - SPI_Cmd(SPI,DISABLE); - - SPI_I2S_ClearFlag(SPI, SPI_I2S_FLAG_OVR); - SPI_I2S_ClearFlag(SPI, SPI_I2S_FLAG_BSY); - SPI_I2S_ClearFlag(SPI, I2S_FLAG_UDR); - SPI_I2S_ClearFlag(SPI, SPI_I2S_FLAG_TIFRFE); - - SPI_Cmd(SPI,ENABLE); - - break; - } - } - ret_val = SPI_I2S_ReceiveData(SPI); - - return (ret_val); -} - -void SPIx_SetSpeed(u8 SpeedSet) -{ - SPI->CR1&=0XFFC7;//Fsck=Fcpu/256 - switch(SpeedSet) - { - case SPI_SPEED_2: - SPI->CR1|=0<<3;//Fsck=Fpclk/2=36Mhz - break; - case SPI_SPEED_4:// - SPI->CR1|=1<<3;//Fsck=Fpclk/4=18Mhz - break; - case SPI_SPEED_8:// - SPI->CR1|=2<<3;//Fsck=Fpclk/8=9Mhz - break; - case SPI_SPEED_16:// - SPI->CR1|=3<<3;//Fsck=Fpclk/16=4.5Mhz - break; - case SPI_SPEED_32: // - SPI->CR1|=4<<3;//Fsck=Fpclk/32=2.25Mhz - break; - case SPI_SPEED_64: // - SPI->CR1|=5<<3;//Fsck=Fpclk/16=1.125Mhz - break; - case SPI_SPEED_128: // - SPI->CR1|=6<<3;//Fsck=Fpclk/16=562.5Khz - break; - case SPI_SPEED_256: // - SPI->CR1|=7<<3;//Fsck=Fpclk/16=281.25Khz - break; - } - SPI->CR1|=1<<6; // -} - -u16 VS_RD_Reg(u8 address) -{ - u16 temp=0; - u8 retry=0; - - while(READ_DREQ()==0&&(retry++)<0XFE); - if(retry>=0XFE)return 0; - SPIx_SetSpeed(SPI_SPEED_64); - XDCS_HIGH(); - CS_LOW(); - SPIy_ReadWriteByte(VS_READ_COMMAND); - SPIy_ReadWriteByte(address); - temp=SPIy_ReadWriteByte(0xff); - temp=temp<<8; - temp+=SPIy_ReadWriteByte(0xff); - delay_us(10);//10us - CS_HIGH(); - SPIx_SetSpeed(SPI_SPEED_8); - - return temp; -} - -u16 VS_RD_Cmd(u8 address) -{ - u16 retry=0; - u16 x ; - while(READ_DREQ()==0&&(retry++)<0xfffe)retry++; - SPIx_SetSpeed(SPI_SPEED_64); - XDCS_HIGH(); - CS_LOW(); - SPIy_ReadWriteByte(VS_READ_COMMAND); - SPIy_ReadWriteByte(address); // - x = SPIy_ReadWriteByte(0); // - x <<= 8 ; - x |= SPIy_ReadWriteByte(0); // - delay_us(5);//5us - CS_HIGH(); - SPIx_SetSpeed(SPI_SPEED_8); // - return x ; -} - -void VS_WR_Cmd(u8 address,u16 data) -{ - u16 retry=0; - while(READ_DREQ()==0&&(retry++)<0xfffe)retry++; - SPIx_SetSpeed(SPI_SPEED_64); - XDCS_HIGH(); - CS_LOW(); - SPIy_ReadWriteByte(VS_WRITE_COMMAND); - SPIy_ReadWriteByte(address); // - SPIy_ReadWriteByte(data>>8); // - SPIy_ReadWriteByte(data); // - delay_us(5);//5us - CS_HIGH(); - SPIx_SetSpeed(SPI_SPEED_8); // -} - -void VS_Rst_DecodeTime(void) -{ - VS_WR_Cmd(SPI_DECODE_TIME,0x0000); - VS_WR_Cmd(SPI_DECODE_TIME,0x0000); -} - -u8 VS_HD_Reset(void) -{ - u8 retry=0; - - XDCS_HIGH(); - CS_HIGH(); - RST_LOW(); - delay_spi(100);//100ms - RST_HIGH(); - while((READ_DREQ() ==0)&&(retry<200))// - { - retry++; - delay_us(50); - } - delay_spi(20);//20ms - if(retry>=200) - return 1; - else - return 0; -} - -uint16_t Mp3ReadValue ; - -void VS_Soft_Reset(void) -{ - volatile u8 retry; - - SPIx_SetSpeed(SPI_SPEED_64); - while(READ_DREQ()== 0); - SPIy_ReadWriteByte(0x00); //start the transfer - retry=0; - VS10XX_ID=VS_RD_Reg(SPI_STATUS);//Read the status register - VS10XX_ID>>=4;//get vs10xx signal - - if(VS10XX_ID==VS1053) VS_WR_Cmd(SPI_MODE,0x0816);//SOFT RESET,new model - else VS_WR_Cmd(SPI_MODE,0x0804); - - while((READ_DREQ()== 0)&&(retry<200))//waiting DREQ HIGH - { - retry++; - delay_us(50); - } - retry=0; - while(VS_RD_Reg(SPI_CLOCKF)!=0x9800) // Wait for set up successful - { - VS_WR_Cmd(SPI_CLOCKF,0x9800); - if(retry++ >100)break; - } - - VS_Rst_DecodeTime(); //Reset the decoding time - SPIx_SetSpeed(SPI_SPEED_8); // - XDCS_LOW(); - SPIy_ReadWriteByte(0X0); - SPIy_ReadWriteByte(0X0); - SPIy_ReadWriteByte(0X0); - SPIy_ReadWriteByte(0X0); - delay_us(10);//10us - XDCS_HIGH(); -} - -void mp3_spi_init(void) -{ - GPIO_InitTypeDef GPIO_InitStructure; - SPI_InitTypeDef SPI_InitStructure; - - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI|RCC_AHB1Periph_GPIOH,ENABLE); - RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE); - RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE); - - GPIO_InitStructure.GPIO_Pin = SPI_MISO_PIN; - GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(SPI_MISO_GPIO_PORT, &GPIO_InitStructure); - - GPIO_InitStructure.GPIO_Pin = SPI_SCK_PIN; - GPIO_Init(SPI_SCK_GPIO_PORT,&GPIO_InitStructure); - - GPIO_InitStructure.GPIO_Pin = SPI_MOSI_PIN; - GPIO_Init(SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); - - GPIO_InitStructure.GPIO_Pin = GPIO_CS_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIO_CS_GPIO_PORT, &GPIO_InitStructure); - - GPIO_InitStructure.GPIO_Pin = GPIO_XDCS_PIN; - GPIO_Init(GPIO_XDCS_GPIO_PORT, &GPIO_InitStructure); - - GPIO_InitStructure.GPIO_Pin = GPIO_RST_PIN; - GPIO_Init(GPIO_RST_GPIO_PORT, &GPIO_InitStructure); - - GPIO_InitStructure.GPIO_Pin = GPIO_DREQ_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_Init(GPIO_DREQ_GPIO_PORT, &GPIO_InitStructure); - - GPIO_PinAFConfig(SPI_SCK_GPIO_PORT, SPI_SCK_SOURCE, GPIO_AF_SPI2); - GPIO_PinAFConfig(SPI_MISO_GPIO_PORT, SPI_MISO_SOURCE, GPIO_AF_SPI2); - GPIO_PinAFConfig(SPI_MOSI_GPIO_PORT, SPI_MOSI_SOURCE, GPIO_AF_SPI2); - - RCC_ClocksTypeDef RCC_Clocks; - RCC_GetClocksFreq( &RCC_Clocks); - - SPI_I2S_DeInit(SPI); - - SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; - SPI_InitStructure.SPI_Mode = SPI_Mode_Master; - SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; - SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; - SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; - SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; - SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; - SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; - SPI_InitStructure.SPI_CRCPolynomial = 7; - SPI_Init(SPI,&SPI_InitStructure); - - SPI_Cmd(SPI,ENABLE); - - SPI_I2S_ClearFlag(SPI, SPI_I2S_FLAG_RXNE); - SPI_I2S_ClearFlag(SPI, SPI_I2S_FLAG_TXE); -} - -int SpiMp3_read(const void * buffer, int len); - -const uint8_t header[] = { - 0x52, 0x49, 0x46, 0x46, 0xff, 0xff, 0xff, 0xff, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, - 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x7d, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, - 0x02, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; - -void audioInit() -{ - mp3_spi_init(); - VS_HD_Reset(); - VS_Soft_Reset(); - SPIx_SetSpeed(SPI_SPEED_8); - - // SPIx_SetSpeed(SPI_SPEED_8); - - // delay_us(10000);//10ms - // VS_WR_Cmd(SPI_BASS, data); - //delay_us(10000);//10ms - // VS_WR_Cmd(SPI_VOL, 0x2424); - // delay_us(10000);//10ms - - - - delay_us(10000);//10ms -/* - XDCS_LOW(); - SPIy_ReadWriteByte(0x53); - SPIy_ReadWriteByte(0xEF); - SPIy_ReadWriteByte(0x6E); - SPIy_ReadWriteByte(0x63); - SPIy_ReadWriteByte(0X0); - SPIy_ReadWriteByte(0X0); - SPIy_ReadWriteByte(0X0); - SPIy_ReadWriteByte(0X0); - delay_us(10);//10ms - XDCS_HIGH(); -*/ - - XDCS_LOW(); - - while (SpiMp3_read(header, sizeof(header)) != 1) { - // delay_us(10);//10ms - } - /*for (int h = 0; h < 10; h++) { - - while (SpiMp3_read(sineValues, sizeof(sineValues)) != 1) { - delay_us(1000);//10ms - } - - for (int i = 0; i < 100; i++) - delay_us(1000);//1ms - }*/ - -} - -unsigned short curIndex = 0; - -bool dacQueue(AudioBuffer * buffer) -{ - while (SpiMp3_read(buffer->data, buffer->size) != 1) { - // delay_us(10);//10ms - } - - return true; - // SpiMp3_read(buffer->data, AUDIO_BUFFER_SIZE); -} - -int SpiMp3_read(const void * buffer, int len) -{ - audioBufferCount++; - - int ret_val = 0; - unsigned char n = 0; - char temp_c = 0; - - char *pTmp = (char*)buffer; - - if( (READ_DREQ()!=0) ) - { - if (curIndex >= len) - { - curIndex = 0; - //send over - ret_val = 1; - } - else - { - // XDCS_LOW(); - //send data - for( n = 0; n < 32; ++n) - { - if (curIndex >= len) - { - curIndex = 0; - return 1; - //none - //temp_c = 0x00; - // SPIy_ReadWriteByte(temp_c); - } - else - { - temp_c = pTmp[curIndex]; - SPIy_ReadWriteByte(temp_c); - ++curIndex; - } - } - //delay for send over - // delay_us(10);//10ms - //XDCS_HIGH(); - - //continue - ret_val = 2; - } - } - else - { - //none , normal - } - - return (ret_val); -} - -#if 0 -int SpiMp3_ioControl(Driver *driver, int io_type , int data) -{ - if (io_type == 0) - { - VS_WR_Cmd(SPI_BASS, data); - } - else if (io_type == 1) - { - VS_WR_Cmd(SPI_VOL, data); - } - else if (io_type == 2) - { - //clear the index - curIndex = 0; - } - - return 0; -} - - -int SpiMp3_close(Driver *driver) -{ - GPIO_InitTypeDef GPIO_InitStructure; - - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3| GPIO_Pin_4 | GPIO_Pin_5; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOB, &GPIO_InitStructure); - - SPI_I2S_DeInit(SPI); - - return 0; -} - -#endif \ No newline at end of file diff --git a/radio/src/targets/horus/pulses_driver.cpp b/radio/src/targets/horus/pulses_driver.cpp index bda5801ed..31c29d8d5 100644 --- a/radio/src/targets/horus/pulses_driver.cpp +++ b/radio/src/targets/horus/pulses_driver.cpp @@ -1,23 +1,23 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * th9x - http://code.google.com/p/th9x - * er9x - http://code.google.com/p/er9x - * gruvin9x - http://code.google.com/p/gruvin9x - * - * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * 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. - */ - +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + */ + #include "../../opentx.h" void setupPulses(unsigned int port); @@ -38,16 +38,16 @@ void init_no_pulses(uint32_t port) // Timer1, channel 1 GPIO_InitTypeDef GPIO_InitStructure; - RCC_AHB1PeriphClockCmd(EXTMODULE_RCC_AHB1Periph_GPIO, ENABLE); + RCC_AHB1PeriphClockCmd(EXTMODULE_RCC_AHB1Periph, ENABLE); - GPIO_InitStructure.GPIO_Pin = EXTMODULE_GPIO_PIN; + GPIO_InitStructure.GPIO_Pin = EXTMODULE_PPM_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT ; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(EXTMODULE_GPIO, &GPIO_InitStructure); + GPIO_Init(EXTMODULE_PPM_GPIO, &GPIO_InitStructure); - GPIO_SetBits(EXTMODULE_GPIO, EXTMODULE_GPIO_PIN) ; // Set high + GPIO_SetBits(EXTMODULE_PPM_GPIO, EXTMODULE_PPM_GPIO_PIN) ; // Set high RCC->APB2ENR |= RCC_APB2ENR_TIM1EN ; // Enable clock @@ -93,14 +93,14 @@ void init_pxx(uint32_t port) RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN ; // Enable portA clock GPIO_InitTypeDef GPIO_InitStructure; - RCC_AHB1PeriphClockCmd(EXTMODULE_RCC_AHB1Periph_GPIO, ENABLE); - GPIO_PinAFConfig(EXTMODULE_GPIO, EXTMODULE_GPIO_PinSource, GPIO_AF_TIM1); - GPIO_InitStructure.GPIO_Pin = EXTMODULE_GPIO_PIN; + RCC_AHB1PeriphClockCmd(EXTMODULE_RCC_AHB1Periph, ENABLE); + GPIO_PinAFConfig(EXTMODULE_PPM_GPIO, EXTMODULE_PPM_GPIO_PinSource, GPIO_AF_TIM1); + GPIO_InitStructure.GPIO_Pin = EXTMODULE_PPM_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(EXTMODULE_GPIO, &GPIO_InitStructure); + GPIO_Init(EXTMODULE_PPM_GPIO, &GPIO_InitStructure); RCC->APB2ENR |= RCC_APB2ENR_TIM1EN ; // Enable clock RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN ; // Enable DMA2 clock @@ -156,14 +156,14 @@ void init_dsm2(uint32_t port) RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN ; // Enable portA clock GPIO_InitTypeDef GPIO_InitStructure; - RCC_AHB1PeriphClockCmd(EXTMODULE_RCC_AHB1Periph_GPIO, ENABLE); - GPIO_PinAFConfig(EXTMODULE_GPIO, EXTMODULE_GPIO_PinSource, GPIO_AF_TIM1); - GPIO_InitStructure.GPIO_Pin = EXTMODULE_GPIO_PIN; + RCC_AHB1PeriphClockCmd(EXTMODULE_RCC_AHB1Periph, ENABLE); + GPIO_PinAFConfig(EXTMODULE_PPM_GPIO, EXTMODULE_PPM_GPIO_PinSource, GPIO_AF_TIM1); + GPIO_InitStructure.GPIO_Pin = EXTMODULE_PPM_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(EXTMODULE_GPIO, &GPIO_InitStructure); + GPIO_Init(EXTMODULE_PPM_GPIO, &GPIO_InitStructure); RCC->APB2ENR |= RCC_APB2ENR_TIM1EN ; // Enable clock RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN ; // Enable DMA2 clock @@ -224,7 +224,7 @@ void init_ppm(uint32_t port) modulePulsesData[EXTERNAL_MODULE].ppm.ptr = modulePulsesData[EXTERNAL_MODULE].ppm.pulses; RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN ; // Enable portA clock - configure_pins( EXTMODULE_GPIO_PIN, PIN_PERIPHERAL | PIN_PORTA | PIN_PER_3 | PIN_OS25 | PIN_PUSHPULL ) ; + configure_pins( EXTMODULE_PPM_GPIO_PIN, PIN_PERIPHERAL | PIN_PORTA | PIN_PER_3 | PIN_OS25 | PIN_PUSHPULL ) ; RCC->APB2ENR |= RCC_APB2ENR_TIM1EN ; // Enable clock TIM1->CR1 &= ~TIM_CR1_CEN ; diff --git a/radio/src/targets/horus/pwr_driver.c b/radio/src/targets/horus/pwr_driver.c index c75f4a92d..81192c99d 100644 --- a/radio/src/targets/horus/pwr_driver.c +++ b/radio/src/targets/horus/pwr_driver.c @@ -39,10 +39,10 @@ void pwrInit() GPIO_Init(AUDIO_SHUTDOWN_GPIO, &GPIO_InitStructure); // Init Module PWR - GPIO_ResetBits(EXTMODULE_GPIO_PWR, EXTMODULE_GPIO_PIN_PWR); - GPIO_InitStructure.GPIO_Pin = EXTMODULE_GPIO_PIN_PWR; + GPIO_ResetBits(EXTMODULE_PWR_GPIO, EXTMODULE_PWR_GPIO_PIN); + GPIO_InitStructure.GPIO_Pin = EXTMODULE_PWR_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_Init(EXTMODULE_GPIO_PWR, &GPIO_InitStructure); + GPIO_Init(EXTMODULE_PWR_GPIO, &GPIO_InitStructure); pwrOn(); } diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index bda3da4e2..85bd26df2 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -453,7 +453,7 @@ struct SimulatorAudio { pthread_t threadPid; } simuAudio; -bool dacQueue(AudioBuffer * buffer) +bool audioPushBuffer(AudioBuffer * buffer) { return false; } diff --git a/radio/src/targets/sky9x/audio_driver.cpp b/radio/src/targets/sky9x/audio_driver.cpp index 3931333e5..19462ef7c 100644 --- a/radio/src/targets/sky9x/audio_driver.cpp +++ b/radio/src/targets/sky9x/audio_driver.cpp @@ -93,7 +93,7 @@ void dacInit() NVIC_EnableIRQ(DACC_IRQn) ; } -bool dacQueue(AudioBuffer *buffer) +bool audioPushBuffer(AudioBuffer *buffer) { dacStart(); return false; diff --git a/radio/src/targets/sky9x/audio_driver.h b/radio/src/targets/sky9x/audio_driver.h index 6cd790d67..c2d479f31 100644 --- a/radio/src/targets/sky9x/audio_driver.h +++ b/radio/src/targets/sky9x/audio_driver.h @@ -23,6 +23,7 @@ void audioInit( void ) ; void audioEnd( void ) ; +#define audioConsumeCurrentBuffer() void setSampleRate( uint32_t frequency ) ; diff --git a/radio/src/targets/taranis/audio_driver.cpp b/radio/src/targets/taranis/audio_driver.cpp index 1cd667c41..5f326c2f8 100644 --- a/radio/src/targets/taranis/audio_driver.cpp +++ b/radio/src/targets/taranis/audio_driver.cpp @@ -1,23 +1,23 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * th9x - http://code.google.com/p/th9x - * er9x - http://code.google.com/p/er9x - * gruvin9x - http://code.google.com/p/gruvin9x - * - * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * 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. - */ - +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + */ + #include "../../opentx.h" const int8_t volumeScale[VOLUME_LEVEL_MAX+1] = @@ -83,7 +83,7 @@ void dacInit() NVIC_SetPriority(DMA1_Stream5_IRQn, 7); } -bool dacQueue(AudioBuffer *buffer) +bool audioPushBuffer(AudioBuffer * buffer) { if (dacIdle) { dacIdle = false; @@ -145,7 +145,7 @@ extern "C" void DMA1_Stream5_IRQHandler() DMA1->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear flags DMA1_Stream5->CR &= ~DMA_SxCR_EN ; // Disable DMA channel - AudioBuffer *nextBuffer = audioQueue.getNextFilledBuffer(); + AudioBuffer * nextBuffer = audioQueue.getNextFilledBuffer(); if (nextBuffer) { DMA1_Stream5->M0AR = CONVERT_PTR_UINT(nextBuffer->data); DMA1_Stream5->NDTR = nextBuffer->size; diff --git a/radio/src/targets/taranis/board_taranis.h b/radio/src/targets/taranis/board_taranis.h index 8b758a28a..9f031f7b6 100644 --- a/radio/src/targets/taranis/board_taranis.h +++ b/radio/src/targets/taranis/board_taranis.h @@ -179,10 +179,10 @@ uint32_t isBootloaderStart(const void * buffer); // Pulses driver #define INTERNAL_MODULE_ON() GPIO_SetBits(INTMODULE_GPIO_PWR, INTMODULE_GPIO_PIN_PWR) #define INTERNAL_MODULE_OFF() GPIO_ResetBits(INTMODULE_GPIO_PWR, INTMODULE_GPIO_PIN_PWR) -#define EXTERNAL_MODULE_ON() GPIO_SetBits(EXTMODULE_GPIO_PWR, EXTMODULE_GPIO_PIN_PWR) -#define EXTERNAL_MODULE_OFF() GPIO_ResetBits(EXTMODULE_GPIO_PWR, EXTMODULE_GPIO_PIN_PWR) +#define EXTERNAL_MODULE_ON() GPIO_SetBits(EXTMODULE_PWR_GPIO, EXTMODULE_PWR_GPIO_PIN) +#define EXTERNAL_MODULE_OFF() GPIO_ResetBits(EXTMODULE_PWR_GPIO, EXTMODULE_PWR_GPIO_PIN) #define IS_INTERNAL_MODULE_ON() (GPIO_ReadInputDataBit(INTMODULE_GPIO_PWR, INTMODULE_GPIO_PIN_PWR) == Bit_SET) -#define IS_EXTERNAL_MODULE_ON() (GPIO_ReadInputDataBit(EXTMODULE_GPIO_PWR, EXTMODULE_GPIO_PIN_PWR) == Bit_SET) +#define IS_EXTERNAL_MODULE_ON() (GPIO_ReadInputDataBit(EXTMODULE_PWR_GPIO, EXTMODULE_PWR_GPIO_PIN) == Bit_SET) void init_no_pulses(uint32_t port); void disable_no_pulses(uint32_t port); void init_ppm( uint32_t module_index ); @@ -331,6 +331,7 @@ extern const int8_t volumeScale[]; void setScaledVolume(uint8_t volume); void setVolume(uint8_t volume); int32_t getVolume(void); +#define audioConsumeCurrentBuffer() // Haptic driver void hapticInit(void); diff --git a/radio/src/targets/taranis/hal.h b/radio/src/targets/taranis/hal.h index 440a8c510..2617af3d7 100644 --- a/radio/src/targets/taranis/hal.h +++ b/radio/src/targets/taranis/hal.h @@ -342,13 +342,13 @@ // External Module #define EXTMODULE_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_DMA2) #define EXTMODULE_RCC_APB2Periph RCC_APB2Periph_TIM8 -#define EXTMODULE_GPIO_PWR GPIOD -#define EXTMODULE_GPIO_PIN_PWR GPIO_Pin_8 -#define EXTMODULE_GPIO_PIN GPIO_Pin_7 // PA.07 -#define EXTMODULE_GPIO GPIOA +#define EXTMODULE_PWR_GPIO GPIOD +#define EXTMODULE_PWR_GPIO_PIN GPIO_Pin_8 +#define EXTMODULE_PPM_GPIO_PIN GPIO_Pin_7 // PA.07 +#define EXTMODULE_PPM_GPIO GPIOA #define EXTMODULE_TIMER TIM8 -#define EXTMODULE_GPIO_AF GPIO_AF_TIM8 -#define EXTMODULE_GPIO_PinSource GPIO_PinSource7 +#define EXTMODULE_PPM_GPIO_AF GPIO_AF_TIM8 +#define EXTMODULE_PPM_GPIO_PinSource GPIO_PinSource7 #define EXTMODULE_TIMER_IRQn TIM8_CC_IRQn // Trainer Port @@ -489,12 +489,12 @@ #define I2C_RCC_APB1Periph RCC_APB1Periph_I2C1 #define I2C I2C1 #define I2C_GPIO GPIOB -#define I2C_GPIO_PIN_SCL GPIO_Pin_6 // PB.06 -#define I2C_GPIO_PIN_SDA GPIO_Pin_7 // PB.07 +#define I2C_SCL_GPIO_PIN GPIO_Pin_6 // PB.06 +#define I2C_SDA_GPIO_PIN GPIO_Pin_7 // PB.07 #define I2C_GPIO_PIN_WP GPIO_Pin_9 // PB.09 #define I2C_GPIO_AF GPIO_AF_I2C1 -#define I2C_GPIO_PinSource_SCL GPIO_PinSource6 -#define I2C_GPIO_PinSource_SDA GPIO_PinSource7 +#define I2C_SCL_GPIO_PinSource GPIO_PinSource6 +#define I2C_SDA_GPIO_PinSource GPIO_PinSource7 #if defined(REV4a) #define I2C_SPEED 100000 #else diff --git a/radio/src/targets/taranis/i2c_driver.cpp b/radio/src/targets/taranis/i2c_driver.cpp index e6cf932de..760b2fe01 100644 --- a/radio/src/targets/taranis/i2c_driver.cpp +++ b/radio/src/targets/taranis/i2c_driver.cpp @@ -46,10 +46,10 @@ void i2cInit() I2C_Init(I2C, &I2C_InitStructure); I2C_Cmd(I2C, ENABLE); - GPIO_PinAFConfig(I2C_GPIO, I2C_GPIO_PinSource_SCL, I2C_GPIO_AF); - GPIO_PinAFConfig(I2C_GPIO, I2C_GPIO_PinSource_SDA, I2C_GPIO_AF); + GPIO_PinAFConfig(I2C_GPIO, I2C_SCL_GPIO_PinSource, I2C_GPIO_AF); + GPIO_PinAFConfig(I2C_GPIO, I2C_SDA_GPIO_PinSource, I2C_GPIO_AF); - GPIO_InitStructure.GPIO_Pin = I2C_GPIO_PIN_SCL | I2C_GPIO_PIN_SDA; + GPIO_InitStructure.GPIO_Pin = I2C_SCL_GPIO_PIN | I2C_SDA_GPIO_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; diff --git a/radio/src/targets/taranis/pulses_driver.cpp b/radio/src/targets/taranis/pulses_driver.cpp index a877dc544..eae367b0e 100644 --- a/radio/src/targets/taranis/pulses_driver.cpp +++ b/radio/src/targets/taranis/pulses_driver.cpp @@ -1,23 +1,23 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * th9x - http://code.google.com/p/th9x - * er9x - http://code.google.com/p/er9x - * gruvin9x - http://code.google.com/p/gruvin9x - * - * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * 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. - */ - +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + */ + #include "../../opentx.h" void setupPulses(unsigned int port); @@ -194,13 +194,13 @@ static void extmoduleNoneStart() } GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.GPIO_Pin = EXTMODULE_GPIO_PIN; + GPIO_InitStructure.GPIO_Pin = EXTMODULE_PPM_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT ; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(EXTMODULE_GPIO, &GPIO_InitStructure); - GPIO_SetBits(EXTMODULE_GPIO, EXTMODULE_GPIO_PIN); // Set high + GPIO_Init(EXTMODULE_PPM_GPIO, &GPIO_InitStructure); + GPIO_SetBits(EXTMODULE_PPM_GPIO, EXTMODULE_PPM_GPIO_PIN); // Set high EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ; EXTMODULE_TIMER->ARR = 36000 ; // 18mS @@ -230,13 +230,13 @@ static void extmoduleCrossfireStart() EXTERNAL_MODULE_ON(); GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.GPIO_Pin = EXTMODULE_GPIO_PIN; + GPIO_InitStructure.GPIO_Pin = EXTMODULE_PPM_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT ; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(EXTMODULE_GPIO, &GPIO_InitStructure); - GPIO_SetBits(EXTMODULE_GPIO, EXTMODULE_GPIO_PIN); // Set high + GPIO_Init(EXTMODULE_PPM_GPIO, &GPIO_InitStructure); + GPIO_SetBits(EXTMODULE_PPM_GPIO, EXTMODULE_PPM_GPIO_PIN); // Set high EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ; EXTMODULE_TIMER->ARR = 5000 ; // 2.5mS @@ -420,13 +420,13 @@ void extmodulePxxStart() setupPulsesPXX(EXTERNAL_MODULE); GPIO_InitTypeDef GPIO_InitStructure; - GPIO_PinAFConfig(EXTMODULE_GPIO, EXTMODULE_GPIO_PinSource, EXTMODULE_GPIO_AF); - GPIO_InitStructure.GPIO_Pin = EXTMODULE_GPIO_PIN; + GPIO_PinAFConfig(EXTMODULE_PPM_GPIO, EXTMODULE_PPM_GPIO_PinSource, EXTMODULE_PPM_GPIO_AF); + GPIO_InitStructure.GPIO_Pin = EXTMODULE_PPM_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(EXTMODULE_GPIO, &GPIO_InitStructure); + GPIO_Init(EXTMODULE_PPM_GPIO, &GPIO_InitStructure); EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ; EXTMODULE_TIMER->ARR = 18000 ; // 9mS @@ -480,13 +480,13 @@ static void extmoduleDsm2Start() setupPulsesDSM2(EXTERNAL_MODULE); GPIO_InitTypeDef GPIO_InitStructure; - GPIO_PinAFConfig(EXTMODULE_GPIO, EXTMODULE_GPIO_PinSource, EXTMODULE_GPIO_AF); - GPIO_InitStructure.GPIO_Pin = EXTMODULE_GPIO_PIN; + GPIO_PinAFConfig(EXTMODULE_PPM_GPIO, EXTMODULE_PPM_GPIO_PinSource, EXTMODULE_PPM_GPIO_AF); + GPIO_InitStructure.GPIO_Pin = EXTMODULE_PPM_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(EXTMODULE_GPIO, &GPIO_InitStructure); + GPIO_Init(EXTMODULE_PPM_GPIO, &GPIO_InitStructure); EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ; EXTMODULE_TIMER->ARR = 44000 ; // 22mS @@ -541,7 +541,7 @@ static void extmodulePpmStart() EXTERNAL_MODULE_ON(); // Timer1 - configure_pins(EXTMODULE_GPIO_PIN, PIN_PERIPHERAL | PIN_PORTA | PIN_PER_3 | PIN_OS25); + configure_pins(EXTMODULE_PPM_GPIO_PIN, PIN_PERIPHERAL | PIN_PORTA | PIN_PER_3 | PIN_OS25); EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ; // setupPulsesPPM() is also configuring registers, diff --git a/radio/src/targets/taranis/pwr_driver.c b/radio/src/targets/taranis/pwr_driver.c index 21854a568..7cb81186c 100644 --- a/radio/src/targets/taranis/pwr_driver.c +++ b/radio/src/targets/taranis/pwr_driver.c @@ -47,10 +47,10 @@ void pwrInit() GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_Init(INTMODULE_GPIO_PWR, &GPIO_InitStructure); - GPIO_ResetBits(EXTMODULE_GPIO_PWR, EXTMODULE_GPIO_PIN_PWR); - GPIO_InitStructure.GPIO_Pin = EXTMODULE_GPIO_PIN_PWR; + GPIO_ResetBits(EXTMODULE_PWR_GPIO, EXTMODULE_PWR_GPIO_PIN); + GPIO_InitStructure.GPIO_Pin = EXTMODULE_PWR_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_Init(EXTMODULE_GPIO_PWR, &GPIO_InitStructure); + GPIO_Init(EXTMODULE_PWR_GPIO, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = TRAINER_GPIO_PIN_DETECT; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;