configs/stm32f103-minimum: Add OLED SSD1306 support to STM332F103-Minimum

This commit is contained in:
Alan Carvalho de Assis 2018-02-11 16:48:38 -06:00 committed by Gregory Nutt
parent 4e32861c3c
commit d3ddf2e05f
3 changed files with 139 additions and 6 deletions

View File

@ -46,12 +46,6 @@
# include <stdint.h>
#endif
#ifdef __KERNEL__
# include "stm32_rcc.h"
# include "stm32_sdio.h"
# include "stm32.h"
#endif
/************************************************************************************
* Pre-processor Definitions
************************************************************************************/

View File

@ -123,6 +123,10 @@ ifeq ($(CONFIG_INPUT_NUNCHUCK),y)
CSRCS += stm32_nunchuck.c
endif
ifeq ($(CONFIG_LCD_SSD1306_I2C),y)
CSRCS += stm32_ssd1306.c
endif
ifeq ($(CONFIG_LCD_ST7567),y)
CSRCS += stm32_lcd.c
endif

View File

@ -0,0 +1,135 @@
/****************************************************************************
* config/stm32f103-minimum/src/sam_ug2832hsweg04.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/lcd/lcd.h>
#include <nuttx/lcd/ssd1306.h>
#include <nuttx/i2c/i2c_master.h>
#include "stm32.h"
#include "stm32_i2c.h"
#include "stm32f103_minimum.h"
#ifdef CONFIG_NX_LCDDRIVER
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifndef CONFIG_LCD_SSD1306
# error "The OLED driver requires CONFIG_LCD_SSD1306 in the configuration"
#endif
#ifndef CONFIG_LCD_MAXPOWER
# define CONFIG_LCD_MAXPOWER 1
#endif
#define OLED_I2C_PORT 1 /* OLED display connected to I2C1 */
/****************************************************************************
* Private Data
****************************************************************************/
FAR struct i2c_master_s *g_i2c;
FAR struct lcd_dev_s *g_lcddev;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_lcd_initialize
****************************************************************************/
int board_lcd_initialize(void)
{
/* Initialize I2C */
g_i2c = stm32_i2cbus_initialize(OLED_I2C_PORT);
if (!g_i2c)
{
lcderr("ERROR: Failed to initialize I2C port %d\n", OLED_I2C_PORT);
return 0;
}
return 1;
}
/****************************************************************************
* Name: board_lcd_getdev
****************************************************************************/
FAR struct lcd_dev_s *board_lcd_getdev(int devno)
{
/* Bind the I2C port to the OLED */
g_lcddev = ssd1306_initialize(g_i2c, NULL, devno);
if (!g_lcddev)
{
lcderr("ERROR: Failed to bind SPI port 1 to OLED %d: %d\n", devno);
}
else
{
lcdinfo("Bound I2C port %d to OLED %d\n", OLED_I2C_PORT, devno);
/* And turn the OLED on */
(void)g_lcddev->setpower(g_lcddev, CONFIG_LCD_MAXPOWER);
return g_lcddev;
}
return NULL;
}
/****************************************************************************
* Name: board_lcd_uninitialize
****************************************************************************/
void board_lcd_uninitialize(void)
{
/* TO-FIX */
}
#endif /* CONFIG_NX_LCDDRIVER */