1313static uint8_t u8Temp[40 ]; // for stretched character drawing
1414static volatile uint8_t u8End = 0 ;
1515static uint8_t u8Cache[MAX_CACHE];
16- struct gpiod_chip *chip = NULL ;
17- struct gpiod_line *lines[128 ];
16+ static struct gpiod_chip *chip = NULL ;
17+ static struct gpiod_line *lines[128 ];
1818//
1919// I/O wrapper functions for Linux
2020//
21- int digitalRead (int iPin)
22- {
23- return gpiod_line_get_value (lines[iPin]);
24- } /* digitalRead() */
25-
26- void digitalWrite (int iPin, int iState)
21+ static void digitalWrite (int iPin, int iState)
2722{
2823 gpiod_line_set_value (lines[iPin], iState);
2924} /* digitalWrite() */
3025
31- void _delay (int l)
26+ static void _delay (int l)
3227{
3328 usleep (l * 1000 );
3429}
3530
36- void pinMode (int iPin, int iMode)
31+ static void pinMode (int iPin, int iMode)
3732{
3833 if (chip == NULL ) {
3934 chip = gpiod_chip_open_by_name (" gpiochip0" );
@@ -48,12 +43,7 @@ void pinMode(int iPin, int iMode)
4843 }
4944} /* pinMode() */
5045
51- void delay (uint32_t u32 )
52- {
53- usleep (u32 *1000 );
54- } /* delay() */
55-
56- void initSPI (OBDISP *pOBD, int iSpeed, int iMOSI, int iCLK, int iCS)
46+ static void initSPI (OBDISP *pOBD, int iSpeed, int iMOSI, int iCLK, int iCS)
5747{
5848char szName[32 ];
5949
@@ -74,23 +64,26 @@ char szName[32];
7464} /* initSPI() */
7565
7666// Initialize the I2C bus on Linux
77- void I2CInit (BBI2C *pI2C, uint32_t iClock)
67+ static void I2CInit (BBI2C *pI2C, uint32_t iClock)
7868{
7969char filename[32 ];
8070int iChannel = pI2C->iSDA ;
8171
72+ // Only try to initialize it if it hasn't already been initialized
73+ if (pI2C->file_i2c == -1 ) {
8274 sprintf (filename, " /dev/i2c-%d" , iChannel);
8375 if ((pI2C->file_i2c = open (filename, O_RDWR)) < 0 )
8476 {
8577 fprintf (stderr, " Failed to open the i2c bus\n " );
8678 return ;
8779 }
80+ }
8881} /* I2CInit() */
8982//
9083// Test if an I2C address responds
9184// returns 1 for success, 0 for failure
9285//
93- uint8_t I2CTest (BBI2C *pI2C, uint8_t addr)
86+ static uint8_t I2CTest (BBI2C *pI2C, uint8_t addr)
9487{
9588uint8_t response = 0 ;
9689 if (ioctl (pI2C->file_i2c , I2C_SLAVE, addr) >= 0 ) {
@@ -104,7 +97,7 @@ uint8_t response = 0;
10497//
10598// Read n bytes from the given I2C address
10699//
107- int I2CRead (BBI2C *pI2C, uint8_t iAddr, uint8_t *pData, int iLen)
100+ static int I2CRead (BBI2C *pI2C, uint8_t iAddr, uint8_t *pData, int iLen)
108101{
109102int rc;
110103 ioctl (pI2C->file_i2c , I2C_SLAVE, iAddr);
@@ -114,7 +107,7 @@ int rc;
114107//
115108// Read n bytes from the given address, after setting the register number
116109//
117- int I2CReadRegister (BBI2C *pI2C, uint8_t iAddr, uint8_t u8Register, uint8_t *pData, int iLen)
110+ static int I2CReadRegister (BBI2C *pI2C, uint8_t iAddr, uint8_t u8Register, uint8_t *pData, int iLen)
118111{
119112int rc;
120113 // Reading from an I2C device involves first writing the 8-bit register
@@ -131,15 +124,15 @@ int rc;
131124//
132125// Write n bytes to the given address
133126//
134- int I2CWrite (BBI2C *pI2C, uint8_t iAddr, uint8_t *pData, int iLen)
127+ static int I2CWrite (BBI2C *pI2C, uint8_t iAddr, uint8_t *pData, int iLen)
135128{
136129int rc;
137130 ioctl (pI2C->file_i2c , I2C_SLAVE, iAddr);
138131 rc = write (pI2C->file_i2c , pData, iLen);
139132 return rc;
140133} /* I2CWrite() */
141134
142- void SPIWrite (OBDISP *pOBD, uint8_t *pData, int iLen)
135+ static void SPIWrite (OBDISP *pOBD, uint8_t *pData, int iLen)
143136{
144137struct spi_ioc_transfer spi;
145138
@@ -170,7 +163,7 @@ static void RawWrite(OBDISP *pOBD, unsigned char *pData, int iLen)
170163 }
171164} /* RawWrite() */
172165
173- void RawWriteData (OBDISP *pOBD, unsigned char *pData, int iLen)
166+ static void RawWriteData (OBDISP *pOBD, unsigned char *pData, int iLen)
174167{
175168uint8_t u8Temp[256 ];
176169 if (pOBD->com_mode == COM_I2C) {// I2C device
0 commit comments