You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
parafraktor-stm32/Src/address_selector.c

54 lines
1.4 KiB
C

#include "stm32g0b1xx.h"
#include <stdio.h>
uint8_t dmx_address;
void adress_selector_init_gpio(){
RCC->IOPENR |= RCC_IOPENR_GPIOEEN;
RCC->IOPENR |= RCC_IOPENR_GPIOBEN;
GPIOE->MODER &= ~(0x3 << (9 * 2));
GPIOE->MODER &= ~(0x3 << (10 * 2));
GPIOE->MODER &= ~(0x3 << (11 * 2));
GPIOE->MODER &= ~(0x3 << (12 * 2));
GPIOE->MODER &= ~(0x3 << (13 * 2));
GPIOE->MODER &= ~(0x3 << (14 * 2));
GPIOE->MODER &= ~(0x3 << (15 * 2));
GPIOB->MODER &= ~(0x3 << (10 * 2)); // B10
GPIOE->PUPDR &= ~(0x3 << (9 * 2));
GPIOE->PUPDR |= (0x1 << (9 * 2));
GPIOE->PUPDR &= ~(0x3 << (10 * 2));
GPIOE->PUPDR |= (0x1 << (10 * 2));
GPIOE->PUPDR &= ~(0x3 << (11 * 2));
GPIOE->PUPDR |= (0x1 << (11 * 2));
GPIOE->PUPDR &= ~(0x3 << (12 * 2));
GPIOE->PUPDR |= (0x1 << (12 * 2));
GPIOE->PUPDR |= (0x1 << (13 * 2));
GPIOE->PUPDR &= ~(0x3 << (13 * 2));
GPIOE->PUPDR |= (0x1 << (14 * 2));
GPIOE->PUPDR &= ~(0x3 << (14 * 2));
GPIOE->PUPDR |= (0x1 << (15 * 2));
GPIOE->PUPDR &= ~(0x3 << (15 * 2));
GPIOB->PUPDR &= ~(0x3 << (10 * 2)); // B10
GPIOB->PUPDR |= (0x1 << (10 * 2));
}
uint8_t read_address(){
#ifndef DMX_ADDRESS
uint16_t address = ((GPIOE->IDR >> 9)&0x7F) | (GPIOB->IDR & (1<<10))>>3;
printf("read address: %d = 0x%x\n", address, address);
#else
uint16_t address = DMX_ADDRESS;
printf("static address: %d\n", address);
#endif
return address;
}