47 lines
824 B
C
Raw Normal View History

2026-04-06 00:06:45 +02:00
#include <ch32fun.h>
2026-04-09 20:51:44 +02:00
#include <stdint.h>
2026-04-09 17:16:19 +02:00
#include <stdio.h>
#include <string.h>
#include <fsusb.h>
2026-04-09 20:51:44 +02:00
#define PIN_LED PA4
uint8_t pin = 0;
2026-04-09 17:16:19 +02:00
// this callback is mandatory when FUNCONF_USE_USBPRINTF is defined,
// can be empty though
void handle_usbfs_input(int numbytes, uint8_t *data)
{
if(numbytes == 1) {
switch(data[0]) {
case 'b':
printf("HAHAHA\n");
break;
}
}
else {
_write(0, (const char*)data, numbytes);
}
}
2026-04-06 00:06:45 +02:00
__attribute__((noreturn)) int main(void)
{
2026-04-09 17:16:19 +02:00
SystemInit();
funGpioInitAll();
2026-04-09 20:51:44 +02:00
funPinMode(PIN_LED, GPIO_CFGLR_OUT_10Mhz_PP);
2026-04-09 17:16:19 +02:00
USBFSSetup();
2026-04-09 20:51:44 +02:00
Delay_Ms(500);
2026-04-09 17:16:19 +02:00
unsigned int count = 0;
2026-04-09 20:51:44 +02:00
for (uint32_t x = 0; true ; x++) {
2026-04-09 17:16:19 +02:00
poll_input(); // usb
2026-04-09 20:51:44 +02:00
if ((x % 100) == 0) {
printf("[%d]: Hello From CH32X035\n", count++);
funDigitalWrite(PIN_LED, pin);
pin = !pin;
}
Delay_Ms(1);
2026-04-06 00:06:45 +02:00
}
}