works, but license issues due to bcm2835 lib

This commit is contained in:
2019-06-17 16:10:04 +01:00
parent 488ad98b96
commit f6f0fdac1e
8 changed files with 83 additions and 1 deletions

31
pyserialext/writec.c Normal file
View File

@ -0,0 +1,31 @@
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <linux/serial.h>
#include <errno.h>
#include <string.h>
#include <stdint.h>
#include <bcm2835.h>
const uint8_t DE_PIN = RPI_V2_GPIO_P1_11;
int set_rs485_mode(int fd) {
bcm2835_init();
bcm2835_gpio_fsel(DE_PIN, BCM2835_GPIO_FSEL_OUTP);
bcm2835_gpio_write(DE_PIN, LOW);
}
ssize_t writec(int fd, char *buf, size_t count) {
bcm2835_gpio_write(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);
return r;
}