Skip to content

Commit

Permalink
Added support for Raspberry pi 4B+
Browse files Browse the repository at this point in the history
Move these wires:
- pin 12 BCM 18 to pin 19 BCM 10 (I2C slave SDA, green)
- pin 37 BCM 19 to pin 23 BCM 11 (I2C slave SCL, gray)
Keep these wires the same:
- pin 1 3V3 Power (VCC, red)
- pin 3 BCM 2 (I2C master SDA, blue)
- pin 5 BCM 3 (I2C master SCL, yellow)
- pin 9 Ground (GND, black)
  • Loading branch information
Lucas van der Ploeg committed Apr 2, 2020
1 parent 5aad09b commit 2f1c749
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 26 deletions.
Binary file modified dgtpicom
Binary file not shown.
122 changes: 96 additions & 26 deletions dgtpicom.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "dgtpicom_dgt3000.h"

int ww;
char piModel;

// while loop
void *wl(void *x) {
Expand Down Expand Up @@ -213,7 +214,10 @@ int dgtpicom_init() {
memset(&bug,0,sizeof(debug_t));
#endif

if (checkPiModel()==1)
piModel = checkPiModel();
if (piModel==4)
base=0xfe000000;
else if (piModel==1)
base=0x20000000;
else
base=0x3f000000;
Expand Down Expand Up @@ -278,29 +282,67 @@ int dgtpicom_init() {
#endif
return ERROR_LINES;
}
if ((*(gpio+1) & 0x07000000) == 0x01000000) {
#ifdef debug
printf("Error, GPIO18 configured as output, in use? We asume not a DGTPI\n");
#endif
return ERROR_LINES;
if (piModel==4)
{
if ((*(gpio+1) & 0x07) == 0x01) {
#ifdef debug
printf("Error, GPIO10 configured as output, in use? We asume not a DGTPI\n");
#endif
return ERROR_LINES;
}
if ((*(gpio+1) & 0x38) == 0x08) {
#ifdef debug
printf("Error, GPIO11 configured as output, in use? We asume not a DGTPI\n");
#endif
return ERROR_LINES;
}
}
if ((*(gpio+1) & 0x38000000) == 0x08000000) {
#ifdef debug
printf("Error, GPIO19 configured as output, in use? We asume not a DGTPI\n");
#endif
return ERROR_LINES;
else
{
if ((*(gpio+1) & 0x07000000) == 0x01000000) {
#ifdef debug
printf("Error, GPIO18 configured as output, in use? We asume not a DGTPI\n");
#endif
return ERROR_LINES;
}
if ((*(gpio+1) & 0x38000000) == 0x08000000) {
#ifdef debug
printf("Error, GPIO19 configured as output, in use? We asume not a DGTPI\n");
#endif
return ERROR_LINES;
}
}
// pinmode GPIO2,GPIO3=input
*gpio &= 0xfffff03f;
// pinmode GPIO18,GPIO19=input
*(gpio+1) &= 0xc0ffffff;
if (piModel==4)
{
// pinmode GPIO10,GPIO11=input
*(gpio+1) &= 0xffffffc0;
}
else
{
// pinmode GPIO18,GPIO19=input
*(gpio+1) &= 0xc0ffffff;
}
usleep(1);
// all pins hi through pullup?
if ((*gpioin & 0xc000c)!=0xc000c) {
#ifdef debug
printf("Error, pin(s) low, shortcircuit, or no connection?\n");
#endif
return ERROR_LINES;
if (piModel==4)
{
if ((*gpioin & 0x0c0c)!=0x0c0c) {
#ifdef debug
printf("Error, pin(s) low, shortcircuit, or no connection?\n");
#endif
return ERROR_LINES;
}
}
else
{
if ((*gpioin & 0xc000c)!=0xc000c) {
#ifdef debug
printf("Error, pin(s) low, shortcircuit, or no connection?\n");
#endif
return ERROR_LINES;
}
}
/* // check SDA connection
// gpio18 low
Expand Down Expand Up @@ -667,14 +709,23 @@ void dgtpicom_stop() {

// pinmode GPIO2,GPIO3=input
*gpio &= 0xfffff03f;
// pinmode GPIO18,GPIO19=input
*(gpio+1) &= 0xc0ffffff;
if (piModel==4)
{
// pinmode GPIO10,GPIO11=input
*(gpio+1) &= 0xffffffc0;
}
else
{
// pinmode GPIO18,GPIO19=input
*(gpio+1) &= 0xc0ffffff;
}
}






// send a wake command to the dgt3000
int dgt3000Wake() {
int e;
Expand Down Expand Up @@ -1492,8 +1543,16 @@ void i2cReset() {

// pinmode GPIO2,GPIO3=input (togle via input to reset i2C master(sometimes hangs))
*gpio &= 0xfffff03f;
// pinmode GPIO18,GPIO19=input (togle via input to reset)
*(gpio+1) &= 0x00ffffff;
if (piModel==4)
{
// pinmode GPIO10,GPIO11=input (togle via input to reset)
*(gpio+1) &= 0xffffffc0;
}
else
{
// pinmode GPIO18,GPIO19=input (togle via input to reset)
*(gpio+1) &= 0xc0ffffff;
}
// send something in case master hangs
//*i2cMasterFIFO = 0x69;
*i2cMasterDLEN = 0;
Expand All @@ -1507,8 +1566,16 @@ void i2cReset() {
*i2cMaster = 10;
// pinmode GPIO2,GPIO3=ALT0
*gpio |= 0x900;
// pinmode GPIO18,GPIO19=ALT3
*(gpio+1) |= 0x3f000000;
if (piModel==4)
{
// pinmode GPIO18,GPIO19=ALT3
*(gpio+1) |= 0x0000003f;
}
else
{
// pinmode GPIO18,GPIO19=ALT3
*(gpio+1) |= 0x3f000000;
}

usleep(1000); // not tested! some delay maybe needed

Expand Down Expand Up @@ -1588,15 +1655,18 @@ int checkPiModel() {
// looking for the revision....
while (fgets (line, 120, cpuFd) != NULL)
if (strncmp (line, "Revision", 8) == 0) {
if ( line[13] == '2' ) { // BCM2837
if ( line[13] == '3' ) { // BCM2838
fclose(cpuFd);
return 4; // PI 4b
} else if ( line[13] == '2' ) { // BCM2837
fclose(cpuFd);
return 3; // PI 3b(+)
} else if ( line[13] == '1' ) { // BCM2836
fclose(cpuFd);
return 2; // PI 2b
} else { // BCM2835
fclose(cpuFd);
return 1; // PI a, b, zero (+)
return 1; // PI a, b, zero (+)
}
}
fclose(cpuFd);
Expand Down
Binary file modified dgtpicom.so
Binary file not shown.

1 comment on commit 2f1c749

@hamilton53
Copy link

@hamilton53 hamilton53 commented on 2f1c749 Jul 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move these wires
pin 37 BCM 19 to pin 23 BCM 11 (I2C slave SCL, gray)

Should read "pin 35" and not pin 37

Thanks for the updated dgtpicom files that allow me to boot Pico on a 4b.

Please sign in to comment.