i2c scanning is now optional: i2cScan = 1

prints the 7 bit addresses in decimal
This commit is contained in:
penfold42 2018-07-17 18:25:15 +10:00
parent 1ed6fd45cd
commit c223b7aa57
3 changed files with 24 additions and 18 deletions

View file

@ -1130,25 +1130,26 @@ void DisplayI2CScan(int y_pos)
{ {
int BSCMaster = options.I2CBusMaster(); int BSCMaster = options.I2CBusMaster();
snprintf(tempBuffer, tempBufferSize, "Scanning i2c devices on bus %d ...\r\n", BSCMaster); snprintf(tempBuffer, tempBufferSize, "Scanning i2c bus %d ...\r\n", BSCMaster);
screen.PrintText(false, 0, y_pos += 16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK); screen.PrintText(false, 0, y_pos , tempBuffer, COLOUR_WHITE, COLOUR_BLACK);
RPI_I2CInit(BSCMaster, 1); RPI_I2CInit(BSCMaster, 1);
int address = 0;
for (int y=0; y<8; y++) int count=0;
int ptr = 0;
ptr = snprintf (tempBuffer+ptr, tempBufferSize-ptr, "Found ");
for (int address = 0; address<128; address++)
{ {
int x=0; if (RPI_I2CScan(BSCMaster, address))
for (x=0; x<16; x++)
{ {
int ret = RPI_I2CScan(BSCMaster, address); ptr += snprintf (tempBuffer+ptr, tempBufferSize-ptr, "%3d ", address);
if (ret) count++;
tempBuffer[x] = '*';
else
tempBuffer[x] = '.';
address++;
} }
tempBuffer[x] = 0;
screen.PrintText(false, 0, y_pos += 16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK);
} }
if (count == 0)
ptr += snprintf (tempBuffer+ptr, tempBufferSize-ptr, "Nothing");
screen.PrintText(false, 0, y_pos+16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK);
} }
static void CheckOptions() static void CheckOptions()
@ -1277,11 +1278,11 @@ extern "C"
snprintf(tempBuffer, tempBufferSize, "This is free software, and you are welcome to redistribute it."); snprintf(tempBuffer, tempBufferSize, "This is free software, and you are welcome to redistribute it.");
screen.PrintText(false, 0, y_pos+=16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK); screen.PrintText(false, 0, y_pos+=16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK);
if (options.ShowOptions()) if (options.I2CScan())
DisplayOptions(y_pos+32); DisplayI2CScan(y_pos+=32);
// if (options.I2CScan()) if (options.ShowOptions())
DisplayI2CScan(y_pos+32); DisplayOptions(y_pos+=32);
if (!options.QuickBoot()) if (!options.QuickBoot())
IEC_Bus::WaitMicroSeconds(3 * 1000000); IEC_Bus::WaitMicroSeconds(3 * 1000000);

View file

@ -142,6 +142,7 @@ Options::Options(void)
, screenHeight(768) , screenHeight(768)
, i2cBusMaster(1) , i2cBusMaster(1)
, i2cLcdAddress(0x3C) , i2cLcdAddress(0x3C)
, i2cScan(0)
, i2cLcdFlip(0) , i2cLcdFlip(0)
, i2cLcdOnContrast(127) , i2cLcdOnContrast(127)
, i2cLcdModel(0) , i2cLcdModel(0)
@ -216,6 +217,7 @@ void Options::Process(char* buffer)
ELSE_CHECK_DECIMAL_OPTION(screenHeight) ELSE_CHECK_DECIMAL_OPTION(screenHeight)
ELSE_CHECK_DECIMAL_OPTION(i2cBusMaster) ELSE_CHECK_DECIMAL_OPTION(i2cBusMaster)
ELSE_CHECK_DECIMAL_OPTION(i2cLcdAddress) ELSE_CHECK_DECIMAL_OPTION(i2cLcdAddress)
ELSE_CHECK_DECIMAL_OPTION(i2cScan)
ELSE_CHECK_DECIMAL_OPTION(i2cLcdFlip) ELSE_CHECK_DECIMAL_OPTION(i2cLcdFlip)
ELSE_CHECK_DECIMAL_OPTION(i2cLcdOnContrast) ELSE_CHECK_DECIMAL_OPTION(i2cLcdOnContrast)
ELSE_CHECK_DECIMAL_OPTION(i2cLcdDimContrast) ELSE_CHECK_DECIMAL_OPTION(i2cLcdDimContrast)

View file

@ -72,11 +72,13 @@ public:
inline unsigned int I2CBusMaster() const { return i2cBusMaster; } inline unsigned int I2CBusMaster() const { return i2cBusMaster; }
inline unsigned int I2CLcdAddress() const { return i2cLcdAddress; } inline unsigned int I2CLcdAddress() const { return i2cLcdAddress; }
inline unsigned int I2CScan() const { return i2cScan; }
inline unsigned int I2CLcdFlip() const { return i2cLcdFlip; } inline unsigned int I2CLcdFlip() const { return i2cLcdFlip; }
inline unsigned int I2CLcdOnContrast() const { return i2cLcdOnContrast; } inline unsigned int I2CLcdOnContrast() const { return i2cLcdOnContrast; }
inline unsigned int I2CLcdDimContrast() const { return i2cLcdDimContrast; } inline unsigned int I2CLcdDimContrast() const { return i2cLcdDimContrast; }
inline unsigned int I2CLcdDimTime() const { return i2cLcdDimTime; } inline unsigned int I2CLcdDimTime() const { return i2cLcdDimTime; }
inline unsigned int I2CLcdModel() const { return i2cLcdModel; } inline unsigned int I2CLcdModel() const { return i2cLcdModel; }
inline const char* GetLcdLogoName() const { return LcdLogoName; } inline const char* GetLcdLogoName() const { return LcdLogoName; }
inline float ScrollHighlightRate() const { return scrollHighlightRate; } inline float ScrollHighlightRate() const { return scrollHighlightRate; }
@ -114,6 +116,7 @@ private:
unsigned int i2cBusMaster; unsigned int i2cBusMaster;
unsigned int i2cLcdAddress; unsigned int i2cLcdAddress;
unsigned int i2cScan;
unsigned int i2cLcdFlip; unsigned int i2cLcdFlip;
unsigned int i2cLcdOnContrast; unsigned int i2cLcdOnContrast;
unsigned int i2cLcdDimContrast; unsigned int i2cLcdDimContrast;