wip
This commit is contained in:
+30
-11
@@ -1,5 +1,5 @@
|
||||
# 0 "src/gpio.c"
|
||||
# 1 "/home/alex/code/own/c-compile-experiments//"
|
||||
# 1 "/home/alex/code/own/stm32-falling-sand//"
|
||||
# 0 "<built-in>"
|
||||
#define __STDC__ 1
|
||||
# 0 "<built-in>"
|
||||
@@ -1995,17 +1995,23 @@ struct gpio {
|
||||
volatile uint32_t ODR;
|
||||
volatile uint32_t BSRR;
|
||||
volatile uint32_t LCKR;
|
||||
volatile uint32_t AFRL[2];
|
||||
volatile uint32_t AFRH[2];
|
||||
volatile uint32_t AFRL;
|
||||
volatile uint32_t AFRH;
|
||||
};
|
||||
|
||||
|
||||
#define GPIO_AF_MCO_1 (0b0000)
|
||||
#define GPIO_AF_USART2_RX (0b0111)
|
||||
#define GPIO_AF_USART2_TX (0b0111)
|
||||
|
||||
#define GPIO_BASE_ADDR (0x40020000U)
|
||||
#define GPIO_PORT_OFFSET (0x400U)
|
||||
#define GPIO(port) ((struct gpio*)(uintptr_t)(GPIO_BASE_ADDR + (GPIO_PORT_OFFSET * port)))
|
||||
|
||||
#define BIT(x) (1 << x)
|
||||
|
||||
#define PIN(port,num) ((((port) - 'A') << 8) | num)
|
||||
#define PORT(port) (((port) - 'A') << 8)
|
||||
|
||||
#define PIN(port,num) (PORT(port) | num)
|
||||
|
||||
#define PINNUM(pin) (pin & 0b1111)
|
||||
|
||||
@@ -2019,24 +2025,37 @@ typedef enum {
|
||||
} GPIO_MODE;
|
||||
|
||||
void gpio_set_mode(uint16_t pin, GPIO_MODE mode);
|
||||
void gpio_set_af(uint16_t pin, uint8_t af);
|
||||
void gpio_write(uint16_t pin,
|
||||
# 40 "src/gpio.h" 3 4
|
||||
# 47 "src/gpio.h" 3 4
|
||||
_Bool
|
||||
# 40 "src/gpio.h"
|
||||
# 47 "src/gpio.h"
|
||||
val);
|
||||
# 5 "src/gpio.c" 2
|
||||
|
||||
void gpio_set_mode(uint16_t pin, GPIO_MODE mode) {
|
||||
struct gpio *gpio = ((struct gpio*)(uintptr_t)((0x40020000U) + ((0x400U) * (pin >> 8))));
|
||||
int pn = (pin & 0b1111);
|
||||
gpio->MODER &= ~(0x0011 << (pn * 2));
|
||||
gpio->MODER |= (mode & 0b011) << (pn * 2);
|
||||
gpio->MODER &= ~(0b11 << (pn * 2));
|
||||
gpio->MODER |= (mode & 0b11) << (pn * 2);
|
||||
}
|
||||
|
||||
void gpio_set_af(uint16_t pin, uint8_t af) {
|
||||
struct gpio *gpio = ((struct gpio*)(uintptr_t)((0x40020000U) + ((0x400U) * (pin >> 8))));
|
||||
int pn = (pin & 0b1111);
|
||||
if (pn < 8) {
|
||||
gpio->AFRL &= ~(0b1111 << (pn * 4));
|
||||
gpio->AFRL |= (af & 0b1111) << (pn * 4);
|
||||
} else {
|
||||
gpio->AFRH &= ~(0b1111 << (pn * 4));
|
||||
gpio->AFRH |= (af & 0b1111) << (pn * 4);
|
||||
}
|
||||
}
|
||||
|
||||
void gpio_write(uint16_t pin,
|
||||
# 13 "src/gpio.c" 3 4
|
||||
# 25 "src/gpio.c" 3 4
|
||||
_Bool
|
||||
# 13 "src/gpio.c"
|
||||
# 25 "src/gpio.c"
|
||||
val) {
|
||||
struct gpio *gpio = ((struct gpio*)(uintptr_t)((0x40020000U) + ((0x400U) * (pin >> 8))));
|
||||
gpio->BSRR = (0b0011 << (pin & 0b1111)) << (val ? 0 : 16);
|
||||
|
||||
Reference in New Issue
Block a user