-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from sc-bin/main
update
- Loading branch information
Showing
35 changed files
with
4,209 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,3 +194,4 @@ cython_debug/ | |
.vscode/settings.json | ||
exe | ||
command/_gpiocommand | ||
server/gpioc-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
echo_red() { | ||
echo -e "\r\033[31m$1\033[0m" | ||
} | ||
echo_green() { | ||
echo -e "\r\033[32m$1\033[0m" | ||
} | ||
echo_blue() { | ||
echo -e "\r\033[36m$1\033[0m" | ||
} | ||
|
||
|
||
PATH_PWD="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" | ||
VERSION=$(uname -r) | ||
VERSION_digit=${VERSION:0:1} | ||
|
||
|
||
bin_path="/usr/bin/gpio" | ||
bin_file_name="gpio.sh" | ||
comple_path="/etc/bash_completion.d/gpio" | ||
comple_file_name="gpio-completion.sh" | ||
|
||
|
||
if [ -f $bin_path ]; then | ||
rm $bin_path | ||
fi | ||
|
||
rm $comple_path | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cc = gcc | ||
|
||
src = $(wildcard *.c) | ||
target = exe | ||
|
||
|
||
all:$(src) | ||
gcc $(src) -lgpio -o $(target) | ||
|
||
clean: | ||
-rm $(target) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
|
||
#include "gpio.h" | ||
#define IO 41 | ||
|
||
int main() | ||
{ | ||
printf("引脚 %d 的mode 0 : %s\n", IO, pin_get_mode_name_by_num(IO, 0)); | ||
printf("引脚 %d 的mode 1 : %s\n", IO, pin_get_mode_name_by_num(IO, 1)); | ||
|
||
printf("引脚 %d 工作于 %d %s\n", IO, pin_get_mode(IO), pin_get_mode_name_now(IO)); | ||
pin_set_mode(IO, OUTPUT); // 设置为输出模式 | ||
printf("引脚 %d 工作于 %d %s\n", IO, pin_get_mode(IO), pin_get_mode_name_now(IO)); | ||
pin_set_mode_by_name(IO, "IN"); // 设置为输入模式 | ||
printf("引脚 %d 工作于 %d %s\n", IO, pin_get_mode(IO), pin_get_mode_name_now(IO)); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
#!/bin/bash | ||
PATH_PWD="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" | ||
|
||
cd libgpio | ||
cd ${PATH_PWD}/libgpio | ||
make | ||
make install | ||
cd ../command | ||
|
||
cd ${PATH_PWD}/command | ||
make | ||
./install | ||
|
||
|
||
cd ${PATH_PWD}/server | ||
./install | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
cc = gcc | ||
target = libgpio | ||
head_file = gpio.h | ||
|
||
src = $(wildcard *.c) | ||
src := $(filter-out %_py.c, $(src)) | ||
target = libgpio.so | ||
head_file = gpio.h | ||
all: | ||
gcc -shared -fPIC $(src) -o $(target) | ||
install: | ||
cp ${target} /usr/lib/ | ||
objects = $(patsubst %.c,%.o,$(src)) | ||
|
||
all: $(target).a $(target).so | ||
|
||
$(target).a: $(objects) | ||
ar -rc $@ $^ | ||
|
||
$(target).so: $(src) | ||
gcc -fPIC -shared $^ -o $@ | ||
|
||
|
||
install:all | ||
cp $(target).a $(target).so /usr/lib/ | ||
cp ${head_file} /usr/include | ||
|
||
clean: | ||
-rm $(target) | ||
-rm /usr/include/${head_file} | ||
-rm $(objects) | ||
-rm $(target).a $(target).so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#ifndef BOARD_PIN_H | ||
#define BOARD_PIN_H | ||
|
||
#define _BOARD_DEF_WANUTPI_1B 1 | ||
#define _BOARD_DEF_WANUTPI_1B_EMMC 2 | ||
|
||
#define PH_NUM_ERROR -1 | ||
#define PH_5V -2 | ||
#define PH_3V3 -3 | ||
#define PH_GND -4 | ||
#define PH_NC -1 | ||
#define PH_COLOR_BLACK 0 | ||
#define PH_COLOR_RED 1 | ||
#define PH_COLOR_GREEEN 2 | ||
#define PH_COLOR_BLUE 3 | ||
#define PH_COLOR_YELLOW 4 | ||
|
||
struct BOARD_PIN | ||
{ | ||
int pin_num; // 在板上的引脚编号 | ||
int gpio_num; // 芯片上的gpio编号 | ||
char *name; // 要显示出来的引脚名称 | ||
int color; // 引脚颜色 | ||
}; | ||
#define DEF_A_BOARD_PIN(_pin_num, _gpio_num, _name, _color) \ | ||
{ \ | ||
.pin_num = _pin_num, \ | ||
.gpio_num = _gpio_num, \ | ||
.name = _name, \ | ||
.color = _color, \ | ||
} | ||
|
||
struct BOARD_PIN_PER | ||
{ | ||
int count; // 共有几个引脚 | ||
int *pins; // 哪些引脚 | ||
int *modes; // 对应引脚需要设置为什么模式 | ||
}; | ||
|
||
struct BOARD_DESC | ||
{ | ||
char *model; // 设备树model字段 | ||
int pin_num; // 共有几个pin脚 | ||
struct BOARD_PIN *pins; // 描述板子所带的所有引脚 | ||
struct BOARD_PIN_PER *pwms; | ||
struct BOARD_PIN_PER *uarts; | ||
struct BOARD_PIN_PER *spis; | ||
struct BOARD_PIN_PER *i2cs; | ||
}; | ||
extern struct BOARD_DESC walnutpi_1b; | ||
extern struct BOARD_DESC walnutpi_1b_emmc; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "board-pin.h" | ||
|
||
struct BOARD_PIN walnutpi1b_emmc_pins[] = { | ||
DEF_A_BOARD_PIN(0, 0, "", 0), | ||
DEF_A_BOARD_PIN(1, PH_3V3, "3.3v", PH_COLOR_YELLOW), | ||
DEF_A_BOARD_PIN(2, PH_5V, "5v", PH_COLOR_RED), | ||
DEF_A_BOARD_PIN(3, 264, "PI8", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(4, PH_5V, "5v", PH_COLOR_RED), | ||
DEF_A_BOARD_PIN(5, 263, "PI7", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(6, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(7, PH_NC, "----", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(8, 261, "PI5", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(9, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(10, 262, "PI6", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(11, PH_NC, "----", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(12, PH_NC, "----", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(13, PH_NC, "----", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(14, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(15, 267, "PI11", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(16, 268, "PI12", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(17, PH_3V3, "3.3v", PH_COLOR_YELLOW), | ||
DEF_A_BOARD_PIN(18, PH_NC, "----", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(19, 231, "PH7", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(20, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(21, 232, "PH8", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(22, PH_NC, "----", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(23, 230, "PH6", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(24, 229, "PH5", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(25, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(26, 233, "PH9", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(27, 266, "PI10", PH_COLOR_BLUE), | ||
DEF_A_BOARD_PIN(28, 265, "PI9", PH_COLOR_BLUE), | ||
DEF_A_BOARD_PIN(29, 256, "PI0", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(30, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(31, 257, "PI1", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(32, 272, "PI16", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(33, 258, "PI2", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(34, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(35, 259, "PI3", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(36, 271, "PI15", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(37, 260, "PI4", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(38, 269, "PI13", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(39, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(40, 270, "PI14", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(41, 76, "KEY", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(42, 71, "LED", PH_COLOR_BLACK), | ||
}; | ||
static int walnutpi1b_emmc_pwms_pins[] = {15, 16, 38, 40}; | ||
static int walnutpi1b_emmc_pwms_modes[] = {5, 5, 5, 5}; | ||
static struct BOARD_PIN_PER walnutpi1b_emmc_pwms = | ||
{ | ||
.count = 4, | ||
.pins = walnutpi1b_emmc_pwms_pins, | ||
.modes = walnutpi1b_emmc_pwms_modes, | ||
}; | ||
|
||
static int walnutpi1b_emmc_uarts_pins[] = {8, 10, 38, 40}; | ||
static int walnutpi1b_emmc_uarts_modes[] = {3, 3, 3, 3}; | ||
static struct BOARD_PIN_PER walnutpi1b_emmc_uarts = | ||
{ | ||
.count = 4, | ||
.pins = walnutpi1b_emmc_uarts_pins, | ||
.modes = walnutpi1b_emmc_uarts_modes, | ||
}; | ||
static int walnutpi1b_emmc_spis_pins[] = {19, 21, 23, 24, 26}; | ||
static int walnutpi1b_emmc_spis_modes[] = {4, 4, 4, 4, 4}; | ||
static struct BOARD_PIN_PER walnutpi1b_emmc_spis = | ||
{ | ||
.count = 4, | ||
.pins = walnutpi1b_emmc_spis_pins, | ||
.modes = walnutpi1b_emmc_spis_modes, | ||
}; | ||
static int walnutpi1b_emmc_i2cs_pins[] = {3, 5, 27, 28}; | ||
static int walnutpi1b_emmc_i2cs_modes[] = {5, 5, 5, 5}; | ||
static struct BOARD_PIN_PER walnutpi1b_emmc_i2cs = | ||
{ | ||
.count = 4, | ||
.pins = walnutpi1b_emmc_i2cs_pins, | ||
.modes = walnutpi1b_emmc_i2cs_modes, | ||
}; | ||
struct BOARD_DESC walnutpi_1b_emmc = { | ||
.model = "walnutpi-1b-emmc", | ||
.pin_num = 42, | ||
.pins = walnutpi1b_emmc_pins, | ||
.pwms = &walnutpi1b_emmc_pwms, | ||
.uarts = &walnutpi1b_emmc_uarts, | ||
.spis = &walnutpi1b_emmc_spis, | ||
.i2cs = &walnutpi1b_emmc_i2cs, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "board-pin.h" | ||
|
||
struct BOARD_PIN walnutpi1b_pins[] = { | ||
DEF_A_BOARD_PIN(0, 0, "", 0), | ||
DEF_A_BOARD_PIN(1, PH_3V3, "3.3v", PH_COLOR_YELLOW), | ||
DEF_A_BOARD_PIN(2, PH_5V, "5v", PH_COLOR_RED), | ||
DEF_A_BOARD_PIN(3, 264, "PI8", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(4, PH_5V, "5v", PH_COLOR_RED), | ||
DEF_A_BOARD_PIN(5, 263, "PI7", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(6, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(7, 72, "PC8", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(8, 261, "PI5", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(9, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(10, 262, "PI6", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(11, 73, "PC9", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(12, 74, "PC10", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(13, 75, "PC11", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(14, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(15, 267, "PI11", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(16, 268, "PI12", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(17, PH_3V3, "3.3v", PH_COLOR_YELLOW), | ||
DEF_A_BOARD_PIN(18, 78, "PC14", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(19, 231, "PH7", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(20, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(21, 232, "PH8", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(22, 79, "PC15", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(23, 230, "PH6", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(24, 229, "PH5", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(25, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(26, 233, "PH9", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(27, 266, "PI10", PH_COLOR_BLUE), | ||
DEF_A_BOARD_PIN(28, 265, "PI9", PH_COLOR_BLUE), | ||
DEF_A_BOARD_PIN(29, 256, "PI0", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(30, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(31, 257, "PI1", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(32, 272, "PI16", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(33, 258, "PI2", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(34, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(35, 259, "PI3", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(36, 271, "PI15", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(37, 260, "PI4", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(38, 269, "PI13", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(39, PH_GND, "GND", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(40, 270, "PI14", PH_COLOR_GREEEN), | ||
DEF_A_BOARD_PIN(41, 76, "KEY", PH_COLOR_BLACK), | ||
DEF_A_BOARD_PIN(42, 77, "LED", PH_COLOR_BLACK), | ||
}; | ||
static int walnutpi1b_pwms_pins[] = {15, 16, 38, 40}; | ||
static int walnutpi1b_pwms_modes[] = {5, 5, 5, 5}; | ||
static struct BOARD_PIN_PER walnutpi1b_pwms = | ||
{ | ||
.count = 4, | ||
.pins = walnutpi1b_pwms_pins, | ||
.modes = walnutpi1b_pwms_modes, | ||
}; | ||
|
||
static int walnutpi1b_uarts_pins[] = {8, 10, 38, 40}; | ||
static int walnutpi1b_uarts_modes[] = {3, 3, 3, 3}; | ||
static struct BOARD_PIN_PER walnutpi1b_uarts = | ||
{ | ||
.count = 4, | ||
.pins = walnutpi1b_uarts_pins, | ||
.modes = walnutpi1b_uarts_modes, | ||
}; | ||
static int walnutpi1b_spis_pins[] = {19, 21, 23, 24, 26}; | ||
static int walnutpi1b_spis_modes[] = {4, 4, 4, 4, 4}; | ||
static struct BOARD_PIN_PER walnutpi1b_spis = | ||
{ | ||
.count = 4, | ||
.pins = walnutpi1b_spis_pins, | ||
.modes = walnutpi1b_spis_modes, | ||
}; | ||
static int walnutpi1b_i2cs_pins[] = {3, 5, 27, 28}; | ||
static int walnutpi1b_i2cs_modes[] = {5, 5, 5, 5}; | ||
static struct BOARD_PIN_PER walnutpi1b_i2cs = | ||
{ | ||
.count = 4, | ||
.pins = walnutpi1b_i2cs_pins, | ||
.modes = walnutpi1b_i2cs_modes, | ||
}; | ||
struct BOARD_DESC walnutpi_1b = { | ||
.model = "walnutpi-1b", | ||
.pin_num = 42, | ||
.pins = walnutpi1b_pins, | ||
.pwms = &walnutpi1b_pwms, | ||
.uarts = &walnutpi1b_uarts, | ||
.spis = &walnutpi1b_spis, | ||
.i2cs = &walnutpi1b_i2cs, | ||
}; |
Oops, something went wrong.