From baee1b2e94ba9570abe902b82aa8cd6a70a565cf Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Sun, 14 Sep 2025 20:23:51 +0200 Subject: [PATCH] add missing files --- Inc/address_selector.h | 6 ++++++ Src/address_selector.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 Inc/address_selector.h create mode 100644 Src/address_selector.c diff --git a/Inc/address_selector.h b/Inc/address_selector.h new file mode 100644 index 0000000..3813df2 --- /dev/null +++ b/Inc/address_selector.h @@ -0,0 +1,6 @@ +#include + +void adress_selector_init_gpio(); +uint8_t read_address(); + +extern uint8_t dmx_address; diff --git a/Src/address_selector.c b/Src/address_selector.c new file mode 100644 index 0000000..e48ba8a --- /dev/null +++ b/Src/address_selector.c @@ -0,0 +1,53 @@ +#include "stm32g0b1xx.h" +#include + +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); +#else + uint16_t address = DMX_ADDRESS; + printf("static address: %d\n", address); +#endif + return address; +}