1 | void pushbuttoninit(void)
|
2 | {
|
3 | GPIO_InitTypeDef GPIO_InitStructure;
|
4 | ADC_InitTypeDef ADC_InitStructure;
|
5 | DMA_InitTypeDef DMA_InitStructure;
|
6 | NVIC_InitTypeDef NVIC_InitStructure;
|
7 |
|
8 |
|
9 | // Read the ADC Value boundaries of the buttons from FRAM
|
10 | eeprom_read_buttonvals(&buttons);
|
11 |
|
12 | GPIO_InitStructure.GPIO_Pin = SETUPBUTTON_PIN;
|
13 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
14 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
15 | GPIO_Init(SETUPBUTTON_GPIO, &GPIO_InitStructure);
|
16 |
|
17 | ADCBuffer[0] = ADCBuffer[1] = 0;
|
18 |
|
19 | RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
|
20 |
|
21 | DMA_InitStructure.DMA_BufferSize = 2;
|
22 | DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
|
23 | DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
24 | DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADCBuffer;
|
25 | DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
|
26 | DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
27 | DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
|
28 | DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR;
|
29 | DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
|
30 | DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
31 | DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
|
32 | DMA_Init(DMA1_Channel1, &DMA_InitStructure);
|
33 |
|
34 | DMA_Cmd(DMA1_Channel1, ENABLE);
|
35 | DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, DISABLE);
|
36 | DMA_ITConfig(DMA1_Channel1, DMA_IT_HT, DISABLE);
|
37 | DMA_ITConfig(DMA1_Channel1, DMA_IT_TE, DISABLE);
|
38 |
|
39 | NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
|
40 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
|
41 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
42 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
43 | NVIC_Init(&NVIC_InitStructure);
|
44 |
|
45 | RCC_ADCCLKConfig(RCC_PCLK2_Div6);
|
46 |
|
47 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO | RCC_APB2Periph_ADC1, ENABLE);
|
48 |
|
49 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
|
50 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
51 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
52 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
53 |
|
54 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
|
55 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
56 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
57 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
58 |
|
59 | ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
|
60 | ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
61 | ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
|
62 | ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
|
63 | ADC_InitStructure.ADC_NbrOfChannel = 2;
|
64 | ADC_InitStructure.ADC_ScanConvMode = ENABLE;
|
65 | ADC_Init(ADC1, &ADC_InitStructure);
|
66 |
|
67 | ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 1, ADC_SampleTime_239Cycles5);
|
68 | ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 2, ADC_SampleTime_239Cycles5);
|
69 |
|
70 | ADC_Cmd(ADC1, ENABLE);
|
71 |
|
72 |
|
73 |
|
74 | ADC_ResetCalibration(ADC1);
|
75 | while(ADC_GetResetCalibrationStatus(ADC1));
|
76 | ADC_StartCalibration(ADC1);
|
77 | while(ADC_GetCalibrationStatus(ADC1));
|
78 |
|
79 | ADC_DMACmd(ADC1, ENABLE);
|
80 |
|
81 | ADC_SoftwareStartConvCmd(ADC1, ENABLE);
|
82 | }
|