microscope-ring-light-remot.../main.c

59 lines
1.3 KiB
C

#include <stm32f0xx.h>
#include <stm-periph/stm32-gpio-macros.h>
#include <systick.h>
static void setup_pins(void)
{
uint32_t tmp;
RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN;
tmp = GPIOA->MODER;
/* Reset all used port pins */
tmp &= MODER_DELETE(0) & MODER_DELETE(1) & MODER_DELETE(2) & MODER_DELETE(3) & \
MODER_DELETE(4) & MODER_DELETE(5) & MODER_DELETE(6) & MODER_DELETE(7) & \
MODER_DELETE(8) & MODER_DELETE(9) & MODER_DELETE(10);
/* Analog ports for POTIs */
tmp |= ANALOG(0) | ANALOG(1) | ANALOG(4);
/* Setup USART1 RX/TX (AF1) */
tmp |= ALTFUNC(2) | ALTFUNC(3);
SETAF(GPIOA, 2, 1);
SETAF(GPIOA, 3, 1);
/* LED enables for Potentiometers */
tmp |= OUTPUT(5) | OUTPUT(6) | OUTPUT(7);
GPIOA->ODR &= ~((1 << 5) | (1 << 6) | (1 << 7));
/* Setup I2C pins (AF4) */
tmp |= ALTFUNC(9) | ALTFUNC(10);
SETAF(GPIOA, 9, 4);
SETAF(GPIOA, 10, 4);
/* Set I2C Pins to open drain. Others are push pull */
GPIOA->OTYPER = OTYP_OPENDRAIN(9) | OTYP_OPENDRAIN(10);
/* Write changes to GPIOA mode register */
GPIOA->MODER = tmp;
/* PB1 Input with pullup */
GPIOB->MODER &= MODER_DELETE(1);
GPIOB->PUPDR = PULLUP(1);
}
int main(void)
{
setup_pins();
SysTick_Config(48000000UL/1000);
GPIOA->ODR |= (1<<5) | (1<<7);
/* Blink the LEDs */
while (1) {
systick_wait_ms(250);
GPIOA->ODR ^= (1 << 5) | (1 << 6) | (1 << 7);
}
}