[Horus] SD Storage started. UI continued.
+ Some boyscout work on LCD functions
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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"
|
||||
|
||||
#define PIN_ANALOG 0x0003
|
||||
#define PIN_PORTA 0x0000
|
||||
#define PIN_PORTB 0x0100
|
||||
#define PIN_PORTC 0x0200
|
||||
|
||||
// Sample time should exceed 1uS
|
||||
#define SAMPTIME 2 // sample time = 28 cycles
|
||||
|
||||
#if defined(REV9E)
|
||||
const int8_t ana_direction[NUMBER_ANALOG] = {1,1,-1,-1, -1,-1,-1,1, -1,1,1,1, -1};
|
||||
#elif defined(REVPLUS)
|
||||
const int8_t ana_direction[NUMBER_ANALOG] = {1,-1,1,-1, -1,1,-1, -1,1, 1};
|
||||
#elif defined(REV4a)
|
||||
const int8_t ana_direction[NUMBER_ANALOG] = {1,-1,1,-1, -1,-1,0, -1,1, 1};
|
||||
#else
|
||||
const int8_t ana_direction[NUMBER_ANALOG] = {1,-1,1,-1, -1,1,0, -1,1, 1};
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
#define NUMBER_ANALOG_ADC1 10
|
||||
#define NUMBER_ANALOG_ADC3 3
|
||||
// mapping from Analog_values order to enum Analogs
|
||||
const uint8_t ana_mapping[NUMBER_ANALOG] = { 0 /*STICK1*/, 1 /*STICK2*/, 2 /*STICK3*/, 3 /*STICK4*/,
|
||||
10 /*POT1*/, 4 /*POT2*/, 5 /*POT3*/, 6 /*POT4*/,
|
||||
11 /*SLIDER1*/, 12 /*SLIDER2*/, 7 /*SLIDER3*/, 8 /*SLIDER4*/,
|
||||
9 /*TX_VOLTAGE*/ };
|
||||
#else
|
||||
#define NUMBER_ANALOG_ADC1 10
|
||||
#endif
|
||||
|
||||
uint16_t Analog_values[NUMBER_ANALOG] __DMA;
|
||||
|
||||
void adcInit()
|
||||
{
|
||||
#if defined(REV9E)
|
||||
configure_pins(ADC_GPIO_PIN_STICK_RV | ADC_GPIO_PIN_STICK_RH | ADC_GPIO_PIN_STICK_LH | ADC_GPIO_PIN_STICK_LV | ADC_GPIO_PIN_SLIDER3, PIN_ANALOG | PIN_PORTA);
|
||||
configure_pins(ADC_GPIO_PIN_POT2 | ADC_GPIO_PIN_SLIDER4, PIN_ANALOG | PIN_PORTB);
|
||||
configure_pins(ADC_GPIO_PIN_POT3 | ADC_GPIO_PIN_POT4 | ADC_GPIO_PIN_SLIDER1 | ADC_GPIO_PIN_SLIDER2 | ADC_GPIO_PIN_BATT, PIN_ANALOG | PIN_PORTC);
|
||||
configure_pins(ADC_GPIO_PIN_POT1 | ADC_GPIO_PIN_SLIDER1 | ADC_GPIO_PIN_SLIDER2, PIN_ANALOG | PIN_PORTF);
|
||||
#elif defined(REVPLUS)
|
||||
configure_pins(ADC_GPIO_PIN_STICK_RV | ADC_GPIO_PIN_STICK_RH | ADC_GPIO_PIN_STICK_LH | ADC_GPIO_PIN_STICK_LV | ADC_GPIO_PIN_POT1, PIN_ANALOG | PIN_PORTA);
|
||||
configure_pins(ADC_GPIO_PIN_POT2 | ADC_GPIO_PIN_POT3, PIN_ANALOG | PIN_PORTB);
|
||||
configure_pins(ADC_GPIO_PIN_SLIDER1 | ADC_GPIO_PIN_SLIDER2 | ADC_GPIO_PIN_BATT, PIN_ANALOG | PIN_PORTC);
|
||||
#else
|
||||
configure_pins(ADC_GPIO_PIN_STICK_RV | ADC_GPIO_PIN_STICK_RH | ADC_GPIO_PIN_STICK_LH | ADC_GPIO_PIN_STICK_LV | ADC_GPIO_PIN_POT1, PIN_ANALOG | PIN_PORTA);
|
||||
configure_pins(ADC_GPIO_PIN_POT2, PIN_ANALOG|PIN_PORTB);
|
||||
configure_pins(ADC_GPIO_PIN_SLIDER1 | ADC_GPIO_PIN_SLIDER2 | ADC_GPIO_PIN_BATT, PIN_ANALOG | PIN_PORTC);
|
||||
#endif
|
||||
|
||||
ADC1->CR1 = ADC_CR1_SCAN;
|
||||
ADC1->CR2 = ADC_CR2_ADON | ADC_CR2_DMA | ADC_CR2_DDS;
|
||||
ADC1->SQR1 = (NUMBER_ANALOG_ADC1-1) << 20 ; // bits 23:20 = number of conversions
|
||||
#if defined(REV9E)
|
||||
ADC1->SQR2 = (ADC_CHANNEL_POT4<<0) + (ADC_CHANNEL_SLIDER3<<5) + (ADC_CHANNEL_SLIDER4<<10) + (ADC_CHANNEL_BATT<<15); // conversions 7 and more
|
||||
ADC1->SQR3 = (ADC_CHANNEL_STICK_LH<<0) + (ADC_CHANNEL_STICK_LV<<5) + (ADC_CHANNEL_STICK_RV<<10) + (ADC_CHANNEL_STICK_RH<<15) + (ADC_CHANNEL_POT2<<20) + (ADC_CHANNEL_POT3<<25); // conversions 1 to 6
|
||||
#else
|
||||
ADC1->SQR2 = (ADC_CHANNEL_POT3<<0) + (ADC_CHANNEL_SLIDER1<<5) + (ADC_CHANNEL_SLIDER2<<10) + (ADC_CHANNEL_BATT<<15); // conversions 7 and more
|
||||
ADC1->SQR3 = (ADC_CHANNEL_STICK_LH<<0) + (ADC_CHANNEL_STICK_LV<<5) + (ADC_CHANNEL_STICK_RV<<10) + (ADC_CHANNEL_STICK_RH<<15) + (ADC_CHANNEL_POT1<<20) + (ADC_CHANNEL_POT2<<25); // conversions 1 to 6
|
||||
#endif
|
||||
ADC1->SMPR1 = SAMPTIME + (SAMPTIME<<3) + (SAMPTIME<<6) + (SAMPTIME<<9) + (SAMPTIME<<12) + (SAMPTIME<<15) + (SAMPTIME<<18) + (SAMPTIME<<21) + (SAMPTIME<<24);
|
||||
ADC1->SMPR2 = SAMPTIME + (SAMPTIME<<3) + (SAMPTIME<<6) + (SAMPTIME<<9) + (SAMPTIME<<12) + (SAMPTIME<<15) + (SAMPTIME<<18) + (SAMPTIME<<21) + (SAMPTIME<<24) + (SAMPTIME<<27) ;
|
||||
|
||||
ADC->CCR = 0 ; //ADC_CCR_ADCPRE_0 ; // Clock div 2
|
||||
|
||||
DMA2_Stream0->CR = DMA_SxCR_PL | DMA_SxCR_MSIZE_0 | DMA_SxCR_PSIZE_0 | DMA_SxCR_MINC;
|
||||
DMA2_Stream0->PAR = CONVERT_PTR_UINT(&ADC1->DR);
|
||||
DMA2_Stream0->M0AR = CONVERT_PTR_UINT(Analog_values);
|
||||
DMA2_Stream0->NDTR = NUMBER_ANALOG_ADC1;
|
||||
DMA2_Stream0->FCR = DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0 ;
|
||||
|
||||
#if defined(REV9E)
|
||||
ADC3->CR1 = ADC_CR1_SCAN ;
|
||||
ADC3->CR2 = ADC_CR2_ADON | ADC_CR2_DMA | ADC_CR2_DDS ;
|
||||
ADC3->SQR1 = (NUMBER_ANALOG_ADC3-1) << 20 ; // NUMBER_ANALOG Channels
|
||||
ADC3->SQR2 = 0;
|
||||
ADC3->SQR3 = (ADC_CHANNEL_POT1<<0) + (ADC_CHANNEL_SLIDER1<<5) + (ADC_CHANNEL_SLIDER2<<10) ; // conversions 1 to 3
|
||||
ADC3->SMPR1 = SAMPTIME + (SAMPTIME<<3) + (SAMPTIME<<6);
|
||||
ADC3->SMPR2 = 0;
|
||||
|
||||
// Enable the DMA channel here, DMA2 stream 1, channel 2
|
||||
DMA2_Stream1->CR = DMA_SxCR_PL | DMA_SxCR_CHSEL_1 | DMA_SxCR_MSIZE_0 | DMA_SxCR_PSIZE_0 | DMA_SxCR_MINC;
|
||||
DMA2_Stream1->PAR = CONVERT_PTR_UINT(&ADC3->DR);
|
||||
DMA2_Stream1->M0AR = CONVERT_PTR_UINT(Analog_values + NUMBER_ANALOG_ADC1);
|
||||
DMA2_Stream1->NDTR = NUMBER_ANALOG_ADC3;
|
||||
DMA2_Stream1->FCR = DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0 ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void adcRead()
|
||||
{
|
||||
DMA2_Stream0->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
ADC1->SR &= ~(uint32_t) ( ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR ) ;
|
||||
DMA2->LIFCR = DMA_LIFCR_CTCIF0 | DMA_LIFCR_CHTIF0 |DMA_LIFCR_CTEIF0 | DMA_LIFCR_CDMEIF0 | DMA_LIFCR_CFEIF0 ; // Write ones to clear bits
|
||||
DMA2_Stream0->CR |= DMA_SxCR_EN ; // Enable DMA
|
||||
ADC1->CR2 |= (uint32_t)ADC_CR2_SWSTART ;
|
||||
|
||||
#if defined(REV9E)
|
||||
DMA2_Stream1->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
ADC3->SR &= ~(uint32_t) ( ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR ) ;
|
||||
DMA2->LIFCR = DMA_LIFCR_CTCIF1 | DMA_LIFCR_CHTIF1 |DMA_LIFCR_CTEIF1 | DMA_LIFCR_CDMEIF1 | DMA_LIFCR_CFEIF1 ; // Write ones to clear bits
|
||||
DMA2_Stream1->CR |= DMA_SxCR_EN ; // Enable DMA
|
||||
ADC3->CR2 |= (uint32_t)ADC_CR2_SWSTART ;
|
||||
#endif // #if defined(REV9E)
|
||||
|
||||
#if defined(REV9E)
|
||||
for (unsigned int i=0; i<10000; i++) {
|
||||
if ((DMA2->LISR & DMA_LISR_TCIF0) && (DMA2->LISR & DMA_LISR_TCIF1)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
DMA2_Stream0->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
DMA2_Stream1->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
#else
|
||||
for (unsigned int i=0; i<10000; i++) {
|
||||
if (DMA2->LISR & DMA_LISR_TCIF0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
DMA2_Stream0->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
#endif
|
||||
}
|
||||
|
||||
// TODO
|
||||
void adcStop()
|
||||
{
|
||||
}
|
||||
|
||||
uint16_t getAnalogValue(uint32_t index)
|
||||
{
|
||||
if (IS_POT(index) && !IS_POT_AVAILABLE(index)) {
|
||||
// Use fixed analog value for non-existing and/or non-connected pots.
|
||||
// Non-connected analog inputs will slightly follow the adjacent connected analog inputs,
|
||||
// which produces ghost readings on these inputs.
|
||||
return 0;
|
||||
}
|
||||
#if defined(REV9E)
|
||||
index = ana_mapping[index];
|
||||
#endif
|
||||
if (ana_direction[index] < 0)
|
||||
return 4096 - Analog_values[index];
|
||||
else
|
||||
return Analog_values[index];
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file Project/spi/spi.c
|
||||
* @author FrSky Application Team
|
||||
* @Hardware version V0.2
|
||||
* @date 11-July-2012
|
||||
* @brief This file provides spi Init(Analog spi),read and write.
|
||||
driver for LCD.
|
||||
* *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "../Taranis/board_taranis.h"
|
||||
|
||||
/**
|
||||
**********send command to lcd**************
|
||||
*/
|
||||
//hardware spi
|
||||
/*u16 spiCmd(u8 addr)
|
||||
{
|
||||
u8 readValue;
|
||||
|
||||
SPI_RS_LOW();
|
||||
SPI_NCS_LOW();
|
||||
|
||||
SPI_WRITE_BYTE(addr);
|
||||
SPI_WAIT_DONE();
|
||||
|
||||
readValue=SPI_READ_BYTE();
|
||||
SPI_NCS_HIGH();
|
||||
return readValue;
|
||||
}*/
|
||||
|
||||
#if defined(REVPLUS)
|
||||
void AspiCmd(uint8_t Command_Byte)
|
||||
{
|
||||
LCD_A0_LOW() ;
|
||||
LCD_NCS_LOW() ;
|
||||
while ( ( SPI3->SR & SPI_SR_TXE ) == 0 ) {
|
||||
// wait
|
||||
}
|
||||
(void)SPI3->DR ; // Clear receive
|
||||
SPI3->DR = Command_Byte ;
|
||||
while ( ( SPI3->SR & SPI_SR_RXNE ) == 0 ) {
|
||||
// wait
|
||||
}
|
||||
LCD_NCS_HIGH() ;
|
||||
}
|
||||
#else
|
||||
// Analog SPI
|
||||
void AspiCmd(u8 Command_Byte)
|
||||
{
|
||||
int i=8;
|
||||
LCD_A0_LOW();
|
||||
|
||||
LCD_CLK_HIGH();
|
||||
LCD_CLK_HIGH();
|
||||
LCD_NCS_LOW();
|
||||
|
||||
while (i--) {
|
||||
LCD_CLK_LOW();
|
||||
|
||||
if (Command_Byte&0x80)
|
||||
LCD_MOSI_HIGH();
|
||||
else
|
||||
LCD_MOSI_LOW();
|
||||
|
||||
Command_Byte <<= 1;
|
||||
LCD_CLK_LOW(); \
|
||||
LCD_CLK_LOW(); \
|
||||
|
||||
LCD_CLK_HIGH();
|
||||
LCD_CLK_HIGH();
|
||||
}
|
||||
|
||||
LCD_NCS_HIGH();
|
||||
LCD_A0_HIGH();
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
********send data to lcd**************
|
||||
|
||||
*/
|
||||
|
||||
//hardware spi
|
||||
/*
|
||||
u16 spiData(u8 addr)
|
||||
{
|
||||
u16 readValue;
|
||||
OLED_RS_HIGH();
|
||||
SPI_NCS_LOW();
|
||||
|
||||
SPI_WRITE_BYTE(addr);
|
||||
SPI_WAIT_DONE();
|
||||
|
||||
readValue=SPI_READ_BYTE();
|
||||
SPI_NCS_HIGH();
|
||||
return readValue;
|
||||
}
|
||||
*/
|
||||
|
||||
//Anolog spi
|
||||
void AspiData(u8 Para_data)
|
||||
{
|
||||
int i=8;
|
||||
LCD_CLK_HIGH();
|
||||
LCD_CLK_HIGH();
|
||||
LCD_A0_HIGH();
|
||||
LCD_NCS_LOW();
|
||||
while (i--) {
|
||||
LCD_CLK_LOW();
|
||||
if (Para_data&0x80)
|
||||
LCD_MOSI_HIGH();
|
||||
else
|
||||
LCD_MOSI_LOW();
|
||||
Para_data <<= 1;
|
||||
LCD_CLK_LOW();
|
||||
LCD_CLK_LOW();
|
||||
|
||||
LCD_CLK_HIGH();
|
||||
LCD_CLK_HIGH();
|
||||
}
|
||||
LCD_NCS_HIGH();
|
||||
LCD_A0_HIGH();
|
||||
}
|
||||
|
||||
/***
|
||||
**********read one byte in a register*******
|
||||
*/
|
||||
|
||||
/*
|
||||
u16 spiRegAccess(u8 addrByte, u8 writeValue)
|
||||
{
|
||||
u8 readValue;
|
||||
|
||||
SPI_NCS_LOW();
|
||||
|
||||
SPI_WRITE_BYTE(addrByte);
|
||||
SPI_WAIT_DONE();
|
||||
|
||||
SPI_WRITE_BYTE(writeValue);
|
||||
SPI_WAIT_DONE();
|
||||
|
||||
readValue=SPI_READ_BYTE();
|
||||
SPI_NCS_HIGH();
|
||||
return readValue;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file Project/spi/spi.h
|
||||
* @author FrSky Application Team
|
||||
* @Hardware version V0.2
|
||||
* @date 11-July-2012
|
||||
* @brief spi.c' Header file.
|
||||
* *
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef _ASPI_H_
|
||||
#define _ASPI_H_
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define __no_operation __NOP
|
||||
|
||||
#define LCD_NCS_HIGH() LCD_GPIO_NCS->BSRRL = LCD_GPIO_PIN_NCS
|
||||
#define LCD_NCS_LOW() LCD_GPIO_NCS->BSRRH = LCD_GPIO_PIN_NCS
|
||||
|
||||
#define LCD_A0_HIGH() LCD_GPIO_SPI->BSRRL = LCD_GPIO_PIN_A0
|
||||
#define LCD_A0_LOW() LCD_GPIO_SPI->BSRRH = LCD_GPIO_PIN_A0
|
||||
|
||||
#define LCD_RST_HIGH() LCD_GPIO_RST->BSRRL = LCD_GPIO_PIN_RST
|
||||
#define LCD_RST_LOW() LCD_GPIO_RST->BSRRH = LCD_GPIO_PIN_RST
|
||||
|
||||
#define LCD_CLK_HIGH() LCD_GPIO_SPI->BSRRL = LCD_GPIO_PIN_CLK
|
||||
#define LCD_CLK_LOW() LCD_GPIO_SPI->BSRRH = LCD_GPIO_PIN_CLK
|
||||
|
||||
#define LCD_MOSI_HIGH() LCD_GPIO_SPI->BSRRL = LCD_GPIO_PIN_MOSI
|
||||
#define LCD_MOSI_LOW() LCD_GPIO_SPI->BSRRH = LCD_GPIO_PIN_MOSI
|
||||
|
||||
void AspiCmd(u8 Command_Byte);
|
||||
void AspiData(u8 Para_data);
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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] =
|
||||
{
|
||||
0, 1, 2, 3, 5, 9, 13, 17, 22, 27, 33, 40,
|
||||
64, 82, 96, 105, 112, 117, 120, 122, 124, 125, 126, 127
|
||||
};
|
||||
|
||||
#if !defined(SIMU)
|
||||
bool dacIdle = true;
|
||||
|
||||
void setSampleRate(uint32_t frequency)
|
||||
{
|
||||
register uint32_t timer = (PERI1_FREQUENCY * TIMER_MULT_APB1) / frequency - 1 ; // MCK/8 and 100 000 Hz
|
||||
|
||||
TIM6->CR1 &= ~TIM_CR1_CEN ;
|
||||
TIM6->CNT = 0 ;
|
||||
TIM6->ARR = limit<uint32_t>(2, timer, 65535) ;
|
||||
TIM6->CR1 |= TIM_CR1_CEN ;
|
||||
}
|
||||
|
||||
// Start TIMER6 at 100000Hz, used for DAC trigger
|
||||
void dacTimerInit()
|
||||
{
|
||||
// Now for timer 6
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN ; // Enable clock
|
||||
|
||||
TIM6->PSC = 0 ; // Max speed
|
||||
TIM6->ARR = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 100000 - 1 ; // 10 uS, 100 kHz
|
||||
TIM6->CR2 = 0 ;
|
||||
TIM6->CR2 = 0x20 ;
|
||||
TIM6->CR1 = TIM_CR1_CEN ;
|
||||
}
|
||||
|
||||
// Configure DAC0 (or DAC1 for REVA)
|
||||
// Not sure why PB14 has not be allocated to the DAC, although it is an EXTRA function
|
||||
// So maybe it is automatically done
|
||||
void dacInit()
|
||||
{
|
||||
dacTimerInit();
|
||||
|
||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN ; // Enable portA clock
|
||||
configure_pins( GPIO_Pin_4, PIN_ANALOG | PIN_PORTA ) ;
|
||||
RCC->APB1ENR |= RCC_APB1ENR_DACEN ; // Enable clock
|
||||
RCC->AHB1ENR |= RCC_AHB1ENR_DMA1EN ; // Enable DMA1 clock
|
||||
|
||||
// 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(TIM6_DAC_IRQn); // TODO needed?
|
||||
NVIC_SetPriority(TIM6_DAC_IRQn, 7);
|
||||
NVIC_EnableIRQ(DMA1_Stream5_IRQn);
|
||||
NVIC_SetPriority(DMA1_Stream5_IRQn, 7);
|
||||
}
|
||||
|
||||
bool dacQueue(AudioBuffer *buffer)
|
||||
{
|
||||
if (dacIdle) {
|
||||
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
|
||||
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 ;
|
||||
TIM6->CR1 = 0 ;
|
||||
// Also need to turn off any possible interrupts
|
||||
NVIC_DisableIRQ(TIM6_DAC_IRQn) ;
|
||||
NVIC_DisableIRQ(DMA1_Stream5_IRQn) ;
|
||||
}
|
||||
|
||||
extern "C" void TIM6_DAC_IRQHandler()
|
||||
{
|
||||
DAC->CR &= ~DAC_CR_DMAEN1 ; // Stop DMA requests
|
||||
#if !defined(REV9E)
|
||||
DAC->CR &= ~DAC_CR_DMAUDRIE1 ; // Stop underrun interrupt
|
||||
#endif
|
||||
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)
|
||||
@@ -0,0 +1,232 @@
|
||||
/**
|
||||
* @file bluetooth_driver.c
|
||||
* @version V1.0.0
|
||||
* @date 2014-11-10
|
||||
* @brief bluetooth driver for Tananis.
|
||||
* @author - Adela
|
||||
* - Robert Zhang <armner@gmail.com>
|
||||
* -
|
||||
*/
|
||||
|
||||
#include "string.h"
|
||||
#include "../../fifo.h"
|
||||
#include "../Taranis/board_taranis.h"
|
||||
|
||||
Fifo<64> btTxFifo;
|
||||
Fifo<64> btRxFifo;
|
||||
|
||||
enum BluetoothState
|
||||
{
|
||||
BLUETOOTH_INIT,
|
||||
BLUETOOTH_WAIT_TTM,
|
||||
BLUETOOTH_WAIT_BAUDRATE_CHANGE,
|
||||
BLUETOOTH_OK,
|
||||
};
|
||||
|
||||
enum BluetoothWriteState
|
||||
{
|
||||
BLUETOOTH_WRITE_IDLE,
|
||||
BLUETOOTH_WRITE_INIT,
|
||||
BLUETOOTH_WRITING,
|
||||
BLUETOOTH_WRITE_DONE
|
||||
};
|
||||
|
||||
volatile uint8_t bluetoothState = BLUETOOTH_INIT;
|
||||
volatile uint8_t bluetoothWriteState = BLUETOOTH_WRITE_IDLE;
|
||||
|
||||
void bluetoothInit(uint32_t baudrate)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
|
||||
USART_DeInit(BT_USART);
|
||||
|
||||
RCC_AHB1PeriphClockCmd(BT_RCC_AHB1Periph, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = BT_GPIO_PIN_BRTS;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(BT_GPIO_BRTS, &GPIO_InitStructure);
|
||||
GPIO_SetBits(BT_GPIO_BRTS, BT_GPIO_PIN_BRTS);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = BT_GPIO_PIN_EN;
|
||||
GPIO_Init(BT_GPIO_EN, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = BT_GPIO_PIN_BCTS;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_Init(BT_GPIO_BCTS, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = BT_GPIO_PIN_TX|BT_GPIO_PIN_RX;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_Init(BT_GPIO_TXRX, &GPIO_InitStructure);
|
||||
|
||||
GPIO_PinAFConfig(BT_GPIO_TXRX, BT_GPIO_PinSource_TX, BT_GPIO_AF);
|
||||
GPIO_PinAFConfig(BT_GPIO_TXRX, BT_GPIO_PinSource_RX, BT_GPIO_AF);
|
||||
|
||||
USART_DeInit(BT_USART);
|
||||
USART_InitStructure.USART_BaudRate = baudrate;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
||||
USART_Init(BT_USART, &USART_InitStructure);
|
||||
|
||||
USART_Cmd(BT_USART, ENABLE);
|
||||
USART_ITConfig(BT_USART, USART_IT_RXNE, ENABLE);
|
||||
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = BT_USART_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
GPIO_ResetBits(BT_GPIO_EN, BT_GPIO_PIN_EN); // open bluetooth
|
||||
}
|
||||
|
||||
void bluetoothDone()
|
||||
{
|
||||
GPIO_SetBits(BT_GPIO_EN, BT_GPIO_PIN_EN); // close bluetooth
|
||||
}
|
||||
|
||||
extern "C" void USART6_IRQHandler(void)
|
||||
{
|
||||
if (USART_GetITStatus(BT_USART, USART_IT_RXNE) != RESET) {
|
||||
USART_ClearITPendingBit(BT_USART, USART_IT_RXNE);
|
||||
uint8_t byte = USART_ReceiveData(BT_USART);
|
||||
btRxFifo.push(byte);
|
||||
}
|
||||
|
||||
if (USART_GetITStatus(BT_USART, USART_IT_TXE) != RESET) {
|
||||
uint8_t byte;
|
||||
bool result = btTxFifo.pop(byte);
|
||||
if (result) {
|
||||
USART_SendData(BT_USART, byte);
|
||||
}
|
||||
else {
|
||||
USART_ITConfig(BT_USART, USART_IT_TXE, DISABLE);
|
||||
bluetoothWriteState = BLUETOOTH_WRITE_DONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bluetoothWrite(const void * buffer, int len)
|
||||
{
|
||||
uint8_t * data = (uint8_t *)buffer;
|
||||
for (int i=0; i<len; ++i) {
|
||||
btTxFifo.push(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void bluetoothWriteString(const char * str)
|
||||
{
|
||||
while (*str != 0) {
|
||||
btTxFifo.push(*str++);
|
||||
}
|
||||
}
|
||||
|
||||
void bluetoothWriteWakeup(void)
|
||||
{
|
||||
if (bluetoothWriteState == BLUETOOTH_WRITE_IDLE) {
|
||||
if (!btTxFifo.isEmpty()) {
|
||||
bluetoothWriteState = BLUETOOTH_WRITE_INIT;
|
||||
GPIO_ResetBits(BT_GPIO_BRTS, BT_GPIO_PIN_BRTS);
|
||||
}
|
||||
}
|
||||
else if (bluetoothWriteState == BLUETOOTH_WRITE_INIT) {
|
||||
bluetoothWriteState = BLUETOOTH_WRITING;
|
||||
USART_ITConfig(BT_USART, USART_IT_TXE, ENABLE);
|
||||
}
|
||||
else if (bluetoothWriteState == BLUETOOTH_WRITE_DONE) {
|
||||
bluetoothWriteState = BLUETOOTH_WRITE_IDLE;
|
||||
GPIO_SetBits(BT_GPIO_BRTS, BT_GPIO_PIN_BRTS);
|
||||
}
|
||||
}
|
||||
|
||||
void bluetoothWakeup(void)
|
||||
{
|
||||
if (!g_eeGeneral.bluetoothEnable) {
|
||||
if (bluetoothState != BLUETOOTH_INIT) {
|
||||
bluetoothDone();
|
||||
bluetoothState = BLUETOOTH_INIT;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (bluetoothState != BLUETOOTH_OK) {
|
||||
static tmr10ms_t waitEnd = 0;
|
||||
|
||||
if (bluetoothState == BLUETOOTH_INIT) {
|
||||
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE);
|
||||
const char btMessage[] = "TTM:REN-";
|
||||
bluetoothWriteString(btMessage);
|
||||
uint8_t len = ZLEN(g_eeGeneral.bluetoothName);
|
||||
for (int i=0; i<len; i++) {
|
||||
btTxFifo.push(idx2char(g_eeGeneral.bluetoothName[i]));
|
||||
}
|
||||
bluetoothState = BLUETOOTH_WAIT_TTM;
|
||||
waitEnd = get_tmr10ms() + 25; // 250ms
|
||||
}
|
||||
else if (bluetoothState == BLUETOOTH_WAIT_TTM) {
|
||||
if (get_tmr10ms() > waitEnd) {
|
||||
char ttm[] = "TTM:REN";
|
||||
int index = 0;
|
||||
uint8_t c;
|
||||
bool found = false;
|
||||
while (btRxFifo.pop(c)) {
|
||||
if (c == ttm[index]) {
|
||||
index++;
|
||||
if (index == sizeof(ttm)-1) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
bluetoothState = BLUETOOTH_OK;
|
||||
}
|
||||
else {
|
||||
bluetoothInit(BLUETOOTH_FACTORY_BAUDRATE);
|
||||
const char btMessage[] = "TTM:BPS-115200";
|
||||
bluetoothWriteString(btMessage);
|
||||
bluetoothState = BLUETOOTH_WAIT_BAUDRATE_CHANGE;
|
||||
waitEnd = get_tmr10ms() + 250; // 2.5s
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (bluetoothState == BLUETOOTH_WAIT_BAUDRATE_CHANGE) {
|
||||
if (get_tmr10ms() > waitEnd) {
|
||||
bluetoothState = BLUETOOTH_INIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bluetoothWriteWakeup();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t bluetoothReady()
|
||||
{
|
||||
return (bluetoothState == BLUETOOTH_OK);
|
||||
}
|
||||
|
||||
int bluetoothRead(void * buffer, int len)
|
||||
{
|
||||
int result = 0;
|
||||
uint8_t * data = (uint8_t *)buffer;
|
||||
while (result < len) {
|
||||
uint8_t byte;
|
||||
if (!btRxFifo.pop(byte)) {
|
||||
break;
|
||||
}
|
||||
data[result++] = byte;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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"
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h"
|
||||
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_bsp.h"
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
}
|
||||
#endif
|
||||
|
||||
void watchdogInit(unsigned int duration)
|
||||
{
|
||||
IWDG->KR = 0x5555 ; // Unlock registers
|
||||
IWDG->PR = 3 ; // Divide by 32 => 1kHz clock
|
||||
IWDG->KR = 0x5555 ; // Unlock registers
|
||||
IWDG->RLR = duration ; // 1.5 seconds nominal
|
||||
IWDG->KR = 0xAAAA ; // reload
|
||||
IWDG->KR = 0xCCCC ; // start
|
||||
}
|
||||
|
||||
// Starts TIMER at 2MHz
|
||||
void init2MhzTimer()
|
||||
{
|
||||
TIMER_2MHz_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 2000000 - 1 ; // 0.5 uS, 2 MHz
|
||||
TIMER_2MHz_TIMER->ARR = 65535;
|
||||
TIMER_2MHz_TIMER->CR2 = 0;
|
||||
TIMER_2MHz_TIMER->CR1 = TIM_CR1_CEN;
|
||||
}
|
||||
|
||||
// Starts TIMER at 200Hz (5ms)
|
||||
void init5msTimer()
|
||||
{
|
||||
INTERRUPT_5MS_TIMER->ARR = 4999 ; // 5mS
|
||||
INTERRUPT_5MS_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 1000000 - 1 ; // 1uS from 30MHz
|
||||
INTERRUPT_5MS_TIMER->CCER = 0 ;
|
||||
INTERRUPT_5MS_TIMER->CCMR1 = 0 ;
|
||||
INTERRUPT_5MS_TIMER->EGR = 0 ;
|
||||
INTERRUPT_5MS_TIMER->CR1 = 5 ;
|
||||
INTERRUPT_5MS_TIMER->DIER |= 1 ;
|
||||
NVIC_EnableIRQ(INTERRUPT_5MS_IRQn) ;
|
||||
NVIC_SetPriority(INTERRUPT_5MS_IRQn, 7);
|
||||
}
|
||||
|
||||
void stop5msTimer( void )
|
||||
{
|
||||
INTERRUPT_5MS_TIMER->CR1 = 0 ; // stop timer
|
||||
NVIC_DisableIRQ(INTERRUPT_5MS_IRQn) ;
|
||||
}
|
||||
|
||||
// TODO use the same than board_sky9x.cpp
|
||||
void interrupt5ms()
|
||||
{
|
||||
static uint32_t pre_scale ; // Used to get 10 Hz counter
|
||||
|
||||
AUDIO_HEARTBEAT();
|
||||
|
||||
#if defined(HAPTIC)
|
||||
HAPTIC_HEARTBEAT();
|
||||
#endif
|
||||
|
||||
if ( ++pre_scale >= 2 ) {
|
||||
pre_scale = 0 ;
|
||||
per10ms();
|
||||
}
|
||||
|
||||
#if defined(REV9E)
|
||||
checkRotaryEncoder();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" void INTERRUPT_5MS_IRQHandler()
|
||||
{
|
||||
INTERRUPT_5MS_TIMER->SR &= ~TIM_SR_UIF ;
|
||||
interrupt5ms() ;
|
||||
}
|
||||
|
||||
#if defined(REV9E)
|
||||
#define PWR_PRESS_DURATION_MIN 200 // 2s
|
||||
#define PWR_PRESS_DURATION_MAX 500 // 5s
|
||||
|
||||
const pm_uchar bmp_startup[] PROGMEM = {
|
||||
#include "../../bitmaps/Taranis/startup.lbm"
|
||||
};
|
||||
|
||||
const pm_uchar bmp_lock[] PROGMEM = {
|
||||
#include "../../bitmaps/Taranis/lock.lbm"
|
||||
};
|
||||
#endif
|
||||
|
||||
void boardInit()
|
||||
{
|
||||
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | KEYS_RCC_AHB1Periph | LCD_RCC_AHB1Periph | BACKLIGHT_RCC_AHB1Periph | ADC_RCC_AHB1Periph | I2C_RCC_AHB1Periph | SD_RCC_AHB1Periph | HAPTIC_RCC_AHB1Periph | INTMODULE_RCC_AHB1Periph | EXTMODULE_RCC_AHB1Periph | TELEMETRY_RCC_AHB1Periph | SERIAL_RCC_AHB1Periph | TRAINER_RCC_AHB1Periph | HEARTBEAT_RCC_AHB1Periph, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(LCD_RCC_APB1Periph | BACKLIGHT_RCC_APB1Periph | INTERRUPT_5MS_APB1Periph | TIMER_2MHz_APB1Periph | I2C_RCC_APB1Periph | SD_RCC_APB1Periph | TRAINER_RCC_APB1Periph | TELEMETRY_RCC_APB1Periph | SERIAL_RCC_APB1Periph, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(BACKLIGHT_RCC_APB2Periph | ADC_RCC_APB2Periph | HAPTIC_RCC_APB2Periph | INTMODULE_RCC_APB2Periph | EXTMODULE_RCC_APB2Periph | HEARTBEAT_RCC_APB2Periph, ENABLE);
|
||||
|
||||
pwrInit();
|
||||
keysInit();
|
||||
adcInit();
|
||||
delaysInit();
|
||||
lcdInit(); // delaysInit() must be called before
|
||||
audioInit();
|
||||
init2MhzTimer();
|
||||
init5msTimer();
|
||||
__enable_irq();
|
||||
i2cInit();
|
||||
usbInit();
|
||||
|
||||
#if defined(HAPTIC)
|
||||
hapticInit();
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE);
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG)
|
||||
DBGMCU_APB1PeriphConfig(DBGMCU_IWDG_STOP|DBGMCU_TIM1_STOP|DBGMCU_TIM2_STOP|DBGMCU_TIM3_STOP|DBGMCU_TIM6_STOP|DBGMCU_TIM8_STOP|DBGMCU_TIM10_STOP|DBGMCU_TIM13_STOP|DBGMCU_TIM14_STOP, ENABLE);
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
if (!WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
|
||||
lcd_clear();
|
||||
lcd_bmp(76, 2, bmp_lock, 0, 60);
|
||||
lcdRefresh();
|
||||
lcdRefreshWait();
|
||||
|
||||
tmr10ms_t start = get_tmr10ms();
|
||||
tmr10ms_t duration = 0;
|
||||
uint8_t pwr_on = 0;
|
||||
while (pwrPressed()) {
|
||||
duration = get_tmr10ms() - start;
|
||||
if (duration < PWR_PRESS_DURATION_MIN) {
|
||||
unsigned index = duration / (PWR_PRESS_DURATION_MIN / 4);
|
||||
lcd_clear();
|
||||
lcd_bmp(76, 2, bmp_startup, index*60, 60);
|
||||
}
|
||||
else if (duration >= PWR_PRESS_DURATION_MAX) {
|
||||
displaySleepBitmap();
|
||||
turnBacklightOff();
|
||||
}
|
||||
else {
|
||||
if (pwr_on != 1) {
|
||||
pwr_on = 1;
|
||||
backlightInit();
|
||||
haptic.play(15, 3, PLAY_NOW);
|
||||
}
|
||||
}
|
||||
lcdRefresh();
|
||||
lcdRefreshWait();
|
||||
}
|
||||
if (duration < PWR_PRESS_DURATION_MIN || duration >= PWR_PRESS_DURATION_MAX) {
|
||||
boardOff();
|
||||
}
|
||||
}
|
||||
else {
|
||||
backlightInit();
|
||||
}
|
||||
topLcdInit();
|
||||
#else
|
||||
backlightInit();
|
||||
#endif
|
||||
}
|
||||
|
||||
void boardOff()
|
||||
{
|
||||
BACKLIGHT_OFF();
|
||||
#if defined(REV9E)
|
||||
topLcdOff();
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
while (pwrPressed()) {
|
||||
wdt_reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
lcdOff();
|
||||
SysTick->CTRL = 0; // turn off systick
|
||||
pwrOff();
|
||||
}
|
||||
|
||||
#endif // #if !defined(SIMU)
|
||||
|
||||
|
||||
#if defined(USB_JOYSTICK) && !defined(SIMU)
|
||||
extern USB_OTG_CORE_HANDLE USB_OTG_dev;
|
||||
|
||||
/*
|
||||
Prepare and send new USB data packet
|
||||
|
||||
The format of HID_Buffer is defined by
|
||||
USB endpoint description can be found in
|
||||
file usb_hid_joystick.c, variable HID_JOYSTICK_ReportDesc
|
||||
*/
|
||||
void usbJoystickUpdate(void)
|
||||
{
|
||||
static uint8_t HID_Buffer[HID_IN_PACKET];
|
||||
|
||||
//buttons
|
||||
HID_Buffer[0] = 0; //buttons
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
if ( channelOutputs[i+8] > 0 ) {
|
||||
HID_Buffer[0] |= (1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
//analog values
|
||||
//uint8_t * p = HID_Buffer + 1;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
int16_t value = channelOutputs[i] / 8;
|
||||
if ( value > 127 ) value = 127;
|
||||
else if ( value < -127 ) value = -127;
|
||||
HID_Buffer[i+1] = static_cast<int8_t>(value);
|
||||
}
|
||||
|
||||
USBD_HID_SendReport (&USB_OTG_dev, HID_Buffer, HID_IN_PACKET );
|
||||
}
|
||||
|
||||
#endif //#if defined(USB_JOYSTICK) && defined(PCBTARANIS) && !defined(SIMU)
|
||||
|
||||
|
||||
uint8_t currentTrainerMode = 0xff;
|
||||
|
||||
void checkTrainerSettings()
|
||||
{
|
||||
uint8_t requiredTrainerMode = g_model.trainerMode;
|
||||
if (requiredTrainerMode != currentTrainerMode) {
|
||||
switch (currentTrainerMode) {
|
||||
case TRAINER_MODE_MASTER:
|
||||
stop_trainer_capture();
|
||||
break;
|
||||
case TRAINER_MODE_SLAVE:
|
||||
stop_trainer_ppm();
|
||||
break;
|
||||
case TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE:
|
||||
stop_cppm_on_heartbeat_capture() ;
|
||||
break;
|
||||
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
|
||||
stop_sbus_on_heartbeat_capture() ;
|
||||
break;
|
||||
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
|
||||
serial2Stop();
|
||||
}
|
||||
|
||||
currentTrainerMode = requiredTrainerMode;
|
||||
switch (requiredTrainerMode) {
|
||||
case TRAINER_MODE_SLAVE:
|
||||
init_trainer_ppm();
|
||||
break;
|
||||
case TRAINER_MODE_MASTER_CPPM_EXTERNAL_MODULE:
|
||||
init_cppm_on_heartbeat_capture() ;
|
||||
break;
|
||||
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
|
||||
init_sbus_on_heartbeat_capture() ;
|
||||
break;
|
||||
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
|
||||
if (g_eeGeneral.serial2Mode == UART_MODE_SBUS_TRAINER) {
|
||||
serial2SbusInit();
|
||||
break;
|
||||
}
|
||||
// no break
|
||||
default:
|
||||
// master is default
|
||||
init_trainer_capture();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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 _BOARD_TARANIS_H_
|
||||
#define _BOARD_TARANIS_H_
|
||||
|
||||
#include "stddef.h"
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_rcc.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_gpio.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_adc.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_spi.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_i2c.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_rtc.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_pwr.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_dma.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_usart.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_flash.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_dbgmcu.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/misc.h"
|
||||
#else
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_rcc.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_gpio.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_adc.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_spi.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_i2c.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_rtc.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_pwr.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_dma.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_usart.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_flash.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_dbgmcu.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/misc.h"
|
||||
#endif
|
||||
|
||||
#if !defined(SIMU)
|
||||
#include "usbd_cdc_core.h"
|
||||
#include "usbd_msc_core.h"
|
||||
#include "usbd_hid_core.h"
|
||||
#include "usbd_usr.h"
|
||||
#include "../Taranis/usbd_desc.h"
|
||||
#include "../Taranis/usb_conf.h"
|
||||
#include "../Taranis/usbd_conf.h"
|
||||
#endif
|
||||
|
||||
#include "../Taranis/hal.h"
|
||||
#include "../Taranis/aspi.h"
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
}
|
||||
#endif
|
||||
|
||||
#define FLASHSIZE 0x80000
|
||||
#define BOOTLOADER_SIZE 0x8000
|
||||
#define FIRMWARE_ADDRESS 0x08000000
|
||||
|
||||
#if defined(REV9E)
|
||||
#define PERI1_FREQUENCY 42000000
|
||||
#define PERI2_FREQUENCY 84000000
|
||||
#else
|
||||
#define PERI1_FREQUENCY 30000000
|
||||
#define PERI2_FREQUENCY 60000000
|
||||
#endif
|
||||
|
||||
#define TIMER_MULT_APB1 2
|
||||
#define TIMER_MULT_APB2 2
|
||||
|
||||
#define PIN_MODE_MASK 0x0003
|
||||
#define PIN_INPUT 0x0000
|
||||
#define PIN_OUTPUT 0x0001
|
||||
#define PIN_PERIPHERAL 0x0002
|
||||
#define PIN_ANALOG 0x0003
|
||||
|
||||
#define PIN_PULL_MASK 0x000C
|
||||
#define PIN_PULLUP 0x0004
|
||||
|
||||
#define PIN_PORT_MASK 0x0700
|
||||
#define PIN_PORTA 0x0000
|
||||
#define PIN_PORTB 0x0100
|
||||
#define PIN_PORTC 0x0200
|
||||
#define PIN_PORTD 0x0300
|
||||
#define PIN_PORTE 0x0400
|
||||
#define PIN_PORTF 0x0500
|
||||
|
||||
#define PIN_PERI_MASK 0x00F0
|
||||
#define PIN_PER_1 0x0010
|
||||
#define PIN_PER_2 0x0020
|
||||
#define PIN_PER_3 0x0030
|
||||
#define PIN_PER_5 0x0050
|
||||
#define PIN_PER_6 0x0060
|
||||
#define PIN_PER_8 0x0080
|
||||
|
||||
#define PIN_SPEED_MASK 0x6000
|
||||
#define PIN_OS25 0x2000
|
||||
#define PIN_OS50 0x4000
|
||||
#define PIN_OS100 0x6000
|
||||
|
||||
void configure_pins( uint32_t pins, uint16_t config );
|
||||
|
||||
#define strcpy_P strcpy
|
||||
#define strcat_P strcat
|
||||
|
||||
extern uint16_t sessionTimer;
|
||||
|
||||
#define SLAVE_MODE() (g_model.trainerMode == TRAINER_MODE_SLAVE)
|
||||
#define TRAINER_CONNECTED() (GPIO_ReadInputDataBit(TRAINER_GPIO_DETECT, TRAINER_GPIO_PIN_DETECT) == Bit_RESET)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void delaysInit(void);
|
||||
void delay_01us(uint16_t nb);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// SD driver
|
||||
#if !defined(SIMU) || defined(SIMU_DISKIO)
|
||||
uint32_t sdIsHC(void);
|
||||
uint32_t sdGetSpeed(void);
|
||||
#define SD_IS_HC() (sdIsHC())
|
||||
#define SD_GET_SPEED() (sdGetSpeed())
|
||||
#define SD_GET_FREE_BLOCKNR() (sdGetFreeSectors())
|
||||
#else
|
||||
#define SD_IS_HC() (0)
|
||||
#define SD_GET_SPEED() (0)
|
||||
#endif
|
||||
|
||||
#if defined(SIMU)
|
||||
#define sdInit()
|
||||
#define sdDone()
|
||||
#else
|
||||
void sdInit(void);
|
||||
void sdDone(void);
|
||||
void sdPoll10ms(void);
|
||||
#define sdMountPoll()
|
||||
uint32_t sdMounted(void);
|
||||
#define SD_CARD_PRESENT() (~SD_GPIO_PRESENT->IDR & SD_GPIO_PIN_PRESENT)
|
||||
#endif
|
||||
|
||||
// Flash Write driver
|
||||
#define FLASH_PAGESIZE 256
|
||||
void unlockFlash(void);
|
||||
void lockFlash(void);
|
||||
void writeFlash(uint32_t * address, uint32_t * buffer);
|
||||
uint32_t isFirmwareStart(const void * buffer);
|
||||
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 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)
|
||||
void init_no_pulses(uint32_t port);
|
||||
void disable_no_pulses(uint32_t port);
|
||||
void init_ppm( uint32_t module_index );
|
||||
void disable_ppm( uint32_t module_index );
|
||||
void set_external_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive);
|
||||
#if defined(TARANIS_INTERNAL_PPM)
|
||||
void set_internal_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive);
|
||||
#endif
|
||||
void init_pxx( uint32_t module_index );
|
||||
void disable_pxx( uint32_t module_index );
|
||||
void init_dsm2( uint32_t module_index );
|
||||
void disable_dsm2( uint32_t module_index );
|
||||
|
||||
// Trainer driver
|
||||
void init_trainer_ppm(void);
|
||||
void stop_trainer_ppm(void);
|
||||
void init_trainer_capture(void);
|
||||
void stop_trainer_capture(void);
|
||||
void init_cppm_on_heartbeat_capture(void);
|
||||
void stop_cppm_on_heartbeat_capture(void);
|
||||
void init_sbus_on_heartbeat_capture(void);
|
||||
void stop_sbus_on_heartbeat_capture(void);
|
||||
void set_trainer_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive);
|
||||
|
||||
// Keys driver
|
||||
void keysInit(void);
|
||||
uint32_t readKeys(void);
|
||||
uint32_t readTrims(void);
|
||||
#define TRIMS_PRESSED() (readTrims())
|
||||
#define KEYS_PRESSED() (readKeys())
|
||||
|
||||
#if defined(REV9E)
|
||||
// Rotary Encoder driver
|
||||
void rotencInit(void);
|
||||
void rotencEnd(void);
|
||||
void checkRotaryEncoder(void);
|
||||
#endif
|
||||
|
||||
// WDT driver
|
||||
#if !defined(SIMU)
|
||||
#define wdt_disable()
|
||||
void watchdogInit(unsigned int duration);
|
||||
#define wdt_enable(x) watchdogInit(1500)
|
||||
#define wdt_reset() IWDG->KR = 0xAAAA
|
||||
#define WAS_RESET_BY_SOFTWARE() (RCC->CSR & RCC_CSR_SFTRSTF)
|
||||
#define WAS_RESET_BY_WATCHDOG() (RCC->CSR & (RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF))
|
||||
#define WAS_RESET_BY_WATCHDOG_OR_SOFTWARE() (RCC->CSR & (RCC_CSR_WDGRSTF | RCC_CSR_WWDGRSTF | RCC_CSR_SFTRSTF))
|
||||
#endif
|
||||
|
||||
// ADC driver
|
||||
void adcInit(void);
|
||||
void adcRead(void);
|
||||
inline uint16_t getAnalogValue(uint32_t value);
|
||||
|
||||
#define BATT_SCALE 150
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Power driver
|
||||
void pwrInit(void);
|
||||
uint32_t pwrCheck(void);
|
||||
void pwrOn(void);
|
||||
void pwrOff(void);
|
||||
#if defined(REV9E)
|
||||
uint32_t pwrPressed(void);
|
||||
uint32_t pwrPressedDuration(void);
|
||||
#endif
|
||||
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
|
||||
|
||||
// Backlight driver
|
||||
void backlightInit(void);
|
||||
#if defined(REVPLUS)
|
||||
void turnBacklightOn(uint8_t level, uint8_t color);
|
||||
void turnBacklightOff(void);
|
||||
#define setBacklight(xx) turnBacklightOn(xx, g_eeGeneral.backlightColor)
|
||||
#define backlightEnable() turnBacklightOn(g_eeGeneral.backlightBright, g_eeGeneral.backlightColor)
|
||||
#define backlightDisable() turnBacklightOff()
|
||||
#define isBacklightEnable() ((BACKLIGHT_TIMER->CCR4 != 0) || (BACKLIGHT_TIMER->CCR2 != 0))
|
||||
#else
|
||||
#define setBacklight(xx) BACKLIGHT_TIMER->CCR1 = 100-xx
|
||||
#define backlightEnable() BACKLIGHT_TIMER->CCR1 = 100-g_eeGeneral.backlightBright
|
||||
#define backlightDisable() BACKLIGHT_TIMER->CCR1 = 0
|
||||
#define isBacklightEnable() (BACKLIGHT_TIMER->CCR1 != 0)
|
||||
#endif
|
||||
|
||||
// USB driver
|
||||
int usbPlugged(void);
|
||||
void usbInit(void);
|
||||
void usbDeInit(void);
|
||||
void usbSerialPutc(uint8_t c);
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
}
|
||||
#endif
|
||||
|
||||
// I2C driver: EEPROM + Audio Volume
|
||||
void i2cInit(void);
|
||||
void eepromReadBlock(uint8_t * buffer, uint32_t address, uint32_t size);
|
||||
void eepromWriteBlock(uint8_t * buffer, uint32_t address, uint32_t size);
|
||||
|
||||
// Debug driver
|
||||
void debugPutc(const char c);
|
||||
|
||||
// Telemetry driver
|
||||
void telemetryPortInit(uint32_t baudrate);
|
||||
void sportSendBuffer(uint8_t *buffer, uint32_t count);
|
||||
|
||||
// Audio driver
|
||||
void audioInit(void) ;
|
||||
void audioEnd(void) ;
|
||||
void dacStart(void);
|
||||
void dacStop(void);
|
||||
void setSampleRate(uint32_t frequency);
|
||||
extern const int8_t volumeScale[];
|
||||
#define VOLUME_LEVEL_MAX 23
|
||||
#define VOLUME_LEVEL_DEF 12
|
||||
void setVolume(uint8_t volume);
|
||||
|
||||
// Haptic driver
|
||||
void hapticInit(void);
|
||||
void hapticOff(void);
|
||||
#if defined(REVPLUS)
|
||||
void hapticOn(uint32_t pwmPercent);
|
||||
#else
|
||||
void hapticOn(void);
|
||||
#endif
|
||||
|
||||
// Second serial port driver
|
||||
#define DEBUG_BAUDRATE 115200
|
||||
void serial2Init(unsigned int mode, unsigned int protocol);
|
||||
void serial2Putc(char c);
|
||||
#define serial2TelemetryInit(protocol) serial2Init(UART_MODE_TELEMETRY, protocol)
|
||||
void serial2SbusInit(void);
|
||||
void serial2Stop(void);
|
||||
|
||||
// BT driver
|
||||
#define BLUETOOTH_DEFAULT_BAUDRATE 115200
|
||||
#define BLUETOOTH_FACTORY_BAUDRATE 9600
|
||||
uint8_t bluetoothReady(void);
|
||||
void bluetoothInit(uint32_t baudrate);
|
||||
void bluetoothWrite(const void * buffer, int len);
|
||||
void bluetoothWriteString(const char * str);
|
||||
int bluetoothRead(void * buffer, int len);
|
||||
void bluetoothWakeup(void);
|
||||
|
||||
// LCD driver
|
||||
void lcdInit(void);
|
||||
void lcdInitFinish(void);
|
||||
void lcdOff(void);
|
||||
|
||||
// Top LCD driver
|
||||
#if defined(REV9E)
|
||||
void topLcdInit(void);
|
||||
void topLcdOff(void);
|
||||
void topLcdRefreshStart(void);
|
||||
void topLcdRefreshEnd(void);
|
||||
void setTopFirstTimer(int32_t value);
|
||||
void setTopSecondTimer(uint32_t value);
|
||||
void setTopRssi(uint32_t rssi);
|
||||
void setTopBatteryState(int state, uint8_t blinking);
|
||||
void setTopBatteryValue(uint32_t volts);
|
||||
#endif
|
||||
|
||||
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
|
||||
|
||||
#if defined(USB_JOYSTICK) && !defined(SIMU)
|
||||
void usbJoystickUpdate(void);
|
||||
#endif
|
||||
|
||||
void checkTrainerSettings(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
/bootloader_ramBoot.*
|
||||
/.dep
|
||||
|
||||
@@ -0,0 +1,342 @@
|
||||
#
|
||||
# !!!! Do NOT edit this makefile with an editor which replace tabs by spaces !!!!
|
||||
#
|
||||
##############################################################################################
|
||||
#
|
||||
# On command line:
|
||||
#
|
||||
# make all = Create project
|
||||
#
|
||||
# make clean = Clean project files.
|
||||
#
|
||||
# To rebuild project do "make clean" and "make all".
|
||||
#
|
||||
|
||||
##############################################################################################
|
||||
# Start of default section
|
||||
#
|
||||
|
||||
TRGT = arm-none-eabi-
|
||||
CC = $(TRGT)gcc
|
||||
CP = $(TRGT)objcopy
|
||||
CLSS = $(TRGT)objdump
|
||||
AS = $(TRGT)as
|
||||
#gcc -x assembler-with-cpp
|
||||
BIN = $(CP) -O ihex
|
||||
BINX = $(CP) -O binary
|
||||
|
||||
OBJDIR = .
|
||||
|
||||
THIRDPARTY = ../../../thirdparty
|
||||
FATFSDIR = $(THIRDPARTY)/FatFs
|
||||
|
||||
ifeq ($(PCBREV), REV9E)
|
||||
MCU = cortex-m4
|
||||
STM32LIBPATH = $(THIRDPARTY)/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries
|
||||
else
|
||||
MCU = cortex-m3
|
||||
STM32LIBPATH = $(THIRDPARTY)/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries
|
||||
endif
|
||||
|
||||
# List all default C defines here, like -D_DEBUG=1
|
||||
DDEFS =
|
||||
|
||||
# List all default ASM defines here, like -D_DEBUG=1
|
||||
DADEFS =
|
||||
|
||||
# List all default directories to look for include files here
|
||||
DINCDIR =
|
||||
|
||||
# List the default directory to look for the libraries here
|
||||
DLIBDIR =
|
||||
|
||||
# List all default libraries here
|
||||
DLIBS =
|
||||
|
||||
MEMORIES = sram
|
||||
|
||||
EXT = STD
|
||||
|
||||
#
|
||||
# End of default section
|
||||
##############################################################################################
|
||||
|
||||
##############################################################################################
|
||||
# Start of user section
|
||||
#
|
||||
|
||||
#
|
||||
# Define project name and Ram/Flash mode here
|
||||
PROJECT = bootloader
|
||||
|
||||
ifeq ($(PCB), TARANIS)
|
||||
RUN_FROM_FLASH = 0
|
||||
else
|
||||
ifeq ($(PCB), X9D)
|
||||
RUN_FROM_FLASH = 0
|
||||
else
|
||||
RUN_FROM_FLASH = 1
|
||||
endif
|
||||
endif
|
||||
|
||||
# PCB revision
|
||||
PCBREV =
|
||||
|
||||
EXTRAINCDIRS = $(THIRDPARTY) $(FATFSDIR) $(FATFSDIR)/option
|
||||
|
||||
STM32USBPATH = ../../../thirdparty/STM32_USB-Host-Device_Lib_V2.1.0/Libraries
|
||||
|
||||
#
|
||||
# Define linker script file here
|
||||
#
|
||||
ifeq ($(PCB), TARANIS)
|
||||
ARCH = ARM
|
||||
LDSCRIPT = ../stm32_ramboot.ld
|
||||
TRGT = arm-none-eabi-
|
||||
CPPDEFS += -DHSE_VALUE=12000000
|
||||
CPPDEFS += -DPCBTARANIS -DEEPROM_RLC -DUSB_MASS_STORAGE
|
||||
FULL_PRJ = $(PROJECT)_ramBoot
|
||||
ifeq ($(PCBREV), REV9E)
|
||||
CPPDEFS += -DSTM32F40_41xxx
|
||||
EXTRAINCDIRS += $(STM32LIBPATH)/STM32F4xx_StdPeriph_Driver/inc
|
||||
EXTRAINCDIRS += $(STM32LIBPATH)/CMSIS/Device/ST/STM32F4xx/Include
|
||||
EXTRAINCDIRS += $(STM32LIBPATH)/CMSIS/Include
|
||||
else
|
||||
EXTRAINCDIRS += $(STM32LIBPATH)/STM32F2xx_StdPeriph_Driver/inc
|
||||
EXTRAINCDIRS += $(STM32LIBPATH)/CMSIS/Device/ST/STM32F2xx/Include
|
||||
EXTRAINCDIRS += $(STM32LIBPATH)/CMSIS/include
|
||||
endif
|
||||
EXTRAINCDIRS += $(STM32USBPATH)/STM32_USB_OTG_Driver/inc
|
||||
EXTRAINCDIRS += $(STM32USBPATH)/STM32_USB_Device_Library/Core/inc
|
||||
EXTRAINCDIRS += $(STM32USBPATH)/STM32_USB_Device_Library/Class/msc/inc
|
||||
EXTRAINCDIRS += $(STM32USBPATH)/STM32_USB_Device_Library/Class/hid/inc
|
||||
EXTRAINCDIRS += $(STM32USBPATH)/STM32_USB_Device_Library/Class/cdc/inc
|
||||
EXTRAINCDIRS += .. ../../.. ../../../fonts/std
|
||||
ifeq ($(PCBREV), REV4a)
|
||||
CPPDEFS += -DREV4a
|
||||
else ifeq ($(PCBREV), REVPLUS)
|
||||
CPPDEFS += -DREVPLUS
|
||||
HAPTIC = YES
|
||||
else ifeq ($(PCBREV), REV9E)
|
||||
CPPDEFS += -DREVPLUS -DREV9E
|
||||
HAPTIC = YES
|
||||
else
|
||||
CPPDEFS += -DREV4
|
||||
endif
|
||||
endif
|
||||
|
||||
# List all user C define here, like -D_DEBUG=1
|
||||
|
||||
# Define ASM defines here
|
||||
UADEFS =
|
||||
|
||||
SRC =
|
||||
|
||||
ifeq ($(PCBREV), REV9E)
|
||||
SRC += ../system_stm32f4xx.c
|
||||
SRC += $(STM32LIBPATH)/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c
|
||||
SRC += $(STM32LIBPATH)/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c
|
||||
SRC += $(STM32LIBPATH)/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spi.c
|
||||
SRC += $(STM32LIBPATH)/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_i2c.c
|
||||
SRC += $(STM32LIBPATH)/STM32F4xx_StdPeriph_Driver/src/misc.c
|
||||
else
|
||||
SRC += ../system_stm32f2xx.c
|
||||
SRC += $(STM32LIBPATH)/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rcc.c
|
||||
SRC += $(STM32LIBPATH)/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_gpio.c
|
||||
SRC += $(STM32LIBPATH)/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_spi.c
|
||||
SRC += $(STM32LIBPATH)/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_i2c.c
|
||||
SRC += $(STM32LIBPATH)/STM32F2xx_StdPeriph_Driver/src/misc.c
|
||||
endif
|
||||
|
||||
SRC += $(STM32USBPATH)/STM32_USB_OTG_Driver/src/usb_core.c
|
||||
SRC += $(STM32USBPATH)/STM32_USB_OTG_Driver/src/usb_dcd.c
|
||||
SRC += $(STM32USBPATH)/STM32_USB_OTG_Driver/src/usb_dcd_int.c
|
||||
SRC += $(STM32USBPATH)/STM32_USB_Device_Library/Core/src/usbd_core.c
|
||||
SRC += $(STM32USBPATH)/STM32_USB_Device_Library/Core/src/usbd_ioreq.c
|
||||
SRC += $(STM32USBPATH)/STM32_USB_Device_Library/Core/src/usbd_req.c
|
||||
SRC += $(STM32USBPATH)/STM32_USB_Device_Library/Class/msc/src/usbd_msc_data.c
|
||||
SRC += $(STM32USBPATH)/STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c
|
||||
SRC += $(STM32USBPATH)/STM32_USB_Device_Library/Class/msc/src/usbd_msc_bot.c
|
||||
SRC += $(STM32USBPATH)/STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c
|
||||
SRC += ../delays.c
|
||||
SRC += $(THIRDPARTY)/FatFs/ff.c $(THIRDPARTY)/FatFs/option/ccsbcs.c
|
||||
SRC += ../usbd_desc.c
|
||||
SRC += ../aspi.c
|
||||
SRC += ../usb_bsp.c
|
||||
SRC += ../usb_driver.c
|
||||
SRC += ../pwr_driver.c
|
||||
SRC += init.c
|
||||
|
||||
CPPSRC = ../lcd_driver.cpp \
|
||||
../configure_pins.cpp \
|
||||
../keys_driver.cpp \
|
||||
../i2c_driver.cpp \
|
||||
../flash_driver.cpp \
|
||||
../diskio.cpp \
|
||||
../usbd_usr.cpp \
|
||||
../usbd_storage_msd.cpp \
|
||||
../../../gui/Taranis/lcd.cpp \
|
||||
../../../keys.cpp \
|
||||
../../../fonts.cpp \
|
||||
../../../strhelpers.cpp \
|
||||
boot.cpp
|
||||
|
||||
# List ASM source files here
|
||||
|
||||
ifeq ($(PCBREV), REV9E)
|
||||
ASRC = $(STM32LIBPATH)/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f40_41xxx.s
|
||||
else
|
||||
ASRC = $(STM32LIBPATH)/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s
|
||||
endif
|
||||
|
||||
# List all user directories here
|
||||
UINCDIR = ./inc
|
||||
# \
|
||||
# ./cmsis/core \
|
||||
# ./cmsis/device
|
||||
|
||||
# List the user directory to look for the libraries here
|
||||
ULIBDIR =
|
||||
|
||||
# List all user libraries here
|
||||
ULIBS =
|
||||
|
||||
# Define optimisation level here
|
||||
OPT = -Os
|
||||
|
||||
#
|
||||
# End of user defines
|
||||
##############################################################################################
|
||||
|
||||
|
||||
VPATH = $(DIRS)
|
||||
|
||||
INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))
|
||||
LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
|
||||
|
||||
ifeq ($(RUN_FROM_FLASH), 0)
|
||||
DEFS = $(DDEFS) $(UDEFS) -DRUN_FROM_FLASH=0
|
||||
else
|
||||
DEFS = $(DDEFS) $(UDEFS) -DRUN_FROM_FLASH=1
|
||||
endif
|
||||
|
||||
ADEFS = $(DADEFS) $(UADEFS)
|
||||
|
||||
AXOBJS = $(ASRC:%.s=%.o)
|
||||
CXOBJS = $(SRC:%.c=%.o)
|
||||
CPPXOBJS = $(CPPSRC:%.cpp=%.o)
|
||||
|
||||
LIBS = $(DLIBS) $(ULIBS)
|
||||
MCFLAGS = -mcpu=$(MCU)
|
||||
|
||||
ifeq ($(NANO), YES)
|
||||
# use newlib-nano for linking
|
||||
# NEWLIB_NANO_FLAGS = --specs=nano.specs -u _printf_float #use this version if printf for floats is needed!
|
||||
NEWLIB_NANO_FLAGS = --specs=nano.specs
|
||||
endif
|
||||
|
||||
#ASFLAGS = $(MCFLAGS) -g -gdwarf-2 -Wa,-amhls=$(OBJDIR)/$(notdir $(<:.s=.lst)) $(ADEFS)
|
||||
CPFLAGS = $(MCFLAGS) $(OPT) -gdwarf-2 -mthumb -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm $(DEFS)
|
||||
LDFLAGS = $(MCFLAGS) -mthumb -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(FULL_PRJ).map,--cref,--no-warn-mismatch,--gc-sections $(LIBDIR) $(NEWLIB_NANO_FLAGS)
|
||||
CPPFLAGS = $(MCFLAGS) $(OPT) -gdwarf-2 -mthumb -fomit-frame-pointer -fdata-sections -ffunction-sections -Wall -fverbose-asm $(DEFS)
|
||||
|
||||
ifeq ($(WARNINGS_AS_ERRORS), YES)
|
||||
CPFLAGS += -Werror
|
||||
CPPFLAGS += -Werror
|
||||
endif
|
||||
|
||||
CPPFLAGS += $(CPPDEFS)
|
||||
CPFLAGS += $(CPPDEFS)
|
||||
CPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
||||
|
||||
AOBJS = $(patsubst %,$(OBJDIR)/%,$(notdir $(AXOBJS) ))
|
||||
COBJS = $(patsubst %,$(OBJDIR)/%,$(notdir $(CXOBJS) ))
|
||||
CPPOBJS = $(patsubst %,$(OBJDIR)/%,$(notdir $(CPPXOBJS) ))
|
||||
DIRS = $(sort $(dir $(AXOBJS) $(CXOBJS) $(CPPXOBJS) ) )
|
||||
|
||||
|
||||
CPPDEFS += -DCPUARM
|
||||
|
||||
ifeq ($(PCB), TARANIS)
|
||||
CPPDEFS += -DCPUSTM32
|
||||
endif
|
||||
|
||||
CPPDEFS += -DTIMERS=0
|
||||
|
||||
# If serial Debug required
|
||||
ifeq ($(DEBUG), 1)
|
||||
CPPDEFS += -DDEBUG
|
||||
endif
|
||||
|
||||
CPPDEFS += -DBOOT
|
||||
|
||||
# Generate dependency information
|
||||
CPFLAGS += -MD -MP -MF .dep/$(@F).d
|
||||
CPPFLAGS += -MD -MP -MF .dep/$(@F).d
|
||||
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
||||
|
||||
#
|
||||
# makefile rules
|
||||
#
|
||||
|
||||
all: size_before $(OBJS) $(COBJS) $(CPPOBJS) $(FULL_PRJ).elf $(FULL_PRJ).hex $(FULL_PRJ).lss $(FULL_PRJ).bin size
|
||||
|
||||
#begin:
|
||||
# @echo $(AXOBJS) $(CXOBJS) $(CPPXOBJS)
|
||||
# @echo
|
||||
# @echo $(OBJS) $(COBJS) $(CPPOBJS)
|
||||
# @echo
|
||||
# @echo $(DIRS)
|
||||
|
||||
size_before:
|
||||
# arm-none-eabi-size $(FULL_PRJ).elf
|
||||
@if test -f $(FULL_PRJ).elf; then arm-none-eabi-size $(FULL_PRJ).elf; fi
|
||||
|
||||
size:
|
||||
# arm-none-eabi-size $(FULL_PRJ).elf
|
||||
@if test -f $(FULL_PRJ).elf; then arm-none-eabi-size $(FULL_PRJ).elf; fi
|
||||
|
||||
$(CPPOBJS) : $(OBJDIR)/%.o : %.cpp
|
||||
$(CC) -c $(CPPFLAGS) -fno-exceptions -I . $(INCDIR) $< -o $@
|
||||
|
||||
$(COBJS) : $(OBJDIR)/%.o : %.c
|
||||
$(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@
|
||||
|
||||
|
||||
$(AOBJS) : $(OBJDIR)/%.o : %.s
|
||||
$(AS) -c $(ASFLAGS) $< -o $@
|
||||
|
||||
%elf: $(AOBJS) $(COBJS) $(CPPOBJS)
|
||||
$(CC) $(AOBJS) $(COBJS) $(CPPOBJS) $(LDFLAGS) $(LIBS) -o $@
|
||||
|
||||
# Create extended listing file from ELF output file.
|
||||
%.lss: %.elf
|
||||
$(CLSS) -h -S $< > $@
|
||||
|
||||
%hex: %elf
|
||||
$(BIN) $< $@
|
||||
|
||||
%bin: %elf
|
||||
$(BINX) $< $@
|
||||
|
||||
# $(PROJECT)_flash8
|
||||
# $(PROJECT)_flash4
|
||||
# $(PROJECT)_ramBootS
|
||||
# $(PROJECT)_ramBootT
|
||||
|
||||
clean:
|
||||
-rm -f *.o
|
||||
-rm -f *.elf
|
||||
-rm -f *.map
|
||||
-rm -f *.hex
|
||||
-rm -f *.bin
|
||||
-rm -f *.lss
|
||||
-rm -fR .dep
|
||||
|
||||
|
||||
#
|
||||
# Include the dependency files, should be the last of the makefile
|
||||
#
|
||||
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
||||
|
||||
# *** EOF ***
|
||||
@@ -0,0 +1,700 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2014 by Michael Blandford. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************
|
||||
* Other Authors:
|
||||
* - Andre Bernet
|
||||
* - Bertrand Songis
|
||||
* - Bryan J. Rentoul (Gruvin)
|
||||
* - Cameron Weeks
|
||||
* - Erez Raviv
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini
|
||||
* - Thomas Husterer
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../Taranis/board_taranis.h"
|
||||
#include "storage/eeprom_rlc.h"
|
||||
#include "pwr.h"
|
||||
#include "gui/Taranis/lcd.h"
|
||||
#include "keys.h"
|
||||
#include "sdcard.h"
|
||||
#include "FatFs/ff.h"
|
||||
#include "FatFs/diskio.h"
|
||||
#include "translations/en.h"
|
||||
#include "stamp-opentx.h"
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
#define BOOTLOADER_TITLE " Taranis BootLoader - " VERS_STR
|
||||
#if defined(REV9E)
|
||||
#define BOOT_KEY_UP KEY_MINUS
|
||||
#define BOOT_KEY_DOWN KEY_PLUS
|
||||
#else
|
||||
#define BOOT_KEY_UP KEY_PLUS
|
||||
#define BOOT_KEY_DOWN KEY_MINUS
|
||||
#endif
|
||||
#define BOOT_KEY_LEFT KEY_MENU
|
||||
#define BOOT_KEY_RIGHT KEY_PAGE
|
||||
#define BOOT_KEY_MENU KEY_ENTER
|
||||
#define BOOT_KEY_EXIT KEY_EXIT
|
||||
#define DISPLAY_CHAR_WIDTH 35
|
||||
#elif defined(PCBSKY9X)
|
||||
#define BOOTLOADER_TITLE "Sky9x Boot Loader - " VERS_STR
|
||||
#endif
|
||||
|
||||
const uint8_t bootloaderVersion[] __attribute__ ((section(".version"), used)) =
|
||||
{
|
||||
'B', 'O', 'O', 'T', '1', '0'
|
||||
};
|
||||
|
||||
// states
|
||||
enum BootLoaderStates {
|
||||
ST_START,
|
||||
ST_FLASH_MENU,
|
||||
ST_DIR_CHECK,
|
||||
ST_OPEN_DIR,
|
||||
ST_FILE_LIST,
|
||||
ST_FLASH_CHECK,
|
||||
ST_FLASHING,
|
||||
ST_FLASH_DONE,
|
||||
ST_RESTORE_MENU,
|
||||
ST_USB,
|
||||
ST_REBOOT,
|
||||
};
|
||||
|
||||
enum MemoryTypes {
|
||||
MEM_FLASH,
|
||||
MEM_EEPROM
|
||||
};
|
||||
|
||||
#define BLOCK_LEN 4096
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Local variables
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
uint32_t FirmwareSize;
|
||||
uint32_t firmwareAddress = FIRMWARE_ADDRESS;
|
||||
uint32_t firmwareWritten = 0;
|
||||
uint32_t eepromAddress = 0;
|
||||
uint32_t eepromWritten = 0;
|
||||
|
||||
TCHAR backupFilename[60];
|
||||
|
||||
uint32_t Master_frequency;
|
||||
volatile uint8_t Tenms;
|
||||
|
||||
FIL FlashFile;
|
||||
DIR Dj;
|
||||
FILINFO Finfo;
|
||||
|
||||
TCHAR Filenames[20][50];
|
||||
uint32_t FileSize[20];
|
||||
uint32_t FnStartIndex;
|
||||
uint32_t Valid;
|
||||
|
||||
uint32_t FlashSize;
|
||||
|
||||
uint32_t LockBits;
|
||||
|
||||
uint32_t Block_buffer[1024];
|
||||
UINT BlockCount;
|
||||
|
||||
uint32_t memoryType;
|
||||
|
||||
uint32_t unlocked = 0;
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
extern int32_t EblockAddress;
|
||||
#endif
|
||||
|
||||
extern uint32_t EepromBlocked;
|
||||
|
||||
extern void init_spi(void);
|
||||
extern void writeBlock(void);
|
||||
extern void usbPluggedIn();
|
||||
|
||||
#if defined(REV9E)
|
||||
typedef int32_t rotenc_t;
|
||||
extern rotenc_t rotencValue;
|
||||
#endif
|
||||
|
||||
void interrupt10ms(void)
|
||||
{
|
||||
Tenms |= 1; // 10 mS has passed
|
||||
|
||||
uint8_t enuk = KEY_MENU;
|
||||
uint8_t in = readKeys();
|
||||
for (uint8_t i = 1; i != uint8_t(1 << TRM_BASE); i <<= 1) {
|
||||
uint8_t value = (in & i);
|
||||
keys[enuk].input(value);
|
||||
++enuk;
|
||||
}
|
||||
|
||||
#if defined(REV9E)
|
||||
checkRotaryEncoder();
|
||||
static rotenc_t rePreviousValue;
|
||||
rotenc_t reNewValue = (rotencValue / 2);
|
||||
int8_t scrollRE = reNewValue - rePreviousValue;
|
||||
if (scrollRE) {
|
||||
rePreviousValue = reNewValue;
|
||||
if (scrollRE < 0) {
|
||||
putEvent(EVT_KEY_FIRST(KEY_MINUS));
|
||||
}
|
||||
else {
|
||||
putEvent(EVT_KEY_FIRST(KEY_PLUS));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void init10msTimer()
|
||||
{
|
||||
TIM14->ARR = 9999; // 10mS
|
||||
TIM14->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 1000000 - 1; // 1uS from 12MHz
|
||||
TIM14->CCER = 0;
|
||||
TIM14->CCMR1 = 0;
|
||||
TIM14->EGR = 0;
|
||||
TIM14->CR1 = 5;
|
||||
TIM14->DIER |= 1;
|
||||
NVIC_EnableIRQ(TIM8_TRG_COM_TIM14_IRQn);
|
||||
}
|
||||
|
||||
extern "C" void TIM8_TRG_COM_TIM14_IRQHandler()
|
||||
{
|
||||
TIM14->SR &= ~TIM_SR_UIF;
|
||||
interrupt10ms();
|
||||
}
|
||||
|
||||
FRESULT readBinDir(DIR *dj, FILINFO *fno)
|
||||
{
|
||||
FRESULT fr;
|
||||
uint32_t loop;
|
||||
do {
|
||||
loop = 0;
|
||||
fr = f_readdir(dj, fno); // First entry
|
||||
|
||||
if (fr != FR_OK || fno->fname[0] == 0) {
|
||||
break;
|
||||
}
|
||||
if (*fno->lfname == 0) {
|
||||
strAppend(fno->lfname, fno->fname); // Copy 8.3 name
|
||||
}
|
||||
int32_t len = strlen(fno->lfname) - 4;
|
||||
if (len < 0) {
|
||||
loop = 1;
|
||||
}
|
||||
if (fno->lfname[len] != '.') {
|
||||
loop = 1;
|
||||
}
|
||||
if ((fno->lfname[len + 1] != 'b') && (fno->lfname[len + 1] != 'B')) {
|
||||
loop = 1;
|
||||
}
|
||||
if ((fno->lfname[len + 2] != 'i') && (fno->lfname[len + 2] != 'I')) {
|
||||
loop = 1;
|
||||
}
|
||||
if ((fno->lfname[len + 3] != 'n') && (fno->lfname[len + 3] != 'N')) {
|
||||
loop = 1;
|
||||
}
|
||||
|
||||
} while (loop);
|
||||
return fr;
|
||||
}
|
||||
|
||||
uint32_t fillNames(uint32_t index)
|
||||
{
|
||||
uint32_t i;
|
||||
FRESULT fr;
|
||||
Finfo.lfname = Filenames[0];
|
||||
Finfo.lfsize = 48;
|
||||
fr = f_readdir(&Dj, 0); // rewind
|
||||
fr = f_readdir(&Dj, &Finfo); // Skip .
|
||||
fr = f_readdir(&Dj, &Finfo); // Skip ..
|
||||
i = 0;
|
||||
while (i <= index) {
|
||||
fr = readBinDir(&Dj, &Finfo); // First entry
|
||||
FileSize[0] = Finfo.fsize;
|
||||
i += 1;
|
||||
if (fr == FR_NO_FILE) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
for (i = 1; i < 7; i += 1) {
|
||||
Finfo.lfname = Filenames[i];
|
||||
fr = readBinDir(&Dj, &Finfo); // First entry
|
||||
FileSize[i] = Finfo.fsize;
|
||||
if (fr != FR_OK || Finfo.fname[0] == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
const char *getBinaryPath()
|
||||
{
|
||||
if (memoryType == MEM_FLASH)
|
||||
return FIRMWARES_PATH;
|
||||
else
|
||||
return EEPROMS_PATH;
|
||||
}
|
||||
|
||||
FRESULT openBinaryFile(uint32_t index)
|
||||
{
|
||||
TCHAR filename[60];
|
||||
FRESULT fr;
|
||||
memset(Block_buffer, 0, sizeof(Block_buffer));
|
||||
strAppend(strAppend(strAppend(filename, getBinaryPath()), "/"), Filenames[index]);
|
||||
if ((fr = f_open(&FlashFile, filename, FA_READ)) != FR_OK) {
|
||||
return fr;
|
||||
}
|
||||
if (memoryType == MEM_FLASH) {
|
||||
if ((fr = f_lseek(&FlashFile, BOOTLOADER_SIZE)) != FR_OK) {
|
||||
return fr;
|
||||
}
|
||||
}
|
||||
fr = f_read(&FlashFile, (BYTE *)Block_buffer, BLOCK_LEN, &BlockCount);
|
||||
|
||||
if (BlockCount == BLOCK_LEN)
|
||||
return fr;
|
||||
else
|
||||
return FR_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
uint32_t isValidBufferStart(const void * buffer)
|
||||
{
|
||||
if (memoryType == MEM_FLASH)
|
||||
return isFirmwareStart(buffer);
|
||||
else
|
||||
return isEepromStart(buffer);
|
||||
}
|
||||
|
||||
int menuFlashFile(uint32_t index, uint8_t event)
|
||||
{
|
||||
FRESULT fr;
|
||||
|
||||
lcd_putsLeft(4*FH, "\012Hold [ENT] to start writing");
|
||||
|
||||
if (Valid == 0) {
|
||||
// Validate file here
|
||||
if ((fr = openBinaryFile(index))) {
|
||||
Valid = 2;
|
||||
}
|
||||
else {
|
||||
if ((fr = f_close(&FlashFile))) {
|
||||
Valid = 2;
|
||||
}
|
||||
else {
|
||||
Valid = 1;
|
||||
}
|
||||
if (!isValidBufferStart(Block_buffer)) {
|
||||
Valid = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Valid == 2) {
|
||||
if (memoryType == MEM_FLASH)
|
||||
lcd_putsLeft(4*FH, "\011Not a valid firmware file! ");
|
||||
else
|
||||
lcd_putsLeft(4*FH, "\011Not a valid EEPROM file! ");
|
||||
if (event == EVT_KEY_BREAK(BOOT_KEY_EXIT) || event == EVT_KEY_BREAK(BOOT_KEY_MENU)) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (event == EVT_KEY_LONG(BOOT_KEY_MENU)) {
|
||||
fr = openBinaryFile(index);
|
||||
return (fr == FR_OK && isValidBufferStart(Block_buffer));
|
||||
}
|
||||
else if (event == EVT_KEY_FIRST(BOOT_KEY_EXIT)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
extern Key keys[];
|
||||
|
||||
static uint32_t PowerUpDelay;
|
||||
|
||||
void writeFlashBlock()
|
||||
{
|
||||
uint32_t blockOffset = 0;
|
||||
while (BlockCount) {
|
||||
writeFlash((uint32_t *)firmwareAddress, &Block_buffer[blockOffset]);
|
||||
blockOffset += FLASH_PAGESIZE/4; // 32-bit words
|
||||
firmwareAddress += FLASH_PAGESIZE;
|
||||
if (BlockCount > FLASH_PAGESIZE) {
|
||||
BlockCount -= FLASH_PAGESIZE;
|
||||
}
|
||||
else {
|
||||
BlockCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void writeEepromBlock()
|
||||
{
|
||||
eepromWriteBlock((uint8_t *)Block_buffer, eepromAddress, BlockCount);
|
||||
eepromAddress += BlockCount;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
uint8_t index = 0;
|
||||
uint8_t maxhsize = DISPLAY_CHAR_WIDTH;
|
||||
FRESULT fr;
|
||||
uint32_t state = ST_START;
|
||||
uint32_t nameCount = 0;
|
||||
uint32_t vpos = 0;
|
||||
uint32_t hpos = 0;
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
wdt_reset();
|
||||
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | KEYS_RCC_AHB1Periph | LCD_RCC_AHB1Periph | BACKLIGHT_RCC_AHB1Periph | I2C_RCC_AHB1Periph | SD_RCC_AHB1Periph, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(LCD_RCC_APB1Periph | BACKLIGHT_RCC_APB1Periph | INTERRUPT_5MS_APB1Periph | I2C_RCC_APB1Periph | SD_RCC_APB1Periph, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(BACKLIGHT_RCC_APB2Periph, ENABLE);
|
||||
#endif
|
||||
|
||||
pwrInit();
|
||||
delaysInit(); //needed for lcdInit()
|
||||
lcdInit();
|
||||
backlightInit();
|
||||
|
||||
lcd_clear();
|
||||
lcd_putsn(0, 0, (const char *)bootloaderVersion, 0); // trick to avoid bootloaderVersion to be optimized out ...
|
||||
lcd_putsLeft(0, BOOTLOADER_TITLE);
|
||||
lcd_invert_line(0);
|
||||
lcdRefresh();
|
||||
|
||||
keysInit();
|
||||
i2cInit();
|
||||
|
||||
__enable_irq();
|
||||
init10msTimer();
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
// SD card detect pin
|
||||
sdInit();
|
||||
usbInit();
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
wdt_reset();
|
||||
|
||||
if (Tenms) {
|
||||
Tenms = 0;
|
||||
|
||||
lcdRefreshWait();
|
||||
lcd_clear();
|
||||
lcd_putsLeft(0, BOOTLOADER_TITLE);
|
||||
lcd_invert_line(0);
|
||||
|
||||
uint8_t event = getEvent();
|
||||
|
||||
if (state != ST_USB) {
|
||||
if (usbPlugged()) {
|
||||
state = ST_USB;
|
||||
if (!unlocked) {
|
||||
unlocked = 1;
|
||||
unlockFlash();
|
||||
}
|
||||
usbPluggedIn();
|
||||
}
|
||||
}
|
||||
|
||||
if (state == ST_START) {
|
||||
lcd_putsLeft(2*FH, "\010Write Firmware");
|
||||
lcd_putsLeft(3*FH, "\010Restore EEPROM");
|
||||
lcd_putsLeft(4*FH, "\010Exit");
|
||||
lcd_invert_line(2+vpos);
|
||||
lcd_putsLeft(7*FH, INDENT "Or plug in a USB cable for mass storage");
|
||||
if (event == EVT_KEY_FIRST(BOOT_KEY_DOWN)) {
|
||||
vpos == 2 ? vpos = 0 : vpos = vpos+1;
|
||||
}
|
||||
else if (event == EVT_KEY_FIRST(BOOT_KEY_UP)) {
|
||||
vpos == 0 ? vpos = 2 : vpos = vpos-1;
|
||||
}
|
||||
else if (event == EVT_KEY_BREAK(BOOT_KEY_MENU)) {
|
||||
switch (vpos) {
|
||||
case 0:
|
||||
state = ST_FLASH_MENU;
|
||||
break;
|
||||
case 1:
|
||||
state = ST_RESTORE_MENU;
|
||||
break;
|
||||
default:
|
||||
state = ST_REBOOT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state == ST_USB) {
|
||||
lcd_putsLeft(4*FH, "\026USB Connected");
|
||||
if (usbPlugged() == 0) {
|
||||
vpos = 0;
|
||||
if (unlocked) {
|
||||
lockFlash();
|
||||
unlocked = 0;
|
||||
}
|
||||
state = ST_START;
|
||||
}
|
||||
#if defined(PCBSKY9X)
|
||||
usbMassStorage();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (state == ST_FLASH_MENU || state == ST_RESTORE_MENU) {
|
||||
sdInit();
|
||||
memoryType = (state == ST_RESTORE_MENU ? MEM_EEPROM : MEM_FLASH);
|
||||
state = ST_DIR_CHECK;
|
||||
}
|
||||
|
||||
else if (state == ST_DIR_CHECK) {
|
||||
fr = f_chdir(getBinaryPath());
|
||||
if (fr == FR_OK) {
|
||||
state = ST_OPEN_DIR;
|
||||
}
|
||||
else {
|
||||
lcd_putsLeft(2*FH, INDENT "Directory is missing!");
|
||||
if (event == EVT_KEY_BREAK(BOOT_KEY_EXIT) || event == EVT_KEY_BREAK(BOOT_KEY_MENU)) {
|
||||
vpos = 0;
|
||||
state = ST_START;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state == ST_OPEN_DIR) {
|
||||
index = 0;
|
||||
fr = f_opendir(&Dj, ".");
|
||||
if (fr == FR_OK) {
|
||||
state = ST_FILE_LIST;
|
||||
nameCount = fillNames(0);
|
||||
hpos = 0;
|
||||
vpos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (state == ST_FILE_LIST) {
|
||||
uint32_t limit = 6;
|
||||
if (nameCount < limit) {
|
||||
limit = nameCount;
|
||||
}
|
||||
maxhsize = 0;
|
||||
for (uint32_t i=0; i<limit; i++) {
|
||||
uint32_t x;
|
||||
x = strlen(Filenames[i]);
|
||||
if (x > maxhsize) {
|
||||
maxhsize = x;
|
||||
}
|
||||
if (x > DISPLAY_CHAR_WIDTH) {
|
||||
if (hpos + DISPLAY_CHAR_WIDTH > x) {
|
||||
x = x - DISPLAY_CHAR_WIDTH;
|
||||
}
|
||||
else {
|
||||
x = hpos;
|
||||
}
|
||||
}
|
||||
else {
|
||||
x = 0;
|
||||
}
|
||||
lcd_putsnAtt(INDENT_WIDTH, 16 + FH * i, &Filenames[i][x], DISPLAY_CHAR_WIDTH, 0);
|
||||
}
|
||||
|
||||
if (event == EVT_KEY_REPT(BOOT_KEY_DOWN) || event == EVT_KEY_FIRST(BOOT_KEY_DOWN)) {
|
||||
if (vpos < limit - 1) {
|
||||
vpos += 1;
|
||||
}
|
||||
else {
|
||||
if (nameCount > limit) {
|
||||
index += 1;
|
||||
nameCount = fillNames(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event == EVT_KEY_REPT(BOOT_KEY_UP) || event == EVT_KEY_FIRST(BOOT_KEY_UP)) {
|
||||
if (vpos > 0) {
|
||||
vpos -= 1;
|
||||
}
|
||||
else {
|
||||
if (index) {
|
||||
index -= 1;
|
||||
nameCount = fillNames(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
#if !defined(PCBTARANIS)
|
||||
else if (event == EVT_KEY_REPT(BOOT_KEY_RIGHT) || event == EVT_KEY_FIRST(BOOT_KEY_RIGHT)) {
|
||||
if (hpos + DISPLAY_CHAR_WIDTH < maxhsize) {
|
||||
hpos += 1;
|
||||
}
|
||||
}
|
||||
else if (event == EVT_KEY_REPT(BOOT_KEY_LEFT) || event == EVT_KEY_FIRST(BOOT_KEY_LEFT)) {
|
||||
if (hpos) {
|
||||
hpos -= 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if (event == EVT_KEY_BREAK(BOOT_KEY_MENU)) {
|
||||
// Select file to flash
|
||||
state = ST_FLASH_CHECK;
|
||||
Valid = 0;
|
||||
}
|
||||
else if (event == EVT_KEY_FIRST(BOOT_KEY_EXIT)) {
|
||||
state = ST_START;
|
||||
vpos = 0;
|
||||
}
|
||||
|
||||
lcd_invert_line(2 + vpos);
|
||||
}
|
||||
|
||||
else if (state == ST_FLASH_CHECK) {
|
||||
int result = menuFlashFile(vpos, event);
|
||||
FirmwareSize = FileSize[vpos] - BOOTLOADER_SIZE;
|
||||
if (result == 0) {
|
||||
// canceled
|
||||
state = ST_FILE_LIST;
|
||||
}
|
||||
else if (result == 1) {
|
||||
// confirmed
|
||||
firmwareAddress = FIRMWARE_ADDRESS + BOOTLOADER_SIZE;
|
||||
firmwareWritten = 0;
|
||||
eepromAddress = 0;
|
||||
eepromWritten = 0;
|
||||
state = ST_FLASHING;
|
||||
}
|
||||
}
|
||||
|
||||
else if (state == ST_FLASHING) {
|
||||
// commit to flashing
|
||||
lcd_putsLeft(4*FH, "\032Writing...");
|
||||
|
||||
if (!unlocked && (memoryType == MEM_FLASH)) {
|
||||
unlocked = 1;
|
||||
unlockFlash();
|
||||
}
|
||||
|
||||
int progress;
|
||||
if (memoryType == MEM_FLASH) {
|
||||
writeFlashBlock();
|
||||
firmwareWritten += sizeof(Block_buffer);
|
||||
progress = (200*firmwareWritten) / FirmwareSize;
|
||||
}
|
||||
else {
|
||||
writeEepromBlock();
|
||||
eepromWritten += sizeof(Block_buffer);
|
||||
progress = (200*eepromWritten) / EESIZE;
|
||||
}
|
||||
|
||||
lcdDrawRect( 3, 6*FH+4, 204, 7);
|
||||
lcd_hline(5, 6*FH+6, progress, FORCE);
|
||||
lcd_hline(5, 6*FH+7, progress, FORCE);
|
||||
lcd_hline(5, 6*FH+8, progress, FORCE);
|
||||
|
||||
fr = f_read(&FlashFile, (BYTE *)Block_buffer, sizeof(Block_buffer), &BlockCount);
|
||||
if (BlockCount == 0) {
|
||||
state = ST_FLASH_DONE; // EOF
|
||||
}
|
||||
if (firmwareWritten >= FLASHSIZE - BOOTLOADER_SIZE) {
|
||||
state = ST_FLASH_DONE; // Backstop
|
||||
}
|
||||
if (eepromWritten >= EESIZE) {
|
||||
state = ST_FLASH_DONE; // Backstop
|
||||
}
|
||||
}
|
||||
|
||||
if (state == ST_FLASH_DONE) {
|
||||
if (unlocked) {
|
||||
lockFlash();
|
||||
unlocked = 0;
|
||||
}
|
||||
lcd_putsLeft(4*FH, "\024Writing Complete");
|
||||
if (event == EVT_KEY_FIRST(BOOT_KEY_EXIT) || event == EVT_KEY_BREAK(BOOT_KEY_MENU)) {
|
||||
state = ST_START;
|
||||
vpos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (event == EVT_KEY_LONG(BOOT_KEY_EXIT)) {
|
||||
state = ST_REBOOT;
|
||||
}
|
||||
|
||||
lcdRefresh();
|
||||
|
||||
if (PowerUpDelay < 20) { // 200 mS
|
||||
PowerUpDelay += 1;
|
||||
}
|
||||
else {
|
||||
sdPoll10ms();
|
||||
}
|
||||
}
|
||||
|
||||
if (state != ST_FLASHING && state != ST_USB) {
|
||||
#if defined(REV9E)
|
||||
if (pwrPressed()) {
|
||||
#else
|
||||
if (pwrCheck() == e_power_off) {
|
||||
#endif
|
||||
lcdOff(); // this drains LCD caps
|
||||
pwrOff();
|
||||
for (;;) {
|
||||
// Wait for power to go off
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state == ST_REBOOT) {
|
||||
if (readKeys() == 0) {
|
||||
lcd_clear();
|
||||
lcdRefresh();
|
||||
lcdRefreshWait();
|
||||
RCC->CSR |= RCC_CSR_RMVF; //clear the reset flags in RCC clock control & status register
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
void _init (void)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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 configure_pins( uint32_t pins, uint16_t config )
|
||||
{
|
||||
uint32_t address ;
|
||||
GPIO_TypeDef *pgpio ;
|
||||
uint32_t thispin ;
|
||||
uint32_t pos ;
|
||||
|
||||
address = ( config & PIN_PORT_MASK ) >> 8 ;
|
||||
address *= (GPIOB_BASE-GPIOA_BASE) ;
|
||||
address += GPIOA_BASE ;
|
||||
pgpio = (GPIO_TypeDef* ) address ;
|
||||
|
||||
/* -------------------------Configure the port pins---------------- */
|
||||
/*-- GPIO Mode Configuration --*/
|
||||
for (thispin = 0x0001, pos = 0; thispin < 0x10000; thispin <<= 1, pos +=1 )
|
||||
{
|
||||
if ( pins & thispin)
|
||||
{
|
||||
pgpio->MODER &= ~(GPIO_MODER_MODER0 << (pos * 2)) ;
|
||||
pgpio->MODER |= (config & PIN_MODE_MASK) << (pos * 2) ;
|
||||
|
||||
if ( ( (config & PIN_MODE_MASK ) == PIN_OUTPUT) || ( (config & PIN_MODE_MASK) == PIN_PERIPHERAL) )
|
||||
{
|
||||
/* Speed mode configuration */
|
||||
pgpio->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pos * 2)) ;
|
||||
pgpio->OSPEEDR |= ((config & PIN_SPEED_MASK) >> 13 ) << (pos * 2) ;
|
||||
|
||||
/* Output mode configuration*/
|
||||
pgpio->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pos)) ;
|
||||
}
|
||||
/* Pull-up Pull down resistor configuration*/
|
||||
pgpio->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pos * 2));
|
||||
pgpio->PUPDR |= ((config & PIN_PULL_MASK) >> 2) << (pos * 2) ;
|
||||
|
||||
pgpio->AFR[pos >> 3] &= ~(0x000F << ((pos & 7)*4)) ;
|
||||
pgpio->AFR[pos >> 3] |= ((config & PIN_PERI_MASK) >> 4) << ((pos & 7)*4) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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 "../Taranis/board_taranis.h"
|
||||
|
||||
void delaysInit(void)
|
||||
{
|
||||
// Timer13
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM13EN; // Enable clock
|
||||
TIM13->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 10000000 - 1; // 0.1uS
|
||||
TIM13->CCER = 0;
|
||||
TIM13->CCMR1 = 0;
|
||||
TIM13->CR1 = 0x02;
|
||||
TIM13->DIER = 0;
|
||||
}
|
||||
|
||||
void delay_01us(uint16_t nb)
|
||||
{
|
||||
TIM13->EGR = 1;
|
||||
TIM13->CNT = 0;
|
||||
TIM13->CR1 = 0x03;
|
||||
while(TIM13->CNT < nb);
|
||||
TIM13->CR1 = 0x02;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,144 @@
|
||||
#include "../../opentx.h"
|
||||
|
||||
//After reset, write is not allowed in the Flash control register (FLASH_CR) to protect the
|
||||
//Flash memory against possible unwanted operations due, for example, to electric
|
||||
//disturbances. The following sequence is used to unlock this register:
|
||||
//1. Write KEY1 = 0x45670123 in the Flash key register (FLASH_KEYR)
|
||||
//2. Write KEY2 = 0xCDEF89AB in the Flash key register (FLASH_KEYR)
|
||||
//Any wrong sequence will return a bus error and lock up the FLASH_CR register until the
|
||||
//next reset.
|
||||
//The FLASH_CR register can be locked again by software by setting the LOCK bit in the
|
||||
//FLASH_CR register.
|
||||
void unlockFlash()
|
||||
{
|
||||
FLASH->KEYR = 0x45670123;
|
||||
FLASH->KEYR = 0xCDEF89AB;
|
||||
}
|
||||
|
||||
void lockFlash()
|
||||
{
|
||||
while (!FLASH->SR & FLASH_SR_BSY);
|
||||
FLASH->CR |= FLASH_CR_LOCK;
|
||||
}
|
||||
|
||||
void waitFlashIdle()
|
||||
{
|
||||
while (FLASH->SR & FLASH_FLAG_BSY) {
|
||||
wdt_reset();
|
||||
}
|
||||
}
|
||||
|
||||
#define SECTOR_MASK ((uint32_t)0xFFFFFF07)
|
||||
|
||||
void eraseSector(uint32_t sector)
|
||||
{
|
||||
waitFlashIdle();
|
||||
|
||||
FLASH->CR &= CR_PSIZE_MASK;
|
||||
FLASH->CR |= FLASH_PSIZE_WORD;
|
||||
FLASH->CR &= SECTOR_MASK;
|
||||
FLASH->CR |= FLASH_CR_SER | (sector << 3);
|
||||
FLASH->CR |= FLASH_CR_STRT;
|
||||
|
||||
/* Wait for operation to be completed */
|
||||
waitFlashIdle();
|
||||
|
||||
/* if the erase operation is completed, disable the SER Bit */
|
||||
FLASH->CR &= (~FLASH_CR_SER);
|
||||
FLASH->CR &= SECTOR_MASK;
|
||||
}
|
||||
|
||||
void writeFlash(uint32_t *address, uint32_t *buffer) // page size is 256 bytes
|
||||
{
|
||||
if ((uint32_t) address == 0x08000000) {
|
||||
eraseSector(0);
|
||||
}
|
||||
else if ((uint32_t) address == 0x08004000) {
|
||||
eraseSector(1);
|
||||
}
|
||||
else if ((uint32_t) address == 0x08008000) {
|
||||
eraseSector(2);
|
||||
}
|
||||
else if ((uint32_t) address == 0x0800C000) {
|
||||
eraseSector(3);
|
||||
}
|
||||
else if ((uint32_t) address == 0x08010000) {
|
||||
eraseSector(4);
|
||||
}
|
||||
else if ((uint32_t) address == 0x08020000) {
|
||||
eraseSector(5);
|
||||
}
|
||||
else if ((uint32_t) address == 0x08040000) {
|
||||
eraseSector(6);
|
||||
}
|
||||
else if ((uint32_t) address == 0x08060000) {
|
||||
eraseSector(7);
|
||||
}
|
||||
|
||||
for (uint32_t i=0; i<FLASH_PAGESIZE/4; i++) {
|
||||
/* Device voltage range supposed to be [2.7V to 3.6V], the operation will
|
||||
be done by word */
|
||||
|
||||
// Wait for last operation to be completed
|
||||
waitFlashIdle();
|
||||
|
||||
FLASH->CR &= CR_PSIZE_MASK;
|
||||
FLASH->CR |= FLASH_PSIZE_WORD;
|
||||
FLASH->CR |= FLASH_CR_PG;
|
||||
|
||||
*address = *buffer;
|
||||
|
||||
/* Wait for operation to be completed */
|
||||
waitFlashIdle();
|
||||
FLASH->CR &= (~FLASH_CR_PG);
|
||||
|
||||
/* Check the written value */
|
||||
if (*address != *buffer) {
|
||||
/* Flash content doesn't match SRAM content */
|
||||
return;
|
||||
}
|
||||
/* Increment FLASH destination address */
|
||||
address += 1;
|
||||
buffer += 1;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t isFirmwareStart(const void * buffer)
|
||||
{
|
||||
const uint32_t * block = (const uint32_t *)buffer;
|
||||
|
||||
#if defined(REV9E)
|
||||
if ((block[0] & 0xFFFC0000) != 0x10000000 && (block[0] & 0xFFFC0000) != 0x20000000) {
|
||||
return 0;
|
||||
}
|
||||
if ((block[1] & 0xFFF00000) != 0x08000000) {
|
||||
return 0;
|
||||
}
|
||||
if ((block[2] & 0xFFF00000) != 0x08000000) {
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
if ((block[0] & 0xFFFC0000) != 0x20000000) {
|
||||
return 0;
|
||||
}
|
||||
if ((block[1] & 0xFFF00000) != 0x08000000) {
|
||||
return 0;
|
||||
}
|
||||
if ((block[2] & 0xFFF00000) != 0x08000000) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t isBootloaderStart(const void * buffer)
|
||||
{
|
||||
const uint32_t * block = (const uint32_t *)buffer;
|
||||
|
||||
for (int i=0; i<256; i++) {
|
||||
if (block[i] == 0x544F4F42/*BOOT*/) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,570 @@
|
||||
#ifndef _HAL_
|
||||
#define _HAL_
|
||||
|
||||
// Keys
|
||||
#define KEYS_GPIO_REG_MENU GPIOD->IDR
|
||||
#define KEYS_GPIO_REG_EXIT GPIOD->IDR
|
||||
#define KEYS_GPIO_REG_PAGE GPIOD->IDR
|
||||
#if defined(REV9E)
|
||||
#if defined(SIMU)
|
||||
#define KEYS_GPIO_REG_PLUS GPIOE->IDR
|
||||
#define KEYS_GPIO_PIN_PLUS GPIO_Pin_5 // This is for SIMU: reuse rotary encoder pins to map UP and DOWN keyboard keys
|
||||
#define KEYS_GPIO_REG_MINUS GPIOE->IDR
|
||||
#define KEYS_GPIO_PIN_MINUS GPIO_Pin_6 // This is for SIMU: reuse rotary encoder pins to map UP and DOWN keyboard keys
|
||||
#endif
|
||||
#define KEYS_GPIO_REG_ENTER GPIOF->IDR
|
||||
#define KEYS_GPIO_PIN_ENTER GPIO_Pin_0 // PF.00
|
||||
#else
|
||||
#define KEYS_GPIO_REG_PLUS GPIOE->IDR
|
||||
#define KEYS_GPIO_PIN_PLUS GPIO_Pin_10 // PE.10
|
||||
#define KEYS_GPIO_REG_MINUS GPIOE->IDR
|
||||
#define KEYS_GPIO_PIN_MINUS GPIO_Pin_11 // PE.11
|
||||
#define KEYS_GPIO_REG_ENTER GPIOE->IDR
|
||||
#define KEYS_GPIO_PIN_ENTER GPIO_Pin_12 // PE.12
|
||||
#endif
|
||||
#define KEYS_GPIO_PIN_MENU GPIO_Pin_7 // PD.07
|
||||
#define KEYS_GPIO_PIN_PAGE GPIO_Pin_3 // PD.02
|
||||
#define KEYS_GPIO_PIN_EXIT GPIO_Pin_2 // PD.03
|
||||
|
||||
// Rotary Encoder
|
||||
#define ENC_GPIO GPIOD
|
||||
#define ENC_GPIO_PIN_A GPIO_Pin_12 // PD.12
|
||||
#define ENC_GPIO_PIN_B GPIO_Pin_13 // PD.13
|
||||
|
||||
// Trims
|
||||
#if defined(REV9E)
|
||||
#define TRIMS_GPIO_REG_LHL GPIOG->IDR
|
||||
#define TRIMS_GPIO_PIN_LHL GPIO_Pin_1 // PG.01
|
||||
#define TRIMS_GPIO_REG_LHR GPIOG->IDR
|
||||
#define TRIMS_GPIO_PIN_LHR GPIO_Pin_0 // PG.00
|
||||
#define TRIMS_GPIO_REG_LVD GPIOE->IDR
|
||||
#define TRIMS_GPIO_PIN_LVD GPIO_Pin_4 // PE.04
|
||||
#define TRIMS_GPIO_REG_LVU GPIOE->IDR
|
||||
#define TRIMS_GPIO_PIN_LVU GPIO_Pin_3 // PE.03
|
||||
#define TRIMS_GPIO_REG_RVD GPIOC->IDR
|
||||
#define TRIMS_GPIO_PIN_RVD GPIO_Pin_3 // PC.03
|
||||
#define TRIMS_GPIO_REG_RHL GPIOC->IDR
|
||||
#define TRIMS_GPIO_PIN_RHL GPIO_Pin_1 // PC.01
|
||||
#define TRIMS_GPIO_REG_RVU GPIOC->IDR
|
||||
#define TRIMS_GPIO_PIN_RVU GPIO_Pin_2 // PC.02
|
||||
#define TRIMS_GPIO_REG_RHR GPIOC->IDR
|
||||
#define TRIMS_GPIO_PIN_RHR GPIO_Pin_13 // PC.13
|
||||
#else
|
||||
#define TRIMS_GPIO_REG_LHL GPIOE->IDR
|
||||
#define TRIMS_GPIO_PIN_LHL GPIO_Pin_4 // PE.04
|
||||
#define TRIMS_GPIO_REG_LHR GPIOE->IDR
|
||||
#define TRIMS_GPIO_PIN_LHR GPIO_Pin_3 // PE.03
|
||||
#define TRIMS_GPIO_REG_LVD GPIOE->IDR
|
||||
#define TRIMS_GPIO_PIN_LVD GPIO_Pin_6 // PE.06
|
||||
#define TRIMS_GPIO_REG_LVU GPIOE->IDR
|
||||
#define TRIMS_GPIO_PIN_LVU GPIO_Pin_5 // PE.05
|
||||
#define TRIMS_GPIO_REG_RVD GPIOC->IDR
|
||||
#define TRIMS_GPIO_PIN_RVD GPIO_Pin_3 // PC.03
|
||||
#define TRIMS_GPIO_REG_RHL GPIOC->IDR
|
||||
#define TRIMS_GPIO_PIN_RHL GPIO_Pin_1 // PC.01
|
||||
#define TRIMS_GPIO_REG_RVU GPIOC->IDR
|
||||
#define TRIMS_GPIO_PIN_RVU GPIO_Pin_2 // PC.02
|
||||
#define TRIMS_GPIO_REG_RHR GPIOC->IDR
|
||||
#define TRIMS_GPIO_PIN_RHR GPIO_Pin_13 // PC.13
|
||||
#endif
|
||||
|
||||
// Switches
|
||||
#if defined(REV9E)
|
||||
#define SWITCHES_GPIO_REG_A_H GPIOD->IDR
|
||||
#define SWITCHES_GPIO_PIN_A_H GPIO_Pin_10 // PD.10
|
||||
#define SWITCHES_GPIO_REG_A_L GPIOD->IDR
|
||||
#define SWITCHES_GPIO_PIN_A_L GPIO_Pin_14 // PD.14
|
||||
#else
|
||||
#define SWITCHES_GPIO_REG_A_H GPIOB->IDR
|
||||
#define SWITCHES_GPIO_PIN_A_H GPIO_Pin_5 // PB.05
|
||||
#define SWITCHES_GPIO_REG_A_L GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_A_L GPIO_Pin_0 // PE.00
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
#define SWITCHES_GPIO_REG_B_H GPIOG->IDR
|
||||
#define SWITCHES_GPIO_PIN_B_H GPIO_Pin_11 // PG.11
|
||||
#define SWITCHES_GPIO_REG_B_L GPIOG->IDR
|
||||
#define SWITCHES_GPIO_PIN_B_L GPIO_Pin_10 // PG.10
|
||||
#else
|
||||
#define SWITCHES_GPIO_REG_B_H GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_B_H GPIO_Pin_1 // PE.01
|
||||
#define SWITCHES_GPIO_REG_B_L GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_B_L GPIO_Pin_2 // PE.02
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
#define SWITCHES_GPIO_REG_C_H GPIOF->IDR
|
||||
#define SWITCHES_GPIO_PIN_C_H GPIO_Pin_13 // PF.13
|
||||
#define SWITCHES_GPIO_REG_C_L GPIOF->IDR
|
||||
#define SWITCHES_GPIO_PIN_C_L GPIO_Pin_14 // PF.14
|
||||
#else
|
||||
#define SWITCHES_GPIO_REG_C_H GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_C_H GPIO_Pin_15 // PE.15
|
||||
#define SWITCHES_GPIO_REG_C_L GPIOA->IDR
|
||||
#define SWITCHES_GPIO_PIN_C_L GPIO_Pin_5 // PA.05
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
#define SWITCHES_GPIO_REG_D_H GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_D_H GPIO_Pin_1 // PE.01
|
||||
#define SWITCHES_GPIO_REG_D_L GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_D_L GPIO_Pin_2 // PE.02
|
||||
#elif defined(REVPLUS)
|
||||
#define SWITCHES_GPIO_REG_D_H GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_D_H GPIO_Pin_7 // PE.07
|
||||
#define SWITCHES_GPIO_REG_D_L GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_D_L GPIO_Pin_13 // PE.13
|
||||
#else
|
||||
#define SWITCHES_GPIO_REG_D_H GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_D_H GPIO_Pin_7 // PE.07
|
||||
#define SWITCHES_GPIO_REG_D_L GPIOB->IDR
|
||||
#define SWITCHES_GPIO_PIN_D_L GPIO_Pin_1 // PB.01
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
#define SWITCHES_GPIO_REG_E_H GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_E_H GPIO_Pin_7 // PE.07
|
||||
#define SWITCHES_GPIO_REG_E_L GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_E_L GPIO_Pin_13 // PE.13
|
||||
#else
|
||||
#define SWITCHES_GPIO_REG_E_L GPIOB->IDR
|
||||
#define SWITCHES_GPIO_PIN_E_L GPIO_Pin_3 // PB.03
|
||||
#define SWITCHES_GPIO_REG_E_H GPIOB->IDR
|
||||
#define SWITCHES_GPIO_PIN_E_H GPIO_Pin_4 // PB.04
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
#define SWITCHES_GPIO_REG_F GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_F GPIO_Pin_11 // PE.11
|
||||
#else
|
||||
#define SWITCHES_GPIO_REG_F GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_F GPIO_Pin_14 // PE.14
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
#define SWITCHES_GPIO_REG_G_H GPIOF->IDR
|
||||
#define SWITCHES_GPIO_PIN_G_H GPIO_Pin_3 // PF.03
|
||||
#define SWITCHES_GPIO_REG_G_L GPIOF->IDR
|
||||
#define SWITCHES_GPIO_PIN_G_L GPIO_Pin_4 // PF.04
|
||||
#else
|
||||
#define SWITCHES_GPIO_REG_G_H GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_G_H GPIO_Pin_9 // PE.09
|
||||
#define SWITCHES_GPIO_REG_G_L GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_G_L GPIO_Pin_8 // PE.08
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
#define SWITCHES_GPIO_REG_H GPIOF->IDR
|
||||
#define SWITCHES_GPIO_PIN_H GPIO_Pin_1 // PF.01
|
||||
#elif defined(REVPLUS)
|
||||
#define SWITCHES_GPIO_REG_H GPIOD->IDR
|
||||
#define SWITCHES_GPIO_PIN_H GPIO_Pin_14 // PD.14
|
||||
#else
|
||||
#define SWITCHES_GPIO_REG_H GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_H GPIO_Pin_13 // PE.13
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
#define SWITCHES_GPIO_REG_I_H GPIOF->IDR
|
||||
#define SWITCHES_GPIO_PIN_I_H GPIO_Pin_15 // PF.15
|
||||
#define SWITCHES_GPIO_REG_I_L GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_I_L GPIO_Pin_14 // PE.14
|
||||
#define SWITCHES_GPIO_REG_J_H GPIOG->IDR
|
||||
#define SWITCHES_GPIO_PIN_J_H GPIO_Pin_7 // PG.07
|
||||
#define SWITCHES_GPIO_REG_J_L GPIOG->IDR
|
||||
#define SWITCHES_GPIO_PIN_J_L GPIO_Pin_8 // PG.08
|
||||
#define SWITCHES_GPIO_REG_K_H GPIOG->IDR
|
||||
#define SWITCHES_GPIO_PIN_K_H GPIO_Pin_13 // PG.13
|
||||
#define SWITCHES_GPIO_REG_K_L GPIOG->IDR
|
||||
#define SWITCHES_GPIO_PIN_K_L GPIO_Pin_12 // PG.12
|
||||
#define SWITCHES_GPIO_REG_L_H GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_L_H GPIO_Pin_9 // PE.09
|
||||
#define SWITCHES_GPIO_REG_L_L GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_L_L GPIO_Pin_8 // PE.08
|
||||
#define SWITCHES_GPIO_REG_M_H GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_M_H GPIO_Pin_15 // PE.15
|
||||
#define SWITCHES_GPIO_REG_M_L GPIOA->IDR
|
||||
#define SWITCHES_GPIO_PIN_M_L GPIO_Pin_5 // PA.05
|
||||
#define SWITCHES_GPIO_REG_N_H GPIOB->IDR
|
||||
#define SWITCHES_GPIO_PIN_N_H GPIO_Pin_3 // PB.03
|
||||
#define SWITCHES_GPIO_REG_N_L GPIOB->IDR
|
||||
#define SWITCHES_GPIO_PIN_N_L GPIO_Pin_4 // PB.04
|
||||
#define SWITCHES_GPIO_REG_O_H GPIOF->IDR
|
||||
#define SWITCHES_GPIO_PIN_O_H GPIO_Pin_7 // PF.07
|
||||
#define SWITCHES_GPIO_REG_O_L GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_O_L GPIO_Pin_10 // PE.10
|
||||
#define SWITCHES_GPIO_REG_P_H GPIOF->IDR
|
||||
#define SWITCHES_GPIO_PIN_P_H GPIO_Pin_11 // PF.11
|
||||
#define SWITCHES_GPIO_REG_P_L GPIOF->IDR
|
||||
#define SWITCHES_GPIO_PIN_P_L GPIO_Pin_12 // PF.12
|
||||
#define SWITCHES_GPIO_REG_Q_H GPIOF->IDR
|
||||
#define SWITCHES_GPIO_PIN_Q_H GPIO_Pin_5 // PF.05
|
||||
#define SWITCHES_GPIO_REG_Q_L GPIOF->IDR
|
||||
#define SWITCHES_GPIO_PIN_Q_L GPIO_Pin_6 // PF.06
|
||||
#define SWITCHES_GPIO_REG_R_H GPIOB->IDR
|
||||
#define SWITCHES_GPIO_PIN_R_H GPIO_Pin_5 // PB.05
|
||||
#define SWITCHES_GPIO_REG_R_L GPIOE->IDR
|
||||
#define SWITCHES_GPIO_PIN_R_L GPIO_Pin_0 // PE.00
|
||||
#endif
|
||||
|
||||
#if defined(REV9E)
|
||||
#define KEYS_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE|RCC_AHB1Periph_GPIOF|RCC_AHB1Periph_GPIOG)
|
||||
#define KEYS_GPIOA_PINS (SWITCHES_GPIO_PIN_M_L)
|
||||
#define KEYS_GPIOB_PINS (SWITCHES_GPIO_PIN_N_H | SWITCHES_GPIO_PIN_N_L | SWITCHES_GPIO_PIN_R_H)
|
||||
#define KEYS_GPIOC_PINS (TRIMS_GPIO_PIN_RVD | TRIMS_GPIO_PIN_RVU | TRIMS_GPIO_PIN_RHL | TRIMS_GPIO_PIN_RHR)
|
||||
#define KEYS_GPIOD_PINS (KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_PAGE | SWITCHES_GPIO_PIN_A_H | SWITCHES_GPIO_PIN_A_L | ENC_GPIO_PIN_A | ENC_GPIO_PIN_B)
|
||||
#define KEYS_GPIOE_PINS (TRIMS_GPIO_PIN_LVU | TRIMS_GPIO_PIN_LVD | SWITCHES_GPIO_PIN_D_H | SWITCHES_GPIO_PIN_D_L| SWITCHES_GPIO_PIN_E_H | SWITCHES_GPIO_PIN_E_L | SWITCHES_GPIO_PIN_F | SWITCHES_GPIO_PIN_I_L | SWITCHES_GPIO_PIN_L_H | SWITCHES_GPIO_PIN_L_L | SWITCHES_GPIO_PIN_M_H | SWITCHES_GPIO_PIN_O_L | SWITCHES_GPIO_PIN_R_L)
|
||||
#define KEYS_GPIOF_PINS (KEYS_GPIO_PIN_ENTER | SWITCHES_GPIO_PIN_C_H | SWITCHES_GPIO_PIN_C_L | SWITCHES_GPIO_PIN_G_H | SWITCHES_GPIO_PIN_G_L | SWITCHES_GPIO_PIN_H | SWITCHES_GPIO_PIN_I_H | SWITCHES_GPIO_PIN_O_H | SWITCHES_GPIO_PIN_P_H | SWITCHES_GPIO_PIN_P_L | SWITCHES_GPIO_PIN_Q_H | SWITCHES_GPIO_PIN_Q_L)
|
||||
#define KEYS_GPIOG_PINS (TRIMS_GPIO_PIN_LHL | TRIMS_GPIO_PIN_LHR| SWITCHES_GPIO_PIN_B_H | SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_J_H | SWITCHES_GPIO_PIN_J_L | SWITCHES_GPIO_PIN_K_H | SWITCHES_GPIO_PIN_K_L)
|
||||
#elif defined(REVPLUS)
|
||||
#define KEYS_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE)
|
||||
#define KEYS_GPIOA_PINS (SWITCHES_GPIO_PIN_C_L)
|
||||
#define KEYS_GPIOB_PINS (SWITCHES_GPIO_PIN_E_L | SWITCHES_GPIO_PIN_E_H | SWITCHES_GPIO_PIN_A_H)
|
||||
#define KEYS_GPIOC_PINS (TRIMS_GPIO_PIN_RVD | TRIMS_GPIO_PIN_RVU | TRIMS_GPIO_PIN_RHL | TRIMS_GPIO_PIN_RHR)
|
||||
#define KEYS_GPIOD_PINS (KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_PAGE | SWITCHES_GPIO_PIN_H)
|
||||
#define KEYS_GPIOE_PINS (KEYS_GPIO_PIN_PLUS | KEYS_GPIO_PIN_ENTER | KEYS_GPIO_PIN_MINUS | TRIMS_GPIO_PIN_LHR | TRIMS_GPIO_PIN_LHL | TRIMS_GPIO_PIN_LVD | TRIMS_GPIO_PIN_LVU | SWITCHES_GPIO_PIN_F | SWITCHES_GPIO_PIN_A_L | SWITCHES_GPIO_PIN_B_H | SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_C_H | SWITCHES_GPIO_PIN_D_H | SWITCHES_GPIO_PIN_D_L | SWITCHES_GPIO_PIN_G_H | SWITCHES_GPIO_PIN_G_L)
|
||||
#else
|
||||
#define KEYS_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE)
|
||||
#define KEYS_GPIOA_PINS (SWITCHES_GPIO_PIN_C_L)
|
||||
#define KEYS_GPIOB_PINS (SWITCHES_GPIO_PIN_E_L | SWITCHES_GPIO_PIN_E_H | SWITCHES_GPIO_PIN_A_H | SWITCHES_GPIO_PIN_D_L)
|
||||
#define KEYS_GPIOC_PINS (TRIMS_GPIO_PIN_RVD | TRIMS_GPIO_PIN_RVU | TRIMS_GPIO_PIN_RHL | TRIMS_GPIO_PIN_RHR)
|
||||
#define KEYS_GPIOD_PINS (KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_PAGE)
|
||||
#define KEYS_GPIOE_PINS (KEYS_GPIO_PIN_PLUS | KEYS_GPIO_PIN_ENTER | KEYS_GPIO_PIN_MINUS | TRIMS_GPIO_PIN_LHR | TRIMS_GPIO_PIN_LHL | TRIMS_GPIO_PIN_LVD | TRIMS_GPIO_PIN_LVU | SWITCHES_GPIO_PIN_F | SWITCHES_GPIO_PIN_A_L | SWITCHES_GPIO_PIN_B_H | SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_C_H | SWITCHES_GPIO_PIN_D_H | SWITCHES_GPIO_PIN_G_H | SWITCHES_GPIO_PIN_G_L | SWITCHES_GPIO_PIN_H)
|
||||
#endif
|
||||
|
||||
// ADC
|
||||
#if defined(REV9E)
|
||||
#define ADC_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_DMA2)
|
||||
#define ADC_RCC_APB2Periph (RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC3)
|
||||
#else
|
||||
#define ADC_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_DMA2)
|
||||
#define ADC_RCC_APB2Periph RCC_APB2Periph_ADC1
|
||||
#endif
|
||||
#define ADC_GPIO_PIN_STICK_RV GPIO_Pin_0 // PA.00
|
||||
#define ADC_GPIO_PIN_STICK_RH GPIO_Pin_1 // PA.01
|
||||
#define ADC_GPIO_PIN_STICK_LH GPIO_Pin_2 // PA.02
|
||||
#define ADC_GPIO_PIN_STICK_LV GPIO_Pin_3 // PA.03
|
||||
#define ADC_CHANNEL_STICK_RV ADC_Channel_0 // ADC1_IN0
|
||||
#define ADC_CHANNEL_STICK_RH ADC_Channel_1 // ADC1_IN1
|
||||
#define ADC_CHANNEL_STICK_LH ADC_Channel_2 // ADC1_IN2
|
||||
#define ADC_CHANNEL_STICK_LV ADC_Channel_3 // ADC1_IN3
|
||||
#if defined(REV9E)
|
||||
#define ADC_GPIO_PIN_POT1 GPIO_Pin_8 // PF.08
|
||||
#define ADC_GPIO_PIN_POT2 GPIO_Pin_0 // PB.00
|
||||
#define ADC_GPIO_PIN_POT3 GPIO_Pin_5 // PC.05
|
||||
#define ADC_GPIO_PIN_POT4 GPIO_Pin_4 // PC.04
|
||||
#define ADC_GPIO_PIN_SLIDER1 GPIO_Pin_10 // PF.10
|
||||
#define ADC_GPIO_PIN_SLIDER2 GPIO_Pin_9 // PF.09
|
||||
#define ADC_GPIO_PIN_SLIDER3 GPIO_Pin_6 // PA.06
|
||||
#define ADC_GPIO_PIN_SLIDER4 GPIO_Pin_1 // PB.01
|
||||
#define ADC_GPIO_PIN_BATT GPIO_Pin_0 // PC.00
|
||||
#define ADC_CHANNEL_POT1 ADC_Channel_6 // ADC3_IN6
|
||||
#define ADC_CHANNEL_POT2 ADC_Channel_8 // ADC1_IN8
|
||||
#define ADC_CHANNEL_POT3 ADC_Channel_15 // ADC1_IN15
|
||||
#define ADC_CHANNEL_POT4 ADC_Channel_14 // ADC1_IN14
|
||||
#define ADC_CHANNEL_SLIDER1 ADC_Channel_8 // ADC3_IN8
|
||||
#define ADC_CHANNEL_SLIDER2 ADC_Channel_7 // ADC3_IN7
|
||||
#define ADC_CHANNEL_SLIDER3 ADC_Channel_6 // ADC1_IN6
|
||||
#define ADC_CHANNEL_SLIDER4 ADC_Channel_9 // ADC1_IN9
|
||||
#define ADC_CHANNEL_BATT ADC_Channel_10 // ADC1_IN10
|
||||
#elif defined(REVPLUS)
|
||||
#define ADC_GPIO_PIN_POT1 GPIO_Pin_6 // PA.06
|
||||
#define ADC_GPIO_PIN_POT2 GPIO_Pin_0 // PB.00
|
||||
#define ADC_GPIO_PIN_POT3 GPIO_Pin_1 // PB.01
|
||||
#define ADC_GPIO_PIN_SLIDER1 GPIO_Pin_4 // PC.04
|
||||
#define ADC_GPIO_PIN_SLIDER2 GPIO_Pin_5 // PC.05
|
||||
#define ADC_GPIO_PIN_BATT GPIO_Pin_0 // PC.00
|
||||
#define ADC_CHANNEL_POT1 ADC_Channel_6
|
||||
#define ADC_CHANNEL_POT2 ADC_Channel_8
|
||||
#define ADC_CHANNEL_POT3 ADC_Channel_9
|
||||
#define ADC_CHANNEL_SLIDER1 ADC_Channel_14
|
||||
#define ADC_CHANNEL_SLIDER2 ADC_Channel_15
|
||||
#define ADC_CHANNEL_BATT ADC_Channel_10
|
||||
#else
|
||||
#define ADC_GPIO_PIN_POT1 GPIO_Pin_6 // PA.06
|
||||
#define ADC_GPIO_PIN_POT2 GPIO_Pin_0 // PB.00
|
||||
#define ADC_GPIO_PIN_SLIDER1 GPIO_Pin_4 // PC.04
|
||||
#define ADC_GPIO_PIN_SLIDER2 GPIO_Pin_5 // PC.05
|
||||
#define ADC_GPIO_PIN_BATT GPIO_Pin_0 // PC.00
|
||||
#define ADC_CHANNEL_POT1 ADC_Channel_6
|
||||
#define ADC_CHANNEL_POT2 ADC_Channel_8
|
||||
#define ADC_CHANNEL_POT3 ADC_Channel_9
|
||||
#define ADC_CHANNEL_SLIDER1 ADC_Channel_14
|
||||
#define ADC_CHANNEL_SLIDER2 ADC_Channel_15
|
||||
#define ADC_CHANNEL_BATT ADC_Channel_10
|
||||
#endif
|
||||
|
||||
// Power_OFF Delay and LED
|
||||
#define PWR_RCC_AHB1Periph (RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD)
|
||||
#define PWR_GPIO GPIOD
|
||||
#define PWR_GPIO_PIN_SWITCH GPIO_Pin_1 // PD.01
|
||||
#define PWR_GPIO_PIN_ON GPIO_Pin_0 // PD.00
|
||||
#define PWR_GPIO_LED GPIOC
|
||||
#define PWR_GPIO_PIN_LED GPIO_Pin_6 // PC.06
|
||||
|
||||
// Internal Module
|
||||
#define INTMODULE_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_DMA2)
|
||||
#define INTMODULE_RCC_APB2Periph RCC_APB2Periph_TIM1
|
||||
#if defined(REVPLUS)
|
||||
#define INTMODULE_GPIO_PWR GPIOC
|
||||
#define INTMODULE_GPIO_PIN_PWR GPIO_Pin_6
|
||||
#else
|
||||
#define INTMODULE_GPIO_PWR GPIOD
|
||||
#define INTMODULE_GPIO_PIN_PWR GPIO_Pin_15
|
||||
#endif
|
||||
#define INTMODULE_GPIO_PIN GPIO_Pin_10 // PA.10
|
||||
#define INTMODULE_GPIO GPIOA
|
||||
#define INTMODULE_GPIO_PinSource GPIO_PinSource10
|
||||
#define INTMODULE_GPIO_AF GPIO_AF_TIM1
|
||||
#define INTMODULE_TIMER TIM1
|
||||
|
||||
// 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_TIMER TIM8
|
||||
#define EXTMODULE_GPIO_AF GPIO_AF_TIM8
|
||||
#define EXTMODULE_GPIO_PinSource GPIO_PinSource7
|
||||
#define EXTMODULE_TIMER_IRQn TIM8_CC_IRQn
|
||||
|
||||
// Trainer Port
|
||||
#define TRAINER_RCC_AHB1Periph RCC_AHB1Periph_GPIOC
|
||||
#define TRAINER_RCC_APB1Periph RCC_APB1Periph_TIM3
|
||||
#define TRAINER_GPIO GPIOC
|
||||
#define TRAINER_GPIO_PIN_IN GPIO_Pin_8 // PC.08
|
||||
#define TRAINER_GPIO_PIN_OUT GPIO_Pin_9 // PC.09
|
||||
#define TRAINER_GPIO_DETECT GPIOA
|
||||
#define TRAINER_GPIO_PIN_DETECT GPIO_Pin_8 // PA.08
|
||||
#define TRAINER_TIMER TIM3
|
||||
#define TRAINER_TIMER_IRQn TIM3_IRQn
|
||||
#define TRAINER_GPIO_PinSource_IN GPIO_PinSource8
|
||||
#define TRAINER_GPIO_AF GPIO_AF_TIM3
|
||||
|
||||
// Serial Port
|
||||
#define SERIAL_RCC_AHB1Periph RCC_AHB1Periph_GPIOB
|
||||
#define SERIAL_RCC_APB1Periph RCC_APB1Periph_USART3
|
||||
#define SERIAL_GPIO GPIOB
|
||||
#define SERIAL_GPIO_PIN_TX GPIO_Pin_10 // PB.10
|
||||
#define SERIAL_GPIO_PIN_RX GPIO_Pin_11 // PB.11
|
||||
#define SERIAL_GPIO_PinSource_TX GPIO_PinSource10
|
||||
#define SERIAL_GPIO_PinSource_RX GPIO_PinSource11
|
||||
#define SERIAL_GPIO_AF GPIO_AF_USART3
|
||||
#define SERIAL_USART USART3
|
||||
#define SERIAL_USART_IRQHandler USART3_IRQHandler
|
||||
#define SERIAL_USART_IRQn USART3_IRQn
|
||||
|
||||
// Telemetry
|
||||
#define TELEMETRY_RCC_AHB1Periph RCC_AHB1Periph_GPIOD
|
||||
#define TELEMETRY_GPIO_DIR GPIOD
|
||||
#define TELEMETRY_GPIO_PIN_DIR GPIO_Pin_4 // PD.04
|
||||
#define TELEMETRY_RCC_APB1Periph RCC_APB1Periph_USART2
|
||||
#define TELEMETRY_GPIO GPIOD
|
||||
#define TELEMETRY_GPIO_PIN_TX GPIO_Pin_5 // PD.05
|
||||
#define TELEMETRY_GPIO_PIN_RX GPIO_Pin_6 // PD.06
|
||||
#define TELEMETRY_GPIO_PinSource_TX GPIO_PinSource5
|
||||
#define TELEMETRY_GPIO_PinSource_RX GPIO_PinSource6
|
||||
#define TELEMETRY_GPIO_AF GPIO_AF_USART2
|
||||
#define TELEMETRY_USART USART2
|
||||
#define TELEMETRY_USART_IRQHandler USART2_IRQHandler
|
||||
#define TELEMETRY_USART_IRQn USART2_IRQn
|
||||
|
||||
// Heartbeat
|
||||
#define HEARTBEAT_RCC_AHB1Periph RCC_AHB1Periph_GPIOC
|
||||
#define HEARTBEAT_RCC_APB2Periph RCC_APB2Periph_USART6
|
||||
#define HEARTBEAT_GPIO_PIN GPIO_Pin_7 // PC.07
|
||||
#define HEARTBEAT_GPIO_PinSource GPIO_PinSource7
|
||||
#define HEARTBEAT_GPIO_AF GPIO_AF_USART6
|
||||
#define HEARTBEAT_USART USART6
|
||||
#define HEARTBEAT_USART_IRQHandler USART6_IRQHandler
|
||||
#define HEARTBEAT_USART_IRQn USART6_IRQn
|
||||
|
||||
// USB
|
||||
#define USB_RCC_AHB1Periph_GPIO RCC_AHB1Periph_GPIOA
|
||||
#define USB_GPIO GPIOA
|
||||
#define USB_GPIO_PIN_VBUS GPIO_Pin_9 // PA.09
|
||||
#define USB_GPIO_PIN_DM GPIO_Pin_11 // PA.11
|
||||
#define USB_GPIO_PIN_DP GPIO_Pin_12 // PA.12
|
||||
#define USB_GPIO_PinSource_DM GPIO_PinSource11
|
||||
#define USB_GPIO_PinSource_DP GPIO_PinSource12
|
||||
#define USB_GPIO_AF GPIO_AF_OTG1_FS
|
||||
|
||||
// BackLight
|
||||
#if defined(REV9E)
|
||||
#define BACKLIGHT_RCC_AHB1Periph RCC_AHB1Periph_GPIOE
|
||||
#define BACKLIGHT_RCC_APB1Periph 0
|
||||
#define BACKLIGHT_RCC_APB2Periph RCC_APB2Periph_TIM9
|
||||
#define BACKLIGHT_TIMER TIM9
|
||||
#define BACKLIGHT_GPIO GPIOE
|
||||
#define BACKLIGHT_GPIO_PIN_1 GPIO_Pin_6 // PE.06
|
||||
#define BACKLIGHT_GPIO_PIN_2 GPIO_Pin_5 // PE.05
|
||||
#define BACKLIGHT_GPIO_PinSource_1 GPIO_PinSource6
|
||||
#define BACKLIGHT_GPIO_PinSource_2 GPIO_PinSource5
|
||||
#define BACKLIGHT_GPIO_AF_1 GPIO_AF_TIM9
|
||||
#define BACKLIGHT_GPIO_AF_2 GPIO_AF_TIM9
|
||||
#elif defined (REVPLUS)
|
||||
#define BACKLIGHT_RCC_AHB1Periph RCC_AHB1Periph_GPIOD
|
||||
#define BACKLIGHT_RCC_APB1Periph RCC_APB1Periph_TIM4
|
||||
#define BACKLIGHT_RCC_APB2Periph 0
|
||||
#define BACKLIGHT_TIMER TIM4
|
||||
#define BACKLIGHT_GPIO GPIOD
|
||||
#define BACKLIGHT_GPIO_PIN_1 GPIO_Pin_15 // PD.15
|
||||
#define BACKLIGHT_GPIO_PIN_2 GPIO_Pin_13 // PD.13
|
||||
#define BACKLIGHT_GPIO_PinSource_1 GPIO_PinSource15
|
||||
#define BACKLIGHT_GPIO_PinSource_2 GPIO_PinSource13
|
||||
#define BACKLIGHT_GPIO_AF_1 GPIO_AF_TIM4
|
||||
#define BACKLIGHT_GPIO_AF_2 GPIO_AF_TIM4
|
||||
#else
|
||||
#define BACKLIGHT_RCC_AHB1Periph RCC_AHB1Periph_GPIOB
|
||||
#define BACKLIGHT_RCC_APB1Periph 0
|
||||
#define BACKLIGHT_RCC_APB2Periph RCC_APB2Periph_TIM10
|
||||
#define BACKLIGHT_TIMER TIM10
|
||||
#define BACKLIGHT_GPIO GPIOB
|
||||
#define BACKLIGHT_GPIO_PIN_1 GPIO_Pin_8 // PB.08
|
||||
#define BACKLIGHT_GPIO_PinSource_1 GPIO_PinSource8
|
||||
#define BACKLIGHT_GPIO_AF_1 GPIO_AF_TIM10
|
||||
#endif
|
||||
|
||||
// LCD
|
||||
#if defined(REV9E)
|
||||
#define LCD_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA1)
|
||||
#define LCD_RCC_APB1Periph RCC_APB1Periph_SPI3
|
||||
#define LCD_GPIO_SPI GPIOC
|
||||
#define LCD_GPIO_NCS GPIOA
|
||||
#define LCD_GPIO_RST GPIOD
|
||||
#define LCD_GPIO_PIN_MOSI GPIO_Pin_12 // PC.12
|
||||
#define LCD_GPIO_PIN_CLK GPIO_Pin_10 // PC.10
|
||||
#define LCD_GPIO_PIN_NCS GPIO_Pin_15 // PA.15
|
||||
#define LCD_GPIO_PIN_A0 GPIO_Pin_11 // PC.11
|
||||
#define LCD_GPIO_PIN_RST GPIO_Pin_15 // PD.15
|
||||
#elif defined(REVPLUS)
|
||||
#define LCD_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_DMA1)
|
||||
#define LCD_RCC_APB1Periph RCC_APB1Periph_SPI3
|
||||
#define LCD_GPIO_SPI GPIOC
|
||||
#define LCD_GPIO_NCS GPIOA
|
||||
#define LCD_GPIO_RST GPIOD
|
||||
#define LCD_GPIO_PIN_MOSI GPIO_Pin_12 // PC.12
|
||||
#define LCD_GPIO_PIN_CLK GPIO_Pin_10 // PC.10
|
||||
#define LCD_GPIO_PIN_NCS GPIO_Pin_15 // PA.15
|
||||
#define LCD_GPIO_PIN_A0 GPIO_Pin_11 // PC.11
|
||||
#define LCD_GPIO_PIN_RST GPIO_Pin_12 // PD.12
|
||||
#else
|
||||
#define LCD_RCC_AHB1Periph RCC_AHB1Periph_GPIOD
|
||||
#define LCD_RCC_APB1Periph 0
|
||||
#define LCD_GPIO_SPI GPIOD
|
||||
#define LCD_GPIO_NCS GPIOD
|
||||
#define LCD_GPIO_RST GPIOD
|
||||
#define LCD_GPIO_PIN_MOSI GPIO_Pin_10 // PD.10
|
||||
#define LCD_GPIO_PIN_CLK GPIO_Pin_11 // PD.11
|
||||
#define LCD_GPIO_PIN_NCS GPIO_Pin_14 // PD.14
|
||||
#define LCD_GPIO_PIN_A0 GPIO_Pin_13 // PD.13
|
||||
#define LCD_GPIO_PIN_RST GPIO_Pin_12 // PD.12
|
||||
#endif
|
||||
|
||||
// I2C Bus: EEPROM and CAT5137
|
||||
#define I2C_RCC_AHB1Periph RCC_AHB1Periph_GPIOB
|
||||
#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_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
|
||||
#if defined(REV4a)
|
||||
#define I2C_SPEED 100000
|
||||
#else
|
||||
#define I2C_SPEED 400000
|
||||
#endif
|
||||
#define I2C_ADDRESS_EEPROM 0xA2
|
||||
#define I2C_ADDRESS_CAT5137 0x5C
|
||||
#define I2C_FLASH_PAGESIZE 64
|
||||
|
||||
// SD - SPI2
|
||||
#define SD_RCC_AHB1Periph (RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_DMA1)
|
||||
#define SD_RCC_APB1Periph RCC_APB1Periph_SPI2
|
||||
#define SD_GPIO_PRESENT GPIOD
|
||||
#define SD_GPIO_PIN_PRESENT GPIO_Pin_9 // PD.09
|
||||
#define SD_GPIO GPIOB
|
||||
#define SD_GPIO_PIN_CS GPIO_Pin_12 // PB.12
|
||||
#define SD_GPIO_PIN_SCK GPIO_Pin_13 // PB.13
|
||||
#define SD_GPIO_PIN_MISO GPIO_Pin_14 // PB.14
|
||||
#define SD_GPIO_PIN_MOSI GPIO_Pin_15 // PB.15
|
||||
#define SD_GPIO_AF GPIO_AF_SPI2
|
||||
#define SD_GPIO_PinSource_CS GPIO_PinSource12
|
||||
#define SD_GPIO_PinSource_SCK GPIO_PinSource13
|
||||
#define SD_GPIO_PinSource_MISO GPIO_PinSource14
|
||||
#define SD_GPIO_PinSource_MOSI GPIO_PinSource15
|
||||
#define SD_SPI SPI2
|
||||
#define SD_SPI_BaudRatePrescaler SPI_BaudRatePrescaler_4 // 10.5<20MHZ, make sure < 20MHZ
|
||||
|
||||
#if !defined(BOOT)
|
||||
#define SD_USE_DMA // Enable the DMA for SD
|
||||
#define SD_DMA_Stream_SPI_RX DMA1_Stream3
|
||||
#define SD_DMA_Stream_SPI_TX DMA1_Stream4
|
||||
#define SD_DMA_FLAG_SPI_TC_RX DMA_FLAG_TCIF3
|
||||
#define SD_DMA_FLAG_SPI_TC_TX DMA_FLAG_TCIF4
|
||||
#define SD_DMA_Channel_SPI DMA_Channel_0
|
||||
#endif
|
||||
|
||||
// Haptic
|
||||
#if defined(REVPLUS)
|
||||
#define HAPTIC_RCC_AHB1Periph RCC_AHB1Periph_GPIOB
|
||||
#define HAPTIC_RCC_APB2Periph RCC_APB2Periph_TIM10
|
||||
#define HAPTIC_GPIO_PinSource GPIO_PinSource8
|
||||
#define HAPTIC_GPIO GPIOB
|
||||
#define HAPTIC_GPIO_PIN GPIO_Pin_8
|
||||
#define HAPTIC_GPIO_AF GPIO_AF_TIM10
|
||||
#define HAPTIC_TIMER TIM10
|
||||
#else
|
||||
#define HAPTIC_RCC_AHB1Periph RCC_AHB1Periph_GPIOC
|
||||
#define HAPTIC_RCC_APB2Periph 0
|
||||
#define HAPTIC_GPIO GPIOC
|
||||
#define HAPTIC_GPIO_PIN GPIO_Pin_12
|
||||
#endif
|
||||
|
||||
// Top LCD on X9E
|
||||
#if defined(REV9E)
|
||||
#define TOPLCD_RCC_AHB1Periph RCC_AHB1Periph_GPIOG
|
||||
#define TOPLCD_GPIO GPIOG
|
||||
#define TOPLCD_GPIO_PIN_DATA GPIO_Pin_5
|
||||
#define TOPLCD_GPIO_PIN_WR GPIO_Pin_4
|
||||
#define TOPLCD_GPIO_PIN_CS1 GPIO_Pin_3
|
||||
#define TOPLCD_GPIO_PIN_CS2 GPIO_Pin_15
|
||||
#define TOPLCD_GPIO_PIN_BL GPIO_Pin_2
|
||||
#endif
|
||||
|
||||
// Bluetooth on X9E
|
||||
#if defined(REV9E)
|
||||
#define BT_USART USART6
|
||||
#define BT_GPIO_AF GPIO_AF_USART6
|
||||
#define BT_USART_IRQn USART6_IRQn
|
||||
#define BT_RCC_AHB1Periph (RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOB)
|
||||
#define BT_GPIO_TXRX GPIOG
|
||||
#define BT_GPIO_PIN_TX GPIO_Pin_14 // PG.14
|
||||
#define BT_GPIO_PIN_RX GPIO_Pin_9 // PG.09
|
||||
#define BT_GPIO_EN GPIOD
|
||||
#define BT_GPIO_PIN_EN GPIO_Pin_11 // PD.11
|
||||
#define BT_GPIO_BRTS GPIOE
|
||||
#define BT_GPIO_PIN_BRTS GPIO_Pin_12 // PE.12
|
||||
#define BT_GPIO_BCTS GPIOG
|
||||
#define BT_GPIO_PIN_BCTS GPIO_Pin_6 // PG.06
|
||||
#define BT_GPIO_PinSource_TX GPIO_PinSource14
|
||||
#define BT_GPIO_PinSource_RX GPIO_PinSource9
|
||||
#endif
|
||||
|
||||
// 5ms Interrupt
|
||||
#define INTERRUPT_5MS_APB1Periph RCC_APB1Periph_TIM14
|
||||
#define INTERRUPT_5MS_TIMER TIM14
|
||||
#define INTERRUPT_5MS_IRQn TIM8_TRG_COM_TIM14_IRQn
|
||||
#define INTERRUPT_5MS_IRQHandler TIM8_TRG_COM_TIM14_IRQHandler
|
||||
|
||||
// 2MHz Timer
|
||||
#define TIMER_2MHz_APB1Periph RCC_APB1Periph_TIM7
|
||||
#define TIMER_2MHz_TIMER TIM7
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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"
|
||||
|
||||
#if defined(REVPLUS)
|
||||
void hapticOff(void)
|
||||
{
|
||||
HAPTIC_TIMER->CCR1 = 0;
|
||||
}
|
||||
|
||||
void hapticOn(uint32_t pwmPercent)
|
||||
{
|
||||
if (pwmPercent > 100) {
|
||||
pwmPercent = 100;
|
||||
}
|
||||
HAPTIC_TIMER->CCR1 = pwmPercent;
|
||||
}
|
||||
|
||||
void hapticInit(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = HAPTIC_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(HAPTIC_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_PinAFConfig(HAPTIC_GPIO, HAPTIC_GPIO_PinSource, HAPTIC_GPIO_AF);
|
||||
|
||||
HAPTIC_TIMER->ARR = 100 ;
|
||||
HAPTIC_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 10000 - 1;
|
||||
HAPTIC_TIMER->CCMR1 = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 ; // PWM
|
||||
HAPTIC_TIMER->CCER = TIM_CCER_CC1E ;
|
||||
|
||||
HAPTIC_TIMER->CCR1 = 0 ;
|
||||
HAPTIC_TIMER->EGR = 0 ;
|
||||
HAPTIC_TIMER->CR1 = TIM_CR1_CEN ; // Counter enable
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// No PWM before REVPLUS
|
||||
void hapticInit(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = HAPTIC_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(HAPTIC_GPIO, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
void hapticOff(void)
|
||||
{
|
||||
GPIO_ResetBits(HAPTIC_GPIO, HAPTIC_GPIO_PIN);
|
||||
}
|
||||
|
||||
void hapticOn()
|
||||
{
|
||||
GPIO_SetBits(HAPTIC_GPIO, HAPTIC_GPIO_PIN);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,271 @@
|
||||
#include "../Taranis/board_taranis.h"
|
||||
|
||||
void eepromPageWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t NumByteToWrite);
|
||||
void eepromWaitEepromStandbyState(void);
|
||||
|
||||
void i2cInit()
|
||||
{
|
||||
I2C_DeInit(I2C);
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = I2C_GPIO_PIN_WP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_Init(I2C_GPIO, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(I2C_GPIO, I2C_GPIO_PIN_WP);
|
||||
|
||||
I2C_InitTypeDef I2C_InitStructure;
|
||||
I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED;
|
||||
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
|
||||
I2C_InitStructure.I2C_OwnAddress1 = 0x00;
|
||||
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
|
||||
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
|
||||
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
|
||||
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_InitStructure.GPIO_Pin = I2C_GPIO_PIN_SCL | I2C_GPIO_PIN_SDA;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_Init(I2C_GPIO, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
#define I2C_TIMEOUT_MAX 1000
|
||||
bool I2C_WaitEvent(uint32_t event)
|
||||
{
|
||||
uint32_t timeout = I2C_TIMEOUT_MAX;
|
||||
while (!I2C_CheckEvent(I2C, event)) {
|
||||
if ((timeout--) == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool I2C_WaitEventCleared(uint32_t event)
|
||||
{
|
||||
uint32_t timeout = I2C_TIMEOUT_MAX;
|
||||
while (I2C_CheckEvent(I2C, event)) {
|
||||
if ((timeout--) == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads a block of data from the EEPROM.
|
||||
* @param pBuffer : pointer to the buffer that receives the data read
|
||||
* from the EEPROM.
|
||||
* @param ReadAddr : EEPROM's internal address to read from.
|
||||
* @param NumByteToRead : number of bytes to read from the EEPROM.
|
||||
* @retval None
|
||||
*/
|
||||
bool I2C_EE_ReadBlock(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRead)
|
||||
{
|
||||
if (!I2C_WaitEventCleared(I2C_FLAG_BUSY))
|
||||
return false;
|
||||
|
||||
I2C_GenerateSTART(I2C, ENABLE);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_MODE_SELECT))
|
||||
return false;
|
||||
|
||||
I2C_Send7bitAddress(I2C, I2C_ADDRESS_EEPROM, I2C_Direction_Transmitter);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
|
||||
return false;
|
||||
|
||||
I2C_SendData(I2C, (uint8_t)((ReadAddr & 0xFF00) >> 8));
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING))
|
||||
return false;
|
||||
I2C_SendData(I2C, (uint8_t)(ReadAddr & 0x00FF));
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED))
|
||||
return false;
|
||||
|
||||
I2C_GenerateSTART(I2C, ENABLE);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_MODE_SELECT))
|
||||
return false;
|
||||
|
||||
I2C_Send7bitAddress(I2C, I2C_ADDRESS_EEPROM, I2C_Direction_Receiver);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
|
||||
return false;
|
||||
|
||||
if (NumByteToRead > 1) {
|
||||
I2C_AcknowledgeConfig(I2C, ENABLE);
|
||||
}
|
||||
|
||||
while (NumByteToRead) {
|
||||
if (NumByteToRead == 1) {
|
||||
I2C_AcknowledgeConfig(I2C, DISABLE);
|
||||
}
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_BYTE_RECEIVED))
|
||||
return false;
|
||||
*pBuffer++ = I2C_ReceiveData(I2C);
|
||||
NumByteToRead--;
|
||||
}
|
||||
|
||||
I2C_GenerateSTOP(I2C, ENABLE);
|
||||
return true;
|
||||
}
|
||||
|
||||
void eepromReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint32_t NumByteToRead)
|
||||
{
|
||||
while (!I2C_EE_ReadBlock(pBuffer, ReadAddr, NumByteToRead)) {
|
||||
i2cInit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes buffer of data to the I2C EEPROM.
|
||||
* @param pBuffer : pointer to the buffer containing the data to be
|
||||
* written to the EEPROM.
|
||||
* @param WriteAddr : EEPROM's internal address to write to.
|
||||
* @param NumByteToWrite : number of bytes to write to the EEPROM.
|
||||
* @retval None
|
||||
*/
|
||||
void eepromWriteBlock(uint8_t* pBuffer, uint32_t WriteAddr, uint32_t NumByteToWrite)
|
||||
{
|
||||
uint8_t offset = WriteAddr % I2C_FLASH_PAGESIZE;
|
||||
uint8_t count = I2C_FLASH_PAGESIZE - offset;
|
||||
if (NumByteToWrite < count) {
|
||||
count = NumByteToWrite;
|
||||
}
|
||||
while (count > 0) {
|
||||
eepromPageWrite(pBuffer, WriteAddr, count);
|
||||
eepromWaitEepromStandbyState();
|
||||
WriteAddr += count;
|
||||
pBuffer += count;
|
||||
NumByteToWrite -= count;
|
||||
count = I2C_FLASH_PAGESIZE;
|
||||
if (NumByteToWrite < I2C_FLASH_PAGESIZE) {
|
||||
count = NumByteToWrite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes more than one byte to the EEPROM with a single WRITE cycle.
|
||||
* @note The number of byte can't exceed the EEPROM page size.
|
||||
* @param pBuffer : pointer to the buffer containing the data to be
|
||||
* written to the EEPROM.
|
||||
* @param WriteAddr : EEPROM's internal address to write to.
|
||||
* @param NumByteToWrite : number of bytes to write to the EEPROM.
|
||||
* @retval None
|
||||
*/
|
||||
bool I2C_EE_PageWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t NumByteToWrite)
|
||||
{
|
||||
if (!I2C_WaitEventCleared(I2C_FLAG_BUSY))
|
||||
return false;
|
||||
|
||||
I2C_GenerateSTART(I2C, ENABLE);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_MODE_SELECT))
|
||||
return false;
|
||||
|
||||
I2C_Send7bitAddress(I2C, I2C_ADDRESS_EEPROM, I2C_Direction_Transmitter);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
|
||||
return false;
|
||||
|
||||
I2C_SendData(I2C, (uint8_t)((WriteAddr & 0xFF00) >> 8));
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING))
|
||||
return false;
|
||||
I2C_SendData(I2C, (uint8_t)(WriteAddr & 0x00FF));
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING))
|
||||
return false;
|
||||
|
||||
/* While there is data to be written */
|
||||
while (NumByteToWrite--) {
|
||||
I2C_SendData(I2C, *pBuffer);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING))
|
||||
return false;
|
||||
pBuffer++;
|
||||
}
|
||||
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED))
|
||||
return false;
|
||||
|
||||
I2C_GenerateSTOP(I2C, ENABLE);
|
||||
return true;
|
||||
}
|
||||
|
||||
void eepromPageWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t NumByteToWrite)
|
||||
{
|
||||
while (!I2C_EE_PageWrite(pBuffer, WriteAddr, NumByteToWrite)) {
|
||||
i2cInit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait for EEPROM Standby state
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
bool I2C_EE_WaitEepromStandbyState(void)
|
||||
{
|
||||
do {
|
||||
I2C_GenerateSTART(I2C, ENABLE);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_MODE_SELECT))
|
||||
return false;
|
||||
|
||||
I2C_Send7bitAddress(I2C, I2C_ADDRESS_EEPROM, I2C_Direction_Transmitter);
|
||||
} while (!I2C_WaitEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
|
||||
|
||||
I2C_GenerateSTOP(I2C, ENABLE);
|
||||
return true;
|
||||
}
|
||||
|
||||
void eepromWaitEepromStandbyState(void)
|
||||
{
|
||||
while (!I2C_EE_WaitEepromStandbyState()) {
|
||||
i2cInit();
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(BOOT)
|
||||
void setVolume(uint8_t volume)
|
||||
{
|
||||
if (volume > VOLUME_LEVEL_MAX) {
|
||||
volume = VOLUME_LEVEL_MAX;
|
||||
}
|
||||
|
||||
if (!I2C_WaitEventCleared(I2C_FLAG_BUSY))
|
||||
return;
|
||||
|
||||
I2C_GenerateSTART(I2C, ENABLE);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_MODE_SELECT))
|
||||
return;
|
||||
|
||||
I2C_Send7bitAddress(I2C, I2C_ADDRESS_CAT5137, I2C_Direction_Transmitter);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
|
||||
return;
|
||||
|
||||
I2C_SendData(I2C, 0);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTING))
|
||||
return;
|
||||
I2C_SendData(I2C, volumeScale[volume]);
|
||||
if (!I2C_WaitEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED))
|
||||
return;
|
||||
|
||||
I2C_GenerateSTOP(I2C, ENABLE);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
uint8_t I2C_read_volume()
|
||||
{
|
||||
uint8_t volume ;
|
||||
I2C_START();
|
||||
I2C_SEND_DATA(I2C_ADDRESS_CAT5137|EE_CMD_WRITE);
|
||||
I2C_WAIT_ACK();
|
||||
I2C_SEND_DATA(0);
|
||||
I2C_WAIT_ACK();
|
||||
I2C_START();
|
||||
I2C_SEND_DATA(I2C_ADDRESS_CAT5137|EE_CMD_READ);
|
||||
I2C_WAIT_ACK();
|
||||
volume = I2C_READ();
|
||||
I2C_NO_ACK();
|
||||
I2C_STOP();
|
||||
return volume ;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,317 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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"
|
||||
|
||||
uint32_t readKeys()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
if (~KEYS_GPIO_REG_ENTER & KEYS_GPIO_PIN_ENTER)
|
||||
result |= 1 << KEY_ENTER;
|
||||
if (~KEYS_GPIO_REG_MENU & KEYS_GPIO_PIN_MENU)
|
||||
result |= 1 << KEY_MENU;
|
||||
if (~KEYS_GPIO_REG_PAGE & KEYS_GPIO_PIN_PAGE)
|
||||
result |= 1 << KEY_PAGE;
|
||||
if (~KEYS_GPIO_REG_EXIT & KEYS_GPIO_PIN_EXIT)
|
||||
result |= 1 << KEY_EXIT;
|
||||
|
||||
#if !defined(REV9E) || defined(SIMU)
|
||||
if (~KEYS_GPIO_REG_PLUS & KEYS_GPIO_PIN_PLUS)
|
||||
result |= 1 << KEY_PLUS;
|
||||
if (~KEYS_GPIO_REG_MINUS & KEYS_GPIO_PIN_MINUS)
|
||||
result |= 1 << KEY_MINUS;
|
||||
#endif
|
||||
|
||||
// TRACE("readKeys(): result=0x%02x", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t readTrims()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
if (~TRIMS_GPIO_REG_LHL & TRIMS_GPIO_PIN_LHL)
|
||||
result |= 0x01;
|
||||
if (~TRIMS_GPIO_REG_LHR & TRIMS_GPIO_PIN_LHR)
|
||||
result |= 0x02;
|
||||
if (~TRIMS_GPIO_REG_LVD & TRIMS_GPIO_PIN_LVD)
|
||||
result |= 0x04;
|
||||
if (~TRIMS_GPIO_REG_LVU & TRIMS_GPIO_PIN_LVU)
|
||||
result |= 0x08;
|
||||
if (~TRIMS_GPIO_REG_RVD & TRIMS_GPIO_PIN_RVD)
|
||||
result |= 0x10;
|
||||
if (~TRIMS_GPIO_REG_RVU & TRIMS_GPIO_PIN_RVU)
|
||||
result |= 0x20;
|
||||
if (~TRIMS_GPIO_REG_RHL & TRIMS_GPIO_PIN_RHL)
|
||||
result |= 0x40;
|
||||
if (~TRIMS_GPIO_REG_RHR & TRIMS_GPIO_PIN_RHR)
|
||||
result |= 0x80;
|
||||
|
||||
// TRACE("readTrims(): result=0x%02x", result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t trimDown(uint8_t idx)
|
||||
{
|
||||
return readTrims() & (1 << idx);
|
||||
}
|
||||
|
||||
uint8_t keyDown()
|
||||
{
|
||||
return readKeys();
|
||||
}
|
||||
|
||||
#if defined(REV9E)
|
||||
uint32_t Rotary_position;
|
||||
rotenc_t rotencValue;
|
||||
void checkRotaryEncoder()
|
||||
{
|
||||
register uint32_t dummy ;
|
||||
|
||||
dummy = ENC_GPIO->IDR; // Read Rotary encoder
|
||||
dummy >>= 12; // quick & dirty!
|
||||
dummy &= 0x03;
|
||||
if ( dummy != ( Rotary_position & 0x03 ) )
|
||||
{
|
||||
if ( ( Rotary_position & 0x01 ) ^ ( ( dummy & 0x02) >> 1 ) )
|
||||
{
|
||||
--rotencValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
++rotencValue;
|
||||
}
|
||||
Rotary_position &= ~0x03 ;
|
||||
Rotary_position |= dummy ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* TODO common to ARM */
|
||||
void readKeysAndTrims()
|
||||
{
|
||||
uint8_t enuk = 0;
|
||||
uint32_t in = readKeys();
|
||||
for (uint8_t i = 1; i != uint8_t(1 << TRM_BASE); i <<= 1) {
|
||||
keys[enuk++].input(in & i);
|
||||
}
|
||||
|
||||
#if defined(REV9E) && !defined(SIMU)
|
||||
#define X9E_RE_TIMEOUT 5
|
||||
static rotenc_t rePreviousValue;
|
||||
rotenc_t reNewValue = (rotencValue / 2);
|
||||
static int timeout = X9E_RE_TIMEOUT;
|
||||
static int lastkey = 0;
|
||||
int8_t scrollRE = reNewValue - rePreviousValue;
|
||||
if (scrollRE) {
|
||||
rePreviousValue = reNewValue;
|
||||
timeout = X9E_RE_TIMEOUT;
|
||||
if (scrollRE < 0) {
|
||||
if (lastkey != KEY_MINUS) {
|
||||
putEvent(EVT_KEY_BREAK(lastkey));
|
||||
}
|
||||
putEvent(EVT_KEY_FIRST(KEY_MINUS));
|
||||
lastkey = KEY_MINUS;
|
||||
}
|
||||
else {
|
||||
if (lastkey != KEY_PLUS) {
|
||||
putEvent(EVT_KEY_BREAK(lastkey));
|
||||
}
|
||||
putEvent(EVT_KEY_FIRST(KEY_PLUS));
|
||||
lastkey = KEY_PLUS;
|
||||
}
|
||||
}
|
||||
else if (timeout > 0) {
|
||||
timeout--;
|
||||
}
|
||||
else if (lastkey && timeout == 0) {
|
||||
putEvent(EVT_KEY_BREAK(lastkey));
|
||||
lastkey = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
in = readTrims();
|
||||
for (uint8_t i = 1; i != uint8_t(1 << 8); i <<= 1) {
|
||||
keys[enuk++].input(in & i);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(REV9E)
|
||||
#define ADD_2POS_CASE(x) \
|
||||
case SW_S ## x ## 2: \
|
||||
xxx = SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
|
||||
break; \
|
||||
case SW_S ## x ## 0: \
|
||||
xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
|
||||
break
|
||||
#define ADD_3POS_CASE(x, i) \
|
||||
case SW_S ## x ## 0: \
|
||||
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H) && (~SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
break; \
|
||||
case SW_S ## x ## 1: \
|
||||
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H) && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
break; \
|
||||
case SW_S ## x ## 2: \
|
||||
xxx = (~SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H) && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
break
|
||||
#define ADD_3POS_INVERTED_CASE(x, i) ADD_3POS_CASE(x, i)
|
||||
#else
|
||||
#define ADD_2POS_CASE(x) \
|
||||
case SW_S ## x ## 0: \
|
||||
xxx = SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
|
||||
break; \
|
||||
case SW_S ## x ## 2: \
|
||||
xxx = ~SWITCHES_GPIO_REG_ ## x & SWITCHES_GPIO_PIN_ ## x ; \
|
||||
break
|
||||
#define ADD_3POS_CASE(x, i) \
|
||||
case SW_S ## x ## 0: \
|
||||
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
|
||||
if (IS_3POS(i)) { \
|
||||
xxx = xxx && (~SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
} \
|
||||
break; \
|
||||
case SW_S ## x ## 1: \
|
||||
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H) && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
break; \
|
||||
case SW_S ## x ## 2: \
|
||||
xxx = (~SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
|
||||
if (IS_3POS(i)) { \
|
||||
xxx = xxx && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
} \
|
||||
break
|
||||
#define ADD_3POS_INVERTED_CASE(x, i) \
|
||||
case SW_S ## x ## 0: \
|
||||
xxx = (~SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
|
||||
if (IS_3POS(i)) { \
|
||||
xxx = xxx && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
} \
|
||||
break; \
|
||||
case SW_S ## x ## 1: \
|
||||
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H) && (SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
break; \
|
||||
case SW_S ## x ## 2: \
|
||||
xxx = (SWITCHES_GPIO_REG_ ## x ## _H & SWITCHES_GPIO_PIN_ ## x ## _H); \
|
||||
if (IS_3POS(i)) { \
|
||||
xxx = xxx && (~SWITCHES_GPIO_REG_ ## x ## _L & SWITCHES_GPIO_PIN_ ## x ## _L); \
|
||||
} \
|
||||
break
|
||||
#endif
|
||||
|
||||
#if !defined(BOOT)
|
||||
bool switchState(EnumKeys enuk)
|
||||
{
|
||||
register uint32_t xxx = 0;
|
||||
|
||||
if (enuk < (int) DIM(keys)) return keys[enuk].state() ? 1 : 0;
|
||||
|
||||
switch ((uint8_t) enuk) {
|
||||
ADD_3POS_CASE(A, 0);
|
||||
ADD_3POS_CASE(B, 1);
|
||||
ADD_3POS_CASE(C, 2);
|
||||
ADD_3POS_CASE(D, 3);
|
||||
ADD_3POS_INVERTED_CASE(E, 4);
|
||||
ADD_2POS_CASE(F);
|
||||
ADD_3POS_CASE(G, 6);
|
||||
ADD_2POS_CASE(H);
|
||||
#if defined(REV9E)
|
||||
ADD_3POS_CASE(I, 8);
|
||||
ADD_3POS_CASE(J, 9);
|
||||
ADD_3POS_CASE(K, 10);
|
||||
ADD_3POS_CASE(L, 11);
|
||||
ADD_3POS_CASE(M, 12);
|
||||
ADD_3POS_CASE(N, 13);
|
||||
ADD_3POS_CASE(O, 14);
|
||||
ADD_3POS_CASE(P, 15);
|
||||
ADD_3POS_CASE(Q, 16);
|
||||
ADD_3POS_CASE(R, 17);
|
||||
#endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// TRACE("switch %d => %d", enuk, xxx);
|
||||
return xxx;
|
||||
}
|
||||
#endif
|
||||
|
||||
void keysInit()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
|
||||
|
||||
#if defined(KEYS_GPIOA_PINS)
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOA_PINS;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOB_PINS)
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOB_PINS;
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOC_PINS)
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOC_PINS;
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOD_PINS)
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOD_PINS;
|
||||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOE_PINS)
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOE_PINS;
|
||||
GPIO_Init(GPIOE, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOF_PINS)
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOF_PINS;
|
||||
GPIO_Init(GPIOF, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#if defined(KEYS_GPIOG_PINS)
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOG_PINS;
|
||||
GPIO_Init(GPIOG, &GPIO_InitStructure);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,450 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file Project/lcd/lcd.c
|
||||
* @author FrSky Application Team
|
||||
* @Hardware version V0.2
|
||||
* @date 11-July-2012
|
||||
* @brief This file provides LCD Init and botom drivers.
|
||||
* *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "../../opentx.h"
|
||||
|
||||
#define WriteData(x) AspiData(x)
|
||||
#define WriteCommand(x) AspiCmd(x)
|
||||
|
||||
#if defined(REVPLUS)
|
||||
#define CONTRAST_OFS 160
|
||||
#define RESET_WAIT_DELAY_MS 300 //wait time after LCD reset before first command
|
||||
#define WAIT_FOR_DMA_END() { while(lcd_busy) {}; }
|
||||
#else
|
||||
#define CONTRAST_OFS 5
|
||||
#define RESET_WAIT_DELAY_MS 1300 //wait time after LCD reset before first command
|
||||
#define WAIT_FOR_DMA_END()
|
||||
#endif
|
||||
|
||||
bool lcdInitFinished = false;
|
||||
void lcdInitFinish();
|
||||
|
||||
/*
|
||||
delaysInit() must be called before the first call to this function!
|
||||
*/
|
||||
static void Delay(uint32_t ms)
|
||||
{
|
||||
while(ms--) {
|
||||
delay_01us(10000);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(REVPLUS)
|
||||
|
||||
// New hardware SPI driver for LCD
|
||||
void initLcdSpi()
|
||||
{
|
||||
// APB1 clock / 2 = 133nS per clock
|
||||
SPI3->CR1 = 0 ; // Clear any mode error
|
||||
SPI3->CR1 = SPI_CR1_SSM | SPI_CR1_SSI | SPI_CR1_CPOL | SPI_CR1_CPHA ;
|
||||
SPI3->CR2 = 0 ;
|
||||
SPI3->CR1 |= SPI_CR1_MSTR ; // Make sure in case SSM/SSI needed to be set first
|
||||
SPI3->CR1 |= SPI_CR1_SPE ;
|
||||
|
||||
configure_pins( LCD_GPIO_PIN_NCS, PIN_OUTPUT | PIN_PORTA | PIN_OS25) ;
|
||||
configure_pins( LCD_GPIO_PIN_RST, PIN_OUTPUT | PIN_PORTD | PIN_OS25) ;
|
||||
configure_pins( LCD_GPIO_PIN_A0, PIN_OUTPUT | PIN_PORTC | PIN_OS50) ;
|
||||
configure_pins( LCD_GPIO_PIN_MOSI|LCD_GPIO_PIN_CLK, PIN_PORTC | PIN_OS50 | PIN_PER_6 | PIN_PERIPHERAL ) ;
|
||||
|
||||
// NVIC_SetPriority( DMA1_Stream7_IRQn, 8 ) ;
|
||||
NVIC_EnableIRQ(DMA1_Stream7_IRQn) ;
|
||||
DMA1->HIFCR |= DMA_HIFCR_CTCIF7; //clear interrupt flag
|
||||
DMA1->LISR |= DMA_HISR_TCIF7; //enable DMA TX end interrupt
|
||||
|
||||
DMA1_Stream7->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
DMA1->HIFCR = DMA_HIFCR_CTCIF7 | DMA_HIFCR_CHTIF7 | DMA_HIFCR_CTEIF7 | DMA_HIFCR_CDMEIF7 | DMA_HIFCR_CFEIF7 ; // Write ones to clear bits
|
||||
DMA1_Stream7->CR = DMA_SxCR_PL_0 | DMA_SxCR_MINC | DMA_SxCR_DIR_0 ;
|
||||
DMA1_Stream7->PAR = (uint32_t) &SPI3->DR ;
|
||||
DMA1_Stream7->M0AR = (uint32_t)displayBuf;
|
||||
DMA1_Stream7->FCR = 0x05 ; //DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0 ;
|
||||
DMA1_Stream7->NDTR = LCD_W*LCD_H/8*4 ;
|
||||
}
|
||||
|
||||
static void LCD_Init()
|
||||
{
|
||||
WriteCommand(0x2F); //Internal pump control
|
||||
Delay(20);
|
||||
WriteCommand(0x24); //Temperature compensation
|
||||
WriteCommand(0xE9); //set bias=1/10
|
||||
WriteCommand(0x81); //Set Vop
|
||||
#if defined(BOOT)
|
||||
AspiCmd(CONTRAST_OFS+25);
|
||||
#else
|
||||
AspiCmd(CONTRAST_OFS+g_eeGeneral.contrast);
|
||||
#endif
|
||||
WriteCommand(0xA2); //set line rate:28KLPS
|
||||
WriteCommand(0x28); //set pannel loading
|
||||
WriteCommand(0x40); //scroll line LSB
|
||||
WriteCommand(0x50); //SCROLL LINE MSB
|
||||
WriteCommand(0x89); //ram address control
|
||||
WriteCommand(0xC0); //LCD mapping control
|
||||
WriteCommand(0x04); //MX=0,MY=1
|
||||
WriteCommand(0xD0); //DISPLAY PATTERN = 16-SCALE GRAY
|
||||
WriteCommand(0xF1); //SET COM end
|
||||
WriteCommand(0x3F); //64
|
||||
|
||||
WriteCommand(0xF8); //Set Window Program Disable.
|
||||
|
||||
WriteCommand(0xF5); //starting row address of RAM program window.PAGE1
|
||||
WriteCommand(0x00);
|
||||
WriteCommand(0xF7); //end row address of RAM program window.PAGE32
|
||||
WriteCommand(0x1F);
|
||||
WriteCommand(0xF4); //start column address of RAM program window.
|
||||
WriteCommand(0x00);
|
||||
WriteCommand(0xF6); //end column address of RAM program window.SEG212
|
||||
WriteCommand(0xD3);
|
||||
}
|
||||
#else
|
||||
static void LCD_Init()
|
||||
{
|
||||
AspiCmd(0x2B); //Panel loading set ,Internal VLCD.
|
||||
Delay(20);
|
||||
AspiCmd(0x25); //Temperature compensation curve definition: 0x25 = -0.05%/oC
|
||||
AspiCmd(0xEA); //set bias=1/10 :Command table NO.27
|
||||
AspiCmd(0x81); //Set Vop
|
||||
#if defined(BOOT)
|
||||
AspiCmd(CONTRAST_OFS+25);
|
||||
#else
|
||||
AspiCmd(CONTRAST_OFS+g_eeGeneral.contrast);
|
||||
#endif
|
||||
AspiCmd(0xA6); //inverse display off
|
||||
AspiCmd(0xD1); //SET RGB:Command table NO.21 .SET RGB or BGR. D1=RGB
|
||||
AspiCmd(0xD5); //set color mode 4K and 12bits :Command table NO.22
|
||||
AspiCmd(0xA0); //line rates,25.2 Klps
|
||||
AspiCmd(0xC8); //SET N-LINE INVERSION
|
||||
AspiCmd(0x1D); //Disable NIV
|
||||
AspiCmd(0xF1); //Set CEN
|
||||
AspiCmd(0x3F); // 1/64DUTY
|
||||
AspiCmd(0x84); //Disable Partial Display
|
||||
AspiCmd(0xC4); //MY=1,MX=0
|
||||
AspiCmd(0x89); //WA=1,column (CA) increment (+1) first until CA reaches CA boundary, then RA will increment by (+1).
|
||||
|
||||
AspiCmd(0xF8); //Set Window Program Enable ,inside modle
|
||||
AspiCmd(0xF4); //starting column address of RAM program window.
|
||||
AspiCmd(0x00);
|
||||
AspiCmd(0xF5); //starting row address of RAM program window.
|
||||
AspiCmd(0x60);
|
||||
AspiCmd(0xF6); //ending column address of RAM program window.
|
||||
AspiCmd(0x47);
|
||||
AspiCmd(0xF7); //ending row address of RAM program window.
|
||||
AspiCmd(0x9F);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Set_Address(u8 x, u8 y)
|
||||
{
|
||||
WriteCommand(x&0x0F); //Set Column Address LSB CA[3:0]
|
||||
WriteCommand((x>>4)|0x10); //Set Column Address MSB CA[7:4]
|
||||
|
||||
WriteCommand((y&0x0F)|0x60); //Set Row Address LSB RA [3:0]
|
||||
WriteCommand(((y>>4)&0x0F)|0x70); //Set Row Address MSB RA [7:4]
|
||||
}
|
||||
|
||||
#define LCD_WRITE_BIT(bit) \
|
||||
if (bit) \
|
||||
LCD_MOSI_HIGH(); \
|
||||
else \
|
||||
LCD_MOSI_LOW(); \
|
||||
LCD_CLK_LOW(); \
|
||||
LCD_CLK_LOW(); \
|
||||
LCD_CLK_LOW(); \
|
||||
LCD_CLK_HIGH(); \
|
||||
LCD_CLK_HIGH();
|
||||
|
||||
#if defined(REVPLUS)
|
||||
|
||||
volatile bool lcd_busy;
|
||||
|
||||
#if !defined(LCD_DUAL_BUFFER)
|
||||
void lcdRefreshWait()
|
||||
{
|
||||
WAIT_FOR_DMA_END();
|
||||
}
|
||||
#endif
|
||||
|
||||
void lcdRefresh(bool wait)
|
||||
{
|
||||
if (!lcdInitFinished) {
|
||||
lcdInitFinish();
|
||||
}
|
||||
|
||||
//wait if previous DMA transfer still active
|
||||
WAIT_FOR_DMA_END();
|
||||
lcd_busy = true;
|
||||
|
||||
Set_Address(0, 0);
|
||||
|
||||
LCD_NCS_LOW();
|
||||
LCD_A0_HIGH();
|
||||
|
||||
DMA1_Stream7->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
DMA1->HIFCR = DMA_HIFCR_CTCIF7 | DMA_HIFCR_CHTIF7 | DMA_HIFCR_CTEIF7 | DMA_HIFCR_CDMEIF7 | DMA_HIFCR_CFEIF7 ; // Write ones to clear bits
|
||||
|
||||
#if defined(LCD_DUAL_BUFFER)
|
||||
//switch LCD buffer
|
||||
DMA1_Stream7->M0AR = (uint32_t)displayBuf;
|
||||
displayBuf = (displayBuf == displayBuf1) ? displayBuf2 : displayBuf1;
|
||||
#endif
|
||||
|
||||
DMA1_Stream7->CR |= DMA_SxCR_EN | DMA_SxCR_TCIE; // Enable DMA & tXe interrupt
|
||||
SPI3->CR2 |= SPI_CR2_TXDMAEN ;
|
||||
}
|
||||
|
||||
extern "C" void DMA1_Stream7_IRQHandler()
|
||||
{
|
||||
//clear interrupt flag
|
||||
DMA1_Stream7->CR &= ~DMA_SxCR_TCIE ; // Stop interrupt
|
||||
DMA1->HIFCR |= DMA_HIFCR_CTCIF7; // Clear interrupt flag
|
||||
SPI3->CR2 &= ~SPI_CR2_TXDMAEN ;
|
||||
DMA1_Stream7->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
|
||||
while ( SPI3->SR & SPI_SR_BSY ) {
|
||||
/* Wait for SPI to finish sending data
|
||||
The DMA TX End interrupt comes two bytes before the end of SPI transmission,
|
||||
therefore we have to wait here.
|
||||
*/
|
||||
}
|
||||
LCD_NCS_HIGH();
|
||||
lcd_busy = false;
|
||||
}
|
||||
|
||||
#else // #if defined(REVPLUS)
|
||||
void lcdRefresh()
|
||||
{
|
||||
if (!lcdInitFinished) {
|
||||
lcdInitFinish();
|
||||
}
|
||||
|
||||
for (uint32_t y=0; y<LCD_H; y++) {
|
||||
uint8_t *p = &displayBuf[y/2 * LCD_W];
|
||||
|
||||
Set_Address(0, y);
|
||||
AspiCmd(0xAF);
|
||||
|
||||
LCD_CLK_HIGH();
|
||||
LCD_A0_HIGH();
|
||||
LCD_NCS_LOW();
|
||||
|
||||
for (uint32_t x=0; x<LCD_W; x++) {
|
||||
uint8_t b = p[x];
|
||||
if (y & 1)
|
||||
b >>= 4;
|
||||
LCD_WRITE_BIT(b & 0x08);
|
||||
LCD_WRITE_BIT(b & 0x04);
|
||||
LCD_WRITE_BIT(b & 0x02);
|
||||
LCD_WRITE_BIT(b & 0x01);
|
||||
}
|
||||
|
||||
LCD_NCS_HIGH();
|
||||
LCD_A0_HIGH();
|
||||
|
||||
WriteData(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void backlightInit()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
#if defined(REV9E)
|
||||
GPIO_InitStructure.GPIO_Pin = BACKLIGHT_GPIO_PIN_1|BACKLIGHT_GPIO_PIN_2;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(BACKLIGHT_GPIO, &GPIO_InitStructure);
|
||||
GPIO_PinAFConfig(BACKLIGHT_GPIO, BACKLIGHT_GPIO_PinSource_1, BACKLIGHT_GPIO_AF_1);
|
||||
GPIO_PinAFConfig(BACKLIGHT_GPIO, BACKLIGHT_GPIO_PinSource_2, BACKLIGHT_GPIO_AF_1);
|
||||
BACKLIGHT_TIMER->ARR = 100 ;
|
||||
BACKLIGHT_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 50000 - 1; // 20us * 100 = 2ms => 500Hz
|
||||
BACKLIGHT_TIMER->CCMR1 = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 ; // PWM
|
||||
BACKLIGHT_TIMER->CCER = TIM_CCER_CC1E | TIM_CCER_CC2E ;
|
||||
BACKLIGHT_TIMER->CCR2 = 0 ;
|
||||
BACKLIGHT_TIMER->CCR1 = 100 ;
|
||||
BACKLIGHT_TIMER->EGR = 0 ;
|
||||
BACKLIGHT_TIMER->CR1 = TIM_CR1_CEN ; // Counter enable
|
||||
#elif defined(REVPLUS)
|
||||
GPIO_InitStructure.GPIO_Pin = BACKLIGHT_GPIO_PIN_1|BACKLIGHT_GPIO_PIN_2;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(BACKLIGHT_GPIO, &GPIO_InitStructure);
|
||||
GPIO_PinAFConfig(BACKLIGHT_GPIO, BACKLIGHT_GPIO_PinSource_1, BACKLIGHT_GPIO_AF_1);
|
||||
GPIO_PinAFConfig(BACKLIGHT_GPIO, BACKLIGHT_GPIO_PinSource_2, BACKLIGHT_GPIO_AF_1);
|
||||
BACKLIGHT_TIMER->ARR = 100 ;
|
||||
BACKLIGHT_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 50000 - 1; // 20us * 100 = 2ms => 500Hz
|
||||
BACKLIGHT_TIMER->CCMR1 = TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 ; // PWM
|
||||
BACKLIGHT_TIMER->CCMR2 = TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2 ; // PWM
|
||||
BACKLIGHT_TIMER->CCER = TIM_CCER_CC4E | TIM_CCER_CC2E ;
|
||||
BACKLIGHT_TIMER->CCR2 = 0 ;
|
||||
BACKLIGHT_TIMER->CCR4 = 100 ;
|
||||
BACKLIGHT_TIMER->EGR = 0 ;
|
||||
BACKLIGHT_TIMER->CR1 = TIM_CR1_CEN ; // Counter enable
|
||||
#else
|
||||
GPIO_InitStructure.GPIO_Pin = BACKLIGHT_GPIO_PIN_1;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(BACKLIGHT_GPIO, &GPIO_InitStructure);
|
||||
GPIO_PinAFConfig(BACKLIGHT_GPIO, BACKLIGHT_GPIO_PinSource_1, BACKLIGHT_GPIO_AF_1);
|
||||
BACKLIGHT_TIMER->ARR = 100 ;
|
||||
BACKLIGHT_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 50000 - 1; // 20us * 100 = 2ms => 500Hz
|
||||
BACKLIGHT_TIMER->CCMR1 = 0x60 ; // PWM
|
||||
BACKLIGHT_TIMER->CCER = 1 ;
|
||||
BACKLIGHT_TIMER->CCR1 = 80;
|
||||
BACKLIGHT_TIMER->EGR = 0 ;
|
||||
BACKLIGHT_TIMER->CR1 = 1 ;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Init the analog SPI GPIO
|
||||
*/
|
||||
static void LCD_Hardware_Init()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
/*!< Configure lcd CLK\ MOSI\ A0pin in output push-pull mode *************/
|
||||
GPIO_InitStructure.GPIO_Pin = LCD_GPIO_PIN_MOSI | LCD_GPIO_PIN_CLK | LCD_GPIO_PIN_A0;
|
||||
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(LCD_GPIO_SPI, &GPIO_InitStructure);
|
||||
|
||||
LCD_NCS_HIGH();
|
||||
|
||||
/*!< Configure lcd NCS pin in output push-pull mode ,PULLUP *************/
|
||||
GPIO_InitStructure.GPIO_Pin = LCD_GPIO_PIN_NCS;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_Init(LCD_GPIO_NCS, &GPIO_InitStructure);
|
||||
|
||||
/*!< Configure lcd RST pin in output pushpull mode ,PULLUP *************/
|
||||
GPIO_InitStructure.GPIO_Pin = LCD_GPIO_PIN_RST;
|
||||
GPIO_Init(LCD_GPIO_RST, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
/*
|
||||
Proper method for turning of LCD module. It must be used,
|
||||
otherwise we might damage LCD crystals in the long run!
|
||||
*/
|
||||
void lcdOff()
|
||||
{
|
||||
WAIT_FOR_DMA_END();
|
||||
/*
|
||||
LCD Sleep mode is also good for draining capacitors and enables us
|
||||
to re-init LCD without any delay
|
||||
*/
|
||||
AspiCmd(0xAE); //LCD sleep
|
||||
Delay(3); //wait for caps to drain
|
||||
}
|
||||
|
||||
/*
|
||||
Starts LCD initialization routine. It should be called as
|
||||
soon as possible after the reset because LCD takes a lot of
|
||||
time to properly power-on.
|
||||
|
||||
Make sure that Delay() is functional before calling this function!
|
||||
*/
|
||||
void lcdInit()
|
||||
{
|
||||
LCD_Hardware_Init();
|
||||
|
||||
if (WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) return; //no need to reset LCD module
|
||||
|
||||
//reset LCD module
|
||||
LCD_RST_LOW();
|
||||
Delay(1); // only 3 us needed according to data-sheet, we use 1 ms
|
||||
LCD_RST_HIGH();
|
||||
}
|
||||
|
||||
/*
|
||||
Finishes LCD initialization. It is called auto-magically when first LCD command is
|
||||
issued by the other parts of the code.
|
||||
*/
|
||||
void lcdInitFinish()
|
||||
{
|
||||
lcdInitFinished = true;
|
||||
|
||||
#if defined(REVPLUS)
|
||||
initLcdSpi();
|
||||
#endif
|
||||
|
||||
/*
|
||||
LCD needs longer time to initialize in low temperatures. The data-sheet
|
||||
mentions a time of at least 150 ms. The delay of 1300 ms was obtained
|
||||
experimentally. It was tested down to -10 deg Celsius.
|
||||
|
||||
The longer initialization time seems to only be needed for regular Taranis,
|
||||
the Taranis Plus (9XE) has been tested to work without any problems at -18 deg Celsius.
|
||||
Therefore the delay for T+ is lower.
|
||||
|
||||
If radio is reset by watchdog or boot-loader the wait is skipped, but the LCD
|
||||
is initialized in any case.
|
||||
|
||||
This initialization is needed in case the user moved power switch to OFF and
|
||||
then immediately to ON position, because lcdOff() was called. In any case the LCD
|
||||
initialization (without reset) is also recommended by the data sheet.
|
||||
*/
|
||||
|
||||
if (!WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
|
||||
#if !defined(BOOT)
|
||||
while(g_tmr10ms < (RESET_WAIT_DELAY_MS/10)) {}; //wait measured from the power-on
|
||||
#else
|
||||
Delay(RESET_WAIT_DELAY_MS);
|
||||
#endif
|
||||
}
|
||||
|
||||
LCD_Init();
|
||||
AspiCmd(0xAF); //dc2=1, IC into exit SLEEP MODE, dc3=1 gray=ON, dc4=1 Green Enhanc mode disabled
|
||||
Delay(20); //needed for internal DC-DC converter startup
|
||||
}
|
||||
|
||||
void lcdSetRefVolt(uint8_t val)
|
||||
{
|
||||
if (!lcdInitFinished) {
|
||||
lcdInitFinish();
|
||||
}
|
||||
WAIT_FOR_DMA_END();
|
||||
AspiCmd(0x81); //Set Vop
|
||||
AspiCmd(val+CONTRAST_OFS); //0--255
|
||||
}
|
||||
|
||||
#if defined(REV9E)
|
||||
void turnBacklightOn(uint8_t level, uint8_t color)
|
||||
{
|
||||
BACKLIGHT_TIMER->CCR1 = ((100-level)*(20-color))/20;
|
||||
BACKLIGHT_TIMER->CCR2 = ((100-level)*color)/20;
|
||||
}
|
||||
|
||||
void turnBacklightOff(void)
|
||||
{
|
||||
BACKLIGHT_TIMER->CCR1 = 0;
|
||||
BACKLIGHT_TIMER->CCR2 = 0;
|
||||
}
|
||||
#elif defined(REVPLUS)
|
||||
void turnBacklightOn(uint8_t level, uint8_t color)
|
||||
{
|
||||
BACKLIGHT_TIMER->CCR4 = ((100-level)*(20-color))/20;
|
||||
BACKLIGHT_TIMER->CCR2 = ((100-level)*color)/20;
|
||||
}
|
||||
|
||||
void turnBacklightOff(void)
|
||||
{
|
||||
BACKLIGHT_TIMER->CCR4 = 0;
|
||||
BACKLIGHT_TIMER->CCR2 = 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,589 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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);
|
||||
void setupPulsesPPM(unsigned int port);
|
||||
void setupPulsesPXX(unsigned int port);
|
||||
|
||||
static void intmodulePxxStart( void ) ;
|
||||
static void intmodulePxxStop( void ) ;
|
||||
#if defined(TARANIS_INTERNAL_PPM)
|
||||
static void intmodulePpmStart( void ) ;
|
||||
static void intmodulePpmStop( void ) ;
|
||||
#endif
|
||||
static void extmodulePxxStart( void ) ;
|
||||
static void extmodulePxxStop( void ) ;
|
||||
#if defined(DSM2)
|
||||
static void extmoduleDsm2Start( void ) ;
|
||||
static void extmoduleDsm2Stop( void ) ;
|
||||
#endif
|
||||
static void extmodulePpmStart( void ) ;
|
||||
static void extmodulePpmStop( void ) ;
|
||||
static void intmoduleNoneStart( void ) ;
|
||||
static void intmoduleNoneStop( void ) ;
|
||||
static void extmoduleNoneStart( void ) ;
|
||||
static void extmoduleNoneStop( void ) ;
|
||||
|
||||
void init_pxx(uint32_t port)
|
||||
{
|
||||
if (port == INTERNAL_MODULE)
|
||||
intmodulePxxStart() ;
|
||||
else
|
||||
extmodulePxxStart() ;
|
||||
}
|
||||
|
||||
void disable_pxx(uint32_t port)
|
||||
{
|
||||
if (port == INTERNAL_MODULE)
|
||||
intmodulePxxStop() ;
|
||||
else
|
||||
extmodulePxxStop() ;
|
||||
}
|
||||
|
||||
#if defined(DSM2)
|
||||
void init_dsm2(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
extmoduleDsm2Start();
|
||||
}
|
||||
}
|
||||
|
||||
void disable_dsm2(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
extmoduleDsm2Stop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void init_ppm(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
extmodulePpmStart();
|
||||
}
|
||||
#if defined(TARANIS_INTERNAL_PPM)
|
||||
else if (port == INTERNAL_MODULE) {
|
||||
intmodulePpmStart();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void disable_ppm(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
extmodulePpmStop();
|
||||
}
|
||||
#if defined(TARANIS_INTERNAL_PPM)
|
||||
else if (port == INTERNAL_MODULE) {
|
||||
intmodulePpmStop();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_external_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive)
|
||||
{
|
||||
EXTMODULE_TIMER->CCR2 = idleTime;
|
||||
EXTMODULE_TIMER->CCR1 = delay;
|
||||
// we are using complementary output so logic has to be reversed here
|
||||
EXTMODULE_TIMER->CCER = TIM_CCER_CC1NE | (positive ? 0 : TIM_CCER_CC1NP);
|
||||
}
|
||||
|
||||
#if defined(TARANIS_INTERNAL_PPM)
|
||||
void set_internal_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive)
|
||||
{
|
||||
INTMODULE_TIMER->CCR2 = idleTime;
|
||||
INTMODULE_TIMER->CCR3 = delay;
|
||||
INTMODULE_TIMER->CCER = TIM_CCER_CC3E | (positive ? TIM_CCER_CC3P : 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
void init_no_pulses(uint32_t port)
|
||||
{
|
||||
if (port == INTERNAL_MODULE)
|
||||
intmoduleNoneStart();
|
||||
else
|
||||
extmoduleNoneStart();
|
||||
}
|
||||
|
||||
void disable_no_pulses(uint32_t port)
|
||||
{
|
||||
if (port == INTERNAL_MODULE)
|
||||
intmoduleNoneStop();
|
||||
else
|
||||
extmoduleNoneStop();
|
||||
}
|
||||
|
||||
static void intmoduleNoneStart()
|
||||
{
|
||||
INTERNAL_MODULE_OFF();
|
||||
|
||||
// Timer1, channel 3
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = INTMODULE_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(INTMODULE_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_SetBits(INTMODULE_GPIO, INTMODULE_GPIO_PIN) ; // Set high
|
||||
|
||||
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
INTMODULE_TIMER->ARR = 36000 ; // 18mS
|
||||
INTMODULE_TIMER->CCR2 = 32000 ; // Update time
|
||||
INTMODULE_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 2000000 - 1 ; // 0.5uS from 30MHz
|
||||
|
||||
INTMODULE_TIMER->CCER = TIM_CCER_CC3E ;
|
||||
|
||||
INTMODULE_TIMER->CCMR2 = 0 ;
|
||||
INTMODULE_TIMER->EGR = 1 ; // Restart
|
||||
|
||||
INTMODULE_TIMER->CCMR2 = TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_0 ; // Toggle CC1 o/p
|
||||
INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF ; // Clear flag
|
||||
INTMODULE_TIMER->DIER |= TIM_DIER_CC2IE ; // Enable this interrupt
|
||||
INTMODULE_TIMER->CR1 |= TIM_CR1_CEN ;
|
||||
NVIC_EnableIRQ(TIM1_CC_IRQn) ;
|
||||
NVIC_SetPriority(TIM1_CC_IRQn, 7);
|
||||
}
|
||||
|
||||
static void intmoduleNoneStop()
|
||||
{
|
||||
NVIC_DisableIRQ(TIM1_CC_IRQn) ;
|
||||
INTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE ;
|
||||
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
}
|
||||
|
||||
static void extmoduleNoneStart()
|
||||
{
|
||||
if (!IS_TRAINER_EXTERNAL_MODULE()) {
|
||||
EXTERNAL_MODULE_OFF();
|
||||
}
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = EXTMODULE_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
|
||||
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
EXTMODULE_TIMER->ARR = 36000 ; // 18mS
|
||||
EXTMODULE_TIMER->CCR2 = 32000 ; // Update time
|
||||
EXTMODULE_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 2000000 - 1 ; // 0.5uS from 30MHz
|
||||
|
||||
EXTMODULE_TIMER->CCMR2 = 0 ;
|
||||
EXTMODULE_TIMER->EGR = 1 ; // Restart
|
||||
|
||||
EXTMODULE_TIMER->CCMR2 = TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_0 ; // Toggle CC1 o/p
|
||||
EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF ; // Clear flag
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC2IE ; // Enable this interrupt
|
||||
EXTMODULE_TIMER->CR1 |= TIM_CR1_CEN ;
|
||||
NVIC_EnableIRQ(EXTMODULE_TIMER_IRQn) ;
|
||||
NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7);
|
||||
}
|
||||
|
||||
static void extmoduleNoneStop()
|
||||
{
|
||||
NVIC_DisableIRQ(EXTMODULE_TIMER_IRQn) ;
|
||||
EXTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE ;
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
}
|
||||
|
||||
static void intmodulePxxStart()
|
||||
{
|
||||
INTERNAL_MODULE_ON();
|
||||
|
||||
// Timer1, channel 3
|
||||
setupPulsesPXX(INTERNAL_MODULE) ; // TODO not here!
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
GPIO_PinAFConfig(INTMODULE_GPIO, INTMODULE_GPIO_PinSource, INTMODULE_GPIO_AF);
|
||||
GPIO_InitStructure.GPIO_Pin = INTMODULE_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(INTMODULE_GPIO, &GPIO_InitStructure);
|
||||
|
||||
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
INTMODULE_TIMER->ARR = 18000 ; // 9mS
|
||||
INTMODULE_TIMER->CCR2 = 15000 ; // Update time
|
||||
INTMODULE_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 2000000 - 1 ; // 0.5uS from 30MHz
|
||||
INTMODULE_TIMER->CCER = TIM_CCER_CC3E ;
|
||||
INTMODULE_TIMER->CR2 = TIM_CR2_OIS3 ; // O/P idle high
|
||||
INTMODULE_TIMER->BDTR = TIM_BDTR_MOE ; // Enable outputs
|
||||
INTMODULE_TIMER->CCR3 = modulePulsesData[INTERNAL_MODULE].pxx.pulses[0];
|
||||
INTMODULE_TIMER->CCMR2 = TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC3M_0 ; // Force O/P high
|
||||
INTMODULE_TIMER->EGR = 1 ; // Restart
|
||||
INTMODULE_TIMER->DIER |= TIM_DIER_CC3DE ; // Enable DMA on CC3 match
|
||||
INTMODULE_TIMER->DCR = 15 ; // DMA to CC1
|
||||
|
||||
// Enable the DMA channel here, DMA2 stream 6, channel 6
|
||||
DMA2_Stream6->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
DMA2->HIFCR = DMA_HIFCR_CTCIF6 | DMA_HIFCR_CHTIF6 | DMA_HIFCR_CTEIF6 | DMA_HIFCR_CDMEIF6 | DMA_HIFCR_CFEIF6 ; // Write ones to clear bits
|
||||
DMA2_Stream6->CR = 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_PFCTRL ;
|
||||
DMA2_Stream6->PAR = CONVERT_PTR_UINT(&INTMODULE_TIMER->DMAR);
|
||||
DMA2_Stream6->M0AR = CONVERT_PTR_UINT(&modulePulsesData[INTERNAL_MODULE].pxx.pulses[1]);
|
||||
DMA2_Stream6->CR |= DMA_SxCR_EN ; // Enable DMA
|
||||
|
||||
INTMODULE_TIMER->CCMR2 = TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_0 ; // Toggle CC1 o/p
|
||||
INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF ; // Clear flag
|
||||
INTMODULE_TIMER->DIER |= TIM_DIER_CC2IE ; // Enable this interrupt
|
||||
INTMODULE_TIMER->CR1 |= TIM_CR1_CEN ;
|
||||
NVIC_EnableIRQ(TIM1_CC_IRQn);
|
||||
NVIC_SetPriority(TIM1_CC_IRQn, 7);
|
||||
}
|
||||
|
||||
static void intmodulePxxStop()
|
||||
{
|
||||
DMA2_Stream6->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
NVIC_DisableIRQ(TIM1_CC_IRQn) ;
|
||||
INTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE ;
|
||||
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
INTERNAL_MODULE_OFF();
|
||||
}
|
||||
|
||||
#if defined(TARANIS_INTERNAL_PPM)
|
||||
// PPM output
|
||||
// Timer 1, channel 1 on PA8 for prototype
|
||||
// Pin is AF1 function for timer 1
|
||||
static void intmodulePpmStart()
|
||||
{
|
||||
INTERNAL_MODULE_ON();
|
||||
|
||||
// Timer1
|
||||
configure_pins(INTMODULE_GPIO_PIN, PIN_PERIPHERAL | PIN_PORTA | PIN_PER_1 | PIN_OS25);
|
||||
|
||||
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
|
||||
// setupPulsesPPM() is also configuring registers,
|
||||
// so it has to be called after the peripheral is enabled
|
||||
setupPulsesPPM(INTERNAL_MODULE) ;
|
||||
|
||||
INTMODULE_TIMER->ARR = *modulePulsesData[INTERNAL_MODULE].ppm.ptr++ ;
|
||||
INTMODULE_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 2000000 - 1 ; // 0.5uS from 30MHz
|
||||
|
||||
INTMODULE_TIMER->CCER = TIM_CCER_CC3E ;
|
||||
|
||||
INTMODULE_TIMER->CCMR2 = TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_2 ; // PWM mode 1
|
||||
INTMODULE_TIMER->CCMR1 = TIM_CCMR1_OC2PE ; // PWM mode 1
|
||||
INTMODULE_TIMER->BDTR = TIM_BDTR_MOE ;
|
||||
INTMODULE_TIMER->EGR = 1 ;
|
||||
INTMODULE_TIMER->DIER = TIM_DIER_UDE ;
|
||||
|
||||
INTMODULE_TIMER->SR &= ~TIM_SR_UIF ; // Clear flag
|
||||
INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF ; // Clear flag
|
||||
INTMODULE_TIMER->DIER |= TIM_DIER_CC2IE ;
|
||||
INTMODULE_TIMER->DIER |= TIM_DIER_UIE ;
|
||||
|
||||
INTMODULE_TIMER->CR1 = TIM_CR1_CEN ;
|
||||
NVIC_EnableIRQ(TIM1_CC_IRQn) ;
|
||||
NVIC_SetPriority(TIM1_CC_IRQn, 7);
|
||||
NVIC_EnableIRQ(TIM1_UP_TIM10_IRQn) ;
|
||||
NVIC_SetPriority(TIM1_UP_TIM10_IRQn, 7);
|
||||
}
|
||||
|
||||
static void intmodulePpmStop()
|
||||
{
|
||||
NVIC_DisableIRQ(TIM1_CC_IRQn) ;
|
||||
NVIC_DisableIRQ(TIM1_UP_TIM10_IRQn) ;
|
||||
INTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE & ~TIM_DIER_UIE ;
|
||||
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
|
||||
INTERNAL_MODULE_OFF();
|
||||
}
|
||||
#endif // #if defined(TARANIS_INTERNAL_PPM)
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" void TIM1_CC_IRQHandler()
|
||||
{
|
||||
INTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE; // stop this interrupt
|
||||
INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; // clear flag
|
||||
DMA2_Stream6->CR &= ~DMA_SxCR_EN; // disable DMA, it will have the whole of the execution time of setupPulses() to actually stop
|
||||
|
||||
setupPulses(INTERNAL_MODULE);
|
||||
|
||||
if (s_current_protocol[INTERNAL_MODULE] == PROTO_PXX) {
|
||||
DMA2->HIFCR = DMA_HIFCR_CTCIF6 | DMA_HIFCR_CHTIF6 | DMA_HIFCR_CTEIF6 | DMA_HIFCR_CDMEIF6 | DMA_HIFCR_CFEIF6;
|
||||
DMA2_Stream6->M0AR = CONVERT_PTR_UINT(&modulePulsesData[INTERNAL_MODULE].pxx.pulses[1]);
|
||||
DMA2_Stream6->CR |= DMA_SxCR_EN; // enable DMA
|
||||
INTMODULE_TIMER->CCR3 = modulePulsesData[INTERNAL_MODULE].pxx.pulses[0];
|
||||
INTMODULE_TIMER->DIER |= TIM_DIER_CC2IE; // enable this interrupt
|
||||
}
|
||||
#if defined(TARANIS_INTERNAL_PPM)
|
||||
else if (s_current_protocol[INTERNAL_MODULE] == PROTO_PPM) {
|
||||
INTMODULE_TIMER->DIER |= TIM_DIER_UDE;
|
||||
INTMODULE_TIMER->SR &= ~TIM_SR_UIF;
|
||||
INTMODULE_TIMER->DIER |= TIM_DIER_UIE;
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
INTMODULE_TIMER->DIER |= TIM_DIER_CC2IE;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void TIM1_UP_TIM10_IRQHandler()
|
||||
{
|
||||
INTMODULE_TIMER->SR &= ~TIM_SR_UIF ; // Clear flag
|
||||
|
||||
INTMODULE_TIMER->ARR = *modulePulsesData[INTERNAL_MODULE].ppm.ptr++ ;
|
||||
if (*modulePulsesData[INTERNAL_MODULE].ppm.ptr == 0) {
|
||||
INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF ; // Clear this flag
|
||||
INTMODULE_TIMER->DIER |= TIM_DIER_CC2IE ; // Enable this interrupt
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void extmodulePxxStart()
|
||||
{
|
||||
EXTERNAL_MODULE_ON();
|
||||
|
||||
// Timer8
|
||||
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_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);
|
||||
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
EXTMODULE_TIMER->ARR = 18000 ; // 9mS
|
||||
EXTMODULE_TIMER->CCR2 = 15000 ; // Update time
|
||||
EXTMODULE_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 2000000 - 1 ; // 0.5uS from 30MHz
|
||||
EXTMODULE_TIMER->CCER = TIM_CCER_CC1NE ;
|
||||
EXTMODULE_TIMER->CR2 = TIM_CR2_OIS1 ; // O/P idle high
|
||||
EXTMODULE_TIMER->BDTR = TIM_BDTR_MOE ; // Enable outputs
|
||||
EXTMODULE_TIMER->CCR1 = modulePulsesData[EXTERNAL_MODULE].pxx.pulses[0];
|
||||
EXTMODULE_TIMER->CCMR1 = TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_0 ; // Force O/P high
|
||||
EXTMODULE_TIMER->EGR = 1 ; // Restart
|
||||
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC1DE ; // Enable DMA on CC1 match
|
||||
EXTMODULE_TIMER->DCR = 13 ; // DMA to CC1
|
||||
|
||||
// Enable the DMA channel here, DMA2 stream 2, channel 7
|
||||
DMA2_Stream2->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
DMA2->LIFCR = DMA_LIFCR_CTCIF2 | DMA_LIFCR_CHTIF2 | DMA_LIFCR_CTEIF2 | DMA_LIFCR_CDMEIF2 | DMA_LIFCR_CFEIF2 ; // Write ones to clear bits
|
||||
DMA2_Stream2->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_PFCTRL ;
|
||||
DMA2_Stream2->PAR = CONVERT_PTR_UINT(&EXTMODULE_TIMER->DMAR);
|
||||
DMA2_Stream2->M0AR = CONVERT_PTR_UINT(&modulePulsesData[EXTERNAL_MODULE].pxx.pulses[1]);
|
||||
// DMA2_Stream2->FCR = 0x05 ; //DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0 ;
|
||||
// DMA2_Stream2->NDTR = 100 ;
|
||||
DMA2_Stream2->CR |= DMA_SxCR_EN ; // Enable DMA
|
||||
|
||||
EXTMODULE_TIMER->CCMR1 = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0 ; // Toggle CC1 o/p
|
||||
EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF ; // Clear flag
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC2IE ; // Enable this interrupt
|
||||
EXTMODULE_TIMER->CR1 |= TIM_CR1_CEN ;
|
||||
NVIC_EnableIRQ(EXTMODULE_TIMER_IRQn) ;
|
||||
NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7);
|
||||
}
|
||||
|
||||
static void extmodulePxxStop()
|
||||
{
|
||||
DMA2_Stream2->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
NVIC_DisableIRQ(EXTMODULE_TIMER_IRQn) ;
|
||||
EXTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE ;
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
if (!IS_TRAINER_EXTERNAL_MODULE()) {
|
||||
EXTERNAL_MODULE_OFF();
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(DSM2)
|
||||
static void extmoduleDsm2Start()
|
||||
{
|
||||
EXTERNAL_MODULE_ON();
|
||||
|
||||
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_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);
|
||||
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
EXTMODULE_TIMER->ARR = 44000 ; // 22mS
|
||||
EXTMODULE_TIMER->CCR2 = 40000 ; // Update time
|
||||
EXTMODULE_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 2000000 - 1 ; // 0.5uS from 30MHz
|
||||
EXTMODULE_TIMER->CCER = TIM_CCER_CC1NE | TIM_CCER_CC1NP ;
|
||||
EXTMODULE_TIMER->CR2 = TIM_CR2_OIS1 ; // O/P idle high
|
||||
EXTMODULE_TIMER->BDTR = TIM_BDTR_MOE ; // Enable outputs
|
||||
EXTMODULE_TIMER->CCR1 = modulePulsesData[EXTERNAL_MODULE].dsm2.pulses[0];
|
||||
EXTMODULE_TIMER->CCMR1 = TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_0 ; // Force O/P high
|
||||
EXTMODULE_TIMER->EGR = 1 ; // Restart
|
||||
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC1DE ; // Enable DMA on CC1 match
|
||||
EXTMODULE_TIMER->DCR = 13 ; // DMA to CC1
|
||||
|
||||
// Enable the DMA channel here, DMA2 stream 2, channel 7
|
||||
DMA2_Stream2->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
DMA2->LIFCR = DMA_LIFCR_CTCIF2 | DMA_LIFCR_CHTIF2 | DMA_LIFCR_CTEIF2 | DMA_LIFCR_CDMEIF2 | DMA_LIFCR_CFEIF2 ; // Write ones to clear bits
|
||||
DMA2_Stream2->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_PFCTRL ;
|
||||
DMA2_Stream2->PAR = CONVERT_PTR_UINT(&EXTMODULE_TIMER->DMAR);
|
||||
DMA2_Stream2->M0AR = CONVERT_PTR_UINT(&modulePulsesData[EXTERNAL_MODULE].dsm2.pulses[1]);
|
||||
// DMA2_Stream2->FCR = 0x05 ; //DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0 ;
|
||||
// DMA2_Stream2->NDTR = 100 ;
|
||||
DMA2_Stream2->CR |= DMA_SxCR_EN ; // Enable DMA
|
||||
|
||||
EXTMODULE_TIMER->CCMR1 = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0 ; // Toggle CC1 o/p
|
||||
EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF ; // Clear flag
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC2IE ; // Enable this interrupt
|
||||
EXTMODULE_TIMER->CR1 |= TIM_CR1_CEN ;
|
||||
NVIC_EnableIRQ(EXTMODULE_TIMER_IRQn) ;
|
||||
NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7);
|
||||
}
|
||||
|
||||
static void extmoduleDsm2Stop()
|
||||
{
|
||||
DMA2_Stream2->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
NVIC_DisableIRQ(EXTMODULE_TIMER_IRQn) ;
|
||||
EXTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE ;
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
if (!IS_TRAINER_EXTERNAL_MODULE()) {
|
||||
EXTERNAL_MODULE_OFF();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// PPM output
|
||||
// Timer 1, channel 1 on PA8 for prototype
|
||||
// Pin is AF1 function for timer 1
|
||||
static void extmodulePpmStart()
|
||||
{
|
||||
EXTERNAL_MODULE_ON();
|
||||
|
||||
// Timer1
|
||||
configure_pins(EXTMODULE_GPIO_PIN, PIN_PERIPHERAL | PIN_PORTA | PIN_PER_3 | PIN_OS25);
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
|
||||
// setupPulsesPPM() is also configuring registers,
|
||||
// so it has to be called after the peripheral is enabled
|
||||
setupPulsesPPM(EXTERNAL_MODULE) ;
|
||||
|
||||
EXTMODULE_TIMER->ARR = *modulePulsesData[EXTERNAL_MODULE].ppm.ptr++ ;
|
||||
EXTMODULE_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 2000000 - 1 ; // 0.5uS from 30MHz
|
||||
|
||||
EXTMODULE_TIMER->CCMR1 = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC2PE ; // PWM mode 1
|
||||
EXTMODULE_TIMER->BDTR = TIM_BDTR_MOE ;
|
||||
EXTMODULE_TIMER->EGR = 1 ;
|
||||
EXTMODULE_TIMER->DIER = TIM_DIER_UDE ;
|
||||
|
||||
EXTMODULE_TIMER->SR &= ~TIM_SR_UIF ; // Clear flag
|
||||
EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF ; // Clear flag
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC2IE ;
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_UIE ;
|
||||
|
||||
EXTMODULE_TIMER->CR1 = TIM_CR1_CEN ;
|
||||
NVIC_EnableIRQ(EXTMODULE_TIMER_IRQn) ;
|
||||
NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7);
|
||||
NVIC_EnableIRQ(TIM8_UP_TIM13_IRQn) ;
|
||||
NVIC_SetPriority(TIM8_UP_TIM13_IRQn, 7);
|
||||
}
|
||||
|
||||
static void extmodulePpmStop()
|
||||
{
|
||||
NVIC_DisableIRQ(EXTMODULE_TIMER_IRQn) ;
|
||||
NVIC_DisableIRQ(TIM8_UP_TIM13_IRQn) ;
|
||||
EXTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE & ~TIM_DIER_UIE ;
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
if (!IS_TRAINER_EXTERNAL_MODULE()) {
|
||||
EXTERNAL_MODULE_OFF();
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" void TIM8_CC_IRQHandler()
|
||||
{
|
||||
EXTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE ; // stop this interrupt
|
||||
EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF ; // Clear flag
|
||||
|
||||
setupPulses(EXTERNAL_MODULE) ;
|
||||
|
||||
if (s_current_protocol[EXTERNAL_MODULE] == PROTO_PXX) {
|
||||
DMA2_Stream2->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
DMA2->LIFCR = DMA_LIFCR_CTCIF2 | DMA_LIFCR_CHTIF2 | DMA_LIFCR_CTEIF2 | DMA_LIFCR_CDMEIF2 | DMA_LIFCR_CFEIF2 ; // Write ones to clear bits
|
||||
DMA2_Stream2->M0AR = CONVERT_PTR_UINT(&modulePulsesData[EXTERNAL_MODULE].pxx.pulses[1]);
|
||||
DMA2_Stream2->CR |= DMA_SxCR_EN ; // Enable DMA
|
||||
EXTMODULE_TIMER->CCR1 = modulePulsesData[EXTERNAL_MODULE].pxx.pulses[0];
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC2IE ; // Enable this interrupt
|
||||
}
|
||||
#if defined(DSM2)
|
||||
else if (s_current_protocol[EXTERNAL_MODULE] >= PROTO_DSM2_LP45 && s_current_protocol[EXTERNAL_MODULE] <= PROTO_DSM2_DSMX) {
|
||||
DMA2_Stream2->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
DMA2->LIFCR = DMA_LIFCR_CTCIF2 | DMA_LIFCR_CHTIF2 | DMA_LIFCR_CTEIF2 | DMA_LIFCR_CDMEIF2 | DMA_LIFCR_CFEIF2 ; // Write ones to clear bits
|
||||
DMA2_Stream2->M0AR = CONVERT_PTR_UINT(&modulePulsesData[EXTERNAL_MODULE].dsm2.pulses[1]);
|
||||
DMA2_Stream2->CR |= DMA_SxCR_EN ; // Enable DMA
|
||||
EXTMODULE_TIMER->CCR1 = modulePulsesData[EXTERNAL_MODULE].dsm2.pulses[0];
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC2IE ; // Enable this interrupt
|
||||
}
|
||||
#endif
|
||||
else if (s_current_protocol[EXTERNAL_MODULE] == PROTO_PPM) {
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_UDE ;
|
||||
EXTMODULE_TIMER->SR &= ~TIM_SR_UIF ; // Clear this flag
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_UIE ; // Enable this interrupt
|
||||
}
|
||||
else {
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC2IE ; // Enable this interrupt
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void TIM8_UP_TIM13_IRQHandler()
|
||||
{
|
||||
EXTMODULE_TIMER->SR &= ~TIM_SR_UIF ; // Clear flag
|
||||
|
||||
EXTMODULE_TIMER->ARR = *modulePulsesData[EXTERNAL_MODULE].ppm.ptr++ ;
|
||||
if (*modulePulsesData[EXTERNAL_MODULE].ppm.ptr == 0) {
|
||||
EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF ; // Clear this flag
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC2IE ; // Enable this interrupt
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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 "../../pwr.h"
|
||||
#include "../Taranis/board_taranis.h"
|
||||
|
||||
void pwrInit()
|
||||
{
|
||||
// if any changes are done to the PWR PIN or pwrOn() function
|
||||
// then the same changes must be done in _bootStart()
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = PWR_GPIO_PIN_ON;
|
||||
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_UP;
|
||||
GPIO_Init(PWR_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = PWR_GPIO_PIN_SWITCH;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_Init(PWR_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = PWR_GPIO_PIN_LED;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(PWR_GPIO_LED, &GPIO_InitStructure);
|
||||
|
||||
GPIO_ResetBits(INTMODULE_GPIO_PWR, INTMODULE_GPIO_PIN_PWR);
|
||||
GPIO_InitStructure.GPIO_Pin = INTMODULE_GPIO_PIN_PWR;
|
||||
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_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_Init(EXTMODULE_GPIO_PWR, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = TRAINER_GPIO_PIN_DETECT;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_Init(TRAINER_GPIO_DETECT, &GPIO_InitStructure);
|
||||
|
||||
pwrOn();
|
||||
}
|
||||
|
||||
void pwrOn()
|
||||
{
|
||||
GPIO_SetBits(PWR_GPIO, PWR_GPIO_PIN_ON);
|
||||
}
|
||||
|
||||
void pwrOff()
|
||||
{
|
||||
GPIO_ResetBits(PWR_GPIO, PWR_GPIO_PIN_ON);
|
||||
|
||||
// disable interrupts
|
||||
__disable_irq();
|
||||
|
||||
while(1) {
|
||||
wdt_reset();
|
||||
#if defined(REV9E)
|
||||
// 9E needs watchdog reset because CPU is still running while
|
||||
// the power key is held pressed by the user.
|
||||
// The power key should be released by now, but we must make sure
|
||||
if (!pwrPressed()) {
|
||||
// Put the CPU into sleep to reduce the consumption,
|
||||
// it might help with the RTC reset issue
|
||||
PWR->CR |= PWR_CR_CWUF;
|
||||
/* Select STANDBY mode */
|
||||
PWR->CR |= PWR_CR_PDDS;
|
||||
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
/* Request Wait For Event */
|
||||
__WFE();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
//this function must not return!
|
||||
}
|
||||
|
||||
#if defined(REV9E)
|
||||
uint32_t pwrPressed()
|
||||
{
|
||||
return GPIO_ReadInputDataBit(PWR_GPIO, PWR_GPIO_PIN_SWITCH) == Bit_RESET;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(REV9E)
|
||||
uint32_t pwrCheck()
|
||||
{
|
||||
#if defined(SIMU)
|
||||
return e_power_on;
|
||||
#else
|
||||
if (GPIO_ReadInputDataBit(PWR_GPIO, PWR_GPIO_PIN_SWITCH) == Bit_RESET)
|
||||
return e_power_on;
|
||||
else if (usbPlugged())
|
||||
return e_power_usb;
|
||||
else
|
||||
return e_power_off;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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 rtcSetTime(struct gtm * t)
|
||||
{
|
||||
RTC_TimeTypeDef RTC_TimeStruct;
|
||||
RTC_DateTypeDef RTC_DateStruct;
|
||||
|
||||
RTC_TimeStructInit(&RTC_TimeStruct);
|
||||
RTC_DateStructInit(&RTC_DateStruct);
|
||||
|
||||
RTC_TimeStruct.RTC_Hours = t->tm_hour;
|
||||
RTC_TimeStruct.RTC_Minutes = t->tm_min;
|
||||
RTC_TimeStruct.RTC_Seconds = t->tm_sec;
|
||||
RTC_DateStruct.RTC_Year = t->tm_year - 100;
|
||||
RTC_DateStruct.RTC_Month = t->tm_mon + 1;
|
||||
RTC_DateStruct.RTC_Date = t->tm_mday;
|
||||
|
||||
RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct);
|
||||
RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct);
|
||||
}
|
||||
|
||||
void rtcGetTime(struct gtm * t)
|
||||
{
|
||||
RTC_TimeTypeDef RTC_TimeStruct;
|
||||
RTC_DateTypeDef RTC_DateStruct;
|
||||
|
||||
RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
|
||||
RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct);
|
||||
|
||||
t->tm_hour = RTC_TimeStruct.RTC_Hours;
|
||||
t->tm_min = RTC_TimeStruct.RTC_Minutes;
|
||||
t->tm_sec = RTC_TimeStruct.RTC_Seconds;
|
||||
t->tm_year = RTC_DateStruct.RTC_Year + 100;
|
||||
t->tm_mon = RTC_DateStruct.RTC_Month - 1;
|
||||
t->tm_mday = RTC_DateStruct.RTC_Date;
|
||||
}
|
||||
|
||||
void rtcInit()
|
||||
{
|
||||
RTC_InitTypeDef RTC_InitStruct;
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||
PWR_BackupAccessCmd(ENABLE);
|
||||
RCC_LSEConfig(RCC_LSE_ON);
|
||||
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
|
||||
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
|
||||
RCC_RTCCLKCmd(ENABLE);
|
||||
RTC_WaitForSynchro();
|
||||
|
||||
// RTC time base = LSE / ((AsynchPrediv+1) * (SynchPrediv+1)) = 1 Hz*/
|
||||
RTC_InitStruct.RTC_HourFormat = RTC_HourFormat_24;
|
||||
RTC_InitStruct.RTC_AsynchPrediv = 127;
|
||||
RTC_InitStruct.RTC_SynchPrediv = 255;
|
||||
RTC_Init(&RTC_InitStruct);
|
||||
|
||||
struct gtm utm;
|
||||
rtcGetTime(&utm);
|
||||
g_rtcTime = gmktime(&utm);
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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"
|
||||
|
||||
uint8_t serial2Mode = 0;
|
||||
Fifo<512> serial2TxFifo;
|
||||
extern Fifo<512> telemetryFifo;
|
||||
extern Fifo<32> sbusFifo;
|
||||
|
||||
void uart3Setup(unsigned int baudrate)
|
||||
{
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
GPIO_PinAFConfig(SERIAL_GPIO, SERIAL_GPIO_PinSource_RX, SERIAL_GPIO_AF);
|
||||
GPIO_PinAFConfig(SERIAL_GPIO, SERIAL_GPIO_PinSource_TX, SERIAL_GPIO_AF);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = SERIAL_GPIO_PIN_TX | SERIAL_GPIO_PIN_RX;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(SERIAL_GPIO, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baudrate;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
|
||||
USART_Init(SERIAL_USART, &USART_InitStructure);
|
||||
USART_Cmd(SERIAL_USART, ENABLE);
|
||||
|
||||
USART_ITConfig(SERIAL_USART, USART_IT_RXNE, ENABLE);
|
||||
USART_ITConfig(SERIAL_USART, USART_IT_TXE, DISABLE);
|
||||
|
||||
NVIC_SetPriority(SERIAL_USART_IRQn, 7);
|
||||
NVIC_EnableIRQ(SERIAL_USART_IRQn);
|
||||
}
|
||||
|
||||
void serial2Init(unsigned int mode, unsigned int protocol)
|
||||
{
|
||||
USART_DeInit(SERIAL_USART);
|
||||
|
||||
serial2Mode = mode;
|
||||
|
||||
switch (mode) {
|
||||
case UART_MODE_TELEMETRY_MIRROR:
|
||||
uart3Setup(FRSKY_SPORT_BAUDRATE);
|
||||
break;
|
||||
#if !defined(USB_SERIAL) && (defined(DEBUG) || defined(CLI))
|
||||
case UART_MODE_DEBUG:
|
||||
uart3Setup(DEBUG_BAUDRATE);
|
||||
break;
|
||||
#endif
|
||||
case UART_MODE_TELEMETRY:
|
||||
if (protocol == PROTOCOL_FRSKY_D_SECONDARY) {
|
||||
uart3Setup(FRSKY_D_BAUDRATE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void serial2Putc(char c)
|
||||
{
|
||||
while (serial2TxFifo.isFull());
|
||||
serial2TxFifo.push(c);
|
||||
USART_ITConfig(SERIAL_USART, USART_IT_TXE, ENABLE);
|
||||
}
|
||||
|
||||
void serial2SbusInit()
|
||||
{
|
||||
uart3Setup(100000);
|
||||
SERIAL_USART->CR1 |= USART_CR1_M | USART_CR1_PCE ;
|
||||
}
|
||||
|
||||
void serial2Stop()
|
||||
{
|
||||
USART_DeInit(SERIAL_USART);
|
||||
}
|
||||
|
||||
uint8_t serial2TracesEnabled()
|
||||
{
|
||||
#if defined(DEBUG)
|
||||
return (serial2Mode == UART_MODE_DEBUG);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" void SERIAL_USART_IRQHandler(void)
|
||||
{
|
||||
// Send
|
||||
if (USART_GetITStatus(SERIAL_USART, USART_IT_TXE) != RESET) {
|
||||
uint8_t txchar;
|
||||
if (serial2TxFifo.pop(txchar)) {
|
||||
/* Write one byte to the transmit data register */
|
||||
USART_SendData(SERIAL_USART, txchar);
|
||||
}
|
||||
else {
|
||||
USART_ITConfig(SERIAL_USART, USART_IT_TXE, DISABLE);
|
||||
}
|
||||
}
|
||||
|
||||
// Receive
|
||||
uint32_t status = SERIAL_USART->SR;
|
||||
while (status & (USART_FLAG_RXNE | USART_FLAG_ERRORS)) {
|
||||
uint8_t data = SERIAL_USART->DR;
|
||||
|
||||
if (!(status & USART_FLAG_ERRORS)) {
|
||||
switch (serial2Mode) {
|
||||
case UART_MODE_TELEMETRY:
|
||||
telemetryFifo.push(data);
|
||||
break;
|
||||
case UART_MODE_SBUS_TRAINER:
|
||||
sbusFifo.push(data);
|
||||
break;
|
||||
#if !defined(USB_SERIAL) && defined(CLI)
|
||||
case UART_MODE_DEBUG:
|
||||
cliRxFifo.push(data);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
status = SERIAL_USART->SR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
**
|
||||
** File : stm32_flashboot.ld
|
||||
**
|
||||
** Abstract : Linker script for STM32F205 Device with
|
||||
** 0.5MByte FLASH, 128KByte SRAM
|
||||
**
|
||||
** Set heap size, stack size and stack location according
|
||||
** to application requirements.
|
||||
**
|
||||
** Set memory bank area and size if external memory is used.
|
||||
**
|
||||
** Target : STMicroelectronics STM32
|
||||
**
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
/* Entry Point */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Highest address of the user mode stack */
|
||||
_estack = 0x20020000; /* end of 128K SRAM */
|
||||
|
||||
/* Generate a link error if heap and stack don't fit into RAM */
|
||||
_Min_Heap_Size = 0; /* required amount of heap */
|
||||
_Main_Stack_Size = 1024; /* required amount of stack for interrupt stack (Main stack) */
|
||||
|
||||
/* Main stack end */
|
||||
_main_stack_start = _estack - _Main_Stack_Size;
|
||||
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
|
||||
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
|
||||
}
|
||||
|
||||
/* Define output sections */
|
||||
SECTIONS
|
||||
{
|
||||
/* The startup code goes first into FLASH */
|
||||
|
||||
/* The program code and other data goes into FLASH */
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
*(.version)
|
||||
. = ALIGN(4); /* Align the start of the text part */
|
||||
*(.text) /* .text sections (code) */
|
||||
*(.text*) /* .text* sections (code) */
|
||||
*(.rodata) /* .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
|
||||
*(.glue_7) /* glue arm to thumb code */
|
||||
*(.glue_7t) /* glue thumb to arm code */
|
||||
*(.eh_frame)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .; /* define a global symbols at end of code */
|
||||
} >RAM
|
||||
|
||||
|
||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >RAM
|
||||
.ARM : {
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
} >RAM
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array*))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
} >RAM
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array*))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
} >RAM
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(.fini_array*))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
} >RAM
|
||||
|
||||
/* used by the startup to initialize data */
|
||||
_sidata = .;
|
||||
|
||||
/* Initialized data sections goes into RAM, load LMA copy after code */
|
||||
.data : AT ( _sidata )
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sdata = .; /* create a global symbol at data start */
|
||||
*(.data) /* .data sections */
|
||||
*(.data*) /* .data* sections */
|
||||
|
||||
. = ALIGN(4);
|
||||
_edata = .; /* define a global symbol at data end */
|
||||
} >RAM
|
||||
|
||||
/* Uninitialized data section */
|
||||
. = ALIGN(4);
|
||||
.bss :
|
||||
{
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
_sbss = .; /* define a global symbol at bss start */
|
||||
__bss_start__ = _sbss;
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
_ebss = .; /* define a global symbol at bss end */
|
||||
__bss_end__ = _ebss;
|
||||
} >RAM
|
||||
|
||||
PROVIDE ( end = _ebss );
|
||||
PROVIDE ( _end = _ebss );
|
||||
|
||||
/* User_heap_stack section, used to check that there is enough RAM left */
|
||||
._user_heap_stack :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
. = . + _Min_Heap_Size;
|
||||
. = . + _Main_Stack_Size;
|
||||
. = ALIGN(4);
|
||||
} >RAM
|
||||
|
||||
/* MEMORY_bank1 section, code must be located here explicitly */
|
||||
/* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
|
||||
.memory_b1_text :
|
||||
{
|
||||
*(.mb1text) /* .mb1text sections (code) */
|
||||
*(.mb1text*) /* .mb1text* sections (code) */
|
||||
*(.mb1rodata) /* read-only data (constants) */
|
||||
*(.mb1rodata*)
|
||||
} >MEMORY_B1
|
||||
|
||||
/* Remove information from the standard libraries */
|
||||
/DISCARD/ :
|
||||
{
|
||||
libc.a ( * )
|
||||
libm.a ( * )
|
||||
libgcc.a ( * )
|
||||
}
|
||||
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
**
|
||||
** File : stm32f2_flash.ld
|
||||
**
|
||||
** Abstract : Linker script for STM32F205 Device with
|
||||
** 0.5MByte FLASH, 128KByte SRAM
|
||||
**
|
||||
** Set heap size, stack size and stack location according
|
||||
** to application requirements.
|
||||
**
|
||||
** Set memory bank area and size if external memory is used.
|
||||
**
|
||||
** Target : STMicroelectronics STM32
|
||||
**
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
/* Entry Point */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Highest address of the user mode stack */
|
||||
_estack = 0x20020000; /* end of 128K SRAM */
|
||||
|
||||
/* Generate a link error if heap and stack don't fit into RAM */
|
||||
_Min_Heap_Size = 0; /* required amount of heap */
|
||||
_Main_Stack_Size = 1024; /* required amount of stack for interrupt stack (Main stack) */
|
||||
|
||||
/* Main stack end */
|
||||
_main_stack_start = _estack - _Main_Stack_Size;
|
||||
_heap_end = _main_stack_start;
|
||||
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
|
||||
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
|
||||
}
|
||||
|
||||
/* Define output sections */
|
||||
SECTIONS
|
||||
{
|
||||
/* The startup code goes first into FLASH */
|
||||
|
||||
/* The program code and other data goes into FLASH */
|
||||
.text :
|
||||
{
|
||||
FILL(0xFFFF)
|
||||
|
||||
CREATE_OBJECT_SYMBOLS
|
||||
|
||||
KEEP(*(.isr_boot_vector)) /* Startup code */
|
||||
*(.bootrodata)
|
||||
*(.bootrodata.*)
|
||||
|
||||
. = 32768; /* Set the start of the main program */
|
||||
_stext = .; /* Provide the name for the start of this section */
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
*(.text) /* .text sections (code) */
|
||||
*(.text*) /* .text* sections (code) */
|
||||
*(.rodata) /* .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
|
||||
*(.glue_7) /* glue arm to thumb code */
|
||||
*(.glue_7t) /* glue thumb to arm code */
|
||||
*(.eh_frame)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .; /* define a global symbols at end of code */
|
||||
} >FLASH
|
||||
|
||||
|
||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
|
||||
.ARM : {
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
} >FLASH
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array*))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
} >FLASH
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array*))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
} >FLASH
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(.fini_array*))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
} >FLASH
|
||||
|
||||
/* used by the startup to initialize data */
|
||||
_sidata = .;
|
||||
|
||||
/* Initialized data sections goes into RAM, load LMA copy after code */
|
||||
.data : AT ( _sidata )
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sdata = .; /* create a global symbol at data start */
|
||||
*(.data) /* .data sections */
|
||||
*(.data*) /* .data* sections */
|
||||
|
||||
. = ALIGN(4);
|
||||
_edata = .; /* define a global symbol at data end */
|
||||
} >RAM
|
||||
|
||||
/* Uninitialized data section */
|
||||
. = ALIGN(4);
|
||||
.bss :
|
||||
{
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
_sbss = .; /* define a global symbol at bss start */
|
||||
__bss_start__ = _sbss;
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
_ebss = .; /* define a global symbol at bss end */
|
||||
__bss_end__ = _ebss;
|
||||
} >RAM
|
||||
|
||||
PROVIDE ( end = _ebss );
|
||||
PROVIDE ( _end = _ebss );
|
||||
|
||||
/* User_heap_stack section, used to check that there is enough RAM left */
|
||||
._user_heap_stack :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
. = . + _Min_Heap_Size;
|
||||
. = . + _Main_Stack_Size;
|
||||
. = ALIGN(4);
|
||||
} >RAM
|
||||
|
||||
/* MEMORY_bank1 section, code must be located here explicitly */
|
||||
/* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
|
||||
.memory_b1_text :
|
||||
{
|
||||
*(.mb1text) /* .mb1text sections (code) */
|
||||
*(.mb1text*) /* .mb1text* sections (code) */
|
||||
*(.mb1rodata) /* read-only data (constants) */
|
||||
*(.mb1rodata*)
|
||||
} >MEMORY_B1
|
||||
|
||||
/* Remove information from the standard libraries */
|
||||
/DISCARD/ :
|
||||
{
|
||||
libc.a ( * )
|
||||
libm.a ( * )
|
||||
libgcc.a ( * )
|
||||
}
|
||||
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
**
|
||||
** File : stm32f4_flash.ld
|
||||
**
|
||||
** Abstract : Linker script for STM32F407 Device with
|
||||
** 0.5MByte FLASH, 128KByte SRAM, 64KByte CCM
|
||||
**
|
||||
** Set heap size, stack size and stack location according
|
||||
** to application requirements.
|
||||
**
|
||||
** Set memory bank area and size if external memory is used.
|
||||
**
|
||||
** Target : STMicroelectronics STM32
|
||||
**
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
/* Entry Point */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Highest address of the user mode stack */
|
||||
_estack = 0x10010000; /* end of 64K CCM */
|
||||
_heap_end = 0x20020000; /* end of 128K SRAM */
|
||||
|
||||
/* Generate a link error if heap and stack don't fit into RAM */
|
||||
_Min_Heap_Size = 0; /* required amount of heap */
|
||||
_Main_Stack_Size = 1024; /* required amount of stack for interrupt stack (Main stack) */
|
||||
|
||||
/* Main stack end */
|
||||
_main_stack_start = _estack - _Main_Stack_Size;
|
||||
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
|
||||
CCM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
|
||||
MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K
|
||||
}
|
||||
|
||||
/* Define output sections */
|
||||
SECTIONS
|
||||
{
|
||||
/* The startup code goes first into FLASH */
|
||||
|
||||
/* The program code and other data goes into FLASH */
|
||||
.text :
|
||||
{
|
||||
FILL(0xFFFF)
|
||||
|
||||
CREATE_OBJECT_SYMBOLS
|
||||
|
||||
KEEP(*(.isr_boot_vector)) /* Startup code */
|
||||
*(.bootrodata)
|
||||
*(.bootrodata.*)
|
||||
|
||||
. = 32768; /* Set the start of the main program */
|
||||
_stext = .; /* Provide the name for the start of this section */
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
*(.text) /* .text sections (code) */
|
||||
*(.text*) /* .text* sections (code) */
|
||||
*(.rodata) /* .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
|
||||
*(.glue_7) /* glue arm to thumb code */
|
||||
*(.glue_7t) /* glue thumb to arm code */
|
||||
*(.eh_frame)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .; /* define a global symbols at end of code */
|
||||
} >FLASH
|
||||
|
||||
|
||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
|
||||
.ARM : {
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
} >FLASH
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array*))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
} >FLASH
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array*))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
} >FLASH
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(.fini_array*))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
} >FLASH
|
||||
|
||||
/* used by the startup to initialize data */
|
||||
_sidata = .;
|
||||
|
||||
/* Initialized data sections goes into RAM, load LMA copy after code */
|
||||
.data : AT ( _sidata )
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sdata = .; /* create a global symbol at data start */
|
||||
*(.data) /* .data sections */
|
||||
*(.data*) /* .data* sections */
|
||||
|
||||
. = ALIGN(4);
|
||||
_edata = .; /* define a global symbol at data end */
|
||||
} >CCM
|
||||
|
||||
/* Uninitialized data section */
|
||||
. = ALIGN(4);
|
||||
.bss :
|
||||
{
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
_sbss = .; /* define a global symbol at bss start */
|
||||
/* __bss_start__ = _sbss; */
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
_ebss = .; /* define a global symbol at bss end */
|
||||
/* __bss_end__ = _ebss; */
|
||||
} >CCM
|
||||
|
||||
/* collect all uninitialized .ccm sections */
|
||||
.ram (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sram = .;
|
||||
/* __ccm_start__ = _sccm; */
|
||||
*(.ram)
|
||||
. = ALIGN(4);
|
||||
_eram = .;
|
||||
/* __ccm_end__ = _eccm; */
|
||||
} >RAM
|
||||
|
||||
PROVIDE ( end = _eram );
|
||||
PROVIDE ( _end = _eram );
|
||||
|
||||
/* User_heap_stack section, used to check that there is enough RAM left */
|
||||
._user_heap_stack :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
. = . + _Min_Heap_Size;
|
||||
. = . + _Main_Stack_Size;
|
||||
. = ALIGN(4);
|
||||
} >RAM
|
||||
|
||||
/* MEMORY_bank1 section, code must be located here explicitly */
|
||||
/* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
|
||||
.memory_b1_text :
|
||||
{
|
||||
*(.mb1text) /* .mb1text sections (code) */
|
||||
*(.mb1text*) /* .mb1text* sections (code) */
|
||||
*(.mb1rodata) /* read-only data (constants) */
|
||||
*(.mb1rodata*)
|
||||
} >MEMORY_B1
|
||||
|
||||
/* Remove information from the standard libraries */
|
||||
/DISCARD/ :
|
||||
{
|
||||
libc.a ( * )
|
||||
libm.a ( * )
|
||||
libgcc.a ( * )
|
||||
}
|
||||
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
}
|
||||
@@ -0,0 +1,538 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32f2xx.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 05-January-2014
|
||||
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
|
||||
* This file contains the system clock configuration for STM32F2xx devices,
|
||||
* and is generated by the clock configuration tool
|
||||
* STM32f2xx_Clock_Configuration_V1.1.0.xls
|
||||
*
|
||||
* 1. This file provides two functions and one global variable to be called from
|
||||
* user application:
|
||||
* - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
|
||||
* and Divider factors, AHB/APBx prescalers and Flash settings),
|
||||
* depending on the configuration made in the clock xls tool.
|
||||
* This function is called at startup just after reset and
|
||||
* before branch to main program. This call is made inside
|
||||
* the "startup_stm32f2xx.s" file.
|
||||
*
|
||||
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
|
||||
* by the user application to setup the SysTick
|
||||
* timer or configure other parameters.
|
||||
*
|
||||
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
|
||||
* be called whenever the core clock is changed
|
||||
* during program execution.
|
||||
*
|
||||
* 2. After each device reset the HSI (16 MHz) is used as system clock source.
|
||||
* Then SystemInit() function is called, in "startup_stm32f2xx.s" file, to
|
||||
* configure the system clock before to branch to main program.
|
||||
*
|
||||
* 3. If the system clock source selected by user fails to startup, the SystemInit()
|
||||
* function will do nothing and HSI still used as system clock source. User can
|
||||
* add some code to deal with this issue inside the SetSysClock() function.
|
||||
*
|
||||
* 4. The default value of HSE crystal is set to 25MHz, refer to "HSE_VALUE" define
|
||||
* in "stm32f2xx.h" file. When HSE is used as system clock source, directly or
|
||||
* through PLL, and you are using different crystal you have to adapt the HSE
|
||||
* value to your own configuration.
|
||||
*
|
||||
* 5. This file configures the system clock as follows:
|
||||
*=============================================================================
|
||||
*=============================================================================
|
||||
* Supported STM32F2xx device revision | Rev B and Y
|
||||
*-----------------------------------------------------------------------------
|
||||
* System Clock source | PLL (HSE)
|
||||
*-----------------------------------------------------------------------------
|
||||
* SYSCLK(Hz) | 120000000
|
||||
*-----------------------------------------------------------------------------
|
||||
* HCLK(Hz) | 120000000
|
||||
*-----------------------------------------------------------------------------
|
||||
* AHB Prescaler | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* APB1 Prescaler | 4
|
||||
*-----------------------------------------------------------------------------
|
||||
* APB2 Prescaler | 2
|
||||
*-----------------------------------------------------------------------------
|
||||
* HSE Frequency(Hz) | 12000000
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_M | 12
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_N | 240
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_P | 2
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_Q | 5
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLI2S_N | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLI2S_R | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* I2S input clock | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* VDD(V) | 3.3
|
||||
*-----------------------------------------------------------------------------
|
||||
* Flash Latency(WS) | 3
|
||||
*-----------------------------------------------------------------------------
|
||||
* Prefetch Buffer | ON
|
||||
*-----------------------------------------------------------------------------
|
||||
* Instruction cache | ON
|
||||
*-----------------------------------------------------------------------------
|
||||
* Data cache | ON
|
||||
*-----------------------------------------------------------------------------
|
||||
* Require 48MHz for USB OTG FS, | Enabled
|
||||
* SDIO and RNG clock |
|
||||
*-----------------------------------------------------------------------------
|
||||
*=============================================================================
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32f2xx_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F2xx_System_Private_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "stm32f2xx.h"
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F2xx_System_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F2xx_System_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!< Uncomment the following line if you need to use external SRAM mounted
|
||||
on STM322xG_EVALboard as data memory */
|
||||
/* #define DATA_IN_ExtSRAM */
|
||||
|
||||
/*!< Uncomment the following line if you need to relocate your vector Table in
|
||||
Internal SRAM. */
|
||||
/* #define VECT_TAB_SRAM */
|
||||
#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
|
||||
|
||||
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
|
||||
#define PLL_M 12
|
||||
#define PLL_N 240
|
||||
|
||||
/* SYSCLK = PLL_VCO / PLL_P */
|
||||
#define PLL_P 2
|
||||
|
||||
/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
|
||||
#define PLL_Q 5
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F2xx_System_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F2xx_System_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
uint32_t SystemCoreClock = 120000000;
|
||||
|
||||
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F2xx_System_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
static void SetSysClock(void);
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
static void SystemInit_ExtMemCtl(void);
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F2xx_System_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system
|
||||
* Initialize the Embedded Flash Interface, the PLL and update the
|
||||
* SystemFrequency variable.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit(void)
|
||||
{
|
||||
/* Reset the RCC clock configuration to the default reset state ------------*/
|
||||
/* Set HSION bit */
|
||||
RCC->CR |= (uint32_t)0x00000001;
|
||||
|
||||
/* Reset CFGR register */
|
||||
RCC->CFGR = 0x00000000;
|
||||
|
||||
/* Reset HSEON, CSSON and PLLON bits */
|
||||
RCC->CR &= (uint32_t)0xFEF6FFFF;
|
||||
|
||||
/* Reset PLLCFGR register */
|
||||
RCC->PLLCFGR = 0x24003010;
|
||||
|
||||
/* Reset HSEBYP bit */
|
||||
RCC->CR &= (uint32_t)0xFFFBFFFF;
|
||||
|
||||
/* Disable all interrupts */
|
||||
RCC->CIR = 0x00000000;
|
||||
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
SystemInit_ExtMemCtl();
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
|
||||
/* Configure the System clock source, PLL Multiplier and Divider factors,
|
||||
AHB/APBx prescalers and Flash settings ----------------------------------*/
|
||||
SetSysClock();
|
||||
|
||||
/* Configure the Vector Table location add offset address ------------------*/
|
||||
#ifdef VECT_TAB_SRAM
|
||||
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
|
||||
#else
|
||||
extern uint32_t g_pfnVectors ;
|
||||
SCB->VTOR = (uint32_t) &g_pfnVectors ; /* Vector Table Relocation in Internal FLASH */
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update SystemCoreClock variable according to Clock Register Values.
|
||||
* The SystemCoreClock variable contains the core clock (HCLK), it can
|
||||
* be used by the user application to setup the SysTick timer or configure
|
||||
* other parameters.
|
||||
*
|
||||
* @note Each time the core clock (HCLK) changes, this function must be called
|
||||
* to update SystemCoreClock variable value. Otherwise, any configuration
|
||||
* based on this variable will be incorrect.
|
||||
*
|
||||
* @note - The system frequency computed by this function is not the real
|
||||
* frequency in the chip. It is calculated based on the predefined
|
||||
* constant and the selected clock source:
|
||||
*
|
||||
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
|
||||
*
|
||||
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
*
|
||||
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
* or HSI_VALUE(*) multiplied/divided by the PLL factors.
|
||||
*
|
||||
* (*) HSI_VALUE is a constant defined in stm32f2xx.h file (default value
|
||||
* 16 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* (**) HSE_VALUE is a constant defined in stm32f2xx.h file (default value
|
||||
* 25 MHz), user has to ensure that HSE_VALUE is same as the real
|
||||
* frequency of the crystal used. Otherwise, this function may
|
||||
* have wrong result.
|
||||
*
|
||||
* - The result of this function could be not correct when using fractional
|
||||
* value for HSE crystal.
|
||||
*
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemCoreClockUpdate(void)
|
||||
{
|
||||
uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
|
||||
|
||||
/* Get SYSCLK source -------------------------------------------------------*/
|
||||
tmp = RCC->CFGR & RCC_CFGR_SWS;
|
||||
|
||||
switch (tmp)
|
||||
{
|
||||
case 0x00: /* HSI used as system clock source */
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
case 0x04: /* HSE used as system clock source */
|
||||
SystemCoreClock = HSE_VALUE;
|
||||
break;
|
||||
case 0x08: /* PLL used as system clock source */
|
||||
|
||||
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
|
||||
SYSCLK = PLL_VCO / PLL_P
|
||||
*/
|
||||
pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
|
||||
pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
|
||||
|
||||
if (pllsource != 0)
|
||||
{
|
||||
/* HSE used as PLL clock source */
|
||||
pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* HSI used as PLL clock source */
|
||||
pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
|
||||
}
|
||||
|
||||
pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
|
||||
SystemCoreClock = pllvco/pllp;
|
||||
break;
|
||||
default:
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
}
|
||||
/* Compute HCLK frequency --------------------------------------------------*/
|
||||
/* Get HCLK prescaler */
|
||||
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
|
||||
/* HCLK frequency */
|
||||
SystemCoreClock >>= tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the System clock source, PLL Multiplier and Divider factors,
|
||||
* AHB/APBx prescalers and Flash settings
|
||||
* @Note This function should be called only once the RCC clock configuration
|
||||
* is reset to the default reset state (done in SystemInit() function).
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
/******************************************************************************/
|
||||
/* PLL (clocked by HSE) used as System clock source */
|
||||
/******************************************************************************/
|
||||
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
||||
|
||||
/* Enable HSE */
|
||||
RCC->CR |= ((uint32_t)RCC_CR_HSEON);
|
||||
|
||||
/* Wait till HSE is ready and if Time out is reached exit */
|
||||
do
|
||||
{
|
||||
HSEStatus = RCC->CR & RCC_CR_HSERDY;
|
||||
StartUpCounter++;
|
||||
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
||||
|
||||
if ((RCC->CR & RCC_CR_HSERDY) != RESET)
|
||||
{
|
||||
HSEStatus = (uint32_t)0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSEStatus = (uint32_t)0x00;
|
||||
}
|
||||
|
||||
if (HSEStatus == (uint32_t)0x01)
|
||||
{
|
||||
/* HCLK = SYSCLK / 1*/
|
||||
RCC->CFGR |= RCC_CFGR_HPRE_DIV1;
|
||||
|
||||
/* PCLK2 = HCLK / 2*/
|
||||
RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;
|
||||
|
||||
/* PCLK1 = HCLK / 4*/
|
||||
RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;
|
||||
|
||||
/* Configure the main PLL */
|
||||
RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) |
|
||||
(RCC_PLLCFGR_PLLSRC_HSE) | (PLL_Q << 24);
|
||||
|
||||
/* Enable the main PLL */
|
||||
RCC->CR |= RCC_CR_PLLON;
|
||||
|
||||
/* Wait till the main PLL is ready */
|
||||
while((RCC->CR & RCC_CR_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
|
||||
/* Configure Flash prefetch, Instruction cache, Data cache and wait state */
|
||||
FLASH->ACR = FLASH_ACR_PRFTEN |FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_3WS;
|
||||
|
||||
/* Select the main PLL as system clock source */
|
||||
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
|
||||
RCC->CFGR |= RCC_CFGR_SW_PLL;
|
||||
|
||||
/* Wait till the main PLL is used as system clock source */
|
||||
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL);
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* If HSE fails to start-up, the application will have wrong clock
|
||||
configuration. User can add here some code to deal with this error */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setup the external memory controller. Called in startup_stm32f2xx.s
|
||||
* before jump to __main
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
/**
|
||||
* @brief Setup the external memory controller.
|
||||
* Called in startup_stm32f2xx.s before jump to main.
|
||||
* This function configures the external SRAM mounted on STM322xG_EVAL board
|
||||
* This SRAM will be used as program data memory (including heap and stack).
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit_ExtMemCtl(void)
|
||||
{
|
||||
/*-- GPIOs Configuration -----------------------------------------------------*/
|
||||
/*
|
||||
+-------------------+--------------------+------------------+------------------+
|
||||
+ SRAM pins assignment +
|
||||
+-------------------+--------------------+------------------+------------------+
|
||||
| PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 |
|
||||
| PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 |
|
||||
| PD4 <-> FSMC_NOE | PE7 <-> FSMC_D4 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 |
|
||||
| PD5 <-> FSMC_NWE | PE8 <-> FSMC_D5 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 |
|
||||
| PD8 <-> FSMC_D13 | PE9 <-> FSMC_D6 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 |
|
||||
| PD9 <-> FSMC_D14 | PE10 <-> FSMC_D7 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 |
|
||||
| PD10 <-> FSMC_D15 | PE11 <-> FSMC_D8 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 |
|
||||
| PD11 <-> FSMC_A16 | PE12 <-> FSMC_D9 | PF13 <-> FSMC_A7 |------------------+
|
||||
| PD12 <-> FSMC_A17 | PE13 <-> FSMC_D10 | PF14 <-> FSMC_A8 |
|
||||
| PD14 <-> FSMC_D0 | PE14 <-> FSMC_D11 | PF15 <-> FSMC_A9 |
|
||||
| PD15 <-> FSMC_D1 | PE15 <-> FSMC_D12 |------------------+
|
||||
+-------------------+--------------------+
|
||||
*/
|
||||
/* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */
|
||||
RCC->AHB1ENR = 0x00000078;
|
||||
|
||||
/* Connect PDx pins to FSMC Alternate function */
|
||||
GPIOD->AFR[0] = 0x00cc00cc;
|
||||
GPIOD->AFR[1] = 0xcc0ccccc;
|
||||
/* Configure PDx pins in Alternate function mode */
|
||||
GPIOD->MODER = 0xa2aa0a0a;
|
||||
/* Configure PDx pins speed to 100 MHz */
|
||||
GPIOD->OSPEEDR = 0xf3ff0f0f;
|
||||
/* Configure PDx pins Output type to push-pull */
|
||||
GPIOD->OTYPER = 0x00000000;
|
||||
/* No pull-up, pull-down for PDx pins */
|
||||
GPIOD->PUPDR = 0x00000000;
|
||||
|
||||
/* Connect PEx pins to FSMC Alternate function */
|
||||
GPIOE->AFR[0] = 0xc00000cc;
|
||||
GPIOE->AFR[1] = 0xcccccccc;
|
||||
/* Configure PEx pins in Alternate function mode */
|
||||
GPIOE->MODER = 0xaaaa800a;
|
||||
/* Configure PEx pins speed to 100 MHz */
|
||||
GPIOE->OSPEEDR = 0xffffc00f;
|
||||
/* Configure PEx pins Output type to push-pull */
|
||||
GPIOE->OTYPER = 0x00000000;
|
||||
/* No pull-up, pull-down for PEx pins */
|
||||
GPIOE->PUPDR = 0x00000000;
|
||||
|
||||
/* Connect PFx pins to FSMC Alternate function */
|
||||
GPIOF->AFR[0] = 0x00cccccc;
|
||||
GPIOF->AFR[1] = 0xcccc0000;
|
||||
/* Configure PFx pins in Alternate function mode */
|
||||
GPIOF->MODER = 0xaa000aaa;
|
||||
/* Configure PFx pins speed to 100 MHz */
|
||||
GPIOF->OSPEEDR = 0xff000fff;
|
||||
/* Configure PFx pins Output type to push-pull */
|
||||
GPIOF->OTYPER = 0x00000000;
|
||||
/* No pull-up, pull-down for PFx pins */
|
||||
GPIOF->PUPDR = 0x00000000;
|
||||
|
||||
/* Connect PGx pins to FSMC Alternate function */
|
||||
GPIOG->AFR[0] = 0x00cccccc;
|
||||
GPIOG->AFR[1] = 0x000000c0;
|
||||
/* Configure PGx pins in Alternate function mode */
|
||||
GPIOG->MODER = 0x00080aaa;
|
||||
/* Configure PGx pins speed to 100 MHz */
|
||||
GPIOG->OSPEEDR = 0x000c0fff;
|
||||
/* Configure PGx pins Output type to push-pull */
|
||||
GPIOG->OTYPER = 0x00000000;
|
||||
/* No pull-up, pull-down for PGx pins */
|
||||
GPIOG->PUPDR = 0x00000000;
|
||||
|
||||
/*-- FSMC Configuration ------------------------------------------------------*/
|
||||
/* Enable the FSMC interface clock */
|
||||
RCC->AHB3ENR = 0x00000001;
|
||||
|
||||
/* Configure and enable Bank1_SRAM2 */
|
||||
FSMC_Bank1->BTCR[2] = 0x00001015;
|
||||
FSMC_Bank1->BTCR[3] = 0x00010400;
|
||||
FSMC_Bank1E->BWTR[2] = 0x0fffffff;
|
||||
/*
|
||||
Bank1_SRAM2 is configured as follow:
|
||||
|
||||
p.FSMC_AddressSetupTime = 0;
|
||||
p.FSMC_AddressHoldTime = 0;
|
||||
p.FSMC_DataSetupTime = 4;
|
||||
p.FSMC_BusTurnAroundDuration = 1;
|
||||
p.FSMC_CLKDivision = 0;
|
||||
p.FSMC_DataLatency = 0;
|
||||
p.FSMC_AccessMode = FSMC_AccessMode_A;
|
||||
|
||||
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2;
|
||||
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM;
|
||||
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
|
||||
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
|
||||
*/
|
||||
|
||||
}
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,563 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32f4xx.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 21-March-2015
|
||||
* @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File.
|
||||
* This file contains the system clock configuration for STM32F4xx devices,
|
||||
* and is generated by the clock configuration tool
|
||||
* stm32f4xx_Clock_Configuration_V1.1.0.xls
|
||||
*
|
||||
* 1. This file provides two functions and one global variable to be called from
|
||||
* user application:
|
||||
* - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
|
||||
* and Divider factors, AHB/APBx prescalers and Flash settings),
|
||||
* depending on the configuration made in the clock xls tool.
|
||||
* This function is called at startup just after reset and
|
||||
* before branch to main program. This call is made inside
|
||||
* the "startup_stm32f4xx.s" file.
|
||||
*
|
||||
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
|
||||
* by the user application to setup the SysTick
|
||||
* timer or configure other parameters.
|
||||
*
|
||||
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
|
||||
* be called whenever the core clock is changed
|
||||
* during program execution.
|
||||
*
|
||||
* 2. After each device reset the HSI (16 MHz) is used as system clock source.
|
||||
* Then SystemInit() function is called, in "startup_stm32f4xx.s" file, to
|
||||
* configure the system clock before to branch to main program.
|
||||
*
|
||||
* 3. If the system clock source selected by user fails to startup, the SystemInit()
|
||||
* function will do nothing and HSI still used as system clock source. User can
|
||||
* add some code to deal with this issue inside the SetSysClock() function.
|
||||
*
|
||||
* 4. The default value of HSE crystal is set to 25MHz, refer to "HSE_VALUE" define
|
||||
* in "stm32f4xx.h" file. When HSE is used as system clock source, directly or
|
||||
* through PLL, and you are using different crystal you have to adapt the HSE
|
||||
* value to your own configuration.
|
||||
*
|
||||
* 5. This file configures the system clock as follows:
|
||||
*=============================================================================
|
||||
*=============================================================================
|
||||
* Supported STM32F40xx/41xx/427x/437x devices
|
||||
*-----------------------------------------------------------------------------
|
||||
* System Clock source | PLL (HSE)
|
||||
*-----------------------------------------------------------------------------
|
||||
* SYSCLK(Hz) | 168000000
|
||||
*-----------------------------------------------------------------------------
|
||||
* HCLK(Hz) | 168000000
|
||||
*-----------------------------------------------------------------------------
|
||||
* AHB Prescaler | 1
|
||||
*-----------------------------------------------------------------------------
|
||||
* APB1 Prescaler | 4
|
||||
*-----------------------------------------------------------------------------
|
||||
* APB2 Prescaler | 2
|
||||
*-----------------------------------------------------------------------------
|
||||
* HSE Frequency(Hz) | 12000000
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_M | 12
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_N | 336
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_P | 2
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLL_Q | 7
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLI2S_N | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* PLLI2S_R | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* I2S input clock | NA
|
||||
*-----------------------------------------------------------------------------
|
||||
* VDD(V) | 3.3
|
||||
*-----------------------------------------------------------------------------
|
||||
* Main regulator output voltage | Scale1 mode
|
||||
*-----------------------------------------------------------------------------
|
||||
* Flash Latency(WS) | 5
|
||||
*-----------------------------------------------------------------------------
|
||||
* Prefetch Buffer | ON
|
||||
*-----------------------------------------------------------------------------
|
||||
* Instruction cache | ON
|
||||
*-----------------------------------------------------------------------------
|
||||
* Data cache | ON
|
||||
*-----------------------------------------------------------------------------
|
||||
* Require 48MHz for USB OTG FS, | Enabled
|
||||
* SDIO and RNG clock |
|
||||
*-----------------------------------------------------------------------------
|
||||
*=============================================================================
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32f4xx_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Private_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/************************* Miscellaneous Configuration ************************/
|
||||
/*!< Uncomment the following line if you need to use external SRAM mounted
|
||||
on STM324xG_EVAL/STM324x7I_EVAL board as data memory */
|
||||
/* #define DATA_IN_ExtSRAM */
|
||||
|
||||
/*!< Uncomment the following line if you need to relocate your vector Table in
|
||||
Internal SRAM. */
|
||||
/* #define VECT_TAB_SRAM */
|
||||
#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
/******************************************************************************/
|
||||
|
||||
/************************* PLL Parameters *************************************/
|
||||
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
|
||||
#define PLL_M 12
|
||||
#define PLL_N 336
|
||||
|
||||
/* SYSCLK = PLL_VCO / PLL_P */
|
||||
#define PLL_P 2
|
||||
|
||||
/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
|
||||
#define PLL_Q 7
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
uint32_t SystemCoreClock = 168000000;
|
||||
|
||||
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
static void SetSysClock(void);
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
static void SystemInit_ExtMemCtl(void);
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F4xx_System_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system
|
||||
* Initialize the Embedded Flash Interface, the PLL and update the
|
||||
* SystemFrequency variable.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit(void)
|
||||
{
|
||||
/* FPU settings ------------------------------------------------------------*/
|
||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
||||
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
|
||||
#endif
|
||||
/* Reset the RCC clock configuration to the default reset state ------------*/
|
||||
/* Set HSION bit */
|
||||
RCC->CR |= (uint32_t)0x00000001;
|
||||
|
||||
/* Reset CFGR register */
|
||||
RCC->CFGR = 0x00000000;
|
||||
|
||||
/* Reset HSEON, CSSON and PLLON bits */
|
||||
RCC->CR &= (uint32_t)0xFEF6FFFF;
|
||||
|
||||
/* Reset PLLCFGR register */
|
||||
RCC->PLLCFGR = 0x24003010;
|
||||
|
||||
/* Reset HSEBYP bit */
|
||||
RCC->CR &= (uint32_t)0xFFFBFFFF;
|
||||
|
||||
/* Disable all interrupts */
|
||||
RCC->CIR = 0x00000000;
|
||||
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
SystemInit_ExtMemCtl();
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
|
||||
/* Configure the System clock source, PLL Multiplier and Divider factors,
|
||||
AHB/APBx prescalers and Flash settings ----------------------------------*/
|
||||
SetSysClock();
|
||||
|
||||
/* Configure the Vector Table location add offset address ------------------*/
|
||||
#ifdef VECT_TAB_SRAM
|
||||
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
|
||||
#else
|
||||
// SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
|
||||
extern uint32_t g_pfnVectors ;
|
||||
SCB->VTOR = (uint32_t) &g_pfnVectors ; /* Vector Table Relocation in Internal FLASH */
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update SystemCoreClock variable according to Clock Register Values.
|
||||
* The SystemCoreClock variable contains the core clock (HCLK), it can
|
||||
* be used by the user application to setup the SysTick timer or configure
|
||||
* other parameters.
|
||||
*
|
||||
* @note Each time the core clock (HCLK) changes, this function must be called
|
||||
* to update SystemCoreClock variable value. Otherwise, any configuration
|
||||
* based on this variable will be incorrect.
|
||||
*
|
||||
* @note - The system frequency computed by this function is not the real
|
||||
* frequency in the chip. It is calculated based on the predefined
|
||||
* constant and the selected clock source:
|
||||
*
|
||||
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
|
||||
*
|
||||
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
*
|
||||
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
* or HSI_VALUE(*) multiplied/divided by the PLL factors.
|
||||
*
|
||||
* (*) HSI_VALUE is a constant defined in stm32f4xx.h file (default value
|
||||
* 16 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* (**) HSE_VALUE is a constant defined in stm32f4xx.h file (default value
|
||||
* 25 MHz), user has to ensure that HSE_VALUE is same as the real
|
||||
* frequency of the crystal used. Otherwise, this function may
|
||||
* have wrong result.
|
||||
*
|
||||
* - The result of this function could be not correct when using fractional
|
||||
* value for HSE crystal.
|
||||
*
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemCoreClockUpdate(void)
|
||||
{
|
||||
uint32_t tmp = 0, pllvco = 0, pllp = 2, pllsource = 0, pllm = 2;
|
||||
|
||||
/* Get SYSCLK source -------------------------------------------------------*/
|
||||
tmp = RCC->CFGR & RCC_CFGR_SWS;
|
||||
|
||||
switch (tmp)
|
||||
{
|
||||
case 0x00: /* HSI used as system clock source */
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
case 0x04: /* HSE used as system clock source */
|
||||
SystemCoreClock = HSE_VALUE;
|
||||
break;
|
||||
case 0x08: /* PLL used as system clock source */
|
||||
|
||||
/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N
|
||||
SYSCLK = PLL_VCO / PLL_P
|
||||
*/
|
||||
pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) >> 22;
|
||||
pllm = RCC->PLLCFGR & RCC_PLLCFGR_PLLM;
|
||||
|
||||
if (pllsource != 0)
|
||||
{
|
||||
/* HSE used as PLL clock source */
|
||||
pllvco = (HSE_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* HSI used as PLL clock source */
|
||||
pllvco = (HSI_VALUE / pllm) * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6);
|
||||
}
|
||||
|
||||
pllp = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLP) >>16) + 1 ) *2;
|
||||
SystemCoreClock = pllvco/pllp;
|
||||
break;
|
||||
default:
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
}
|
||||
/* Compute HCLK frequency --------------------------------------------------*/
|
||||
/* Get HCLK prescaler */
|
||||
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
|
||||
/* HCLK frequency */
|
||||
SystemCoreClock >>= tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the System clock source, PLL Multiplier and Divider factors,
|
||||
* AHB/APBx prescalers and Flash settings
|
||||
* @Note This function should be called only once the RCC clock configuration
|
||||
* is reset to the default reset state (done in SystemInit() function).
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void SetSysClock(void)
|
||||
{
|
||||
/******************************************************************************/
|
||||
/* PLL (clocked by HSE) used as System clock source */
|
||||
/******************************************************************************/
|
||||
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
|
||||
|
||||
/* Enable HSE */
|
||||
RCC->CR |= ((uint32_t)RCC_CR_HSEON);
|
||||
|
||||
/* Wait till HSE is ready and if Time out is reached exit */
|
||||
do
|
||||
{
|
||||
HSEStatus = RCC->CR & RCC_CR_HSERDY;
|
||||
StartUpCounter++;
|
||||
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
|
||||
|
||||
if ((RCC->CR & RCC_CR_HSERDY) != RESET)
|
||||
{
|
||||
HSEStatus = (uint32_t)0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
HSEStatus = (uint32_t)0x00;
|
||||
}
|
||||
|
||||
if (HSEStatus == (uint32_t)0x01)
|
||||
{
|
||||
/* Select regulator voltage output Scale 1 mode, System frequency up to 168 MHz */
|
||||
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
|
||||
PWR->CR |= PWR_CR_VOS;
|
||||
|
||||
/* HCLK = SYSCLK / 1*/
|
||||
RCC->CFGR |= RCC_CFGR_HPRE_DIV1;
|
||||
|
||||
/* PCLK2 = HCLK / 2*/
|
||||
RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;
|
||||
|
||||
/* PCLK1 = HCLK / 4*/
|
||||
RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;
|
||||
|
||||
/* Configure the main PLL */
|
||||
RCC->PLLCFGR = PLL_M | (PLL_N << 6) | (((PLL_P >> 1) -1) << 16) |
|
||||
(RCC_PLLCFGR_PLLSRC_HSE) | (PLL_Q << 24);
|
||||
|
||||
/* Enable the main PLL */
|
||||
RCC->CR |= RCC_CR_PLLON;
|
||||
|
||||
/* Wait till the main PLL is ready */
|
||||
while((RCC->CR & RCC_CR_PLLRDY) == 0)
|
||||
{
|
||||
}
|
||||
|
||||
/* Configure Flash prefetch, Instruction cache, Data cache and wait state */
|
||||
FLASH->ACR = FLASH_ACR_PRFTEN |FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS;
|
||||
|
||||
/* Select the main PLL as system clock source */
|
||||
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
|
||||
RCC->CFGR |= RCC_CFGR_SW_PLL;
|
||||
|
||||
/* Wait till the main PLL is used as system clock source */
|
||||
while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS ) != RCC_CFGR_SWS_PLL);
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* If HSE fails to start-up, the application will have wrong clock
|
||||
configuration. User can add here some code to deal with this error */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setup the external memory controller. Called in startup_stm32f4xx.s
|
||||
* before jump to __main
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
/**
|
||||
* @brief Setup the external memory controller.
|
||||
* Called in startup_stm32f4xx.s before jump to main.
|
||||
* This function configures the external SRAM mounted on STM324xG_EVAL/STM324x7I_EVAL board
|
||||
* This SRAM will be used as program data memory (including heap and stack).
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit_ExtMemCtl(void)
|
||||
{
|
||||
/*-- GPIOs Configuration -----------------------------------------------------*/
|
||||
/*
|
||||
+-------------------+--------------------+------------------+------------------+
|
||||
+ SRAM pins assignment +
|
||||
+-------------------+--------------------+------------------+------------------+
|
||||
| PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 |
|
||||
| PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 |
|
||||
| PD4 <-> FSMC_NOE | PE2 <-> FSMC_A23 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 |
|
||||
| PD5 <-> FSMC_NWE | PE3 <-> FSMC_A19 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 |
|
||||
| PD8 <-> FSMC_D13 | PE4 <-> FSMC_A20 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 |
|
||||
| PD9 <-> FSMC_D14 | PE5 <-> FSMC_A21 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 |
|
||||
| PD10 <-> FSMC_D15 | PE6 <-> FSMC_A22 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 |
|
||||
| PD11 <-> FSMC_A16 | PE7 <-> FSMC_D4 | PF13 <-> FSMC_A7 |------------------+
|
||||
| PD12 <-> FSMC_A17 | PE8 <-> FSMC_D5 | PF14 <-> FSMC_A8 |
|
||||
| PD13 <-> FSMC_A18 | PE9 <-> FSMC_D6 | PF15 <-> FSMC_A9 |
|
||||
| PD14 <-> FSMC_D0 | PE10 <-> FSMC_D7 |------------------+
|
||||
| PD15 <-> FSMC_D1 | PE11 <-> FSMC_D8 |
|
||||
+-------------------| PE12 <-> FSMC_D9 |
|
||||
| PE13 <-> FSMC_D10 |
|
||||
| PE14 <-> FSMC_D11 |
|
||||
| PE15 <-> FSMC_D12 |
|
||||
+--------------------+
|
||||
*/
|
||||
/* Enable GPIOD, GPIOE, GPIOF and GPIOG interface clock */
|
||||
RCC->AHB1ENR |= 0x00000078;
|
||||
|
||||
/* Connect PDx pins to FSMC Alternate function */
|
||||
GPIOD->AFR[0] = 0x00cc00cc;
|
||||
GPIOD->AFR[1] = 0xcccccccc;
|
||||
/* Configure PDx pins in Alternate function mode */
|
||||
GPIOD->MODER = 0xaaaa0a0a;
|
||||
/* Configure PDx pins speed to 100 MHz */
|
||||
GPIOD->OSPEEDR = 0xffff0f0f;
|
||||
/* Configure PDx pins Output type to push-pull */
|
||||
GPIOD->OTYPER = 0x00000000;
|
||||
/* No pull-up, pull-down for PDx pins */
|
||||
GPIOD->PUPDR = 0x00000000;
|
||||
|
||||
/* Connect PEx pins to FSMC Alternate function */
|
||||
GPIOE->AFR[0] = 0xcccccccc;
|
||||
GPIOE->AFR[1] = 0xcccccccc;
|
||||
/* Configure PEx pins in Alternate function mode */
|
||||
GPIOE->MODER = 0xaaaaaaaa;
|
||||
/* Configure PEx pins speed to 100 MHz */
|
||||
GPIOE->OSPEEDR = 0xffffffff;
|
||||
/* Configure PEx pins Output type to push-pull */
|
||||
GPIOE->OTYPER = 0x00000000;
|
||||
/* No pull-up, pull-down for PEx pins */
|
||||
GPIOE->PUPDR = 0x00000000;
|
||||
|
||||
/* Connect PFx pins to FSMC Alternate function */
|
||||
GPIOF->AFR[0] = 0x00cccccc;
|
||||
GPIOF->AFR[1] = 0xcccc0000;
|
||||
/* Configure PFx pins in Alternate function mode */
|
||||
GPIOF->MODER = 0xaa000aaa;
|
||||
/* Configure PFx pins speed to 100 MHz */
|
||||
GPIOF->OSPEEDR = 0xff000fff;
|
||||
/* Configure PFx pins Output type to push-pull */
|
||||
GPIOF->OTYPER = 0x00000000;
|
||||
/* No pull-up, pull-down for PFx pins */
|
||||
GPIOF->PUPDR = 0x00000000;
|
||||
|
||||
/* Connect PGx pins to FSMC Alternate function */
|
||||
GPIOG->AFR[0] = 0x00cccccc;
|
||||
GPIOG->AFR[1] = 0x000000c0;
|
||||
/* Configure PGx pins in Alternate function mode */
|
||||
GPIOG->MODER = 0x00080aaa;
|
||||
/* Configure PGx pins speed to 100 MHz */
|
||||
GPIOG->OSPEEDR = 0x000c0fff;
|
||||
/* Configure PGx pins Output type to push-pull */
|
||||
GPIOG->OTYPER = 0x00000000;
|
||||
/* No pull-up, pull-down for PGx pins */
|
||||
GPIOG->PUPDR = 0x00000000;
|
||||
|
||||
/*-- FSMC Configuration ------------------------------------------------------*/
|
||||
/* Enable the FSMC interface clock */
|
||||
RCC->AHB3ENR |= 0x00000001;
|
||||
|
||||
/* Configure and enable Bank1_SRAM2 */
|
||||
FSMC_Bank1->BTCR[2] = 0x00001011;
|
||||
FSMC_Bank1->BTCR[3] = 0x00000201;
|
||||
FSMC_Bank1E->BWTR[2] = 0x0fffffff;
|
||||
/*
|
||||
Bank1_SRAM2 is configured as follow:
|
||||
|
||||
p.FSMC_AddressSetupTime = 1;
|
||||
p.FSMC_AddressHoldTime = 0;
|
||||
p.FSMC_DataSetupTime = 2;
|
||||
p.FSMC_BusTurnAroundDuration = 0;
|
||||
p.FSMC_CLKDivision = 0;
|
||||
p.FSMC_DataLatency = 0;
|
||||
p.FSMC_AccessMode = FSMC_AccessMode_A;
|
||||
|
||||
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2;
|
||||
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
|
||||
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
|
||||
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
|
||||
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
|
||||
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
|
||||
*/
|
||||
}
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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"
|
||||
|
||||
extern Fifo<512> telemetryFifo;
|
||||
|
||||
void telemetryPortInit(uint32_t baudrate)
|
||||
{
|
||||
if (baudrate == 0) {
|
||||
USART_DeInit(TELEMETRY_USART);
|
||||
return;
|
||||
}
|
||||
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
GPIO_PinAFConfig(TELEMETRY_GPIO, TELEMETRY_GPIO_PinSource_RX, TELEMETRY_GPIO_AF);
|
||||
GPIO_PinAFConfig(TELEMETRY_GPIO, TELEMETRY_GPIO_PinSource_TX, TELEMETRY_GPIO_AF);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = TELEMETRY_GPIO_PIN_TX | TELEMETRY_GPIO_PIN_RX;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(TELEMETRY_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = TELEMETRY_GPIO_PIN_DIR;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(TELEMETRY_GPIO_DIR, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(TELEMETRY_GPIO_DIR, TELEMETRY_GPIO_PIN_DIR);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = baudrate;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
|
||||
|
||||
USART_Init(TELEMETRY_USART, &USART_InitStructure);
|
||||
USART_Cmd(TELEMETRY_USART, ENABLE);
|
||||
USART_ITConfig(TELEMETRY_USART, USART_IT_RXNE, ENABLE);
|
||||
|
||||
NVIC_SetPriority(TELEMETRY_USART_IRQn, 6);
|
||||
NVIC_EnableIRQ(TELEMETRY_USART_IRQn);
|
||||
}
|
||||
|
||||
struct SportTxBuffer
|
||||
{
|
||||
uint8_t *ptr;
|
||||
uint32_t count;
|
||||
} sportTxBuffer;
|
||||
|
||||
void sportSendBuffer(uint8_t *buffer, uint32_t count)
|
||||
{
|
||||
sportTxBuffer.ptr = buffer ;
|
||||
sportTxBuffer.count = count ;
|
||||
TELEMETRY_GPIO_DIR->BSRRL = TELEMETRY_GPIO_PIN_DIR ; // output enable
|
||||
TELEMETRY_USART->CR1 &= ~USART_CR1_RE ; // turn off receiver
|
||||
TELEMETRY_USART->CR1 |= USART_CR1_TXEIE ;
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
|
||||
|
||||
extern "C" void TELEMETRY_USART_IRQHandler()
|
||||
{
|
||||
uint32_t status;
|
||||
uint8_t data;
|
||||
|
||||
status = TELEMETRY_USART->SR;
|
||||
|
||||
if (status & USART_SR_TXE) {
|
||||
if (sportTxBuffer.count) {
|
||||
TELEMETRY_USART->DR = *sportTxBuffer.ptr++;
|
||||
if (--sportTxBuffer.count == 0) {
|
||||
TELEMETRY_USART->CR1 &= ~USART_CR1_TXEIE; // stop Tx interrupt
|
||||
TELEMETRY_USART->CR1 |= USART_CR1_TCIE; // enable complete interrupt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((status & USART_SR_TC) && (TELEMETRY_USART->CR1 & USART_CR1_TCIE)) {
|
||||
TELEMETRY_USART->CR1 &= ~USART_CR1_TCIE ; // stop Complete interrupt
|
||||
TELEMETRY_GPIO_DIR->BSRRH = TELEMETRY_GPIO_PIN_DIR ; // output disable
|
||||
TELEMETRY_USART->CR1 |= USART_CR1_RE ;
|
||||
while (status & (USART_FLAG_RXNE)) {
|
||||
status = TELEMETRY_USART->DR;
|
||||
status = TELEMETRY_USART->SR ;
|
||||
}
|
||||
}
|
||||
|
||||
while (status & (USART_FLAG_RXNE | USART_FLAG_ERRORS)) {
|
||||
data = TELEMETRY_USART->DR;
|
||||
if (!(status & USART_FLAG_ERRORS)) {
|
||||
telemetryFifo.push(data);
|
||||
}
|
||||
status = TELEMETRY_USART->SR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,432 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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 "../Taranis/board_taranis.h"
|
||||
|
||||
#define CS1_HIGH() TOPLCD_GPIO->BSRRL = TOPLCD_GPIO_PIN_CS1
|
||||
#define CS1_LOW() TOPLCD_GPIO->BSRRH = TOPLCD_GPIO_PIN_CS1
|
||||
#define CS2_HIGH() TOPLCD_GPIO->BSRRL = TOPLCD_GPIO_PIN_CS2
|
||||
#define CS2_LOW() TOPLCD_GPIO->BSRRH = TOPLCD_GPIO_PIN_CS2
|
||||
#define WR_HIGH() TOPLCD_GPIO->BSRRL = TOPLCD_GPIO_PIN_WR
|
||||
#define WR_LOW() TOPLCD_GPIO->BSRRH = TOPLCD_GPIO_PIN_WR
|
||||
#define DATA_HIGH() TOPLCD_GPIO->BSRRL = TOPLCD_GPIO_PIN_DATA
|
||||
#define DATA_LOW() TOPLCD_GPIO->BSRRH = TOPLCD_GPIO_PIN_DATA
|
||||
#define BL_ON() TOPLCD_GPIO->BSRRL = TOPLCD_GPIO_PIN_BL
|
||||
#define BL_OFF() TOPLCD_GPIO->BSRRH = TOPLCD_GPIO_PIN_BL
|
||||
|
||||
const uint8_t TimeLCDsegs[] = { 0xAF, 0x06, 0x6D, 0x4F, 0xC6, 0xCB, 0xEB, 0x0E, 0xEF, 0xCF };
|
||||
const uint8_t RssiLCDsegs[] = { 0xFA, 0x60, 0xBC, 0xF4, 0x66, 0xD6, 0xDE, 0x70, 0xFE, 0xF6 };
|
||||
const uint8_t OpTimeLCDsegs[] = { 0x5F, 0x06, 0x6B, 0x2F, 0x36, 0x3D, 0x7D, 0x07, 0x7F, 0x3F };
|
||||
|
||||
uint8_t Ht1621Data1[11] = { 0 };
|
||||
uint8_t Ht1621Data2[7] = { 0 };
|
||||
|
||||
void delay1_7us()
|
||||
{
|
||||
delay_01us(17);
|
||||
}
|
||||
|
||||
void ht1621SendCommand(uint8_t chip, unsigned char command)
|
||||
{
|
||||
if (chip)
|
||||
CS2_LOW();
|
||||
else
|
||||
CS1_LOW();
|
||||
|
||||
delay1_7us();
|
||||
WR_LOW(); //PRESENT 100 COMMAND CODE
|
||||
delay1_7us();
|
||||
DATA_HIGH();
|
||||
delay1_7us();
|
||||
WR_HIGH();
|
||||
delay1_7us();
|
||||
WR_LOW();
|
||||
delay1_7us();
|
||||
DATA_LOW();
|
||||
delay1_7us();
|
||||
WR_HIGH();
|
||||
delay1_7us();
|
||||
|
||||
WR_LOW();
|
||||
delay1_7us();
|
||||
DATA_LOW();
|
||||
delay1_7us();
|
||||
WR_HIGH();
|
||||
delay1_7us();
|
||||
|
||||
for (int i=0; i<8; i++) {
|
||||
WR_LOW();
|
||||
delay1_7us();
|
||||
if ((command & 0x80) !=0) {
|
||||
DATA_HIGH();
|
||||
delay1_7us();
|
||||
}
|
||||
else {
|
||||
DATA_LOW();
|
||||
delay1_7us();
|
||||
}
|
||||
WR_HIGH();
|
||||
delay1_7us();
|
||||
command = command << 1;
|
||||
}
|
||||
WR_LOW();
|
||||
delay1_7us();
|
||||
WR_HIGH();
|
||||
delay1_7us();
|
||||
|
||||
if (chip)
|
||||
CS2_HIGH();
|
||||
else
|
||||
CS1_HIGH();
|
||||
|
||||
delay1_7us();
|
||||
}
|
||||
|
||||
void ht1621WrData(uint8_t data, uint8_t count)
|
||||
{
|
||||
while (count) {
|
||||
WR_LOW();
|
||||
if (data & 0x80)
|
||||
DATA_HIGH();
|
||||
else
|
||||
DATA_LOW();
|
||||
delay1_7us();
|
||||
WR_HIGH();
|
||||
delay1_7us();
|
||||
data <<= 1;
|
||||
count -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
void ht1621WrAllData(uint8_t chip, uint8_t *pData)
|
||||
{
|
||||
int len;
|
||||
if (chip) {
|
||||
len = sizeof(Ht1621Data2);
|
||||
CS2_LOW();
|
||||
}
|
||||
else {
|
||||
len = sizeof(Ht1621Data1);
|
||||
CS1_LOW();
|
||||
}
|
||||
delay1_7us();
|
||||
ht1621WrData(0xa0, 3);
|
||||
ht1621WrData(0, 6); // HT1621 6 bit,left 2 bit;
|
||||
for (int i=0; i<len; i++) {
|
||||
ht1621WrData(*pData++, 8);
|
||||
}
|
||||
if (chip)
|
||||
CS2_HIGH();
|
||||
else
|
||||
CS1_HIGH();
|
||||
delay1_7us();
|
||||
}
|
||||
|
||||
#if 0
|
||||
void initTimerTopLcd()
|
||||
{
|
||||
// Timer12
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM12EN; // Enable clock
|
||||
TIM12->ARR = 17; // 1.7uS
|
||||
TIM12->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 10000000 - 1; // 0.1uS from 30MHz
|
||||
TIM12->CCER = 0;
|
||||
TIM12->CCMR1 = 0;
|
||||
TIM12->EGR = 0;
|
||||
TIM12->CR1 = 5;
|
||||
// TIM12->DIER |= 1;
|
||||
NVIC_SetPriority(TIM8_BRK_TIM12_IRQn, 2 );
|
||||
NVIC_EnableIRQ(TIM8_BRK_TIM12_IRQn);
|
||||
}
|
||||
|
||||
extern "C" void TIM8_BRK_TIM12_IRQHandler()
|
||||
{
|
||||
struct t_top_lcd_control *pc;
|
||||
TIM12->SR &= ~TIM_SR_UIF;
|
||||
pc = &TopLcdControl;
|
||||
|
||||
if ( pc->state == TOP_LCD_CKLOW ) {
|
||||
WR_LOW(); //PRESENT 100 COMMAND CODE
|
||||
if ((*pc->data & 0x80) !=0) {
|
||||
DATA_HIGH();
|
||||
}
|
||||
else {
|
||||
DATA_LOW();
|
||||
}
|
||||
*pc->data <<= 1;
|
||||
pc->state = TOP_LCD_CKHI;
|
||||
}
|
||||
else if ( pc->state == TOP_LCD_CKHI ) {
|
||||
WR_HIGH();
|
||||
if ( --pc->count == 0 ) {
|
||||
pc->state = TOP_LCD_END;
|
||||
}
|
||||
else {
|
||||
pc->state = TOP_LCD_CKLOW;
|
||||
}
|
||||
}
|
||||
else if (pc->state == TOP_LCD_END) {
|
||||
if (pc->chip) {
|
||||
CS2_HIGH();
|
||||
pc->state = TOP_LCD_IDLE;
|
||||
TIM12->DIER &= ~1;
|
||||
}
|
||||
else {
|
||||
CS1_HIGH();
|
||||
pc->chip = 1;
|
||||
pc->data = pc->data2;
|
||||
pc->count = pc->count2;
|
||||
pc->state = TOP_LCD_IDLE;
|
||||
}
|
||||
}
|
||||
else if ( pc->state == TOP_LCD_IDLE ) {
|
||||
WR_HIGH();
|
||||
if ( pc->chip ) CS2_LOW(); else CS1_LOW();
|
||||
pc->state = TOP_LCD_1CKLOW;
|
||||
}
|
||||
else if ( pc->state == TOP_LCD_1CKLOW ) {
|
||||
WR_LOW();
|
||||
DATA_HIGH(); // First 1 bit
|
||||
pc->state = TOP_LCD_1CKHI;
|
||||
}
|
||||
else if ( pc->state == TOP_LCD_1CKHI ) {
|
||||
WR_HIGH();
|
||||
if ( --pc->count == 0 ) {
|
||||
pc->state = TOP_LCD_END;
|
||||
}
|
||||
else {
|
||||
pc->state = TOP_LCD_CKLOW;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void topLcdInit()
|
||||
{
|
||||
RCC_AHB1PeriphClockCmd(TOPLCD_RCC_AHB1Periph, ENABLE);
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = TOPLCD_GPIO_PIN_DATA | TOPLCD_GPIO_PIN_WR |TOPLCD_GPIO_PIN_BL|TOPLCD_GPIO_PIN_CS1|TOPLCD_GPIO_PIN_CS2;
|
||||
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_UP;
|
||||
GPIO_Init(TOPLCD_GPIO, &GPIO_InitStructure);
|
||||
|
||||
BL_ON();
|
||||
|
||||
ht1621SendCommand(0, 0x03);
|
||||
ht1621SendCommand(0, 0x01);
|
||||
ht1621SendCommand(0, 0x29);
|
||||
|
||||
ht1621SendCommand(1, 0x03);
|
||||
ht1621SendCommand(1, 0x01);
|
||||
ht1621SendCommand(1, 0x29);
|
||||
|
||||
topLcdRefreshStart();
|
||||
topLcdRefreshEnd();
|
||||
}
|
||||
|
||||
void topLcdOff()
|
||||
{
|
||||
BL_OFF();
|
||||
topLcdRefreshStart();
|
||||
topLcdRefreshEnd();
|
||||
}
|
||||
|
||||
void setTopFirstTimer(int32_t value)
|
||||
{
|
||||
Ht1621Data1[2] |= 0x10; // ":"
|
||||
|
||||
if (value < 0) {
|
||||
if (BLINK_ON_PHASE) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
value = -value;
|
||||
}
|
||||
}
|
||||
|
||||
div_t qr = div(value, 60);
|
||||
uint32_t r = qr.rem;
|
||||
qr = div(qr.quot, 10);
|
||||
|
||||
// Limit to 99 min 99 sec to avoid breaking display
|
||||
if (qr.quot > 9) {
|
||||
qr.quot = 9;
|
||||
qr.rem = 9;
|
||||
r = 99;
|
||||
}
|
||||
|
||||
Ht1621Data1[0] |= TimeLCDsegs[qr.quot];
|
||||
Ht1621Data1[1] |= TimeLCDsegs[qr.rem];
|
||||
qr = div(r, 10);
|
||||
Ht1621Data1[2] |= TimeLCDsegs[qr.quot];
|
||||
Ht1621Data1[3] |= TimeLCDsegs[qr.rem];
|
||||
}
|
||||
|
||||
void setTopRssiValue(uint32_t rssi)
|
||||
{
|
||||
div_t qr = div(rssi, 10);
|
||||
uint32_t r = 0;
|
||||
if (qr.quot > 9) {
|
||||
r = 1;
|
||||
qr.quot -= 10;
|
||||
}
|
||||
Ht1621Data2[2] |= r ? RssiLCDsegs[1] : 0;
|
||||
Ht1621Data2[1] |= (r || qr.quot) ? RssiLCDsegs[qr.quot] : 0;
|
||||
Ht1621Data2[0] |= RssiLCDsegs[qr.rem];
|
||||
}
|
||||
|
||||
void setTopRssiBar(uint32_t rssi)
|
||||
{
|
||||
if (rssi > 42)
|
||||
Ht1621Data2[2] |= 1;
|
||||
if (rssi > 45)
|
||||
Ht1621Data2[1] |= 1;
|
||||
if (rssi > 50)
|
||||
Ht1621Data2[0] |= 1;
|
||||
if (rssi > 60)
|
||||
Ht1621Data2[3] |= 0x10;
|
||||
if (rssi > 70)
|
||||
Ht1621Data2[3] |= 0x20;
|
||||
if (rssi > 80)
|
||||
Ht1621Data2[3] |= 0x40;
|
||||
if (rssi > 90)
|
||||
Ht1621Data2[3] |= 0x80;
|
||||
}
|
||||
|
||||
void setTopRssi(uint32_t rssi)
|
||||
{
|
||||
Ht1621Data1[4] |= 0x10; // "RSSI"
|
||||
Ht1621Data2[3] |= 0x01; // "dB"
|
||||
Ht1621Data2[4] |= 0x01; // Horizontal line
|
||||
setTopRssiValue(rssi);
|
||||
setTopRssiBar(rssi);
|
||||
}
|
||||
|
||||
void setTopBatteryState(int state, uint8_t blinking)
|
||||
{
|
||||
if (!blinking || BLINK_ON_PHASE) {
|
||||
// since the border can not be turned off,
|
||||
// we blink the first bar even if the actual value is zero
|
||||
if (blinking && state < 1) {
|
||||
state = 1;
|
||||
}
|
||||
Ht1621Data1[4] |= 0x40; // Battery border // TODO this is not working for me, the border is ALWAYS on
|
||||
if (state > 0)
|
||||
Ht1621Data1[7] |= 0x80;
|
||||
if (state > 2)
|
||||
Ht1621Data1[9] |= 0x80;
|
||||
if (state > 4)
|
||||
Ht1621Data1[5] |= 0x80;
|
||||
if (state > 6)
|
||||
Ht1621Data1[10] |= 0x80;
|
||||
if (state > 8)
|
||||
Ht1621Data1[4] |= 0x80;
|
||||
}
|
||||
}
|
||||
|
||||
void setTopBatteryValue(uint32_t volts)
|
||||
{
|
||||
div_t qr;
|
||||
uint32_t r = 0;
|
||||
uint32_t segs;
|
||||
qr = div(volts, 10);
|
||||
if (qr.quot > 9) {
|
||||
r = 1;
|
||||
qr.quot -= 10;
|
||||
}
|
||||
segs = r ? RssiLCDsegs[1] : 0;
|
||||
Ht1621Data2[3] |= ((segs & 7) << 1);
|
||||
Ht1621Data2[4] |= segs & 0xF0;
|
||||
segs = (r || qr.quot) ? RssiLCDsegs[qr.quot] : 0;
|
||||
Ht1621Data2[4] |= (segs & 0x0E);
|
||||
Ht1621Data2[5] |= segs & 0xF0;
|
||||
segs = RssiLCDsegs[qr.rem];
|
||||
Ht1621Data2[5] |= (segs & 0x0E) | 1; // Decimal point
|
||||
Ht1621Data2[6] |= segs & 0xF0;
|
||||
Ht1621Data1[4] |= 0x20; // "V"
|
||||
}
|
||||
|
||||
void setTopSecondTimer(uint32_t value)
|
||||
{
|
||||
div_t qr;
|
||||
uint32_t segs;
|
||||
uint32_t segs2;
|
||||
|
||||
qr = div(value, 60);
|
||||
uint32_t secs = qr.rem;
|
||||
qr = div(qr.quot, 60);
|
||||
uint32_t mins = qr.rem;
|
||||
uint32_t hours = qr.quot;
|
||||
|
||||
qr = div(secs, 10);
|
||||
segs = OpTimeLCDsegs[qr.rem];
|
||||
Ht1621Data1[4] |= (segs & 0x0F) | 0x70;
|
||||
segs &= 0x70;
|
||||
segs2 = OpTimeLCDsegs[qr.quot];
|
||||
Ht1621Data1[5] |= segs | (segs2 & 0x0F);
|
||||
|
||||
qr = div(mins, 10);
|
||||
segs = OpTimeLCDsegs[qr.rem];
|
||||
segs2 &= 0x70;
|
||||
Ht1621Data1[6] |= segs2 | (segs & 0x0F) | 0x80; // ":"
|
||||
segs &= 0x70;
|
||||
segs2 = OpTimeLCDsegs[qr.quot];
|
||||
Ht1621Data1[7] |= segs | (segs2 & 0x0F);
|
||||
|
||||
qr = div(hours, 10);
|
||||
segs = OpTimeLCDsegs[qr.rem];
|
||||
segs2 &= 0x70;
|
||||
Ht1621Data1[8] |= segs2 | (segs & 0x0F) | 0x80; // ":"
|
||||
segs &= 0x70;
|
||||
segs2 = OpTimeLCDsegs[qr.quot];
|
||||
Ht1621Data1[9] |= segs | (segs2 & 0x0F);
|
||||
Ht1621Data1[10] |= segs2 & 0xF0;
|
||||
|
||||
Ht1621Data1[3] |= 0x10; // "Operation Time"
|
||||
}
|
||||
|
||||
void topLcdRefreshStart()
|
||||
{
|
||||
memset(Ht1621Data1, 0, sizeof(Ht1621Data1));
|
||||
memset(Ht1621Data2, 0, sizeof(Ht1621Data2));
|
||||
}
|
||||
|
||||
void topLcdRefreshEnd()
|
||||
{
|
||||
ht1621WrAllData(0, Ht1621Data1);
|
||||
ht1621WrAllData(1, Ht1621Data2);
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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"
|
||||
|
||||
extern Fifo<32> sbusFifo;
|
||||
|
||||
#define setupTrainerPulses() setupPulsesPPM(TRAINER_MODULE)
|
||||
|
||||
// Trainer PPM output PC9, Timer 3 channel 4, (Alternate Function 2)
|
||||
void init_trainer_ppm()
|
||||
{
|
||||
trainerPulsesData.ppm.ptr = trainerPulsesData.ppm.pulses;
|
||||
|
||||
configure_pins( TRAINER_GPIO_PIN_OUT, PIN_PERIPHERAL | PIN_PORTC | PIN_PER_2 | PIN_OS25) ;
|
||||
|
||||
TRAINER_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
|
||||
// setupTrainerPulses() is also configuring registers,
|
||||
// so it has to be called after the peripheral is enabled
|
||||
setupTrainerPulses() ;
|
||||
|
||||
TRAINER_TIMER->ARR = *trainerPulsesData.ppm.ptr++ ;
|
||||
TRAINER_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 2000000 - 1 ; // 0.5uS
|
||||
TRAINER_TIMER->CCMR2 = TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC4PE ; // PWM mode 1
|
||||
TRAINER_TIMER->BDTR = TIM_BDTR_MOE ;
|
||||
TRAINER_TIMER->EGR = 1 ;
|
||||
|
||||
TRAINER_TIMER->SR &= ~TIM_SR_UIF ; // Clear flag
|
||||
TRAINER_TIMER->SR &= ~TIM_SR_CC1IF ; // Clear flag
|
||||
TRAINER_TIMER->DIER |= TIM_DIER_CC1IE ;
|
||||
TRAINER_TIMER->DIER |= TIM_DIER_UIE ;
|
||||
|
||||
TRAINER_TIMER->CR1 = TIM_CR1_CEN ;
|
||||
NVIC_EnableIRQ(TRAINER_TIMER_IRQn) ;
|
||||
NVIC_SetPriority(TRAINER_TIMER_IRQn, 7);
|
||||
}
|
||||
|
||||
// TODO - testing
|
||||
void stop_trainer_ppm()
|
||||
{
|
||||
configure_pins( TRAINER_GPIO_PIN_OUT, PIN_INPUT | PIN_PORTC ) ; // Pin as input
|
||||
TRAINER_TIMER->DIER = 0 ; // Stop Interrupt
|
||||
TRAINER_TIMER->CR1 &= ~TIM_CR1_CEN ; // Stop counter
|
||||
NVIC_DisableIRQ(TRAINER_TIMER_IRQn) ; // Stop Interrupt
|
||||
}
|
||||
|
||||
void set_trainer_ppm_parameters(uint32_t idleTime, uint32_t delay, uint32_t positive)
|
||||
{
|
||||
TRAINER_TIMER->CCR1 = idleTime;
|
||||
TRAINER_TIMER->CCR4 = delay;
|
||||
TRAINER_TIMER->CCER = TIM_CCER_CC4E | (positive ? TIM_CCER_CC4P : 0);
|
||||
}
|
||||
|
||||
// Trainer capture, PC8, Timer 3 channel 3
|
||||
void init_trainer_capture()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = TRAINER_GPIO_PIN_IN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(TRAINER_GPIO, &GPIO_InitStructure);
|
||||
GPIO_PinAFConfig(TRAINER_GPIO, TRAINER_GPIO_PinSource_IN, TRAINER_GPIO_AF);
|
||||
|
||||
TRAINER_TIMER->ARR = 0xFFFF ;
|
||||
TRAINER_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 2000000 - 1 ; // 0.5uS
|
||||
TRAINER_TIMER->CR2 = 0 ;
|
||||
TRAINER_TIMER->CCMR2 = TIM_CCMR2_IC3F_0 | TIM_CCMR2_IC3F_1 | TIM_CCMR2_CC3S_0 ;
|
||||
TRAINER_TIMER->CCER = TIM_CCER_CC3E ;
|
||||
TRAINER_TIMER->SR &= ~TIM_SR_CC3IF & ~TIM_SR_CC2IF & ~TIM_SR_UIF ; // Clear flags
|
||||
TRAINER_TIMER->DIER |= TIM_DIER_CC3IE ;
|
||||
TRAINER_TIMER->CR1 = TIM_CR1_CEN ;
|
||||
NVIC_EnableIRQ(TRAINER_TIMER_IRQn) ;
|
||||
NVIC_SetPriority(TRAINER_TIMER_IRQn, 7);
|
||||
}
|
||||
|
||||
void stop_trainer_capture()
|
||||
{
|
||||
TRAINER_TIMER->CR1 &= ~TIM_CR1_CEN ; // Stop counter
|
||||
TRAINER_TIMER->DIER = 0; // Stop Interrupt
|
||||
NVIC_DisableIRQ(TRAINER_TIMER_IRQn) ; // Stop Interrupt
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" void TIM3_IRQHandler()
|
||||
{
|
||||
uint16_t capture = 0;
|
||||
bool doCapture = false ;
|
||||
|
||||
// What mode? in or out?
|
||||
if ( (TRAINER_TIMER->DIER & TIM_DIER_CC3IE ) && ( TRAINER_TIMER->SR & TIM_SR_CC3IF ) ) {
|
||||
// capture mode on trainer jack
|
||||
capture = TRAINER_TIMER->CCR3 ;
|
||||
doCapture = true;
|
||||
}
|
||||
|
||||
if ( ( TRAINER_TIMER->DIER & TIM_DIER_CC2IE ) && ( TRAINER_TIMER->SR & TIM_SR_CC2IF ) ) {
|
||||
// capture mode on heartbeat pin (external module)
|
||||
capture = TRAINER_TIMER->CCR2 ;
|
||||
doCapture = true ;
|
||||
}
|
||||
|
||||
if (doCapture) {
|
||||
captureTrainerPulses(capture);
|
||||
}
|
||||
|
||||
// PPM out compare interrupt
|
||||
if ( ( TRAINER_TIMER->DIER & TIM_DIER_CC1IE ) && ( TRAINER_TIMER->SR & TIM_SR_CC1IF ) ) {
|
||||
// compare interrupt
|
||||
TRAINER_TIMER->DIER &= ~TIM_DIER_CC1IE ; // stop this interrupt
|
||||
TRAINER_TIMER->SR &= ~TIM_SR_CC1IF ; // Clear flag
|
||||
|
||||
setupTrainerPulses() ;
|
||||
|
||||
trainerPulsesData.ppm.ptr = trainerPulsesData.ppm.pulses;
|
||||
TRAINER_TIMER->DIER |= TIM_DIER_UDE ;
|
||||
TRAINER_TIMER->SR &= ~TIM_SR_UIF ; // Clear this flag
|
||||
TRAINER_TIMER->DIER |= TIM_DIER_UIE ; // Enable this interrupt
|
||||
}
|
||||
|
||||
// PPM out update interrupt
|
||||
if ( (TRAINER_TIMER->DIER & TIM_DIER_UIE) && ( TRAINER_TIMER->SR & TIM_SR_UIF ) ) {
|
||||
TRAINER_TIMER->SR &= ~TIM_SR_UIF ; // Clear flag
|
||||
TRAINER_TIMER->ARR = *trainerPulsesData.ppm.ptr++ ;
|
||||
if ( *trainerPulsesData.ppm.ptr == 0 ) {
|
||||
TRAINER_TIMER->SR &= ~TIM_SR_CC1IF ; // Clear this flag
|
||||
TRAINER_TIMER->DIER |= TIM_DIER_CC1IE ; // Enable this interrupt
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void init_cppm_on_heartbeat_capture(void)
|
||||
{
|
||||
EXTERNAL_MODULE_ON();
|
||||
|
||||
configure_pins(HEARTBEAT_GPIO_PIN, PIN_PERIPHERAL | PIN_PORTC | PIN_PER_2);
|
||||
|
||||
TRAINER_TIMER->ARR = 0xFFFF ;
|
||||
TRAINER_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 2000000 - 1 ; // 0.5uS
|
||||
TRAINER_TIMER->CR2 = 0 ;
|
||||
TRAINER_TIMER->CCMR1 = TIM_CCMR1_IC2F_0 | TIM_CCMR1_IC2F_1 | TIM_CCMR1_CC2S_0 ;
|
||||
TRAINER_TIMER->CCER = TIM_CCER_CC2E ;
|
||||
TRAINER_TIMER->SR &= ~TIM_SR_CC2IF ; // Clear flag
|
||||
TRAINER_TIMER->DIER |= TIM_DIER_CC2IE ;
|
||||
TRAINER_TIMER->CR1 = TIM_CR1_CEN ;
|
||||
NVIC_SetPriority(TRAINER_TIMER_IRQn, 7);
|
||||
NVIC_EnableIRQ(TRAINER_TIMER_IRQn) ;
|
||||
}
|
||||
|
||||
void stop_cppm_on_heartbeat_capture(void)
|
||||
{
|
||||
TRAINER_TIMER->DIER = 0 ;
|
||||
TRAINER_TIMER->CR1 &= ~TIM_CR1_CEN ; // Stop counter
|
||||
NVIC_DisableIRQ(TRAINER_TIMER_IRQn) ; // Stop Interrupt
|
||||
|
||||
if (!IS_PULSES_EXTERNAL_MODULE()) {
|
||||
EXTERNAL_MODULE_OFF();
|
||||
}
|
||||
}
|
||||
|
||||
void init_sbus_on_heartbeat_capture()
|
||||
{
|
||||
EXTERNAL_MODULE_ON();
|
||||
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
GPIO_PinAFConfig(GPIOC, HEARTBEAT_GPIO_PinSource, HEARTBEAT_GPIO_AF);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = HEARTBEAT_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||
|
||||
USART_InitStructure.USART_BaudRate = 100000;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_Even;
|
||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||
USART_InitStructure.USART_Mode = USART_Mode_Rx;
|
||||
|
||||
USART_Init(HEARTBEAT_USART, &USART_InitStructure);
|
||||
USART_Cmd(HEARTBEAT_USART, ENABLE);
|
||||
USART_ITConfig(HEARTBEAT_USART, USART_IT_RXNE, ENABLE);
|
||||
|
||||
NVIC_SetPriority(HEARTBEAT_USART_IRQn, 6);
|
||||
NVIC_EnableIRQ(HEARTBEAT_USART_IRQn);
|
||||
}
|
||||
|
||||
void stop_sbus_on_heartbeat_capture(void)
|
||||
{
|
||||
configure_pins(HEARTBEAT_GPIO_PIN, PIN_INPUT | PIN_PORTC);
|
||||
NVIC_DisableIRQ(HEARTBEAT_USART_IRQn) ;
|
||||
|
||||
if (!IS_PULSES_EXTERNAL_MODULE()) {
|
||||
EXTERNAL_MODULE_OFF();
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(SIMU) && !defined(REV9E)
|
||||
extern "C" void HEARTBEAT_USART_IRQHandler()
|
||||
{
|
||||
uint32_t status;
|
||||
uint8_t data;
|
||||
|
||||
status = HEARTBEAT_USART->SR;
|
||||
|
||||
while (status & (USART_FLAG_RXNE | USART_FLAG_ERRORS)) {
|
||||
data = HEARTBEAT_USART->DR;
|
||||
|
||||
if (!(status & USART_FLAG_ERRORS))
|
||||
sbusFifo.push(data);
|
||||
|
||||
status = HEARTBEAT_USART->SR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,149 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_bsp.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 19-March-2012
|
||||
* @brief This file is responsible to offer board support package and is
|
||||
* configurable by user.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "usb_bsp.h"
|
||||
|
||||
#include "../Taranis/board_taranis.h"
|
||||
#include "../Taranis/usbd_conf.h"
|
||||
|
||||
extern uint32_t SystemCoreClock;
|
||||
|
||||
/**
|
||||
* @brief USB_OTG_BSP_Init
|
||||
* Initilizes BSP configurations
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_AHB1PeriphClockCmd(USB_RCC_AHB1Periph_GPIO, ENABLE);
|
||||
|
||||
/* Configure DM and DP Pins */
|
||||
GPIO_InitStructure.GPIO_Pin = USB_GPIO_PIN_DM | USB_GPIO_PIN_DP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(USB_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_PinAFConfig(USB_GPIO, USB_GPIO_PinSource_DM, USB_GPIO_AF);
|
||||
GPIO_PinAFConfig(USB_GPIO, USB_GPIO_PinSource_DP, USB_GPIO_AF);
|
||||
|
||||
/* Configure VBUS Pin */
|
||||
GPIO_InitStructure.GPIO_Pin = USB_GPIO_PIN_VBUS;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
|
||||
GPIO_Init(USB_GPIO, &GPIO_InitStructure);
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
|
||||
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ;
|
||||
}
|
||||
|
||||
void USB_OTG_BSP_Deinit(USB_OTG_CORE_HANDLE *pdev)
|
||||
{
|
||||
//nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USB_OTG_BSP_EnableInterrupt
|
||||
* Enable USB Global interrupt
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
|
||||
NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USB_OTG_BSP_DisableInterrupt
|
||||
* Disable USB Global interrupt
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void USB_OTG_BSP_DisableInterrupt(USB_OTG_CORE_HANDLE *pdev)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
|
||||
NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USB_OTG_BSP_uDelay
|
||||
* This function provides delay time in micro sec
|
||||
* @param usec : Value of delay required in micro sec
|
||||
* @retval None
|
||||
*/
|
||||
void USB_OTG_BSP_uDelay (const uint32_t usec)
|
||||
{
|
||||
uint32_t count = 0;
|
||||
const uint32_t utime = ((SystemCoreClock/1000000) * usec);
|
||||
do
|
||||
{
|
||||
if ( ++count > utime )
|
||||
{
|
||||
return ;
|
||||
}
|
||||
}
|
||||
while (1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USB_OTG_BSP_mDelay
|
||||
* This function provides delay time in milli sec
|
||||
* @param msec : Value of delay required in milli sec
|
||||
* @retval None
|
||||
*/
|
||||
void USB_OTG_BSP_mDelay (const uint32_t msec)
|
||||
{
|
||||
USB_OTG_BSP_uDelay(msec * 1000);
|
||||
}
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usb_conf.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 19-March-2012
|
||||
* @brief General low level driver configuration
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_CONF__H__
|
||||
#define __USB_CONF__H__
|
||||
|
||||
#if defined(REV9E)
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
|
||||
#else
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h"
|
||||
#endif
|
||||
|
||||
/* USB Core and PHY interface configuration.
|
||||
Tip: To avoid modifying these defines each time you need to change the USB
|
||||
configuration, you can declare the needed define in your toolchain
|
||||
compiler preprocessor.
|
||||
*/
|
||||
/****************** USB OTG FS PHY CONFIGURATION *******************************
|
||||
* The USB OTG FS Core supports one on-chip Full Speed PHY.
|
||||
*
|
||||
* The USE_EMBEDDED_PHY symbol is defined in the project compiler preprocessor
|
||||
* when FS core is used.
|
||||
*******************************************************************************/
|
||||
#ifndef USE_USB_OTG_FS
|
||||
#define USE_USB_OTG_FS // USB2.0 Full Speed == 12 Mbit
|
||||
#endif /* USE_USB_OTG_FS */
|
||||
|
||||
#ifdef USE_USB_OTG_FS
|
||||
#define USB_OTG_FS_CORE
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* FIFO Size Configuration in Device mode
|
||||
*
|
||||
* (i) Receive data FIFO size = RAM for setup packets +
|
||||
* OUT endpoint control information +
|
||||
* data OUT packets + miscellaneous
|
||||
* Space = ONE 32-bits words
|
||||
* --> RAM for setup packets = 10 spaces
|
||||
* (n is the nbr of CTRL EPs the device core supports)
|
||||
* --> OUT EP CTRL info = 1 space
|
||||
* (one space for status information written to the FIFO along with each
|
||||
* received packet)
|
||||
* --> data OUT packets = (Largest Packet Size / 4) + 1 spaces
|
||||
* (MINIMUM to receive packets)
|
||||
* --> OR data OUT packets = at least 2*(Largest Packet Size / 4) + 1 spaces
|
||||
* (if high-bandwidth EP is enabled or multiple isochronous EPs)
|
||||
* --> miscellaneous = 1 space per OUT EP
|
||||
* (one space for transfer complete status information also pushed to the
|
||||
* FIFO with each endpoint's last packet)
|
||||
*
|
||||
* (ii)MINIMUM RAM space required for each IN EP Tx FIFO = MAX packet size for
|
||||
* that particular IN EP. More space allocated in the IN EP Tx FIFO results
|
||||
* in a better performance on the USB and can hide latencies on the AHB.
|
||||
*
|
||||
* (iii) TXn min size = 16 words. (n : Transmit FIFO index)
|
||||
* (iv) When a TxFIFO is not used, the Configuration should be as follows:
|
||||
* case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
|
||||
* --> Txm can use the space allocated for Txn.
|
||||
* case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
|
||||
* --> Txn should be configured with the minimum space of 16 words
|
||||
* (v) The FIFO is used optimally when used TxFIFOs are allocated in the top
|
||||
* of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
|
||||
* (vi) In HS case12 FIFO locations should be reserved for internal DMA registers
|
||||
* so total FIFO size should be 1012 Only instead of 1024
|
||||
*******************************************************************************/
|
||||
|
||||
/****************** USB OTG FS CONFIGURATION **********************************/
|
||||
#ifdef USB_OTG_FS_CORE
|
||||
#define RX_FIFO_FS_SIZE 128
|
||||
#define TX0_FIFO_FS_SIZE 64
|
||||
#define TX1_FIFO_FS_SIZE 128
|
||||
#define TX2_FIFO_FS_SIZE 0
|
||||
#define TX3_FIFO_FS_SIZE 0
|
||||
|
||||
// #define USB_OTG_FS_LOW_PWR_MGMT_SUPPORT
|
||||
// #define USB_OTG_FS_SOF_OUTPUT_ENABLED
|
||||
#endif
|
||||
|
||||
/****************** USB OTG MISC CONFIGURATION ********************************/
|
||||
#define VBUS_SENSING_ENABLED
|
||||
|
||||
/****************** USB OTG MODE CONFIGURATION ********************************/
|
||||
//#define USE_HOST_MODE
|
||||
#define USE_DEVICE_MODE
|
||||
//#define USE_OTG_MODE
|
||||
|
||||
#ifndef USB_OTG_FS_CORE
|
||||
#ifndef USB_OTG_HS_CORE
|
||||
#error "USB_OTG_HS_CORE or USB_OTG_FS_CORE should be defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef USE_DEVICE_MODE
|
||||
#ifndef USE_HOST_MODE
|
||||
#error "USE_DEVICE_MODE or USE_HOST_MODE should be defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef USE_USB_OTG_HS
|
||||
#ifndef USE_USB_OTG_FS
|
||||
#error "USE_USB_OTG_HS or USE_USB_OTG_FS should be defined"
|
||||
#endif
|
||||
#else //USE_USB_OTG_HS
|
||||
#ifndef USE_ULPI_PHY
|
||||
#ifndef USE_EMBEDDED_PHY
|
||||
#error "USE_ULPI_PHY or USE_EMBEDDED_PHY should be defined"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************** C Compilers dependant keywords ****************************/
|
||||
/* In HS mode and when the DMA is used, all variables and data structures dealing
|
||||
with the DMA during the transaction process should be 4-bytes aligned */
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#if defined (__GNUC__) /* GNU Compiler */
|
||||
#define __ALIGN_END __attribute__ ((aligned (4)))
|
||||
#define __ALIGN_BEGIN
|
||||
#else
|
||||
#define __ALIGN_END
|
||||
#if defined (__CC_ARM) /* ARM Compiler */
|
||||
#define __ALIGN_BEGIN __align(4)
|
||||
#elif defined (__ICCARM__) /* IAR Compiler */
|
||||
#define __ALIGN_BEGIN
|
||||
#elif defined (__TASKING__) /* TASKING Compiler */
|
||||
#define __ALIGN_BEGIN __align(4)
|
||||
#endif /* __CC_ARM */
|
||||
#endif /* __GNUC__ */
|
||||
#else
|
||||
#define __ALIGN_BEGIN
|
||||
#define __ALIGN_END
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
|
||||
/* __packed keyword used to decrease the data type alignment to 1-byte */
|
||||
#if !defined(__packed)
|
||||
#if defined (__CC_ARM) /* ARM Compiler */
|
||||
#define __packed __packed
|
||||
#elif defined (__ICCARM__) /* IAR Compiler */
|
||||
#define __packed __packed
|
||||
#elif defined ( __GNUC__ ) /* GNU Compiler */
|
||||
#define __packed __attribute__ ((__packed__))
|
||||
#elif defined (__TASKING__) /* TASKING Compiler */
|
||||
#define __packed __unaligned
|
||||
#endif /* __CC_ARM */
|
||||
#endif
|
||||
|
||||
#endif //__USB_CONF__H__
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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 "../Taranis/board_taranis.h"
|
||||
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h"
|
||||
|
||||
int usbPlugged(void)
|
||||
{
|
||||
// debounce
|
||||
static uint8_t debounced_state = 0;
|
||||
static uint8_t last_state = 0;
|
||||
|
||||
if (GPIO_ReadInputDataBit(USB_GPIO, USB_GPIO_PIN_VBUS)) {
|
||||
if (last_state) {
|
||||
debounced_state = 1;
|
||||
}
|
||||
last_state = 1;
|
||||
}
|
||||
else {
|
||||
if (!last_state) {
|
||||
debounced_state = 0;
|
||||
}
|
||||
last_state = 0;
|
||||
}
|
||||
return debounced_state;
|
||||
}
|
||||
|
||||
USB_OTG_CORE_HANDLE USB_OTG_dev;
|
||||
|
||||
void OTG_FS_IRQHandler(void)
|
||||
{
|
||||
USBD_OTG_ISR_Handler(&USB_OTG_dev);
|
||||
}
|
||||
|
||||
void usbInit(void)
|
||||
{
|
||||
#if defined(USB_JOYSTICK)
|
||||
// initialize USB as HID device
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_HID_cb, &USR_cb);
|
||||
#elif defined(USB_SERIAL)
|
||||
// initialize USB as CDC device (virtual serial port)
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb);
|
||||
#elif defined(USB_MASS_STORAGE)
|
||||
// initialize USB as MSC device
|
||||
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb);
|
||||
#endif
|
||||
}
|
||||
|
||||
void usbDeInit(void)
|
||||
{
|
||||
USBD_DeInit(&USB_OTG_dev);
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_cdc_vcp.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 19-March-2012
|
||||
* @brief Generic media access Layer.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#pragma data_alignment = 4
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "../Taranis/usb_conf.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
|
||||
/* These are external variables imported from CDC core to be used for IN
|
||||
transfer management. */
|
||||
extern uint8_t APP_Rx_Buffer []; /* Write CDC received data in this buffer.
|
||||
These data will be sent over USB IN endpoint
|
||||
in the CDC core functions. */
|
||||
extern volatile uint32_t APP_Rx_ptr_in; /* Increment this pointer or roll it back to
|
||||
start address when writing received data
|
||||
in the buffer APP_Rx_Buffer. */
|
||||
extern volatile uint32_t APP_Rx_ptr_out;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static uint16_t VCP_Init (void);
|
||||
static uint16_t VCP_DeInit (void);
|
||||
static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len);
|
||||
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len);
|
||||
|
||||
// static uint16_t VCP_COMConfig(uint8_t Conf);
|
||||
|
||||
CDC_IF_Prop_TypeDef VCP_fops =
|
||||
{
|
||||
VCP_Init,
|
||||
VCP_DeInit,
|
||||
VCP_Ctrl,
|
||||
0,
|
||||
VCP_DataRx
|
||||
};
|
||||
|
||||
} // extern "C"
|
||||
|
||||
bool cdcConnected = false;
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @brief VCP_Init
|
||||
* Initializes the Media on the STM32
|
||||
* @param None
|
||||
* @retval Result of the opeartion (USBD_OK in all cases)
|
||||
*/
|
||||
static uint16_t VCP_Init(void)
|
||||
{
|
||||
cdcConnected = true;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VCP_DeInit
|
||||
* DeInitializes the Media on the STM32
|
||||
* @param None
|
||||
* @retval Result of the opeartion (USBD_OK in all cases)
|
||||
*/
|
||||
static uint16_t VCP_DeInit(void)
|
||||
{
|
||||
cdcConnected = false;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief VCP_Ctrl
|
||||
* Manage the CDC class requests
|
||||
* @param Cmd: Command code
|
||||
* @param Buf: Buffer containing command data (request parameters)
|
||||
* @param Len: Number of data to be sent (in bytes)
|
||||
* @retval Result of the opeartion (USBD_OK in all cases)
|
||||
*/
|
||||
static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
|
||||
{
|
||||
switch (Cmd)
|
||||
{
|
||||
case SEND_ENCAPSULATED_COMMAND:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
case GET_ENCAPSULATED_RESPONSE:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
case SET_COMM_FEATURE:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
case GET_COMM_FEATURE:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
case CLEAR_COMM_FEATURE:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
case SET_LINE_CODING:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
case GET_LINE_CODING:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
case SET_CONTROL_LINE_STATE:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
case SEND_BREAK:
|
||||
/* Not needed for this driver */
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
// some debug vars
|
||||
uint16_t usbWraps = 0;
|
||||
uint16_t charsWritten = 0;
|
||||
|
||||
void usbSerialPutc(uint8_t c)
|
||||
{
|
||||
if (!cdcConnected) return;
|
||||
|
||||
uint32_t txDataLen;
|
||||
do {
|
||||
txDataLen = APP_RX_DATA_SIZE + APP_Rx_ptr_in - APP_Rx_ptr_out;
|
||||
if (txDataLen >= APP_RX_DATA_SIZE) {
|
||||
txDataLen -= APP_RX_DATA_SIZE;
|
||||
}
|
||||
} while (txDataLen >= (APP_RX_DATA_SIZE - CDC_DATA_MAX_PACKET_SIZE));
|
||||
|
||||
APP_Rx_Buffer[APP_Rx_ptr_in] = c;
|
||||
++charsWritten;
|
||||
/* To avoid buffer overflow */
|
||||
if (APP_Rx_ptr_in >= APP_RX_DATA_SIZE-1) {
|
||||
APP_Rx_ptr_in = 0;
|
||||
++usbWraps;
|
||||
}
|
||||
else {
|
||||
APP_Rx_ptr_in++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief VCP_DataRx
|
||||
* Data received over USB OUT endpoint is available here
|
||||
*
|
||||
* @note
|
||||
* This function will block any OUT packet reception on USB endpoint
|
||||
* until exiting this function. If you exit this function before transfer
|
||||
* is complete on CDC interface (ie. using DMA controller) it will result
|
||||
* in receiving more data while previous ones are still not sent.
|
||||
*
|
||||
* @note
|
||||
* This function is executed inside the USBD_OTG_ISR_Handler() interrupt handler!
|
||||
|
||||
* @param Buf: Buffer of data to be received
|
||||
* @param Len: Number of data received (in bytes)
|
||||
* @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL
|
||||
*/
|
||||
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)
|
||||
{
|
||||
// TODO: try implementing inbound flow control:
|
||||
// if the cliRxFifo does not have enough free space to receive all
|
||||
// available characters, return VCP_FAIL. Maybe that will throttle down
|
||||
// the sender and we will receive the same packet at a later time.
|
||||
|
||||
#if defined(CLI)
|
||||
//copy data to the application FIFO
|
||||
for (uint32_t i = 0; i < Len; i++)
|
||||
{
|
||||
cliRxFifo.push(Buf[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_conf.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 19-March-2012
|
||||
* @brief USB Device configuration file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_CONF__H__
|
||||
#define __USBD_CONF__H__
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "../Taranis/usb_conf.h"
|
||||
|
||||
#define USBD_CFG_MAX_NUM 1
|
||||
#define USBD_ITF_MAX_NUM 1
|
||||
#define USB_MAX_STR_DESC_SIZ 64
|
||||
|
||||
#define USBD_SELF_POWERED
|
||||
|
||||
/* Class Layer Parameter */
|
||||
|
||||
#define MSC_IN_EP 0x81
|
||||
#define MSC_OUT_EP 0x01
|
||||
#define MSC_MAX_PACKET 64
|
||||
|
||||
#define MSC_MEDIA_PACKET 4096
|
||||
|
||||
#define HID_IN_EP 0x81
|
||||
#define HID_OUT_EP 0x01
|
||||
|
||||
#define HID_IN_PACKET 9
|
||||
#define HID_OUT_PACKET 9
|
||||
|
||||
#define CDC_IN_EP 0x81 /* EP1 for data IN */
|
||||
#define CDC_OUT_EP 0x01 /* EP1 for data OUT */
|
||||
#define CDC_CMD_EP 0x82 /* EP2 for CDC commands */
|
||||
|
||||
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
||||
#define CDC_DATA_MAX_PACKET_SIZE 64 /* Endpoint IN & OUT Packet size */
|
||||
#define CDC_CMD_PACKET_SZE 8 /* Control Endpoint Packet size */
|
||||
|
||||
#define CDC_IN_FRAME_INTERVAL 5 /* Number of frames between IN transfers */
|
||||
#define APP_RX_DATA_SIZE 512 // USB serial port output buffer. TODO: tune this buffer size /* Total size of IN buffer: APP_RX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > CDC_IN_FRAME_INTERVAL */
|
||||
#define APP_FOPS VCP_fops
|
||||
|
||||
#endif //__USBD_CONF__H__
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_desc.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 19-March-2012
|
||||
* @brief This file provides the USBD descriptors and string formating method.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <string.h>
|
||||
#include "usbd_desc.h"
|
||||
#include "board_taranis.h"
|
||||
#include "usbd_conf.h"
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_req.h"
|
||||
#include "usb_regs.h"
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_DESC
|
||||
* @brief USBD descriptors module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_DESC_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define USBD_VID 0x0483
|
||||
|
||||
#define USBD_LANGID_STRING 0x409
|
||||
#define USBD_MANUFACTURER_STRING "FrSky"
|
||||
#define USBD_SERIALNUMBER_FS_STRING "00000000001B"
|
||||
|
||||
|
||||
#if defined(BOOT)
|
||||
#define USBD_PID 0x5720
|
||||
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Bootloader"
|
||||
#define USBD_CONFIGURATION_FS_STRING "MSC Config"
|
||||
#define USBD_INTERFACE_FS_STRING "MSC Interface"
|
||||
#elif defined(USB_JOYSTICK)
|
||||
#define USBD_PID 0x5710
|
||||
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Joystick"
|
||||
#define USBD_CONFIGURATION_FS_STRING "HID Config"
|
||||
#define USBD_INTERFACE_FS_STRING "HID Interface"
|
||||
#elif defined(USB_SERIAL)
|
||||
#define USBD_PID 0x5740 // do not change, this ID is used by the ST USB driver for Windows
|
||||
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Serial Port"
|
||||
#define USBD_CONFIGURATION_FS_STRING "VSP Config"
|
||||
#define USBD_INTERFACE_FS_STRING "VSP Interface"
|
||||
#elif defined(USB_MASS_STORAGE)
|
||||
#define USBD_PID 0x5720
|
||||
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Mass Storage"
|
||||
#define USBD_CONFIGURATION_FS_STRING "MSC Config"
|
||||
#define USBD_INTERFACE_FS_STRING "MSC Interface"
|
||||
#endif
|
||||
|
||||
const USBD_DEVICE USR_desc =
|
||||
{
|
||||
USBD_USR_DeviceDescriptor,
|
||||
USBD_USR_LangIDStrDescriptor,
|
||||
USBD_USR_ManufacturerStrDescriptor,
|
||||
USBD_USR_ProductStrDescriptor,
|
||||
USBD_USR_SerialStrDescriptor,
|
||||
USBD_USR_ConfigStrDescriptor,
|
||||
USBD_USR_InterfaceStrDescriptor,
|
||||
};
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN const uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
|
||||
{
|
||||
USB_SIZ_DEVICE_DESC, /*bLength */
|
||||
USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
|
||||
0x00, /*bcdUSB */
|
||||
0x02,
|
||||
0x00, /*bDeviceClass*/
|
||||
0x00, /*bDeviceSubClass*/
|
||||
0x00, /*bDeviceProtocol*/
|
||||
USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize*/
|
||||
LOBYTE(USBD_VID), /*idVendor*/
|
||||
HIBYTE(USBD_VID), /*idVendor*/
|
||||
LOBYTE(USBD_PID), /*idVendor*/
|
||||
HIBYTE(USBD_PID), /*idVendor*/
|
||||
0x00, /*bcdDevice rel. 2.00*/
|
||||
0x02,
|
||||
USBD_IDX_MFC_STR, /*Index of manufacturer string*/
|
||||
USBD_IDX_PRODUCT_STR, /*Index of product string*/
|
||||
USBD_IDX_SERIAL_STR, /*Index of serial number string*/
|
||||
USBD_CFG_MAX_NUM /*bNumConfigurations*/
|
||||
}; /* USB_DeviceDescriptor */
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN const uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||
{
|
||||
USB_LEN_DEV_QUALIFIER_DESC,
|
||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
};
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN const uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END =
|
||||
{
|
||||
USB_SIZ_STRING_LANGID,
|
||||
USB_DESC_TYPE_STRING,
|
||||
LOBYTE(USBD_LANGID_STRING),
|
||||
HIBYTE(USBD_LANGID_STRING),
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief USBD_USR_DeviceDescriptor
|
||||
* return the device descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_DeviceDesc);
|
||||
memcpy(USBD_StrDesc, USBD_DeviceDesc, *length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_LangIDStrDescriptor
|
||||
* return the LangID string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_LangIDDesc);
|
||||
memcpy(USBD_StrDesc, USBD_LangIDDesc, *length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_ProductStrDescriptor
|
||||
* return the product string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
{
|
||||
USBD_GetString ((uint8_t*)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_ManufacturerStrDescriptor
|
||||
* return the manufacturer string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
{
|
||||
USBD_GetString ((uint8_t*)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_SerialStrDescriptor
|
||||
* return the serial number string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
{
|
||||
USBD_GetString ((uint8_t*)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_ConfigStrDescriptor
|
||||
* return the configuration string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
{
|
||||
USBD_GetString ((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_InterfaceStrDescriptor
|
||||
* return the interface string descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length)
|
||||
{
|
||||
USBD_GetString ((uint8_t*)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_desc.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 19-March-2012
|
||||
* @brief header file for the usbd_desc.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
|
||||
#ifndef __USB_DESC_H
|
||||
#define __USB_DESC_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usb_core.h"
|
||||
#include "usbd_def.h"
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_DESC
|
||||
* @brief general defines for the usb device library file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_DESC_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
|
||||
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
|
||||
#define USB_STRING_DESCRIPTOR_TYPE 0x03
|
||||
#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
|
||||
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
|
||||
#define USB_SIZ_DEVICE_DESC 18
|
||||
#define USB_SIZ_STRING_LANGID 4
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_DESC_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_DESC_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
extern const uint8_t USBD_DeviceDesc [USB_SIZ_DEVICE_DESC];
|
||||
extern uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ];
|
||||
extern const uint8_t USBD_OtherSpeedCfgDesc[USB_LEN_CFG_DESC];
|
||||
extern const uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC];
|
||||
extern const uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID];
|
||||
extern const USBD_DEVICE USR_desc;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DESC_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length);
|
||||
uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length);
|
||||
uint8_t * USBD_USR_ManufacturerStrDescriptor ( uint8_t speed , uint16_t *length);
|
||||
uint8_t * USBD_USR_ProductStrDescriptor ( uint8_t speed , uint16_t *length);
|
||||
uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length);
|
||||
uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length);
|
||||
uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length);
|
||||
|
||||
#ifdef USB_SUPPORT_USER_STRING_DESC
|
||||
uint8_t * USBD_USR_USRStringDesc (uint8_t speed, uint8_t idx , uint16_t *length);
|
||||
#endif /* USB_SUPPORT_USER_STRING_DESC */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* __USBD_DESC_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,479 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_hid_core.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 19-March-2012
|
||||
* @brief This file provides the HID core functions.
|
||||
*
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* HID Class Description
|
||||
* ===================================================================
|
||||
* This module manages the HID class V1.11 following the "Device Class Definition
|
||||
* for Human Interface Devices (HID) Version 1.11 Jun 27, 2001".
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - The Boot Interface Subclass
|
||||
* - The Mouse protocol
|
||||
* - Usage Page : Generic Desktop
|
||||
* - Usage : Joystick)
|
||||
* - Collection : Application
|
||||
*
|
||||
* @note In HS mode and when the DMA is used, all variables and data structures
|
||||
* dealing with the DMA during the transaction process should be 32-bit aligned.
|
||||
*
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "../Taranis/usbd_desc.h"
|
||||
#include "usbd_hid_core.h"
|
||||
#include "usbd_req.h"
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_HID
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_HID_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_HID_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_HID_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_HID_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
static uint8_t USBD_HID_Init (void *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_HID_DeInit (void *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_HID_Setup (void *pdev,
|
||||
USB_SETUP_REQ *req);
|
||||
|
||||
static const uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length);
|
||||
|
||||
static uint8_t USBD_HID_DataIn (void *pdev, uint8_t epnum);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
/*
|
||||
This USB HID endpoint report description defines a device with:
|
||||
* 8 digital buttons
|
||||
* 8 analog axes with 8bit resolution
|
||||
|
||||
Repot packet described as C struct is:
|
||||
|
||||
struct {
|
||||
uint8_t buttons; //bit 0 - button 1, bit 1 - button 2, ..., mapped to channels 9-16, on if channel > 0
|
||||
uint8_t X; //analog value, mapped to channel 1
|
||||
uint8_t Y; //analog value, mapped to channel 2
|
||||
uint8_t Z; //analog value, mapped to channel 3
|
||||
uint8_t Rx; //analog value, mapped to channel 4
|
||||
uint8_t Ry //analog value, mapped to channel 5
|
||||
uint8_t Rz; //analog value, mapped to channel 6
|
||||
uint8_t S1; //analog value, mapped to channel 7
|
||||
uint8_t S2; //analog value, mapped to channel 8
|
||||
}
|
||||
*/
|
||||
__ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END =
|
||||
{
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x05, // USAGE (Game Pad)
|
||||
0xa1, 0x01, // COLLECTION (Application)
|
||||
0xa1, 0x00, // COLLECTION (Physical)
|
||||
0x05, 0x09, // USAGE_PAGE (Button)
|
||||
0x19, 0x01, // USAGE_MINIMUM (Button 1)
|
||||
0x29, 0x08, // USAGE_MAXIMUM (Button 8)
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
||||
0x95, 0x08, // REPORT_COUNT (8)
|
||||
0x75, 0x01, // REPORT_SIZE (1)
|
||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x30, // USAGE (X)
|
||||
0x09, 0x31, // USAGE (Y)
|
||||
0x09, 0x32, // USAGE (Z)
|
||||
0x09, 0x33, // USAGE (Rx)
|
||||
0x09, 0x34, // USAGE (Ry)
|
||||
0x09, 0x35, // USAGE (Rz)
|
||||
0x09, 0x36, // USAGE (Slider)
|
||||
0x09, 0x36, // USAGE (Slider)
|
||||
0x15, 0x81, // LOGICAL_MINIMUM (-127)
|
||||
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
|
||||
0x75, 0x08, // REPORT_SIZE (8)
|
||||
0x95, 0x08, // REPORT_COUNT (8)
|
||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
0xc0, // END_COLLECTION
|
||||
0xc0 // END_COLLECTION
|
||||
};
|
||||
|
||||
|
||||
/** @defgroup USBD_HID_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
const USBD_Class_cb_TypeDef USBD_HID_cb =
|
||||
{
|
||||
USBD_HID_Init,
|
||||
USBD_HID_DeInit,
|
||||
USBD_HID_Setup,
|
||||
NULL, /*EP0_TxSent*/
|
||||
NULL, /*EP0_RxReady*/
|
||||
USBD_HID_DataIn, /*DataIn*/
|
||||
NULL, /*DataOut*/
|
||||
NULL, /*SOF */
|
||||
NULL,
|
||||
NULL,
|
||||
USBD_HID_GetCfgDesc,
|
||||
#ifdef USB_OTG_HS_CORE
|
||||
USBD_HID_GetCfgDesc, /* use same config as per FS */
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
__ALIGN_BEGIN static uint32_t USBD_HID_AltSet __ALIGN_END = 0;
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
__ALIGN_BEGIN static uint32_t USBD_HID_Protocol __ALIGN_END = 0;
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
__ALIGN_BEGIN static uint32_t USBD_HID_IdleState __ALIGN_END = 0;
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
/* USB HID device Configuration Descriptor */
|
||||
__ALIGN_BEGIN static const uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
|
||||
USB_HID_CONFIG_DESC_SIZ,
|
||||
/* wTotalLength: Bytes returned */
|
||||
0x00,
|
||||
0x01, /*bNumInterfaces: 1 interface*/
|
||||
0x01, /*bConfigurationValue: Configuration value*/
|
||||
0x00, /*iConfiguration: Index of string descriptor describing
|
||||
the configuration*/
|
||||
0xE0, /*bmAttributes: bus powered and Support Remote Wake-up */
|
||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
||||
|
||||
/************** Descriptor of Joystick Mouse interface ****************/
|
||||
/* 09 */
|
||||
0x09, /*bLength: Interface Descriptor size*/
|
||||
USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/
|
||||
0x00, /*bInterfaceNumber: Number of Interface*/
|
||||
0x00, /*bAlternateSetting: Alternate setting*/
|
||||
0x01, /*bNumEndpoints*/
|
||||
0x03, /*bInterfaceClass: HID*/
|
||||
0x00 /*0x01*/, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
|
||||
0x00 /*0x02*/, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
|
||||
0, /*iInterface: Index of string descriptor*/
|
||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
||||
/* 18 */
|
||||
0x09, /*bLength: HID Descriptor size*/
|
||||
HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
|
||||
0x11, /*bcdHID: HID Class Spec release number*/
|
||||
0x01,
|
||||
0x00, /*bCountryCode: Hardware target country*/
|
||||
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
|
||||
0x22, /*bDescriptorType*/
|
||||
sizeof(HID_JOYSTICK_ReportDesc),/*wItemLength: Total length of Report descriptor*/
|
||||
0x00,
|
||||
/******************** Descriptor of Mouse endpoint ********************/
|
||||
/* 27 */
|
||||
0x07, /*bLength: Endpoint Descriptor size*/
|
||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
|
||||
|
||||
HID_IN_EP, /*bEndpointAddress: Endpoint Address (IN)*/
|
||||
0x03, /*bmAttributes: Interrupt endpoint*/
|
||||
HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */
|
||||
0x00,
|
||||
0x0A, /*bInterval: Polling Interval (10 ms)*/
|
||||
/* 34 */
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
static uint8_t ReportSent;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_HID_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_HID_Init
|
||||
* Initialize the HID interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_Init (void *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
|
||||
/* Open EP IN */
|
||||
DCD_EP_Open(pdev,
|
||||
HID_IN_EP,
|
||||
HID_IN_PACKET,
|
||||
USB_OTG_EP_INT);
|
||||
|
||||
/* Open EP OUT */
|
||||
DCD_EP_Open(pdev,
|
||||
HID_OUT_EP,
|
||||
HID_OUT_PACKET,
|
||||
USB_OTG_EP_INT);
|
||||
|
||||
ReportSent = 1;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_HID_Init
|
||||
* DeInitialize the HID layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_DeInit (void *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
/* Close HID EPs */
|
||||
DCD_EP_Close (pdev , HID_IN_EP);
|
||||
DCD_EP_Close (pdev , HID_OUT_EP);
|
||||
|
||||
ReportSent = 1;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_HID_Setup
|
||||
* Handle the HID specific requests
|
||||
* @param pdev: instance
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_Setup (void *pdev,
|
||||
USB_SETUP_REQ *req)
|
||||
{
|
||||
uint16_t len = 0;
|
||||
const uint8_t *pbuf = NULL;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
|
||||
|
||||
case HID_REQ_SET_PROTOCOL:
|
||||
USBD_HID_Protocol = (uint8_t)(req->wValue);
|
||||
break;
|
||||
|
||||
case HID_REQ_GET_PROTOCOL:
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&USBD_HID_Protocol,
|
||||
1);
|
||||
break;
|
||||
|
||||
case HID_REQ_SET_IDLE:
|
||||
USBD_HID_IdleState = (uint8_t)(req->wValue >> 8);
|
||||
break;
|
||||
|
||||
case HID_REQ_GET_IDLE:
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&USBD_HID_IdleState,
|
||||
1);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
return USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if( req->wValue >> 8 == HID_REPORT_DESC)
|
||||
{
|
||||
len = MIN(sizeof(HID_JOYSTICK_ReportDesc) , req->wLength);
|
||||
pbuf = HID_JOYSTICK_ReportDesc; // wiiccReportDescriptor; //
|
||||
}
|
||||
else if( req->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
|
||||
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
|
||||
pbuf = USBD_HID_Desc;
|
||||
#else
|
||||
pbuf = USBD_HID_CfgDesc + 0x12;
|
||||
#endif
|
||||
len = MIN(USB_HID_DESC_SIZ , req->wLength);
|
||||
}
|
||||
|
||||
USBD_CtlSendData (pdev,
|
||||
pbuf,
|
||||
len);
|
||||
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&USBD_HID_AltSet,
|
||||
1);
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
USBD_HID_AltSet = (uint8_t)(req->wValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_HID_SendReport
|
||||
* Send HID Report
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to report
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_HID_SendReport (USB_OTG_CORE_HANDLE *pdev,
|
||||
uint8_t *report,
|
||||
uint16_t len)
|
||||
{
|
||||
if (pdev->dev.device_status == USB_OTG_CONFIGURED )
|
||||
{
|
||||
if ( ReportSent )
|
||||
{
|
||||
ReportSent = 0;
|
||||
DCD_EP_Tx (pdev, HID_IN_EP, report, len);
|
||||
}
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_HID_GetCfgDesc
|
||||
* return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static const uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_HID_CfgDesc);
|
||||
return USBD_HID_CfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_HID_DataIn
|
||||
* handle data IN Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_DataIn (void *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
ReportSent = 1;
|
||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
||||
be caused by a new transfer before the end of the previous transfer */
|
||||
DCD_EP_Flush(pdev, HID_IN_EP);
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@@ -0,0 +1,811 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_storage_msd.c
|
||||
* @author MCD application Team
|
||||
* @version V1.1.0
|
||||
* @date 19-March-2012
|
||||
* @brief This file provides the disk operations functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "../../opentx.h"
|
||||
#include "../../thirdparty/FatFs/diskio.h"
|
||||
#include "../Taranis/board_taranis.h"
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "usbd_msc_mem.h"
|
||||
#include "../Taranis/usb_conf.h"
|
||||
|
||||
#if defined(BOOT)
|
||||
#define STORAGE_LUN_NBR 2
|
||||
#else
|
||||
/* SD card only when not running bootloader */
|
||||
#define STORAGE_LUN_NBR 1
|
||||
#endif
|
||||
#define BLOCKSIZE 512
|
||||
|
||||
/* USB Mass storage Standard Inquiry Data */
|
||||
const unsigned char STORAGE_Inquirydata[] = {//36
|
||||
|
||||
/* LUN 0 */
|
||||
0x00,
|
||||
0x80,
|
||||
0x02,
|
||||
0x02,
|
||||
(USBD_STD_INQUIRY_LENGTH - 5),
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
'F', 'r', 'S', 'k', 'y', ' ', ' ', ' ', /* Manufacturer : 8 bytes */
|
||||
'T', 'a', 'r', 'a', 'n', 'i', 's', ' ', /* Product : 16 Bytes */
|
||||
'R', 'a', 'd', 'i', 'o', ' ', ' ', ' ',
|
||||
'1', '.', '0', '0', /* Version : 4 Bytes */
|
||||
#if defined(BOOT)
|
||||
/* LUN 1 */
|
||||
0x00,
|
||||
0x80,
|
||||
0x02,
|
||||
0x02,
|
||||
(USBD_STD_INQUIRY_LENGTH - 5),
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
'F', 'r', 'S', 'k', 'y', ' ', ' ', ' ', /* Manufacturer : 8 bytes */
|
||||
'T', 'a', 'r', 'a', 'n', 'i', 's', ' ', /* Product : 16 Bytes */
|
||||
'R', 'a', 'd', 'i', 'o', ' ', ' ', ' ',
|
||||
'1', '.', '0' ,'0', /* Version : 4 Bytes */
|
||||
#endif
|
||||
};
|
||||
|
||||
#if defined(BOOT)
|
||||
int32_t fat12Write( const uint8_t *buffer, uint16_t sector, uint16_t count ) ;
|
||||
int32_t fat12Read( uint8_t *buffer, uint16_t sector, uint16_t count ) ;
|
||||
#endif
|
||||
|
||||
int8_t STORAGE_Init (uint8_t lun);
|
||||
|
||||
int8_t STORAGE_GetCapacity (uint8_t lun,
|
||||
uint32_t *block_num,
|
||||
uint32_t *block_size);
|
||||
|
||||
int8_t STORAGE_IsReady (uint8_t lun);
|
||||
|
||||
int8_t STORAGE_IsWriteProtected (uint8_t lun);
|
||||
|
||||
int8_t STORAGE_Read (uint8_t lun,
|
||||
uint8_t *buf,
|
||||
uint32_t blk_addr,
|
||||
uint16_t blk_len);
|
||||
|
||||
int8_t STORAGE_Write (uint8_t lun,
|
||||
uint8_t *buf,
|
||||
uint32_t blk_addr,
|
||||
uint16_t blk_len);
|
||||
|
||||
int8_t STORAGE_GetMaxLun (void);
|
||||
|
||||
USBD_STORAGE_cb_TypeDef USBD_MICRO_SDIO_fops =
|
||||
{
|
||||
STORAGE_Init,
|
||||
STORAGE_GetCapacity,
|
||||
STORAGE_IsReady,
|
||||
STORAGE_IsWriteProtected,
|
||||
STORAGE_Read,
|
||||
STORAGE_Write,
|
||||
STORAGE_GetMaxLun,
|
||||
(int8_t *)STORAGE_Inquirydata,
|
||||
};
|
||||
|
||||
USBD_STORAGE_cb_TypeDef *USBD_STORAGE_fops = &USBD_MICRO_SDIO_fops;
|
||||
|
||||
__IO uint32_t count = 0;
|
||||
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
}
|
||||
#endif
|
||||
|
||||
int8_t STORAGE_Init (uint8_t lun)
|
||||
{
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
/* TODO if no SD ... if( SD_Init() != 0)
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief return medium capacity and block size
|
||||
* @param lun : logical unit number
|
||||
* @param block_num : number of physical block
|
||||
* @param block_size : size of a physical block
|
||||
* @retval Status
|
||||
*/
|
||||
int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_size)
|
||||
{
|
||||
#if defined(BOOT)
|
||||
if (lun == 1) {
|
||||
*block_size = BLOCKSIZE;
|
||||
*block_num = 3 + EESIZE/BLOCKSIZE + FLASHSIZE/BLOCKSIZE;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (!SD_CARD_PRESENT())
|
||||
return -1;
|
||||
|
||||
*block_size = BLOCKSIZE;
|
||||
|
||||
static DWORD sector_count = 0;
|
||||
if (sector_count == 0) {
|
||||
if (disk_ioctl(0, GET_SECTOR_COUNT, §or_count) != RES_OK) {
|
||||
sector_count = 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
*block_num = sector_count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(BOOT)
|
||||
uint8_t lunReady[2] ;
|
||||
#else
|
||||
uint8_t lunReady[1] ;
|
||||
#endif
|
||||
|
||||
void usbPluggedIn()
|
||||
{
|
||||
if (lunReady[0] == 0) {
|
||||
lunReady[0] = 1;
|
||||
}
|
||||
#if defined(BOOT)
|
||||
if (lunReady[1] == 0) {
|
||||
lunReady[1] = 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief check whether the medium is ready
|
||||
* @param lun : logical unit number
|
||||
* @retval Status
|
||||
*/
|
||||
int8_t STORAGE_IsReady (uint8_t lun)
|
||||
{
|
||||
#if defined(BOOT)
|
||||
if (lun == 1) {
|
||||
if (lunReady[1] == 0) {
|
||||
return -1 ;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (lunReady[0] == 0) {
|
||||
return -1 ;
|
||||
}
|
||||
return SD_CARD_PRESENT() ? 0 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief check whether the medium is write-protected
|
||||
* @param lun : logical unit number
|
||||
* @retval Status
|
||||
*/
|
||||
int8_t STORAGE_IsWriteProtected (uint8_t lun)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read data from the medium
|
||||
* @param lun : logical unit number
|
||||
* @param buf : Pointer to the buffer to save data
|
||||
* @param blk_addr : address of 1st block to be read
|
||||
* @param blk_len : nmber of blocks to be read
|
||||
* @retval Status
|
||||
*/
|
||||
|
||||
int8_t SD_ReadSectors(uint8_t *buff, uint32_t sector, uint32_t count);
|
||||
|
||||
int8_t STORAGE_Read (uint8_t lun,
|
||||
uint8_t *buf,
|
||||
uint32_t blk_addr,
|
||||
uint16_t blk_len)
|
||||
{
|
||||
#if defined(BOOT)
|
||||
if (lun == 1) {
|
||||
if (fat12Read(buf, blk_addr, blk_len) != 0)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (SD_ReadSectors(buf, blk_addr, blk_len) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* @brief Write data to the medium
|
||||
* @param lun : logical unit number
|
||||
* @param buf : Pointer to the buffer to write from
|
||||
* @param blk_addr : address of 1st block to be written
|
||||
* @param blk_len : nmber of blocks to be read
|
||||
* @retval Status
|
||||
*/
|
||||
|
||||
int8_t SD_WriteSectors(const uint8_t *buf, uint32_t sector, uint32_t count);
|
||||
|
||||
int8_t STORAGE_Write (uint8_t lun,
|
||||
uint8_t *buf,
|
||||
uint32_t blk_addr,
|
||||
uint16_t blk_len)
|
||||
{
|
||||
#if defined(BOOT)
|
||||
if (lun == 1) {
|
||||
if (fat12Write(buf, blk_addr, blk_len) != 0)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (SD_WriteSectors(buf, blk_addr, blk_len) != 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return number of supported logical unit
|
||||
* @param None
|
||||
* @retval number of logical unit
|
||||
*/
|
||||
|
||||
int8_t STORAGE_GetMaxLun (void)
|
||||
{
|
||||
return STORAGE_LUN_NBR - 1;
|
||||
}
|
||||
|
||||
#if defined(BOOT)
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
* FAT12 boot sector partition.
|
||||
*/
|
||||
const char g_FATboot[BLOCKSIZE] =
|
||||
{
|
||||
0xeb, 0x3c, 0x90, // Jump instruction.
|
||||
0x39, 0x58, 0x20, 0x54, 0x45, 0x41, 0x4D, 0x00, // OEM Name
|
||||
0x00, 0x02, // Bytes per sector
|
||||
0x08, // Sectors per FS cluster.
|
||||
0x01, 0x00, // Reserved sector count
|
||||
|
||||
0x01, // Number of FATs
|
||||
0x10, 0x00, // Number of root directory entries
|
||||
3+(EESIZE/BLOCKSIZE), (FLASHSIZE/BLOCKSIZE)>>8, // Total sectors
|
||||
0xf8, // Media descriptor
|
||||
0x01, 0x00, // Sectors per FAT table
|
||||
0x20, 0x00, // Sectors per track
|
||||
0x40, 0x00, // Number of heads
|
||||
0x00, 0x00, 0x00, 0x00, // Number of hidden sectors
|
||||
|
||||
0x00, 0x00, 0x00, 0x00, // Large number of sectors.
|
||||
0x00, // Physical drive number
|
||||
0x00, // Reserved
|
||||
0x29, // Extended boot signature
|
||||
0xCE, 0xFA, 0x5C, 0xD1, // Disk ID (serial number)
|
||||
0x56, 0x49, 0x52, 0x54, 0x46, 0x53, 0x20, 0x20, 0x20, 0x20, 0x20, // Volume label
|
||||
0x46, 0x41, 0x54, 0x31, 0x32, 0x20, 0x20, 0x20, // FAT file system type
|
||||
0x00, 0x00, // OS boot code
|
||||
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
|
||||
};
|
||||
|
||||
#if defined(REV4a)
|
||||
const char g_FAT[BLOCKSIZE] =
|
||||
{
|
||||
0xF8, 0xFF, 0xFF, 0x03, 0x40, 0x00, 0x05, 0x60, 0x00, 0x07, 0x80, 0x00, 0x09, 0xA0, 0x00, 0x0B,
|
||||
0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x0F, 0x00, 0x01, 0x11, 0xF0, 0xFF, 0x13, 0x40, 0x01, 0x15, 0x60,
|
||||
0x01, 0x17, 0x80, 0x01, 0x19, 0xA0, 0x01, 0x1B, 0xC0, 0x01, 0x1D, 0xE0, 0x01, 0x1F, 0x00, 0x02,
|
||||
0x21, 0x20, 0x02, 0x23, 0x40, 0x02, 0x25, 0x60, 0x02, 0x27, 0x80, 0x02, 0x29, 0xA0, 0x02, 0x2B,
|
||||
0xC0, 0x02, 0x2D, 0xE0, 0x02, 0x2F, 0x00, 0x03, 0x31, 0x20, 0x03, 0x33, 0x40, 0x03, 0x35, 0x60,
|
||||
0x03, 0x37, 0x80, 0x03, 0x39, 0xA0, 0x03, 0x3B, 0xC0, 0x03, 0x3D, 0xE0, 0x03, 0x3F, 0x00, 0x04,
|
||||
0x41, 0x20, 0x04, 0x43, 0x40, 0x04, 0x45, 0x60, 0x04, 0x47, 0x80, 0x04, 0x49, 0xA0, 0x04, 0x4B,
|
||||
0xC0, 0x04, 0x4D, 0xE0, 0x04, 0x4F, 0x00, 0x05, 0x51, 0x20, 0x05, 0x53, 0x40, 0x05, 0x55, 0x60,
|
||||
0x05, 0x57, 0x80, 0x05, 0x59, 0xA0, 0x05, 0x5B, 0xC0, 0x05, 0x5D, 0xE0, 0x05, 0x5F, 0x00, 0x06,
|
||||
0x61, 0x20, 0x06, 0x63, 0x40, 0x06, 0x65, 0x60, 0x06, 0x67, 0x80, 0x06, 0x69, 0xA0, 0x06, 0x6B,
|
||||
0xC0, 0x06, 0x6D, 0xE0, 0x06, 0x6F, 0x00, 0x07, 0x71, 0x20, 0x07, 0x73, 0x40, 0x07, 0x75, 0x60,
|
||||
0x07, 0x77, 0x80, 0x07, 0x79, 0xA0, 0x07, 0x7B, 0xC0, 0x07, 0x7D, 0xE0, 0x07, 0x7F, 0x00, 0x08,
|
||||
0x81, 0x20, 0x08, 0x83, 0x40, 0x08, 0x85, 0x60, 0x08, 0x87, 0x80, 0x08, 0x89, 0xA0, 0x08, 0x8B,
|
||||
0xC0, 0x08, 0x8D, 0xE0, 0x08, 0x8F, 0x00, 0x09, 0x91, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
#else
|
||||
const char g_FAT[BLOCKSIZE] =
|
||||
{
|
||||
0xF8, 0xFF, 0xFF, 0x03, 0x40, 0x00, 0x05, 0x60, 0x00, 0x07, 0x80, 0x00, 0x09, 0xF0, 0xFF, 0x0B,
|
||||
0xC0, 0x00, 0x0D, 0xE0, 0x00, 0x0F, 0x00, 0x01, 0x11, 0x20, 0x01, 0x13, 0x40, 0x01, 0x15, 0x60,
|
||||
0x01, 0x17, 0x80, 0x01, 0x19, 0xA0, 0x01, 0x1B, 0xC0, 0x01, 0x1D, 0xE0, 0x01, 0x1F, 0x00, 0x02,
|
||||
0x21, 0x20, 0x02, 0x23, 0x40, 0x02, 0x25, 0x60, 0x02, 0x27, 0x80, 0x02, 0x29, 0xA0, 0x02, 0x2B,
|
||||
0xC0, 0x02, 0x2D, 0xE0, 0x02, 0x2F, 0x00, 0x03, 0x31, 0x20, 0x03, 0x33, 0x40, 0x03, 0x35, 0x60,
|
||||
0x03, 0x37, 0x80, 0x03, 0x39, 0xA0, 0x03, 0x3B, 0xC0, 0x03, 0x3D, 0xE0, 0x03, 0x3F, 0x00, 0x04,
|
||||
0x41, 0x20, 0x04, 0x43, 0x40, 0x04, 0x45, 0x60, 0x04, 0x47, 0x80, 0x04, 0x49, 0xA0, 0x04, 0x4B,
|
||||
0xC0, 0x04, 0x4D, 0xE0, 0x04, 0x4F, 0x00, 0x05, 0x51, 0x20, 0x05, 0x53, 0x40, 0x05, 0x55, 0x60,
|
||||
0x05, 0x57, 0x80, 0x05, 0x59, 0xA0, 0x05, 0x5B, 0xC0, 0x05, 0x5D, 0xE0, 0x05, 0x5F, 0x00, 0x06,
|
||||
0x61, 0x20, 0x06, 0x63, 0x40, 0x06, 0x65, 0x60, 0x06, 0x67, 0x80, 0x06, 0x69, 0xA0, 0x06, 0x6B,
|
||||
0xC0, 0x06, 0x6D, 0xE0, 0x06, 0x6F, 0x00, 0x07, 0x71, 0x20, 0x07, 0x73, 0x40, 0x07, 0x75, 0x60,
|
||||
0x07, 0x77, 0x80, 0x07, 0x79, 0xA0, 0x07, 0x7B, 0xC0, 0x07, 0x7D, 0xE0, 0x07, 0x7F, 0x00, 0x08,
|
||||
0x81, 0x20, 0x08, 0x83, 0x40, 0x08, 0x85, 0x60, 0x08, 0x87, 0x80, 0x08, 0x89, 0xF0, 0xFF, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
#endif
|
||||
|
||||
// File Attributes
|
||||
// 0 0x01 Read Only.
|
||||
// 1 0x02 Hidden.
|
||||
// 2 0x04 System.
|
||||
// 3 0x08 Volume Label.
|
||||
// 4 0x10 Subdirectory.
|
||||
// 5 0x20 Archive.
|
||||
// 6 0x40 Device.
|
||||
// 7 0x80 Reserved.
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t name[8];
|
||||
uint8_t ext[3];
|
||||
uint8_t attribute;
|
||||
uint8_t reserved;
|
||||
uint8_t create_time_ms;
|
||||
uint16_t create_time;
|
||||
uint16_t create_date;
|
||||
uint16_t access_date;
|
||||
uint16_t ea_index;
|
||||
uint16_t modify_time;
|
||||
uint16_t modify_date;
|
||||
uint16_t start_cluster;
|
||||
uint32_t file_size;
|
||||
} FATDirEntry_t;
|
||||
|
||||
// First 16 FAT root directory entries (1 sector)
|
||||
const FATDirEntry_t g_DIRroot[16] =
|
||||
{
|
||||
{
|
||||
{ 'T', 'A', 'R', 'A', 'N', 'I', 'S', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x08, // Volume
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
{
|
||||
{ 'E', 'E', 'P', 'R', 'O', 'M', ' ', ' '},
|
||||
{ 'B', 'I', 'N'},
|
||||
0x20, // Archive
|
||||
0x00,
|
||||
0x3E,
|
||||
0xA301,
|
||||
0x3D55,
|
||||
0x3D55,
|
||||
0x0000,
|
||||
0xA302,
|
||||
0x3D55,
|
||||
0x0002,
|
||||
EESIZE
|
||||
},
|
||||
{
|
||||
{ 'F', 'I', 'R', 'M', 'W', 'A', 'R', 'E'},
|
||||
{ 'B', 'I', 'N'},
|
||||
0x20, // Archive
|
||||
0x00,
|
||||
0x3E,
|
||||
0xA301,
|
||||
0x3D55,
|
||||
0x3D55,
|
||||
0x0000,
|
||||
0xA302,
|
||||
0x3D55,
|
||||
0x0002 + (EESIZE/BLOCKSIZE)/8,
|
||||
FLASHSIZE
|
||||
},
|
||||
{
|
||||
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
{
|
||||
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
{
|
||||
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
{
|
||||
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
{
|
||||
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
{
|
||||
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
{
|
||||
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
{
|
||||
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
{
|
||||
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
{
|
||||
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
{
|
||||
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
{
|
||||
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
{
|
||||
{ '\x00', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
|
||||
{ ' ', ' ', ' '},
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x0000,
|
||||
0x00000000
|
||||
},
|
||||
};
|
||||
|
||||
// count is number of 512 byte sectors
|
||||
int32_t fat12Read( uint8_t *buffer, uint16_t sector, uint16_t count )
|
||||
{
|
||||
while ( count )
|
||||
{
|
||||
if (sector == 0) {
|
||||
memcpy(buffer, g_FATboot, BLOCKSIZE ) ;
|
||||
}
|
||||
else if (sector == 1/*Reserved sector count*/) {
|
||||
// FAT table.
|
||||
memcpy(buffer, g_FAT, BLOCKSIZE);
|
||||
}
|
||||
else if (sector == 2) {
|
||||
memcpy(buffer, g_DIRroot, BLOCKSIZE ) ;
|
||||
}
|
||||
else if (sector < 3 + (EESIZE/BLOCKSIZE)) {
|
||||
eepromReadBlock(buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE);
|
||||
}
|
||||
else if (sector < 3 + (EESIZE/BLOCKSIZE) + (FLASHSIZE/BLOCKSIZE)) {
|
||||
uint32_t address;
|
||||
address = sector - 3 - (EESIZE/BLOCKSIZE);
|
||||
address *= BLOCKSIZE;
|
||||
address += FIRMWARE_ADDRESS;
|
||||
memcpy(buffer, (uint8_t *)address, BLOCKSIZE);
|
||||
}
|
||||
buffer += BLOCKSIZE ;
|
||||
sector++ ;
|
||||
count-- ;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint16_t count)
|
||||
{
|
||||
enum FatWriteOperation {
|
||||
FATWRITE_NONE,
|
||||
FATWRITE_EEPROM,
|
||||
FATWRITE_FIRMWARE
|
||||
};
|
||||
|
||||
static unsigned int operation = FATWRITE_NONE;
|
||||
|
||||
TRACE("FAT12 Write(sector=%d, count=%d)", sector, count);
|
||||
|
||||
if (sector < 3) {
|
||||
// reserved, read-only
|
||||
}
|
||||
else if (sector < 3 + (EESIZE/BLOCKSIZE)) {
|
||||
// eeprom
|
||||
while (count) {
|
||||
if (operation == FATWRITE_NONE && isEepromStart(buffer)) {
|
||||
TRACE("EEPROM start found in sector %d", sector);
|
||||
operation = FATWRITE_EEPROM;
|
||||
}
|
||||
if (operation == FATWRITE_EEPROM) {
|
||||
eepromWriteBlock((uint8_t *)buffer, (sector-3)*BLOCKSIZE, BLOCKSIZE);
|
||||
}
|
||||
buffer += BLOCKSIZE;
|
||||
sector++;
|
||||
count--;
|
||||
if (sector-3 >= (EESIZE/BLOCKSIZE)) {
|
||||
TRACE("EEPROM end written at sector %d", sector-1);
|
||||
operation = FATWRITE_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (sector < 3 + (EESIZE/BLOCKSIZE) + (FLASHSIZE/BLOCKSIZE)) {
|
||||
// firmware
|
||||
uint32_t address;
|
||||
address = sector - 3 - (EESIZE/BLOCKSIZE);
|
||||
address *= BLOCKSIZE;
|
||||
address += FIRMWARE_ADDRESS;
|
||||
while (count) {
|
||||
for (uint32_t i=0; i<BLOCKSIZE/FLASH_PAGESIZE; i++) {
|
||||
if (address >= FIRMWARE_ADDRESS+BOOTLOADER_SIZE/*protect bootloader*/ && address <= FIRMWARE_ADDRESS+FLASHSIZE-FLASH_PAGESIZE) {
|
||||
if (address == FIRMWARE_ADDRESS+BOOTLOADER_SIZE && isFirmwareStart(buffer)) {
|
||||
TRACE("FIRMWARE start found in sector %d", sector);
|
||||
operation = FATWRITE_FIRMWARE;
|
||||
}
|
||||
if (operation == FATWRITE_FIRMWARE) {
|
||||
writeFlash((uint32_t *)address, (uint32_t *)buffer);
|
||||
}
|
||||
}
|
||||
address += FLASH_PAGESIZE;
|
||||
buffer += FLASH_PAGESIZE;
|
||||
}
|
||||
sector++;
|
||||
count--;
|
||||
if (sector-3-(EESIZE/BLOCKSIZE) >= (FLASHSIZE/BLOCKSIZE)) {
|
||||
TRACE("FIRMWARE end written at sector %d", sector-1);
|
||||
operation = FATWRITE_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_usr.c
|
||||
* @author MCD Application Team
|
||||
* @version V1.1.0
|
||||
* @date 19-March-2012
|
||||
* @brief This file includes the user application layer
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "../../opentx.h"
|
||||
|
||||
extern "C" {
|
||||
#include "usbd_usr.h"
|
||||
|
||||
/* Points to the DEVICE_PROP structure of current device */
|
||||
/* The purpose of this register is to speed up the execution */
|
||||
|
||||
|
||||
const USBD_Usr_cb_TypeDef USR_cb =
|
||||
{
|
||||
USBD_USR_Init,
|
||||
USBD_USR_DeviceReset,
|
||||
USBD_USR_DeviceConfigured,
|
||||
USBD_USR_DeviceSuspended,
|
||||
USBD_USR_DeviceResumed,
|
||||
|
||||
USBD_USR_DeviceConnected,
|
||||
USBD_USR_DeviceDisconnected,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Whatever the user application needs to do when USB is initialised
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_USR_Init(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Displays the message on LCD on device reset event
|
||||
* @param speed : device speed
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_USR_DeviceReset (uint8_t speed)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Displays the message on LCD on device config event
|
||||
* @param None
|
||||
* @retval Staus
|
||||
*/
|
||||
void USBD_USR_DeviceConfigured (void)
|
||||
{
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief Displays the message on LCD on device suspend event
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_USR_DeviceSuspended(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Displays the message on LCD on device resume event
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_USR_DeviceResumed(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_DeviceConnected
|
||||
* Displays the message on LCD on device connection Event
|
||||
* @param None
|
||||
* @retval Staus
|
||||
*/
|
||||
void USBD_USR_DeviceConnected (void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_USR_DeviceDisonnected
|
||||
* Displays the message on LCD on device disconnection Event
|
||||
* @param None
|
||||
* @retval Staus
|
||||
*/
|
||||
void USBD_USR_DeviceDisconnected (void)
|
||||
{
|
||||
#if !defined(BOOT) && defined(USB_MASS_STORAGE)
|
||||
NVIC_SystemReset();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
Reference in New Issue
Block a user