Add gpio_set_af to set alternative function of a pin
This commit is contained in:
BIN
build/final.elf
BIN
build/final.elf
Binary file not shown.
@@ -18,6 +18,8 @@ Discarded input sections
|
||||
.text 0x00000000 0x0 build/gpio.o
|
||||
.data 0x00000000 0x0 build/gpio.o
|
||||
.bss 0x00000000 0x0 build/gpio.o
|
||||
.text.gpio_set_af
|
||||
0x00000000 0x98 build/gpio.o
|
||||
.group 0x00000000 0xc build/main.o
|
||||
.group 0x00000000 0xc build/main.o
|
||||
.group 0x00000000 0xc build/main.o
|
||||
@@ -261,38 +263,38 @@ LOAD build/timer.o
|
||||
OUTPUT(build/final.elf elf32-littlearm)
|
||||
LOAD linker stubs
|
||||
|
||||
.debug_info 0x00000000 0xb10
|
||||
.debug_info 0x00000000 0x205 build/gpio.o
|
||||
.debug_info 0x00000205 0x44e build/main.o
|
||||
.debug_info 0x00000653 0x188 build/startup.o
|
||||
.debug_info 0x000007db 0x335 build/timer.o
|
||||
.debug_info 0x00000000 0xb6d
|
||||
.debug_info 0x00000000 0x262 build/gpio.o
|
||||
.debug_info 0x00000262 0x44e build/main.o
|
||||
.debug_info 0x000006b0 0x188 build/startup.o
|
||||
.debug_info 0x00000838 0x335 build/timer.o
|
||||
|
||||
.debug_abbrev 0x00000000 0x439
|
||||
.debug_abbrev 0x00000000 0x119 build/gpio.o
|
||||
.debug_abbrev 0x00000119 0x144 build/main.o
|
||||
.debug_abbrev 0x0000025d 0x127 build/startup.o
|
||||
.debug_abbrev 0x00000384 0xb5 build/timer.o
|
||||
.debug_abbrev 0x00000000 0x43d
|
||||
.debug_abbrev 0x00000000 0x11d build/gpio.o
|
||||
.debug_abbrev 0x0000011d 0x144 build/main.o
|
||||
.debug_abbrev 0x00000261 0x127 build/startup.o
|
||||
.debug_abbrev 0x00000388 0xb5 build/timer.o
|
||||
|
||||
.debug_aranges 0x00000000 0xa8
|
||||
.debug_aranges 0x00000000 0xb0
|
||||
.debug_aranges
|
||||
0x00000000 0x28 build/gpio.o
|
||||
0x00000000 0x30 build/gpio.o
|
||||
.debug_aranges
|
||||
0x00000028 0x28 build/main.o
|
||||
0x00000030 0x28 build/main.o
|
||||
.debug_aranges
|
||||
0x00000050 0x30 build/startup.o
|
||||
0x00000058 0x30 build/startup.o
|
||||
.debug_aranges
|
||||
0x00000080 0x28 build/timer.o
|
||||
0x00000088 0x28 build/timer.o
|
||||
|
||||
.debug_rnglists
|
||||
0x00000000 0x6c
|
||||
0x00000000 0x73
|
||||
.debug_rnglists
|
||||
0x00000000 0x19 build/gpio.o
|
||||
0x00000000 0x20 build/gpio.o
|
||||
.debug_rnglists
|
||||
0x00000019 0x1b build/main.o
|
||||
0x00000020 0x1b build/main.o
|
||||
.debug_rnglists
|
||||
0x00000034 0x1f build/startup.o
|
||||
0x0000003b 0x1f build/startup.o
|
||||
.debug_rnglists
|
||||
0x00000053 0x19 build/timer.o
|
||||
0x0000005a 0x19 build/timer.o
|
||||
|
||||
.debug_macro 0x00000000 0x3ba0
|
||||
.debug_macro 0x00000000 0xb56 build/gpio.o
|
||||
@@ -321,20 +323,20 @@ LOAD linker stubs
|
||||
.debug_macro 0x00002f20 0xb5c build/timer.o
|
||||
.debug_macro 0x00003a7c 0x124 build/timer.o
|
||||
|
||||
.debug_line 0x00000000 0x4b3
|
||||
.debug_line 0x00000000 0x116 build/gpio.o
|
||||
.debug_line 0x00000116 0x1d4 build/main.o
|
||||
.debug_line 0x000002ea 0xea build/startup.o
|
||||
.debug_line 0x000003d4 0xdf build/timer.o
|
||||
.debug_line 0x00000000 0x516
|
||||
.debug_line 0x00000000 0x179 build/gpio.o
|
||||
.debug_line 0x00000179 0x1d4 build/main.o
|
||||
.debug_line 0x0000034d 0xea build/startup.o
|
||||
.debug_line 0x00000437 0xdf build/timer.o
|
||||
|
||||
.debug_str 0x00000000 0x5eba
|
||||
.debug_str 0x00000000 0x5375 build/gpio.o
|
||||
0x551d (size before relaxing)
|
||||
.debug_str 0x00005375 0xab1 build/main.o
|
||||
.debug_str 0x00000000 0x5ed0
|
||||
.debug_str 0x00000000 0x538b build/gpio.o
|
||||
0x553b (size before relaxing)
|
||||
.debug_str 0x0000538b 0xab1 build/main.o
|
||||
0x5f7e (size before relaxing)
|
||||
.debug_str 0x00005e26 0x88 build/startup.o
|
||||
.debug_str 0x00005e3c 0x88 build/startup.o
|
||||
0x3cdc (size before relaxing)
|
||||
.debug_str 0x00005eae 0xc build/timer.o
|
||||
.debug_str 0x00005ec4 0xc build/timer.o
|
||||
0x5b16 (size before relaxing)
|
||||
|
||||
.comment 0x00000000 0x45
|
||||
@@ -370,8 +372,8 @@ LOAD linker stubs
|
||||
0x00000278 0x8 build/timer.o
|
||||
0x25b (size before relaxing)
|
||||
|
||||
.debug_frame 0x00000000 0x16c
|
||||
.debug_frame 0x00000000 0x60 build/gpio.o
|
||||
.debug_frame 0x00000060 0x50 build/main.o
|
||||
.debug_frame 0x000000b0 0x6c build/startup.o
|
||||
.debug_frame 0x0000011c 0x50 build/timer.o
|
||||
.debug_frame 0x00000000 0x194
|
||||
.debug_frame 0x00000000 0x88 build/gpio.o
|
||||
.debug_frame 0x00000088 0x50 build/main.o
|
||||
.debug_frame 0x000000d8 0x6c build/startup.o
|
||||
.debug_frame 0x00000144 0x50 build/timer.o
|
||||
|
||||
769
build/gpio.S
769
build/gpio.S
File diff suppressed because it is too large
Load Diff
21
build/gpio.i
21
build/gpio.i
@@ -2020,10 +2020,11 @@ 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,
|
||||
# 41 "src/gpio.h" 3 4
|
||||
# 42 "src/gpio.h" 3 4
|
||||
_Bool
|
||||
# 41 "src/gpio.h"
|
||||
# 42 "src/gpio.h"
|
||||
val);
|
||||
# 5 "src/gpio.c" 2
|
||||
|
||||
@@ -2034,10 +2035,22 @@ void gpio_set_mode(uint16_t pin, GPIO_MODE mode) {
|
||||
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);
|
||||
|
||||
BIN
build/gpio.o
BIN
build/gpio.o
Binary file not shown.
@@ -824,7 +824,7 @@ main:
|
||||
.byte 0
|
||||
.uleb128 0xa
|
||||
.4byte .LASF996
|
||||
.byte 0x29
|
||||
.byte 0x2a
|
||||
.4byte 0x3cd
|
||||
.uleb128 0x6
|
||||
.4byte 0x88
|
||||
|
||||
@@ -2144,10 +2144,11 @@ 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,
|
||||
# 41 "src/gpio.h" 3 4
|
||||
# 42 "src/gpio.h" 3 4
|
||||
_Bool
|
||||
# 41 "src/gpio.h"
|
||||
# 42 "src/gpio.h"
|
||||
val);
|
||||
# 6 "src/main.c" 2
|
||||
# 1 "src/flash.h" 1
|
||||
|
||||
BIN
build/main.o
BIN
build/main.o
Binary file not shown.
12
src/gpio.c
12
src/gpio.c
@@ -10,6 +10,18 @@ void gpio_set_mode(uint16_t pin, GPIO_MODE mode) {
|
||||
gpio->MODER |= (mode & 0b11) << (pn * 2); // Set new mode. Each pin uses 2 bits
|
||||
}
|
||||
|
||||
void gpio_set_af(uint16_t pin, uint8_t af) {
|
||||
struct gpio *gpio = GPIO(PINPORT(pin));
|
||||
int pn = PINNUM(pin);
|
||||
if (pn < 8) {
|
||||
gpio->AFRL &= ~(0b1111 << (pn * 4)); // Each pin uses 4 bits
|
||||
gpio->AFRL |= (af & 0b1111) << (pn * 4);
|
||||
} else {
|
||||
gpio->AFRH &= ~(0b1111 << (pn * 4)); // Each pin uses 4 bits
|
||||
gpio->AFRH |= (af & 0b1111) << (pn * 4);
|
||||
}
|
||||
}
|
||||
|
||||
void gpio_write(uint16_t pin, bool val) {
|
||||
struct gpio *gpio = GPIO(PINPORT(pin));
|
||||
gpio->BSRR = (0b0011 << PINNUM(pin)) << (val ? 0 : 16);
|
||||
|
||||
@@ -38,6 +38,7 @@ 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, bool val);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user