Skip to content

Instantly share code, notes, and snippets.

View boochow's full-sized avatar
🏠
Working from home

boochow

🏠
Working from home
View GitHub Profile
sd = SD()
os.mount(sd, '/sd')
os.chdir('sd')
import gpu, framebuf
gpu.fb_init(320, 240, screen_w=1920, screen_h=1080)
fb = framebuf.FrameBuffer(gpu.fb_data(), 320, 240, framebuf.RGB565)
fb.fill_rect(0, 0, 320, 240, 0)
f = open('test1.raw', 'rb')
if (sd_init() == SD_OK) {
unsigned char buf[1024];
if (sd_readblock(0, buf, 1)) {
for (int i = 0; i < 512; i++) {
if (i % 16 == 0) {
printf("%04x:", i);
}
printf("%02x ", buf[i]);
if ((i + 1) % 16 == 0) {
printf("\n\r");
class RAMBlockDev:
def __init__(self, block_size, num_blocks):
self.block_size = block_size
self.data = bytearray(block_size * num_blocks)
def readblocks(self, block_num, buf):
for i in range(len(buf)):
buf[i] = self.data[block_num * self.block_size + i]
def writeblocks(self, block_num, buf):
import time
def performanceTest():
millis = time.ticks_ms
endTime = millis() + 10000
count = 0
while millis() < endTime:
count += 1
print("Count: ", count)
class RAMBlockDev:
def __init__(self, block_size, num_blocks):
self.block_size = block_size
self.data = bytearray(block_size * num_blocks)
def readblocks(self, block_num, buf):
for i in range(len(buf)):
buf[i] = self.data[block_num * self.block_size + i]
def writeblocks(self, block_num, buf):
import gpu, framebuf
gpu.fb_init(240, 135, screen_w=1920, screen_h=1080)
fb = framebuf.FrameBuffer(gpu.fb_data(), 240, 135, framebuf.RGB565)
fb.fill_rect(0,0,240,135,0)
minX = -2.0
maxX = 1.0
width = 240
height = 135
aspectRatio = 1.0
import machine, utime
log = []
def add_log(t):
global log
log.append((utime.ticks_us() & 0xffffffff) + 1000 - t.compare_register())
times = 1000
tim = machine.Timer(3)
tim.init(period=1000,mode=tim.PERIODIC,callback=lambda t:add_log(t))
typedef enum _timer_mode_t {
ONE_SHOT = 0,
PERIODIC = 1,
} timer_mode_t;
typedef struct _machine_timer_obj_t {
mp_obj_base_t base;
uint32_t id;
uint32_t period;
timer_mode_t mode;
import machine
counter = 0
def inc_ctr(t):
global counter
counter += 1
print(t)
t = machine.Timer(0)
t.init(period=1000000,mode=t.PERIODIC,callback=lambda t:inc_ctr(t))