writec stuff, gitignore not working ;-(

This commit is contained in:
2019-06-17 16:20:21 +01:00
parent 2b84200f9e
commit 10365339df
4 changed files with 11 additions and 10 deletions

View File

@ -1,7 +1,8 @@
CFLAGS=-I/opt/bcm2835/include
CFLAGS=
LIBS=-lwiringPi
writec.so: writec.o /opt/bcm2835/lib/libbcm2835.a
$(LD) -shared -o $@ $^
writec.so: writec.o
$(LD) -shared $(LIBS) -o $@ $^
writec.o: writec.c

View File

@ -6,25 +6,25 @@
#include <errno.h>
#include <string.h>
#include <stdint.h>
#include <bcm2835.h>
#include <wiringPi.h>
const uint8_t DE_PIN = RPI_V2_GPIO_P1_11;
const uint8_t DE_PIN = 0;
int set_rs485_mode(int fd) {
bcm2835_init();
bcm2835_gpio_fsel(DE_PIN, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_write(DE_PIN, LOW);
wiringPiSetup();
pinMode(DE_PIN, OUTPUT);
digitalWrite(DE_PIN, HIGH);
}
ssize_t writec(int fd, char *buf, size_t count) {
bcm2835_gpio_write(DE_PIN, LOW);
digitalWrite(DE_PIN, LOW);
ssize_t r = write(fd, buf, count);
uint8_t lsr;
do {
int r = ioctl(fd, TIOCSERGETLSR, &lsr);
} while (!(lsr & TIOCSER_TEMT));
bcm2835_gpio_write(DE_PIN, HIGH);
digitalWrite(DE_PIN, HIGH);
return r;
}

Binary file not shown.

Binary file not shown.