Skip to content

Commit

Permalink
Add Inspire3D demo
Browse files Browse the repository at this point in the history
  • Loading branch information
eric15342335 committed Aug 23, 2024
1 parent 4559405 commit 0cb1b72
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
12 changes: 12 additions & 0 deletions inspire3d-demo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
TARGET:=inspire3d-demo
include ../ch32v003fun/ch32v003fun.mk
clean:
rm -f $(TARGET).elf $(TARGET).hex $(TARGET).bin $(TARGET).map $(TARGET).lst \
$(TARGET).o $(TARGET).d $(TARGET).srec $(TARGET).sym $(TARGET).lss
$(MAKE) -f Makefile-emulator clean

emulator:
$(MAKE) -f Makefile-emulator clean
$(MAKE) -f Makefile-emulator

.PHONY: emulator clean
35 changes: 35 additions & 0 deletions inspire3d-demo/Makefile-emulator
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
CC=gcc
INCLUDES=-I../emulator -I../data -I.
CFLAGS=-g -Wall -Wextra -Wshadow -Wswitch -Wfloat-equal $(INCLUDES)
LDFLAGS=$(CFLAGS)

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
LDFLAGS += -framework CoreFoundation -framework ApplicationServices -pthread
endif

SRCS=inspire3d-demo.c
TARGET=inspire3d-demo

SRCS += $(wildcard ../emulator/*.c)
ifneq ($(UNAME_S), Darwin)
SRCS := $(filter-out ../emulator/system_mac.c,$(SRCS))
endif
OBJS = $(SRCS:.c=.o)
# Default target
all: $(TARGET)

# Linking
$(TARGET): $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) -o $(TARGET)

# Compiling
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

# Clean up
clean:
rm -f $(OBJS) $(TARGET) *.exe

# Phony targets
.PHONY: all clean
18 changes: 18 additions & 0 deletions inspire3d-demo/funconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _FUNCONFIG_H
#define _FUNCONFIG_H

#define CH32V003 1
#define FUNCONF_USE_DEBUGPRINTF 0
#define FUNCONF_USE_UARTPRINTF 1
#define FUNCONF_UART_PRINTF_BAUD 115200
#define FUNCONF_SYSTICK_USE_HCLK 1
#define GPIO_ADC_MUX_DELAY 1200
// todo: fix name
#define horizontalButtons 25
#define verticalButtons 5
#define NUM_LEDS (horizontalButtons * verticalButtons)

//#define CH32V003J4M6_USE_PD6_AS_UART_TX
//#define INTERNAL_INSPIRE_MATRIX

#endif
43 changes: 43 additions & 0 deletions inspire3d-demo/inspire3d-demo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#define WS2812BSIMPLE_IMPLEMENTATION
#include "buttons.h"
#include "ch32v003_GPIO_branchless.h"
#include "colors.h"
#include "driver.h"
#include "ws2812b_simple.h"

#include <stdio.h>

#define LED_PINS GPIOA, 2

#define x_max 5
#define y_max 5
#define z_max 5
#if (x_max * y_max * z_max) != NUM_LEDS
#error "x_max * y_max * z_max must equal NUM_LEDS"
// todo: fix name
#endif
// convert position of LEDs to x, y, z coordinates
void convert_pos_to_xyz(uint16_t pos, uint8_t *x, uint8_t *y, uint8_t *z) {
*x = pos % x_max;
*y = (pos / x_max) % y_max;
*z = pos / (x_max * y_max);
}

#define color_multiplier 20
int main(void) {
SystemInit();
while (1) {
clear();
for (uint16_t i = 0; i < NUM_LEDS; i++) {
uint8_t x, y, z;
convert_pos_to_xyz(i, &x, &y, &z);
// not using set_color to achieve maximum brightness
led_array[i].r = x * color_multiplier;
led_array[i].g = y * color_multiplier;
led_array[i].b = z * color_multiplier;
WS2812BSimpleSend(LED_PINS, (uint8_t *)led_array, NUM_LEDS * 3);
printf("Hello, World!\n");
Delay_Ms(20);
}
}
}

0 comments on commit 0cb1b72

Please sign in to comment.