This commit is contained in:
rohoog 2021-05-15 16:26:53 +02:00 committed by GitHub
commit 176062d8f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 233 additions and 79 deletions

2
RaspberryPi&JetsonNano/c/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
bin/
epd

View file

@ -29,6 +29,7 @@
******************************************************************************/
#include "DEV_Config.h"
#include <fcntl.h>
#include <time.h>
/**
* GPIO
@ -85,6 +86,31 @@ UBYTE DEV_Digital_Read(UWORD Pin)
return Read_value;
}
void DEV_Digital_Wait(UWORD Pin, UBYTE Value)
{
#ifdef RPI
#ifdef USE_BCM2835_LIB
do {
DEV_Delay_ms(10);
} while(bcm2835_gpio_lev(Pin) != Value);
#elif USE_WIRINGPI_LIB
do {
DEV_Delay_ms(10);
} while(digitalRead(Pin) != Value);
#elif USE_DEV_LIB
SYSFS_GPIO_Wait(Pin, Value);
#endif
#endif
#ifdef JETSON
#ifdef USE_DEV_LIB
SYSFS_GPIO_Wait(Pin, Value);
#elif USE_HARDWARE_LIB
Debug("not support");
#endif
#endif
}
/**
* SPI
**/
@ -185,10 +211,10 @@ void DEV_Delay_ms(UDOUBLE xms)
#elif USE_WIRINGPI_LIB
delay(xms);
#elif USE_DEV_LIB
UDOUBLE i;
for(i=0; i < xms; i++) {
usleep(1000);
}
struct timespec tv;
tv.tv_nsec=(xms%1000)*1000000;
tv.tv_sec=xms/1000;
nanosleep(&tv, NULL);
#endif
#endif
@ -229,7 +255,7 @@ static int DEV_Equipment_Testing(void)
if(i<5) {
printf("Unrecognizable\r\n");
} else {
char RPI_System[10] = {"Raspbian"};
char RPI_System[10] = {"Debian"};
for(i=0; i<6; i++) {
if(RPI_System[i]!= value_str[i]) {
printf("Please make JETSON !!!!!!!!!!\r\n");
@ -366,10 +392,10 @@ void DEV_Module_Exit(void)
DEV_Digital_Write(EPD_DC_PIN, 0);
DEV_Digital_Write(EPD_RST_PIN, 0);
#elif USE_DEV_LIB
DEV_HARDWARE_SPI_end();
DEV_Digital_Write(EPD_CS_PIN, 0);
DEV_Digital_Write(EPD_DC_PIN, 0);
DEV_Digital_Write(EPD_RST_PIN, 0);
DEV_HARDWARE_SPI_end();
#endif
#elif JETSON

View file

@ -96,6 +96,7 @@ extern int EPD_BUSY_PIN;
/*------------------------------------------------------------------------------------------------------*/
void DEV_Digital_Write(UWORD Pin, UBYTE Value);
UBYTE DEV_Digital_Read(UWORD Pin);
void DEV_Digital_Wait(UWORD Pin, UBYTE Value);
void DEV_SPI_WriteByte(UBYTE Value);
void DEV_SPI_Write_nByte(uint8_t *pData, uint32_t Len);

View file

@ -36,6 +36,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/poll.h>
int SYSFS_GPIO_Export(int Pin)
{
@ -107,6 +108,32 @@ int SYSFS_GPIO_Direction(int Pin, int Dir)
return 0;
}
int SYSFS_GPIO_Edge(int Pin, int edge)
{
const char *edge_str[] = {"rising","falling","both"};
const int edge_str_l[] = {6, 7, 4};
char path[DIR_MAXSIZ];
int fd;
snprintf(path, DIR_MAXSIZ, "/sys/class/gpio/gpio%d/edge", Pin);
fd = open(path, O_WRONLY);
if (fd < 0) {
SYSFS_GPIO_Debug( "Set Edge failed: Pin%d\n", Pin);
return -1;
}
if (edge>2) edge=2;
if (write(fd, edge_str[edge], edge_str_l[edge]) < 0) {
SYSFS_GPIO_Debug("failed to set edge!\r\n");
return -1;
}
SYSFS_GPIO_Debug("Pin%d:%s edge\r\n", Pin, edge_str[edge]);
close(fd);
return 0;
}
int SYSFS_GPIO_Read(int Pin)
{
char path[DIR_MAXSIZ];
@ -122,6 +149,7 @@ int SYSFS_GPIO_Read(int Pin)
if (read(fd, value_str, 3) < 0) {
SYSFS_GPIO_Debug( "failed to read value!\n");
close(fd);
return -1;
}
@ -129,6 +157,50 @@ int SYSFS_GPIO_Read(int Pin)
return(atoi(value_str));
}
int SYSFS_GPIO_Wait(int Pin, int value)
{
char path[DIR_MAXSIZ];
char value_str[3];
int fd;
struct pollfd pfd[1];
SYSFS_GPIO_Edge(Pin, SYSFS_GPIO_BOTH);
snprintf(path, DIR_MAXSIZ, "/sys/class/gpio/gpio%d/value", Pin);
fd = open(path, O_RDONLY);
if (fd < 0) {
SYSFS_GPIO_Debug( "Read failed Pin%d\n", Pin);
return -1;
}
while (1) {
int n;
if (read(fd, value_str, 3) < 0) {
SYSFS_GPIO_Debug( "failed to read value!\n");
close(fd);
return -1;
}
if (atoi(value_str) == value) break;
pfd[0].fd=fd;
pfd[0].events=POLLPRI;
n = poll(pfd, 1, -1);
if (n < 0) {
SYSFS_GPIO_Debug( "poll failed: %m!\n");
close(fd);
return -1;
}
/* lseek(0) doesn't seem to work reliably */
close(fd);
fd = open(path, O_RDONLY);
if (fd < 0) {
SYSFS_GPIO_Debug( "open failed: %m\n");
return -1;
}
}
close(fd);
return 0;
}
int SYSFS_GPIO_Write(int Pin, int value)
{
const char s_values_str[] = "01";
@ -144,6 +216,7 @@ int SYSFS_GPIO_Write(int Pin, int value)
if (write(fd, &s_values_str[value == SYSFS_GPIO_LOW ? 0 : 1], 1) < 0) {
SYSFS_GPIO_Debug( "failed to write value!\n");
close(fd);
return -1;
}

View file

@ -39,6 +39,10 @@
#define SYSFS_GPIO_LOW 0
#define SYSFS_GPIO_HIGH 1
#define SYSFS_GPIO_RISING 0
#define SYSFS_GPIO_FALLING 1
#define SYSFS_GPIO_BOTH 2
#define NUM_MAXBUF 4
#define DIR_MAXSIZ 60
@ -78,5 +82,6 @@ int SYSFS_GPIO_Unexport(int Pin);
int SYSFS_GPIO_Direction(int Pin, int Dir);
int SYSFS_GPIO_Read(int Pin);
int SYSFS_GPIO_Write(int Pin, int value);
int SYSFS_GPIO_Wait(int Pin, int value);
#endif
#endif

View file

@ -330,18 +330,13 @@ Info:
uint8_t DEV_HARDWARE_SPI_TransferByte(uint8_t buf)
{
uint8_t rbuf[1];
tr.len = 1;
tr.tx_buf = (unsigned long)&buf;
tr.rx_buf = (unsigned long)rbuf;
//ioctl Operation, transmission of data
if ( ioctl(hardware_SPI.fd, SPI_IOC_MESSAGE(1), &tr) < 1 )
DEV_HARDWARE_SPI_Debug("can't send spi message\r\n");
rbuf[0] = buf;
DEV_HARDWARE_SPI_Transfer(rbuf, 1);
return rbuf[0];
}
/******************************************************************************
function: The SPI port reads a byte
function: The SPI port reads some bytes
parameter:
Info: Return read data
******************************************************************************/

View file

@ -36,6 +36,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/poll.h>
int SYSFS_GPIO_Export(int Pin)
{
@ -107,6 +108,32 @@ int SYSFS_GPIO_Direction(int Pin, int Dir)
return 0;
}
int SYSFS_GPIO_Edge(int Pin, int edge)
{
const char *edge_str[] = {"rising","falling","both"};
const int edge_str_l[] = {6, 7, 4};
char path[DIR_MAXSIZ];
int fd;
snprintf(path, DIR_MAXSIZ, "/sys/class/gpio/gpio%d/edge", Pin);
fd = open(path, O_WRONLY);
if (fd < 0) {
SYSFS_GPIO_Debug( "Set Edge failed: Pin%d\n", Pin);
return -1;
}
if (edge>2) edge=2;
if (write(fd, edge_str[edge], edge_str_l[edge]) < 0) {
SYSFS_GPIO_Debug("failed to set edge!\r\n");
return -1;
}
SYSFS_GPIO_Debug("Pin%d:%s edge\r\n", Pin, edge_str[edge]);
close(fd);
return 0;
}
int SYSFS_GPIO_Read(int Pin)
{
char path[DIR_MAXSIZ];
@ -122,6 +149,7 @@ int SYSFS_GPIO_Read(int Pin)
if (read(fd, value_str, 3) < 0) {
SYSFS_GPIO_Debug( "failed to read value!\n");
close(fd);
return -1;
}
@ -129,6 +157,50 @@ int SYSFS_GPIO_Read(int Pin)
return(atoi(value_str));
}
int SYSFS_GPIO_Wait(int Pin, int value)
{
char path[DIR_MAXSIZ];
char value_str[3];
int fd;
struct pollfd pfd[1];
SYSFS_GPIO_Edge(Pin, SYSFS_GPIO_BOTH);
snprintf(path, DIR_MAXSIZ, "/sys/class/gpio/gpio%d/value", Pin);
fd = open(path, O_RDONLY);
if (fd < 0) {
SYSFS_GPIO_Debug( "Read failed Pin%d\n", Pin);
return -1;
}
while (1) {
int n;
if (read(fd, value_str, 3) < 0) {
SYSFS_GPIO_Debug( "failed to read value!\n");
close(fd);
return -1;
}
if (atoi(value_str) == value) break;
pfd[0].fd=fd;
pfd[0].events=POLLPRI;
n = poll(pfd, 1, -1);
if (n < 0) {
SYSFS_GPIO_Debug( "poll failed: %m!\n");
close(fd);
return -1;
}
/* lseek(0) doesn't seem to work reliably */
close(fd);
fd = open(path, O_RDONLY);
if (fd < 0) {
SYSFS_GPIO_Debug( "open failed: %m\n");
return -1;
}
}
close(fd);
return 0;
}
int SYSFS_GPIO_Write(int Pin, int value)
{
const char s_values_str[] = "01";
@ -144,6 +216,7 @@ int SYSFS_GPIO_Write(int Pin, int value)
if (write(fd, &s_values_str[value == LOW ? 0 : 1], 1) < 0) {
SYSFS_GPIO_Debug( "failed to write value!\n");
close(fd);
return -1;
}

View file

@ -39,6 +39,10 @@
#define LOW 0
#define HIGH 1
#define SYSFS_GPIO_RISING 0
#define SYSFS_GPIO_FALLING 1
#define SYSFS_GPIO_BOTH 2
#define NUM_MAXBUF 4
#define DIR_MAXSIZ 60
@ -80,5 +84,6 @@ int SYSFS_GPIO_Unexport(int Pin);
int SYSFS_GPIO_Direction(int Pin, int Dir);
int SYSFS_GPIO_Read(int Pin);
int SYSFS_GPIO_Write(int Pin, int value);
int SYSFS_GPIO_Wait(int Pin, int value);
#endif
#endif

View file

@ -147,10 +147,9 @@ parameter:
******************************************************************************/
void EPD_1IN54_ReadBusy(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return;
Debug("e-Paper busy\r\n");
while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy
DEV_Delay_ms(100);
}
DEV_Digital_Wait(EPD_BUSY_PIN, 0);
Debug("e-Paper busy release\r\n");
}

View file

@ -149,11 +149,9 @@ parameter:
******************************************************************************/
static void EPD_1IN54B_ReadBusy(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return;
Debug("e-Paper busy\r\n");
while(1) {
if(DEV_Digital_Read(EPD_BUSY_PIN) == 1)
break;
}
DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle
DEV_Delay_ms(200);
Debug("e-Paper busy release\r\n");
}

View file

@ -77,11 +77,9 @@ parameter:
******************************************************************************/
static void EPD_1IN54B_V2_ReadBusy(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return;
Debug("e-Paper busy\r\n");
while(1) {
if(DEV_Digital_Read(EPD_BUSY_PIN) == 0)
break;
}
DEV_Digital_Wait(EPD_BUSY_PIN, 0);
DEV_Delay_ms(200);
Debug("e-Paper busy release\r\n");
}

View file

@ -110,10 +110,9 @@ parameter:
******************************************************************************/
void EPD_2IN13_ReadBusy(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return;
Debug("e-Paper busy\r\n");
while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy
DEV_Delay_ms(100);
}
DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle
Debug("e-Paper busy release\r\n");
}

View file

@ -134,10 +134,9 @@ parameter:
******************************************************************************/
void EPD_2IN13_V2_ReadBusy(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return;
Debug("e-Paper busy\r\n");
while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy
DEV_Delay_ms(100);
}
DEV_Digital_Wait(EPD_BUSY_PIN, 0);
Debug("e-Paper busy release\r\n");
}

View file

@ -129,10 +129,9 @@ parameter:
******************************************************************************/
void EPD_2IN13BC_ReadBusy(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return;
Debug("e-Paper busy\r\n");
while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) {
DEV_Delay_ms(100);
}
DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle
Debug("e-Paper busy release\r\n");
}

View file

@ -96,11 +96,10 @@ parameter:
******************************************************************************/
static void EPD_2IN66_ReadBusy(void)
{
DEV_Delay_ms(200);
if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return;
Debug("e-Paper busy\r\n");
DEV_Delay_ms(200);
while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy
DEV_Delay_ms(5);
}
DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle
DEV_Delay_ms(100);
Debug("e-Paper busy release\r\n");
}

View file

@ -190,10 +190,9 @@ parameter:
******************************************************************************/
static void EPD_2IN7B_ReadBusy(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return;
Debug("e-Paper busy\r\n");
while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //0: busy, 1: idle
DEV_Delay_ms(100);
}
DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle
Debug("e-Paper busy release\r\n");
}

View file

@ -142,11 +142,10 @@ parameter:
******************************************************************************/
void EPD_2IN9_ReadBusy(void)
{
Debug("e-Paper busy\r\n");
DEV_Delay_ms(100);
while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy
DEV_Delay_ms(100);
}
if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return;
Debug("e-Paper busy\r\n");
DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle
Debug("e-Paper busy release\r\n");
}

View file

@ -130,10 +130,9 @@ parameter:
******************************************************************************/
void EPD_2IN9BC_ReadBusy(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return;
Debug("e-Paper busy\r\n");
while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //LOW: idle, HIGH: busy
DEV_Delay_ms(100);
}
DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle
Debug("e-Paper busy release\r\n");
}

View file

@ -133,11 +133,9 @@ static void EPD_3IN7_SendData(UBYTE Data)
static void EPD_3IN7_ReadBusy_HIGH(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return;
Debug("e-Paper busy\r\n");
UBYTE busy;
do {
busy = DEV_Digital_Read(EPD_BUSY_PIN);
} while(busy);
DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle
DEV_Delay_ms(200);
Debug("e-Paper busy release\r\n");
}

View file

@ -130,10 +130,9 @@ parameter:
******************************************************************************/
void EPD_4IN2BC_ReadBusy(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return;
Debug("e-Paper busy\r\n");
while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //0: busy, 1: idle
DEV_Delay_ms(100);
}
DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle
Debug("e-Paper busy release\r\n");
}

View file

@ -133,10 +133,9 @@ parameter:
******************************************************************************/
static void EPD_5IN83_ReadBusy(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return;
Debug("e-Paper busy\r\n");
while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //LOW: idle, HIGH: busy
DEV_Delay_ms(100);
}
DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle
Debug("e-Paper busy release\r\n");
}

View file

@ -133,10 +133,9 @@ parameter:
******************************************************************************/
void EPD_7IN5_ReadBusy(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 1) return;
Debug("e-Paper busy\r\n");
while(DEV_Digital_Read(EPD_BUSY_PIN) == 0) { //LOW: idle, HIGH: busy
DEV_Delay_ms(100);
}
DEV_Digital_Wait(EPD_BUSY_PIN, 1); //0: busy, 1: idle
Debug("e-Paper busy release\r\n");
}

View file

@ -77,10 +77,10 @@ parameter:
******************************************************************************/
static void EPD_7IN5_HD_WaitUntilIdle(void)
{
DEV_Delay_ms(10);
if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return;
Debug("e-Paper busy\r\n");
do{
DEV_Delay_ms(10);
}while(DEV_Digital_Read(EPD_BUSY_PIN) == 1);
DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle
DEV_Delay_ms(200);
Debug("e-Paper busy release\r\n");

View file

@ -77,10 +77,9 @@ parameter:
******************************************************************************/
void EPD_7IN5B_HD_WaitUntilIdle(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return;
Debug("e-Paper busy\r\n");
while(DEV_Digital_Read(EPD_BUSY_PIN)){
DEV_Delay_ms(10);
}
DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle
DEV_Delay_ms(200);
Debug("e-Paper busy release\r\n");
}

View file

@ -76,17 +76,9 @@ parameter:
******************************************************************************/
static void EPD_1IN54_V2_ReadBusy(void)
{
if(DEV_Digital_Read(EPD_BUSY_PIN) == 0) return;
Debug("e-Paper busy\r\n");
// UBYTE busy;
// do {
// EPD_1IN54_V2_SendCommand(0x71);
// busy = DEV_Digital_Read(EPD_BUSY_PIN);
// busy = !(busy & 0x01);
// } while(busy);
// DEV_Delay_ms(200);
while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy
DEV_Delay_ms(100);
}
DEV_Digital_Wait(EPD_BUSY_PIN, 0); //1: busy, 0: idle
Debug("e-Paper busy release\r\n");
}