Merge branch 'master' into ed/lvgl_demo

This commit is contained in:
Hsuan Han Lai 2025-03-31 19:11:13 +08:00 committed by GitHub
commit d101c167da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 3771 additions and 18 deletions

5
.gitmodules vendored
View File

@ -1,4 +1,9 @@
[submodule "Code/picocalc_helloworld/rp2040-psram"]
path = Code/picocalc_helloworld/rp2040-psram
url = https://github.com/polpo/rp2040-psram.git
[submodule "lvgl"]
path = Code/picocalc_lvgl_graphics_demo/lib/lvgl/lvgl
url = https://github.com/lvgl/lvgl.git
branch = release/v9.2

View File

@ -1,10 +1,16 @@
# How to compile FUZIX
All the operations in this document are performed in a Linux environment. A basic understanding of Linux, as well as familiarity with Git and pico sdk development, is required.
```bash
git clone https://github.com/EtchedPixels/FUZIX.git
cd FUZIX
git reset --hard f0d56efd5ba70211c4c2d0b084a154fcff30ac5a
git apply fuzix.patch
git clone https://github.com/clockworkpi/PicoCalc.git #get patch code
git apply PicoCalc/Code/FUZIX/fuzix.patch
export PICO_SDK_PATH=/to/where/your/pico/sdk/is
cd Kernel/platform/platform-rpipico

View File

@ -1,5 +1,7 @@
# PicoCalc simple mp3 player
All the operations in this document are performed in a Linux environment. A basic understanding of Linux, as well as familiarity with Git and cross-compilation development, is required.
## toolchain
```
@ -11,6 +13,12 @@ https://github.com/cuu/YAHAL.git branch picocalc
## How to compile
### Get this code
```
git clone https://github.com/clockworkpi/PicoCalc.git
```
### Get YAHAL first
```
git clone -b picocalc https://github.com/cuu/YAHAL.git

View File

@ -1,9 +1,15 @@
# How to compile NES emulator
All the operations in this document are performed in a Linux environment. A basic understanding of Linux, as well as familiarity with Git and pico sdk development, is required.
```bash
git clone https://github.com/shapoco/shapones.git
cd shapones
git apply shapones.patch
git clone https://github.com/clockworkpi/PicoCalc.git #get patch code
git apply PicoCalc/Code/NES/shapones.patch
cd samples/v3/
mkdir build
cd build

View File

@ -1,10 +1,14 @@
# How to compile PicoMite(MMBasic)
All the operations in this document are performed in a Linux environment. A basic understanding of Linux, as well as familiarity with Git and pico sdk development, is required.
```bash
git clone https://github.com/cuu/PicoMite.git
cd PicoMite
git apply PicoMite.patch
git clone https://github.com/clockworkpi/PicoCalc.git #get patch code
git apply PicoCalc/Code/PicoMite/PicoMite.patch
export PICO_SDK_PATH=/to/where/your/pico/sdk/is
mkdir build

View File

@ -14,11 +14,24 @@ include_directories(
add_subdirectory(i2ckbd)
add_subdirectory(lcdspi)
add_subdirectory(pwm_sound)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/rp2040-psram rp2040-psram)
add_executable(picocalc_helloworld
main.c
)
##picocalc spi0
target_compile_definitions(picocalc_helloworld PRIVATE
PSRAM_MUTEX=1
#PSRAM_SPINLOCK=0
PSRAM_ASYNC=0
PSRAM_PIN_CS=20
PSRAM_PIN_SCK=21
PSRAM_PIN_MOSI=2
PSRAM_PIN_MISO=3
)
target_link_libraries(picocalc_helloworld
pico_stdlib
hardware_flash
@ -33,7 +46,8 @@ target_link_libraries(picocalc_helloworld
pico_multicore
i2ckbd
lcdspi
rp2040-psram
pwm_sound
)
pico_enable_stdio_usb(picocalc_helloworld 0)

View File

@ -1,6 +1,6 @@
# PicoCalc Hello World
Demonstrate how to use spi screen and i2c keyboard on PicoCalc.
Demonstrate how to use spi screen, i2c keyboard and psram on PicoCalc.
## Building
```

View File

@ -6,15 +6,208 @@
#include <string.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "hardware/clocks.h"
#include "i2ckbd.h"
#include "lcdspi.h"
#include "psram_spi.h"
#include "pwm_sound.h"
const uint LEDPIN = 25;
psram_spi_inst_t* async_spi_inst;
int psram_test(psram_spi_inst_t*psram_spi){
uint32_t psram_begin, psram_elapsed;
float psram_speed;
char buf[128];
sprintf(buf,"Testing PSRAM...\n");
printf("%s",buf);
lcd_print_string(buf);
// **************** 8 bits testing ****************
psram_begin = time_us_32();
for (uint32_t addr = 0; addr < (8 * 1024 * 1024); ++addr) {
psram_write8(psram_spi, addr, (addr & 0xFF));
}
psram_elapsed = time_us_32() - psram_begin;
psram_speed = 1000000.0 * 8 * 1024.0 * 1024 / psram_elapsed;
sprintf(buf,"8 bit: PSRAM write 8MB in %d us, %d B/s\n", psram_elapsed, (uint32_t)psram_speed);
printf("%s", buf);
lcd_print_string(buf);
psram_begin = time_us_32();
for (uint32_t addr = 0; addr < (8 * 1024 * 1024); ++addr) {
psram_write8_async(psram_spi, addr, (addr & 0xFF));
}
psram_elapsed = time_us_32() - psram_begin;
psram_speed = 1000000.0 * 8 * 1024.0 * 1024 / psram_elapsed;
sprintf(buf,"8 bit: PSRAM write async 8MB in %d us, %d B/s\n", psram_elapsed, (uint32_t)psram_speed);
printf("%s", buf);
lcd_print_string(buf);
psram_begin = time_us_32();
for (uint32_t addr = 0; addr < (8 * 1024 * 1024); ++addr) {
uint8_t result = psram_read8(psram_spi, addr);
if ((uint8_t)(addr & 0xFF) != result) {
sprintf(buf,"\nPSRAM failure at address %x (%x != %x)\n", addr, addr & 0xFF, result);
printf("%s", buf);
lcd_print_string(buf);
return 1;
}
}
psram_elapsed = time_us_32() - psram_begin;
psram_speed = 1000000.0 * 8 * 1024.0 * 1024 / psram_elapsed;
sprintf(buf,"8 bit: PSRAM read 8MB in %d us, %d B/s\n", psram_elapsed, (uint32_t)psram_speed);
printf("%s", buf);
lcd_print_string(buf);
// **************** 16 bits testing ****************
psram_begin = time_us_32();
for (uint32_t addr = 0; addr < (8 * 1024 * 1024); addr += 2) {
psram_write16(psram_spi, addr, (((addr + 1) & 0xFF) << 8) | (addr & 0xFF));
}
psram_elapsed = time_us_32() - psram_begin;
psram_speed = 1000000.0 * 8 * 1024.0 * 1024 / psram_elapsed;
sprintf(buf,"16 bit: PSRAM write 8MB in %d us, %d B/s\n", psram_elapsed, (uint32_t)psram_speed);
printf("%s", buf);
lcd_print_string(buf);
psram_begin = time_us_32();
for (uint32_t addr = 0; addr < (8 * 1024 * 1024); addr += 2) {
uint16_t result = psram_read16(psram_spi, addr);
if ((uint16_t)(
(((addr + 1) & 0xFF) << 8) |
(addr & 0xFF)) != result
) {
sprintf(buf,"PSRAM failure at address %x (%x != %x) ", addr, (
(((addr + 1) & 0xFF) << 8) |
(addr & 0xFF)), result
);
printf("%s", buf);
lcd_print_string(buf);
return 1;
}
}
psram_elapsed = (time_us_32() - psram_begin);
psram_speed = 1000000.0 * 8 * 1024 * 1024 / psram_elapsed;
sprintf(buf,"16 bit: PSRAM read 8MB in %d us, %d B/s\n", psram_elapsed, (uint32_t)psram_speed);
printf("%s", buf);
lcd_print_string(buf);
// **************** 32 bits testing ****************
psram_begin = time_us_32();
for (uint32_t addr = 0; addr < (8 * 1024 * 1024); addr += 4) {
psram_write32(
psram_spi, addr,
(uint32_t)(
(((addr + 3) & 0xFF) << 24) |
(((addr + 2) & 0xFF) << 16) |
(((addr + 1) & 0xFF) << 8) |
(addr & 0XFF))
);
}
psram_elapsed = time_us_32() - psram_begin;
psram_speed = 1000000.0 * 8 * 1024.0 * 1024 / psram_elapsed;
sprintf(buf,"32 bit: PSRAM write 8MB in %d us, %d B/s\n", psram_elapsed, (uint32_t)psram_speed);
printf("%s", buf);
lcd_print_string(buf);
psram_begin = time_us_32();
for (uint32_t addr = 0; addr < (8 * 1024 * 1024); addr += 4) {
uint32_t result = psram_read32(psram_spi, addr);
if ((uint32_t)(
(((addr + 3) & 0xFF) << 24) |
(((addr + 2) & 0xFF) << 16) |
(((addr + 1) & 0xFF) << 8) |
(addr & 0XFF)) != result
) {
sprintf(buf,"PSRAM failure at address %x (%x != %x) ", addr, (
(((addr + 3) & 0xFF) << 24) |
(((addr + 2) & 0xFF) << 16) |
(((addr + 1) & 0xFF) << 8) |
(addr & 0XFF)), result
);
printf("%s", buf);
lcd_print_string(buf);
return 1;
}
}
psram_elapsed = (time_us_32() - psram_begin);
psram_speed = 1000000.0 * 8 * 1024 * 1024 / psram_elapsed;
sprintf(buf,"32 bit: PSRAM read 8MB in %d us, %d B/s\n", psram_elapsed, (uint32_t)psram_speed);
printf("%s", buf);
lcd_print_string(buf);
// **************** n bits testing ****************
uint8_t write_data[256];
for (size_t i = 0; i < 256; ++i) {
write_data[i] = i;
}
psram_begin = time_us_32();
for (uint32_t addr = 0; addr < (8 * 1024 * 1024); addr += 256) {
for (uint32_t step = 0; step < 256; step += 16) {
psram_write(psram_spi, addr + step, write_data + step, 16);
}
}
psram_elapsed = time_us_32() - psram_begin;
psram_speed = 1000000.0 * 8 * 1024.0 * 1024 / psram_elapsed;
sprintf(buf,"128 bit: PSRAM write 8MB in %d us, %d B/s\n", psram_elapsed, (uint32_t)psram_speed);
printf("%s", buf);
lcd_print_string(buf);
psram_begin = time_us_32();
uint8_t read_data[16];
for (uint32_t addr = 0; addr < (8 * 1024 * 1024); addr += 256) {
for (uint32_t step = 0; step < 256; step += 16) {
psram_read(psram_spi, addr + step, read_data, 16);
if (memcmp(read_data, write_data + step, 16) != 0) {
sprintf(buf,"PSRAM failure at address %x", addr);
printf("%s", buf);
lcd_print_string(buf);
return 1;
}
}
}
psram_elapsed = time_us_32() - psram_begin;
psram_speed = 1000000.0 * 8 * 1024.0 * 1024 / psram_elapsed;
sprintf(buf,"128 bit: PSRAM read 8MB in %d us, %d B/s\n", psram_elapsed, (uint32_t)psram_speed);
printf("%s", buf);
lcd_print_string(buf);
lcd_print_string("PSRAM testing done\n");
}
#include "sample.h"
int wav_position = 0;
void pwm_interrupt_handler() {
int slice_l = pwm_gpio_to_slice_num(AUDIO_PIN_L);
int slice_r = pwm_gpio_to_slice_num(AUDIO_PIN_R);
pwm_clear_irq(slice_l);
pwm_clear_irq(slice_r);
if (wav_position < (WAV_DATA_LENGTH << 3) - 1) {
pwm_set_chan_level(pwm_gpio_to_slice_num(AUDIO_PIN_L), PWM_CHAN_A, WAV_DATA[wav_position >> 3]);
pwm_set_chan_level(pwm_gpio_to_slice_num(AUDIO_PIN_R), PWM_CHAN_B, WAV_DATA[wav_position >> 3]);
wav_position++;
} else {
wav_position = 0; // Stop
pwm_set_chan_level(slice_l, PWM_CHAN_A, 0);
pwm_set_chan_level(slice_r, PWM_CHAN_B, 0);
pwm_set_irq_enabled(slice_l, false);
pwm_set_irq_enabled(slice_r, false);
irq_remove_handler(PWM_IRQ_WRAP, pwm_interrupt_handler);
//
}
}
int main() {
stdio_init_all();
set_sys_clock_khz(133000, true);
init_i2c_kbd();
lcd_init();
@ -23,11 +216,18 @@ int main() {
gpio_set_dir(LEDPIN, GPIO_OUT);
lcd_clear();
lcd_print_string("Hello World");
lcd_print_string("Hello World PicoCalc\n");
gpio_put(LEDPIN, 1);
sleep_ms(500);
gpio_put(LEDPIN, 0);
init_pwm(pwm_interrupt_handler);
psram_spi_inst_t psram_spi = psram_spi_init_clkdiv(pio1, -1,1.0f,true);
psram_test(&psram_spi);
while (1) {
int c = lcd_getc(0);
if(c != -1 && c > 0) {
lcd_putc(0,c);

View File

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 11)
project(pwm_sound
VERSION 0.0.1
DESCRIPTION "pwm_sound for rp2040."
)
add_library(pwm_sound INTERFACE)
target_sources(pwm_sound INTERFACE
pwm_sound.c
)
target_link_libraries(pwm_sound INTERFACE pico_stdlib hardware_pwm)
target_include_directories(pwm_sound INTERFACE ${CMAKE_CURRENT_LIST_DIR})

View File

@ -0,0 +1,33 @@
#include "pwm_sound.h"
void init_pwm(irq_handler_t my_handler) {
gpio_set_function(AUDIO_PIN_L, GPIO_FUNC_PWM);
gpio_set_function(AUDIO_PIN_R, GPIO_FUNC_PWM);
int slice_l = pwm_gpio_to_slice_num(AUDIO_PIN_L);
int slice_r = pwm_gpio_to_slice_num(AUDIO_PIN_R);
pwm_clear_irq(slice_l);
pwm_clear_irq(slice_r);
pwm_set_irq_enabled(slice_l, true);
pwm_set_irq_enabled(slice_r, true);
irq_set_exclusive_handler(PWM_IRQ_WRAP, my_handler);
irq_set_enabled(PWM_IRQ_WRAP, true);
pwm_config config = pwm_get_default_config();
pwm_config_set_clkdiv(&config, 6.05f); // 133MHz
pwm_config_set_wrap(&config, 250);
pwm_init(slice_l, &config, true);
pwm_init(slice_r, &config, true);
pwm_set_chan_level(slice_l, PWM_CHAN_A, 0);
pwm_set_chan_level(slice_r, PWM_CHAN_B, 0);
}

View File

@ -0,0 +1,15 @@
#ifndef PWM_SOUND_H
#define PWM_SOUND_H
#include "pico/stdlib.h"
#include "hardware/pwm.h"
#include <stdio.h>
#define PWM_CLOCK_KHZ 133000
#define AUDIO_PIN_L 26
#define AUDIO_PIN_R 27
void init_pwm(irq_handler_t);
#endif //PWM_SOUND_H

@ -0,0 +1 @@
Subproject commit 7786c93ec8d02dbb4f94a2e99645b25fb4abc2db

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,8 @@
uLisp for PicoCalc uses [Arduino IDE](https://www.arduino.cc/en/software) for development
All the operations in this document are performed in a Linux environment. A basic understanding of Linux, as well as familiarity with Git and Arduino development, is required.
## Install arduino-pico
Open up the Arduino IDE and go to File->Preferences.
@ -29,9 +31,12 @@ git clone https://github.com/technoblogy/ulisp-arm.git
cd uLisp-arm
git reset --hard 97e61151dfb236311089abd3e89029e367613f70
git reset --hard 97e61151dfb236311089abd3e89029e367613f70 #Switch to the required version
git clone https://github.com/clockworkpi/PicoCalc.git #get patch code
git apply PicoCalc/Code/uLisp/uLisp.patch
git apply uLisp.patch
```
Install **TFT_eSPI 2.5.34** in arduino ide and patch it

View File

@ -1,9 +1,7 @@
# PicoCalc A cost-effective portable MCU terminal
![picocalc](https://github.com/clockworkpi/PicoCalc/blob/master/wiki/PicoCalc.png)
---
## 📌 Features
@ -23,14 +21,11 @@ PicoCalc supports **C/C++ development** via Pico SDK,The firmware can be modifie
- I²C/SPI communication for interfacing with external sensors.
- Keyboard remapping and custom UI modifications.
See the [Code](https://github.com/clockworkpi/PicoCalc/tree/master/Code) directory for sample applications.
---
## 📢 Community & Support
- Official website: [clockworkpi.com](https://forum.clockworkpi.com/)
- Official website: [clockworkpi.com](https://www.clockworkpi.com/)
- Forum: [ClockworkPi Community](https://forum.clockworkpi.com/)
- GitHub Issues: [Report Bugs & Features](https://github.com/clockworkpi/PicoCalc/issues)