Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
hdw-ch32v003.h File Reference

Detailed Description

This file contains the header to control the semihosted ch32v003 via the swio programming pin.

Go to the source code of this file.

Macros

#define CH32V003_MAX_IMAGE_SLOTS   20
 
#define ch32v003RunBinaryAsset(asset)
 Load and run a binary image from the assets folder on the ch32v003. Included as a #define because we can't include main functionality in a module.
 

Functions

int initCh32v003 (int swdio_pin)
 
int ch32v003WriteFlash (const uint8_t *buf, int sz)
 Write data into the ch32v003's flash.
 
int ch32v003WriteMemory (const uint8_t *binary, uint32_t length, uint32_t address)
 Write to memory on the ch32v003.
 
int ch32v003ReadMemory (uint8_t *binary, uint32_t length, uint32_t address)
 Read data from the ch32v003's memory space into host processor memory space.
 
int ch32v003GetReg (int regno, uint32_t *value)
 Read ch32v003 debug module registers.
 
int ch32v003SetReg (int regno, uint32_t regValue)
 Write ch32v003 debug module registers.
 
int ch32v003Resume ()
 Cause the 003 to reboot and execute the program loaded into it.
 
void ch32v003CheckTerminal ()
 See if the ch32v003 has any pending printf to print on host processor.
 
void ch32v003Teardown ()
 Disables ch32v003 communications.
 
int ch32v003WriteBitmapAsset (int slot, int asset_idx)
 Halt the processor, and write to RAM a greyscale asset image.
 
int ch32v003WriteBitmap (int slot, uint8_t pixels[6][12])
 Write a 12x6 pixel greyscale image into a RAM slot on the ch32v003.
 
int ch32v003SelectBitmap (int slot)
 Override the DMA pointer on the 003 to point at a pre-loaded image in RAM.
 
void ch32v003EmuDraw (int window_w, int window_h)
 

Macro Definition Documentation

◆ CH32V003_MAX_IMAGE_SLOTS

#define CH32V003_MAX_IMAGE_SLOTS   20

◆ ch32v003RunBinaryAsset

#define ch32v003RunBinaryAsset ( asset)
Value:
({ \
size_t sz; \
const uint8_t* buf = cnfsGetFile(asset, &sz); \
int r = ch32v003WriteFlash(buf, sz); \
ch32v003Resume(); \
r; \
})
const uint8_t * cnfsGetFile(cnfsFileIdx_t fIdx, size_t *flen)
Get a pointer to a file, without needing to read it. Same rules that apply to cnfsGetFile,...
Definition cnfs.c:65
int ch32v003WriteFlash(const uint8_t *buf, int sz)
Write data into the ch32v003's flash.
Definition hdw-ch32v003.c:206

Load and run a binary image from the assets folder on the ch32v003. Included as a #define because we can't include main functionality in a module.

Parameters
assetcnfsFileIdx_t of a binary image to be loaded into a location in the ch32v003. This must be of type cnfsFileIdx_t
Returns
0 if OK, nonzero in error condition.

Function Documentation

◆ initCh32v003()

int initCh32v003 ( int swdio_pin)

◆ ch32v003WriteFlash()

int ch32v003WriteFlash ( const uint8_t * buf,
int sz )

Write data into the ch32v003's flash.

Parameters
bufA pointer to a binary image in the master processor
szThe size of the binary image to be written
Returns
0 if OK, nonzero in error condition.

◆ ch32v003WriteMemory()

int ch32v003WriteMemory ( const uint8_t * binary,
uint32_t length,
uint32_t offset )

Write to memory on the ch32v003.

Parameters
binaryA binary image to be loaded into a location in the ch32v003.
lengthThe size of the binary image.
offsetThe offset of the binary image.s

◆ ch32v003ReadMemory()

int ch32v003ReadMemory ( uint8_t * binary,
uint32_t length,
uint32_t offset )

Read data from the ch32v003's memory space into host processor memory space.

Parameters
binaryA pointer to a buffer in the host processor
lengthThe number of bytes to read
offsetThe location of memory to read in the ch32v003
Returns
0 if OK, nonzero if error.

◆ ch32v003GetReg()

int ch32v003GetReg ( int regno,
uint32_t * value )

Read ch32v003 debug module registers.

Parameters
regnoThe debug module register number.
valueA pointer to the uint32_t to receive that register's value.
Returns
0 if OK, nonzero if error.

◆ ch32v003SetReg()

int ch32v003SetReg ( int regno,
uint32_t regValue )

Write ch32v003 debug module registers.

Parameters
regnoThe debug module register number.
regValueThe value to write into that debug module regsiter
Returns
0 if OK, nonzero if error.

◆ ch32v003Resume()

int ch32v003Resume ( )

Cause the 003 to reboot and execute the program loaded into it.

Returns
0 if OK, nonzero in error condition.

◆ ch32v003CheckTerminal()

void ch32v003CheckTerminal ( )

See if the ch32v003 has any pending printf to print on host processor.

◆ ch32v003Teardown()

void ch32v003Teardown ( )

Disables ch32v003 communications.

◆ ch32v003WriteBitmapAsset()

int ch32v003WriteBitmapAsset ( int slot,
int asset_idx )

Halt the processor, and write to RAM a greyscale asset image.

Parameters
slotMust be less than CH32V003_MAX_IMAGE_SLOTS.
asset_idxIs a .gs.png asset, for instance EYES_DEFAULT_GS (From eyes_default.gs.png). This image must be 12x6 pixels in size.
Returns
0 if OK, nonzero if error.

◆ ch32v003WriteBitmap()

int ch32v003WriteBitmap ( int slot,
uint8_t pixels[6][12] )

Write a 12x6 pixel greyscale image into a RAM slot on the ch32v003.

Parameters
slotMust be less than CH32V003_MAX_IMAGE_SLOTS.
pixelsare a greyscale image to be written out.
Returns
0 if OK, nonzero if error.

◆ ch32v003SelectBitmap()

int ch32v003SelectBitmap ( int slot)

Override the DMA pointer on the 003 to point at a pre-loaded image in RAM.

Parameters
slotMust be less than CH32V003_MAX_IMAGE_SLOTS.
Returns
0 if OK, nonzero if error.

◆ ch32v003EmuDraw()

void ch32v003EmuDraw ( int window_w,
int window_h )