From: Arjen Baart Date: Thu, 2 Apr 2020 06:11:59 +0000 (+0200) Subject: First test for curtain control X-Git-Url: http://www.andromeda.nl/gitweb/?a=commitdiff_plain;h=808674036a5a9ec9cb2bb02c82362462a42c4404;p=wakeup.git First test for curtain control --- diff --git a/src/Makefile.am b/src/Makefile.am index 0507dc3..702824d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,8 @@ -bin_PROGRAMS = wakeup pwm lightcontrol sunrise read_serial +bin_PROGRAMS = wakeup pwm curtain lightcontrol sunrise read_serial wakeup_SOURCES = wakeup.cpp event.cpp pwm_SOURCES = pwm.c +curtain_SOURCES = curtain.c lightcontrol_SOURCES = lightcontrol.cpp logging.cpp sunrise_SOURCES = sunrise.cpp diff --git a/src/curtain.c b/src/curtain.c new file mode 100644 index 0000000..46f2e61 --- /dev/null +++ b/src/curtain.c @@ -0,0 +1,111 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#define PAGE_SIZE (4*1024) +#define BLOCK_SIZE (4*1024) + +/* Direct access to GPIO hardware */ + +// Access from ARM Running Linux +// For Raspberry Pi 2 and Pi 3, change BCM2708_PERI_BASE to 0x3F000000 for the code to work. + +//#define BCM2708_PERI_BASE 0x20000000 +#define BCM2708_PERI_BASE 0x3F000000 +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */ + + +// I/O access +volatile unsigned *gpio; + + +// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y) +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3)) +#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3)) +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3)) + +#define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0 +#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0 + +#define GET_GPIO(g) (*(gpio+13)&(1<