From 7dac0cccc846d4452293b47b40d43f6b50ebcc33 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 23 Oct 2018 10:07:31 +0200 Subject: POSIX: Improve GPIO emulation --- include/arch/posix/driver/gpio.h | 122 +++++++++++++++++++++++++++++++++++++-- src/arch/posix/Makefile.inc | 4 ++ src/arch/posix/driver/gpio.cc | 28 --------- 3 files changed, 120 insertions(+), 34 deletions(-) diff --git a/include/arch/posix/driver/gpio.h b/include/arch/posix/driver/gpio.h index 0995729..12e9121 100644 --- a/include/arch/posix/driver/gpio.h +++ b/include/arch/posix/driver/gpio.h @@ -1,17 +1,127 @@ #ifndef GPIO_H #define GPIO_H +#include + class GPIO { private: GPIO(const GPIO ©); - unsigned char ledstate; + unsigned int pin_dir, pin_pull, pin_out, pull_dir; +#ifdef GPIO_TRACE + void print_pinstate() { + unsigned int mask = 1; + for (unsigned char i=0; i < 32; i++) { + if (i == 0) { + fputs("▶ LED ", stdout); + } + else if (i == 8) { + fputs(" GPIO ", stdout); + } + else if (i == 16) { + fputs(" ", stdout); + } + else if (i == 24) { + fputs(" ", stdout); + } + if (pin_dir & mask) { + if (pin_out & (1< - -void GPIO::led_on(unsigned char id) -{ - if (id < 8) { - printf("▶ LED %3d on\n", id); - ledstate |= (1 << id); - } -} - -void GPIO::led_off(unsigned char id) -{ - if (id < 8) { - printf("▶ LED %3d off\n", id); - ledstate &= ~(1 << id); - } -} - -void GPIO::led_toggle(unsigned char id) -{ - if (id < 8) { - if (ledstate & (1 << id)) { - led_off(id); - } else { - led_on(id); - } - } -} GPIO gpio; -- cgit v1.2.3