Skip to content
This repository was archived by the owner on Jul 28, 2024. It is now read-only.

Commit 41fbe9a

Browse files
committed
i have no idea what i'm doing
but it works
1 parent a271d09 commit 41fbe9a

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11

2-
gpio_item.c
3-
gpio_item.h

gpio_item.c

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "gpio_item.h"
2+
3+
#include <furi_hal_resources.h>
4+
5+
typedef struct {
6+
const char* name;
7+
const GpioPin* pin;
8+
} GpioItem;
9+
10+
static const GpioItem gpio_item[GPIO_ITEM_COUNT] = {
11+
{"1.2: PA7", &gpio_ext_pa7},
12+
{"1.3: PA6", &gpio_ext_pa6},
13+
{"1.4: PA4", &gpio_ext_pa4},
14+
{"1.5: PB3", &gpio_ext_pb3},
15+
{"1.6: PB2", &gpio_ext_pb2},
16+
{"1.7: PC3", &gpio_ext_pc3},
17+
{"2.7: PC1", &gpio_ext_pc1},
18+
{"2.8: PC0", &gpio_ext_pc0},
19+
};
20+
21+
void gpio_item_configure_pin(uint8_t index, GpioMode mode) {
22+
furi_assert(index < GPIO_ITEM_COUNT);
23+
furi_hal_gpio_write(gpio_item[index].pin, false);
24+
furi_hal_gpio_init(gpio_item[index].pin, mode, GpioPullNo, GpioSpeedVeryHigh);
25+
}
26+
27+
void gpio_item_configure_all_pins(GpioMode mode) {
28+
for(uint8_t i = 0; i < GPIO_ITEM_COUNT; i++) {
29+
gpio_item_configure_pin(i, mode);
30+
}
31+
}
32+
33+
void gpio_item_set_pin(uint8_t index, bool level) {
34+
furi_assert(index < GPIO_ITEM_COUNT);
35+
furi_hal_gpio_write(gpio_item[index].pin, level);
36+
}
37+
38+
void gpio_item_set_all_pins(bool level) {
39+
for(uint8_t i = 0; i < GPIO_ITEM_COUNT; i++) {
40+
gpio_item_set_pin(i, level);
41+
}
42+
}
43+
44+
const char* gpio_item_get_pin_name(uint8_t index) {
45+
furi_assert(index < GPIO_ITEM_COUNT + 1);
46+
if(index == GPIO_ITEM_COUNT) {
47+
return "ALL";
48+
} else {
49+
return gpio_item[index].name;
50+
}
51+
}

gpio_item.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <furi_hal_gpio.h>
4+
5+
#define GPIO_ITEM_COUNT 8
6+
7+
void gpio_item_configure_pin(uint8_t index, GpioMode mode);
8+
9+
void gpio_item_configure_all_pins(GpioMode mode);
10+
11+
void gpio_item_set_pin(uint8_t index, bool level);
12+
13+
void gpio_item_set_all_pins(bool level);
14+
15+
const char* gpio_item_get_pin_name(uint8_t index);

0 commit comments

Comments
 (0)