Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
max1168_arch.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2010 Antoine Drouin <poinix@gmail.com>
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
24 #ifndef MAX1168_ARCH_H
25 #define MAX1168_ARCH_H
26 
27 /*
28  * max1168 analog to digital converter
29  * connected on spi2
30  * select on PB12
31  * drdy on PD2
32  */
33 #include <stm32/gpio.h>
34 
35 #define Max1168Unselect() GPIOB->BSRR = GPIO_Pin_12
36 #define Max1168Select() GPIOB->BRR = GPIO_Pin_12
37 
38 #define Max1168OnDmaIrq() { \
39  /* ASSERT((max1168_status == STA_MAX1168_READING_RES), \
40  * DEBUG_MAX_1168, MAX1168_ERR_SPURIOUS_DMA_IRQ); \
41  */ \
42  Max1168Unselect(); \
43  DMA_ITConfig(DMA1_Channel4, DMA_IT_TC, DISABLE); \
44  /* Disable SPI_2 Rx and TX request */ \
45  SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Rx, DISABLE); \
46  SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Tx, DISABLE); \
47  /* Disable DMA1 Channel4 and 5 */ \
48  DMA_Cmd(DMA1_Channel4, DISABLE); \
49  DMA_Cmd(DMA1_Channel5, DISABLE); \
50  \
51  max1168_status = STA_MAX1168_DATA_AVAILABLE; \
52  }
53 
54 
55 #define Max1168ConfigureSPI() { \
56  SPI_InitTypeDef SPI_InitStructure; \
57  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; \
58  SPI_InitStructure.SPI_Mode = SPI_Mode_Master; \
59  SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; \
60  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; \
61  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; \
62  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; \
63  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16; \
64  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; \
65  SPI_InitStructure.SPI_CRCPolynomial = 7; \
66  SPI_Init(SPI2, &SPI_InitStructure); \
67  }
68 
69 #endif /* MAX1168_ARCH_H */