Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
hdw-ch32v003.h
Go to the documentation of this file.
1
6
7#ifndef _HDW_CH32V003_H_
8#define _HDW_CH32V003_H_
9
10#include <stdbool.h>
11#include <stdint.h>
12#include <driver/gpio.h>
13
14// Convenience macros for consistent LED values across modes
15#define EYE_LED_OFF 0x00
16#define EYE_LED_DIM 0x08
17#define EYE_LED_BRIGHT 0x10
18
19#define EYE_LED_W 12
20#define EYE_LED_H 6
21
22int initCh32v003(int swdio_pin);
23
24#define CH32V003_MAX_IMAGE_SLOTS 20
25
34#define ch32v003RunBinaryAsset(asset) \
35 ({ \
36 size_t sz; \
37 const uint8_t* buf = cnfsGetFile(asset, &sz); \
38 int r = ch32v003WriteFlash(buf, sz); \
39 ch32v003Resume(); \
40 vTaskDelay(10); \
41 r; \
42 })
43
44// More nitty gritty functions
45
46int ch32v003WriteFlash(const uint8_t* buf, int sz);
47int ch32v003WriteMemory(const uint8_t* binary, uint32_t length, uint32_t address);
48int ch32v003ReadMemory(uint8_t* binary, uint32_t length, uint32_t address);
49int ch32v003GetReg(int regno, uint32_t* value);
50int ch32v003SetReg(int regno, uint32_t regValue);
51int ch32v003Resume();
53void ch32v003Teardown();
54
55int ch32v003WriteBitmapAsset(int slot, int asset_idx);
56int ch32v003WriteBitmap(int slot, const uint8_t pixels[6][12]);
57int ch32v003SelectBitmap(int slot);
58
59#endif
int initCh32v003(int swdio_pin)
Definition hdw-ch32v003.c:102
int ch32v003WriteFlash(const uint8_t *buf, int sz)
Write data into the ch32v003's flash.
Definition hdw-ch32v003.c:206
void ch32v003Teardown()
Disables ch32v003 communications.
Definition hdw-ch32v003.c:365
int ch32v003WriteBitmapAsset(int slot, int asset_idx)
Halt the processor, and write to RAM a greyscale asset image.
Definition hdw-ch32v003.c:390
int ch32v003Resume()
Cause the 003 to reboot and execute the program loaded into it.
Definition hdw-ch32v003.c:264
int ch32v003GetReg(int regno, uint32_t *value)
Read ch32v003 debug module registers.
Definition hdw-ch32v003.c:320
int ch32v003WriteMemory(const uint8_t *binary, uint32_t length, uint32_t address)
Write to memory on the ch32v003.
Definition hdw-ch32v003.c:133
void ch32v003CheckTerminal()
See if the ch32v003 has any pending printf to print on host processor.
Definition hdw-ch32v003.c:349
int ch32v003ReadMemory(uint8_t *binary, uint32_t length, uint32_t address)
Read data from the ch32v003's memory space into host processor memory space.
Definition hdw-ch32v003.c:288
int ch32v003SelectBitmap(int slot)
Override the DMA pointer on the 003 to point at a pre-loaded image in RAM.
Definition hdw-ch32v003.c:472
int ch32v003WriteBitmap(int slot, const uint8_t pixels[6][12])
int ch32v003SetReg(int regno, uint32_t regValue)
Write ch32v003 debug module registers.
Definition hdw-ch32v003.c:335