支持 Arduino Nano, 2KB 内存

This commit is contained in:
chai2010
2025-06-20 06:20:13 +08:00
parent 5756cbf8f5
commit 465a281744
6 changed files with 62 additions and 6 deletions

View File

@@ -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) {

View File

@@ -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]))
}
}

View File

@@ -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 {

View File

@@ -97,6 +97,10 @@ func LCDPrint(s: string) {
}
}
func LCDWriteChar(ch: rune) {
writeChar(byte(ch))
}
// Claer screen.
func LCDClear {
command(0x01)

View File

@@ -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 策略

View File

@@ -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