Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapted f>s so rounding follows the ANS standard. #140

Merged
merged 16 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reformatted app.fth, solved a bug in ms and added .path
  • Loading branch information
pi authored and pi committed Oct 15, 2024
commit 926dc5744da33169477ae78b26458561ee4e57a8
52 changes: 27 additions & 25 deletions src/app/esp32-extra/app.fth
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
\ Load file for application-specific Forth extensions

fl ../../lib/misc.fth
fl ../../lib/dl.fth
fl ../../lib/random.fth
Expand Down Expand Up @@ -28,35 +27,38 @@ alias m-init noop
key? if key true exit then
false
;

: ms>ticks ( ms -- ticks )
esp-clk-cpu-freq #80000000 over =
if drop
else #240000000 =
if exit
else #1 lshift
then
then #3 /
esp-clk-cpu-freq #80000000 over = if
drop
else
#240000000 = if
exit
else
#1 lshift
then
then #3 /
;

: system-time>f ( us seconds -- ) ( f: -- us )
s" s>d d>f f# 1000000 f* s>d d>f f+ " evaluate ; immediate

: usf@ ( f: -- us )
: usf@ ( f: -- us )
s" dup dup sp@ get-system-time! system-time>f" evaluate ; immediate

: ms@ ( -- ms ) f# .001 usf@ f* f>d drop ;
: ms@ ( -- ms ) f# 0.001 usf@ f* f>d drop ;

alias get-msecs ms@

: fus ( f: us - )
usf@ f+
begin fdup usf@ f- f# 100000000 f>
while #100000000 us
repeat
usf@ f- f>d drop abs us ;
usf@ f+ begin
fdup usf@ f# 6000 f- f>
while
#6000 us
repeat
usf@ fswap f- f>d drop abs us
;

: ms ( ms -- ) s>d d>f f# 1000 f* fus ;
: ms ( ms -- ) s>d d>f f# 1000 f* fus ;

fl wifi.fth

Expand All @@ -81,15 +83,15 @@ fl tools/extra.fth
: load-startup-file ( -- ior ) " start" ['] included catch ;

: app ( - ) \ Sometimes SPIFFS or a wifi connection causes an error. A reboot solves that.
banner hex interrupt? 0=
if s" start" file-exist?
if load-startup-file
if ." Reading SPIFFS. " cr interrupt? 0=
if reboot
then
then
then
banner hex interrupt? 0= if
s" start" file-exist? if
load-startup-file if
." Reading SPIFFS. " cr interrupt? 0= if
reboot
then
then
then
then
quit
;

Expand Down
22 changes: 9 additions & 13 deletions src/app/esp32-extra/extend.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ cell errno_val(void) { return (cell)errno; }

extern void open_dir(void);
extern void dirent_size(void);
// extern void sd_mount(void);
extern void sd_unmount(void);


extern void software_reset(void);
extern void adc1_config_width(void);
extern void adc1_config_channel_atten(void);
Expand Down Expand Up @@ -86,10 +84,9 @@ extern void my_spiffs_unmount(void);
extern void spi_bus_init(void);
extern void spi_bus_setup(void);
extern void spi_master_data(void);

extern void spi_bus_init_slave(void);
extern void spi_slave_data(void);

extern void mysetvbuf(void);

int xTaskGetTickCount(void);
void raw_emit(char c);
Expand Down Expand Up @@ -417,16 +414,15 @@ cell ((* const ccalls[])()) = {
C(set_esp_now_callback_rcv) //c set-esp-now-callback-rcv { i.HQueueEnow -- }
C(esp_now_unregister_recv_cb) //c esp-now-unregister-recv_cb { -- }

// Spi master
C(spi_bus_init) //c spi-bus-init { i.dma, i.sclk i.miso, i.mosi -- i.res }
C(spi_bus_setup) //c spi-bus-setup { i.qsize, i.mode i.clkspeed -- i.handle }
C(spi_master_data) //c spi-master-data { i.len, a.send, a.receive, i.handle -- i.res }
C(spi_bus_init) //c spi-bus-init { i.dma i.sclk i.miso i.mosi -- i.res }
C(spi_bus_setup) //c spi-bus-setup { i.qsize i.mode i.clkspeed -- i.handle }
C(spi_master_data) //c spi-master-data { i.len a.send a.receive i.handle -- i.res }
C(spi_bus_init_slave) //c spi-bus-init-slave { i.qsize i.dma i.mode i.spics i.sclk i.miso i.mosi -- i.res }
C(spi_slave_data) //c spi-slave-data { a.recvbuf a.sendbuf i.size i.ticks_to_wait -- i.res }

// Spi slave
C(spi_bus_init_slave) //c spi-bus-init-slave { i.qsize, i.dma, i.mode, i.spics, i.sclk, i.miso, i.mosi -- i.res }
C(spi_slave_data) //c spi-slave-data { a.recvbuf, a.sendbuf, i.size i.ticks_to_wait -- i.res }

// SDcard
C(sd_mount) //c mount-sd-card { i.sd_spics i.sd_clk i.sd_miso i.sd_mosi i.format_option i.sd_speed -- i.ior }
C(sd_unmount) //c sd-unmount { -- }
C(mysetvbuf) //c setvbuf { i.handle i.method a.buf i.size -- i.res }
};


5 changes: 3 additions & 2 deletions src/app/esp32-extra/files.fth
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ create &valid-paths ," /spiffs/" ," /sdcard/"
&valid-paths +str count 2swap $= r> or
;

: get-path ( - path$ ) 0. -9 open-file drop cscount ;
: get-path ( - path$ ) 0. -9 open-file drop cscount ;
: .path ( - ) get-path type ;
: expand-name ( name$ - fullname$ ) negate -9 open-file drop cscount ;

: set-path ( path$ - )
: set-path ( path$ - )
2dup valid-path? if
0. -9 open-file drop swap cmove
else
Expand Down
2 changes: 1 addition & 1 deletion src/app/esp32-extra/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ char *dirent_name(void *ent);
void rename_file(char *new, char *old);
cell fs_avail(void);

void us(cell us);
void us(uint32_t us);

void esp_deep_sleep(uint64_t time_in_us);

Expand Down
3 changes: 3 additions & 0 deletions src/app/esp32-extra/sdcard.fth
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Change in menuconfig: Component config > FAT Filesystem support > Long filename
mount-sd-card
;

: spiffs ( - ) s" /spiffs/" set-path ;
: sdcard ( - ) s" /sdcard/" set-path ;

0 [if] \ EG:

.SDcard-settings sd-mount .
Expand Down