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

Macros

#define MAX_IN_TIMEOUT   1000
 
#define DisableISR()
 
#define EnableISR()
 
#define GPIO_VAR_W1TC   (*GPIO_VAR_W1TC_R)
 
#define GPIO_VAR_W1TS   (*GPIO_VAR_W1TS_R)
 
#define GPIO_VAR_ENABLE_W1TC   (*GPIO_VAR_ENABLE_W1TC_R)
 
#define GPIO_VAR_ENABLE_W1TS   (*GPIO_VAR_ENABLE_W1TS_R)
 
#define GPIO_VAR_IN   (*GPIO_VAR_IN_R)
 
#define IO_MUX_REG(x)
 
#define XIO_MUX_REG(x)
 
#define GPIO_NUM(x)
 
#define XGPIO_NUM(x)
 

Functions

int uprintf (const char *fmt,...)
 vaprintf stand-in for USB logging.
 
const uint8_t * cnfsGetFile (int index, size_t *size)
 
int initCh32v003 (int swdio_pin)
 
int ch32v003WriteMemory (const uint8_t *binary, uint32_t length, uint32_t offset)
 Write to memory on the ch32v003.
 
int ch32v003WriteFlash (const uint8_t *buf, int sz)
 Write data into the ch32v003's flash.
 
int ch32v003Resume ()
 Cause the 003 to reboot and execute the program loaded into it.
 
int ch32v003ReadMemory (uint8_t *binary, uint32_t length, uint32_t offset)
 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.
 
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.
 

Variables

const uint16_t Coordmap [8 *16]
 
struct SWIOState swioContext
 

Macro Definition Documentation

◆ MAX_IN_TIMEOUT

#define MAX_IN_TIMEOUT   1000

◆ DisableISR

#define DisableISR ( )
Value:
do \
{ \
XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL); \
portbenchmarkINTERRUPT_DISABLE(); \
} while (0)

◆ EnableISR

#define EnableISR ( )
Value:
do \
{ \
portbenchmarkINTERRUPT_RESTORE(0); \
XTOS_SET_INTLEVEL(0); \
} while (0)

◆ GPIO_VAR_W1TC

#define GPIO_VAR_W1TC   (*GPIO_VAR_W1TC_R)

◆ GPIO_VAR_W1TS

#define GPIO_VAR_W1TS   (*GPIO_VAR_W1TS_R)

◆ GPIO_VAR_ENABLE_W1TC

#define GPIO_VAR_ENABLE_W1TC   (*GPIO_VAR_ENABLE_W1TC_R)

◆ GPIO_VAR_ENABLE_W1TS

#define GPIO_VAR_ENABLE_W1TS   (*GPIO_VAR_ENABLE_W1TS_R)

◆ GPIO_VAR_IN

#define GPIO_VAR_IN   (*GPIO_VAR_IN_R)

◆ IO_MUX_REG

#define IO_MUX_REG ( x)
Value:
#define XIO_MUX_REG(x)
Definition hdw-ch32v003.c:52

◆ XIO_MUX_REG

#define XIO_MUX_REG ( x)
Value:
(IO_MUX_GPIO0_REG + (x * 4))

◆ GPIO_NUM

#define GPIO_NUM ( x)
Value:
#define XGPIO_NUM(x)
Definition hdw-ch32v003.c:55

◆ XGPIO_NUM

#define XGPIO_NUM ( x)
Value:
(GPIO_NUM_0 + (x * 4))

Function Documentation

◆ uprintf()

int uprintf ( const char * fmt,
... )

vaprintf stand-in for USB logging.

Parameters
fmtvaprintf format
...vaprintf args
Returns
size Number of characters that were written.

◆ cnfsGetFile()

const uint8_t * cnfsGetFile ( int index,
size_t * size )

◆ initCh32v003()

int initCh32v003 ( int swdio_pin)

◆ 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

◆ 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.

◆ ch32v003Resume()

int ch32v003Resume ( )

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

Returns
0 if OK, nonzero in error condition.

◆ 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.

◆ 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.

Variable Documentation

◆ Coordmap

const uint16_t Coordmap[8 *16]
Initial value:
= {
0x0000, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0xffff, 0xffff, 0x0002, 0x0102, 0x0202, 0x0302, 0x0402, 0x0502,
0xffff, 0xffff, 0x0001, 0x0101, 0x0201, 0x0301, 0x0401, 0x0501, 0xffff, 0xffff, 0x0008, 0x0108, 0x0208, 0x0308,
0x0408, 0x0508, 0xffff, 0xffff, 0x0007, 0x0107, 0x0207, 0x0307, 0x0407, 0x0507, 0xffff, 0xffff, 0x0006, 0x0106,
0x0206, 0x0306, 0x0406, 0x0506, 0xffff, 0xffff, 0x0005, 0x0205, 0x0405, 0x0605, 0x0600, 0x0700, 0xffff, 0xffff,
0x0004, 0x0204, 0x0404, 0x0604, 0x0602, 0x0702, 0xffff, 0xffff, 0x0003, 0x0203, 0x0403, 0x0603, 0x0601, 0x0701,
0xffff, 0xffff, 0x0105, 0x0305, 0x0505, 0x0705, 0x0608, 0x0708, 0xffff, 0xffff, 0x0104, 0x0304, 0x0504, 0x0704,
0x0607, 0x0707, 0xffff, 0xffff, 0x0103, 0x0303, 0x0503, 0x0703, 0x0606, 0x0706, 0xffff, 0xffff,
}

◆ swioContext

struct SWIOState swioContext