diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..20d5904 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "stdbool.h": "c" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 17bdc08..728b284 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,16 +2,16 @@ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", - "type":"shell", - "command": "make", - "echoCommand": true, - "problemMatcher": { - "base": "gcc", - }, "tasks": [ { "label": "all", - "args": ["all"], + "type":"shell", + "command": "make all -j4", + "problemMatcher": { + "base": "gcc", + "owner": "gcc", + "fileLocation":"absolute" + }, "group": { "kind": "build", "isDefault": true @@ -19,7 +19,23 @@ }, { "label": "clean", - "args": ["clean"], + "type":"shell", + "command": "make clean -j4", + "problemMatcher": { + "base": "gcc", + "owner": "gcc", + "fileLocation":"absolute" + }, + "group": { + "kind": "build", + "isDefault": true + } } - ] -} \ No newline at end of file + ], + "presentation": { + "focus": true, + "reveal": "always", + "panel": "shared", + "clear": true, + } +} diff --git a/inc/def.h b/inc/def.h deleted file mode 100644 index c4b2dc5..0000000 --- a/inc/def.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __INC_DEF_H__ -#define __INC_DEF_H__ - -#define HELLO "Hello world!" - -#endif // __INC_DEF_H__ \ No newline at end of file diff --git a/inc/gpio.h b/inc/gpio.h new file mode 100644 index 0000000..20c4216 --- /dev/null +++ b/inc/gpio.h @@ -0,0 +1,14 @@ +#ifndef __GPIO_H__ +#define __GPIO_H__ + +struct gpio { + unsigned int pin; +}; + +int gpio_open(const struct gpio *gpio); +int gpio_close(const struct gpio *gpio); +char gpio_read(const struct gpio *gpio); +void gpio_write(const struct gpio *gpio, char byte); +void gpio_toggle(const struct gpio *gpio); + +#endif diff --git a/src/gpio.c b/src/gpio.c new file mode 100644 index 0000000..08eb27b --- /dev/null +++ b/src/gpio.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +#include + +struct gpio_obj { + struct ftdi_context *ftdi; + bool is_open; +}; + +static struct gpio_obj gpio_obj = { + .ftdi = NULL, + .is_open = false, +}; + +int gpio_open(const struct gpio *gpio) +{ + int res; + if((gpio_obj.ftdi = ftdi_new()) == 0) { + syslog(LOG_ERR, "ftdi_new failed\n"); + return EXIT_FAILURE; + } + res = ftdi_usb_open(gpio_obj.ftdi, 0x0403, 0x6001); + if (res < 0 && res != -5) { + syslog(LOG_ERR, "unable to open ftdi device: %d (%s)\n", res, + ftdi_get_error_string(gpio_obj.ftdi)); + ftdi_free(gpio_obj.ftdi); + return EXIT_FAILURE; + } + + res = ftdi_set_bitmode(gpio_obj.ftdi, (char)gpio->pin, BITMODE_BITBANG); + if(res < 0) { + syslog(LOG_ERR, "unable to set bit bang mode: %d (%s)\n", res, + ftdi_get_error_string(gpio_obj.ftdi)); + ftdi_free(gpio_obj.ftdi); + return EXIT_FAILURE; + } + gpio_obj.is_open = true; + + return EXIT_SUCCESS; +} + +int gpio_close(const struct gpio *gpio) +{ + ftdi_usb_close(gpio_obj.ftdi); + ftdi_free(gpio_obj.ftdi); + + return EXIT_SUCCESS; +} + +char gpio_read(const struct gpio *gpio) +{ + return 0; +} + +void gpio_write(const struct gpio *gpio, char byte) +{ +} + +void gpio_toggle(const struct gpio *gpio) +{ +} diff --git a/src/main.c b/src/main.c index 08b36d2..2e1390c 100644 --- a/src/main.c +++ b/src/main.c @@ -3,8 +3,6 @@ #include #include -#include - #define LED 0x08 int main(int argc, char *argv[]) {