/** * @brief Run auto test * @caller main * @param None * @retval None */ void auto_test(void) { uint16_t tab[6]={0x20,0x20,0x20,0x20,0x20,0x20}; Auto_test = TRUE; /* Switch off leds*/ GPIO_LOW(LED_GREEN_PORT,LED_GREEN_PIN); GPIO_LOW(LED_BLUE_PORT,LED_BLUE_PIN); /* To display version */ LCD_GLASS_DisplayString(" TEST "); delay_ms(150); STR_VERSION; LCD_GLASS_DisplayStrDeci(tab); delay_ms(200); /* And launch the tests*/ test_LSE(); test_vdd(); test_icc_Run(); test_icc_HALT(); test_icc_LP(); Auto_test = FALSE; /* Infinite loop: Press reset button at the end of test for exit*/ while (1) { LCD_GLASS_ScrollSentence("TEST OK ",1,SCROLL_SPEED); KeyPressed = FALSE; } }
void setup_gpios(void) { /* configure gpios */ static GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIOs clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); /* Configure the GPIO_LED pins LD3 & LD4*/ GPIO_InitStructure.GPIO_Pin = LED_GREEN | LED_BLUE; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_LOW(GPIOB, LED_GREEN); GPIO_LOW(GPIOB, LED_BLUE); // setup my own green led... on PC3 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_Init(GPIOC, &GPIO_InitStructure); // setup my own red led... on PA4 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_Init(GPIOA, &GPIO_InitStructure); }
void WriteCtrl(unsigned char value){ GPIO_LOW(CTRL_PORT, CTRL_RS); //RS=0 GPIO_LOW(CTRL_PORT, CTRL_RW); //RW=0 WriteCommon( value ); //Delay(EXT_LCD_DELAY); DelayBusy(); }
void Init_GPIOs (void) { GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; conf_analog_all_GPIOS(); /* configure all GPIOs as analog input */ /* Enable GPIOs clock */ RCC_AHBPeriphClockCmd(LD_GPIO_PORT_CLK | USERBUTTON_GPIO_CLK, ENABLE); /* USER button and WakeUP button init: GPIO set in input interrupt active mode */ /* Configure User Button pin as input */ GPIO_InitStructure.GPIO_Pin = USERBUTTON_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_Init(USERBUTTON_GPIO_PORT, &GPIO_InitStructure); /* Connect Button EXTI Line to Button GPIO Pin */ SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0); /* Configure User Button and IDD_WakeUP EXTI line */ EXTI_InitStructure.EXTI_Line = EXTI_Line0 ; // PA0 for User button AND IDD_WakeUP EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable and set User Button and IDD_WakeUP EXTI Interrupt to the lowest priority */ NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Configure the GPIO_LED pins LD3 & LD4*/ GPIO_InitStructure.GPIO_Pin = LD_GREEN_GPIO_PIN | LD_BLUE_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(LD_GPIO_PORT, &GPIO_InitStructure); GPIO_LOW(LD_GPIO_PORT, LD_GREEN_GPIO_PIN); GPIO_LOW(LD_GPIO_PORT, LD_BLUE_GPIO_PIN); /* Disable all GPIOs clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE | RCC_AHBPeriph_GPIOH, DISABLE); }
static inline void enable_motors (unsigned int lstate, unsigned int rstate) { GPIO_LOW(GPIOA, GPIO_Pin_3); if (rstate) GPIO_HIGH(GPIOA, GPIO_Pin_2); else GPIO_LOW(GPIOA, GPIO_Pin_2); if (lstate) GPIO_HIGH(GPIOA, GPIO_Pin_1); else GPIO_LOW(GPIOA, GPIO_Pin_1); GPIO_HIGH(GPIOA, GPIO_Pin_3); }
void SelectChip(unsigned char value){ if ((value&0x01) == 0x00){ GPIO_LOW(CRSLC_PORT, CRSLC_PIN0); } else{ GPIO_HIGH(CRSLC_PORT, CRSLC_PIN0); } if ((value&0x02) == 0x00){ GPIO_LOW(CRSLC_PORT, CRSLC_PIN1); } else{ GPIO_HIGH(CRSLC_PORT, CRSLC_PIN1); } }
/** * @brief Function used to Configure the GPIO in low consumption * @caller ADC_Icc_Test * @param None * @retval None */ void GPIO_LowPower_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; /* store GPIO configuration before lowpower switch */ GPIOA_MODER = GPIOA->MODER; GPIOB_MODER = GPIOB->MODER; GPIOC_MODER = GPIOC->MODER; GPIOD_MODER = GPIOD->MODER; GPIOE_MODER = GPIOE->MODER; GPIOH_MODER = GPIOH->MODER; GPIOA_PUPDR = GPIOA->PUPDR; GPIOB_PUPDR = GPIOB->PUPDR; GPIOC_PUPDR = GPIOC->PUPDR; GPIOD_PUPDR = GPIOD->PUPDR; GPIOE_PUPDR = GPIOE->PUPDR; GPIOH_PUPDR = GPIOH->PUPDR; /* Configure all GPIO port pins in Analog input mode (trigger OFF) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIOD->MODER = 0xFFFFFFFF; GPIOE->MODER = 0xFFFFFFFF; GPIOH->MODER = 0xFFFFFFFF; /* all GPIOA */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_6| GPIO_Pin_7 \ | GPIO_Pin_13 | GPIO_Pin_14|GPIO_Pin_5 | GPIO_Pin_8 |GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 |GPIO_Pin_15 ; GPIO_Init(GPIOA, &GPIO_InitStructure); /* All GPIOC except PC13 which is used for mesurement */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4| GPIO_Pin_5 |GPIO_Pin_6| GPIO_Pin_7| GPIO_Pin_8 \ | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_14 | GPIO_Pin_15 ; GPIO_Init(GPIOC, &GPIO_InitStructure); /* all GPIOB except PB6 and PB7 used for LED*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4| GPIO_Pin_5 | GPIO_Pin_8 \ | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 |GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 ; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_LOW(GPIOB,GPIO_Pin_6); GPIO_LOW(GPIOB,GPIO_Pin_7); }
/** * @brief To configure the GPIO in low consumption * @caller ADC_Icc_Test * @param None * @retval None */ void GPIO_LowPower_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIOA_MODER = GPIOA->MODER; GPIOB_MODER = GPIOB->MODER; GPIOC_MODER = GPIOC->MODER; GPIOD_MODER = GPIOD->MODER; GPIOE_MODER = GPIOE->MODER; GPIOH_MODER = GPIOH->MODER; GPIOA_PUPDR = GPIOA->PUPDR; GPIOB_PUPDR = GPIOB->PUPDR; GPIOC_PUPDR = GPIOC->PUPDR; GPIOD_PUPDR = GPIOD->PUPDR; GPIOE_PUPDR = GPIOE->PUPDR; GPIOH_PUPDR = GPIOH->PUPDR; /* Configure all GPIO port pins in Analog Input mode (floating input trigger OFF) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIOD->MODER = 0xFFFFFFFF; GPIOE->MODER = 0xFFFFFFFF; GPIOH->MODER = 0xFFFFFFFF; /* Configure all GPIO port pins in Analog Input mode (floating input trigger OFF) */ /* Not PA0, PA4, (PA13 PA14 PA5 for debug only)*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_6| GPIO_Pin_7 \ | GPIO_Pin_13 | GPIO_Pin_14|GPIO_Pin_5 | GPIO_Pin_8 |GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 |GPIO_Pin_15 ; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Not PC13 USED FOR MEASUREMENT */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4| GPIO_Pin_5 |GPIO_Pin_6| GPIO_Pin_7| GPIO_Pin_8 \ | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_14 | GPIO_Pin_15 ; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4| GPIO_Pin_5 | GPIO_Pin_8 \ | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 |GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 ; GPIO_Init(GPIOB, &GPIO_InitStructure); /* PB 6 & 7 it's for the LEDs */ GPIO_LOW(GPIOB,GPIO_Pin_6); GPIO_LOW(GPIOB,GPIO_Pin_7); }
static void prvQueueReceiveTask( void *pvParameters ) { unsigned long ulReceivedValue; /* Remove compiler warning about unused parameter. */ ( void ) pvParameters; for( ;; ) { /* Wait until something arrives in the queue. */ xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY ); /* To get here something must have arrived, but is it the expected value? If it is, turn the LED on for a short while. */ if( ulReceivedValue == mainQUEUED_VALUE ) { /* LED on... */ GPIO_HIGH( LD_GPIO_PORT, LD_GREEN_GPIO_PIN ); /* ... short delay ... */ vTaskDelay( mainLED_TOGGLE_DELAY ); /* ... LED off again. */ GPIO_LOW( LD_GPIO_PORT, LD_GREEN_GPIO_PIN ); } } }
/** * @brief Function in RAM for Low Power Sleep current measurment * @caller ADC_Icc_Test * @param None * @retval None */ __RAMFUNC EnterLPSLEEPModeRAM(void) { uint32_t tmpreg = 0; RAM_FLASH_RUNPowerDownCmd(ENABLE); RAM_PWR_LowPowerRunModeCmd(ENABLE); /* The application Run with delay */ GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* Select the regulator state in Sleep mode ---------------------------------*/ tmpreg = PWR->CR; /* Clear PDDS and LPDSR bits */ tmpreg &= CR_DS_MASK; /* Set LPDSR bit according to PWR_Regulator value */ tmpreg |= PWR_Regulator_LowPower; /* Store the new value */ PWR->CR = tmpreg; /* Clear SLEEPDEEP bit of Cortex System Control Register */ SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP); /* Request Wait For Event */ __WFE(); RAM_FLASH_RUNPowerDownCmd(DISABLE); RAM_PWR_LowPowerRunModeCmd(DISABLE); }
static void setup_motors(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_LOW(GPIOA, GPIO_Pin_1); GPIO_LOW(GPIOA, GPIO_Pin_2); GPIO_LOW(GPIOA, GPIO_Pin_3); }
void Pulse_E(void){ GPIO_HIGH(CTRL_PORT, CTRL_E); //E=1 //Delay(EXT_LCD_DELAY); GLCD_Delay(300); GPIO_LOW(CTRL_PORT, CTRL_E); //E=0 //Delay(EXT_LCD_DELAY); GLCD_Delay(300); }
void gpio_low(int g) { #ifndef GPIO_SIMULATED GPIO_LOW(g); #else printf("gpio:low:%d\n", g); #endif }
void DelayBusy(void){ GPIO_InitTypeDef GPIO_InitStructure; uint8_t busy_state = 1; GPIO_InitStructure.GPIO_Pin = DATA_PIN7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init( DATA_PORT, &GPIO_InitStructure); GPIO_LOW(CTRL_PORT, CTRL_RS); //RS=0 GPIO_HIGH(CTRL_PORT, CTRL_RW); //RW=1 while (busy_state){ GPIO_HIGH(CTRL_PORT, CTRL_E); //E=1 busy_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN7); GPIO_LOW(CTRL_PORT, CTRL_E); //E=0 } }
int main(void) { static unsigned int led_state = 0; RCC_ClocksTypeDef clockinfo; RCC_GetClocksFreq(&clockinfo); // regardless of clock speed this gives us 1000 ticks per second SysTick_Config(clockinfo.SYSCLK_Frequency / 1000); int blink_speed_ms = 400; setup_gpios(); setup_adc(); setup_usart(); setup_button_irqs(); kkputs("hello karl...\n"); uint64_t lasttime = millis(); while (1) { if (millis() - blink_speed_ms > lasttime) { if (led_state & 1) { switch_leds_on(); kkputs("O"); } else { switch_leds_off(); kkputs("o"); } led_state ^= 1; GPIO_TOGGLE(GPIOC, GPIO_Pin_3); lasttime = millis(); } if (button_pressed) { button_pressed = 0; kkputs("button was pressed!\n"); blink_speed_ms >>= 1; if (blink_speed_ms <= 50) { blink_speed_ms = 1000; } } // start and wait for adc to convert... ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 1, ADC_SampleTime_192Cycles); ADC_SoftwareStartConv(ADC1); while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0) ; uint16_t pot_val = ADC_GetConversionValue(ADC1); if (pot_val > 0x700) { GPIO_HIGH(GPIOA, GPIO_Pin_4); } else { GPIO_LOW(GPIOA, GPIO_Pin_4); } } }
uint8_t read_DHT11(uint8_t *buf){ uint16_t dt[42]; uint16_t cnt; uint8_t i, check_sum; //reset DHT11 Delay(500); GPIO_LOW(GPIOA,GPIO_Pin_2); Delay(20); GPIO_HIGH(GPIOA,GPIO_Pin_2); //start reading cnt = 0; for(i=0;i<83 && cnt<MAX_TICS;i++){ if (i & 1){ cnt = read_cycle(cnt, 1); } else { cnt = read_cycle(cnt, 0); dt[i/2]= cnt; } } //release line GPIO_HIGH(GPIOA,GPIO_Pin_2); if (cnt>=MAX_TICS) return DHT11_NO_CONN; //convert data for(i=2;i<42;i++){ (*buf) <<= 1; if (dt[i]>20) { (*buf)++; } if (!((i-1)%8) && (i>2)) { buf++; } } //calculate checksum buf -= 5; check_sum = 0; for(i=0;i<4;i++){ check_sum += *buf; buf++; } if (*buf != check_sum) return DHT11_CS_ERROR; return DHT11_OK; //return check_sum; }
/** * @brief EXTI line detection callbacks * @param GPIO_Pin: Specifies the pins connected EXTI line * @retval None */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { // Servicing Interrupt from PWR_ONSTAT (power off required) if (GPIO_Pin == ONOFF_STAT_PIN) { Stm32_Led_OFF(); #ifdef OLED_PRESENT // (defined in User_Configuration.h) // Do not send command if no OLED (else SPI hangs) OLED_Switch_OFF(); Delay_ms(100); // Delay between cutting OLED VDDH (13V) and VDD (logic) // to preserve panel lifetile - as per DD160128FC-1A datasheet //Caution: TimerTick involved, its IRQ priority must be high (urgent) enough // in Interrupt Configuration files #endif // wait as long as ONOFF is active (ie. until user has finished pushing button) while(HAL_GPIO_ReadPin(ONOFF_STAT_PORT, ONOFF_STAT_PIN) == GPIO_PIN_RESET); //Quickly blink LED 3 times Stm32_Led_ON(); Delay_ms(100); Stm32_Led_OFF(); Delay_ms(200); Stm32_Led_ON(); Delay_ms(100); Stm32_Led_OFF(); Delay_ms(200); Stm32_Led_ON(); Delay_ms(100); Stm32_Led_OFF(); // Bye bye: Power down VCC_NUM by resetting pin BUCK3V_ON GPIO_LOW(BUCK3V_ON_PORT, BUCK3V_ON_PIN); Delay_ms(3000); while(1); } }
/** * @brief EXTI line detection callbacks * @param GPIO_Pin: Specifies the pins connected EXTI line * @retval None */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { // Servicing Interrupt from PWR_ONSTAT (power off required) if (GPIO_Pin == PWR_ONSTAT_PIN) { Green_Led_ON(); // Power down OLED // Recommended sequence - from DD-160128FC-1A datasheet: // 1. Send Display off command // 2. Power down VDDH // 3. Delay 100ms // (When VDDH reach 0 and panel is completely discharged) // 4. Power down VDD & VDDIO if (Check_VDDH_On()) // Do not send command if no OLED (else SPI hangs) { // Display off OLED_WriteReg(0x06, 0x00); } //!! Need to make this more robust as one may have turned VDDH on //despite no OLED present Red_Led_ON(); // Power down OLED panel (VDDH 14V supply) Turn_VDDH_Off(); Delay_ms(100); //Caution: TimerTick involved, its IRQ priority must be high (urgent) enough // in Interrupt Configuration files // wait as long as /ONSTAT is high //while(GPIO_ReadInputDataBit(PWR_ONSTAT_GPIO_PORT, PWR_ONSTAT_PIN)); while(HAL_GPIO_ReadPin(PWR_ONSTAT_GPIO_PORT, PWR_ONSTAT_PIN)); // Power down VCC_NUM by un-acknowledging PowerAck pin of PMIC GPIO_LOW(PWR_POWERACK_GPIO_PORT, PWR_POWERACK_PIN); } // Servicing Interrupt from IRQB if (GPIO_Pin == PWR_IRQB_PIN) { } }
void gpio_write(int g, int v) { #ifndef GPIO_SIMULATED if (v != 0) { GPIO_HIGH(g); } else { GPIO_LOW(g); } #else printf("gpio:write:%d=%d\n", g, v); #endif }
uint8_t GetByte(void){ GPIO_InitTypeDef GPIO_InitStructure; uint8_t byte_state; uint8_t res_byte; GPIO_HIGH(CTRL_PORT, CTRL_RS); //RS=1 GPIO_HIGH(CTRL_PORT, CTRL_RW); //RW=1 GLCD_Delay(100); GPIO_InitStructure.GPIO_Pin = DATA_PIN0 | DATA_PIN1 | DATA_PIN2 | DATA_PIN3 | DATA_PIN4 | DATA_PIN5 | DATA_PIN6 | DATA_PIN7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init( DATA_PORT, &GPIO_InitStructure); GPIO_HIGH(CTRL_PORT, CTRL_E); //E=1 GLCD_Delay(100); byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN0); res_byte = byte_state; byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN1); res_byte += byte_state*0x02; byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN2); res_byte += byte_state*0x04; byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN3); res_byte += byte_state*0x08; byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN4); res_byte += byte_state*0x10; byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN5); res_byte += byte_state*0x20; byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN6); res_byte += byte_state*0x40; byte_state = GPIO_ReadInputDataBit(DATA_PORT, DATA_PIN7); res_byte += byte_state*0x80; GPIO_LOW(CTRL_PORT, CTRL_E); //E=0 DelayBusy(); return res_byte; }
void LPR_Ram(void) inram #endif #ifdef _IAR_ #pragma location="MY_RAM_FUNC" void LPR_Ram(void) #endif { uint8_t i = 0; /* To reduce consumption to minimal Swith off the Flash */ FLASH->CR1 = 0x08; while(((CLK->REGCSR)&0x80)==0x80); /* Swith off the Regulator*/ CLK->REGCSR = 0x02; while(((CLK->REGCSR)&0x01)==0x01); /* Set trigger on GPIOE pin6*/ WFE->CR2 = 0x04; GPIOE->CR2 = 0x44; for (i=0; i<100; i++); /* To start counter on falling edge*/ GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /*Wait for end of counter */ wfe(); EXTI->SR1 |= 0x40; WFE->CR2 = 0x00; //Switch on the regulator CLK->REGCSR = 0x00; while(((CLK->REGCSR)&0x1) != 0x1); }
/** * @brief Function in RAM for Low Power RUN current measurment * @caller ADC_Icc_Test * @param None * @retval None */ __RAMFUNC EnterLPRUNModeRAM(void) { RAM_FLASH_RUNPowerDownCmd(ENABLE); RAM_PWR_LowPowerRunModeCmd(ENABLE); /* The application Run with delay */ GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); do{ __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } while((USERBUTTON_GPIO_PORT->IDR & USERBUTTON_GPIO_PIN) == 0); RAM_FLASH_RUNPowerDownCmd(DISABLE); RAM_PWR_LowPowerRunModeCmd(DISABLE); }
// инициализируем дисплей void Init_LCD(void) { GPIO_InitTypeDef GPIO_InitStructure; // структура инициализации RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); GPIO_InitStructure.GPIO_Pin = LCD_RST; // настраиваем только некоторые выводы порта GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // частота работы порта GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; // режим - выход GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // пуш-пулл GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // без подтягивающих резисторов GPIO_Init(GPIOC, &GPIO_InitStructure); // запуск настройки // управляющие выводы дисплея GPIO_LOW(LCD_PORT, LCD_RST); // лог.0 на вывод RESET _delay_ms(50); // начинаем инициализацию LCD GPIO_HIGH(LCD_PORT, LCD_RST); // лог.1 на вывод RESET _delay_ms(50); LCD_write_comand (0x01); // software reset comand _delay_ms(5); LCD_write_comand (0x28); // display off //------------power control------------------------------ LCD_write_comand (0xc0); // power control LCD_write_data (0x26); // GVDD = 4.75v LCD_write_comand (0xc1); // power control LCD_write_data (0x11); // AVDD=VCIx2, VGH=VCIx7, VGL=-VCIx3 //--------------VCOM------------------------------------- LCD_write_comand (0xc5); // vcom control LCD_write_data (0x35); // Set the VCOMH voltage (0x35 = 4.025v) LCD_write_data (0x3e); // Set the VCOML voltage (0x3E = -0.950v) LCD_write_comand (0xc7); // vcom control LCD_write_data (0xbe); // 0x94 (0xBE = nVM: 1, VCOMH: VMH–2, VCOML: VML–2) //------------memory access control------------------------ LCD_write_comand (0x36); // memory access control LCD_write_data (0x48); // 0048 my,mx,mv,ml,BGR,mh,0.0 (mirrors) LCD_write_comand (0x3a); // pixel format set LCD_write_data (0x55); // 16bit /pixel //-------------ddram ---------------------------- LCD_write_comand (0x2a); // column set LCD_write_data (0x00); // x0_HIGH---0 LCD_write_data (0x00); // x0_LOW----0 LCD_write_data (0x00); // x1_HIGH---240 LCD_write_data (0xEF); // x1_LOW----240 LCD_write_comand (0x2b); // page address set LCD_write_data (0x00); // y0_HIGH---0 LCD_write_data (0x00); // y0_LOW----0 LCD_write_data (0x01); // y1_HIGH---320 LCD_write_data (0x3F); // y1_LOW----320 LCD_write_comand (0x34); // tearing effect off //LCD_write_cmd(0x35); // tearing effect on //LCD_write_cmd(0xb4); // display inversion LCD_write_comand (0xb7); // entry mode set // Deep Standby Mode: OFF // Set the output level of gate driver G1~G320: Normal display // Low voltage detection: Disable LCD_write_data (0x07); //-----------------display------------------------ LCD_write_comand (0xb6); // display function control //Set the scan mode in non-display area //Determine source/VCOM output in a non-display area in the partial display mode LCD_write_data (0x0a); //Select whether the liquid crystal type is normally white type or normally black type //Sets the direction of scan by the gate driver in the range determined by SCN and NL //Select the shift direction of outputs from the source driver //Sets the gate driver pin arrangement in combination with the GS bit to select the optimal scan mode for the module //Specify the scan cycle interval of gate driver in non-display area when PTG to select interval scan LCD_write_data (0x82); // Sets the number of lines to drive the LCD at an interval of 8 lines LCD_write_data (0x27); LCD_write_data (0x00); // clock divisor LCD_write_comand (0x11); // sleep out _delay_ms(100); LCD_write_comand (0x29); // display on _delay_ms(100); LCD_write_comand (0x2c); // memory write _delay_ms(5); }
/** * @brief This function handles external interrupts generated by UserButton. * @param None * @retval None */ void UserButtonHandler (void) { uint32_t i=0; /* set KeyPressed Flag */ KeyPressed = TRUE; /* check if user button is pressed for 4 seconds (approx.) */ while ((USERBUTTON_GPIO_PORT->IDR & USERBUTTON_GPIO_PIN) == 1 ) { i++; if (i == 0x0100000) { /* set autotest flag in E²prom*/ AUTOTEST(TRUE) ; return; } } /* if autotest is set in E²prom exit interrupt handler */ if (Auto_test) return ; /* Go to next state of state machine*/ state_machine++; if (state_machine == MAX_STATE) state_machine = STATE_VREF; /* To update Bar graph & leds*/ switch (state_machine) { case STATE_VREF: GPIO_HIGH(LD_GPIO_PORT,LD_GREEN_GPIO_PIN); GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN); BAR0_OFF; BAR1_OFF; BAR2_OFF; BAR3_OFF; break; case STATE_SLIDER_VALUE: GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN); GPIO_HIGH(LD_GPIO_PORT,LD_GREEN_GPIO_PIN); break; case STATE_SLIDER_BUTTON: GPIO_LOW(LD_GPIO_PORT,LD_GREEN_GPIO_PIN); GPIO_HIGH(LD_GPIO_PORT,LD_BLUE_GPIO_PIN); break; case STATE_ICC_RUN: GPIO_LOW(LD_GPIO_PORT,LD_GREEN_GPIO_PIN); GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN); BAR0_ON; BAR1_OFF; BAR2_OFF; BAR3_OFF; break; case STATE_ICC_LP_RUN: GPIO_LOW(LD_GPIO_PORT,LD_GREEN_GPIO_PIN); GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN); BAR0_ON; BAR1_ON; BAR2_OFF; BAR3_OFF; break; case STATE_ICC_STOP: GPIO_LOW(LD_GPIO_PORT,LD_GREEN_GPIO_PIN); GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN); BAR0_ON; BAR1_ON; BAR2_ON; BAR3_OFF; break; case STATE_ICC_STBY: GPIO_LOW(LD_GPIO_PORT,LD_GREEN_GPIO_PIN); GPIO_LOW(LD_GPIO_PORT,LD_BLUE_GPIO_PIN); BAR0_ON; BAR1_ON; BAR2_ON; BAR3_ON; break; } }
/******************************************************************************* * Function Name : Green_Led_OFF * Description : Switched Green LED Off. * Return : None. *******************************************************************************/ void Green_Led_OFF(void) { GPIO_LOW(LED_GREEN_PORT, LED_GREEN_PIN); }
static void prvSetupHardware( void ) { /* GPIO, EXTI and NVIC Init structure declaration */ GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; void SystemCoreClockUpdate( void ); /* System function that updates the SystemCoreClock variable. */ SystemCoreClockUpdate(); /* Essential on STM32 Cortex-M devices. */ NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); /* Systick is fed from HCLK/8. */ SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK_Div8 ); /* Set MSI clock range to ~4.194MHz. */ RCC_MSIRangeConfig( RCC_MSIRange_6 ); /* Enable the GPIOs clocks. */ RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC| RCC_AHBPeriph_GPIOD| RCC_AHBPeriph_GPIOE| RCC_AHBPeriph_GPIOH, ENABLE ); /* Enable comparator clocks. */ RCC_APB1PeriphClockCmd( RCC_APB1Periph_COMP, ENABLE ); /* Enable SYSCFG clocks. */ RCC_APB2PeriphClockCmd( RCC_APB2Periph_SYSCFG , ENABLE ); /* Set internal voltage regulator to 1.5V. */ PWR_VoltageScalingConfig( PWR_VoltageScaling_Range2 ); /* Wait Until the Voltage Regulator is ready. */ while( PWR_GetFlagStatus( PWR_FLAG_VOS ) != RESET ); /* Configure User Button pin as input */ GPIO_InitStructure.GPIO_Pin = USERBUTTON_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_Init( USERBUTTON_GPIO_PORT, &GPIO_InitStructure ); /* Select User Button pin as input source for EXTI Line */ SYSCFG_EXTILineConfig( EXTI_PortSourceGPIOA, EXTI_PinSource0 ); /* Configure EXT1 Line 0 in interrupt mode trigged on Rising edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line0 ; /* PA0 for User button AND IDD_WakeUP */ EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init( &EXTI_InitStructure ); /* Enable and set EXTI0 Interrupt to the lowest priority */ NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_LOWEST_INTERRUPT_PRIORITY; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init( &NVIC_InitStructure ); /* Configure the LED_pin as output push-pull for LD3 & LD4 usage */ GPIO_InitStructure.GPIO_Pin = LD_GREEN_GPIO_PIN | LD_BLUE_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init( LD_GPIO_PORT, &GPIO_InitStructure ); /* Force a low level on LEDs */ GPIO_LOW( LD_GPIO_PORT, LD_GREEN_GPIO_PIN ); GPIO_LOW( LD_GPIO_PORT, LD_BLUE_GPIO_PIN ); }
/** * @brief Current measurement in different MCU modes: * RUN/SLEEP/LowPower/STANDBY with/without RTC * @caller main and ADC_Icc_Test * @param MCU state * @retval ADC value. */ uint16_t ADC_Icc_Test(uint8_t Mcu_State) { GPIO_InitTypeDef GPIO_InitStructure; uint16_t adc_measure; uint32_t i; RCC_TypeDef SavRCC; /* Reset UserButton State */ UserButton = FALSE; /* Start counter */ GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* Disable the RTC Wakeup Interrupt */ RTC_ITConfig(RTC_IT_WUT, DISABLE); /* Disable LCD */ LCD_Cmd(DISABLE); /* wait until LCD disable */ while (LCD_GetFlagStatus(LCD_FLAG_ENS) == SET); /*Reset Idd-WakeUP flag*/ Idd_WakeUP = FALSE; /* Set IO in lowpower configuration*/ GPIO_LowPower_Config(); /*Disable fast wakeUp*/ PWR_FastWakeUpCmd(DISABLE); /* Test MCU state for configuration */ switch (Mcu_State) { /* Run mode : Measurement Measurement performed with MSI 4 MHz without RTC*/ case MCU_RUN: /* switch on MSI clock */ SetHSICLKToMSI(RCC_MSIRange_6,NoDIV2,NoRTC) ; /* shitch on MSI clock */ Config_RCC(&SavRCC); SysTick->CTRL = 0; RCC->APB1ENR = 0; /* To run nops during measurement: it's the best case for low current */ for (i=0;i<0xffff;i++) { __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } break; /* SLEEP mode : Measurement performed with MSI 4 MHz without RTC in WFI mode*/ case MCU_SLEEP: SetHSICLKToMSI(RCC_MSIRange_6,NoDIV2,NoRTC) ; Config_RCC(&SavRCC); Config_Systick_50ms(); Delay(1); /* Request Wait For Interrupt */ PWR_EnterSleepMode(PWR_Regulator_ON,PWR_SLEEPEntry_WFI); break; /* RUN LOW POWER mode : Measurement performed with MSI 32 Khz without RTC */ case MCU_LP_RUN: /* Disable PVD */ PWR_PVDCmd(DISABLE); /* Enable The ultra Low Power Mode */ PWR_UltraLowPowerCmd(ENABLE); /* Save the RCC configuration registers */ Config_RCC(&SavRCC); /* Stop the sys tick in order to avoid IT */ SysTick->CTRL = 0; #ifdef TESTINRAM SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; PWR_EnterLowPowerRunMode(ENABLE); while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET) ; DisableInterrupts(); EnterLPRUNModeRAM(); EnableInterrupts(); #else /* Swith in MSI 32KHz */ SetHSICLKToMSI(RCC_MSIRange_64KHz,DIV2,NoRTC) ; PWR_EnterLowPowerRunMode(ENABLE); while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET) ; /* Launch the counter */ GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* To run the nop during measurement: it's the best case for low current until counter reach detected by IT --> Idd_WakeUP */ do{ __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } while (Idd_WakeUP == FALSE ); #endif PWR_EnterLowPowerRunMode(DISABLE); while(PWR_GetFlagStatus(PWR_FLAG_REGLP) != RESET) ; break; /* SLEEP LOW POWER mode Measurement done to MSI 32 Khz without RTC */ case MCU_LP_SLEEP: /* Disable PVD */ PWR_PVDCmd(DISABLE); /* Enable Ultra low power mode */ PWR_UltraLowPowerCmd(ENABLE); /* To save the RCC configuration registers */ Config_RCC(&SavRCC); /* To stop the sys tick for avoid IT */ SysTick->CTRL = 0; /* Swith in MSI 32KHz */ SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; #ifdef TESTINRAM DisableInterrupts(); EnterLPSLEEPModeRAM(); EnableInterrupts(); #else /* Falling edge for start counter */ GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* Request Wait For Interrupt */ PWR_EnterSleepMode(PWR_Regulator_LowPower,PWR_SLEEPEntry_WFI); #endif break; /* STOP modes Measurement done to MSI 32 Khz without or with RTC */ case MCU_STOP_NoRTC: case MCU_STOP_RTC: /* Disable PVD */ PWR_PVDCmd(DISABLE); /* Enable Ultra low power mode */ PWR_UltraLowPowerCmd(ENABLE); /* To save the RCC configuration registers */ Config_RCC(&SavRCC); /* To stop the sys tick for avoid IT */ SysTick->CTRL = 0; /* Swith in MSI 32KHz */ if( Mcu_State == MCU_STOP_NoRTC ) SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; else SetHSICLKToMSI(RCC_MSIRange_0,DIV2,WITHRTC) ; /* Falling edge for start counter */ GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* Request Wait For Interrupt */ PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI); break; /* Standby mode without RTC Measurement done to MSI 32 Khz without RTC */ case MCU_STBY: /* Disable PVD */ PWR_PVDCmd(DISABLE); /* Enable Ultra low power mode */ PWR_UltraLowPowerCmd(ENABLE); RTC_OutputTypeConfig(RTC_OutputType_PushPull); RTC_OutputConfig(RTC_Output_WakeUp,RTC_OutputPolarity_High); /* To configure PC13 WakeUP output */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 ; //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_Init( GPIOC, &GPIO_InitStructure); // GPIO_Init( GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOC, GPIO_PinSource13,GPIO_AF_RTC_AF1) ; //GPIO_PinAFConfig(GPIOA, GPIO_PinSource0,GPIO_AF_RTC_AF1) ; Config_RCC(&SavRCC); SysTick->CTRL = 0; /* Swith in MSI 32KHz */ SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; PWR_WakeUpPinCmd(PWR_WakeUpPin_1,ENABLE); PWR_UltraLowPowerCmd(ENABLE); PWR_EnterSTANDBYMode(); /* Stop here WakeUp EXIT on RESET */ break; } SetHSICLK(); Config_Systick(); RCC->AHBENR = SavRCC.AHBENR; PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ; /* Read ADC for current measurmeent */ adc_measure = Current_Measurement(); /* ICC_CNT_EN Hi */ GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); UserButton = TRUE; /* To restore RCC registers */ RCC->APB1ENR = SavRCC.APB1ENR; RCC->APB2ENR = SavRCC.APB2ENR; RCC->AHBLPENR = SavRCC.AHBLPENR; RCC->APB1LPENR = SavRCC.APB1LPENR; RCC->APB2LPENR = SavRCC.APB2LPENR; /* Need to reinit RCC for LCD*/ RCC_Configuration(); PWR_EnterLowPowerRunMode(DISABLE); /* Disable Ultra low power mode */ PWR_UltraLowPowerCmd(DISABLE); /* Disable FLASH during SLeep LP */ FLASH_SLEEPPowerDownCmd(DISABLE); Restore_GPIO_Config(); /* Clear Wake Up flag */ PWR_ClearFlag(PWR_FLAG_WU); /* Enable PVD */ PWR_PVDCmd(ENABLE); LCD_GLASS_Init(); return (adc_measure); }
/******************************************************************************* * @brief : Disable generation of VDDH to OLED on the board * @param : xx. * @return : xx. ******************************************************************************/ void Turn_VDDH_Off (void) { GPIO_LOW(VDDH_EN_PORT, VDDH_EN_PIN); VDDH_On = FALSE; }
/** * @brief To initialize the I/O ports * @caller main * @param None * @retval None */ void Init_GPIOs (void) { GPIO_InitTypeDef GPIO_InitStructure; /* USER button and WakeUP button init: GPIO set in input interrupt active mode */ EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Configure User Button pin as input */ GPIO_InitStructure.GPIO_Pin = USER_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_Init(BUTTON_GPIO_PORT, &GPIO_InitStructure); /* Connect Button EXTI Line to Button GPIO Pin */ SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0); /* Configure User Button and IDD_WakeUP EXTI line */ EXTI_InitStructure.EXTI_Line = EXTI_Line0 ; // PA0 for User button AND IDD_WakeUP EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable and set User Button and IDD_WakeUP EXTI Interrupt to the lowest priority */ NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Configure the GPIO_LED pins LD3 & LD4*/ GPIO_InitStructure.GPIO_Pin = LD_GREEN|LD_BLUE; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(LD_PORT, &GPIO_InitStructure); GPIO_LOW(LD_PORT,LD_GREEN); GPIO_LOW(LD_PORT,LD_BLUE); /* Counter enable: GPIO set in output for enable the counter */ GPIO_InitStructure.GPIO_Pin = CTN_CNTEN_GPIO_PIN; GPIO_Init( CTN_GPIO_PORT, &GPIO_InitStructure); /* To prepare to start counter */ GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* Configure Output for LCD */ /* Port A */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_8 | GPIO_Pin_9 |GPIO_Pin_10 |GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_Init( GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource1,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOA, GPIO_PinSource2,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOA, GPIO_PinSource3,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOA, GPIO_PinSource8,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOA, GPIO_PinSource9,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOA, GPIO_PinSource10,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOA, GPIO_PinSource15,GPIO_AF_LCD) ; /* Configure Output for LCD */ /* Port B */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_9 \ | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_Init( GPIOB, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOB, GPIO_PinSource3,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource4,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource5,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource8,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource9,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource10,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource11,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource12,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource13,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource14,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOB, GPIO_PinSource15,GPIO_AF_LCD) ; /* Configure Output for LCD */ /* Port C*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_6 \ | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |GPIO_Pin_11 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_Init( GPIOC, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOC, GPIO_PinSource0,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource1,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource2,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource3,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource6,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource7,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource8,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource9,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource10,GPIO_AF_LCD) ; GPIO_PinAFConfig(GPIOC, GPIO_PinSource11,GPIO_AF_LCD) ; /* ADC input */ GPIO_InitStructure.GPIO_Pin = IDD_MEASURE ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_Init( IDD_MEASURE_PORT, &GPIO_InitStructure); }
static inline void disable_motors(void) { GPIO_LOW(GPIOA, GPIO_Pin_1); GPIO_LOW(GPIOA, GPIO_Pin_2); GPIO_LOW(GPIOA, GPIO_Pin_3); }