mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
stm32/common: Common LCD1602 based on PCF8574 Backpack
This commit is contained in:
committed by
Xiang Xiao
parent
43bce6d9b0
commit
0fb2059fd9
@@ -0,0 +1,83 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/arm/stm32/common/include/stm32_lcd_backpack.h
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __STM32_LCD_BACKPACK_H
|
||||||
|
#define __STM32_LCD_BACKPACK_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Type Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Inline Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: board_lcd_backpack_init
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the LCD1602 display controlled by Backpack with PCF8574
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* devpath - The full path to the driver to register. E.g., "/dev/slcd0"
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno value on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int board_lcd_backpack_init(int devno, int busno, int rows, int cols);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __STM32_LCD_BACKPACK_H */
|
||||||
@@ -46,6 +46,10 @@ ifeq ($(CONFIG_AUDIO_TONE),y)
|
|||||||
CSRCS += stm32_tone.c
|
CSRCS += stm32_tone.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_LCD_BACKPACK),y)
|
||||||
|
CSRCS += stm32_lcd_backpack.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_LCD_SSD1306),y)
|
ifeq ($(CONFIG_LCD_SSD1306),y)
|
||||||
CSRCS += stm32_ssd1306.c
|
CSRCS += stm32_ssd1306.c
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/arm/stm32/common/src/stm32_lcd_backpack.c
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <nuttx/i2c/i2c_master.h>
|
||||||
|
#include <nuttx/lcd/pcf8574_lcd_backpack.h>
|
||||||
|
|
||||||
|
#include "stm32_i2c.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: board_lcd_backpack_init
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the LCD1602 display controlled by Backpack with PCF8574
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* devpath - The full path to the driver to register. E.g., "/dev/slcd0"
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success; a negated errno value on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int board_lcd_backpack_init(int devno, int busno, int rows, int cols)
|
||||||
|
{
|
||||||
|
FAR struct pcf8574_lcd_backpack_config_s cfg =
|
||||||
|
LCD_I2C_BACKPACK_CFG_SAINSMART;
|
||||||
|
FAR struct i2c_master_s *i2c;
|
||||||
|
char devpath[12];
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Setup the LCD row and cols size.
|
||||||
|
* Note: We are using the LCD_I2C_BACKPACK_CFG_SAINSMART config that
|
||||||
|
* defined the I2C Address to 0x27 to PCF8574. Double check if all
|
||||||
|
* the bits (pins) from PCF8574 connected to the LCD controller
|
||||||
|
* are correct with this LCD CFG definition.
|
||||||
|
*/
|
||||||
|
|
||||||
|
cfg.rows = rows;
|
||||||
|
cfg.cols = cols;
|
||||||
|
|
||||||
|
/* Initialize the I2C1 */
|
||||||
|
|
||||||
|
i2c = stm32_i2cbus_initialize(busno);
|
||||||
|
if (i2c == NULL)
|
||||||
|
{
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Regiter the Segment LCD */
|
||||||
|
|
||||||
|
snprintf(devpath, 12, "/dev/slcd%d", devno);
|
||||||
|
ret = pcf8574_lcd_backpack_register(devpath, i2c, &cfg);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
lcderr("ERROR: pcf8574_lcd_backpack_register(%s) failed: %d\n",
|
||||||
|
devpath, ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
@@ -67,10 +67,6 @@ ifeq ($(CONFIG_PWM),y)
|
|||||||
CSRCS += stm32_pwm.c
|
CSRCS += stm32_pwm.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_LCD_BACKPACK),y)
|
|
||||||
CSRCS += stm32_lcd_backpack.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_RGBLED),y)
|
ifeq ($(CONFIG_RGBLED),y)
|
||||||
CSRCS += stm32_rgbled.c
|
CSRCS += stm32_rgbled.c
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -137,6 +137,10 @@
|
|||||||
#include "board_qencoder.h"
|
#include "board_qencoder.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_LCD_BACKPACK
|
||||||
|
#include "stm32_lcd_backpack.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_USBADB
|
#ifdef CONFIG_USBADB
|
||||||
#include <nuttx/usb/adb.h>
|
#include <nuttx/usb/adb.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -224,7 +228,9 @@ int stm32_bringup(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_LCD_BACKPACK
|
#ifdef CONFIG_LCD_BACKPACK
|
||||||
ret = stm32_lcd_backpack_init("/dev/slcd0");
|
/* slcd:0, i2c:1, rows=2, cols=16 */
|
||||||
|
|
||||||
|
ret = board_lcd_backpack_init(0, 1, 2, 16);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, "Failed to initialize PCF8574 LCD, error %d\n", ret);
|
syslog(LOG_ERR, "Failed to initialize PCF8574 LCD, error %d\n", ret);
|
||||||
|
|||||||
@@ -1,126 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
* boards/arm/stm32/stm32f103-minimum/src/stm32_lcd_backpack.c
|
|
||||||
*
|
|
||||||
* Copyright (C) 2019 Alan Carvalho de Assis. All rights reserved.
|
|
||||||
* Author: Alan Carvalho de Assis <acassis@gmail.com>
|
|
||||||
*
|
|
||||||
* 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 <errno.h>
|
|
||||||
#include <debug.h>
|
|
||||||
|
|
||||||
#include <nuttx/i2c/i2c_master.h>
|
|
||||||
#include <nuttx/lcd/pcf8574_lcd_backpack.h>
|
|
||||||
|
|
||||||
#include "stm32.h"
|
|
||||||
#include "stm32f103_minimum.h"
|
|
||||||
|
|
||||||
#if defined(CONFIG_I2C) && defined(CONFIG_LCD_BACKPACK)
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#define LCDBP_I2C_PORTNO 1 /* PCF8574 connected to I2C1 */
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: stm32_lcd_backpack_init
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Initialize the LCD1602 display controlled by Backpack with PCF8574
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
* devpath - The full path to the driver to register. E.g., "/dev/slcd0"
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* Zero (OK) on success; a negated errno value on failure.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int stm32_lcd_backpack_init(FAR const char *devpath)
|
|
||||||
{
|
|
||||||
FAR struct pcf8574_lcd_backpack_config_s cfg =
|
|
||||||
LCD_I2C_BACKPACK_CFG_SAINSMART;
|
|
||||||
FAR struct i2c_master_s *i2c;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Setup the LCD row and cols size.
|
|
||||||
* Note: We are using the LCD_I2C_BACKPACK_CFG_SAINSMART config that
|
|
||||||
* defined the I2C Address to 0x27 to PCF8574. Double check if all
|
|
||||||
* the bits (pins) from PCF8574 connected to the LCD controller
|
|
||||||
* are correct with this LCD CFG definition.
|
|
||||||
*/
|
|
||||||
|
|
||||||
cfg.rows = 2;
|
|
||||||
cfg.cols = 16;
|
|
||||||
|
|
||||||
/* Initialize the I2C1 */
|
|
||||||
|
|
||||||
i2c = stm32_i2cbus_initialize(LCDBP_I2C_PORTNO);
|
|
||||||
if (i2c == NULL)
|
|
||||||
{
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_I2C_DRIVER
|
|
||||||
/* Register the I2C to get the "nsh> i2c bus" command working */
|
|
||||||
|
|
||||||
ret = i2c_register(i2c, LCDBP_I2C_PORTNO);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
rtcerr("ERROR: Failed to register I2C driver: %d\n", ret);
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Register the LCD BACKPACK PCF8574 driver at the specified location. */
|
|
||||||
|
|
||||||
ret = pcf8574_lcd_backpack_register(devpath, i2c, &cfg);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
lcderr("ERROR: pcf8574_lcd_backpack_register(%s) failed: %d\n",
|
|
||||||
devpath, ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* CONFIG_I2C && CONFIG_LCD_BACKPACK */
|
|
||||||
@@ -317,18 +317,6 @@ int stm32_rgbled_setup(void);
|
|||||||
int stm32_mcp2515initialize(FAR const char *devpath);
|
int stm32_mcp2515initialize(FAR const char *devpath);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: stm32_lcd_backpack_init
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Initialize and register the PCF8574 LCD Backpack driver.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_LCD_BACKPACK
|
|
||||||
int stm32_lcd_backpack_init(FAR const char *devpath);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: stm32_usbinitialize
|
* Name: stm32_usbinitialize
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user