[Horus] Mouse analogs
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
@@ -105,23 +105,29 @@ void adcInit()
|
||||
{
|
||||
ADS7952_Init();
|
||||
|
||||
configure_pins(ADC_GPIO_PIN_MOUSE1 | ADC_GPIO_PIN_MOUSE2, PIN_ANALOG | PIN_PORTF);
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = ADC_GPIO_PIN_MOUSE1 | ADC_GPIO_PIN_MOUSE2;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(ADC_GPIO_MOUSE, &GPIO_InitStructure);
|
||||
|
||||
ADC3->CR1 = ADC_CR1_SCAN;
|
||||
ADC3->CR2 = ADC_CR2_ADON | ADC_CR2_DMA | ADC_CR2_DDS;
|
||||
ADC3->SQR1 = (2-1) << 20; // NUMBER_ANALOG Channels
|
||||
ADC3->SQR2 = 0;
|
||||
ADC3->SQR3 = ADC_IN_MOUSE1 + (ADC_IN_MOUSE2<<5);
|
||||
ADC3->SMPR1 = SAMPTIME + (SAMPTIME<<3) + (SAMPTIME<<6) + (SAMPTIME<<9) + (SAMPTIME<<12)
|
||||
+ (SAMPTIME<<15) + (SAMPTIME<<18) + (SAMPTIME<<21) + (SAMPTIME<<24);
|
||||
ADC3->SMPR2 = SAMPTIME + (SAMPTIME<<3) + (SAMPTIME<<6) + (SAMPTIME<<9) + (SAMPTIME<<12)
|
||||
+ (SAMPTIME<<15) + (SAMPTIME<<18) + (SAMPTIME<<21) + (SAMPTIME<<24) + (SAMPTIME<<27);
|
||||
ADC3->SMPR1 = 0;
|
||||
ADC3->SMPR2 = 3 + (3<<3); // TODO SAMPTIME constant
|
||||
ADC->CCR = 0; // ADC_CCR_ADCPRE_0; Clock div 2
|
||||
|
||||
|
||||
// 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(&adcValues[MOUSE1]);
|
||||
DMA2_Stream1->FCR = DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0;
|
||||
ADC_DMA_Stream->CR = DMA_SxCR_PL | DMA_SxCR_CHSEL_1 | DMA_SxCR_MSIZE_0 | DMA_SxCR_PSIZE_0 | DMA_SxCR_MINC;
|
||||
ADC_DMA_Stream->PAR = CONVERT_PTR_UINT(&ADC3->DR);
|
||||
ADC_DMA_Stream->M0AR = CONVERT_PTR_UINT(&adcValues[MOUSE1]);
|
||||
ADC_DMA_Stream->NDTR = 2;
|
||||
ADC_DMA_Stream->FCR = DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0;
|
||||
}
|
||||
|
||||
const uint16_t adcCommands[MOUSE1+2] =
|
||||
@@ -172,7 +178,7 @@ uint32_t adcReadNextSPIChannel(uint8_t index)
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
ADC_CS_LOW();
|
||||
delay_01us(1);
|
||||
// command is changed to the next index for the last two readings
|
||||
// command is changed to the next index for the last two readings
|
||||
// (because the sampled data is lagging behind for two command cycles)
|
||||
uint16_t val = (0x0fff & SPIx_ReadWriteByte(adcCommands[(i>1) ? index+1 : index]));
|
||||
#if defined(JITTER_MEASURE)
|
||||
@@ -190,18 +196,18 @@ uint32_t adcReadNextSPIChannel(uint8_t index)
|
||||
|
||||
void adcOnChipReadStart()
|
||||
{
|
||||
DMA2_Stream1->CR &= ~DMA_SxCR_EN; // Disable DMA
|
||||
ADC_DMA_Stream->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->M0AR = CONVERT_PTR_UINT(&adcValues[MOUSE1]);
|
||||
DMA2_Stream1->NDTR = 2;
|
||||
DMA2_Stream1->CR |= DMA_SxCR_EN; // Enable DMA
|
||||
ADC_DMA->LIFCR = DMA_LIFCR_CTCIF0 | DMA_LIFCR_CHTIF0 |DMA_LIFCR_CTEIF0 | DMA_LIFCR_CDMEIF0 | DMA_LIFCR_CFEIF0 ; // Write ones to clear bits
|
||||
ADC_DMA_Stream->M0AR = CONVERT_PTR_UINT(&adcValues[MOUSE1]);
|
||||
ADC_DMA_Stream->NDTR = 2;
|
||||
ADC_DMA_Stream->CR |= DMA_SxCR_EN; // Enable DMA
|
||||
ADC3->CR2 |= (uint32_t)ADC_CR2_SWSTART;
|
||||
}
|
||||
|
||||
bool adcOnChipReadFinished()
|
||||
{
|
||||
return (DMA2->LISR & DMA_LISR_TCIF1);
|
||||
return (ADC_DMA->LISR & DMA_LISR_TCIF0);
|
||||
}
|
||||
|
||||
void adcRead()
|
||||
@@ -214,7 +220,7 @@ void adcRead()
|
||||
adcReadSPIDummy();
|
||||
for (uint32_t index=0; index<MOUSE1; index++) {
|
||||
adcValues[index] = adcReadNextSPIChannel(index);
|
||||
if (noInternalReads < 4 && adcOnChipReadFinished()) {
|
||||
if (noInternalReads < 4 && adcOnChipReadFinished()) {
|
||||
for (uint8_t x=0; x<NUMBER_ANALOG-MOUSE1; x++) {
|
||||
uint16_t val = adcValues[MOUSE1+x];
|
||||
#if defined(JITTER_MEASURE)
|
||||
|
||||
@@ -121,12 +121,15 @@
|
||||
#define ADC_SPI_PIN_MOSI GPIO_Pin_6
|
||||
#define ADC_SPI_PIN_MISO GPIO_Pin_5
|
||||
#define ADC_SPI_PinSource_SCK GPIO_PinSource2
|
||||
#define ADC_SPI_PinSource_MISO GPIO_PinSource5
|
||||
#define ADC_SPI_PinSource_MOSI GPIO_PinSource6
|
||||
#define ADC_GPIO_PIN_MOUSE1 GPIO_Pin_8 // PF.8 ADC3_IN6 J5 MOUSE_X
|
||||
#define ADC_GPIO_PIN_MOUSE2 GPIO_Pin_9 // PF.9 ADC3_IN7 J6 MOUSE_Y
|
||||
#define ADC_SPI_PinSource_MISO GPIO_PinSource5
|
||||
#define ADC_SPI_PinSource_MOSI GPIO_PinSource6
|
||||
#define ADC_GPIO_PIN_MOUSE1 GPIO_Pin_8 // PF.08 ADC3_IN6 J5 MOUSE_X
|
||||
#define ADC_GPIO_PIN_MOUSE2 GPIO_Pin_9 // PF.09 ADC3_IN7 J6 MOUSE_Y
|
||||
#define ADC_GPIO_MOUSE GPIOF
|
||||
#define ADC_IN_MOUSE1 6
|
||||
#define ADC_IN_MOUSE2 7
|
||||
#define ADC_DMA DMA2
|
||||
#define ADC_DMA_Stream DMA2_Stream0
|
||||
|
||||
// Power
|
||||
#define PWR_RCC_AHB1Periph RCC_AHB1Periph_GPIOJ
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @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 "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/inc/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****/
|
||||
Reference in New Issue
Block a user