You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by je...@apache.org on 2020/05/14 06:33:05 UTC
[incubator-nuttx] 05/23: stm32: move ssd1306 and tone driver
handling to common board logic
This is an automated email from the ASF dual-hosted git repository.
jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 35471e33dc0faebdb96b0e2d92896c1627dc73e0
Author: Matias Nitsche <mn...@dc.uba.ar>
AuthorDate: Fri May 8 15:10:02 2020 -0300
stm32: move ssd1306 and tone driver handling to common board logic
---
boards/arm/stm32/common/include/stm32_ssd1306.h | 96 +++++++++++++
boards/arm/stm32/common/include/stm32_tone.h | 84 ++++++++++++
boards/arm/stm32/common/src/Make.defs | 8 ++
boards/arm/stm32/common/src/stm32_ssd1306.c | 128 +++++++++++++++++
boards/arm/stm32/common/src/stm32_tone.c | 133 ++++++++++++++++++
.../nucleo-f303ze/src/{Makefile => Make.defs} | 6 +-
.../src/{stm32_ssd1306.c => stm32_lcd.c} | 40 ++----
boards/arm/stm32/stm32f103-minimum/src/Make.defs | 8 +-
.../stm32/stm32f103-minimum/src/stm32_bringup.c | 20 ++-
.../src/{stm32_ssd1306.c => stm32_lcd_ssd1306.c} | 45 ++----
.../src/{stm32_lcd.c => stm32_lcd_st7567.c} | 0
.../arm/stm32/stm32f103-minimum/src/stm32_tone.c | 151 ---------------------
12 files changed, 491 insertions(+), 228 deletions(-)
diff --git a/boards/arm/stm32/common/include/stm32_ssd1306.h b/boards/arm/stm32/common/include/stm32_ssd1306.h
new file mode 100644
index 0000000..cac37a3
--- /dev/null
+++ b/boards/arm/stm32/common/include/stm32_ssd1306.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+ * boards/arm/stm32/common/include/stm32_ssd1306.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_SSD1306_H
+#define __STM32_SSD1306_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_ssd1306_initialize
+ *
+ * Description:
+ * Initialize and register the device
+ *
+ * Input Parameters:
+ * busno - The I2C bus number
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_ssd1306_initialize(int busno);
+
+/****************************************************************************
+ * Name: board_ssd1306_getdev
+ *
+ * Description:
+ * Get the SSD1306 device driver instance
+ *
+ * Returned Value:
+ * Pointer to the instance
+ *
+ ****************************************************************************/
+
+FAR struct lcd_dev_s *board_ssd1306_getdev(void);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __STM32_SSD1306_H
diff --git a/boards/arm/stm32/common/include/stm32_tone.h b/boards/arm/stm32/common/include/stm32_tone.h
new file mode 100644
index 0000000..517db85
--- /dev/null
+++ b/boards/arm/stm32/common/include/stm32_tone.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * boards/arm/stm32/common/include/stm32_tone.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_TONE_H
+#define __STM32_TONE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+struct board_tone_config_s
+{
+ int pwm_timer; /* PWM timer number for tone generation */
+ int oneshot_timer; /* Oneshot timer for note intervals */
+ int oneshot_timer_resolution; /* Oneshot timer resolution in us */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_tone_initialize
+ *
+ * Input Parameters:
+ * cfg - Configuration for the driver
+ * devno - The device number, used to build the device path as /dev/toneN
+ *
+ * Description:
+ * Configure and initialize the tone generator.
+ *
+ ****************************************************************************/
+
+int board_tone_initialize(FAR struct board_tone_config_s *cfg, int devno);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __STM32_TONE_H
diff --git a/boards/arm/stm32/common/src/Make.defs b/boards/arm/stm32/common/src/Make.defs
index 58951f5..c308f1a 100644
--- a/boards/arm/stm32/common/src/Make.defs
+++ b/boards/arm/stm32/common/src/Make.defs
@@ -38,6 +38,14 @@ ifeq ($(CONFIG_INPUT_NUNCHUCK),y)
CSRCS += stm32_nunchuck.c
endif
+ifeq ($(CONFIG_AUDIO_TONE),y)
+ CSRCS += stm32_tone.c
+endif
+
+ifeq ($(CONFIG_LCD_SSD1306),y)
+ CSRCS += stm32_ssd1306.c
+endif
+
DEPPATH += --dep-path src
VPATH += :src
CFLAGS += $(shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src)
diff --git a/boards/arm/stm32/common/src/stm32_ssd1306.c b/boards/arm/stm32/common/src/stm32_ssd1306.c
new file mode 100644
index 0000000..a9ee58e
--- /dev/null
+++ b/boards/arm/stm32/common/src/stm32_ssd1306.c
@@ -0,0 +1,128 @@
+/****************************************************************************
+ * boards/arm/stm32/common/src/stm32_ssd1306.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 <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"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+FAR struct lcd_dev_s *g_lcddev;
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_ssd1306_initialize
+ *
+ * Description:
+ * Initialize and register the device
+ *
+ * Input Parameters:
+ * busno - The I2C bus number
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_ssd1306_initialize(int busno)
+{
+ FAR struct i2c_master_s* i2c;
+
+ /* Initialize I2C */
+
+ i2c = stm32_i2cbus_initialize(busno);
+ if (!i2c)
+ {
+ lcderr("ERROR: Failed to initialize I2C port %d\n", OLED_I2C_PORT);
+ return -ENODEV;
+ }
+
+ /* Bind the I2C port to the OLED */
+
+ g_lcddev = ssd1306_initialize(i2c, NULL, 0);
+ if (!g_lcddev)
+ {
+ lcderr("ERROR: Failed to bind I2C port 1 to OLED %d: %d\n", devno);
+ return -ENODEV;
+ }
+ else
+ {
+ lcdinfo("Bound I2C port %d to OLED %d\n", OLED_I2C_PORT, devno);
+
+ /* And turn the OLED on */
+
+ g_lcddev->setpower(g_lcddev, CONFIG_LCD_MAXPOWER);
+ return OK;
+ }
+}
+
+/****************************************************************************
+ * Name: board_ssd1306_getdev
+ *
+ * Description:
+ * Get the SSD1306 device driver instance
+ *
+ * Returned Value:
+ * Pointer to the instance
+ *
+ ****************************************************************************/
+
+FAR struct lcd_dev_s *board_ssd1306_getdev(void)
+{
+ return g_lcddev;
+}
+
diff --git a/boards/arm/stm32/common/src/stm32_tone.c b/boards/arm/stm32/common/src/stm32_tone.c
new file mode 100644
index 0000000..67ba874
--- /dev/null
+++ b/boards/arm/stm32/common/src/stm32_tone.c
@@ -0,0 +1,133 @@
+/****************************************************************************
+ * boards/arm/stm32/common/src/stm32_tone.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 <nuttx/config.h>
+
+#include <errno.h>
+#include <debug.h>
+#include <stdio.h>
+
+#include <nuttx/timers/pwm.h>
+#include <nuttx/timers/oneshot.h>
+#include <nuttx/audio/tone.h>
+#include <arch/board/board.h>
+
+#include "chip.h"
+#include "arm_arch.h"
+#include "stm32_pwm.h"
+#include "stm32_tone.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_tone_initialize
+ *
+ * Input Parameters:
+ * cfg - Configuration for the driver
+ * devno - The device number, used to build the device path as /dev/toneN
+ *
+ * Description:
+ * Configure and initialize the tone generator.
+ *
+ ****************************************************************************/
+
+int board_tone_initialize(FAR struct board_tone_config_s *cfg, int devno)
+{
+ static bool initialized = false;
+ struct pwm_lowerhalf_s *tone;
+ struct oneshot_lowerhalf_s *oneshot = NULL;
+ int ret;
+ char devpath[12];
+
+ /* Have we already initialized? */
+
+ if (!initialized)
+ {
+ /* Call stm32_pwminitialize() to get an instance of the PWM interface */
+
+ tone = stm32_pwminitialize(cfg->pwm_timer);
+ if (!tone)
+ {
+ auderr("Failed to get the STM32 PWM lower half to AUDIO TONE\n");
+ return -ENODEV;
+ }
+
+ /* Initialize TONE PWM */
+
+ tone->ops->setup(tone);
+
+ /* Initialize ONESHOT Timer */
+
+ oneshot = oneshot_initialize(cfg->oneshot_timer,
+ cfg->oneshot_timer_resolution);
+ if (!oneshot)
+ {
+ auderr("Failed to initialize ONESHOT Timer!\n");
+ return -ENODEV;
+ }
+
+ /* Register the Audio Tone driver at "/dev/tone0" */
+
+ snprintf(devpath, 12, "/dev/tone%d", devno);
+ ret = tone_register(devpath, tone, oneshot);
+ if (ret < 0)
+ {
+ auderr("ERROR: tone_register failed: %d\n", ret);
+ return ret;
+ }
+
+ /* Now we are initialized */
+
+ initialized = true;
+ }
+
+ return OK;
+}
diff --git a/boards/arm/stm32/nucleo-f303ze/src/Makefile b/boards/arm/stm32/nucleo-f303ze/src/Make.defs
similarity index 91%
rename from boards/arm/stm32/nucleo-f303ze/src/Makefile
rename to boards/arm/stm32/nucleo-f303ze/src/Make.defs
index 1fecf9b..53fcd29 100644
--- a/boards/arm/stm32/nucleo-f303ze/src/Makefile
+++ b/boards/arm/stm32/nucleo-f303ze/src/Make.defs
@@ -57,7 +57,9 @@ CSRCS += stm32_adc.c
endif
ifeq ($(CONFIG_LCD_SSD1306),y)
-CSRCS += stm32_ssd1306.c
+CSRCS += stm32_lcd.c
endif
-include $(TOPDIR)/boards/Board.mk
+DEPPATH += --dep-path board
+VPATH += :board
+CFLAGS += $(shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)
diff --git a/boards/arm/stm32/nucleo-f303ze/src/stm32_ssd1306.c b/boards/arm/stm32/nucleo-f303ze/src/stm32_lcd.c
similarity index 81%
rename from boards/arm/stm32/nucleo-f303ze/src/stm32_ssd1306.c
rename to boards/arm/stm32/nucleo-f303ze/src/stm32_lcd.c
index b0dc361..710273c 100644
--- a/boards/arm/stm32/nucleo-f303ze/src/stm32_ssd1306.c
+++ b/boards/arm/stm32/nucleo-f303ze/src/stm32_lcd.c
@@ -49,23 +49,18 @@
#include "stm32.h"
#include "nucleo-f303ze.h"
+#include "stm32_ssd1306.h"
+
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
-/* Configuration ************************************************************/
-
-#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
****************************************************************************/
@@ -76,13 +71,13 @@ FAR struct lcd_dev_s *g_lcddev;
int board_lcd_initialize(void)
{
- /* Initialize I2C */
+ int ret;
- g_i2c = stm32_i2cbus_initialize(OLED_I2C_PORT);
- if (!g_i2c)
+ ret = board_ssd1306_initialize(OLED_I2C_PORT);
+ if (ret < 0)
{
- lcderr("ERROR: Failed to initialize I2C port %d\n", OLED_I2C_PORT);
- return -ENODEV;
+ lcderr("ERROR: Failed to initialize SSD1306\n");
+ return ret;
}
return OK;
@@ -94,24 +89,7 @@ int board_lcd_initialize(void)
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 I2C 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 */
-
- g_lcddev->setpower(g_lcddev, CONFIG_LCD_MAXPOWER);
- return g_lcddev;
- }
-
- return NULL;
+ return board_ssd1306_getdev();
}
/****************************************************************************
diff --git a/boards/arm/stm32/stm32f103-minimum/src/Make.defs b/boards/arm/stm32/stm32f103-minimum/src/Make.defs
index b4bf184..ee01d76 100644
--- a/boards/arm/stm32/stm32f103-minimum/src/Make.defs
+++ b/boards/arm/stm32/stm32f103-minimum/src/Make.defs
@@ -95,10 +95,6 @@ CSRCS += stm32_at24.c
endif
endif
-ifeq ($(CONFIG_AUDIO_TONE),y)
- CSRCS += stm32_tone.c
-endif
-
ifeq ($(CONFIG_CAN_MCP2515),y)
CSRCS += stm32_mcp2515.c
endif
@@ -120,11 +116,11 @@ ifeq ($(CONFIG_INPUT_NUNCHUCK),y)
endif
ifeq ($(CONFIG_LCD_SSD1306_I2C),y)
-CSRCS += stm32_ssd1306.c
+CSRCS += stm32_lcd_ssd1306.c
endif
ifeq ($(CONFIG_LCD_ST7567),y)
- CSRCS += stm32_lcd.c
+ CSRCS += stm32_lcd_st7567.c
endif
ifeq ($(CONFIG_LCD_PCD8544),y)
diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c
index 7ed51ff..f9cacd3 100644
--- a/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c
+++ b/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c
@@ -105,6 +105,11 @@
#include "stm32_nunchuck.h"
#endif
+#ifdef CONFIG_AUDIO_TONE
+#include "stm32_tone.h"
+#endif
+
+
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -140,6 +145,19 @@
#endif
/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_AUDIO_TONE
+struct board_tone_config_s g_tone_cfg =
+{
+ .pwm_timer = 2,
+ .oneshot_timer = 3,
+ .oneshot_timer_resolution = 10
+};
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -270,7 +288,7 @@ int stm32_bringup(void)
#ifdef CONFIG_AUDIO_TONE
/* Configure and initialize the tone generator. */
- ret = stm32_tone_setup();
+ ret = board_tone_initialize(&g_tone_cfg, 0);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_tone_setup() failed: %d\n", ret);
diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_ssd1306.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_lcd_ssd1306.c
similarity index 78%
rename from boards/arm/stm32/stm32f103-minimum/src/stm32_ssd1306.c
rename to boards/arm/stm32/stm32f103-minimum/src/stm32_lcd_ssd1306.c
index 585207b..acde9ec 100644
--- a/boards/arm/stm32/stm32f103-minimum/src/stm32_ssd1306.c
+++ b/boards/arm/stm32/stm32f103-minimum/src/stm32_lcd_ssd1306.c
@@ -44,24 +44,15 @@
#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"
+#include "stm32_ssd1306.h"
+
/****************************************************************************
* 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 */
@@ -69,9 +60,6 @@
* Private Data
****************************************************************************/
-FAR struct i2c_master_s *g_i2c;
-FAR struct lcd_dev_s *g_lcddev;
-
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -82,13 +70,13 @@ FAR struct lcd_dev_s *g_lcddev;
int board_lcd_initialize(void)
{
- /* Initialize I2C */
+ int ret;
- g_i2c = stm32_i2cbus_initialize(OLED_I2C_PORT);
- if (!g_i2c)
+ ret = board_ssd1306_initialize(OLED_I2C_PORT);
+ if (ret < 0)
{
- lcderr("ERROR: Failed to initialize I2C port %d\n", OLED_I2C_PORT);
- return -ENODEV;
+ lcderr("ERROR: Failed to initialize SSD1306\n");
+ return ret;
}
return OK;
@@ -100,24 +88,7 @@ int board_lcd_initialize(void)
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 I2C 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 */
-
- g_lcddev->setpower(g_lcddev, CONFIG_LCD_MAXPOWER);
- return g_lcddev;
- }
-
- return NULL;
+ return board_ssd1306_getdev();
}
/****************************************************************************
diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_lcd.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_lcd_st7567.c
similarity index 100%
rename from boards/arm/stm32/stm32f103-minimum/src/stm32_lcd.c
rename to boards/arm/stm32/stm32f103-minimum/src/stm32_lcd_st7567.c
diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_tone.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_tone.c
deleted file mode 100644
index a06886d..0000000
--- a/boards/arm/stm32/stm32f103-minimum/src/stm32_tone.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/****************************************************************************
- * boards/arm/stm32/stm32f103minimum/src/stm32_tone.c
- *
- * Copyright (C) 2016 Gregory Nutt. All rights reserved.
- * Author: Alan Carvalho de Assis <ac...@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/timers/pwm.h>
-#include <nuttx/timers/oneshot.h>
-#include <nuttx/audio/tone.h>
-#include <arch/board/board.h>
-
-#include "chip.h"
-#include "arm_arch.h"
-#include "stm32_pwm.h"
-#include "stm32f103_minimum.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* Configuration ************************************************************/
-
-#define HAVE_TONE 1
-
-/* TIMx used to generate PWM signal to Buzzer/Speaker */
-
-#define TONE_PWM_TIMER 2
-
-/* TIMx used to generate oneshot */
-
-#define ONESHOT_TIMER 3
-
-/* Oneshot timer resolution in microseconds */
-
-#define OST_RES 10
-
-#ifndef CONFIG_PWM
-# undef HAVE_TONE
-#endif
-
-#ifndef CONFIG_STM32_TIM2
-# undef HAVE_TONE
-#endif
-
-#ifndef CONFIG_STM32_TIM2_PWM
-# undef HAVE_TONE
-#endif
-
-#ifdef HAVE_TONE
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: stm32_tone_setup
- *
- * Description:
- * Configure and initialize the tone generator.
- *
- ****************************************************************************/
-
-int stm32_tone_setup(void)
-{
- static bool initialized = false;
- struct pwm_lowerhalf_s *tone;
- struct oneshot_lowerhalf_s *oneshot = NULL;
- int ret;
-
- /* Have we already initialized? */
-
- if (!initialized)
- {
- /* Call stm32_pwminitialize() to get an instance of the PWM interface */
-
- tone = stm32_pwminitialize(TONE_PWM_TIMER);
- if (!tone)
- {
- auderr("Failed to get the STM32 PWM lower half to AUDIO TONE\n");
- return -ENODEV;
- }
-
- /* Initialize TONE PWM */
-
- tone->ops->setup(tone);
-
- /* Initialize ONESHOT Timer */
-
- oneshot = oneshot_initialize(ONESHOT_TIMER, OST_RES);
- if (!oneshot)
- {
- auderr("Failed to initialize ONESHOT Timer!\n");
- return -ENODEV;
- }
-
- /* Register the Audio Tone driver at "/dev/tone0" */
-
- ret = tone_register("/dev/tone0", tone, oneshot);
- if (ret < 0)
- {
- auderr("ERROR: tone_register failed: %d\n", ret);
- return ret;
- }
-
- /* Now we are initialized */
-
- initialized = true;
- }
-
- return OK;
-}
-
-#endif /* HAVE_TONE */