stm32/common: Common LCD1602 based on PCF8574 Backpack

This commit is contained in:
Alan C. Assis
2021-03-14 19:04:43 -03:00
committed by Xiang Xiao
parent 43bce6d9b0
commit 0fb2059fd9
7 changed files with 191 additions and 143 deletions
@@ -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 */
+4
View File
@@ -46,6 +46,10 @@ ifeq ($(CONFIG_AUDIO_TONE),y)
CSRCS += stm32_tone.c
endif
ifeq ($(CONFIG_LCD_BACKPACK),y)
CSRCS += stm32_lcd_backpack.c
endif
ifeq ($(CONFIG_LCD_SSD1306),y)
CSRCS += stm32_ssd1306.c
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;
}