stm32: common: fix SSD1306 initialization when LED is in SPI bus

Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
This commit is contained in:
Juha Niskanen
2020-10-23 13:31:21 +03:00
committed by Alan Carvalho de Assis
parent fabfc9ab10
commit 59faf8d8f4
2 changed files with 60 additions and 45 deletions
@@ -27,18 +27,6 @@
#include <nuttx/config.h> #include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Type Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Data * Public Data
****************************************************************************/ ****************************************************************************/
@@ -51,10 +39,6 @@ extern "C"
#define EXTERN extern #define EXTERN extern
#endif #endif
/****************************************************************************
* Inline Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Function Prototypes * Public Function Prototypes
****************************************************************************/ ****************************************************************************/
@@ -66,7 +50,7 @@ extern "C"
* Initialize and register the device * Initialize and register the device
* *
* Input Parameters: * Input Parameters:
* busno - The I2C bus number * busno - The I2C or SPI bus number
* *
* Returned Value: * Returned Value:
* Zero (OK) on success; a negated errno value on failure. * Zero (OK) on success; a negated errno value on failure.
+59 -28
View File
@@ -30,35 +30,16 @@
#include <nuttx/lcd/lcd.h> #include <nuttx/lcd/lcd.h>
#include <nuttx/lcd/ssd1306.h> #include <nuttx/lcd/ssd1306.h>
#include <nuttx/i2c/i2c_master.h> #include <nuttx/i2c/i2c_master.h>
#include <nuttx/spi/spi.h>
#include "stm32.h"
#include "stm32_i2c.h" #include "stm32_i2c.h"
#include "stm32_spi.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
FAR struct lcd_dev_s *g_lcddev; static FAR struct lcd_dev_s *g_lcddev;
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
@@ -68,7 +49,7 @@ FAR struct lcd_dev_s *g_lcddev;
* Name: board_ssd1306_initialize * Name: board_ssd1306_initialize
* *
* Description: * Description:
* Initialize and register the device * Initialize and register the device. I2C version.
* *
* Input Parameters: * Input Parameters:
* busno - The I2C bus number * busno - The I2C bus number
@@ -77,31 +58,32 @@ FAR struct lcd_dev_s *g_lcddev;
* Zero (OK) on success; a negated errno value on failure. * Zero (OK) on success; a negated errno value on failure.
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_LCD_SSD1306_I2C
int board_ssd1306_initialize(int busno) int board_ssd1306_initialize(int busno)
{ {
FAR struct i2c_master_s *i2c; FAR struct i2c_master_s *i2c;
const int devno = 0;
/* Initialize I2C */ /* Initialize I2C */
i2c = stm32_i2cbus_initialize(busno); i2c = stm32_i2cbus_initialize(busno);
if (!i2c) if (!i2c)
{ {
lcderr("ERROR: Failed to initialize I2C port %d\n", OLED_I2C_PORT); lcderr("ERROR: Failed to initialize I2C port %d\n", busno);
return -ENODEV; return -ENODEV;
} }
/* Bind the I2C port to the OLED */ /* Bind the I2C port to the OLED */
g_lcddev = ssd1306_initialize(i2c, NULL, 0); g_lcddev = ssd1306_initialize(i2c, NULL, devno);
if (!g_lcddev) if (!g_lcddev)
{ {
lcderr("ERROR: Failed to bind I2C port 1 to OLED %d: %d\n", devno); lcderr("ERROR: Failed to bind I2C port %d to OLED %d\n", busno, devno);
return -ENODEV; return -ENODEV;
} }
else else
{ {
lcdinfo("Bound I2C port %d to OLED %d\n", OLED_I2C_PORT, devno); lcdinfo("Bound I2C port %d to OLED %d\n", busno, devno);
/* And turn the OLED on */ /* And turn the OLED on */
@@ -109,6 +91,55 @@ int board_ssd1306_initialize(int busno)
return OK; return OK;
} }
} }
#endif
/****************************************************************************
* Name: board_ssd1306_initialize
*
* Description:
* Initialize and register the device. SPI version.
*
* Input Parameters:
* busno - The SPI bus number
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_LCD_SSD1306_SPI
int board_ssd1306_initialize(int busno)
{
FAR struct spi_dev_s *spi;
const int devno = 0;
/* Initialize SPI */
spi = stm32_spibus_initialize(busno);
if (!spi)
{
lcderr("ERROR: Failed to initialize SPI port %d\n", busno);
return -ENODEV;
}
/* Bind the SPI port to the OLED */
g_lcddev = ssd1306_initialize(spi, NULL, devno);
if (!g_lcddev)
{
lcderr("ERROR: Failed to bind SPI port %d to OLED %d\n", busno, devno);
return -ENODEV;
}
else
{
lcdinfo("Bound SPI port %d to OLED %d\n", busno, devno);
/* And turn the OLED on */
g_lcddev->setpower(g_lcddev, CONFIG_LCD_MAXPOWER);
return OK;
}
}
#endif
/**************************************************************************** /****************************************************************************
* Name: board_ssd1306_getdev * Name: board_ssd1306_getdev