mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 09:18:00 +08:00
configs/flipnclick-sam3x: Adds basic board support for the HiletGo OLED.
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
|
||||
if ARCH_BOARD_FLIPNCLICK_PIC32MZ
|
||||
|
||||
|
||||
config FLIPNCLICK_PIC32MZ_HILETGO
|
||||
bool "HiletGo Click Present"
|
||||
default n
|
||||
|
||||
@@ -38,9 +38,10 @@ Port Status
|
||||
2018-02-10: Added the nxlines configuration to test the custom HiletGo
|
||||
OLED on a Click proto board. Debug output indicates that the example is
|
||||
running error free yet nothing appears on the OLED in mikroBUS slot A.
|
||||
It looks like all of the signals are present at the mikroBUS A slot and
|
||||
the proto click ohms out okay so this must be a software driver issue.
|
||||
Write only LCDs are tough to debug!
|
||||
I tried slot D with same result. I also ported the configuration to
|
||||
the Flip&Click SAM3X and got the same result. There could be SPI issues
|
||||
on the PIC32MX, but more likely that there is an error in my custom
|
||||
HiletGo Click. Damn!
|
||||
|
||||
On Board Debug Support
|
||||
======================
|
||||
@@ -338,9 +339,6 @@ HiletGo OLED
|
||||
|
||||
NOTE that this is a write-only display (MOSI only)!
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
Configurations
|
||||
==============
|
||||
|
||||
@@ -427,6 +425,7 @@ Where <subdir> is one of the following:
|
||||
|
||||
2018-02-10: The debug output indicates that the nxlines example is
|
||||
running with no errors, however, nothing appears on the OLED display.
|
||||
It looks like all of the signals are present at the mikroBUS A slot and
|
||||
the proto click ohms out okay so this must be a software driver issue.
|
||||
Write only LCDs are tough to debug!
|
||||
I tried slot D with same result. I also ported the configuration to
|
||||
the Flip&Click SAM3X and got the same result. There could be SPI issues
|
||||
on the PIC32MX, but more likely that there is an error in my custom
|
||||
HiletGo Click. Damn!
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
############################################################################
|
||||
# configs/flipnclick-pic32mz/src/Makefile
|
||||
#
|
||||
# Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -58,6 +58,11 @@
|
||||
!defined(CONFIG_FLIPNCLICK_PIC32MZ_HILETGO) || \
|
||||
!defined(CONFIG_LCD_SSD1306_SPI)
|
||||
# undef HAVE_HILETGO
|
||||
# undef CONFIG_FLIPNCLICK_PIC32MZ_HILETGO
|
||||
# undef CONFIG_FLIPNCLICK_PIC32MZ_HILETGO_MBA
|
||||
# undef CONFIG_FLIPNCLICK_PIC32MZ_HILETGO_MBB
|
||||
# undef CONFIG_FLIPNCLICK_PIC32MZ_HILETGO_MBC
|
||||
# undef CONFIG_FLIPNCLICK_PIC32MZ_HILETGO_MBD
|
||||
#endif
|
||||
|
||||
/* LEDs *********************************************************************/
|
||||
@@ -277,7 +282,7 @@ int pic32mz_bringup(void);
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_HILETGO
|
||||
struct lcd_dev_s; /* Forward reference3 */
|
||||
struct lcd_dev_s; /* Forward reference */
|
||||
FAR struct lcd_dev_s *pic32mz_graphics_setup(unsigned int devno);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ int pic32mz_bringup(void)
|
||||
|
||||
if (pic32mz_graphics_setup(0) == NULL)
|
||||
{
|
||||
syslog(LOG_ERR,"ERROR: Failed to configure the HiletGo OLEDn");
|
||||
syslog(LOG_ERR,"ERROR: Failed to configure the HiletGo OLED\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -68,9 +68,9 @@
|
||||
|
||||
void weak_function pic32mz_spidev_initialize(void)
|
||||
{
|
||||
/* Configure the SPI chip select GPIOs */
|
||||
#ifdef HAVE_HILETGO
|
||||
/* Configure the HiletGo chip select and command/data GPIOs */
|
||||
|
||||
#ifdef CONFIG_LCD_HILETGO
|
||||
(void)pic32mz_configgpio(GPIO_HILETGO_CS);
|
||||
(void)pic32mz_configgpio(GPIO_HILETGO_DC);
|
||||
#endif
|
||||
@@ -186,6 +186,7 @@ int pic32mz_spi2cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
|
||||
pic32mz_gpiowrite(GPIO_HILETGO_DC, !cmd);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4,4 +4,30 @@
|
||||
#
|
||||
|
||||
if ARCH_BOARD_FLIPNCLICK_SAM3X
|
||||
|
||||
config FLIPNCLICK_SAM3X_HILETGO
|
||||
bool "HiletGo Click Present"
|
||||
default n
|
||||
depends on LCD_HILETGO
|
||||
select NXSTART_EXTERNINIT if NX
|
||||
|
||||
choice
|
||||
prompt "HiletGo mikroBUS"
|
||||
default FLIPNCLICK_SAM3X_HILETGO_MBA
|
||||
depends on FLIPNCLICK_SAM3X_HILETGO
|
||||
|
||||
config FLIPNCLICK_SAM3X_HILETGO_MBA
|
||||
bool "mikroBUS A"
|
||||
|
||||
config FLIPNCLICK_SAM3X_HILETGO_MBB
|
||||
bool "mikroBUS B"
|
||||
|
||||
config FLIPNCLICK_SAM3X_HILETGO_MBC
|
||||
bool "mikroBUS C"
|
||||
|
||||
config FLIPNCLICK_SAM3X_HILETGO_MBD
|
||||
bool "mikroBUS D"
|
||||
|
||||
endchoice # HiletGo mikroBUS
|
||||
|
||||
endif
|
||||
|
||||
@@ -16,6 +16,7 @@ Contents
|
||||
- Serial Consoles
|
||||
- SPI
|
||||
- I2C
|
||||
- HiletGo OLED
|
||||
- Loading Code
|
||||
- Flip&Click SAM3X-specific Configuration Options
|
||||
- Configurations
|
||||
@@ -29,6 +30,11 @@ STATUS
|
||||
2018-01-24: I ordered a JTAG connector and soldered that to the Flip'n'Click
|
||||
and I am now successfully able to load code. The NSH configuration appears
|
||||
to be fully functional.
|
||||
2018-02-11: Added the nxlines configuration to test the custom HiletGo
|
||||
OLED on a Click proto board. This is the same logic from the Flip&Click
|
||||
PIC32MZ and the result is the same: No complaints from the software, but
|
||||
nothing appears on the OLED. There is, most likely, an error in my custom
|
||||
HiletGo Click. Damn!
|
||||
|
||||
Buttons and LEDs
|
||||
================
|
||||
@@ -182,6 +188,27 @@ I2C
|
||||
SCL I2C1_SCL PB13 SCL I2C1_SCL PB13
|
||||
SDA I2C1_SDA PB12 SDA I2C1_SDA PB12
|
||||
|
||||
HiletGo OLED
|
||||
============
|
||||
|
||||
Hardware
|
||||
--------
|
||||
The HiletGo is a 128x64 OLED that can be driven either via SPI or I2C (SPI
|
||||
is the default and is what is used here). I have mounted the OLED on a
|
||||
proto click board. The OLED is connected as follows:
|
||||
|
||||
OLED ALIAS DESCRIPTION PROTO CLICK
|
||||
----- ----------- ------------- -----------------
|
||||
GND Ground GND
|
||||
VCC Power Supply 5V (3-5V)
|
||||
D0 SCL,CLK,SCK Clock SCK
|
||||
D1 SDA,MOSI Data MOSI,SDI
|
||||
RES RST,RESET Reset RST (GPIO OUTPUT)
|
||||
DC AO Data/Command INT (GPIO OUTPUT)
|
||||
CS Chip Select CS (GPIO OUTPUT)
|
||||
|
||||
NOTE that this is a write-only display (MOSI only)!
|
||||
|
||||
Loading Code
|
||||
============
|
||||
|
||||
@@ -514,7 +541,7 @@ Flip&Click SAM3X-specific Configuration Options
|
||||
CONFIG_SAM34_GPIOF_IRQ
|
||||
|
||||
Configurations
|
||||
^^^^^^^^^^^^^^
|
||||
==============
|
||||
|
||||
Each Flip&Click SAM3X configuration is maintained in a sub-directory and
|
||||
can be selected as follow:
|
||||
@@ -587,3 +614,23 @@ Configuration sub-directories
|
||||
|
||||
Application Configuration:
|
||||
CONFIG_NSH_BUILTIN_APPS=y : Enable starting apps from NSH command line
|
||||
|
||||
nxlines
|
||||
|
||||
This is an NSH configuration that supports the NX graphics example at
|
||||
apps/examples/nxlines as a built-in application.
|
||||
|
||||
NOTES:
|
||||
|
||||
1. This configuration derives from the nsh configuration. All of the
|
||||
notes there apply here as well.
|
||||
|
||||
2. The default configuration assumes there is the custom HiletGo OLED
|
||||
in the mikroBUS B slot (and a Mikroe RS-232 Click card in the
|
||||
mikroBUS A slot). That is easily changed by reconfiguring, however.
|
||||
See the section entitled "HiletGo OLED" for information about this
|
||||
custom click card.
|
||||
|
||||
STATUS:
|
||||
2018-02-11: No complaints from the software, but nothing appears on the
|
||||
OLED. There is, most likely, an error in my custom HiletGo Click. Damn!
|
||||
|
||||
@@ -290,7 +290,7 @@
|
||||
* Chip select pin definitions are provided in
|
||||
* configs/flipnclick-sam3x/src/flipnclick-3x.h.
|
||||
*
|
||||
* There are no alternative pin selections for SPI0_MSIO and SPIO_MOSI.
|
||||
* There are no alternative pin selections for SPI0_MISO and SPIO_MOSI.
|
||||
*/
|
||||
|
||||
#define GPIO_SPI0_SPCK GPIO_SPI0_SPCK_1
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
# CONFIG_ARCH_RAMFUNCS is not set
|
||||
# CONFIG_NX_DISABLE_1BPP is not set
|
||||
# CONFIG_SAM34_UART0 is not set
|
||||
CONFIG_ARCH_BOARD_FLIPNCLICK_SAM3X=y
|
||||
CONFIG_ARCH_BOARD="flipnclick-sam3x"
|
||||
CONFIG_ARCH_CHIP_ATSAM3X8E=y
|
||||
CONFIG_ARCH_CHIP_SAM34=y
|
||||
CONFIG_ARCH_CHIP_SAM3X=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_BOARD_LOOPSPERMSEC=6965
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y
|
||||
CONFIG_EXAMPLES_NSH=y
|
||||
CONFIG_EXAMPLES_NXLINES_BORDERWIDTH=4
|
||||
CONFIG_EXAMPLES_NXLINES_BPP=1
|
||||
CONFIG_EXAMPLES_NXLINES_LINEWIDTH=4
|
||||
CONFIG_EXAMPLES_NXLINES=y
|
||||
CONFIG_FLIPNCLICK_SAM3X_HILETGO_MBB=y
|
||||
CONFIG_FLIPNCLICK_SAM3X_HILETGO=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_HOST_WINDOWS=y
|
||||
CONFIG_LCD_HILETGO=y
|
||||
CONFIG_LCD_MAXCONTRAST=255
|
||||
CONFIG_LCD=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_MAX_WDOGPARMS=2
|
||||
CONFIG_MM_REGIONS=3
|
||||
CONFIG_MQ_MAXMSGSIZE=64
|
||||
CONFIG_NFILE_DESCRIPTORS=8
|
||||
CONFIG_NFILE_STREAMS=8
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_DISABLE_IFUPDOWN=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_NX_BLOCKING=y
|
||||
CONFIG_NX=y
|
||||
CONFIG_NXFONT_TOM_THUMB_4X6=y
|
||||
CONFIG_NXTK_BORDERWIDTH=2
|
||||
CONFIG_PREALLOC_MQ_MSGS=8
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_PREALLOC_WDOGS=4
|
||||
CONFIG_RAM_SIZE=65536
|
||||
CONFIG_RAM_START=0x20000000
|
||||
CONFIG_RAW_BINARY=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SAM34_SPI0=y
|
||||
CONFIG_SAM34_USART0=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_START_DAY=11
|
||||
CONFIG_START_MONTH=2
|
||||
CONFIG_USART0_SERIAL_CONSOLE=y
|
||||
CONFIG_USER_ENTRYPOINT="nsh_main"
|
||||
CONFIG_WDOG_INTRESERVE=0
|
||||
@@ -48,4 +48,12 @@ ifeq ($(CONFIG_LIB_BOARDCTL),y)
|
||||
CSRCS += sam_appinit.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SAM34_SPI0),y)
|
||||
CSRCS += sam_spi0.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_FLIPNCLICK_SAM3X_HILETGO),y)
|
||||
CSRCS += sam_hiletgo.c
|
||||
endif
|
||||
|
||||
include $(TOPDIR)/configs/Board.mk
|
||||
|
||||
@@ -53,6 +53,25 @@
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#define HAVE_HILETGO 1
|
||||
|
||||
/* The HiletGo LCD must be selected, installed on the Flip&Click, and must
|
||||
* be configured to use the SPI interface.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_LCD_HILETGO) || \
|
||||
!defined(CONFIG_FLIPNCLICK_SAM3X_HILETGO) || \
|
||||
!defined(CONFIG_LCD_SSD1306_SPI)
|
||||
# undef HAVE_HILETGO
|
||||
# undef CONFIG_FLIPNCLICK_SAM3X_HILETGO
|
||||
# undef CONFIG_FLIPNCLICK_SAM3X_HILETGO_MBA
|
||||
# undef CONFIG_FLIPNCLICK_SAM3X_HILETGO_MBB
|
||||
# undef CONFIG_FLIPNCLICK_SAM3X_HILETGO_MBC
|
||||
# undef CONFIG_FLIPNCLICK_SAM3X_HILETGO_MBD
|
||||
#endif
|
||||
|
||||
/* There are four LEDs on the top, blue side of the board. Only one can be
|
||||
* controlled by software:
|
||||
*
|
||||
@@ -128,6 +147,90 @@
|
||||
GPIO_PORT_PIOB | GPIO_PIN23)
|
||||
#define MBD_CSNUM 3
|
||||
|
||||
/* HiletGo OLED
|
||||
*
|
||||
* The HiletGo is a 128x64 OLED that can be driven either via SPI or I2C (SPI
|
||||
* is the default and is what is used here). I have mounted the OLED on a
|
||||
* proto click board. The OLED is connected as follows:
|
||||
*
|
||||
* OLED ALIAS DESCRIPTION PROTO CLICK
|
||||
* ----- ----------- ------------- -----------------
|
||||
* GND Ground GND
|
||||
* VCC Power Supply 5V (3-5V)
|
||||
* D0 SCL,CLK,SCK Clock SCK
|
||||
* D1 SDA,MOSI Data MOSI,SDI
|
||||
* RES RST,RESET Reset RST (GPIO OUTPUT)
|
||||
* DC AO Data/Command INT (GPIO OUTPUT)
|
||||
* CS Chip Select CS (GPIO OUTPUT)
|
||||
*
|
||||
* NOTE that this is a write-only display (MOSI only)!
|
||||
*
|
||||
* MikroBUS A: MikroBUS B:
|
||||
* Pin Board Signal SAM3X Pin Board Signal SAM3X
|
||||
* ---- ------------ ----- ---- ------------ -------
|
||||
* RST RSTA PC1 RST RSTB PC2
|
||||
* DC INTA PD1 DC INTB PD2
|
||||
*
|
||||
* MikroBUS C: MikroBUS D:
|
||||
* Pin Board Signal SAM3X Pin Board Signal SAM3X
|
||||
* ---- ------------ ----- ---- ------------ -------
|
||||
* RST RSTC PC3 RST RSTD PC4
|
||||
* DC INTC PD3 DC INTD PD6
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_FLIPNCLICK_SAM3X_HILETGO_MBA)
|
||||
# ifndef CONFIG_SAM34_SPI0
|
||||
# error "The OLED driver requires CONFIG_SAM34_SPI0 in the configuration"
|
||||
# endif
|
||||
|
||||
# define HILETGO_SPI_BUS 0
|
||||
# define HILETGO_CSNUM MBA_CSNUM
|
||||
# define GPIO_HILETGO_CS GPIO_MBA_CS
|
||||
# define GPIO_HILETGO_RST (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOC | GPIO_PIN1)
|
||||
# define GPIO_HILETGO_DC (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOD | GPIO_PIN1)
|
||||
|
||||
#elif defined(CONFIG_FLIPNCLICK_SAM3X_HILETGO_MBB)
|
||||
# ifndef CONFIG_SAM34_SPI0
|
||||
# error "The OLED driver requires CONFIG_SAM34_SPI0 in the configuration"
|
||||
# endif
|
||||
|
||||
# define HILETGO_SPI_BUS 0
|
||||
# define HILETGO_CSNUM MBB_CSNUM
|
||||
# define GPIO_HILETGO_CS GPIO_MBB_CS
|
||||
# define GPIO_HILETGO_RST (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOC | GPIO_PIN2)
|
||||
# define GPIO_HILETGO_DC (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOD | GPIO_PIN2)
|
||||
|
||||
#elif defined(CONFIG_FLIPNCLICK_SAM3X_HILETGO_MBC)
|
||||
# ifndef CONFIG_SAM34_SPI0
|
||||
# error "The OLED driver requires CONFIG_SAM34_SPI0 in the configuration"
|
||||
# endif
|
||||
|
||||
# define HILETGO_SPI_BUS 0
|
||||
# define HILETGO_CSNUM MBC_CSNUM
|
||||
# define GPIO_HILETGO_CS GPIO_MBC_CS
|
||||
# define GPIO_HILETGO_RST (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOC | GPIO_PIN3)
|
||||
# define GPIO_HILETGO_DC (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOD | GPIO_PIN3)
|
||||
|
||||
#elif defined(CONFIG_FLIPNCLICK_SAM3X_HILETGO_MBD)
|
||||
# ifndef CONFIG_SAM34_SPI0
|
||||
# error "The OLED driver requires CONFIG_SAM34_SPI0 in the configuration"
|
||||
# endif
|
||||
|
||||
# define HILETGO_SPI_BUS 0
|
||||
# define HILETGO_CSNUM MBD_CSNUM
|
||||
# define GPIO_HILETGO_CS GPIO_MBD_CS
|
||||
# define GPIO_HILETGO_RST (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOC | GPIO_PIN4)
|
||||
# define GPIO_HILETGO_DC (GPIO_OUTPUT | GPIO_CFG_DEFAULT | GPIO_OUTPUT_CLEAR | \
|
||||
GPIO_PORT_PIOD | GPIO_PIN6)
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Public Types
|
||||
************************************************************************************/
|
||||
@@ -158,6 +261,21 @@
|
||||
|
||||
int sam_bringup(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_graphics_setup
|
||||
*
|
||||
* Description:
|
||||
* Called by either NX initialization logic (via board_graphics_setup) or
|
||||
* directly from the board bring-up logic in order to configure the
|
||||
* HiletGo OLED.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_HILETGO
|
||||
struct lcd_dev_s; /* Forward reference */
|
||||
FAR struct lcd_dev_s *sam_graphics_setup(unsigned int devno);
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __CONFIGS_FLIPNCLICK_SAM3X_SRC_FLIPNCLICK_SAM3X_H */
|
||||
|
||||
|
||||
@@ -84,6 +84,15 @@ int sam_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_HILETGO) && !defined(CONFIG_NXSTART_EXTERNINIT)
|
||||
/* Configure the HiletGo OLED */
|
||||
|
||||
if (sam_graphics_setup(0) == NULL)
|
||||
{
|
||||
syslog(LOG_ERR,"ERROR: Failed to configure the HiletGo OLED\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
UNUSED(ret);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
/****************************************************************************
|
||||
* config/flipnclick-sam3x/src/sam_hiletgo.c
|
||||
*
|
||||
* Copyright (C) 2018 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* HiletGo OLED
|
||||
*
|
||||
* The HiletGo is a 128x64 OLED that can be driven either via SPI or I2C (SPI
|
||||
* is the default and is what is used here). I have mounted the OLED on a
|
||||
* proto click board. The OLED is connected as follows:
|
||||
*
|
||||
* OLED ALIAS DESCRIPTION PROTO CLICK
|
||||
* ----- ----------- ------------- -----------------
|
||||
* GND Ground GND
|
||||
* VCC Power Supply 5V (3-5V)
|
||||
* D0 SCL,CLK,SCK Clock SCK
|
||||
* D1 SDA,MOSI Data MOSI,SDI
|
||||
* RES RST,RESET Reset RST (GPIO OUTPUT)
|
||||
* DC AO Data/Command INT (GPIO OUTPUT)
|
||||
* CS Chip Select CS (GPIO OUTPUT)
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/board.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/lcd/lcd.h>
|
||||
#include <nuttx/lcd/ssd1306.h>
|
||||
|
||||
#if defined(CONFIG_VIDEO_FB) && defined(CONFIG_LCD_FRAMEBUFFER)
|
||||
# include <nuttx/video/fb.h>
|
||||
#endif
|
||||
|
||||
#include "sam_gpio.h"
|
||||
#include "sam_spi.h"
|
||||
|
||||
#include "flipnclick-sam3x.h"
|
||||
|
||||
#ifdef HAVE_HILETGO
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifndef CONFIG_SPI_CMDDATA
|
||||
# error "The OLED driver requires CONFIG_SPI_CMDDATA in the configuration"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_graphics_setup
|
||||
*
|
||||
* Description:
|
||||
* Called by either NX initialization logic (via board_graphics_setup) or
|
||||
* directly from the board bring-up logic in order to configure the
|
||||
* HiletGo OLED.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct lcd_dev_s *sam_graphics_setup(unsigned int devno)
|
||||
{
|
||||
FAR struct spi_dev_s *spi;
|
||||
FAR struct lcd_dev_s *dev;
|
||||
|
||||
/* Configure the OLED GPIOs. This initial configuration is RESET low,
|
||||
* putting the OLED into reset state.
|
||||
*/
|
||||
|
||||
sam_configgpio(GPIO_HILETGO_RST);
|
||||
|
||||
/* Wait a bit then release the OLED from the reset state */
|
||||
|
||||
up_mdelay(20);
|
||||
sam_gpiowrite(GPIO_HILETGO_RST, true);
|
||||
|
||||
/* Get the SPI1 port interface */
|
||||
|
||||
spi = sam_spibus_initialize(GPIO_HILETGO_CS);
|
||||
if (!spi)
|
||||
{
|
||||
lcderr("ERROR: Failed to initialize SPI port 1\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Bind the SPI port to the OLED */
|
||||
|
||||
dev = ssd1306_initialize(spi, NULL, devno);
|
||||
if (!dev)
|
||||
{
|
||||
lcderr("ERROR: Failed to bind SPI port 1 to OLED %d: %d\n", devno);
|
||||
}
|
||||
else
|
||||
{
|
||||
lcdinfo("Bound SPI port 1 to OLED %d\n", devno);
|
||||
|
||||
/* And turn the OLED on */
|
||||
|
||||
(void)dev->setpower(dev, CONFIG_LCD_MAXPOWER);
|
||||
|
||||
#if defined(CONFIG_VIDEO_FB) && defined(CONFIG_LCD_FRAMEBUFFER)
|
||||
/* Initialize and register the simulated framebuffer driver */
|
||||
|
||||
ret = fb_register(0, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: fb_register() failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
return dev;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_graphics_setup
|
||||
*
|
||||
* Description:
|
||||
* Called by NX initialization logic to configure the OLED.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NXSTART_EXTERNINIT
|
||||
FAR struct lcd_dev_s *board_graphics_setup(unsigned int devno)
|
||||
{
|
||||
return sam_graphics_setup(devno);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_HILETGO */
|
||||
@@ -0,0 +1,220 @@
|
||||
/************************************************************************************
|
||||
* configs/flipnclick-sam3x/src/sam_spi0.c
|
||||
*
|
||||
* Copyright (C) 2018 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 <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "up_arch.h"
|
||||
#include "chip.h"
|
||||
#include "sam_gpio.h"
|
||||
#include "sam_spi.h"
|
||||
|
||||
#include "flipnclick-sam3x.h"
|
||||
|
||||
#ifdef CONFIG_SAM34_SPI0
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: sam_spidev_initialize
|
||||
*
|
||||
* Description:
|
||||
* Called to configure SPI chip select GPIO pins for the SAM4E-EK board.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
void weak_function sam_spidev_initialize(void)
|
||||
{
|
||||
#ifdef HAVE_HILETGO
|
||||
/* Configure the HiletGo chip select and command/data GPIOs */
|
||||
|
||||
sam_configgpio(GPIO_HILETGO_CS);
|
||||
sam_configgpio(GPIO_HILETGO_DC);
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_spi0select, sam_spi0status, and sam_spic0mddata
|
||||
*
|
||||
* Description:
|
||||
* These external functions must be provided by board-specific logic. They
|
||||
* include:
|
||||
*
|
||||
* o sam_spi0select is a functions tomanage the board-specific chip selects
|
||||
* o sam_spi0status and sam_spic0mddata: Implementations of the status
|
||||
* and cmddata methods of the SPI interface defined by struct spi_ops_
|
||||
* (see include/nuttx/spi/spi.h). All other methods including
|
||||
* sam_spibus_initialize()) are provided by common SAM3/4 logic.
|
||||
*
|
||||
* To use this common SPI logic on your board:
|
||||
*
|
||||
* 1. Provide logic in sam_boardinitialize() to configure SPI chip select
|
||||
* pins.
|
||||
* 2. Provide sam_spi0select() and sam_spi0status() functions in your board-
|
||||
* specific logic. These functions will perform chip selection and
|
||||
* status operations using GPIOs in the way your board is configured.
|
||||
* 2. If CONFIG_SPI_CMDDATA is defined in the NuttX configuration, provide
|
||||
* sam_spic0mddata() functions in your board-specific logic. This
|
||||
* function will perform cmd/data selection operations using GPIOs in
|
||||
* the way your board is configured.
|
||||
* 3. Add a call to sam_spibus_initialize() in your low level application
|
||||
* initialization logic
|
||||
* 4. The handle returned by sam_spibus_initialize() may then be used to bind the
|
||||
* SPI driver to higher level logic (e.g., calling
|
||||
* mmcsd_spislotinitialize(), for example, will bind the SPI driver to
|
||||
* the SPI MMC/SD driver).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_spi0select
|
||||
*
|
||||
* Description:
|
||||
* PIO chip select pins may be programmed by the board specific logic in
|
||||
* one of two different ways. First, the pins may be programmed as SPI
|
||||
* peripherals. In that case, the pins are completely controlled by the
|
||||
* SPI driver. This method still needs to be provided, but it may be only
|
||||
* a stub.
|
||||
*
|
||||
* An alternative way to program the PIO chip select pins is as a normal
|
||||
* GPIO output. In that case, the automatic control of the CS pins is
|
||||
* bypassed and this function must provide control of the chip select.
|
||||
* NOTE: In this case, the GPIO output pin does *not* have to be the
|
||||
* same as the NPCS pin normal associated with the chip select number.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devid - Identifies the (logical) device
|
||||
* selected - TRUE:Select the device, FALSE:De-select the device
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void sam_spi0select(uint32_t devid, bool selected)
|
||||
{
|
||||
spiinfo("devid: %08x CS: %s\n",
|
||||
(unsigned int)devid, selected ? "assert" : "de-assert");
|
||||
|
||||
#ifdef HAVE_HILETGO
|
||||
if (devid == SPIDEV_DISPLAY(0))
|
||||
{
|
||||
/* Low: the display is selected
|
||||
* High: the display is deselected
|
||||
*/
|
||||
|
||||
sam_gpiowrite(GPIO_HILETGO_CS, !selected);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam_spi0status
|
||||
*
|
||||
* Description:
|
||||
* Return status information associated with the SPI device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devid - Identifies the (logical) device
|
||||
*
|
||||
* Returned Value:
|
||||
* Bit-encoded SPI status (see include/nuttx/spi/spi.h.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint8_t sam_spi0status(FAR struct spi_dev_s *dev, uint32_t devid)
|
||||
{
|
||||
spiinfo("Returning nothing\n");
|
||||
return 0;
|
||||
}
|
||||
/****************************************************************************
|
||||
* Name: sam_spi0cmddata
|
||||
*
|
||||
* Description:
|
||||
* Some SPI devices require an additional control to determine if the SPI
|
||||
* data being sent is a command or is data. If CONFIG_SPI_CMDDATA then
|
||||
* this function will be called to different be command and data transfers.
|
||||
*
|
||||
* This is often needed, for example, by LCD drivers. Some LCD hardware
|
||||
* may be configured to use 9-bit data transfers with the 9th bit
|
||||
* indicating command or data. That same hardware may be configurable,
|
||||
* instead, to use 8-bit data but to require an additional, board-
|
||||
* specific PIO control to distinguish command and data. This function
|
||||
* would be needed in that latter case.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - SPI device info
|
||||
* devid - Identifies the (logical) device
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SPI_CMDDATA
|
||||
int sam_spi0cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
|
||||
{
|
||||
spiinfo("devid: %08x %s\n", (unsigned int)devid, cmd ? "cmd" : "data");
|
||||
|
||||
#ifdef HAVE_HILETGO
|
||||
if (devid == SPIDEV_DISPLAY(0))
|
||||
{
|
||||
/* High: the inputs are treated as display data.
|
||||
* Low: the inputs are transferred to the command registers.
|
||||
*/
|
||||
|
||||
sam_gpiowrite(GPIO_HILETGO_DC, !cmd);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_SAM34_SPI0 */
|
||||
Reference in New Issue
Block a user