1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 10:52:44 +01:00

boards: add common esp8266 based sources

This commit is contained in:
Schorcht 2018-09-05 02:39:50 +02:00
parent e4ca897661
commit bc1906ef42
9 changed files with 575 additions and 0 deletions

View File

@ -0,0 +1,3 @@
MODULE = boards_common_esp8266
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,5 @@
include $(RIOTCPU)/esp8266/Makefile.dep
ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_gpio
endif

View File

@ -0,0 +1,13 @@
# MCU defined features that are provided independent on board definitions
include $(RIOTCPU)/esp8266/Makefile.features
# MCU defined peripheral features provided by all boards in alphabetical order
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_gpio
FEATURES_PROVIDED += periph_gpio_irq
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_pwm
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_uart

View File

@ -0,0 +1,11 @@
# the cpu to build for
export CPU ?= esp8266
export CPU_MODEL ?= esp8266
# configure the serial interface
PORT_LINUX ?= /dev/ttyUSB0
PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*)))
include $(RIOTMAKE)/tools/serial.inc.mk
# reset tool configuration
export RESET = esptool.py --before default_reset run

View File

@ -0,0 +1,80 @@
/*
* Copyright (C) 2018 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup boards_common_esp8266 ESP8266 Common
* @ingroup boards_common
* @brief Common files for the esp8266 board.
* @{
*
* @file
* @brief Definitions for all esp8266 board.
*
* @author Gunar Schorcht <gunar@schorcht.net>
*/
#include "board_common.h"
#include "log.h"
#include "periph/gpio.h"
#ifdef __cplusplus
extern "C" {
#endif
void board_init(void)
{
#ifdef LED0_PIN
gpio_init (LED0_PIN, GPIO_OUT);
LED0_OFF;
#endif
#ifdef LED1_PIN
gpio_init (LED1_PIN, GPIO_OUT);
LED1_OFF;
#endif
#ifdef LED2_PIN
gpio_init (LED2_PIN, GPIO_OUT);
LED2_OFF;
#endif
}
extern void pwm_print_config(void);
extern void i2c_print_config(void);
extern void spi_print_config(void);
extern void uart_print_config(void);
extern void timer_print_config(void);
void board_print_config (void)
{
LOG_INFO("\nBoard configuration:\n");
pwm_print_config();
i2c_print_config();
spi_print_config();
uart_print_config();
timer_print_config();
LOG_INFO("\tLED: pins=[ ");
#ifdef LED0_PIN
LOG_INFO("%d ", LED0_PIN);
#endif
#ifdef LED1_PIN
LOG_INFO("%d ", LED1_PIN);
#endif
#ifdef LED2_PIN
LOG_INFO("%d ", LED2_PIN);
#endif
LOG_INFO("]\n");
LOG_INFO("\n\n");
}
#ifdef __cplusplus
} /* end extern "C" */
#endif
/** @} */

View File

@ -0,0 +1,21 @@
/**
* @defgroup boards_common_esp8266 ESP8266 Common
* @ingroup boards_common
* @ingroup boards_esp8266
* @brief Definitions and configurations that are common for
* all ESP8266 boards.
*
* For detailed information about the ESP8266, configuring and compiling RIOT
* for ESP8266 boards, please refer \ref esp8266_riot.
*/
/**
* @defgroup boards_esp8266 ESP8266 Boards
* @ingroup boards
* @brief This group of boards contains the documentation
* defined ESP8266 boards.
*
* @note For detailed information about the ESP8266 SoC, the tool chain
* as well as configuring and compiling RIOT for ESP8266 boards,
* see \ref esp8266_riot.
*/

View File

@ -0,0 +1,143 @@
/*
* Copyright (C) 2018 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
#ifndef BOARD_COMMON_H
#define BOARD_COMMON_H
/**
* @ingroup boards_common_esp8266
* @brief Board definitions that are common for all ESP8266 boards.
* @file
* @author Gunar Schorcht <gunar@schorcht.net>
* @{
*/
#include <stdint.h>
#include "cpu.h"
#include "periph_conf.h"
#include "periph_conf_common.h"
#include "periph/gpio.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @name Common on-board LED control definitions
* @{
*/
#ifdef LED0_PIN
#define LED0_MASK (BIT(LED0_PIN))
#define LED0_TOGGLE (gpio_toggle(LED0_PIN))
#define LED0_ON (gpio_write(LED0_PIN, LED0_ACTIVE))
#define LED0_OFF (gpio_write(LED0_PIN, !LED0_ACTIVE))
#endif
#ifdef LED1_PIN
#define LED1_MASK (BIT(LED1_PIN))
#define LED1_TOGGLE (gpio_toggle(LED1_PIN))
#define LED1_ON (gpio_write(LED1_PIN, LED1_ACTIVE))
#define LED1_OFF (gpio_write(LED1_PIN, !LED1_ACTIVE))
#endif
#ifdef LED2_PIN
#define LED2_MASK (BIT(LED2_PIN))
#define LED2_TOGGLE (gpio_toggle(LED2_PIN))
#define LED2_ON (gpio_write(LED2_PIN, LED2_ACTIVE))
#define LED2_OFF (gpio_write(LED2_PIN, !LED2_ACTIVE))
#endif
/** @} */
/**
* @name STDIO configuration
* @{
*/
#ifndef STDIO_UART_BAUDRATE
#define STDIO_UART_BAUDRATE (115200) /**< Default baudrate of UART for stdio */
#endif
/** @} */
#ifndef DOXYGEN
/**
* @name XTimer configuration
* @{
*/
#define XTIMER_OVERHEAD (0U)
#if defined(MODULE_ESP_SW_TIMER)
#define XTIMER_BACKOFF (100U)
#define XTIMER_ISR_BACKOFF (100U)
#endif /* MODULE_ESP_SW_TIMER */
/** @} */
#endif /* DOXYGEN */
#if defined(MODULE_MTD) || defined(DOXYGEN)
/**
* @name MTD device configuration
*
* Internal flash memory can be used as MTD device. For that purpose
* a system MTD device has to be defined.
* @{
*/
#include "mtd.h"
/** Default MTD device definition */
#define MTD_0 mtd0
/** Pointer to the default MTD device structure */
extern mtd_dev_t *mtd0;
/** @} */
#endif /* defined(MODULE_MTD) || defined(DOXYGEN) */
#if defined(MODULE_SPIFFS) || defined(DOXYGEN)
/**
* @name SPIFFS configuration
*
* Configuration of the SPIFFS that can be used on the system MTD device.
* @{
*/
#define SPIFFS_ALIGNED_OBJECT_INDEX_TABLES 1
#define SPIFFS_READ_ONLY 0
#define SPIFFS_SINGLETON 0
#define SPIFFS_HAL_CALLBACK_EXTRA 1
#define SPIFFS_CACHE 1
/** @} */
#endif /* defined(MODULE_SPIFFS) || defined(DOXYGEN) */
/**
* @brief Initialize board specific hardware
*
* Since all features of ESP8266 boards are provided by the MCU, almost all
* initializations are done during the CPU initialization that is called from
* boot loader.
*/
extern void board_init(void);
/**
* @brief Print the board configuration in a human readable format
*/
void board_print_config (void);
#ifdef __cplusplus
} /* end extern "C" */
#endif
/* include definitions for optional off-board hardware modules */
#include "board_modules.h"
/** @} */
#endif /* BOARD_COMMON_H */

View File

@ -0,0 +1,133 @@
/*
* Copyright (C) 2018 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
#ifndef BOARD_MODULES_H
#define BOARD_MODULES_H
/**
* @ingroup boards_common_esp8266
* @brief Definitions for optional off-board hardware modules that can
* be used with all ESP8266 boards.
*
* All ESP8266 boards can be used with different off-board hardware modules.
* This file contains the default configurations for those external hardware
* modules that have been tested with the ESP8266 and are preconfigured here.
* Most of these configurations can be overridden by application-specific
* configurations. The configuration for a hardware module is only used if the
* corresponding driver modules are used.
*
* @file
* @author Gunar Schorcht <gunar@schorcht.net>
* @{
*/
#include <stdint.h>
#include "cpu.h"
#include "periph_conf.h"
#include "periph_conf_common.h"
#include "periph/gpio.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(MODULE_ENC28J60) || defined(DOXYGEN)
/**
* @name ENC28J60 configuration
*
* Configuration for the ENC28J60 interface when module ```enc28j60``` is used.
*
* SPI_DEV(0) is always used for the the module. The only configurations that
* can be overridden by
* \ref esp8266_app_spec_conf "Application Specific Board Configuration"
* are the CS, INT and RESET signals.
*
* @note The RESET signal can also be connected to the ESP8266 RST pin to
* keep an additional GPIO free.
*
* @{
*/
#define ENC28J60_PARAM_SPI SPI_DEV(0) /**< SPI_DEV(0) is used (fixed) */
#ifndef ENC28J60_PARAM_CS
#define ENC28J60_PARAM_CS GPIO4 /**< ENC28J60 CS signal (can be overriden) */
#endif
#ifndef ENC28J60_PARAM_INT
#define ENC28J60_PARAM_INT GPIO9 /**< ENC28J60 CS signal (can be overriden) */
#endif
#ifndef ENC28J60_PARAM_RESET
#define ENC28J60_PARAM_RESET GPIO10 /**< ENC28J60 RESET signal (can be overriden) */
#endif
/** @} */
#endif /* defined(MODULE_ENC28J60) || defined(DOXYGEN) */
#if defined(MODULE_MRF24J40) || defined(DOXYGEN)
/**
* @name MRF24J40 configuration
*
* Configuration for the MRF24J40 interface when module ```mrf24j40``` is used.
*
* SPI_DEV(0) is always used for the the module. The only configurations that
* can be overridden by
* \ref esp8266_app_spec_conf "Application Specific Board Configuration"
* are the CS, INT and RESET signals.
*
* @note The RESET signal can also be connected to the ESP8266 RST pin to
* keep an additional GPIO free.
* @{
*/
#define MRF24J40_PARAM_SPI SPI_DEV(0) /**< SPI_DEV(0) is used (fixed) */
#ifndef MRF24J40_PARAM_SPI_CLK
#define MRF24J40_PARAM_SPI_CLK SPI_CLK_1MHZ /**< SPI bus speed used (can be overriden) */
#endif
#ifndef MRF24J40_PARAM_CS
#define MRF24J40_PARAM_CS GPIO16 /**< MRF24J40 CS signal (can be overriden) */
#endif
#ifndef MRF24J40_PARAM_INT
#define MRF24J40_PARAM_INT GPIO0 /**< MRF24J40 CS signal (can be overriden) */
#endif
#ifndef MRF24J40_PARAM_RESET
#define MRF24J40_PARAM_RESET GPIO2 /**< MRF24J40 RESET signal (can be overriden) */
#endif
/** @} */
#endif /* defined(MODULE_MRF24J40) || defined(DOXYGEN) */
#if defined(MODULE_SDCARD_SPI) || defined(DOXYGEN)
/**
* @name SD-Card configuration
*
* Configuration of the SD-Card interface when module ```sdcard_spi``` is used.
*
* The SPI interface with the corresponding pins used for the SD-Card
* interface is fixed. SPI_DEV(0) is always used for the SD-Card. The only
* configuration that can be overridden by \ref esp8266_app_spec_conf
* "Application Specific Board Configuration" is the CS signal.
* If not defined, the default CS signal of SPI_DEV(0) is used.
* @{
*/
#define SDCARD_SPI_PARAM_SPI SPI_DEV(0) /**< SPI_DEV(0) is used (fixed) */
#define SDCARD_SPI_PARAM_CLK SPI0_SCK_GPIO /**< SPI_DEV(0) SCK is used (fixed) */
#define SDCARD_SPI_PARAM_MOSI SPI0_MOSI_GPIO /**< SPI_DEV(0) MOSI is used (fixed) */
#define SDCARD_SPI_PARAM_MISO SPI0_MISO_GPIO /**< SPI_DEV(0) MISO is used (fixed) */
#define SDCARD_SPI_PARAM_POWER GPIO_UNDEF /**< power control is not used (fixed) */
#ifndef SDCARD_SPI_PARAM_CS
#define SDCARD_SPI_PARAM_CS SPI0_CS0_GPIO /**< SD-Card CS signal (can be overridden) */
#endif
/** @} */
#endif /* defined(MODULE_SDCARD_SPI) || defined(DOXYGEN) */
#ifdef __cplusplus
} /* end extern "C" */
#endif
/** @} */
#endif /* BOARD_MODULES_H */

View File

@ -0,0 +1,166 @@
/*
* Copyright (C) 2018 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup boards_common_esp8266
* @brief Configurations of the MCU periphery that are common for all
* ESP8266 boards
* @file
* @author Gunar Schorcht <gunar@schorcht.net>
* @{
*/
#ifndef PERIPH_CONF_COMMON_H
#define PERIPH_CONF_COMMON_H
/* include board.h and periph_cpu.h to make them visible in any case */
#include "board.h"
#include "periph_cpu.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef BIT
#define BIT(X) (1<<(X))
#endif
/**
* @name ADC configuration
*
* ESP8266 provides one ADC pin that is broken out on all boards.
* @{
*/
#define ADC_NUMOF 1 /**< number of ADC channels */
/** @} */
/**
* @name PWM configuration
*
* The hardware implementation of ESP8266 PWM supports only frequencies as power of
* two. Therefore a software implementation of one PWM device PWM_DEV(0) with up to
* 8 PWM channels (PWM_CHANNEL_NUM_MAX) is used.
*
* @note The minumum PWM period that can be realized is 10 us or 100.000 PWM
* clock cycles per second. Therefore, the product of frequency and resolution
* should not be greater than 100.000. Otherwise the frequency is scaled down
* automatically.
*
* @{
*/
#define PWM_NUMOF (1) /**< Number of PWM devices */
/**
* @brief Maximum number of channels per PWM device.
*/
#define PWM_CHANNEL_NUM_MAX (8)
/**
* @brief Definition of GPIOs that can be used as PWM channels
* of device PWM_DEV(0).
*
* The following definition is just an example configuration. Declare up to
* \ref PWM_CHANNEL_NUM_MAX GPIOs as PWM channels. GPIOs with a duty cycle
* value of 0 can be used as normal GPIOs for other purposes. GPIOs in the
* list that are used for other purposes, e.g., I2C or SPI, are then not
* available as PWM channels.
*/
#ifndef PWM0_CHANNEL_GPIOS
#define PWM0_CHANNEL_GPIOS { GPIO2, GPIO4, GPIO5 }
#endif
/** Alternative device definition */
#define PWM0_DEV PWM_DEV(0)
/** @} */
/**
* @name SPI configuration
*
* ESP8266 provides two hardware SPI interfaces:
*
* _FSPI_ for flash memory and usually simply referred to as _SPI_<br>
* _HSPI_ for peripherals
*
* Even though _FSPI_ (or simply _SPI_) is a normal SPI interface, it is not
* possible to use it for peripherals. _HSPI_ is therefore the only usable
* SPI interface available for peripherals as RIOT's SPI_DEV(0).
*
* The pin configuration of the _HSPI_ interface SPI_DEV(0) is fixed. The
* only pin definition that can be overridden by an application-specific
* board configuration is the CS signal defined by SPI0_CS0_GPIO.
*
* Signal | Pin
* ----------------|-------
* SPI_DEV(0).MISO | GPIO12
* SPI_DEV(0).MOSI | GPIO13
* SPI_DEV(0).SCK | GPIO14
* SPI_DEV(0).CS | GPIOn with n = 0, 2, 4, 5, 15, 16 (additionally 9, 10 in DOUT flash mode)
* @{
*/
#if defined(MODULE_PERIPH_SPI) || defined(DOXYGEN)
#define SPI_NUMOF 1 /**< Number of SPI interfaces */
#define SPI_DEV(x) ((unsigned int)(x+1)) /**< SPI_DEV to SPI hardware mapping */
#define SPI0_DEV SPI_DEV(0) /**< HSPI / SPI_DEV(0) device */
#define SPI0_MISO_GPIO GPIO12 /**< HSPI / SPI_DEV(0) MISO pin */
#define SPI0_MOSI_GPIO GPIO13 /**< HSPI / SPI_DEV(0) MOSI pin */
#define SPI0_SCK_GPIO GPIO14 /**< HSPI / SPI_DEV(0) SCK pin */
#ifndef SPI0_CS0_GPIO
#define SPI0_CS0_GPIO GPIO15 /**< HSPI / SPI_DEV(0) CS default pin, only used when cs
parameter in spi_acquire is GPIO_UNDEF */
#endif
#endif /* defined(MODULE_PERIPH_SPI) || defined(DOXYGEN) */
/** @} */
/**
* @name Timer configuration
* @{
*/
#if defined(MODULE_ESP_SW_TIMER)
/* software timer */
#define TIMER_NUMOF (1U) /**< number of timer devices */
#define TIMER_CHANNELS (10U) /**< number of channels per timer device */
#else /* MODULE_ESP_SW_TIMER */
/* hardware timer */
#define TIMER_NUMOF (1U) /**< number of timer devices */
#define TIMER_CHANNELS (1U) /**< number of channels per timer device */
#endif /* MODULE_ESP_SW_TIMER */
/** @} */
/**
* @name UART configuration
*
* All ESP8266 boards have exactly one UART device with fixed pin mapping.
* This UART device is used for flashing and as a console interface.
* Therefore, the number of UART devices is fixed and can not be overridden.
* Used pins are determined by the MCU implementation and are defined here
* only for documentation reasons.
*
* @{
*/
#define UART_NUMOF 1 /**< Number of UART devices */
#define UART0_TXD GPIO1 /**< TxD pin of UART_DEV(0) */
#define UART0_RXD GPIO3 /**< RxD pin of UART_DEV(0) */
/** @} */
#ifdef __cplusplus
} /* end extern "C" */
#endif
#endif /* PERIPH_CONF_COMMON_H */
/** @} */