Merge pull request #1 from arendst/development

Merge code
This commit is contained in:
Laurent 2019-08-26 15:20:46 -04:00 committed by GitHub
commit 392287dcc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
914 changed files with 162341 additions and 33654 deletions

View File

@ -15,6 +15,8 @@ about: Create a report to help us improve
<If your issue has been addresed before (duplicated issue), please ask in the original issue>
<If your issue is wifi problem or mqtt problem, please try first the steps provided in troubleshooting of the wiki>
Please take a few minutes to complete the requested information below. Our ability to provide assistance is greatly hampered without it. The details requested potentially affect which options to pursue. The small amount of time you spend completing the template will also help the volunteers providing the assistance to you to reduce the time required to help you.
### BUG DESCRIPTION
_A clear and concise description of what the bug is._

View File

@ -17,6 +17,8 @@ about: Users Troubleshooting Help
<If your issue has been addresed before (duplicated issue), please ask in the original issue>
<If your issue is wifi problem or mqtt problem, please try first the steps provided in troubleshooting of the wiki>
Please take a few minutes to complete the requested information below. Our ability to provide assistance is greatly hampered without it. The details requested potentially affect which options to pursue. The small amount of time you spend completing the template will also help the volunteers providing the assistance to you to reduce the time required to help you.
### ISSUE DESCRIPTION - TROUBLESHOOTING
_A clear description of what the issue is and be as extensive as possible_

View File

@ -3,7 +3,9 @@ name: Feature request
about: Suggest an idea for this project
---
**Have you look for this feature in other issues and in the wiki?**
Please take a few minutes to complete the requested information below. Our ability to provide assistance is greatly hampered without it. The details requested potentially affect which options to pursue. The small amount of time you spend completing the template will also help the volunteers providing the assistance to you to reduce the time required to help you.
**Have you looked for this feature in other issues and in the wiki?**
**Is your feature request related to a problem? Please describe.**
_A clear and concise description of what the problem is._

View File

@ -4,8 +4,8 @@
## Checklist:
- [ ] The pull request is done against the latest dev branch
- [ ] Only relevant files were touched (Also remember to update _changelog.ino_ file)
- [ ] Only relevant files were touched
- [ ] Only one feature/fix was added per PR.
- [ ] The code change is tested and works.
- [ ] The code change is tested and works on core 2.3.0, 2.4.2 and 2.5.2
- [ ] The code change pass travis tests. **Your PR cannot be merged unless tests pass**
- [ ] I accept the [CLA](https://github.com/arendst/Sonoff-Tasmota/blob/development/CONTRIBUTING.md#contributor-license-agreement-cla).

5
API.md
View File

@ -1,4 +1,7 @@
## Sonoff-Tasmota basic API information
<img src="/tools/logo/TASMOTA_FullLogo_Vector.svg" alt="Logo" align="right" height="76"/>
# Basic API information
Sonoff-Tasmota can easily be extended by developers using provided function pointers as callback Ids. This document lists the available callback function Ids. See the wiki (https://github.com/arendst/Sonoff-Tasmota/wiki/Sensor-API) for more information.
Callback availability can be checked by searching for either XdrvCall, XsnsCall, XdspCall and XnrgCall.

View File

@ -1,4 +1,6 @@
# Contributing to Sonoff-Tasmota
<img src="/tools/logo/TASMOTA_FullLogo_Vector.svg" alt="Logo" align="right" height="76"/>
# Contributing
**Any contribution helps our team and makes Tasmota better for the entire community!**
@ -26,7 +28,7 @@ This document describes rules that are in effect for this repository, meant for
1. Any contributor to the project can participate in the triaging process, if he/she chooses to do so.
2. An issue that needs to be closed, either due to not complying with this policy, or for other reasons, should be closed by a contributor.
3. Issues that are accepted should be marked with appropriate labels.
4. Issues that could impact functionality for many users should be considered severe.
4. Issues that could impact functionality for many users should be considered severe.
5. Issues caused by the SDK or chip should not be marked severe, as there usually isnt much to be done. Common sense should be applied when deciding. Such issues should be documented in the Wiki, for reference by users.
6. Issues with feature requests should be discussed for viability/desirability.
7. Feature requests or changes that are meant to address a very specific/limited use case, especially if at the expense of increased code complexity, may be denied, or may be required to be redesigned, generalized, or simplified.
@ -100,7 +102,7 @@ A CLA is a legal document in which you state _you are entitled to contribute the
CLA is a safety because it also ensures that once you have provided a contribution, you cannot try to withdraw permission for its use at a later date. People can therefore use that software, confident that they will not be asked to stop using pieces of the code at a later date.
A __license__ grants "outbound" rights to the user of project.
A __license__ grants "outbound" rights to the user of project.
A __CLA__ enables a contributor to grant "inbound" rights to a project.

View File

@ -1,5 +1,6 @@
## Sonoff-Tasmota
<img src="/tools/logo/TASMOTA_FullLogo_Vector.svg" alt="Logo" align="right" height="76"/>
# Sonoff-Tasmota
Alternative firmware for _ESP8266 based devices_ like [iTead](https://www.itead.cc/) _**Sonoff**_ with **web UI, rules and timers, OTA updates, custom device templates and sensor support**. Allows control over **MQTT**, **HTTP**, **Serial** and **KNX** for integrations with smart home systems. Written for Arduino IDE and PlatformIO.
[![GitHub version](https://img.shields.io/github/release/arendst/Sonoff-Tasmota.svg)](https://github.com/arendst/Sonoff-Tasmota/releases/latest)
@ -15,43 +16,43 @@ If you like **Sonoff-Tasmota**, give it a star, or fork it and contribute!
See [RELEASENOTES.md](https://github.com/arendst/Sonoff-Tasmota/blob/development/RELEASENOTES.md) for release information.
In addition to the [release webpage](https://github.com/arendst/Sonoff-Tasmota/releases/latest), the binaries can also be OTA downloaded from http://thehackbox.org/tasmota/release/
In addition to the [release webpage](https://github.com/arendst/Sonoff-Tasmota/releases/latest) the binaries can also be downloaded from http://thehackbox.org/tasmota/release/
### Development
[![Dev Version](https://img.shields.io/badge/development%20version-6.5.0.x-blue.svg)](https://github.com/arendst/Sonoff-Tasmota)
## Development
[![Dev Version](https://img.shields.io/badge/development%20version-v6.6.0.x-blue.svg)](https://github.com/arendst/Sonoff-Tasmota)
[![Download Dev](https://img.shields.io/badge/download-development-yellow.svg)](http://thehackbox.org/tasmota/)
[![Build Status](https://img.shields.io/travis/arendst/Sonoff-Tasmota.svg)](https://travis-ci.org/arendst/Sonoff-Tasmota)
See [RELEASENOTES.md](https://github.com/arendst/Sonoff-Tasmota/blob/development/RELEASENOTES.md) for release information and [sonoff/_changelog.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_changelog.ino) for detailed change information.
See [sonoff/_changelog.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_changelog.ino) for detailed change information.
The development codebase is checked hourly for changes and if new commits have been merged and compile successfuly they will be posted at http://thehackbox.org/tasmota/ (this web address can be used for OTA too). It is important to note that these are based on the current development codebase and it is not recommended to flash it to devices used in production or which are hard to reach in the event that you need to manually flash the device if OTA failed. The last compiled commit number is also posted on the same page along with the current build status (if a firmware rebuild is in progress).
### Disclaimer
## Disclaimer
:warning: **DANGER OF ELECTROCUTION** :warning:
A Sonoff device is not a toy. It uses Mains AC so there is a danger of electrocution if not installed properly. If you don't know how to install it, please call an electrician. Remember: _**SAFETY FIRST**_. It is not worth risk to yourself, your family, and your home if you don't know exactly what you are doing. Never try to flash a Sonoff device while it is connected to MAINS AC.
We don't take any responsibility nor liability for using this software nor for the installation or any tips, advice, videos, etc. given by any member of this site or any related site.
### Note
Please do not ask to add devices where you can't provide a basic working configuration (other than sonoff). Since there are thousands of them.
## Note
Please do not ask to add new devices unless it requires additional code for new features. If the device is not listed as a module, try using [Templates](https://github.com/arendst/Sonoff-Tasmota/wiki/Templates) first. If it is not listed in the [Tasmota Device Templates Repository](http://blakadder.github.io/templates) create your own [Template](https://github.com/arendst/Sonoff-Tasmota/wiki/Templates#creating-your-template-).
### Quick Install
Download one of the released binaries from https://github.com/arendst/Sonoff-Tasmota/releases and flash it to your hardware as documented in the wiki.
## Quick Install
Download one of the released binaries from https://github.com/arendst/Sonoff-Tasmota/releases and flash it to your hardware as [documented in the wiki](https://github.com/arendst/Sonoff-Tasmota/wiki/Flashing).
### Important User Compilation Information
## Important User Compilation Information
If you want to compile Sonoff-Tasmota yourself keep in mind the following:
- Only Flash Mode **DOUT** is supported. Do not use Flash Mode DIO / QIO / QOUT as it might seem to brick your device. See [Wiki](https://github.com/arendst/Sonoff-Tasmota/wiki/Theo's-Tasmota-Tips) for background information.
- Sonoff-Tasmota uses a 1M linker script WITHOUT spiffs **1M (no SPIFFS)** for optimal code space. If you compile using ESP/Arduino library 2.3.0 then download the provided new linker script to your Arduino IDE or Platformio base folder. Later version of ESP/Arduino library already contain the correct linker script. See [Wiki > Prerequisite](https://github.com/arendst/Sonoff-Tasmota/wiki/Prerequisite).
- Sonoff-Tasmota uses a 1M linker script WITHOUT spiffs **1M (no SPIFFS)** for optimal code space. If you compile using ESP/Arduino library 2.3.0 then download the provided new linker script to your Arduino IDE or Platformio base folder. Later version of ESP/Arduino library already contain the correct linker script. See [Wiki > Prerequisites](https://github.com/arendst/Sonoff-Tasmota/wiki/Prerequisites).
- To make compile time changes to Sonoff-Tasmota it can use the ``user_config_override.h`` file. It assures keeping your settings when you download and compile a new version. To use ``user_config.override.h`` you will have to make a copy of the provided ``user_config_override_sample.h`` file and add your setting overrides. To enable the override file you will need to use a compile define as documented in the ``user_config_override_sample.h`` file.
### Version Information
## Version Information
- Sonoff-Tasmota provides all (Sonoff) modules in one file and starts with module Sonoff Basic.
- Once uploaded select module using the configuration webpage or the commands ```Modules``` and ```Module```.
- Once uploaded, select [Module](https://github.com/arendst/Sonoff-Tasmota/wiki/Modules) using the configuration webpage, the commands ```Modules``` and ```Module``` or configure the [Template](https://github.com/arendst/Sonoff-Tasmota/wiki/Templates) for your device
- After reboot select config menu again or use commands ```GPIOs``` and ```GPIO``` to change GPIO with desired sensor.
### Migration Information
## Migration Information
See [wiki migration path](https://github.com/arendst/Sonoff-Tasmota/wiki/Upgrade#migration-path) for instructions how to migrate to a major version. Pay attention to the following version breaks due to dynamic settings updates:
1. Migrate to **Sonoff-Tasmota 3.9.x**
@ -59,56 +60,16 @@ See [wiki migration path](https://github.com/arendst/Sonoff-Tasmota/wiki/Upgrade
3. Migrate to **Sonoff-Tasmota 5.14**
4. Migrate to **Sonoff-Tasmota 6.x**
### Support Information
## Support Information
<img src="https://github.com/arendst/arendst.github.io/blob/master/media/sonoffbasic.jpg" width="250" align="right" />
See [Wiki](https://github.com/arendst/Sonoff-Tasmota/wiki) for more information.<br />
For a database of supported devices see [Tasmota Device Templates Repository](https://blakadder.github.io/templates)
See [Wiki](https://github.com/arendst/Sonoff-Tasmota/wiki) for use instructions and how-to's.<br />
See [Community](https://groups.google.com/d/forum/sonoffusers) for forum.<br />
Visit [Discord Chat](https://discord.gg/Ks2Kzd4) for discussions and troubleshooting.
The following devices are supported:
- [iTead Sonoff Basic (R2)](https://www.itead.cc/smart-home/sonoff-wifi-wireless-switch-1.html)
- [iTead Sonoff RF](https://www.itead.cc/smart-home/sonoff-rf.html)
- [iTead Sonoff SV](https://www.itead.cc/smart-home/sonoff-sv.html)<img src="https://github.com/arendst/arendst.github.io/blob/master/media/sonoff_th.jpg" width="250" align="right" />
- [iTead Sonoff TH10/TH16 with temperature sensor](https://www.itead.cc/smart-home/sonoff-th.html)
- [iTead Sonoff Dual (R2)](https://www.itead.cc/smart-home/sonoff-dual.html)
- [iTead Sonoff Pow with Energy Monitoring](https://www.itead.cc/smart-home/sonoff-pow.html)
- [iTead Sonoff Pow R2 with Energy Monitoring](https://www.itead.cc/sonoff-pow-r2.html)
- [iTead Sonoff 4CH (R2)](https://www.itead.cc/smart-home/sonoff-4ch.html)
- [iTead Sonoff 4CH Pro (R2)](https://www.itead.cc/smart-home/sonoff-4ch-pro.html)
- [iTead Sonoff S20 Smart Socket](https://www.itead.cc/smart-socket.html)
- [Sonoff S22 Smart Socket](https://github.com/arendst/Sonoff-Tasmota/issues/627)
- [iTead Sonoff S26 Smart Socket](https://www.itead.cc/sonoff-s26-wifi-smart-plug.html)
- [iTead Sonoff S31 Smart Socket with Energy Monitoring](https://www.itead.cc/sonoff-s31.html)
- [iTead Slampher](https://www.itead.cc/slampher.html)
- [iTead Sonoff Touch](https://www.itead.cc/sonoff-touch.html)
- [iTead Sonoff T1](https://www.itead.cc/sonoff-t1.html)
- [iTead Sonoff SC](https://www.itead.cc/sonoff-sc.html)
- [iTead Sonoff Led](https://www.itead.cc/sonoff-led.html)<img src="https://github.com/arendst/arendst.github.io/blob/master/media/sonoff4chpror2.jpg" height="250" align="right" />
- [iTead Sonoff BN-SZ01 Ceiling Led](https://www.itead.cc/bn-sz01.html)
- [iTead Sonoff B1](https://www.itead.cc/sonoff-b1.html)
- [iTead Sonoff iFan02](https://www.itead.cc/sonoff-ifan02-wifi-smart-ceiling-fan-with-light.html)
- [iTead Sonoff RF Bridge 433](https://www.itead.cc/sonoff-rf-bridge-433.html)
- [iTead Sonoff Dev](https://www.itead.cc/sonoff-dev.html)
- [iTead 1 Channel Switch 5V / 12V](https://www.itead.cc/smart-home/inching-self-locking-wifi-wireless-switch.html)
- [iTead Motor Clockwise/Anticlockwise](https://www.itead.cc/smart-home/motor-reversing-wifi-wireless-switch.html)
- [Electrodragon IoT Relay Board](http://www.electrodragon.com/product/wifi-iot-relay-board-based-esp8266/)
- AI Light or any my9291 compatible RGBW LED bulb
- H801 PWM LED controller
- [MagicHome PWM LED controller](https://github.com/arendst/Sonoff-Tasmota/wiki/MagicHome-LED-strip-controller)
- AriLux AL-LC01, AL-LC06 and AL-LC11 PWM LED controller
- [Supla device - Espablo-inCan mod. for electrical Installation box](https://forum.supla.org/viewtopic.php?f=33&t=2188)
- [BlitzWolf BW-SHP2 Smart Socket with Energy Monitoring](https://www.banggood.com/BlitzWolf-BW-SHP2-Smart-WIFI-Socket-EU-Plug-220V-16A-Work-with-Amazon-Alexa-Google-Assistant-p-1292899.html)<img src="https://github.com/arendst/arendst.github.io/blob/master/media/shelly2_small_250a.png" width="250" align="right" />
- [Luani HVIO board](https://luani.de/projekte/esp8266-hvio/)
- [Wemos D1 mini](https://wiki.wemos.cc/products:d1:d1_mini)
- [HuaFan Smart Socket](https://github.com/arendst/Sonoff-Tasmota/wiki/HuaFan-Smart-Socket)
- [Hyleton-313 Smart Plug](https://github.com/arendst/Sonoff-Tasmota/wiki/Hyleton-313-Smart-Plug)
- [Allterco Shelly 1](https://shelly.cloud/shelly1-open-source/)
- [Allterco Shelly 2 with Energy Monitoring](https://shelly.cloud/shelly2/)
- NodeMcu and Ledunia
- [KS-602 based switches like GresaTek, Jesiya, NewRice, Lyasi etc](https://ucexperiment.wordpress.com/2017/11/14/reprogramming-a-lyasi-wifi-wall-switch-with-esp8285/)
### Contribute
## Contribute
You can contribute to Sonoff-Tasmota by
- providing Pull Requests (Features, Proof of Concepts, Language files or Fixes)
- testing new released features and report issues
@ -117,9 +78,9 @@ You can contribute to Sonoff-Tasmota by
[![donate](https://img.shields.io/badge/donate-PayPal-blue.svg)](https://paypal.me/tasmota)
### Credits
## Credits
#### Libraries Used
### Libraries Used
Libraries used with Sonoff-Tasmota are:
- [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)
- [Adafruit CCS811](https://github.com/adafruit/Adafruit_CCS811)
@ -146,7 +107,7 @@ Libraries used with Sonoff-Tasmota are:
- [PubSubClient](https://github.com/knolleary/pubsubclient)
- [rc-switch](https://github.com/sui77/rc-switch)
#### People inspiring me
### People inspiring me
People helping to keep the show on the road:
- David Lang providing initial issue resolution and code optimizations
- Heiko Krupp for his IRSend, HTU21, SI70xx and Wemo/Hue emulation drivers
@ -162,7 +123,7 @@ People helping to keep the show on the road:
- Emontnemery for his HomeAssistant Discovery concept and many code tuning tips
- Aidan Mountford for his HSB support
- Daniel Ztolnai for his Serial Bridge implementation
- Gerhard Mutz for his SGP30, Sunrise/Sunset and display support drivers
- Gerhard Mutz for multiple sensor & display drivers, Sunrise/Sunset, and scripting
- Nuno Ferreira for his HC-SR04 driver
- Adrian Scillato for his (security)fixes and implementing and maintaining KNX
- Gennaro Tortone for implementing and maintaining Eastron drivers
@ -172,8 +133,10 @@ People helping to keep the show on the road:
- Joel Stein and digiblur for their Tuya research and driver
- Frogmore42 and Jason2866 for providing many issue answers
- Blakadder for editing the wiki and providing template management
- Stephan Hadinger for refactoring light driver and enhancing HueEmulation
- tmo for designing the official logo
- Many more providing Tips, Wips, Pocs or PRs
### License
## License
This program is licensed under GPL-3.0

View File

@ -1,4 +1,7 @@
## Tasmota Reference
<img src="/tools/logo/TASMOTA_FullLogo_Vector.svg" alt="Logo" align="right" height="76"/>
# Reference
Tasmota backgound information.
## Supported Smart Switch with Energy Monitoring GPIO usage

View File

@ -1,3 +1,7 @@
<img src="/tools/logo/TASMOTA_FullLogo_Vector.svg" alt="Logo" align="right" height="76"/>
# RELEASE NOTES
## Migration Information
See [wiki migration path](https://github.com/arendst/Sonoff-Tasmota/wiki/Upgrade#migration-path) for instructions how to migrate to a major version. Pay attention to the following version breaks due to dynamic settings updates:
@ -6,11 +10,10 @@ See [wiki migration path](https://github.com/arendst/Sonoff-Tasmota/wiki/Upgrade
3. Migrate to **Sonoff-Tasmota 5.14**
4. Migrate to **Sonoff-Tasmota 6.x**
## Release notes
### Core version 2.3.0 vs 2.4.2
## Core version 2.3.0 vs 2.4.2
This release is based on ESP8266/Arduino library core 2.3.0 (again) as some people encountered wifi related issues on core 2.4.2. For others core 2.4.2 is working just fine. Both version are available from http://thehackbox.org/tasmota/release/
### Change in default initial configuration tool
## Change in default initial configuration tool
Firmware binary **sonoff-classic.bin** supports **WifiManager, Wps and SmartConfig** for initial configuration. The default tool is **Wps**.
To save memory space all other binaries support **WifiManager only**.
@ -104,7 +107,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
Core version **2.4.2** binaries can be found at http://thehackbox.org/tasmota/release/020402/
### Available Features and Sensors
## Available Features and Sensors
| Feature or Sensor | minimal | basic | classic | sonoff | knx | sensors | display | Remarks
|-----------------------|---------|-------|---------|--------|------|---------|---------|--------

View File

@ -1,20 +1,23 @@
# Sonoff-Tasmota Support
<img src="/tools/logo/TASMOTA_FullLogo_Vector.svg" alt="Logo" align="right" height="76"/>
# Support
If you're looking for support on **Sonoff-Tasmota** there are some options available:
### Documentation:
## Documentation:
* [Wiki Pages](https://github.com/arendst/Sonoff-Tasmota/wiki): For information on how to Flash Tasmota, configure and use it.
* [Troubleshooting Information](https://github.com/arendst/Sonoff-Tasmota/wiki/Troubleshooting): For information on common problems and solutions.
* [FAQ](https://github.com/arendst/Sonoff-Tasmota/wiki/FAQ): For information on common problems and solutions.
* [Troubleshooting Information](https://github.com/arendst/Sonoff-Tasmota/wiki/Troubleshooting): For ways to debug and troubleshoot.
* [Commands Information](https://github.com/arendst/Sonoff-Tasmota/wiki/Commands): For information on all the commands supported by Tasmota.
### Support's Community:
## Support's Community:
* [Tasmota Forum](https://groups.google.com/d/forum/sonoffusers): For usage and discussions.
* [Tasmota Support Chat](https://discord.gg/Ks2Kzd4): For support, troubleshooting and general questions. You have better chances to get fast answers from members of the Tasmota Community.
* [Search in Issues](https://github.com/arendst/Sonoff-Tasmota/issues): You might find an answer to your question by searching current or closed issues.
### Developers' Community:
## Developers' Community:
* [Bug Report](https://github.com/arendst/Sonoff-Tasmota/issues/new?template=Bug_report.md): For reporting Bugs of Tasmota Software.
* [Feature Request](https://github.com/arendst/Sonoff-Tasmota/issues/new?template=Feature_request.md): For requesting features/functions to Tasmota Software.

View File

@ -1,4 +1,7 @@
## Sonoff-Tasmota template information
<img src="/tools/logo/TASMOTA_FullLogo_Vector.svg" alt="Logo" align="right" height="76"/>
# Template information
Sonoff-Tasmota uses Device or Module information to control peripherals connected to GPIOs. This information is stored in the ``sonoff_template.h`` file as a device specific template. The template contains information about what GPIO should be connected to what peripheral and what GPIO may be configured online using the ``GPIO`` command or GUI Configure Module menu. In addition a device may need specific coding to process the data from these peripherals. The module number as provided by the ``Modules`` command is used to select this coding.
Starting with version 6.4.1.16 Sonoff-Tasmota Modules can be extended by users online using a template. To provide easy processing by Sonoff-Tasmota a user template is written as JSON text and could look like this:
@ -83,4 +86,4 @@ The following command will update the flag of a stored template
``Template {"FLAG":1}``
The following command will update the base of a stored template to Generic
``Template {"BASE":0}``
``Template {"BASE":0}``

View File

@ -1,155 +1,157 @@
# ESP8266 platform
# ------------------------------
# For more info:
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
name=ESP8266 Boards (2.5.0)
version=2.5.0
runtime.tools.xtensa-lx106-elf-gcc.path={runtime.platform.path}/tools/xtensa-lx106-elf
runtime.tools.esptool.path={runtime.platform.path}/tools/esptool
runtime.tools.signing={runtime.platform.path}/tools/signing.py
compiler.warning_flags=-w
compiler.warning_flags.none=-w
compiler.warning_flags.default=
compiler.warning_flags.more=-Wall
compiler.warning_flags.all=-Wall -Wextra
build.lwip_lib=-llwip_gcc
build.lwip_include=lwip/include
build.lwip_flags=-DLWIP_OPEN_SRC
build.vtable_flags=-DVTABLES_IN_FLASH
build.exception_flags=-fno-exceptions
build.stdcpp_lib=-lstdc++
#build.float=-u _printf_float -u _scanf_float
build.float=
build.led=
compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/
compiler.sdk.path={runtime.platform.path}/tools/sdk
compiler.libc.path={runtime.platform.path}/tools/sdk/libc/xtensa-lx106-elf
compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/{build.lwip_include}" "-I{compiler.libc.path}/include" "-I{build.path}/core"
compiler.c.cmd=xtensa-lx106-elf-gcc
compiler.c.flags=-c {compiler.warning_flags} -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections {build.exception_flags}
compiler.S.cmd=xtensa-lx106-elf-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls
compiler.c.elf.flags=-g {compiler.warning_flags} -Os -nostdlib -Wl,--no-check-sections -u app_entry {build.float} -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-L{compiler.libc.path}/lib" "-T{build.flash_ld}" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read
compiler.c.elf.cmd=xtensa-lx106-elf-gcc
compiler.c.elf.libs=-lhal -lphy -lpp -lnet80211 {build.lwip_lib} -lwpa -lcrypto -lmain -lwps -lbearssl -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 {build.stdcpp_lib} -lm -lc -lgcc
compiler.cpp.cmd=xtensa-lx106-elf-g++
compiler.cpp.flags=-c {compiler.warning_flags} -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections {build.exception_flags}
compiler.as.cmd=xtensa-lx106-elf-as
compiler.ar.cmd=xtensa-lx106-elf-ar
compiler.ar.flags=cru
compiler.elf2hex.cmd=esptool
compiler.elf2hex.flags=
compiler.size.cmd=xtensa-lx106-elf-size
compiler.esptool.cmd=esptool
compiler.esptool.cmd.windows=esptool.exe
# This can be overriden in boards.txt
build.extra_flags=-DESP8266
# These can be overridden in platform.local.txt
compiler.c.extra_flags=
compiler.c.elf.extra_flags=
compiler.S.extra_flags=
compiler.cpp.extra_flags=
compiler.ar.extra_flags=
compiler.objcopy.eep.extra_flags=
compiler.elf2hex.extra_flags=
## generate file with git version number
## needs bash, git, and echo
recipe.hooks.core.prebuild.1.pattern=python "{runtime.tools.signing}" --mode header --publickey "{build.source.path}/public.key" --out "{build.path}/core/Updater_Signing.h"
recipe.hooks.core.prebuild.2.pattern=bash -c "mkdir -p {build.path}/core && echo \#define ARDUINO_ESP8266_GIT_VER 0x`git --git-dir {runtime.platform.path}/.git rev-parse --short=8 HEAD 2>/dev/null || echo ffffffff` >{build.path}/core/core_version.h"
recipe.hooks.core.prebuild.3.pattern=bash -c "mkdir -p {build.path}/core && echo \#define ARDUINO_ESP8266_GIT_DESC `cd "{runtime.platform.path}"; git describe --tags 2>/dev/null || echo unix-{version}` >>{build.path}/core/core_version.h"
## windows-compatible version without git
recipe.hooks.core.prebuild.1.pattern.windows=cmd.exe /c rem cannot sign on windows
recipe.hooks.core.prebuild.2.pattern.windows=cmd.exe /c mkdir {build.path}\core & (echo #define ARDUINO_ESP8266_GIT_VER 0x00000000 & echo #define ARDUINO_ESP8266_GIT_DESC win-{version} ) > {build.path}\core\core_version.h
recipe.hooks.core.prebuild.3.pattern.windows=cmd.exe /c if exist {build.source.path}\public.key echo #error Cannot automatically build signed binaries on Windows > {build.path}\core\Updater_Signing.h
## Build the app.ld linker file
recipe.hooks.linking.prelink.1.pattern="{compiler.path}{compiler.c.cmd}" -CC -E -P {build.vtable_flags} "{runtime.platform.path}/tools/sdk/ld/eagle.app.v6.common.ld.h" -o "{build.path}/local.eagle.app.v6.common.ld"
## Compile c files
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {build.flash_flags} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
## Compile c++ files
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {build.flash_flags} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
## Compile S files
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {build.flash_flags} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
## Create archives
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {build.exception_flags} -Wl,-Map "-Wl,{build.path}/{build.project_name}.map" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{archive_file_path}" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}"
## Create eeprom
recipe.objcopy.eep.pattern=
## Create hex
#recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
recipe.objcopy.hex.1.pattern="{runtime.tools.esptool.path}/{compiler.esptool.cmd}" -eo "{runtime.platform.path}/bootloaders/eboot/eboot.elf" -bo "{build.path}/{build.project_name}.bin" -bm {build.flash_mode} -bf {build.flash_freq} -bz {build.flash_size} -bs .text -bp 4096 -ec -eo "{build.path}/{build.project_name}.elf" -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
recipe.objcopy.hex.2.pattern=python "{runtime.tools.signing}" --mode sign --privatekey "{build.source.path}/private.key" --bin "{build.path}/{build.project_name}.bin" --out "{build.path}/{build.project_name}.bin.signed"
# No signing on Windows
recipe.objcopy.hex.1.pattern.windows="{runtime.tools.esptool.path}/{compiler.esptool.cmd}" -eo "{runtime.platform.path}/bootloaders/eboot/eboot.elf" -bo "{build.path}/{build.project_name}.bin" -bm {build.flash_mode} -bf {build.flash_freq} -bz {build.flash_size} -bs .text -bp 4096 -ec -eo "{build.path}/{build.project_name}.elf" -bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
recipe.objcopy.hex.2.pattern.windows=
## Save hex
recipe.output.tmp_file={build.project_name}.bin
recipe.output.save_file={build.project_name}.{build.variant}.bin
## Compute size
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
recipe.size.regex=^(?:\.irom0\.text|\.text|\.data|\.rodata|)\s+([0-9]+).*
recipe.size.regex.data=^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*
#recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*
# ------------------------------
tools.esptool.cmd=esptool
tools.esptool.cmd.windows=esptool.exe
tools.esptool.path={runtime.tools.esptool.path}
tools.esptool.network_cmd=python
tools.esptool.network_cmd.windows=python.exe
tools.esptool.upload.protocol=esp
tools.esptool.upload.params.verbose=-vv
tools.esptool.upload.params.quiet=
tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" {upload.erase_cmd} -ca 0x00000 -cf "{build.path}/{build.project_name}.bin"
tools.esptool.upload.network_pattern="{network_cmd}" "{runtime.platform.path}/tools/espota.py" -i "{serial.port}" -p "{network.port}" "--auth={network.password}" -f "{build.path}/{build.project_name}.bin"
tools.mkspiffs.cmd=mkspiffs
tools.mkspiffs.cmd.windows=mkspiffs.exe
tools.mkspiffs.path={runtime.tools.mkspiffs.path}
tools.espupload.cmd=python
tools.espupload.cmd.windows=python.exe
tools.espupload.path={runtime.platform.path}/tools
tools.espupload.upload.protocol=espupload
tools.espupload.upload.params.verbose=
tools.espupload.upload.params.quiet=
tools.espupload.upload.pattern="{cmd}" "{path}/espupload.py" -f "{build.path}/{build.project_name}.bin"
# ESP8266 platform
# ------------------------------
# For more info:
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification
name=ESP8266 Boards (2.5.2)
version=2.5.2
# These will be removed by the packager script when doing a JSON release
runtime.tools.signing={runtime.platform.path}/tools/signing.py
runtime.tools.elf2bin={runtime.platform.path}/tools/elf2bin.py
runtime.tools.makecorever={runtime.platform.path}/tools/makecorever.py
runtime.tools.eboot={runtime.platform.path}/bootloaders/eboot/eboot.elf
compiler.warning_flags=-w
compiler.warning_flags.none=-w
compiler.warning_flags.default=
compiler.warning_flags.more=-Wall
compiler.warning_flags.all=-Wall -Wextra
build.lwip_lib=-llwip_gcc
build.lwip_include=lwip/include
build.lwip_flags=-DLWIP_OPEN_SRC
build.vtable_flags=-DVTABLES_IN_FLASH
build.sslflags=
build.exception_flags=-fno-exceptions
build.stdcpp_lib=-lstdc++
#build.float=-u _printf_float -u _scanf_float
build.float=
build.led=
build.sdk=NONOSDK221
compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/
compiler.sdk.path={runtime.platform.path}/tools/sdk
compiler.libc.path={runtime.platform.path}/tools/sdk/libc/xtensa-lx106-elf
compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/{build.lwip_include}" "-I{compiler.libc.path}/include" "-I{build.path}/core"
compiler.c.cmd=xtensa-lx106-elf-gcc
compiler.c.flags=-c {compiler.warning_flags} -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags}
compiler.S.cmd=xtensa-lx106-elf-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls
compiler.c.elf.flags=-g {compiler.warning_flags} -Os -nostdlib -Wl,--no-check-sections -u app_entry {build.float} -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/lib/{build.sdk}" "-L{compiler.sdk.path}/ld" "-L{compiler.libc.path}/lib" "-T{build.flash_ld}" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read
compiler.c.elf.cmd=xtensa-lx106-elf-gcc
compiler.c.elf.libs=-lhal -lphy -lpp -lnet80211 {build.lwip_lib} -lwpa -lcrypto -lmain -lwps -lbearssl -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 {build.stdcpp_lib} -lm -lc -lgcc
compiler.cpp.cmd=xtensa-lx106-elf-g++
compiler.cpp.flags=-c {compiler.warning_flags} -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags}
compiler.as.cmd=xtensa-lx106-elf-as
compiler.ar.cmd=xtensa-lx106-elf-ar
compiler.ar.flags=cru
compiler.elf2hex.cmd=esptool
compiler.elf2hex.flags=
compiler.size.cmd=xtensa-lx106-elf-size
# This can be overriden in boards.txt
build.extra_flags=-DESP8266
# These can be overridden in platform.local.txt
compiler.c.extra_flags=
compiler.c.elf.extra_flags=
compiler.S.extra_flags=
compiler.cpp.extra_flags=
compiler.ar.extra_flags=
compiler.objcopy.eep.extra_flags=
compiler.elf2hex.extra_flags=
## generate file with git version number
## needs bash, git, and echo
recipe.hooks.core.prebuild.1.pattern="{runtime.tools.python.path}/python" "{runtime.tools.signing}" --mode header --publickey "{build.source.path}/public.key" --out "{build.path}/core/Updater_Signing.h"
## Build the app.ld linker file
recipe.hooks.linking.prelink.1.pattern="{compiler.path}{compiler.c.cmd}" -CC -E -P {build.vtable_flags} "{runtime.platform.path}/tools/sdk/ld/eagle.app.v6.common.ld.h" -o "{build.path}/local.eagle.app.v6.common.ld"
## Compile c files
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -D{build.sdk}=1 -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {build.flash_flags} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
## Compile c++ files
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -D{build.sdk}=1 -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {build.flash_flags} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
## Compile S files
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -D{build.sdk}=1 -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {build.flash_flags} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
## Create archives
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {build.exception_flags} -Wl,-Map "-Wl,{build.path}/{build.project_name}.map" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{archive_file_path}" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}"
## Create eeprom
recipe.objcopy.eep.pattern=
## Create hex
recipe.objcopy.hex.1.pattern="{runtime.tools.python.path}/python" "{runtime.tools.elf2bin}" --eboot "{runtime.tools.eboot}" --app "{build.path}/{build.project_name}.elf" --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} --path "{runtime.tools.xtensa-lx106-elf-gcc.path}/bin" --out "{build.path}/{build.project_name}.bin"
recipe.objcopy.hex.2.pattern="{runtime.tools.python.path}/python" "{runtime.tools.signing}" --mode sign --privatekey "{build.source.path}/private.key" --bin "{build.path}/{build.project_name}.bin" --out "{build.path}/{build.project_name}.bin.signed"
## Save hex
recipe.output.tmp_file={build.project_name}.bin
recipe.output.save_file={build.project_name}.{build.variant}.bin
## Compute size
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
recipe.size.regex=^(?:\.irom0\.text|\.text|\.text1|\.data|\.rodata|)\s+([0-9]+).*
recipe.size.regex.data=^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*
#recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*
# ------------------------------
tools.esptool.path=
# Because the variable expansion doesn't allow one tool to find another, the following lines
# will point to "{runtime.platform.path}/tools/python/python" in GIT and
# "{runtime.tools.python.path}/python" for JSON board manager releases.
tools.esptool.cmd={runtime.tools.python.path}/python
tools.esptool.network_cmd={runtime.tools.python.path}/python
tools.esptool.upload.protocol=esp
tools.esptool.upload.params.verbose=--trace
tools.esptool.upload.params.quiet=
# First, potentially perform an erase or nothing
# Next, do the binary upload
# Combined in one rule because Arduino doesn't suport upload.1.pattern/upload.3.pattern
tools.esptool.upload.pattern="{cmd}" "{runtime.platform.path}/tools/upload.py" --chip esp8266 --port "{serial.port}" --baud "{upload.speed}" "{upload.verbose}" {upload.erase_cmd} --end --chip esp8266 --port "{serial.port}" --baud "{upload.speed}" "{upload.verbose}" write_flash 0x0 "{build.path}/{build.project_name}.bin" --end
tools.esptool.upload.network_pattern="{network_cmd}" "{runtime.platform.path}/tools/espota.py" -i "{serial.port}" -p "{network.port}" "--auth={network.password}" -f "{build.path}/{build.project_name}.bin"
tools.mkspiffs.cmd=mkspiffs
tools.mkspiffs.cmd.windows=mkspiffs.exe
tools.mkspiffs.path={runtime.tools.mkspiffs.path}
tools.espupload.cmd=python
tools.espupload.cmd.windows=python.exe
tools.espupload.path={runtime.platform.path}/tools
tools.espupload.upload.protocol=espupload
tools.espupload.upload.params.verbose=
tools.espupload.upload.params.quiet=
tools.espupload.upload.pattern="{cmd}" "{path}/espupload.py" -f "{build.path}/{build.project_name}.bin"

334
lib/AT24C256/Eeprom24C128_256.cpp Executable file
View File

@ -0,0 +1,334 @@
/**************************************************************************//**
* \brief EEPROM 24C128 / 24C256 library for Arduino
* \author Copyright (C) 2012 Julien Le Sech - www.idreammicro.com
* \version 1.0
* \date 20120203
*
* This file is part of the EEPROM 24C128 / 24C256 library for Arduino.
*
* This library is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
******************************************************************************/
/**************************************************************************//**
* \file Eeprom24C128_256.cpp
******************************************************************************/
/******************************************************************************
* Header file inclusions.
******************************************************************************/
#include <Arduino.h>
#include <Wire.h>
#include <Eeprom24C128_256.h>
/******************************************************************************
* Private macro definitions.
******************************************************************************/
/**************************************************************************//**
* \def EEPROM__PAGE_SIZE
* \brief Size of a page in EEPROM memory.
* This size is given by EEPROM memory datasheet.
******************************************************************************/
#define EEPROM__PAGE_SIZE 64
/**************************************************************************//**
* \def EEPROM__RD_BUFFER_SIZE
* \brief Size of input TWI buffer.
* This size is equal to BUFFER_LENGTH defined in Wire library (32 bytes).
******************************************************************************/
#define xBUFFER_LENGTH 24
#define EEPROM__RD_BUFFER_SIZE xBUFFER_LENGTH
/**************************************************************************//**
* \def EEPROM__WR_BUFFER_SIZE
* \brief Size of output TWI buffer.
* This size is equal to BUFFER_LENGTH - 2 bytes reserved for address.
******************************************************************************/
#define EEPROM__WR_BUFFER_SIZE (xBUFFER_LENGTH - 2)
/******************************************************************************
* Public method definitions.
******************************************************************************/
/**************************************************************************//**
* \fn Eeprom24C128_256::Eeprom24C128_256(byte deviceAddress)
*
* \brief Constructor.
*
* \param deviceAddress EEPROM address on TWI bus.
******************************************************************************/
Eeprom24C128_256::Eeprom24C128_256
(
byte deviceAddress
){
m_deviceAddress = deviceAddress;
}
/**************************************************************************//**
* \fn void Eeprom24C128_256::initialize()
*
* \brief Initialize library and TWI bus.
*
* If several devices are connected to TWI bus, this method mustn't be
* called. TWI bus must be initialized out of this library using
* Wire.begin() method.
******************************************************************************/
void
Eeprom24C128_256::initialize()
{
Wire.begin();
}
/**************************************************************************//**
* \fn void Eeprom24C128_256::writeByte(
* word address,
* byte data)
*
* \brief Write a byte in EEPROM memory.
*
* \remarks A delay of 10 ms is required after write cycle.
*
* \param address Address.
* \param data Byte to write.
******************************************************************************/
void
Eeprom24C128_256::writeByte
(
word address,
byte data
){
Wire.beginTransmission(m_deviceAddress);
Wire.write(address >> 8);
Wire.write(address & 0xFF);
Wire.write(data);
Wire.endTransmission();
}
/**************************************************************************//**
* \fn void Eeprom24C128_256::writeBytes(
* word address,
* word length,
* byte* p_data)
*
* \brief Write bytes in EEPROM memory.
*
* \param address Start address.
* \param length Number of bytes to write.
* \param[in] p_data Bytes to write.
******************************************************************************/
void
Eeprom24C128_256::writeBytes
(
word address,
word length,
byte* p_data
){
// Write first page if not aligned.
byte notAlignedLength = 0;
byte pageOffset = address % EEPROM__PAGE_SIZE;
if (pageOffset > 0)
{
notAlignedLength = EEPROM__PAGE_SIZE - pageOffset;
if (length < notAlignedLength)
{
notAlignedLength = length;
}
writePage(address, notAlignedLength, p_data);
length -= notAlignedLength;
}
if (length > 0)
{
address += notAlignedLength;
p_data += notAlignedLength;
// Write complete and aligned pages.
word pageCount = length / EEPROM__PAGE_SIZE;
for (word i = 0; i < pageCount; i++)
{
writePage(address, EEPROM__PAGE_SIZE, p_data);
address += EEPROM__PAGE_SIZE;
p_data += EEPROM__PAGE_SIZE;
length -= EEPROM__PAGE_SIZE;
}
if (length > 0)
{
// Write remaining uncomplete page.
writePage(address, length, p_data);
}
}
}
/**************************************************************************//**
* \fn byte Eeprom24C128_256::readByte(word address)
*
* \brief Read a byte in EEPROM memory.
*
* \param address Address.
*
* \return Read byte.
******************************************************************************/
byte
Eeprom24C128_256::readByte
(
word address
){
Wire.beginTransmission(m_deviceAddress);
Wire.write(address >> 8);
Wire.write(address & 0xFF);
Wire.endTransmission();
Wire.requestFrom(m_deviceAddress, (byte)1);
byte data = 0;
if (Wire.available())
{
data = Wire.read();
}
return data;
}
/**************************************************************************//**
* \fn void Eeprom24C128_256::readBytes(
* word address,
* word length,
* byte* p_data)
*
* \brief Read bytes in EEPROM memory.
*
* \param address Start address.
* \param length Number of bytes to read.
* \patam[in] p_data Byte array to fill with read bytes.
******************************************************************************/
void
Eeprom24C128_256::readBytes
(
word address,
word length,
byte* p_data
){
byte bufferCount = length / EEPROM__RD_BUFFER_SIZE;
for (byte i = 0; i < bufferCount; i++)
{
word offset = i * EEPROM__RD_BUFFER_SIZE;
readBuffer(address + offset, EEPROM__RD_BUFFER_SIZE, p_data + offset);
}
byte remainingBytes = length % EEPROM__RD_BUFFER_SIZE;
word offset = length - remainingBytes;
readBuffer(address + offset, remainingBytes, p_data + offset);
}
/******************************************************************************
* Private method definitions.
******************************************************************************/
/**************************************************************************//**
* \fn void Eeprom24C128_256::writePage(
* word address,
* byte length,
* byte* p_data)
*
* \brief Write page in EEPROM memory.
*
* \param address Start address.
* \param length Number of bytes (EEPROM__PAGE_SIZE bytes max).
* \param[in] p_data Data.
******************************************************************************/
void
Eeprom24C128_256::writePage
(
word address,
byte length,
byte* p_data
){
// Write complete buffers.
byte bufferCount = length / EEPROM__WR_BUFFER_SIZE;
for (byte i = 0; i < bufferCount; i++)
{
byte offset = i * EEPROM__WR_BUFFER_SIZE;
writeBuffer(address + offset, EEPROM__WR_BUFFER_SIZE, p_data + offset);
}
// Write remaining bytes.
byte remainingBytes = length % EEPROM__WR_BUFFER_SIZE;
byte offset = length - remainingBytes;
writeBuffer(address + offset, remainingBytes, p_data + offset);
}
/**************************************************************************//**
* \fn void Eeprom24C128_256::writeBuffer(
* word address,
* byte length,
* byte* p_data)
*
* \brief Write bytes into memory.
*
* \param address Start address.
* \param length Number of bytes (EEPROM__WR_BUFFER_SIZE bytes max).
* \param[in] p_data Data.
******************************************************************************/
void
Eeprom24C128_256::writeBuffer
(
word address,
byte length,
byte* p_data
){
Wire.beginTransmission(m_deviceAddress);
Wire.write(address >> 8);
Wire.write(address & 0xFF);
for (byte i = 0; i < length; i++)
{
Wire.write(p_data[i]);
}
Wire.endTransmission();
// Write cycle time (tWR). See EEPROM memory datasheet for more details.
delay(10);
}
/**************************************************************************//**
* \fn void Eeprom24C128_256::readBuffer(
* word address,
* byte length,
* byte* p_data)
*
* \brief Read bytes in memory.
*
* \param address Start address.
* \param length Number of bytes (EEPROM__RD_BUFFER_SIZE bytes max).
* \param[in] p_data Buffer to fill with read bytes.
******************************************************************************/
void
Eeprom24C128_256::readBuffer
(
word address,
byte length,
byte* p_data
){
Wire.beginTransmission(m_deviceAddress);
Wire.write(address >> 8);
Wire.write(address & 0xFF);
Wire.endTransmission();
Wire.requestFrom(m_deviceAddress, length);
for (byte i = 0; i < length; i++)
{
if (Wire.available())
{
p_data[i] = Wire.read();
}
}
}

212
lib/AT24C256/Eeprom24C128_256.h Executable file
View File

@ -0,0 +1,212 @@
/**************************************************************************//**
* \brief EEPROM 24C128 / 24C256 library for Arduino
* \author Copyright (C) 2012 Julien Le Sech - www.idreammicro.com
* \version 1.0
* \date 20120203
*
* This file is part of the EEPROM 24C128 / 24C256 library for Arduino.
*
* This library is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see http://www.gnu.org/licenses/
******************************************************************************/
/**************************************************************************//**
* \headerfile Eeprom24C128_256.h
******************************************************************************/
#ifndef Eeprom24C128_256_h
#define Eeprom24C128_256_h
/******************************************************************************
* Header file inclusion.
******************************************************************************/
#include <Arduino.h>
/**************************************************************************//**
* \class Eeprom24C128_256
*
* \brief EEPROM 24C128 / 24C256 memory driver.
*
* This driver is mainly designed for 24C128 and 24C256 EEPROM memories. It's
* also suitable for 24C512 memories.
******************************************************************************/
class Eeprom24C128_256
{
public:
/******************************************************************//**
* \fn Eeprom24C128_256(byte deviceAddress)
*
* \brief Constructor.
*
* \param deviceAddress EEPROM address on TWI bus.
**********************************************************************/
Eeprom24C128_256
(
byte deviceAddress
);
/******************************************************************//**
* \fn void initialize()
*
* \brief Initialize library abnd TWI bus.
*
* If several devices are connected to TWI bus, this method mustn't be
* called. TWI bus must be initialized out of this library using
* Wire.begin() method.
**********************************************************************/
void
initialize();
/******************************************************************//**
* \fn void writeByte(
* word address,
* byte data)
*
* \brief Write a byte in EEPROM memory.
*
* \remarks A delay of 10 ms is required after write cycle.
*
* \param address Address.
* \param data Byte to write.
**********************************************************************/
void
writeByte
(
word address,
byte data
);
/******************************************************************//**
* \fn void writeBytes(
* word address,
* word length,
* byte* p_data)
*
* \brief Write bytes in EEPROM memory.
*
* \param address Start address.
* \param length Number of bytes to write.
* \param[in] p_data Bytes to write.
**********************************************************************/
void
writeBytes
(
word address,
word length,
byte* p_data
);
/******************************************************************//**
* \fn byte readByte(word address)
*
* \brief Read a byte in EEPROM memory.
*
* \param address Address.
*
* \return Read byte.
**********************************************************************/
byte
readByte
(
word address
);
/******************************************************************//**
* \fn void readBytes(
* word address,
* word length,
* byte* p_data)
*
* \brief Read bytes in EEPROM memory.
*
* \param address Start address.
* \param length Number of bytes to read.
* \patam[in] p_data Byte array to fill with read bytes.
**********************************************************************/
void
readBytes
(
word address,
word length,
byte* p_buffer
);
private:
byte m_deviceAddress;
/******************************************************************//**
* \fn void writePage(
* word address,
* byte length,
* byte* p_data)
*
* \brief Write page in EEPROM memory.
*
* \param address Start address.
* \param length Number of bytes (64 bytes max).
* \param[in] p_data Data.
**********************************************************************/
void
writePage
(
word address,
byte length,
byte* p_data
);
/******************************************************************//**
* \fn void writeBuffer(
* word address,
* byte length,
* byte* p_data)
*
* \brief Write bytes into memory.
*
* \param address Start address.
* \param length Number of bytes (30 bytes max).
* \param[in] p_date Data.
**********************************************************************/
void
writeBuffer
(
word address,
byte length,
byte* p_data
);
/******************************************************************//**
* \fn void readBuffer(
* word address,
* byte length,
* byte* p_data)
*
* \brief Read bytes in memory.
*
* \param address Start address.
* \param length Number of bytes to read (32 bytes max).
* \param[in] p_data Buffer to fill with read bytes.
**********************************************************************/
void
readBuffer
(
word address,
byte length,
byte* p_data
);
};
#endif // Eeprom24C128_256_h

View File

@ -1,555 +0,0 @@
/*!
* @file Adafruit_SPITFT.cpp
*
* @mainpage Adafruit SPI TFT Displays
*
* @section intro_sec Introduction
This is our library for generic SPI TFT Displays with
address windows and 16 bit color (e.g. ILI9341, HX8357D, ST7735...)
Check out the links above for our tutorials and wiring diagrams
These displays use SPI to communicate, 4 or 5 pins are required to
interface (RST is optional)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
* @section dependencies Dependencies
*
* This library depends on <a href="https://github.com/adafruit/Adafruit_GFX">
* Adafruit_GFX</a> being present on your system. Please make sure you have
* installed the latest version before using this library.
*
* @section author Author
*
* Written by Limor "ladyada" Fried for Adafruit Industries.
*
* @section license License
*
* BSD license, all text here must be included in any redistribution.
*
*/
#ifndef __AVR_ATtiny85__ // NOT A CHANCE of this stuff working on ATtiny!
#include "Adafruit_SPITFT.h"
#ifndef ARDUINO_STM32_FEATHER
#include "pins_arduino.h"
#ifndef RASPI
#include "wiring_private.h"
#endif
#endif
#include <limits.h>
#include "Adafruit_SPITFT_Macros.h"
/**************************************************************************/
/*!
@brief Pass 8-bit (each) R,G,B, get back 16-bit packed color
This function converts 8-8-8 RGB data to 16-bit 5-6-5
@param red Red 8 bit color
@param green Green 8 bit color
@param blue Blue 8 bit color
@return Unsigned 16-bit down-sampled color in 5-6-5 format
*/
/**************************************************************************/
uint16_t Adafruit_SPITFT::color565(uint8_t red, uint8_t green, uint8_t blue) {
return ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | ((blue & 0xF8) >> 3);
}
/**************************************************************************/
/*!
@brief Instantiate Adafruit SPI display driver with software SPI
@param w Display width in pixels
@param h Display height in pixels
@param cs Chip select pin #
@param dc Data/Command pin #
@param mosi SPI MOSI pin #
@param sclk SPI Clock pin #
@param rst Reset pin # (optional, pass -1 if unused)
@param miso SPI MISO pin # (optional, pass -1 if unused)
*/
/**************************************************************************/
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h,
int8_t cs, int8_t dc, int8_t mosi,
int8_t sclk, int8_t rst, int8_t miso)
: Adafruit_GFX(w, h) {
_cs = cs;
_dc = dc;
_rst = rst;
_sclk = sclk;
_mosi = mosi;
_miso = miso;
_freq = 0;
#ifdef USE_FAST_PINIO
dcport = (RwReg *)portOutputRegister(digitalPinToPort(dc));
dcpinmask = digitalPinToBitMask(dc);
clkport = (RwReg *)portOutputRegister(digitalPinToPort(sclk));
clkpinmask = digitalPinToBitMask(sclk);
mosiport = (RwReg *)portOutputRegister(digitalPinToPort(mosi));
mosipinmask = digitalPinToBitMask(mosi);
if(miso >= 0){
misoport = (RwReg *)portInputRegister(digitalPinToPort(miso));
misopinmask = digitalPinToBitMask(miso);
} else {
misoport = 0;
misopinmask = 0;
}
if(cs >= 0) {
csport = (RwReg *)portOutputRegister(digitalPinToPort(cs));
cspinmask = digitalPinToBitMask(cs);
} else {
// No chip-select line defined; might be permanently tied to GND.
// Assign a valid GPIO register (though not used for CS), and an
// empty pin bitmask...the nonsense bit-twiddling might be faster
// than checking _cs and possibly branching.
csport = dcport;
cspinmask = 0;
}
#endif
}
/**************************************************************************/
/*!
@brief Instantiate Adafruit SPI display driver with hardware SPI
@param w Display width in pixels
@param h Display height in pixels
@param cs Chip select pin #
@param dc Data/Command pin #
@param rst Reset pin # (optional, pass -1 if unused)
*/
/**************************************************************************/
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h,
int8_t cs, int8_t dc, int8_t rst)
: Adafruit_GFX(w, h) {
_cs = cs;
_dc = dc;
_rst = rst;
_sclk = -1;
_mosi = -1;
_miso = -1;
_freq = 0;
#ifdef USE_FAST_PINIO
clkport = 0;
clkpinmask = 0;
mosiport = 0;
mosipinmask = 0;
misoport = 0;
misopinmask = 0;
dcport = (RwReg *)portOutputRegister(digitalPinToPort(dc));
dcpinmask = digitalPinToBitMask(dc);
if(cs >= 0) {
csport = (RwReg *)portOutputRegister(digitalPinToPort(cs));
cspinmask = digitalPinToBitMask(cs);
} else {
// See notes in prior constructor.
csport = dcport;
cspinmask = 0;
}
#endif
}
/**************************************************************************/
/*!
@brief Initialiaze the SPI interface (hardware or software)
@param freq The desired maximum SPI hardware clock frequency
*/
/**************************************************************************/
void Adafruit_SPITFT::initSPI(uint32_t freq) {
_freq = freq;
// Control Pins
if(_cs >= 0) {
pinMode(_cs, OUTPUT);
digitalWrite(_cs, HIGH); // Deselect
}
pinMode(_dc, OUTPUT);
digitalWrite(_dc, LOW);
// Software SPI
if(_sclk >= 0){
pinMode(_mosi, OUTPUT);
digitalWrite(_mosi, LOW);
pinMode(_sclk, OUTPUT);
digitalWrite(_sclk, HIGH);
if(_miso >= 0){
pinMode(_miso, INPUT);
}
}
// Hardware SPI
SPI_BEGIN();
// toggle RST low to reset
if (_rst >= 0) {
pinMode(_rst, OUTPUT);
digitalWrite(_rst, HIGH);
delay(100);
digitalWrite(_rst, LOW);
delay(100);
digitalWrite(_rst, HIGH);
delay(200);
}
}
/**************************************************************************/
/*!
@brief Read one byte from SPI interface (hardware or software
@returns One byte, MSB order
*/
/**************************************************************************/
uint8_t Adafruit_SPITFT::spiRead() {
if(_sclk < 0){
return HSPI_READ();
}
if(_miso < 0){
return 0;
}
uint8_t r = 0;
for (uint8_t i=0; i<8; i++) {
SSPI_SCK_LOW();
SSPI_SCK_HIGH();
r <<= 1;
if (SSPI_MISO_READ()){
r |= 0x1;
}
}
return r;
}
/**************************************************************************/
/*!
@brief Write one byte to SPI interface (hardware or software
@param b One byte to send, MSB order
*/
/**************************************************************************/
void Adafruit_SPITFT::spiWrite(uint8_t b) {
if(_sclk < 0){
HSPI_WRITE(b);
return;
}
for(uint8_t bit = 0x80; bit; bit >>= 1){
if((b) & bit){
SSPI_MOSI_HIGH();
} else {
SSPI_MOSI_LOW();
}
SSPI_SCK_LOW();
SSPI_SCK_HIGH();
}
}
/*
* Transaction API
* */
/**************************************************************************/
/*!
@brief Begin an SPI transaction & set CS low.
*/
/**************************************************************************/
void inline Adafruit_SPITFT::startWrite(void){
SPI_BEGIN_TRANSACTION();
SPI_CS_LOW();
}
/**************************************************************************/
/*!
@brief Begin an SPI transaction & set CS high.
*/
/**************************************************************************/
void inline Adafruit_SPITFT::endWrite(void){
SPI_CS_HIGH();
SPI_END_TRANSACTION();
}
/**************************************************************************/
/*!
@brief Write a command byte (must have a transaction in progress)
@param cmd The 8-bit command to send
*/
/**************************************************************************/
void Adafruit_SPITFT::writeCommand(uint8_t cmd){
SPI_DC_LOW();
spiWrite(cmd);
SPI_DC_HIGH();
}
/**************************************************************************/
/*!
@brief Push a 2-byte color to the framebuffer RAM, will start transaction
@param color 16-bit 5-6-5 Color to draw
*/
/**************************************************************************/
void Adafruit_SPITFT::pushColor(uint16_t color) {
startWrite();
SPI_WRITE16(color);
endWrite();
}
/**************************************************************************/
/*!
@brief Blit multiple 2-byte colors (must have a transaction in progress)
@param colors Array of 16-bit 5-6-5 Colors to draw
@param len How many pixels to draw - 2 bytes per pixel!
*/
/**************************************************************************/
void Adafruit_SPITFT::writePixels(uint16_t * colors, uint32_t len){
SPI_WRITE_PIXELS((uint8_t*)colors , len * 2);
}
/**************************************************************************/
/*!
@brief Blit a 2-byte color many times (must have a transaction in progress)
@param color The 16-bit 5-6-5 Color to draw
@param len How many pixels to draw
*/
/**************************************************************************/
void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len){
#ifdef SPI_HAS_WRITE_PIXELS
if(_sclk >= 0){
for (uint32_t t=0; t<len; t++){
writePixel(color);
}
return;
}
static uint16_t temp[SPI_MAX_PIXELS_AT_ONCE];
size_t blen = (len > SPI_MAX_PIXELS_AT_ONCE)?SPI_MAX_PIXELS_AT_ONCE:len;
uint16_t tlen = 0;
for (uint32_t t=0; t<blen; t++){
temp[t] = color;
}
while(len){
tlen = (len>blen)?blen:len;
writePixels(temp, tlen);
len -= tlen;
}
#else
uint8_t hi = color >> 8, lo = color;
if(_sclk < 0){ //AVR Optimization
for (uint32_t t=len; t; t--){
HSPI_WRITE(hi);
HSPI_WRITE(lo);
}
return;
}
for (uint32_t t=len; t; t--){
spiWrite(hi);
spiWrite(lo);
}
#endif
}
/**************************************************************************/
/*!
@brief Write a pixel (must have a transaction in progress)
@param x x coordinate
@param y y coordinate
@param color 16-bit 5-6-5 Color to draw with
*/
/**************************************************************************/
void Adafruit_SPITFT::writePixel(int16_t x, int16_t y, uint16_t color) {
if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return;
setAddrWindow(x,y,1,1);
writePixel(color);
}
/**************************************************************************/
/*!
@brief Write a filled rectangle (must have a transaction in progress)
@param x Top left corner x coordinate
@param y Top left corner y coordinate
@param w Width in pixels
@param h Height in pixels
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void Adafruit_SPITFT::writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color){
if((x >= _width) || (y >= _height)) return;
int16_t x2 = x + w - 1, y2 = y + h - 1;
if((x2 < 0) || (y2 < 0)) return;
// Clip left/top
if(x < 0) {
x = 0;
w = x2 + 1;
}
if(y < 0) {
y = 0;
h = y2 + 1;
}
// Clip right/bottom
if(x2 >= _width) w = _width - x;
if(y2 >= _height) h = _height - y;
int32_t len = (int32_t)w * h;
setAddrWindow(x, y, w, h);
writeColor(color, len);
}
/**************************************************************************/
/*!
@brief Write a perfectly vertical line (must have a transaction in progress)
@param x Top-most x coordinate
@param y Top-most y coordinate
@param h Height in pixels
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void inline Adafruit_SPITFT::writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color){
writeFillRect(x, y, 1, h, color);
}
/**************************************************************************/
/*!
@brief Write a perfectly horizontal line (must have a transaction in progress)
@param x Left-most x coordinate
@param y Left-most y coordinate
@param w Width in pixels
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void inline Adafruit_SPITFT::writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color){
writeFillRect(x, y, w, 1, color);
}
/**************************************************************************/
/*!
@brief Draw a pixel - sets up transaction
@param x x coordinate
@param y y coordinate
@param color 16-bit 5-6-5 Color to draw with
*/
/**************************************************************************/
void Adafruit_SPITFT::drawPixel(int16_t x, int16_t y, uint16_t color){
startWrite();
writePixel(x, y, color);
endWrite();
}
/**************************************************************************/
/*!
@brief Write a perfectly vertical line - sets up transaction
@param x Top-most x coordinate
@param y Top-most y coordinate
@param h Height in pixels
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void Adafruit_SPITFT::drawFastVLine(int16_t x, int16_t y,
int16_t h, uint16_t color) {
startWrite();
writeFastVLine(x, y, h, color);
endWrite();
}
/**************************************************************************/
/*!
@brief Write a perfectly horizontal line - sets up transaction
@param x Left-most x coordinate
@param y Left-most y coordinate
@param w Width in pixels
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void Adafruit_SPITFT::drawFastHLine(int16_t x, int16_t y,
int16_t w, uint16_t color) {
startWrite();
writeFastHLine(x, y, w, color);
endWrite();
}
/**************************************************************************/
/*!
@brief Fill a rectangle completely with one color.
@param x Top left corner x coordinate
@param y Top left corner y coordinate
@param w Width in pixels
@param h Height in pixels
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void Adafruit_SPITFT::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color) {
startWrite();
writeFillRect(x,y,w,h,color);
endWrite();
}
/**************************************************************************/
/*!
@brief Invert the display using built-in hardware command
@param i True if you want to invert, false to make 'normal'
*/
/**************************************************************************/
void Adafruit_SPITFT::invertDisplay(boolean i) {
startWrite();
writeCommand(i ? invertOnCommand : invertOffCommand);
endWrite();
}
/**************************************************************************/
/*!
@brief Draw a 16-bit image (RGB 5/6/5) at the specified (x,y) position.
For 16-bit display devices; no color reduction performed.
Adapted from https://github.com/PaulStoffregen/ILI9341_t3
by Marc MERLIN. See examples/pictureEmbed to use this.
5/6/2017: function name and arguments have changed for compatibility
with current GFX library and to avoid naming problems in prior
implementation. Formerly drawBitmap() with arguments in different order.
@param x Top left corner x coordinate
@param y Top left corner y coordinate
@param pcolors 16-bit array with 16-bit color bitmap
@param w Width of bitmap in pixels
@param h Height of bitmap in pixels
*/
/**************************************************************************/
void Adafruit_SPITFT::drawRGBBitmap(int16_t x, int16_t y,
uint16_t *pcolors, int16_t w, int16_t h) {
int16_t x2, y2; // Lower-right coord
if(( x >= _width ) || // Off-edge right
( y >= _height) || // " top
((x2 = (x+w-1)) < 0 ) || // " left
((y2 = (y+h-1)) < 0) ) return; // " bottom
int16_t bx1=0, by1=0, // Clipped top-left within bitmap
saveW=w; // Save original bitmap width value
if(x < 0) { // Clip left
w += x;
bx1 = -x;
x = 0;
}
if(y < 0) { // Clip top
h += y;
by1 = -y;
y = 0;
}
if(x2 >= _width ) w = _width - x; // Clip right
if(y2 >= _height) h = _height - y; // Clip bottom
pcolors += by1 * saveW + bx1; // Offset bitmap ptr to clipped top-left
startWrite();
setAddrWindow(x, y, w, h); // Clipped area
while(h--) { // For each (clipped) scanline...
writePixels(pcolors, w); // Push one (clipped) row
pcolors += saveW; // Advance pointer by one full (unclipped) line
}
endWrite();
}
#endif // !__AVR_ATtiny85__

View File

@ -1,125 +0,0 @@
#ifndef _ADAFRUIT_SPITFT_
#define _ADAFRUIT_SPITFT_
#if ARDUINO >= 100
#include "Arduino.h"
#include "Print.h"
#else
#include "WProgram.h"
#endif
#include <SPI.h>
#include "Adafruit_GFX.h"
#define USE_FAST_PINIO
#if defined(__AVR__)
typedef volatile uint8_t RwReg;
#elif defined(ARDUINO_STM32_FEATHER)
typedef volatile uint32 RwReg;
#undef USE_FAST_PINIO
#elif defined(__OPENCR__) || defined (__OPENCM904__)
#undef USE_FAST_PINIO
#elif defined(ARDUINO_FEATHER52) || defined(__arm__)
typedef volatile uint32_t RwReg;
#elif defined(ESP32) || defined(ESP8266)
typedef volatile uint32_t RwReg;
#undef USE_FAST_PINIO
#else
#undef USE_FAST_PINIO
#endif
#include "Adafruit_SPITFT_Macros.h"
/// A heavily optimized SPI display subclass of GFX. Manages SPI bitbanging, transactions, DMA, etc! Despite being called SPITFT, the classic SPI data/command interface is also used by OLEDs.
class Adafruit_SPITFT : public Adafruit_GFX {
protected:
public:
Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, int8_t _RST = -1, int8_t _MISO = -1);
Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t _CS, int8_t _DC, int8_t _RST = -1);
virtual void begin(uint32_t freq) = 0; ///< Virtual begin() function to set SPI frequency, must be overridden in subclass. @param freq Maximum SPI hardware clock speed
void initSPI(uint32_t freq);
// Required Non-Transaction
void drawPixel(int16_t x, int16_t y, uint16_t color);
// Transaction API
void startWrite(void);
void endWrite(void);
void writePixel(int16_t x, int16_t y, uint16_t color);
void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
// Transaction API not used by GFX
/*!
@brief SPI displays set an address window rectangle for blitting pixels
@param x Top left corner x coordinate
@param y Top left corner x coordinate
@param w Width of window
@param h Height of window
*/
virtual void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) = 0;
/*!
@brief Write a 2-byte color (must have a transaction in progress)
@param color 16-bit 5-6-5 Color to draw
*/
void inline writePixel(uint16_t color) { SPI_WRITE16(color); }
void writePixels(uint16_t * colors, uint32_t len);
void writeColor(uint16_t color, uint32_t len);
void pushColor(uint16_t color);
// Recommended Non-Transaction
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
using Adafruit_GFX::drawRGBBitmap; // Check base class first
void drawRGBBitmap(int16_t x, int16_t y,
uint16_t *pcolors, int16_t w, int16_t h);
void invertDisplay(boolean i);
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
protected:
uint32_t _freq; ///< SPI clock frequency (for hardware SPI)
#if defined (__AVR__) || defined(TEENSYDUINO) || defined (ESP8266) || defined (ESP32)
int8_t _cs, _dc, _rst, _sclk, _mosi, _miso;
#else
int32_t _cs, ///< Arduino pin # for chip-select pin
_dc, ///< Arduino pin # for data-command pin
_rst, ///< Arduino pin # for reset pin
_sclk, ///< Arduino pin # for SPI clock pin
_mosi, ///< Arduino pin # for SPI MOSI pin
_miso; ///< Arduino pin # for SPI MISO pin
#endif
#ifdef USE_FAST_PINIO
volatile RwReg *mosiport, ///< Direct chip register for toggling MOSI with fast bitbang IO
*misoport, ///< Direct chip register for toggling MISO with fast bitbang IO
*clkport, ///< Direct chip register for toggling CLK with fast bitbang IO
*dcport, ///< Direct chip register for toggling DC with fast bitbang IO
*csport; ///< Direct chip register for toggling CS with fast bitbang IO
RwReg mosipinmask, ///< bitmask for turning on/off MOSI with fast register bitbang IO
misopinmask, ///< bitmask for turning on/off MISO with fast register bitbang IO
clkpinmask, ///< bitmask for turning on/off CLK with fast register bitbang IO
cspinmask, ///< bitmask for turning on/off CS with fast register bitbang IO
dcpinmask; ///< bitmask for turning on/off DC with fast register bitbang IO
#endif
void writeCommand(uint8_t cmd);
void spiWrite(uint8_t v);
uint8_t spiRead(void);
uint8_t invertOnCommand = 0, ///< SPI command byte to turn on invert
invertOffCommand = 0; ///< SPI command byte to turn off invert
int16_t _xstart = 0; ///< Many displays don't have pixels starting at (0,0) of the internal framebuffer, this is the x offset from 0 to align
int16_t _ystart = 0; ///< Many displays don't have pixels starting at (0,0) of the internal framebuffer, this is the y offset from 0 to align
};
#endif

View File

@ -1,118 +0,0 @@
#ifndef _ADAFRUIT_SPITFT_MACROS
#define _ADAFRUIT_SPITFT_MACROS
/*
* Control Pins
* */
#ifdef USE_FAST_PINIO
#define SPI_DC_HIGH() *dcport |= dcpinmask
#define SPI_DC_LOW() *dcport &= ~dcpinmask
#define SPI_CS_HIGH() *csport |= cspinmask
#define SPI_CS_LOW() *csport &= ~cspinmask
#else
#define SPI_DC_HIGH() digitalWrite(_dc, HIGH)
#define SPI_DC_LOW() digitalWrite(_dc, LOW)
#define SPI_CS_HIGH() { if(_cs >= 0) digitalWrite(_cs, HIGH); }
#define SPI_CS_LOW() { if(_cs >= 0) digitalWrite(_cs, LOW); }
#endif
/*
* Software SPI Macros
* */
#ifdef USE_FAST_PINIO
#define SSPI_MOSI_HIGH() *mosiport |= mosipinmask
#define SSPI_MOSI_LOW() *mosiport &= ~mosipinmask
#define SSPI_SCK_HIGH() *clkport |= clkpinmask
#define SSPI_SCK_LOW() *clkport &= ~clkpinmask
#define SSPI_MISO_READ() ((*misoport & misopinmask) != 0)
#else
#define SSPI_MOSI_HIGH() digitalWrite(_mosi, HIGH)
#define SSPI_MOSI_LOW() digitalWrite(_mosi, LOW)
#define SSPI_SCK_HIGH() digitalWrite(_sclk, HIGH)
#define SSPI_SCK_LOW() digitalWrite(_sclk, LOW)
#define SSPI_MISO_READ() digitalRead(_miso)
#endif
#define SSPI_BEGIN_TRANSACTION()
#define SSPI_END_TRANSACTION()
#define SSPI_WRITE(v) spiWrite(v)
#define SSPI_WRITE16(s) SSPI_WRITE((s) >> 8); SSPI_WRITE(s)
#define SSPI_WRITE32(l) SSPI_WRITE((l) >> 24); SSPI_WRITE((l) >> 16); SSPI_WRITE((l) >> 8); SSPI_WRITE(l)
#define SSPI_WRITE_PIXELS(c,l) for(uint32_t i=0; i<(l); i+=2){ SSPI_WRITE(((uint8_t*)(c))[i+1]); SSPI_WRITE(((uint8_t*)(c))[i]); }
/*
* Hardware SPI Macros
* */
#define SPI_OBJECT SPI
#if defined (__AVR__) || defined(TEENSYDUINO) || defined(ARDUINO_ARCH_STM32F1)
#define HSPI_SET_CLOCK() SPI_OBJECT.setClockDivider(SPI_CLOCK_DIV2);
#elif defined (__arm__)
#define HSPI_SET_CLOCK() SPI_OBJECT.setClockDivider(11);
#elif defined(ESP8266) || defined(ESP32)
#define HSPI_SET_CLOCK() SPI_OBJECT.setFrequency(_freq);
#elif defined(RASPI)
#define HSPI_SET_CLOCK() SPI_OBJECT.setClock(_freq);
#elif defined(ARDUINO_ARCH_STM32F1)
#define HSPI_SET_CLOCK() SPI_OBJECT.setClock(_freq);
#else
#define HSPI_SET_CLOCK()
#endif
#ifdef SPI_HAS_TRANSACTION
#define HSPI_BEGIN_TRANSACTION() SPI_OBJECT.beginTransaction(SPISettings(_freq, MSBFIRST, SPI_MODE0))
#define HSPI_END_TRANSACTION() SPI_OBJECT.endTransaction()
#else
#define HSPI_BEGIN_TRANSACTION() HSPI_SET_CLOCK(); SPI_OBJECT.setBitOrder(MSBFIRST); SPI_OBJECT.setDataMode(SPI_MODE0)
#define HSPI_END_TRANSACTION()
#endif
#ifdef ESP32
#define SPI_HAS_WRITE_PIXELS
#endif
#if defined(ESP8266) || defined(ESP32)
// Optimized SPI (ESP8266 and ESP32)
#define HSPI_READ() SPI_OBJECT.transfer(0)
#define HSPI_WRITE(b) SPI_OBJECT.write(b)
#define HSPI_WRITE16(s) SPI_OBJECT.write16(s)
#define HSPI_WRITE32(l) SPI_OBJECT.write32(l)
#ifdef SPI_HAS_WRITE_PIXELS
#define SPI_MAX_PIXELS_AT_ONCE 32
#define HSPI_WRITE_PIXELS(c,l) SPI_OBJECT.writePixels(c,l)
#else
#define HSPI_WRITE_PIXELS(c,l) for(uint32_t i=0; i<((l)/2); i++){ SPI_WRITE16(((uint16_t*)(c))[i]); }
#endif
#else
// Standard Byte-by-Byte SPI
#if defined (__AVR__) || defined(TEENSYDUINO)
static inline uint8_t _avr_spi_read(void) __attribute__((always_inline));
static inline uint8_t _avr_spi_read(void) {
uint8_t r = 0;
SPDR = r;
while(!(SPSR & _BV(SPIF)));
r = SPDR;
return r;
}
#define HSPI_WRITE(b) {SPDR = (b); while(!(SPSR & _BV(SPIF)));}
#define HSPI_READ() _avr_spi_read()
#else
#define HSPI_WRITE(b) SPI_OBJECT.transfer((uint8_t)(b))
#define HSPI_READ() HSPI_WRITE(0)
#endif
#define HSPI_WRITE16(s) HSPI_WRITE((s) >> 8); HSPI_WRITE(s)
#define HSPI_WRITE32(l) HSPI_WRITE((l) >> 24); HSPI_WRITE((l) >> 16); HSPI_WRITE((l) >> 8); HSPI_WRITE(l)
#define HSPI_WRITE_PIXELS(c,l) for(uint32_t i=0; i<(l); i+=2){ HSPI_WRITE(((uint8_t*)(c))[i+1]); HSPI_WRITE(((uint8_t*)(c))[i]); }
#endif
#define SPI_BEGIN() if(_sclk < 0){SPI_OBJECT.begin();}
#define SPI_BEGIN_TRANSACTION() if(_sclk < 0){HSPI_BEGIN_TRANSACTION();}
#define SPI_END_TRANSACTION() if(_sclk < 0){HSPI_END_TRANSACTION();}
#define SPI_WRITE16(s) if(_sclk < 0){HSPI_WRITE16(s);}else{SSPI_WRITE16(s);}
#define SPI_WRITE32(l) if(_sclk < 0){HSPI_WRITE32(l);}else{SSPI_WRITE32(l);}
#define SPI_WRITE_PIXELS(c,l) if(_sclk < 0){HSPI_WRITE_PIXELS(c,l);}else{SSPI_WRITE_PIXELS(c,l);}
#endif // _ADAFRUIT_SPITFT_MACROS

View File

@ -9,7 +9,6 @@ git:
quiet: true
env:
global:
- ARDUINO_IDE_VERSION="1.8.5"
- PRETTYNAME="Adafruit GFX Library"
before_install:
@ -24,4 +23,4 @@ script:
# Generate and deploy documentation
after_success:
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/library_check.sh)
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/doxy_gen_and_deploy.sh)
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/doxy_gen_and_deploy.sh)

View File

@ -62,6 +62,30 @@ POSSIBILITY OF SUCH DAMAGE.
#define pgm_read_pointer(addr) ((void *)pgm_read_word(addr))
#endif
inline GFXglyph * pgm_read_glyph_ptr(const GFXfont *gfxFont, uint8_t c)
{
#ifdef __AVR__
return &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]);
#else
// expression in __AVR__ section may generate "dereferencing type-punned pointer will break strict-aliasing rules" warning
// In fact, on other platforms (such as STM32) there is no need to do this pointer magic as program memory may be read in a usual way
// So expression may be simplified
return gfxFont->glyph + c;
#endif //__AVR__
}
inline uint8_t * pgm_read_bitmap_ptr(const GFXfont *gfxFont)
{
#ifdef __AVR__
return (uint8_t *)pgm_read_pointer(&gfxFont->bitmap);
#else
// expression in __AVR__ section generates "dereferencing type-punned pointer will break strict-aliasing rules" warning
// In fact, on other platforms (such as STM32) there is no need to do this pointer magic as program memory may be read in a usual way
// So expression may be simplified
return gfxFont->bitmap;
#endif //__AVR__
}
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
@ -84,7 +108,7 @@ WIDTH(w), HEIGHT(h)
_height = HEIGHT;
rotation = 0;
cursor_y = cursor_x = 0;
textsize = 1;
textsize_x = textsize_y = 1;
textcolor = textbgcolor = 0xFFFF;
wrap = true;
_cp437 = false;
@ -103,6 +127,9 @@ WIDTH(w), HEIGHT(h)
/**************************************************************************/
void Adafruit_GFX::writeLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
uint16_t color) {
#if defined(ESP8266)
yield();
#endif
int16_t steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) {
_swap_int16_t(x0, y0);
@ -317,6 +344,9 @@ void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
/**************************************************************************/
void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r,
uint16_t color) {
#if defined(ESP8266)
yield();
#endif
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
@ -353,7 +383,7 @@ void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r,
/**************************************************************************/
/*!
@brief Quarter-circle drawer, used to do circles and roundrects
@brief Quarter-circle drawer, used to do circles and roundrects
@param x0 Center-point x coordinate
@param y0 Center-point y coordinate
@param r Radius of circle
@ -417,25 +447,29 @@ void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r,
/**************************************************************************/
/*!
@brief Quarter-circle drawer with fill, used to do circles and roundrects
@param x0 Center-point x coordinate
@param y0 Center-point y coordinate
@param r Radius of circle
@param cornername Mask bit #1 or bit #2 to indicate which quarters of the circle we're doing
@param delta Offset from center-point, used for round-rects
@param color 16-bit 5-6-5 Color to fill with
@brief Quarter-circle drawer with fill, used for circles and roundrects
@param x0 Center-point x coordinate
@param y0 Center-point y coordinate
@param r Radius of circle
@param corners Mask bits indicating which quarters we're doing
@param delta Offset from center-point, used for round-rects
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
uint8_t cornername, int16_t delta, uint16_t color) {
uint8_t corners, int16_t delta, uint16_t color) {
int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
int16_t px = x;
int16_t py = y;
while (x<y) {
delta++; // Avoid some +1's in the loop
while(x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
@ -444,15 +478,18 @@ void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
x++;
ddF_x += 2;
f += ddF_x;
if (cornername & 0x1) {
writeFastVLine(x0+x, y0-y, 2*y+1+delta, color);
writeFastVLine(x0+y, y0-x, 2*x+1+delta, color);
// These checks avoid double-drawing certain lines, important
// for the SSD1306 library which has an INVERT drawing mode.
if(x < (y + 1)) {
if(corners & 1) writeFastVLine(x0+x, y0-y, 2*y+delta, color);
if(corners & 2) writeFastVLine(x0-x, y0-y, 2*y+delta, color);
}
if (cornername & 0x2) {
writeFastVLine(x0-x, y0-y, 2*y+1+delta, color);
writeFastVLine(x0-y, y0-x, 2*x+1+delta, color);
if(y != py) {
if(corners & 1) writeFastVLine(x0+py, y0-px, 2*px+delta, color);
if(corners & 2) writeFastVLine(x0-py, y0-px, 2*px+delta, color);
py = y;
}
px = x;
}
}
@ -488,7 +525,9 @@ void Adafruit_GFX::drawRect(int16_t x, int16_t y, int16_t w, int16_t h,
*/
/**************************************************************************/
void Adafruit_GFX::drawRoundRect(int16_t x, int16_t y, int16_t w,
int16_t h, int16_t r, uint16_t color) {
int16_t h, int16_t r, uint16_t color) {
int16_t max_radius = ((w < h) ? w : h) / 2; // 1/2 minor axis
if(r > max_radius) r = max_radius;
// smarter version
startWrite();
writeFastHLine(x+r , y , w-2*r, color); // Top
@ -515,11 +554,12 @@ void Adafruit_GFX::drawRoundRect(int16_t x, int16_t y, int16_t w,
*/
/**************************************************************************/
void Adafruit_GFX::fillRoundRect(int16_t x, int16_t y, int16_t w,
int16_t h, int16_t r, uint16_t color) {
int16_t h, int16_t r, uint16_t color) {
int16_t max_radius = ((w < h) ? w : h) / 2; // 1/2 minor axis
if(r > max_radius) r = max_radius;
// smarter version
startWrite();
writeFillRect(x+r, y, w-2*r, h, color);
// draw four corners
fillCircleHelper(x+w-r-1, y+r, r, 1, h-2*r-1, color);
fillCircleHelper(x+r , y+r, r, 2, h-2*r-1, color);
@ -620,8 +660,8 @@ void Adafruit_GFX::fillTriangle(int16_t x0, int16_t y0,
// For lower part of triangle, find scanline crossings for segments
// 0-2 and 1-2. This loop is skipped if y1=y2.
sa = dx12 * (y - y1);
sb = dx02 * (y - y0);
sa = (int32_t)dx12 * (y - y1);
sb = (int32_t)dx02 * (y - y0);
for(; y<=y2; y++) {
a = x1 + sa / dy12;
b = x0 + sb / dy02;
@ -646,7 +686,7 @@ void Adafruit_GFX::fillTriangle(int16_t x0, int16_t y0,
@param y Top left corner y coordinate
@param bitmap byte array with monochrome bitmap
@param w Width of bitmap in pixels
@param h Hieght of bitmap in pixels
@param h Height of bitmap in pixels
@param color 16-bit 5-6-5 Color to draw with
*/
/**************************************************************************/
@ -674,7 +714,7 @@ void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
@param y Top left corner y coordinate
@param bitmap byte array with monochrome bitmap
@param w Width of bitmap in pixels
@param h Hieght of bitmap in pixels
@param h Height of bitmap in pixels
@param color 16-bit 5-6-5 Color to draw pixels with
@param bg 16-bit 5-6-5 Color to draw background with
*/
@ -704,7 +744,7 @@ void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
@param y Top left corner y coordinate
@param bitmap byte array with monochrome bitmap
@param w Width of bitmap in pixels
@param h Hieght of bitmap in pixels
@param h Height of bitmap in pixels
@param color 16-bit 5-6-5 Color to draw with
*/
/**************************************************************************/
@ -732,7 +772,7 @@ void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
@param y Top left corner y coordinate
@param bitmap byte array with monochrome bitmap
@param w Width of bitmap in pixels
@param h Hieght of bitmap in pixels
@param h Height of bitmap in pixels
@param color 16-bit 5-6-5 Color to draw pixels with
@param bg 16-bit 5-6-5 Color to draw background with
*/
@ -756,7 +796,7 @@ void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
/**************************************************************************/
/*!
@brief Draw PROGMEM-resident XBitMap Files (*.xbm), exported from GIMP.
@brief Draw PROGMEM-resident XBitMap Files (*.xbm), exported from GIMP.
Usage: Export from GIMP to *.xbm, rename *.xbm to *.c and open in editor.
C Array can be directly used with this function.
There is no RAM-resident version of this function; if generating bitmaps
@ -765,7 +805,7 @@ void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
@param y Top left corner y coordinate
@param bitmap byte array with monochrome bitmap
@param w Width of bitmap in pixels
@param h Hieght of bitmap in pixels
@param h Height of bitmap in pixels
@param color 16-bit 5-6-5 Color to draw pixels with
*/
/**************************************************************************/
@ -791,13 +831,13 @@ void Adafruit_GFX::drawXBitmap(int16_t x, int16_t y,
/**************************************************************************/
/*!
@brief Draw a PROGMEM-resident 8-bit image (grayscale) at the specified (x,y) pos.
@brief Draw a PROGMEM-resident 8-bit image (grayscale) at the specified (x,y) pos.
Specifically for 8-bit display devices such as IS31FL3731; no color reduction/expansion is performed.
@param x Top left corner x coordinate
@param y Top left corner y coordinate
@param bitmap byte array with grayscale bitmap
@param w Width of bitmap in pixels
@param h Hieght of bitmap in pixels
@param h Height of bitmap in pixels
*/
/**************************************************************************/
void Adafruit_GFX::drawGrayscaleBitmap(int16_t x, int16_t y,
@ -813,13 +853,13 @@ void Adafruit_GFX::drawGrayscaleBitmap(int16_t x, int16_t y,
/**************************************************************************/
/*!
@brief Draw a RAM-resident 8-bit image (grayscale) at the specified (x,y) pos.
@brief Draw a RAM-resident 8-bit image (grayscale) at the specified (x,y) pos.
Specifically for 8-bit display devices such as IS31FL3731; no color reduction/expansion is performed.
@param x Top left corner x coordinate
@param y Top left corner y coordinate
@param bitmap byte array with grayscale bitmap
@param w Width of bitmap in pixels
@param h Hieght of bitmap in pixels
@param h Height of bitmap in pixels
*/
/**************************************************************************/
void Adafruit_GFX::drawGrayscaleBitmap(int16_t x, int16_t y,
@ -900,7 +940,7 @@ void Adafruit_GFX::drawGrayscaleBitmap(int16_t x, int16_t y,
/**************************************************************************/
/*!
@brief Draw a PROGMEM-resident 16-bit image (RGB 5/6/5) at the specified (x,y) position.
@brief Draw a PROGMEM-resident 16-bit image (RGB 5/6/5) at the specified (x,y) position.
For 16-bit display devices; no color reduction performed.
@param x Top left corner x coordinate
@param y Top left corner y coordinate
@ -922,7 +962,7 @@ void Adafruit_GFX::drawRGBBitmap(int16_t x, int16_t y,
/**************************************************************************/
/*!
@brief Draw a RAM-resident 16-bit image (RGB 5/6/5) at the specified (x,y) position.
@brief Draw a RAM-resident 16-bit image (RGB 5/6/5) at the specified (x,y) position.
For 16-bit display devices; no color reduction performed.
@param x Top left corner x coordinate
@param y Top left corner y coordinate
@ -1016,13 +1056,31 @@ void Adafruit_GFX::drawRGBBitmap(int16_t x, int16_t y,
/**************************************************************************/
void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
uint16_t color, uint16_t bg, uint8_t size) {
drawChar(x, y, c, color, bg, size, size);
}
// Draw a character
/**************************************************************************/
/*!
@brief Draw a single character
@param x Bottom left corner x coordinate
@param y Bottom left corner y coordinate
@param c The 8-bit font-indexed character (likely ascii)
@param color 16-bit 5-6-5 Color to draw chraracter with
@param bg 16-bit 5-6-5 Color to fill background with (if same as color, no background)
@param size_x Font magnification level in X-axis, 1 is 'original' size
@param size_y Font magnification level in Y-axis, 1 is 'original' size
*/
/**************************************************************************/
void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
uint16_t color, uint16_t bg, uint8_t size_x, uint8_t size_y) {
if(!gfxFont) { // 'Classic' built-in font
if((x >= _width) || // Clip right
(y >= _height) || // Clip bottom
((x + 6 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0)) // Clip top
((x + 6 * size_x - 1) < 0) || // Clip left
((y + 8 * size_y - 1) < 0)) // Clip top
return;
if(!_cp437 && (c >= 176)) c++; // Handle 'classic' charset behavior
@ -1032,21 +1090,21 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
uint8_t line = pgm_read_byte(&font[c * 5 + i]);
for(int8_t j=0; j<8; j++, line >>= 1) {
if(line & 1) {
if(size == 1)
if(size_x == 1 && size_y == 1)
writePixel(x+i, y+j, color);
else
writeFillRect(x+i*size, y+j*size, size, size, color);
writeFillRect(x+i*size_x, y+j*size_y, size_x, size_y, color);
} else if(bg != color) {
if(size == 1)
if(size_x == 1 && size_y == 1)
writePixel(x+i, y+j, bg);
else
writeFillRect(x+i*size, y+j*size, size, size, bg);
writeFillRect(x+i*size_x, y+j*size_y, size_x, size_y, bg);
}
}
}
if(bg != color) { // If opaque, draw vertical line for last column
if(size == 1) writeFastVLine(x+5, y, 8, bg);
else writeFillRect(x+5*size, y, size, 8*size, bg);
if(size_x == 1 && size_y == 1) writeFastVLine(x+5, y, 8, bg);
else writeFillRect(x+5*size_x, y, size_x, 8*size_y, bg);
}
endWrite();
@ -1057,8 +1115,8 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
// drawChar() directly with 'bad' characters of font may cause mayhem!
c -= (uint8_t)pgm_read_byte(&gfxFont->first);
GFXglyph *glyph = &(((GFXglyph *)pgm_read_pointer(&gfxFont->glyph))[c]);
uint8_t *bitmap = (uint8_t *)pgm_read_pointer(&gfxFont->bitmap);
GFXglyph *glyph = pgm_read_glyph_ptr(gfxFont, c);
uint8_t *bitmap = pgm_read_bitmap_ptr(gfxFont);
uint16_t bo = pgm_read_word(&glyph->bitmapOffset);
uint8_t w = pgm_read_byte(&glyph->width),
@ -1068,7 +1126,7 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
uint8_t xx, yy, bits = 0, bit = 0;
int16_t xo16 = 0, yo16 = 0;
if(size > 1) {
if(size_x > 1 || size_y > 1) {
xo16 = xo;
yo16 = yo;
}
@ -1098,11 +1156,11 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
bits = pgm_read_byte(&bitmap[bo++]);
}
if(bits & 0x80) {
if(size == 1) {
if(size_x == 1 && size_y == 1) {
writePixel(x+xo+xx, y+yo+yy, color);
} else {
writeFillRect(x+(xo16+xx)*size, y+(yo16+yy)*size,
size, size, color);
writeFillRect(x+(xo16+xx)*size_x, y+(yo16+yy)*size_y,
size_x, size_y, color);
}
}
bits <<= 1;
@ -1123,39 +1181,38 @@ size_t Adafruit_GFX::write(uint8_t c) {
if(c == '\n') { // Newline?
cursor_x = 0; // Reset x to zero,
cursor_y += textsize * 8; // advance y one line
cursor_y += textsize_y * 8; // advance y one line
} else if(c != '\r') { // Ignore carriage returns
if(wrap && ((cursor_x + textsize * 6) > _width)) { // Off right?
if(wrap && ((cursor_x + textsize_x * 6) > _width)) { // Off right?
cursor_x = 0; // Reset x to zero,
cursor_y += textsize * 8; // advance y one line
cursor_y += textsize_y * 8; // advance y one line
}
drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize);
cursor_x += textsize * 6; // Advance x one char
drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize_x, textsize_y);
cursor_x += textsize_x * 6; // Advance x one char
}
} else { // Custom font
if(c == '\n') {
cursor_x = 0;
cursor_y += (int16_t)textsize *
cursor_y += (int16_t)textsize_y *
(uint8_t)pgm_read_byte(&gfxFont->yAdvance);
} else if(c != '\r') {
uint8_t first = pgm_read_byte(&gfxFont->first);
if((c >= first) && (c <= (uint8_t)pgm_read_byte(&gfxFont->last))) {
GFXglyph *glyph = &(((GFXglyph *)pgm_read_pointer(
&gfxFont->glyph))[c - first]);
GFXglyph *glyph = pgm_read_glyph_ptr(gfxFont, c - first);
uint8_t w = pgm_read_byte(&glyph->width),
h = pgm_read_byte(&glyph->height);
if((w > 0) && (h > 0)) { // Is there an associated bitmap?
int16_t xo = (int8_t)pgm_read_byte(&glyph->xOffset); // sic
if(wrap && ((cursor_x + textsize * (xo + w)) > _width)) {
if(wrap && ((cursor_x + textsize_x * (xo + w)) > _width)) {
cursor_x = 0;
cursor_y += (int16_t)textsize *
cursor_y += (int16_t)textsize_y *
(uint8_t)pgm_read_byte(&gfxFont->yAdvance);
}
drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize);
drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize_x, textsize_y);
}
cursor_x += (uint8_t)pgm_read_byte(&glyph->xAdvance) * (int16_t)textsize;
cursor_x += (uint8_t)pgm_read_byte(&glyph->xAdvance) * (int16_t)textsize_x;
}
}
@ -1163,37 +1220,6 @@ size_t Adafruit_GFX::write(uint8_t c) {
return 1;
}
/**************************************************************************/
/*!
@brief Set text cursor location
@param x X coordinate in pixels
@param y Y coordinate in pixels
*/
/**************************************************************************/
void Adafruit_GFX::setCursor(int16_t x, int16_t y) {
cursor_x = x;
cursor_y = y;
}
/**************************************************************************/
/*!
@brief Get text cursor X location
@returns X coordinate in pixels
*/
/**************************************************************************/
int16_t Adafruit_GFX::getCursorX(void) const {
return cursor_x;
}
/**************************************************************************/
/*!
@brief Get text cursor Y location
@returns Y coordinate in pixels
*/
/**************************************************************************/
int16_t Adafruit_GFX::getCursorY(void) const {
return cursor_y;
}
/**************************************************************************/
/*!
@ -1202,51 +1228,19 @@ int16_t Adafruit_GFX::getCursorY(void) const {
*/
/**************************************************************************/
void Adafruit_GFX::setTextSize(uint8_t s) {
textsize = (s > 0) ? s : 1;
setTextSize(s, s);
}
/**************************************************************************/
/*!
@brief Set text font color with transparant background
@param c 16-bit 5-6-5 Color to draw text with
@brief Set text 'magnification' size. Each increase in s makes 1 pixel that much bigger.
@param s_x Desired text width magnification level in X-axis. 1 is default
@param s_y Desired text width magnification level in Y-axis. 1 is default
*/
/**************************************************************************/
void Adafruit_GFX::setTextColor(uint16_t c) {
// For 'transparent' background, we'll set the bg
// to the same as fg instead of using a flag
textcolor = textbgcolor = c;
}
/**************************************************************************/
/*!
@brief Set text font color with custom background color
@param c 16-bit 5-6-5 Color to draw text with
@param b 16-bit 5-6-5 Color to draw background/fill with
*/
/**************************************************************************/
void Adafruit_GFX::setTextColor(uint16_t c, uint16_t b) {
textcolor = c;
textbgcolor = b;
}
/**************************************************************************/
/*!
@brief Whether text that is too long should 'wrap' around to the next line.
@param w Set true for wrapping, false for clipping
*/
/**************************************************************************/
void Adafruit_GFX::setTextWrap(boolean w) {
wrap = w;
}
/**************************************************************************/
/*!
@brief Get rotation setting for display
@returns 0 thru 3 corresponding to 4 cardinal rotations
*/
/**************************************************************************/
uint8_t Adafruit_GFX::getRotation(void) const {
return rotation;
void Adafruit_GFX::setTextSize(uint8_t s_x, uint8_t s_y) {
textsize_x = (s_x > 0) ? s_x : 1;
textsize_y = (s_y > 0) ? s_y : 1;
}
/**************************************************************************/
@ -1271,22 +1265,6 @@ void Adafruit_GFX::setRotation(uint8_t x) {
}
}
/**************************************************************************/
/*!
@brief Enable (or disable) Code Page 437-compatible charset.
There was an error in glcdfont.c for the longest time -- one character
(#176, the 'light shade' block) was missing -- this threw off the index
of every character that followed it. But a TON of code has been written
with the erroneous character indices. By default, the library uses the
original 'wrong' behavior and old sketches will still work. Pass 'true'
to this function to use correct CP437 character values in your code.
@param x Whether to enable (True) or not (False)
*/
/**************************************************************************/
void Adafruit_GFX::cp437(boolean x) {
_cp437 = x;
}
/**************************************************************************/
/*!
@brief Set the font to display when print()ing, either custom or default
@ -1329,32 +1307,32 @@ void Adafruit_GFX::charBounds(char c, int16_t *x, int16_t *y,
if(c == '\n') { // Newline?
*x = 0; // Reset x to zero, advance y by one line
*y += textsize * (uint8_t)pgm_read_byte(&gfxFont->yAdvance);
*y += textsize_y * (uint8_t)pgm_read_byte(&gfxFont->yAdvance);
} else if(c != '\r') { // Not a carriage return; is normal char
uint8_t first = pgm_read_byte(&gfxFont->first),
last = pgm_read_byte(&gfxFont->last);
if((c >= first) && (c <= last)) { // Char present in this font?
GFXglyph *glyph = &(((GFXglyph *)pgm_read_pointer(
&gfxFont->glyph))[c - first]);
GFXglyph *glyph = pgm_read_glyph_ptr(gfxFont, c - first);
uint8_t gw = pgm_read_byte(&glyph->width),
gh = pgm_read_byte(&glyph->height),
xa = pgm_read_byte(&glyph->xAdvance);
int8_t xo = pgm_read_byte(&glyph->xOffset),
yo = pgm_read_byte(&glyph->yOffset);
if(wrap && ((*x+(((int16_t)xo+gw)*textsize)) > _width)) {
if(wrap && ((*x+(((int16_t)xo+gw)*textsize_x)) > _width)) {
*x = 0; // Reset x to zero, advance y by one line
*y += textsize * (uint8_t)pgm_read_byte(&gfxFont->yAdvance);
*y += textsize_y * (uint8_t)pgm_read_byte(&gfxFont->yAdvance);
}
int16_t ts = (int16_t)textsize,
x1 = *x + xo * ts,
y1 = *y + yo * ts,
x2 = x1 + gw * ts - 1,
y2 = y1 + gh * ts - 1;
int16_t tsx = (int16_t)textsize_x,
tsy = (int16_t)textsize_y,
x1 = *x + xo * tsx,
y1 = *y + yo * tsy,
x2 = x1 + gw * tsx - 1,
y2 = y1 + gh * tsy - 1;
if(x1 < *minx) *minx = x1;
if(y1 < *miny) *miny = y1;
if(x2 > *maxx) *maxx = x2;
if(y2 > *maxy) *maxy = y2;
*x += xa * ts;
*x += xa * tsx;
}
}
@ -1362,20 +1340,20 @@ void Adafruit_GFX::charBounds(char c, int16_t *x, int16_t *y,
if(c == '\n') { // Newline?
*x = 0; // Reset x to zero,
*y += textsize * 8; // advance y one line
*y += textsize_y * 8; // advance y one line
// min/max x/y unchaged -- that waits for next 'normal' character
} else if(c != '\r') { // Normal char; ignore carriage returns
if(wrap && ((*x + textsize * 6) > _width)) { // Off right?
if(wrap && ((*x + textsize_x * 6) > _width)) { // Off right?
*x = 0; // Reset x to zero,
*y += textsize * 8; // advance y one line
*y += textsize_y * 8; // advance y one line
}
int x2 = *x + textsize * 6 - 1, // Lower-right pixel of char
y2 = *y + textsize * 8 - 1;
int x2 = *x + textsize_x * 6 - 1, // Lower-right pixel of char
y2 = *y + textsize_y * 8 - 1;
if(x2 > *maxx) *maxx = x2; // Track max x, y
if(y2 > *maxy) *maxy = y2;
if(*x < *minx) *minx = *x; // Track min x, y
if(*y < *miny) *miny = *y;
*x += textsize * 6; // Advance x one char
*x += textsize_x * 6; // Advance x one char
}
}
}
@ -1470,26 +1448,6 @@ void Adafruit_GFX::getTextBounds(const __FlashStringHelper *str,
}
}
/**************************************************************************/
/*!
@brief Get width of the display, accounting for the current rotation
@returns Width in pixels
*/
/**************************************************************************/
int16_t Adafruit_GFX::width(void) const {
return _width;
}
/**************************************************************************/
/*!
@brief Get height of the display, accounting for the current rotation
@returns Height in pixels
*/
/**************************************************************************/
int16_t Adafruit_GFX::height(void) const {
return _height;
}
/**************************************************************************/
/*!
@brief Invert the display (ideally using built-in hardware command)
@ -1537,6 +1495,33 @@ void Adafruit_GFX_Button::initButton(
textcolor, label, textsize);
}
/**************************************************************************/
/*!
@brief Initialize button with our desired color/size/settings
@param gfx Pointer to our display so we can draw to it!
@param x The X coordinate of the center of the button
@param y The Y coordinate of the center of the button
@param w Width of the buttton
@param h Height of the buttton
@param outline Color of the outline (16-bit 5-6-5 standard)
@param fill Color of the button fill (16-bit 5-6-5 standard)
@param textcolor Color of the button label (16-bit 5-6-5 standard)
@param label Ascii string of the text inside the button
@param textsize_x The font magnification in X-axis of the label text
@param textsize_y The font magnification in Y-axis of the label text
*/
/**************************************************************************/
// Classic initButton() function: pass center & size
void Adafruit_GFX_Button::initButton(
Adafruit_GFX *gfx, int16_t x, int16_t y, uint16_t w, uint16_t h,
uint16_t outline, uint16_t fill, uint16_t textcolor,
char *label, uint8_t textsize_x, uint8_t textsize_y)
{
// Tweak arguments and pass to the newer initButtonUL() function...
initButtonUL(gfx, x - (w / 2), y - (h / 2), w, h, outline, fill,
textcolor, label, textsize_x, textsize_y);
}
/**************************************************************************/
/*!
@brief Initialize button with our desired color/size/settings, with upper-left coordinates
@ -1556,6 +1541,30 @@ void Adafruit_GFX_Button::initButtonUL(
Adafruit_GFX *gfx, int16_t x1, int16_t y1, uint16_t w, uint16_t h,
uint16_t outline, uint16_t fill, uint16_t textcolor,
char *label, uint8_t textsize)
{
initButtonUL(gfx, x1, y1, w, h, outline, fill, textcolor, label, textsize, textsize);
}
/**************************************************************************/
/*!
@brief Initialize button with our desired color/size/settings, with upper-left coordinates
@param gfx Pointer to our display so we can draw to it!
@param x1 The X coordinate of the Upper-Left corner of the button
@param y1 The Y coordinate of the Upper-Left corner of the button
@param w Width of the buttton
@param h Height of the buttton
@param outline Color of the outline (16-bit 5-6-5 standard)
@param fill Color of the button fill (16-bit 5-6-5 standard)
@param textcolor Color of the button label (16-bit 5-6-5 standard)
@param label Ascii string of the text inside the button
@param textsize_x The font magnification in X-axis of the label text
@param textsize_y The font magnification in Y-axis of the label text
*/
/**************************************************************************/
void Adafruit_GFX_Button::initButtonUL(
Adafruit_GFX *gfx, int16_t x1, int16_t y1, uint16_t w, uint16_t h,
uint16_t outline, uint16_t fill, uint16_t textcolor,
char *label, uint8_t textsize_x, uint8_t textsize_y)
{
_x1 = x1;
_y1 = y1;
@ -1564,7 +1573,8 @@ void Adafruit_GFX_Button::initButtonUL(
_outlinecolor = outline;
_fillcolor = fill;
_textcolor = textcolor;
_textsize = textsize;
_textsize_x = textsize_x;
_textsize_y = textsize_y;
_gfx = gfx;
strncpy(_label, label, 9);
}
@ -1592,19 +1602,20 @@ void Adafruit_GFX_Button::drawButton(boolean inverted) {
_gfx->fillRoundRect(_x1, _y1, _w, _h, r, fill);
_gfx->drawRoundRect(_x1, _y1, _w, _h, r, outline);
_gfx->setCursor(_x1 + (_w/2) - (strlen(_label) * 3 * _textsize),
_y1 + (_h/2) - (4 * _textsize));
_gfx->setCursor(_x1 + (_w/2) - (strlen(_label) * 3 * _textsize_x),
_y1 + (_h/2) - (4 * _textsize_y));
_gfx->setTextColor(text);
_gfx->setTextSize(_textsize);
_gfx->setTextSize(_textsize_x, _textsize_y);
_gfx->print(_label);
}
/**************************************************************************/
/*!
@brief Helper to let us know if a coordinate is within the bounds of the button
@brief Helper to let us know if a coordinate is within the bounds of the button
@param x The X coordinate to check
@param y The Y coordinate to check
@returns True if within button graphics outline
@returns True if within button graphics outline
*/
/**************************************************************************/
boolean Adafruit_GFX_Button::contains(int16_t x, int16_t y) {
@ -1612,25 +1623,6 @@ boolean Adafruit_GFX_Button::contains(int16_t x, int16_t y) {
(y >= _y1) && (y < (int16_t) (_y1 + _h)));
}
/**************************************************************************/
/*!
@brief Sets the state of the button, should be done by some touch function
@param p True for pressed, false for not.
*/
/**************************************************************************/
void Adafruit_GFX_Button::press(boolean p) {
laststate = currstate;
currstate = p;
}
/**************************************************************************/
/*!
@brief Query whether the button is currently pressed
@returns True if pressed
*/
/**************************************************************************/
boolean Adafruit_GFX_Button::isPressed() { return currstate; }
/**************************************************************************/
/*!
@brief Query whether the button was pressed since we last checked state
@ -1691,20 +1683,10 @@ GFXcanvas1::~GFXcanvas1(void) {
/**************************************************************************/
/*!
@brief Get a pointer to the internal buffer memory
@returns A pointer to the allocated buffer
*/
/**************************************************************************/
uint8_t* GFXcanvas1::getBuffer(void) {
return buffer;
}
/**************************************************************************/
/*!
@brief Draw a pixel to the canvas framebuffer
@param x x coordinate
@param y y coordinate
@param color 16-bit 5-6-5 Color to fill with
@brief Draw a pixel to the canvas framebuffer
@param x x coordinate
@param y y coordinate
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void GFXcanvas1::drawPixel(int16_t x, int16_t y, uint16_t color) {
@ -1749,8 +1731,8 @@ void GFXcanvas1::drawPixel(int16_t x, int16_t y, uint16_t color) {
/**************************************************************************/
/*!
@brief Fill the framebuffer completely with one color
@param color 16-bit 5-6-5 Color to fill with
@brief Fill the framebuffer completely with one color
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void GFXcanvas1::fillScreen(uint16_t color) {
@ -1783,23 +1765,12 @@ GFXcanvas8::~GFXcanvas8(void) {
if(buffer) free(buffer);
}
/**************************************************************************/
/*!
@brief Get a pointer to the internal buffer memory
@returns A pointer to the allocated buffer
*/
/**************************************************************************/
uint8_t* GFXcanvas8::getBuffer(void) {
return buffer;
}
/**************************************************************************/
/*!
@brief Draw a pixel to the canvas framebuffer
@param x x coordinate
@param y y coordinate
@param color 16-bit 5-6-5 Color to fill with
@brief Draw a pixel to the canvas framebuffer
@param x x coordinate
@param y y coordinate
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void GFXcanvas8::drawPixel(int16_t x, int16_t y, uint16_t color) {
@ -1830,8 +1801,8 @@ void GFXcanvas8::drawPixel(int16_t x, int16_t y, uint16_t color) {
/**************************************************************************/
/*!
@brief Fill the framebuffer completely with one color
@param color 16-bit 5-6-5 Color to fill with
@brief Fill the framebuffer completely with one color
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void GFXcanvas8::fillScreen(uint16_t color) {
@ -1900,20 +1871,10 @@ GFXcanvas16::~GFXcanvas16(void) {
/**************************************************************************/
/*!
@brief Get a pointer to the internal buffer memory
@returns A pointer to the allocated buffer
*/
/**************************************************************************/
uint16_t* GFXcanvas16::getBuffer(void) {
return buffer;
}
/**************************************************************************/
/*!
@brief Draw a pixel to the canvas framebuffer
@param x x coordinate
@param y y coordinate
@param color 16-bit 5-6-5 Color to fill with
@brief Draw a pixel to the canvas framebuffer
@param x x coordinate
@param y y coordinate
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void GFXcanvas16::drawPixel(int16_t x, int16_t y, uint16_t color) {
@ -1944,8 +1905,8 @@ void GFXcanvas16::drawPixel(int16_t x, int16_t y, uint16_t color) {
/**************************************************************************/
/*!
@brief Fill the framebuffer completely with one color
@param color 16-bit 5-6-5 Color to fill with
@brief Fill the framebuffer completely with one color
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void GFXcanvas16::fillScreen(uint16_t color) {
@ -1960,3 +1921,22 @@ void GFXcanvas16::fillScreen(uint16_t color) {
}
}
/**************************************************************************/
/*!
@brief Reverses the "endian-ness" of each 16-bit pixel within the
canvas; little-endian to big-endian, or big-endian to little.
Most microcontrollers (such as SAMD) are little-endian, while
most displays tend toward big-endianness. All the drawing
functions (including RGB bitmap drawing) take care of this
automatically, but some specialized code (usually involving
DMA) can benefit from having pixel data already in the
display-native order. Note that this does NOT convert to a
SPECIFIC endian-ness, it just flips the bytes within each word.
*/
/**************************************************************************/
void GFXcanvas16::byteSwap(void) {
if(buffer) {
uint32_t i, pixels = WIDTH * HEIGHT;
for(i=0; i<pixels; i++) buffer[i] = __builtin_bswap16(buffer[i]);
}
}

View File

@ -17,7 +17,7 @@ class Adafruit_GFX : public Print {
Adafruit_GFX(int16_t w, int16_t h); // Constructor
// This MUST be defined by the subclass:
virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; ///< Virtual drawPixel() function to draw to the screen/framebuffer/etc, must be overridden in subclass. @param x X coordinate. @param y Y coordinate. @param color 16-bit pixel color.
virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; ///< Virtual drawPixel() function to draw to the screen/framebuffer/etc, must be overridden in subclass. @param x X coordinate. @param y Y coordinate. @param color 16-bit pixel color.
// TRANSACTION API / CORE DRAW API
// These MAY be overridden by the subclass to provide device-specific
@ -51,20 +51,10 @@ class Adafruit_GFX : public Print {
// These exist only with Adafruit_GFX (no subclass overrides)
void
drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
uint16_t color),
fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
int16_t delta, uint16_t color),
drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color),
fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color),
drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
int16_t radius, uint16_t color),
fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
int16_t radius, uint16_t color),
drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
int16_t w, int16_t h, uint16_t color),
drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
@ -95,41 +85,143 @@ class Adafruit_GFX : public Print {
uint16_t *bitmap, uint8_t *mask, int16_t w, int16_t h),
drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
uint16_t bg, uint8_t size),
setCursor(int16_t x, int16_t y),
setTextColor(uint16_t c),
setTextColor(uint16_t c, uint16_t bg),
setTextSize(uint8_t s),
setTextWrap(boolean w),
cp437(boolean x=true),
setFont(const GFXfont *f = NULL),
drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
uint16_t bg, uint8_t size_x, uint8_t size_y),
getTextBounds(const char *string, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
getTextBounds(const String &str, int16_t x, int16_t y,
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
setFont(const GFXfont *f = NULL);
virtual void
drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
int16_t radius, uint16_t color),
fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
int16_t radius, uint16_t color),
drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color),
fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color),
setTextSize(uint8_t s),
setTextSize(uint8_t sx, uint8_t sy);
/**********************************************************************/
/*!
@brief Set text cursor location
@param x X coordinate in pixels
@param y Y coordinate in pixels
*/
/**********************************************************************/
virtual void setCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; }
/**********************************************************************/
/*!
@brief Set text font color with transparant background
@param c 16-bit 5-6-5 Color to draw text with
@note For 'transparent' background, background and foreground
are set to same color rather than using a separate flag.
*/
/**********************************************************************/
void setTextColor(uint16_t c) { textcolor = textbgcolor = c; }
/**********************************************************************/
/*!
@brief Set text font color with custom background color
@param c 16-bit 5-6-5 Color to draw text with
@param bg 16-bit 5-6-5 Color to draw background/fill with
*/
/**********************************************************************/
void setTextColor(uint16_t c, uint16_t bg) {
textcolor = c;
textbgcolor = bg;
}
/**********************************************************************/
/*!
@brief Set whether text that is too long for the screen width should
automatically wrap around to the next line (else clip right).
@param w true for wrapping, false for clipping
*/
/**********************************************************************/
void setTextWrap(boolean w) { wrap = w; }
/**********************************************************************/
/*!
@brief Enable (or disable) Code Page 437-compatible charset.
There was an error in glcdfont.c for the longest time -- one
character (#176, the 'light shade' block) was missing -- this
threw off the index of every character that followed it.
But a TON of code has been written with the erroneous
character indices. By default, the library uses the original
'wrong' behavior and old sketches will still work. Pass
'true' to this function to use correct CP437 character values
in your code.
@param x true = enable (new behavior), false = disable (old behavior)
*/
/**********************************************************************/
void cp437(boolean x=true) { _cp437 = x; }
#if ARDUINO >= 100
virtual size_t write(uint8_t);
#else
virtual void write(uint8_t);
#endif
size_t iwrite(uint8_t);
/************************************************************************/
/*!
@brief Get width of the display, accounting for current rotation
@returns Width in pixels
*/
/************************************************************************/
int16_t width(void) const { return _width; };
int16_t height(void) const;
int16_t width(void) const;
/************************************************************************/
/*!
@brief Get height of the display, accounting for current rotation
@returns Height in pixels
*/
/************************************************************************/
int16_t height(void) const { return _height; }
uint8_t getRotation(void) const;
/************************************************************************/
/*!
@brief Get rotation setting for display
@returns 0 thru 3 corresponding to 4 cardinal rotations
*/
/************************************************************************/
uint8_t getRotation(void) const { return rotation; }
// get current cursor position (get rotation safe maximum values, using: width() for x, height() for y)
int16_t getCursorX(void) const;
int16_t getCursorY(void) const;
// get current cursor position (get rotation safe maximum values,
// using: width() for x, height() for y)
/************************************************************************/
/*!
@brief Get text cursor X location
@returns X coordinate in pixels
*/
/************************************************************************/
int16_t getCursorX(void) const { return cursor_x; }
/************************************************************************/
/*!
@brief Get text cursor Y location
@returns Y coordinate in pixels
*/
/************************************************************************/
int16_t getCursorY(void) const { return cursor_y; };
uint16_t
textcolor, ///< 16-bit background color for print()
textbgcolor; ///< 16-bit text color for print()
protected:
void
charBounds(char c, int16_t *x, int16_t *y,
int16_t *minx, int16_t *miny, int16_t *maxx, int16_t *maxy);
const int16_t
int16_t
WIDTH, ///< This is the 'raw' display width - never changes
HEIGHT; ///< This is the 'raw' display height - never changes
int16_t
@ -137,11 +229,12 @@ class Adafruit_GFX : public Print {
_height, ///< Display height as modified by current rotation
cursor_x, ///< x location to start print()ing text
cursor_y; ///< y location to start print()ing text
uint16_t
textcolor, ///< 16-bit background color for print()
textbgcolor; ///< 16-bit text color for print()
//uint16_t
// textcolor, ///< 16-bit background color for print()
// textbgcolor; ///< 16-bit text color for print()
uint8_t
textsize, ///< Desired magnification of text to print()
textsize_x, ///< Desired magnification in X-axis of text to print()
textsize_y, ///< Desired magnification in Y-axis of text to print()
rotation; ///< Display rotation (0 thru 3)
boolean
wrap, ///< If set, 'wrap' text at right edge of display
@ -160,23 +253,44 @@ class Adafruit_GFX_Button {
void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
uint16_t textcolor, char *label, uint8_t textsize);
void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
uint16_t textcolor, char *label, uint8_t textsize_x, uint8_t textsize_y);
// New/alt initButton() uses upper-left corner & size
void initButtonUL(Adafruit_GFX *gfx, int16_t x1, int16_t y1,
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
uint16_t textcolor, char *label, uint8_t textsize);
void initButtonUL(Adafruit_GFX *gfx, int16_t x1, int16_t y1,
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
uint16_t textcolor, char *label, uint8_t textsize_x, uint8_t textsize_y);
void drawButton(boolean inverted = false);
boolean contains(int16_t x, int16_t y);
void press(boolean p);
boolean isPressed();
/**********************************************************************/
/*!
@brief Sets button state, should be done by some touch function
@param p True for pressed, false for not.
*/
/**********************************************************************/
void press(boolean p) { laststate = currstate; currstate = p; }
boolean justPressed();
boolean justReleased();
/**********************************************************************/
/*!
@brief Query whether the button is currently pressed
@returns True if pressed
*/
/**********************************************************************/
boolean isPressed(void) { return currstate; };
private:
Adafruit_GFX *_gfx;
int16_t _x1, _y1; // Coordinates of top-left corner
uint16_t _w, _h;
uint8_t _textsize;
uint8_t _textsize_x;
uint8_t _textsize_y;
uint16_t _outlinecolor, _fillcolor, _textcolor;
char _label[10];
@ -191,7 +305,13 @@ class GFXcanvas1 : public Adafruit_GFX {
~GFXcanvas1(void);
void drawPixel(int16_t x, int16_t y, uint16_t color),
fillScreen(uint16_t color);
uint8_t *getBuffer(void);
/**********************************************************************/
/*!
@brief Get a pointer to the internal buffer memory
@returns A pointer to the allocated buffer
*/
/**********************************************************************/
uint8_t *getBuffer(void) const { return buffer; }
private:
uint8_t *buffer;
};
@ -205,8 +325,13 @@ class GFXcanvas8 : public Adafruit_GFX {
void drawPixel(int16_t x, int16_t y, uint16_t color),
fillScreen(uint16_t color),
writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
uint8_t *getBuffer(void);
/**********************************************************************/
/*!
@brief Get a pointer to the internal buffer memory
@returns A pointer to the allocated buffer
*/
/**********************************************************************/
uint8_t *getBuffer(void) const { return buffer; }
private:
uint8_t *buffer;
};
@ -218,8 +343,15 @@ class GFXcanvas16 : public Adafruit_GFX {
GFXcanvas16(uint16_t w, uint16_t h);
~GFXcanvas16(void);
void drawPixel(int16_t x, int16_t y, uint16_t color),
fillScreen(uint16_t color);
uint16_t *getBuffer(void);
fillScreen(uint16_t color),
byteSwap(void);
/**********************************************************************/
/*!
@brief Get a pointer to the internal buffer memory
@returns A pointer to the allocated buffer
*/
/**********************************************************************/
uint16_t *getBuffer(void) const { return buffer; }
private:
uint16_t *buffer;
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,519 @@
/*!
* @file Adafruit_SPITFT.h
*
* Part of Adafruit's GFX graphics library. Originally this class was
* written to handle a range of color TFT displays connected via SPI,
* but over time this library and some display-specific subclasses have
* mutated to include some color OLEDs as well as parallel-interfaced
* displays. The name's been kept for the sake of older code.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Limor "ladyada" Fried for Adafruit Industries,
* with contributions from the open source community.
*
* BSD license, all text here must be included in any redistribution.
*/
#ifndef _ADAFRUIT_SPITFT_H_
#define _ADAFRUIT_SPITFT_H_
#if !defined(__AVR_ATtiny85__) // Not for ATtiny, at all
#include <SPI.h>
#include "Adafruit_GFX.h"
// HARDWARE CONFIG ---------------------------------------------------------
#if defined(__AVR__)
typedef uint8_t ADAGFX_PORT_t; ///< PORT values are 8-bit
#define USE_FAST_PINIO ///< Use direct PORT register access
#elif defined(ARDUINO_STM32_FEATHER) // WICED
typedef class HardwareSPI SPIClass; ///< SPI is a bit odd on WICED
typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit
#elif defined(__arm__)
#if defined(ARDUINO_ARCH_SAMD)
// Adafruit M0, M4
typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit
#define USE_FAST_PINIO ///< Use direct PORT register access
#define HAS_PORT_SET_CLR ///< PORTs have set & clear registers
#elif defined(CORE_TEENSY)
// PJRC Teensy 4.x
#if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x
typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit
// PJRC Teensy 3.x
#else
typedef uint8_t ADAGFX_PORT_t; ///< PORT values are 8-bit
#endif
#define USE_FAST_PINIO ///< Use direct PORT register access
#define HAS_PORT_SET_CLR ///< PORTs have set & clear registers
#else
// Arduino Due?
typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit
// USE_FAST_PINIO not available here (yet)...Due has a totally different
// GPIO register set and will require some changes elsewhere (e.g. in
// constructors especially).
#endif
#else // !ARM
// Probably ESP8266 or ESP32. USE_FAST_PINIO is not available here (yet)
// but don't worry about it too much...the digitalWrite() implementation
// on these platforms is reasonably efficient and already RAM-resident,
// only gotcha then is no parallel connection support for now.
typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit
#endif // end !ARM
typedef volatile ADAGFX_PORT_t* PORTreg_t; ///< PORT register type
#if defined(__AVR__)
#define DEFAULT_SPI_FREQ 8000000L ///< Hardware SPI default speed
#else
#define DEFAULT_SPI_FREQ 16000000L ///< Hardware SPI default speed
#endif
#if defined(ADAFRUIT_PYPORTAL) || defined(ADAFRUIT_PYBADGE_M4_EXPRESS) || defined(ADAFRUIT_PYGAMER_M4_EXPRESS)
#define USE_SPI_DMA ///< Auto DMA if using PyPortal
#else
//#define USE_SPI_DMA ///< If set, use DMA if available
#endif
// Another "oops" name -- this now also handles parallel DMA.
// If DMA is enabled, Arduino sketch MUST #include <Adafruit_ZeroDMA.h>
// Estimated RAM usage:
// 4 bytes/pixel on display major axis + 8 bytes/pixel on minor axis,
// e.g. 320x240 pixels = 320 * 4 + 240 * 8 = 3,200 bytes.
#if !defined(ARDUINO_ARCH_SAMD)
#undef USE_SPI_DMA ///< DMA currently for SAMD chips only
#endif
#if defined(USE_SPI_DMA)
#pragma message ("GFX DMA IS ENABLED. HIGHLY EXPERIMENTAL.")
#include <Adafruit_ZeroDMA.h>
#endif
// This is kind of a kludge. Needed a way to disambiguate the software SPI
// and parallel constructors via their argument lists. Originally tried a
// bool as the first argument to the parallel constructor (specifying 8-bit
// vs 16-bit interface) but the compiler regards this as equivalent to an
// integer and thus still ambiguous. SO...the parallel constructor requires
// an enumerated type as the first argument: tft8 (for 8-bit parallel) or
// tft16 (for 16-bit)...even though 16-bit isn't fully implemented or tested
// and might never be, still needed that disambiguation from soft SPI.
enum tftBusWidth { tft8bitbus, tft16bitbus }; ///< For first arg to parallel constructor
// CLASS DEFINITION --------------------------------------------------------
/*!
@brief Adafruit_SPITFT is an intermediary class between Adafruit_GFX
and various hardware-specific subclasses for different displays.
It handles certain operations that are common to a range of
displays (address window, area fills, etc.). Originally these were
all color TFT displays interfaced via SPI, but it's since expanded
to include color OLEDs and parallel-interfaced TFTs. THE NAME HAS
BEEN KEPT TO AVOID BREAKING A LOT OF SUBCLASSES AND EXAMPLE CODE.
Many of the class member functions similarly live on with names
that don't necessarily accurately describe what they're doing,
again to avoid breaking a lot of other code. If in doubt, read
the comments.
*/
class Adafruit_SPITFT : public Adafruit_GFX {
public:
// CONSTRUCTORS --------------------------------------------------------
// Software SPI constructor: expects width & height (at default rotation
// setting 0), 4 signal pins (cs, dc, mosi, sclk), 2 optional pins
// (reset, miso). cs argument is required but can be -1 if unused --
// rather than moving it to the optional arguments, it was done this way
// to avoid breaking existing code (-1 option was a later addition).
Adafruit_SPITFT(uint16_t w, uint16_t h,
int8_t cs, int8_t dc, int8_t mosi, int8_t sck,
int8_t rst = -1, int8_t miso = -1);
// Hardware SPI constructor using the default SPI port: expects width &
// height (at default rotation setting 0), 2 signal pins (cs, dc),
// optional reset pin. cs is required but can be -1 if unused -- rather
// than moving it to the optional arguments, it was done this way to
// avoid breaking existing code (-1 option was a later addition).
Adafruit_SPITFT(uint16_t w, uint16_t h,
int8_t cs, int8_t dc, int8_t rst = -1);
#if !defined(ESP8266) // See notes in .cpp
// Hardware SPI constructor using an arbitrary SPI peripheral: expects
// width & height (rotation 0), SPIClass pointer, 2 signal pins (cs, dc)
// and optional reset pin. cs is required but can be -1 if unused.
Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass,
int8_t cs, int8_t dc, int8_t rst = -1);
#endif // end !ESP8266
// Parallel constructor: expects width & height (rotation 0), flag
// indicating whether 16-bit (true) or 8-bit (false) interface, 3 signal
// pins (d0, wr, dc), 3 optional pins (cs, rst, rd). 16-bit parallel
// isn't even fully implemented but the 'wide' flag was added as a
// required argument to avoid ambiguity with other constructors.
Adafruit_SPITFT(uint16_t w, uint16_t h, tftBusWidth busWidth,
int8_t d0, int8_t wr, int8_t dc,
int8_t cs = -1, int8_t rst = -1, int8_t rd = -1);
// CLASS MEMBER FUNCTIONS ----------------------------------------------
// These first two functions MUST be declared by subclasses:
/*!
@brief Display-specific initialization function.
@param freq SPI frequency, in hz (or 0 for default or unused).
*/
virtual void begin(uint32_t freq) = 0;
/*!
@brief Set up the specific display hardware's "address window"
for subsequent pixel-pushing operations.
@param x Leftmost pixel of area to be drawn (MUST be within
display bounds at current rotation setting).
@param y Topmost pixel of area to be drawn (MUST be within
display bounds at current rotation setting).
@param w Width of area to be drawn, in pixels (MUST be >0 and,
added to x, within display bounds at current rotation).
@param h Height of area to be drawn, in pixels (MUST be >0 and,
added to x, within display bounds at current rotation).
*/
virtual void setAddrWindow(
uint16_t x, uint16_t y, uint16_t w, uint16_t h) = 0;
// Remaining functions do not need to be declared in subclasses
// unless they wish to provide hardware-specific optimizations.
// Brief comments here...documented more thoroughly in .cpp file.
// Subclass' begin() function invokes this to initialize hardware.
// freq=0 to use default SPI speed. spiMode must be one of the SPI_MODEn
// values defined in SPI.h, which are NOT the same as 0 for SPI_MODE0,
// 1 for SPI_MODE1, etc...use ONLY the SPI_MODEn defines! Only!
// Name is outdated (interface may be parallel) but for compatibility:
void initSPI(uint32_t freq = 0, uint8_t spiMode = SPI_MODE0);
// Chip select and/or hardware SPI transaction start as needed:
void startWrite(void);
// Chip deselect and/or hardware SPI transaction end as needed:
void endWrite(void);
void sendCommand(uint8_t commandByte, uint8_t *dataBytes = NULL, uint8_t numDataBytes = 0);
void sendCommand(uint8_t commandByte, const uint8_t *dataBytes, uint8_t numDataBytes);
uint8_t readcommand8(uint8_t commandByte, uint8_t index = 0);
// These functions require a chip-select and/or SPI transaction
// around them. Higher-level graphics primitives might start a
// single transaction and then make multiple calls to these functions
// (e.g. circle or text rendering might make repeated lines or rects)
// before ending the transaction. It's more efficient than starting a
// transaction every time.
void writePixel(int16_t x, int16_t y, uint16_t color);
void writePixels(uint16_t *colors, uint32_t len,
bool block=true, bool bigEndian=false);
void writeColor(uint16_t color, uint32_t len);
void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color);
void writeFastHLine(int16_t x, int16_t y, int16_t w,
uint16_t color);
void writeFastVLine(int16_t x, int16_t y, int16_t h,
uint16_t color);
// This is a new function, similar to writeFillRect() except that
// all arguments MUST be onscreen, sorted and clipped. If higher-level
// primitives can handle their own sorting/clipping, it avoids repeating
// such operations in the low-level code, making it potentially faster.
// CALLING THIS WITH UNCLIPPED OR NEGATIVE VALUES COULD BE DISASTROUS.
inline void writeFillRectPreclipped(int16_t x, int16_t y,
int16_t w, int16_t h, uint16_t color);
// Another new function, companion to the new non-blocking
// writePixels() variant.
void dmaWait(void);
// These functions are similar to the 'write' functions above, but with
// a chip-select and/or SPI transaction built-in. They're typically used
// solo -- that is, as graphics primitives in themselves, not invoked by
// higher-level primitives (which should use the functions above).
void drawPixel(int16_t x, int16_t y, uint16_t color);
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color);
void drawFastHLine(int16_t x, int16_t y, int16_t w,
uint16_t color);
void drawFastVLine(int16_t x, int16_t y, int16_t h,
uint16_t color);
// A single-pixel push encapsulated in a transaction. I don't think
// this is used anymore (BMP demos might've used it?) but is provided
// for backward compatibility, consider it deprecated:
void pushColor(uint16_t color);
using Adafruit_GFX::drawRGBBitmap; // Check base class first
void drawRGBBitmap(int16_t x, int16_t y,
uint16_t *pcolors, int16_t w, int16_t h);
void invertDisplay(bool i);
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
// Despite parallel additions, function names kept for compatibility:
void spiWrite(uint8_t b); // Write single byte as DATA
void writeCommand(uint8_t cmd); // Write single byte as COMMAND
uint8_t spiRead(void); // Read single byte of data
// Most of these low-level functions were formerly macros in
// Adafruit_SPITFT_Macros.h. Some have been made into inline functions
// to avoid macro mishaps. Despite the addition of code for a parallel
// display interface, the names have been kept for backward
// compatibility (some subclasses may be invoking these):
void SPI_WRITE16(uint16_t w); // Not inline
void SPI_WRITE32(uint32_t l); // Not inline
// Old code had both a spiWrite16() function and SPI_WRITE16 macro
// in addition to the SPI_WRITE32 macro. The latter two have been
// made into functions here, and spiWrite16() removed (use SPI_WRITE16()
// instead). It looks like most subclasses had gotten comfortable with
// SPI_WRITE16 and SPI_WRITE32 anyway so those names were kept rather
// than the less-obnoxious camelcase variants, oh well.
// Placing these functions entirely in the class definition inlines
// them implicitly them while allowing their use in other code:
/*!
@brief Set the chip-select line HIGH. Does NOT check whether CS pin
is set (>=0), that should be handled in calling function.
Despite function name, this is used even if the display
connection is parallel.
*/
void SPI_CS_HIGH(void) {
#if defined(USE_FAST_PINIO)
#if defined(HAS_PORT_SET_CLR)
#if defined(KINETISK)
*csPortSet = 1;
#else // !KINETISK
*csPortSet = csPinMask;
#endif // end !KINETISK
#else // !HAS_PORT_SET_CLR
*csPort |= csPinMaskSet;
#endif // end !HAS_PORT_SET_CLR
#else // !USE_FAST_PINIO
digitalWrite(_cs, HIGH);
#endif // end !USE_FAST_PINIO
}
/*!
@brief Set the chip-select line LOW. Does NOT check whether CS pin
is set (>=0), that should be handled in calling function.
Despite function name, this is used even if the display
connection is parallel.
*/
void SPI_CS_LOW(void) {
#if defined(USE_FAST_PINIO)
#if defined(HAS_PORT_SET_CLR)
#if defined(KINETISK)
*csPortClr = 1;
#else // !KINETISK
*csPortClr = csPinMask;
#endif // end !KINETISK
#else // !HAS_PORT_SET_CLR
*csPort &= csPinMaskClr;
#endif // end !HAS_PORT_SET_CLR
#else // !USE_FAST_PINIO
digitalWrite(_cs, LOW);
#endif // end !USE_FAST_PINIO
}
/*!
@brief Set the data/command line HIGH (data mode).
*/
void SPI_DC_HIGH(void) {
#if defined(USE_FAST_PINIO)
#if defined(HAS_PORT_SET_CLR)
#if defined(KINETISK)
*dcPortSet = 1;
#else // !KINETISK
*dcPortSet = dcPinMask;
#endif // end !KINETISK
#else // !HAS_PORT_SET_CLR
*dcPort |= dcPinMaskSet;
#endif // end !HAS_PORT_SET_CLR
#else // !USE_FAST_PINIO
digitalWrite(_dc, HIGH);
#endif // end !USE_FAST_PINIO
}
/*!
@brief Set the data/command line LOW (command mode).
*/
void SPI_DC_LOW(void) {
#if defined(USE_FAST_PINIO)
#if defined(HAS_PORT_SET_CLR)
#if defined(KINETISK)
*dcPortClr = 1;
#else // !KINETISK
*dcPortClr = dcPinMask;
#endif // end !KINETISK
#else // !HAS_PORT_SET_CLR
*dcPort &= dcPinMaskClr;
#endif // end !HAS_PORT_SET_CLR
#else // !USE_FAST_PINIO
digitalWrite(_dc, LOW);
#endif // end !USE_FAST_PINIO
}
protected:
// A few more low-level member functions -- some may have previously
// been macros. Shouldn't have a need to access these externally, so
// they've been moved to the protected section. Additionally, they're
// declared inline here and the code is in the .cpp file, since outside
// code doesn't need to see these.
inline void SPI_MOSI_HIGH(void);
inline void SPI_MOSI_LOW(void);
inline void SPI_SCK_HIGH(void);
inline void SPI_SCK_LOW(void);
inline bool SPI_MISO_READ(void);
inline void SPI_BEGIN_TRANSACTION(void);
inline void SPI_END_TRANSACTION(void);
inline void TFT_WR_STROBE(void); // Parallel interface write strobe
inline void TFT_RD_HIGH(void); // Parallel interface read high
inline void TFT_RD_LOW(void); // Parallel interface read low
// CLASS INSTANCE VARIABLES --------------------------------------------
// Here be dragons! There's a big union of three structures here --
// one each for hardware SPI, software (bitbang) SPI, and parallel
// interfaces. This is to save some memory, since a display's connection
// will be only one of these. The order of some things is a little weird
// in an attempt to get values to align and pack better in RAM.
#if defined(USE_FAST_PINIO)
#if defined(HAS_PORT_SET_CLR)
PORTreg_t csPortSet; ///< PORT register for chip select SET
PORTreg_t csPortClr; ///< PORT register for chip select CLEAR
PORTreg_t dcPortSet; ///< PORT register for data/command SET
PORTreg_t dcPortClr; ///< PORT register for data/command CLEAR
#else // !HAS_PORT_SET_CLR
PORTreg_t csPort; ///< PORT register for chip select
PORTreg_t dcPort; ///< PORT register for data/command
#endif // end HAS_PORT_SET_CLR
#endif // end USE_FAST_PINIO
#if defined(__cplusplus) && (__cplusplus >= 201100)
union {
#endif
struct { // Values specific to HARDWARE SPI:
SPIClass *_spi; ///< SPI class pointer
#if defined(SPI_HAS_TRANSACTION)
SPISettings settings; ///< SPI transaction settings
#else
uint32_t _freq; ///< SPI bitrate (if no SPI transactions)
#endif
uint32_t _mode; ///< SPI data mode (transactions or no)
} hwspi; ///< Hardware SPI values
struct { // Values specific to SOFTWARE SPI:
#if defined(USE_FAST_PINIO)
PORTreg_t misoPort; ///< PORT (PIN) register for MISO
#if defined(HAS_PORT_SET_CLR)
PORTreg_t mosiPortSet; ///< PORT register for MOSI SET
PORTreg_t mosiPortClr; ///< PORT register for MOSI CLEAR
PORTreg_t sckPortSet; ///< PORT register for SCK SET
PORTreg_t sckPortClr; ///< PORT register for SCK CLEAR
#if !defined(KINETISK)
ADAGFX_PORT_t mosiPinMask; ///< Bitmask for MOSI
ADAGFX_PORT_t sckPinMask; ///< Bitmask for SCK
#endif // end !KINETISK
#else // !HAS_PORT_SET_CLR
PORTreg_t mosiPort; ///< PORT register for MOSI
PORTreg_t sckPort; ///< PORT register for SCK
ADAGFX_PORT_t mosiPinMaskSet; ///< Bitmask for MOSI SET (OR)
ADAGFX_PORT_t mosiPinMaskClr; ///< Bitmask for MOSI CLEAR (AND)
ADAGFX_PORT_t sckPinMaskSet; ///< Bitmask for SCK SET (OR bitmask)
ADAGFX_PORT_t sckPinMaskClr; ///< Bitmask for SCK CLEAR (AND)
#endif // end HAS_PORT_SET_CLR
#if !defined(KINETISK)
ADAGFX_PORT_t misoPinMask; ///< Bitmask for MISO
#endif // end !KINETISK
#endif // end USE_FAST_PINIO
int8_t _mosi; ///< MOSI pin #
int8_t _miso; ///< MISO pin #
int8_t _sck; ///< SCK pin #
} swspi; ///< Software SPI values
struct { // Values specific to 8-bit parallel:
#if defined(USE_FAST_PINIO)
#if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x
volatile uint32_t *writePort; ///< PORT register for DATA WRITE
volatile uint32_t *readPort; ///< PORT (PIN) register for DATA READ
#else
volatile uint8_t *writePort; ///< PORT register for DATA WRITE
volatile uint8_t *readPort; ///< PORT (PIN) register for DATA READ
#endif
#if defined(HAS_PORT_SET_CLR)
// Port direction register pointers are always 8-bit regardless of
// PORTreg_t -- even if 32-bit port, we modify a byte-aligned 8 bits.
#if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x
volatile uint32_t *dirSet; ///< PORT byte data direction SET
volatile uint32_t *dirClr; ///< PORT byte data direction CLEAR
#else
volatile uint8_t *dirSet; ///< PORT byte data direction SET
volatile uint8_t *dirClr; ///< PORT byte data direction CLEAR
#endif
PORTreg_t wrPortSet; ///< PORT register for write strobe SET
PORTreg_t wrPortClr; ///< PORT register for write strobe CLEAR
PORTreg_t rdPortSet; ///< PORT register for read strobe SET
PORTreg_t rdPortClr; ///< PORT register for read strobe CLEAR
#if !defined(KINETISK)
ADAGFX_PORT_t wrPinMask; ///< Bitmask for write strobe
#endif // end !KINETISK
ADAGFX_PORT_t rdPinMask; ///< Bitmask for read strobe
#else // !HAS_PORT_SET_CLR
// Port direction register pointer is always 8-bit regardless of
// PORTreg_t -- even if 32-bit port, we modify a byte-aligned 8 bits.
volatile uint8_t *portDir; ///< PORT direction register
PORTreg_t wrPort; ///< PORT register for write strobe
PORTreg_t rdPort; ///< PORT register for read strobe
ADAGFX_PORT_t wrPinMaskSet; ///< Bitmask for write strobe SET (OR)
ADAGFX_PORT_t wrPinMaskClr; ///< Bitmask for write strobe CLEAR (AND)
ADAGFX_PORT_t rdPinMaskSet; ///< Bitmask for read strobe SET (OR)
ADAGFX_PORT_t rdPinMaskClr; ///< Bitmask for read strobe CLEAR (AND)
#endif // end HAS_PORT_SET_CLR
#endif // end USE_FAST_PINIO
int8_t _d0; ///< Data pin 0 #
int8_t _wr; ///< Write strobe pin #
int8_t _rd; ///< Read strobe pin # (or -1)
bool wide = 0; ///< If true, is 16-bit interface
} tft8; ///< Parallel interface settings
#if defined(__cplusplus) && (__cplusplus >= 201100)
}; ///< Only one interface is active
#endif
#if defined(USE_SPI_DMA) // Used by hardware SPI and tft8
Adafruit_ZeroDMA dma; ///< DMA instance
DmacDescriptor *dptr = NULL; ///< 1st descriptor
DmacDescriptor *descriptor = NULL; ///< Allocated descriptor list
uint16_t *pixelBuf[2]; ///< Working buffers
uint16_t maxFillLen; ///< Max pixels per DMA xfer
uint16_t lastFillColor = 0; ///< Last color used w/fill
uint32_t lastFillLen = 0; ///< # of pixels w/last fill
uint8_t onePixelBuf; ///< For hi==lo fill
#endif
#if defined(USE_FAST_PINIO)
#if defined(HAS_PORT_SET_CLR)
#if !defined(KINETISK)
ADAGFX_PORT_t csPinMask; ///< Bitmask for chip select
ADAGFX_PORT_t dcPinMask; ///< Bitmask for data/command
#endif // end !KINETISK
#else // !HAS_PORT_SET_CLR
ADAGFX_PORT_t csPinMaskSet; ///< Bitmask for chip select SET (OR)
ADAGFX_PORT_t csPinMaskClr; ///< Bitmask for chip select CLEAR (AND)
ADAGFX_PORT_t dcPinMaskSet; ///< Bitmask for data/command SET (OR)
ADAGFX_PORT_t dcPinMaskClr; ///< Bitmask for data/command CLEAR (AND)
#endif // end HAS_PORT_SET_CLR
#endif // end USE_FAST_PINIO
uint8_t connection; ///< TFT_HARD_SPI, TFT_SOFT_SPI, etc.
int8_t _rst; ///< Reset pin # (or -1)
int8_t _cs; ///< Chip select pin # (or -1)
int8_t _dc; ///< Data/command pin #
int16_t _xstart = 0; ///< Internal framebuffer X offset
int16_t _ystart = 0; ///< Internal framebuffer Y offset
uint8_t invertOnCommand = 0; ///< Command to enable invert mode
uint8_t invertOffCommand = 0; ///< Command to disable invert mode
uint32_t _freq = 0; ///< Dummy var to keep subclasses happy
};
#endif // end __AVR_ATtiny85__
#endif // end _ADAFRUIT_SPITFT_H_

View File

@ -0,0 +1,6 @@
// THIS FILE INTENTIONALLY LEFT BLANK.
// Macros previously #defined here have been made into (mostly) inline
// functions in the Adafruit_SPITFT class. Other libraries might still
// contain code trying to #include this header file, so until everything's
// updated this file still exists (but doing nothing) to avoid trouble.

View File

@ -1,4 +1,4 @@
# Adafruit GFX Library # [![Build Status](https://travis-ci.org/adafruit/Adafruit_GFX.svg?branch=master)](https://travis-ci.org/adafruit/Adafruit_GFX)
# Adafruit GFX Library [![Build Status](https://travis-ci.com/adafruit/Adafruit-GFX-Library.svg?branch=master)](https://travis-ci.com/adafruit/Adafruit-GFX-Library)
This is the core graphics library for all our displays, providing a common set of graphics primitives (points, lines, circles, etc.). It needs to be paired with a hardware-specific library for each display device we carry (to handle the lower-level functions).

View File

@ -362,4 +362,4 @@ unsigned long testFilledRoundRects() {
}
return micros() - start;
}
}

View File

@ -16,12 +16,14 @@ Keep 7-bit fonts around as an option in that case, more compact.
See notes at end for glyph nomenclature & other tidbits.
*/
#ifndef ARDUINO
#include <stdio.h>
#include <ctype.h>
#include <stdint.h>
#include <ft2build.h>
#include FT_GLYPH_H
#include FT_TRUETYPE_DRIVER_H
#include "../gfxfont.h" // Adafruit_GFX font structures
#define DPI 141 // Approximate res. of Adafruit 2.8" TFT
@ -116,6 +118,16 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "FreeType init error: %d", err);
return err;
}
// Use TrueType engine version 35, without subpixel rendering.
// This improves clarity of fonts since this library does not
// support rendering multiple levels of gray in a glyph.
// See https://github.com/adafruit/Adafruit-GFX-Library/issues/103
FT_UInt interpreter_version = TT_INTERPRETER_VERSION_35;
FT_Property_Set( library, "truetype",
"interpreter-version",
&interpreter_version );
if((err = FT_New_Face(library, argv[1], 0, &face))) {
fprintf(stderr, "Font load error: %d", err);
FT_Done_FreeType(library);
@ -282,3 +294,5 @@ the cursor on the X axis after drawing the corresponding symbol.
There's also some changes with regard to 'background' color and new GFX
fonts (classic fonts unchanged). See Adafruit_GFX.cpp for explanation.
*/
#endif /* !ARDUINO */

View File

@ -9,6 +9,10 @@
#include <avr/pgmspace.h>
#elif defined(ESP8266)
#include <pgmspace.h>
#elif defined(__IMXRT1052__) || defined(__IMXRT1062__)
// PROGMEM is defefind for T4 to place data in specific memory section
#undef PROGMEM
#define PROGMEM
#else
#define PROGMEM
#endif

View File

@ -1,5 +1,5 @@
name=Adafruit GFX Library
version=1.2.9
version=1.5.6
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from.

View File

@ -0,0 +1,286 @@
/***************************************************
This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865
Designed specifically to work with the Adafruit RTD Sensor
----> https://www.adafruit.com/products/3328
This sensor uses SPI to communicate, 4 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include "Adafruit_MAX31865.h"
#ifdef __AVR
#include <avr/pgmspace.h>
#elif defined(ESP8266)
#include <pgmspace.h>
#endif
#include <stdlib.h>
#include <SPI.h>
static SPISettings max31865_spisettings = SPISettings(500000, MSBFIRST, SPI_MODE1);
// Software (bitbang) SPI
Adafruit_MAX31865::Adafruit_MAX31865(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso, int8_t spi_clk) {
setPins( spi_cs, spi_mosi, spi_miso, spi_clk);
}
void Adafruit_MAX31865::setPins(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso, int8_t spi_clk) {
_sclk = spi_clk;
_cs = spi_cs;
_miso = spi_miso;
_mosi = spi_mosi;
}
// Hardware SPI init
Adafruit_MAX31865::Adafruit_MAX31865(int8_t spi_cs) {
_cs = spi_cs;
_sclk = _miso = _mosi = -1;
}
// Default constructor
Adafruit_MAX31865::Adafruit_MAX31865(void) {
_cs = _sclk = _miso = _mosi = -1;
}
boolean Adafruit_MAX31865::begin(max31865_numwires_t wires) {
pinMode(_cs, OUTPUT);
digitalWrite(_cs, HIGH);
if (_sclk != -1) {
//define pin modes
pinMode(_sclk, OUTPUT);
digitalWrite(_sclk, LOW);
pinMode(_mosi, OUTPUT);
pinMode(_miso, INPUT);
} else {
//start and configure hardware SPI
SPI.begin();
}
for (uint8_t i=0; i<16; i++) {
// readRegister8(i);
}
setWires(wires);
enableBias(false);
autoConvert(false);
clearFault();
//Serial.print("config: "); Serial.println(readRegister8(MAX31856_CONFIG_REG), HEX);
return true;
}
uint8_t Adafruit_MAX31865::readFault(void) {
return readRegister8(MAX31856_FAULTSTAT_REG);
}
void Adafruit_MAX31865::clearFault(void) {
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
t &= ~0x2C;
t |= MAX31856_CONFIG_FAULTSTAT;
writeRegister8(MAX31856_CONFIG_REG, t);
}
void Adafruit_MAX31865::enableBias(boolean b) {
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
if (b) {
t |= MAX31856_CONFIG_BIAS; // enable bias
} else {
t &= ~MAX31856_CONFIG_BIAS; // disable bias
}
writeRegister8(MAX31856_CONFIG_REG, t);
}
void Adafruit_MAX31865::autoConvert(boolean b) {
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
if (b) {
t |= MAX31856_CONFIG_MODEAUTO; // enable autoconvert
} else {
t &= ~MAX31856_CONFIG_MODEAUTO; // disable autoconvert
}
writeRegister8(MAX31856_CONFIG_REG, t);
}
void Adafruit_MAX31865::setWires(max31865_numwires_t wires ) {
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
if (wires == MAX31865_3WIRE) {
t |= MAX31856_CONFIG_3WIRE;
} else {
// 2 or 4 wire
t &= ~MAX31856_CONFIG_3WIRE;
}
writeRegister8(MAX31856_CONFIG_REG, t);
}
float Adafruit_MAX31865::rtd_to_temperature(uint16_t rtd, float RTDnominal, float refResistor) {
//float Adafruit_MAX31865::temperature(float RTDnominal, float refResistor) {
// http://www.analog.com/media/en/technical-documentation/application-notes/AN709_0.pdf
float Z1, Z2, Z3, Z4, Rt, temp;
Rt = rtd;
Rt /= 32768;
Rt *= refResistor;
// Serial.print("\nResistance: "); Serial.println(Rt, 8);
Z1 = -RTD_A;
Z2 = RTD_A * RTD_A - (4 * RTD_B);
Z3 = (4 * RTD_B) / RTDnominal;
Z4 = 2 * RTD_B;
temp = Z2 + (Z3 * Rt);
temp = (sqrt(temp) + Z1) / Z4;
if (temp >= 0) return temp;
// ugh.
Rt /= RTDnominal;
Rt *= 100; // normalize to 100 ohm
float rpoly = Rt;
temp = -242.02;
temp += 2.2228 * rpoly;
rpoly *= Rt; // square
temp += 2.5859e-3 * rpoly;
rpoly *= Rt; // ^3
temp -= 4.8260e-6 * rpoly;
rpoly *= Rt; // ^4
temp -= 2.8183e-8 * rpoly;
rpoly *= Rt; // ^5
temp += 1.5243e-10 * rpoly;
return temp;
}
float Adafruit_MAX31865::rtd_to_resistance(uint16_t rtd, float refResistor) {
float Rt;
Rt = rtd;
Rt /= 32768;
Rt *= refResistor;
return Rt;
}
float Adafruit_MAX31865::temperature(float RTDnominal, float refResistor) {
uint16_t rtd = readRTD();
return rtd_to_temperature(rtd, RTDnominal, refResistor);
}
uint16_t Adafruit_MAX31865::readRTD (void) {
clearFault();
enableBias(true);
delay(10);
uint8_t t = readRegister8(MAX31856_CONFIG_REG);
t |= MAX31856_CONFIG_1SHOT;
writeRegister8(MAX31856_CONFIG_REG, t);
delay(65);
uint16_t rtd = readRegister16(MAX31856_RTDMSB_REG);
// remove fault
rtd >>= 1;
return rtd;
}
/**********************************************/
uint8_t Adafruit_MAX31865::readRegister8(uint8_t addr) {
uint8_t ret = 0;
readRegisterN(addr, &ret, 1);
return ret;
}
uint16_t Adafruit_MAX31865::readRegister16(uint8_t addr) {
uint8_t buffer[2] = {0, 0};
readRegisterN(addr, buffer, 2);
uint16_t ret = buffer[0];
ret <<= 8;
ret |= buffer[1];
return ret;
}
void Adafruit_MAX31865::readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n) {
addr &= 0x7F; // make sure top bit is not set
if (_sclk == -1)
SPI.beginTransaction(max31865_spisettings);
else
digitalWrite(_sclk, LOW);
digitalWrite(_cs, LOW);
spixfer(addr);
//Serial.print("$"); Serial.print(addr, HEX); Serial.print(": ");
while (n--) {
buffer[0] = spixfer(0xFF);
//Serial.print(" 0x"); Serial.print(buffer[0], HEX);
buffer++;
}
//Serial.println();
if (_sclk == -1)
SPI.endTransaction();
digitalWrite(_cs, HIGH);
}
void Adafruit_MAX31865::writeRegister8(uint8_t addr, uint8_t data) {
if (_sclk == -1)
SPI.beginTransaction(max31865_spisettings);
else
digitalWrite(_sclk, LOW);
digitalWrite(_cs, LOW);
spixfer(addr | 0x80); // make sure top bit is set
spixfer(data);
//Serial.print("$"); Serial.print(addr, HEX); Serial.print(" = 0x"); Serial.println(data, HEX);
if (_sclk == -1)
SPI.endTransaction();
digitalWrite(_cs, HIGH);
}
uint8_t Adafruit_MAX31865::spixfer(uint8_t x) {
if (_sclk == -1)
return SPI.transfer(x);
// software spi
//Serial.println("Software SPI");
uint8_t reply = 0;
for (int i=7; i>=0; i--) {
reply <<= 1;
digitalWrite(_sclk, HIGH);
digitalWrite(_mosi, x & (1<<i));
digitalWrite(_sclk, LOW);
if (digitalRead(_miso))
reply |= 1;
}
return reply;
}

View File

@ -0,0 +1,99 @@
/***************************************************
This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865
Designed specifically to work with the Adafruit RTD Sensor
----> https://www.adafruit.com/products/3328
This sensor uses SPI to communicate, 4 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#ifndef ADAFRUIT_MAX31865_H
#define ADAFRUIT_MAX31865_H
#define MAX31856_CONFIG_REG 0x00
#define MAX31856_CONFIG_BIAS 0x80
#define MAX31856_CONFIG_MODEAUTO 0x40
#define MAX31856_CONFIG_MODEOFF 0x00
#define MAX31856_CONFIG_1SHOT 0x20
#define MAX31856_CONFIG_3WIRE 0x10
#define MAX31856_CONFIG_24WIRE 0x00
#define MAX31856_CONFIG_FAULTSTAT 0x02
#define MAX31856_CONFIG_FILT50HZ 0x01
#define MAX31856_CONFIG_FILT60HZ 0x00
#define MAX31856_RTDMSB_REG 0x01
#define MAX31856_RTDLSB_REG 0x02
#define MAX31856_HFAULTMSB_REG 0x03
#define MAX31856_HFAULTLSB_REG 0x04
#define MAX31856_LFAULTMSB_REG 0x05
#define MAX31856_LFAULTLSB_REG 0x06
#define MAX31856_FAULTSTAT_REG 0x07
#define MAX31865_FAULT_HIGHTHRESH 0x80
#define MAX31865_FAULT_LOWTHRESH 0x40
#define MAX31865_FAULT_REFINLOW 0x20
#define MAX31865_FAULT_REFINHIGH 0x10
#define MAX31865_FAULT_RTDINLOW 0x08
#define MAX31865_FAULT_OVUV 0x04
#define RTD_A 3.9083e-3
#define RTD_B -5.775e-7
#if (ARDUINO >= 100)
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
typedef enum max31865_numwires {
MAX31865_2WIRE = 0,
MAX31865_3WIRE = 1,
MAX31865_4WIRE = 0
} max31865_numwires_t;
class Adafruit_MAX31865 {
public:
Adafruit_MAX31865(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso, int8_t spi_clk);
Adafruit_MAX31865(int8_t spi_cs);
Adafruit_MAX31865(void);
void setPins(int8_t spi_cs, int8_t spi_mosi, int8_t spi_miso, int8_t spi_clk);
boolean begin(max31865_numwires_t x = MAX31865_2WIRE);
uint8_t readFault(void);
void clearFault(void);
uint16_t readRTD();
void setWires(max31865_numwires_t wires);
void autoConvert(boolean b);
void enableBias(boolean b);
float temperature(float RTDnominal, float refResistor);
float rtd_to_temperature(uint16_t rtd, float RTDnominal, float refResistor);
float rtd_to_resistance(uint16_t rtd, float refResistor);
private:
int8_t _sclk, _miso, _mosi, _cs;
void readRegisterN(uint8_t addr, uint8_t buffer[], uint8_t n);
uint8_t readRegister8(uint8_t addr);
uint16_t readRegister16(uint8_t addr);
void writeRegister8(uint8_t addr, uint8_t reg);
uint8_t spixfer(uint8_t addr);
};
#endif

View File

@ -0,0 +1,2 @@
# Adafruit_MAX31865
Arduino Library for Adafruit MAX31865 RTD Sensor

View File

@ -0,0 +1,16 @@
This is the Adafruit MAX31856 Arduino Library
Tested and works great with the Adafruit Thermocouple Breakout w/MAX31856
* http://www.adafruit.com/products/3328
These sensors use SPI to communicate, 4 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above must be included in any redistribution

View File

@ -0,0 +1,74 @@
/***************************************************
This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865
Designed specifically to work with the Adafruit RTD Sensor
----> https://www.adafruit.com/products/3328
This sensor uses SPI to communicate, 4 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Adafruit_MAX31865.h>
// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 max = Adafruit_MAX31865(10, 11, 12, 13);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 max = Adafruit_MAX31865(10);
// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RREF 430.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100, 1000.0 for PT1000
#define RNOMINAL 100.0
void setup() {
Serial.begin(115200);
Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
max.begin(MAX31865_3WIRE); // set to 2WIRE or 4WIRE as necessary
}
void loop() {
uint16_t rtd = max.readRTD();
Serial.print("RTD value: "); Serial.println(rtd);
float ratio = rtd;
ratio /= 32768;
Serial.print("Ratio = "); Serial.println(ratio,8);
Serial.print("Resistance = "); Serial.println(RREF*ratio,8);
Serial.print("Temperature = "); Serial.println(max.temperature(RNOMINAL, RREF));
// Check and print any faults
uint8_t fault = max.readFault();
if (fault) {
Serial.print("Fault 0x"); Serial.println(fault, HEX);
if (fault & MAX31865_FAULT_HIGHTHRESH) {
Serial.println("RTD High Threshold");
}
if (fault & MAX31865_FAULT_LOWTHRESH) {
Serial.println("RTD Low Threshold");
}
if (fault & MAX31865_FAULT_REFINLOW) {
Serial.println("REFIN- > 0.85 x Bias");
}
if (fault & MAX31865_FAULT_REFINHIGH) {
Serial.println("REFIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865_FAULT_RTDINLOW) {
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open");
}
if (fault & MAX31865_FAULT_OVUV) {
Serial.println("Under/Over voltage");
}
max.clearFault();
}
Serial.println();
delay(1000);
}

View File

@ -0,0 +1,9 @@
name=Adafruit MAX31865 library
version=1.0.1
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Library for the Adafruit RTD Amplifier breakout with MAX31865
paragraph=Library for the Adafruit RTD Amplifier breakout with MAX31865
category=Sensors
url=https://github.com/adafruit/Adafruit_MAX31865
architectures=*

View File

View File

@ -37,7 +37,7 @@
//#define I2C_DEBUG
/**************************************************************************/
/*!
/*!
@brief Instantiates a new SGP30 class
*/
/**************************************************************************/
@ -45,7 +45,7 @@ Adafruit_SGP30::Adafruit_SGP30() {
}
/**************************************************************************/
/*!
/*!
@brief Setups the hardware and detects a valid SGP30. Initializes I2C
then reads the serialnumber and checks that we are talking to an SGP30
@param theWire Optional pointer to I2C interface, otherwise use Wire
@ -60,31 +60,32 @@ boolean Adafruit_SGP30::begin(TwoWire *theWire) {
_i2c = theWire;
}
_i2c->begin();
// assume i2c initialized already to avoid resetting clock stretching
// _i2c->begin();
uint8_t command[2];
command[0] = 0x36;
command[1] = 0x82;
if (! readWordFromCommand(command, 2, 10, serialnumber, 3))
if (! readWordFromCommand(command, 2, 10, serialnumber, 3))
return false;
uint16_t featureset;
command[0] = 0x20;
command[1] = 0x2F;
if (! readWordFromCommand(command, 2, 10, &featureset, 1))
if (! readWordFromCommand(command, 2, 10, &featureset, 1))
return false;
//Serial.print("Featureset 0x"); Serial.println(featureset, HEX);
if (featureset != SGP30_FEATURESET)
if (featureset != SGP30_FEATURESET)
return false;
if (! IAQinit())
if (! IAQinit())
return false;
return true;
}
/**************************************************************************/
/*!
/*!
@brief Commands the sensor to begin the IAQ algorithm. Must be called after startup.
@returns True if command completed successfully, false if something went wrong!
*/
@ -97,7 +98,7 @@ boolean Adafruit_SGP30::IAQinit(void) {
}
/**************************************************************************/
/*!
/*!
@brief Commands the sensor to take a single eCO2/VOC measurement. Places results in {@link TVOC} and {@link eCO2}
@returns True if command completed successfully, false if something went wrong!
*/
@ -113,9 +114,9 @@ boolean Adafruit_SGP30::IAQmeasure(void) {
eCO2 = reply[0];
return true;
}
/**************************************************************************/
/*!
/*!
@brief Request baseline calibration values for both CO2 and TVOC IAQ calculations. Places results in parameter memory locaitons.
@param eco2_base A pointer to a uint16_t which we will save the calibration value to
@param tvoc_base A pointer to a uint16_t which we will save the calibration value to
@ -135,7 +136,7 @@ boolean Adafruit_SGP30::getIAQBaseline(uint16_t *eco2_base, uint16_t *tvoc_base)
}
/**************************************************************************/
/*!
/*!
@brief Assign baseline calibration values for both CO2 and TVOC IAQ calculations.
@param eco2_base A uint16_t which we will save the calibration value from
@param tvoc_base A uint16_t which we will save the calibration value from
@ -157,7 +158,30 @@ boolean Adafruit_SGP30::setIAQBaseline(uint16_t eco2_base, uint16_t tvoc_base) {
}
/**************************************************************************/
/*!
/*!
@brief Set the absolute humidity value [mg/m^3] for compensation to increase precision of TVOC and eCO2.
@param absolute_humidity A uint32_t [mg/m^3] which we will be used for compensation. If the absolute humidity is set to zero, humidity compensation will be disabled.
@returns True if command completed successfully, false if something went wrong!
*/
/**************************************************************************/
boolean Adafruit_SGP30::setHumidity(uint32_t absolute_humidity) {
if (absolute_humidity > 256000) {
return false;
}
uint16_t ah_scaled = (uint16_t)(((uint64_t)absolute_humidity * 256 * 16777) >> 24);
uint8_t command[5];
command[0] = 0x20;
command[1] = 0x61;
command[2] = ah_scaled >> 8;
command[3] = ah_scaled & 0xFF;
command[4] = generateCRC(command+2, 2);
return readWordFromCommand(command, 5, 10);
}
/**************************************************************************/
/*!
@brief I2C low level interfacing
*/
/**************************************************************************/
@ -186,16 +210,16 @@ boolean Adafruit_SGP30::readWordFromCommand(uint8_t command[], uint8_t commandLe
delay(delayms);
if (readlen == 0)
if (readlen == 0)
return true;
uint8_t replylen = readlen * (SGP30_WORD_LEN +1);
if (_i2c->requestFrom(_i2caddr, replylen) != replylen)
if (_i2c->requestFrom(_i2caddr, replylen) != replylen)
return false;
uint8_t replybuffer[replylen];
#ifdef I2C_DEBUG
Serial.print("\t\t<- ");
#endif
#endif
for (uint8_t i=0; i<replylen; i++) {
replybuffer[i] = _i2c->read();
#ifdef I2C_DEBUG

View File

@ -42,6 +42,7 @@ class Adafruit_SGP30 {
boolean getIAQBaseline(uint16_t *eco2_base, uint16_t *tvoc_base);
boolean setIAQBaseline(uint16_t eco2_base, uint16_t tvoc_base);
boolean setHumidity(uint32_t absolute_humidity);
/**
* The last measurement of the IAQ-calculated Total Volatile Organic Compounds in ppb. This value is set when you call {@link IAQmeasure()}

Some files were not shown because too many files have changed in this diff Show More