mirror of
https://gitee.com/wa-lang/wa.git
synced 2025-12-06 09:18:53 +08:00
支持 Arduino Nano, 2KB 内存
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
// 配置初始内存
|
||||
static uint8_t app_host_memory[{{.MemoryBytes}}];
|
||||
static int32_t app_host_memory_page_size = ({{.MemoryBytes}})/(1<<16);
|
||||
static uint8_t app_host_memory[1014]; // Arduino Nano 只有2KB内存, 不足1页
|
||||
static int32_t app_host_memory_page_size = 0;
|
||||
|
||||
// 初始化内存
|
||||
extern "C" void app_memory_init(uint8_t** pp_memory, int32_t* page_size) {
|
||||
|
||||
@@ -1,10 +1,57 @@
|
||||
// 版权 @2025 arduino-lcd1602 作者。保留所有权利。
|
||||
|
||||
import (
|
||||
"arduino/lcd1602"
|
||||
"syscall/arduino"
|
||||
)
|
||||
|
||||
global LED = arduino.GetPinLED()
|
||||
|
||||
func init {
|
||||
LCDInit()
|
||||
LCDPrint("Hello Wa-lang")
|
||||
arduino.PinMode(LED, 1)
|
||||
arduino.Print("凹语言(Wa)/Arduino is running ...\n")
|
||||
arduino.Print("https://wa-lang.org\n")
|
||||
arduino.Print("基于wat2c技术\n")
|
||||
|
||||
lcd1602.LCDInit()
|
||||
}
|
||||
|
||||
func Loop {
|
||||
//
|
||||
const s = "hello wa-lang!"
|
||||
|
||||
arduino.DigitalWrite(LED, arduino.HIGH)
|
||||
|
||||
lcd1602.LCDClear()
|
||||
SayHello(0, 1, s)
|
||||
SayHello(1, 0, s)
|
||||
arduino.Delay(500)
|
||||
arduino.DigitalWrite(LED, arduino.LOW)
|
||||
|
||||
lcd1602.LCDClear()
|
||||
SayHello(0, 1, s)
|
||||
SayHello(1, 1, s)
|
||||
arduino.Delay(500)
|
||||
arduino.DigitalWrite(LED, arduino.HIGH)
|
||||
|
||||
lcd1602.LCDClear()
|
||||
SayHello(0, 1, s)
|
||||
SayHello(1, 2, s)
|
||||
arduino.Delay(500)
|
||||
arduino.DigitalWrite(LED, arduino.LOW)
|
||||
|
||||
lcd1602.LCDClear()
|
||||
SayHello(0, 1, s)
|
||||
SayHello(1, 1, s)
|
||||
arduino.Delay(500)
|
||||
arduino.DigitalWrite(LED, arduino.HIGH)
|
||||
}
|
||||
|
||||
func SayHello(row, col: i32, s: string) {
|
||||
lcd1602.LCDSetCursor(row, col)
|
||||
|
||||
// Arduino Nano 内存太小, 暂不支持 for range
|
||||
|
||||
for i := 0; i < len(s); i++ {
|
||||
lcd1602.LCDWriteChar(i32(s[i]))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ func init {
|
||||
arduino.PinMode(LED, 1)
|
||||
arduino.Print("凹语言(Wa)/Arduino is running ...\n")
|
||||
arduino.Print("https://wa-lang.org\n")
|
||||
arduino.Print("基于wat2c技术\n")
|
||||
}
|
||||
|
||||
func Loop {
|
||||
|
||||
@@ -97,6 +97,10 @@ func LCDPrint(s: string) {
|
||||
}
|
||||
}
|
||||
|
||||
func LCDWriteChar(ch: rune) {
|
||||
writeChar(byte(ch))
|
||||
}
|
||||
|
||||
// Claer screen.
|
||||
func LCDClear {
|
||||
command(0x01)
|
||||
@@ -6,6 +6,6 @@
|
||||
;; | 0 <-- stack --> | <-- static-data --> | <-- heap --> |
|
||||
;; +-----------------+---------------------+--------------+
|
||||
|
||||
(global $__stack_ptr (mut i32) (i32.const 1024)) ;; 1024
|
||||
(global $__stack_ptr (mut i32) (i32.const 128)) ;; 基本用不上
|
||||
|
||||
(global $__heap_lfixed_cap i32 (i32.const 0)) ;; 固定尺寸空闲链表最大长度, 满时回收; 也可用于关闭 fixed 策略
|
||||
|
||||
@@ -121,6 +121,9 @@ func GetStdTestPkgList() []string {
|
||||
if strings.HasPrefix(s, "syscall") {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(s, "arduino/") {
|
||||
continue
|
||||
}
|
||||
if s == "js" || strings.HasPrefix(s, "js/") {
|
||||
continue
|
||||
}
|
||||
@@ -132,6 +135,7 @@ func GetStdTestPkgList() []string {
|
||||
var stdPkgs = []string{
|
||||
"ai", // ?
|
||||
"apple", // 测试已覆盖, wat2wasm ok
|
||||
"arduino/lcd1602", // Arduino 平台, LCD显示屏
|
||||
"archive/txtar", // API 完整, wat2wasm ok
|
||||
"bufio", // API 完整, wat2wasm ok
|
||||
"bytes", // API 完整, wat2wasm ok
|
||||
|
||||
Reference in New Issue
Block a user