More module decomposition.
Needs much more on device testing.
This commit is contained in:
@ -10,6 +10,7 @@ into the parent directory, next to the ESPforth.ino file.
|
||||
|
||||
These are the current optional modules:
|
||||
* assemblers.h - Assemblers for ESP32 Xtensa and ESP32 RISC-V
|
||||
* camera.h - Support for the ESP32-CAM camera
|
||||
* oled.h - Support for the SSD1306 Oled
|
||||
|
||||
Initially ESP32forth focused on a minimal C kernel, with most functionality
|
||||
|
||||
130
esp32/optional/camera/camera.fs
Normal file
130
esp32/optional/camera/camera.fs
Normal file
@ -0,0 +1,130 @@
|
||||
\ Copyright 2021 Bradley D. Nelson
|
||||
\
|
||||
\ 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.
|
||||
|
||||
internals definitions
|
||||
transfer camera-builtins
|
||||
DEFINED? esp_camera_init [IF]
|
||||
forth definitions
|
||||
|
||||
( Lazy loaded camera handling for ESP32-CAM )
|
||||
: camera r|
|
||||
|
||||
vocabulary camera camera definitions
|
||||
also internals
|
||||
transfer camera-builtins
|
||||
|
||||
0 constant PIXFORMAT_RGB565
|
||||
1 constant PIXFORMAT_YUV422
|
||||
2 constant PIXFORMAT_GRAYSCALE
|
||||
3 constant PIXFORMAT_JPEG
|
||||
4 constant PIXFORMAT_RGB888
|
||||
5 constant PIXFORMAT_RAW
|
||||
6 constant PIXFORMAT_RGB444
|
||||
7 constant PIXFORMAT_RGB555
|
||||
|
||||
0 constant FRAMESIZE_96x96 ( 96x96)
|
||||
1 constant FRAMESIZE_QQVGA ( 160x120 )
|
||||
2 constant FRAMESIZE_QCIF ( 176x144 )
|
||||
3 constant FRAMESIZE_HQVGA ( 240x176 )
|
||||
4 constant FRAMESIZE_240x240 ( 176x144 )
|
||||
5 constant FRAMESIZE_QVGA ( 320x240 )
|
||||
6 constant FRAMESIZE_CIF ( 400x296 )
|
||||
7 constant FRAMESIZE_HVGA ( 480x320 )
|
||||
8 constant FRAMESIZE_VGA ( 640x480 )
|
||||
9 constant FRAMESIZE_SVGA ( 800x600 )
|
||||
10 constant FRAMESIZE_XGA ( 1024x768 )
|
||||
11 constant FRAMESIZE_HD ( 1280x720 )
|
||||
12 constant FRAMESIZE_SXGA ( 1280x1024 )
|
||||
13 constant FRAMESIZE_UXGA ( 1600x1200 )
|
||||
|
||||
( See https://github.com/espressif/esp32-camera/blob/master/driver/include/esp_camera.h )
|
||||
( Settings for AI_THINKER )
|
||||
create camera-config
|
||||
32 , ( pin_pwdn ) -1 , ( pin_reset ) 0 , ( pin_xclk )
|
||||
26 , ( pin_sscb_sda ) 27 , ( pin_sscb_scl )
|
||||
35 , 34 , 39 , 36 , 21 , 19 , 18 , 5 , ( pin_d7 - pin_d0 )
|
||||
25 , ( pin_vsync ) 23 , ( pin_href ) 22 , ( pin_pclk )
|
||||
20000000 , ( xclk_freq_hz )
|
||||
0 , ( ledc_timer ) 0 , ( ledc_channel )
|
||||
here
|
||||
PIXFORMAT_JPEG , ( pixel_format )
|
||||
here
|
||||
FRAMESIZE_VGA , ( frame_size )
|
||||
here
|
||||
12 , ( jpeg_quality 0-63 low good )
|
||||
here
|
||||
1 , ( fb_count )
|
||||
constant camera-fb-count
|
||||
constant camera-jpeg-quality
|
||||
constant camera-frame-size
|
||||
constant camera-format
|
||||
|
||||
: field@ ( n -- n ) dup create , cell+ does> @ + @ ;
|
||||
|
||||
0
|
||||
field@ fb->buf
|
||||
field@ fb->len
|
||||
field@ fb->width
|
||||
field@ fb->height
|
||||
field@ fb->format
|
||||
field@ fb->sec
|
||||
field@ fb->usec
|
||||
drop
|
||||
|
||||
5 cells
|
||||
field@ s->xclk_freq_hz ( a )
|
||||
field@ s->init_status ( s )
|
||||
field@ s->reset ( s )
|
||||
field@ s->set_pixformat ( s pixformat )
|
||||
field@ s->set_framesize ( s framesize )
|
||||
field@ s->set_contrast ( s level )
|
||||
field@ s->set_brightness ( s level )
|
||||
field@ s->set_saturation ( s level )
|
||||
field@ s->set_sharpness ( s level )
|
||||
field@ s->set_denoise ( s level )
|
||||
field@ s->set_gainceiling ( s gainceil )
|
||||
field@ s->set_quality ( s quality )
|
||||
field@ s->set_colorbar ( s enable )
|
||||
field@ s->set_whitebal ( s enable )
|
||||
field@ s->set_gain_ctrl ( s enable )
|
||||
field@ s->set_exposure_ctrl ( s enable )
|
||||
field@ s->set_hmirror ( s enable )
|
||||
field@ s->set_vflip ( s enable )
|
||||
|
||||
field@ s->set_aec2 ( s enable )
|
||||
field@ s->set_awb_gain ( s enable )
|
||||
field@ s->set_agc_gain ( s gain )
|
||||
field@ s->set_aec_value ( s gain )
|
||||
|
||||
field@ s->set_special_effect ( s effect )
|
||||
field@ s->set_wb_mode ( s mode )
|
||||
field@ s->set_ae_level ( s level )
|
||||
|
||||
field@ s->set_raw_gma ( s enable )
|
||||
field@ s->set_lenc ( s enable )
|
||||
|
||||
field@ s->get_reg ( s reg mask )
|
||||
field@ s->set_reg ( s reg mask value )
|
||||
field@ s->set_res_raw ( s startX startY endX endY offsetX offsetY totalX totalY outputX outputY scale binning )
|
||||
field@ s->set_pll ( s bypass mul sys root pre seld5 pclken pclk )
|
||||
field@ s->set_xclk ( s time xclk )
|
||||
drop
|
||||
|
||||
forth definitions
|
||||
camera
|
||||
| evaluate ;
|
||||
|
||||
[ELSE]
|
||||
forth definitions
|
||||
[THEN]
|
||||
35
esp32/optional/camera/camera.h
Normal file
35
esp32/optional/camera/camera.h
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright 2023 Bradley D. Nelson
|
||||
//
|
||||
// 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.
|
||||
|
||||
/*
|
||||
* ESP32forth ESP32-CAM Camera v{{VERSION}}
|
||||
* Revision: {{REVISION}}
|
||||
*/
|
||||
|
||||
#ifndef SIM_PRINT_ONLY
|
||||
# include "esp_camera.h"
|
||||
#endif
|
||||
#define OPTIONAL_CAMERA_VOCABULARY V(camera)
|
||||
#define OPTIONAL_CAMERA_SUPPORT \
|
||||
XV(internals, "camera-source", CAMERA_SOURCE, \
|
||||
PUSH camera_source; PUSH sizeof(camera_source) - 1) \
|
||||
YV(camera, esp_camera_init, n0 = esp_camera_init((camera_config_t *) a0)) \
|
||||
YV(camera, esp_camera_deinit, PUSH esp_camera_deinit()) \
|
||||
YV(camera, esp_camera_fb_get, PUSH esp_camera_fb_get()) \
|
||||
YV(camera, esp_camera_fb_return, esp_camera_fb_return((camera_fb_t *) a0); DROP) \
|
||||
YV(camera, esp_camera_sensor_get, PUSH esp_camera_sensor_get()) \
|
||||
YV(camera, esp_camera_save_to_nvs, n0 = esp_camera_save_to_nvs(c0)) \
|
||||
YV(camera, esp_camera_load_from_nvs, n0 = esp_camera_load_from_nvs(c0))
|
||||
|
||||
{{camera}}
|
||||
87
esp32/optional/camera/camera_server.fs
Normal file
87
esp32/optional/camera/camera_server.fs
Normal file
@ -0,0 +1,87 @@
|
||||
\ Copyright 2021 Bradley D. Nelson
|
||||
\
|
||||
\ 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.
|
||||
|
||||
( Lazy loaded Camera Server )
|
||||
: camera-server r~
|
||||
|
||||
camera httpd
|
||||
vocabulary camera-server camera-server definitions
|
||||
also camera also httpd
|
||||
|
||||
r|
|
||||
<!DOCTYPE html>
|
||||
<body>
|
||||
<img id="pic">
|
||||
<script>
|
||||
var pic = document.getElementById('pic');
|
||||
function httpPost(url, callback) {
|
||||
var r = new XMLHttpRequest();
|
||||
r.responseType = 'blob';
|
||||
r.onreadystatechange = function() {
|
||||
if (this.readyState == XMLHttpRequest.DONE) {
|
||||
if (this.status === 200) {
|
||||
callback(this.response);
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
r.open('POST', url);
|
||||
r.send();
|
||||
}
|
||||
function Frame() {
|
||||
httpPost('./image', function(r) {
|
||||
if (r !== null) {
|
||||
try {
|
||||
pic.src = URL.createObjectURL(r);
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
setTimeout(Frame, 30);
|
||||
});
|
||||
}
|
||||
Frame();
|
||||
</script>
|
||||
| constant index-html# constant index-html
|
||||
|
||||
: handle-index
|
||||
s" text/html" ok-response
|
||||
index-html index-html# send
|
||||
;
|
||||
|
||||
: handle-image
|
||||
s" image/jpeg" ok-response
|
||||
esp_camera_fb_get dup dup @ swap cell+ @ send
|
||||
esp_camera_fb_return
|
||||
;
|
||||
|
||||
: handle1
|
||||
handleClient if
|
||||
s" /" path str= if handle-index exit then
|
||||
s" /image" path str= if handle-image exit then
|
||||
notfound-response
|
||||
then
|
||||
;
|
||||
|
||||
: do-serve begin ['] handle1 catch drop pause again ;
|
||||
|
||||
: server ( port -- )
|
||||
server
|
||||
camera-config esp_camera_init throw
|
||||
do-serve
|
||||
;
|
||||
|
||||
only forth definitions
|
||||
camera-server
|
||||
~ evaluate ;
|
||||
37
esp32/optional/oled/oled.fs
Normal file
37
esp32/optional/oled/oled.fs
Normal file
@ -0,0 +1,37 @@
|
||||
\ Copyright 2023 Bradley D. Nelson
|
||||
\
|
||||
\ 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.
|
||||
|
||||
vocabulary oled oled definitions
|
||||
transfer oled-builtins
|
||||
DEFINED? OledNew [IF]
|
||||
128 constant WIDTH
|
||||
64 constant HEIGHT
|
||||
-1 constant OledReset
|
||||
0 constant BLACK
|
||||
1 constant WHITE
|
||||
1 constant SSD1306_EXTERNALVCC
|
||||
2 constant SSD1306_SWITCHCAPVCC
|
||||
: OledInit
|
||||
OledAddr @ 0= if
|
||||
WIDTH HEIGHT OledReset OledNew
|
||||
SSD1306_SWITCHCAPVCC $3C OledBegin drop
|
||||
then
|
||||
OledCLS
|
||||
2 OledTextsize ( Draw 2x Scale Text )
|
||||
WHITE OledTextc ( Draw white text )
|
||||
0 0 OledSetCursor ( Start at top-left corner )
|
||||
z" *Esp32forth*" OledPrintln OledDisplay
|
||||
;
|
||||
[THEN]
|
||||
forth definitions
|
||||
@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
/*
|
||||
* ESP32forth Assemblers v{{VERSION}}
|
||||
* ESP32forth Oled v{{VERSION}}
|
||||
* Revision: {{REVISION}}
|
||||
*/
|
||||
|
||||
@ -22,12 +22,15 @@
|
||||
// Adafruit GFX Library
|
||||
// Adafruit BusIO
|
||||
|
||||
# ifndef SIM_PRINT_ONLY
|
||||
# include <Adafruit_GFX.h>
|
||||
# include <Adafruit_SSD1306.h>
|
||||
#ifndef SIM_PRINT_ONLY
|
||||
# include <Adafruit_GFX.h>
|
||||
# include <Adafruit_SSD1306.h>
|
||||
static Adafruit_SSD1306 *oled_display = 0;
|
||||
# endif
|
||||
# define OPTIONAL_OLED_SUPPORT \
|
||||
#endif
|
||||
#define OPTIONAL_OLED_VOCABULARY V(oled)
|
||||
#define OPTIONAL_OLED_SUPPORT \
|
||||
XV(internals, "oled-source", OLED_SOURCE, \
|
||||
PUSH oled_source; PUSH sizeof(oled_source) - 1) \
|
||||
YV(oled, OledAddr, PUSH &oled_display) \
|
||||
YV(oled, OledNew, oled_display = new Adafruit_SSD1306(n2, n1, &Wire, n0); DROPn(3)) \
|
||||
YV(oled, OledDelete, delete oled_display) \
|
||||
@ -51,3 +54,5 @@ static Adafruit_SSD1306 *oled_display = 0;
|
||||
YV(oled, OledRectF, oled_display->fillRect(n4, n3, n2, n1, n0); DROPn(3)) \
|
||||
YV(oled, OledRectR, oled_display->drawRoundRect(n5, n4, n3, n2, n1, n0); DROPn(5)) \
|
||||
YV(oled, OledRectRF, oled_display->fillRoundRect(n5, n4, n3, n2, n1, n0 ); DROPn(5))
|
||||
|
||||
{{oled}}
|
||||
40
esp32/optional/serial-bluetooth/bterm.fs
Normal file
40
esp32/optional/serial-bluetooth/bterm.fs
Normal file
@ -0,0 +1,40 @@
|
||||
\ Copyright 2021 Bradley D. Nelson
|
||||
\
|
||||
\ 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.
|
||||
|
||||
DEFINED? bluetooth [IF]
|
||||
|
||||
( Lazy loaded Bluetooth Serial Terminal )
|
||||
: bterm r|
|
||||
vocabulary bterm bterm definitions
|
||||
also bluetooth also internals also esp
|
||||
120000 getFreeHeap - 0 max relinquish ( must have 110k for bluetooth )
|
||||
z" forth xx:xx:xx:xx:xx:xx" constant name
|
||||
( Create unique name for device )
|
||||
base @ hex getEfuseMac
|
||||
<# # # char : hold # # #> name 6 + swap cmove
|
||||
<# # # char : hold # # char : hold # # char : hold # # #> name c + swap cmove
|
||||
base !
|
||||
SerialBT.new constant bt
|
||||
name 0 bt SerialBT.begin drop
|
||||
." Bluetooth Serial Terminal on: " name z>s type cr
|
||||
: bt-type ( a n -- ) bt SerialBT.write drop ;
|
||||
: bt-key? ( -- f ) bt SerialBT.available 0<> pause ;
|
||||
: bt-key ( -- ch ) begin bt-key? until 0 >r rp@ 1 bt SerialBT.readBytes drop r> ;
|
||||
: bt-on ['] bt-type is type ['] bt-key is key ['] bt-key? is key? ;
|
||||
: bt-off ['] default-type is type ['] default-key is key ['] default-key? is key? ;
|
||||
only forth definitions
|
||||
bterm 500 ms bt-on
|
||||
| evaluate ;
|
||||
|
||||
[THEN]
|
||||
23
esp32/optional/serial-bluetooth/serial-bluetooth.fs
Normal file
23
esp32/optional/serial-bluetooth/serial-bluetooth.fs
Normal file
@ -0,0 +1,23 @@
|
||||
\ Copyright 2023 Bradley D. Nelson
|
||||
\
|
||||
\ 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.
|
||||
|
||||
DEFINED? SerialBT.new [IF]
|
||||
vocabulary bluetooth bluetooth definitions
|
||||
transfer bluetooth-builtins
|
||||
forth definitions
|
||||
[ELSE]
|
||||
internals definitions
|
||||
transfer bluetooth-builtins
|
||||
forth definitions
|
||||
[THEN]
|
||||
51
esp32/optional/serial-bluetooth/serial-bluetooth.h
Normal file
51
esp32/optional/serial-bluetooth/serial-bluetooth.h
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright 2022 Bradley D. Nelson
|
||||
//
|
||||
// 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.
|
||||
|
||||
/*
|
||||
* ESP32forth Serial Bluetooth v{{VERSION}}
|
||||
* Revision: {{REVISION}}
|
||||
*/
|
||||
|
||||
#ifndef SIM_PRINT_ONLY
|
||||
# include "esp_bt_device.h"
|
||||
# include "BluetoothSerial.h"
|
||||
# define bt0 ((BluetoothSerial *) a0)
|
||||
#endif
|
||||
#define OPTIONAL_BLUETOOTH_VOCABULARY V(bluetooth)
|
||||
#define OPTIONAL_SERIAL_BLUETOOTH_SUPPORT \
|
||||
XV(internals, "bterm-source", BTERM_SOURCE, \
|
||||
PUSH bterm_source; PUSH sizeof(bterm_source) - 1) \
|
||||
XV(bluetooth, "SerialBT.new", SERIALBT_NEW, PUSH new BluetoothSerial()) \
|
||||
XV(bluetooth, "SerialBT.delete", SERIALBT_DELETE, delete bt0; DROP) \
|
||||
XV(bluetooth, "SerialBT.begin", SERIALBT_BEGIN, n0 = bt0->begin(c2, n1); NIPn(2)) \
|
||||
XV(bluetooth, "SerialBT.end", SERIALBT_END, bt0->end(); DROP) \
|
||||
XV(bluetooth, "SerialBT.available", SERIALBT_AVAILABLE, n0 = bt0->available()) \
|
||||
XV(bluetooth, "SerialBT.readBytes", SERIALBT_READ_BYTES, n0 = bt0->readBytes(b2, n1); NIPn(2)) \
|
||||
XV(bluetooth, "SerialBT.write", SERIALBT_WRITE, n0 = bt0->write(b2, n1); NIPn(2)) \
|
||||
XV(bluetooth, "SerialBT.flush", SERIALBT_FLUSH, bt0->flush(); DROP) \
|
||||
XV(bluetooth, "SerialBT.hasClient", SERIALBT_HAS_CLIENT, n0 = bt0->hasClient()) \
|
||||
XV(bluetooth, "SerialBT.enableSSP", SERIALBT_ENABLE_SSP, bt0->enableSSP(); DROP) \
|
||||
XV(bluetooth, "SerialBT.setPin", SERIALBT_SET_PIN, n0 = bt0->setPin(c1); NIP) \
|
||||
XV(bluetooth, "SerialBT.unpairDevice", SERIALBT_UNPAIR_DEVICE, \
|
||||
n0 = bt0->unpairDevice(b1); NIP) \
|
||||
XV(bluetooth, "SerialBT.connect", SERIALBT_CONNECT, n0 = bt0->connect(c1); NIP) \
|
||||
XV(bluetooth, "SerialBT.connectAddr", SERIALBT_CONNECT_ADDR, n0 = bt0->connect(b1); NIP) \
|
||||
XV(bluetooth, "SerialBT.disconnect", SERIALBT_DISCONNECT, n0 = bt0->disconnect()) \
|
||||
XV(bluetooth, "SerialBT.connected", SERIALBT_CONNECTED, n0 = bt0->connected(n1); NIP) \
|
||||
XV(bluetooth, "SerialBT.isReady", SERIALBT_IS_READY, n0 = bt0->isReady(n2, n1); NIPn(2)) \
|
||||
/* Bluetooth */ \
|
||||
YV(bluetooth, esp_bt_dev_get_address, PUSH esp_bt_dev_get_address())
|
||||
#endif
|
||||
|
||||
{{serial_bluetooth}}
|
||||
45
esp32/optional/spi-flash/spi-flash.fs
Normal file
45
esp32/optional/spi-flash/spi-flash.fs
Normal file
@ -0,0 +1,45 @@
|
||||
\ Copyright 2023 Bradley D. Nelson
|
||||
\
|
||||
\ 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.
|
||||
|
||||
vocabulary spi_flash spi_flash definitions
|
||||
transfer spi_flash-builtins
|
||||
DEFINED? spi_flash_init [IF]
|
||||
0 constant SPI_PARTITION_TYPE_APP
|
||||
1 constant SPI_PARTITION_TYPE_DATA
|
||||
$ff constant SPI_PARTITION_SUBTYPE_ANY
|
||||
|
||||
also structures
|
||||
struct esp_partition_t
|
||||
( Work around changing struct layout )
|
||||
esp_partition_t_size 40 >= [IF]
|
||||
ptr field p>gap
|
||||
[THEN]
|
||||
ptr field p>type
|
||||
ptr field p>subtype
|
||||
ptr field p>address
|
||||
ptr field p>size
|
||||
ptr field p>label
|
||||
|
||||
: p. ( part -- )
|
||||
base @ >r >r decimal
|
||||
." TYPE: " r@ p>type @ . ." SUBTYPE: " r@ p>subtype @ .
|
||||
." ADDR: " r@ hex p>address @ . ." SIZE: " r@ p>size @ .
|
||||
." LABEL: " r> p>label @ z>s type cr r> base ! ;
|
||||
: list-partition-type ( type -- )
|
||||
SPI_PARTITION_SUBTYPE_ANY 0 esp_partition_find
|
||||
begin dup esp_partition_get p. esp_partition_next dup 0= until drop ;
|
||||
: list-partitions SPI_PARTITION_TYPE_APP list-partition-type
|
||||
SPI_PARTITION_TYPE_DATA list-partition-type ;
|
||||
[THEN]
|
||||
only forth definitions
|
||||
81
esp32/optional/spi-flash/spi-flash.h
Normal file
81
esp32/optional/spi-flash/spi-flash.h
Normal file
@ -0,0 +1,81 @@
|
||||
// Copyright 2023 Bradley D. Nelson
|
||||
//
|
||||
// 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.
|
||||
|
||||
/*
|
||||
* ESP32forth SPI Flash v{{VERSION}}
|
||||
* Revision: {{REVISION}}
|
||||
*/
|
||||
|
||||
#ifndef SIM_PRINT_ONLY
|
||||
# include "esp_spi_flash.h"
|
||||
# include "esp_partition.h"
|
||||
#endif
|
||||
#define OPTIONAL_SPI_FLASH_VOCABULARY V(spi_flash)
|
||||
#define OPTIONAL_SPI_FLASH_SUPPORT \
|
||||
XV(internals, "spi_flash-source", SPI_FLASH_SOURCE, \
|
||||
PUSH spi_flash_source; PUSH sizeof(spi_flash_source) - 1) \
|
||||
YV(spi_flash, spi_flash_init, spi_flash_init()) \
|
||||
YV(spi_flash, spi_flash_get_chip_size, PUSH spi_flash_get_chip_size()) \
|
||||
YV(spi_flash, spi_flash_erase_sector, n0 = spi_flash_erase_sector(n0)) \
|
||||
YV(spi_flash, spi_flash_erase_range, n0 = spi_flash_erase_range(n1, n0); DROP) \
|
||||
YV(spi_flash, spi_flash_write, n0 = spi_flash_write(n2, a1, n0); NIPn(2)) \
|
||||
YV(spi_flash, spi_flash_write_encrypted, n0 = spi_flash_write_encrypted(n2, a1, n0); NIPn(2)) \
|
||||
YV(spi_flash, spi_flash_read, n0 = spi_flash_read(n2, a1, n0); NIPn(2)) \
|
||||
YV(spi_flash, spi_flash_read_encrypted, n0 = spi_flash_read_encrypted(n2, a1, n0); NIPn(2)) \
|
||||
YV(spi_flash, spi_flash_mmap, \
|
||||
n0 = spi_flash_mmap(n4, n3, (spi_flash_mmap_memory_t) n2, \
|
||||
(const void **) a1, (spi_flash_mmap_handle_t *) a0); NIPn(4)) \
|
||||
YV(spi_flash, spi_flash_mmap_pages, \
|
||||
n0 = spi_flash_mmap_pages((const int *) a4, n3, (spi_flash_mmap_memory_t) n2, \
|
||||
(const void **) a1, (spi_flash_mmap_handle_t *) a0); NIPn(4)) \
|
||||
YV(spi_flash, spi_flash_munmap, spi_flash_munmap((spi_flash_mmap_handle_t) a0); DROP) \
|
||||
YV(spi_flash, spi_flash_mmap_dump, spi_flash_mmap_dump()) \
|
||||
YV(spi_flash, spi_flash_mmap_get_free_pages, \
|
||||
n0 = spi_flash_mmap_get_free_pages((spi_flash_mmap_memory_t) n0)) \
|
||||
YV(spi_flash, spi_flash_cache2phys, n0 = spi_flash_cache2phys(a0)) \
|
||||
YV(spi_flash, spi_flash_phys2cache, \
|
||||
n0 = (cell_t) spi_flash_phys2cache(n1, (spi_flash_mmap_memory_t) n0); NIP) \
|
||||
YV(spi_flash, spi_flash_cache_enabled, PUSH spi_flash_cache_enabled()) \
|
||||
YV(spi_flash, esp_partition_find, \
|
||||
n0 = (cell_t) esp_partition_find((esp_partition_type_t) n2, \
|
||||
(esp_partition_subtype_t) n1, c0); NIPn(2)) \
|
||||
YV(spi_flash, esp_partition_find_first, \
|
||||
n0 = (cell_t) esp_partition_find_first((esp_partition_type_t) n2, \
|
||||
(esp_partition_subtype_t) n1, c0); NIPn(2)) \
|
||||
YV(spi_flash, esp_partition_t_size, PUSH sizeof(esp_partition_t)) \
|
||||
YV(spi_flash, esp_partition_get, \
|
||||
n0 = (cell_t) esp_partition_get((esp_partition_iterator_t) a0)) \
|
||||
YV(spi_flash, esp_partition_next, \
|
||||
n0 = (cell_t) esp_partition_next((esp_partition_iterator_t) a0)) \
|
||||
YV(spi_flash, esp_partition_iterator_release, \
|
||||
esp_partition_iterator_release((esp_partition_iterator_t) a0); DROP) \
|
||||
YV(spi_flash, esp_partition_verify, n0 = (cell_t) esp_partition_verify((esp_partition_t *) a0)) \
|
||||
YV(spi_flash, esp_partition_read, \
|
||||
n0 = esp_partition_read((const esp_partition_t *) a3, n2, a1, n0); NIPn(3)) \
|
||||
YV(spi_flash, esp_partition_write, \
|
||||
n0 = esp_partition_write((const esp_partition_t *) a3, n2, a1, n0); NIPn(3)) \
|
||||
YV(spi_flash, esp_partition_erase_range, \
|
||||
n0 = esp_partition_erase_range((const esp_partition_t *) a2, n1, n0); NIPn(2)) \
|
||||
YV(spi_flash, esp_partition_mmap, \
|
||||
n0 = esp_partition_mmap((const esp_partition_t *) a5, n4, n3, \
|
||||
(spi_flash_mmap_memory_t) n2, \
|
||||
(const void **) a1, \
|
||||
(spi_flash_mmap_handle_t *) a0); NIPn(5)) \
|
||||
YV(spi_flash, esp_partition_get_sha256, \
|
||||
n0 = esp_partition_get_sha256((const esp_partition_t *) a1, b0); NIP) \
|
||||
YV(spi_flash, esp_partition_check_identity, \
|
||||
n0 = esp_partition_check_identity((const esp_partition_t *) a1, \
|
||||
(const esp_partition_t *) a0); NIP)
|
||||
|
||||
{{spi_flash}}
|
||||
Reference in New Issue
Block a user