raspi read test
This commit is contained in:
parent
75b9513a06
commit
4723a8c9fa
|
@ -102,6 +102,7 @@ uint8_t u8x8_gpio_and_delay_raspi_gpio_hal(u8x8_t *u8x8, uint8_t msg, uint8_t ar
|
|||
break; // arg_int=1: delay by 5us, arg_int = 4: delay by 1.25us
|
||||
|
||||
case U8X8_MSG_GPIO_MENU_SELECT:
|
||||
/* read pin level: uint8_t bcm2835_gpio_lev(uint8_t pin); */
|
||||
u8x8_SetGPIOResult(u8x8, /* get menu select pin state */ 0);
|
||||
break;
|
||||
case U8X8_MSG_GPIO_MENU_NEXT:
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
CFLAGS = -O -I../hal -I../../../csrc -DU8X8_USE_PINS -ffunction-sections -fdata-sections
|
||||
LDFLAGS = -Wl,--gc-sections
|
||||
|
||||
SRC = $(wildcard *.c) $(wildcard ../hal/*.c) $(wildcard ../../../csrc/*.c)
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
|
||||
main: $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o main
|
||||
|
||||
clean:
|
||||
-rm $(OBJ) main
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
|
||||
main.c
|
||||
|
||||
raspberry pi zero GPIO read test
|
||||
|
||||
For speedup run this example as root, either wis
|
||||
sudo ./main
|
||||
or by setting the superuser bit:
|
||||
sudo chown root:root ./main
|
||||
sudo chmod u+s ./main
|
||||
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include "bcm2835.h"
|
||||
#include "raspi_gpio_hal.h"
|
||||
|
||||
void sigtermhandler(int x)
|
||||
{
|
||||
puts("SIGTERM");
|
||||
bcm2835_close();
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
if (!bcm2835_init())
|
||||
exit(1);
|
||||
|
||||
signal(SIGTERM, sigtermhandler);
|
||||
|
||||
atexit((void (*) (void))bcm2835_close);
|
||||
|
||||
bcm2835_gpio_fsel(12, BCM2835_GPIO_FSEL_INPT);
|
||||
bcm2835_gpio_fsel(13, BCM2835_GPIO_FSEL_INPT);
|
||||
bcm2835_gpio_fsel(16, BCM2835_GPIO_FSEL_INPT);
|
||||
bcm2835_gpio_fsel(17, BCM2835_GPIO_FSEL_INPT);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
|
||||
delaynanoseconds(1000000UL);
|
||||
|
||||
printf("%d: %d ", 12, bcm2835_gpio_lev(12));
|
||||
printf("%d: %d ", 13, bcm2835_gpio_lev(13));
|
||||
printf("%d: %d ", 16, bcm2835_gpio_lev(16));
|
||||
printf("%d: %d ", 17, bcm2835_gpio_lev(17));
|
||||
puts("");
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue