Skip to content
Snippets Groups Projects
Commit 2cd167f2 authored by Lukas Friedrichsen's avatar Lukas Friedrichsen
Browse files

RSSI-measuring as well as a simple UDP-broadcast project and drivers for...

RSSI-measuring as well as a simple UDP-broadcast project and drivers for SSD1306 OLED-displays added
parent fb8197fb
No related branches found
No related tags found
No related merge requests found
Showing
with 3730 additions and 0 deletions
...@@ -54,3 +54,6 @@ own projects settings can be found at ...@@ -54,3 +54,6 @@ own projects settings can be found at
Notes: - If not configured otherwise in your program, the ESP8266 uses a Notes: - If not configured otherwise in your program, the ESP8266 uses a
baudrate of 74880 baud to communicate via serial by default! baudrate of 74880 baud to communicate via serial by default!
- If you want to flash an ESP without integrated USB-serial-converter,
you have to connect GPIO0 to GND and CH_PD to VCC.
/build
/firmware
.pioenvs
.piolibdeps
.clang_complete
.gcc-flags.json
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < http://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < http://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < http://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choice one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#
#
# Template #1: General project. Test it using existing `platformio.ini`.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
#
# script:
# - platformio run
#
# Template #2: The project is intended to by used as a library with examples
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
/home/lukas/Espressif/libs_extern/Adafruit-GFX/
\ No newline at end of file
/home/lukas/Espressif/libs_extern/Adafruit-SSD1306_Canadaduane/
\ No newline at end of file
This directory is intended for the project specific (private) libraries.
PlatformIO will compile them to static libraries and link to executable file.
The source code of each library should be placed in separate directory, like
"lib/private_lib/[here are source files]".
For example, see how can be organized `Foo` and `Bar` libraries:
|--lib
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |- readme.txt --> THIS FILE
|- platformio.ini
|--src
|- main.c
Then in `src/main.c` you should use:
#include <Foo.h>
#include <Bar.h>
// rest H/C/CPP code
PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.
More information about PlatformIO Library Dependency Finder
- http://docs.platformio.org/page/librarymanager/ldf.html
// user_config.h
// Copyright 2017 Lukas Friedrichsen
// License: Modified BSD-License
//
// 2017-02-28
/*------------ user configurable --------------*/
#define TARGET_SSID "testNetwork"
#define BLINK_THRESHOLD -70
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[env:nodemcu]
platform = espressif8266
board = nodemcu
framework = arduino
// main.cpp
// Copyright 2017 Lukas Friedrichsen
// License: Modified BSD-License
//
// 2017-02-28
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#include "../lib/user_config.h"
#define OLED_RESET 16
Adafruit_SSD1306 display(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
#define onboardLED 2
int32_t rssi;
// Measures and returns the wireless-networks RSSI-value
int32_t getRSSI(String target_ssid) {
uint8_t available_networks = WiFi.scanNetworks();
String network_ssid;
for (int network = 0; network < available_networks; network++) {
network_ssid = WiFi.SSID(network);
Serial.println(target_ssid+" "+network_ssid+" "+network_ssid.compareTo(target_ssid));
if (network_ssid.compareTo(target_ssid) == 0 && network_ssid.length() == target_ssid.length()) {
return WiFi.RSSI(network);
}
}
// Return 0 if the specified network wasn't found
return 0;
}
void setup() {
// Initializing...
Serial.begin(115200);
Serial.println("Initializing...");
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize with the I2C addr 0x3C (for the 128x64)
pinMode(onboardLED, OUTPUT);
digitalWrite(onboardLED, HIGH);
// Set the textsize and -color
display.setTextColor(WHITE);
}
void loop() {
rssi = getRSSI(TARGET_SSID);
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0,0);
display.printf("SSID: %s\n",TARGET_SSID);
display.setCursor(0,12);
display.print("Status: ");
if (rssi) {
display.println("found!");
}
else {
display.println("not found!");
}
display.setTextSize(2);
display.setCursor(0,36);
display.printf("RSSI: %d\n",rssi);
display.display();
if (rssi > BLINK_THRESHOLD && rssi != 0) {
digitalWrite(onboardLED, LOW);
}
else {
digitalWrite(onboardLED, HIGH);
}
}
// RSSIMeter
// Copyright 2017 Lukas Friedrichsen
// License: Modified BSD-License
//
// 2017-02-23
Modified BSD License
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. The name of the author may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "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 AUTHOR 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.
# This makefile is based on https://github.com/esp8266/source-code-examples/blob/master/example.Makefile
# Makefile for ESP8266 projects
# Output directors to store intermediate compiled files
# relative to the project directory
BUILD_BASE = build
FW_BASE = firmware
# base directory for the compiler
XTENSA_TOOLS_ROOT ?= $(ESP8266_BUILD)
# base directory of the ESP8266 SDK package, absolute
SDK_BASE ?= $(ESP8266_SDK_ROOT)
# esptool.py path and port
ESPTOOL ?= $(ESP8266_SDK_ROOT)/../esptool/esptool.py
ESPPORT ?= /dev/ttyUSB0
# name for the target project
TARGET = app
# which modules (subdirectories) of the project to include in compiling
MODULES = driver/ESP-I2C-OLED-SSD1306/user user
EXTRA_INCDIR = include driver/ESP-I2C-OLED-SSD1306/include
# libraries used in this project, mainly provided by the SDK
LIBS = c gcc hal pp phy net80211 lwip wpa main crypto driver
# compiler flags using during compilation of source files
CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH
# linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
# linker script used for the above linkier step
LD_SCRIPT = eagle.app.v6.ld
# various paths from the SDK used in this project
SDK_LIBDIR = lib
SDK_LDDIR = ld
SDK_INCDIR = include include/json driver_lib/include
# we create two different files for uploading into the flash
# these are the names and options to generate them
FW_FILE_1_ADDR = 0x00000
FW_FILE_2_ADDR = 0x10000
# select which tools to use as compiler, librarian and linker
CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc
AR := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-ar
LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc
####
#### no user configurable options below here
####
SRC_DIR := $(MODULES)
BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES))
SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR))
SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR))
SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c))
OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC))
LIBS := $(addprefix -l,$(LIBS))
APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a)
TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out)
LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT))
INCDIR := $(addprefix -I,$(SRC_DIR))
EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR))
MODULE_INCDIR := $(addsuffix /include,$(INCDIR))
FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1_ADDR).bin)
FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2_ADDR).bin)
V ?= $(VERBOSE)
ifeq ("$(V)","1")
Q :=
vecho := @true
else
Q := @
vecho := @echo
endif
vpath %.c $(SRC_DIR)
define compile-objects
$1/%.o: %.c
$(vecho) "CC $$<"
$(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@
endef
.PHONY: all checkdirs flash clean
all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2)
$(FW_BASE)/%.bin: $(TARGET_OUT) | $(FW_BASE)
$(vecho) "FW $(FW_BASE)/"
$(Q) $(ESPTOOL) elf2image -o $(FW_BASE)/ $(TARGET_OUT)
$(TARGET_OUT): $(APP_AR)
$(vecho) "LD $@"
$(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@
$(APP_AR): $(OBJ)
$(vecho) "AR $@"
$(Q) $(AR) cru $@ $^
checkdirs: $(BUILD_DIR) $(FW_BASE)
$(BUILD_DIR):
$(Q) mkdir -p $@
$(FW_BASE):
$(Q) mkdir -p $@
flash: $(FW_FILE_1) $(FW_FILE_2)
$(ESPTOOL) --port $(ESPPORT) --baud 115200 write_flash --flash_mode qio $(FW_FILE_1_ADDR) $(FW_FILE_1) $(FW_FILE_2_ADDR) $(FW_FILE_2)
base:
$(ESPTOOL) --port $(ESPPORT) --baud 115200 write_flash --flash_mode qio 0x01000 $(SDK_BASE)/bin/at/1024+1024/user1.2048.new.5.bin 0x00000 $(SDK_BASE)/bin/boot_v1.6.bin 0xFC000 $(SDK_BASE)/bin/esp_init_data_default.bin 0xFE000 $(SDK_BASE)/bin/blank.bin
clean:
$(Q) rm -rf $(FW_BASE) $(BUILD_BASE)
$(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir))))
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
.dep/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
*.pubxml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#############
## Windows detritus
#############
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
doc/*.docx
Software License Agreement (BSD License)
Copyright (c) 2015, Baoshi Zhu (www.ba0sh1.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* 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.
* Neither the name of Baoshi Zhu nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission from me.
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.
\ No newline at end of file
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of object file images to be generated ()
# GEN_BINS - list of binaries to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
TARGET = eagle
#FLAVOR = release
FLAVOR = debug
#EXTRA_CCFLAGS += -u
ifndef PDIR # {
GEN_IMAGES= eagle.app.v6.out
GEN_BINS= eagle.app.v6.bin
SPECIAL_MKTARGETS=$(APP_MKTARGETS)
SUBDIRS= \
user
endif # } PDIR
APPDIR = .
LDDIR = ../ld
CCFLAGS += -Os
TARGET_LDFLAGS = \
-nostdlib \
-Wl,-EL \
--longcalls \
--text-section-literals
ifeq ($(FLAVOR),debug)
TARGET_LDFLAGS += -g -O2
endif
ifeq ($(FLAVOR),release)
TARGET_LDFLAGS += -g -O0
endif
LD_FILE = $(LDDIR)/eagle.app.v6.ld
ifeq ($(APP), 1)
LD_FILE = $(LDDIR)/eagle.app.v6.app1.ld
endif
ifeq ($(APP), 2)
LD_FILE = $(LDDIR)/eagle.app.v6.app2.ld
endif
COMPONENTS_eagle.app.v6 = \
user/libuser.a
LINKFLAGS_eagle.app.v6 = \
-L../lib \
-nostdlib \
-T$(LD_FILE) \
-Wl,--no-check-sections \
-u call_user_start \
-Wl,-static \
-Wl,--start-group \
-lgcc \
-lhal \
-lphy \
-lpp \
-lnet80211 \
-lwpa \
-lmain \
-lfreertos \
-llwip \
-ludhcp \
$(DEP_LIBS_eagle.app.v6) \
-Wl,--end-group
DEPENDS_eagle.app.v6 = \
$(LD_FILE) \
$(LDDIR)/eagle.rom.addr.v6.ld
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#UNIVERSAL_TARGET_DEFINES = \
# Other potential configuration flags include:
# -DTXRX_TXBUF_DEBUG
# -DTXRX_RXBUF_DEBUG
# -DWLAN_CONFIG_CCX
CONFIGURATION_DEFINES = -D__ets__ \
-DICACHE_FLASH
DEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES)
DDEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES)
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
#########################################################################
#
# generate bin file
#
$(BINODIR)/%.bin: $(IMAGEODIR)/%.out
@mkdir -p $(BINODIR)
$(OBJCOPY) -O binary $< $@
.PHONY: FORCE
FORCE:
/**
******************************************************************************
* @file fonts.h
* @author Baoshi <mail(at)ba0sh1(dot)com>
* @version 0.8
* @date Jan 3, 2014
* @brief Font description for OLED display, based on
* <a href="http://www.eran.io/the-dot-factory-an-lcd-font-and-image-generator/">
* "TheDotFactory"</a> by Eran "Pavius" Duchan
*
******************************************************************************
* @copyright
*
* Copyright (c) 2015, Baoshi Zhu. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE.txt file.
*
* THIS SOFTWARE IS PROVIDED 'AS-IS', WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN NO EVENT WILL THE AUTHOR(S) BE HELD LIABLE FOR ANY DAMAGES
* ARISING FROM THE USE OF THIS SOFTWARE.
*
*/
#ifndef FONTS_H
#define FONTS_H
//! @brief Character descriptor
typedef struct _font_char_desc
{
uint8_t width; //!< Character width in pixel
uint16_t offset; //!< Offset of this character in bitmap
} font_char_desc_t;
//! @brief Font information
typedef struct _font_info
{
uint8_t height; //!< Character height in pixel, all characters have same height
uint8_t c; //!< Simulation of "C" width in TrueType term, the space between adjacent characters
char char_start; //!< First character
char char_end; //!< Last character
const font_char_desc_t* char_descriptors; //! descriptor for each character
const uint8_t *bitmap; //!< Character bitmap
} font_info_t;
#define NUM_FONTS 2 //!< Number of built-in fonts
extern const font_info_t * fonts[NUM_FONTS]; //!< Built-in fonts
#endif /* FONTS */
/**
******************************************************************************
* @file i2c.h
* @author Baoshi <mail(at)ba0sh1(dot)com>
* @version 0.1
* @date Dec 24, 2014
* @brief Bit-bang I2C interface for ESP8266. For pin selection, edit
* the configuration block in i2c.c
*
******************************************************************************
* @copyright
*
* Copyright (c) 2015, Baoshi Zhu. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE.txt file.
*
* THIS SOFTWARE IS PROVIDED 'AS-IS', WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN NO EVENT WILL THE AUTHOR(S) BE HELD LIABLE FOR ANY DAMAGES
* ARISING FROM THE USE OF THIS SOFTWARE.
*
*/
#ifndef I2C_H_
#define I2C_H_
/**
* @brief Initialize I2C GPIO pins
*/
void i2c_init(void);
/**
* @brief Send I2C start bit
* @return true if start successfully. Otherwise the bus is busy
*/
bool i2c_start(void);
/**
* @brief Send I2C stop bit
*/
void i2c_stop(void);
/**
* @brief Send data to I2C bus
* @param data Data to send
* @return true if ACK is received at end of sending. False if not ACK'ed
*/
bool i2c_write(uint8_t data);
/**
* @brief Read data from I2C bus
* @return Data read
*/
uint8_t i2c_read(void);
/**
* @brief Send acknowledge bit (at end of reading)
* @param ack ACK (true) or NACK (false)
*/
void i2c_set_ack(bool ack);
#endif
/**
******************************************************************************
* @file ssd1306.h
* @author Baoshi <mail(at)ba0sh1(dot)com>
* @version 0.6
* @date Dec 29, 2014
* @brief SSD1306 OLED driver interface for ESP8266. For panel
* configuration, edit the panel option block in ssd1306_i2c.c
*
******************************************************************************
* @copyright
*
* Many of the work here are based on Adafruit SSD1306 and GFX Arduino library.
* Please support Adafruit by purchasing products from Adafruit!
*
* Copyright (c) 2015, Baoshi Zhu. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE.txt file.
*
* THIS SOFTWARE IS PROVIDED 'AS-IS', WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN NO EVENT WILL THE AUTHOR(S) BE HELD LIABLE FOR ANY DAMAGES
* ARISING FROM THE USE OF THIS SOFTWARE.
*
*/
#ifndef SSD1306_H
#define SSD1306_H
//! @brief Drawing color
typedef enum
{
SSD1306_COLOR_TRANSPARENT = -1, //!< Transparent (not drawing)
SSD1306_COLOR_BLACK = 0, //!< Black (pixel off)
SSD1306_COLOR_WHITE = 1, //!< White (or blue, yellow, pixel on)
SSD1306_COLOR_INVERT = 2, //!< Invert pixel (XOR)
} ssd1306_color_t;
/**
* @brief Initialize OLED panel
* @param id Panel ID
* @return true if successful
* @remark Possible reasons for failure include non-configured panel type, out of memory or I2C not responding
*/
bool ssd1306_init(uint8_t id);
/**
* @brief De-initialize OLED panel, turn off power and free memory
* @param id Panel ID
* @return true if successful
* @remark Possible reasons for failure include non-configured panel type, out of memory or I2C not responding
*/
void ssd1306_term(uint8_t id);
/**
* @brief Return OLED panel width
* @param id Panel ID
* @return Panel width, or return 0 if failed (panel not initialized)
*/
uint8_t ssd1306_get_width(uint8_t id);
/**
* @brief Return OLED panel height
* @param id Panel ID
* @return Panel height, or return 0 if failed (panel not initialized)
*/
uint8_t ssd1306_get_height(uint8_t id);
/**
* @brief Clear display buffer (fill with black)
* @param id Panel ID
*/
void ssd1306_clear(uint8_t id);
/**
* @brief Refresh display (send display buffer to the panel)
* @param id Panel ID
* @param force The program automatically tracks "dirty" region to minimize refresh area. Set #force to true
* ignores the dirty region and refresh the whole screen.
*/
void ssd1306_refresh(uint8_t id, bool force);
/**
* @brief Draw one pixel
* @param id Panel ID
* @param x X coordinate
* @param y Y coordinate
* @param color Color of the pixel
*/
void ssd1306_draw_pixel(uint8_t id, int8_t x, int8_t y, ssd1306_color_t color);
/**
* @brief Draw horizontal line
* @param id Panel ID
* @param x X coordinate or starting (left) point
* @param y Y coordinate or starting (left) point
* @param w Line width
* @param color Color of the line
*/
void ssd1306_draw_hline(uint8_t id, int8_t x, int8_t y, uint8_t w, ssd1306_color_t color);
/**
* @brief Draw vertical line
* @param id Panel ID
* @param x X coordinate or starting (top) point
* @param y Y coordinate or starting (top) point
* @param h Line height
* @param color Color of the line
*/
void ssd1306_draw_vline(uint8_t id, int8_t x, int8_t y, uint8_t h, ssd1306_color_t color);
/**
* @brief Draw a rectangle
* @param id Panel ID
* @param x X coordinate or starting (top left) point
* @param y Y coordinate or starting (top left) point
* @param w Rectangle width
* @param h Rectangle height
* @param color Color of the rectangle border
*/
void ssd1306_draw_rectangle(uint8_t id, int8_t x, int8_t y, uint8_t w, uint8_t h, ssd1306_color_t color);
/**
* @brief Draw a filled rectangle
* @param id Panel ID
* @param x X coordinate or starting (top left) point
* @param y Y coordinate or starting (top left) point
* @param w Rectangle width
* @param h Rectangle height
* @param color Color of the rectangle
*/
void ssd1306_fill_rectangle(uint8_t id, int8_t x, int8_t y, uint8_t w, uint8_t h, ssd1306_color_t color);
/**
* @brief Draw a circle
* @param id Panel ID
* @param x0 X coordinate or center
* @param y0 Y coordinate or center
* @param r Radius
* @param color Color of the circle
*/
void ssd1306_draw_circle(uint8_t id, int8_t x0, int8_t y0, uint8_t r, ssd1306_color_t color);
/**
* @brief Draw a filled circle
* @param id Panel ID
* @param x0 X coordinate or center
* @param y0 Y coordinate or center
* @param r Radius
* @param color Color of the circle
*/
void ssd1306_fill_circle(uint8_t id, int8_t x0, int8_t y0, uint8_t r, ssd1306_color_t color);
/**
* @brief Select font for drawing
* @param id Panel ID
* @param idx Font index, see fonts.c
*/
void ssd1306_select_font(uint8_t id, uint8_t idx);
/**
* @brief Draw one character using currently selected font
* @param id Panel ID
* @param x X position of character (top-left corner)
* @param y Y position of character (top-left corner)
* @param c The character to draw
* @param foreground Character color
* @param background Background color
* @return Width of the character
*/
uint8_t ssd1306_draw_char(uint8_t id, uint8_t x, uint8_t y, char c, ssd1306_color_t foreground, ssd1306_color_t background);
/**
* @brief Draw string using currently selected font
* @param id Panel ID
* @param x X position of string (top-left corner)
* @param y Y position of string (top-left corner)
* @param str The string to draw
* @param foreground Character color
* @param background Background color
* @return Width of the string (out-of-display pixels also included)
*/
uint8_t ssd1306_draw_string(uint8_t id, uint8_t x, uint8_t y, char *str, ssd1306_color_t foreground, ssd1306_color_t background);
/**
* @brief Measure width of string with current selected font
* @param id Panel ID
* @param str String to measure
* @return Width of the string
*/
uint8_t ssd1306_measure_string(uint8_t id, char *str);
/**
* @brief Get the height of current selected font
* @param id Panel ID
* @return Height of the font (in pixels) or 0 if no font selected
*/
uint8_t ssd1306_get_font_height(uint8_t id);
/**
* @brief Get the "C" value (space between adjacent characters)
* @param id Panel ID
* @return "C" value
*/
uint8_t ssd1306_get_font_c(uint8_t id);
/**
* @brief Set normal or inverted display
* @param id Panel ID
* @param invert Invert display?
*/
void ssd1306_invert_display(uint8_t id, bool invert);
/**
* @brief Direct update display buffer
* @param id Panel ID
* @param data Data to fill display buffer, no length check is performed!
* @param length Length of data
*/
void ssd1306_update_buffer(uint8_t id, uint8_t* data, uint16_t length);
#endif /* SSD1306_H */
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment