Compare commits

..

264 Commits

Author SHA1 Message Date
Sebastien
5e5c7e0c80 Merge branch 'master-v4.3' of https://github.com/sle118/squeezelite-esp32 into master-v4.3 2022-11-24 09:07:45 -05:00
Sebastien
3144cf5f91 Change auth methods for pushing 2022-11-24 09:07:35 -05:00
github-actions
18cc0adfb4 Update prebuilt objects [skip actions] 2022-11-22 15:28:59 +00:00
github-actions
78ece491a9 Update prebuilt objects [skip actions] 2022-11-22 14:39:21 +00:00
Sébastien
9e66a822de Change call to web installer update 2022-11-22 09:35:34 -05:00
philippe44
0e12f7f887 bypass protobuf generation for now - release 2022-11-19 19:01:47 -08:00
philippe44
5df561890c mpr121 table init - release 2022-11-19 18:28:33 -08:00
philippe44
f6630fae4e release 2022-11-17 17:26:12 -08:00
philippe44
e2df4b1cc3 chmod on protoc 2022-11-17 17:20:20 -08:00
philippe44
3172576fc1 update CMake file 2022-11-17 16:36:25 -08:00
philippe44
e0dd7a596b release 2022-11-17 16:20:16 -08:00
philippe44
6e4dd65fd7 Merge branch 'master-v4.3' of https://github.com/sle118/squeezelite-esp32 into master-v4.3 2022-11-17 14:06:05 -08:00
philippe44
7e5f27af12 update cspot 2022-11-17 14:06:00 -08:00
github-actions
f805db3d27 Update prebuilt objects [skip actions] 2022-11-15 03:51:38 +00:00
philippe44
a81d0e0513 fix opus & vorbis last decode 2022-11-10 23:05:17 -08:00
Andy Boff
6c524cd094 Implement mpr121 touch sensor capability to GPIO Expanders (#192)
Co-authored-by: Andy Boff <gitdev@plek.me.uk>
2022-10-22 00:55:04 -04:00
Olecorp
e34cec1ad1 Update services.c (#189)
Reset pin config before use. Some pins (like GPIO14, JTAG TMS by default) wont work without this.
2022-10-19 22:48:20 -04:00
Sébastien
a2c16decee Adjust artifacts target folder [skip actions] 2022-10-11 11:35:15 -04:00
github-actions
d06893c43d Update prebuilt objects [skip actions] 2022-10-07 19:51:07 +00:00
Sebastien L
aecaed4a5f WIP Workflow [skip actions] 2022-10-07 15:47:49 -04:00
github-actions
113a75a61d Update prebuilt objects [skip actions] 2022-10-07 19:42:11 +00:00
Sébastien
f721d140e7 WIP Workflow [skip actions] 2022-10-07 15:39:27 -04:00
Sébastien
46848b3afe WIP Workflow [skip actions] 2022-10-07 15:37:21 -04:00
Sébastien
3d63670499 WIP Workflow [skip actions] 2022-10-07 15:31:52 -04:00
Sébastien
83114861c5 WIP Workflow [skip actions] 2022-10-07 15:30:12 -04:00
Sebastien L
5e7ab93e4a WIP Workflow [skip actions] 2022-10-07 15:29:05 -04:00
Sebastien L
2c56f2d7ae WIP Workflow [skip actions] 2022-10-07 15:27:20 -04:00
Sebastien L
c62e719c11 WIP Workflow [skip actions] 2022-10-07 15:05:21 -04:00
Sebastien L
0226355ab7 Create web_deploy.yml [skip actions] 2022-10-07 14:57:30 -04:00
Sebastien L
42bee2a7b0 WIP Workflow [skip actions] 2022-10-07 14:54:50 -04:00
Sebastien L
130f54526f WIP Workflow [skip actions] 2022-10-07 14:41:43 -04:00
Sebastien L
f14f2debc3 Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3 2022-10-07 14:40:25 -04:00
github-actions
25772c9ccb WIP Workflow [skip actions] 2022-10-07 14:40:19 -04:00
github-actions
1ae1b03fc3 Update prebuilt objects [skip actions] 2022-10-07 18:31:58 +00:00
Sebastien L
08ff02dc3c Update prebuilt objects [skip actions] 2022-10-07 14:28:33 -04:00
Sebastien L
3f4df9a348 Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3 2022-10-06 13:05:12 -04:00
github-actions
bb70ea1eaa Update prebuilt objects [skip actions] 2022-10-06 13:05:03 -04:00
github-actions
c0e8e36221 Update prebuilt objects [skip actions] 2022-10-06 16:54:31 +00:00
Sebastien L
4c94042c1d Update BuildTest.yml [skip actions] 2022-10-06 12:51:33 -04:00
Sebastien L
66be31a76c Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3 2022-10-06 12:49:35 -04:00
Sebastien L
5a53011383 Update BuiltTest.yml [skip actions] 2022-10-06 12:49:27 -04:00
Sebastien L
9ca1b87919 Update BuiltTest.yml [skip actions] 2022-10-06 12:44:19 -04:00
Sebastien L
2698577592 Update BuildTest.yml [skip actions] 2022-10-06 11:44:18 -04:00
Sebastien L
f70f973ca9 Allow dispatch options to control build [skip actions] 2022-10-06 11:31:43 -04:00
Sebastien L
83592b7079 WIP workflow [skip actions] 2022-10-06 11:16:05 -04:00
github-actions
2967723fdf Update prebuilt objects [skip actions] 2022-10-06 14:37:41 +00:00
Sébastien
d6e75dc71e Update BuildTest.yml [skip actions] 2022-10-06 10:32:35 -04:00
github-actions
fc50d55a27 Update prebuilt objects [skip actions] 2022-10-06 14:17:54 +00:00
Sebastien L
4fff2f0dc1 Squash some commits [skip actions] 2022-10-06 09:54:07 -04:00
Sebastien L
027d81af21 Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3 2022-10-06 09:53:03 -04:00
github-actions
96a2581534 Update prebuilt objects [skip actions] 2022-10-06 09:52:20 -04:00
Sébastien
461486ce21 Update BuildTest.yml
Update BuildTest.yml
Update build tools
Update BuildTest.yml
Update BuildTest.yml
Update BuildTest.yml
Update BuildTest.yml
Update BuildTest.yml
Update BuildTest.yml [skip actions]
Update BuildTest.yml [skip actions]
Update prebuilt objects [skip actions]

Update prebuilt objects [skip actions]

Update prebuilt objects [skip actions]

Update Build test [skip actions]
2022-10-06 09:52:20 -04:00
github-actions
7f0bc6c2ba Update prebuilt objects [skip actions] 2022-10-06 03:21:20 +00:00
Sébastien
551db4a7d1 Update Build test [skip actions] 2022-10-05 23:16:32 -04:00
github-actions
eee3123eba Update prebuilt objects [skip actions] 2022-10-06 03:13:55 +00:00
github-actions
d1a5e0aaa6 Update prebuilt objects [skip actions] 2022-10-06 02:46:59 +00:00
github-actions
e6d9c5f5a3 Update prebuilt objects [skip actions] 2022-10-05 19:46:26 +00:00
Sébastien
8164ccacaa Update BuildTest.yml [skip actions] 2022-10-05 15:41:09 -04:00
Sébastien
b2ceb8c0e3 Update BuildTest.yml [skip actions] 2022-10-05 15:35:01 -04:00
Sébastien
2e66a6a6cb Update BuildTest.yml 2022-10-05 15:26:00 -04:00
Sébastien
ac1817f4d3 Update BuildTest.yml 2022-10-05 15:22:40 -04:00
Sébastien
1d4bd8274b Update BuildTest.yml 2022-10-05 15:15:05 -04:00
Sébastien
58af548252 Update BuildTest.yml 2022-10-05 15:10:46 -04:00
Sébastien
c400f4467e Update BuildTest.yml 2022-10-05 14:55:09 -04:00
Sebastien L
24c69a70d2 Update build tools 2022-10-05 14:41:41 -04:00
Sébastien
0ce4e9e240 Update BuildTest.yml 2022-10-05 13:16:43 -04:00
Sébastien
b50caddb39 Update BuildTest.yml 2022-10-05 12:34:39 -04:00
Sébastien
639ed446f5 Update BuildTest.yml 2022-10-05 12:28:55 -04:00
Sebastien L
06b65f6f6c Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3 2022-10-05 12:25:59 -04:00
Sebastien L
f70cd0eeb1 Push a test build script for github actions 2022-10-05 12:24:31 -04:00
github-actions
95018f39e8 Update prebuilt objects [skip actions] 2022-10-05 16:10:26 +00:00
github-actions
c8e999590d Update prebuilt objects [skip actions] 2022-10-05 15:24:44 +00:00
github-actions
b640ff1c88 Update prebuilt objects [skip actions] 2022-10-05 15:08:49 +00:00
github-actions
bfe1be3c99 Update prebuilt objects [skip actions] 2022-10-05 14:57:02 +00:00
github-actions
9416c6916a Update prebuilt objects 2022-10-05 14:04:23 +00:00
philippe44
f23116d2c6 GH desktop thought it was smart to CRLF all the pull 2022-09-26 19:58:50 -07:00
philippe44
ff1d276148 Update plugin (credits @mherger) 2022-09-25 11:32:11 -07:00
philippe44
c143ea56ff protobuf generation still fails, bypass it - release 2022-09-24 23:31:35 -07:00
philippe44
3fc7e68163 release 2022-09-24 23:18:55 -07:00
philippe44
2dea2ca08c Merge branch 'master-v4.3' of https://github.com/sle118/squeezelite-esp32 into master-v4.3 2022-09-24 23:17:17 -07:00
philippe44
2584026e5c Merge pull request #180 from michaelherger/eq-preview
Enable live EQ preview in Material skin (and Classic/EN)
2022-09-24 23:13:29 -07:00
philippe44
f2b0c40848 fix potential cspot on socket timeout & optimize HTTP server - release 2022-09-24 23:11:20 -07:00
Michael Herger
1876b26100 Enable live EQ preview in Material skin (and Classic/EN)
* add JavaScript to submit the changes before storing them
* add input validation
* fix settings page loading in case of networking issues (which I suffered from when I tried to implement the above :-))
2022-09-24 18:42:02 +02:00
philippe44
f84e856e68 update cmake files 2022-09-22 16:42:22 -07:00
Sebastien
34fa7203be Handle known connection events 2022-09-20 09:24:39 -04:00
philippe44
751d683b3e muse called abort() w/o necessity (can silently ignore RMT errors) - release 2022-09-18 00:13:57 -07:00
philippe44
b000bbd383 limit CSPOT buffering of decoded audio for less plops & lag - release 2022-09-17 10:00:56 -07:00
philippe44
6f504839bb add TJPGD directory - release 2022-09-16 23:04:12 -07:00
philippe44
b48e9fe1fa just create empty cspot_config at first boot - release 2022-09-16 22:52:24 -07:00
philippe44
eb6b99d461 no workaround to use ROM version of TJPGD (loosing 5kB of flash) 2022-09-15 14:05:16 -07:00
philippe44
405c7742ef use TJPGD in flash 2022-09-15 13:47:32 -07:00
philippe44
eab321d233 release 2022-09-13 23:53:42 -07:00
philippe44
50475e9305 release 2022-09-13 23:52:49 -07:00
philippe44
a1e15abba7 Merge branch 'master-v4.3' of https://github.com/sle118/squeezelite-esp32 into master-v4.3 2022-09-13 23:51:29 -07:00
philippe44
7e733f4fa9 Was using wrong protobuf - release 2022-09-13 23:51:26 -07:00
philippe44
3e35937272 syntax error in yaml - release 2022-09-12 20:12:52 -07:00
philippe44
2d9dd14e06 exclude 32 bits build for Muse 2022-09-12 19:55:34 -07:00
philippe44
698cc70aa3 release 2022-09-12 19:46:25 -07:00
philippe44
6e67606a07 Merge branch 'master-v4.3' of https://github.com/sle118/squeezelite-esp32 into master-v4.3 2022-09-12 19:45:53 -07:00
philippe44
f6f2f612a1 Allow AudioChunkManager to use PSRAM stack - release 2022-09-12 19:45:46 -07:00
philippe44
60bf802f3f change build number in ... 4.3 - release 2022-09-12 15:05:57 -07:00
philippe44
f7c9f08071 release 2022-09-12 14:46:06 -07:00
philippe44
9be4593d81 Tweak for JPEG - release 2022-09-12 14:16:02 -07:00
philippe44
922889fee2 try to fix misc cspot issues + silence network manager log 2022-09-12 11:54:49 -07:00
philippe44
a8e28f9ff0 espressif's patch for SPI concurrent issue + fix override mechanismi 2022-09-08 13:34:06 -07:00
philippe44
1fcda53941 fix 32 bist in AC101 and ES8388 2022-08-29 17:40:00 -07:00
philippe44
0222dbd6de update CSpot + clear audio buffer when changing track 2022-08-23 17:06:59 -07:00
Sébastien
36f18fc069 Bump to trigger build 2022-06-05 08:30:48 -04:00
Sebastien L
12f9b1eae8 Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3 2022-03-05 10:31:38 -05:00
Sebastien L
16225ed8c9 Fix credits and status page not showing 2022-03-05 10:31:27 -05:00
philippe44
57b77766ff update CSpot 2022-03-04 20:06:19 -08:00
philippe44
7b1d1ad45e fix color swap 2022-02-28 13:56:42 -08:00
Sebastien L
b191ea6ec1 Update Docker to use idf 4.3.2 2022-02-28 11:58:18 -05:00
Sebastien L
70e194e763 Added display invert Web ui option 2022-02-28 11:28:09 -05:00
Sebastien L
828c28720f Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3 2022-02-28 11:16:37 -05:00
philippe44
dd519b9229 add color swap BGR/RGB and generalize invert option 2022-02-27 14:34:11 -08:00
philippe44
54d7e222d0 fix CLI structure 2022-02-26 17:53:01 -08:00
philippe44
23a5f7fbe4 tweak muse color + add "invert" option 2022-02-26 17:37:08 -08:00
Sebastien L
3eab93b595 Network manager WIP 2022-02-25 14:23:56 -05:00
Sebastien L
bda4c18abe Merge branch 'tmp' into master-v4.3 2022-02-25 14:18:49 -05:00
Philippe G
72b66054b1 debounce is 50ms default, .defaults has always been overwritten by build params.... 2022-02-03 23:14:10 -08:00
Philippe G
9da735da95 update AMP_GPIO 2022-02-02 11:35:04 -08:00
Sebastien L
168eb061af Try to speed up the build 2022-02-01 07:59:23 -05:00
Sebastien L
c9adf6320b Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3 2022-02-01 06:48:26 -05:00
Sebastien L
7fd87eeba5 Fixing bugs 2022-01-31 21:52:57 -05:00
philippe44
042169e7eb Update CrossBuild.yml 2022-01-29 13:47:08 -08:00
Sebastien L
68e7512073 Change script permissions to run on Github Actions 2022-01-29 12:03:04 -05:00
Sebastien L
a5da6bbcf1 Many many many changes to update the UI. It hurts... 2022-01-28 22:11:09 -05:00
philippe44
44829ae59f Update CrossBuild.yml 2022-01-28 18:33:41 -08:00
Philippe G
882ed4dce9 update battery scale for muse 2022-01-28 18:21:52 -08:00
Sebastien L
28dba930c7 .3: Auto stash before merge of "master-v4.3" and "origin/master-v4.3" 2022-01-27 21:03:32 -05:00
Sebastien L
5ee2bc318e Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3 2022-01-27 20:57:14 -05:00
Sebastien L
7fcb201b06 UI Migration to Webpack+Bootstrap etc latest version 2022-01-27 20:57:03 -05:00
Philippe G
839f31d485 fix target config priority between NVS and dedicated builds 2022-01-26 15:09:25 -08:00
Philippe G
6d1cf28fd6 tweaks 2022-01-26 12:41:39 -08:00
Philippe G
8e6d409311 use muse built-in keyboard definition 2022-01-26 02:30:31 -08:00
Philippe G
eb3a8f76da really add battery led at boot 2022-01-24 16:10:43 -08:00
Philippe G
cf4ed64eb0 muse long_press & battery read at boot 2022-01-24 16:08:00 -08:00
Philippe G
3d8055a948 Merge branch 'master-v4.3' of https://github.com/sle118/squeezelite-esp32 into master-v4.3 2022-01-23 00:01:59 -08:00
Philippe G
0052ff9625 add battery led 2022-01-23 00:01:55 -08:00
Sebastien L
977935015e Update webpack and web ui to recent versions, bug fixes 2022-01-21 17:02:34 -05:00
Sebastien L
bd63723189 Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3 2022-01-21 17:01:27 -05:00
Philippe G
9185acf513 Merge branch 'master-v4.3' of https://github.com/sle118/squeezelite-esp32 into master-v4.3 2022-01-21 11:24:51 -08:00
Philippe G
6f28153a3f port default audio_controls in 4.3 2022-01-21 11:24:46 -08:00
Sebastien L
b79e1f9391 Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3 2022-01-21 08:34:56 -05:00
philippe44
9843d404bd Update CrossBuild.yml 2022-01-20 17:42:59 -08:00
Philippe G
47774c98f0 make targets "loadable" 2022-01-20 17:34:21 -08:00
Sebastien L
285225401c Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3 2022-01-20 19:35:19 -05:00
philippe44
1b74c82c72 Update esp-idf-v4.3-build.yml 2022-01-20 16:19:27 -08:00
Philippe G
f1d9e32f2c Muse volume 2022-01-20 16:05:14 -08:00
Philippe G
d16e7eed09 add Muse configscript 2022-01-20 13:12:29 -08:00
Sebastien L
89b4b5ca2d Merge remote-tracking branch 'origin/master-v4.3' into master-v4.3 2022-01-20 13:45:36 -05:00
Sebastien L
15c0e47ae3 Network WIP 2022-01-20 13:43:23 -05:00
Philippe G
d1dd27b7cb add Muse support 2022-01-19 13:40:03 -08:00
Philippe G
750e455b0d targets 2022-01-19 01:16:49 -08:00
Philippe G
533ee5e408 backend for Muse 2022-01-19 00:51:35 -08:00
Philippe G
de025602ac fix equalizer in NVS 2022-01-15 00:54:11 -08:00
Philippe G
396366b509 CSpot copyright 2022-01-13 18:48:29 -08:00
Philippe G
60584ae207 no more clicks on SPDIF & CSpot 2022-01-13 18:21:36 -08:00
Philippe G
3fb1c16f56 get ready for 4.4 2022-01-13 13:08:45 -08:00
Philippe G
4420f7da4d remove warnings (except CSpot ones) 2022-01-12 18:29:03 -08:00
Philippe G
1b83d0eb5f fix prio 2022-01-12 18:10:46 -08:00
Philippe G
b2741b5bef duration is now 1ms units & don't get cspot artwork when display disabled 2022-01-11 20:15:16 -08:00
Philippe G
04919f7b6e change priorities and force spdif_convert in IRAM 2022-01-11 14:44:06 -08:00
Philippe G
8fa3906b52 updated CSpot 2022-01-10 12:11:21 -08:00
Philippe G
72657d6951 simplify artwork and bypass server certificate verification 2022-01-10 11:24:19 -08:00
Philippe G
f09a95cc8b artwork for Spotify 2022-01-10 00:46:56 -08:00
Philippe G
3125a095fa airplay artwork and CSpot leak fix (temporary) 2022-01-09 19:40:18 -08:00
Philippe G
e9da432bfc more CSpot catchup 2022-01-07 19:16:55 -08:00
Philippe G
052600a45a add missing files 2022-01-06 18:56:27 -08:00
Philippe G
9af4cd5b23 catching up (trying to) wiht CSpot 2022-01-06 18:46:57 -08:00
Philippe G
491d0d260d set timeout for ethernet/dhcp to 30s 2022-01-05 19:38:35 -08:00
Philippe G
c1b39610fc fix LAN8720 2022-01-05 19:30:39 -08:00
Philippe G
f95ec33457 fix "join" command 2022-01-05 17:06:03 -08:00
Philippe G
fb24168d99 SOme displays needs to adjust CS_post for speed 2022-01-05 11:58:47 -08:00
Philippe G
28ac503ef7 tweaks 2022-01-04 21:55:35 -08:00
Philippe G
0127428a15 add SPI display's CS pre/post 2022-01-04 21:19:37 -08:00
Sebastien L
df8d31c679 don't try caching docker 2022-01-04 21:42:58 -05:00
Sebastien L
f2f578a719 that didn't work 2022-01-04 21:40:40 -05:00
Sebastien L
e6046fa343 one more attempt 2022-01-04 21:33:32 -05:00
Philippe G
7959850970 and more crap again... 2022-01-04 17:32:28 -08:00
Philippe G
54440e87b6 more crap 2022-01-04 17:22:32 -08:00
Philippe G
47ad526890 more nanopb 2022-01-04 17:10:54 -08:00
Philippe G
d81e95c94a protobug generation optional 2022-01-04 17:02:31 -08:00
Philippe G
bf24735422 Merge branch 'master-v4.3' of https://github.com/sle118/squeezelite-esp32 into master-v4.3 2022-01-04 15:09:30 -08:00
Philippe G
685ac92f6e more memory leaks fixes 2022-01-04 15:09:26 -08:00
Sebastien L
5cad1aeed6 more logs 2022-01-04 17:27:40 -05:00
Sebastien L
9e21e302b8 more attempts to figure out permissions 2022-01-04 17:16:30 -05:00
Sebastien L
3a99c65eb3 Add verbosity to protogen 2022-01-04 17:12:51 -05:00
Sebastien L
e5516db60f Merge branch 'master-v4.3' of https://github.com/sle118/squeezelite-esp32 into master-v4.3 2022-01-04 17:02:11 -05:00
Sebastien L
c8430bcfa2 more permissions! 2022-01-04 17:02:08 -05:00
Philippe G
97793ceea8 Merge branch 'master-v4.3' of https://github.com/sle118/squeezelite-esp32 into master-v4.3 2022-01-04 13:52:49 -08:00
Philippe G
e59188ec44 non-crashing CSpot + spi_master and override fixes 2022-01-04 13:52:45 -08:00
Sebastien L
bea28a0a90 Some more permissions to add 2022-01-04 16:32:53 -05:00
Sebastien L
c612410a3b update permissions on protoc-gen-nanopb 2022-01-04 16:22:21 -05:00
Sebastien L
cdf6e88362 Try to fix cache for build 2022-01-04 14:52:45 -05:00
Sebastien L
edb830f7b2 Fix permission for protoc generation 2022-01-04 14:36:57 -05:00
Philippe G
33c7ba820d chmod 2022-01-04 11:27:56 -08:00
Philippe G
39f5a81238 add nanopb (manual) 2022-01-04 11:01:14 -08:00
Philippe G
06b637c55b idf overriding method to bring back SPDIF and fix SPI + new CSPOT (which crashes) 2022-01-04 00:15:33 -08:00
Philippe G
cf1315e6a4 tweak KConfig to reset defaults
(don't forget to remove ".old" file
2022-01-02 17:51:07 -08:00
Philippe G
59cc5a5a70 cspot conditional 2022-01-02 15:17:52 -08:00
Philippe G
6dbefa5a76 had to replace the full sdkconfigs. Diff, even with .js is too painful 2022-01-02 14:07:35 -08:00
philippe44
a31a31a414 forced update 2022-01-02 11:53:28 -08:00
philippe44
e71672cf49 release 2022-01-02 11:47:47 -08:00
philippe44
6e1dbe5021 Update I2S-4MFlash-sdkconfig.defaults 2022-01-02 11:47:24 -08:00
Sebastien L
aa1cfdd6b2 minor fixes, remove wifi scan mode from config 2022-01-01 21:12:08 -05:00
Philippe G
7bf1ede250 dm9501 is not a RMII + CS delay option for displays 2022-01-01 17:56:51 -08:00
Philippe G
25249ce13e BT source improvment, GPIO expander intr fix, SPI display improvments 2021-12-31 17:49:43 -08:00
Sébastien
756d930912 Update README.md 2021-12-29 23:14:33 -05:00
Sebastien L
a93bd3c187 temp fix network manager log verbosity 2021-12-29 15:08:24 -05:00
Philippe G
f076a7260e make some squeezelite symbol weak to force removal from recovery during link 2021-12-28 20:04:24 -08:00
Sebastien L
9b20001c97 fix missing double quote in script 2021-12-28 13:19:56 -05:00
Sebastien L
6cdd2d302f Update webapp build steps 2021-12-28 13:13:11 -05:00
Sebastien L
b2ec1506d7 Update build system, add cspot service option 2021-12-28 12:43:29 -05:00
Philippe G
f3c405579f can't shift by more or equal to length... 2021-12-27 22:01:55 -08:00
Philippe G
2332e22d99 fonts 2021-12-27 19:34:06 -08:00
Philippe G
a40d7f5caa removing 1 font 2021-12-27 19:15:32 -08:00
Philippe G
d7d47d1127 unique UUID per CSPOT player 2021-12-27 14:49:12 -08:00
Philippe G
51c178ca46 duration unit change 2021-12-26 17:45:55 -08:00
Philippe G
e85733fc32 cspot duration 2021-12-26 15:48:25 -08:00
Philippe G
676acbdbc2 fixed cspot crash when switching with LMS 2021-12-25 23:05:53 -08:00
Philippe G
1422003271 player stop logic fix 2021-12-25 00:38:56 -08:00
Philippe G
7f894f1635 finhsing CSpot integration 2021-12-24 21:56:42 -08:00
Philippe G
e2bcb041e9 fixing memory leaks 2021-12-24 12:35:32 -08:00
Philippe G
5aca6f974c free mbedtls 2021-12-24 01:25:45 -08:00
Philippe G
523127bdea lock syntax error 2021-12-24 01:09:34 -08:00
Philippe G
662962ddb1 alignment with cspot 2021-12-23 11:55:51 -08:00
Philippe G
c68919d2d1 use pthread default priority for Mercury 2021-12-23 00:33:29 -08:00
Philippe G
b79878f590 Mercury should not reconnect when stopped 2021-12-23 00:23:09 -08:00
Philippe G
dc1e258d64 use network manager events for AirPlay and Spotify
- split network_manager.h in two parts
- centralize mDNS
2021-12-22 18:41:49 -08:00
Philippe G
d914e68a9b more fixes 2021-12-22 15:10:42 -08:00
Philippe G
9dfe90c26f alignment to 4.0 + misc cspot fixes 2021-12-22 12:15:05 -08:00
Philippe G
80270b772b only update VU/spectrum if we own the display 2021-12-21 01:05:28 -08:00
Philippe G
e16b7dd15b squeezelite must be on pthread core + BT sink start in internal stack 2021-12-20 23:35:47 -08:00
Philippe G
088825102e fix stack depth & memory issues when using telnet 2021-12-20 17:09:23 -08:00
Sebastien L
a354e6248a Move a few network manager parameters to nvs config 2021-12-19 09:57:57 -05:00
Philippe G
9a37d9dba4 Spotify over Ethernet! 2021-12-18 23:45:59 -08:00
Philippe G
898998efb0 big merge 2021-12-18 21:04:23 -08:00
Sébastien
955692f8ad Update esp-idf-v4.3-build.yml 2021-12-17 10:00:19 -05:00
Sebastien L
c0fc0c0276 Merge remote-tracking branch 'origin/ethernet_idf4.3' into ethernet_idf4.3 2021-12-17 09:58:46 -05:00
Sebastien L
49de5b8f23 Update actions config file one more time! 2021-12-17 09:58:38 -05:00
Sebastien L
a326699d76 Update actions config file one more time! 2021-12-17 09:56:45 -05:00
Sebastien L
efefb266f9 Fix state machine compile errors 2021-12-17 09:46:14 -05:00
Sebastien L
a9cc5c7b55 Merge branch 'ethernet_idf4.3' of https://github.com/sle118/squeezelite-esp32 into ethernet_idf4.3 2021-12-17 09:35:17 -05:00
Sebastien L
d0bcc72bce Update config scripts and compare tool 2021-12-17 09:34:56 -05:00
Sébastien
a569b2a82e Update esp-idf-v4.3-build.yml 2021-12-15 14:49:47 -05:00
Sebastien L
3a89597ff0 Merge branch 'ethernet_idf4.3' of https://github.com/sle118/squeezelite-esp32 into ethernet_idf4.3 2021-12-15 14:46:08 -05:00
Sebastien L
8892d66f9e Update build scripts with ethernet support 2021-12-15 14:45:50 -05:00
Sébastien
a7469e5258 update idf version - one more time 2021-12-15 13:06:46 -05:00
Sébastien
0e33e112ae update build script to esp-idf v4.3.1 2021-12-15 13:00:17 -05:00
Sebastien L
626303e563 One more time... 2021-12-10 16:31:11 -05:00
Sebastien L
f7dfb1d695 Fix Build Script 2021-12-10 16:26:44 -05:00
Sebastien L
0e89f988cd Update build scripts 2021-12-10 16:24:37 -05:00
Sebastien L
732f5cb793 Kicking off build 2021-12-10 16:17:38 -05:00
Sebastien L
e6b7ed28e7 Included sub-module for state machine 2021-12-10 16:06:57 -05:00
Sebastien L
2e061f5cec Added TTGO T-Watch to Presets 2021-12-10 15:45:53 -05:00
Sebastien L
f8903770c2 fix Preset options, cleanup 2021-12-10 15:36:59 -05:00
Sebastien L
63fbc2f645 Network manager implemented and relatively stable 2021-12-10 13:07:27 -05:00
Sebastien L
81756a7649 cpp state machine for ethernet 2021-11-16 10:11:38 -05:00
Sebastien L
699c1da42f Merge branch 'master-cmake' into Ethernet 2021-11-08 16:19:36 -05:00
Philippe G
2a6f5c8a10 add "MISO" to SPI system config 2021-10-31 16:14:33 -07:00
Philippe G
2805629c4b add SPI ethernet 2021-10-31 14:47:28 -07:00
Philippe G
97ae01b89f ethernet sample 2021-10-30 18:00:56 -07:00
1319 changed files with 145158 additions and 9395 deletions

232
.github/workflows/BuildTest.yml vendored Normal file
View File

@@ -0,0 +1,232 @@
name: Manually executable test for ESP-IDF v4.3.1
on:
workflow_dispatch:
inputs:
ui_build:
description: 'Force Rebuilding the UI. When not forced, the system will check for [ui-build] in the last commit message to trigger a ui rebuild'
required: true
type: boolean
release_build:
description: 'Force a Release build. When not forced, the system will check for release word in the last commit message to trigger a release'
required: true
type: boolean
# push:
# branches:
# - '**4.3'
jobs:
bootstrap:
name: Global setup
runs-on: ubuntu-latest
container:
image: sle118/squeezelite-esp32-idfv43
outputs:
build_number: ${{ steps.buildnumber.outputs.build_number }}
ui_build: ${{ steps.build_flags.outputs.ui_build }}
release_flag: ${{ steps.build_flags.outputs.release_flag }}
mock: ${{ steps.build_flags.outputs.mock }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: true
- name: Generate common build number
id: buildnumber
uses: einaregilsson/build-number@v3
with:
token: ${{secrets.github_token}}
- name: Set build flags
id: build_flags
run: |
git config --global --add safe.directory /__w/squeezelite-esp32/squeezelite-esp32
[ ${{github.event.inputs.ui_build}} ] && ui_build_option="--ui_build" || ui_build_option=""
[ ${{github.event.inputs.release_build}} ] && release_build_option="--force" || release_build_option=""
echo "ui_build_option=$ui_build_option" >> $GITHUB_ENV
echo "release_build_option=$release_build_option" >> $GITHUB_ENV
echo "Dumping environment"
env
. /opt/esp/python_env/idf4.3_py3.8_env/bin/activate
# build_flags support the following options
# --mock - to mock the compilation part - this is to be used for testing only
# --force - to force a release build even if the last commit message doesn't contain the word "release"
# --ui_build - to force a ui_build even if the last commit message doesn't contain "[ui-build]"
build_tools.py build_flags $ui_build_option $release_build_option
- name: Show Build Flags
run: |
echo "Running with the following options"
echo "Web Build Flag=${{steps.build_flags.outputs.ui_build}}"
echo "Mock flag=${{steps.build_flags.outputs.mock}}"
echo "Release Flag=${{steps.build_flags.outputs.release_flag}}"
- name: Refresh certificates
if: ${{ steps.build_flags.outputs.release_flag }}
run: |
git update-index --chmod=+x ./server_certs/getcert.sh
cd server_certs;./getcert.sh;cat github.pem;cd ..
- name: Setup Node.js dependencies
if: ${{ !env.ACT }}
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
cache-dependency-path: components/wifi-manager/webapp/package.json
- name: Build Web Application
if: ${{ steps.build_flags.outputs.ui_build == 1 }}
run: |
cd components/wifi-manager/webapp/
npm install
npm run-script build
- name: Update repository with prebuilt items
if: ${{ steps.build_flags.outputs.ui_build == 1 || steps.build_flags.outputs.release_flag == 1 }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add server_certs
git add components/wifi-manager/webapp/*.h
git add components/wifi-manager/webapp/*.c
git add components/wifi-manager/webapp/*.cmake
git add components/wifi-manager/webapp/dist/*
git commit -m "Update prebuilt objects [skip actions]"
git push https://${{secrets.github_token}}@github.com/sle118/squeezelite-esp32.git
- name: Locally store commonly built objects
uses: actions/upload-artifact@v3
with:
name: prebuilt_objects
path: |
server_certs
components/wifi-manager/webapp/*.h
components/wifi-manager/webapp/*.c
components/wifi-manager/webapp/dist/*
components/wifi-manager/webapp/*.cmake
build:
runs-on: ubuntu-latest
container:
image: sle118/squeezelite-esp32-idfv43
needs: [bootstrap]
strategy:
matrix:
node: [I2S-4MFlash, SqueezeAmp, Muse]
depth: [16, 32]
exclude:
- node: Muse
depth: 32
- node: bootstrap
depth: 32
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: true
- name: Show Build Flags
run: |
echo "Running with the following options"
echo "Web Build Flag=${{needs.bootstrap.outputs.ui_build}}"
echo "Mock flag=${{needs.bootstrap.outputs.mock}}"
echo "Release Flag=${{needs.bootstrap.outputs.release_flag}}"
echo Environment File name: $GITHUB_ENV
- name: Set build parameters
run: |
. /opt/esp/python_env/idf4.3_py3.8_env/bin/activate
git config --global --add safe.directory /__w/squeezelite-esp32/squeezelite-esp32
git status
build_tools.py environment --build ${{ needs.bootstrap.outputs.build_number }} --env_file "$GITHUB_ENV" --node "${{matrix.node}}" --depth ${{matrix.depth}} --major 2 --docker sle118/squeezelite-esp32-idfv43
- uses: actions/download-artifact@master
name: Restore common objects
with:
name: prebuilt_objects
- name: Build the firmware
if: ${{ needs.bootstrap.outputs.mock == 0 }}
run: |
. ${IDF_PYTHON_ENV_PATH}/bin/activate
chmod +x ./components/spotify/cspot/bell/nanopb/generator/protoc
chmod +x ./components/spotify/cspot/bell/nanopb/generator/protoc-gen-nanopb
chmod +x ./components/spotify/cspot/bell/nanopb/generator/*.py
chmod +x ./components/spotify/cspot/bell/nanopb/generator/*.py2
chmod +x ./components/spotify/cspot/bell/nanopb/generator/proto/*.py
echo "Copying target sdkconfig"
cp build-scripts/${TARGET_BUILD_NAME}-sdkconfig.defaults sdkconfig
echo "Building project"
idf.py build -DDEPTH=${DEPTH} -DBUILD_NUMBER=${BUILD_NUMBER}-${DEPTH}
- name: Build Mock firmware
if: ${{ needs.bootstrap.outputs.mock == 1 }}
run: |
mkdir -p build
cd build
mkdir -p partition_table
mkdir -p bootloader
echo \\"mock content\\"> ./squeezelite.bin
echo \"mock content\"> ./recovery.bin
echo \"mock content\"> ./bootloader/bootloader.bin
echo \"mock content\"> ./partition_table/partition-table.bin
echo \"mock content\"> ./ota_data_initial.bin
echo \"mock content\"> ./flash_project_args
echo \"mock content\"> ./size_comp1.txt
echo \"mock content\"> ./size_comp2.txt
echo \"mock content\"> ./partitions.csv
echo { \"write_flash_args\" : [ \"--flash_mode\", \"dio\", \"--flash_size\", \"detect\", \"--flash_freq\", \"80m\" ], \"flash_settings\" : { \"flash_mode\": \"dio\", \"flash_size\": \"detect\", \"flash_freq\": \"80m\" }, \"flash_files\" : { \"0x8000\" : \"partition_table/partition-table.bin\", \"0xd000\" : \"ota_data_initial.bin\", \"0x1000\" : \"bootloader/bootloader.bin\", \"0x10000\" : \"recovery.bin\", \"0x150000\" : \"squeezelite.bin\" }, \"partition_table\" : { \"offset\" : \"0x8000\", \"file\" : \"partition_table/partition-table.bin\" }, \"otadata\" : { \"offset\" : \"0xd000\", \"file\" : \"ota_data_initial.bin\" }, \"bootloader\" : { \"offset\" : \"0x1000\", \"file\" : \"bootloader/bootloader.bin\" }, \"app\" : { \"offset\" : \"0x10000\", \"file\" : \"recovery.bin\" }, \"squeezelite\" : { \"offset\" : \"0x150000\", \"file\" : \"squeezelite.bin\" }, \"extra_esptool_args\" : { \"after\" : \"hard_reset\", \"before\" : \"default_reset\" } } > ./flasher_args.json
- name: Create Release Artifact Zip
if: ${{ needs.bootstrap.outputs.release_flag == 1 && needs.bootstrap.outputs.mock == 0 }}
run: |
if [ -z "${artifact_file_name}" ]
then
echo "No artifact file name set. Will not generate zip file."
else
echo "Generating build artifact zip file"
zip -r build_output.zip build
zip build/${artifact_file_name} partitions*.csv components/ build/*.bin build/bootloader/bootloader.bin build/partition_table/partition-table.bin build/flash_project_args build/size_*.txt
fi
- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
if: ${{ needs.bootstrap.outputs.mock == 0 }}
with:
name: ${{ env.artifact_prefix }}
path: |
build/flash_project_args
build/size_comp1.txt
build/size_comp2.txt
partitions.csv
sdkconfig
server_certs/github.pem
build/*.bin
build/bootloader/bootloader.bin
build/partition_table/partition-table.bin
build_output.zip
- name: Create Release
if: ${{ needs.bootstrap.outputs.release_flag == 1 && needs.bootstrap.outputs.mock == 0 }}
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ env.tag }}
release_name: ${{ env.name }}
body: ${{ env.description }}
draft: false
prerelease: true
- name: Upload Release Asset - Squeezelite binary file
if: ${{ needs.bootstrap.outputs.release_flag == 1 && needs.bootstrap.outputs.mock == 0 }}
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: build/squeezelite.bin
asset_name: ${{ env.artifact_bin_file_name }}
asset_content_type: application/octet-stream
- name: Upload Release Asset - Zip file
if: ${{ needs.bootstrap.outputs.release_flag == 1 && needs.bootstrap.outputs.mock == 0 }}
id: upload-release-asset-zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: build/${{ env.artifact_file_name }}
asset_name: ${{ env.artifact_file_name }}
asset_content_type: application/octet-stream
update_web_installer:
name: Update Web Installer After Release
needs: [ bootstrap, build ]
if: ${{( always() && !cancelled() ) && needs.bootstrap.outputs.release_flag == 1 && needs.bootstrap.outputs.mock == 0 }}
uses: ./.github/workflows/web_deploy.yml

View File

@@ -1,13 +1,15 @@
# This is a basic workflow to help you get started with Actions
name: Cross-Build
on:
push:
branches:
- 'master-cmake'
- '!**4.3'
pull_request:
branches:
- 'master-cmake'
- '!**4.3'
jobs:
job1:
name: Build Number

View File

@@ -27,11 +27,14 @@ jobs:
matrix:
node: [I2S-4MFlash, SqueezeAmp, Muse]
depth: [16, 32]
exclude:
- node: Muse
depth: 32
steps:
- name: Set target name
run: |
echo "TARGET_BUILD_NAME=${{ matrix.node }}" >> $GITHUB_ENV
echo "build_version_prefix=1." >> $GITHUB_ENV
echo "build_version_prefix=2." >> $GITHUB_ENV
- uses: actions/checkout@v2
with:
fetch-depth: 15
@@ -41,23 +44,32 @@ jobs:
uses: actions/cache@v2
with:
path: |
build
/var/lib/docker
key: idf4.3-${{ runner.os }}-${{ matrix.node }}-${{ matrix.depth }}
~/build
./
key: ${{ runner.os }}-${{ matrix.node }}
- name: Set build parameters
run: |
git update-index --chmod=+x ./server_certs/getcert.sh
git update-index --chmod=+x ./buildFirmware.sh
git update-index --chmod=+x ./components/spotify/cspot/bell/nanopb/generator/protoc
git update-index --chmod=+x ./components/spotify/cspot/bell/nanopb/generator/protoc-gen-nanopb
git update-index --chmod=+x ./components/spotify/cspot/bell/nanopb/generator/*.py
git update-index --chmod=+x ./components/spotify/cspot/bell/nanopb/generator/*.py2
git update-index --chmod=+x ./components/spotify/cspot/bell/nanopb/generator/proto/*.py
cd server_certs;./getcert.sh;cat github.pem;cd ..
shopt -s nocasematch
branch_name="${GITHUB_REF//refs\/heads\//}"
branch_name="${branch_name//[^a-zA-Z0-9\-~!@_\.]/}"
BUILD_NUMBER=${{ needs.job1.outputs.build_number }}
echo "BUILD_NUMBER=${BUILD_NUMBER}" >> $GITHUB_ENV
echo "DOCKER_IMAGE_NAME=sle118/squeezelite-esp32-idfv4-master" >> $GITHUB_ENV
tag="${TARGET_BUILD_NAME}.${{matrix.depth}}.${BUILD_NUMBER}.${branch_name}"
echo "tag=${tag}" >> $GITHUB_ENV
last_commit="$(git log --pretty=format:'%s' --max-count=1)"
if [[ "$last_commit" =~ .*"Release".* ]]; then echo "release_flag=1" >> $GITHUB_ENV; else echo "release_flag=0" >> $GITHUB_ENV; fi
name="1.${BUILD_NUMBER}-${{matrix.depth}}#v4.0#${TARGET_BUILD_NAME}#${branch_name}"
name="${build_version_prefix}${BUILD_NUMBER}-${{matrix.depth}}#v4.0#${TARGET_BUILD_NAME}#${branch_name}"
artifact_prefix="squeezelite-esp32-${branch_name}-${TARGET_BUILD_NAME}-${{matrix.depth}}-${build_version_prefix}${BUILD_NUMBER}"
artifact_file_name="${artifact_prefix}.zip"
artifact_bin_file_name="${artifact_prefix}.bin"
@@ -66,9 +78,9 @@ jobs:
echo "artifact_file_name=${artifact_file_name}" >> $GITHUB_ENV
echo "PROJECT_VER=${TARGET_BUILD_NAME}-${{ steps.buildnumber.outputs.build_number }} " >> $GITHUB_ENV
echo "artifact_bin_file_name=${artifact_bin_file_name}" >> $GITHUB_ENV
description=""
description=${description}$'------------------------------\n### Revision Log\n\n'
description="$description$(git log --pretty=format:'%h %s (%cI) <%an>' --abbrev-commit --max-count=15 | sed --r 's/(^[\*]+)/\\\1/g') "
description=$'### Revision Log\n'
githist="$(git log --pretty=format:'%h %s (%cI) <%an>' --abbrev-commit --max-count=15 | sed --r 's/(^[\*]+)/\\\1/g')"
description="$description$githist"
echo 'description<<~EOD' >> $GITHUB_ENV
echo ${description}>> $GITHUB_ENV
echo '~EOD' >> $GITHUB_ENV
@@ -83,11 +95,9 @@ jobs:
- name: Build the firmware
run: |
env | grep "artifact\|tag\|GITHUB\|version\|NUMBER\|TARGET" >${TARGET_BUILD_NAME}-env.txt
echo "${tag}" >version.txt
echo pulling docker version 4.3.1
docker pull espressif/idf:v4.3.1
docker info
docker run --env-file=${TARGET_BUILD_NAME}-env.txt -v $PWD:/project -w /project espressif/idf:v4.3.1 /bin/bash -c "cp build-scripts/${TARGET_BUILD_NAME}-sdkconfig.defaults sdkconfig && idf.py build -DDEPTH=${{ matrix.depth }} -DBUILD_NUMBER=${BUILD_NUMBER}-${{ matrix.depth }} && zip -r build_output.zip build && zip build/${artifact_file_name} partitions*.csv build/*.bin build/bootloader/bootloader.bin build/partition_table/partition-table.bin build/flash_project_args build/size_*.txt"
echo pulling custom docker image ${DOCKER_IMAGE_NAME}
docker pull ${DOCKER_IMAGE_NAME}
docker run --env-file=${TARGET_BUILD_NAME}-env.txt -v $PWD:/project -w /project ${DOCKER_IMAGE_NAME} /bin/bash -c "./buildFirmware.sh"
# - name: Build Mock firmware
# run: |
# mkdir -p build

23
.github/workflows/web_deploy.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: Update Web Installer
on:
workflow_call:
workflow_dispatch:
jobs:
update_web_installer:
name: Update Web Installer After Release
runs-on: ubuntu-latest
container:
image: sle118/squeezelite-esp32-idfv43
env:
WEB_INSTALLER: ${{ secrets.WEB_INSTALLER }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: true
- name: Update Web Installer Project
run: |
. /opt/esp/python_env/idf4.3_py3.8_env/bin/activate
git config --global --add safe.directory /__w/squeezelite-esp32/squeezelite-esp32
build_tools.py manifest --flash_file "/build/flash_project_args" --outdir "./bin_files" --manif_name "manifest" --max_count 3
build_tools.py pushinstaller --source "./bin_files" --manif_name "manifest" --target "web-installer" --url "https://github.com/sle118/squeezelite-esp32-installer.git" --artifacts "docs/artifacts" --web_installer_branch "main" --token "${{env.WEB_INSTALLER}}"

110
.gitignore vendored
View File

@@ -1,102 +1,20 @@
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.lib
# Executables
*.exe
*.out
*.app
# Build files with potential private info
build/
sdkconfig.old
# =========================
# Operating System Files
# =========================
# Windows
# =========================
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
*.save
libs/
/cdump.cmd
/_*
squeezelite-esp32-jsonblob.zip
/flash_cmd.txt
/writeSequeezeEsp.bat
/writeSequeezeEsp.sh
all_releases.json
alltags.txt
releases.json
sdkconfig
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/settings.json
.vscode/tasks.json
alltags.txt
components/wifi-manager/network_manager_handlers.multi
esp32.code-workspace
sdkconfig.old
test/.vscode/c_cpp_properties.json
test/.vscode/launch.json
test/.vscode/settings.json
test/.vscode/tasks.json
test/sdkconfig
components/wifi-manager/UML-State-Machine-in-C
*.bak
components/wifi-manager/.project
components/wifi-manager/.settings/.jsdtscope
components/wifi-manager/.settings/org.eclipse.wst.jsdt.ui.superType.container
components/wifi-manager/.settings/org.eclipse.wst.jsdt.ui.superType.name
components/wifi-manager/res/backup/
*.code-workspace
test/.vscode/
node_modules/*
esp-dsp/
envfile.txt
artifacts
web-installer

3
.gitmodules vendored
View File

@@ -5,3 +5,6 @@
[submodule "components/esp-dsp"]
path = components/esp-dsp
url = https://github.com/philippe44/esp-dsp.git
[submodule "components/wifi-manager/UML-State-Machine-in-C"]
path = components/wifi-manager/UML-State-Machine-in-C
url = https://github.com/kiishor/UML-State-Machine-in-C

View File

@@ -2,6 +2,22 @@ cmake_minimum_required(VERSION 3.5)
set(EXTRA_COMPONENT_DIRS components/platform_console/app_recovery components/platform_console/app_squeezelite )
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
add_definitions(-DMODEL_NAME=SqueezeESP32)
# State machine hierarchy enabled and logging enabled
add_definitions(-DSTATE_MACHINE_LOGGER=1)
add_definitions(-DHIERARCHICAL_STATES=1)
# Uncomment line below to get memory usage trace details
#add_definitions(-DENABLE_MEMTRACE=1)
#uncomment line below to get network ethernet debug logs
#add_definitions(-DNETWORK_ETHERNET_LOG_LEVEL=ESP_LOG_DEBUG)
#uncomment line below to get network status debug logs
#add_definitions(-DNETWORK_STATUS_LOG_LEVEL=ESP_LOG_DEBUG)
#add_definitions(-DNETWORK_HANDLERS_LOG_LEVEL=ESP_LOG_DEBUG)
#add_definitions(-DNETWORK_WIFI_LOG_LEVEL=ESP_LOG_DEBUG)
#add_definitions(-DNETWORK_MANAGER_LOG_LEVEL=ESP_LOG_DEBUG)
#add_definitions(-DNETWORK_HTTP_SERVER_LOG_LEVEL=ESP_LOG_DEBUG)
if(NOT DEFINED DEPTH)
set(DEPTH "16")
endif()
@@ -10,5 +26,103 @@ project(recovery)
set_property(TARGET recovery.elf PROPERTY RECOVERY_PREFIX app_recovery )
include(squeezelite.cmake)
set(PROJECT_VER $ENV{PROJECT_VER})
#target_compile_definitions(__idf_squeezelite-ota PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_VERBOSE)
#target_compile_definitions(__idf_driver_bt PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
#target_compile_definitions(__idf_esp_eth PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_INFO)
#target_compile_definitions(__idf_services PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
#target_compile_definitions(__idf_driver PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
#target_compile_definitions(__idf_wifi-manager PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
#target_compile_definitions(__idf_esp_wifi PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
#target_compile_definitions(__idf_platform_console PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
#target_compile_definitions(__idf_app_recovery PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_INFO)
# target_compile_definitions(__idf_esp_eth PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_INFO)
# target_compile_definitions(__idf_esp_event PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_INFO)
# target_compile_definitions(__idf_esp_netif PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_freertos PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
#target_compile_definitions(__idf_bt PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_ERROR)
# target_compile_definitions(__idf_mdns PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_tcpip_adapter PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_tcp_transport PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
#target_compile_definitions(__idf_app_squeezelite PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_app_trace PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_app_update PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_asio PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_audio PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_bootloader_support PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_cbor PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_cmock PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_coap PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_console PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_cxx PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_display PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_driver PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_driver_bt PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_efuse PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp-dsp PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp-tls PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp32 PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_espcoredump PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_adc_cal PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_common PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_gdbstub PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_hid PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_https_ota PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_http_client PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_http_server PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_hw_support PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_ipc PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_local_ctrl PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_pm PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_ringbuf PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_rom PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_serial_slave_link PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_system PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_timer PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_esp_websocket_client PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_expat PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_fatfs PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_freemodbus PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_hal PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_heap PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_jsmn PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_json PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_libsodium PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_log PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_lwip PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_main PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_mbedtls PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(mbedcrypto PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(mbedtls PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(mbedx509 PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_mqtt PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_newlib PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_nghttp PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_nvs_flash PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_openssl PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_perfmon PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_platform_config PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_protobuf-c PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_protocomm PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_pthread PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_raop PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_sdmmc PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_soc PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_spiffs PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_spi_flash PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_squeezelite PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_squeezelite-ota PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_telnet PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_tools PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_ulp PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_unity PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_vfs PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_wear_levelling PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_wifi_provisioning PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_wpa_supplicant PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)
# target_compile_definitions(__idf_xtensa PRIVATE -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG)

View File

@@ -1,33 +1,156 @@
FROM ubuntu:18.04
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y git wget libncurses-dev flex bison gperf \
python python-pip python-setuptools python-serial python-click \
python-cryptography python-future python-pyparsing \
python-pyelftools cmake ninja-build ccache libusb-1.0
RUN mkdir /workspace
WORKDIR /workspace
ARG DEBIAN_FRONTEND=noninteractive
ENV GCC_TOOLS_BASE=/opt/esp/tools/xtensa-esp32-elf/esp-2021r2-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-
# To build the image for a branch or a tag of IDF, pass --build-arg IDF_CLONE_BRANCH_OR_TAG=name.
# To build the image with a specific commit ID of IDF, pass --build-arg IDF_CHECKOUT_REF=commit-id.
# It is possibe to combine both, e.g.:
# IDF_CLONE_BRANCH_OR_TAG=release/vX.Y
# IDF_CHECKOUT_REF=<some commit on release/vX.Y branch>.
# The following commit contains the ldgen fix: eab738c79e063b3d6f4c345ea5e1d4f8caef725b
# to build an image using that commit: docker build . --build-arg IDF_CHECKOUT_REF=eab738c79e063b3d6f4c345ea5e1d4f8caef725b -t sle118/squeezelite-esp32-idfv43
# Docker build for release 4.3.2 as of 2022/02/28
# docker build . --build-arg IDF_CHECKOUT_REF=8bf14a9238329954c7c5062eeeda569529aedf75 -t sle118/squeezelite-esp32-idfv43
# To run the image interactive (windows):
# docker run --rm -v %cd%:/project -w /project -it sle118/squeezelite-esp32-idfv43
# To run the image interactive (linux):
# docker run --rm -v `pwd`:/project -w /project -it sle118/squeezelite-esp32-idfv4-master
# to build the web app inside of the interactive session
# pushd components/wifi-manager/webapp/ && npm install && npm run-script build && popd
#
# to run the docker with netwotrk port published on the host:
# docker run --rm -p 5000:5000/tcp -v %cd%:/project -w /project -it sle118/squeezelite-esp32-idfv43
# Download and checkout known good esp-idf commit
RUN git clone --recursive https://github.com/espressif/esp-idf.git esp-idf
RUN cd esp-idf && git checkout 4dac7c7df885adaa86a5c79f2adeaf8d68667349
RUN git clone https://github.com/sle118/squeezelite-esp32.git
ARG IDF_CLONE_URL=https://github.com/espressif/esp-idf.git
ARG IDF_CLONE_BRANCH_OR_TAG=master
ARG IDF_CHECKOUT_REF=8bf14a9238329954c7c5062eeeda569529aedf75
# Download GCC 5.2.0
RUN wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz
RUN tar -xzf xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz
RUN rm xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz
ENV IDF_PATH=/opt/esp/idf
ENV IDF_TOOLS_PATH=/opt/esp
RUN rm -r /workspace/squeezelite-esp32
RUN mkdir /workspace/squeezelite-esp32
# We need libpython2.7 due to GDB tools
# we also need npm 8 for the webapp to work
RUN : \
&& apt-get update \
&& apt-get install -y \
apt-utils \
bison \
ca-certificates \
ccache \
check \
curl \
flex \
git \
gperf \
lcov \
libffi-dev \
libncurses-dev \
libpython2.7 \
libusb-1.0-0-dev \
make \
ninja-build \
python3 \
python3-pip \
unzip \
wget \
xz-utils \
zip \
npm \
nodejs \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 10 \
&& python -m pip install --upgrade \
pip \
virtualenv \
&& cd /opt \
&& git clone https://github.com/HBehrens/puncover.git \
&& cd puncover \
&& python setup.py -q install \
&& echo IDF_CHECKOUT_REF=$IDF_CHECKOUT_REF IDF_CLONE_BRANCH_OR_TAG=$IDF_CLONE_BRANCH_OR_TAG \
&& git clone --recursive \
${IDF_CLONE_BRANCH_OR_TAG:+-b $IDF_CLONE_BRANCH_OR_TAG} \
$IDF_CLONE_URL $IDF_PATH \
&& if [ -n "$IDF_CHECKOUT_REF" ]; then \
cd $IDF_PATH \
&& git checkout $IDF_CHECKOUT_REF \
&& git submodule update --init --recursive; \
fi \
&& update-ca-certificates --fresh \
&& $IDF_PATH/tools/idf_tools.py --non-interactive install required \
&& $IDF_PATH/tools/idf_tools.py --non-interactive install cmake \
&& $IDF_PATH/tools/idf_tools.py --non-interactive install-python-env \
&& :
RUN : \
echo Installing pygit2 ******************************************************** \
&& . /opt/esp/python_env/idf4.3_py3.8_env/bin/activate \
&& ln -sf /opt/esp/python_env/idf4.3_py3.8_env/bin/python /usr/local/bin/python \
&& pip install pygit2 requests \
&& pip show pygit2 \
&& python --version \
&& pip --version \
&& pip3 install protobuf grpcio-tools \
&& rm -rf $IDF_TOOLS_PATH/dist \
&& :
# Setup PATH to use esp-idf and gcc-5.2.0
RUN touch /root/.bashrc && \
echo export PATH="\$PATH:/workspace/xtensa-esp32-elf/bin" >> /root/.bashrc && \
echo export IDF_PATH=/workspace/esp-idf >> /root/.bashrc
COPY docker/patches $IDF_PATH
# OPTIONAL: Install vim for text editing in Bash
RUN apt-get update && apt-get install -y vim
#set idf environment variabies
ENV PATH /opt/esp/idf/components/esptool_py/esptool:/opt/esp/idf/components/espcoredump:/opt/esp/idf/components/partition_table:/opt/esp/idf/components/app_update:/opt/esp/tools/xtensa-esp32-elf/esp-2021r2-8.4.0/xtensa-esp32-elf/bin:/opt/esp/tools/xtensa-esp32s2-elf/esp-2021r2-8.4.0/xtensa-esp32s2-elf/bin:/opt/esp/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin:/opt/esp/tools/riscv32-esp-elf/esp-2021r2-8.4.0/riscv32-esp-elf/bin:/opt/esp/tools/esp32ulp-elf/2.28.51-esp-20191205/esp32ulp-elf-binutils/bin:/opt/esp/tools/esp32s2ulp-elf/2.28.51-esp-20191205/esp32s2ulp-elf-binutils/bin:/opt/esp/tools/cmake/3.16.4/bin:/opt/esp/tools/openocd-esp32/v0.10.0-esp32-20211111/openocd-esp32/bin:/opt/esp/python_env/idf4.3_py3.8_env/bin:/opt/esp/idf/tools:$PATH
ENV GCC_TOOLS_BASE="/opt/esp/tools/xtensa-esp32-elf/esp-2021r2-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-"
ENV IDF_PATH="/opt/esp/idf"
ENV IDF_PYTHON_ENV_PATH="/opt/esp/python_env/idf4.3_py3.8_env"
ENV IDF_TOOLS_EXPORT_CMD="/opt/esp/idf/export.sh"
ENV IDF_TOOLS_INSTALL_CMD="/opt/esp/idf/install.sh"
ENV IDF_TOOLS_PATH="/opt/esp"
ENV NODE_PATH="/v8/lib/node_modules"
ENV NODE_VERSION="8"
ENV OPENOCD_SCRIPTS="/opt/esp/tools/openocd-esp32/v0.10.0-esp32-20211111/openocd-esp32/share/openocd/scripts"
# Ccache is installed, enable it by default
WORKDIR /workspace/squeezelite-esp32
CMD ["bash"]
ENV IDF_CCACHE_ENABLE=1
COPY docker/entrypoint.sh /opt/esp/entrypoint.sh
COPY components/wifi-manager/webapp/package.json /opt
ENV NODE_VERSION 8
SHELL ["/bin/bash", "--login", "-c"]
# Install nvm with node and npm
# RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash \
# && export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" \
# && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" \
# && nvm install $NODE_VERSION \
# && nvm alias default $NODE_VERSION \
# && nvm use default \
# && echo installing nodejs version 16 \
# && curl -sL https://deb.nodesource.com/setup_16.x | bash - \
# && echo installing node modules \
# && cd /opt \
# && nvm use default \
# && npm install -g \
# && :
RUN : \
&& curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get install -y nodejs jq \
&& echo installing dev node modules globally \
&& cd /opt \
&& cat ./package.json | jq '.devDependencies | keys[] as $k | "\($k)@\(.[$k])"' | xargs -t npm install --global \
&& echo installing npm global packages \
&& npm i -g npm \
&& node --version \
&& npm install -g \
&& :
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $IDF_PYTHON_ENV_PATH:$NVM_DIR/v$NODE_VERSION/bin:$PATH
COPY ./docker/build_tools.py /usr/sbin/build_tools.py
RUN : \
&& echo Changing permissions ******************************************************** \
&& chmod +x /opt/esp/entrypoint.sh \
&& chmod +x /usr/sbin/build_tools.py \
&& :
ENTRYPOINT [ "/opt/esp/entrypoint.sh" ]
CMD [ "/bin/bash" ]

237
README.md
View File

@@ -1,24 +1,21 @@
![Cross-Build](https://github.com/sle118/squeezelite-esp32/workflows/Cross-Build/badge.svg?branch=master-cmake)
![ESP-IDF v4.3.1](https://github.com/sle118/squeezelite-esp32/actions/workflows/esp-idf-v4.3-build.yml/badge.svg?branch=master-v4.3)
# Squeezelite-esp32
## What is this?
## What is this
Squeezelite-esp32 is an audio software suite made to run on espressif's ESP32 wifi (b/g/n) and bluetooth chipset. It offers the following capabilities
- Stream your local music and connect to all major on-line music providers (Spotify, Deezer, Tidal, Qobuz) using [Logitech Media Server - a.k.a LMS](https://forums.slimdevices.com/) and enjoy multi-room audio synchronization. LMS can be extended by numerous plugins and can be controlled using a Web browser or dedicated applications (iPhone, Android). It can also send audio to UPnP, Sonos, ChromeCast and AirPlay speakers/devices.
- Stream from a **Bluetooth** device (iPhone, Android)
- Stream from an **AirPlay** controller (iPhone, iTunes ...) and enjoy synchronization multiroom as well (although it's AirPlay 1 only)
- Stream from a Spotify controller
- Stream from a Bluetooth device (iPhone, Android)
- Stream from an AirPlay controller (iPhone, iTunes ...) and enjoy synchronization multiroom as well (although it's AirPlay 1 only)
Depending on the hardware connected to the ESP32, you can send audio to a local DAC, to SPDIF or to a Bluetooth speaker. The bare minimum required hardware is a WROVER module with 4MB of Flash and 4MB of PSRAM (https://www.espressif.com/en/products/modules/esp32). With that module standalone, just apply power and you can stream to a Bluetooth speaker. You can also send audio to most I2S DAC as well as to SPDIF receivers using just a cable or an optical transducer.
But squeezelite-esp32 is highly extensible and you can add
- [Buttons](#buttons) and [Rotary Encoder](#rotary-encoder) and map/combine them to various functions (play, pause, volume, next ...)
- [GPIO expander](#gpio-expanders) (buttons, led and rotary)
- [IR receiver](#infrared) (no pullup resistor or capacitor needed, just the 38kHz receiver)
- [Monochrome, GrayScale or Color displays](#display) using SPI or I2C (supported drivers are SH1106, SSD1306, SSD1322, SSD1326/7, SSD1351, ST7735, ST7789 and ILI9341).
- [Ethernet](#ethernet-required-unpublished-version-43) using a Microchip LAN8720 with RMII interface or Davicom DM9051/W5500 over SPI.
- Buttons and Rotary Encoder and map/combine them to various functions (play, pause, volume, next ...)
- IR receiver (no pullup resistor or capacitor needed, just the 38kHz receiver)
- Monochrome, GrayScale or Color displays using SPI or I2C (supported drivers are SH1106, SSD1306, SSD1322, SSD1326/7, SSD1351, ST7735, ST7789 and ILI9341).
- Ethernet using a Microchip LAN8720 with RMII interface or Davicom DM9051 over SPI.
Other features include
@@ -53,44 +50,29 @@ The esp32 must run at 240 MHz, with Quad-SPI I/O at 80 MHz and a clock of 40 Mhz
In 16 bits mode, although 192 kHz is reported as max rate, it's highly recommended to limit reported sampling rate to 96k (-Z 96000). Note that some high-speed 24/96k on-line streams might stutter because of TCP/IP stack performances. It is usually due to the fact that the server sends small packets of data and the esp32 cannot receive encoded audio fast enough, regardless of task priority settings (I've tried to tweak that a fair bit). The best option in that case is to let LMS proxy the stream as it will provide larger chunks and a "smoother" stream that can then be handled.
Note as well that some codecs consume more CPU than others or have not been optimized as much. I've done my best to tweak these, but that level of optimization includes writing some assembly which is painful. One very demanding codec is AAC when files are encoded with SBR. It allows reconstruction of upper part of spectrum and thus higher sampling rate, but the codec spec is such that this is optional, you can decode simply lower band and accept lower sampling rate - See the AAC_DISABLE_SBR option below.
## Supported Hardware
Any esp32-based hardware with at least 4MB of flash and 4MB of PSRAM will be capable of running squeezelite-esp32 and there are various boards that include such chip. A few are mentionned below, but any should work. You can find various help & instructions [here](https://forums.slimdevices.com/showthread.php?112697-ANNOUNCE-Squeezelite-ESP32-(dedicated-thread))
**For the sake of clarity, WROOM modules DO NOT work as they don't include PSRAM. Some designs might add it externally, but it's (very) unlikely.**
### Raw WROVER module
Per above description, a [WROVER module](https://www.espressif.com/en/products/modules/esp32) is enough to run Squeezelite-esp32, but that requires a bit of tinkering to extend it to have analogue audio or hardware buttons (e.g.)
Please note that when sending to a Bluetooth speaker (source), only 44.1 kHz can be used, so you either let LMS do the resampling, but you must make sure it only sends 44.1kHz tracks or enable internal resampling (using -R) option. If you connect a DAC, choice of sample rates will depends on its capabilities. See below for more details.
Most DAC will work out-of-the-box with simply an I2S connection, but some require specific commands to be sent using I2C. See DAC option below to understand how to send these dedicated commands. There is build-in support for TAS575x, TAS5780, TAS5713 and AC101 DAC.
### SqueezeAMP
This is the main hardware companion of Squeezelite-esp32 and has been developped together. Details on capabilities can be found [here](https://forums.slimdevices.com/showthread.php?110926-pre-ANNOUNCE-SqueezeAMP-and-SqueezeliteESP32) and [here](https://github.com/philippe44/SqueezeAMP).
If you want to rebuild, use the `squeezelite-esp32-SqueezeAmp-sdkconfig.defaults` configuration file.
if you want to rebuild, use the `squeezelite-esp32-SqueezeAmp-sdkconfig.defaults` configuration file.
NB: You can use the pre-build binaries SqueezeAMP4MBFlash which has all the hardware I/O set properly. You can also use the generic binary I2S4MBFlash in which case the NVS parameters shall be set to get the exact same behavior
- set_GPIO: `12=green,13=red,34=jack,2=spkfault`
- bat_config: `channel=7,scale=20.24`
- dac_config: `model=TAS57xx,bck=33,ws=25,do=32,sda=27,scl=26,mute=14:0`
- spdif_config: `bck=33,ws=25,do=15`
### MuseLuxe
This portable battery-powered [speaker](https://raspiaudio.com/produit/esp-muse-luxe) is compatible with squeezelite-esp32 for which there is a dedicated build supplied with every update. If you want to rebuild, use the `squeezelite-esp32-Muse-sdkconfig.defaults` configuration file.
NB: You can use the pre-build binaries Muse4MBFlash which has all the hardware I/O set properly. You can also use the generic binary I2S4MBFlash in which case the NVS parameters shall be set to get the exact same behavior
- target: `muse`
- bat_config: `channel=5,scale=7.48,atten=3,cells=1`
- spi_config: `"mosi=15,miso=2,clk=14` *(this one is probably optional)*
- dac_config: `model=I2S,bck=5,ws=25,do=26,di=35,i2c=16,sda=18,scl=23,mck`
- dac_controlset: `{"init":[ {"reg":0,"val":128}, {"reg":0,"val":0}, {"reg":25,"val":4}, {"reg":1,"val":80}, {"reg":2,"val":0}, {"reg":8,"val":0}, {"reg":4,"val":192}, {"reg":0,"val":18}, {"reg":1,"val":0}, {"reg":23,"val":24}, {"reg":24,"val":2}, {"reg":38,"val":9}, {"reg":39,"val":144}, {"reg":42,"val":144}, {"reg":43,"val":128}, {"reg":45,"val":128}, {"reg":27,"val":0}, {"reg":26,"val":0}, {"reg":2,"val":240}, {"reg":2,"val":0}, {"reg":29,"val":28}, {"reg":4,"val":48}, {"reg":25,"val":0}, {"reg":46,"val":33}, {"reg":47,"val":33} ]}`
- actrls_config: buttons
- define a "buttons" variable with: `[{"gpio":32, "pull":true, "debounce":10, "normal":{"pressed":"ACTRLS_VOLDOWN"}}, {"gpio":19, "pull":true, "debounce":40, "normal":{"pressed":"ACTRLS_VOLUP"}}, {"gpio":12, "pull":true, "debounce":40, "long_press":1000, "normal":{"pressed":"ACTRLS_TOGGLE"},"longpress":{"pressed":"ACTRLS_POWER"}}]`
- set_GPIO: 12=green,13=red,34=jack,2=spkfault
- batt_config: channel=7,scale=20.24
- dac_config: model=TAS57xx,bck=33,ws=25,do=32,sda=27,scl=26,mute=14:0
- spdif_config: bck=33,ws=25,do=15
### ESP32-A1S
Works with [ESP32-A1S](https://docs.ai-thinker.com/esp32-a1s) module that includes audio codec and headset output. You still need to use a demo board like [this](https://www.aliexpress.com/item/4001060963585.html) or an external amplifier if you want direct speaker connection. Note that there is a version with AC101 codec and another one with ES8388 with probably two variants - these boards are a mess (see below)
Works with [ESP32-A1S](https://docs.ai-thinker.com/esp32-a1s) module that includes audio codec and headset output. You still need to use a demo board like [this](https://www.aliexpress.com/item/4001060963585.html) or an external amplifier if you want direct speaker connection. Note that there is a version with AC101 codec and another one with ES8388 (see below)
The board shown above has the following IO set
- amplifier: GPIO21
@@ -106,30 +88,23 @@ The board shown above has the following IO set
(note that some GPIO need pullups)
So a possible config would be
- set_GPIO: `21=amp,22=green:0,39=jack:0`
- set_GPIO: 21=amp,22=green:0,39=jack:0
- a button mapping:
```json
[{"gpio":5,"normal":{"pressed":"ACTRLS_TOGGLE"}},{"gpio":18,"pull":true,"shifter_gpio":5,"normal":{"pressed":"ACTRLS_VOLUP"}, "shifted":{"pressed":"ACTRLS_NEXT"}}, {"gpio":23,"pull":true,"shifter_gpio":5,"normal":{"pressed":"ACTRLS_VOLDOWN"},"shifted":{"pressed":"ACTRLS_PREV"}}]
```
for **AC101**
- dac_config: `model=AC101,bck=27,ws=26,do=25,di=35,sda=33,scl=32`
```
[{"gpio":5,"normal":{"pressed":"ACTRLS_TOGGLE"}},{"gpio":18,"pull":true,"shifter_gpio":5,"normal":{"pressed":"ACTRLS_VOLUP"}, "shifted":{"pressed":"ACTRLS_NEXT"}}, {"gpio":23,"pull":true,"shifter_gpio":5,"normal":{"pressed":"ACTRLS_VOLDOWN"},"shifted":{"pressed":"ACTRLS_PREV"}}]
```
for AC101
- dac_config: model=AC101,bck=27,ws=26,do=25,di=35,sda=33,scl=32
for **ES8388** (it seems that there are variants with same version number - a total mess)
- dac_config: `model=ES8388,bck=5,ws=25,do=26,sda=18,scl=23,i2c=16`
or
- dac_config: `model=ES8388,bck=27,ws=25,do=26,sda=33,scl=32,i2c=16`
for ES8388
- dac_config: model=ES8388,bck=5,ws=25,do=26,sda=18,scl=23,i2c=16
### T-WATCH2020 by LilyGo
This is a fun [smartwatch](http://www.lilygo.cn/prod_view.aspx?TypeId=50036&Id=1290&FId=t3:50036:3) based on ESP32. It has a 240x240 ST7789 screen and onboard audio. Not very useful to listen to anything but it works. This is an example of a device that requires an I2C set of commands for its dac (see below). There is a build-option if you decide to rebuild everything by yourself, otherwise the I2S default option works with the following parameters
- dac_config: `model=I2S,bck=26,ws=25,do=33,i2c=106,sda=21,scl=22`
- dac_controlset:
```json
{ "init": [ {"reg":41, "val":128}, {"reg":18, "val":255} ], "poweron": [ {"reg":18, "val":64, "mode":"or"} ], "poweroff": [ {"reg":18, "val":191, "mode":"and"} ] }
```
- spi_config: `dc=27,data=19,clk=18`
- display_config: `SPI,driver=ST7789,width=240,height=240,cs=5,back=12,speed=16000000,HFlip,VFlip`
- dac_config: model=I2S,bck=26,ws=25,do=33,i2c=106,sda=21,scl=22
- dac_controlset: { "init": [ {"reg":41, "val":128}, {"reg":18, "val":255} ], "poweron": [ {"reg":18, "val":64, "mode":"or"} ], "poweroff": [ {"reg":18, "val":191, "mode":"and"} ] }
- spi_config: dc=27,data=19,clk=18
- display_config: SPI,driver=ST7789,width=240,height=240,cs=5,back=12,speed=16000000,HFlip,VFlip
### ESP32-WROVER + I2S DAC
Squeezelite-esp32 requires esp32 chipset and 4MB PSRAM. ESP32-WROVER meets these requirements. To get an audio output an I2S DAC can be used. Cheap PCM5102 I2S DACs work others may also work. PCM5012 DACs can be hooked up via:
@@ -155,23 +130,18 @@ And the super cool project https://github.com/rochuck/squeeze-amp-too
## Configuration
To access NVS, in the webUI, go to credits and select "shows nvs editor". Go into the NVS editor tab to change NFS parameters. In syntax description below \<\> means a value while \[\] describe optional parameters.
As mentionned above, there are a few dedicated builds that are provided today: SqueezeAMP and Muse but if you build it yourself, you can also create a build for T-WATCH2020. The default build is a generic firmware named I2S which can be configured through NVS to produce *exactly* the same results than dedicated builds. The difference is that parameters must be entered and can accidently be erased. The GUI provides a great help to load "known config sets" as well.
By design choice, there is no code that is only embedded for a given version, all code is always there. The philosophy is to minimize as much as possible platform-specific code and use of specific `#ifdef` is prohibited, no matter what. So if you want to add your own platfrom, please look **very hard** at the `main\KConfig.projbuild` to see how you can, using parameters below, make your device purely a configuration-based solution. When there is really no other option, look at `targets\<target>` to add your own code. I will not accept PR for code that can avoid creating such dedicated code whenever possible. The NVS "target" will be used to call target-specific code then, but again this is purely runtime, not compile-time.
### I2C
The NVS parameter "i2c_config" set the i2c's gpio used for generic purpose (e.g. display). Leave it blank to disable I2C usage. Note that on SqueezeAMP, port must be 1. Default speed is 400000 but some display can do up to 800000 or more. Syntax is
```
sda=<gpio>,scl=<gpio>[,port=0|1][,speed=<speed>]
```
**Please note that you can not use the same GPIO or port as the DAC.**
<strong>Please note that you can not use the same GPIO or port as the DAC</strong>
### SPI
The esp32 has 3 user-accessible SPI sub-systems but SPI0 and SPI2 are reserved for internal use and Flash/PSRAM, so only SPI1 is available. The NVS parameter "spi_config" set the spi's gpio used for user purpose (e.g. display, ethernet, GPIO expander). Leave it blank to disable SPI usage. The DC parameter is needed for displays. Syntax is
The esp32 has 4 SPI sub-systems, one is unaccessible so numbering is 0..2 and SPI0 is reserved for Flash/PSRAM. The NVS parameter "spi_config" set the spi's gpio used for generic purpose (e.g. display). Leave it blank to disable SPI usage. The DC parameter is needed for displays. Syntax is
```
data|mosi=<gpio>,clk=<gpio>[,dc=<gpio>][,host=1][,miso=<gpio>]
data|mosi=<gpio>,clk=<gpio>[,dc=<gpio>][,host=1|2][,miso=<gpio>]
```
Default and only "host" is 1 as others are used already by flash and spiram. The optional "miso" (MasterInSlaveOut) parameter is only used when SPI bus is bi-directional and shared with other peripheral like ethernet, gpio expander. Note that "data" can also be named "mosi" (MasterOutSlaveIn).
Default "host" is 1. The "miso" parameter is only used when SPI bus is to be shared with other peripheral (e.g. ethernet, see below), otherwise it can be omitted. Note that "data" can also be named "mosi".
### DAC/I2S
The NVS parameter "dac_config" set the gpio used for i2s communication with your DAC. You can define the defaults at compile time but nvs parameter takes precedence except for SqueezeAMP and A1S where these are forced at runtime. Syntax is
```
@@ -179,20 +149,17 @@ bck=<gpio>,ws=<gpio>,do=<gpio>[,mck][,mute=<gpio>[:0|1][,model=TAS57xx|TAS5713|A
```
if "model" is not set or is not recognized, then default "I2S" is used. The option "mck" is used for some codecs that require a master clock (although they should not). Only GPIO0 can be used as MCLK and be aware that this cannot coexit with RMII Ethernet (see ethernet section below). I2C parameters are optional and only needed if your DAC requires an I2C control (See 'dac_controlset' below). Note that "i2c" parameters are decimal, hex notation is not allowed.
So far, TAS57xx, TAS5713, AC101, WM8978 and ES8388 are recognized models where the proper init sequence/volume/power controls are sent. For other codecs that might require an I2C commands, please use the parameter "dac_controlset" that allows definition of simple commands to be sent over i2c for init, power, speakder and headset on and off using a JSON syntax:
```json
{ <command>: [ {"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"}, ... {{"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"} ],
<command>: [ {"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"}, ... {{"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"} ],
... }
So far, TAS57xx, TAS5713, AC101, WM8978 and ES8388 are recognized models where the proper init sequence/volume/power controls are sent. For other codecs that might require an I2C commands, please use the parameter "dac_controlset" that allows definition of simple commands to be sent over i2c for init, power on and off using a JSON syntax:
```
Where `<command>` is one of init, poweron, poweroff, speakeron, speakeroff, headseton, headsetoff
This is standard JSON notation, so if you are not familiar with it, Google is your best friend. Be aware that the '...' means you can have as many entries as you want, it's not part of the syntax. Every section is optional, but it does not make sense to set i2c in the 'dac_config' parameter and not setting anything here. The parameter 'mode' allows to *or* the register with the value or to *and* it. Don't set 'mode' if you simply want to write. The 'val parameter can be an array [v1, v2,...] to write a serie of bytes in a single i2c burst (in that case 'mode' is ignored). **Note that all values must be decimal**. You can use a validator like [this](https://jsonlint.com) to verify your syntax
{ init: [ {"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"}, ... {{"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"} ],
poweron: [ {"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"}, ... {{"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"} ],
poweroff: [ {"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"}, ... {{"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"} ] }
```
This is standard JSON notation, so if you are not familiar with it, Google is your best friend. Be aware that the '...' means you can have as many entries as you want, it's not part of the syntax. Every section is optional, but it does not make sense to set i2c in the 'dac_config' parameter and not setting anything here. The parameter 'mode' allows to *or* the register with the value or to *and* it. Don't set 'mode' if you simply want to write. **Note that all values must be decimal**. You can use a validator like [this](https://jsonlint.com) to verify your syntax
NB: For specific builds (all except I2S), all this is ignored. For know codecs, the built-in sequences can be overwritten using dac_controlset
**Please note that you can not use the same GPIO or port as the I2C.**
<strong>Please note that you can not use the same GPIO or port as the I2C</strong>
### SPDIF
The NVS parameter "spdif_config" sets the i2s's gpio needed for SPDIF.
@@ -217,28 +184,25 @@ GPIO ----210ohm-----------||---- coax S/PDIF signal out
|
Ground -------------------------- coax signal ground
```
### Display
The NVS parameter "display_config" sets the parameters for an optional display. It can be I2C (see [here](#i2c) for shared bus) or SPI (see [here](#spi) for shared bus) Syntax is
The NVS parameter "display_config" sets the parameters for an optional display. Syntax is
```
I2C,width=<pixels>,height=<pixels>[address=<i2c_address>][,reset=<gpio>][,HFlip][,VFlip][driver=SSD1306|SSD1326[:1|4]|SSD1327|SH1106]
SPI,width=<pixels>,height=<pixels>,cs=<gpio>[,back=<gpio>][,reset=<gpio>][,speed=<speed>][,HFlip][,VFlip][driver=SSD1306|SSD1322|SSD1326[:1|4]|SSD1327|SH1106|SSD1675|ST7735[:x=<offset>][:y=<offset>]|ST7789|ILI9341[:16|18][,rotate][,invert][,cswap]
SPI,width=<pixels>,height=<pixels>,cs=<gpio>[,back=<gpio>][,reset=<gpio>][,speed=<speed>][,HFlip][,VFlip][driver=SSD1306|SSD1322|SSD1326[:1|4]|SSD1327|SH1106|SSD1675|ST7735|ST7789|ILI9341[:16|18][,rotate]]
```
- back: a LED backlight used by some older devices (ST7735). It is PWM controlled for brightness
- reset: some display have a reset pin that is should normally be pulled up if unused. Most displays require reset and will not initialize well otherwise.
- reset: some display have a reset pin that is should normally be pulled up if unused
- VFlip and HFlip are optional can be used to change display orientation
- rotate: for non-square *drivers*, move to portrait mode. Note that *width* and *height* must be inverted then
- invert: pixel invertion
- cswap: some display require a GBR color ordering instead of RGB (ST77xx only)
- Default speed is 8000000 (8MHz) but SPI can work up to 26MHz or even 40MHz
- SH1106 is 128x64 monochrome I2C/SPI [here](https://www.waveshare.com/wiki/1.3inch_OLED_HAT)
- SH1106 is 128x64 monochrome I2C/SPI [here]((https://www.waveshare.com/wiki/1.3inch_OLED_HAT))
- SSD1306 is 128x32 monochrome I2C/SPI [here](https://www.buydisplay.com/i2c-blue-0-91-inch-oled-display-module-128x32-arduino-raspberry-pi)
- SSD1322 is 256x64 grayscale 16-levels SPI in multiple sizes [here](https://www.buydisplay.com/oled-display/oled-display-module?resolution=159) - it is very nice
- SSD1326 is 256x32 monochrome or grayscale 16-levels SPI [here](https://www.aliexpress.com/item/32833603664.html?spm=a2g0o.productlist.0.0.2d19776cyQvsBi&algo_pvid=c7a3db92-e019-4095-8a28-dfdf0a087f98&algo_expid=c7a3db92-e019-4095-8a28-dfdf0a087f98-1&btsid=0ab6f81e15955375483301352e4208&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_)
- SSD1327 is 128x128 16-level grayscale SPI [here](https://www.amazon.com/gp/product/B079N1LLG8/ref=ox_sc_act_title_1?smid=A1N6DLY3NQK2VM&psc=1) - artwork can be up to 96x96 with vertical vu-meter/spectrum
- SSD1351 is 128x128 65k/262k color SPI [here](https://www.waveshare.com/product/displays/lcd-oled/lcd-oled-3/1.5inch-rgb-oled-module.htm)
- SSD1675 is an e-ink paper and is experimental as e-ink is really not suitable for LMS du to its very low refresh rate
- ST7735 is a 128x160 65k color SPI [here](https://www.waveshare.com/product/displays/lcd-oled/lcd-oled-3/1.8inch-lcd-module.htm). This needs a backlight control. Some have X/Y offsets betwen the driver and the glass (green/black/red models) that can be added using "x" and "y" options (case sensitive!)
- ST7735 is a 128x160 65k color SPI [here](https://www.waveshare.com/product/displays/lcd-oled/lcd-oled-3/1.8inch-lcd-module.htm). This needs a backlight control
- ST7789 is a 240x320 65k (262k not enabled) color SPI [here](https://www.waveshare.com/product/displays/lcd-oled/lcd-oled-3/2inch-lcd-module.htm). It also exist with 240x240 displays. See **rotate** for use in portrait mode
- ILI9341 is another 240x320 65k (262k capable) color SPI. I've not used it much, the driver it has been provided by one external contributor to the project
@@ -246,12 +210,13 @@ You can tweak how the vu-meter and spectrum analyzer are displayed, as well as s
The NVS parameter "metadata_config" sets how metadata is displayed for AirPlay and Bluetooth. Syntax is
```
[format=<display_content>][,speed=<speed>][,pause=<pause>][,artwork[:0|1]]
[format=<display_content>][,speed=<speed>][,pause=<pause>]
```
- 'speed' is the scrolling speed in ms (default is 33ms)
- 'pause' is the pause time between scrolls in ms (default is 3600ms)
- 'format' can contain free text and any of the 3 keywords `%artist%`, `%album%`, `%title%`. Using that format string, the keywords are replaced by their value to build the string to be displayed. Note that the plain text following a keyword that happens to be empty during playback of a track will be removed. For example, if you have set format=`%artist% - %title%` and there is no artist in the metadata then only `<title>` will be displayed not ` - <title>`.
- 'artwork' enables coverart display, if available (does not work for Bluetooth). The optional parameter indicates if the artwork should be resized (1) to fit the available space. Note that the built-in resizer can only do 2,4 and 8 downsizing, so fit is not optimal. The artwork will be placed at the right of the display for landscape displays and underneath the two information lines for others (there is no user option to tweak that).
- 'format' can contain free text and any of the 3 keywords %artist%, %album%, %title%. Using that format string, the keywords are replaced by their value to build the string to be displayed. Note that the plain text following a keyword that happens to be empty during playback of a track will be removed. For example, if you have set format=%artist% - %title% and there is no artist in the metadata then only <title> will be displayed not " - <title>".
### Infrared
You can use any IR receiver compatible with NEC protocol (38KHz). Vcc, GND and output are the only pins that need to be connected, no pullup, no filtering capacitor, it's a straight connection.
@@ -267,13 +232,13 @@ The parameter "set_GPIO" is used to assign GPIO to various functions.
GPIO can be set to GND provide or Vcc at boot. This is convenient to power devices that consume less than 40mA from the side connector. Be careful because there is no conflict checks being made wrt which GPIO you're changing, so you might damage your board or create a conflict here.
The `<amp>` parameter can use used to assign a GPIO that will be set to active level (default 1) when playback starts. It will be reset when squeezelite becomes idle. The idle timeout is set on the squeezelite command line through `-C <timeout>`
The \<amp\> parameter can use used to assign a GPIO that will be set to active level (default 1) when playback starts. It will be reset when squeezelite becomes idle. The idle timeout is set on the squeezelite command line through -C \<timeout\>
If you have an audio jack that supports insertion (use :0 or :1 to set the level when inserted), you can specify which GPIO it's connected to. Using the parameter jack_mutes_amp allows to mute the amp when headset (e.g.) is inserted.
You can set the Green and Red status led as well with their respective active state (:0 or :1)
The `<ir>` parameter set the GPIO associated to an IR receiver. No need to add pullup or capacitor
The \<ir\> parameter set the GPIO associated to an IR receiver. No need to add pullup or capacitor
Syntax is:
@@ -282,34 +247,12 @@ Syntax is:
```
You can define the defaults for jack, spkfault leds at compile time but nvs parameter takes precedence except for well-known configurations where these are forced at runtime.
**Note that gpio 36 and 39 are input only and cannot use interrupt. When set to jack or speaker fault, a 100ms polling checks their value but that's expensive**
### GPIO expanders
It is possible to add GPIO expanders using I2C or SPI bus. They should mainly be used for buttons but they can support generic-purpose outputs as well. These additional GPIOs can be numbered starting from an arbitrary value (40 and above as esp32 has GPIO 0..39). Then these new "virtual" GPIOs from (e.g) 100 to 115 can be used in [button](#Buttons) configuration, [set_GPIO](#set-gpio) or other config settings.
Each expander can support up to 32 GPIO. To use an expander for buttons, an interrupt must be provided, polling mode is not acceptable. An expander w/o interruption can still be configured, but only output will be usable. Note that the same interrupt can be shared accross expanders, as long as they are using open drain or open collectors (which they probably all do)
The parameter "gpio_exp_config" is a semicolon (;) separated list with following syntax for each expander
```
model=<model>,addr=<addr>,[,port=system|dac][,base=<n>|100][,count=<n>|16][,intr=<gpio>][,cs=<gpio>][,speed=<Hz>]
```
- model: pca9535, pca85xx, mcp23017 and mcp23s17 (SPI version)
- addr: chip i2c/spi address (decimal)
- port (I2C): use either "system" port (shared with display for example) or "dac" port (system is default)
- cs (SPI): gpio used for Chip Select
- speed (SPI): speed of the SPI bus for that device (in Hz)
- base: GPIO numbering offset to use everywhere else (default 40)
- count: number of GPIO of expander (default 16 - might be obsolted if model if sufficient to decide)
- intr: real GPIO to use as interrupt.
Note that PWM ("led_brightness" below) is not supported for expanded GPIOs and they cannot be used for high speed or precise timing signals like CS, D/C, Reset and Ready. Buttons, rotary encoder, amplifier control and power are supported. Depending on the actual chipset, pullup or pulldown might be supported so you might have to add external resistors (only MCP23x17 does pullup). The pca8575 is not a great chip, it generate a fair bit of spurious interrupts when used for GPIO out. When using a SPI expander, the bus must be configured using shared [SPI](#SPI) bus
### LED
See [set_GPIO](#set-gpio) for how to set the green and red LEDs. In addition, their brightness can be controlled using the "led_brigthness" parameter. The syntax is
See §**set_GPIO** for how to set the green and red LEDs. In addition, their brightness can be controlled using the "led_brigthness" parameter. The syntax is
```
[green=0..100][,red=0..100]
```
NB: For well-known configuration, this is ignored
### Rotary Encoder
One rotary encoder is supported, quadrature shift with press. Such encoders usually have 2 pins for encoders (A and B), and common C that must be set to ground and an optional SW pin for press. A, B and SW must be pulled up, so automatic pull-up is provided by ESP32, but you can add your own resistors. A bit of filtering on A and B (~470nF) helps for debouncing which is not made by software.
@@ -335,15 +278,14 @@ The SW gpio is optional, you can re-affect it to a pure button if you prefer but
See also the "IMPORTANT NOTE" on the "Buttons" section and remember that when 'lms_ctrls_raw' (see below) is activated, none of these knobonly,volume,longpress options apply, raw button codes (not actions) are simply sent to LMS
**Note that gpio 36 and 39 are input only and cannot use interrupt, so they cannot be set to A or B. When using them for SW, a 100ms polling is used which is expensive**
### Buttons
Buttons are described using a JSON string with the following syntax
```json
```
[
{"gpio":<num>,
"type":"BUTTON_LOW | BUTTON_HIGH",
{"gpio":<num>,
"type":"BUTTON_LOW | BUTTON_HIGH",
"pull":[true|false],
"long_press":<ms>,
"long_press":<ms>,
"debounce":<ms>,
"shifter_gpio":<-1|num>,
"normal": {"pressed":"<action>","released":"<action>"},
@@ -367,7 +309,7 @@ Where (all parameters are optionals except gpio)
- "shifted": action to take when a button is pressed/released and shifted (see above/below)
- "longshifted": action to take when a button is long-pressed/released and shifted (see above/below)
Where `<action>` is either the name of another configuration to load (remap) or one amongst
Where \<action\> is either the name of another configuration to load (remap) or one amongst
```
ACTRLS_NONE, ACTRLS_POWER, ACTRLS_VOLUP, ACTRLS_VOLDOWN, ACTRLS_TOGGLE, ACTRLS_PLAY,
@@ -380,7 +322,7 @@ KNOB_LEFT, KNOB_RIGHT, KNOB_PUSH,
One you've created such a string, use it to fill a new NVS parameter with any name below 16(?) characters. You can have as many of these configs as you can. Then set the config parameter "actrls_config" with the name of your default config
For example a config named "buttons" :
```json
```
[{"gpio":4,"type":"BUTTON_LOW","pull":true,"long_press":1000,"normal":{"pressed":"ACTRLS_VOLDOWN"},"longpress":{"pressed":"buttons_remap"}},
{"gpio":5,"type":"BUTTON_LOW","pull":true,"shifter_gpio":4,"normal":{"pressed":"ACTRLS_VOLUP"}, "shifted":{"pressed":"ACTRLS_TOGGLE"}}]
```
@@ -389,7 +331,7 @@ Defines two buttons
- second on GPIO 5, active low. When pressed it triggers a volume up command. If first button is pressed together with this button, then a play/pause toggle command is generated.
While the config named "buttons_remap"
```json
```
[{"gpio":4,"type":"BUTTON_LOW","pull":true,"long_press":1000,"normal":{"pressed":"BCTRLS_DOWN"},"longpress":{"pressed":"buttons"}},
{"gpio":5,"type":"BUTTON_LOW","pull":true,"shifter_gpio":4,"normal":{"pressed":"BCTRLS_UP"}}]
```
@@ -397,14 +339,10 @@ Defines two buttons
- first on GPIO 4, active low. When pressed, it triggers a navigation down command. When pressed more than 1000ms, it changes the button configuration for the one described above
- second on GPIO 5, active low. When pressed it triggers a navigation up command. That button, in that configuration, has no shift option
Below is a difficult but functional 2-buttons interface for your decoding pleasure:
Below is a difficult but functional 2-buttons interface for your decoding pleasure
`actrls_config`:
*buttons*
```
buttons
```
`buttons`:
```json
[{"gpio":4,"type":"BUTTON_LOW","pull":true,"long_press":1000,
"normal":{"pressed":"ACTRLS_VOLDOWN"},
"longpress":{"pressed":"buttons_remap"}},
@@ -414,8 +352,8 @@ buttons
"longpress":{"pressed":"ACTRLS_NEXT"}}
]
```
`buttons_remap`:
```json
*buttons_remap*
```
[{"gpio":4,"type":"BUTTON_LOW","pull":true,"long_press":1000,
"normal":{"pressed":"BCTRLS_DOWN"},
"longpress":{"pressed":"buttons"}},
@@ -426,19 +364,17 @@ buttons
"longshifted":{"pressed":"BCTRLS_LEFT"}}
]
```
**IMPORTANT NOTE**: LMS also supports the possibility to send 'raw' button codes. It's a bit complicated, so bear with me. Buttons can either be processed by SqueezeESP32 and mapped to a "function" like play/pause or they can be just sent to LMS as plain (raw) code and the full logic of press/release/longpress is handled by LMS, you don't have any control on that.
When buttons are mapped to a "function" (non "raw" mode) a *command* is sent to LMS using the CLI (Command Line Interface) but this only works if LMS does not have a password set. In "raw" mode, a button *code* is sent using the always-openn control socket between LMS and the player.
<strong>IMPORTANT NOTE</strong>: LMS also supports the possibility to send 'raw' button codes. It's a bit complicated, so bear with me. Buttons can either be processed by SqueezeESP32 and mapped to a "function" like play/pause or they can be just sent to LMS as plain (raw) code and the full logic of press/release/longpress is handled by LMS, you don't have any control on that.
The benefit of the "raw" mode is that you can build a player which is as close as possible to a Boom (e.g.) but you can't use the remapping function nor longress or shift logics to do your own mapping when you have a limited set of buttons. In 'raw' mode, all you really need to define is the mapping between the gpio and the button. As far as LMS is concerned, any other option in these JSON payloads does not matter. Now, when you use BT or AirPlay, the full JSON construct described above fully applies, so the shift, longpress, remapping options still work.
The benefit of the "raw" mode is that you can build a player which is as close as possible to a Boom (e.g.) but you can't use the remapping function nor longress or shift logics to do your own mapping when you have a limited set of buttons. In 'raw' mode, all you really need to define is the mapping between the gpio and the button. As far as LMS is concerned, any other option in these JSON payloads does not matter. Now, when you use BT or AirPlay, the full JSON construct described above fully applies, so the shift, longpress, remapping options still work.
**Be aware that when using non "raw" mode, the CLI (Command Line Interface) of LMS is used and *must* be available without password**
There is no good or bad option, it's your choice. Use the NVS parameter "lms_ctrls_raw" to change that option
**Note that gpio 36 and 39 are input only and cannot use interrupt. When using them for a button, a 100ms polling is started which is expensive. Long press is also likely to not work very well**
### Ethernet (required unpublished version 4.3)
Wired ethernet is supported by esp32 with various options but squeezelite is only supporting a Microchip LAN8720 with a RMII interface like [this](https://www.aliexpress.com/item/32858432526.html) or SPI-ethernet bridges like Davicom DM9051 [that](https://www.amazon.com/dp/B08JLFWX9Z) or W5500 like [this](https://www.aliexpress.com/item/32312441357.html).
**Note:** Touch buttons that can be find on some board like the LyraT V4.3 are not supported currently.
### Ethernet (coming soon)
Wired ethernet is supported by esp32 with various options but squeezelite is only supporting a Microchip LAN8720 with a RMII interface like [this](https://www.aliexpress.com/item/32858432526.html) or Davicom DM9051 over SPI like [that](https://www.amazon.com/dp/B08JLFWX9Z).
#### RMII (LAN8720)
- RMII PHY wiring is fixed and can not be changed
@@ -451,7 +387,6 @@ Wired ethernet is supported by esp32 with various options but squeezelite is onl
| GPIO25 | RX0 | EMAC_RXD0 |
| GPIO26 | RX1 | EMAC_RXD1 |
| GPIO27 | CRS_DV | EMAC_RX_DRV |
| GPIO0 | REF_CLK | 50MHz clock |
- SMI (Serial Management Interface) wiring is not fixed and you can change it either in the configuration or using "eth_config" parameter with the following syntax:
```
@@ -461,30 +396,30 @@ Connecting a reset pin for the LAN8720 is optional but recommended to avoid that
- Clock
The APLL of the esp32 is required for the audio codec, so we **need** a LAN8720 that provides a 50MHz clock. That clock **must** be connected to GPIO0, there is no alternative. This means that if your DAC requires an MCLK, then you are out of luck. It is not possible to have both to work together. There might be some workaround using CLK_OUT2 and GPIO3, but I don't have time for this.
#### SPI (DM9051 or W5500)
Ethernet over SPI is supported as well and requires less GPIOs but is obvsiously slower. SPI is the shared bus set with [spi_config](#spi). The "eth_config" parameter syntax becomes:
#### SPI (DM9051)
Ethernet over SPI is supported as well and requires less GPIOs but is obvsiously slower. Another benefit is that the SPI bus can be shared with the display, but it's also possible to have a dedicated SPI interface. The esp32 has 4 SPI sub-systems, one is unaccessible so numbering is 0..2 and SPI0 is reserved for Flash/PSRAM. The "eth_config" parameter syntax becomes:
```
model=dm9051|w5500,cs=<gpio>,speed=<clk_in_Hz>,intr=<gpio>[,rst=<gpio>]
model=dm9051,cs=<gpio>,speed=<clk_in_Hz>,intr=<gpio>[,host=<-1|1|2>][,rst=<gpio>][,mosi=<gpio>,miso=<gpio>,clk=<gpio>]
```
- The reset pin is optional but recommended
- The esp32 has a special I/O multiplexer for faster speed (up to 80 MHz) but that requires using specific GPIOs, which depends on SPI bus (See [here](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html) for more details). Note that currently only SPI2 is available.
- To use the system SPI, shared with display (see spi_config) "host" must be set to -1. Any other value will reserve the SPI interface (careful of conflict with spi_config). The default "host" is 2 to avoid conflicting wiht default "spi_config" settings.
- When not using system SPI, "mosi" for data out, "miso" for data in and "clk" **must** be set
- The esp32 has a special I/O multiplexer for faster speed (up to 80 MHz) but that requires using specific GPIOs, which depends on SPI bus (See [here](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/spi_master.html) for more details)
| Pin Name | SPI1 | SPI2 |
| Pin Name | SPI2 | SPI3 |
| -------- | ---- | ---- |
| CS | 15 | 5 |
| CS0* | 15 | 5 |
| SCLK | 14 | 18 |
| MISO | 12 | 19 |
| MOSI | 13 | 23 |
** THIS IS NOT AVAILABLE YET, SO MORE TO COME ON HOW TO USE WIRED ETHERNET***
### Battery / ADC
The NVS parameter "bat_config" sets the ADC1 channel used to measure battery/DC voltage. The "atten" value attenuates the input voltage to the ADC input (the read value maintains a 0-1V rage) where: 0=no attenuation(0..800mV), 1=2.5dB attenuation(0..1.1V), 2=6dB attenuation(0..1.35V), 3=11dB attenuation(0..2.6V). Scale is a float ratio applied to every sample of the 12 bits ADC. A measure is taken every 10s and an average is made every 5 minutes (not a sliding window). Syntax is
```
channel=0..7,scale=<scale>,cells=<2|3>[,atten=<0|1|2|3>]
```
NB: Set parameter to empty to disable battery reading. For well-known configuration, this is ignored (except for SqueezeAMP where number of cells is required)
# Configuration
## Setup WiFi
- Boot the esp, look for a new wifi access point showing up and connect to it. Default build ssid and passwords are "squeezelite"/"squeezelite".
- Once connected, navigate to 192.168.4.1
@@ -493,6 +428,7 @@ NB: Set parameter to empty to disable battery reading. For well-known configurat
- Once connection is established, note down the address the device received; this is the address you will use to configure it going forward
## Setup squeezelite command line (optional)
At this point, the device should have disabled its built-in access point and should be connected to a known WiFi network.
- navigate to the address that was noted in step #1
- Using the list of predefined options, choose the mode in which you want squeezelite to start
@@ -505,6 +441,7 @@ At this point, the device should have disabled its built-in access point and sho
- You can enable accessto NVS parameters under 'credits'
## Monitor
In addition of the esp-idf serial link monitor option, you can also enable a telnet server (see NVS parameters) where you'll have access to a ton of logs of what's happening inside the WROVER.
## Update Squeezelite
@@ -536,23 +473,22 @@ See squeezlite command line, but keys options are
- r "<minrate>-<maxrate>"
- C <sec> : set timeout to switch off amp gpio
- W : activate WAV and AIFF header parsing
# Building everything yourself
## Setting up ESP-IDF
### Docker
You can use docker to build squeezelite-esp32 (optional)
First you need to build the Docker container:
A simple alternative to building the project's binaries is to leverage the same docker image that is being used on the GitHub Actions to build our releases. The instructions below assume that you have cloned the squeezelite-esp32 code that you want to build locally and that you have opened a command line/bash session in the folder that contains the code.
Pull the most recent docker image for the environment:
```
docker build -t esp-idf .
docker pull sle118/squeezelite-esp32-idfv4-master
```
Then you need to run the container:
Then run the container interactively :
```
docker run -i -t -v `pwd`:/workspace/squeezelite-esp32 esp-idf
for windows:
docker run -v %cd%:/project -w /project -it sle118/squeezelite-esp32-idfv4-master
for linux:
docker run -it -v `pwd`:/workspace/squeezelite-esp32 sle118/squeezelite-esp32-idfv4-master
```
The above command will mount this repo into the docker container and start a bash terminal
for you to then follow the below build steps
The above command will mount this repo into the docker container and start a bash terminal. From there, simply run idf.py build to build, etc. Note that at the time of writing these lines, flashing is not possible for docker running under windows https://github.com/docker/for-win/issues/1018.
### Manual Install of ESP-IDF
You can install IDF manually on Linux or Windows (using the Subsystem for Linux) following the instructions at: https://www.instructables.com/id/ESP32-Development-on-Windows-Subsystem-for-Linux/ or see here https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/windows-setup.html for a direct install.
@@ -573,7 +509,6 @@ Use `idf.py monitor` to monitor the application (see esp-idf documentation)
Note: You can use `idf.py build -DDEPTH=32` to build the 32 bits version and add the `-DVERSION=<your_version>` to add a custom version name (it will be 0.0-<your_version>). If you want to change the whole version string, see squeezelite.h. You can also disable the SBR extension of AAC codecs as it consumes a lot of CPU and might overload the esp32. Use `-DAAC_DISABLE_SBR=1` for that
If you have already cloned the repository and you are getting compile errors on one of the submodules (e.g. telnet), run the following git command in the root of the repository location: `git submodule update --init --recursive`
### Rebuild codecs (highly recommended to NOT try that)
- for codecs libraries, add -mlongcalls if you want to rebuild them, but you should not (use the provided ones in codecs/lib). if you really want to rebuild them, open an issue
- libmad, libflac (no esp's version), libvorbis (tremor - not esp's version), alac work

View File

@@ -1,876 +0,0 @@
#
# Automatically generated file. DO NOT EDIT.
# Espressif IoT Development Framework (ESP-IDF) Project Configuration
#
# ESP32-A1S defaults (with AC101 codec)
CONFIG_A1S=y
CONFIG_I2S_NUM=0
CONFIG_I2C_LOCKED=y
CONFIG_DISPLAY_CONFIG=""
CONFIG_I2C_CONFIG=""
CONFIG_SPI_CONFIG=""
CONFIG_SET_GPIO=""
CONFIG_GPIO_EXP_CONFIG=""
CONFIG_ROTARY_ENCODER=""
CONFIG_LED_GREEN_GPIO=-1
CONFIG_LED_GREEN_GPIO_LEVEL=1
CONFIG_LED_RED_GPIO=-1
CONFIG_LED_RED_GPIO_LEVEL=1
CONFIG_JACK_GPIO=-1
CONFIG_JACK_GPIO_LEVEL=0
CONFIG_SPKFAULT_GPIO=-1
CONFIG_SPKFAULT_GPIO_LEVEL=0
CONFIG_BAT_CHANNEL=-1
CONFIG_BAT_SCALE="0"
CONFIG_SPDIF_NUM=0
CONFIG_SPDIF_BCK_IO=27
CONFIG_SPDIF_WS_IO=26
CONFIG_SPDIF_DO_IO=-1
CONFIG_DAC_CONFIG="model=AC101,bck=27,ws=26,do=25,di=35,sda=33,scl=32"
CONFIG_MUTE_GPIO=-1
CONFIG_MUTE_GPIO_LEVEL=-1
CONFIG_RELEASE_API="https://api.github.com/repos/sle118/squeezelite-esp32/releases"
CONFIG_SQUEEZELITE_ESP32_RELEASE_URL "https://github.com/sle118/squeezelite-esp32/releases"
CONFIG_PROJECT_NAME="Squeezelite ESP32-A1S"
CONFIG_FW_PLATFORM_NAME="ESP32-A1S"
CONFIG_IDF_TARGET_ESP32=y
CONFIG_IDF_TARGET="esp32"
CONFIG_IDF_FIRMWARE_CHIP_ID=0x0000
#
# SDK tool configuration
#
CONFIG_SDK_TOOLPREFIX="xtensa-esp32-elf-"
CONFIG_APP_COMPILE_TIME_DATE=y
# CONFIG_APP_EXCLUDE_PROJECT_VER_VAR is not set
# CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR is not set
# CONFIG_BOOTLOADER_LOG_LEVEL_NONE is not set
# CONFIG_BOOTLOADER_LOG_LEVEL_ERROR is not set
# CONFIG_BOOTLOADER_LOG_LEVEL_WARN is not set
CONFIG_BOOTLOADER_LOG_LEVEL_INFO=y
# CONFIG_BOOTLOADER_LOG_LEVEL_DEBUG is not set
# CONFIG_BOOTLOADER_LOG_LEVEL_VERBOSE is not set
CONFIG_BOOTLOADER_LOG_LEVEL=3
CONFIG_BOOTLOADER_SPI_WP_PIN=7
CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y
# CONFIG_BOOTLOADER_FACTORY_RESET is not set
# CONFIG_BOOTLOADER_APP_TEST is not set
CONFIG_BOOTLOADER_WDT_ENABLE=y
# CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE is not set
CONFIG_BOOTLOADER_WDT_TIME_MS=9000
# CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE is not set
# CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT is not set
# CONFIG_SECURE_BOOT_ENABLED is not set
# CONFIG_SECURE_FLASH_ENC_ENABLED is not set
CONFIG_ESPTOOLPY_BAUD_OTHER_VAL=115200
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
# CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set
# CONFIG_ESPTOOLPY_FLASHMODE_DIO is not set
# CONFIG_ESPTOOLPY_FLASHMODE_DOUT is not set
CONFIG_ESPTOOLPY_FLASHMODE="dio"
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
# CONFIG_ESPTOOLPY_FLASHFREQ_40M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
CONFIG_ESPTOOLPY_FLASHFREQ="80m"
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
CONFIG_ESPTOOLPY_BEFORE_RESET=y
# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set
CONFIG_ESPTOOLPY_BEFORE="default_reset"
CONFIG_ESPTOOLPY_AFTER_RESET=y
# CONFIG_ESPTOOLPY_AFTER_NORESET is not set
CONFIG_ESPTOOLPY_AFTER="hard_reset"
# CONFIG_ESPTOOLPY_MONITOR_BAUD_9600B is not set
# CONFIG_ESPTOOLPY_MONITOR_BAUD_57600B is not set
CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y
# CONFIG_ESPTOOLPY_MONITOR_BAUD_230400B is not set
# CONFIG_ESPTOOLPY_MONITOR_BAUD_921600B is not set
# CONFIG_ESPTOOLPY_MONITOR_BAUD_2MB is not set
# CONFIG_ESPTOOLPY_MONITOR_BAUD_OTHER is not set
CONFIG_ESPTOOLPY_MONITOR_BAUD_OTHER_VAL=115200
CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
# CONFIG_PARTITION_TABLE_SINGLE_APP is not set
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_OFFSET=0x8000
CONFIG_PARTITION_TABLE_MD5=y
CONFIG_LOGGING_SLIMPROTO="info"
CONFIG_LOGGING_STREAM="info"
CONFIG_LOGGING_DECODE="info"
CONFIG_LOGGING_OUTPUT="info"
# CONFIG_BASIC_I2C_BT is not set
CONFIG_A2DP_SINK_NAME="SMSL BT4.2"
CONFIG_A2DP_DEV_NAME="Squeezelite"
CONFIG_A2DP_CONTROL_DELAY_MS=500
CONFIG_A2DP_CONNECT_TIMEOUT_MS=1000
CONFIG_BT_SINK=y
CONFIG_BT_NAME="ESP32-BT"
CONFIG_BT_SINK_PIN=1234
CONFIG_AIRPLAY_SINK=y
CONFIG_AIRPLAY_NAME="ESP32-AirPlay"
CONFIG_AIRPLAY_PORT="5000"
CONFIG_WIFI_MANAGER_TASK_PRIORITY=5
CONFIG_WIFI_MANAGER_MAX_RETRY=2
CONFIG_DEFAULT_AP_SSID="squeezelite"
CONFIG_DEFAULT_AP_PASSWORD="squeezelite"
CONFIG_DEFAULT_AP_CHANNEL=1
CONFIG_DEFAULT_AP_IP="192.168.4.1"
CONFIG_DEFAULT_AP_GATEWAY="192.168.4.1"
CONFIG_DEFAULT_AP_NETMASK="255.255.255.0"
CONFIG_DEFAULT_AP_MAX_CONNECTIONS=4
CONFIG_DEFAULT_AP_BEACON_INTERVAL=100
CONFIG_DEFAULT_COMMAND_LINE="squeezelite -o I2S -b 500:2000 -d all=info -C 30 -W"
# CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG is not set
CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE=y
# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE is not set
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y
# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE is not set
CONFIG_COMPILER_CXX_EXCEPTIONS=y
CONFIG_COMPILER_CXX_EXCEPTIONS_EMG_POOL_SIZE=0
CONFIG_COMPILER_STACK_CHECK_MODE_NONE=y
# CONFIG_COMPILER_STACK_CHECK_MODE_NORM is not set
# CONFIG_COMPILER_STACK_CHECK_MODE_STRONG is not set
# CONFIG_COMPILER_STACK_CHECK_MODE_ALL is not set
# CONFIG_COMPILER_STACK_CHECK is not set
# CONFIG_COMPILER_WARN_WRITE_STRINGS is not set
# CONFIG_COMPILER_DISABLE_GCC8_WARNINGS is not set
# CONFIG_ESP32_APPTRACE_DEST_TRAX is not set
CONFIG_ESP32_APPTRACE_DEST_NONE=y
# CONFIG_ESP32_APPTRACE_ENABLE is not set
CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y
CONFIG_BT_ENABLED=y
# CONFIG_BTDM_CTRL_MODE_BLE_ONLY is not set
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=y
# CONFIG_BTDM_CTRL_MODE_BTDM is not set
CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN=2
CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN=0
# CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_HCI is not set
CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_PCM=y
CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_EFF=1
CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF=0
CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN_EFF=2
CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF=0
CONFIG_BTDM_CTRL_PINNED_TO_CORE_0=y
# CONFIG_BTDM_CTRL_PINNED_TO_CORE_1 is not set
CONFIG_BTDM_CTRL_PINNED_TO_CORE=0
CONFIG_BTDM_CTRL_HCI_MODE_VHCI=y
# CONFIG_BTDM_CTRL_HCI_MODE_UART_H4 is not set
CONFIG_BTDM_MODEM_SLEEP=y
CONFIG_BTDM_MODEM_SLEEP_MODE_ORIG=y
# CONFIG_BTDM_MODEM_SLEEP_MODE_EVED is not set
CONFIG_BTDM_LPCLK_SEL_MAIN_XTAL=y
CONFIG_BTDM_BLE_SLEEP_CLOCK_ACCURACY_INDEX_EFF=1
# CONFIG_BTDM_COEX_BT_OPTIONS is not set
CONFIG_BT_BLUEDROID_ENABLED=y
# CONFIG_BT_NIMBLE_ENABLED is not set
# CONFIG_BT_CONTROLLER_ONLY is not set
CONFIG_BT_BTC_TASK_STACK_SIZE=3072
CONFIG_BT_BLUEDROID_PINNED_TO_CORE_0=y
# CONFIG_BT_BLUEDROID_PINNED_TO_CORE_1 is not set
CONFIG_BT_BLUEDROID_PINNED_TO_CORE=0
CONFIG_BT_BTU_TASK_STACK_SIZE=4096
# CONFIG_BT_BLUEDROID_MEM_DEBUG is not set
CONFIG_BT_CLASSIC_ENABLED=y
CONFIG_BT_A2DP_ENABLE=y
# CONFIG_BT_SPP_ENABLED is not set
# CONFIG_BT_HFP_ENABLE is not set
CONFIG_BT_SSP_ENABLED=y
CONFIG_BT_BLE_ENABLED=n
CONFIG_BT_BLE_SMP_ENABLE=y
CONFIG_BT_STACK_NO_LOG=y
CONFIG_BT_LOG_HCI_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_HCI_TRACE_LEVEL=2
CONFIG_BT_LOG_BTM_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_BTM_TRACE_LEVEL=2
CONFIG_BT_LOG_L2CAP_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_L2CAP_TRACE_LEVEL=2
CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL=2
CONFIG_BT_LOG_SDP_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_SDP_TRACE_LEVEL=2
CONFIG_BT_LOG_GAP_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_GAP_TRACE_LEVEL=2
CONFIG_BT_LOG_BNEP_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_BNEP_TRACE_LEVEL=2
CONFIG_BT_LOG_PAN_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_PAN_TRACE_LEVEL=2
CONFIG_BT_LOG_A2D_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_A2D_TRACE_LEVEL=2
CONFIG_BT_LOG_AVDT_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_AVDT_TRACE_LEVEL=2
CONFIG_BT_LOG_AVCT_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_AVCT_TRACE_LEVEL=2
CONFIG_BT_LOG_AVRC_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_AVRC_TRACE_LEVEL=2
CONFIG_BT_LOG_MCA_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_MCA_TRACE_LEVEL=2
CONFIG_BT_LOG_HID_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_HID_TRACE_LEVEL=2
CONFIG_BT_LOG_APPL_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_APPL_TRACE_LEVEL=2
CONFIG_BT_LOG_GATT_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_GATT_TRACE_LEVEL=2
CONFIG_BT_LOG_SMP_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_SMP_TRACE_LEVEL=2
CONFIG_BT_LOG_BTIF_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_BTIF_TRACE_LEVEL=2
CONFIG_BT_LOG_BTC_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_BTC_TRACE_LEVEL=2
CONFIG_BT_LOG_OSI_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_OSI_TRACE_LEVEL=2
CONFIG_BT_LOG_BLUFI_TRACE_LEVEL_WARNING=y
CONFIG_BT_LOG_BLUFI_TRACE_LEVEL=2
CONFIG_BT_ACL_CONNECTIONS=4
CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST=y
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=y
# CONFIG_BT_BLE_HOST_QUEUE_CONG_CHECK is not set
CONFIG_BT_SMP_ENABLE=y
CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT=30
CONFIG_BT_RESERVE_DRAM=0xdb5c
# CONFIG_BLE_MESH is not set
# CONFIG_ADC_FORCE_XPD_FSM is not set
CONFIG_ADC_DISABLE_DAC=y
CONFIG_SPI_MASTER_IN_IRAM=y
CONFIG_SPI_MASTER_ISR_IN_IRAM=y
CONFIG_SPI_SLAVE_IN_IRAM=y
CONFIG_SPI_SLAVE_ISR_IN_IRAM=y
# CONFIG_EFUSE_CUSTOM_TABLE is not set
# CONFIG_EFUSE_VIRTUAL is not set
# CONFIG_EFUSE_CODE_SCHEME_COMPAT_NONE is not set
CONFIG_EFUSE_CODE_SCHEME_COMPAT_3_4=y
# CONFIG_EFUSE_CODE_SCHEME_COMPAT_REPEAT is not set
CONFIG_EFUSE_MAX_BLK_LEN=192
# CONFIG_ESP_TLS_SERVER is not set
CONFIG_ESP32_REV_MIN_0=y
# CONFIG_ESP32_REV_MIN_1 is not set
# CONFIG_ESP32_REV_MIN_2 is not set
# CONFIG_ESP32_REV_MIN_3 is not set
CONFIG_ESP32_REV_MIN=0
CONFIG_ESP32_DPORT_WORKAROUND=y
# CONFIG_ESP32_DEFAULT_CPU_FREQ_80 is not set
# CONFIG_ESP32_DEFAULT_CPU_FREQ_160 is not set
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240
CONFIG_ESP32_SPIRAM_SUPPORT=y
CONFIG_SPIRAM_BOOT_INIT=y
# CONFIG_SPIRAM_USE_MEMMAP is not set
# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set
CONFIG_SPIRAM_USE_MALLOC=y
CONFIG_SPIRAM_TYPE_AUTO=y
# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set
# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set
CONFIG_SPIRAM_SIZE=-1
# CONFIG_SPIRAM_SPEED_40M is not set
CONFIG_SPIRAM_SPEED_80M=y
CONFIG_SPIRAM_MEMTEST=y
CONFIG_SPIRAM_CACHE_WORKAROUND=y
CONFIG_SPIRAM_BANKSWITCH_ENABLE=y
CONFIG_SPIRAM_BANKSWITCH_RESERVE=8
CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=256
CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=65536
CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY=y
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
# CONFIG_SPIRAM_OCCUPY_HSPI_HOST is not set
CONFIG_SPIRAM_OCCUPY_VSPI_HOST=y
# CONFIG_SPIRAM_OCCUPY_NO_HOST is not set
CONFIG_D0WD_PSRAM_CLK_IO=17
CONFIG_D0WD_PSRAM_CS_IO=16
CONFIG_D2WD_PSRAM_CLK_IO=9
CONFIG_D2WD_PSRAM_CS_IO=10
CONFIG_PICO_PSRAM_CS_IO=10
# CONFIG_ESP32_MEMMAP_TRACEMEM is not set
# CONFIG_ESP32_MEMMAP_TRACEMEM_TWOBANKS is not set
# CONFIG_ESP32_TRAX is not set
CONFIG_ESP32_TRACEMEM_RESERVE_DRAM=0x0
# CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_TWO is not set
CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR=y
CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES=4
# CONFIG_ESP32_ULP_COPROC_ENABLED is not set
CONFIG_ESP32_ULP_COPROC_RESERVE_MEM=0
# CONFIG_ESP32_PANIC_PRINT_HALT is not set
CONFIG_ESP32_PANIC_PRINT_REBOOT=y
# CONFIG_ESP32_PANIC_SILENT_REBOOT is not set
# CONFIG_ESP32_PANIC_GDBSTUB is not set
CONFIG_ESP32_DEBUG_OCDAWARE=y
# CONFIG_ESP32_DEBUG_STUBS_ENABLE is not set
CONFIG_ESP32_BROWNOUT_DET=y
CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0=y
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_1 is not set
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_2 is not set
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_3 is not set
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_4 is not set
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_5 is not set
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_6 is not set
# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_7 is not set
CONFIG_ESP32_BROWNOUT_DET_LVL=0
CONFIG_ESP32_REDUCE_PHY_TX_POWER=y
CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y
# CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set
# CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set
# CONFIG_ESP32_TIME_SYSCALL_USE_NONE is not set
CONFIG_ESP32_RTC_CLK_SRC_INT_RC=y
# CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS is not set
# CONFIG_ESP32_RTC_CLK_SRC_EXT_OSC is not set
# CONFIG_ESP32_RTC_CLK_SRC_INT_8MD256 is not set
CONFIG_ESP32_RTC_CLK_CAL_CYCLES=1024
CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=2000
CONFIG_ESP32_XTAL_FREQ_40=y
# CONFIG_ESP32_XTAL_FREQ_26 is not set
# CONFIG_ESP32_XTAL_FREQ_AUTO is not set
CONFIG_ESP32_XTAL_FREQ=40
# CONFIG_ESP32_DISABLE_BASIC_ROM_CONSOLE is not set
# CONFIG_ESP32_COMPATIBLE_PRE_V2_1_BOOTLOADERS is not set
# CONFIG_ESP32_USE_FIXED_STATIC_RAM_SIZE is not set
CONFIG_ESP32_DPORT_DIS_INTERRUPT_LVL=5
# CONFIG_PM_ENABLE is not set
CONFIG_ADC_CAL_EFUSE_TP_ENABLE=y
CONFIG_ADC_CAL_EFUSE_VREF_ENABLE=y
CONFIG_ADC_CAL_LUT_ENABLE=y
# CONFIG_ESP_TIMER_PROFILING is not set
CONFIG_ESP_ERR_TO_NAME_LOOKUP=y
CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
CONFIG_ESP_IPC_TASK_STACK_SIZE=1024
CONFIG_ESP_TIMER_TASK_STACK_SIZE=3584
CONFIG_ESP_CONSOLE_UART_DEFAULT=y
# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set
# CONFIG_ESP_CONSOLE_UART_NONE is not set
CONFIG_ESP_CONSOLE_UART_NUM=0
CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200
CONFIG_ESP_INT_WDT=y
CONFIG_ESP_INT_WDT_TIMEOUT_MS=800
CONFIG_ESP_INT_WDT_CHECK_CPU1=y
CONFIG_ESP_TASK_WDT=y
# CONFIG_ESP_TASK_WDT_PANIC is not set
CONFIG_ESP_TASK_WDT_TIMEOUT_S=5
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=y
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=y
# CONFIG_ETH_USE_ESP32_EMAC is not set
# CONFIG_ETH_USE_SPI_ETHERNET is not set
# CONFIG_ESP_EVENT_LOOP_PROFILING is not set
CONFIG_ESP_EVENT_POST_FROM_ISR=y
CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=y
CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=y
# CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH is not set
CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024
CONFIG_HTTPD_MAX_URI_LEN=512
CONFIG_HTTPD_ERR_RESP_NO_DELAY=y
CONFIG_HTTPD_PURGE_BUF_LEN=32
# CONFIG_HTTPD_LOG_PURGE_DATA is not set
CONFIG_OTA_ALLOW_HTTP=y
# CONFIG_ESP_HTTPS_SERVER_ENABLE is not set
CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE=y
CONFIG_ESP32_WIFI_SW_COEXIST_PREFERENCE_BALANCE=y
CONFIG_ESP32_WIFI_SW_COEXIST_PREFERENCE_VALUE=2
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=12
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=40
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER=y
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=0
CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM=12
# CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED is not set
# CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED is not set
CONFIG_ESP32_WIFI_NVS_ENABLED=y
CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y
# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set
CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752
CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32
# CONFIG_ESP32_WIFI_DEBUG_LOG_ENABLE is not set
# CONFIG_ESP32_WIFI_IRAM_OPT is not set
# CONFIG_ESP32_WIFI_RX_IRAM_OPT is not set
CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y
#CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION is not set
CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20
CONFIG_ESP32_PHY_MAX_TX_POWER=20
# CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set
CONFIG_ESP32_ENABLE_COREDUMP_TO_UART=y
# CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE is not set
CONFIG_ESP32_ENABLE_COREDUMP=y
CONFIG_ESP32_CORE_DUMP_MAX_TASKS_NUM=64
CONFIG_ESP32_CORE_DUMP_UART_DELAY=0
# CONFIG_FATFS_CODEPAGE_DYNAMIC is not set
CONFIG_FATFS_CODEPAGE_437=y
# CONFIG_FATFS_CODEPAGE_720 is not set
# CONFIG_FATFS_CODEPAGE_737 is not set
# CONFIG_FATFS_CODEPAGE_771 is not set
# CONFIG_FATFS_CODEPAGE_775 is not set
# CONFIG_FATFS_CODEPAGE_850 is not set
# CONFIG_FATFS_CODEPAGE_852 is not set
# CONFIG_FATFS_CODEPAGE_855 is not set
# CONFIG_FATFS_CODEPAGE_857 is not set
# CONFIG_FATFS_CODEPAGE_860 is not set
# CONFIG_FATFS_CODEPAGE_861 is not set
# CONFIG_FATFS_CODEPAGE_862 is not set
# CONFIG_FATFS_CODEPAGE_863 is not set
# CONFIG_FATFS_CODEPAGE_864 is not set
# CONFIG_FATFS_CODEPAGE_865 is not set
# CONFIG_FATFS_CODEPAGE_866 is not set
# CONFIG_FATFS_CODEPAGE_869 is not set
# CONFIG_FATFS_CODEPAGE_932 is not set
# CONFIG_FATFS_CODEPAGE_936 is not set
# CONFIG_FATFS_CODEPAGE_949 is not set
# CONFIG_FATFS_CODEPAGE_950 is not set
CONFIG_FATFS_CODEPAGE=437
CONFIG_FATFS_LFN_NONE=y
# CONFIG_FATFS_LFN_HEAP is not set
# CONFIG_FATFS_LFN_STACK is not set
CONFIG_FATFS_FS_LOCK=0
CONFIG_FATFS_TIMEOUT_MS=10000
CONFIG_FATFS_PER_FILE_CACHE=y
CONFIG_FATFS_ALLOC_PREFER_EXTRAM=y
CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND=150
CONFIG_FMB_MASTER_DELAY_MS_CONVERT=200
CONFIG_FMB_QUEUE_LENGTH=20
CONFIG_FMB_SERIAL_TASK_STACK_SIZE=2048
CONFIG_FMB_SERIAL_BUF_SIZE=256
CONFIG_FMB_SERIAL_TASK_PRIO=10
# CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORT is not set
CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT=20
CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE=20
CONFIG_FMB_CONTROLLER_STACK_SIZE=4096
CONFIG_FMB_EVENT_QUEUE_TIMEOUT=20
CONFIG_FMB_TIMER_PORT_ENABLED=y
CONFIG_FMB_TIMER_GROUP=0
CONFIG_FMB_TIMER_INDEX=0
# CONFIG_FREERTOS_UNICORE is not set
CONFIG_FREERTOS_NO_AFFINITY=0x7FFFFFFF
CONFIG_FREERTOS_CORETIMER_0=y
# CONFIG_FREERTOS_CORETIMER_1 is not set
CONFIG_FREERTOS_HZ=100
CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y
# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set
# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL is not set
CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y
# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set
CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1
CONFIG_FREERTOS_ASSERT_FAIL_ABORT=y
# CONFIG_FREERTOS_ASSERT_FAIL_PRINT_CONTINUE is not set
# CONFIG_FREERTOS_ASSERT_DISABLE is not set
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1536
CONFIG_FREERTOS_ISR_STACKSIZE=1536
# CONFIG_FREERTOS_LEGACY_HOOKS is not set
CONFIG_FREERTOS_MAX_TASK_NAME_LEN=16
CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION=y
# CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP is not set
CONFIG_FREERTOS_TIMER_TASK_PRIORITY=1
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2800
CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10
CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0
#CONFIG_FREERTOS_USE_TRACE_FACILITY=y
#CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y
CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y
#CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y
#CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER=y
# CONFIG_FREERTOS_RUN_TIME_STATS_USING_CPU_CLK is not set
# CONFIG_FREERTOS_DEBUG_INTERNALS is not set
CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y
# CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set
CONFIG_HEAP_POISONING_DISABLED=y
# CONFIG_HEAP_POISONING_LIGHT is not set
# CONFIG_HEAP_POISONING_COMPREHENSIVE is not set
CONFIG_HEAP_TRACING_OFF=y
# CONFIG_HEAP_TRACING_STANDALONE is not set
# CONFIG_HEAP_TRACING_TOHOST is not set
# CONFIG_HEAP_TRACING is not set
# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set
# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
# CONFIG_LOG_DEFAULT_LEVEL_INFO is not set
# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set
# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_COLORS=y
CONFIG_LWIP_LOCAL_HOSTNAME="esp32a1s"
# CONFIG_LWIP_L2_TO_L3_COPY is not set
# CONFIG_LWIP_IRAM_OPTIMIZATION is not set
CONFIG_LWIP_TIMERS_ONDEMAND=y
CONFIG_LWIP_MAX_SOCKETS=16
# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set
CONFIG_LWIP_SO_REUSE=y
CONFIG_LWIP_SO_REUSE_RXTOALL=y
#CONFIG_LWIP_IP_REASSEMBLY is not set
CONFIG_LWIP_IP6_REASSEMBLY=y
CONFIG_LWIP_IP4_REASSEMBLY=y
CONFIG_LWIP_ESP_GRATUITOUS_ARP=y
CONFIG_LWIP_GARP_TMR_INTERVAL=60
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32
CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y
CONFIG_LWIP_DHCP_RESTORE_LAST_IP=y
CONFIG_LWIP_DHCPS_LEASE_UNIT=60
CONFIG_LWIP_DHCPS_MAX_STATION_NUM=8
# CONFIG_LWIP_AUTOIP is not set
# CONFIG_LWIP_IPV6_AUTOCONFIG is not set
CONFIG_LWIP_NETIF_LOOPBACK=y
CONFIG_LWIP_LOOPBACK_MAX_PBUFS=8
CONFIG_LWIP_MAX_ACTIVE_TCP=16
CONFIG_LWIP_MAX_LISTENING_TCP=16
CONFIG_LWIP_TCP_MAXRTX=12
CONFIG_LWIP_TCP_SYNMAXRTX=6
CONFIG_LWIP_TCP_MSS=1440
CONFIG_LWIP_TCP_MSL=60000
CONFIG_LWIP_TCP_SND_BUF_DEFAULT=8192
CONFIG_LWIP_TCP_WND_DEFAULT=32768
CONFIG_LWIP_TCP_RECVMBOX_SIZE=32
CONFIG_LWIP_TCP_QUEUE_OOSEQ=y
# CONFIG_LWIP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set
CONFIG_LWIP_TCP_OVERSIZE_MSS=y
# CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS is not set
# CONFIG_LWIP_TCP_OVERSIZE_DISABLE is not set
# CONFIG_LWIP_WND_SCALE is not set
CONFIG_LWIP_MAX_UDP_PCBS=16
CONFIG_LWIP_UDP_RECVMBOX_SIZE=32
CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=3072
CONFIG_LWIP_TCPIP_TASK_AFFINITY_NO_AFFINITY=y
# CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU0 is not set
# CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU1 is not set
CONFIG_LWIP_TCPIP_TASK_AFFINITY=0x7FFFFFFF
# CONFIG_LWIP_PPP_SUPPORT is not set
# CONFIG_LWIP_MULTICAST_PING is not set
# CONFIG_LWIP_BROADCAST_PING is not set
CONFIG_LWIP_MAX_RAW_PCBS=16
CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1
CONFIG_LWIP_SNTP_UPDATE_DELAY=3600000
# CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC is not set
CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y
# CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC is not set
# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384
# CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN is not set
# CONFIG_MBEDTLS_DEBUG is not set
# CONFIG_MBEDTLS_ECP_RESTARTABLE is not set
# CONFIG_MBEDTLS_CMAC_C is not set
CONFIG_MBEDTLS_HARDWARE_AES=y
CONFIG_MBEDTLS_HARDWARE_MPI=y
CONFIG_MBEDTLS_MPI_USE_INTERRUPT=y
CONFIG_MBEDTLS_HARDWARE_SHA=y
CONFIG_MBEDTLS_HAVE_TIME=y
# CONFIG_MBEDTLS_HAVE_TIME_DATE is not set
# CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT is not set
# CONFIG_MBEDTLS_TLS_SERVER_ONLY is not set
CONFIG_MBEDTLS_TLS_CLIENT_ONLY=y
# CONFIG_MBEDTLS_TLS_DISABLED is not set
CONFIG_MBEDTLS_TLS_CLIENT=y
CONFIG_MBEDTLS_TLS_ENABLED=y
# CONFIG_MBEDTLS_PSK_MODES is not set
CONFIG_MBEDTLS_KEY_EXCHANGE_RSA=y
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA=y
CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE=y
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA=y
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA=y
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA=y
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA=y
CONFIG_MBEDTLS_SSL_RENEGOTIATION=y
# CONFIG_MBEDTLS_SSL_PROTO_SSL3 is not set
# CONFIG_MBEDTLS_SSL_PROTO_TLS1 is not set
CONFIG_MBEDTLS_SSL_PROTO_TLS1_1=y
CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y
# CONFIG_MBEDTLS_SSL_PROTO_DTLS is not set
CONFIG_MBEDTLS_SSL_ALPN=y
CONFIG_MBEDTLS_CLIENT_SSL_SESSION_TICKETS=y
CONFIG_MBEDTLS_SERVER_SSL_SESSION_TICKETS=y
CONFIG_MBEDTLS_AES_C=y
# CONFIG_MBEDTLS_CAMELLIA_C is not set
# CONFIG_MBEDTLS_DES_C is not set
CONFIG_MBEDTLS_RC4_DISABLED=y
# CONFIG_MBEDTLS_RC4_ENABLED_NO_DEFAULT is not set
# CONFIG_MBEDTLS_RC4_ENABLED is not set
# CONFIG_MBEDTLS_BLOWFISH_C is not set
# CONFIG_MBEDTLS_XTEA_C is not set
CONFIG_MBEDTLS_CCM_C=y
CONFIG_MBEDTLS_GCM_C=y
# CONFIG_MBEDTLS_RIPEMD160_C is not set
CONFIG_MBEDTLS_PEM_PARSE_C=y
CONFIG_MBEDTLS_PEM_WRITE_C=y
CONFIG_MBEDTLS_X509_CRL_PARSE_C=y
CONFIG_MBEDTLS_X509_CSR_PARSE_C=y
CONFIG_MBEDTLS_ECP_C=y
CONFIG_MBEDTLS_ECDH_C=y
CONFIG_MBEDTLS_ECDSA_C=y
CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=y
CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED=y
CONFIG_MBEDTLS_ECP_NIST_OPTIM=y
CONFIG_MDNS_MAX_SERVICES=10
CONFIG_MQTT_PROTOCOL_311=y
CONFIG_MQTT_TRANSPORT_SSL=y
CONFIG_MQTT_TRANSPORT_WEBSOCKET=y
CONFIG_MQTT_TRANSPORT_WEBSOCKET_SECURE=y
# CONFIG_MQTT_USE_CUSTOM_CONFIG is not set
# CONFIG_MQTT_TASK_CORE_SELECTION_ENABLED is not set
# CONFIG_MQTT_CUSTOM_OUTBOX is not set
CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF=y
# CONFIG_NEWLIB_STDOUT_LINE_ENDING_LF is not set
# CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR is not set
# CONFIG_NEWLIB_STDIN_LINE_ENDING_CRLF is not set
# CONFIG_NEWLIB_STDIN_LINE_ENDING_LF is not set
CONFIG_NEWLIB_STDIN_LINE_ENDING_CR=y
# CONFIG_NEWLIB_NANO_FORMAT is not set
# CONFIG_OPENSSL_DEBUG is not set
CONFIG_OPENSSL_ASSERT_DO_NOTHING=y
# CONFIG_OPENSSL_ASSERT_EXIT is not set
CONFIG_PTHREAD_TASK_PRIO_DEFAULT=5
CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=3072
CONFIG_PTHREAD_STACK_MIN=768
# CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY is not set
# CONFIG_PTHREAD_DEFAULT_CORE_0 is not set
CONFIG_PTHREAD_DEFAULT_CORE_1=y
CONFIG_PTHREAD_TASK_CORE_DEFAULT=1
CONFIG_PTHREAD_TASK_NAME_DEFAULT="pthread"
# CONFIG_SPI_FLASH_VERIFY_WRITE is not set
# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set
CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y
CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS is not set
# CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set
# CONFIG_SPI_FLASH_USE_LEGACY_IMPL is not set
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=y
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=y
CONFIG_SPIFFS_MAX_PARTITIONS=3
CONFIG_SPIFFS_CACHE=y
CONFIG_SPIFFS_CACHE_WR=y
# CONFIG_SPIFFS_CACHE_STATS is not set
CONFIG_SPIFFS_PAGE_CHECK=y
CONFIG_SPIFFS_GC_MAX_RUNS=10
# CONFIG_SPIFFS_GC_STATS is not set
CONFIG_SPIFFS_PAGE_SIZE=256
CONFIG_SPIFFS_OBJ_NAME_LEN=32
CONFIG_SPIFFS_USE_MAGIC=y
CONFIG_SPIFFS_USE_MAGIC_LENGTH=y
CONFIG_SPIFFS_META_LENGTH=4
CONFIG_SPIFFS_USE_MTIME=y
# CONFIG_SPIFFS_DBG is not set
# CONFIG_SPIFFS_API_DBG is not set
# CONFIG_SPIFFS_GC_DBG is not set
# CONFIG_SPIFFS_CACHE_DBG is not set
# CONFIG_SPIFFS_CHECK_DBG is not set
# CONFIG_SPIFFS_TEST_VISUALISATION is not set
CONFIG_NETIF_IP_LOST_TIMER_INTERVAL=120
CONFIG_TCPIP_LWIP=y
CONFIG_UNITY_ENABLE_FLOAT=y
CONFIG_UNITY_ENABLE_DOUBLE=y
# CONFIG_UNITY_ENABLE_COLOR is not set
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=y
# CONFIG_UNITY_ENABLE_FIXTURE is not set
# CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL is not set
CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT=y
CONFIG_VFS_SUPPORT_TERMIOS=y
CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS=1
CONFIG_SEMIHOSTFS_HOST_PATH_MAX_LEN=128
CONFIG_WL_SECTOR_SIZE_512=y
# CONFIG_WL_SECTOR_SIZE_4096 is not set
CONFIG_WL_SECTOR_SIZE=512
# CONFIG_WL_SECTOR_MODE_PERF is not set
CONFIG_WL_SECTOR_MODE_SAFE=y
CONFIG_WL_SECTOR_MODE=1
CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES=16
CONFIG_WPA_MBEDTLS_CRYPTO=y
# CONFIG_DSP_ANSI is not set
CONFIG_DSP_OPTIMIZED=y
CONFIG_DSP_OPTIMIZATION=1
CONFIG_DSP_MAX_FFT_SIZE_512=y
# CONFIG_DSP_MAX_FFT_SIZE_1024 is not set
# CONFIG_DSP_MAX_FFT_SIZE_2048 is not set
# CONFIG_DSP_MAX_FFT_SIZE_4096 is not set
# CONFIG_DSP_MAX_FFT_SIZE_8192 is not set
# CONFIG_DSP_MAX_FFT_SIZE_16384 is not set
# CONFIG_DSP_MAX_FFT_SIZE_32768 is not set
CONFIG_DSP_MAX_FFT_SIZE=512
# CONFIG_LEGACY_INCLUDE_COMMON_HEADERS is not set
# Deprecated options for backward compatibility
CONFIG_TOOLPREFIX="xtensa-esp32-elf-"
# CONFIG_LOG_BOOTLOADER_LEVEL_NONE is not set
# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set
# CONFIG_LOG_BOOTLOADER_LEVEL_WARN is not set
CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y
# CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set
# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set
CONFIG_LOG_BOOTLOADER_LEVEL=3
# CONFIG_APP_ROLLBACK_ENABLE is not set
# CONFIG_FLASH_ENCRYPTION_ENABLED is not set
CONFIG_FLASHMODE_QIO=y
# CONFIG_FLASHMODE_QOUT is not set
# CONFIG_FLASHMODE_DIO is not set
# CONFIG_FLASHMODE_DOUT is not set
# CONFIG_MONITOR_BAUD_9600B is not set
# CONFIG_MONITOR_BAUD_57600B is not set
CONFIG_MONITOR_BAUD_115200B=y
# CONFIG_MONITOR_BAUD_230400B is not set
# CONFIG_MONITOR_BAUD_921600B is not set
# CONFIG_MONITOR_BAUD_2MB is not set
# CONFIG_MONITOR_BAUD_OTHER is not set
CONFIG_MONITOR_BAUD_OTHER_VAL=115200
CONFIG_MONITOR_BAUD=115200
# CONFIG_OPTIMIZATION_LEVEL_DEBUG is not set
CONFIG_OPTIMIZATION_LEVEL_RELEASE=y
CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y
# CONFIG_OPTIMIZATION_ASSERTIONS_SILENT is not set
# CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED is not set
CONFIG_CXX_EXCEPTIONS=y
CONFIG_CXX_EXCEPTIONS_EMG_POOL_SIZE=0
CONFIG_STACK_CHECK_NONE=y
# CONFIG_STACK_CHECK_NORM is not set
# CONFIG_STACK_CHECK_STRONG is not set
# CONFIG_STACK_CHECK_ALL is not set
# CONFIG_STACK_CHECK is not set
# CONFIG_WARN_WRITE_STRINGS is not set
# CONFIG_DISABLE_GCC8_WARNINGS is not set
# CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY is not set
CONFIG_BTDM_CONTROLLER_MODE_BR_EDR_ONLY=y
# CONFIG_BTDM_CONTROLLER_MODE_BTDM is not set
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN=2
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN=0
CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF=0
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_EFF=2
CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_EFF=0
CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE=0
CONFIG_BTDM_CONTROLLER_HCI_MODE_VHCI=y
# CONFIG_BTDM_CONTROLLER_HCI_MODE_UART_H4 is not set
CONFIG_BTDM_CONTROLLER_MODEM_SLEEP=y
CONFIG_BLUEDROID_ENABLED=y
CONFIG_BTC_TASK_STACK_SIZE=3072
CONFIG_BLUEDROID_PINNED_TO_CORE_0=y
# CONFIG_BLUEDROID_PINNED_TO_CORE_1 is not set
CONFIG_BLUEDROID_PINNED_TO_CORE=0
CONFIG_BTU_TASK_STACK_SIZE=4096
# CONFIG_BLUEDROID_MEM_DEBUG is not set
CONFIG_CLASSIC_BT_ENABLED=y
CONFIG_A2DP_ENABLE=y
# CONFIG_HFP_ENABLE is not set
# CONFIG_BLE_HOST_QUEUE_CONGESTION_CHECK is not set
CONFIG_SMP_ENABLE=y
CONFIG_BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT=30
CONFIG_ADC2_DISABLE_DAC=y
CONFIG_SPIRAM_SUPPORT=y
CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST=y
# CONFIG_MEMMAP_TRACEMEM is not set
# CONFIG_MEMMAP_TRACEMEM_TWOBANKS is not set
CONFIG_TRACEMEM_RESERVE_DRAM=0x0
# CONFIG_TWO_UNIVERSAL_MAC_ADDRESS is not set
CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y
CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4
# CONFIG_ULP_COPROC_ENABLED is not set
CONFIG_ULP_COPROC_RESERVE_MEM=0
CONFIG_BROWNOUT_DET=y
CONFIG_BROWNOUT_DET_LVL_SEL_0=y
# CONFIG_BROWNOUT_DET_LVL_SEL_1 is not set
# CONFIG_BROWNOUT_DET_LVL_SEL_2 is not set
# CONFIG_BROWNOUT_DET_LVL_SEL_3 is not set
# CONFIG_BROWNOUT_DET_LVL_SEL_4 is not set
# CONFIG_BROWNOUT_DET_LVL_SEL_5 is not set
# CONFIG_BROWNOUT_DET_LVL_SEL_6 is not set
# CONFIG_BROWNOUT_DET_LVL_SEL_7 is not set
CONFIG_BROWNOUT_DET_LVL=0
CONFIG_REDUCE_PHY_TX_POWER=y
CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y
# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL is not set
# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_OSC is not set
# CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_8MD256 is not set
# CONFIG_DISABLE_BASIC_ROM_CONSOLE is not set
# CONFIG_COMPATIBLE_PRE_V2_1_BOOTLOADERS is not set
CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32
CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2304
CONFIG_MAIN_TASK_STACK_SIZE=8192
CONFIG_IPC_TASK_STACK_SIZE=1024
CONFIG_TIMER_TASK_STACK_SIZE=3584
CONFIG_CONSOLE_UART_DEFAULT=y
# CONFIG_CONSOLE_UART_CUSTOM is not set
# CONFIG_CONSOLE_UART_NONE is not set
CONFIG_CONSOLE_UART_NUM=0
CONFIG_CONSOLE_UART_BAUDRATE=115200
CONFIG_INT_WDT=y
CONFIG_INT_WDT_TIMEOUT_MS=800
CONFIG_INT_WDT_CHECK_CPU1=y
CONFIG_TASK_WDT=y
# CONFIG_TASK_WDT_PANIC is not set
CONFIG_TASK_WDT_TIMEOUT_S=5
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=y
CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1=y
# CONFIG_EVENT_LOOP_PROFILING is not set
CONFIG_POST_EVENTS_FROM_ISR=y
CONFIG_POST_EVENTS_FROM_IRAM_ISR=y
CONFIG_SW_COEXIST_ENABLE=y
CONFIG_SW_COEXIST_PREFERENCE_BALANCE=y
CONFIG_SW_COEXIST_PREFERENCE_VALUE=2
CONFIG_MB_MASTER_TIMEOUT_MS_RESPOND=150
CONFIG_MB_MASTER_DELAY_MS_CONVERT=200
CONFIG_MB_QUEUE_LENGTH=20
CONFIG_MB_SERIAL_TASK_STACK_SIZE=2048
CONFIG_MB_SERIAL_BUF_SIZE=256
CONFIG_MB_SERIAL_TASK_PRIO=10
# CONFIG_MB_CONTROLLER_SLAVE_ID_SUPPORT is not set
CONFIG_MB_CONTROLLER_NOTIFY_TIMEOUT=20
CONFIG_MB_CONTROLLER_NOTIFY_QUEUE_SIZE=20
CONFIG_MB_CONTROLLER_STACK_SIZE=4096
CONFIG_MB_EVENT_QUEUE_TIMEOUT=20
CONFIG_MB_TIMER_PORT_ENABLED=y
CONFIG_MB_TIMER_GROUP=0
CONFIG_MB_TIMER_INDEX=0
CONFIG_SUPPORT_STATIC_ALLOCATION=y
# CONFIG_ENABLE_STATIC_TASK_CLEAN_UP_HOOK is not set
CONFIG_TIMER_TASK_PRIORITY=1
CONFIG_TIMER_TASK_STACK_DEPTH=2800
CONFIG_TIMER_QUEUE_LENGTH=10
# CONFIG_L2_TO_L3_COPY is not set
# CONFIG_USE_ONLY_LWIP_SELECT is not set
CONFIG_ESP_GRATUITOUS_ARP=y
CONFIG_GARP_TMR_INTERVAL=60
CONFIG_TCPIP_RECVMBOX_SIZE=32
CONFIG_TCP_MAXRTX=12
CONFIG_TCP_SYNMAXRTX=6
CONFIG_TCP_MSS=1440
CONFIG_TCP_MSL=60000
CONFIG_TCP_SND_BUF_DEFAULT=8192
CONFIG_TCP_WND_DEFAULT=32768
CONFIG_TCP_RECVMBOX_SIZE=32
CONFIG_TCP_QUEUE_OOSEQ=y
# CONFIG_ESP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set
CONFIG_TCP_OVERSIZE_MSS=y
# CONFIG_TCP_OVERSIZE_QUARTER_MSS is not set
# CONFIG_TCP_OVERSIZE_DISABLE is not set
CONFIG_UDP_RECVMBOX_SIZE=32
CONFIG_TCPIP_TASK_STACK_SIZE=3072
CONFIG_TCPIP_TASK_AFFINITY_NO_AFFINITY=y
# CONFIG_TCPIP_TASK_AFFINITY_CPU0 is not set
# CONFIG_TCPIP_TASK_AFFINITY_CPU1 is not set
CONFIG_TCPIP_TASK_AFFINITY=0x7FFFFFFF
# CONFIG_PPP_SUPPORT is not set
CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT=5
CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT=3072
CONFIG_ESP32_PTHREAD_STACK_MIN=768
# CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY is not set
# CONFIG_ESP32_DEFAULT_PTHREAD_CORE_0 is not set
CONFIG_ESP32_DEFAULT_PTHREAD_CORE_1=y
CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT=1
CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT="pthread"
CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS=y
# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_FAILS is not set
# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED is not set
CONFIG_IP_LOST_TIMER_INTERVAL=120
CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT=y
CONFIG_SUPPORT_TERMIOS=y
# End of deprecated options

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

47
buildFirmware.sh Executable file
View File

@@ -0,0 +1,47 @@
#!/bin/bash
echo "Build process started"
echo "Setting up build name and build number"
if [ -z "${TARGET_BUILD_NAME}" ]
then
export TARGET_BUILD_NAME="I2S-4MFlash"
echo "TARGET_BUILD_NAME is not set. Defaulting to ${TARGET_BUILD_NAME}"
fi
if [ -z "${BUILD_NUMBER}" ]
then
export BUILD_NUMBER="500"
echo "BUILD_NUMBER is not set. Defaulting to ${BUILD_NUMBER}"
fi
if [ -z "$DEPTH" ]
then
export DEPTH="16"
echo "DEPTH is not set. Defaulting to ${DEPTH}"
fi
if [ -z "$tag" ]
then
branch_name="$(git rev-parse --abbrev-ref HEAD)"
branch_name="${branch_name//[^a-zA-Z0-9\-~!@_\.]/}"
app_name="${TARGET_BUILD_NAME}.${DEPTH}.dev-$(git log --pretty=format:'%h' --max-count=1).${branch_name}"
echo "${app_name}">version.txt
echo "app_name is not set. Defaulting to ${app_name}"
else
echo "${tag}" >version.txt
fi
echo "Copying target sdkconfig"
cp build-scripts/${TARGET_BUILD_NAME}-sdkconfig.defaults sdkconfig
echo "Building project"
idf.py build -DDEPTH=${DEPTH} -DBUILD_NUMBER=${BUILD_NUMBER}-${DEPTH}
echo "Generating size report"
idf.py size-components >build/size_components.txt
idf.py size-components-squeezelite build/size_components_squeezelite.txt
if [ -z "${artifact_file_name}" ]
then
echo "No artifact file name set. Will not generate zip file."
else
echo "Generating build artifact zip file"
zip -r build_output.zip build
zip build/${artifact_file_name} partitions*.csv components/ build/*.bin build/bootloader/bootloader.bin build/partition_table/partition-table.bin build/flash_project_args build/size_*.txt
fi

View File

@@ -0,0 +1,21 @@
set(lib_dir ${build_dir}/esp-idf)
set(driver i2s.c i2s_hal.c spi_bus_lock.c)
string(REPLACE ".c" ".c.obj" driver_obj "${driver}")
idf_component_register( SRCS ${driver}
REQUIRES driver
INCLUDE_DIRS ${IDF_PATH}/components/driver
PRIV_INCLUDE_DIRS ${IDF_PATH}/components/driver/include/driver
)
# CMake is just a pile of crap
message("!! overriding ${driver} !!")
message("CAREFUL, LIBRARIES STRIPPING FROM DUPLICATED COMPONENTS DEPENDS ON THIS BEING REBUILD")
add_custom_command(
TARGET ${COMPONENT_LIB}
PRE_LINK
COMMAND xtensa-esp32-elf-ar -d ${lib_dir}/driver/libdriver.a ${driver_obj}
VERBATIM
)

1206
components/_override/i2s.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,275 @@
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// The HAL layer for I2S (common part)
#include "soc/soc.h"
#include "soc/soc_caps.h"
#include "hal/i2s_hal.h"
#define I2S_TX_PDM_FP_DEF 960 // Set to the recommended value(960) in TRM
#define I2S_RX_PDM_DSR_DEF 0
void i2s_hal_set_tx_mode(i2s_hal_context_t *hal, i2s_channel_t ch, i2s_bits_per_sample_t bits)
{
if (bits <= I2S_BITS_PER_SAMPLE_16BIT) {
i2s_ll_set_tx_fifo_mod(hal->dev, (ch == I2S_CHANNEL_STEREO) ? 0 : 1);
} else {
i2s_ll_set_tx_fifo_mod(hal->dev, (ch == I2S_CHANNEL_STEREO) ? 2 : 3);
}
i2s_ll_set_tx_chan_mod(hal->dev, (ch == I2S_CHANNEL_STEREO) ? 0 : 1);
#if SOC_I2S_SUPPORTS_DMA_EQUAL
i2s_ll_set_tx_dma_equal(hal->dev, (ch == I2S_CHANNEL_STEREO) ? 0 : 1);
#endif
}
void i2s_hal_set_rx_mode(i2s_hal_context_t *hal, i2s_channel_t ch, i2s_bits_per_sample_t bits)
{
if (bits <= I2S_BITS_PER_SAMPLE_16BIT) {
i2s_ll_set_rx_fifo_mod(hal->dev, (ch == I2S_CHANNEL_STEREO) ? 0 : 1);
} else {
i2s_ll_set_rx_fifo_mod(hal->dev, (ch == I2S_CHANNEL_STEREO) ? 2 : 3);
}
i2s_ll_set_rx_chan_mod(hal->dev, (ch == I2S_CHANNEL_STEREO) ? 0 : 1);
#if SOC_I2S_SUPPORTS_DMA_EQUAL
i2s_ll_set_rx_dma_equal(hal->dev, (ch == I2S_CHANNEL_STEREO) ? 0 : 1);
#endif
}
void i2s_hal_set_in_link(i2s_hal_context_t *hal, uint32_t bytes_num, uint32_t addr)
{
i2s_ll_set_in_link_addr(hal->dev, addr);
i2s_ll_set_rx_eof_num(hal->dev, bytes_num);
}
#if SOC_I2S_SUPPORTS_PDM
void i2s_hal_tx_pdm_cfg(i2s_hal_context_t *hal, uint32_t fp, uint32_t fs)
{
i2s_ll_tx_pdm_cfg(hal->dev, fp, fs);
}
void i2s_hal_get_tx_pdm(i2s_hal_context_t *hal, uint32_t *fp, uint32_t *fs)
{
i2s_ll_get_tx_pdm(hal->dev, fp, fs);
}
void i2s_hal_rx_pdm_cfg(i2s_hal_context_t *hal, uint32_t dsr)
{
i2s_ll_rx_pdm_cfg(hal->dev, dsr);
}
void i2s_hal_get_rx_pdm(i2s_hal_context_t *hal, uint32_t *dsr)
{
i2s_ll_get_rx_pdm(hal->dev, dsr);
}
#endif
void i2s_hal_set_clk_div(i2s_hal_context_t *hal, int div_num, int div_a, int div_b, int tx_bck_div, int rx_bck_div)
{
i2s_ll_set_clkm_div_num(hal->dev, div_num);
i2s_ll_set_clkm_div_a(hal->dev, div_a);
i2s_ll_set_clkm_div_b(hal->dev, div_b);
i2s_ll_set_tx_bck_div_num(hal->dev, tx_bck_div);
i2s_ll_set_rx_bck_div_num(hal->dev, rx_bck_div);
}
void i2s_hal_set_tx_bits_mod(i2s_hal_context_t *hal, i2s_bits_per_sample_t bits)
{
i2s_ll_set_tx_bits_mod(hal->dev, bits);
}
void i2s_hal_set_rx_bits_mod(i2s_hal_context_t *hal, i2s_bits_per_sample_t bits)
{
i2s_ll_set_rx_bits_mod(hal->dev, bits);
}
void i2s_hal_reset(i2s_hal_context_t *hal)
{
// Reset I2S TX/RX module first, and then, reset DMA and FIFO.
i2s_ll_reset_tx(hal->dev);
i2s_ll_reset_rx(hal->dev);
i2s_ll_reset_dma_in(hal->dev);
i2s_ll_reset_dma_out(hal->dev);
i2s_ll_reset_rx_fifo(hal->dev);
i2s_ll_reset_tx_fifo(hal->dev);
}
void i2s_hal_start_tx(i2s_hal_context_t *hal)
{
i2s_ll_start_out_link(hal->dev);
i2s_ll_start_tx(hal->dev);
}
void i2s_hal_start_rx(i2s_hal_context_t *hal)
{
i2s_ll_start_in_link(hal->dev);
i2s_ll_start_rx(hal->dev);
}
void i2s_hal_stop_tx(i2s_hal_context_t *hal)
{
i2s_ll_stop_out_link(hal->dev);
i2s_ll_stop_tx(hal->dev);
}
void i2s_hal_stop_rx(i2s_hal_context_t *hal)
{
i2s_ll_stop_in_link(hal->dev);
i2s_ll_stop_rx(hal->dev);
}
void i2s_hal_format_config(i2s_hal_context_t *hal, const i2s_config_t *i2s_config)
{
switch (i2s_config->communication_format) {
case I2S_COMM_FORMAT_STAND_MSB:
if (i2s_config->mode & I2S_MODE_TX) {
i2s_ll_set_tx_format_msb_align(hal->dev);
}
if (i2s_config->mode & I2S_MODE_RX) {
i2s_ll_set_rx_format_msb_align(hal->dev);
}
break;
case I2S_COMM_FORMAT_STAND_PCM_SHORT:
if (i2s_config->mode & I2S_MODE_TX) {
i2s_ll_set_tx_pcm_long(hal->dev);
}
if (i2s_config->mode & I2S_MODE_RX) {
i2s_ll_set_rx_pcm_long(hal->dev);
}
break;
case I2S_COMM_FORMAT_STAND_PCM_LONG:
if (i2s_config->mode & I2S_MODE_TX) {
i2s_ll_set_tx_pcm_short(hal->dev);
}
if (i2s_config->mode & I2S_MODE_RX) {
i2s_ll_set_rx_pcm_short(hal->dev);
}
break;
default: //I2S_COMM_FORMAT_STAND_I2S
if (i2s_config->mode & I2S_MODE_TX) {
i2s_ll_set_tx_format_philip(hal->dev);
}
if (i2s_config->mode & I2S_MODE_RX) {
i2s_ll_set_rx_format_philip(hal->dev);
}
break;
}
}
void i2s_hal_config_param(i2s_hal_context_t *hal, const i2s_config_t *i2s_config)
{
//reset i2s
i2s_ll_reset_tx(hal->dev);
i2s_ll_reset_rx(hal->dev);
//reset dma
i2s_ll_reset_dma_in(hal->dev);
i2s_ll_reset_dma_out(hal->dev);
i2s_ll_enable_dma(hal->dev);
i2s_ll_set_lcd_en(hal->dev, 0);
i2s_ll_set_camera_en(hal->dev, 0);
i2s_ll_set_dscr_en(hal->dev, 0);
i2s_ll_set_tx_chan_mod(hal->dev, i2s_config->channel_format < I2S_CHANNEL_FMT_ONLY_RIGHT ? i2s_config->channel_format : (i2s_config->channel_format >> 1)); // 0-two channel;1-right;2-left;3-righ;4-left
i2s_ll_set_tx_fifo_mod(hal->dev, i2s_config->channel_format < I2S_CHANNEL_FMT_ONLY_RIGHT ? 0 : 1); // 0-right&left channel;1-one channel
i2s_ll_set_tx_mono(hal->dev, 0);
i2s_ll_set_rx_chan_mod(hal->dev, i2s_config->channel_format < I2S_CHANNEL_FMT_ONLY_RIGHT ? i2s_config->channel_format : (i2s_config->channel_format >> 1)); // 0-two channel;1-right;2-left;3-righ;4-left
i2s_ll_set_rx_fifo_mod(hal->dev, i2s_config->channel_format < I2S_CHANNEL_FMT_ONLY_RIGHT ? 0 : 1); // 0-right&left channel;1-one channel
i2s_ll_set_rx_mono(hal->dev, 0);
i2s_ll_set_dscr_en(hal->dev, 1); //connect dma to fifo
i2s_ll_stop_tx(hal->dev);
i2s_ll_stop_rx(hal->dev);
if (i2s_config->mode & I2S_MODE_TX) {
int order = i2s_config->bits_per_sample == 32 ? 0 : 1;
i2s_ll_set_tx_msb_right(hal->dev, order);
i2s_ll_set_tx_right_first(hal->dev, ~order);
i2s_ll_set_tx_slave_mod(hal->dev, 0); // Master
i2s_ll_set_tx_fifo_mod_force_en(hal->dev, 1);
if (i2s_config->mode & I2S_MODE_SLAVE) {
i2s_ll_set_tx_slave_mod(hal->dev, 1); //TX Slave
}
}
if (i2s_config->mode & I2S_MODE_RX) {
i2s_ll_set_rx_msb_right(hal->dev, 0);
i2s_ll_set_rx_right_first(hal->dev, 0);
i2s_ll_set_rx_slave_mod(hal->dev, 0); // Master
i2s_ll_set_rx_fifo_mod_force_en(hal->dev, 1);
if (i2s_config->mode & I2S_MODE_SLAVE) {
i2s_ll_set_rx_slave_mod(hal->dev, 1); //RX Slave
}
}
#if SOC_I2S_SUPPORTS_PDM
if (!(i2s_config->mode & I2S_MODE_PDM)) {
i2s_ll_set_rx_pdm_en(hal->dev, 0);
i2s_ll_set_tx_pdm_en(hal->dev, 0);
} else {
if (i2s_config->mode & I2S_MODE_TX) {
i2s_ll_tx_pdm_cfg(hal->dev, I2S_TX_PDM_FP_DEF, i2s_config->sample_rate/100);
}
if(i2s_config->mode & I2S_MODE_RX) {
i2s_ll_rx_pdm_cfg(hal->dev, I2S_RX_PDM_DSR_DEF);
}
// PDM mode have nothing to do with communication format configuration.
return;
}
#endif
#if SOC_I2S_SUPPORTS_ADC_DAC
if (i2s_config->mode & (I2S_MODE_DAC_BUILT_IN | I2S_MODE_ADC_BUILT_IN)) {
if (i2s_config->mode & I2S_MODE_DAC_BUILT_IN) {
i2s_ll_build_in_dac_ena(hal->dev);
}
if (i2s_config->mode & I2S_MODE_ADC_BUILT_IN) {
i2s_ll_build_in_adc_ena(hal->dev);
i2s_ll_set_rx_chan_mod(hal->dev, 1);
i2s_ll_set_rx_fifo_mod(hal->dev, 1);
i2s_ll_set_rx_mono(hal->dev, 0);
}
// Buildin ADC and DAC have nothing to do with communication format configuration.
return;
}
#endif
i2s_hal_format_config(hal, i2s_config);
}
void i2s_hal_enable_master_mode(i2s_hal_context_t *hal)
{
i2s_ll_set_tx_slave_mod(hal->dev, 0); //MASTER Slave
i2s_ll_set_rx_slave_mod(hal->dev, 1); //RX Slave
}
void i2s_hal_enable_slave_mode(i2s_hal_context_t *hal)
{
i2s_ll_set_tx_slave_mod(hal->dev, 1); //TX Slave
i2s_ll_set_rx_slave_mod(hal->dev, 1); //RX Slave
}
void i2s_hal_init(i2s_hal_context_t *hal, int i2s_num)
{
//Get hardware instance.
hal->dev = I2S_LL_GET_HW(i2s_num);
}

View File

@@ -0,0 +1,849 @@
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include <stdatomic.h>
#include "sdkconfig.h"
#include "spi_common_internal.h"
#include "esp_intr_alloc.h"
#include "soc/soc_caps.h"
#include "stdatomic.h"
#include "esp_log.h"
#include <strings.h>
#include "esp_heap_caps.h"
/*
* This lock is designed to solve the conflicts between SPI devices (used in tasks) and
* the background operations (ISR or cache access).
*
* There are N (device/task) + 1 (BG) acquiring processer candidates that may touch the bus.
*
* The core of the lock is a `status` atomic variable, which is always available. No intermediate
* status is allowed. The atomic operations (mainly `atomic_fetch_and`, `atomic_fetch_or`)
* atomically read the status, and bitwisely write status value ORed / ANDed with given masks.
*
* Definitions of the status:
* - [30] WEAK_BG_FLAG, active when the BG is the cache
* - [29:20] LOCK bits, active when corresponding device is asking for acquiring
* - [19:10] PENDING bits, active when the BG acknowledges the REQ bits, but hasn't fully handled them.
* - [ 9: 0] REQ bits, active when corresponding device is requesting for BG operations.
*
* The REQ bits together PENDING bits are called BG bits, which represent the actual BG request
* state of devices. Either one of REQ or PENDING being active indicates the device has pending BG
* requests. Reason of having two bits instead of one is in the appendix below.
*
* Acquiring processer means the current processor (task or ISR) allowed to touch the critical
* resources, or the SPI bus.
*
* States of the lock:
* - STATE_IDLE: There's no acquiring processor. No device is acquiring the bus, and no BG
* operation is in progress.
*
* - STATE_ACQ: The acquiring processor is a device task. This means one of the devices is
* acquiring the bus.
*
* - STATE_BG: The acquiring processor is the ISR, and there is no acquiring device.
*
* - STATE_BG_ACQ: The acquiring processor is the ISR, and there is an acquiring device.
*
*
* Whenever a bit is written to the status, it means the a device on a task is trying to acquire
* the lock (either for the task, or the ISR). When there is no LOCK bits or BG bits active, the
* caller immediately become the acquiring processor. Otherwise, the task has to block, and the ISR
* will not be invoked until scheduled by the current acquiring processor.
*
* The acquiring processor is responsible to assign the next acquiring processor by calling the
* scheduler, usually after it finishes some requests, and cleared the corresponding status bit.
* But there is one exception, when the last bit is cleared from the status, after which there is
* no other LOCK bits or BG bits active, the acquiring processor lost its role immediately, and
* don't need to call the scheduler to assign the next acquiring processor.
*
* The acquiring processor may also choose to assign a new acquiring device when there is no, by
* calling `spi_bus_lock_bg_rotate_acq_dev` in the ISR. But the acquiring processor, in this case,
* is still the ISR, until it calls the scheduler.
*
*
* Transition of the FSM:
*
* - STATE_IDLE: no acquiring device, nor acquiring processor, no LOCK or BG bits active
* -> STATE_BG: by `req_core`
* -> STATE_ACQ: by `acquire_core`
*
* - STATE_BG:
* * No acquiring device, the ISR is the acquiring processor, there is BG bits active, but no LOCK
* bits
* * The BG operation should be enabled while turning into this state.
*
* -> STATE_IDLE: by `bg_exit_core` after `clear_pend_core` for all BG bits
* -> STATE_BG_ACQ: by `schedule_core`, when there is new LOCK bit set (by `acquire_core`)
*
* - STATE_BG_ACQ:
* * There is acquiring device, the ISR is the acquiring processor, there may be BG bits active for
* the acquiring device.
* * The BG operation should be enabled while turning into this state.
*
* -> STATE_ACQ: by `bg_exit_core` after `clear_pend_core` for all BG bits for the acquiring
* device.
*
* Should not go to the STATE_ACQ (unblock the acquiring task) until all requests of the
* acquiring device are finished. This is to preserve the sequence of foreground (polling) and
* background operations of the device. The background operations queued before the acquiring
* should be completed first.
*
* - STATE_ACQ:
* * There is acquiring device, the task is the acquiring processor, there is no BG bits active for
* the acquiring device.
* * The acquiring task (if blocked at `spi_bus_lock_acquire_start` or `spi_bus_lock_wait_bg_done`)
* should be resumed while turning into this state.
*
* -> STATE_BG_ACQ: by `req_core`
* -> STATE_BG_ACQ (other device): by `acquire_end_core`, when there is LOCK bit for another
* device, and the new acquiring device has active BG bits.
* -> STATE_ACQ (other device): by `acquire_end_core`, when there is LOCK bit for another devices,
* but the new acquiring device has no active BG bits.
* -> STATE_BG: by `acquire_end_core` when there is no LOCK bit active, but there are active BG
* bits.
* -> STATE_IDLE: by `acquire_end_core` when there is no LOCK bit, nor BG bit active.
*
* The `req_core` used in the task is a little special. It asks for acquiring processor for the
* ISR. When it succeed for the first time, it will invoke the ISR (hence passing the acquiring
* role to the BG). Otherwise it will not block, the ISR will be automatically be invoked by other
* acquiring processor. The caller of `req_core` will never become acquiring processor by this
* function.
*
*
* Appendix: The design, that having both request bit and pending bit, is to solve the
* concurrency issue between tasks and the bg, when the task can queue several requests,
* however the request bit cannot represent the number of requests queued.
*
* Here's the workflow of task and ISR work concurrently:
* - Task: (a) Write to Queue -> (b) Write request bit
* The Task have to write request bit (b) after the data is prepared in the queue (a),
* otherwise the BG may fail to read from the queue when it sees the request bit set.
*
* - BG: (c) Read queue -> (d) Clear request bit
* Since the BG cannot know the number of requests queued, it have to repeatedly check the
* queue (c), until it find the data is empty, and then clear the request bit (d).
*
* The events are possible to happen in the order: (c) -> (a) -> (b) -> (d). This may cause a false
* clear of the request bit. And there will be data prepared in the queue, but the request bit is
* inactive.
*
* (e) move REQ bits to PEND bits, happen before (c) is introduced to solve this problem. In this
* case (d) is changed to clear the PEND bit. Even if (e) -> (c) -> (a) -> (b) -> (d), only PEND
* bit is cleared, while the REQ bit is still active.
*/
struct spi_bus_lock_dev_t;
typedef struct spi_bus_lock_dev_t spi_bus_lock_dev_t;
typedef struct spi_bus_lock_t spi_bus_lock_t;
#define MAX_DEV_NUM 10
// Bit 29-20: lock bits, Bit 19-10: pending bits
// Bit 9-0: request bits, Bit 30:
#define LOCK_SHIFT 20
#define PENDING_SHIFT 10
#define REQ_SHIFT 0
#define WEAK_BG_FLAG BIT(30) /**< The bus is permanently requested by background operations.
* This flag is weak, will not prevent acquiring of devices. But will help the BG to be re-enabled again after the bus is release.
*/
// get the bit mask wher bit [high-1, low] are all 1'b1 s.
#define BIT1_MASK(high, low) ((UINT32_MAX << (high)) ^ (UINT32_MAX << (low)))
#define LOCK_BIT(mask) ((mask) << LOCK_SHIFT)
#define REQUEST_BIT(mask) ((mask) << REQ_SHIFT)
#define PENDING_BIT(mask) ((mask) << PENDING_SHIFT)
#define DEV_MASK(id) (LOCK_BIT(1<<id) | PENDING_BIT(1<<id) | REQUEST_BIT(1<<id))
#define ID_DEV_MASK(mask) (ffs(mask) - 1)
#define REQ_MASK BIT1_MASK(REQ_SHIFT+MAX_DEV_NUM, REQ_SHIFT)
#define PEND_MASK BIT1_MASK(PENDING_SHIFT+MAX_DEV_NUM, PENDING_SHIFT)
#define BG_MASK BIT1_MASK(REQ_SHIFT+MAX_DEV_NUM*2, REQ_SHIFT)
#define LOCK_MASK BIT1_MASK(LOCK_SHIFT+MAX_DEV_NUM, LOCK_SHIFT)
#define DEV_REQ_MASK(dev) ((dev)->mask & REQ_MASK)
#define DEV_PEND_MASK(dev) ((dev)->mask & PEND_MASK)
#define DEV_BG_MASK(dev) ((dev)->mask & BG_MASK)
struct spi_bus_lock_t {
/**
* The core of the lock. These bits are status of the lock, which should be always available.
* No intermediate status is allowed. This is realized by atomic operations, mainly
* `atomic_fetch_and`, `atomic_fetch_or`, which atomically read the status, and bitwise write
* status value ORed / ANDed with given masks.
*
* The request bits together pending bits represent the actual bg request state of one device.
* Either one of them being active indicates the device has pending bg requests.
*
* Whenever a bit is written to the status, it means the a device on a task is trying to
* acquire the lock. But this will succeed only when no LOCK or BG bits active.
*
* The acquiring processor is responsible to call the scheduler to pass its role to other tasks
* or the BG, unless it clear the last bit in the status register.
*/
//// Critical resources, they are only writable by acquiring processor, and stable only when read by the acquiring processor.
atomic_uint_fast32_t status;
spi_bus_lock_dev_t* volatile acquiring_dev; ///< The acquiring device
bool volatile acq_dev_bg_active; ///< BG is the acquiring processor serving the acquiring device, used for the wait_bg to skip waiting quickly.
bool volatile in_isr; ///< ISR is touching HW
//// End of critical resources
atomic_intptr_t dev[DEV_NUM_MAX]; ///< Child locks.
bg_ctrl_func_t bg_enable; ///< Function to enable background operations.
bg_ctrl_func_t bg_disable; ///< Function to disable background operations
void* bg_arg; ///< Argument for `bg_enable` and `bg_disable` functions.
spi_bus_lock_dev_t* last_dev; ///< Last used device, to decide whether to refresh all registers.
int periph_cs_num; ///< Number of the CS pins the HW has.
//debug information
int host_id; ///< Host ID, for debug information printing
uint32_t new_req; ///< Last int_req when `spi_bus_lock_bg_start` is called. Debug use.
};
struct spi_bus_lock_dev_t {
SemaphoreHandle_t semphr; ///< Binray semaphore to notify the device it claimed the bus
spi_bus_lock_t* parent; ///< Pointer to parent spi_bus_lock_t
uint32_t mask; ///< Bitwise OR-ed mask of the REQ, PEND, LOCK bits of this device
};
portMUX_TYPE s_spinlock = portMUX_INITIALIZER_UNLOCKED;
DRAM_ATTR static const char TAG[] = "bus_lock";
#define LOCK_CHECK(a, str, ret_val, ...) \
if (!(a)) { \
ESP_LOGE(TAG,"%s(%d): "str, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
return (ret_val); \
}
static inline int mask_get_id(uint32_t mask);
static inline int dev_lock_get_id(spi_bus_lock_dev_t *dev_lock);
/*******************************************************************************
* atomic operations to the status
******************************************************************************/
SPI_MASTER_ISR_ATTR static inline uint32_t lock_status_fetch_set(spi_bus_lock_t *lock, uint32_t set)
{
return atomic_fetch_or(&lock->status, set);
}
IRAM_ATTR static inline uint32_t lock_status_fetch_clear(spi_bus_lock_t *lock, uint32_t clear)
{
return atomic_fetch_and(&lock->status, ~clear);
}
IRAM_ATTR static inline uint32_t lock_status_fetch(spi_bus_lock_t *lock)
{
return atomic_load(&lock->status);
}
SPI_MASTER_ISR_ATTR static inline void lock_status_init(spi_bus_lock_t *lock)
{
atomic_store(&lock->status, 0);
}
// return the remaining status bits
IRAM_ATTR static inline uint32_t lock_status_clear(spi_bus_lock_t* lock, uint32_t clear)
{
//the fetch and clear should be atomic, avoid missing the all '0' status when all bits are clear.
uint32_t state = lock_status_fetch_clear(lock, clear);
return state & (~clear);
}
/*******************************************************************************
* Schedule service
*
* The modification to the status bits may cause rotating of the acquiring processor. It also have
* effects to `acquired_dev` (the acquiring device), `in_isr` (HW used in BG), and
* `acq_dev_bg_active` (wait_bg_end can be skipped) members of the lock structure.
*
* Most of them should be atomic, and special attention should be paid to the operation
* sequence.
******************************************************************************/
SPI_MASTER_ISR_ATTR static inline void resume_dev_in_isr(spi_bus_lock_dev_t *dev_lock, BaseType_t *do_yield)
{
xSemaphoreGiveFromISR(dev_lock->semphr, do_yield);
}
IRAM_ATTR static inline void resume_dev(const spi_bus_lock_dev_t *dev_lock)
{
xSemaphoreGive(dev_lock->semphr);
}
SPI_MASTER_ISR_ATTR static inline void bg_disable(spi_bus_lock_t *lock)
{
BUS_LOCK_DEBUG_EXECUTE_CHECK(lock->bg_disable);
lock->bg_disable(lock->bg_arg);
}
IRAM_ATTR static inline void bg_enable(spi_bus_lock_t* lock)
{
BUS_LOCK_DEBUG_EXECUTE_CHECK(lock->bg_enable);
lock->bg_enable(lock->bg_arg);
}
// Set the REQ bit. If we become the acquiring processor, invoke the ISR and pass that to it.
// The caller will never become the acquiring processor after this function returns.
SPI_MASTER_ATTR static inline void req_core(spi_bus_lock_dev_t *dev_handle)
{
spi_bus_lock_t *lock = dev_handle->parent;
// Though `acquired_dev` is critical resource, `dev_handle == lock->acquired_dev`
// is a stable statement unless `acquire_start` or `acquire_end` is called by current
// device.
if (dev_handle == lock->acquiring_dev){
// Set the REQ bit and check BG bits if we are the acquiring processor.
// If the BG bits were not active before, invoke the BG again.
// Avoid competitive risk against the `clear_pend_core`, `acq_dev_bg_active` should be set before
// setting REQ bit.
lock->acq_dev_bg_active = true;
uint32_t status = lock_status_fetch_set(lock, DEV_REQ_MASK(dev_handle));
if ((status & DEV_BG_MASK(dev_handle)) == 0) {
bg_enable(lock); //acquiring processor passed to BG
}
} else {
uint32_t status = lock_status_fetch_set(lock, DEV_REQ_MASK(dev_handle));
if (status == 0) {
bg_enable(lock); //acquiring processor passed to BG
}
}
}
//Set the LOCK bit. Handle related stuff and return true if we become the acquiring processor.
SPI_MASTER_ISR_ATTR static inline bool acquire_core(spi_bus_lock_dev_t *dev_handle)
{
spi_bus_lock_t* lock = dev_handle->parent;
portENTER_CRITICAL_SAFE(&s_spinlock);
uint32_t status = lock_status_fetch_set(lock, dev_handle->mask & LOCK_MASK);
portEXIT_CRITICAL_SAFE(&s_spinlock);
// Check all bits except WEAK_BG
if ((status & (BG_MASK | LOCK_MASK)) == 0) {
//succeed at once
lock->acquiring_dev = dev_handle;
BUS_LOCK_DEBUG_EXECUTE_CHECK(!lock->acq_dev_bg_active);
if (status & WEAK_BG_FLAG) {
//Mainly to disable the cache (Weak_BG), that is not able to disable itself
bg_disable(lock);
}
return true;
}
return false;
}
/**
* Find the next acquiring processor according to the status. Will directly change
* the acquiring device if new one found.
*
* Cases:
* - BG should still be the acquiring processor (Return false):
* 1. Acquiring device has active BG bits: out_desired_dev = new acquiring device
* 2. No acquiring device, but BG active: out_desired_dev = randomly pick one device with active BG bits
* - BG should yield to the task (Return true):
* 3. Acquiring device has no active BG bits: out_desired_dev = new acquiring device
* 4. No acquiring device while no active BG bits: out_desired_dev=NULL
*
* Acquiring device task need to be resumed only when case 3.
*
* This scheduling can happen in either task or ISR, so `in_isr` or `bg_active` not touched.
*
* @param lock
* @param status Current status
* @param out_desired_dev Desired device to work next, see above.
*
* @return False if BG should still be the acquiring processor, otherwise True (yield to task).
*/
IRAM_ATTR static inline bool
schedule_core(spi_bus_lock_t *lock, uint32_t status, spi_bus_lock_dev_t **out_desired_dev)
{
spi_bus_lock_dev_t* desired_dev = NULL;
uint32_t lock_bits = (status & LOCK_MASK) >> LOCK_SHIFT;
uint32_t bg_bits = status & BG_MASK;
bg_bits = ((bg_bits >> REQ_SHIFT) | (bg_bits >> PENDING_SHIFT)) & REQ_MASK;
bool bg_yield;
if (lock_bits) {
int dev_id = mask_get_id(lock_bits);
desired_dev = (spi_bus_lock_dev_t *)atomic_load(&lock->dev[dev_id]);
BUS_LOCK_DEBUG_EXECUTE_CHECK(desired_dev);
lock->acquiring_dev = desired_dev;
bg_yield = ((bg_bits & desired_dev->mask) == 0);
lock->acq_dev_bg_active = !bg_yield;
} else {
lock->acq_dev_bg_active = false;
if (bg_bits) {
int dev_id = mask_get_id(bg_bits);
desired_dev = (spi_bus_lock_dev_t *)atomic_load(&lock->dev[dev_id]);
BUS_LOCK_DEBUG_EXECUTE_CHECK(desired_dev);
lock->acquiring_dev = NULL;
bg_yield = false;
} else {
desired_dev = NULL;
lock->acquiring_dev = NULL;
bg_yield = true;
}
}
*out_desired_dev = desired_dev;
return bg_yield;
}
//Clear the LOCK bit and trigger a rescheduling.
IRAM_ATTR static inline void acquire_end_core(spi_bus_lock_dev_t *dev_handle)
{
spi_bus_lock_t* lock = dev_handle->parent;
//uint32_t status = lock_status_clear(lock, dev_handle->mask & LOCK_MASK);
spi_bus_lock_dev_t* desired_dev = NULL;
portENTER_CRITICAL_SAFE(&s_spinlock);
uint32_t status = lock_status_clear(lock, dev_handle->mask & LOCK_MASK);
bool invoke_bg = !schedule_core(lock, status, &desired_dev);
portEXIT_CRITICAL_SAFE(&s_spinlock);
if (invoke_bg) {
bg_enable(lock);
} else if (desired_dev) {
resume_dev(desired_dev);
} else if (status & WEAK_BG_FLAG) {
bg_enable(lock);
}
}
// Move the REQ bits to corresponding PEND bits. Must be called by acquiring processor.
// Have no side effects on the acquiring device/processor.
SPI_MASTER_ISR_ATTR static inline void update_pend_core(spi_bus_lock_t *lock, uint32_t status)
{
uint32_t active_req_bits = status & REQ_MASK;
#if PENDING_SHIFT > REQ_SHIFT
uint32_t pending_mask = active_req_bits << (PENDING_SHIFT - REQ_SHIFT);
#else
uint32_t pending_mask = active_req_bits >> (REQ_SHIFT - PENDING_SHIFT);
#endif
// We have to set the PEND bits and then clear the REQ bits, since BG bits are using bitwise OR logic,
// this will not influence the effectiveness of the BG bits of every device.
lock_status_fetch_set(lock, pending_mask);
lock_status_fetch_clear(lock, active_req_bits);
}
// Clear the PEND bit (not REQ bit!) of a device, return the suggestion whether we can try to quit the ISR.
// Lost the acquiring processor immediately when the BG bits for active device are inactive, indiciating by the return value.
// Can be called only when ISR is acting as the acquiring processor.
SPI_MASTER_ISR_ATTR static inline bool clear_pend_core(spi_bus_lock_dev_t *dev_handle)
{
bool finished;
spi_bus_lock_t *lock = dev_handle->parent;
uint32_t pend_mask = DEV_PEND_MASK(dev_handle);
BUS_LOCK_DEBUG_EXECUTE_CHECK(lock_status_fetch(lock) & pend_mask);
uint32_t status = lock_status_clear(lock, pend_mask);
if (lock->acquiring_dev == dev_handle) {
finished = ((status & DEV_REQ_MASK(dev_handle)) == 0);
if (finished) {
lock->acq_dev_bg_active = false;
}
} else {
finished = (status == 0);
}
return finished;
}
// Return true if the ISR has already touched the HW, which means previous operations should
// be terminated first, before we use the HW again. Otherwise return false.
// In either case `in_isr` will be marked as true, until call to `bg_exit_core` with `wip=false` successfully.
SPI_MASTER_ISR_ATTR static inline bool bg_entry_core(spi_bus_lock_t *lock)
{
BUS_LOCK_DEBUG_EXECUTE_CHECK(!lock->acquiring_dev || lock->acq_dev_bg_active);
/*
* The interrupt is disabled at the entry of ISR to avoid competitive risk as below:
*
* The `esp_intr_enable` will be called (b) after new BG request is queued (a) in the task;
* while `esp_intr_disable` should be called (c) if we check and found the sending queue is empty (d).
* If (c) happens after (d), if things happens in this sequence:
* (d) -> (a) -> (b) -> (c), the interrupt will be disabled while there's pending BG request in the queue.
*
* To avoid this, interrupt is disabled here, and re-enabled later if required. (c) -> (d) -> (a) -> (b) -> revert (c) if !d
*/
bg_disable(lock);
if (lock->in_isr) {
return false;
} else {
lock->in_isr = true;
return true;
}
}
// Handle the conditions of status and interrupt, avoiding the ISR being disabled when there is any new coming BG requests.
// When called with `wip=true`, means the ISR is performing some operations. Will enable the interrupt again and exit unconditionally.
// When called with `wip=false`, will only return `true` when there is no coming BG request. If return value is `false`, the ISR should try again.
// Will not change acquiring device.
SPI_MASTER_ISR_ATTR static inline bool bg_exit_core(spi_bus_lock_t *lock, bool wip, BaseType_t *do_yield)
{
//See comments in `bg_entry_core`, re-enable interrupt disabled in entry if we do need the interrupt
if (wip) {
bg_enable(lock);
BUS_LOCK_DEBUG_EXECUTE_CHECK(!lock->acquiring_dev || lock->acq_dev_bg_active);
return true;
}
bool ret;
uint32_t status = lock_status_fetch(lock);
if (lock->acquiring_dev) {
if (status & DEV_BG_MASK(lock->acquiring_dev)) {
BUS_LOCK_DEBUG_EXECUTE_CHECK(lock->acq_dev_bg_active);
ret = false;
} else {
// The request may happen any time, even after we fetched the status.
// The value of `acq_dev_bg_active` is random.
resume_dev_in_isr(lock->acquiring_dev, do_yield);
ret = true;
}
} else {
BUS_LOCK_DEBUG_EXECUTE_CHECK(!lock->acq_dev_bg_active);
ret = !(status & BG_MASK);
}
if (ret) {
//when successfully exit, but no transaction done, mark BG as inactive
lock->in_isr = false;
}
return ret;
}
IRAM_ATTR static inline void dev_wait_prepare(spi_bus_lock_dev_t *dev_handle)
{
xSemaphoreTake(dev_handle->semphr, 0);
}
SPI_MASTER_ISR_ATTR static inline esp_err_t dev_wait(spi_bus_lock_dev_t *dev_handle, TickType_t wait)
{
BaseType_t ret = xSemaphoreTake(dev_handle->semphr, wait);
if (ret == pdFALSE) return ESP_ERR_TIMEOUT;
return ESP_OK;
}
/*******************************************************************************
* Initialization & Deinitialization
******************************************************************************/
esp_err_t spi_bus_init_lock(spi_bus_lock_handle_t *out_lock, const spi_bus_lock_config_t *config)
{
spi_bus_lock_t* lock = (spi_bus_lock_t*)calloc(sizeof(spi_bus_lock_t), 1);
if (lock == NULL) {
return ESP_ERR_NO_MEM;
}
lock_status_init(lock);
lock->acquiring_dev = NULL;
lock->last_dev = NULL;
lock->periph_cs_num = config->cs_num;
lock->host_id = config->host_id;
*out_lock = lock;
return ESP_OK;
}
void spi_bus_deinit_lock(spi_bus_lock_handle_t lock)
{
for (int i = 0; i < DEV_NUM_MAX; i++) {
assert(atomic_load(&lock->dev[i]) == (intptr_t)NULL);
}
free(lock);
}
static int try_acquire_free_dev(spi_bus_lock_t *lock, bool cs_required)
{
if (cs_required) {
int i;
for (i = 0; i < lock->periph_cs_num; i++) {
intptr_t null = (intptr_t) NULL;
//use 1 to occupy the slot, actual setup comes later
if (atomic_compare_exchange_strong(&lock->dev[i], &null, (intptr_t) 1)) {
break;
}
}
return ((i == lock->periph_cs_num)? -1: i);
} else {
int i;
for (i = DEV_NUM_MAX - 1; i >= 0; i--) {
intptr_t null = (intptr_t) NULL;
//use 1 to occupy the slot, actual setup comes later
if (atomic_compare_exchange_strong(&lock->dev[i], &null, (intptr_t) 1)) {
break;
}
}
return i;
}
}
esp_err_t spi_bus_lock_register_dev(spi_bus_lock_handle_t lock, spi_bus_lock_dev_config_t *config,
spi_bus_lock_dev_handle_t *out_dev_handle)
{
if (lock == NULL) return ESP_ERR_INVALID_ARG;
int id = try_acquire_free_dev(lock, config->flags & SPI_BUS_LOCK_DEV_FLAG_CS_REQUIRED);
if (id == -1) return ESP_ERR_NOT_SUPPORTED;
spi_bus_lock_dev_t* dev_lock = (spi_bus_lock_dev_t*)heap_caps_calloc(sizeof(spi_bus_lock_dev_t), 1, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
if (dev_lock == NULL) {
return ESP_ERR_NO_MEM;
}
dev_lock->semphr = xSemaphoreCreateBinary();
if (dev_lock->semphr == NULL) {
free(dev_lock);
atomic_store(&lock->dev[id], (intptr_t)NULL);
return ESP_ERR_NO_MEM;
}
dev_lock->parent = lock;
dev_lock->mask = DEV_MASK(id);
ESP_LOGV(TAG, "device registered on bus %d slot %d.", lock->host_id, id);
atomic_store(&lock->dev[id], (intptr_t)dev_lock);
*out_dev_handle = dev_lock;
return ESP_OK;
}
void spi_bus_lock_unregister_dev(spi_bus_lock_dev_handle_t dev_handle)
{
int id = dev_lock_get_id(dev_handle);
spi_bus_lock_t* lock = dev_handle->parent;
BUS_LOCK_DEBUG_EXECUTE_CHECK(atomic_load(&lock->dev[id]) == (intptr_t)dev_handle);
if (lock->last_dev == dev_handle) lock->last_dev = NULL;
atomic_store(&lock->dev[id], (intptr_t)NULL);
if (dev_handle->semphr) {
vSemaphoreDelete(dev_handle->semphr);
}
free(dev_handle);
}
IRAM_ATTR static inline int mask_get_id(uint32_t mask)
{
return ID_DEV_MASK(mask);
}
IRAM_ATTR static inline int dev_lock_get_id(spi_bus_lock_dev_t *dev_lock)
{
return mask_get_id(dev_lock->mask);
}
void spi_bus_lock_set_bg_control(spi_bus_lock_handle_t lock, bg_ctrl_func_t bg_enable, bg_ctrl_func_t bg_disable, void *arg)
{
lock->bg_enable = bg_enable;
lock->bg_disable = bg_disable;
lock->bg_arg = arg;
}
IRAM_ATTR int spi_bus_lock_get_dev_id(spi_bus_lock_dev_handle_t dev_handle)
{
return (dev_handle? dev_lock_get_id(dev_handle): -1);
}
//will be called when cache disabled
IRAM_ATTR bool spi_bus_lock_touch(spi_bus_lock_dev_handle_t dev_handle)
{
spi_bus_lock_dev_t* last_dev = dev_handle->parent->last_dev;
dev_handle->parent->last_dev = dev_handle;
if (last_dev != dev_handle) {
int last_dev_id = (last_dev? dev_lock_get_id(last_dev): -1);
ESP_DRAM_LOGV(TAG, "SPI dev changed from %d to %d",
last_dev_id, dev_lock_get_id(dev_handle));
}
return (dev_handle != last_dev);
}
/*******************************************************************************
* Acquiring service
******************************************************************************/
IRAM_ATTR esp_err_t spi_bus_lock_acquire_start(spi_bus_lock_dev_t *dev_handle, TickType_t wait)
{
LOCK_CHECK(wait == portMAX_DELAY, "timeout other than portMAX_DELAY not supported", ESP_ERR_INVALID_ARG);
spi_bus_lock_t* lock = dev_handle->parent;
// Clear the semaphore before checking
dev_wait_prepare(dev_handle);
if (!acquire_core(dev_handle)) {
//block until becoming the acquiring processor (help by previous acquiring processor)
esp_err_t err = dev_wait(dev_handle, wait);
//TODO: add timeout handling here.
if (err != ESP_OK) return err;
}
ESP_DRAM_LOGV(TAG, "dev %d acquired.", dev_lock_get_id(dev_handle));
BUS_LOCK_DEBUG_EXECUTE_CHECK(lock->acquiring_dev == dev_handle);
//When arrives at here, requests of this device should already be handled
uint32_t status = lock_status_fetch(lock);
(void) status;
BUS_LOCK_DEBUG_EXECUTE_CHECK((status & DEV_BG_MASK(dev_handle)) == 0);
return ESP_OK;
}
IRAM_ATTR esp_err_t spi_bus_lock_acquire_end(spi_bus_lock_dev_t *dev_handle)
{
//release the bus
spi_bus_lock_t* lock = dev_handle->parent;
LOCK_CHECK(lock->acquiring_dev == dev_handle, "Cannot release a lock that hasn't been acquired.", ESP_ERR_INVALID_STATE);
acquire_end_core(dev_handle);
ESP_LOGV(TAG, "dev %d released.", dev_lock_get_id(dev_handle));
return ESP_OK;
}
SPI_MASTER_ISR_ATTR spi_bus_lock_dev_handle_t spi_bus_lock_get_acquiring_dev(spi_bus_lock_t *lock)
{
return lock->acquiring_dev;
}
/*******************************************************************************
* BG (background operation) service
******************************************************************************/
SPI_MASTER_ISR_ATTR bool spi_bus_lock_bg_entry(spi_bus_lock_t* lock)
{
return bg_entry_core(lock);
}
SPI_MASTER_ISR_ATTR bool spi_bus_lock_bg_exit(spi_bus_lock_t* lock, bool wip, BaseType_t* do_yield)
{
return bg_exit_core(lock, wip, do_yield);
}
SPI_MASTER_ATTR esp_err_t spi_bus_lock_bg_request(spi_bus_lock_dev_t *dev_handle)
{
req_core(dev_handle);
return ESP_OK;
}
IRAM_ATTR esp_err_t spi_bus_lock_wait_bg_done(spi_bus_lock_dev_handle_t dev_handle, TickType_t wait)
{
spi_bus_lock_t *lock = dev_handle->parent;
LOCK_CHECK(lock->acquiring_dev == dev_handle, "Cannot wait for a device that is not acquired", ESP_ERR_INVALID_STATE);
LOCK_CHECK(wait == portMAX_DELAY, "timeout other than portMAX_DELAY not supported", ESP_ERR_INVALID_ARG);
// If no BG bits active, skip quickly. This is ensured by `spi_bus_lock_wait_bg_done`
// cannot be executed with `bg_request` on the same device concurrently.
if (lock_status_fetch(lock) & DEV_BG_MASK(dev_handle)) {
// Clear the semaphore before checking
dev_wait_prepare(dev_handle);
if (lock_status_fetch(lock) & DEV_BG_MASK(dev_handle)) {
//block until becoming the acquiring processor (help by previous acquiring processor)
esp_err_t err = dev_wait(dev_handle, wait);
//TODO: add timeout handling here.
if (err != ESP_OK) return err;
}
}
BUS_LOCK_DEBUG_EXECUTE_CHECK(!lock->acq_dev_bg_active);
BUS_LOCK_DEBUG_EXECUTE_CHECK((lock_status_fetch(lock) & DEV_BG_MASK(dev_handle)) == 0);
return ESP_OK;
}
SPI_MASTER_ISR_ATTR bool spi_bus_lock_bg_clear_req(spi_bus_lock_dev_t *dev_handle)
{
bool finished = clear_pend_core(dev_handle);
ESP_EARLY_LOGV(TAG, "dev %d served from bg.", dev_lock_get_id(dev_handle));
return finished;
}
SPI_MASTER_ISR_ATTR bool spi_bus_lock_bg_check_dev_acq(spi_bus_lock_t *lock,
spi_bus_lock_dev_handle_t *out_dev_lock)
{
BUS_LOCK_DEBUG_EXECUTE_CHECK(!lock->acquiring_dev);
uint32_t status = lock_status_fetch(lock);
return schedule_core(lock, status, out_dev_lock);
}
SPI_MASTER_ISR_ATTR bool spi_bus_lock_bg_check_dev_req(spi_bus_lock_dev_t *dev_lock)
{
spi_bus_lock_t* lock = dev_lock->parent;
uint32_t status = lock_status_fetch(lock);
uint32_t dev_status = status & dev_lock->mask;
// move REQ bits of all device to corresponding PEND bits.
// To reduce executing time, only done when the REQ bit of the calling device is set.
if (dev_status & REQ_MASK) {
update_pend_core(lock, status);
return true;
} else {
return dev_status & PEND_MASK;
}
}
SPI_MASTER_ISR_ATTR bool spi_bus_lock_bg_req_exist(spi_bus_lock_t *lock)
{
uint32_t status = lock_status_fetch(lock);
return status & BG_MASK;
}
/*******************************************************************************
* Static variables of the locks of the main flash
******************************************************************************/
#if CONFIG_SPI_FLASH_SHARE_SPI1_BUS
static spi_bus_lock_dev_t lock_main_flash_dev;
static spi_bus_lock_t main_spi_bus_lock = {
/*
* the main bus cache is permanently required, this flag is set here and never clear so that the
* cache will always be enabled if acquiring devices yield.
*/
.status = ATOMIC_VAR_INIT(WEAK_BG_FLAG),
.acquiring_dev = NULL,
.dev = {ATOMIC_VAR_INIT((intptr_t)&lock_main_flash_dev)},
.new_req = 0,
.periph_cs_num = SOC_SPI_PERIPH_CS_NUM(0),
};
const spi_bus_lock_handle_t g_main_spi_bus_lock = &main_spi_bus_lock;
esp_err_t spi_bus_lock_init_main_bus(void)
{
spi_bus_main_set_lock(g_main_spi_bus_lock);
return ESP_OK;
}
static StaticSemaphore_t main_flash_semphr;
static spi_bus_lock_dev_t lock_main_flash_dev = {
.semphr = NULL,
.parent = &main_spi_bus_lock,
.mask = DEV_MASK(0),
};
const spi_bus_lock_dev_handle_t g_spi_lock_main_flash_dev = &lock_main_flash_dev;
esp_err_t spi_bus_lock_init_main_dev(void)
{
g_spi_lock_main_flash_dev->semphr = xSemaphoreCreateBinaryStatic(&main_flash_semphr);
if (g_spi_lock_main_flash_dev->semphr == NULL) {
return ESP_ERR_NO_MEM;
}
return ESP_OK;
}
#else //CONFIG_SPI_FLASH_SHARE_SPI1_BUS
//when the dev lock is not initialized, point to NULL
const spi_bus_lock_dev_handle_t g_spi_lock_main_flash_dev = NULL;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,16 @@
# the JPEG library is in ROM but seems to fail randomly (PSRAM issue?)
set(TJPGD tjpgd)
idf_component_register(SRC_DIRS . core core/ifaces fonts
INCLUDE_DIRS . fonts core
REQUIRES platform_config tools esp_common
PRIV_REQUIRES services freertos driver
EMBED_FILES note.jpg
)
PRIV_REQUIRES services freertos driver ${TJPGD}
EMBED_FILES note.jpg )
if (NOT TJPGD)
add_compile_definitions(TJPGD_ROM)
endif()
set_source_files_properties(display.c
PROPERTIES COMPILE_FLAGS
-Wno-format-overflow
)
-Wno-format-overflow )

View File

@@ -195,15 +195,14 @@ static void SetLayout( struct GDS_Device* Device, struct GDS_Layout *Layout ) {
if (Layout->Rotate) Private->Offset.Width += Layout->HFlip ? 320 - Device->Width : 0;
else Private->Offset.Height += Layout->HFlip ? 320 - Device->Height : 0;
Device->WriteCommand( Device, Layout->Invert ? 0x20 : 0x21 );
Private->MADCtl = Layout->ColorSwap ? (Private->MADCtl & ~(1 << 3)) : (Private->MADCtl | (1 << 3));
} else {
Device->WriteCommand( Device, Layout->Invert ? 0x21 : 0x20 );
Private->MADCtl = Layout->ColorSwap ? (Private->MADCtl | (1 << 3)) : (Private->MADCtl & ~(1 << 3));
}
Private->MADCtl = Layout->HFlip ? (Private->MADCtl | (1 << 7)) : (Private->MADCtl & ~(1 << 7));
Private->MADCtl = Layout->VFlip ? (Private->MADCtl | (1 << 6)) : (Private->MADCtl & ~(1 << 6));
Private->MADCtl = Layout->Rotate ? (Private->MADCtl | (1 << 5)) : (Private->MADCtl & ~(1 << 5));
Private->MADCtl = Layout->ColorSwap ? (Private->MADCtl & ~(1 << 3)) : (Private->MADCtl | (1 << 3));
Device->WriteCommand( Device, 0x36 );
WriteByte( Device, Private->MADCtl );

View File

@@ -8,7 +8,11 @@
#include <string.h>
#include "math.h"
#ifdef TJPGD_ROM
#include "esp32/rom/tjpgd.h"
#else
#include "tjpgd.h"
#endif
#include "esp_log.h"
#include "gds.h"
@@ -142,7 +146,7 @@ static unsigned OutHandlerDirect(JDEC *Decoder, void *Bitmap, JRECT *Frame) {
JpegCtx *Context = (JpegCtx*) Decoder->device;
uint8_t *Pixels = (uint8_t*) Bitmap;
int Shift = 8 - Context->Depth;
// decoded image is RGB888, shift only make sense for grayscale
if (Context->Mode == GDS_RGB888) {
OUTHANDLERDIRECT(Scaler888, 0);

View File

@@ -125,7 +125,7 @@ struct GDS_Device {
void (*DrawRGB)( struct GDS_Device* Device, uint8_t *Image,int x, int y, int Width, int Height, int RGB_Mode );
void (*ClearWindow)( struct GDS_Device* Device, int x1, int y1, int x2, int y2, int Color );
// may provide for tweaking
void (*SPIParams)(int Speed, uint8_t *mode, uint8_t *CS_pre, uint8_t *CS_post);
void (*SPIParams)(int Speed, uint8_t *mode, uint16_t *CS_pre, uint8_t *CS_post);
// interface-specific methods
WriteCommandProc WriteCommand;

View File

@@ -26,19 +26,20 @@ static char TAG[] = "gds";
*/
static const struct GDS_FontDef *GuessFont( struct GDS_Device *Device, int FontType) {
switch(FontType) {
case GDS_FONT_DEFAULT:
return Device->Font;
case GDS_FONT_LINE_1:
return &Font_line_1;
case GDS_FONT_LINE_2:
return &Font_line_2;
case GDS_FONT_SMALL:
return &Font_droid_sans_fallback_11x13;
case GDS_FONT_MEDIUM:
default:
return &Font_droid_sans_fallback_15x17;
//return &Font_droid_sans_fallback_15x17;
case GDS_FONT_SMALL:
default:
return &Font_droid_sans_fallback_11x13;
#ifdef USE_LARGE_FONTS
case GDS_FONT_LARGE:
return &Font_droid_sans_fallback_24x28;
break;
case GDS_FONT_SEGMENT:
if (Device->Height == 32) return &Font_Tarable7Seg_16x32;
else return &Font_Tarable7Seg_32x64;
@@ -46,8 +47,8 @@ static const struct GDS_FontDef *GuessFont( struct GDS_Device *Device, int FontT
case GDS_FONT_LARGE:
case GDS_FONT_SEGMENT:
ESP_LOGW(TAG, "large fonts disabled");
return &Font_droid_sans_fallback_15x17;
break;
//return &Font_droid_sans_fallback_15x17;
return &Font_droid_sans_fallback_11x13;
#endif
}
}

View File

@@ -150,8 +150,8 @@ void display_init(char *welcome) {
};
GDS_SetLayout(display, &Layout);
GDS_SetFont(display, &Font_droid_sans_fallback_15x17 );
GDS_TextPos(display, GDS_FONT_MEDIUM, GDS_TEXT_CENTERED, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, welcome);
GDS_SetFont(display, &Font_line_2);
GDS_TextPos(display, GDS_FONT_DEFAULT, GDS_TEXT_CENTERED, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, welcome);
// start the task that will handle scrolling & counting
displayer.mutex = xSemaphoreCreateMutex();

View File

@@ -17,6 +17,7 @@
#include "esp_bt_main.h"
#include "esp_gap_bt_api.h"
#include "bt_app_core.h"
#include "tools.h"
static const char *TAG = "btappcore";
@@ -41,8 +42,7 @@ bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, i
if (param_len == 0) {
return bt_app_send_msg(&msg);
} else if (p_params && param_len > 0) {
if ((msg.param = malloc(param_len)) != NULL) {
memcpy(msg.param, p_params, param_len);
if ((msg.param = clone_obj_psram(p_params, param_len)) != NULL) {
/* check if caller has provided a copy callback to do the deep copy */
if (p_copy_cback) {
p_copy_cback(&msg, msg.param, p_params);

View File

@@ -25,7 +25,7 @@
#include "platform_config.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "trace.h"
#include "tools.h"
#include "audio_controls.h"
#include "sys/lock.h"
#include "display.h"
@@ -214,6 +214,10 @@ void bt_app_a2d_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
bt_app_work_dispatch(bt_av_hdl_a2d_evt, event, param, sizeof(esp_a2d_cb_param_t), NULL);
break;
}
case ESP_A2D_PROF_STATE_EVT: {
ESP_LOGI(BT_AV_TAG, "Bluetooth Init complete");
break;
}
default:
ESP_LOGE(BT_AV_TAG, "Invalid A2DP event: %d", event);
break;

View File

@@ -19,7 +19,7 @@
#include "platform_config.h"
#include "messaging.h"
#include "cJSON.h"
#include "trace.h"
#include "tools.h"
static const char * TAG = "bt_app_source";
static const char * BT_RC_CT_TAG="RCCT";
@@ -27,6 +27,7 @@ extern int32_t output_bt_data(uint8_t *data, int32_t len);
extern void output_bt_tick(void);
extern char* output_state_str(void);
extern bool output_stopped(void);
extern bool is_recovery_running;
static void bt_app_av_state_connecting(uint16_t event, void *param);
static void filter_inquiry_scan_result(esp_bt_gap_cb_param_t *param);
@@ -189,7 +190,10 @@ static void peers_list_maintain(const char * s_peer_bdname, int32_t rssi){
}
int bt_app_source_get_a2d_state(){
ESP_LOGD(TAG,"a2dp status: %u = %s", bt_app_source_a2d_state, APP_AV_STATE_DESC[bt_app_source_a2d_state]);
if(!is_recovery_running){
// if we are in recovery mode, don't log BT status
ESP_LOGD(TAG,"a2dp status: %u = %s", bt_app_source_a2d_state, APP_AV_STATE_DESC[bt_app_source_a2d_state]);
}
return bt_app_source_a2d_state;
}
@@ -224,8 +228,8 @@ void hal_bluetooth_init(const char * options)
squeezelite_args.end = arg_end(2);
ESP_LOGD(TAG,"Copying parameters");
char * opts = strdup(options);
char **argv = malloc(sizeof(char**)*15);
char * opts = strdup_psram(options);
char **argv = malloc_init_external(sizeof(char**)*15);
size_t argv_size=15;
@@ -252,7 +256,7 @@ void hal_bluetooth_init(const char * options)
ESP_LOGW(TAG,"Unable to retrieve the a2dp sink name from nvs.");
}
} else {
squeezelite_conf.sink_name=strdup(squeezelite_args.sink_name->sval[0]);
squeezelite_conf.sink_name=strdup_psram(squeezelite_args.sink_name->sval[0]);
// sync with NVS
esp_err_t err=ESP_OK;
if((err= config_set_value(NVS_TYPE_STR, "a2dp_sink_name", squeezelite_args.sink_name->sval[0]))!=ESP_OK){

View File

@@ -2,9 +2,9 @@ idf_build_get_property(prefix IDF_PATH)
string(CONCAT prefix "${prefix}" "/components/esp_http_server")
idf_component_register(
SRC_DIRS "${prefix}/src" "${prefix}/src/util"
SRC_DIRS "${prefix}/src" "${prefix}/src/util"
INCLUDE_DIRS "${prefix}/include"
PRIV_INCLUDE_DIRS "." "${prefix}/src/port/esp32" "${prefix}/src/util"
REQUIRES nghttp # for http_parser.h
PRIV_REQUIRES lwip
PRIV_INCLUDE_DIRS "." "${prefix}/src/port/esp32" "${prefix}/src/util"
REQUIRES nghttp # for http_parser.h
PRIV_REQUIRES lwip mbedtls esp_timer
)

View File

@@ -0,0 +1,49 @@
set(srcs
"heap_caps.c"
"heap_caps_init.c"
"multi_heap.c"
"heap_tlsf.c")
if(NOT CONFIG_HEAP_POISONING_DISABLED)
list(APPEND srcs "multi_heap_poisoning.c")
endif()
if(CONFIG_HEAP_TASK_TRACKING)
list(APPEND srcs "heap_task_info.c")
endif()
if(CONFIG_HEAP_TRACING_STANDALONE)
list(APPEND srcs "heap_trace_standalone.c")
set_source_files_properties(heap_trace_standalone.c
PROPERTIES COMPILE_FLAGS
-Wno-frame-address)
endif()
idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS include
LDFRAGMENTS linker.lf
PRIV_REQUIRES soc)
if(CONFIG_HEAP_TRACING)
set(WRAP_FUNCTIONS
calloc
malloc
free
realloc
heap_caps_malloc
heap_caps_free
heap_caps_realloc
heap_caps_malloc_default
heap_caps_realloc_default)
foreach(wrap ${WRAP_FUNCTIONS})
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=${wrap}")
endforeach()
endif()
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
idf_build_get_property(build_components BUILD_COMPONENTS)
if(freertos IN_LIST build_components)
target_compile_options(${COMPONENT_TARGET} PRIVATE "-DMULTI_HEAP_FREERTOS")
endif()
endif()

74
components/heap/Kconfig Normal file
View File

@@ -0,0 +1,74 @@
menu "Heap memory debugging"
choice HEAP_CORRUPTION_DETECTION
prompt "Heap corruption detection"
default HEAP_POISONING_DISABLED
help
Enable heap poisoning features to detect heap corruption caused by out-of-bounds access to heap memory.
See the "Heap Memory Debugging" page of the IDF documentation
for a description of each level of heap corruption detection.
config HEAP_POISONING_DISABLED
bool "Basic (no poisoning)"
config HEAP_POISONING_LIGHT
bool "Light impact"
config HEAP_POISONING_COMPREHENSIVE
bool "Comprehensive"
endchoice
choice HEAP_TRACING_DEST
bool "Heap tracing"
default HEAP_TRACING_OFF
help
Enables the heap tracing API defined in esp_heap_trace.h.
This function causes a moderate increase in IRAM code side and a minor increase in heap function
(malloc/free/realloc) CPU overhead, even when the tracing feature is not used.
So it's best to keep it disabled unless tracing is being used.
config HEAP_TRACING_OFF
bool "Disabled"
config HEAP_TRACING_STANDALONE
bool "Standalone"
select HEAP_TRACING
config HEAP_TRACING_TOHOST
bool "Host-based"
select HEAP_TRACING
endchoice
config HEAP_TRACING
bool
default F
help
Enables/disables heap tracing API.
config HEAP_TRACING_STACK_DEPTH
int "Heap tracing stack depth"
range 0 0 if IDF_TARGET_ARCH_RISCV # Disabled for RISC-V due to `__builtin_return_address` limitation
default 0 if IDF_TARGET_ARCH_RISCV
range 0 10
default 2
depends on HEAP_TRACING
help
Number of stack frames to save when tracing heap operation callers.
More stack frames uses more memory in the heap trace buffer (and slows down allocation), but
can provide useful information.
config HEAP_TASK_TRACKING
bool "Enable heap task tracking"
depends on !HEAP_POISONING_DISABLED
help
Enables tracking the task responsible for each heap allocation.
This function depends on heap poisoning being enabled and adds four more bytes of overhead for each block
allocated.
config HEAP_ABORT_WHEN_ALLOCATION_FAILS
bool "Abort if memory allocation fails"
default n
help
When enabled, if a memory allocation operation fails it will cause a system abort.
endmenu

View File

@@ -0,0 +1,32 @@
#
# Component Makefile
#
COMPONENT_OBJS := heap_caps_init.o heap_caps.o multi_heap.o heap_tlsf.o
ifndef CONFIG_HEAP_POISONING_DISABLED
COMPONENT_OBJS += multi_heap_poisoning.o
ifdef CONFIG_HEAP_TASK_TRACKING
COMPONENT_OBJS += heap_task_info.o
endif
endif
ifdef CONFIG_HEAP_TRACING_STANDALONE
COMPONENT_OBJS += heap_trace_standalone.o
endif
ifdef CONFIG_HEAP_TRACING
WRAP_FUNCTIONS = calloc malloc free realloc heap_caps_malloc heap_caps_free heap_caps_realloc heap_caps_malloc_default heap_caps_realloc_default
WRAP_ARGUMENT := -Wl,--wrap=
COMPONENT_ADD_LDFLAGS = -l$(COMPONENT_NAME) $(addprefix $(WRAP_ARGUMENT),$(WRAP_FUNCTIONS))
endif
COMPONENT_ADD_LDFRAGMENTS += linker.lf
CFLAGS += -DMULTI_HEAP_FREERTOS

609
components/heap/heap_caps.c Normal file
View File

@@ -0,0 +1,609 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <sys/param.h>
#include "esp_attr.h"
#include "esp_heap_caps.h"
#include "multi_heap.h"
#include "esp_log.h"
#include "heap_private.h"
#include "esp_system.h"
/*
This file, combined with a region allocator that supports multiple heaps, solves the problem that the ESP32 has RAM
that's slightly heterogeneous. Some RAM can be byte-accessed, some allows only 32-bit accesses, some can execute memory,
some can be remapped by the MMU to only be accessed by a certain PID etc. In order to allow the most flexible memory
allocation possible, this code makes it possible to request memory that has certain capabilities. The code will then use
its knowledge of how the memory is configured along with a priority scheme to allocate that memory in the most sane way
possible. This should optimize the amount of RAM accessible to the code without hardwiring addresses.
*/
static esp_alloc_failed_hook_t alloc_failed_callback;
/*
This takes a memory chunk in a region that can be addressed as both DRAM as well as IRAM. It will convert it to
IRAM in such a way that it can be later freed. It assumes both the address as well as the length to be word-aligned.
It returns a region that's 1 word smaller than the region given because it stores the original Dram address there.
*/
IRAM_ATTR static void *dram_alloc_to_iram_addr(void *addr, size_t len)
{
uintptr_t dstart = (uintptr_t)addr; //First word
uintptr_t dend = dstart + len - 4; //Last word
assert(esp_ptr_in_diram_dram((void *)dstart));
assert(esp_ptr_in_diram_dram((void *)dend));
assert((dstart & 3) == 0);
assert((dend & 3) == 0);
#if SOC_DIRAM_INVERTED // We want the word before the result to hold the DRAM address
uint32_t *iptr = esp_ptr_diram_dram_to_iram((void *)dend);
#else
uint32_t *iptr = esp_ptr_diram_dram_to_iram((void *)dstart);
#endif
*iptr = dstart;
return iptr + 1;
}
static void heap_caps_alloc_failed(size_t requested_size, uint32_t caps, const char *function_name)
{
if (alloc_failed_callback) {
alloc_failed_callback(requested_size, caps, function_name);
}
#ifdef CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS
esp_system_abort("Memory allocation failed");
#endif
}
esp_err_t heap_caps_register_failed_alloc_callback(esp_alloc_failed_hook_t callback)
{
if (callback == NULL) {
return ESP_ERR_INVALID_ARG;
}
alloc_failed_callback = callback;
return ESP_OK;
}
bool heap_caps_match(const heap_t *heap, uint32_t caps)
{
return heap->heap != NULL && ((get_all_caps(heap) & caps) == caps);
}
/*
Routine to allocate a bit of memory with certain capabilities. caps is a bitfield of MALLOC_CAP_* bits.
*/
IRAM_ATTR void *heap_caps_malloc( size_t size, uint32_t caps )
{
void *ret = NULL;
if (size > HEAP_SIZE_MAX) {
// Avoids int overflow when adding small numbers to size, or
// calculating 'end' from start+size, by limiting 'size' to the possible range
heap_caps_alloc_failed(size, caps, __func__);
return NULL;
}
if (caps & MALLOC_CAP_EXEC) {
//MALLOC_CAP_EXEC forces an alloc from IRAM. There is a region which has both this as well as the following
//caps, but the following caps are not possible for IRAM. Thus, the combination is impossible and we return
//NULL directly, even although our heap capabilities (based on soc_memory_tags & soc_memory_regions) would
//indicate there is a tag for this.
if ((caps & MALLOC_CAP_8BIT) || (caps & MALLOC_CAP_DMA)) {
heap_caps_alloc_failed(size, caps, __func__);
return NULL;
}
caps |= MALLOC_CAP_32BIT; // IRAM is 32-bit accessible RAM
}
if (caps & MALLOC_CAP_32BIT) {
/* 32-bit accessible RAM should allocated in 4 byte aligned sizes
* (Future versions of ESP-IDF should possibly fail if an invalid size is requested)
*/
size = (size + 3) & (~3); // int overflow checked above
}
for (int prio = 0; prio < SOC_MEMORY_TYPE_NO_PRIOS; prio++) {
//Iterate over heaps and check capabilities at this priority
heap_t *heap;
SLIST_FOREACH(heap, &registered_heaps, next) {
if (heap->heap == NULL) {
continue;
}
if ((heap->caps[prio] & caps) != 0) {
//Heap has at least one of the caps requested. If caps has other bits set that this prio
//doesn't cover, see if they're available in other prios.
if ((get_all_caps(heap) & caps) == caps) {
//This heap can satisfy all the requested capabilities. See if we can grab some memory using it.
if ((caps & MALLOC_CAP_EXEC) && esp_ptr_in_diram_dram((void *)heap->start)) {
//This is special, insofar that what we're going to get back is a DRAM address. If so,
//we need to 'invert' it (lowest address in DRAM == highest address in IRAM and vice-versa) and
//add a pointer to the DRAM equivalent before the address we're going to return.
ret = multi_heap_malloc(heap->heap, size + 4); // int overflow checked above
if (ret != NULL) {
return dram_alloc_to_iram_addr(ret, size + 4); // int overflow checked above
}
} else {
//Just try to alloc, nothing special.
ret = multi_heap_malloc(heap->heap, size);
if (ret != NULL) {
return ret;
}
}
}
}
}
}
heap_caps_alloc_failed(size, caps, __func__);
//Nothing usable found.
return NULL;
}
#define MALLOC_DISABLE_EXTERNAL_ALLOCS -1
//Dual-use: -1 (=MALLOC_DISABLE_EXTERNAL_ALLOCS) disables allocations in external memory, >=0 sets the limit for allocations preferring internal memory.
static int malloc_alwaysinternal_limit=MALLOC_DISABLE_EXTERNAL_ALLOCS;
void heap_caps_malloc_extmem_enable(size_t limit)
{
malloc_alwaysinternal_limit=limit;
}
/*
Default memory allocation implementation. Should return standard 8-bit memory. malloc() essentially resolves to this function.
*/
IRAM_ATTR void *heap_caps_malloc_default( size_t size )
{
if (malloc_alwaysinternal_limit==MALLOC_DISABLE_EXTERNAL_ALLOCS) {
return heap_caps_malloc( size, MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL);
} else {
void *r;
if (size <= (size_t)malloc_alwaysinternal_limit) {
r=heap_caps_malloc( size, MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL );
} else {
r=heap_caps_malloc( size, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM );
}
if (r==NULL) {
//try again while being less picky
r=heap_caps_malloc( size, MALLOC_CAP_DEFAULT );
}
return r;
}
}
/*
Same for realloc()
Note: keep the logic in here the same as in heap_caps_malloc_default (or merge the two as soon as this gets more complex...)
*/
IRAM_ATTR void *heap_caps_realloc_default( void *ptr, size_t size )
{
if (malloc_alwaysinternal_limit==MALLOC_DISABLE_EXTERNAL_ALLOCS) {
return heap_caps_realloc( ptr, size, MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL );
} else {
void *r;
if (size <= (size_t)malloc_alwaysinternal_limit) {
r=heap_caps_realloc( ptr, size, MALLOC_CAP_DEFAULT | MALLOC_CAP_INTERNAL );
} else {
r=heap_caps_realloc( ptr, size, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM );
}
if (r==NULL && size>0) {
//We needed to allocate memory, but we didn't. Try again while being less picky.
r=heap_caps_realloc( ptr, size, MALLOC_CAP_DEFAULT );
}
return r;
}
}
/*
Memory allocation as preference in decreasing order.
*/
IRAM_ATTR void *heap_caps_malloc_prefer( size_t size, size_t num, ... )
{
va_list argp;
va_start( argp, num );
void *r = NULL;
while (num--) {
uint32_t caps = va_arg( argp, uint32_t );
r = heap_caps_malloc( size, caps );
if (r != NULL) {
break;
}
}
va_end( argp );
return r;
}
/*
Memory reallocation as preference in decreasing order.
*/
IRAM_ATTR void *heap_caps_realloc_prefer( void *ptr, size_t size, size_t num, ... )
{
va_list argp;
va_start( argp, num );
void *r = NULL;
while (num--) {
uint32_t caps = va_arg( argp, uint32_t );
r = heap_caps_realloc( ptr, size, caps );
if (r != NULL || size == 0) {
break;
}
}
va_end( argp );
return r;
}
/*
Memory callocation as preference in decreasing order.
*/
IRAM_ATTR void *heap_caps_calloc_prefer( size_t n, size_t size, size_t num, ... )
{
va_list argp;
va_start( argp, num );
void *r = NULL;
while (num--) {
uint32_t caps = va_arg( argp, uint32_t );
r = heap_caps_calloc( n, size, caps );
if (r != NULL) break;
}
va_end( argp );
return r;
}
/* Find the heap which belongs to ptr, or return NULL if it's
not in any heap.
(This confirms if ptr is inside the heap's region, doesn't confirm if 'ptr'
is an allocated block or is some other random address inside the heap.)
*/
IRAM_ATTR static heap_t *find_containing_heap(void *ptr )
{
intptr_t p = (intptr_t)ptr;
heap_t *heap;
SLIST_FOREACH(heap, &registered_heaps, next) {
if (heap->heap != NULL && p >= heap->start && p < heap->end) {
return heap;
}
}
return NULL;
}
IRAM_ATTR void heap_caps_free( void *ptr)
{
if (ptr == NULL) {
return;
}
if (esp_ptr_in_diram_iram(ptr)) {
//Memory allocated here is actually allocated in the DRAM alias region and
//cannot be de-allocated as usual. dram_alloc_to_iram_addr stores a pointer to
//the equivalent DRAM address, though; free that.
uint32_t *dramAddrPtr = (uint32_t *)ptr;
ptr = (void *)dramAddrPtr[-1];
}
heap_t *heap = find_containing_heap(ptr);
assert(heap != NULL && "free() target pointer is outside heap areas");
multi_heap_free(heap->heap, ptr);
}
IRAM_ATTR void *heap_caps_realloc( void *ptr, size_t size, uint32_t caps)
{
bool ptr_in_diram_case = false;
heap_t *heap = NULL;
void *dram_ptr = NULL;
if (ptr == NULL) {
return heap_caps_malloc(size, caps);
}
if (size == 0) {
heap_caps_free(ptr);
return NULL;
}
if (size > HEAP_SIZE_MAX) {
heap_caps_alloc_failed(size, caps, __func__);
return NULL;
}
//The pointer to memory may be aliased, we need to
//recover the corresponding address before to manage a new allocation:
if(esp_ptr_in_diram_iram((void *)ptr)) {
uint32_t *dram_addr = (uint32_t *)ptr;
dram_ptr = (void *)dram_addr[-1];
heap = find_containing_heap(dram_ptr);
assert(heap != NULL && "realloc() pointer is outside heap areas");
//with pointers that reside on diram space, we avoid using
//the realloc implementation due to address translation issues,
//instead force a malloc/copy/free
ptr_in_diram_case = true;
} else {
heap = find_containing_heap(ptr);
assert(heap != NULL && "realloc() pointer is outside heap areas");
}
// are the existing heap's capabilities compatible with the
// requested ones?
bool compatible_caps = (caps & get_all_caps(heap)) == caps;
if (compatible_caps && !ptr_in_diram_case) {
// try to reallocate this memory within the same heap
// (which will resize the block if it can)
void *r = multi_heap_realloc(heap->heap, ptr, size);
if (r != NULL) {
return r;
}
}
// if we couldn't do that, try to see if we can reallocate
// in a different heap with requested capabilities.
void *new_p = heap_caps_malloc(size, caps);
if (new_p != NULL) {
size_t old_size = 0;
//If we're dealing with aliased ptr, information regarding its containing
//heap can only be obtained with translated address.
if(ptr_in_diram_case) {
old_size = multi_heap_get_allocated_size(heap->heap, dram_ptr);
} else {
old_size = multi_heap_get_allocated_size(heap->heap, ptr);
}
assert(old_size > 0);
memcpy(new_p, ptr, MIN(size, old_size));
heap_caps_free(ptr);
return new_p;
}
heap_caps_alloc_failed(size, caps, __func__);
return NULL;
}
IRAM_ATTR void *heap_caps_calloc( size_t n, size_t size, uint32_t caps)
{
void *result;
size_t size_bytes;
if (__builtin_mul_overflow(n, size, &size_bytes)) {
return NULL;
}
result = heap_caps_malloc(size_bytes, caps);
if (result != NULL) {
bzero(result, size_bytes);
}
return result;
}
size_t heap_caps_get_total_size(uint32_t caps)
{
size_t total_size = 0;
heap_t *heap;
SLIST_FOREACH(heap, &registered_heaps, next) {
if (heap_caps_match(heap, caps)) {
total_size += (heap->end - heap->start);
}
}
return total_size;
}
size_t heap_caps_get_free_size( uint32_t caps )
{
size_t ret = 0;
heap_t *heap;
SLIST_FOREACH(heap, &registered_heaps, next) {
if (heap_caps_match(heap, caps)) {
ret += multi_heap_free_size(heap->heap);
}
}
return ret;
}
size_t heap_caps_get_minimum_free_size( uint32_t caps )
{
size_t ret = 0;
heap_t *heap;
SLIST_FOREACH(heap, &registered_heaps, next) {
if (heap_caps_match(heap, caps)) {
ret += multi_heap_minimum_free_size(heap->heap);
}
}
return ret;
}
size_t heap_caps_get_largest_free_block( uint32_t caps )
{
multi_heap_info_t info;
heap_caps_get_info(&info, caps);
return info.largest_free_block;
}
void heap_caps_get_info( multi_heap_info_t *info, uint32_t caps )
{
bzero(info, sizeof(multi_heap_info_t));
heap_t *heap;
SLIST_FOREACH(heap, &registered_heaps, next) {
if (heap_caps_match(heap, caps)) {
multi_heap_info_t hinfo;
multi_heap_get_info(heap->heap, &hinfo);
info->total_free_bytes += hinfo.total_free_bytes;
info->total_allocated_bytes += hinfo.total_allocated_bytes;
info->largest_free_block = MAX(info->largest_free_block,
hinfo.largest_free_block);
info->minimum_free_bytes += hinfo.minimum_free_bytes;
info->allocated_blocks += hinfo.allocated_blocks;
info->free_blocks += hinfo.free_blocks;
info->total_blocks += hinfo.total_blocks;
}
}
}
void heap_caps_print_heap_info( uint32_t caps )
{
multi_heap_info_t info;
printf("Heap summary for capabilities 0x%08X:\n", caps);
heap_t *heap;
SLIST_FOREACH(heap, &registered_heaps, next) {
if (heap_caps_match(heap, caps)) {
multi_heap_get_info(heap->heap, &info);
printf(" At 0x%08x len %d free %d allocated %d min_free %d\n",
heap->start, heap->end - heap->start, info.total_free_bytes, info.total_allocated_bytes, info.minimum_free_bytes);
printf(" largest_free_block %d alloc_blocks %d free_blocks %d total_blocks %d\n",
info.largest_free_block, info.allocated_blocks,
info.free_blocks, info.total_blocks);
}
}
printf(" Totals:\n");
heap_caps_get_info(&info, caps);
printf(" free %d allocated %d min_free %d largest_free_block %d\n", info.total_free_bytes, info.total_allocated_bytes, info.minimum_free_bytes, info.largest_free_block);
}
bool heap_caps_check_integrity(uint32_t caps, bool print_errors)
{
bool all_heaps = caps & MALLOC_CAP_INVALID;
bool valid = true;
heap_t *heap;
SLIST_FOREACH(heap, &registered_heaps, next) {
if (heap->heap != NULL
&& (all_heaps || (get_all_caps(heap) & caps) == caps)) {
valid = multi_heap_check(heap->heap, print_errors) && valid;
}
}
return valid;
}
bool heap_caps_check_integrity_all(bool print_errors)
{
return heap_caps_check_integrity(MALLOC_CAP_INVALID, print_errors);
}
bool heap_caps_check_integrity_addr(intptr_t addr, bool print_errors)
{
heap_t *heap = find_containing_heap((void *)addr);
if (heap == NULL) {
return false;
}
return multi_heap_check(heap->heap, print_errors);
}
void heap_caps_dump(uint32_t caps)
{
bool all_heaps = caps & MALLOC_CAP_INVALID;
heap_t *heap;
SLIST_FOREACH(heap, &registered_heaps, next) {
if (heap->heap != NULL
&& (all_heaps || (get_all_caps(heap) & caps) == caps)) {
multi_heap_dump(heap->heap);
}
}
}
void heap_caps_dump_all(void)
{
heap_caps_dump(MALLOC_CAP_INVALID);
}
size_t heap_caps_get_allocated_size( void *ptr )
{
heap_t *heap = find_containing_heap(ptr);
size_t size = multi_heap_get_allocated_size(heap->heap, ptr);
return size;
}
IRAM_ATTR void *heap_caps_aligned_alloc(size_t alignment, size_t size, uint32_t caps)
{
void *ret = NULL;
if(!alignment) {
return NULL;
}
//Alignment must be a power of two:
if((alignment & (alignment - 1)) != 0) {
return NULL;
}
if (size > HEAP_SIZE_MAX) {
// Avoids int overflow when adding small numbers to size, or
// calculating 'end' from start+size, by limiting 'size' to the possible range
heap_caps_alloc_failed(size, caps, __func__);
return NULL;
}
for (int prio = 0; prio < SOC_MEMORY_TYPE_NO_PRIOS; prio++) {
//Iterate over heaps and check capabilities at this priority
heap_t *heap;
SLIST_FOREACH(heap, &registered_heaps, next) {
if (heap->heap == NULL) {
continue;
}
if ((heap->caps[prio] & caps) != 0) {
//Heap has at least one of the caps requested. If caps has other bits set that this prio
//doesn't cover, see if they're available in other prios.
if ((get_all_caps(heap) & caps) == caps) {
//Just try to alloc, nothing special.
ret = multi_heap_aligned_alloc(heap->heap, size, alignment);
if (ret != NULL) {
return ret;
}
}
}
}
}
heap_caps_alloc_failed(size, caps, __func__);
//Nothing usable found.
return NULL;
}
IRAM_ATTR void heap_caps_aligned_free(void *ptr)
{
heap_caps_free(ptr);
}
void *heap_caps_aligned_calloc(size_t alignment, size_t n, size_t size, uint32_t caps)
{
size_t size_bytes;
if (__builtin_mul_overflow(n, size, &size_bytes)) {
return NULL;
}
void *ptr = heap_caps_aligned_alloc(alignment,size_bytes, caps);
if(ptr != NULL) {
memset(ptr, 0, size_bytes);
}
return ptr;
}

View File

@@ -0,0 +1,241 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "heap_private.h"
#include <assert.h>
#include <string.h>
#include <sys/lock.h>
#include "esp_log.h"
#include "multi_heap.h"
#include "multi_heap_platform.h"
#include "esp_heap_caps_init.h"
#include "soc/soc_memory_layout.h"
static const char *TAG = "heap_init";
/* Linked-list of registered heaps */
struct registered_heap_ll registered_heaps;
static void register_heap(heap_t *region)
{
size_t heap_size = region->end - region->start;
assert(heap_size <= HEAP_SIZE_MAX);
region->heap = multi_heap_register((void *)region->start, heap_size);
if (region->heap != NULL) {
ESP_EARLY_LOGD(TAG, "New heap initialised at %p", region->heap);
}
}
void heap_caps_enable_nonos_stack_heaps(void)
{
heap_t *heap;
SLIST_FOREACH(heap, &registered_heaps, next) {
// Assume any not-yet-registered heap is
// a nonos-stack heap
if (heap->heap == NULL) {
register_heap(heap);
if (heap->heap != NULL) {
multi_heap_set_lock(heap->heap, &heap->heap_mux);
}
}
}
}
/* Initialize the heap allocator to use all of the memory not
used by static data or reserved for other purposes
*/
void heap_caps_init(void)
{
/* Get the array of regions that we can use for heaps
(with reserved memory removed already.)
*/
size_t num_regions = soc_get_available_memory_region_max_count();
soc_memory_region_t regions[num_regions];
num_regions = soc_get_available_memory_regions(regions);
//The heap allocator will treat every region given to it as separate. In order to get bigger ranges of contiguous memory,
//it's useful to coalesce adjacent regions that have the same type.
for (size_t i = 1; i < num_regions; i++) {
soc_memory_region_t *a = &regions[i - 1];
soc_memory_region_t *b = &regions[i];
if (b->start == (intptr_t)(a->start + a->size) && b->type == a->type ) {
a->type = -1;
b->start = a->start;
b->size += a->size;
}
}
/* Count the heaps left after merging */
size_t num_heaps = 0;
for (size_t i = 0; i < num_regions; i++) {
if (regions[i].type != -1) {
num_heaps++;
}
}
/* Start by allocating the registered heap data on the stack.
Once we have a heap to copy it to, we will copy it to a heap buffer.
*/
heap_t temp_heaps[num_heaps];
size_t heap_idx = 0;
ESP_EARLY_LOGI(TAG, "Initializing. RAM available for dynamic allocation:");
for (size_t i = 0; i < num_regions; i++) {
soc_memory_region_t *region = &regions[i];
const soc_memory_type_desc_t *type = &soc_memory_types[region->type];
heap_t *heap = &temp_heaps[heap_idx];
if (region->type == -1) {
continue;
}
heap_idx++;
assert(heap_idx <= num_heaps);
memcpy(heap->caps, type->caps, sizeof(heap->caps));
heap->start = region->start;
heap->end = region->start + region->size;
MULTI_HEAP_LOCK_INIT(&heap->heap_mux);
if (type->startup_stack) {
/* Will be registered when OS scheduler starts */
heap->heap = NULL;
} else {
register_heap(heap);
}
SLIST_NEXT(heap, next) = NULL;
ESP_EARLY_LOGI(TAG, "At %08X len %08X (%d KiB): %s",
region->start, region->size, region->size / 1024, type->name);
}
assert(heap_idx == num_heaps);
/* Allocate the permanent heap data that we'll use as a linked list at runtime.
Allocate this part of data contiguously, even though it's a linked list... */
assert(SLIST_EMPTY(&registered_heaps));
heap_t *heaps_array = NULL;
for (size_t i = 0; i < num_heaps; i++) {
if (heap_caps_match(&temp_heaps[i], MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL)) {
/* use the first DRAM heap which can fit the data */
heaps_array = multi_heap_malloc(temp_heaps[i].heap, sizeof(heap_t) * num_heaps);
if (heaps_array != NULL) {
break;
}
}
}
assert(heaps_array != NULL); /* if NULL, there's not enough free startup heap space */
memcpy(heaps_array, temp_heaps, sizeof(heap_t)*num_heaps);
/* Iterate the heaps and set their locks, also add them to the linked list. */
for (size_t i = 0; i < num_heaps; i++) {
if (heaps_array[i].heap != NULL) {
multi_heap_set_lock(heaps_array[i].heap, &heaps_array[i].heap_mux);
}
if (i == 0) {
SLIST_INSERT_HEAD(&registered_heaps, &heaps_array[0], next);
} else {
SLIST_INSERT_AFTER(&heaps_array[i-1], &heaps_array[i], next);
}
}
}
esp_err_t heap_caps_add_region(intptr_t start, intptr_t end)
{
if (start == 0) {
return ESP_ERR_INVALID_ARG;
}
for (size_t i = 0; i < soc_memory_region_count; i++) {
const soc_memory_region_t *region = &soc_memory_regions[i];
// Test requested start only as 'end' may be in a different region entry, assume 'end' has same caps
if (region->start <= start && (intptr_t)(region->start + region->size) > start) {
const uint32_t *caps = soc_memory_types[region->type].caps;
return heap_caps_add_region_with_caps(caps, start, end);
}
}
return ESP_ERR_NOT_FOUND;
}
esp_err_t heap_caps_add_region_with_caps(const uint32_t caps[], intptr_t start, intptr_t end)
{
esp_err_t err = ESP_FAIL;
if (caps == NULL || start == 0 || end == 0 || end <= start) {
return ESP_ERR_INVALID_ARG;
}
//Check if region overlaps the start and/or end of an existing region. If so, the
//region is invalid (or maybe added twice)
/*
* assume that in on region, start must be less than end (cannot equal to) !!
* Specially, the 4th scenario can be allowed. For example, allocate memory from heap,
* then change the capability and call this function to create a new region for special
* application.
* In the following chart, 'start = start' and 'end = end' is contained in 3rd scenario.
* This all equal scenario is incorrect because the same region cannot be add twice. For example,
* add the .bss memory to region twice, if not do the check, it will cause exception.
*
* the existing heap region s(tart) e(nd)
* |----------------------|
* 1.add region [Correct] (s1<s && e1<=s) |-----|
* 2.add region [Incorrect] (s2<=s && s<e2<=e) |---------------|
* 3.add region [Incorrect] (s3<=s && e<e3) |-------------------------------------|
* 4 add region [Correct] (s<s4<e && s<e4<=e) |-------|
* 5.add region [Incorrect] (s<s5<e && e<e5) |----------------------------|
* 6.add region [Correct] (e<=s6 && e<e6) |----|
*/
heap_t *heap;
SLIST_FOREACH(heap, &registered_heaps, next) {
if ((start <= heap->start && end > heap->start)
|| (start < heap->end && end > heap->end)) {
return ESP_FAIL;
}
}
heap_t *p_new = heap_caps_malloc(sizeof(heap_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
if (p_new == NULL) {
err = ESP_ERR_NO_MEM;
goto done;
}
memcpy(p_new->caps, caps, sizeof(p_new->caps));
p_new->start = start;
p_new->end = end;
MULTI_HEAP_LOCK_INIT(&p_new->heap_mux);
p_new->heap = multi_heap_register((void *)start, end - start);
SLIST_NEXT(p_new, next) = NULL;
if (p_new->heap == NULL) {
err = ESP_ERR_INVALID_SIZE;
goto done;
}
multi_heap_set_lock(p_new->heap, &p_new->heap_mux);
/* (This insertion is atomic to registered_heaps, so
we don't need to worry about thread safety for readers,
only for writers. */
static multi_heap_lock_t registered_heaps_write_lock = MULTI_HEAP_LOCK_STATIC_INITIALIZER;
MULTI_HEAP_LOCK(&registered_heaps_write_lock);
SLIST_INSERT_HEAD(&registered_heaps, p_new, next);
MULTI_HEAP_UNLOCK(&registered_heaps_write_lock);
err = ESP_OK;
done:
if (err != ESP_OK) {
free(p_new);
}
return err;
}

View File

@@ -0,0 +1,77 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdlib.h>
#include <stdint.h>
#include <soc/soc_memory_layout.h>
#include "multi_heap.h"
#include "multi_heap_platform.h"
#include "sys/queue.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Some common heap registration data structures used
for heap_caps_init.c to share heap information with heap_caps.c
*/
#define HEAP_SIZE_MAX (SOC_MAX_CONTIGUOUS_RAM_SIZE)
/* Type for describing each registered heap */
typedef struct heap_t_ {
uint32_t caps[SOC_MEMORY_TYPE_NO_PRIOS]; ///< Capabilities for the type of memory in this heap (as a prioritised set). Copied from soc_memory_types so it's in RAM not flash.
intptr_t start;
intptr_t end;
multi_heap_lock_t heap_mux;
multi_heap_handle_t heap;
SLIST_ENTRY(heap_t_) next;
} heap_t;
/* All registered heaps.
Forms a single linked list, even though most entries are contiguous.
This means at the expense of 4 bytes per heap, new heaps can be
added at runtime in a fast & thread-safe way.
*/
extern SLIST_HEAD(registered_heap_ll, heap_t_) registered_heaps;
bool heap_caps_match(const heap_t *heap, uint32_t caps);
/* return all possible capabilities (across all priorities) for a given heap */
inline static IRAM_ATTR uint32_t get_all_caps(const heap_t *heap)
{
if (heap->heap == NULL) {
return 0;
}
uint32_t all_caps = 0;
for (int prio = 0; prio < SOC_MEMORY_TYPE_NO_PRIOS; prio++) {
all_caps |= heap->caps[prio];
}
return all_caps;
}
/*
Because we don't want to add _another_ known allocation method to the stack of functions to trace wrt memory tracing,
these are declared private. The newlib malloc()/realloc() implementation also calls these, so they are declared
separately in newlib/syscalls.c.
*/
void *heap_caps_realloc_default(void *p, size_t size);
void *heap_caps_malloc_default(size_t size);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,129 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <multi_heap.h>
#include "multi_heap_internal.h"
#include "heap_private.h"
#include "esp_heap_task_info.h"
#ifdef CONFIG_HEAP_TASK_TRACKING
/*
* Return per-task heap allocation totals and lists of blocks.
*
* For each task that has allocated memory from the heap, return totals for
* allocations within regions matching one or more sets of capabilities.
*
* Optionally also return an array of structs providing details about each
* block allocated by one or more requested tasks, or by all tasks.
*
* Returns the number of block detail structs returned.
*/
size_t heap_caps_get_per_task_info(heap_task_info_params_t *params)
{
heap_t *reg;
heap_task_block_t *blocks = params->blocks;
size_t count = *params->num_totals;
size_t remaining = params->max_blocks;
// Clear out totals for any prepopulated tasks.
if (params->totals) {
for (size_t i = 0; i < count; ++i) {
for (size_t type = 0; type < NUM_HEAP_TASK_CAPS; ++type) {
params->totals[i].size[type] = 0;
params->totals[i].count[type] = 0;
}
}
}
SLIST_FOREACH(reg, &registered_heaps, next) {
multi_heap_handle_t heap = reg->heap;
if (heap == NULL) {
continue;
}
// Find if the capabilities of this heap region match on of the desired
// sets of capabilities.
uint32_t caps = get_all_caps(reg);
uint32_t type;
for (type = 0; type < NUM_HEAP_TASK_CAPS; ++type) {
if ((caps & params->mask[type]) == params->caps[type]) {
break;
}
}
if (type == NUM_HEAP_TASK_CAPS) {
continue;
}
multi_heap_block_handle_t b = multi_heap_get_first_block(heap);
multi_heap_internal_lock(heap);
for ( ; b ; b = multi_heap_get_next_block(heap, b)) {
if (multi_heap_is_free(b)) {
continue;
}
void *p = multi_heap_get_block_address(b); // Safe, only arithmetic
size_t bsize = multi_heap_get_allocated_size(heap, p); // Validates
TaskHandle_t btask = (TaskHandle_t)multi_heap_get_block_owner(b);
// Accumulate per-task allocation totals.
if (params->totals) {
size_t i;
for (i = 0; i < count; ++i) {
if (params->totals[i].task == btask) {
break;
}
}
if (i < count) {
params->totals[i].size[type] += bsize;
params->totals[i].count[type] += 1;
}
else {
if (count < params->max_totals) {
params->totals[count].task = btask;
params->totals[count].size[type] = bsize;
params->totals[i].count[type] = 1;
++count;
}
}
}
// Return details about allocated blocks for selected tasks.
if (blocks && remaining > 0) {
if (params->tasks) {
size_t i;
for (i = 0; i < params->num_tasks; ++i) {
if (btask == params->tasks[i]) {
break;
}
}
if (i == params->num_tasks) {
continue;
}
}
blocks->task = btask;
blocks->address = p;
blocks->size = bsize;
++blocks;
--remaining;
}
}
multi_heap_internal_unlock(heap);
}
*params->num_totals = count;
return params->max_blocks - remaining;
}
#endif // CONFIG_HEAP_TASK_TRACKING

1015
components/heap/heap_tlsf.c Normal file

File diff suppressed because it is too large Load Diff

119
components/heap/heap_tlsf.h Normal file
View File

@@ -0,0 +1,119 @@
/*
** Two Level Segregated Fit memory allocator, version 3.1.
** Written by Matthew Conte
** http://tlsf.baisoku.org
**
** Based on the original documentation by Miguel Masmano:
** http://www.gii.upv.es/tlsf/main/docs
**
** This implementation was written to the specification
** of the document, therefore no GPL restrictions apply.
**
** Copyright (c) 2006-2016, Matthew Conte
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the copyright holder nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <assert.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include "heap_tlsf_config.h"
#if defined(__cplusplus)
extern "C" {
#endif
/*
** Cast and min/max macros.
*/
#define tlsf_cast(t, exp) ((t) (exp))
#define tlsf_min(a, b) ((a) < (b) ? (a) : (b))
#define tlsf_max(a, b) ((a) > (b) ? (a) : (b))
/* A type used for casting when doing pointer arithmetic. */
typedef ptrdiff_t tlsfptr_t;
typedef struct block_header_t
{
/* Points to the previous physical block. */
struct block_header_t* prev_phys_block;
/* The size of this block, excluding the block header. */
size_t size;
/* Next and previous free blocks. */
struct block_header_t* next_free;
struct block_header_t* prev_free;
} block_header_t;
#include "heap_tlsf_block_functions.h"
/* tlsf_t: a TLSF structure. Can contain 1 to N pools. */
/* pool_t: a block of memory that TLSF can manage. */
typedef void* tlsf_t;
typedef void* pool_t;
/* Create/destroy a memory pool. */
tlsf_t tlsf_create(void* mem, size_t max_bytes);
tlsf_t tlsf_create_with_pool(void* mem, size_t pool_bytes, size_t max_bytes);
pool_t tlsf_get_pool(tlsf_t tlsf);
/* Add/remove memory pools. */
pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes);
void tlsf_remove_pool(tlsf_t tlsf, pool_t pool);
/* malloc/memalign/realloc/free replacements. */
void* tlsf_malloc(tlsf_t tlsf, size_t size);
void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t size);
void* tlsf_memalign_offs(tlsf_t tlsf, size_t align, size_t size, size_t offset);
void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size);
void tlsf_free(tlsf_t tlsf, void* ptr);
/* Returns internal block size, not original request size */
size_t tlsf_block_size(void* ptr);
/* Overheads/limits of internal structures. */
size_t tlsf_size(tlsf_t tlsf);
size_t tlsf_align_size(void);
size_t tlsf_block_size_min(void);
size_t tlsf_block_size_max(tlsf_t tlsf);
size_t tlsf_pool_overhead(void);
size_t tlsf_alloc_overhead(void);
size_t tlsf_fit_size(tlsf_t tlsf, size_t size);
/* Debugging. */
typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user);
void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user);
/* Returns nonzero if any internal consistency check fails. */
int tlsf_check(tlsf_t tlsf);
int tlsf_check_pool(pool_t pool);
#if defined(__cplusplus)
};
#endif

View File

@@ -0,0 +1,174 @@
/*
** Two Level Segregated Fit memory allocator, version 3.1.
** Written by Matthew Conte
** http://tlsf.baisoku.org
**
** Based on the original documentation by Miguel Masmano:
** http://www.gii.upv.es/tlsf/main/docs
**
** This implementation was written to the specification
** of the document, therefore no GPL restrictions apply.
**
** Copyright (c) 2006-2016, Matthew Conte
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the copyright holder nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
/*
** Data structures and associated constants.
*/
/*
** Since block sizes are always at least a multiple of 4, the two least
** significant bits of the size field are used to store the block status:
** - bit 0: whether block is busy or free
** - bit 1: whether previous block is busy or free
*/
#define block_header_free_bit (1 << 0)
#define block_header_prev_free_bit (1 << 1)
/*
** The size of the block header exposed to used blocks is the size field.
** The prev_phys_block field is stored *inside* the previous free block.
*/
#define block_header_overhead (sizeof(size_t))
/* User data starts directly after the size field in a used block. */
#define block_start_offset (offsetof(block_header_t, size) + sizeof(size_t))
/*
** A free block must be large enough to store its header minus the size of
** the prev_phys_block field, and no larger than the number of addressable
** bits for FL_INDEX.
** The block_size_max macro returns the maximum block for the minimum pool
** use tlsf_block_size_max for a value specific to the pool
*/
#define block_size_min (sizeof(block_header_t) - sizeof(block_header_t*))
#define block_size_max (tlsf_cast(size_t, 1) << FL_INDEX_MAX_MIN)
/*
** block_header_t member functions.
*/
static inline __attribute__((__always_inline__)) size_t block_size(const block_header_t* block)
{
return block->size & ~(block_header_free_bit | block_header_prev_free_bit);
}
static inline __attribute__((__always_inline__)) void block_set_size(block_header_t* block, size_t size)
{
const size_t oldsize = block->size;
block->size = size | (oldsize & (block_header_free_bit | block_header_prev_free_bit));
}
static inline __attribute__((__always_inline__)) int block_is_last(const block_header_t* block)
{
return block_size(block) == 0;
}
static inline __attribute__((__always_inline__)) int block_is_free(const block_header_t* block)
{
return tlsf_cast(int, block->size & block_header_free_bit);
}
static inline __attribute__((__always_inline__)) void block_set_free(block_header_t* block)
{
block->size |= block_header_free_bit;
}
static inline __attribute__((__always_inline__)) void block_set_used(block_header_t* block)
{
block->size &= ~block_header_free_bit;
}
static inline __attribute__((__always_inline__)) int block_is_prev_free(const block_header_t* block)
{
return tlsf_cast(int, block->size & block_header_prev_free_bit);
}
static inline __attribute__((__always_inline__)) void block_set_prev_free(block_header_t* block)
{
block->size |= block_header_prev_free_bit;
}
static inline __attribute__((__always_inline__)) void block_set_prev_used(block_header_t* block)
{
block->size &= ~block_header_prev_free_bit;
}
static inline __attribute__((__always_inline__)) block_header_t* block_from_ptr(const void* ptr)
{
return tlsf_cast(block_header_t*,
tlsf_cast(unsigned char*, ptr) - block_start_offset);
}
static inline __attribute__((__always_inline__)) void* block_to_ptr(const block_header_t* block)
{
return tlsf_cast(void*,
tlsf_cast(unsigned char*, block) + block_start_offset);
}
/* Return location of next block after block of given size. */
static inline __attribute__((__always_inline__)) block_header_t* offset_to_block(const void* ptr, size_t size)
{
return tlsf_cast(block_header_t*, tlsf_cast(tlsfptr_t, ptr) + size);
}
/* Return location of previous block. */
static inline __attribute__((__always_inline__)) block_header_t* block_prev(const block_header_t* block)
{
return block->prev_phys_block;
}
/* Return location of next existing block. */
static inline __attribute__((__always_inline__)) block_header_t* block_next(const block_header_t* block)
{
block_header_t* next = offset_to_block(block_to_ptr(block),
block_size(block) - block_header_overhead);
return next;
}
/* Link a new block with its physical neighbor, return the neighbor. */
static inline __attribute__((__always_inline__)) block_header_t* block_link_next(block_header_t* block)
{
block_header_t* next = block_next(block);
next->prev_phys_block = block;
return next;
}
static inline __attribute__((__always_inline__)) void block_mark_as_free(block_header_t* block)
{
/* Link the block to the next block, first. */
block_header_t* next = block_link_next(block);
block_set_prev_free(next);
block_set_free(block);
}
static inline __attribute__((__always_inline__)) void block_mark_as_used(block_header_t* block)
{
block_header_t* next = block_next(block);
block_set_prev_used(next);
block_set_used(block);
}

View File

@@ -0,0 +1,66 @@
/*
** Two Level Segregated Fit memory allocator, version 3.1.
** Written by Matthew Conte
** http://tlsf.baisoku.org
**
** Based on the original documentation by Miguel Masmano:
** http://www.gii.upv.es/tlsf/main/docs
**
** This implementation was written to the specification
** of the document, therefore no GPL restrictions apply.
**
** Copyright (c) 2006-2016, Matthew Conte
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the copyright holder nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
enum tlsf_config
{
/* log2 of number of linear subdivisions of block sizes. Larger
** values require more memory in the control structure. Values of
** 4 or 5 are typical, 3 is for very small pools.
*/
SL_INDEX_COUNT_LOG2_MIN = 3,
/* All allocation sizes and addresses are aligned to 4 bytes. */
ALIGN_SIZE_LOG2 = 2,
ALIGN_SIZE = (1 << ALIGN_SIZE_LOG2),
/*
** We support allocations of sizes up to (1 << FL_INDEX_MAX) bits.
** However, because we linearly subdivide the second-level lists, and
** our minimum size granularity is 4 bytes, it doesn't make sense to
** create first-level lists for sizes smaller than SL_INDEX_COUNT * 4,
** or (1 << (SL_INDEX_COUNT_LOG2 + 2)) bytes, as there we will be
** trying to split size ranges into more slots than we have available.
** Instead, we calculate the minimum threshold size, and place all
** blocks below that size into the 0th first-level list.
** Values below are the absolute minimum to accept a pool addition
*/
FL_INDEX_MAX_MIN = 14, // For a less than 16kB pool
SL_INDEX_COUNT_MIN = (1 << SL_INDEX_COUNT_LOG2_MIN),
FL_INDEX_COUNT_MIN = (FL_INDEX_MAX_MIN - (SL_INDEX_COUNT_LOG2_MIN + ALIGN_SIZE_LOG2) + 1),
};

View File

@@ -0,0 +1,255 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include <sdkconfig.h>
#define HEAP_TRACE_SRCFILE /* don't warn on inclusion here */
#include "esp_heap_trace.h"
#undef HEAP_TRACE_SRCFILE
#include "esp_attr.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define STACK_DEPTH CONFIG_HEAP_TRACING_STACK_DEPTH
#if CONFIG_HEAP_TRACING_STANDALONE
static portMUX_TYPE trace_mux = portMUX_INITIALIZER_UNLOCKED;
static bool tracing;
static heap_trace_mode_t mode;
/* Buffer used for records, starting at offset 0
*/
static heap_trace_record_t *buffer;
static size_t total_records;
/* Count of entries logged in the buffer.
Maximum total_records
*/
static size_t count;
/* Actual number of allocations logged */
static size_t total_allocations;
/* Actual number of frees logged */
static size_t total_frees;
/* Has the buffer overflowed and lost trace entries? */
static bool has_overflowed = false;
esp_err_t heap_trace_init_standalone(heap_trace_record_t *record_buffer, size_t num_records)
{
if (tracing) {
return ESP_ERR_INVALID_STATE;
}
buffer = record_buffer;
total_records = num_records;
memset(buffer, 0, num_records * sizeof(heap_trace_record_t));
return ESP_OK;
}
esp_err_t heap_trace_start(heap_trace_mode_t mode_param)
{
if (buffer == NULL || total_records == 0) {
return ESP_ERR_INVALID_STATE;
}
portENTER_CRITICAL(&trace_mux);
tracing = false;
mode = mode_param;
count = 0;
total_allocations = 0;
total_frees = 0;
has_overflowed = false;
heap_trace_resume();
portEXIT_CRITICAL(&trace_mux);
return ESP_OK;
}
static esp_err_t set_tracing(bool enable)
{
if (tracing == enable) {
return ESP_ERR_INVALID_STATE;
}
tracing = enable;
return ESP_OK;
}
esp_err_t heap_trace_stop(void)
{
return set_tracing(false);
}
esp_err_t heap_trace_resume(void)
{
return set_tracing(true);
}
size_t heap_trace_get_count(void)
{
return count;
}
esp_err_t heap_trace_get(size_t index, heap_trace_record_t *record)
{
if (record == NULL) {
return ESP_ERR_INVALID_STATE;
}
esp_err_t result = ESP_OK;
portENTER_CRITICAL(&trace_mux);
if (index >= count) {
result = ESP_ERR_INVALID_ARG; /* out of range for 'count' */
} else {
memcpy(record, &buffer[index], sizeof(heap_trace_record_t));
}
portEXIT_CRITICAL(&trace_mux);
return result;
}
void heap_trace_dump(void)
{
size_t delta_size = 0;
size_t delta_allocs = 0;
printf("%u allocations trace (%u entry buffer)\n",
count, total_records);
size_t start_count = count;
for (int i = 0; i < count; i++) {
heap_trace_record_t *rec = &buffer[i];
if (rec->address != NULL) {
printf("%d bytes (@ %p) allocated CPU %d ccount 0x%08x caller ",
rec->size, rec->address, rec->ccount & 1, rec->ccount & ~3);
for (int j = 0; j < STACK_DEPTH && rec->alloced_by[j] != 0; j++) {
printf("%p%s", rec->alloced_by[j],
(j < STACK_DEPTH - 1) ? ":" : "");
}
if (mode != HEAP_TRACE_ALL || STACK_DEPTH == 0 || rec->freed_by[0] == NULL) {
delta_size += rec->size;
delta_allocs++;
printf("\n");
} else {
printf("\nfreed by ");
for (int j = 0; j < STACK_DEPTH; j++) {
printf("%p%s", rec->freed_by[j],
(j < STACK_DEPTH - 1) ? ":" : "\n");
}
}
}
}
if (mode == HEAP_TRACE_ALL) {
printf("%u bytes alive in trace (%u/%u allocations)\n",
delta_size, delta_allocs, heap_trace_get_count());
} else {
printf("%u bytes 'leaked' in trace (%u allocations)\n", delta_size, delta_allocs);
}
printf("total allocations %u total frees %u\n", total_allocations, total_frees);
if (start_count != count) { // only a problem if trace isn't stopped before dumping
printf("(NB: New entries were traced while dumping, so trace dump may have duplicate entries.)\n");
}
if (has_overflowed) {
printf("(NB: Buffer has overflowed, so trace data is incomplete.)\n");
}
}
/* Add a new allocation to the heap trace records */
static IRAM_ATTR void record_allocation(const heap_trace_record_t *record)
{
if (!tracing || record->address == NULL) {
return;
}
portENTER_CRITICAL(&trace_mux);
if (tracing) {
if (count == total_records) {
has_overflowed = true;
/* Move the whole buffer back one slot.
This is a bit slow, compared to treating this buffer as a ringbuffer and rotating a head pointer.
However, ringbuffer code gets tricky when we remove elements in mid-buffer (for leak trace mode) while
trying to keep track of an item count that may overflow.
*/
memmove(&buffer[0], &buffer[1], sizeof(heap_trace_record_t) * (total_records -1));
count--;
}
// Copy new record into place
memcpy(&buffer[count], record, sizeof(heap_trace_record_t));
count++;
total_allocations++;
}
portEXIT_CRITICAL(&trace_mux);
}
// remove a record, used when freeing
static void remove_record(int index);
/* record a free event in the heap trace log
For HEAP_TRACE_ALL, this means filling in the freed_by pointer.
For HEAP_TRACE_LEAKS, this means removing the record from the log.
*/
static IRAM_ATTR void record_free(void *p, void **callers)
{
if (!tracing || p == NULL) {
return;
}
portENTER_CRITICAL(&trace_mux);
if (tracing && count > 0) {
total_frees++;
/* search backwards for the allocation record matching this free */
int i;
for (i = count - 1; i >= 0; i--) {
if (buffer[i].address == p) {
break;
}
}
if (i >= 0) {
if (mode == HEAP_TRACE_ALL) {
memcpy(buffer[i].freed_by, callers, sizeof(void *) * STACK_DEPTH);
} else { // HEAP_TRACE_LEAKS
// Leak trace mode, once an allocation is freed we remove it from the list
remove_record(i);
}
}
}
portEXIT_CRITICAL(&trace_mux);
}
/* remove the entry at 'index' from the ringbuffer of saved records */
static IRAM_ATTR void remove_record(int index)
{
if (index < count - 1) {
// Remove the buffer entry from the list
memmove(&buffer[index], &buffer[index+1],
sizeof(heap_trace_record_t) * (total_records - index - 1));
} else {
// For last element, just zero it out to avoid ambiguity
memset(&buffer[index], 0, sizeof(heap_trace_record_t));
}
count--;
}
#include "heap_trace.inc"
#endif /*CONFIG_HEAP_TRACING_STANDALONE*/

View File

@@ -0,0 +1,402 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdint.h>
#include <stdlib.h>
#include "multi_heap.h"
#include <sdkconfig.h>
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Flags to indicate the capabilities of the various memory systems
*/
#define MALLOC_CAP_EXEC (1<<0) ///< Memory must be able to run executable code
#define MALLOC_CAP_32BIT (1<<1) ///< Memory must allow for aligned 32-bit data accesses
#define MALLOC_CAP_8BIT (1<<2) ///< Memory must allow for 8/16/...-bit data accesses
#define MALLOC_CAP_DMA (1<<3) ///< Memory must be able to accessed by DMA
#define MALLOC_CAP_PID2 (1<<4) ///< Memory must be mapped to PID2 memory space (PIDs are not currently used)
#define MALLOC_CAP_PID3 (1<<5) ///< Memory must be mapped to PID3 memory space (PIDs are not currently used)
#define MALLOC_CAP_PID4 (1<<6) ///< Memory must be mapped to PID4 memory space (PIDs are not currently used)
#define MALLOC_CAP_PID5 (1<<7) ///< Memory must be mapped to PID5 memory space (PIDs are not currently used)
#define MALLOC_CAP_PID6 (1<<8) ///< Memory must be mapped to PID6 memory space (PIDs are not currently used)
#define MALLOC_CAP_PID7 (1<<9) ///< Memory must be mapped to PID7 memory space (PIDs are not currently used)
#define MALLOC_CAP_SPIRAM (1<<10) ///< Memory must be in SPI RAM
#define MALLOC_CAP_INTERNAL (1<<11) ///< Memory must be internal; specifically it should not disappear when flash/spiram cache is switched off
#define MALLOC_CAP_DEFAULT (1<<12) ///< Memory can be returned in a non-capability-specific memory allocation (e.g. malloc(), calloc()) call
#define MALLOC_CAP_IRAM_8BIT (1<<13) ///< Memory must be in IRAM and allow unaligned access
#define MALLOC_CAP_RETENTION (1<<14)
#define MALLOC_CAP_INVALID (1<<31) ///< Memory can't be used / list end marker
/**
* @brief callback called when a allocation operation fails, if registered
* @param size in bytes of failed allocation
* @param caps capabillites requested of failed allocation
* @param function_name function which generated the failure
*/
typedef void (*esp_alloc_failed_hook_t) (size_t size, uint32_t caps, const char * function_name);
/**
* @brief registers a callback function to be invoked if a memory allocation operation fails
* @param callback caller defined callback to be invoked
* @return ESP_OK if callback was registered.
*/
esp_err_t heap_caps_register_failed_alloc_callback(esp_alloc_failed_hook_t callback);
/**
* @brief Allocate a chunk of memory which has the given capabilities
*
* Equivalent semantics to libc malloc(), for capability-aware memory.
*
* In IDF, ``malloc(p)`` is equivalent to ``heap_caps_malloc(p, MALLOC_CAP_8BIT)``.
*
* @param size Size, in bytes, of the amount of memory to allocate
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
* of memory to be returned
*
* @return A pointer to the memory allocated on success, NULL on failure
*/
void *heap_caps_malloc(size_t size, uint32_t caps);
/**
* @brief Free memory previously allocated via heap_caps_malloc() or heap_caps_realloc().
*
* Equivalent semantics to libc free(), for capability-aware memory.
*
* In IDF, ``free(p)`` is equivalent to ``heap_caps_free(p)``.
*
* @param ptr Pointer to memory previously returned from heap_caps_malloc() or heap_caps_realloc(). Can be NULL.
*/
void heap_caps_free( void *ptr);
/**
* @brief Reallocate memory previously allocated via heap_caps_malloc() or heap_caps_realloc().
*
* Equivalent semantics to libc realloc(), for capability-aware memory.
*
* In IDF, ``realloc(p, s)`` is equivalent to ``heap_caps_realloc(p, s, MALLOC_CAP_8BIT)``.
*
* 'caps' parameter can be different to the capabilities that any original 'ptr' was allocated with. In this way,
* realloc can be used to "move" a buffer if necessary to ensure it meets a new set of capabilities.
*
* @param ptr Pointer to previously allocated memory, or NULL for a new allocation.
* @param size Size of the new buffer requested, or 0 to free the buffer.
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
* of memory desired for the new allocation.
*
* @return Pointer to a new buffer of size 'size' with capabilities 'caps', or NULL if allocation failed.
*/
void *heap_caps_realloc( void *ptr, size_t size, uint32_t caps);
/**
* @brief Allocate a aligned chunk of memory which has the given capabilities
*
* Equivalent semantics to libc aligned_alloc(), for capability-aware memory.
* @param alignment How the pointer received needs to be aligned
* must be a power of two
* @param size Size, in bytes, of the amount of memory to allocate
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
* of memory to be returned
*
* @return A pointer to the memory allocated on success, NULL on failure
*
*
*/
void *heap_caps_aligned_alloc(size_t alignment, size_t size, uint32_t caps);
/**
* @brief Used to deallocate memory previously allocated with heap_caps_aligned_alloc
*
* @param ptr Pointer to the memory allocated
* @note This function is deprecated, plase consider using heap_caps_free() instead
*/
void __attribute__((deprecated)) heap_caps_aligned_free(void *ptr);
/**
* @brief Allocate a aligned chunk of memory which has the given capabilities. The initialized value in the memory is set to zero.
*
* @param alignment How the pointer received needs to be aligned
* must be a power of two
* @param n Number of continuing chunks of memory to allocate
* @param size Size, in bytes, of a chunk of memory to allocate
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
* of memory to be returned
*
* @return A pointer to the memory allocated on success, NULL on failure
*
*/
void *heap_caps_aligned_calloc(size_t alignment, size_t n, size_t size, uint32_t caps);
/**
* @brief Allocate a chunk of memory which has the given capabilities. The initialized value in the memory is set to zero.
*
* Equivalent semantics to libc calloc(), for capability-aware memory.
*
* In IDF, ``calloc(p)`` is equivalent to ``heap_caps_calloc(p, MALLOC_CAP_8BIT)``.
*
* @param n Number of continuing chunks of memory to allocate
* @param size Size, in bytes, of a chunk of memory to allocate
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
* of memory to be returned
*
* @return A pointer to the memory allocated on success, NULL on failure
*/
void *heap_caps_calloc(size_t n, size_t size, uint32_t caps);
/**
* @brief Get the total size of all the regions that have the given capabilities
*
* This function takes all regions capable of having the given capabilities allocated in them
* and adds up the total space they have.
*
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
* of memory
*
* @return total size in bytes
*/
size_t heap_caps_get_total_size(uint32_t caps);
/**
* @brief Get the total free size of all the regions that have the given capabilities
*
* This function takes all regions capable of having the given capabilities allocated in them
* and adds up the free space they have.
*
* Note that because of heap fragmentation it is probably not possible to allocate a single block of memory
* of this size. Use heap_caps_get_largest_free_block() for this purpose.
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
* of memory
*
* @return Amount of free bytes in the regions
*/
size_t heap_caps_get_free_size( uint32_t caps );
/**
* @brief Get the total minimum free memory of all regions with the given capabilities
*
* This adds all the low water marks of the regions capable of delivering the memory
* with the given capabilities.
*
* Note the result may be less than the global all-time minimum available heap of this kind, as "low water marks" are
* tracked per-region. Individual regions' heaps may have reached their "low water marks" at different points in time. However
* this result still gives a "worst case" indication for all-time minimum free heap.
*
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
* of memory
*
* @return Amount of free bytes in the regions
*/
size_t heap_caps_get_minimum_free_size( uint32_t caps );
/**
* @brief Get the largest free block of memory able to be allocated with the given capabilities.
*
* Returns the largest value of ``s`` for which ``heap_caps_malloc(s, caps)`` will succeed.
*
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
* of memory
*
* @return Size of largest free block in bytes.
*/
size_t heap_caps_get_largest_free_block( uint32_t caps );
/**
* @brief Get heap info for all regions with the given capabilities.
*
* Calls multi_heap_info() on all heaps which share the given capabilities. The information returned is an aggregate
* across all matching heaps. The meanings of fields are the same as defined for multi_heap_info_t, except that
* ``minimum_free_bytes`` has the same caveats described in heap_caps_get_minimum_free_size().
*
* @param info Pointer to a structure which will be filled with relevant
* heap metadata.
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
* of memory
*
*/
void heap_caps_get_info( multi_heap_info_t *info, uint32_t caps );
/**
* @brief Print a summary of all memory with the given capabilities.
*
* Calls multi_heap_info on all heaps which share the given capabilities, and
* prints a two-line summary for each, then a total summary.
*
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
* of memory
*
*/
void heap_caps_print_heap_info( uint32_t caps );
/**
* @brief Check integrity of all heap memory in the system.
*
* Calls multi_heap_check on all heaps. Optionally print errors if heaps are corrupt.
*
* Calling this function is equivalent to calling heap_caps_check_integrity
* with the caps argument set to MALLOC_CAP_INVALID.
*
* @param print_errors Print specific errors if heap corruption is found.
*
* @return True if all heaps are valid, False if at least one heap is corrupt.
*/
bool heap_caps_check_integrity_all(bool print_errors);
/**
* @brief Check integrity of all heaps with the given capabilities.
*
* Calls multi_heap_check on all heaps which share the given capabilities. Optionally
* print errors if the heaps are corrupt.
*
* See also heap_caps_check_integrity_all to check all heap memory
* in the system and heap_caps_check_integrity_addr to check memory
* around a single address.
*
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
* of memory
* @param print_errors Print specific errors if heap corruption is found.
*
* @return True if all heaps are valid, False if at least one heap is corrupt.
*/
bool heap_caps_check_integrity(uint32_t caps, bool print_errors);
/**
* @brief Check integrity of heap memory around a given address.
*
* This function can be used to check the integrity of a single region of heap memory,
* which contains the given address.
*
* This can be useful if debugging heap integrity for corruption at a known address,
* as it has a lower overhead than checking all heap regions. Note that if the corrupt
* address moves around between runs (due to timing or other factors) then this approach
* won't work and you should call heap_caps_check_integrity or
* heap_caps_check_integrity_all instead.
*
* @note The entire heap region around the address is checked, not only the adjacent
* heap blocks.
*
* @param addr Address in memory. Check for corruption in region containing this address.
* @param print_errors Print specific errors if heap corruption is found.
*
* @return True if the heap containing the specified address is valid,
* False if at least one heap is corrupt or the address doesn't belong to a heap region.
*/
bool heap_caps_check_integrity_addr(intptr_t addr, bool print_errors);
/**
* @brief Enable malloc() in external memory and set limit below which
* malloc() attempts are placed in internal memory.
*
* When external memory is in use, the allocation strategy is to initially try to
* satisfy smaller allocation requests with internal memory and larger requests
* with external memory. This sets the limit between the two, as well as generally
* enabling allocation in external memory.
*
* @param limit Limit, in bytes.
*/
void heap_caps_malloc_extmem_enable(size_t limit);
/**
* @brief Allocate a chunk of memory as preference in decreasing order.
*
* @attention The variable parameters are bitwise OR of MALLOC_CAP_* flags indicating the type of memory.
* This API prefers to allocate memory with the first parameter. If failed, allocate memory with
* the next parameter. It will try in this order until allocating a chunk of memory successfully
* or fail to allocate memories with any of the parameters.
*
* @param size Size, in bytes, of the amount of memory to allocate
* @param num Number of variable paramters
*
* @return A pointer to the memory allocated on success, NULL on failure
*/
void *heap_caps_malloc_prefer( size_t size, size_t num, ... );
/**
* @brief Allocate a chunk of memory as preference in decreasing order.
*
* @param ptr Pointer to previously allocated memory, or NULL for a new allocation.
* @param size Size of the new buffer requested, or 0 to free the buffer.
* @param num Number of variable paramters
*
* @return Pointer to a new buffer of size 'size', or NULL if allocation failed.
*/
void *heap_caps_realloc_prefer( void *ptr, size_t size, size_t num, ... );
/**
* @brief Allocate a chunk of memory as preference in decreasing order.
*
* @param n Number of continuing chunks of memory to allocate
* @param size Size, in bytes, of a chunk of memory to allocate
* @param num Number of variable paramters
*
* @return A pointer to the memory allocated on success, NULL on failure
*/
void *heap_caps_calloc_prefer( size_t n, size_t size, size_t num, ... );
/**
* @brief Dump the full structure of all heaps with matching capabilities.
*
* Prints a large amount of output to serial (because of locking limitations,
* the output bypasses stdout/stderr). For each (variable sized) block
* in each matching heap, the following output is printed on a single line:
*
* - Block address (the data buffer returned by malloc is 4 bytes after this
* if heap debugging is set to Basic, or 8 bytes otherwise).
* - Data size (the data size may be larger than the size requested by malloc,
* either due to heap fragmentation or because of heap debugging level).
* - Address of next block in the heap.
* - If the block is free, the address of the next free block is also printed.
*
* @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
* of memory
*/
void heap_caps_dump(uint32_t caps);
/**
* @brief Dump the full structure of all heaps.
*
* Covers all registered heaps. Prints a large amount of output to serial.
*
* Output is the same as for heap_caps_dump.
*
*/
void heap_caps_dump_all(void);
/**
* @brief Return the size that a particular pointer was allocated with.
*
* @param ptr Pointer to currently allocated heap memory. Must be a pointer value previously
* returned by heap_caps_malloc,malloc,calloc, etc. and not yet freed.
*
* @note The app will crash with an assertion failure if the pointer is not valid.
*
* @return Size of the memory allocated at this block.
*
*/
size_t heap_caps_get_allocated_size( void *ptr );
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,92 @@
// Copyright 2017 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "esp_err.h"
#include "esp_heap_caps.h"
#include "soc/soc_memory_layout.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Initialize the capability-aware heap allocator.
*
* This is called once in the IDF startup code. Do not call it
* at other times.
*/
void heap_caps_init(void);
/**
* @brief Enable heap(s) in memory regions where the startup stacks are located.
*
* On startup, the pro/app CPUs have a certain memory region they use as stack, so we
* cannot do allocations in the regions these stack frames are. When FreeRTOS is
* completely started, they do not use that memory anymore and heap(s) there can
* be enabled.
*/
void heap_caps_enable_nonos_stack_heaps(void);
/**
* @brief Add a region of memory to the collection of heaps at runtime.
*
* Most memory regions are defined in soc_memory_layout.c for the SoC,
* and are registered via heap_caps_init(). Some regions can't be used
* immediately and are later enabled via heap_caps_enable_nonos_stack_heaps().
*
* Call this function to add a region of memory to the heap at some later time.
*
* This function does not consider any of the "reserved" regions or other data in soc_memory_layout, caller needs to
* consider this themselves.
*
* All memory within the region specified by start & end parameters must be otherwise unused.
*
* The capabilities of the newly registered memory will be determined by the start address, as looked up in the regions
* specified in soc_memory_layout.c.
*
* Use heap_caps_add_region_with_caps() to register a region with custom capabilities.
*
* @param start Start address of new region.
* @param end End address of new region.
*
* @return ESP_OK on success, ESP_ERR_INVALID_ARG if a parameter is invalid, ESP_ERR_NOT_FOUND if the
* specified start address doesn't reside in a known region, or any error returned by heap_caps_add_region_with_caps().
*/
esp_err_t heap_caps_add_region(intptr_t start, intptr_t end);
/**
* @brief Add a region of memory to the collection of heaps at runtime, with custom capabilities.
*
* Similar to heap_caps_add_region(), only custom memory capabilities are specified by the caller.
*
* @param caps Ordered array of capability masks for the new region, in order of priority. Must have length
* SOC_MEMORY_TYPE_NO_PRIOS. Does not need to remain valid after the call returns.
* @param start Start address of new region.
* @param end End address of new region.
*
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_ARG if a parameter is invalid
* - ESP_ERR_NO_MEM if no memory to register new heap.
* - ESP_ERR_INVALID_SIZE if the memory region is too small to fit a heap
* - ESP_FAIL if region overlaps the start and/or end of an existing region
*/
esp_err_t heap_caps_add_region_with_caps(const uint32_t caps[], intptr_t start, intptr_t end);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,98 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef CONFIG_HEAP_TASK_TRACKING
#ifdef __cplusplus
extern "C" {
#endif
// This macro controls how much space is provided for partitioning the per-task
// heap allocation info according to one or more sets of heap capabilities.
#define NUM_HEAP_TASK_CAPS 4
/** @brief Structure to collect per-task heap allocation totals partitioned by selected caps */
typedef struct {
TaskHandle_t task; ///< Task to which these totals belong
size_t size[NUM_HEAP_TASK_CAPS]; ///< Total allocations partitioned by selected caps
size_t count[NUM_HEAP_TASK_CAPS]; ///< Number of blocks partitioned by selected caps
} heap_task_totals_t;
/** @brief Structure providing details about a block allocated by a task */
typedef struct {
TaskHandle_t task; ///< Task that allocated the block
void *address; ///< User address of allocated block
uint32_t size; ///< Size of the allocated block
} heap_task_block_t;
/** @brief Structure to provide parameters to heap_caps_get_per_task_info
*
* The 'caps' and 'mask' arrays allow partitioning the per-task heap allocation
* totals by selected sets of heap region capabilities so that totals for
* multiple regions can be accumulated in one scan. The capabilities flags for
* each region ANDed with mask[i] are compared to caps[i] in order; the
* allocations in that region are added to totals->size[i] and totals->count[i]
* for the first i that matches. To collect the totals without any
* partitioning, set mask[0] and caps[0] both to zero. The allocation totals
* are returned in the 'totals' array of heap_task_totals_t structs. To allow
* easily comparing the totals array between consecutive calls, that array can
* be left populated from one call to the next so the order of tasks is the
* same even if some tasks have freed their blocks or have been deleted. The
* number of blocks prepopulated is given by num_totals, which is updated upon
* return. If there are more tasks with allocations than the capacity of the
* totals array (given by max_totals), information for the excess tasks will be
* not be collected. The totals array pointer can be NULL if the totals are
* not desired.
*
* The 'tasks' array holds a list of handles for tasks whose block details are
* to be returned in the 'blocks' array of heap_task_block_t structs. If the
* tasks array pointer is NULL, block details for all tasks will be returned up
* to the capacity of the buffer array, given by max_blocks. The function
* return value tells the number of blocks filled into the array. The blocks
* array pointer can be NULL if block details are not desired, or max_blocks
* can be set to zero.
*/
typedef struct {
int32_t caps[NUM_HEAP_TASK_CAPS]; ///< Array of caps for partitioning task totals
int32_t mask[NUM_HEAP_TASK_CAPS]; ///< Array of masks under which caps must match
TaskHandle_t *tasks; ///< Array of tasks whose block info is returned
size_t num_tasks; ///< Length of tasks array
heap_task_totals_t *totals; ///< Array of structs to collect task totals
size_t *num_totals; ///< Number of task structs currently in array
size_t max_totals; ///< Capacity of array of task totals structs
heap_task_block_t *blocks; ///< Array of task block details structs
size_t max_blocks; ///< Capacity of array of task block info structs
} heap_task_info_params_t;
/**
* @brief Return per-task heap allocation totals and lists of blocks.
*
* For each task that has allocated memory from the heap, return totals for
* allocations within regions matching one or more sets of capabilities.
*
* Optionally also return an array of structs providing details about each
* block allocated by one or more requested tasks, or by all tasks.
*
* @param params Structure to hold all the parameters for the function
* (@see heap_task_info_params_t).
* @return Number of block detail structs returned (@see heap_task_block_t).
*/
extern size_t heap_caps_get_per_task_info(heap_task_info_params_t *params);
#ifdef __cplusplus
}
#endif
#endif // CONFIG_HEAP_TASK_TRACKING

View File

@@ -0,0 +1,154 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "sdkconfig.h"
#include <stdint.h>
#include <esp_err.h>
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(CONFIG_HEAP_TRACING) && !defined(HEAP_TRACE_SRCFILE)
#warning "esp_heap_trace.h is included but heap tracing is disabled in menuconfig, functions are no-ops"
#endif
#ifndef CONFIG_HEAP_TRACING_STACK_DEPTH
#define CONFIG_HEAP_TRACING_STACK_DEPTH 0
#endif
typedef enum {
HEAP_TRACE_ALL,
HEAP_TRACE_LEAKS,
} heap_trace_mode_t;
/**
* @brief Trace record data type. Stores information about an allocated region of memory.
*/
typedef struct {
uint32_t ccount; ///< CCOUNT of the CPU when the allocation was made. LSB (bit value 1) is the CPU number (0 or 1).
void *address; ///< Address which was allocated
size_t size; ///< Size of the allocation
void *alloced_by[CONFIG_HEAP_TRACING_STACK_DEPTH]; ///< Call stack of the caller which allocated the memory.
void *freed_by[CONFIG_HEAP_TRACING_STACK_DEPTH]; ///< Call stack of the caller which freed the memory (all zero if not freed.)
} heap_trace_record_t;
/**
* @brief Initialise heap tracing in standalone mode.
*
* This function must be called before any other heap tracing functions.
*
* To disable heap tracing and allow the buffer to be freed, stop tracing and then call heap_trace_init_standalone(NULL, 0);
*
* @param record_buffer Provide a buffer to use for heap trace data. Must remain valid any time heap tracing is enabled, meaning
* it must be allocated from internal memory not in PSRAM.
* @param num_records Size of the heap trace buffer, as number of record structures.
* @return
* - ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig.
* - ESP_ERR_INVALID_STATE Heap tracing is currently in progress.
* - ESP_OK Heap tracing initialised successfully.
*/
esp_err_t heap_trace_init_standalone(heap_trace_record_t *record_buffer, size_t num_records);
/**
* @brief Initialise heap tracing in host-based mode.
*
* This function must be called before any other heap tracing functions.
*
* @return
* - ESP_ERR_INVALID_STATE Heap tracing is currently in progress.
* - ESP_OK Heap tracing initialised successfully.
*/
esp_err_t heap_trace_init_tohost(void);
/**
* @brief Start heap tracing. All heap allocations & frees will be traced, until heap_trace_stop() is called.
*
* @note heap_trace_init_standalone() must be called to provide a valid buffer, before this function is called.
*
* @note Calling this function while heap tracing is running will reset the heap trace state and continue tracing.
*
* @param mode Mode for tracing.
* - HEAP_TRACE_ALL means all heap allocations and frees are traced.
* - HEAP_TRACE_LEAKS means only suspected memory leaks are traced. (When memory is freed, the record is removed from the trace buffer.)
* @return
* - ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig.
* - ESP_ERR_INVALID_STATE A non-zero-length buffer has not been set via heap_trace_init_standalone().
* - ESP_OK Tracing is started.
*/
esp_err_t heap_trace_start(heap_trace_mode_t mode);
/**
* @brief Stop heap tracing.
*
* @return
* - ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig.
* - ESP_ERR_INVALID_STATE Heap tracing was not in progress.
* - ESP_OK Heap tracing stopped..
*/
esp_err_t heap_trace_stop(void);
/**
* @brief Resume heap tracing which was previously stopped.
*
* Unlike heap_trace_start(), this function does not clear the
* buffer of any pre-existing trace records.
*
* The heap trace mode is the same as when heap_trace_start() was
* last called (or HEAP_TRACE_ALL if heap_trace_start() was never called).
*
* @return
* - ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig.
* - ESP_ERR_INVALID_STATE Heap tracing was already started.
* - ESP_OK Heap tracing resumed.
*/
esp_err_t heap_trace_resume(void);
/**
* @brief Return number of records in the heap trace buffer
*
* It is safe to call this function while heap tracing is running.
*/
size_t heap_trace_get_count(void);
/**
* @brief Return a raw record from the heap trace buffer
*
* @note It is safe to call this function while heap tracing is running, however in HEAP_TRACE_LEAK mode record indexing may
* skip entries unless heap tracing is stopped first.
*
* @param index Index (zero-based) of the record to return.
* @param[out] record Record where the heap trace record will be copied.
* @return
* - ESP_ERR_NOT_SUPPORTED Project was compiled without heap tracing enabled in menuconfig.
* - ESP_ERR_INVALID_STATE Heap tracing was not initialised.
* - ESP_ERR_INVALID_ARG Index is out of bounds for current heap trace record count.
* - ESP_OK Record returned successfully.
*/
esp_err_t heap_trace_get(size_t index, heap_trace_record_t *record);
/**
* @brief Dump heap trace record data to stdout
*
* @note It is safe to call this function while heap tracing is running, however in HEAP_TRACE_LEAK mode the dump may skip
* entries unless heap tracing is stopped first.
*
*
*/
void heap_trace_dump(void);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,200 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include <sdkconfig.h>
#include "soc/soc_memory_layout.h"
#include "esp_attr.h"
/* Encode the CPU ID in the LSB of the ccount value */
inline static uint32_t get_ccount(void)
{
uint32_t ccount = cpu_hal_get_cycle_count() & ~3;
#ifndef CONFIG_FREERTOS_UNICORE
ccount |= xPortGetCoreID();
#endif
return ccount;
}
/* Architecture-specific return value of __builtin_return_address which
* should be interpreted as an invalid address.
*/
#ifdef __XTENSA__
#define HEAP_ARCH_INVALID_PC 0x40000000
#else
#define HEAP_ARCH_INVALID_PC 0x00000000
#endif
// Caller is 2 stack frames deeper than we care about
#define STACK_OFFSET 2
#define TEST_STACK(N) do { \
if (STACK_DEPTH == N) { \
return; \
} \
callers[N] = __builtin_return_address(N+STACK_OFFSET); \
if (!esp_ptr_executable(callers[N]) \
|| callers[N] == (void*) HEAP_ARCH_INVALID_PC) { \
callers[N] = 0; \
return; \
} \
} while(0)
/* Static function to read the call stack for a traced heap call.
Calls to __builtin_return_address are "unrolled" via TEST_STACK macro as gcc requires the
argument to be a compile-time constant.
*/
static IRAM_ATTR __attribute__((noinline)) void get_call_stack(void **callers)
{
bzero(callers, sizeof(void *) * STACK_DEPTH);
TEST_STACK(0);
TEST_STACK(1);
TEST_STACK(2);
TEST_STACK(3);
TEST_STACK(4);
TEST_STACK(5);
TEST_STACK(6);
TEST_STACK(7);
TEST_STACK(8);
TEST_STACK(9);
}
_Static_assert(STACK_DEPTH >= 0 && STACK_DEPTH <= 10, "CONFIG_HEAP_TRACING_STACK_DEPTH must be in range 0-10");
typedef enum {
TRACE_MALLOC_CAPS,
TRACE_MALLOC_DEFAULT
} trace_malloc_mode_t;
void *__real_heap_caps_malloc(size_t size, uint32_t caps);
void *__real_heap_caps_malloc_default( size_t size );
void *__real_heap_caps_realloc_default( void *ptr, size_t size );
/* trace any 'malloc' event */
static IRAM_ATTR __attribute__((noinline)) void *trace_malloc(size_t size, uint32_t caps, trace_malloc_mode_t mode)
{
uint32_t ccount = get_ccount();
void *p;
if ( mode == TRACE_MALLOC_CAPS ) {
p = __real_heap_caps_malloc(size, caps);
} else { //TRACE_MALLOC_DEFAULT
p = __real_heap_caps_malloc_default(size);
}
heap_trace_record_t rec = {
.address = p,
.ccount = ccount,
.size = size,
};
get_call_stack(rec.alloced_by);
record_allocation(&rec);
return p;
}
void __real_heap_caps_free(void *p);
/* trace any 'free' event */
static IRAM_ATTR __attribute__((noinline)) void trace_free(void *p)
{
void *callers[STACK_DEPTH];
get_call_stack(callers);
record_free(p, callers);
__real_heap_caps_free(p);
}
void * __real_heap_caps_realloc(void *p, size_t size, uint32_t caps);
/* trace any 'realloc' event */
static IRAM_ATTR __attribute__((noinline)) void *trace_realloc(void *p, size_t size, uint32_t caps, trace_malloc_mode_t mode)
{
void *callers[STACK_DEPTH];
uint32_t ccount = get_ccount();
void *r;
/* trace realloc as free-then-alloc */
get_call_stack(callers);
record_free(p, callers);
if (mode == TRACE_MALLOC_CAPS ) {
r = __real_heap_caps_realloc(p, size, caps);
} else { //TRACE_MALLOC_DEFAULT
r = __real_heap_caps_realloc_default(p, size);
}
/* realloc with zero size is a free */
if (size != 0) {
heap_trace_record_t rec = {
.address = r,
.ccount = ccount,
.size = size,
};
memcpy(rec.alloced_by, callers, sizeof(void *) * STACK_DEPTH);
record_allocation(&rec);
}
return r;
}
/* Note: this changes the behaviour of libc malloc/realloc/free a bit,
as they no longer go via the libc functions in ROM. But more or less
the same in the end. */
IRAM_ATTR void *__wrap_malloc(size_t size)
{
return trace_malloc(size, 0, TRACE_MALLOC_DEFAULT);
}
IRAM_ATTR void __wrap_free(void *p)
{
trace_free(p);
}
IRAM_ATTR void *__wrap_realloc(void *p, size_t size)
{
return trace_realloc(p, size, 0, TRACE_MALLOC_DEFAULT);
}
IRAM_ATTR void *__wrap_calloc(size_t nmemb, size_t size)
{
size = size * nmemb;
void *result = trace_malloc(size, 0, TRACE_MALLOC_DEFAULT);
if (result != NULL) {
memset(result, 0, size);
}
return result;
}
IRAM_ATTR void *__wrap_heap_caps_malloc(size_t size, uint32_t caps)
{
return trace_malloc(size, caps, TRACE_MALLOC_CAPS);
}
void __wrap_heap_caps_free(void *p) __attribute__((alias("__wrap_free")));
IRAM_ATTR void *__wrap_heap_caps_realloc(void *p, size_t size, uint32_t caps)
{
return trace_realloc(p, size, caps, TRACE_MALLOC_CAPS);
}
IRAM_ATTR void *__wrap_heap_caps_malloc_default( size_t size )
{
return trace_malloc(size, 0, TRACE_MALLOC_DEFAULT);
}
IRAM_ATTR void *__wrap_heap_caps_realloc_default( void *ptr, size_t size )
{
return trace_realloc(ptr, size, 0, TRACE_MALLOC_DEFAULT);
}

View File

@@ -0,0 +1,190 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
/* multi_heap is a heap implementation for handling multiple
heterogenous heaps in a single program.
Any contiguous block of memory can be registered as a heap.
*/
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Opaque handle to a registered heap */
typedef struct multi_heap_info *multi_heap_handle_t;
/**
* @brief allocate a chunk of memory with specific alignment
*
* @param heap Handle to a registered heap.
* @param size size in bytes of memory chunk
* @param alignment how the memory must be aligned
*
* @return pointer to the memory allocated, NULL on failure
*/
void *multi_heap_aligned_alloc(multi_heap_handle_t heap, size_t size, size_t alignment);
/** @brief malloc() a buffer in a given heap
*
* Semantics are the same as standard malloc(), only the returned buffer will be allocated in the specified heap.
*
* @param heap Handle to a registered heap.
* @param size Size of desired buffer.
*
* @return Pointer to new memory, or NULL if allocation fails.
*/
void *multi_heap_malloc(multi_heap_handle_t heap, size_t size);
/** @brief free() a buffer aligned in a given heap.
*
* @param heap Handle to a registered heap.
* @param p NULL, or a pointer previously returned from multi_heap_aligned_alloc() for the same heap.
* @note This function is deprecated, consider using multi_heap_free() instead
*/
void __attribute__((deprecated)) multi_heap_aligned_free(multi_heap_handle_t heap, void *p);
/** @brief free() a buffer in a given heap.
*
* Semantics are the same as standard free(), only the argument 'p' must be NULL or have been allocated in the specified heap.
*
* @param heap Handle to a registered heap.
* @param p NULL, or a pointer previously returned from multi_heap_malloc() or multi_heap_realloc() for the same heap.
*/
void multi_heap_free(multi_heap_handle_t heap, void *p);
/** @brief realloc() a buffer in a given heap.
*
* Semantics are the same as standard realloc(), only the argument 'p' must be NULL or have been allocated in the specified heap.
*
* @param heap Handle to a registered heap.
* @param p NULL, or a pointer previously returned from multi_heap_malloc() or multi_heap_realloc() for the same heap.
* @param size Desired new size for buffer.
*
* @return New buffer of 'size' containing contents of 'p', or NULL if reallocation failed.
*/
void *multi_heap_realloc(multi_heap_handle_t heap, void *p, size_t size);
/** @brief Return the size that a particular pointer was allocated with.
*
* @param heap Handle to a registered heap.
* @param p Pointer, must have been previously returned from multi_heap_malloc() or multi_heap_realloc() for the same heap.
*
* @return Size of the memory allocated at this block. May be more than the original size argument, due
* to padding and minimum block sizes.
*/
size_t multi_heap_get_allocated_size(multi_heap_handle_t heap, void *p);
/** @brief Register a new heap for use
*
* This function initialises a heap at the specified address, and returns a handle for future heap operations.
*
* There is no equivalent function for deregistering a heap - if all blocks in the heap are free, you can immediately start using the memory for other purposes.
*
* @param start Start address of the memory to use for a new heap.
* @param size Size (in bytes) of the new heap.
*
* @return Handle of a new heap ready for use, or NULL if the heap region was too small to be initialised.
*/
multi_heap_handle_t multi_heap_register(void *start, size_t size);
/** @brief Associate a private lock pointer with a heap
*
* The lock argument is supplied to the MULTI_HEAP_LOCK() and MULTI_HEAP_UNLOCK() macros, defined in multi_heap_platform.h.
*
* The lock in question must be recursive.
*
* When the heap is first registered, the associated lock is NULL.
*
* @param heap Handle to a registered heap.
* @param lock Optional pointer to a locking structure to associate with this heap.
*/
void multi_heap_set_lock(multi_heap_handle_t heap, void* lock);
/** @brief Dump heap information to stdout
*
* For debugging purposes, this function dumps information about every block in the heap to stdout.
*
* @param heap Handle to a registered heap.
*/
void multi_heap_dump(multi_heap_handle_t heap);
/** @brief Check heap integrity
*
* Walks the heap and checks all heap data structures are valid. If any errors are detected, an error-specific message
* can be optionally printed to stderr. Print behaviour can be overriden at compile time by defining
* MULTI_CHECK_FAIL_PRINTF in multi_heap_platform.h.
*
* @param heap Handle to a registered heap.
* @param print_errors If true, errors will be printed to stderr.
* @return true if heap is valid, false otherwise.
*/
bool multi_heap_check(multi_heap_handle_t heap, bool print_errors);
/** @brief Return free heap size
*
* Returns the number of bytes available in the heap.
*
* Equivalent to the total_free_bytes member returned by multi_heap_get_heap_info().
*
* Note that the heap may be fragmented, so the actual maximum size for a single malloc() may be lower. To know this
* size, see the largest_free_block member returned by multi_heap_get_heap_info().
*
* @param heap Handle to a registered heap.
* @return Number of free bytes.
*/
size_t multi_heap_free_size(multi_heap_handle_t heap);
/** @brief Return the lifetime minimum free heap size
*
* Equivalent to the minimum_free_bytes member returned by multi_heap_get_info().
*
* Returns the lifetime "low water mark" of possible values returned from multi_free_heap_size(), for the specified
* heap.
*
* @param heap Handle to a registered heap.
* @return Number of free bytes.
*/
size_t multi_heap_minimum_free_size(multi_heap_handle_t heap);
/** @brief Structure to access heap metadata via multi_heap_get_info */
typedef struct {
size_t total_free_bytes; ///< Total free bytes in the heap. Equivalent to multi_free_heap_size().
size_t total_allocated_bytes; ///< Total bytes allocated to data in the heap.
size_t largest_free_block; ///< Size of largest free block in the heap. This is the largest malloc-able size.
size_t minimum_free_bytes; ///< Lifetime minimum free heap size. Equivalent to multi_minimum_free_heap_size().
size_t allocated_blocks; ///< Number of (variable size) blocks allocated in the heap.
size_t free_blocks; ///< Number of (variable size) free blocks in the heap.
size_t total_blocks; ///< Total number of (variable size) blocks in the heap.
} multi_heap_info_t;
/** @brief Return metadata about a given heap
*
* Fills a multi_heap_info_t structure with information about the specified heap.
*
* @param heap Handle to a registered heap.
* @param info Pointer to a structure to fill with heap metadata.
*/
void multi_heap_get_info(multi_heap_handle_t heap, multi_heap_info_t *info);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,7 @@
[mapping:heap]
archive: libheap.a
entries:
heap_tlsf (noflash)
multi_heap (noflash)
if HEAP_POISONING_DISABLED = n:
multi_heap_poisoning (noflash)

View File

@@ -0,0 +1,376 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/cdefs.h>
#include "heap_tlsf.h"
#include <multi_heap.h>
#include "multi_heap_internal.h"
/* Note: Keep platform-specific parts in this header, this source
file should depend on libc only */
#include "multi_heap_platform.h"
/* Defines compile-time configuration macros */
#include "multi_heap_config.h"
#ifndef MULTI_HEAP_POISONING
/* if no heap poisoning, public API aliases directly to these implementations */
void *multi_heap_malloc(multi_heap_handle_t heap, size_t size)
__attribute__((alias("multi_heap_malloc_impl")));
void *multi_heap_aligned_alloc(multi_heap_handle_t heap, size_t size, size_t alignment)
__attribute__((alias("multi_heap_aligned_alloc_impl")));
void multi_heap_aligned_free(multi_heap_handle_t heap, void *p)
__attribute__((alias("multi_heap_free_impl")));
void multi_heap_free(multi_heap_handle_t heap, void *p)
__attribute__((alias("multi_heap_free_impl")));
void *multi_heap_realloc(multi_heap_handle_t heap, void *p, size_t size)
__attribute__((alias("multi_heap_realloc_impl")));
size_t multi_heap_get_allocated_size(multi_heap_handle_t heap, void *p)
__attribute__((alias("multi_heap_get_allocated_size_impl")));
multi_heap_handle_t multi_heap_register(void *start, size_t size)
__attribute__((alias("multi_heap_register_impl")));
void multi_heap_get_info(multi_heap_handle_t heap, multi_heap_info_t *info)
__attribute__((alias("multi_heap_get_info_impl")));
size_t multi_heap_free_size(multi_heap_handle_t heap)
__attribute__((alias("multi_heap_free_size_impl")));
size_t multi_heap_minimum_free_size(multi_heap_handle_t heap)
__attribute__((alias("multi_heap_minimum_free_size_impl")));
void *multi_heap_get_block_address(multi_heap_block_handle_t block)
__attribute__((alias("multi_heap_get_block_address_impl")));
void *multi_heap_get_block_owner(multi_heap_block_handle_t block)
{
return NULL;
}
#endif
#define ALIGN(X) ((X) & ~(sizeof(void *)-1))
#define ALIGN_UP(X) ALIGN((X)+sizeof(void *)-1)
#define ALIGN_UP_BY(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
typedef struct multi_heap_info {
void *lock;
size_t free_bytes;
size_t minimum_free_bytes;
size_t pool_size;
tlsf_t heap_data;
} heap_t;
/* Return true if this block is free. */
static inline bool is_free(const block_header_t *block)
{
return ((block->size & 0x01) != 0);
}
/* Data size of the block (excludes this block's header) */
static inline size_t block_data_size(const block_header_t *block)
{
return (block->size & ~0x03);
}
/* Check a block is valid for this heap. Used to verify parameters. */
static void assert_valid_block(const heap_t *heap, const block_header_t *block)
{
pool_t pool = tlsf_get_pool(heap->heap_data);
void *ptr = block_to_ptr(block);
MULTI_HEAP_ASSERT((ptr >= pool) &&
(ptr < pool + heap->pool_size),
(uintptr_t)ptr);
}
void *multi_heap_get_block_address_impl(multi_heap_block_handle_t block)
{
void *ptr = block_to_ptr(block);
return (ptr);
}
size_t multi_heap_get_allocated_size_impl(multi_heap_handle_t heap, void *p)
{
return tlsf_block_size(p);
}
multi_heap_handle_t multi_heap_register_impl(void *start_ptr, size_t size)
{
assert(start_ptr);
if(size < (tlsf_size(NULL) + tlsf_block_size_min() + sizeof(heap_t))) {
//Region too small to be a heap.
return NULL;
}
heap_t *result = (heap_t *)start_ptr;
size -= sizeof(heap_t);
result->heap_data = tlsf_create_with_pool(start_ptr + sizeof(heap_t), size, 0);
if(!result->heap_data) {
return NULL;
}
result->lock = NULL;
result->free_bytes = size - tlsf_size(result->heap_data);
result->pool_size = size;
result->minimum_free_bytes = result->free_bytes;
return result;
}
void multi_heap_set_lock(multi_heap_handle_t heap, void *lock)
{
heap->lock = lock;
}
void inline multi_heap_internal_lock(multi_heap_handle_t heap)
{
MULTI_HEAP_LOCK(heap->lock);
}
void inline multi_heap_internal_unlock(multi_heap_handle_t heap)
{
MULTI_HEAP_UNLOCK(heap->lock);
}
multi_heap_block_handle_t multi_heap_get_first_block(multi_heap_handle_t heap)
{
assert(heap != NULL);
pool_t pool = tlsf_get_pool(heap->heap_data);
block_header_t* block = offset_to_block(pool, -(int)block_header_overhead);
return (multi_heap_block_handle_t)block;
}
multi_heap_block_handle_t multi_heap_get_next_block(multi_heap_handle_t heap, multi_heap_block_handle_t block)
{
assert(heap != NULL);
assert_valid_block(heap, block);
block_header_t* next = block_next(block);
if(block_data_size(next) == 0) {
//Last block:
return NULL;
} else {
return (multi_heap_block_handle_t)next;
}
}
bool multi_heap_is_free(multi_heap_block_handle_t block)
{
return is_free(block);
}
void *multi_heap_malloc_impl(multi_heap_handle_t heap, size_t size)
{
if (size == 0 || heap == NULL) {
return NULL;
}
multi_heap_internal_lock(heap);
void *result = tlsf_malloc(heap->heap_data, size);
if(result) {
heap->free_bytes -= tlsf_block_size(result);
if (heap->free_bytes < heap->minimum_free_bytes) {
heap->minimum_free_bytes = heap->free_bytes;
}
}
multi_heap_internal_unlock(heap);
return result;
}
void multi_heap_free_impl(multi_heap_handle_t heap, void *p)
{
if (heap == NULL || p == NULL) {
return;
}
assert_valid_block(heap, p);
multi_heap_internal_lock(heap);
heap->free_bytes += tlsf_block_size(p);
tlsf_free(heap->heap_data, p);
multi_heap_internal_unlock(heap);
}
void *multi_heap_realloc_impl(multi_heap_handle_t heap, void *p, size_t size)
{
assert(heap != NULL);
if (p == NULL) {
return multi_heap_malloc_impl(heap, size);
}
assert_valid_block(heap, p);
if (heap == NULL) {
return NULL;
}
multi_heap_internal_lock(heap);
size_t previous_block_size = tlsf_block_size(p);
void *result = tlsf_realloc(heap->heap_data, p, size);
if(result) {
heap->free_bytes += previous_block_size;
heap->free_bytes -= tlsf_block_size(result);
if (heap->free_bytes < heap->minimum_free_bytes) {
heap->minimum_free_bytes = heap->free_bytes;
}
}
multi_heap_internal_unlock(heap);
return result;
}
void *multi_heap_aligned_alloc_impl_offs(multi_heap_handle_t heap, size_t size, size_t alignment, size_t offset)
{
if(heap == NULL) {
return NULL;
}
if(!size) {
return NULL;
}
//Alignment must be a power of two:
if(((alignment & (alignment - 1)) != 0) ||(!alignment)) {
return NULL;
}
multi_heap_internal_lock(heap);
void *result = tlsf_memalign_offs(heap->heap_data, alignment, size, offset);
if(result) {
heap->free_bytes -= tlsf_block_size(result);
if(heap->free_bytes < heap->minimum_free_bytes) {
heap->minimum_free_bytes = heap->free_bytes;
}
}
multi_heap_internal_unlock(heap);
return result;
}
void *multi_heap_aligned_alloc_impl(multi_heap_handle_t heap, size_t size, size_t alignment)
{
return multi_heap_aligned_alloc_impl_offs(heap, size, alignment, 0);
}
bool multi_heap_check(multi_heap_handle_t heap, bool print_errors)
{
(void)print_errors;
bool valid = true;
assert(heap != NULL);
multi_heap_internal_lock(heap);
if(tlsf_check(heap->heap_data)) {
valid = false;
}
if(tlsf_check_pool(tlsf_get_pool(heap->heap_data))) {
valid = false;
}
multi_heap_internal_unlock(heap);
return valid;
}
static void multi_heap_dump_tlsf(void* ptr, size_t size, int used, void* user)
{
(void)user;
MULTI_HEAP_STDERR_PRINTF("Block %p data, size: %d bytes, Free: %s \n",
(void *)ptr,
size,
used ? "No" : "Yes");
}
void multi_heap_dump(multi_heap_handle_t heap)
{
assert(heap != NULL);
multi_heap_internal_lock(heap);
MULTI_HEAP_STDERR_PRINTF("Showing data for heap: %p \n", (void *)heap);
tlsf_walk_pool(tlsf_get_pool(heap->heap_data), multi_heap_dump_tlsf, NULL);
multi_heap_internal_unlock(heap);
}
size_t multi_heap_free_size_impl(multi_heap_handle_t heap)
{
if (heap == NULL) {
return 0;
}
return heap->free_bytes;
}
size_t multi_heap_minimum_free_size_impl(multi_heap_handle_t heap)
{
if (heap == NULL) {
return 0;
}
return heap->minimum_free_bytes;
}
static void multi_heap_get_info_tlsf(void* ptr, size_t size, int used, void* user)
{
multi_heap_info_t *info = user;
if(used) {
info->allocated_blocks++;
} else {
info->free_blocks++;
if(size > info->largest_free_block ) {
info->largest_free_block = size;
}
}
info->total_blocks++;
}
void multi_heap_get_info_impl(multi_heap_handle_t heap, multi_heap_info_t *info)
{
memset(info, 0, sizeof(multi_heap_info_t));
if (heap == NULL) {
return;
}
multi_heap_internal_lock(heap);
tlsf_walk_pool(tlsf_get_pool(heap->heap_data), multi_heap_get_info_tlsf, info);
info->total_allocated_bytes = (heap->pool_size - tlsf_size(heap->heap_data)) - heap->free_bytes;
info->minimum_free_bytes = heap->minimum_free_bytes;
info->total_free_bytes = heap->free_bytes;
info->largest_free_block = tlsf_fit_size(heap->heap_data, info->largest_free_block);
multi_heap_internal_unlock(heap);
}

View File

@@ -0,0 +1,31 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef ESP_PLATFORM
#include "sdkconfig.h"
#include "soc/soc.h"
#include "soc/soc_caps.h"
#endif
/* Configuration macros for multi-heap */
#ifdef CONFIG_HEAP_POISONING_LIGHT
#define MULTI_HEAP_POISONING
#endif
#ifdef CONFIG_HEAP_POISONING_COMPREHENSIVE
#define MULTI_HEAP_POISONING
#define MULTI_HEAP_POISONING_SLOW
#endif

View File

@@ -0,0 +1,76 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
/* Opaque handle to a heap block */
typedef const struct block_header_t *multi_heap_block_handle_t;
/* Internal definitions for the "implementation" of the multi_heap API,
as defined in multi_heap.c.
If heap poisioning is disabled, these are aliased directly to the public API.
If heap poisoning is enabled, wrapper functions call each of these.
*/
void *multi_heap_malloc_impl(multi_heap_handle_t heap, size_t size);
/* Allocate a memory region of minimum `size` bytes, aligned on `alignment`. */
void *multi_heap_aligned_alloc_impl(multi_heap_handle_t heap, size_t size, size_t alignment);
/* Allocate a memory region of minimum `size` bytes, where memory's `offset` is aligned on `alignment`. */
void *multi_heap_aligned_alloc_impl_offs(multi_heap_handle_t heap, size_t size, size_t alignment, size_t offset);
void multi_heap_free_impl(multi_heap_handle_t heap, void *p);
void *multi_heap_realloc_impl(multi_heap_handle_t heap, void *p, size_t size);
multi_heap_handle_t multi_heap_register_impl(void *start, size_t size);
void multi_heap_get_info_impl(multi_heap_handle_t heap, multi_heap_info_t *info);
size_t multi_heap_free_size_impl(multi_heap_handle_t heap);
size_t multi_heap_minimum_free_size_impl(multi_heap_handle_t heap);
size_t multi_heap_get_allocated_size_impl(multi_heap_handle_t heap, void *p);
void *multi_heap_get_block_address_impl(multi_heap_block_handle_t block);
/* Some internal functions for heap poisoning use */
/* Check an allocated block's poison bytes are correct. Called by multi_heap_check(). */
bool multi_heap_internal_check_block_poisoning(void *start, size_t size, bool is_free, bool print_errors);
/* Fill a region of memory with the free or malloced pattern.
Called when merging blocks, to overwrite the old block header.
*/
void multi_heap_internal_poison_fill_region(void *start, size_t size, bool is_free);
/* Allow heap poisoning to lock/unlock the heap to avoid race conditions
if multi_heap_check() is running concurrently.
*/
void multi_heap_internal_lock(multi_heap_handle_t heap);
void multi_heap_internal_unlock(multi_heap_handle_t heap);
/* Some internal functions for heap debugging code to use */
/* Get the handle to the first (fixed free) block in a heap */
multi_heap_block_handle_t multi_heap_get_first_block(multi_heap_handle_t heap);
/* Get the handle to the next block in a heap, with validation */
multi_heap_block_handle_t multi_heap_get_next_block(multi_heap_handle_t heap, multi_heap_block_handle_t block);
/* Test if a heap block is free */
bool multi_heap_is_free(const multi_heap_block_handle_t block);
/* Get the data address of a heap block */
void *multi_heap_get_block_address(multi_heap_block_handle_t block);
/* Get the owner identification for a heap block */
void *multi_heap_get_block_owner(multi_heap_block_handle_t block);

View File

@@ -0,0 +1,108 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef MULTI_HEAP_FREERTOS
#include "freertos/FreeRTOS.h"
#include "sdkconfig.h"
#include "esp_rom_sys.h"
#if CONFIG_IDF_TARGET_ESP32
#include "esp32/rom/ets_sys.h" // will be removed in idf v5.0
#elif CONFIG_IDF_TARGET_ESP32S2
#include "esp32s2/rom/ets_sys.h"
#endif
#include <assert.h>
typedef portMUX_TYPE multi_heap_lock_t;
/* Because malloc/free can happen inside an ISR context,
we need to use portmux spinlocks here not RTOS mutexes */
#define MULTI_HEAP_LOCK(PLOCK) do { \
if((PLOCK) != NULL) { \
portENTER_CRITICAL((PLOCK)); \
} \
} while(0)
#define MULTI_HEAP_UNLOCK(PLOCK) do { \
if ((PLOCK) != NULL) { \
portEXIT_CRITICAL((PLOCK)); \
} \
} while(0)
#define MULTI_HEAP_LOCK_INIT(PLOCK) do { \
vPortCPUInitializeMutex((PLOCK)); \
} while(0)
#define MULTI_HEAP_LOCK_STATIC_INITIALIZER portMUX_INITIALIZER_UNLOCKED
/* Not safe to use std i/o while in a portmux critical section,
can deadlock, so we use the ROM equivalent functions. */
#define MULTI_HEAP_PRINTF esp_rom_printf
#define MULTI_HEAP_STDERR_PRINTF(MSG, ...) esp_rom_printf(MSG, __VA_ARGS__)
inline static void multi_heap_assert(bool condition, const char *format, int line, intptr_t address)
{
/* Can't use libc assert() here as it calls printf() which can cause another malloc() for a newlib lock.
Also, it's useful to be able to print the memory address where corruption was detected.
*/
#ifndef NDEBUG
if(!condition) {
#ifndef CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT
esp_rom_printf(format, line, address);
#endif // CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT
abort();
}
#else // NDEBUG
(void) condition;
#endif // NDEBUG
}
#define MULTI_HEAP_ASSERT(CONDITION, ADDRESS) \
multi_heap_assert((CONDITION), "CORRUPT HEAP: multi_heap.c:%d detected at 0x%08x\n", \
__LINE__, (intptr_t)(ADDRESS))
#ifdef CONFIG_HEAP_TASK_TRACKING
#include <freertos/task.h>
#define MULTI_HEAP_BLOCK_OWNER TaskHandle_t task;
#define MULTI_HEAP_SET_BLOCK_OWNER(HEAD) (HEAD)->task = xTaskGetCurrentTaskHandle()
#define MULTI_HEAP_GET_BLOCK_OWNER(HEAD) ((HEAD)->task)
#else
#define MULTI_HEAP_BLOCK_OWNER
#define MULTI_HEAP_SET_BLOCK_OWNER(HEAD)
#define MULTI_HEAP_GET_BLOCK_OWNER(HEAD) (NULL)
#endif
#else // MULTI_HEAP_FREERTOS
#include <assert.h>
#define MULTI_HEAP_PRINTF printf
#define MULTI_HEAP_STDERR_PRINTF(MSG, ...) fprintf(stderr, MSG, __VA_ARGS__)
#define MULTI_HEAP_LOCK(PLOCK) (void) (PLOCK)
#define MULTI_HEAP_UNLOCK(PLOCK) (void) (PLOCK)
#define MULTI_HEAP_LOCK_INIT(PLOCK) (void) (PLOCK)
#define MULTI_HEAP_LOCK_STATIC_INITIALIZER 0
#define MULTI_HEAP_ASSERT(CONDITION, ADDRESS) assert((CONDITION) && "Heap corrupt")
#define MULTI_HEAP_BLOCK_OWNER
#define MULTI_HEAP_SET_BLOCK_OWNER(HEAD)
#define MULTI_HEAP_GET_BLOCK_OWNER(HEAD) (NULL)
#endif // MULTI_HEAP_FREERTOS

View File

@@ -0,0 +1,426 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/param.h>
#include <multi_heap.h>
#include "multi_heap_internal.h"
/* Note: Keep platform-specific parts in this header, this source
file should depend on libc only */
#include "multi_heap_platform.h"
/* Defines compile-time configuration macros */
#include "multi_heap_config.h"
#ifdef MULTI_HEAP_POISONING
/* Alias MULTI_HEAP_POISONING_SLOW to SLOW for better readabilty */
#ifdef SLOW
#error "external header has defined SLOW"
#endif
#ifdef MULTI_HEAP_POISONING_SLOW
#define SLOW 1
#endif
#define MALLOC_FILL_PATTERN 0xce
#define FREE_FILL_PATTERN 0xfe
#define HEAD_CANARY_PATTERN 0xABBA1234
#define TAIL_CANARY_PATTERN 0xBAAD5678
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
typedef struct {
uint32_t head_canary;
MULTI_HEAP_BLOCK_OWNER
size_t alloc_size;
} poison_head_t;
typedef struct {
uint32_t tail_canary;
} poison_tail_t;
#define POISON_OVERHEAD (sizeof(poison_head_t) + sizeof(poison_tail_t))
/* Given a "poisoned" region with pre-data header 'head', and actual data size 'alloc_size', fill in the head and tail
region checks.
Returns the pointer to the actual usable data buffer (ie after 'head')
*/
static uint8_t *poison_allocated_region(poison_head_t *head, size_t alloc_size)
{
uint8_t *data = (uint8_t *)(&head[1]); /* start of data ie 'real' allocated buffer */
poison_tail_t *tail = (poison_tail_t *)(data + alloc_size);
head->alloc_size = alloc_size;
head->head_canary = HEAD_CANARY_PATTERN;
MULTI_HEAP_SET_BLOCK_OWNER(head);
uint32_t tail_canary = TAIL_CANARY_PATTERN;
if ((intptr_t)tail % sizeof(void *) == 0) {
tail->tail_canary = tail_canary;
} else {
/* unaligned tail_canary */
memcpy(&tail->tail_canary, &tail_canary, sizeof(uint32_t));
}
return data;
}
/* Given a pointer to some allocated data, check the head & tail poison structures (before & after it) that were
previously injected by poison_allocated_region().
Returns a pointer to the poison header structure, or NULL if the poison structures are corrupt.
*/
static poison_head_t *verify_allocated_region(void *data, bool print_errors)
{
poison_head_t *head = (poison_head_t *)((intptr_t)data - sizeof(poison_head_t));
poison_tail_t *tail = (poison_tail_t *)((intptr_t)data + head->alloc_size);
/* check if the beginning of the data was overwritten */
if (head->head_canary != HEAD_CANARY_PATTERN) {
if (print_errors) {
MULTI_HEAP_STDERR_PRINTF("CORRUPT HEAP: Bad head at %p. Expected 0x%08x got 0x%08x\n", &head->head_canary,
HEAD_CANARY_PATTERN, head->head_canary);
}
return NULL;
}
/* check if the end of the data was overrun */
uint32_t canary;
if ((intptr_t)tail % sizeof(void *) == 0) {
canary = tail->tail_canary;
} else {
/* tail is unaligned */
memcpy(&canary, &tail->tail_canary, sizeof(canary));
}
if (canary != TAIL_CANARY_PATTERN) {
if (print_errors) {
MULTI_HEAP_STDERR_PRINTF("CORRUPT HEAP: Bad tail at %p. Expected 0x%08x got 0x%08x\n", &tail->tail_canary,
TAIL_CANARY_PATTERN, canary);
}
return NULL;
}
return head;
}
#ifdef SLOW
/* Go through a region that should have the specified fill byte 'pattern',
verify it.
if expect_free is true, expect FREE_FILL_PATTERN otherwise MALLOC_FILL_PATTERN.
if swap_pattern is true, swap patterns in the buffer (ie replace MALLOC_FILL_PATTERN with FREE_FILL_PATTERN, and vice versa.)
Returns true if verification checks out.
*/
static bool verify_fill_pattern(void *data, size_t size, bool print_errors, bool expect_free, bool swap_pattern)
{
const uint32_t FREE_FILL_WORD = (FREE_FILL_PATTERN << 24) | (FREE_FILL_PATTERN << 16) | (FREE_FILL_PATTERN << 8) | FREE_FILL_PATTERN;
const uint32_t MALLOC_FILL_WORD = (MALLOC_FILL_PATTERN << 24) | (MALLOC_FILL_PATTERN << 16) | (MALLOC_FILL_PATTERN << 8) | MALLOC_FILL_PATTERN;
const uint32_t EXPECT_WORD = expect_free ? FREE_FILL_WORD : MALLOC_FILL_WORD;
const uint32_t REPLACE_WORD = expect_free ? MALLOC_FILL_WORD : FREE_FILL_WORD;
bool valid = true;
/* Use 4-byte operations as much as possible */
if ((intptr_t)data % 4 == 0) {
uint32_t *p = data;
while (size >= 4) {
if (*p != EXPECT_WORD) {
if (print_errors) {
MULTI_HEAP_STDERR_PRINTF("CORRUPT HEAP: Invalid data at %p. Expected 0x%08x got 0x%08x\n", p, EXPECT_WORD, *p);
}
valid = false;
#ifndef NDEBUG
/* If an assertion is going to fail as soon as we're done verifying the pattern, leave the rest of the
buffer contents as-is for better post-mortem analysis
*/
swap_pattern = false;
#endif
}
if (swap_pattern) {
*p = REPLACE_WORD;
}
p++;
size -= 4;
}
data = p;
}
uint8_t *p = data;
for (size_t i = 0; i < size; i++) {
if (p[i] != (uint8_t)EXPECT_WORD) {
if (print_errors) {
MULTI_HEAP_STDERR_PRINTF("CORRUPT HEAP: Invalid data at %p. Expected 0x%02x got 0x%02x\n", p, (uint8_t)EXPECT_WORD, *p);
}
valid = false;
#ifndef NDEBUG
swap_pattern = false; // same as above
#endif
}
if (swap_pattern) {
p[i] = (uint8_t)REPLACE_WORD;
}
}
return valid;
}
#endif
void *multi_heap_aligned_alloc(multi_heap_handle_t heap, size_t size, size_t alignment)
{
if (!size) {
return NULL;
}
if (size > SIZE_MAX - POISON_OVERHEAD) {
return NULL;
}
multi_heap_internal_lock(heap);
poison_head_t *head = multi_heap_aligned_alloc_impl_offs(heap, size + POISON_OVERHEAD,
alignment, sizeof(poison_head_t));
uint8_t *data = NULL;
if (head != NULL) {
data = poison_allocated_region(head, size);
#ifdef SLOW
/* check everything we got back is FREE_FILL_PATTERN & swap for MALLOC_FILL_PATTERN */
bool ret = verify_fill_pattern(data, size, true, true, true);
assert( ret );
#endif
} else {
multi_heap_internal_unlock(heap);
return NULL;
}
multi_heap_internal_unlock(heap);
return data;
}
void *multi_heap_malloc(multi_heap_handle_t heap, size_t size)
{
if (!size) {
return NULL;
}
if(size > SIZE_MAX - POISON_OVERHEAD) {
return NULL;
}
multi_heap_internal_lock(heap);
poison_head_t *head = multi_heap_malloc_impl(heap, size + POISON_OVERHEAD);
uint8_t *data = NULL;
if (head != NULL) {
data = poison_allocated_region(head, size);
#ifdef SLOW
/* check everything we got back is FREE_FILL_PATTERN & swap for MALLOC_FILL_PATTERN */
bool ret = verify_fill_pattern(data, size, true, true, true);
assert( ret );
#endif
}
multi_heap_internal_unlock(heap);
return data;
}
void multi_heap_free(multi_heap_handle_t heap, void *p)
{
if (p == NULL) {
return;
}
multi_heap_internal_lock(heap);
poison_head_t *head = verify_allocated_region(p, true);
assert(head != NULL);
#ifdef SLOW
/* replace everything with FREE_FILL_PATTERN, including the poison head/tail */
memset(head, FREE_FILL_PATTERN,
head->alloc_size + POISON_OVERHEAD);
#endif
multi_heap_free_impl(heap, head);
multi_heap_internal_unlock(heap);
}
void multi_heap_aligned_free(multi_heap_handle_t heap, void *p)
{
multi_heap_free(heap, p);
}
void *multi_heap_realloc(multi_heap_handle_t heap, void *p, size_t size)
{
poison_head_t *head = NULL;
poison_head_t *new_head;
void *result = NULL;
if(size > SIZE_MAX - POISON_OVERHEAD) {
return NULL;
}
if (p == NULL) {
return multi_heap_malloc(heap, size);
}
if (size == 0) {
multi_heap_free(heap, p);
return NULL;
}
/* p != NULL, size != 0 */
head = verify_allocated_region(p, true);
assert(head != NULL);
multi_heap_internal_lock(heap);
#ifndef SLOW
new_head = multi_heap_realloc_impl(heap, head, size + POISON_OVERHEAD);
if (new_head != NULL) {
/* For "fast" poisoning, we only overwrite the head/tail of the new block so it's safe
to poison, so no problem doing this even if realloc resized in place.
*/
result = poison_allocated_region(new_head, size);
}
#else // SLOW
/* When slow poisoning is enabled, it becomes very fiddly to try and correctly fill memory when resizing in place
(where the buffer may be moved (including to an overlapping address with the old buffer), grown, or shrunk in
place.)
For now we just malloc a new buffer, copy, and free. :|
Note: If this ever changes, multi_heap defrag realloc test should be enabled.
*/
size_t orig_alloc_size = head->alloc_size;
new_head = multi_heap_malloc_impl(heap, size + POISON_OVERHEAD);
if (new_head != NULL) {
result = poison_allocated_region(new_head, size);
memcpy(result, p, MIN(size, orig_alloc_size));
multi_heap_free(heap, p);
}
#endif
multi_heap_internal_unlock(heap);
return result;
}
void *multi_heap_get_block_address(multi_heap_block_handle_t block)
{
char *head = multi_heap_get_block_address_impl(block);
return head + sizeof(poison_head_t);
}
void *multi_heap_get_block_owner(multi_heap_block_handle_t block)
{
return MULTI_HEAP_GET_BLOCK_OWNER((poison_head_t*)multi_heap_get_block_address_impl(block));
}
multi_heap_handle_t multi_heap_register(void *start, size_t size)
{
#ifdef SLOW
if (start != NULL) {
memset(start, FREE_FILL_PATTERN, size);
}
#endif
return multi_heap_register_impl(start, size);
}
static inline void subtract_poison_overhead(size_t *arg) {
if (*arg > POISON_OVERHEAD) {
*arg -= POISON_OVERHEAD;
} else {
*arg = 0;
}
}
size_t multi_heap_get_allocated_size(multi_heap_handle_t heap, void *p)
{
poison_head_t *head = verify_allocated_region(p, true);
assert(head != NULL);
size_t result = multi_heap_get_allocated_size_impl(heap, head);
return result;
}
void multi_heap_get_info(multi_heap_handle_t heap, multi_heap_info_t *info)
{
multi_heap_get_info_impl(heap, info);
/* don't count the heap poison head & tail overhead in the allocated bytes size */
info->total_allocated_bytes -= info->allocated_blocks * POISON_OVERHEAD;
/* trim largest_free_block to account for poison overhead */
subtract_poison_overhead(&info->largest_free_block);
/* similarly, trim total_free_bytes so there's no suggestion that
a block this big may be available. */
subtract_poison_overhead(&info->total_free_bytes);
subtract_poison_overhead(&info->minimum_free_bytes);
}
size_t multi_heap_free_size(multi_heap_handle_t heap)
{
size_t r = multi_heap_free_size_impl(heap);
subtract_poison_overhead(&r);
return r;
}
size_t multi_heap_minimum_free_size(multi_heap_handle_t heap)
{
size_t r = multi_heap_minimum_free_size_impl(heap);
subtract_poison_overhead(&r);
return r;
}
/* Internal hooks used by multi_heap to manage poisoning, while keeping some modularity */
bool multi_heap_internal_check_block_poisoning(void *start, size_t size, bool is_free, bool print_errors)
{
if (is_free) {
#ifdef SLOW
return verify_fill_pattern(start, size, print_errors, true, false);
#else
return true; /* can only verify empty blocks in SLOW mode */
#endif
} else {
void *data = (void *)((intptr_t)start + sizeof(poison_head_t));
poison_head_t *head = verify_allocated_region(data, print_errors);
if (head != NULL && head->alloc_size > size - POISON_OVERHEAD) {
/* block can be bigger than alloc_size, for reasons of alignment & fragmentation,
but block can never be smaller than head->alloc_size... */
if (print_errors) {
MULTI_HEAP_STDERR_PRINTF("CORRUPT HEAP: Size at %p expected <=0x%08x got 0x%08x\n", &head->alloc_size,
size - POISON_OVERHEAD, head->alloc_size);
}
return false;
}
return head != NULL;
}
}
void multi_heap_internal_poison_fill_region(void *start, size_t size, bool is_free)
{
memset(start, is_free ? FREE_FILL_PATTERN : MALLOC_FILL_PATTERN, size);
}
#else // !MULTI_HEAP_POISONING
#ifdef MULTI_HEAP_POISONING_SLOW
#error "MULTI_HEAP_POISONING_SLOW requires MULTI_HEAP_POISONING"
#endif
#endif // MULTI_HEAP_POISONING

View File

@@ -0,0 +1,3 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES cmock test_utils heap)

View File

@@ -0,0 +1,5 @@
#
#Component Makefile
#
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive

View File

@@ -0,0 +1,147 @@
/*
Tests for the capabilities-based memory allocator.
*/
#include <esp_types.h>
#include <stdio.h>
#include "unity.h"
#include "esp_attr.h"
#include "esp_heap_caps.h"
#include "esp_spi_flash.h"
#include <stdlib.h>
#include <sys/param.h>
#include <string.h>
#include <malloc.h>
TEST_CASE("Capabilities aligned allocator test", "[heap]")
{
uint32_t alignments = 0;
printf("[ALIGNED_ALLOC] Allocating from default CAP: \n");
for(;alignments <= 1024; alignments++) {
uint8_t *buf = (uint8_t *)memalign(alignments, (alignments + 137));
if(((alignments & (alignments - 1)) != 0) || (!alignments)) {
TEST_ASSERT( buf == NULL );
//printf("[ALIGNED_ALLOC] alignment: %u is not a power of two, don't allow allocation \n", aligments);
} else {
TEST_ASSERT( buf != NULL );
printf("[ALIGNED_ALLOC] alignment required: %u \n", alignments);
printf("[ALIGNED_ALLOC] address of allocated memory: %p \n\n", (void *)buf);
//Address of obtained block must be aligned with selected value
TEST_ASSERT(((intptr_t)buf & (alignments - 1)) == 0);
//Write some data, if it corrupts memory probably the heap
//canary verification will fail:
memset(buf, 0xA5, (alignments + 137));
free(buf);
}
}
//Alloc from a non permitted area:
uint32_t *not_permitted_buf = (uint32_t *)heap_caps_aligned_alloc(alignments, (alignments + 137), MALLOC_CAP_EXEC | MALLOC_CAP_32BIT);
TEST_ASSERT( not_permitted_buf == NULL );
#if CONFIG_ESP32_SPIRAM_SUPPORT || CONFIG_ESP32S2_SPIRAM_SUPPORT
alignments = 0;
printf("[ALIGNED_ALLOC] Allocating from external memory: \n");
for(;alignments <= 1024 * 1024; alignments++) {
//Now try to take aligned memory from IRAM:
uint8_t *buf = (uint8_t *)heap_caps_aligned_alloc(alignments, 10*1024, MALLOC_CAP_SPIRAM);
if(((alignments & (alignments - 1)) != 0) || (!alignments)) {
TEST_ASSERT( buf == NULL );
//printf("[ALIGNED_ALLOC] alignment: %u is not a power of two, don't allow allocation \n", aligments);
} else {
TEST_ASSERT( buf != NULL );
printf("[ALIGNED_ALLOC] alignment required: %u \n", alignments);
printf("[ALIGNED_ALLOC] address of allocated memory: %p \n\n", (void *)buf);
//Address of obtained block must be aligned with selected value
TEST_ASSERT(((intptr_t)buf & (alignments - 1)) == 0);
//Write some data, if it corrupts memory probably the heap
//canary verification will fail:
memset(buf, 0xA5, (10*1024));
heap_caps_free(buf);
}
}
#endif
}
TEST_CASE("Capabilities aligned calloc test", "[heap]")
{
uint32_t alignments = 0;
printf("[ALIGNED_ALLOC] Allocating from default CAP: \n");
for(;alignments <= 1024; alignments++) {
uint8_t *buf = (uint8_t *)heap_caps_aligned_calloc(alignments, 1, (alignments + 137), MALLOC_CAP_DEFAULT);
if(((alignments & (alignments - 1)) != 0) || (!alignments)) {
TEST_ASSERT( buf == NULL );
//printf("[ALIGNED_ALLOC] alignment: %u is not a power of two, don't allow allocation \n", aligments);
} else {
TEST_ASSERT( buf != NULL );
printf("[ALIGNED_ALLOC] alignment required: %u \n", alignments);
printf("[ALIGNED_ALLOC] address of allocated memory: %p \n\n", (void *)buf);
//Address of obtained block must be aligned with selected value
TEST_ASSERT(((intptr_t)buf & (alignments - 1)) == 0);
//Write some data, if it corrupts memory probably the heap
//canary verification will fail:
memset(buf, 0xA5, (alignments + 137));
heap_caps_free(buf);
}
}
//Check if memory is initialized with zero:
uint8_t byte_array[1024];
memset(&byte_array, 0, sizeof(byte_array));
uint8_t *buf = (uint8_t *)heap_caps_aligned_calloc(1024, 1, 1024, MALLOC_CAP_DEFAULT);
TEST_ASSERT(memcmp(byte_array, buf, sizeof(byte_array)) == 0);
heap_caps_free(buf);
//Same size, but different chunk:
buf = (uint8_t *)heap_caps_aligned_calloc(1024, 1024, 1, MALLOC_CAP_DEFAULT);
TEST_ASSERT(memcmp(byte_array, buf, sizeof(byte_array)) == 0);
heap_caps_free(buf);
//Alloc from a non permitted area:
uint32_t *not_permitted_buf = (uint32_t *)heap_caps_aligned_calloc(alignments, 1, (alignments + 137), MALLOC_CAP_32BIT);
TEST_ASSERT( not_permitted_buf == NULL );
#if CONFIG_ESP32_SPIRAM_SUPPORT || CONFIG_ESP32S2_SPIRAM_SUPPORT
alignments = 0;
printf("[ALIGNED_ALLOC] Allocating from external memory: \n");
for(;alignments <= 1024 * 1024; alignments++) {
//Now try to take aligned memory from IRAM:
uint8_t *buf = (uint8_t *)(uint8_t *)heap_caps_aligned_calloc(alignments, 1, 10*1024, MALLOC_CAP_SPIRAM);
if(((alignments & (alignments - 1)) != 0) || (!alignments)) {
TEST_ASSERT( buf == NULL );
//printf("[ALIGNED_ALLOC] alignment: %u is not a power of two, don't allow allocation \n", aligments);
} else {
TEST_ASSERT( buf != NULL );
printf("[ALIGNED_ALLOC] alignment required: %u \n", alignments);
printf("[ALIGNED_ALLOC] address of allocated memory: %p \n\n", (void *)buf);
//Address of obtained block must be aligned with selected value
TEST_ASSERT(((intptr_t)buf & (alignments - 1)) == 0);
//Write some data, if it corrupts memory probably the heap
//canary verification will fail:
memset(buf, 0xA5, (10*1024));
heap_caps_free(buf);
}
}
#endif
}
TEST_CASE("aligned_alloc(0) should return a NULL pointer", "[heap]")
{
void *p;
p = heap_caps_aligned_alloc(32, 0, MALLOC_CAP_DEFAULT);
TEST_ASSERT(p == NULL);
}

View File

@@ -0,0 +1,108 @@
#include "freertos/FreeRTOS.h"
#include <esp_types.h>
#include <stdio.h>
#include "unity.h"
#include "esp_attr.h"
#include "esp_heap_caps.h"
#include <stdlib.h>
#include <sys/param.h>
#include <string.h>
#include <test_utils.h>
//This test only makes sense with poisoning disabled (light or comprehensive)
#if !defined(CONFIG_HEAP_POISONING_COMPREHENSIVE) && !defined(CONFIG_HEAP_POISONING_LIGHT)
#define NUM_POINTERS 128
#define ITERATIONS 10000
TEST_CASE("Heap many random allocations timings", "[heap]")
{
void *p[NUM_POINTERS] = { 0 };
size_t s[NUM_POINTERS] = { 0 };
uint32_t cycles_before;
uint64_t alloc_time_average = 0;
uint64_t free_time_average = 0;
uint64_t realloc_time_average = 0;
for (int i = 0; i < ITERATIONS; i++) {
uint8_t n = esp_random() % NUM_POINTERS;
if (esp_random() % 4 == 0) {
/* 1 in 4 iterations, try to realloc the buffer instead
of using malloc/free
*/
size_t new_size = esp_random() % 1024;
cycles_before = portGET_RUN_TIME_COUNTER_VALUE();
void *new_p = heap_caps_realloc(p[n], new_size, MALLOC_CAP_DEFAULT);
realloc_time_average = portGET_RUN_TIME_COUNTER_VALUE() - cycles_before;
printf("realloc %p -> %p (%zu -> %zu) time spent cycles: %lld \n", p[n], new_p, s[n], new_size, realloc_time_average);
heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true);
if (new_size == 0 || new_p != NULL) {
p[n] = new_p;
s[n] = new_size;
if (new_size > 0) {
memset(p[n], n, new_size);
}
}
continue;
}
if (p[n] != NULL) {
if (s[n] > 0) {
/* Verify pre-existing contents of p[n] */
uint8_t compare[s[n]];
memset(compare, n, s[n]);
TEST_ASSERT(( memcmp(compare, p[n], s[n]) == 0 ));
}
TEST_ASSERT(heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true));
cycles_before = portGET_RUN_TIME_COUNTER_VALUE();
heap_caps_free(p[n]);
free_time_average = portGET_RUN_TIME_COUNTER_VALUE() - cycles_before;
printf("freed %p (%zu) time spent cycles: %lld\n", p[n], s[n], free_time_average);
if (!heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true)) {
printf("FAILED iteration %d after freeing %p\n", i, p[n]);
heap_caps_dump(MALLOC_CAP_DEFAULT);
TEST_ASSERT(0);
}
}
s[n] = rand() % 1024;
heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true);
cycles_before = portGET_RUN_TIME_COUNTER_VALUE();
p[n] = heap_caps_malloc(s[n], MALLOC_CAP_DEFAULT);
alloc_time_average = portGET_RUN_TIME_COUNTER_VALUE() - cycles_before;
printf("malloc %p (%zu) time spent cycles: %lld \n", p[n], s[n], alloc_time_average);
if (!heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true)) {
printf("FAILED iteration %d after mallocing %p (%zu bytes)\n", i, p[n], s[n]);
heap_caps_dump(MALLOC_CAP_DEFAULT);
TEST_ASSERT(0);
}
if (p[n] != NULL) {
memset(p[n], n, s[n]);
}
}
for (int i = 0; i < NUM_POINTERS; i++) {
cycles_before = portGET_RUN_TIME_COUNTER_VALUE();
heap_caps_free( p[i]);
free_time_average = portGET_RUN_TIME_COUNTER_VALUE() - cycles_before;
if (!heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true)) {
printf("FAILED during cleanup after freeing %p\n", p[i]);
heap_caps_dump(MALLOC_CAP_DEFAULT);
TEST_ASSERT(0);
}
}
TEST_ASSERT(heap_caps_check_integrity(MALLOC_CAP_DEFAULT, true));
}
#endif

View File

@@ -0,0 +1,74 @@
/*
Tests for D/IRAM support in heap capability allocator
*/
#include <esp_types.h>
#include <stdio.h>
#include "unity.h"
#include "esp_heap_caps.h"
#include "soc/soc_memory_layout.h"
#define ALLOC_SZ 1024
static void *malloc_block_diram(uint32_t caps)
{
void *attempts[256] = { 0 }; // Allocate up to 256 ALLOC_SZ blocks to exhaust all non-D/IRAM memory temporarily
int count = 0;
void *result;
while(count < sizeof(attempts)/sizeof(void *)) {
result = heap_caps_malloc(ALLOC_SZ, caps);
TEST_ASSERT_NOT_NULL_MESSAGE(result, "not enough free heap to perform test");
if (esp_ptr_in_diram_dram(result) || esp_ptr_in_diram_iram(result)) {
break;
}
attempts[count] = result;
result = NULL;
count++;
}
for (int i = 0; i < count; i++) {
free(attempts[i]);
}
TEST_ASSERT_NOT_NULL_MESSAGE(result, "not enough D/IRAM memory is free");
return result;
}
TEST_CASE("Allocate D/IRAM as DRAM", "[heap]")
{
uint32_t *dram = malloc_block_diram(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
for (int i = 0; i < ALLOC_SZ / sizeof(uint32_t); i++) {
uint32_t v = i + 0xAAAA;
dram[i] = v;
volatile uint32_t *iram = esp_ptr_diram_dram_to_iram(dram + i);
TEST_ASSERT_EQUAL(v, dram[i]);
TEST_ASSERT_EQUAL(v, *iram);
*iram = UINT32_MAX;
TEST_ASSERT_EQUAL(UINT32_MAX, *iram);
TEST_ASSERT_EQUAL(UINT32_MAX, dram[i]);
}
free(dram);
}
TEST_CASE("Allocate D/IRAM as IRAM", "[heap]")
{
uint32_t *iram = malloc_block_diram(MALLOC_CAP_EXEC);
for (int i = 0; i < ALLOC_SZ / sizeof(uint32_t); i++) {
uint32_t v = i + 0xEEE;
iram[i] = v;
volatile uint32_t *dram = esp_ptr_diram_iram_to_dram(iram + i);
TEST_ASSERT_EQUAL_HEX32(v, iram[i]);
TEST_ASSERT_EQUAL_HEX32(v, *dram);
*dram = UINT32_MAX;
TEST_ASSERT_EQUAL_HEX32(UINT32_MAX, *dram);
TEST_ASSERT_EQUAL_HEX32(UINT32_MAX, iram[i]);
}
free(iram);
}

View File

@@ -0,0 +1,164 @@
/*
Generic test for heap tracing support
Only compiled in if CONFIG_HEAP_TRACING is set
*/
#include <esp_types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sdkconfig.h"
#include "unity.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#ifdef CONFIG_HEAP_TRACING
// only compile in heap tracing tests if tracing is enabled
#include "esp_heap_trace.h"
TEST_CASE("heap trace leak check", "[heap]")
{
heap_trace_record_t recs[8];
heap_trace_init_standalone(recs, 8);
printf("Leak check test\n"); // Print something before trace starts, or stdout allocations skew total counts
fflush(stdout);
heap_trace_start(HEAP_TRACE_LEAKS);
void *a = malloc(64);
memset(a, '3', 64);
void *b = malloc(96);
memset(b, '4', 11);
printf("a.address %p vs %p b.address %p vs %p\n", a, recs[0].address, b, recs[1].address);
heap_trace_dump();
TEST_ASSERT_EQUAL(2, heap_trace_get_count());
heap_trace_record_t trace_a, trace_b;
heap_trace_get(0, &trace_a);
heap_trace_get(1, &trace_b);
printf("trace_a.address %p trace_bb.address %p\n", trace_a.address, trace_b.address);
TEST_ASSERT_EQUAL_PTR(a, trace_a.address);
TEST_ASSERT_EQUAL_PTR(b, trace_b.address);
TEST_ASSERT_EQUAL_PTR(recs[0].address, trace_a.address);
TEST_ASSERT_EQUAL_PTR(recs[1].address, trace_b.address);
free(a);
TEST_ASSERT_EQUAL(1, heap_trace_get_count());
heap_trace_get(0, &trace_b);
TEST_ASSERT_EQUAL_PTR(b, trace_b.address);
/* buffer deletes trace_a when freed,
so trace_b at head of buffer */
TEST_ASSERT_EQUAL_PTR(recs[0].address, trace_b.address);
heap_trace_stop();
}
TEST_CASE("heap trace wrapped buffer check", "[heap]")
{
const size_t N = 8;
heap_trace_record_t recs[N];
heap_trace_init_standalone(recs, N);
heap_trace_start(HEAP_TRACE_LEAKS);
void *ptrs[N+1];
for (int i = 0; i < N+1; i++) {
ptrs[i] = malloc(i*3);
}
// becuase other mallocs happen as part of this control flow,
// we can't guarantee N entries of ptrs[] are in the heap check buffer.
// but we should guarantee at least the last one is
bool saw_last_ptr = false;
for (int i = 0; i < N; i++) {
heap_trace_record_t rec;
heap_trace_get(i, &rec);
if (rec.address == ptrs[N-1]) {
saw_last_ptr = true;
}
}
TEST_ASSERT(saw_last_ptr);
void *other = malloc(6);
heap_trace_dump();
for (int i = 0; i < N+1; i++) {
free(ptrs[i]);
}
heap_trace_dump();
bool saw_other = false;
for (int i = 0; i < heap_trace_get_count(); i++) {
heap_trace_record_t rec;
heap_trace_get(i, &rec);
// none of ptr[]s should be in the heap trace any more
for (int j = 0; j < N+1; j++) {
TEST_ASSERT_NOT_EQUAL(ptrs[j], rec.address);
}
if (rec.address == other) {
saw_other = true;
}
}
// 'other' pointer should be somewhere in the leak dump
TEST_ASSERT(saw_other);
heap_trace_stop();
}
static void print_floats_task(void *ignore)
{
heap_trace_start(HEAP_TRACE_ALL);
char buf[16] = { };
volatile float f = 12.3456;
sprintf(buf, "%.4f", f);
TEST_ASSERT_EQUAL_STRING("12.3456", buf);
heap_trace_stop();
vTaskDelete(NULL);
}
TEST_CASE("can trace allocations made by newlib", "[heap]")
{
const size_t N = 8;
heap_trace_record_t recs[N];
heap_trace_init_standalone(recs, N);
/* Verifying that newlib code performs an allocation is very fiddly:
- Printing a float allocates data associated with the task, but only the
first time a task prints a float of this length. So we do it in a one-shot task
to avoid possibility it already happened.
- If newlib is updated this test may start failing if the printf() implementation
changes. (This version passes for both nano & regular formatting in newlib 2.2.0)
- We also do the tracing in the task so we only capture things directly related to it.
*/
xTaskCreate(print_floats_task, "print_float", 4096, NULL, 5, NULL);
vTaskDelay(10);
/* has to be at least a few as newlib allocates via multiple different function calls */
TEST_ASSERT(heap_trace_get_count() > 3);
}
#endif

View File

@@ -0,0 +1,60 @@
/*
Tests for a leak tag
*/
#include <stdio.h>
#include "unity.h"
#include "esp_heap_caps_init.h"
#include "esp_system.h"
#include <stdlib.h>
static char* check_calloc(int size)
{
char *arr = calloc(size, sizeof(char));
TEST_ASSERT_NOT_NULL(arr);
return arr;
}
TEST_CASE("Check for leaks (no leak)", "[heap]")
{
char *arr = check_calloc(1000);
free(arr);
}
TEST_CASE("Check for leaks (leak)", "[heap][ignore]")
{
check_calloc(1000);
}
TEST_CASE("Not check for leaks", "[heap][leaks]")
{
check_calloc(1000);
}
TEST_CASE("Set a leak level = 7016", "[heap][leaks=7016]")
{
check_calloc(7000);
}
static void test_fn(void)
{
check_calloc(1000);
}
TEST_CASE_MULTIPLE_STAGES("Not check for leaks in MULTIPLE_STAGES mode", "[heap][leaks]", test_fn, test_fn, test_fn);
TEST_CASE_MULTIPLE_STAGES("Check for leaks in MULTIPLE_STAGES mode (leak)", "[heap][ignore]", test_fn, test_fn, test_fn);
static void test_fn2(void)
{
check_calloc(1000);
esp_restart();
}
static void test_fn3(void)
{
check_calloc(1000);
}
TEST_CASE_MULTIPLE_STAGES("Check for leaks in MULTIPLE_STAGES mode (manual reset)", "[heap][leaks][reset=SW_CPU_RESET, SW_CPU_RESET]", test_fn2, test_fn2, test_fn3);

View File

@@ -0,0 +1,134 @@
/*
Generic test for malloc/free
*/
#include <esp_types.h>
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "unity.h"
#include "esp_heap_caps.h"
#include "sdkconfig.h"
static int **allocatedMem;
static int noAllocated;
static int tryAllocMem(void) {
int i, j;
const int allocateMaxK=1024*5; //try to allocate a max of 5MiB
allocatedMem=malloc(sizeof(int *)*allocateMaxK);
if (!allocatedMem) return 0;
for (i=0; i<allocateMaxK; i++) {
allocatedMem[i]=malloc(1024);
if (allocatedMem[i]==NULL) break;
for (j=0; j<1024/4; j++) allocatedMem[i][j]=(0xdeadbeef);
}
noAllocated=i;
return i;
}
static void tryAllocMemFree(void) {
int i, j;
for (i=0; i<noAllocated; i++) {
for (j=0; j<1024/4; j++) {
TEST_ASSERT(allocatedMem[i][j]==(0xdeadbeef));
}
free(allocatedMem[i]);
}
free(allocatedMem);
}
TEST_CASE("Malloc/overwrite, then free all available DRAM", "[heap]")
{
int m1=0, m2=0;
m1=tryAllocMem();
tryAllocMemFree();
m2=tryAllocMem();
tryAllocMemFree();
printf("Could allocate %dK on first try, %dK on 2nd try.\n", m1, m2);
TEST_ASSERT(m1==m2);
}
#if CONFIG_SPIRAM_USE_MALLOC
#if (CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL > 1024)
TEST_CASE("Check if reserved DMA pool still can allocate even when malloc()'ed memory is exhausted", "[heap]")
{
char** dmaMem=malloc(sizeof(char*)*512);
assert(dmaMem);
int m=tryAllocMem();
int i=0;
for (i=0; i<512; i++) {
dmaMem[i]=heap_caps_malloc(1024, MALLOC_CAP_DMA);
if (dmaMem[i]==NULL) break;
}
for (int j=0; j<i; j++) free(dmaMem[j]);
free(dmaMem);
tryAllocMemFree();
printf("Could allocate %dK of DMA memory after allocating all of %dK of normal memory.\n", i, m);
TEST_ASSERT(i);
}
#endif
#endif
/* As you see, we are desperately trying to outsmart the compiler, so that it
* doesn't warn about oversized allocations in the next two unit tests.
* To be removed when we switch to GCC 8.2 and add
* -Wno-alloc-size-larger-than=PTRDIFF_MAX to CFLAGS for this file.
*/
void* (*g_test_malloc_ptr)(size_t) = &malloc;
void* (*g_test_calloc_ptr)(size_t, size_t) = &calloc;
void* test_malloc_wrapper(size_t size)
{
return (*g_test_malloc_ptr)(size);
}
void* test_calloc_wrapper(size_t count, size_t size)
{
return (*g_test_calloc_ptr)(count, size);
}
TEST_CASE("alloc overflows should all fail", "[heap]")
{
/* allocates 8 bytes if size_t overflows */
TEST_ASSERT_NULL(test_calloc_wrapper(SIZE_MAX / 2 + 4, 2));
/* will overflow if any poisoning is enabled
(should fail for sensible OOM reasons, otherwise) */
TEST_ASSERT_NULL(test_malloc_wrapper(SIZE_MAX - 1));
TEST_ASSERT_NULL(test_calloc_wrapper(SIZE_MAX - 1, 1));
/* will overflow when the size is rounded up to word align it */
TEST_ASSERT_NULL(heap_caps_malloc(SIZE_MAX-1, MALLOC_CAP_32BIT));
TEST_ASSERT_NULL(heap_caps_malloc(SIZE_MAX-1, MALLOC_CAP_EXEC));
}
TEST_CASE("unreasonable allocs should all fail", "[heap]")
{
TEST_ASSERT_NULL(test_calloc_wrapper(16, 1024*1024));
TEST_ASSERT_NULL(test_malloc_wrapper(16*1024*1024));
TEST_ASSERT_NULL(test_malloc_wrapper(SIZE_MAX / 2));
TEST_ASSERT_NULL(test_malloc_wrapper(SIZE_MAX - 256));
TEST_ASSERT_NULL(test_malloc_wrapper(xPortGetFreeHeapSize() - 1));
}
TEST_CASE("malloc(0) should return a NULL pointer", "[heap]")
{
void *p;
p = malloc(0);
TEST_ASSERT(p == NULL);
}

View File

@@ -0,0 +1,247 @@
/*
Tests for the capabilities-based memory allocator.
*/
#include <esp_types.h>
#include <stdio.h>
#include "unity.h"
#include "esp_attr.h"
#include "esp_heap_caps.h"
#include "esp_spi_flash.h"
#include <stdlib.h>
#include <sys/param.h>
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
TEST_CASE("Capabilities allocator test", "[heap]")
{
char *m1, *m2[10];
int x;
size_t free8start, free32start, free8, free32;
/* It's important we printf() something before we take the empty heap sizes,
as the first printf() in a task allocates heap resources... */
printf("Testing capabilities allocator...\n");
free8start = heap_caps_get_free_size(MALLOC_CAP_8BIT);
free32start = heap_caps_get_free_size(MALLOC_CAP_32BIT);
printf("Free 8bit-capable memory (start): %dK, 32-bit capable memory %dK\n", free8start, free32start);
TEST_ASSERT(free32start >= free8start);
printf("Allocating 10K of 8-bit capable RAM\n");
m1= heap_caps_malloc(10*1024, MALLOC_CAP_8BIT);
printf("--> %p\n", m1);
free8 = heap_caps_get_free_size(MALLOC_CAP_8BIT);
free32 = heap_caps_get_free_size(MALLOC_CAP_32BIT);
printf("Free 8bit-capable memory (both reduced): %dK, 32-bit capable memory %dK\n", free8, free32);
//Both should have gone down by 10K; 8bit capable ram is also 32-bit capable
TEST_ASSERT(free8<=(free8start-10*1024));
TEST_ASSERT(free32<=(free32start-10*1024));
//Assume we got DRAM back
TEST_ASSERT((((int)m1)&0xFF000000)==0x3F000000);
free(m1);
//The goal here is to allocate from IRAM. Since there is no external IRAM (yet)
//the following gives size of IRAM-only (not D/IRAM) memory.
size_t free_iram = heap_caps_get_free_size(MALLOC_CAP_INTERNAL) -
heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
size_t alloc32 = MIN(free_iram / 2, 10*1024) & (~3);
if(free_iram) {
printf("Freeing; allocating %u bytes of 32K-capable RAM\n", alloc32);
m1 = heap_caps_malloc(alloc32, MALLOC_CAP_32BIT);
printf("--> %p\n", m1);
//Check that we got IRAM back
TEST_ASSERT((((int)m1)&0xFF000000)==0x40000000);
free8 = heap_caps_get_free_size(MALLOC_CAP_8BIT);
free32 = heap_caps_get_free_size(MALLOC_CAP_32BIT);
printf("Free 8bit-capable memory (after 32-bit): %dK, 32-bit capable memory %dK\n", free8, free32);
//Only 32-bit should have gone down by alloc32: 32-bit isn't necessarily 8bit capable
TEST_ASSERT(free32<=(free32start-alloc32));
TEST_ASSERT(free8==free8start);
free(m1);
} else {
printf("This platform has no 32-bit only capable RAM, jumping to next test \n");
}
printf("Allocating impossible caps\n");
m1= heap_caps_malloc(10*1024, MALLOC_CAP_8BIT|MALLOC_CAP_EXEC);
printf("--> %p\n", m1);
TEST_ASSERT(m1==NULL);
if(free_iram) {
printf("Testing changeover iram -> dram");
// priorities will exhaust IRAM first, then start allocating from DRAM
for (x=0; x<10; x++) {
m2[x]= heap_caps_malloc(alloc32, MALLOC_CAP_32BIT);
printf("--> %p\n", m2[x]);
}
TEST_ASSERT((((int)m2[0])&0xFF000000)==0x40000000);
TEST_ASSERT((((int)m2[9])&0xFF000000)==0x3F000000);
} else {
printf("This platform has no IRAM-only so changeover will never occur, jumping to next test\n");
}
printf("Test if allocating executable code still gives IRAM, even with dedicated IRAM region depleted\n");
if(free_iram) {
// (the allocation should come from D/IRAM)
free_iram = heap_caps_get_free_size(MALLOC_CAP_EXEC);
m1= heap_caps_malloc(MIN(free_iram / 2, 10*1024), MALLOC_CAP_EXEC);
printf("--> %p\n", m1);
TEST_ASSERT((((int)m1)&0xFF000000)==0x40000000);
for (x=0; x<10; x++) free(m2[x]);
} else {
// (the allocation should come from D/IRAM)
free_iram = heap_caps_get_free_size(MALLOC_CAP_EXEC);
m1= heap_caps_malloc(MIN(free_iram / 2, 10*1024), MALLOC_CAP_EXEC);
printf("--> %p\n", m1);
TEST_ASSERT((((int)m1)&0xFF000000)==0x40000000);
}
free(m1);
printf("Done.\n");
}
#endif
#ifdef CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY
TEST_CASE("IRAM_8BIT capability test", "[heap]")
{
uint8_t *ptr;
size_t free_size, free_size32, largest_free_size;
/* need to print something as first printf allocates some heap */
printf("IRAM_8BIT capability test\n");
free_size = heap_caps_get_free_size(MALLOC_CAP_IRAM_8BIT);
free_size32 = heap_caps_get_free_size(MALLOC_CAP_32BIT);
largest_free_size = heap_caps_get_largest_free_block(MALLOC_CAP_IRAM_8BIT);
ptr = heap_caps_malloc(largest_free_size, MALLOC_CAP_IRAM_8BIT);
TEST_ASSERT((((int)ptr)&0xFF000000)==0x40000000);
TEST_ASSERT(heap_caps_get_free_size(MALLOC_CAP_IRAM_8BIT) == (free_size - heap_caps_get_allocated_size(ptr)));
TEST_ASSERT(heap_caps_get_free_size(MALLOC_CAP_32BIT) == (free_size32 - heap_caps_get_allocated_size(ptr)));
free(ptr);
}
#endif
TEST_CASE("heap_caps metadata test", "[heap]")
{
/* need to print something as first printf allocates some heap */
printf("heap_caps metadata test\n");
heap_caps_print_heap_info(MALLOC_CAP_8BIT);
multi_heap_info_t original;
heap_caps_get_info(&original, MALLOC_CAP_8BIT);
void *b = heap_caps_malloc(original.largest_free_block, MALLOC_CAP_8BIT);
TEST_ASSERT_NOT_NULL(b);
printf("After allocating %d bytes:\n", original.largest_free_block);
heap_caps_print_heap_info(MALLOC_CAP_8BIT);
multi_heap_info_t after;
heap_caps_get_info(&after, MALLOC_CAP_8BIT);
TEST_ASSERT(after.largest_free_block <= original.largest_free_block);
TEST_ASSERT(after.total_free_bytes <= original.total_free_bytes);
free(b);
heap_caps_get_info(&after, MALLOC_CAP_8BIT);
printf("\n\n After test, heap status:\n");
heap_caps_print_heap_info(MALLOC_CAP_8BIT);
/* Allow some leeway here, because LWIP sometimes allocates up to 144 bytes in the background
as part of timer management.
*/
TEST_ASSERT_INT32_WITHIN(200, after.total_free_bytes, original.total_free_bytes);
TEST_ASSERT_INT32_WITHIN(200, after.largest_free_block, original.largest_free_block);
TEST_ASSERT(after.minimum_free_bytes < original.total_free_bytes);
}
/* Small function runs from IRAM to check that malloc/free/realloc
all work OK when cache is disabled...
*/
static IRAM_ATTR __attribute__((noinline)) bool iram_malloc_test(void)
{
spi_flash_guard_get()->start(); // Disables flash cache
bool result = true;
void *x = heap_caps_malloc(64, MALLOC_CAP_EXEC);
result = result && (x != NULL);
void *y = heap_caps_realloc(x, 32, MALLOC_CAP_EXEC);
result = result && (y != NULL);
heap_caps_free(y);
spi_flash_guard_get()->end(); // Re-enables flash cache
return result;
}
TEST_CASE("heap_caps_xxx functions work with flash cache disabled", "[heap]")
{
TEST_ASSERT( iram_malloc_test() );
}
#ifdef CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS
TEST_CASE("When enabled, allocation operation failure generates an abort", "[heap][reset=abort,SW_CPU_RESET]")
{
const size_t stupid_allocation_size = (128 * 1024 * 1024);
void *ptr = heap_caps_malloc(stupid_allocation_size, MALLOC_CAP_DEFAULT);
(void)ptr;
TEST_FAIL_MESSAGE("should not be reached");
}
#endif
static bool called_user_failed_hook = false;
void heap_caps_alloc_failed_hook(size_t requested_size, uint32_t caps, const char *function_name)
{
printf("%s was called but failed to allocate %d bytes with 0x%X capabilities. \n",function_name, requested_size, caps);
called_user_failed_hook = true;
}
TEST_CASE("user provided alloc failed hook must be called when allocation fails", "[heap]")
{
TEST_ASSERT(heap_caps_register_failed_alloc_callback(heap_caps_alloc_failed_hook) == ESP_OK);
const size_t stupid_allocation_size = (128 * 1024 * 1024);
void *ptr = heap_caps_malloc(stupid_allocation_size, MALLOC_CAP_DEFAULT);
TEST_ASSERT(called_user_failed_hook != false);
called_user_failed_hook = false;
ptr = heap_caps_realloc(ptr, stupid_allocation_size, MALLOC_CAP_DEFAULT);
TEST_ASSERT(called_user_failed_hook != false);
called_user_failed_hook = false;
ptr = heap_caps_aligned_alloc(0x200, stupid_allocation_size, MALLOC_CAP_DEFAULT);
TEST_ASSERT(called_user_failed_hook != false);
(void)ptr;
}
TEST_CASE("allocation with invalid capability should also trigger the alloc failed hook", "[heap]")
{
const size_t allocation_size = 64;
const uint32_t invalid_cap = MALLOC_CAP_INVALID;
TEST_ASSERT(heap_caps_register_failed_alloc_callback(heap_caps_alloc_failed_hook) == ESP_OK);
called_user_failed_hook = false;
void *ptr = heap_caps_malloc(allocation_size, invalid_cap);
TEST_ASSERT(called_user_failed_hook != false);
called_user_failed_hook = false;
ptr = heap_caps_realloc(ptr, allocation_size, invalid_cap);
TEST_ASSERT(called_user_failed_hook != false);
called_user_failed_hook = false;
ptr = heap_caps_aligned_alloc(0x200, allocation_size, invalid_cap);
TEST_ASSERT(called_user_failed_hook != false);
(void)ptr;
}

View File

@@ -0,0 +1,67 @@
/*
Generic test for realloc
*/
#include <stdlib.h>
#include <string.h>
#include "unity.h"
#include "sdkconfig.h"
#include "esp_heap_caps.h"
#include "soc/soc_memory_layout.h"
#ifndef CONFIG_HEAP_POISONING_COMPREHENSIVE
/* (can't realloc in place if comprehensive is enabled) */
TEST_CASE("realloc shrink buffer in place", "[heap]")
{
void *x = malloc(64);
TEST_ASSERT(x);
void *y = realloc(x, 48);
TEST_ASSERT_EQUAL_PTR(x, y);
}
#endif
#ifndef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
TEST_CASE("realloc shrink buffer with EXEC CAPS", "[heap]")
{
const size_t buffer_size = 64;
void *x = heap_caps_malloc(buffer_size, MALLOC_CAP_EXEC);
TEST_ASSERT(x);
void *y = heap_caps_realloc(x, buffer_size - 16, MALLOC_CAP_EXEC);
TEST_ASSERT(y);
//y needs to fall in a compatible memory area of IRAM:
TEST_ASSERT(esp_ptr_executable(y)|| esp_ptr_in_iram(y) || esp_ptr_in_diram_iram(y));
free(y);
}
TEST_CASE("realloc move data to a new heap type", "[heap]")
{
const char *test = "I am some test content to put in the heap";
char buf[64];
memset(buf, 0xEE, 64);
strlcpy(buf, test, 64);
char *a = malloc(64);
memcpy(a, buf, 64);
// move data from 'a' to IRAM
char *b = heap_caps_realloc(a, 64, MALLOC_CAP_EXEC);
TEST_ASSERT_NOT_NULL(b);
TEST_ASSERT_NOT_EQUAL(a, b);
TEST_ASSERT(heap_caps_check_integrity(MALLOC_CAP_INVALID, true));
TEST_ASSERT_EQUAL_HEX32_ARRAY(buf, b, 64 / sizeof(uint32_t));
// Move data back to DRAM
char *c = heap_caps_realloc(b, 48, MALLOC_CAP_8BIT);
TEST_ASSERT_NOT_NULL(c);
TEST_ASSERT_NOT_EQUAL(b, c);
TEST_ASSERT(heap_caps_check_integrity(MALLOC_CAP_INVALID, true));
TEST_ASSERT_EQUAL_HEX8_ARRAY(buf, c, 48);
free(c);
}
#endif

View File

@@ -0,0 +1,72 @@
/*
Tests for registering new heap memory at runtime
*/
#include <stdio.h>
#include "unity.h"
#include "esp_heap_caps_init.h"
#include "esp_system.h"
#include <stdlib.h>
/* NOTE: This is not a well-formed unit test, it leaks memory */
TEST_CASE("Allocate new heap at runtime", "[heap][ignore]")
{
const size_t BUF_SZ = 1000;
const size_t HEAP_OVERHEAD_MAX = 200;
void *buffer = malloc(BUF_SZ);
TEST_ASSERT_NOT_NULL(buffer);
uint32_t before_free = esp_get_free_heap_size();
TEST_ESP_OK( heap_caps_add_region((intptr_t)buffer, (intptr_t)buffer + BUF_SZ) );
uint32_t after_free = esp_get_free_heap_size();
printf("Before %u after %u\n", before_free, after_free);
/* allow for some 'heap overhead' from accounting structures */
TEST_ASSERT(after_free >= before_free + BUF_SZ - HEAP_OVERHEAD_MAX);
}
/* NOTE: This is not a well-formed unit test, it leaks memory and
may fail if run twice in a row without a reset.
*/
TEST_CASE("Allocate new heap with new capability", "[heap][ignore]")
{
const size_t BUF_SZ = 100;
#ifdef CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
const size_t ALLOC_SZ = 32;
#else
const size_t ALLOC_SZ = 64; // More than half of BUF_SZ
#endif
const uint32_t MALLOC_CAP_INVENTED = (1 << 30); /* this must be unused in esp_heap_caps.h */
/* no memory exists to provide this capability */
TEST_ASSERT_NULL( heap_caps_malloc(ALLOC_SZ, MALLOC_CAP_INVENTED) );
void *buffer = malloc(BUF_SZ);
TEST_ASSERT_NOT_NULL(buffer);
uint32_t caps[SOC_MEMORY_TYPE_NO_PRIOS] = { MALLOC_CAP_INVENTED };
TEST_ESP_OK( heap_caps_add_region_with_caps(caps, (intptr_t)buffer, (intptr_t)buffer + BUF_SZ) );
/* ta-da, it's now possible! */
TEST_ASSERT_NOT_NULL( heap_caps_malloc(ALLOC_SZ, MALLOC_CAP_INVENTED) );
}
/* NOTE: This is not a well-formed unit test.
* If run twice without a reset, it will failed.
*/
TEST_CASE("Add .bss memory to heap region runtime", "[heap][ignore]")
{
#define BUF_SZ 1000
#define HEAP_OVERHEAD_MAX 200
static uint8_t s_buffer[BUF_SZ];
printf("s_buffer start %08x end %08x\n", (intptr_t)s_buffer, (intptr_t)s_buffer + BUF_SZ);
uint32_t before_free = esp_get_free_heap_size();
TEST_ESP_OK( heap_caps_add_region((intptr_t)s_buffer, (intptr_t)s_buffer + BUF_SZ) );
uint32_t after_free = esp_get_free_heap_size();
printf("Before %u after %u\n", before_free, after_free);
/* allow for some 'heap overhead' from accounting structures */
TEST_ASSERT(after_free >= before_free + BUF_SZ - HEAP_OVERHEAD_MAX);
/* Twice add must be failed */
TEST_ASSERT( (heap_caps_add_region((intptr_t)s_buffer, (intptr_t)s_buffer + BUF_SZ) != ESP_OK) );
}

View File

@@ -0,0 +1,54 @@
TEST_PROGRAM=test_multi_heap
all: $(TEST_PROGRAM)
ifneq ($(filter clean,$(MAKECMDGOALS)),)
.NOTPARALLEL: # prevent make clean racing the other targets
endif
SOURCE_FILES = $(abspath \
../multi_heap.c \
../heap_tlsf.c \
../multi_heap_poisoning.c \
test_multi_heap.cpp \
main.cpp \
)
INCLUDE_FLAGS = -I../include -I../../../tools/catch
GCOV ?= gcov
CPPFLAGS += $(INCLUDE_FLAGS) -D CONFIG_LOG_DEFAULT_LEVEL -g -fstack-protector-all -m32 -DCONFIG_HEAP_POISONING_COMPREHENSIVE
CFLAGS += -Wall -Werror -fprofile-arcs -ftest-coverage
CXXFLAGS += -std=c++11 -Wall -Werror -fprofile-arcs -ftest-coverage
LDFLAGS += -lstdc++ -fprofile-arcs -ftest-coverage -m32
OBJ_FILES = $(filter %.o, $(SOURCE_FILES:.cpp=.o) $(SOURCE_FILES:.c=.o))
COVERAGE_FILES = $(OBJ_FILES:.o=.gc*)
$(TEST_PROGRAM): $(OBJ_FILES)
g++ $(LDFLAGS) -o $(TEST_PROGRAM) $(OBJ_FILES)
$(OUTPUT_DIR):
mkdir -p $(OUTPUT_DIR)
test: $(TEST_PROGRAM)
./$(TEST_PROGRAM)
$(COVERAGE_FILES): $(TEST_PROGRAM) test
coverage.info: $(COVERAGE_FILES)
find ../ -name "*.gcno" -exec $(GCOV) -r -pb {} +
lcov --capture --directory $(abspath ../) --no-external --output-file coverage.info --gcov-tool $(GCOV)
coverage_report: coverage.info
genhtml coverage.info --output-directory coverage_report
@echo "Coverage report is in coverage_report/index.html"
clean:
rm -f $(OBJ_FILES) $(TEST_PROGRAM)
rm -f $(COVERAGE_FILES) *.gcov
rm -rf coverage_report/
rm -f coverage.info
.PHONY: clean all test

View File

@@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
#
# Run the test suite with all configurations enabled
#
FAIL=0
for FLAGS in "CONFIG_HEAP_POISONING_NONE" "CONFIG_HEAP_POISONING_LIGHT" "CONFIG_HEAP_POISONING_COMPREHENSIVE" ; do
echo "==== Testing with config: ${FLAGS} ===="
CPPFLAGS="-D${FLAGS}" make clean test || FAIL=1
done
make clean
if [ $FAIL == 0 ]; then
echo "All configurations passed"
else
echo "Some configurations failed, see log."
exit 1
fi

View File

@@ -0,0 +1,508 @@
#include "catch.hpp"
#include "multi_heap.h"
#include "../multi_heap_config.h"
#include <string.h>
#include <assert.h>
static void *__malloc__(size_t bytes)
{
return malloc(bytes);
}
static void __free__(void *ptr)
{
free(ptr);
}
/* Insurance against accidentally using libc heap functions in tests */
#undef free
#define free #error
#undef malloc
#define malloc #error
#undef calloc
#define calloc #error
#undef realloc
#define realloc #error
TEST_CASE("multi_heap simple allocations", "[multi_heap]")
{
uint8_t small_heap[4 * 1024];
multi_heap_handle_t heap = multi_heap_register(small_heap, sizeof(small_heap));
size_t test_alloc_size = (multi_heap_free_size(heap) + 4) / 2;
printf("New heap:\n");
multi_heap_dump(heap);
printf("*********************\n");
uint8_t *buf = (uint8_t *)multi_heap_malloc(heap, test_alloc_size);
printf("small_heap %p buf %p\n", small_heap, buf);
REQUIRE( buf != NULL );
REQUIRE((intptr_t)buf >= (intptr_t)small_heap);
REQUIRE( (intptr_t)buf < (intptr_t)(small_heap + sizeof(small_heap)));
REQUIRE( multi_heap_get_allocated_size(heap, buf) >= test_alloc_size );
REQUIRE( multi_heap_get_allocated_size(heap, buf) < test_alloc_size + 16);
memset(buf, 0xEE, test_alloc_size);
REQUIRE( multi_heap_malloc(heap, test_alloc_size) == NULL );
multi_heap_free(heap, buf);
printf("Empty?\n");
multi_heap_dump(heap);
printf("*********************\n");
/* Now there should be space for another allocation */
buf = (uint8_t *)multi_heap_malloc(heap, test_alloc_size);
REQUIRE( buf != NULL );
multi_heap_free(heap, buf);
REQUIRE( multi_heap_free_size(heap) > multi_heap_minimum_free_size(heap) );
}
TEST_CASE("multi_heap fragmentation", "[multi_heap]")
{
uint8_t small_heap[4 * 1024];
multi_heap_handle_t heap = multi_heap_register(small_heap, sizeof(small_heap));
const size_t alloc_size = 128;
void *p[4];
for (int i = 0; i < 4; i++) {
multi_heap_dump(heap);
REQUIRE( multi_heap_check(heap, true) );
p[i] = multi_heap_malloc(heap, alloc_size);
printf("%d = %p ****->\n", i, p[i]);
multi_heap_dump(heap);
REQUIRE( p[i] != NULL );
}
printf("allocated %p %p %p %p\n", p[0], p[1], p[2], p[3]);
REQUIRE( multi_heap_malloc(heap, alloc_size * 5) == NULL ); /* no room to allocate 5*alloc_size now */
printf("4 allocations:\n");
multi_heap_dump(heap);
printf("****************\n");
multi_heap_free(heap, p[0]);
multi_heap_free(heap, p[1]);
multi_heap_free(heap, p[3]);
printf("1 allocations:\n");
multi_heap_dump(heap);
printf("****************\n");
void *big = multi_heap_malloc(heap, alloc_size * 3);
//Blocks in TLSF are organized in different form, so this makes no sense
multi_heap_free(heap, big);
multi_heap_free(heap, p[2]);
printf("0 allocations:\n");
multi_heap_dump(heap);
printf("****************\n");
big = multi_heap_malloc(heap, alloc_size * 2);
//Blocks in TLSF are organized in different form, so this makes no sense
multi_heap_free(heap, big);
}
/* Test that malloc/free does not leave free space fragmented */
TEST_CASE("multi_heap defrag", "[multi_heap]")
{
void *p[4];
uint8_t small_heap[4 * 1024];
multi_heap_info_t info, info2;
multi_heap_handle_t heap = multi_heap_register(small_heap, sizeof(small_heap));
printf("0 ---\n");
multi_heap_dump(heap);
REQUIRE( multi_heap_check(heap, true) );
multi_heap_get_info(heap, &info);
REQUIRE( 0 == info.allocated_blocks );
REQUIRE( 1 == info.free_blocks );
printf("1 ---\n");
p[0] = multi_heap_malloc(heap, 128);
p[1] = multi_heap_malloc(heap, 32);
multi_heap_dump(heap);
REQUIRE( multi_heap_check(heap, true) );
printf("2 ---\n");
multi_heap_free(heap, p[0]);
p[2] = multi_heap_malloc(heap, 64);
multi_heap_dump(heap);
REQUIRE( p[2] == p[0] );
REQUIRE( multi_heap_check(heap, true) );
printf("3 ---\n");
multi_heap_free(heap, p[2]);
p[3] = multi_heap_malloc(heap, 32);
multi_heap_dump(heap);
REQUIRE( p[3] == p[0] );
REQUIRE( multi_heap_check(heap, true) );
multi_heap_get_info(heap, &info2);
REQUIRE( 2 == info2.allocated_blocks );
REQUIRE( 2 == info2.free_blocks );
multi_heap_free(heap, p[0]);
multi_heap_free(heap, p[1]);
multi_heap_get_info(heap, &info2);
REQUIRE( 0 == info2.allocated_blocks );
REQUIRE( 1 == info2.free_blocks );
REQUIRE( info.total_free_bytes == info2.total_free_bytes );
}
/* Test that malloc/free does not leave free space fragmented
Note: With fancy poisoning, realloc is implemented as malloc-copy-free and this test does not apply.
*/
#ifndef MULTI_HEAP_POISONING_SLOW
TEST_CASE("multi_heap defrag realloc", "[multi_heap]")
{
void *p[4];
uint8_t small_heap[4 * 1024];
multi_heap_info_t info, info2;
multi_heap_handle_t heap = multi_heap_register(small_heap, sizeof(small_heap));
printf("0 ---\n");
multi_heap_dump(heap);
REQUIRE( multi_heap_check(heap, true) );
multi_heap_get_info(heap, &info);
REQUIRE( 0 == info.allocated_blocks );
REQUIRE( 1 == info.free_blocks );
printf("1 ---\n");
p[0] = multi_heap_malloc(heap, 128);
p[1] = multi_heap_malloc(heap, 32);
multi_heap_dump(heap);
REQUIRE( multi_heap_check(heap, true) );
printf("2 ---\n");
p[2] = multi_heap_realloc(heap, p[0], 64);
multi_heap_dump(heap);
REQUIRE( p[2] == p[0] );
REQUIRE( multi_heap_check(heap, true) );
printf("3 ---\n");
p[3] = multi_heap_realloc(heap, p[2], 32);
multi_heap_dump(heap);
REQUIRE( p[3] == p[0] );
REQUIRE( multi_heap_check(heap, true) );
multi_heap_get_info(heap, &info2);
REQUIRE( 2 == info2.allocated_blocks );
REQUIRE( 2 == info2.free_blocks );
multi_heap_free(heap, p[0]);
multi_heap_free(heap, p[1]);
multi_heap_get_info(heap, &info2);
REQUIRE( 0 == info2.allocated_blocks );
REQUIRE( 1 == info2.free_blocks );
REQUIRE( info.total_free_bytes == info2.total_free_bytes );
}
#endif
void multi_heap_allocation_impl(int heap_size)
{
uint8_t *big_heap = (uint8_t *) __malloc__(2*heap_size);
const int NUM_POINTERS = 64;
printf("Running multi-allocation test with heap_size %d...\n", heap_size);
REQUIRE( big_heap );
multi_heap_handle_t heap = multi_heap_register(big_heap, heap_size);
void *p[NUM_POINTERS] = { 0 };
size_t s[NUM_POINTERS] = { 0 };
const size_t initial_free = multi_heap_free_size(heap);
const int ITERATIONS = 10000;
for (int i = 0; i < ITERATIONS; i++) {
/* check all pointers allocated so far are valid inside big_heap */
for (int j = 0; j < NUM_POINTERS; j++) {
if (p[j] != NULL) {
}
}
uint8_t n = rand() % NUM_POINTERS;
if (rand() % 4 == 0) {
/* 1 in 4 iterations, try to realloc the buffer instead
of using malloc/free
*/
size_t new_size = rand() % 1024;
void *new_p = multi_heap_realloc(heap, p[n], new_size);
printf("realloc %p -> %p (%zu -> %zu)\n", p[n], new_p, s[n], new_size);
multi_heap_check(heap, true);
if (new_size == 0 || new_p != NULL) {
p[n] = new_p;
s[n] = new_size;
if (new_size > 0) {
REQUIRE( p[n] >= big_heap );
REQUIRE( p[n] < big_heap + heap_size );
memset(p[n], n, new_size);
}
}
continue;
}
if (p[n] != NULL) {
if (s[n] > 0) {
/* Verify pre-existing contents of p[n] */
uint8_t compare[s[n]];
memset(compare, n, s[n]);
/*REQUIRE*/assert( memcmp(compare, p[n], s[n]) == 0 );
}
REQUIRE( multi_heap_check(heap, true) );
multi_heap_free(heap, p[n]);
printf("freed %p (%zu)\n", p[n], s[n]);
if (!multi_heap_check(heap, true)) {
printf("FAILED iteration %d after freeing %p\n", i, p[n]);
multi_heap_dump(heap);
REQUIRE(0);
}
}
s[n] = rand() % 1024;
REQUIRE( multi_heap_check(heap, true) );
p[n] = multi_heap_malloc(heap, s[n]);
printf("malloc %p (%zu)\n", p[n], s[n]);
if (p[n] != NULL) {
REQUIRE( p[n] >= big_heap );
REQUIRE( p[n] < big_heap + heap_size );
}
if (!multi_heap_check(heap, true)) {
printf("FAILED iteration %d after mallocing %p (%zu bytes)\n", i, p[n], s[n]);
multi_heap_dump(heap);
REQUIRE(0);
}
if (p[n] != NULL) {
memset(p[n], n, s[n]);
}
}
for (int i = 0; i < NUM_POINTERS; i++) {
multi_heap_free(heap, p[i]);
if (!multi_heap_check(heap, true)) {
printf("FAILED during cleanup after freeing %p\n", p[i]);
multi_heap_dump(heap);
REQUIRE(0);
}
}
REQUIRE( initial_free == multi_heap_free_size(heap) );
__free__(big_heap);
}
TEST_CASE("multi_heap many random allocations", "[multi_heap]")
{
size_t poolsize[] = { 15, 255, 4095, 8191 };
for (size_t i = 0; i < sizeof(poolsize)/sizeof(size_t); i++) {
multi_heap_allocation_impl(poolsize[i] * 1024);
}
}
TEST_CASE("multi_heap_get_info() function", "[multi_heap]")
{
uint8_t heapdata[4 * 1024];
multi_heap_handle_t heap = multi_heap_register(heapdata, sizeof(heapdata));
multi_heap_info_t before, after, freed;
multi_heap_get_info(heap, &before);
printf("before: total_free_bytes %zu\ntotal_allocated_bytes %zu\nlargest_free_block %zu\nminimum_free_bytes %zu\nallocated_blocks %zu\nfree_blocks %zu\ntotal_blocks %zu\n",
before.total_free_bytes,
before.total_allocated_bytes,
before.largest_free_block,
before.minimum_free_bytes,
before.allocated_blocks,
before.free_blocks,
before.total_blocks);
REQUIRE( 0 == before.allocated_blocks );
REQUIRE( 0 == before.total_allocated_bytes );
REQUIRE( before.total_free_bytes == before.minimum_free_bytes );
void *x = multi_heap_malloc(heap, 32);
multi_heap_get_info(heap, &after);
printf("after: total_free_bytes %zu\ntotal_allocated_bytes %zu\nlargest_free_block %zu\nminimum_free_bytes %zu\nallocated_blocks %zu\nfree_blocks %zu\ntotal_blocks %zu\n",
after.total_free_bytes,
after.total_allocated_bytes,
after.largest_free_block,
after.minimum_free_bytes,
after.allocated_blocks,
after.free_blocks,
after.total_blocks);
REQUIRE( 1 == after.allocated_blocks );
REQUIRE( 32 == after.total_allocated_bytes );
REQUIRE( after.minimum_free_bytes < before.minimum_free_bytes);
REQUIRE( after.minimum_free_bytes > 0 );
multi_heap_free(heap, x);
multi_heap_get_info(heap, &freed);
printf("freed: total_free_bytes %zu\ntotal_allocated_bytes %zu\nlargest_free_block %zu\nminimum_free_bytes %zu\nallocated_blocks %zu\nfree_blocks %zu\ntotal_blocks %zu\n",
freed.total_free_bytes,
freed.total_allocated_bytes,
freed.largest_free_block,
freed.minimum_free_bytes,
freed.allocated_blocks,
freed.free_blocks,
freed.total_blocks);
REQUIRE( 0 == freed.allocated_blocks );
REQUIRE( 0 == freed.total_allocated_bytes );
REQUIRE( before.total_free_bytes == freed.total_free_bytes );
REQUIRE( after.minimum_free_bytes == freed.minimum_free_bytes );
}
TEST_CASE("multi_heap minimum-size allocations", "[multi_heap]")
{
uint8_t heapdata[4096];
void *p[sizeof(heapdata) / sizeof(void *)] = {NULL};
const size_t NUM_P = sizeof(p) / sizeof(void *);
size_t allocated_size = 0;
multi_heap_handle_t heap = multi_heap_register(heapdata, sizeof(heapdata));
size_t before_free = multi_heap_free_size(heap);
size_t i;
for (i = 0; i < NUM_P; i++) {
//TLSF minimum block size is 4 bytes
p[i] = multi_heap_malloc(heap, 1);
if (p[i] == NULL) {
break;
}
}
REQUIRE( i < NUM_P); // Should have run out of heap before we ran out of pointers
printf("Allocated %zu minimum size chunks\n", i);
REQUIRE(multi_heap_free_size(heap) < before_free);
multi_heap_check(heap, true);
/* Free in random order */
bool has_allocations = true;
while (has_allocations) {
i = rand() % NUM_P;
multi_heap_free(heap, p[i]);
p[i] = NULL;
multi_heap_check(heap, true);
has_allocations = false;
for (i = 0; i < NUM_P && !has_allocations; i++) {
has_allocations = (p[i] != NULL);
}
}
/* all freed! */
REQUIRE( before_free == multi_heap_free_size(heap) );
}
TEST_CASE("multi_heap_realloc()", "[multi_heap]")
{
const uint32_t PATTERN = 0xABABDADA;
uint8_t small_heap[4 * 1024];
multi_heap_handle_t heap = multi_heap_register(small_heap, sizeof(small_heap));
uint32_t *a = (uint32_t *)multi_heap_malloc(heap, 64);
uint32_t *b = (uint32_t *)multi_heap_malloc(heap, 32);
REQUIRE( a != NULL );
REQUIRE( b != NULL );
REQUIRE( b > a); /* 'b' takes the block after 'a' */
*a = PATTERN;
uint32_t *c = (uint32_t *)multi_heap_realloc(heap, a, 72);
REQUIRE( multi_heap_check(heap, true));
REQUIRE( c != NULL );
REQUIRE( c > b ); /* 'a' moves, 'c' takes the block after 'b' */
REQUIRE( *c == PATTERN );
#ifndef MULTI_HEAP_POISONING_SLOW
// "Slow" poisoning implementation doesn't reallocate in place, so these
// test will fail...
uint32_t *d = (uint32_t *)multi_heap_realloc(heap, c, 36);
REQUIRE( multi_heap_check(heap, true) );
REQUIRE( c == d ); /* 'c' block should be shrunk in-place */
REQUIRE( *d == PATTERN);
uint32_t *e = (uint32_t *)multi_heap_malloc(heap, 64);
REQUIRE( multi_heap_check(heap, true));
REQUIRE( a == e ); /* 'e' takes the block formerly occupied by 'a' */
multi_heap_free(heap, d);
uint32_t *f = (uint32_t *)multi_heap_realloc(heap, b, 64);
REQUIRE( multi_heap_check(heap, true) );
REQUIRE( f == b ); /* 'b' should be extended in-place, over space formerly occupied by 'd' */
#ifdef MULTI_HEAP_POISONING
#define TOO_MUCH 7420 + 1
#else
#define TOO_MUCH 7420 + 1
#endif
/* not enough contiguous space left in the heap */
uint32_t *g = (uint32_t *)multi_heap_realloc(heap, e, TOO_MUCH);
REQUIRE( g == NULL );
multi_heap_free(heap, f);
/* try again */
g = (uint32_t *)multi_heap_realloc(heap, e, 128);
REQUIRE( multi_heap_check(heap, true) );
REQUIRE( e == g ); /* 'g' extends 'e' in place, into the space formerly held by 'f' */
#endif
}
// TLSF only accepts heaps aligned to 4-byte boundary so
// only aligned allocation tests make sense.
TEST_CASE("multi_heap aligned allocations", "[multi_heap]")
{
uint8_t test_heap[4 * 1024];
multi_heap_handle_t heap = multi_heap_register(test_heap, sizeof(test_heap));
uint32_t aligments = 0; // starts from alignment by 4-byte boundary
size_t old_size = multi_heap_free_size(heap);
size_t leakage = 1024;
printf("[ALIGNED_ALLOC] heap_size before: %d \n", old_size);
printf("New heap:\n");
multi_heap_dump(heap);
printf("*********************\n");
for(;aligments <= 256; aligments++) {
//Use some stupid size value to test correct alignment even in strange
//memory layout objects:
uint8_t *buf = (uint8_t *)multi_heap_aligned_alloc(heap, (aligments + 137), aligments );
if(((aligments & (aligments - 1)) != 0) || (!aligments)) {
REQUIRE( buf == NULL );
} else {
REQUIRE( buf != NULL );
REQUIRE((intptr_t)buf >= (intptr_t)test_heap);
REQUIRE((intptr_t)buf < (intptr_t)(test_heap + sizeof(test_heap)));
printf("[ALIGNED_ALLOC] alignment required: %u \n", aligments);
printf("[ALIGNED_ALLOC] address of allocated memory: %p \n\n", (void *)buf);
//Address of obtained block must be aligned with selected value
REQUIRE(((intptr_t)buf & (aligments - 1)) == 0);
//Write some data, if it corrupts memory probably the heap
//canary verification will fail:
memset(buf, 0xA5, (aligments + 137));
multi_heap_free(heap, buf);
}
}
printf("[ALIGNED_ALLOC] heap_size after: %d \n", multi_heap_free_size(heap));
REQUIRE((old_size - multi_heap_free_size(heap)) <= leakage);
}

View File

@@ -1,6 +1,6 @@
idf_component_register( SRC_DIRS .
INCLUDE_DIRS .
PRIV_REQUIRES tools newlib console esp_common freertos
PRIV_REQUIRES tools newlib console esp_common freertos tools
REQUIRES nvs_flash json
)

View File

@@ -1,4 +1,3 @@
//#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
#include "nvs_utilities.h"
#include <stdio.h>
@@ -15,6 +14,7 @@
#include "nvs_flash.h"
#include "nvs_utilities.h"
#include "platform_config.h"
#include "tools.h"
const char current_namespace[] = "config";
const char settings_partition[] = "settings";
@@ -69,6 +69,11 @@ const char *type_to_str(nvs_type_t type)
return "Unknown";
}
void erase_settings_partition(){
ESP_LOGW(TAG, "Erasing nvs on partition %s",settings_partition);
ESP_ERROR_CHECK(nvs_flash_erase_partition(settings_partition));
nvs_flash_init_partition(settings_partition);
}
void initialize_nvs() {
ESP_LOGI(TAG, "Initializing flash nvs ");
esp_err_t err = nvs_flash_init();
@@ -95,62 +100,89 @@ void initialize_nvs() {
ESP_LOGD(TAG, "nvs init completed");
}
esp_err_t nvs_load_config(){
nvs_entry_info_t info;
esp_err_t err = ESP_OK;
size_t malloc_int = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
size_t malloc_spiram = heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
esp_err_t nvs_load_config() {
nvs_entry_info_t info;
esp_err_t err = ESP_OK;
size_t malloc_int = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
size_t malloc_spiram = heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
nvs_iterator_t it = nvs_entry_find(settings_partition, NULL, NVS_TYPE_ANY);
if(it == NULL) {
ESP_LOGW(TAG, "empty nvs partition %s, namespace %s",settings_partition,current_namespace );
}
while (it != NULL) {
nvs_entry_info(it, &info);
nvs_iterator_t it = nvs_entry_find(settings_partition, NULL, NVS_TYPE_ANY);
if (it == NULL) {
ESP_LOGW(TAG, "empty nvs partition %s, namespace %s", settings_partition, current_namespace);
}
while (it != NULL) {
nvs_entry_info(it, &info);
if(strstr(info.namespace_name, current_namespace)) {
void * value = get_nvs_value_alloc(info.type,info.key);
if(value==NULL)
{
ESP_LOGE(TAG, "nvs read failed.");
return ESP_FAIL;
if (strstr(info.namespace_name, current_namespace)) {
if (strlen(info.key) == 0) {
ESP_LOGW(TAG, "empty key name in namespace %s. Removing it.", current_namespace);
nvs_handle_t nvs_handle;
err = nvs_open(settings_partition, NVS_READWRITE, &nvs_handle);
if (err != ESP_OK) {
ESP_LOGE(TAG, "nvs_open failed. %s", esp_err_to_name(err));
} else {
if ((err = nvs_erase_key(nvs_handle, info.key)) != ESP_OK) {
ESP_LOGE(TAG, "nvs_erase_key failed. %s", esp_err_to_name(err));
} else {
nvs_commit(nvs_handle);
}
nvs_close(nvs_handle);
if (err == ESP_OK) {
ESP_LOGW(TAG, "nvs_erase_key completed on empty key. Restarting system to apply changes.");
esp_restart();
}
}
if (err != ESP_OK) {
ESP_LOGW(TAG, "nvs_erase_key failed on empty key. Configuration partition should be erased. %s", esp_err_to_name(err));
err = ESP_OK;
}
}
else {
void* value = get_nvs_value_alloc(info.type, info.key);
if (value == NULL) {
ESP_LOGE(TAG, "nvs read failed.");
return ESP_FAIL;
}
config_set_value(info.type, info.key, value);
free(value);
}
config_set_value(info.type, info.key, value);
free(value );
}
it = nvs_entry_next(it);
}
char * json_string= config_alloc_get_json(false);
if(json_string!=NULL) {
ESP_LOGD(TAG, "config json : %s\n", json_string);
free(json_string);
}
ESP_LOGD(TAG,"Config memory usage. Heap internal:%zu (min:%zu) (used:%zu) external:%zu (min:%zu) (used:%zd)",
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
malloc_int-heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
malloc_spiram -heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
return err;
}
}
it = nvs_entry_next(it);
}
char* json_string = config_alloc_get_json(false);
if (json_string != NULL) {
ESP_LOGD(TAG, "config json : %s\n", json_string);
free(json_string);
}
ESP_LOGW(TAG, "Configuration memory usage. Heap internal:%zu (min:%zu) (used:%zu) external:%zu (min:%zu) (used:%zd)",
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
malloc_int - heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
malloc_spiram - heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
return err;
}
esp_err_t store_nvs_value(nvs_type_t type, const char *key, void * data) {
if (type == NVS_TYPE_BLOB)
return ESP_ERR_NVS_TYPE_MISMATCH;
return store_nvs_value_len(type, key, data,0);
}
esp_err_t store_nvs_value_len(nvs_type_t type, const char *key, void * data,
size_t data_len) {
esp_err_t store_nvs_value_len_for_partition(const char * partition,const char * namespace,nvs_type_t type, const char *key, const void * data,size_t data_len) {
esp_err_t err;
nvs_handle nvs;
if(!key || key[0]=='\0'){
ESP_LOGE(TAG, "Cannot store value to nvs: key is empty");
return ESP_ERR_INVALID_ARG;
}
if (type == NVS_TYPE_ANY) {
return ESP_ERR_NVS_TYPE_MISMATCH;
}
err = nvs_open_from_partition(settings_partition, current_namespace, NVS_READWRITE, &nvs);
err = nvs_open_from_partition(partition, namespace, NVS_READWRITE, &nvs);
if (err != ESP_OK) {
return err;
}
@@ -185,53 +217,65 @@ esp_err_t store_nvs_value_len(nvs_type_t type, const char *key, void * data,
nvs_close(nvs);
return err;
}
void * get_nvs_value_alloc(nvs_type_t type, const char *key) {
esp_err_t store_nvs_value_len(nvs_type_t type, const char *key, void * data,
size_t data_len) {
return store_nvs_value_len_for_partition(settings_partition,current_namespace,type,key,data,data_len);
}
void * get_nvs_value_alloc_for_partition(const char * partition,const char * namespace,nvs_type_t type, const char *key, size_t * size){
nvs_handle nvs;
esp_err_t err;
void * value=NULL;
err = nvs_open_from_partition(settings_partition, current_namespace, NVS_READONLY, &nvs);
if(size){
*size=0;
}
err = nvs_open_from_partition(partition, namespace, NVS_READONLY, &nvs);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Could not open the nvs storage.");
return NULL;
}
if (type == NVS_TYPE_I8) {
value=malloc(sizeof(int8_t));
value=malloc_init_external(sizeof(int8_t));
err = nvs_get_i8(nvs, key, (int8_t *) value);
} else if (type == NVS_TYPE_U8) {
value=malloc(sizeof(uint8_t));
value=malloc_init_external(sizeof(uint8_t));
err = nvs_get_u8(nvs, key, (uint8_t *) value);
} else if (type == NVS_TYPE_I16) {
value=malloc(sizeof(int16_t));
value=malloc_init_external(sizeof(int16_t));
err = nvs_get_i16(nvs, key, (int16_t *) value);
} else if (type == NVS_TYPE_U16) {
value=malloc(sizeof(uint16_t));
value=malloc_init_external(sizeof(uint16_t));
err = nvs_get_u16(nvs, key, (uint16_t *) value);
} else if (type == NVS_TYPE_I32) {
value=malloc(sizeof(int32_t));
value=malloc_init_external(sizeof(int32_t));
err = nvs_get_i32(nvs, key, (int32_t *) value);
} else if (type == NVS_TYPE_U32) {
value=malloc(sizeof(uint32_t));
value=malloc_init_external(sizeof(uint32_t));
err = nvs_get_u32(nvs, key, (uint32_t *) value);
} else if (type == NVS_TYPE_I64) {
value=malloc(sizeof(int64_t));
value=malloc_init_external(sizeof(int64_t));
err = nvs_get_i64(nvs, key, (int64_t *) value);
} else if (type == NVS_TYPE_U64) {
value=malloc(sizeof(uint64_t));
value=malloc_init_external(sizeof(uint64_t));
err = nvs_get_u64(nvs, key, (uint64_t *) value);
} else if (type == NVS_TYPE_STR) {
size_t len=0;
err = nvs_get_str(nvs, key, NULL, &len);
if (err == ESP_OK) {
value=malloc(len);
value=malloc_init_external(len+1);
err = nvs_get_str(nvs, key, value, &len);
}
if(size){
*size=len;
}
}
} else if (type == NVS_TYPE_BLOB) {
size_t len;
err = nvs_get_blob(nvs, key, NULL, &len);
if (err == ESP_OK) {
value=malloc(len+1);
value=malloc_init_external(len+1);
if(size){
*size=len;
}
err = nvs_get_blob(nvs, key, value, &len);
}
}
@@ -244,6 +288,9 @@ void * get_nvs_value_alloc(nvs_type_t type, const char *key) {
nvs_close(nvs);
return value;
}
void * get_nvs_value_alloc(nvs_type_t type, const char *key) {
return get_nvs_value_alloc_for_partition(settings_partition, current_namespace,type,key,NULL);
}
esp_err_t get_nvs_value(nvs_type_t type, const char *key, void*value, const uint8_t buf_size) {
nvs_handle nvs;
esp_err_t err;
@@ -296,11 +343,10 @@ esp_err_t get_nvs_value(nvs_type_t type, const char *key, void*value, const uint
nvs_close(nvs);
return err;
}
esp_err_t erase_nvs(const char *key)
esp_err_t erase_nvs_for_partition(const char * partition, const char * namespace,const char *key)
{
nvs_handle nvs;
esp_err_t err = nvs_open(current_namespace, NVS_READWRITE, &nvs);
esp_err_t err = nvs_open_from_partition(partition,namespace, NVS_READWRITE, &nvs);
if (err == ESP_OK) {
err = nvs_erase_key(nvs, key);
if (err == ESP_OK) {
@@ -311,7 +357,35 @@ esp_err_t erase_nvs(const char *key)
}
nvs_close(nvs);
}
else {
ESP_LOGE(TAG,"Could not erase key %s from partition %s namespace %s : %s", key,partition,namespace, esp_err_to_name(err));
}
return err;
}
esp_err_t erase_nvs(const char *key)
{
return erase_nvs_for_partition(NVS_DEFAULT_PART_NAME, current_namespace,key);
}
esp_err_t erase_nvs_partition(const char * partition, const char * namespace){
nvs_handle nvs;
const char * step = "Opening";
ESP_LOGD(TAG,"%s partition %s, namespace %s ",step,partition,namespace);
esp_err_t err = nvs_open_from_partition(partition,namespace, NVS_READWRITE, &nvs);
if (err == ESP_OK) {
step = "Erasing";
ESP_LOGD(TAG,"%s namespace %s ",step,partition);
err = nvs_erase_all(nvs);
if (err == ESP_OK) {
step = "Committing";
ESP_LOGD(TAG,"%s",step);
err = nvs_commit(nvs);
}
}
if(err !=ESP_OK){
ESP_LOGE(TAG,"%s partition %s, name space %s : %s",step,partition,namespace,esp_err_to_name(err));
}
ESP_LOGD(TAG,"Closing %s ",namespace);
nvs_close(nvs);
return err;
}

View File

@@ -13,10 +13,15 @@ esp_err_t store_nvs_value_len(nvs_type_t type, const char *key, void * data, siz
esp_err_t store_nvs_value(nvs_type_t type, const char *key, void * data);
esp_err_t get_nvs_value(nvs_type_t type, const char *key, void*value, const uint8_t buf_size);
void * get_nvs_value_alloc(nvs_type_t type, const char *key);
void * get_nvs_value_alloc_for_partition(const char * partition,const char * namespace,nvs_type_t type, const char *key, size_t * size);
esp_err_t erase_nvs_for_partition(const char * partition, const char * namespace,const char *key);
esp_err_t store_nvs_value_len_for_partition(const char * partition,const char * namespace,nvs_type_t type, const char *key, const void * data,size_t data_len);
esp_err_t erase_nvs(const char *key);
void print_blob(const char *blob, size_t len);
const char *type_to_str(nvs_type_t type);
nvs_type_t str_to_type(const char *type);
esp_err_t erase_nvs_partition(const char * partition, const char * namespace);
void erase_settings_partition();
#ifdef __cplusplus
}
#endif

View File

@@ -18,11 +18,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
//#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
#include "platform_config.h"
#include "nvs_utilities.h"
#include "platform_esp32.h"
#include "trace.h"
#include <stdio.h>
#include <string.h>
#include "esp_system.h"
@@ -39,18 +37,19 @@
#include "cJSON.h"
#include "freertos/timers.h"
#include "freertos/event_groups.h"
#include "tools.h"
#include "trace.h"
#define CONFIG_COMMIT_DELAY 1000
#define LOCK_MAX_WAIT 20*CONFIG_COMMIT_DELAY
static const char * TAG = "config";
static cJSON * nvs_json=NULL;
static TimerHandle_t timer;
static SemaphoreHandle_t config_mutex = NULL;
static EventGroupHandle_t config_group;
EXT_RAM_ATTR static cJSON * nvs_json=NULL;
EXT_RAM_ATTR static TimerHandle_t timer;
EXT_RAM_ATTR static SemaphoreHandle_t config_mutex = NULL;
EXT_RAM_ATTR static EventGroupHandle_t config_group;
/* @brief indicate that the ESP32 is currently connected. */
static const int CONFIG_NO_COMMIT_PENDING = BIT0;
static const int CONFIG_LOAD_BIT = BIT1;
EXT_RAM_ATTR static const int CONFIG_NO_COMMIT_PENDING = BIT0;
EXT_RAM_ATTR static const int CONFIG_LOAD_BIT = BIT1;
bool config_lock(TickType_t xTicksToWait);
void config_unlock();
@@ -62,7 +61,7 @@ cJSON * config_set_value_safe(nvs_type_t nvs_type, const char *key,const void *
static void vCallbackFunction( TimerHandle_t xTimer );
void config_set_entry_changed_flag(cJSON * entry, cJSON_bool flag);
#define IMPLEMENT_SET_DEFAULT(t,nt) void config_set_default_## t (const char *key, t value){\
void * pval = malloc(sizeof(value));\
void * pval = malloc_init_external(sizeof(value));\
*((t *) pval) = value;\
config_set_default(nt, key,pval,0);\
free(pval); }
@@ -72,7 +71,7 @@ void config_set_entry_changed_flag(cJSON * entry, cJSON_bool flag);
return ESP_FAIL;}
static void * malloc_fn(size_t sz){
void * ptr = is_recovery_running?malloc(sz):heap_caps_malloc(sz, MALLOC_CAP_SPIRAM);
void * ptr = is_recovery_running?malloc(sz):heap_caps_malloc(sz, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
if(ptr==NULL){
ESP_LOGE(TAG,"malloc_fn: unable to allocate memory!");
}
@@ -85,20 +84,28 @@ void init_cJSON(){
}
void config_init(){
ESP_LOGD(TAG, "Creating mutex for Config");
MEMTRACE_PRINT_DELTA();
config_mutex = xSemaphoreCreateMutex();
MEMTRACE_PRINT_DELTA();
ESP_LOGD(TAG, "Creating event group");
MEMTRACE_PRINT_DELTA();
config_group = xEventGroupCreate();
MEMTRACE_PRINT_DELTA();
ESP_LOGD(TAG, "Loading config from nvs");
init_cJSON();
MEMTRACE_PRINT_DELTA();
if(nvs_json !=NULL){
cJSON_Delete(nvs_json);
}
nvs_json = cJSON_CreateObject();
config_set_group_bit(CONFIG_LOAD_BIT,true);
MEMTRACE_PRINT_DELTA();
nvs_load_config();
MEMTRACE_PRINT_DELTA();
config_set_group_bit(CONFIG_LOAD_BIT,false);
MEMTRACE_PRINT_DELTA();
config_start_timer();
}
@@ -318,28 +325,28 @@ void * config_safe_alloc_get_entry_value(nvs_type_t nvs_type, cJSON * entry){
return NULL;
}
if (nvs_type == NVS_TYPE_I8) {
value=malloc(sizeof(int8_t));
value=malloc_init_external(sizeof(int8_t));
*(int8_t *)value = (int8_t)entry_value->valuedouble;
} else if (nvs_type == NVS_TYPE_U8) {
value=malloc(sizeof(uint8_t));
value=malloc_init_external(sizeof(uint8_t));
*(uint8_t *)value = (uint8_t)entry_value->valuedouble;
} else if (nvs_type == NVS_TYPE_I16) {
value=malloc(sizeof(int16_t));
value=malloc_init_external(sizeof(int16_t));
*(int16_t *)value = (int16_t)entry_value->valuedouble;
} else if (nvs_type == NVS_TYPE_U16) {
value=malloc(sizeof(uint16_t));
value=malloc_init_external(sizeof(uint16_t));
*(uint16_t *)value = (uint16_t)entry_value->valuedouble;
} else if (nvs_type == NVS_TYPE_I32) {
value=malloc(sizeof(int32_t));
value=malloc_init_external(sizeof(int32_t));
*(int32_t *)value = (int32_t)entry_value->valuedouble;
} else if (nvs_type == NVS_TYPE_U32) {
value=malloc(sizeof(uint32_t));
value=malloc_init_external(sizeof(uint32_t));
*(uint32_t *)value = (uint32_t)entry_value->valuedouble;
} else if (nvs_type == NVS_TYPE_I64) {
value=malloc(sizeof(int64_t));
value=malloc_init_external(sizeof(int64_t));
*(int64_t *)value = (int64_t)entry_value->valuedouble;
} else if (nvs_type == NVS_TYPE_U64) {
value=malloc(sizeof(uint64_t));
value=malloc_init_external(sizeof(uint64_t));
*(uint64_t *)value = (uint64_t)entry_value->valuedouble;
} else if (nvs_type == NVS_TYPE_STR) {
if(!cJSON_IsString(entry_value)){
@@ -361,8 +368,7 @@ void * config_safe_alloc_get_entry_value(nvs_type_t nvs_type, cJSON * entry){
}
else {
size_t len=strlen(cJSON_GetStringValue(entry_value));
value=(void *)heap_caps_malloc(len+1, MALLOC_CAP_DMA);
memset(value,0x00,len+1);
value=(void *)malloc_init_external(len+1);
memcpy(value,cJSON_GetStringValue(entry_value),len);
if(value==NULL){
char * entry_str = cJSON_PrintUnformatted(entry);
@@ -406,12 +412,11 @@ void config_commit_to_nvs(){
void * value = config_safe_alloc_get_entry_value(type, entry);
if(value!=NULL){
size_t len=strlen(entry->string);
char * key=(void *)heap_caps_malloc(len+1, MALLOC_CAP_DMA);
memset(key,0x00,len+1);
char * key=(void *)malloc_init_external(len+1);
memcpy(key,entry->string,len);
esp_err_t err = store_nvs_value(type,key,value);
free(key);
free(value);
FREE_AND_NULL(key);
FREE_AND_NULL(value);
if(err!=ESP_OK){
char * entry_str = cJSON_PrintUnformatted(entry);
@@ -615,13 +620,47 @@ void config_delete_key(const char *key){
void * config_alloc_get(nvs_type_t nvs_type, const char *key) {
return config_alloc_get_default(nvs_type, key, NULL, 0);
}
cJSON * config_alloc_get_cjson(const char *key){
char * conf_str = config_alloc_get_default(NVS_TYPE_STR, key, NULL, 0);
if(conf_str==NULL){
ESP_LOGE(TAG, "Unable to get config value for key [%s]", key);
return NULL;
}
cJSON * conf_json = cJSON_Parse(conf_str);
free(conf_str);
if(conf_json==NULL){
ESP_LOGE(TAG, "Unable to parse config value for key [%s]", key);
return NULL;
}
return conf_json;
}
esp_err_t config_set_cjson_str(const char *key, cJSON *value){
char * value_str = cJSON_PrintUnformatted(value);
if(value_str==NULL){
ESP_LOGE(TAG, "Unable to print cJSON for key [%s]", key);
return ESP_ERR_INVALID_ARG;
}
esp_err_t err = config_set_value(NVS_TYPE_STR,key, value_str);
free(value_str);
cJSON_Delete(value);
return err;
}
void config_get_uint16t_from_str(const char *key, uint16_t *value, uint16_t default_value){
char * str_value = config_alloc_get(NVS_TYPE_STR, key);
if(str_value == NULL){
*value = default_value;
return ;
}
*value = atoi(str_value);
free(str_value);
}
void * config_alloc_get_str(const char *key, char *lead, char *fallback) {
if (lead && *lead) return strdup(lead);
if (lead && *lead) return strdup_psram(lead);
char *value = config_alloc_get_default(NVS_TYPE_STR, key, NULL, 0);
if ((!value || !*value) && fallback) {
if (value) free(value);
value = strdup(fallback);
value = strdup_psram(fallback);
}
return value;
}
@@ -673,7 +712,7 @@ char * config_alloc_get_json(bool bFormatted){
char * json_buffer = NULL;
if(!config_lock(LOCK_MAX_WAIT/portTICK_PERIOD_MS)){
ESP_LOGE(TAG, "Unable to lock config after %d ms",LOCK_MAX_WAIT);
return strdup("{\"error\":\"Unable to lock configuration object.\"}");
return strdup_psram("{\"error\":\"Unable to lock configuration object.\"}");
}
if(bFormatted){
json_buffer= cJSON_Print(nvs_json);
@@ -686,6 +725,10 @@ char * config_alloc_get_json(bool bFormatted){
}
esp_err_t config_set_value(nvs_type_t nvs_type, const char *key, const void * value){
esp_err_t result = ESP_OK;
if(!key ||!key[0]){
ESP_LOGW(TAG,"Empty key passed. Ignoring entry!");
return ESP_ERR_INVALID_ARG;
}
if(!config_lock(LOCK_MAX_WAIT/portTICK_PERIOD_MS)){
ESP_LOGE(TAG, "Unable to lock config after %d ms",LOCK_MAX_WAIT);
result = ESP_FAIL;
@@ -707,7 +750,42 @@ esp_err_t config_set_value(nvs_type_t nvs_type, const char *key, const void * va
config_unlock();
return result;
}
cJSON* cjson_update_string(cJSON** root, const char* key, const char* value) {
if (*root == NULL) {
*root = cJSON_CreateObject();
if (*root == NULL) {
ESP_LOGE(TAG, "Error creating cJSON object!");
}
}
if (!key || !value || strlen(key) == 0) {
ESP_LOGE(TAG, "cjson_update_string. Invalid key or value passed! key: %s, value: %s", STR_OR_ALT(key, ""), STR_OR_ALT(value, ""));
return *root;
}
cJSON* cjsonvalue = cJSON_GetObjectItemCaseSensitive(*root, key);
if (cjsonvalue && strcasecmp(cJSON_GetStringValue(cjsonvalue), value) != 0) {
ESP_LOGD(TAG, "Value %s changed from %s to %s", key, cJSON_GetStringValue(cjsonvalue), value);
cJSON_SetValuestring(cjsonvalue, value);
} else if(!cjsonvalue){
ESP_LOGD(TAG, "Adding new value %s: %s", key, value);
cJSON_AddItemToObject(*root, key, cJSON_CreateString(value));
}
return *root;
}
cJSON* cjson_update_number(cJSON** root, const char* key, int value) {
if (*root == NULL) {
*root = cJSON_CreateObject();
}
if (key && strlen(key) != 0) {
cJSON* cjsonvalue = cJSON_GetObjectItemCaseSensitive(*root, key);
if (cjsonvalue) {
cJSON_SetNumberValue(cjsonvalue, value);
} else {
cJSON_AddNumberToObject(*root, key, value);
}
}
return *root;
}
IMPLEMENT_SET_DEFAULT(uint8_t,NVS_TYPE_U8);
IMPLEMENT_SET_DEFAULT(int8_t,NVS_TYPE_I8);
IMPLEMENT_SET_DEFAULT(uint16_t,NVS_TYPE_U16);

View File

@@ -52,6 +52,9 @@ void config_start_timer();
void config_init();
void * config_alloc_get_default(nvs_type_t type, const char *key, void * default_value, size_t blob_size);
void * config_alloc_get_str(const char *key, char *lead, char *fallback);
cJSON * config_alloc_get_cjson(const char *key);
esp_err_t config_set_cjson_str(const char *key, cJSON *value);
void config_get_uint16t_from_str(const char *key, uint16_t *value, uint16_t default_value);
void config_delete_key(const char *key);
void config_set_default(nvs_type_t type, const char *key, void * default_value, size_t blob_size);
void * config_alloc_get(nvs_type_t nvs_type, const char *key) ;
@@ -60,7 +63,8 @@ char * config_alloc_get_json(bool bFormatted);
esp_err_t config_set_value(nvs_type_t nvs_type, const char *key, const void * value);
nvs_type_t config_get_item_type(cJSON * entry);
void * config_safe_alloc_get_entry_value(nvs_type_t nvs_type, cJSON * entry);
cJSON* cjson_update_number(cJSON** root, const char* key, int value);
cJSON* cjson_update_string(cJSON** root, const char* key, const char* value);
#ifdef __cplusplus
}
#endif

View File

@@ -8,9 +8,10 @@ idf_component_register( SRCS
cmd_config.c
INCLUDE_DIRS .
REQUIRES nvs_flash
PRIV_REQUIRES console app_update tools services spi_flash platform_config vfs pthread wifi-manager platform_config newlib telnet display squeezelite)
PRIV_REQUIRES console app_update tools services spi_flash platform_config vfs pthread wifi-manager platform_config newlib telnet display squeezelite tools)
target_link_libraries(${COMPONENT_LIB} "-Wl,--undefined=GDS_DrawPixelFast")
target_link_libraries(${COMPONENT_LIB} ${build_dir}/esp-idf/$<TARGET_PROPERTY:RECOVERY_PREFIX>/lib$<TARGET_PROPERTY:RECOVERY_PREFIX>.a )
set_source_files_properties(cmd_config.c
PROPERTIES COMPILE_FLAGS
-Wno-unused-function

View File

@@ -30,8 +30,19 @@ const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
int main(int argc, char **argv){
return 1;
}
void register_squeezelite(){
}
void register_external(void) {
}
void deregister_external(void) {
}
void decode_restore(int external) {
}
esp_err_t start_ota(const char * bin_url, char * bin_buffer, uint32_t length)
{
return process_recovery_ota(bin_url,bin_buffer,length);

View File

@@ -1,7 +1,7 @@
idf_build_get_property(idf_path IDF_PATH)
idf_component_register( SRCS cmd_squeezelite.c
INCLUDE_DIRS .
PRIV_REQUIRES spi_flash bootloader_support partition_table bootloader_support console codecs squeezelite newlib pthread tools platform_config display )
PRIV_REQUIRES spi_flash bootloader_support partition_table bootloader_support console codecs squeezelite newlib pthread tools platform_config display tools)
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=feof")

View File

@@ -11,6 +11,8 @@
#include "platform_esp32.h"
#include "platform_config.h"
#include "esp_app_format.h"
#include "tools.h"
extern esp_err_t process_recovery_ota(const char * bin_url, char * bin_buffer, uint32_t length);
static const char * TAG = "squeezelite_cmd";
#define SQUEEZELITE_THREAD_STACK_SIZE (8*1024)
@@ -98,8 +100,7 @@ static int launchsqueezelite(int argc, char **argv) {
ESP_LOGV(TAG,"Saving args in thread structure");
thread_parms.argc=0;
thread_parms.argv = malloc(sizeof(char**)*(argc+ADDITIONAL_SQUEEZELITE_ARGS));
memset(thread_parms.argv,'\0',sizeof(char**)*(argc+ADDITIONAL_SQUEEZELITE_ARGS));
thread_parms.argv = malloc_init_external(sizeof(char**)*(argc+ADDITIONAL_SQUEEZELITE_ARGS));
for(int i=0;i<argc;i++){
ESP_LOGD(TAG ,"assigning parm %u : %s",i,argv[i]);

View File

@@ -6,7 +6,6 @@
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
//#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#include <stdio.h>
#include "cmd_config.h"
#include "argtable3/argtable3.h"
@@ -15,17 +14,23 @@
#include "string.h"
#include "stdio.h"
#include "platform_config.h"
#include "trace.h"
#include "messaging.h"
#include "accessors.h"
#include "adac.h"
#include "tools.h"
#include "cJSON.h"
#include "cmd_i2ctools.h"
const char * desc_squeezelite ="Squeezelite Options";
const char * desc_dac= "DAC Options";
const char * desc_cspotc= "Spotify (cSpot) Options";
const char * desc_preset= "Preset Options";
const char * desc_spdif= "SPDIF Options";
const char * desc_audio= "General Audio Options";
const char * desc_bt_source= "Bluetooth Audio Output Options";
const char * desc_rotary= "Rotary Control";
extern const struct adac_s *dac_set[];
#define CODECS_BASE "flac|pcm|mp3|ogg"
#if NO_FAAD
@@ -45,7 +50,6 @@ const char * desc_rotary= "Rotary Control";
#endif
#define CODECS_MP3 "|mad|mpg"
#if !defined(MODEL_NAME)
#define MODEL_NAME SqueezeLite
#endif
@@ -58,6 +62,7 @@ const char * desc_rotary= "Rotary Control";
#define MODEL_NAME_STRING STR(MODEL_NAME)
#endif
#define CODECS CODECS_BASE CODECS_AAC CODECS_FF CODECS_DSD CODECS_MP3
#define NOT_OUTPUT "has input capabilities only"
#define NOT_GPIO "is not a GPIO"
@@ -85,7 +90,10 @@ static struct {
struct arg_lit *clear;
struct arg_end *end;
} i2s_args;
static struct {
struct arg_str *model_config;
struct arg_end *end;
} known_model_args;
static struct {
struct arg_rem * rem;
struct arg_int * A;
@@ -96,6 +104,7 @@ static struct {
struct arg_lit * knobonly;
struct arg_int * timer;
struct arg_lit * clear;
struct arg_lit * raw_mode;
struct arg_end * end;
} rotary_args;
//config_rotary_get
@@ -106,7 +115,12 @@ static struct{
// struct arg_dbl *control_delay;
struct arg_end *end;
} bt_source_args;
static struct {
struct arg_str *deviceName;
// struct arg_int *volume;
struct arg_int *bitrate;
struct arg_end *end;
} cspot_args;
static struct {
struct arg_int *clock;
struct arg_int *wordselect;
@@ -189,9 +203,12 @@ int check_missing_parm(struct arg_int * int_parm, FILE * f){
}
char * strip_bt_name(char * opt_str)
{
char *result = malloc(strlen(opt_str)+1);
memset(result, 0x00, strlen(opt_str)+1);
char *str = strdup(opt_str);
if(!opt_str || strlen(opt_str)==0){
ESP_LOGW(TAG,"strip_bt_name: opt_str is NULL");
return NULL;
}
char *result = malloc_init_external(strlen(opt_str)+1);
char *str = strdup_psram(opt_str);
const char * output_marker=" -o";
if(!result ){
@@ -532,6 +549,7 @@ static int do_rotary_cmd(int argc, char **argv){
fprintf(f,"error: Cannot use volume lock or longpress option when knob only option selected\n");
nerrors++;
}
if(rotary_args.timer->count>0 && rotary_args.timer->ival[0]<0){
fprintf(f,"error: knob only timer should be greater than or equal to zero.\n");
nerrors++;
@@ -546,6 +564,13 @@ static int do_rotary_cmd(int argc, char **argv){
fprintf(f,"Storing rotary parameters.\n");
nerrors+=(config_rotary_set(&rotary )!=ESP_OK);
}
if(!nerrors ){
fprintf(f,"Storing raw mode parameter.\n");
nerrors+=(config_set_value(NVS_TYPE_STR, "lms_ctrls_raw", rotary_args.raw_mode->count>0?"Y":"N")!=ESP_OK);
if(nerrors>0){
fprintf(f,"error: Unable to store raw mode parameter.\n");
}
}
if(!nerrors ){
fprintf(f,"Done.\n");
}
@@ -555,7 +580,61 @@ static int do_rotary_cmd(int argc, char **argv){
FREE_AND_NULL(buf);
return (nerrors==0 && err==ESP_OK)?0:1;
}
static int is_valid_gpio_number(int gpio, const char * name, FILE *f, bool mandatory, struct arg_int * target, bool output){
bool invalid = (!GPIO_IS_VALID_GPIO(gpio) ||(output && !GPIO_IS_VALID_OUTPUT_GPIO(gpio))) ;
if(invalid && mandatory && gpio!=-1){
fprintf(f,"Error: Invalid mandatory gpio %d for %s\n",gpio,name);
return 1;
}
if(target && !invalid){
target->count=1;
target->ival[0]=gpio;
}
return 0;
}
static int do_cspot_config(int argc, char **argv){
char * name = NULL;
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&cspot_args);
if (nerrors != 0) {
return 1;
}
char *buf = NULL;
size_t buf_size = 0;
FILE *f = open_memstream(&buf, &buf_size);
if (f == NULL) {
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
return 1;
}
cJSON * cspot_config = config_alloc_get_cjson("cspot_config");
if(!cspot_config){
nerrors++;
fprintf(f,"error: Unable to get cspot config.\n");
}
else {
cjson_update_string(&cspot_config,cspot_args.deviceName->hdr.longopts,cspot_args.deviceName->count>0?cspot_args.deviceName->sval[0]:NULL);
// cjson_update_number(&cspot_config,cspot_args.volume->hdr.longopts,cspot_args.volume->count>0?cspot_args.volume->ival[0]:0);
cjson_update_number(&cspot_config,cspot_args.bitrate->hdr.longopts,cspot_args.bitrate->count>0?cspot_args.bitrate->ival[0]:0);
}
if(!nerrors ){
fprintf(f,"Storing cspot parameters.\n");
nerrors+=(config_set_cjson_str("cspot_config",cspot_config) !=ESP_OK);
}
if(nerrors==0){
fprintf(f,"Device name changed to %s\n",name);
}
if(!nerrors ){
fprintf(f,"Done.\n");
}
FREE_AND_NULL(name);
fflush (f);
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
fclose(f);
FREE_AND_NULL(buf);
return nerrors;
}
static int do_i2s_cmd(int argc, char **argv)
{
i2s_platform_config_t i2s_dac_pin = {
@@ -570,6 +649,7 @@ static int do_i2s_cmd(int argc, char **argv)
return 1;
}
strcpy(i2s_dac_pin.model, "I2S");
ESP_LOGD(TAG,"Processing i2s command %s with %d parameters",argv[0],argc);
esp_err_t err=ESP_OK;
int nerrors = arg_parse(argc, argv,(void **)&i2s_args);
@@ -583,39 +663,39 @@ static int do_i2s_cmd(int argc, char **argv)
size_t buf_size = 0;
FILE *f = open_memstream(&buf, &buf_size);
if (f == NULL) {
ESP_LOGE(TAG, "do_i2s_cmd: Failed to open memstream");
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
return 1;
}
if(nerrors >0){
ESP_LOGE(TAG,"do_i2s_cmd: %d errors parsing arguments",nerrors);
arg_print_errors(f,i2s_args.end,desc_dac);
fclose(f);
return 1;
}
nerrors+=is_output_gpio(i2s_args.clock, f, &i2s_dac_pin.pin.bck_io_num, true);
nerrors+=is_output_gpio(i2s_args.wordselect, f, &i2s_dac_pin.pin.ws_io_num, true);
nerrors+=is_output_gpio(i2s_args.data, f, &i2s_dac_pin.pin.data_out_num, true);
nerrors+=is_output_gpio(i2s_args.mute_gpio, f, &i2s_dac_pin.mute_gpio, false);
if(i2s_dac_pin.mute_gpio>0){
i2s_dac_pin.mute_level = i2s_args.mute_level->count>0?1:0;
}
if(i2s_args.dac_sda->count>0 && i2s_args.dac_sda->ival[0]>=0){
// if SDA specified, then SDA and SCL are both mandatory
nerrors+=is_output_gpio(i2s_args.dac_sda, f, &i2s_dac_pin.sda, false);
nerrors+=is_output_gpio(i2s_args.dac_scl, f, &i2s_dac_pin.scl, false);
}
if(i2s_args.dac_sda->count==0&& i2s_args.dac_i2c->count>0){
fprintf(f,"warning: ignoring i2c address, since dac i2c gpios config is incomplete\n");
}
else if(i2s_args.dac_i2c->count>0){
i2s_dac_pin.i2c_addr = i2s_args.dac_i2c->ival[0];
}
if(i2s_args.model_name->count>0 && strlen(i2s_args.model_name->sval[0])>0){
else {
strncpy(i2s_dac_pin.model,i2s_args.model_name->sval[0],sizeof(i2s_dac_pin.model));
i2s_dac_pin.model[sizeof(i2s_dac_pin.model) - 1] = '\0';
}
if(!nerrors ){
fprintf(f,"Storing i2s parameters.\n");
nerrors+=(config_i2s_set(&i2s_dac_pin, "dac_config")!=ESP_OK);
nerrors += is_output_gpio(i2s_args.clock, f, &i2s_dac_pin.pin.bck_io_num, true);
nerrors += is_output_gpio(i2s_args.wordselect, f, &i2s_dac_pin.pin.ws_io_num, true);
nerrors += is_output_gpio(i2s_args.data, f, &i2s_dac_pin.pin.data_out_num, true);
nerrors += is_output_gpio(i2s_args.mute_gpio, f, &i2s_dac_pin.mute_gpio, false);
if (i2s_dac_pin.mute_gpio >= 0) {
i2s_dac_pin.mute_level = i2s_args.mute_level->count > 0 ? 1 : 0;
}
if (i2s_args.dac_sda->count > 0 && i2s_args.dac_sda->ival[0] >= 0) {
// if SDA specified, then SDA and SCL are both mandatory
nerrors += is_output_gpio(i2s_args.dac_sda, f, &i2s_dac_pin.sda, false);
nerrors += is_output_gpio(i2s_args.dac_scl, f, &i2s_dac_pin.scl, false);
}
if (i2s_args.dac_sda->count == 0 && i2s_args.dac_i2c->count > 0) {
fprintf(f, "warning: ignoring i2c address, since dac i2c gpios config is incomplete\n");
} else if (i2s_args.dac_i2c->count > 0) {
i2s_dac_pin.i2c_addr = i2s_args.dac_i2c->ival[0];
}
if (!nerrors) {
fprintf(f, "Storing i2s parameters.\n");
nerrors += (config_i2s_set(&i2s_dac_pin, "dac_config") != ESP_OK);
}
}
if(!nerrors ){
fprintf(f,"Done.\n");
@@ -647,40 +727,81 @@ cJSON * example_cb(){
return values;
}
//const i2s_pin_config_t * config_get_spdif_pin_struct( );
cJSON * i2s_cb(){
cJSON * known_model_cb(){
cJSON * values = cJSON_CreateObject();
const i2s_platform_config_t * i2s_conf= config_dac_get( );
if(i2s_conf->pin.bck_io_num>0 ) {
cJSON_AddNumberToObject(values,"clock",i2s_conf->pin.bck_io_num);
if(!values){
ESP_LOGE(TAG,"known_model_cb: Failed to create JSON object");
return NULL;
}
if(i2s_conf->pin.ws_io_num>=0 ) {
cJSON_AddNumberToObject(values,"wordselect",i2s_conf->pin.ws_io_num);
}
if(i2s_conf->pin.data_out_num>=0 ) {
cJSON_AddNumberToObject(values,"data",i2s_conf->pin.data_out_num);
}
if(i2s_conf->sda>=0 ) {
cJSON_AddNumberToObject(values,"dac_sda",i2s_conf->sda);
}
if(i2s_conf->scl>=0 ) {
cJSON_AddNumberToObject(values,"dac_scl",i2s_conf->scl);
}
if(i2s_conf->i2c_addr>=0 ) {
cJSON_AddNumberToObject(values,"dac_i2c",i2s_conf->i2c_addr);
}
if(i2s_conf->mute_gpio>=0 ) {
cJSON_AddNumberToObject(values,"mute_gpio",i2s_conf->mute_gpio);
}
if(i2s_conf->mute_level>=0 ) {
cJSON_AddBoolToObject(values,"mute_level",i2s_conf->mute_level>0);
}
if(strlen(i2s_conf->model)>0){
cJSON_AddStringToObject(values,"model_name",i2s_conf->model);
char * name = config_alloc_get_default(NVS_TYPE_STR,known_model_args.model_config->hdr.longopts,"",0);
if(!name){
ESP_LOGE(TAG,"Failed to get board model from nvs key %s ",known_model_args.model_config->hdr.longopts);
}
else {
cJSON_AddStringToObject(values,"model_name","I2S");
cJSON_AddStringToObject(values,known_model_args.model_config->hdr.longopts,name);
}
return values;
}
cJSON * cspot_cb(){
cJSON * values = cJSON_CreateObject();
if(!values){
ESP_LOGE(TAG,"cspot_cb: Failed to create JSON object");
return NULL;
}
cJSON * cspot_config = config_alloc_get_cjson("cspot_config");
if(!cspot_config){
ESP_LOGE(TAG,"cspot_cb: Failed to get cspot config");
return NULL;
}
cJSON * cspot_values = cJSON_GetObjectItem(cspot_config,cspot_args.deviceName->hdr.longopts);
if(cspot_values){
cJSON_AddStringToObject(values,cspot_args.deviceName->hdr.longopts,cJSON_GetStringValue(cspot_values));
}
cspot_values = cJSON_GetObjectItem(cspot_config,cspot_args.bitrate->hdr.longopts);
if(cspot_values){
cJSON_AddNumberToObject(values,cspot_args.bitrate->hdr.longopts,cJSON_GetNumberValue(cspot_values));
}
// cspot_values = cJSON_GetObjectItem(cspot_config,cspot_args.volume->hdr.longopts);
// if(cspot_values){
// cJSON_AddNumberToObject(values,cspot_args.volume->hdr.longopts,cJSON_GetNumberValue(cspot_values));
// }
cJSON_Delete(cspot_config);
return values;
}
cJSON * i2s_cb(){
cJSON * values = cJSON_CreateObject();
const i2s_platform_config_t * i2s_conf= config_dac_get( );
if(i2s_conf->pin.bck_io_num>0 ) {
cJSON_AddNumberToObject(values,i2s_args.clock->hdr.longopts,i2s_conf->pin.bck_io_num);
}
if(i2s_conf->pin.ws_io_num>=0 ) {
cJSON_AddNumberToObject(values,i2s_args.wordselect->hdr.longopts,i2s_conf->pin.ws_io_num);
}
if(i2s_conf->pin.data_out_num>=0 ) {
cJSON_AddNumberToObject(values,i2s_args.data->hdr.longopts,i2s_conf->pin.data_out_num);
}
if(i2s_conf->sda>=0 ) {
cJSON_AddNumberToObject(values,i2s_args.dac_sda->hdr.longopts,i2s_conf->sda);
}
if(i2s_conf->scl>=0 ) {
cJSON_AddNumberToObject(values,i2s_args.dac_scl->hdr.longopts,i2s_conf->scl);
}
if(i2s_conf->i2c_addr>=0 ) {
cJSON_AddNumberToObject(values,i2s_args.dac_i2c->hdr.longopts,i2s_conf->i2c_addr);
}
if(i2s_conf->mute_gpio>=0 ) {
cJSON_AddNumberToObject(values,i2s_args.mute_gpio->hdr.longopts,i2s_conf->mute_gpio);
}
if(i2s_conf->mute_level>=0 ) {
cJSON_AddBoolToObject(values,i2s_args.mute_level->hdr.longopts,i2s_conf->mute_level>0);
}
if(strlen(i2s_conf->model)>0){
cJSON_AddStringToObject(values,i2s_args.model_name->hdr.longopts,i2s_conf->model);
}
else {
cJSON_AddStringToObject(values,i2s_args.model_name->hdr.longopts,"I2S");
}
return values;
@@ -702,18 +823,22 @@ cJSON * spdif_cb(){
}
cJSON * rotary_cb(){
cJSON * values = cJSON_CreateObject();
char *p = config_alloc_get_default(NVS_TYPE_STR, "lms_ctrls_raw", "n", 0);
bool raw_mode = p && (*p == '1' || *p == 'Y' || *p == 'y');
free(p);
const rotary_struct_t *rotary= config_rotary_get();
if(GPIO_IS_VALID_GPIO(rotary->A ) && rotary->A>=0 && GPIO_IS_VALID_GPIO(rotary->B) && rotary->B>=0){
cJSON_AddNumberToObject(values,"A",rotary->A);
cJSON_AddNumberToObject(values,"B",rotary->B);
cJSON_AddNumberToObject(values,rotary_args.A->hdr.longopts,rotary->A);
cJSON_AddNumberToObject(values,rotary_args.B->hdr.longopts,rotary->B);
if(GPIO_IS_VALID_GPIO(rotary->SW ) && rotary->SW>=0 ){
cJSON_AddNumberToObject(values,"SW",rotary->SW);
cJSON_AddNumberToObject(values,rotary_args.SW->hdr.longopts,rotary->SW);
}
cJSON_AddBoolToObject(values,"volume_lock",rotary->volume_lock);
cJSON_AddBoolToObject(values,"longpress",rotary->longpress);
cJSON_AddBoolToObject(values,"knobonly",rotary->knobonly);
cJSON_AddNumberToObject(values,"timer",rotary->timer);
cJSON_AddBoolToObject(values,rotary_args.volume_lock->hdr.longopts,rotary->volume_lock);
cJSON_AddBoolToObject(values,rotary_args.longpress->hdr.longopts,rotary->longpress);
cJSON_AddBoolToObject(values,rotary_args.knobonly->hdr.longopts,rotary->knobonly);
cJSON_AddNumberToObject(values,rotary_args.timer->hdr.longopts,rotary->timer);
cJSON_AddNumberToObject(values,rotary_args.raw_mode->hdr.longopts,raw_mode);
}
return values;
}
@@ -862,17 +987,212 @@ static char * get_log_level_options(const char * longname){
char * options = NULL;
int len = snprintf(NULL,0,template,longname,longname,longname);
if(len>0){
options = malloc(len+1);
options = malloc_init_external(len+1);
snprintf(options,len,template,longname,longname,longname);
}
return options;
}
// loop through dac_set and concatenate model name separated with |
static char * get_dac_list(){
const char * ES8388_MODEL_NAME = "ES8388|";
char * dac_list=NULL;
size_t total_len=0;
for(int i=0;dac_set[i];i++){
if(dac_set[i]->model && strlen(dac_set[i]->model)>0){
total_len+=strlen(dac_set[i]->model)+1;
}
else {
break;
}
}
total_len+=strlen(ES8388_MODEL_NAME);
dac_list = malloc_init_external(total_len+1);
if(dac_list){
for(int i=0;dac_set[i];i++){
if(dac_set[i]->model && strlen(dac_set[i]->model)>0){
strcat(dac_list,dac_set[i]->model);
strcat(dac_list,"|");
}
else {
break;
}
}
strcat(dac_list,ES8388_MODEL_NAME);
}
return dac_list;
}
void replace_char_in_string(char * str, char find, char replace){
for(int i=0;str[i];i++){
if(str[i]==find){
str[i]=replace;
}
}
}
static esp_err_t save_known_config(cJSON * known_item, const char * name,FILE * f){
esp_err_t err = ESP_OK;
char * json_string=NULL;
json_string = cJSON_Print(known_item);
ESP_LOGD(TAG,"known_item_string: %s",STR_OR_BLANK(json_string));
FREE_AND_NULL(json_string);
cJSON * kvp=NULL;
cJSON * config_array = cJSON_GetObjectItem(known_item,"config");
if(config_array && cJSON_IsArray(config_array)){
json_string = cJSON_Print(config_array);
ESP_LOGD(TAG,"config_array: %s",STR_OR_BLANK(json_string));
FREE_AND_NULL(json_string);
cJSON_ArrayForEach(kvp, config_array){
cJSON * kvp_value=kvp->child;
if(!kvp_value){
printf("config entry is not an object!\n");
err=ESP_FAIL;
continue;
}
char * key = kvp_value->string;
char * value = kvp_value->valuestring;
if(!key || !value || strlen(key)==0){
printf("Invalid config entry %s:%s\n",STR_OR_BLANK(key),STR_OR_BLANK(value));
err=ESP_FAIL;
continue;
}
fprintf(f,"Storing %s=%s\n",key,value);
err = config_set_value(NVS_TYPE_STR,key,value);
if(err){
fprintf(f,"Failed to store config value: %s\n",esp_err_to_name(err));
break;
}
}
}
else {
json_string = cJSON_Print(config_array);
char * known_item_string = cJSON_Print(known_item);
fprintf(f,"Failed to parse config array. %s\n%s\nKnown item found: %s\n",config_array?cJSON_IsArray(config_array)?"":"NOT AN ARRAY":"config entry not found",STR_OR_BLANK(json_string),STR_OR_BLANK(known_item_string));
FREE_AND_NULL(json_string);
FREE_AND_NULL(known_item_string);
err = ESP_FAIL;
}
if(err==ESP_OK){
err = config_set_value(NVS_TYPE_STR,"board_model",name);
if(err!=ESP_OK){
fprintf(f,"Failed to save board model %s\n",name);
}
}
return err;
}
static int do_register_known_templates_config(int argc, char **argv){
esp_err_t err=ESP_OK;
int nerrors = arg_parse(argc, argv,(void **)&known_model_args);
char *buf = NULL;
size_t buf_size = 0;
cJSON * config_name =NULL;
FILE *f = open_memstream(&buf, &buf_size);
if (f == NULL) {
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
return 1;
}
if(nerrors >0){
arg_print_errors(f,known_model_args.end,desc_preset);
}
else {
ESP_LOGD(TAG,"arg: %s",STR_OR_BLANK(known_model_args.model_config->sval[0]));
char * model_config = strdup_psram(known_model_args.model_config->sval[0]);
char * t = model_config;
for(const char * p=known_model_args.model_config->sval[0];*p;p++){
if(*p=='\\' && *(p+1)=='"'){
*t++='"';
p++;
}
else {
*t++=*p;
}
}
*t=0;
cJSON * known_item = cJSON_Parse(model_config);
if(known_item){
ESP_LOGD(TAG,"Parsing success");
config_name= cJSON_GetObjectItem(known_item,"name");
if(!config_name || !cJSON_IsString(config_name) || strlen(config_name->valuestring)==0){
fprintf(f,"Failed to find name in config\n");
err=ESP_FAIL;
nerrors++;
}
if(nerrors==0){
const char * name = cJSON_GetStringValue(config_name);
nerrors+=(err = save_known_config(known_item,name,f)!=ESP_OK);
if(nerrors==0){
const i2s_platform_config_t * i2s_config= config_dac_get();
if(i2s_config->scl!=-1 && i2s_config->sda!=-1 && GPIO_IS_VALID_GPIO(i2s_config->scl) && GPIO_IS_VALID_GPIO(i2s_config->sda)){
fprintf(f,"Scanning i2c bus for devices\n");
cmd_i2ctools_scan_bus(f,i2s_config->sda, i2s_config->scl);
}
}
}
cJSON_Delete(known_item);
}
else {
ESP_LOGE(TAG,"Parsing error: %s",cJSON_GetErrorPtr());
fprintf(f,"Failed to parse JSON: %s\n",cJSON_GetErrorPtr());
err=ESP_FAIL;
}
if(err!=ESP_OK){
nerrors++;
fprintf(f,"Error registering known config %s.\n",known_model_args.model_config->sval[0]);
}
else {
fprintf(f,"Registered known config %s.\n",known_model_args.model_config->sval[0]);
}
}
if(!nerrors ){
fprintf(f,"Done.\n");
}
fflush (f);
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
fclose(f);
FREE_AND_NULL(buf);
return (nerrors==0 && err==ESP_OK)?0:1;
}
static void register_known_templates_config(){
known_model_args.model_config = arg_str1(NULL,"model_config","SqueezeAMP|T-WATCH2020 by LilyGo","Known Board Name.\nFor known boards, several systems parameters will be updated");
known_model_args.end = arg_end(1);
const esp_console_cmd_t cmd = {
.command = CFG_TYPE_HW("preset"),
.help = desc_preset,
.hint = NULL,
.func = &do_register_known_templates_config,
.argtable = &known_model_args
};
cmd_to_json_with_cb(&cmd,&known_model_cb);
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
}
static void register_cspot_config(){
cspot_args.deviceName = arg_str1(NULL,"deviceName","","Device Name");
cspot_args.bitrate = arg_int1(NULL,"bitrate","96|160|320","Streaming Bitrate (kbps)");
// cspot_args.volume = arg_int1(NULL,"volume","","Spotify Volume");
cspot_args.end = arg_end(1);
const esp_console_cmd_t cmd = {
.command = CFG_TYPE_SYST("cspot"),
.help = desc_cspotc,
.hint = NULL,
.func = &do_cspot_config,
.argtable = &cspot_args
};
cmd_to_json_with_cb(&cmd,&cspot_cb);
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
}
static void register_i2s_config(void){
i2s_args.model_name = arg_str1(NULL,"model_name","TAS57xx|TAS5713|AC101|WM8978|I2S","DAC Model Name");
i2s_args.model_name = arg_str1(NULL,"model_name",STR_OR_BLANK(get_dac_list()),"DAC Model Name");
i2s_args.clear = arg_lit0(NULL, "clear", "Clear configuration");
i2s_args.clock = arg_int1(NULL,"clock","<n>","Clock GPIO. e.g. 33");
i2s_args.wordselect = arg_int1(NULL,"wordselect","<n>","Word Select GPIO. e.g. 25");
i2s_args.data = arg_int1(NULL,"data","<n>","Data GPIO. e.g. 32");
i2s_args.clock = arg_int0(NULL,"clock","<n>","Clock GPIO. e.g. 33");
i2s_args.wordselect = arg_int0(NULL,"wordselect","<n>","Word Select GPIO. e.g. 25");
i2s_args.data = arg_int0(NULL,"data","<n>","Data GPIO. e.g. 32");
i2s_args.mute_gpio = arg_int0(NULL,"mute_gpio", "<n>", "Mute GPIO. e.g. 14");
i2s_args.mute_level = arg_lit0(NULL,"mute_level","Mute GPIO level. Checked=HIGH, Unchecked=LOW");
i2s_args.dac_sda = arg_int0(NULL,"dac_sda", "<n>", "SDA GPIO. e.g. 27");
@@ -919,6 +1239,7 @@ static void register_rotary_config(void){
rotary_args.volume_lock = arg_lit0(NULL,"volume_lock", "Force Volume down/up/play toggle all the time (even in LMS). ");
rotary_args.longpress = arg_lit0(NULL,"longpress","Enable alternate mode mode on long-press. In that mode, left is previous, right is next and press is toggle. Every long press on SW alternates between modes (the main mode actual behavior depends on 'volume').");
rotary_args.clear = arg_lit0(NULL, "clear", "Clear configuration");
rotary_args.raw_mode = arg_lit0(NULL, "raw_mode", "Send button events as raw values to LMS. No remapping is possible when this is enabled");
rotary_args.end = arg_end(3);
const esp_console_cmd_t cmd = {
.command = CFG_TYPE_HW("rotary"),
@@ -1005,6 +1326,10 @@ static void register_squeezelite_config(void){
}
void register_config_cmd(void){
if(!is_dac_config_locked()){
register_known_templates_config();
}
register_cspot_config();
register_audio_config();
// register_squeezelite_config();
register_bt_source_config();

View File

@@ -6,7 +6,6 @@
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
//#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#include <stdio.h>
#include "cmd_i2ctools.h"
#include "argtable3/argtable3.h"
@@ -21,6 +20,8 @@
#include "messaging.h"
#include "display.h"
#include "config.h"
#include "tools.h"
#include "adac.h"
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
@@ -99,6 +100,7 @@ static struct {
struct arg_int *back;
struct arg_int *reset;
struct arg_lit *clear;
struct arg_lit *invert;
struct arg_end *end;
} i2cdisp_args;
@@ -123,124 +125,131 @@ bool is_i2c_started(i2c_port_t port){
typedef struct {
uint8_t address;
char * description;
const char * description;
} i2c_db_t;
// the list was taken from https://i2cdevices.org/addresses
// on 2020-01-16
static const i2c_db_t i2c_db[] = {
{ .address = 0x00, .description = "Unknown"},
{ .address = 0x01, .description = "Unknown"},
{ .address = 0x02, .description = "Unknown"},
{ .address = 0x03, .description = "Unknown"},
{ .address = 0x04, .description = "Unknown"},
{ .address = 0x05, .description = "Unknown"},
{ .address = 0x06, .description = "Unknown"},
{ .address = 0x07, .description = "Unknown"},
{ .address = 0x0c, .description = "AK8975"},
{ .address = 0x0d, .description = "AK8975"},
{ .address = 0x0e, .description = "MAG3110 AK8975 IST-8310"},
{ .address = 0x0f, .description = "AK8975"},
{ .address = 0x10, .description = "VEML7700 VML6075"},
{ .address = 0x11, .description = "Si4713 SAA5246 SAA5243P/K SAA5243P/L SAA5243P/E SAA5243P/H"},
{ .address = 0x13, .description = "VCNL40x0"},
{ .address = 0x18, .description = "MCP9808 LIS3DH LSM303"},
{ .address = 0x19, .description = "MCP9808 LIS3DH LSM303"},
{ .address = 0x1a, .description = "MCP9808"},
{ .address = 0x1b, .description = "MCP9808"},
{ .address = 0x1c, .description = "MCP9808 MMA845x FXOS8700"},
{ .address = 0x1d, .description = "MCP9808 MMA845x ADXL345 FXOS8700"},
{ .address = 0x1e, .description = "MCP9808 FXOS8700 HMC5883 LSM303 LSM303"},
{ .address = 0x1f, .description = "MCP9808 FXOS8700"},
{ .address = 0x20, .description = "FXAS21002 MCP23008 MCP23017 Chirp!"},
{ .address = 0x21, .description = "FXAS21002 MCP23008 MCP23017 SAA4700"},
{ .address = 0x22, .description = "MCP23008 MCP23017 PCA1070"},
{ .address = 0x23, .description = "MCP23008 MCP23017 SAA4700"},
{ .address = 0x24, .description = "MCP23008 MCP23017 PCD3311C PCD3312C"},
{ .address = 0x25, .description = "MCP23008 MCP23017 PCD3311C PCD3312C"},
{ .address = 0x26, .description = "MCP23008 MCP23017"},
{ .address = 0x27, .description = "MCP23008 MCP23017"},
{ .address = 0x28, .description = "BNO055 CAP1188"},
{ .address = 0x29, .description = "BNO055 CAP1188 TCS34725 TSL2591 VL53L0x VL6180X"},
{ .address = 0x2a, .description = "CAP1188"},
{ .address = 0x2b, .description = "CAP1188"},
{ .address = 0x2c, .description = "CAP1188 AD5248 AD5251 AD5252 CAT5171"},
{ .address = 0x2d, .description = "CAP1188 AD5248 AD5251 AD5252 CAT5171"},
{ .address = 0x2e, .description = "AD5248 AD5251 AD5252"},
{ .address = 0x2f, .description = "AD5248 AD5243 AD5251 AD5252"},
{ .address = 0x30, .description = "SAA2502"},
{ .address = 0x31, .description = "SAA2502"},
{ .address = 0x38, .description = "FT6x06 VEML6070 BMA150 SAA1064"},
{ .address = 0x39, .description = "TSL2561 APDS-9960 VEML6070 SAA1064"},
{ .address = 0x3a, .description = "PCF8577C SAA1064"},
{ .address = 0x3b, .description = "SAA1064 PCF8569"},
{ .address = 0x3c, .description = "SSD1305 SSD1306 PCF8578 PCF8569 SH1106"},
{ .address = 0x3d, .description = "SSD1305 SSD1306 PCF8578 SH1106"},
{ .address = 0x40, .description = "HTU21D-F TMP007 PCA9685 NE5751 TDA8421 INA260 TEA6320 TEA6330 TMP006 TEA6300 Si7021 INA219 TDA9860"},
{ .address = 0x41, .description = "TMP007 PCA9685 STMPE811 TDA8424 NE5751 TDA8421 INA260 STMPE610 TDA8425 TMP006 INA219 TDA9860 TDA8426"},
{ .address = 0x42, .description = "HDC1008 TMP007 TMP006 PCA9685 INA219 TDA8415 TDA8417 INA260"},
{ .address = 0x43, .description = "HDC1008 TMP007 TMP006 PCA9685 INA219 INA260"},
{ .address = 0x44, .description = "TMP007 TMP006 PCA9685 INA219 STMPE610 SHT31 ISL29125 STMPE811 TDA4688 TDA4672 TDA4780 TDA4670 TDA8442 TDA4687 TDA4671 TDA4680 INA260"},
{ .address = 0x45, .description = "TMP007 TMP006 PCA9685 INA219 SHT31 TDA8376 INA260"},
{ .address = 0x46, .description = "TMP007 TMP006 PCA9685 INA219 TDA9150 TDA8370 INA260"},
{ .address = 0x47, .description = "TMP007 TMP006 PCA9685 INA219 INA260"},
{ .address = 0x48, .description = "PCA9685 INA219 PN532 TMP102 INA260 ADS1115"},
{ .address = 0x49, .description = "TSL2561 PCA9685 INA219 TMP102 INA260 ADS1115 AS7262"},
{ .address = 0x4a, .description = "PCA9685 INA219 TMP102 ADS1115 MAX44009 INA260"},
{ .address = 0x4b, .description = "PCA9685 INA219 TMP102 ADS1115 MAX44009 INA260"},
{ .address = 0x4c, .description = "PCA9685 INA219 INA260"},
{ .address = 0x4d, .description = "PCA9685 INA219 INA260"},
{ .address = 0x4e, .description = "PCA9685 INA219 INA260"},
{ .address = 0x4f, .description = "PCA9685 INA219 INA260"},
{ .address = 0x50, .description = "PCA9685 MB85RC"},
{ .address = 0x51, .description = "PCA9685 MB85RC"},
{ .address = 0x52, .description = "PCA9685 MB85RC Nunchuck controller APDS-9250"},
{ .address = 0x53, .description = "ADXL345 PCA9685 MB85RC"},
{ .address = 0x54, .description = "PCA9685 MB85RC"},
{ .address = 0x55, .description = "PCA9685 MB85RC"},
{ .address = 0x56, .description = "PCA9685 MB85RC"},
{ .address = 0x57, .description = "PCA9685 MB85RC MAX3010x"},
{ .address = 0x58, .description = "PCA9685 TPA2016 SGP30"},
{ .address = 0x59, .description = "PCA9685"},
{ .address = 0x5a, .description = "PCA9685 CCS811 MLX90614 DRV2605 MPR121"},
{ .address = 0x5b, .description = "PCA9685 CCS811 MPR121"},
{ .address = 0x5c, .description = "PCA9685 AM2315 MPR121"},
{ .address = 0x5d, .description = "PCA9685 MPR121"},
{ .address = 0x5e, .description = "PCA9685"},
{ .address = 0x5f, .description = "PCA9685 HTS221"},
{ .address = 0x60, .description = "PCA9685 MPL115A2 MPL3115A2 Si5351A Si1145 MCP4725A0 TEA5767 TSA5511 SAB3037 SAB3035 MCP4725A1"},
{ .address = 0x61, .description = "PCA9685 Si5351A MCP4725A0 TEA6100 TSA5511 SAB3037 SAB3035 MCP4725A1"},
{ .address = 0x62, .description = "PCA9685 MCP4725A1 TSA5511 SAB3037 SAB3035 UMA1014T"},
{ .address = 0x63, .description = "Si4713 PCA9685 MCP4725A1 TSA5511 SAB3037 SAB3035 UMA1014T"},
{ .address = 0x64, .description = "PCA9685 MCP4725A2 MCP4725A1"},
{ .address = 0x65, .description = "PCA9685 MCP4725A2 MCP4725A1"},
{ .address = 0x66, .description = "PCA9685 MCP4725A3 IS31FL3731 MCP4725A1"},
{ .address = 0x67, .description = "PCA9685 MCP4725A3 MCP4725A1"},
{ .address = 0x68, .description = "PCA9685 AMG8833 DS1307 PCF8523 DS3231 MPU-9250 ITG3200 PCF8573 MPU6050"},
{ .address = 0x69, .description = "PCA9685 AMG8833 MPU-9250 ITG3200 PCF8573 SPS30 MPU6050"},
{ .address = 0x6a, .description = "PCA9685 L3GD20H PCF8573"},
{ .address = 0x6b, .description = "PCA9685 L3GD20H PCF8573"},
{ .address = 0x6c, .description = "PCA9685"},
{ .address = 0x6d, .description = "PCA9685"},
{ .address = 0x6e, .description = "PCA9685"},
{ .address = 0x6f, .description = "PCA9685"},
{ .address = 0x70, .description = "PCA9685 TCA9548 HT16K33"},
{ .address = 0x71, .description = "PCA9685 TCA9548 HT16K33"},
{ .address = 0x72, .description = "PCA9685 TCA9548 HT16K33"},
{ .address = 0x73, .description = "PCA9685 TCA9548 HT16K33"},
{ .address = 0x74, .description = "PCA9685 TCA9548 HT16K33"},
{ .address = 0x75, .description = "PCA9685 TCA9548 HT16K33"},
{ .address = 0x76, .description = "PCA9685 TCA9548 HT16K33 BME280 BMP280 MS5607 MS5611 BME680"},
{ .address = 0x77, .description = "PCA9685 TCA9548 HT16K33 IS31FL3731 BME280 BMP280 MS5607 BMP180 BMP085 BMA180 MS5611 BME680"},
{ .address = 0x78, .description = "PCA9685"},
{ .address = 0x79, .description = "PCA9685"},
{ .address = 0x7a, .description = "PCA9685"},
{ .address = 0x7b, .description = "PCA9685"},
{ .address = 0x7c, .description = "PCA9685"},
{ .address = 0x7d, .description = "PCA9685"},
{ .address = 0x7e, .description = "PCA9685"},
{ .address = 0x7f, .description = "PCA9685"},
{ .address = 0x00, .description="Unknown"},
{ .address = 0x01, .description="Unknown"},
{ .address = 0x02, .description="Unknown"},
{ .address = 0x03, .description="Unknown"},
{ .address = 0x04, .description="Unknown"},
{ .address = 0x05, .description="Unknown"},
{ .address = 0x06, .description="Unknown"},
{ .address = 0x07, .description="Unknown"},
{ .address = 0x08, .description="Unknown"},
{ .address = 0x0c, .description="AK8975"},
{ .address = 0x0d, .description="AK8975"},
{ .address = 0x0e, .description="MAG3110 AK8975 IST-8310"},
{ .address = 0x0f, .description="AK8975"},
{ .address = 0x10, .description="VEML7700 VML6075 VEML6075"},
{ .address = 0x11, .description="Si4713 SAA5246 SAA5243P/K SAA5243P/L SAA5243P/E SAA5243P/H"},
{ .address = 0x12, .description="SEN-17374"},
{ .address = 0x13, .description="VCNL40x0 SEN-17374"},
{ .address = 0x18, .description="MCP9808 LIS3DH LSM303 COM-15093"},
{ .address = 0x19, .description="MCP9808 LIS3DH LSM303 COM-15093"},
{ .address = 0x20, .description="ES8388"},
{ .address = 0x1a, .description="AC101 MCP9808"},
{ .address = 0x1b, .description="MCP9808"},
{ .address = 0x1c, .description="MCP9808 MMA845x FXOS8700"},
{ .address = 0x1d, .description="MCP9808 MMA845x ADXL345 FXOS8700"},
{ .address = 0x1e, .description="HMC5883 LSM303 MCP9808 LSM303 FXOS8700"},
{ .address = 0x1f, .description="MCP9808 FXOS8700"},
{ .address = 0x20, .description="TCA9554 MCP23008 MA12070P MCP23017 Chirp! FXAS21002"},
{ .address = 0x21, .description="FXAS21002 MCP23008 MCP23017 SAA4700 MA12070P TCA9554"},
{ .address = 0x22, .description="ES8388 MCP23008 MCP23017 PCA1070 MA12070P TCA9554"},
{ .address = 0x23, .description="MCP23008 MCP23017 SAA4700 MA12070P TCA9554"},
{ .address = 0x24, .description="TCA9554 MCP23008 PCD3312C MCP23017 PCD3311C"},
{ .address = 0x25, .description="TCA9554 MCP23008 PCD3312C MCP23017 PCD3311C"},
{ .address = 0x26, .description="MCP23008 MCP23017 TCA9554"},
{ .address = 0x27, .description="MCP23008 MCP23017 HIH6130 TCA9554"},
{ .address = 0x28, .description="BNO055 CAP1188"},
{ .address = 0x29, .description="BNO055 VL53L0x VL6180X CAP1188 TCS34725 TSL2591"},
{ .address = 0x2a, .description="CAP1188"},
{ .address = 0x2b, .description="CAP1188"},
{ .address = 0x2c, .description="CAP1188 AD5248 AD5251 AD5252 CAT5171"},
{ .address = 0x2d, .description="CAP1188 AD5248 AD5251 AD5252 CAT5171"},
{ .address = 0x2e, .description="AD5248 AD5251 AD5252 LPS22HB"},
{ .address = 0x2f, .description="AD5248 AD5243 AD5251 AD5252"},
{ .address = 0x30, .description="SAA2502"},
{ .address = 0x31, .description="SAA2502"},
{ .address = 0x33, .description="MLX90640"},
{ .address = 0x38, .description="FT6x06 VEML6070 BMA150 SAA1064 SEN-15892 PCF8574AP"},
{ .address = 0x39, .description="TSL2561 APDS-9960 VEML6070 SAA1064 PCF8574AP"},
{ .address = 0x3a, .description="PCF8577C SAA1064 PCF8574AP"},
{ .address = 0x3b, .description="SAA1064 PCF8569 PCF8574AP"},
{ .address = 0x3c, .description="SSD1305 SSD1306 PCF8578 PCF8569 SH1106 PCF8574AP"},
{ .address = 0x3d, .description="SSD1305 SSD1306 PCF8578 SH1106 PCF8574AP"},
{ .address = 0x3e, .description="PCF8574AP"},
{ .address = 0x3f, .description="PCF8574AP"},
{ .address = 0x40, .description="Si7021 HTU21D-F TMP007 TMP006 PCA9685 INA219 TEA6330 TEA6300 TDA9860 TEA6320 TDA8421 NE5751 INA260 PCF8574"},
{ .address = 0x41, .description="TMP007 TDA8421 TDA8424 STMPE610 PCF8574 STMPE811 NE5751 INA260 TDA8425 TMP006 TDA9860 PCA9685 INA219 TDA8426"},
{ .address = 0x42, .description="TMP007 TDA8417 HDC1008 PCF8574 INA260 TDA8415 TMP006 PCA9685 INA219"},
{ .address = 0x43, .description="TMP007 HDC1008 PCF8574 INA260 TMP006 PCA9685 INA219"},
{ .address = 0x44, .description="TMP007 TMP006 PCA9685 INA219 STMPE610 SHT31 ISL29125 STMPE811 TDA4688 TDA4672 TDA4780 TDA4670 TDA8442 TDA4687 TDA4671 TDA4680 INA260 PCF8574"},
{ .address = 0x45, .description="TMP007 TDA7433 PCF8574 TDA8376 INA260 TMP006 PCA9685 INA219 SHT31"},
{ .address = 0x46, .description="TMP007 PCF8574 TDA8370 INA260 TMP006 PCA9685 INA219 TDA9150"},
{ .address = 0x47, .description="TMP007 PCF8574 INA260 TMP006 PCA9685 INA219"},
{ .address = 0x48, .description="PCA9685 INA219 PN532 TMP102 INA260 ADS1115 PCF8574 ADS7828"},
{ .address = 0x49, .description="TSL2561 PCA9685 INA219 TMP102 INA260 ADS1115 AS7262 PCF8574 ADS7828"},
{ .address = 0x4a, .description="ADS7828 PCF8574 ADS1115 INA260 PCA9685 MAX44009 INA219 TMP102"},
{ .address = 0x4b, .description="ADS7828 PCF8574 ADS1115 INA260 PCA9685 MAX44009 INA219 TMP102"},
{ .address = 0x4c, .description="PCA9685 INA219 INA260 PCF8574"},
{ .address = 0x4d, .description="PCA9685 INA219 INA260 PCF8574"},
{ .address = 0x4e, .description="PCA9685 INA219 INA260 PCF8574"},
{ .address = 0x4f, .description="PCA9685 INA219 INA260 PCF8574"},
{ .address = 0x50, .description="PCA9685 MB85RC"},
{ .address = 0x51, .description="PCA9685 MB85RC VCNL4200"},
{ .address = 0x52, .description="PCA9685 MB85RC Nunchuck controller APDS-9250 SI1133"},
{ .address = 0x53, .description="ADXL345 PCA9685 MB85RC"},
{ .address = 0x54, .description="PCA9685 MB85RC"},
{ .address = 0x55, .description="PCA9685 MB85RC MAX30101 SI1133"},
{ .address = 0x56, .description="PCA9685 MB85RC"},
{ .address = 0x57, .description="PCA9685 MB85RC MAX3010x"},
{ .address = 0x58, .description="PCA9685 TPA2016 SGP30"},
{ .address = 0x59, .description="PCA9685"},
{ .address = 0x5a, .description="MPR121 MLX90614 CCS811 PCA9685 DRV2605"},
{ .address = 0x5b, .description="PCA9685 CCS811 MPR121"},
{ .address = 0x5c, .description="PCA9685 AM2315 MPR121"},
{ .address = 0x5d, .description="PCA9685 MPR121"},
{ .address = 0x5e, .description="PCA9685"},
{ .address = 0x5f, .description="PCA9685 HTS221"},
{ .address = 0x60, .description="SI1132 Si5351A ATECC608A TSA5511 ATECC508A SAB3035 MCP4725A0 SAB3037 PCA9685 MCP4725A1 TEA5767 MPL3115A2 MPL115A2 Si1145"},
{ .address = 0x61, .description="Si5351A TSA5511 SAB3035 MCP4725A0 SAB3037 TEA6100 PCA9685 MCP4725A1"},
{ .address = 0x62, .description="SCD40-D-R2 TSA5511 SAB3035 UMA1014T SAB3037 PCA9685 MCP4725A1"},
{ .address = 0x63, .description="Si4713 TSA5511 SAB3035 UMA1014T SAB3037 PCA9685 MCP4725A1"},
{ .address = 0x64, .description="PCA9685 MCP4725A2 MCP4725A1"},
{ .address = 0x65, .description="PCA9685 MCP4725A2 MCP4725A1"},
{ .address = 0x66, .description="PCA9685 MCP4725A3 IS31FL3731 MCP4725A1"},
{ .address = 0x67, .description="PCA9685 MCP4725A3 MCP4725A1"},
{ .address = 0x68, .description="MPU-9250 ICM-20948 MPU6050 AMG8833 DS3231 PCA9685 PCF8573 PCF8523 DS1307 ITG3200"},
{ .address = 0x69, .description="MPU-9250 ICM-20948 MPU6050 AMG8833 PCA9685 PCF8573 ITG3200 SPS30"},
{ .address = 0x6a, .description="PCA9685 L3GD20H PCF8573"},
{ .address = 0x6b, .description="PCA9685 L3GD20H PCF8573"},
{ .address = 0x6c, .description="PCA9685"},
{ .address = 0x6d, .description="PCA9685"},
{ .address = 0x6e, .description="PCA9685"},
{ .address = 0x6f, .description="PCA9685 MCP7940N"},
{ .address = 0x70, .description="PCA9685 TCA9548 HT16K33 SHTC3"},
{ .address = 0x71, .description="PCA9685 TCA9548 HT16K33"},
{ .address = 0x72, .description="PCA9685 TCA9548 HT16K33"},
{ .address = 0x73, .description="PCA9685 TCA9548 HT16K33"},
{ .address = 0x74, .description="PCA9685 TCA9548 HT16K33"},
{ .address = 0x75, .description="PCA9685 TCA9548 HT16K33"},
{ .address = 0x76, .description="BME688 BME680 MS5611 MS5607 HT16K33 PCA9685 BME280 BMP280 TCA9548"},
{ .address = 0x77, .description="PCA9685 TCA9548 HT16K33 IS31FL3731 BME280 BMP280 MS5607 BMP180 BMP085 BMA180 MS5611 BME680 BME688"},
{ .address = 0x78, .description="PCA9685"},
{ .address = 0x79, .description="PCA9685"},
{ .address = 0x7a, .description="PCA9685"},
{ .address = 0x7b, .description="PCA9685"},
{ .address = 0x7c, .description="PCA9685"},
{ .address = 0x7d, .description="PCA9685"},
{ .address = 0x7e, .description="PCA9685"},
{ .address = 0x7f, .description="PCA9685"},
{ .address = 0, .description = NULL}
};
@@ -400,6 +409,7 @@ static int do_i2c_set_display(int argc, char **argv)
config.rotate = i2cdisp_args.rotate->count>0;
config.hflip = i2cdisp_args.hflip->count>0;
config.vflip = i2cdisp_args.vflip->count>0;
config.invert = i2cdisp_args.invert->count>0;
if(nerrors==0){
fprintf(f,"Saving display configuration\n");
@@ -754,7 +764,7 @@ static int do_i2cget_cmd(int argc, char **argv)
}
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
uint8_t *data = malloc(len);
uint8_t *data = malloc_init_external(len);
if (data_addr != -1) {
i2c_master_write_byte(cmd, chip_addr << 1 | WRITE_BIT, ACK_CHECK_EN);
i2c_master_write_byte(cmd, data_addr, ACK_CHECK_EN);
@@ -793,7 +803,67 @@ static int do_i2cget_cmd(int argc, char **argv)
FREE_AND_NULL(buf);
return 0;
}
esp_err_t cmd_i2ctools_scan_bus(FILE *f,int sda, int scl){
uint8_t matches[128]={};
int last_match=0;
esp_err_t ret = ESP_OK;
if(!GPIO_IS_VALID_GPIO(scl) || !GPIO_IS_VALID_GPIO(sda)){
fprintf(f,"Invalid GPIO. Cannot scan bus\n");
return 1;
}
// configure i2c
i2c_config_t i2c_config = {
.mode = I2C_MODE_MASTER,
.sda_io_num = -1,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_io_num = -1,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = 250000,
};
i2c_config.sda_io_num = sda;
i2c_config.scl_io_num = scl;
// we have an I2C configured
i2c_port_t i2c_port = 0;
// make sure that we don't have an i2c driver running
i2c_driver_delete(i2c_port);
ret = i2c_param_config(i2c_port, &i2c_config);
if (ret != ESP_OK) {
fprintf(f,"I2C Param Config failed %s\n", esp_err_to_name(ret));
return ret;
}
ret=i2c_driver_install(i2c_port, I2C_MODE_MASTER, false, false, false);
if (ret != ESP_OK) {
fprintf(f,"I2C driver install failed %s\n", esp_err_to_name(ret));
return ret;
}
for (int i = 0; i < 128 ; i ++) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (i << 1) | WRITE_BIT, ACK_CHECK_EN);
i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(i2c_port, cmd, 50 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
if (ret == ESP_OK) {
matches[++last_match-1] = i;
}
}
i2c_driver_delete(i2c_port);
if(last_match) {
fprintf(f,"i2c device detected (names provided by https://i2cdevices.org/addresses).\n");
for(int i=0;i<last_match;i++){
fprintf(f,"%u [%02xh]- %s\n", matches[i], matches[i], i2c_get_description(matches[i]));
}
}
else {
fprintf(f,"No i2c devices found with scl-%d and sda-%d\n",scl,sda);
}
return 0;
}
static int do_i2cdetect_cmd(int argc, char **argv)
{
uint8_t matches[128]={};
@@ -893,7 +963,7 @@ cJSON * i2c_set_display_cb(){
cJSON_AddBoolToObject(values,"rotate",conf->rotate);
cJSON_AddBoolToObject(values,"hf",conf->hflip);
cJSON_AddBoolToObject(values,"vf",conf->vflip);
cJSON_AddBoolToObject(values,"invert",conf->invert);
}
return values;
}
@@ -914,6 +984,7 @@ static void register_i2c_set_display(){
i2cdisp_args.depth = arg_int0("p", "depth", "-1|1|4", "Bit Depth (only for SSD1326 displays)");
i2cdisp_args.type = arg_str0("t", "type", "<I2C|SPI>", "Interface (default I2C)");
i2cdisp_args.rotate = arg_lit0("r", "rotate", "Rotate 180 degrees");
i2cdisp_args.invert = arg_lit0("i", "invert", "Invert colors");
i2cdisp_args.clear = arg_lit0(NULL, "clear", "clear configuration and return");
i2cdisp_args.end = arg_end(8);
const esp_console_cmd_t i2c_set_display= {

View File

@@ -8,13 +8,13 @@
*/
#pragma once
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
void register_i2ctools(void);
esp_err_t cmd_i2ctools_scan_bus(FILE *f,int sda, int scl);
#ifdef __cplusplus
}
#endif

View File

@@ -6,7 +6,6 @@
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
//#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
#ifdef __cplusplus
extern "C" {
#endif
@@ -27,41 +26,50 @@ extern "C" {
#include "nvs_utilities.h"
#include "platform_console.h"
#include "messaging.h"
#include "tools.h"
#include "trace.h"
extern esp_err_t network_wifi_erase_legacy();
extern esp_err_t network_wifi_erase_known_ap();
static const char *ARG_TYPE_STR = "type can be: i8, u8, i16, u16 i32, u32 i64, u64, str, blob";
static const char * TAG = "cmd_nvs";
static struct {
EXT_RAM_ATTR static struct {
struct arg_str *key;
struct arg_str *type;
struct arg_str *value;
struct arg_end *end;
} set_args;
static struct {
EXT_RAM_ATTR static struct {
struct arg_str *key;
struct arg_str *type;
struct arg_end *end;
} get_args;
static struct {
EXT_RAM_ATTR static struct {
struct arg_str *key;
struct arg_end *end;
} erase_args;
static struct {
EXT_RAM_ATTR static struct {
struct arg_str *namespace;
struct arg_end *end;
} erase_all_args;
static struct {
EXT_RAM_ATTR static struct {
struct arg_str *partition;
struct arg_str *namespace;
struct arg_str *type;
struct arg_end *end;
} list_args;
EXT_RAM_ATTR static struct {
struct arg_lit *legacy;
struct arg_lit *ap_list;
struct arg_end *end;
} wifi_erase_args;
static esp_err_t store_blob(nvs_handle nvs, const char *key, const char *str_values)
@@ -75,7 +83,7 @@ static esp_err_t store_blob(nvs_handle nvs, const char *key, const char *str_val
return ESP_ERR_NVS_TYPE_MISMATCH;
}
char *blob = (char *)malloc(blob_len);
char *blob = (char *)malloc_init_external(blob_len);
if (blob == NULL) {
return ESP_ERR_NO_MEM;
}
@@ -261,7 +269,7 @@ static esp_err_t get_value_from_nvs(const char *key, const char *str_type)
} else if (type == NVS_TYPE_STR) {
size_t len=0;
if ( (err = nvs_get_str(nvs, key, NULL, &len)) == ESP_OK) {
char *str = (char *)malloc(len);
char *str = (char *)malloc_init_external(len);
if ( (err = nvs_get_str(nvs, key, str, &len)) == ESP_OK) {
log_send_messaging(MESSAGING_INFO,"String associated with key '%s' is %s \n", key, str);
}
@@ -270,7 +278,7 @@ static esp_err_t get_value_from_nvs(const char *key, const char *str_type)
} else if (type == NVS_TYPE_BLOB) {
size_t len;
if ( (err = nvs_get_blob(nvs, key, NULL, &len)) == ESP_OK) {
char *blob = (char *)malloc(len);
char *blob = (char *)malloc_init_external(len);
if ( (err = nvs_get_blob(nvs, key, blob, &len)) == ESP_OK) {
log_send_messaging(MESSAGING_INFO,"Blob associated with key '%s' is %d bytes long: \n", key, len);
print_blob(blob, len);
@@ -399,7 +407,7 @@ static int erase_namespace(int argc, char **argv)
return 0;
}
static int erase_wifi_manager(int argc, char **argv)
static int erase_network_manager(int argc, char **argv)
{
nvs_handle nvs;
esp_err_t err = nvs_open("config", NVS_READWRITE, &nvs);
@@ -411,15 +419,49 @@ static int erase_wifi_manager(int argc, char **argv)
}
nvs_close(nvs);
if (err != ESP_OK) {
cmd_send_messaging(argv[0],MESSAGING_ERROR, "wifi manager configuration was not erase. %s", esp_err_to_name(err));
cmd_send_messaging(argv[0],MESSAGING_ERROR, "System configuration was not erased. %s", esp_err_to_name(err));
return 1;
}
else {
cmd_send_messaging(argv[0],MESSAGING_WARNING, "Wifi manager configuration was erased");
cmd_send_messaging(argv[0],MESSAGING_WARNING, "system configuration was erased. Please reboot.");
}
return 0;
}
static int wifi_erase_config(int argc, char **argv)
{
esp_err_t err=ESP_OK;
esp_err_t err_ap_list=ESP_OK;
bool done = false;
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&wifi_erase_args);
if (nerrors != 0) {
return 1;
}
if(wifi_erase_args.ap_list->count>0){
err_ap_list = network_wifi_erase_known_ap();
if (err_ap_list != ESP_OK) {
cmd_send_messaging(argv[0],MESSAGING_ERROR, "Could not erase legacy wifi configuration: %s", esp_err_to_name(err));
}
else {
cmd_send_messaging(argv[0],MESSAGING_ERROR, "Legacy wifi configuration was erased");
}
done = true;
}
if(wifi_erase_args.legacy->count>0){
err = network_wifi_erase_legacy();
if (err != ESP_OK) {
cmd_send_messaging(argv[0],MESSAGING_ERROR, "Could not erase known ap list : %s", esp_err_to_name(err));
}
else {
cmd_send_messaging(argv[0],MESSAGING_ERROR, "Known access point list was erased");
}
done = true;
}
if(!done){
cmd_send_messaging(argv[0],MESSAGING_WARNING, "Please specify at least one configuration type to erase.", esp_err_to_name(err));
}
return (err_ap_list==ESP_OK && err==ESP_OK)?0:1;
}
static int list(const char *part, const char *name, const char *str_type)
{
@@ -476,6 +518,10 @@ void register_nvs()
erase_all_args.namespace = arg_str1(NULL, NULL, "<namespace>", "namespace to be erased");
erase_all_args.end = arg_end(2);
wifi_erase_args.ap_list = arg_lit0("a","ap_list","Erases Known access points list");
wifi_erase_args.legacy = arg_lit0("l","legacy","Erases legacy access point storage");
wifi_erase_args.end = arg_end(1);
list_args.partition = arg_str1(NULL, NULL, "<partition>", "partition name");
list_args.namespace = arg_str0("n", "namespace", "<namespace>", "namespace name");
list_args.type = arg_str0("t", "type", "<type>", ARG_TYPE_STR);
@@ -516,11 +562,19 @@ void register_nvs()
.func = &erase_namespace,
.argtable = &erase_all_args
};
const esp_console_cmd_t erase_wifimanager_cmd = {
.command = "nvs_erase_wifi_manager",
.help = "Erases wifi_manager's config",
const esp_console_cmd_t erase_config_cmd = {
.command = "wifi_erase_config",
.help = "Erases all stored access points from flash",
.hint = NULL,
.func = &erase_wifi_manager,
.func = &wifi_erase_config,
.argtable = &wifi_erase_args
};
const esp_console_cmd_t erase_networkmanager_cmd = {
.command = "nvs_erase_configuration",
.help = "Erases system's configuration",
.hint = NULL,
.func = &erase_network_manager,
.argtable = NULL
};
@@ -535,12 +589,21 @@ void register_nvs()
.func = &list_entries,
.argtable = &list_args
};
MEMTRACE_PRINT_DELTA_MESSAGE("registering list_entries_cmd");
ESP_ERROR_CHECK(esp_console_cmd_register(&list_entries_cmd));
MEMTRACE_PRINT_DELTA_MESSAGE("registering set_cmd");
ESP_ERROR_CHECK(esp_console_cmd_register(&set_cmd));
MEMTRACE_PRINT_DELTA_MESSAGE("registering get_cmd");
ESP_ERROR_CHECK(esp_console_cmd_register(&get_cmd));
MEMTRACE_PRINT_DELTA_MESSAGE("registering erase_cmd");
ESP_ERROR_CHECK(esp_console_cmd_register(&erase_cmd));
MEMTRACE_PRINT_DELTA_MESSAGE("registering erase_namespace_cmd");
ESP_ERROR_CHECK(esp_console_cmd_register(&erase_namespace_cmd));
ESP_ERROR_CHECK(esp_console_cmd_register(&erase_wifimanager_cmd));
MEMTRACE_PRINT_DELTA_MESSAGE("registering erase_config_cmd");
ESP_ERROR_CHECK(esp_console_cmd_register(&erase_networkmanager_cmd));
MEMTRACE_PRINT_DELTA_MESSAGE("registering erase_config_cmd");
ESP_ERROR_CHECK(esp_console_cmd_register(&erase_config_cmd));
MEMTRACE_PRINT_DELTA_MESSAGE("Done");
}
#ifdef __cplusplus

View File

@@ -31,25 +31,26 @@
#include "driver/uart.h" // for the uart driver access
#include "messaging.h"
#include "platform_console.h"
#include "trace.h"
#include "tools.h"
#ifdef CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
#pragma message("Runtime stats enabled")
#define WITH_TASKS_INFO 1
#else
#pragma message("Runtime stats disabled")
#endif
static struct {
struct arg_str *scanmode;
struct arg_end *end;
} wifi_parms_arg;
static struct {
EXT_RAM_ATTR static struct {
struct arg_str *name;
struct arg_end *end;
} name_args;
static struct {
EXT_RAM_ATTR static struct {
#if CONFIG_CSPOT_SINK
struct arg_lit *cspot;
#endif
struct arg_lit *btspeaker;
struct arg_lit *airplay;
struct arg_str *telnet;
#if WITH_TASKS_INFO
struct arg_lit *stats;
#endif
@@ -61,6 +62,7 @@ static const char * TAG = "cmd_system";
static void register_free();
static void register_setdevicename();
static void register_heap();
static void register_dump_heap();
static void register_version();
static void register_restart();
static void register_deep_sleep();
@@ -69,18 +71,16 @@ static void register_factory_boot();
static void register_restart_ota();
static void register_update_certs();
static void register_set_services();
static void register_set_wifi_parms();
#if WITH_TASKS_INFO
static void register_tasks();
#endif
extern BaseType_t wifi_manager_task;
extern BaseType_t network_manager_task;
void register_system()
{
register_set_wifi_parms();
// register_setbtsource();
register_free();
register_set_services();
register_heap();
register_dump_heap();
register_setdevicename();
register_version();
register_restart();
@@ -297,12 +297,35 @@ static void register_free()
cmd_to_json(&cmd);
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
}
static int dump_heap(int argc, char **argv)
{
ESP_LOGD(TAG, "Dumping heap");
heap_caps_dump_all();
return 0;
}
/* 'heap' command prints minumum heap size */
static int heap_size(int argc, char **argv)
{
uint32_t heap_size = heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT);
cmd_send_messaging(argv[0],MESSAGING_INFO, "min heap size: %u", heap_size);
ESP_LOGI(TAG,"Heap internal:%zu (min:%zu) (largest block:%zu)\nexternal:%zu (min:%zu) (largest block:%zd)\ndma :%zu (min:%zu) (largest block:%zd)",
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL),
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM),
heap_caps_get_free_size(MALLOC_CAP_DMA),
heap_caps_get_minimum_free_size(MALLOC_CAP_DMA),
heap_caps_get_largest_free_block(MALLOC_CAP_DMA));
cmd_send_messaging(argv[0],MESSAGING_INFO,"Heap internal:%zu (min:%zu) (largest block:%zu)\nexternal:%zu (min:%zu) (largest block:%zd)\ndma :%zu (min:%zu) (largest block:%zd)",
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL),
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM),
heap_caps_get_free_size(MALLOC_CAP_DMA),
heap_caps_get_minimum_free_size(MALLOC_CAP_DMA),
heap_caps_get_largest_free_block(MALLOC_CAP_DMA));
return 0;
}
cJSON * setdevicename_cb(){
@@ -323,6 +346,35 @@ typedef enum {
SCANNING,
PROCESSING_NAME
} scanstate_t;
int set_cspot_player_name(FILE * f,const char * name){
int ret=0;
cJSON * cspot_config = config_alloc_get_cjson("cspot_config");
if(cspot_config==NULL){
fprintf(f,"Unable to get cspot_config\n");
return 1;
}
cJSON * player_name = cJSON_GetObjectItemCaseSensitive(cspot_config,"deviceName");
if(player_name==NULL){
fprintf(f,"Unable to get deviceName\n");
ret=1;
}
if(strcmp(player_name->valuestring,name)==0){
fprintf(f,"CSpot device name not changed.\n");
ret=0;
}
else{
cJSON_SetValuestring(player_name,name);
if(setnamevar("cspot_config",f,cJSON_Print(cspot_config))!=0){
fprintf(f,"Unable to set cspot_config\n");
ret=1;
}
else{
fprintf(f,"CSpot device name set to %s\n",name);
}
}
cJSON_Delete(cspot_config);
return ret;
}
int set_squeezelite_player_name(FILE * f,const char * name){
char * nvs_config= config_alloc_get(NVS_TYPE_STR, "autoexec1");
char **argv = NULL;
@@ -341,10 +393,9 @@ int set_squeezelite_player_name(FILE * f,const char * name){
if(nvs_config && strlen(nvs_config)>0){
// allocate enough memory to hold the new command line
size_t cmdLength = strlen(nvs_config) + strlen(cleaned_name) + strlen(parm) +1 ;
newCommandLine = malloc(cmdLength);
memset(newCommandLine,0x00, cmdLength);
ESP_LOGD(TAG,"Parsing command %s",nvs_config);
argv = (char **) calloc(22, sizeof(char *));
newCommandLine = malloc_init_external(cmdLength);
ESP_LOGD(TAG,"Parsing command %s",nvs_config);
argv = (char **) malloc_init_external(22* sizeof(char *));
if (argv == NULL) {
FREE_AND_NULL(nvs_config);
return 1;
@@ -400,7 +451,7 @@ static int setdevicename(int argc, char **argv)
/* Check "--name" option */
if (name_args.name->count) {
name=strdup(name_args.name->sval[0]);
name=strdup_psram(name_args.name->sval[0]);
}
else {
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Name must be specified.");
@@ -420,6 +471,7 @@ static int setdevicename(int argc, char **argv)
nerrors+=setnamevar("bt_name", f, name);
nerrors+=setnamevar("host_name", f, name);
nerrors+=set_squeezelite_player_name(f, name);
nerrors+=set_cspot_player_name(f, name);
if(nerrors==0){
fprintf(f,"Device name changed to %s\n",name);
}
@@ -448,6 +500,17 @@ static void register_heap()
}
static void register_dump_heap()
{
const esp_console_cmd_t heap_cmd = {
.command = "dump_heap",
.help = "Dumps the content of the heap to serial output",
.hint = NULL,
.func = &dump_heap,
};
ESP_ERROR_CHECK( esp_console_cmd_register(&heap_cmd) );
}
static void register_setdevicename()
{
@@ -470,7 +533,7 @@ static void register_setdevicename()
static int tasks_info(int argc, char **argv)
{
const size_t bytes_per_task = 40; /* see vTaskList description */
char *task_list_buffer = malloc(uxTaskGetNumberOfTasks() * bytes_per_task);
char *task_list_buffer = malloc_init_external(uxTaskGetNumberOfTasks() * bytes_per_task);
if (task_list_buffer == NULL) {
cmd_send_messaging(argv[0],MESSAGING_ERROR, "failed to allocate buffer for vTaskList output");
return 1;
@@ -596,44 +659,7 @@ static int enable_disable(FILE * f,char * nvs_name, struct arg_lit *arg){
}
return err;
}
static int do_configure_wifi(int argc, char **argv){
esp_err_t err = ESP_OK;
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&wifi_parms_arg);
if (nerrors != 0) {
return 1;
}
char *buf = NULL;
size_t buf_size = 0;
FILE *f = open_memstream(&buf, &buf_size);
if (f == NULL) {
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
return 1;
}
if(wifi_parms_arg.scanmode->count>0){
if(strcasecmp(wifi_parms_arg.scanmode->sval[0],"Comprehensive") == 0){
err = config_set_value(NVS_TYPE_STR, "wifi_smode", "A");
}
else {
err = config_set_value(NVS_TYPE_STR, "wifi_smode", "F");
}
if(err!=ESP_OK){
nerrors++;
fprintf(f,"Error setting wifi scan mode to %s. %s\n",wifi_parms_arg.scanmode->sval[0], esp_err_to_name(err));
}
else {
fprintf(f,"Wifi Scan Mode changed to %s\n",wifi_parms_arg.scanmode->sval[0]);
}
}
if(!nerrors ){
fprintf(f,"Done.\n");
}
fflush (f);
cmd_send_messaging(argv[0],nerrors>0?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
fclose(f);
FREE_AND_NULL(buf);
return nerrors;
}
static int do_set_services(int argc, char **argv)
{
esp_err_t err = ESP_OK;
@@ -651,6 +677,9 @@ static int do_set_services(int argc, char **argv)
nerrors += enable_disable(f,"enable_airplay",set_services_args.airplay);
nerrors += enable_disable(f,"enable_bt_sink",set_services_args.btspeaker);
#if CONFIG_CSPOT_SINK
nerrors += enable_disable(f,"enable_cspot",set_services_args.cspot);
#endif
if(set_services_args.telnet->count>0){
if(strcasecmp(set_services_args.telnet->sval[0],"Disabled") == 0){
@@ -685,53 +714,41 @@ static int do_set_services(int argc, char **argv)
return nerrors;
}
cJSON * configure_wifi_cb(){
cJSON * values = cJSON_CreateObject();
char * p=NULL;
if ((p = config_alloc_get(NVS_TYPE_STR, "wifi_smode")) != NULL) {
cJSON_AddStringToObject(values,"scanmode",strcasecmp(p,"a") == 0 ?"Comprehensive":"Fast");
FREE_AND_NULL(p);
}
return values;
}
cJSON * set_services_cb(){
cJSON * values = cJSON_CreateObject();
char * p=NULL;
if ((p = config_alloc_get(NVS_TYPE_STR, "enable_bt_sink")) != NULL) {
cJSON_AddBoolToObject(values,"BT_Speaker",strcmp(p,"1") == 0 || strcasecmp(p,"y") == 0);
FREE_AND_NULL(p);
}
if ((p = config_alloc_get(NVS_TYPE_STR, "enable_airplay")) != NULL) {
cJSON_AddBoolToObject(values,"AirPlay",strcmp(p,"1") == 0 || strcasecmp(p,"y") == 0);
FREE_AND_NULL(p);
}
console_set_bool_parameter(values,"enable_bt_sink",set_services_args.btspeaker);
console_set_bool_parameter(values,"enable_airplay",set_services_args.airplay);
#if CONFIG_CSPOT_SINK
console_set_bool_parameter(values,"enable_cspot",set_services_args.cspot);
#endif
#if WITH_TASKS_INFO
console_set_bool_parameter(values,"stats",set_services_args.stats);
#endif
if ((p = config_alloc_get(NVS_TYPE_STR, "telnet_enable")) != NULL) {
if(strcasestr("YX",p)!=NULL){
cJSON_AddStringToObject(values,"telnet","Telnet Only");
cJSON_AddStringToObject(values,set_services_args.telnet->hdr.longopts,"Telnet Only");
}
else if(strcasestr("D",p)!=NULL){
cJSON_AddStringToObject(values,"telnet","Telnet and Serial");
cJSON_AddStringToObject(values,set_services_args.telnet->hdr.longopts,"Telnet and Serial");
}
else {
cJSON_AddStringToObject(values,"telnet","Disabled");
cJSON_AddStringToObject(values,set_services_args.telnet->hdr.longopts,"Disabled");
}
FREE_AND_NULL(p);
}
#if WITH_TASKS_INFO
if((p = config_alloc_get_default(NVS_TYPE_STR, "stats", "n", 0))!=NULL){
cJSON_AddBoolToObject(values,"stats",(*p == '1' || *p == 'Y' || *p == 'y')) ;
}
#endif
return values;
}
static void register_set_services(){
set_services_args.airplay = arg_lit0(NULL, "AirPlay", "AirPlay");
#if CONFIG_CSPOT_SINK
set_services_args.cspot = arg_lit0(NULL, "cspot", "Spotify (cspot)");
#endif
set_services_args.btspeaker = arg_lit0(NULL, "BT_Speaker", "Bluetooth Speaker");
set_services_args.telnet= arg_str0("t", "telnet","Disabled|Telnet Only|Telnet and Serial","Telnet server. Use only for troubleshooting");
#if WITH_TASKS_INFO
@@ -748,22 +765,6 @@ static void register_set_services(){
cmd_to_json_with_cb(&cmd,&set_services_cb);
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
}
static void register_set_wifi_parms(){
wifi_parms_arg.scanmode = arg_str0(NULL, "scanmode", "Fast|Comprehensive","Sets the WiFi Scan Mode. Use Comprehensive where more than one AP has the same name on different channels. This will ensure that the AP with the strongest signal is chosen.");
wifi_parms_arg.end=arg_end(2);
const esp_console_cmd_t cmd = {
.command = CFG_TYPE_SYST("wifi"),
.help = "WiFi",
.argtable = &wifi_parms_arg,
.hint = NULL,
.func = &do_configure_wifi,
};
cmd_to_json_with_cb(&cmd,&configure_wifi_cb);
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
}
/** 'light_sleep' command puts the chip into light sleep mode */
static struct {
struct arg_int *wakeup_time;
struct arg_int *wakeup_gpio_num;

View File

@@ -8,7 +8,7 @@
*/
// cmd_wifi has been replaced by wifi-manager
/* Console example <20> WiFi commands
/* Console example <20> WiFi commands
This example code is in the Public Domain (or CC0 licensed, at your option.)
@@ -30,15 +30,15 @@
#include "freertos/timers.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "esp_event.h"
#include "led.h"
extern bool bypass_wifi_manager;
extern bool bypass_network_manager;
#define JOIN_TIMEOUT_MS (10000)
#include "platform_console.h"
extern EventGroupHandle_t wifi_event_group;
extern EventGroupHandle_t network_event_group;
extern const int CONNECTED_BIT;
//static const char * TAG = "cmd_wifi";
/** Arguments used by 'join' function */
@@ -66,10 +66,10 @@ static void event_handler(void* arg, esp_event_base_t event_base,
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
led_blink_pushed(LED_GREEN, 250, 250);
esp_wifi_connect();
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
xEventGroupClearBits(network_event_group, CONNECTED_BIT);
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
led_unpush(LED_GREEN);
xEventGroupSetBits(wifi_event_group, CONNECTED_BIT);
xEventGroupSetBits(network_event_group, CONNECTED_BIT);
}
}
//bool wait_for_wifi(){
@@ -99,7 +99,7 @@ static void initialise_wifi(void)
if (initialized) {
return;
}
tcpip_adapter_init();
esp_netif_init();
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &event_handler, NULL) );
@@ -130,7 +130,7 @@ static void wifi_join(void *arg)
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
ESP_ERROR_CHECK( esp_wifi_connect() );
int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
int bits = xEventGroupWaitBits(network_event_group, CONNECTED_BIT,
pdFALSE, pdTRUE, timeout_ms / portTICK_PERIOD_MS);
if (bits & CONNECTED_BIT) {
@@ -205,7 +205,7 @@ void register_wifi_join()
void register_wifi()
{
register_wifi_join();
if(bypass_wifi_manager){
if(bypass_network_manager){
initialise_wifi();
}
}

View File

@@ -26,6 +26,7 @@
#include "trace.h"
#include "platform_config.h"
#include "telnet.h"
#include "tools.h"
#include "messaging.h"
@@ -34,12 +35,12 @@ static pthread_t thread_console;
static void * console_thread();
void console_start();
static const char * TAG = "console";
extern bool bypass_wifi_manager;
extern bool bypass_network_manager;
extern void register_squeezelite();
static EXT_RAM_ATTR QueueHandle_t uart_queue;
static EXT_RAM_ATTR struct {
uint8_t _buf[128];
uint8_t _buf[512];
StaticRingbuffer_t _ringbuf;
RingbufHandle_t handle;
QueueSetHandle_t queue_set;
@@ -82,7 +83,17 @@ cJSON * get_cmd_list(){
}
return list;
}
void console_set_bool_parameter(cJSON * root,char * nvs_name, struct arg_lit *arg){
char * p=NULL;
if(!root) {
ESP_LOGE(TAG,"Invalid json parameter. Cannot set %s from %s",arg->hdr.longopts?arg->hdr.longopts:arg->hdr.glossary,nvs_name);
return;
}
if ((p = config_alloc_get(NVS_TYPE_STR, nvs_name)) != NULL) {
cJSON_AddBoolToObject(root,arg->hdr.longopts,strcmp(p,"1") == 0 || strcasecmp(p,"y") == 0);
FREE_AND_NULL(p);
}
}
struct arg_end *getParmsEnd(struct arg_hdr * * argtable){
if(!argtable) return NULL;
struct arg_hdr * *table = (struct arg_hdr * *)argtable;
@@ -196,8 +207,8 @@ void process_autoexec(){
uint8_t autoexec_flag=0;
char * str_flag = config_alloc_get(NVS_TYPE_STR, "autoexec");
if(!bypass_wifi_manager){
ESP_LOGW(TAG, "Processing autoexec commands while wifi_manager active. Wifi related commands will be ignored.");
if(!bypass_network_manager){
ESP_LOGW(TAG, "Processing autoexec commands while network manager active. Wifi related commands will be ignored.");
}
if(is_recovery_running){
ESP_LOGD(TAG, "Processing autoexec commands in recovery mode. Squeezelite commands will be ignored.");
@@ -211,7 +222,7 @@ void process_autoexec(){
ESP_LOGD(TAG,"Getting command name %s", autoexec_name);
autoexec_value= config_alloc_get(NVS_TYPE_STR, autoexec_name);
if(autoexec_value!=NULL ){
if(!bypass_wifi_manager && strstr(autoexec_value, "join ")!=NULL ){
if(!bypass_network_manager && strstr(autoexec_value, "join ")!=NULL ){
ESP_LOGW(TAG,"Ignoring wifi join command.");
}
else if(is_recovery_running && !strstr(autoexec_value, "squeezelite " ) ){
@@ -279,10 +290,10 @@ void initialize_console() {
/* Configure UART. Note that REF_TICK is used so that the baud rate remains
* correct while APB frequency is changing in light sleep mode.
*/
const uart_config_t uart_config = { .baud_rate =
CONFIG_ESP_CONSOLE_UART_BAUDRATE, .data_bits = UART_DATA_8_BITS,
const uart_config_t uart_config = { .baud_rate = CONFIG_ESP_CONSOLE_UART_BAUDRATE,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1,
.use_ref_tick = true };
};
ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config));
/* Install UART driver for interrupt-driven reads and writes */
@@ -343,18 +354,26 @@ void console_start() {
initialize_console();
/* Register commands */
MEMTRACE_PRINT_DELTA_MESSAGE("Registering help command");
esp_console_register_help_command();
MEMTRACE_PRINT_DELTA_MESSAGE("Registering system commands");
register_system();
MEMTRACE_PRINT_DELTA_MESSAGE("Registering config commands");
register_config_cmd();
MEMTRACE_PRINT_DELTA_MESSAGE("Registering nvs commands");
register_nvs();
MEMTRACE_PRINT_DELTA_MESSAGE("Registering wifi commands");
register_wifi();
if(!is_recovery_running){
MEMTRACE_PRINT_DELTA_MESSAGE("Registering squeezelite commands");
register_squeezelite();
}
else {
MEMTRACE_PRINT_DELTA_MESSAGE("Registering recovery commands");
register_ota_cmd();
}
MEMTRACE_PRINT_DELTA_MESSAGE("Registering i2c commands");
register_i2ctools();
printf("\n");
@@ -401,8 +420,10 @@ void console_start() {
if(is_recovery_running){
prompt = recovery_prompt;
}
MEMTRACE_PRINT_DELTA_MESSAGE("Creating console thread with stack size of 4096 bytes");
esp_pthread_set_cfg(&cfg);
pthread_create(&thread_console, NULL, console_thread, NULL);
MEMTRACE_PRINT_DELTA_MESSAGE("Console thread created");
}
@@ -429,7 +450,9 @@ static esp_err_t run_command(char * line){
static void * console_thread() {
if(!is_recovery_running){
MEMTRACE_PRINT_DELTA_MESSAGE("Running autoexec");
process_autoexec();
MEMTRACE_PRINT_DELTA_MESSAGE("Autoexec done");
}
/* Main loop */
while (1) {

View File

@@ -22,6 +22,7 @@ typedef cJSON * parm_values_fn_t(void);
esp_err_t cmd_to_json(const esp_console_cmd_t *cmd);
esp_err_t cmd_to_json_with_cb(const esp_console_cmd_t *cmd, parm_values_fn_t parm_values_fn);
int arg_parse_msg(int argc, char **argv, struct arg_hdr ** args);
void console_set_bool_parameter(cJSON * root,char * nvs_name, struct arg_lit *arg);
cJSON * get_cmd_list();
#ifdef __cplusplus
}

View File

@@ -1,7 +1,7 @@
idf_component_register(SRC_DIRS .
INCLUDE_DIRS .
PRIV_REQUIRES newlib freertos pthread platform_config mdns services codecs tools display
PRIV_REQUIRES newlib freertos pthread platform_config mdns services codecs tools display wifi-manager
)
set_source_files_properties(raop.c

View File

@@ -3,10 +3,8 @@
#include <ctype.h>
#include <stdlib.h>
#include "mdns.h"
#include "nvs.h"
#include "tcpip_adapter.h"
// IDF-V4++ #include "esp_netif.h"
#include "esp_netif.h"
#include "esp_log.h"
#include "esp_console.h"
#include "esp_pthread.h"
@@ -18,7 +16,7 @@
#include "display.h"
#include "accessors.h"
#include "log_util.h"
#include "trace.h"
#include "network_services.h"
#ifndef CONFIG_AIRPLAY_NAME
#define CONFIG_AIRPLAY_NAME "ESP32-AirPlay"
@@ -156,72 +154,36 @@ static bool cmd_handler(raop_event_t event, ...) {
*/
void raop_sink_deinit(void) {
raop_delete(raop);
mdns_free();
}
/****************************************************************************************
* Airplay sink startup
*/
static bool raop_sink_start(raop_cmd_vcb_t cmd_cb, raop_data_cb_t data_cb) {
const char *hostname = NULL;
char sink_name[64-6] = CONFIG_AIRPLAY_NAME;
tcpip_adapter_ip_info_t ipInfo = { };
tcpip_adapter_if_t ifs[] = { TCPIP_ADAPTER_IF_ETH, TCPIP_ADAPTER_IF_STA, TCPIP_ADAPTER_IF_AP };
// get various IP info
for (int i = 0; i < sizeof(ifs) / sizeof(tcpip_adapter_if_t); i++)
if (tcpip_adapter_get_ip_info(ifs[i], &ipInfo) == ESP_OK && ipInfo.ip.addr != IPADDR_ANY) {
tcpip_adapter_get_hostname(ifs[i], &hostname);
break;
}
if (!hostname) {
LOG_INFO( "no hostname/IP found, can't start AirPlay");
return false;
}
// initialize mDNS
ESP_ERROR_CHECK( mdns_init() );
ESP_ERROR_CHECK( mdns_hostname_set(hostname) );
char * sink_name_buffer= (char *)config_alloc_get(NVS_TYPE_STR,"airplay_name");
if (sink_name_buffer != NULL){
memset(sink_name, 0x00, sizeof(sink_name));
strncpy(sink_name,sink_name_buffer,sizeof(sink_name)-1 );
free(sink_name_buffer);
}
LOG_INFO( "mdns hostname for ip %s set to: [%s] with servicename %s", inet_ntoa(ipInfo.ip.addr), hostname, sink_name);
// create RAOP instance, latency is set by controller
static void raop_sink_start(nm_state_t state_id, int sub_state) {
esp_netif_t* netif;
esp_netif_ip_info_t ipInfo = { };
uint8_t mac[6];
esp_read_mac(mac, ESP_MAC_WIFI_STA);
cmd_handler_chain = cmd_cb;
raop = raop_create(ipInfo.ip.addr, sink_name, mac, 0, cmd_handler, data_cb);
return true;
}
char* sink_name = (char*) config_alloc_get_default(NVS_TYPE_STR, "airplay_name", CONFIG_AIRPLAY_NAME, 0);
/****************************************************************************************
* Airplay sink timer handler
*/
static void raop_start_handler( TimerHandle_t xTimer ) {
if (raop_sink_start(raop_cbs.cmd, raop_cbs.data)) {
xTimerDelete(xTimer, portMAX_DELAY);
}
}
netif = network_get_active_interface();
esp_netif_get_ip_info(netif, &ipInfo);
esp_netif_get_mac(netif, mac);
cmd_handler_chain = raop_cbs.cmd;
LOG_INFO( "Starting Airplay for ip %s with servicename %s", inet_ntoa(ipInfo.ip.addr), sink_name);
raop = raop_create(ipInfo.ip.addr, sink_name, mac, 0, cmd_handler, raop_cbs.data);
free(sink_name);
}
/****************************************************************************************
* Airplay sink initialization
*/
void raop_sink_init(raop_cmd_vcb_t cmd_cb, raop_data_cb_t data_cb) {
if (!raop_sink_start(cmd_cb, data_cb)) {
raop_cbs.cmd = cmd_cb;
raop_cbs.data = data_cb;
TimerHandle_t timer = xTimerCreate("raopStart", 5000 / portTICK_RATE_MS, pdTRUE, NULL, raop_start_handler);
xTimerStart(timer, portMAX_DELAY);
LOG_INFO( "Delaying AirPlay start");
}
raop_cbs.cmd = cmd_cb;
raop_cbs.data = data_cb;
network_register_state_callback(NETWORK_WIFI_ACTIVE_STATE, WIFI_CONNECTED_STATE, "raop_sink_start", raop_sink_start);
network_register_state_callback(NETWORK_ETH_ACTIVE_STATE, ETH_ACTIVE_CONNECTED_STATE, "raop_sink_start", raop_sink_start);
}
/****************************************************************************************

View File

@@ -13,7 +13,7 @@
#ifdef WIN32
#include <iphlpapi.h>
#else
#include "tcpip_adapter.h"
#include "esp_netif.h"
// IDF-V4++ #include "esp_netif.h"
#include <ctype.h>
#endif

View File

@@ -1,7 +1,5 @@
idf_component_register(SRC_DIRS .
INCLUDE_DIRS . ${IDF_PATH}/components/driver
REQUIRES json tools platform_config display
INCLUDE_DIRS .
REQUIRES json tools platform_config display wifi-manager
PRIV_REQUIRES soc esp32
)

View File

@@ -28,10 +28,10 @@
#include "driver/gpio.h"
#include "driver/spi_common_internal.h"
#include "esp32/rom/efuse.h"
#include "trace.h"
#include "tools.h"
#include "monitor.h"
#include "messaging.h"
#include "network_ethernet.h"
static const char *TAG = "services";
const char *i2c_name_type="I2C";
@@ -116,13 +116,8 @@ static void set_i2s_pin(char *config, i2s_pin_config_t *pin_config) {
* Get i2s config structure from config string
*/
const i2s_platform_config_t * config_i2s_get_from_str(char * dac_config ){
static i2s_platform_config_t i2s_dac_pin = {
.i2c_addr = -1,
.sda= -1,
.scl = -1,
.mute_gpio = -1,
.mute_level = -1
};
static EXT_RAM_ATTR i2s_platform_config_t i2s_dac_pin;
memset(&i2s_dac_pin, 0xff, sizeof(i2s_dac_pin));
set_i2s_pin(dac_config, &i2s_dac_pin.pin);
strcpy(i2s_dac_pin.model, "i2s");
char * p=NULL;
@@ -140,6 +135,65 @@ const i2s_platform_config_t * config_i2s_get_from_str(char * dac_config ){
return &i2s_dac_pin;
}
/****************************************************************************************
* Get eth config structure from config string
*/
const eth_config_t * config_eth_get_from_str(char* config ){
static EXT_RAM_ATTR eth_config_t eth_config;
eth_config.rst = eth_config.intr = -1;
PARSE_PARAM_STR(config, "model", '=', eth_config.model, 15);
PARSE_PARAM(config, "rst", '=', eth_config.rst);
// RMII
PARSE_PARAM(config, "mdc", '=', eth_config.mdc);
PARSE_PARAM(config, "mdio", '=', eth_config.mdio);
// SPI
PARSE_PARAM(config, "intr", '=', eth_config.intr);
PARSE_PARAM(config, "cs", '=', eth_config.cs);
PARSE_PARAM(config, "speed", '=', eth_config.speed);
/* not used as SPI must be shared
PARSE_PARAM(config, "mosi", '=', eth_config.mosi);
PARSE_PARAM(config, "miso", '=', eth_config.miso);
PARSE_PARAM(config, "clk", '=', eth_config.clk);
PARSE_PARAM(config, "host", '=', eth_config.host);
*/
// only system host is available
eth_config.host = spi_system_host;
eth_config.valid = true;
if(!eth_config.model || strlen(eth_config.model)==0){
eth_config.valid = false;
return &eth_config;
}
network_ethernet_driver_t* network_driver = network_ethernet_driver_autodetect(eth_config.model);
if(!network_driver || !network_driver->valid){
messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"Ethernet config invalid: model %s %s",eth_config.model,network_driver?"was not compiled in":"was not found");
eth_config.valid = false;
}
if(network_driver){
eth_config.rmii = network_driver->rmii;
eth_config.spi = network_driver->spi;
if(network_driver->rmii){
if(!GPIO_IS_VALID_GPIO(eth_config.mdio) || !GPIO_IS_VALID_GPIO(eth_config.mdc)){
messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"Ethernet config invalid: %s %s",!GPIO_IS_VALID_GPIO(eth_config.mdc)?"Invalid MDC":"",!GPIO_IS_VALID_GPIO(eth_config.mdio)?"Invalid mdio":"");
eth_config.valid = false;
}
}
else if(network_driver->spi){
if(!GPIO_IS_VALID_GPIO(eth_config.cs)){
messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"Ethernet config invalid: invalid CS pin");
return false;
}
}
}
return &eth_config;
}
/****************************************************************************************
* Get spdif config structure
*/
@@ -162,13 +216,53 @@ const i2s_platform_config_t * config_dac_get(){
return &i2s_dac_config;
}
/****************************************************************************************
* Get ethernet config structure
*/
const eth_config_t * config_eth_get( ){
char * config = config_alloc_get_str("eth_config", CONFIG_ETH_CONFIG, "rst=" STR(CONFIG_ETH_PHY_RST_IO)
#if defined(ETH_LAN8720)
#else
#if defined(CONFIG_ETH_USE_SPI_ETHERNET)
#if defined(CONFIG_ETH_DM9051)
",model=dm9051"
#elif defined(CONFIG_ETH_W5500)
",model=w5500"
#endif
",host=" STR(CONFIG_ETH_SPI_HOST) ",cs=" STR(CONFIG_ETH_SPI_CS_IO)
",mosi=" STR(CONFIG_ETH_SPI_MOSI_IO) ",miso=" STR(CONFIG_ETH_SPI_MISO_IO)
",intr=" STR(CONFIG_ETH_SPI_INTR_IO)
",clk=" STR(CONFIG_ETH_SPI_CLK_IO) ",speed=" STR(CONFIG_ETH_SPI_SPEED)
#elif defined(CONFIG_ETH_PHY_INTERFACE_RMII)
",model=lan8720, tx_en=21, tx0=19, tx1=22, rx0=25, rx1=26, crs_dv=27"
#endif
#endif
",mdc=" STR(CONFIG_ETH_MDC_IO) ",mdio=" STR(CONFIG_ETH_MDIO_IO)) ;
if(config && strlen(config)>0){
ESP_LOGD(TAG,"Parsing ethernet configuration %s", config);
}
static EXT_RAM_ATTR eth_config_t eth_config;
memcpy(&eth_config, config_eth_get_from_str(config), sizeof(eth_config));
FREE_AND_NULL(config);
return &eth_config;
}
/****************************************************************************************
* Get ethernet config structure and assign to eth config structure
*/
void config_eth_init( eth_config_t * target ){
const eth_config_t * source = config_eth_get();
memcpy(target,source,sizeof(eth_config_t));
}
/****************************************************************************************
*
*/
esp_err_t config_i2c_set(const i2c_config_t * config, int port){
int buffer_size=255;
esp_err_t err=ESP_OK;
char * config_buffer=calloc(buffer_size,1);
char * config_buffer=malloc_init_external(buffer_size);
if(config_buffer) {
snprintf(config_buffer,buffer_size,"scl=%u,sda=%u,speed=%u,port=%u",config->scl_io_num,config->sda_io_num,config->master.clk_speed,port);
log_send_messaging(MESSAGING_INFO,"Updating I2C configuration to %s",config_buffer);
@@ -187,8 +281,8 @@ esp_err_t config_i2c_set(const i2c_config_t * config, int port){
esp_err_t config_rotary_set(rotary_struct_t * config){
int buffer_size=512;
esp_err_t err=ESP_OK;
char * config_buffer=calloc(buffer_size,1);
char * config_buffer2=calloc(buffer_size,1);
char * config_buffer=malloc_init_external(buffer_size);
char * config_buffer2=malloc_init_external(buffer_size);
if(config_buffer && config_buffer2) {
snprintf(config_buffer,buffer_size,"A=%i,B=%i",config->A, config->B);
if(config->SW >=0 ){
@@ -228,8 +322,8 @@ esp_err_t config_rotary_set(rotary_struct_t * config){
esp_err_t config_display_set(const display_config_t * config){
int buffer_size=512;
esp_err_t err=ESP_OK;
char * config_buffer=calloc(buffer_size,1);
char * config_buffer2=calloc(buffer_size,1);
char * config_buffer=malloc_init_external(buffer_size);
char * config_buffer2=malloc_init_external(buffer_size);
if(config_buffer && config_buffer2) {
snprintf(config_buffer,buffer_size,"%s,width=%i,height=%i",config->type,config->width,config->height);
if(strcasecmp("I2C",config->type)==0){
@@ -280,8 +374,8 @@ esp_err_t config_display_set(const display_config_t * config){
esp_err_t config_i2s_set(const i2s_platform_config_t * config, const char * nvs_name){
int buffer_size=255;
esp_err_t err=ESP_OK;
char * config_buffer=calloc(buffer_size,1);
char * config_buffer2=calloc(buffer_size,1);
char * config_buffer=malloc_init_external(buffer_size);
char * config_buffer2=malloc_init_external(buffer_size);
if(config_buffer && config_buffer2) {
snprintf(config_buffer,buffer_size,"model=%s,bck=%u,ws=%u,do=%u",config->model,config->pin.bck_io_num,config->pin.ws_io_num,config->pin.data_out_num);
if(config->mute_gpio>=0){
@@ -316,7 +410,7 @@ esp_err_t config_i2s_set(const i2s_platform_config_t * config, const char * nvs_
esp_err_t config_spdif_set(const i2s_platform_config_t * config){
int buffer_size=255;
esp_err_t err=ESP_OK;
char * config_buffer=calloc(buffer_size,1);
char * config_buffer=malloc_init_external(buffer_size);
if(config_buffer ) {
snprintf(config_buffer,buffer_size,"bck=%u,ws=%u,do=%u",config->pin.bck_io_num,config->pin.ws_io_num,config->pin.data_out_num);
log_send_messaging(MESSAGING_INFO,"Updating SPDIF configuration to %s",config_buffer);
@@ -338,7 +432,7 @@ esp_err_t config_spdif_set(const i2s_platform_config_t * config){
esp_err_t config_spi_set(const spi_bus_config_t * config, int host, int dc){
int buffer_size=255;
esp_err_t err = ESP_OK;
char * config_buffer=calloc(buffer_size,1);
char * config_buffer=malloc_init_external(buffer_size);
if(config_buffer) {
snprintf(config_buffer,buffer_size,"data=%u,clk=%u,dc=%u,host=%u,miso=%d",config->mosi_io_num,config->sclk_io_num,dc,host,config->miso_io_num);
log_send_messaging(MESSAGING_INFO,"Updating SPI configuration to %s",config_buffer);
@@ -390,7 +484,6 @@ const display_config_t * config_display_get(){
PARSE_PARAM(config, "address", '=', dstruct.address);
PARSE_PARAM(config, "cs", '=', dstruct.CS_pin);
PARSE_PARAM(config, "speed", '=', dstruct.speed);
PARSE_PARAM(config, "back", '=', dstruct.back);
if (strstr(config, "I2C") ) dstruct.type=i2c_name_type;
if (strstr(config, "SPI") ) dstruct.type=spi_name_type;
@@ -556,6 +649,7 @@ const set_GPIO_struct_t * get_gpio_struct(){
*/
const spi_bus_config_t * config_spi_get(spi_host_device_t * spi_host) {
char *nvs_item;
// don't memset all to 0xff as it's more than just GPIO
static spi_bus_config_t spi = {
.mosi_io_num = -1,
.sclk_io_num = -1,
@@ -563,7 +657,7 @@ const spi_bus_config_t * config_spi_get(spi_host_device_t * spi_host) {
.quadwp_io_num = -1,
.quadhd_io_num = -1
};
nvs_item = config_alloc_get_str("spi_config", CONFIG_SPI_CONFIG, NULL);
if (nvs_item) {
PARSE_PARAM(nvs_item, "data", '=', spi.mosi_io_num);
@@ -763,6 +857,46 @@ cJSON * get_SPI_GPIO(cJSON * list){
return llist;
}
/****************************************************************************************
*
*/
cJSON * get_eth_GPIO(cJSON * list){
cJSON * llist = list;
if(!llist){
llist = cJSON_CreateArray();
}
spi_host_device_t spi_host;
const eth_config_t * eth_config = config_eth_get(&spi_host);
#if defined(CONFIG_ETH_CONFIG)
bool fixed = strlen(CONFIG_ETH_CONFIG)>0;
#else
bool fixed =false;
#endif
if(eth_config->valid ){
add_gpio_for_value(llist,"mdc",eth_config->mdc,"ethernet",fixed);
add_gpio_for_value(llist,"rst",eth_config->rst,"ethernet",fixed);
add_gpio_for_value(llist,"mdio",eth_config->mdio,"ethernet",fixed);
if(eth_config->rmii){
add_gpio_for_value(llist,"tx_en", 21,"ethernet",true);
add_gpio_for_value(llist,"tx0", 19 ,"ethernet",true);
add_gpio_for_value(llist,"tx1", 22 ,"ethernet",true);
add_gpio_for_value(llist,"rx0", 25 ,"ethernet",true);
add_gpio_for_value(llist,"rx1", 26 ,"ethernet",true);
add_gpio_for_value(llist,"crs_dv",27 ,"ethernet",true);
}
else if(eth_config->spi) {
/* SPI ethernet */
add_gpio_for_value(llist,"cs",eth_config->cs,"ethernet",fixed);
add_gpio_for_value(llist,"mosi",eth_config->mosi,"ethernet",fixed);
add_gpio_for_value(llist,"miso",eth_config->miso,"ethernet",fixed);
add_gpio_for_value(llist,"intr",eth_config->intr,"ethernet",fixed);
add_gpio_for_value(llist,"clk",eth_config->clk,"ethernet",fixed);
}
}
return llist;
}
/****************************************************************************************
*
*/
@@ -796,7 +930,7 @@ cJSON * get_Rotary_GPIO(cJSON * list){
*/
esp_err_t get_gpio_structure(cJSON * gpio_entry, gpio_entry_t ** gpio){
esp_err_t err = ESP_OK;
*gpio = malloc(sizeof(gpio_entry_t));
*gpio = malloc_init_external(sizeof(gpio_entry_t));
cJSON * val = cJSON_GetObjectItem(gpio_entry,"gpio");
if(val){
(*gpio)->gpio= (int)val->valuedouble;
@@ -806,14 +940,14 @@ esp_err_t get_gpio_structure(cJSON * gpio_entry, gpio_entry_t ** gpio){
}
val = cJSON_GetObjectItem(gpio_entry,"name");
if(val){
(*gpio)->name= strdup(cJSON_GetStringValue(val));
(*gpio)->name= strdup_psram(cJSON_GetStringValue(val));
} else {
ESP_LOGE(TAG,"gpio name value not found");
err=ESP_FAIL;
}
val = cJSON_GetObjectItem(gpio_entry,"group");
if(val){
(*gpio)->group= strdup(cJSON_GetStringValue(val));
(*gpio)->group= strdup_psram(cJSON_GetStringValue(val));
} else {
ESP_LOGE(TAG,"gpio group value not found");
err=ESP_FAIL;
@@ -989,7 +1123,6 @@ cJSON * get_gpio_list(bool refresh) {
}
free(bat_config);
}
gpio_list=get_GPIO_nvs_list(gpio_list);
gpio_list=get_SPDIF_GPIO(gpio_list,is_spdif_config_locked());
gpio_list=get_Rotary_GPIO(gpio_list);
@@ -998,5 +1131,6 @@ cJSON * get_gpio_list(bool refresh) {
gpio_list=get_I2C_GPIO(gpio_list);
gpio_list=get_DAC_GPIO(gpio_list);
gpio_list=get_psram_gpio_list(gpio_list);
gpio_list=get_eth_GPIO(gpio_list);
return gpio_list;
}

View File

@@ -35,9 +35,11 @@ typedef struct {
int colorswap;
} display_config_t;
typedef struct {
bool rmii;
typedef struct eth_config_struct {
char model[16];
bool valid;
bool rmii;
bool spi;
int rst;
int mdc, mdio;
int host;
@@ -90,6 +92,8 @@ typedef struct {
} gpio_entry_t;
const display_config_t * config_display_get();
const eth_config_t * config_eth_get( );
void config_eth_init( eth_config_t * target );
esp_err_t config_display_set(const display_config_t * config);
esp_err_t config_i2c_set(const i2c_config_t * config, int port);
esp_err_t config_i2s_set(const i2s_platform_config_t * config, const char * nvs_name);
@@ -100,6 +104,7 @@ const gpio_exp_config_t * config_gpio_exp_get(int index);
void parse_set_GPIO(void (*cb)(int gpio, char *value));
const i2s_platform_config_t * config_dac_get();
const i2s_platform_config_t * config_spdif_get( );
const i2s_platform_config_t * config_i2s_get_from_str(char * dac_config );
esp_err_t config_spdif_set(const i2s_platform_config_t * config);
bool is_spdif_config_locked();
esp_err_t free_gpio_entry( gpio_entry_t ** gpio);

View File

@@ -60,6 +60,10 @@ static const char TAG[] = "gpio expander";
static void IRAM_ATTR intr_isr_handler(void* arg);
static gpio_exp_t* find_expander(gpio_exp_t *expander, int *gpio);
static esp_err_t mpr121_init(gpio_exp_t* self);
static uint32_t mpr121_read(gpio_exp_t* self);
static void mpr121_write(gpio_exp_t* self);
static void pca9535_set_direction(gpio_exp_t* self);
static uint32_t pca9535_read(gpio_exp_t* self);
static void pca9535_write(gpio_exp_t* self);
@@ -98,6 +102,11 @@ static const struct gpio_exp_model_s {
void (*set_direction)(gpio_exp_t* self);
void (*set_pull_mode)(gpio_exp_t* self);
} registered[] = {
{ .model = "mpr121",
.trigger = GPIO_INTR_LOW_LEVEL,
.init = mpr121_init,
.read = mpr121_read,
.write = mpr121_write, },
{ .model = "pca9535",
.trigger = GPIO_INTR_LOW_LEVEL,
.set_direction = pca9535_set_direction,
@@ -498,6 +507,56 @@ static gpio_exp_t* find_expander(gpio_exp_t *expander, int *gpio) {
DRIVERS
****************************************************************************************/
/****************************************************************************************
* MPR121 family : init, direction, read and write
*/
static esp_err_t mpr121_init(gpio_exp_t* self) {
static const struct {
uint8_t addr;
uint8_t data;
} mpr121_init_table[] = {
{ 0x80, 0x63 }, /* Soft reset */
{ 0x2b, 0x01 }, { 0x2c, 0x01 }, { 0x2d, 0x10 }, { 0x2e, 0x20 }, /* MHDR, NHDR, NCLR, FDLR */
{ 0x2f, 0x01 }, { 0x30, 0x01 }, { 0x31, 0x10 }, { 0x32, 0x20 }, /* MHDF, NHDF, NCLF, FDLF */
{ 0x33, 0x01 }, { 0x34, 0x10 }, { 0x35, 0xff }, /* NHDT, NCLT, FDLT */
{ 0x5b, 0x11 }, { 0x5c, 0xff }, { 0x5d, 0x30 }, /* DTR, AFE1, AFE2 */
{ 0x7b, 0x00 }, { 0x7c, 0x00 }, { 0x7d, 0x00 }, { 0x7e, 0x00 }, { 0x7f, 0x00 },/* ACCR0, ACCR1, USL, LSL, TL */
{ 0x41, 0x28 }, { 0x42, 0x14 }, /* ELE0: Touch Threshold, Release Threshold */
{ 0x43, 0x28 }, { 0x44, 0x14 }, /* ELE1: Touch Threshold, Release Threshold */
{ 0x45, 0x28 }, { 0x46, 0x14 }, /* ELE2: Touch Threshold, Release Threshold */
{ 0x47, 0x28 }, { 0x48, 0x14 }, /* ELE3: Touch Threshold, Release Threshold */
{ 0x49, 0x28 }, { 0x4a, 0x14 }, /* ELE4: Touch Threshold, Release Threshold */
{ 0x4b, 0x28 }, { 0x4c, 0x14 }, /* ELE5: Touch Threshold, Release Threshold */
{ 0x4d, 0x28 }, { 0x4e, 0x14 }, /* ELE6: Touch Threshold, Release Threshold */
{ 0x4f, 0x28 }, { 0x50, 0x14 }, /* ELE7: Touch Threshold, Release Threshold */
{ 0x51, 0x28 }, { 0x52, 0x14 }, /* ELE8: Touch Threshold, Release Threshold */
{ 0x53, 0x28 }, { 0x54, 0x14 }, /* ELE9: Touch Threshold, Release Threshold */
{ 0x55, 0x28 }, { 0x56, 0x14 }, /* ELE10: Touch Threshold, Release Threshold */
{ 0x57, 0x28 }, { 0x58, 0x14 }, /* ELE11: Touch Threshold, Release Threshold */
{ 0x5e, 0xcc }, /* ECR - must be set last */
{0, 0}
};
esp_err_t err = 0;
for (int i = 0; mpr121_init_table[i].addr; i++) {
err |= i2c_write(self->phy.port, self->phy.addr, mpr121_init_table[i].addr, mpr121_init_table[i].data, 1);
}
return err;
}
static uint32_t mpr121_read(gpio_exp_t* self) {
// only return the lower 12 bits of the pin status registers
return i2c_read(self->phy.port, self->phy.addr, 0x00, 2) & 0x0fff;
}
static void mpr121_write(gpio_exp_t* self) {
ESP_LOGE(TAG, "MPR121 GPIO write not implemented");
}
/****************************************************************************************
* PCA9535 family : direction, read and write
*/

View File

@@ -28,7 +28,7 @@
#include "driver/i2s.h"
#include "driver/rtc_io.h"
#include "driver/dac.h"
#include <adc1_i2s_private.h>
#include "adc1_private.h"
#include "esp_intr_alloc.h"
#include "esp_err.h"
@@ -880,7 +880,7 @@ static esp_err_t i2s_param_config(i2s_port_t i2s_num, const i2s_config_t *i2s_co
//initialize the specific ADC channel.
//in the current stage, we only support ADC1 and single channel mode.
//In default data mode, the ADC data is in 12-bit resolution mode.
adc_power_always_on();
// todo: fix this - adc_power_always_on();
}
// configure I2S data port interface.
i2s_reset_fifo(i2s_num);
@@ -974,35 +974,36 @@ static esp_err_t i2s_param_config(i2s_port_t i2s_num, const i2s_config_t *i2s_co
I2S[i2s_num]->pdm_conf.rx_pdm_en = 0;
I2S[i2s_num]->pdm_conf.tx_pdm_en = 0;
}
if (i2s_config->communication_format & I2S_COMM_FORMAT_I2S) {
I2S[i2s_num]->conf.tx_short_sync = 0;
I2S[i2s_num]->conf.rx_short_sync = 0;
I2S[i2s_num]->conf.tx_msb_shift = 1;
I2S[i2s_num]->conf.rx_msb_shift = 1;
if (i2s_config->communication_format & I2S_COMM_FORMAT_I2S_LSB) {
if (i2s_config->mode & I2S_MODE_TX) {
I2S[i2s_num]->conf.tx_msb_shift = 0;
}
if (i2s_config->mode & I2S_MODE_RX) {
I2S[i2s_num]->conf.rx_msb_shift = 0;
}
}
}
// todo: fix this below!!
// if (i2s_config->communication_format & I2S_COMM_FORMAT_I2S) {
// I2S[i2s_num]->conf.tx_short_sync = 0;
// I2S[i2s_num]->conf.rx_short_sync = 0;
// I2S[i2s_num]->conf.tx_msb_shift = 1;
// I2S[i2s_num]->conf.rx_msb_shift = 1;
// if (i2s_config->communication_format & I2S_COMM_FORMAT_I2S_LSB) {
// if (i2s_config->mode & I2S_MODE_TX) {
// I2S[i2s_num]->conf.tx_msb_shift = 0;
// }
// if (i2s_config->mode & I2S_MODE_RX) {
// I2S[i2s_num]->conf.rx_msb_shift = 0;
// }
// }
// }
if (i2s_config->communication_format & I2S_COMM_FORMAT_PCM) {
I2S[i2s_num]->conf.tx_msb_shift = 0;
I2S[i2s_num]->conf.rx_msb_shift = 0;
I2S[i2s_num]->conf.tx_short_sync = 0;
I2S[i2s_num]->conf.rx_short_sync = 0;
if (i2s_config->communication_format & I2S_COMM_FORMAT_PCM_SHORT) {
if (i2s_config->mode & I2S_MODE_TX) {
I2S[i2s_num]->conf.tx_short_sync = 1;
}
if (i2s_config->mode & I2S_MODE_RX) {
I2S[i2s_num]->conf.rx_short_sync = 1;
}
}
}
// if (i2s_config->communication_format & I2S_COMM_FORMAT_PCM) {
// I2S[i2s_num]->conf.tx_msb_shift = 0;
// I2S[i2s_num]->conf.rx_msb_shift = 0;
// I2S[i2s_num]->conf.tx_short_sync = 0;
// I2S[i2s_num]->conf.rx_short_sync = 0;
// if (i2s_config->communication_format & I2S_COMM_FORMAT_PCM_SHORT) {
// if (i2s_config->mode & I2S_MODE_TX) {
// I2S[i2s_num]->conf.tx_short_sync = 1;
// }
// if (i2s_config->mode & I2S_MODE_RX) {
// I2S[i2s_num]->conf.rx_short_sync = 1;
// }
// }
// }
if ((p_i2s_obj[i2s_num]->mode & I2S_MODE_RX) && (p_i2s_obj[i2s_num]->mode & I2S_MODE_TX)) {
I2S[i2s_num]->conf.sig_loopback = 1;
if (p_i2s_obj[i2s_num]->mode & I2S_MODE_MASTER) {
@@ -1217,7 +1218,7 @@ esp_err_t i2s_adc_enable(i2s_port_t i2s_num)
I2S_CHECK((p_i2s_obj[i2s_num] != NULL), "Not initialized yet", ESP_ERR_INVALID_STATE);
I2S_CHECK((p_i2s_obj[i2s_num]->mode & I2S_MODE_ADC_BUILT_IN), "i2s built-in adc not enabled", ESP_ERR_INVALID_STATE);
adc1_i2s_mode_acquire();
// todo: fix this adc1_i2s_mode_acquire();
_i2s_adc_mode_recover();
return i2s_set_clk(i2s_num, p_i2s_obj[i2s_num]->sample_rate, p_i2s_obj[i2s_num]->bits_per_sample, p_i2s_obj[i2s_num]->channel_num);
}

View File

@@ -14,7 +14,7 @@
#include "nvs_utilities.h"
#include "platform_esp32.h"
#include "messaging.h"
#include "trace.h"
#include "tools.h"
/************************************
* Globals
*/
@@ -38,7 +38,7 @@ messaging_handle_t get_handle_ptr(messaging_list_t * handle){
RingbufHandle_t messaging_create_ring_buffer(uint8_t max_count){
RingbufHandle_t buf_handle = NULL;
StaticRingbuffer_t *buffer_struct = malloc(sizeof(StaticRingbuffer_t));
StaticRingbuffer_t *buffer_struct = malloc_init_external(sizeof(StaticRingbuffer_t));
if (buffer_struct != NULL) {
size_t buf_size = (size_t )(sizeof(single_message_t)+8+MSG_LENGTH_AVG)*(size_t )(max_count>0?max_count:5); // no-split buffer requires an additional 8 bytes
buf_size = buf_size - (buf_size % 4);
@@ -76,7 +76,7 @@ messaging_handle_t messaging_register_subscriber(uint8_t max_count, char * name)
while(cur->next){
cur = get_struct_ptr(cur->next);
}
cur->next=heap_caps_malloc(sizeof(messaging_list_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
cur->next=malloc_init_external(sizeof(messaging_list_t));
if(!cur->next){
ESP_LOGE(tag,"subscriber alloc failed");
return NULL;
@@ -84,7 +84,7 @@ messaging_handle_t messaging_register_subscriber(uint8_t max_count, char * name)
memset(cur->next,0x00,sizeof(messaging_list_t));
cur = get_struct_ptr(cur->next);
cur->max_count=max_count;
cur->subscriber_name=strdup(name);
cur->subscriber_name=strdup_psram(name);
cur->buf_handle = messaging_create_ring_buffer(max_count);
if(cur->buf_handle){
messaging_fill_messages(cur);
@@ -99,7 +99,7 @@ void messaging_service_init(){
}
else {
top.max_count = max_count;
top.subscriber_name = strdup("messaging");
top.subscriber_name = strdup_psram("messaging");
}
return;
}
@@ -161,10 +161,7 @@ single_message_t * messaging_retrieve_message(RingbufHandle_t buf_handle){
vRingbufferGetInfo(buf_handle, NULL, NULL, NULL, NULL, &uxItemsWaiting);
if(uxItemsWaiting>0){
message = (single_message_t *)xRingbufferReceive(buf_handle, &item_size, pdMS_TO_TICKS(50));
message_copy = heap_caps_malloc(item_size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
if(message_copy){
memcpy(message_copy,message,item_size);
}
message_copy = clone_obj_psram(message,item_size);
vRingbufferReturnItem(buf_handle, (void *)message);
}
return message_copy;
@@ -231,14 +228,23 @@ void messaging_post_message(messaging_types type,messaging_classes msg_class, co
va_start(va, fmt);
ln = vsnprintf(NULL, 0, fmt, va)+1;
msg_size = sizeof(single_message_t)+ln;
message = (single_message_t *)heap_caps_malloc(msg_size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
message = (single_message_t *)malloc_init_external(msg_size);
vsprintf(message->message, fmt, va);
va_end(va);
message->msg_size = msg_size;
message->type = type;
message->msg_class = msg_class;
message->sent_time = esp_timer_get_time() / 1000;
ESP_LOGD(tag,"Post: %s",message->message);
if(type==MESSAGING_WARNING) {
ESP_LOGW(tag,"%s",message->message);
}
else if(type==MESSAGING_ERROR) {
ESP_LOGE(tag,"%s",message->message);
}
else {
ESP_LOGD(tag,"Post: %s",message->message);
}
while(cur){
messaging_post_to_queue(get_handle_ptr(cur), message, msg_size);
cur = get_struct_ptr(cur->next);
@@ -247,11 +253,25 @@ void messaging_post_message(messaging_types type,messaging_classes msg_class, co
return;
}
char * messaging_alloc_format_string(const char *fmt, ...) {
va_list va;
va_start(va, fmt);
size_t ln = vsnprintf(NULL, 0, fmt, va)+1;
char * message_txt = malloc_init_external(ln);
if(message_txt){
vsprintf(message_txt, fmt, va);
va_end(va);
}
else{
ESP_LOGE(tag, "Memory allocation failed while sending message");
}
return message_txt;
}
void log_send_messaging(messaging_types msgtype,const char *fmt, ...) {
va_list va;
va_start(va, fmt);
size_t ln = vsnprintf(NULL, 0, fmt, va)+1;
char * message_txt = malloc(ln);
char * message_txt = malloc_init_external(ln);
if(message_txt){
vsprintf(message_txt, fmt, va);
va_end(va);
@@ -263,12 +283,13 @@ void log_send_messaging(messaging_types msgtype,const char *fmt, ...) {
ESP_LOGE(tag, "Memory allocation failed while sending message");
}
}
void cmd_send_messaging(const char * cmdname,messaging_types msgtype, const char *fmt, ...){
va_list va;
va_start(va, fmt);
size_t cmd_len = strlen(cmdname)+1;
size_t ln = vsnprintf(NULL, 0, fmt, va)+1;
char * message_txt = malloc(ln+cmd_len);
char * message_txt = malloc_init_external(ln+cmd_len);
if(message_txt){
strcpy(message_txt,cmdname);
strcat(message_txt,"\n");

View File

@@ -3,6 +3,10 @@
#include "freertos/ringbuf.h"
#include "cJSON.h"
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
MESSAGING_INFO,
MESSAGING_WARNING,
@@ -35,6 +39,7 @@ single_message_t * messaging_retrieve_message(RingbufHandle_t buf_handle);
void log_send_messaging(messaging_types msgtype,const char *fmt, ...);
void cmd_send_messaging(const char * cmdname,messaging_types msgtype, const char *fmt, ...);
esp_err_t messaging_type_to_err_type(messaging_types type);
char * messaging_alloc_format_string(const char *fmt, ...) ;
void messaging_service_init();
#define REALLOC_CAT(e,n) e=realloc(e,strlen(n)); e=strcat(e,n)
@@ -48,3 +53,6 @@ messaging_post_message(y, MESSAGING_CLASS_SYSTEM, ##__VA_ARGS__); }
#define LOG_SEND_WARN( ...) LOG_SEND(MESSAGING_WARNING,##__VA_ARGS__)
#ifdef __cplusplus
}
#endif

View File

@@ -23,7 +23,7 @@
#include "accessors.h"
#include "messaging.h"
#include "cJSON.h"
#include "trace.h"
#include "tools.h"
#define MONITOR_TIMER (10*1000)
#define SCRATCH_SIZE 256
@@ -54,7 +54,7 @@ static void task_stats( cJSON* top ) {
} current, previous;
cJSON * tlist=cJSON_CreateArray();
current.n = uxTaskGetNumberOfTasks();
current.tasks = malloc( current.n * sizeof( TaskStatus_t ) );
current.tasks = malloc_init_external( current.n * sizeof( TaskStatus_t ) );
current.n = uxTaskGetSystemState( current.tasks, current.n, &current.total );
cJSON_AddNumberToObject(top,"ntasks",current.n);
@@ -126,11 +126,13 @@ static void monitor_callback(TimerHandle_t xTimer) {
cJSON_AddNumberToObject(top,"free_spiram",heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
cJSON_AddNumberToObject(top,"min_free_spiram",heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
ESP_LOGI(TAG, "Heap internal:%zu (min:%zu) external:%zu (min:%zu)",
ESP_LOGI(TAG, "Heap internal:%zu (min:%zu) external:%zu (min:%zu) dma:%zu (min:%zu)",
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
heap_caps_get_free_size(MALLOC_CAP_DMA),
heap_caps_get_minimum_free_size(MALLOC_CAP_DMA));
task_stats(top);
char * top_a= cJSON_PrintUnformatted(top);
@@ -248,11 +250,13 @@ void monitor_svc_init(void) {
}
FREE_AND_NULL(p);
ESP_LOGI(TAG, "Heap internal:%zu (min:%zu) external:%zu (min:%zu)",
ESP_LOGI(TAG, "Heap internal:%zu (min:%zu) external:%zu (min:%zu) dma:%zu (min:%zu)",
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
heap_caps_get_free_size(MALLOC_CAP_DMA),
heap_caps_get_minimum_free_size(MALLOC_CAP_DMA));
}
/****************************************************************************************

View File

@@ -111,6 +111,7 @@ void services_init(void) {
if (spi_config->mosi_io_num != -1 && spi_config->sclk_io_num != -1) {
spi_bus_initialize( spi_system_host, spi_config, 1 );
if (spi_system_dc_gpio != -1) {
gpio_reset_pin(spi_system_dc_gpio);
gpio_set_direction( spi_system_dc_gpio, GPIO_MODE_OUTPUT );
gpio_set_level( spi_system_dc_gpio, 0 );
} else {

View File

@@ -0,0 +1,22 @@
# this must be set *before* idf_component_register
set(CMAKE_CXX_STANDARD 17)
idf_component_register(
SRC_DIRS .
INCLUDE_DIRS . "cspot/include" "cspot/bell/include"
PRIV_REQUIRES mbedtls mdns nvs_flash platform_config services esp_http_server tools codecs
LDFRAGMENTS "linker.lf"
)
add_definitions(-Wno-unused-variable -Wno-unused-const-variable -Wchar-subscripts -Wunused-label -Wmaybe-uninitialized -Wmisleading-indentation)
set(BELL_DISABLE_CODECS ON)
set(BELL_DISABLE_SINKS ON)
set(CSPOT_TARGET_ESP32 ON)
# becase CMake is so broken, the cache set below overrides a normal "set" for the first build
set(BELL_EXTERNAL_TREMOR "idf::codecs" CACHE STRING "provide own codecs")
set(BELL_EXTERNAL_CJSON "idf::json" CACHE STRING "provide own CJSON")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cspot ${CMAKE_CURRENT_BINARY_DIR}/cspot)
target_link_libraries(${COMPONENT_LIB} PRIVATE cspot ${EXTRA_REQ_LIBS})

388
components/spotify/Shim.cpp Normal file
View File

@@ -0,0 +1,388 @@
/*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*
*/
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_http_server.h"
#include <ConstantParameters.h>
#include <Session.h>
#include <SpircController.h>
#include <MercuryManager.h>
#include <ZeroconfAuthenticator.h>
#include <ApResolve.h>
#include <HTTPServer.h>
#include "ConfigJSON.h"
#include "Logger.h"
#include "platform_config.h"
#include "tools.h"
#include "cspot_private.h"
#include "cspot_sink.h"
#include "Shim.h"
extern "C" {
httpd_handle_t get_http_server(int *port);
static esp_err_t handlerWrapper(httpd_req_t *req);
};
#define CSPOT_STACK_SIZE (8*1024)
static const char *TAG = "cspot";
// using a global is pretty ugly, but it's easier with all Lambda below
static EXT_RAM_ATTR struct cspot_s {
char name[32];
cspot_cmd_cb_t cHandler;
cspot_data_cb_t dHandler;
TaskHandle_t TaskHandle;
std::shared_ptr<LoginBlob> blob;
} cspot;
std::shared_ptr<ConfigJSON> configMan;
std::shared_ptr<NVSFile> file;
std::shared_ptr<MercuryManager> mercuryManager;
std::shared_ptr<SpircController> spircController;
/****************************************************************************************
* Main task (could it be deleted after spirc has started?)
*/
static void cspotTask(void *pvParameters) {
char configName[] = "cspot_config";
std::string jsonConfig;
// Config file
file = std::make_shared<NVSFile>();
configMan = std::make_shared<ConfigJSON>(configName, file);
// We might have no config at all
if (!file->readFile(configName, jsonConfig) || !jsonConfig.length()) {
ESP_LOGW(TAG, "Cannot load config, using default");
configMan->deviceName = cspot.name;
configMan->format = AudioFormat_OGG_VORBIS_160;
configMan->volume = 32767;
configMan->save();
}
// safely load config now
configMan->load();
if (!configMan->deviceName.length()) configMan->deviceName = cspot.name;
ESP_LOGI(TAG, "Started CSpot with %s (bitrate %d)", configMan->deviceName.c_str(), configMan->format == AudioFormat_OGG_VORBIS_320 ? 320 : (configMan->format == AudioFormat_OGG_VORBIS_160 ? 160 : 96));
// All we do here is notify the task to start the mercury loop
auto createPlayerCallback = [](std::shared_ptr<LoginBlob> blob) {
// TODO: handle/refuse that another user takes ownership
cspot.blob = blob;
xTaskNotifyGive(cspot.TaskHandle);
};
int port;
httpd_handle_t server = get_http_server(&port);
auto httpServer = std::make_shared<ShimHTTPServer>(server, port);
auto authenticator = std::make_shared<ZeroconfAuthenticator>(createPlayerCallback, httpServer);
authenticator->registerHandlers();
// wait to be notified and have a mercury loop
while (1) {
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
auto session = std::make_unique<Session>();
session->connectWithRandomAp();
auto token = session->authenticate(cspot.blob);
ESP_LOGI(TAG, "Creating Spotify (using CSpot) player");
// Auth successful
if (token.size() > 0 && cspot.cHandler(CSPOT_SETUP, 44100)) {
auto audioSink = std::make_shared<ShimAudioSink>();
mercuryManager = std::make_shared<MercuryManager>(std::move(session));
mercuryManager->startTask();
spircController = std::make_shared<SpircController>(mercuryManager, cspot.blob->username, audioSink);
spircController->setEventHandler([](CSpotEvent &event) {
ESP_LOGI(TAG, "Getting Spotify event %d ", (int) event.eventType);
switch (event.eventType) {
case CSpotEventType::TRACK_INFO: {
TrackInfo track = std::get<TrackInfo>(event.data);
cspot.cHandler(CSPOT_TRACK, 44100, track.duration, track.artist.c_str(),
track.album.c_str(), track.name.c_str(), track.imageUrl.c_str());
break;
}
case CSpotEventType::PLAY_PAUSE: {
bool isPaused = std::get<bool>(event.data);
if (isPaused) cspot.cHandler(CSPOT_PAUSE);
else cspot.cHandler(CSPOT_PLAY, false);
break;
}
case CSpotEventType::PLAYBACK_START:
cspot.cHandler(CSPOT_PLAY, (int) std::get<bool>(event.data));
break;
case CSpotEventType::LOAD:
cspot.cHandler(CSPOT_LOAD, std::get<int>(event.data), -1);
break;
case CSpotEventType::SEEK:
cspot.cHandler(CSPOT_SEEK, std::get<int>(event.data));
break;
case CSpotEventType::DISC:
cspot.cHandler(CSPOT_DISC);
spircController->stopPlayer();
mercuryManager->stop();
break;
case CSpotEventType::PREV:
case CSpotEventType::NEXT:
cspot.cHandler(CSPOT_FLUSH);
break;
/*
// we use volume from sink which is a 16 bits value
case CSpotEventType::VOLUME: {
int volume = std::get<int>(event.data);
cspot.cHandler(CSPOT_VOLUME, volume);
ESP_LOGW(TAG, "cspot volume : %d", volume);
break;
}
*/
default:
break;
}
});
mercuryManager->reconnectedCallback = []() {
return spircController->subscribe();
};
mercuryManager->handleQueue();
// release controllers
mercuryManager.reset();
spircController.reset();
}
// release auth blob and flush files
cspot.blob.reset();
file->flush();
ESP_LOGI(TAG, "Shutting down CSpot player");
}
// we should not be here
vTaskDelete(NULL);
}
/****************************************************************************************
* API to create and start a cspot instance
*/
struct cspot_s* cspot_create(const char *name, cspot_cmd_cb_t cmd_cb, cspot_data_cb_t data_cb) {
static DRAM_ATTR StaticTask_t xTaskBuffer __attribute__ ((aligned (4)));
static EXT_RAM_ATTR StackType_t xStack[CSPOT_STACK_SIZE] __attribute__ ((aligned (4)));
bell::setDefaultLogger();
cspot.cHandler = cmd_cb;
cspot.dHandler = data_cb;
strncpy(cspot.name, name, sizeof(cspot.name) - 1);
cspot.TaskHandle = xTaskCreateStatic(&cspotTask, "cspot", CSPOT_STACK_SIZE, NULL, CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT - 2, xStack, &xTaskBuffer);
return &cspot;
}
/****************************************************************************************
* Commands sent by local buttons/actions
*/
bool cspot_cmd(struct cspot_s* ctx, cspot_event_t event, void *param) {
// we might have not controller left
if (!spircController.use_count()) return false;
switch(event) {
case CSPOT_PREV:
spircController->prevSong();
break;
case CSPOT_NEXT:
spircController->nextSong();
break;
case CSPOT_TOGGLE:
spircController->playToggle();
break;
case CSPOT_PAUSE:
spircController->setPause(true);
break;
case CSPOT_PLAY:
spircController->setPause(false);
break;
case CSPOT_DISC:
spircController->disconnect();
break;
case CSPOT_STOP:
spircController->stopPlayer();
break;
case CSPOT_VOLUME_UP:
spircController->adjustVolume(MAX_VOLUME / 100 + 1);
break;
case CSPOT_VOLUME_DOWN:
spircController->adjustVolume(-(MAX_VOLUME / 100 + 1));
break;
default:
break;
}
return true;
}
/****************************************************************************************
* AudioSink class to push data to squeezelite backend (decode_external)
*/
void ShimAudioSink::volumeChanged(uint16_t volume) {
cspot.cHandler(CSPOT_VOLUME, volume);
}
void ShimAudioSink::feedPCMFrames(const uint8_t *data, size_t bytes) {
cspot.dHandler(data, bytes);
}
/****************************************************************************************
* NVSFile class to store config
*/
bool NVSFile::readFile(std::string filename, std::string &fileContent) {
auto search = files.find(filename);
// cache
if (search == files.end()) {
char *content = (char*) config_alloc_get(NVS_TYPE_STR, filename.c_str());
if (!content) return false;
fileContent = content;
free(content);
} else {
fileContent = search->second;
}
return true;
}
bool NVSFile::writeFile(std::string filename, std::string fileContent) {
auto search = files.find(filename);
files[filename] = fileContent;
if (search == files.end()) return (ESP_OK == config_set_value(NVS_TYPE_STR, filename.c_str(), fileContent.c_str()));
return true;
}
bool NVSFile::flush() {
esp_err_t err = ESP_OK;
for (auto it = files.begin(); it != files.end(); ++it) {
err |= config_set_value(NVS_TYPE_STR, it->first.c_str(), it->second.c_str());
}
return (err == ESP_OK);
}
/****************************************************************************************
* Shim HTTP server for spirc
*/
static esp_err_t handlerWrapper(httpd_req_t *req) {
std::unique_ptr<bell::HTTPRequest> request = std::make_unique<bell::HTTPRequest>();
char *query = NULL, *body = NULL;
bell::httpHandler *handler = (bell::httpHandler*) req->user_ctx;
size_t query_len = httpd_req_get_url_query_len(req);
request->connection = httpd_req_to_sockfd(req);
// get body if any (add '\0' at the end if used as string)
if (req->content_len) {
body = (char*) calloc(1, req->content_len + 1);
int size = httpd_req_recv(req, body, req->content_len);
request->body = body;
ESP_LOGD(TAG,"wrapper received body %d/%d", size, req->content_len);
}
// parse query if any (can be in body as well for url-encoded)
if (query_len) {
query = (char*) malloc(query_len + 1);
httpd_req_get_url_query_str(req, query, query_len + 1);
} else if (body && strchr(body, '&')) {
query = body;
body = NULL;
}
// I know this is very crude and unsafe...
url_decode(query);
char *key = strtok(query, "&");
while (key) {
char *value = strchr(key, '=');
*value++ = '\0';
request->queryParams[key] = value;
ESP_LOGD(TAG,"wrapper received key:%s value:%s", key, value);
key = strtok(NULL, "&");
};
if (query) free(query);
if (body) free(body);
/*
This is a strange construct as the C++ handler will call the ShimHTTPSer::respond
and then we'll return. So we can't obtain the response to be sent, as esp_http_server
normally expects, instead respond() will use raw socket and close connection
*/
(*handler)(std::move(request));
return ESP_OK;
}
void ShimHTTPServer::registerHandler(bell::RequestType requestType, const std::string &routeUrl, bell::httpHandler handler, bool readDataToStr) {
httpd_uri_t request = {
.uri = routeUrl.c_str(),
.method = (requestType == bell::RequestType::GET ? HTTP_GET : HTTP_POST),
.handler = handlerWrapper,
.user_ctx = NULL,
};
// find the first free spot and register handler
for (int i = 0; i < sizeof(uriHandlers)/sizeof(bell::httpHandler); i++) {
if (!uriHandlers[i]) {
uriHandlers[i] = handler;
request.user_ctx = uriHandlers + i;
httpd_register_uri_handler(serverHandle, &request);
break;
}
}
if (!request.user_ctx) ESP_LOGW(TAG, "Cannot add handler for %s", routeUrl.c_str());
}
void ShimHTTPServer::respond(const bell::HTTPResponse &response) {
char *buf;
size_t len = asprintf(&buf, "HTTP/1.1 %d OK\r\n"
"Server: SQUEEZEESP32\r\n"
"Connection: close\r\n"
"Content-type: %s\r\n"
"Content-length: %d\r\n"
"Access-Control-Allow-Origin: *\r\n"
"Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS\r\n"
"Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token\r\n"
"\r\n%s",
response.status, response.contentType.c_str(),
response.body.size(), response.body.c_str()
);
// use raw socket send and close connection
httpd_socket_send(serverHandle, response.connectionFd, buf, len, 0);
free(buf);
// we want to close the socket due to the strange construct
httpd_sess_trigger_close(serverHandle, response.connectionFd);
}

49
components/spotify/Shim.h Normal file
View File

@@ -0,0 +1,49 @@
/*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*
*/
#pragma once
#include <vector>
#include <iostream>
#include <map>
#include "AudioSink.h"
#include "FileHelper.h"
#include "BaseHTTPServer.h"
#include <stdio.h>
#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include "esp_err.h"
#include "esp_http_server.h"
#include "esp_log.h"
class ShimAudioSink : public AudioSink {
public:
ShimAudioSink(void) { softwareVolumeControl = false; }
void feedPCMFrames(const uint8_t *data, size_t bytes);
virtual void volumeChanged(uint16_t volume);
};
class NVSFile : public FileHelper {
private:
std::map<std::string, std::string> files;
public:
bool readFile(std::string filename, std::string &fileContent);
bool writeFile(std::string filename, std::string fileContent);
bool flush();
};
class ShimHTTPServer : public bell::BaseHTTPServer {
private:
httpd_handle_t serverHandle;
bell::httpHandler uriHandlers[4];
public:
ShimHTTPServer(httpd_handle_t server, int port) { serverHandle = server; serverPort = port; }
void registerHandler(bell::RequestType requestType, const std::string &, bell::httpHandler, bool readDataToStr = false);
void respond(const bell::HTTPResponse &);
};

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