Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • flow3r/flow3r-firmware
  • Vespasian/flow3r-firmware
  • alxndr42/flow3r-firmware
  • pl/flow3r-firmware
  • Kari/flow3r-firmware
  • raimue/flow3r-firmware
  • grandchild/flow3r-firmware
  • mu5tach3/flow3r-firmware
  • Nervengift/flow3r-firmware
  • arachnist/flow3r-firmware
  • TheNewCivilian/flow3r-firmware
  • alibi/flow3r-firmware
  • manuel_v/flow3r-firmware
  • xeniter/flow3r-firmware
  • maxbachmann/flow3r-firmware
  • yGifoom/flow3r-firmware
  • istobic/flow3r-firmware
  • EiNSTeiN_/flow3r-firmware
  • gnudalf/flow3r-firmware
  • 999eagle/flow3r-firmware
  • toerb/flow3r-firmware
  • pandark/flow3r-firmware
  • teal/flow3r-firmware
  • x42/flow3r-firmware
  • alufers/flow3r-firmware
  • dos/flow3r-firmware
  • yrlf/flow3r-firmware
  • LuKaRo/flow3r-firmware
  • ThomasElRubio/flow3r-firmware
  • ai/flow3r-firmware
  • T_X/flow3r-firmware
  • highTower/flow3r-firmware
  • beanieboi/flow3r-firmware
  • Woazboat/flow3r-firmware
  • gooniesbro/flow3r-firmware
  • marvino/flow3r-firmware
  • kressnerd/flow3r-firmware
  • quazgar/flow3r-firmware
  • aoid/flow3r-firmware
  • jkj/flow3r-firmware
  • naomi/flow3r-firmware
41 results
Show changes
Commits on Source (1502)
Showing with 1265 additions and 1074 deletions
---
BasedOnStyle: Google
IndentWidth: 4
IncludeBlocks: Preserve
Cpp11BracedListStyle: false
# Don't care about deprecated APIs (noisy) and about memcpy/strcpy (we'll fix
# that later).
Checks: '-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,-clang-diagnostic-deprecated-declarations'
# esp-idf
sdkconfig.old
sdkconfig
dependencies.lock
build
.sdkconfig.defaults.generated
# micropython
__pycache__
# editor crud
.vscode
*swp
*~
# Python
.venv
/venv/
# sphinx
docs/_build/
/tools/mypy.sh
# bl00mbox docs
components/bl00mbox/docs/
components/bl00mbox/public/
stages:
- check
- build
- deploy
variables:
GIT_SUBMODULE_STRATEGY: recursive
GIT_DEPTH: 0
default:
# built via:
# docker load < $(nix-build nix/docker-image.nix)
image: registry.gitlab.com/flow3r-badge/flow3r-build:238576xsg79mjr2bkqg106qisvd3b5q9
clang-tidy:
stage: check
script:
- "bash tools/clang-tidy.sh"
- "python3 tools/codequal-report.py clang-tidy warnings.txt > cqual.json"
artifacts:
when: always
reports:
codequality: cqual.json
format:
stage: check
script:
- "git clean -fdx"
- "bash tools/format.sh"
- "[ -z \"$(git status --porcelain)\" ] || (echo 'Differences found, please run tools/format.sh.' && git diff HEAD && exit 1)"
build:
stage: build
script:
- idf.py -g c23 build size
artifacts:
expose_as: 'firmware'
paths: ['build/flow3r.bin']
expire_in: 5 hours
build_recovery:
stage: build
script:
- cd recovery
- idf.py build size
artifacts:
expose_as: 'Recovery'
paths: ['recovery/build/flow3r-recovery.bin', 'recovery/build/partition_table/partition-table.bin', 'recovery/build/bootloader/bootloader.bin']
expire_in: 5 hours
simulate:
stage: build
script:
- python3 sim/run.py --screenshot
artifacts:
expose_as: 'Simulator Screenshot'
paths: ['flow3r.png']
expire_in: 5 hours
pages:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == "main"
script:
- git tag | xargs git tag -d
- git checkout origin/main
- git checkout -b dev
- git branch --all
- git branch --all | sed -e 's/..//' | grep '^remotes/origin/release/' | while read b; do git checkout -b "v${b#remotes/origin/release/}" "$b"; done
- git checkout dev
- git branch
- mkdir public
- cd docs
- make versionedhtml
- cp -r _build/$(git branch --sort=version:refname | tail -n1 | sed -e 's/..//')/* _build/
- python redirects.py
- cp -r _build/* ../public/
- find ../public/
artifacts:
paths: ['public']
expire_in: 1d
dist:
stage: deploy
variables:
# Force a full clone to make version machinery work.
GIT_STRATEGY: clone
rules:
- if: $CI_COMMIT_TAG
script:
- bash tools/dist.sh
artifacts:
paths: ['dist']
[submodule "lib/berkeley-db-1.xx"]
path = micropython/lib/berkeley-db-1.xx
path = components/micropython/vendor/lib/berkeley-db-1.xx
url = https://github.com/pfalcon/berkeley-db-1.xx
[submodule "lib/micropython-lib"]
path = micropython/lib/micropython-lib
path = components/micropython/vendor/lib/micropython-lib
url = https://github.com/micropython/micropython-lib.git
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
## [1.4.0] - 2024-12-24
### Summary
- documentation reworked and expanded
- primary context menu: can be opened at any time to view help texts, open the audio mixer or force-exit an application.
- help viewer: applications can provide context-sensitive help texts to make it easier to figure them out and reduce
the load on appilcation writers to explain everything on a small screen.
- audio mixer: set levels of bl00mbox channels and mute/unmute them. Muted channels don't use CPU.
- secondary context menu: can be opened in an application menu to delete apps, set them as autostart or mark them as
favorite to sort them to the top of menus
- new preloaded apps: violin, wobbler, mp3 player
- major rework of captouch driver features
- added `st3m.ui.widgets` module for easier app integration of user inputs (for example, captouch gestures)
- bl00mbox can now run channel-specific micropython callbacks whenever the channel is rendered, allowing
for much more flexible backgrounded music applications
### Added
- system: unregistered apps are marked as "new"
- system: new category "Demos" for things that focus on being technical examples rather than being use case oriented
- gdb: micropython REPL available while debugging
- micropython: added `indent` keyword to `json.dumps`/`json.dump`
- apps: added overrides for OS button
- apps: added `get_help()` method to provide context sensitive help texts to users
- settings: Touch UI (default off) activates preview for captouch menu navigation
- media: support for more (most) mp3 tag types
- gr33nhouse: sort by application type
- captouch: no more silent captouch calibration, driver saves persistent calibration file and guides user through manual
calibration when none is found.
- captouch: petals can be turned off run with reduced output to increase data rate
- captouch: unfiltered data log is accessible
- captouch: added `PetalLog` helper class for data processing
- bl00mbox: added .delete() method for various objects, added destructors for better garbabe collection behavior
- bl00mbox: added RMS volume collection option and provide volume normalization guidelines in flo3r docs
### Changed
- settings: "Enable WiFi on Boot" option is now "Always-On Wi-Fi" (but is functionally identical), should help reduce confusion about Wi-Fi turning off automatically
- captouch: normalized positional output in new `.pos`/`.raw_pos` attributes, deprecated old `.position` API
- captouch: normalized raw capacitance output in new `.raw_cap` attribute, deprecated old `.pressure` API
- captouch: removed all abstractions that indicate petal pads without replacement,
i.e. `InputController.petals[x].ccw` or `InputState.petals[x].raw`
### Fixed
- updat3r: Improved version comparison logic, making the "you are up to date :)" logic work
- captouch: petal 5 fully functional
- bl00mbox: a whole lot of bugs and performance issues (but not all :P)
## [1.3.0] - 2023-11-26
### Summary
- Wifi connection UI
- Media framework
- SD card works reliably
- Performance improvements
- Backend improvements
- Wider micropython API
- Improved preloaded applications
- ...and many bugfixes!
### Added
- Added the `Audio Passthrough` app for toggling audio passthrough through
line-in/mic to speaker or lineout.
- Added the `w1f1` app for managing wifi access to Settings, incorporates
an in-progress cap-touch multi-tap keyboard (`k3yboard`).
- Added the `Scalar` app in `Music` category for playing scales.
- Added the `Mandelbrot` app, which illustrates how one can do direct
framebuffer access and control 8bpp palettized modes from python.
- Added configuration of audio adjustments and startup dB level to `settings.json`.
- Added configuration of wifi credentials + hostname via `settings.json`
- Added support for apps to set wifi state automatically (configurable in
settings: `Let apps change WiFi`)
- Added task profiler which prints over serial (configurable in
settings: `Debug: ftop`)
- Added an error screen to the `Nick` app when `nick.json` is invalid.
- Added `urequests` and `uos` support in the simulator.
- Added audio/video media framework, and `Wurzelitzer` app as a small jukebox
frontend - currently supporting mp3 audio, mpeg1 video, GIF and protracker
.mod files.
- Added exporting of built firmwares as part of CI.
- Added basic implementation of `os.statvfs()` to fetch full/available
disk space on flash and SD.
- Added `set_position` and `scroll_to` methods to `ScrollController`
- graphics: sprite sheet support for `ctx.image()`
- graphics: `ctx.parse()` for parsing SVG-path-data/ctx-protocol.
- graphics: 1,2,4,8,16,24 and 32 bits-per-pixel graphics modes.
- graphics: direct framebuffer access.
- graphics: palette setting in 1,2,4 and 8bpp graphics modes.
- graphics: flags for 2x 3x and 4x pixel doubling, low-latency and direct-ctx modes.
- graphics: experimental smart redraw mode
- graphics: clipped and composited overlay buffer
- graphics: allow a graphics state depth of up to 10 (`ctx.save()` `ctx.restore()`)
- graphics: virtual framebuffer with scrolling
- battery: Main menu shows a charge percentage estimate based on real battery characterization
- Added basic media playback in the `fil3s` app.
- Added a delete button to `fil3s`/Files app to allow for deleting files,
folders and apps on-device.
- Added new menu categories, `Media` and `Games`, and made category handling more robust
to correctly handle introducing new categories in the future.
- Added configuration UI for audio, appearance and graphics settings.
- Added configurable LED patterns for the main menu.
- Added "restore defaults" option in the settings menu.
- Added wah modulation in `Otamatone`.
- Added several API functions for `ViewManager` to make complex view handling in apps
easier and robust.
- Added firmware update app, `updat3r`.
- Added storage information in `About` app.
- Added audio equalization for built-in speakers.
- Added a function to retrieve scope data for manual drawing/processing.
- Added I2C scanner app.
- Added sensor demo app.
- Added `CONFIG_DEBUG_GDB_ENABLED` flag for easy debugging over USB JTAG.
- Added saving/restoring state to several apps.
- Added variable sequence length support in `gay drums`.
### Changed
- Changed the st3m\_tar logic to only update files on flash after an update
if they've been changed, greatly improving start times after an update.
- Flashing flow3r through idf.py now automatically restarts it.
- Switched the REPL/fatal/disk restart button to the OS shoulder button (right
shoulder button, unless swapped in settings).
- Improved performance of the `gr33nhouse` app list by not rendering hidden
entries and scrolling ones too long to fit on screen.
- Changed the audio adjustment logic, and added support for holding down the
shoulder to keep increasing/decreasing level.
- Improved download reliability of the `gr33nhouse` app by adding chunked
downloads, some `gc.collect()` calls, progress bar and an error screen.
- Settings are now automatically loaded and saved when entering and leaving
the settings page.
- Moved the `Clouds` app to the `Badge` menu and updated it to use IMU data.
- Added a more sane commandline interface to the simulator.
- More stub functions for the simulator.
- Improved performance of system menus by not rendering hidden entries.
- Added visualization of state, instead of an audio scope in UI of `harmonic
demo` and `melodic demo`.
- The system provided scope is now always stroked.
- Improved BPM tap accuracy in `gay drums`.
- Some shell code rewritten to avoid the expensive calls `ctx.start_group()` and
`ctx.end_group()`.
- Overlay graphics gets rendered to a separate framebuffer, of which a clipped rectangle
is composited during scan-out. The python overlay code has been adapted to keep track
of which parts of overlay need refresh.
- Slightly lower AA quality; for a 3x performance boost in the
worst-case scanline rasterization code path.
- The entry section in `flow3r.toml` can now be omitted if the Application
class is called `App`.
- disabled support for compositing group API in ctx, where used global\_alpha on
its own did was responsible for it seeming to work.
- Split the `settings.py` file into two, creating `settings_menu.py` to hold
UI-related code and allow `settings` to be used import loops without
in many cases.
- When running apps through REPL mode (with `mpremote` etc), multi-view apps
are now properly handled and don't restart whenever OS shoulder is pressed.
- A multitude of built-in apps now scroll names to fit the screen.
- Apps are now sorted and deduplicated by display name, not by folder name.
- Improved handedness in buttons.
- `harmonic demo` turned into a fully-featured `chord organ`
- `menu` key in `flow3r.toml` has been replaced with `category`. The old key can still
be used to maintain backwards compatibility with older firmwares.
- Backported recent improvements for micropython's garbage collection to make it faster.
- `shoegaze` can now use chords configured in `chord organ`.
- Changed the priority of additional threads spawned by micropython to be equal to its
main thread's priority.
- Apps that require Wi-Fi connection can directly take the user to Wi-Fi settings.
- Changed the default app installation directory on flash to `/flash/apps`.
- `gr33nhouse` now installs apps on SD card if available.
- Increased the frequency of LED animations.
- Changed the way LED colors are blended when using slew rates lower than 255 to be
more in line with color perception.
- Rearranged system menu.
- Made system indicator icons bigger.
- Removed CCCamp's Wi-Fi settings from the default config.
- Made InputState and parts of InputController lazily evaluated.
- bl00mbox: allow circular signal dependencies
- bl00mbox: several plugins and patches deprecated and replaced with updated
versions, see https://gitlab.com/moon2embeddedaudio/bl00mbox/-/blob/main/README.md
### Fixed
- Fixed `tiny sampler` keeping the microphone active after app exit.
- Fixed missing `include/` dir on builds on Darwin.
- Fixed the `time` module in the simulator being broken for apps trying to use it.
- Fixed wrong petal ordering in the simulator.
- Fixed simulator not exiting when closed.
- Fixed `Comic Mono` missing in the simulator.
- Fixed initialization orientation of display and transform initialization for
ctx contexts, (this enables arbitrary transformations to images and gradients.)
- Fixed broken anti-aliasing for compressed side of curved strokes.
- Fixed cleanup at exit for firmware apps
- Fixed sampler start bug in bl00mbox
- Fixed reset of graphics subsystem upon entering REPL / using mpremote.
- Fixed multitude of issues with transition animations.
- Fixed lost captouch and button presses when they're shorter than a think cycle.
- Fixed `ScrollController`'s handling of high delta values.
- Fixed many crashes in `fil3s` app.
- Fixed a crash in `CapScrollController`.
- Fixed gamma LUT setting for LEDs.
- Fixed bl00mbox channels leaking on micropython's soft reboot.
- Fixed importing bl00mbox's fake stub in the simulator.
- Performance fixes for bl00mbox.
- Fixed troubles with deleting files on some SD cards (like the bundled one).
- Fixed the default I2C1 pins in micropython's I2C interface.
- Fixed large files being truncated when installing apps via `gr33nhouse`.
- Fixed LED color handling in the simulator.
- Fixed flickering .down property of Pressable when going through REPEATED state.
## [1.2.0] - 2023-08-18
### Added
- Added a WiFi status indicator icon.
- Added a battery status indicator icon.
- Added support for loading apps from `/sd/apps` and `/flash/apps`.
- Added an error screen when apps fail to start.
- Added Python/st3m API to access battery charge status.
- Added the ability to always hide icons (*System**Settings**Show Icons*).
### Fixed
- File descriptor leak on app load. This would lead to the OS crashing when
too many apps are installed.
## [1.1.1] - 2023-08-17
### Fixed
- Crash on WiFi startup
## [1.1.0] - 2023-08-17
### Added
- Added _Comic Mono_ font.
- Added a setting for automatically connecting to Camp WiFi.
- Added a *System**Get Apps* App for downloading apps directly from <https://flow3r.garden/apps/>.
- Added `ApplicationContext.bundle_path` so apps can find out what directory
they live in. This should be used for loading app assets from the correct
path.
- Added TLS support for MicroPython.
- Added modules for `.tar.gz` extraction.
- Added `aioble` module (Bluetooth Low Energy).
- Added line-in support to bl00mbox.
- Added pronoun support in the Nick app.
- Added color options in the Nick app.
- Added IMU-based rotation in the Nick app.
### Changed
- `ctx.get_font_name()` now raises an exception for unknown fonts.
- Raised max concurrent texture limit to 32.
### Fixed
- Fixed PNG without alpha and JPEG support by enabling `CTX_FORMAT_RGB8`.
- Fixed image cache eviction by introducing a ctx frameclock.
- Fixed incorrect merging of settings dicts in `st3m.settings`.
- Fixed some USB problems.
- Fixed sound filenames not working when they start with `/flash/` or `/sd/`.
- Fixed syntax errors in `flow3r.toml` crashing the menu.
## [1.0.0] - 2023-08-13
Initial Release
[unreleased]: https://git.flow3r.garden/flow3r/flow3r-firmware/-/compare/v1.4.0...main
[1.4.0]: https://git.flow3r.garden/flow3r/flow3r-firmware/-/compare/v1.3.0...v1.4.0
[1.3.0]: https://git.flow3r.garden/flow3r/flow3r-firmware/-/compare/v1.2.0...v1.3.0
[1.2.0]: https://git.flow3r.garden/flow3r/flow3r-firmware/-/compare/v1.1.1...v1.2.0
[1.1.1]: https://git.flow3r.garden/flow3r/flow3r-firmware/-/compare/v1.1.0...v1.1.1
[1.1.0]: https://git.flow3r.garden/flow3r/flow3r-firmware/-/compare/v1.0.0...v1.1.0
[1.0.0]: https://git.flow3r.garden/flow3r/flow3r-firmware/-/tags/v1.0.0
......@@ -4,7 +4,19 @@ set(IDF_TARGET esp32s3)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# TODO(q3k): migrate badge23/components/* to components/*.
list(APPEND EXTRA_COMPONENT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/badge23/components/")
project(flow3r)
project(badge23)
# Make `1.1` literals into single-point precision float instead of double
# precision. Also warn any time something gets promoted to a double. We
# generally don't want doubles, doubles on ESP32 bad.
idf_component_get_property(st3m_lib st3m COMPONENT_LIB)
idf_component_get_property(flow3r_bsp_lib flow3r_bsp COMPONENT_LIB)
idf_component_get_property(bl00mbox_lib bl00mbox COMPONENT_LIB)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(${st3m_lib} PRIVATE -cl-single-precision-constant -Wdouble-promotion)
target_compile_options(${flow3r_bsp_lib} PRIVATE -cl-single-precision-constant -Wdouble-promotion)
target_compile_options(${bl00mbox_lib} PRIVATE -Wno-error=unknown-pragmas)
else()
target_compile_options(${st3m_lib} PRIVATE -fsingle-precision-constant -Wdouble-promotion)
target_compile_options(${flow3r_bsp_lib} PRIVATE -fsingle-precision-constant -Wdouble-promotion)
endif()
This diff is collapsed.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
## Current functionality
# flow3r badge
Micropython repl hooked up, hw functionality partly broken>
See https://docs.flow3r.garden/badge/firmware-development.html for a firmware development guide.
Some fun commands to try:
## License
All original source code in this repository is Copyright (C) 2023 Flow3r Badge Contributors. This source code is licensed under the GNU Lesser General Public License Version 3.0 as described in the file COPYING.
```
import hardware
#turn on sound
hardware.set_global_volume_dB(-10)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License Version 3.0 as published by the Free Software Foundation.
from synth import tinysynth
a=tinysynth(440,1); # enters decay phase without stop signal
a.start();
b=tinysynth(660,0); # sustains until stop signal
b.start();
b.stop();
This program 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.
#tiny issue with garbage collect:
hardware.count_sources();
a.__del__();
hardware.count_sources();
import gc
del b
gc.collect()
hardware.count_sources();
#...don't know how to hook up gc to __del__, maybe wrong approach
```
Files can be transferred with mpremote, such as:
```
mpremote fs cp python_payload/boot.py :boot.py
mpremote fs cp python_payload/cap_touch_demo.py :cap_touch_demo.py
```
## How to install dependencies
### Generic
1. install esp-idf v4.4:
(copied from https://www.wemos.cc/en/latest/tutorials/others/build\_micropython\_esp32.html)
```
$ cd ~
$ git clone https://github.com/espressif/esp-idf.git
$ cd esp-idf
$ git checkout v4.4
$ git submodule update --init --recursive
$ cd esp-idf
$ ./install.sh
$ source export.sh
```
best put something like "alias espidf='source ~/esp-idf/export.sh'" in your .bashrc etc,
you need to run it in every new terminal and adding it to autostart did bother us
### Nix(OS)
```
$ nix-shell nix/shell.nix
```
## How to build and flash
Standard ESP-IDF project machinery present and working. You can run `idf.py` from the git checkout and things should just work.
### Building
```
$ idf.py build
```
### Flashing
Put badge into bootloader mode by holding left should button down during boot.
```
$ idf.py -p /dev/ttyACM0 flash
```
You can skip `-p /dev/ttyACM0` if you set the environment variable `ESPPORT=/dev/ttyACM0`. This environment variable is also set by default when using Nix.
After flashing, remember to powercycle your badge to get it into the user application.
### Accessing MicroPython REPL:
```
$ picocom -b 115200 /dev/ttyACM0
$ # or
$ screen /dev/ttyACM0
$ # or (will eat newlines in REPL, though)
$ idf.py -p /dev/ttyACM0 monitor
```
### Use CMake
`idf.py` calls cmake under the hood for most operations. If you dislike using wrappers you can do the same work yourself:
```
mkdir build
cd build
cmake .. -G Ninja
ninja
```
There's `flash/monitor` targets, too (but no openocd/gdb...). To pick what port to flash to/monitor, set the ESPPORT environment variable.
## How to modify
### General info
Global + micropython entry point: app\_main() in micropython/ports/esp32/main.c (includes badge23/espan.h).
C entry point, called by^: os\_app\_main() in badge23/espan.c
Register new c files for compilation: add to set(BADGE23\_SOURCE) in main/CMakelists.txt
Change output volume in the set\_global\_vol\_dB(int8\_t) call; -90 for mute
### Debugging
The badge is currently configured to run in HW USB UART/JTAG mode (vs. using TinyUSB and 'software' CDC/whatever using the generic OTG peripheral).
What this means:
1. You can use the MicroPython REPL over a USB console,
2. The MicroPython REPL will also print ESP-IDF logs, including panics,
3. You can use OpenOCD/GDB.
#### printf() debugging and logging in C-land
Given the above, you can do the following to get a log. This is part of ESP-IDF's standard logging functionality.
```
static const char *TAG = "misery";
// ...
ESP_LOGI(TAG, "i love C");
```
However, this will **only work** if you first set `CONFIG_LOG_DEFAULT_LEVEL_INFO=y` (which will likely break programs interacting with micropython REPL as many components of the ESP-IDF will suddenly become very chatty). But that's fine for troubleshooting some C-land bugs.
If you want to only log errors or just add temporary logs, use `ESP_LOGE` instead, which will always print to the USB console.
`printf()` also just works. But it should only be used for development debugging, for long-term logging statements please use `ESP_LOG*` instead.
#### Running OpenOCD+GDB
First, make sure your badge is running in application mode (not bootloader mode! that will stay in bootloader mode).
Then, start OpenOCD:
```
$ OPENOCD_COMMANDS="-f board/esp32s3-builtin.cfg" idf.py openocd
```
(you can skip setting `OPENOCD_COMMANDS` if you're using Nix)
Then, in another terminal:
```
$ idf.py gdb
```
Good luck. The idf.py gdb/openocd scripts seem somewhat buggy.
### ESP-IDF functionality
Currently we have one large sdkconfig file. To modify it, run:
```
$ idf.py menuconfig
```
TODO(q3k): split into defaults
You should have received a copy of the GNU Lesser General Public License Version 3.0 along with this program. If not, see <https://www.gnu.org/licenses/>.
idf_component_register(SRCS "espan.c" "apa102LEDStrip.c" "audio.c" "captouch.c" "decode_image.c" "leds.c" "display.c" "synth.c" "scope.c"
EMBED_FILES
${project_dir}/resources/boot.snd
${project_dir}/resources/pan.s16
${project_dir}/resources/image.jpg
INCLUDE_DIRS ".")
menu "Example Configuration"
orsource "$IDF_PATH/examples/common_components/env_caps/$IDF_TARGET/Kconfig.env_caps"
config I2C_MASTER_SCL
int "SCL GPIO Num"
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
default 19 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
default 6
help
GPIO number for I2C Master clock line.
config I2C_MASTER_SDA
int "SDA GPIO Num"
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
default 18 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
default 5
help
GPIO number for I2C Master data line.
endmenu
#include "apa102LEDStrip.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
void initLEDs(struct apa102LEDStrip *ledObject, short int numLEDs, unsigned char bytesPerLED, unsigned char globalBrightness)
{
ledObject->_numLEDs = numLEDs;
ledObject->_bytesPerLED = bytesPerLED;
ledObject->_endFrameLength = 1;//round( (numLEDs/2)/8 );
ledObject->_frameLength = (1+numLEDs+ledObject->_endFrameLength)*bytesPerLED;
ledObject->_globalBrightness = globalBrightness;
ledObject->LEDs = (unsigned char *)malloc(ledObject->_frameLength*sizeof(unsigned char));
//Start Frame
ledObject->LEDs[0] = 0;
ledObject->LEDs[1] = 0;
ledObject->LEDs[2] = 0;
ledObject->LEDs[3] = 0;
//Driver frame+PIXEL frames
for(ledObject->_counter=ledObject->_bytesPerLED; ledObject->_counter<ledObject->_frameLength-(ledObject->_endFrameLength*ledObject->_bytesPerLED); ledObject->_counter+=ledObject->_bytesPerLED)
{
ledObject->LEDs[ledObject->_counter] = ledObject->_globalBrightness;
ledObject->LEDs[ledObject->_counter+1] = 0;
ledObject->LEDs[ledObject->_counter+2] = 0;
ledObject->LEDs[ledObject->_counter+3] = 0;
}
//END frames
for(ledObject->_counter=ledObject->_frameLength-(ledObject->_endFrameLength*ledObject->_bytesPerLED); ledObject->_counter<ledObject->_frameLength; ledObject->_counter+=ledObject->_bytesPerLED)
{
ledObject->LEDs[ledObject->_counter] = 255;
ledObject->LEDs[ledObject->_counter+1] = 255;
ledObject->LEDs[ledObject->_counter+2] = 255;
ledObject->LEDs[ledObject->_counter+3] = 255;
}
}
void setPixel(struct apa102LEDStrip *ledObject, short int pixelIndex, unsigned char *pixelColour)
{
ledObject->_counter = 4*(pixelIndex+1);
ledObject->LEDs[ ledObject->_counter + 1 ] = pixelColour[2];
ledObject->LEDs[ ledObject->_counter + 2 ] = pixelColour[1];
ledObject->LEDs[ ledObject->_counter + 3 ] = pixelColour[0];
}
void getPixel(struct apa102LEDStrip *ledObject, short int pixelIndex, unsigned char *pixelColour)
{
ledObject->_counter = 4*(pixelIndex+1);
pixelColour[2] = ledObject->LEDs[ ledObject->_counter + 1 ];
pixelColour[1] = ledObject->LEDs[ ledObject->_counter + 2 ];
pixelColour[0] = ledObject->LEDs[ ledObject->_counter + 3 ];
}
#ifndef DEF_apa102LEDStrip
#define DEF_apa102LEDStrip
struct apa102LEDStrip
{
unsigned char *LEDs;
short int _frameLength;
short int _endFrameLength;
short int _numLEDs;
unsigned char _bytesPerLED;
short int _counter;
unsigned char _globalBrightness;
};
void initLEDs(struct apa102LEDStrip *ledObject, short int numLEDs, unsigned char bytesPerLED, unsigned char globalBrightness);
void setPixel(struct apa102LEDStrip *ledObject, short int pixelIndex, unsigned char *pixelColour);
void getPixel(struct apa102LEDStrip *ledObject, short int pixelIndex, unsigned char *pixelColour);
#endif
#include "audio.h"
#include "synth.h"
#include "scope.h"
#include "driver/i2s.h"
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/queue.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "../../py/mphal.h"
static void audio_player_task(void* arg);
#define DMA_BUFFER_SIZE 64
#define DMA_BUFFER_COUNT 2
#define I2S_PORT 0
static void i2s_init(void){
static const i2s_config_t i2s_config = {
.mode = I2S_MODE_MASTER | I2S_MODE_TX,
.sample_rate = SAMPLE_RATE,
.bits_per_sample = 16,
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
//.communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB,
.communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB,
.intr_alloc_flags = 0, // default interrupt priority
.dma_buf_count = DMA_BUFFER_COUNT,
.dma_buf_len = DMA_BUFFER_SIZE,
.use_apll = false
};
static const i2s_pin_config_t pin_config = {
.bck_io_num = 13,
.mck_io_num = 11,
.ws_io_num = 12,
.data_out_num = 14,
.data_in_num = I2S_PIN_NO_CHANGE
};
i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
i2s_set_pin(I2S_PORT, &pin_config);
}
typedef struct _audio_source_t{
void * render_data;
float (* render_function)(void *);
uint16_t index;
struct _audio_source_t * next;
} audio_source_t;
static audio_source_t * _audio_sources = NULL;
uint16_t add_audio_source(void * render_data, void * render_function){
//construct audio source struct
audio_source_t * src = malloc(sizeof(audio_source_t));
if(src == NULL) return;
src->render_data = render_data;
src->render_function = render_function;
src->next = NULL;
src->index = 0;
//handle empty list special case
if(_audio_sources == NULL){
_audio_sources = src;
return 0; //only nonempty lists from here on out!
}
//searching for lowest unused index
audio_source_t * index_source = _audio_sources;
while(1){
if(src->index == (index_source->index)){
src->index++; //someone else has index already, try next
index_source = _audio_sources; //start whole list for new index
} else {
index_source = index_source->next;
}
if(index_source == NULL){ //traversed the entire list
break;
}
}
audio_source_t * audio_source = _audio_sources;
//append new source to linked list
while(audio_source != NULL){
if(audio_source->next == NULL){
audio_source->next = src;
break;
} else {
audio_source = audio_source->next;
}
}
return src->index;
}
void remove_audio_source(uint16_t index){
audio_source_t * audio_source = _audio_sources;
audio_source_t * start_gap = NULL;
while(audio_source != NULL){
if(index == audio_source->index){
if(start_gap == NULL){
_audio_sources = audio_source->next;
} else {
start_gap->next = audio_source->next;
}
vTaskDelay(20 / portTICK_PERIOD_MS); //give other tasks time to stop using
free(audio_source); //terrible hack tbh
break;
}
start_gap = audio_source;
audio_source = audio_source->next;
}
}
uint16_t count_audio_sources(){
uint16_t ret = 0;
audio_source_t * audio_source = _audio_sources;
while(audio_source != NULL){
audio_source = audio_source->next;
ret++;
}
return ret;
}
static void _audio_init(void) {
init_scope(241);
i2s_init();
//ESP_ERROR_CHECK(i2s_channel_enable(tx_chan));
TaskHandle_t handle;
xTaskCreate(&audio_player_task, "Audio player", 3000, NULL, configMAX_PRIORITIES - 1, &handle);
}
#define LR_PHASE 1
#define NAT_LOG_DB 0.1151292546497023
static uint16_t _global_vol = 3000;
void set_global_vol_dB(int8_t vol_dB){
if(vol_dB < (BADGE_MIN_VOLUME_DB)){
_global_vol = 0;
} else {
if(vol_dB > (BADGE_MAX_VOLUME_DB)) vol_dB = (BADGE_MAX_VOLUME_DB);
uint16_t buf = 3000 * exp(vol_dB * NAT_LOG_DB);
if(buf > (BADGE_VOLUME_LIMIT)) buf = (BADGE_VOLUME_LIMIT);
_global_vol = buf;
}
}
static void audio_player_task(void* arg) {
int16_t buffer[DMA_BUFFER_SIZE * 2];
memset(buffer, 0, sizeof(buffer));
while(true) {
for(int i = 0; i < (DMA_BUFFER_SIZE * 2); i += 2){
float sample = 0;
audio_source_t * audio_source = _audio_sources;
while(audio_source != NULL){
sample += (*(audio_source->render_function))(audio_source->render_data);
audio_source = audio_source->next;
}
write_to_scope((int16_t) (1600. * sample));
sample = _global_vol * sample;
if(sample > 32767) sample = 32767;
if(sample < -32767) sample = -32767;
buffer[i] = (int16_t) sample;
buffer[i+1] = LR_PHASE * buffer[i];
}
size_t count = 0;
i2s_write(I2S_PORT, buffer, sizeof(buffer), &count, 1000);
if (count != sizeof(buffer)) {
printf("i2s_write_bytes: count (%d) != length (%d)\n", count, sizeof(buffer));
abort();
}
}
}
void audio_init() { _audio_init(); }
/*
#define NAT_LOG_SEMITONE 0.05776226504666215
void synth_set_bend(int i, float bend){
if(bend != bend) return;
if((bend > -0.0001) && (bend < 0.0001)){
synths[i].bend = 1;
} else {
synths[i].bend = exp(bend * NAT_LOG_SEMITONE);
}
}
*/
/*
void synth_stop(int i){
if(synths[i].env_phase){
synths[i].env_phase = 3;
}
}
void synth_fullstop(int i){
synths[i].env_phase = 0;
}
void synth_start(int i){
synths[i].env_phase = 1; //put into attack phase;
}
float synth_get_env(int i){
return synths[i].env;
}
*/
#pragma once
#include <stdint.h>
#define SAMPLE_RATE 16000
#define BADGE_MAX_VOLUME_DB 20
#define BADGE_MIN_VOLUME_DB (-80)
#define BADGE_VOLUME_LIMIT 30000
void audio_init();
void set_global_vol_dB(int8_t vol_dB);
uint16_t count_audio_sources();
uint16_t add_audio_source(void * render_data, void * render_function);
void remove_audio_source(uint16_t index);
//#include <stdio.h>
//#include <string.h>
#include "esp_log.h"
#include "driver/i2c.h"
#include <stdint.h>
static const char *TAG = "captouch";
#define I2C_MASTER_NUM 0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
#define AD7147_BASE_ADDR 0x2C
#define AD7147_REG_PWR_CONTROL 0x00
#define AD7147_REG_STAGE_CAL_EN 0x01
#define AD7147_REG_STAGE_HIGH_INT_ENABLE 0x06
#define AD7147_REG_DEVICE_ID 0x17
#define TIMEOUT_MS 1000
struct ad714x_chip {
uint8_t addr;
uint8_t gpio;
int afe_offsets[13];
int stages;
};
static const struct ad714x_chip chip_top = {.addr = AD7147_BASE_ADDR + 1, .gpio = 48, .afe_offsets = {24, 12, 16, 33, 30, 28, 31, 27, 22, 24, 18, 19, }, .stages=12};
static const struct ad714x_chip chip_bot = {.addr = AD7147_BASE_ADDR, .gpio = 3, .afe_offsets = {3, 2, 1, 1 ,1, 1, 1, 1, 2, 3}, .stages=10};
static esp_err_t ad714x_i2c_write(const struct ad714x_chip *chip, const uint16_t reg, const uint16_t data)
{
const uint8_t tx[] = {reg >> 8, reg & 0xFF, data >> 8, data & 0xFF};
ESP_LOGI(TAG, "AD7147 write reg %X-> %X", reg, data);
return i2c_master_write_to_device(I2C_MASTER_NUM, chip->addr, tx, sizeof(tx), TIMEOUT_MS / portTICK_PERIOD_MS);
}
static esp_err_t ad714x_i2c_read(const struct ad714x_chip *chip, const uint16_t reg, uint16_t *data, const size_t len)
{
const uint8_t tx[] = {reg >> 8, reg & 0xFF};
uint8_t rx[len * 2];
esp_err_t ret = i2c_master_write_read_device(I2C_MASTER_NUM, chip->addr, tx, sizeof(tx), rx, sizeof(rx), TIMEOUT_MS / portTICK_PERIOD_MS);
for(int i = 0; i < len; i++) {
data[i] = (rx[i * 2] << 8) | rx[i * 2 + 1];
}
return ret;
}
struct ad7147_stage_config {
unsigned int cinX_connection_setup[13];
unsigned int se_connection_setup:2;
unsigned int neg_afe_offset_disable:1;
unsigned int pos_afe_offset_disable:1;
unsigned int neg_afe_offset:6;
unsigned int neg_afe_offset_swap:1;
unsigned int pos_afe_offset:6;
unsigned int pos_afe_offset_swap:1;
unsigned int neg_threshold_sensitivity:4;
unsigned int neg_peak_detect:3;
unsigned int pos_threshold_sensitivity:4;
unsigned int pos_peak_detect:3;
};
#define CIN CDC_NONE 0
#define CIN_CDC_NEG 1
#define CIN_CDC_POS 2
#define CIN_BIAS 3
static const uint16_t bank2 = 0x80;
static void ad714x_set_stage_config(const struct ad714x_chip *chip, const uint8_t stage, const struct ad7147_stage_config * config)
{
const uint16_t connection_6_0 = (config->cinX_connection_setup[6] << 12) | (config->cinX_connection_setup[5] << 10) | (config->cinX_connection_setup[4] << 8) | (config->cinX_connection_setup[3] << 6) | (config->cinX_connection_setup[2] << 4) | (config->cinX_connection_setup[1] << 2) | (config->cinX_connection_setup[0] << 0);
const uint16_t connection_12_7 = (config->pos_afe_offset_disable << 15) | (config->neg_afe_offset_disable << 14) | (config->se_connection_setup << 12) | (config->cinX_connection_setup[12] << 10) | (config->cinX_connection_setup[11] << 8) | (config->cinX_connection_setup[10] << 6) | (config->cinX_connection_setup[9] << 4) | (config->cinX_connection_setup[8] << 2) | (config->cinX_connection_setup[7] << 0);
const uint16_t afe_offset = (config->pos_afe_offset_swap << 15) | (config->pos_afe_offset << 8) | (config->neg_afe_offset_swap << 7) | (config->neg_afe_offset << 0);
const uint16_t sensitivity = (config->pos_peak_detect << 12) | (config->pos_threshold_sensitivity << 8) | (config->neg_peak_detect << 4) | (config->neg_threshold_sensitivity << 0);
//ESP_LOGI(TAG, "Stage %d config-> %X %X %X %X", stage, connection_6_0, connection_12_7, afe_offset, sensitivity);
//ESP_LOGI(TAG, "Config: %X %X %X %X %X %X %X %X %X", config->pos_afe_offset_disable, config->pos_afe_offset_disable, config->se_connection_setup, config->cinX_connection_setup[12], config->cinX_connection_setup[11], config->cinX_connection_setup[10], config->cinX_connection_setup[9], config->cinX_connection_setup[8], config->cinX_connection_setup[7]);
ad714x_i2c_write(chip, bank2 + stage * 8, connection_6_0);
ad714x_i2c_write(chip, bank2 + stage * 8 + 1, connection_12_7);
ad714x_i2c_write(chip, bank2 + stage * 8 + 2, afe_offset);
ad714x_i2c_write(chip, bank2 + stage * 8 + 3, sensitivity);
}
struct ad7147_device_config {
unsigned int power_mode:2;
unsigned int lp_conv_delay:2;
unsigned int sequence_stage_num:4;
unsigned int decimation:2;
unsigned int sw_reset:1;
unsigned int int_pol:1;
unsigned int ext_source:1;
unsigned int cdc_bias:2;
unsigned int stage0_cal_en:1;
unsigned int stage1_cal_en:1;
unsigned int stage2_cal_en:1;
unsigned int stage3_cal_en:1;
unsigned int stage4_cal_en:1;
unsigned int stage5_cal_en:1;
unsigned int stage6_cal_en:1;
unsigned int stage7_cal_en:1;
unsigned int stage8_cal_en:1;
unsigned int stage9_cal_en:1;
unsigned int stage10_cal_en:1;
unsigned int stage11_cal_en:1;
unsigned int avg_fp_skip:2;
unsigned int avg_lp_skip:2;
unsigned int stage0_high_int_enable:1;
unsigned int stage1_high_int_enable:1;
unsigned int stage2_high_int_enable:1;
unsigned int stage3_high_int_enable:1;
unsigned int stage4_high_int_enable:1;
unsigned int stage5_high_int_enable:1;
unsigned int stage6_high_int_enable:1;
unsigned int stage7_high_int_enable:1;
unsigned int stage8_high_int_enable:1;
unsigned int stage9_high_int_enable:1;
unsigned int stage10_high_int_enable:1;
unsigned int stage11_high_int_enable:1;
};
static void ad714x_set_device_config(const struct ad714x_chip *chip, const struct ad7147_device_config * config)
{
const uint16_t pwr_control = (config->cdc_bias << 14) | (config->ext_source << 12) | (config->int_pol << 11) | (config->sw_reset << 10) | (config->decimation << 8) | (config->sequence_stage_num << 4) | (config->lp_conv_delay << 2) | (config->power_mode << 0);
const uint16_t stage_cal_en = (config->avg_lp_skip << 14) | (config->avg_fp_skip << 12) | (config->stage11_cal_en << 11) | (config->stage10_cal_en << 10) | (config->stage9_cal_en << 9) | (config->stage8_cal_en << 8) | (config->stage7_cal_en << 7) | (config->stage6_cal_en << 6) | (config->stage5_cal_en << 5) | (config->stage4_cal_en << 4) | (config->stage3_cal_en << 3) | (config->stage2_cal_en << 2) | (config->stage1_cal_en << 1) | (config->stage0_cal_en << 0);
const uint16_t stage_high_int_enable = (config->stage11_high_int_enable << 11) | (config->stage10_high_int_enable << 10) | (config->stage9_high_int_enable << 9) | (config->stage8_high_int_enable << 8) | (config->stage7_high_int_enable << 7) | (config->stage6_high_int_enable << 6) | (config->stage5_high_int_enable << 5) | (config->stage4_high_int_enable << 4) | (config->stage3_high_int_enable << 3) | (config->stage2_high_int_enable << 2) | (config->stage1_high_int_enable << 1) | (config->stage0_high_int_enable << 0);
ad714x_i2c_write(chip, AD7147_REG_PWR_CONTROL, pwr_control);
ad714x_i2c_write(chip, AD7147_REG_STAGE_CAL_EN, stage_cal_en);
ad714x_i2c_write(chip, AD7147_REG_STAGE_HIGH_INT_ENABLE, stage_high_int_enable);
}
static struct ad7147_stage_config ad714x_default_config(void)
{
return (struct ad7147_stage_config) {
.cinX_connection_setup={CIN_BIAS, CIN_BIAS, CIN_BIAS, CIN_BIAS, CIN_BIAS, CIN_BIAS, CIN_BIAS, CIN_BIAS, CIN_BIAS, CIN_BIAS, CIN_BIAS, CIN_BIAS},
.se_connection_setup=0b01,
.pos_afe_offset=0,
};
}
#define ESP_INTR_FLAG_DEFAULT 0
static QueueHandle_t gpio_evt_queue = NULL;
static void IRAM_ATTR gpio_isr_handler(void* arg)
{
struct ad714x_chip* chip = (struct ad714x_chip *) arg;
xQueueSendFromISR(gpio_evt_queue, &chip, NULL);
}
void manual_captouch_readout(uint8_t top)
{
struct ad714x_chip* chip = top ? (&chip_top) : (&chip_bot);
xQueueSend(gpio_evt_queue, &chip, NULL);
}
static uint16_t pressed_top, pressed_bot;
void gpio_event_handler(void* arg)
{
static unsigned long counter = 0;
struct ad714x_chip* chip;
uint16_t pressed;
while(true) {
if(xQueueReceive(gpio_evt_queue, &chip, portMAX_DELAY)) {
ad714x_i2c_read(chip, 9, &pressed, 1);
ESP_LOGI(TAG, "Addr %x, High interrupt %X", chip->addr, pressed);
pressed &= ((1 << chip->stages) - 1);
if(chip == &chip_top) pressed_top = pressed;
if(chip == &chip_bot) pressed_bot = pressed;
}
}
}
static uint8_t top_map[] = {2, 2, 2, 0, 0, 8, 8, 8, 6, 6, 4, 4};
static uint8_t bot_map[] = {1, 1, 3, 3, 5, 5, 7, 7, 9, 9};
uint16_t read_captouch(){
uint16_t petals = 0;
uint16_t top = pressed_top;
uint16_t bot = pressed_bot;
for(int i=0; i<12; i++) {
if(top & (1 << i)) {
petals |= (1<<top_map[i]);
}
}
for(int i=0; i<10; i++) {
if(bot & (1 << i)) {
petals |= (1<<bot_map[i]);
}
}
return petals;
}
void captouch_force_calibration(){
ad714x_i2c_write(&chip_top, 2, (1 << 14));
ad714x_i2c_write(&chip_bot, 2, (1 << 14));
}
static void captouch_init_chip(const struct ad714x_chip* chip, const struct ad7147_device_config device_config)
{
uint16_t data;
ad714x_i2c_read(chip, AD7147_REG_DEVICE_ID, &data, 1);
ESP_LOGI(TAG, "DEVICE ID = %X", data);
ad714x_set_device_config(chip, &device_config);
for(int i=0; i<chip->stages; i++) {
struct ad7147_stage_config stage_config;
stage_config = ad714x_default_config();
stage_config.cinX_connection_setup[i] = CIN_CDC_POS;
stage_config.pos_afe_offset=chip->afe_offsets[i];
ad714x_set_stage_config(chip, i, &stage_config);
}
captouch_force_calibration();
gpio_config_t io_conf = {};
io_conf.intr_type = GPIO_INTR_NEGEDGE;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = (1ULL << chip->gpio);
io_conf.pull_up_en = 1;
io_conf.pull_down_en = 0;
gpio_config(&io_conf);
// gpio_isr_handler_add(chip->gpio, gpio_isr_handler, (void *)chip);
}
void captouch_init(void)
{
//gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
captouch_init_chip(&chip_top, (struct ad7147_device_config){.sequence_stage_num = 11,
.decimation = 1,
.stage0_cal_en = 1,
.stage1_cal_en = 1,
.stage2_cal_en = 1,
.stage3_cal_en = 1,
.stage4_cal_en = 1,
.stage5_cal_en = 1,
.stage6_cal_en = 1,
.stage7_cal_en = 1,
.stage8_cal_en = 1,
.stage9_cal_en = 1,
.stage10_cal_en = 1,
.stage11_cal_en = 1,
.stage0_high_int_enable = 1,
.stage1_high_int_enable = 1,
.stage2_high_int_enable = 1,
.stage3_high_int_enable = 1,
.stage4_high_int_enable = 1,
.stage5_high_int_enable = 1,
.stage6_high_int_enable = 1,
.stage7_high_int_enable = 1,
.stage8_high_int_enable = 1,
.stage9_high_int_enable = 1,
.stage10_high_int_enable = 1,
.stage11_high_int_enable = 1,
});
captouch_init_chip(&chip_bot, (struct ad7147_device_config){.sequence_stage_num = 11,
.decimation = 1,
.stage0_cal_en = 1,
.stage1_cal_en = 1,
.stage2_cal_en = 1,
.stage3_cal_en = 1,
.stage4_cal_en = 1,
.stage5_cal_en = 1,
.stage6_cal_en = 1,
.stage7_cal_en = 1,
.stage8_cal_en = 1,
.stage9_cal_en = 1,
.stage0_high_int_enable = 1,
.stage1_high_int_enable = 1,
.stage2_high_int_enable = 1,
.stage3_high_int_enable = 1,
.stage4_high_int_enable = 1,
.stage5_high_int_enable = 1,
.stage6_high_int_enable = 1,
.stage7_high_int_enable = 1,
.stage8_high_int_enable = 1,
.stage9_high_int_enable = 1,
});
gpio_evt_queue = xQueueCreate(10, sizeof(const struct ad714x_chip*));
xTaskCreate(gpio_event_handler, "gpio_event_handler", 2048 * 2, NULL, configMAX_PRIORITIES - 2, NULL);
}
static void captouch_print_debug_info_chip(const struct ad714x_chip* chip)
{
uint16_t data[12] = {0,};
uint16_t ambient[12] = {0,};
const int stages = chip->stages;
#if 1
for(int stage=0; stage<stages; stage++) {
ad714x_i2c_read(chip, 0x0FA + stage * (0x104 - 0xE0), data, 1);
ESP_LOGI(TAG, "stage %d threshold: %X", stage, data[0]);
}
ad714x_i2c_read(chip, 0xB, data, stages);
ESP_LOGI(TAG, "CDC results: %X %X %X %X %X %X %X %X %X %X %X %X", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11]);
for(int stage=0; stage<stages; stage++) {
ad714x_i2c_read(chip, 0x0F1 + stage * (0x104 - 0xE0), &ambient[stage], 1);
ESP_LOGI(TAG, "stage %d ambient: %X diff: %d", stage, ambient[stage], data[stage] - ambient[stage]);
}
#endif
#if 1
ad714x_i2c_read(chip, 8, data, 1);
ESP_LOGI(TAG, "Low interrupt %X", data[0]);
ad714x_i2c_read(chip, 9, data, 1);
ESP_LOGI(TAG, "High interrupt %X", data[0]);
ad714x_i2c_read(chip, 0x42, data, 1);
ESP_LOGI(TAG, "Proximity %X", data[0]);
//ESP_LOGI(TAG, "CDC result = %X", data[0]);
//if(data[0] > 0xa000) {
//ESP_LOGI(TAG, "Touch! %X", data[0]);
//}
#endif
}
void captouch_print_debug_info(void)
{
captouch_print_debug_info_chip(&chip_top);
captouch_print_debug_info_chip(&chip_bot);
}
void captouch_get_cross(int paddle, int *x, int *y)
{
uint16_t data[12] = {0,};
uint16_t ambient[12] = {0,};
int result[2] = {0, 0};
float total = 0;
#if 0
if(paddle == 2) {
ad714x_i2c_read(&chip_top, 0xB, data, 3);
//ESP_LOGI(TAG, "CDC results: %X %X %X %X %X %X %X %X %X %X %X %X", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11]);
for(int stage=0; stage<3; stage++) {
ad714x_i2c_read(&chip_top, 0x0F1 + stage * (0x104 - 0xE0), &ambient[stage], 1);
//ESP_LOGI(TAG, "stage %d ambient: %X diff: %d", stage, ambient[stage], data[stage] - ambient[stage]);
}
int vectors[][2] = {{0, 0}, {0,240}, {240, 120}};
total = (data[0] - ambient[0]) + (data[1] - ambient[1]) + (data[2] - ambient[2]);
result[0] = vectors[0][0] * (data[0] - ambient[0]) + vectors[1][0] * (data[1] - ambient[1]) + vectors[2][0] * (data[2] - ambient[2]);
result[1] = vectors[0][1] * (data[0] - ambient[0]) + vectors[1][1] * (data[1] - ambient[1]) + vectors[2][1] * (data[2] - ambient[2]);
}
if(paddle == 8) {
ad714x_i2c_read(&chip_top, 0xB + 5, data + 5, 3);
//ESP_LOGI(TAG, "CDC results: %X %X %X %X %X %X %X %X %X %X %X %X", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11]);
for(int stage=5; stage<8; stage++) {
ad714x_i2c_read(&chip_top, 0x0F1 + stage * (0x104 - 0xE0), &ambient[stage], 1);
//ESP_LOGI(TAG, "stage %d ambient: %X diff: %d", stage, ambient[stage], data[stage] - ambient[stage]);
}
int vectors[][2] = {{240, 240}, {240, 0}, {0, 120}};
total = (data[5] - ambient[5]) + (data[6] - ambient[6]) + (data[7] - ambient[7]);
result[0] = vectors[0][0] * (data[5] - ambient[5]) + vectors[1][0] * (data[6] - ambient[6]) + vectors[2][0] * (data[7] - ambient[7]);
result[1] = vectors[0][1] * (data[5] - ambient[5]) + vectors[1][1] * (data[6] - ambient[6]) + vectors[2][1] * (data[7] - ambient[7]);
}
*x = result[0] / total;
*y = result[1] / total;
//ESP_LOGI(TAG, "x=%d y=%d\n", *x, *y);
#endif
const int paddle_info_1[] = {
4,
0,
1,
2,
11,
4,
9,
7,
6,
9,
};
const int paddle_info_2[] = {
3,
1,
0,
3,
10,
5,
8,
6,
5,
8,
};
struct ad714x_chip* chip;
if (paddle % 2 == 0) {
chip = &chip_top;
} else {
chip = &chip_bot;
}
ad714x_i2c_read(chip, 0xB, data, 12);
//ESP_LOGI(TAG, "CDC results: %X %X %X %X %X %X %X %X %X %X %X %X", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11]);
for(int stage=0; stage<12; stage++) {
ad714x_i2c_read(chip, 0x0F1 + stage * (0x104 - 0xE0), &ambient[stage], 1);
//ESP_LOGI(TAG, "stage %d ambient: %X diff: %d", stage, ambient[stage], data[stage] - ambient[stage]);
}
int diff1 = data[paddle_info_1[paddle]] - ambient[paddle_info_1[paddle]];
int diff2 = data[paddle_info_2[paddle]] - ambient[paddle_info_2[paddle]];
ESP_LOGI(TAG, "%10d %10d", diff1, diff2);
int vectors[][2] = {{240, 240}, {240, 0}, {0, 120}};
total = ((diff1) + (diff2));
result[0] = vectors[0][0] * (diff1) + vectors[1][0] * (diff2);
result[1] = vectors[0][1] * (diff1) + vectors[1][1] * (diff2);
*x = result[0] / total;
*y = result[1] / total;
}
#pragma once
#include <stdint.h>
void captouch_init(void);
void captouch_print_debug_info(void);
void gpio_event_handler(void * arg);
void manual_captouch_readout(uint8_t top);
void captouch_get_cross(int paddle, int * x, int * y);
void captouch_force_calibration();
uint16_t read_captouch();
idf_component_register(SRCS "gc9a01.c" REQUIRES driver INCLUDE_DIRS ".")
menu "GC9A01 LCD Config"
config GC9A01_Width
int "GC9A01 LCD Width"
range 64 1024
default 240
config GC9A01_Height
int "GC9A01 LCD Height"
range 64 1024
default 240
#---------------------------------------------
choice GC9A01_SPI_HOST
prompt "GC9A01 SPI HOST"
default USE_SPI3_HOST
help
Hardware SPI , HSPI=SPI2 , VSPI=SPI3
config USE_SPI1_HOST
bool "USE SPI1 HOST"
config USE_SPI2_HOST
bool "USE SPI2 HOST"
config USE_SPI3_HOST
bool "USE SPI3 HOST"
config USE_SPI4_HOST
bool "USE SPI4 HOST"
endchoice
config GC9A01_SPI_HOST
int
default 0 if USE_SPI1_HOST
default 1 if USE_SPI2_HOST
default 2 if USE_SPI3_HOST
default 3 if USE_SPI4_HOST
#---------------------------------------------
config GC9A01_PIN_NUM_SCK
int "LCD SPI SCK Pin"
range 0 48
default 18
help
Must Support SPI SCK
config GC9A01_PIN_NUM_MOSI
int "LCD SPI MOSI Pin"
range 0 48
default 23
help
Must Support SPI MOSI
config GC9A01_PIN_NUM_CS
int "LCD SPI CS Pin"
range 0 48
default 05
config GC9A01_PIN_NUM_DC
int "LCD DC(Data or Command) GPIO Pin Number"
range 0 48
default 21
config GC9A01_SPI_SCK_FREQ_M
int "SPI Clock Freq in MHz"
range 1 80
default 40
config GC9A01_CONTROL_BACK_LIGHT_USED
bool "LCD Control Back Light"
default y
config GC9A01_PIN_NUM_BCKL
int "LCD BL(Back Light) GPIO Pin Number"
depends on GC9A01_CONTROL_BACK_LIGHT_USED
range 0 48
default 19
#---------------------------------------------
choice GC9A01_CONTROL_BACK_LIGHT_MODE
prompt "GC9A01b Control Back Light Mode"
default GC9A01_BACK_LIGHT_MODE_PWM
depends on GC9A01_CONTROL_BACK_LIGHT_USED
help
PWM use LEDC_TIMER_0 and LEDC_CHANNEL_0
config GC9A01_BACK_LIGHT_MODE_On_OFF
bool "USE GPIO ON/OF"
config GC9A01_BACK_LIGHT_MODE_PWM
bool "USE PWM"
endchoice
config GC9A01_CONTROL_BACK_LIGHT_MODE
int
default 0 if GC9A01_BACK_LIGHT_MODE_On_OFF
default 1 if GC9A01_BACK_LIGHT_MODE_PWM
#---------------------------------------------
config GC9A01_RESET_USED
bool "GC9A01 RESET Pin Used"
default y
help
Use GC9A01 Hard Reset Pin
config GC9A01_PIN_NUM_RST
int "LCD RST GPIO Pin Number"
depends on GC9A01_RESET_USED
range 0 48
default 22
config GC9A01_BUFFER_MODE
bool "Enable Buffer Mode"
default y
help
Disable for Direct Mode
config GC9A01_BUFFER_SCREEN_FAST_MODE
bool "Don't Convert Buffer for Screen_Load() & Screen_Shot()"
default n
depends on GC9A01_BUFFER_MODE
help
If Enabled , the Screen_load() & Screen_Shot() don't run SwapBytes() for Buffer
& Direct Save Data to SPI Buffer,So the data must manually SwapBytes before Send to LCD.
endmenu