Files
@ 6d43230d5986
Branch filter:
Location: therm/gpio.c - annotation
6d43230d5986
4.7 KiB
text/plain
Untested changes for RTDs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | ab7abb62e433 ab7abb62e433 ab7abb62e433 857e86bbc10d ab7abb62e433 857e86bbc10d 857e86bbc10d ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 857e86bbc10d 857e86bbc10d db81b1787e6e e28695e6887c db81b1787e6e e28695e6887c e28695e6887c e28695e6887c db81b1787e6e db81b1787e6e e28695e6887c e28695e6887c e28695e6887c db81b1787e6e db81b1787e6e e28695e6887c e28695e6887c e28695e6887c e28695e6887c ab7abb62e433 857e86bbc10d 857e86bbc10d 857e86bbc10d ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 ab7abb62e433 | #include "gpio.h"
// Increase on each press, and increase at a fast rate after duration elapsed of continuously holding down... somehow...
static uint32_t change_time_reset = 0;
// Increment/decrement unsigned variable with up/down buttons
void user_input(uint16_t* to_modify)
{
if(CHANGE_ELAPSED) {
if(!HAL_GPIO_ReadPin(SW_UP) ) {
CHANGE_RESET;
(*to_modify)++;
}
else if(!HAL_GPIO_ReadPin(SW_DOWN) && (*to_modify) > 0) {
CHANGE_RESET;
(*to_modify)--;
}
}
}
// Increment/decrement signed variable with up/down buttons
void user_input_signed(int32_t* to_modify)
{
//fixme: need to cast to 16/32 bits correctly
if(CHANGE_ELAPSED) {
if(!HAL_GPIO_ReadPin(SW_UP) ) {
CHANGE_RESET;
if (*to_modify < 32768)
(*to_modify)++;
}
else if(!HAL_GPIO_ReadPin(SW_DOWN)) {
CHANGE_RESET;
if (*to_modify >= -32768)
(*to_modify)--;
}
}
}
// Initialize GPIO
void gpio_init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__GPIOF_CLK_ENABLE();
__GPIOA_CLK_ENABLE();
__GPIOB_CLK_ENABLE();
__SPI1_CLK_ENABLE();
//////////////////
// PORT F //
//////////////////
// PORTF OUTPUT
// Configure GPIO pin : PF0 [Power LED]
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
// PORTF UNUSED
// Configure GPIO pin : PF1
GPIO_InitStruct.Pin = GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
//////////////////
// PORT A //
//////////////////
// PORT A OUTPUT
// Configure GPIO pins : (SSR+ CS_OLED RES D/C CS_MAX)
GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// PORTA INPUT
// Configure GPIO pin : PA15
// GPIO_InitStruct.Pin = GPIO_PIN_15;
// GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
// GPIO_InitStruct.Pull = GPIO_PULLUP;
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// PORTA UNUSED
// Configure GPIO pins : PA0 PA8
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// USART1 [PORTA]
// Configure GPIO pins : PA9 PA10
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// SPI1 [PORTA]
// Configure GPIO pin : PA, MOSI, SCK
GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// Configure GPIO pin: PA, MISO
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// USB [PORTA]
/** USB GPIO Configuration
PA11 ------> USB_DM
PA12 ------> USB_DP
*/
// Configure GPIO pin : PA, D+, D-
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF2_USB; // Can also be AF5
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
//////////////////
// PORT B //
//////////////////
// PORT B UNUSED
// Configure GPIO pins : PB0 PB1 PB8
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
// PORT B INPUT
// Configure GPIO pins : PB3 PB4 PB5 PB6 PB7
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6
|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
// Enable DMA clocks (Is AHB even the right thing???)
//RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); // EMZ TODO get the right ones
}
// vim:softtabstop=4 shiftwidth=4 expandtab
|