aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/gpio.h14
-rw-r--r--include/pattern.h5
-rw-r--r--include/risc-v.h45
-rw-r--r--include/task.h9
-rw-r--r--include/voltdisc.h19
-rw-r--r--include/ws2812b.h12
6 files changed, 98 insertions, 6 deletions
diff --git a/include/gpio.h b/include/gpio.h
index ab793f1..99b6e5f 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -66,23 +66,25 @@ typedef enum {
typedef void (*gpio_callback_t)(gpio_pin_t pin);
#define On_Gpio(arg) \
- static void __local_on_gpio__(gpio_pin_t pin); \
+ static void __local_on_gpio__(gpio_pin_t pin); \
__attribute__((__section__( \
".gpio_callbacks"))) static volatile gpio_callback_t __gpio__position = \
__local_on_gpio__; \
static void __local_on_gpio__(arg)
+void gpio_init();
+
/** Configure the given gpio pin for .*/
-void configure_gpio(gpio_pin_t pin, gpio_config_t);
+void gpio_configure_pin(gpio_pin_t pin, gpio_config_t);
/** Read the input value of the gpio. */
-int read_gpio(gpio_pin_t pin);
+int gpio_read(gpio_pin_t pin);
/** Sets the gpio pin. */
-void set_gpio(gpio_pin_t pin, int high);
+void gpio_set(gpio_pin_t pin, int high);
/** Set or unset the peripheral to the alternate set of pins. */
-void enable_alternate_funciton(alternate_function_t af, int enable);
+void gpio_enable_alternate_function(alternate_function_t af, int enable);
/** Enables the interrupt for a with the provided interrupt mode. */
-void enable_gpio_interrupt(gpio_pin_t pin, interrupt_mode_t int_mode);
+void gpio_enable_interrupt(gpio_pin_t pin, interrupt_mode_t int_mode);
diff --git a/include/pattern.h b/include/pattern.h
index f5d0a1b..f56e1ec 100644
--- a/include/pattern.h
+++ b/include/pattern.h
@@ -24,3 +24,8 @@ extern pattern_t PATTERNS_END;
#define patterns (&PATTERNS_START)
#define n_patterns (&PATTERNS_END - &PATTERNS_START)
+
+rgb_t twinkle(uint32_t t, size_t x);
+
+rgb_t more_twinkle(uint32_t t, size_t x);
+
diff --git a/include/risc-v.h b/include/risc-v.h
new file mode 100644
index 0000000..946ca7c
--- /dev/null
+++ b/include/risc-v.h
@@ -0,0 +1,45 @@
+#pragma once
+
+#include <stdint.h>
+
+/* Macros and functions for generic RISC-V cores. */
+
+/* Wait for interrupt macro. */
+static inline void wfi()
+{
+ asm volatile("wfi");
+}
+
+/* The mode for the mtvec. */
+typedef enum {
+ MODE_DIRECT = 0,
+ MODE_VECTORED = 1,
+} mtvec_mode_t;
+
+/* Macro to read the value from a RISC-V CSR. */
+#define csrr(csr) \
+ ({ \
+ uint32_t _tmp_csr; \
+ asm volatile("csrr %0, " csr : "=r"(_tmp_csr)); \
+ _tmp_csr; \
+ })
+
+/* Macro to write a value to a RISC-V CSR. */
+#define csrw(csr, v) \
+ { \
+ asm volatile("csrw " csr ", %0" : : "r"(v)); \
+ }
+
+/* Sets the mtvec to point to the given vector_table with the given mode. */
+static inline void set_mtvec(void* vector_table, mtvec_mode_t mode)
+{
+ uint32_t mtvec = (uint32_t)vector_table;
+ mtvec |= !!mode;
+ csrw("mtvec", mtvec);
+}
+
+#define MCAUSE csrr("mcause")
+#define MEPC csrr("mepc")
+#define MTVAL csrr("mtval")
+
+#define __nop() asm volatile ("nop")
diff --git a/include/task.h b/include/task.h
new file mode 100644
index 0000000..63fe543
--- /dev/null
+++ b/include/task.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include <stdint.h>
+
+typedef struct {
+ uint32_t x[32];
+
+ uint32_t pc;
+} task_t;
diff --git a/include/voltdisc.h b/include/voltdisc.h
new file mode 100644
index 0000000..562b352
--- /dev/null
+++ b/include/voltdisc.h
@@ -0,0 +1,19 @@
+#pragma once
+
+// Volatge discovery. Determines what the voltage of the christmas lights is.
+//
+// This is done by using channel 0 of the ADC (which is on pin PA4). There is a
+// voltage divider from the main power source to pin PA4 which uses a 4.7MOhm
+// resistor and a 470KOhm resistor to divide the voltage by 10, which may then
+// be turned into a reading on the ADC.
+//
+// This helps to determine if the lights being driven are WS2812b's or WS2811 as
+// the latter are run on 12v and use RGB instead of GRB byte order.
+
+
+#include <stdint.h>
+
+typedef uint32_t millivolts_t;
+
+// Returns the estimated input voltage in millivolts.
+millivolts_t get_input_voltage();
diff --git a/include/ws2812b.h b/include/ws2812b.h
index 2061379..6f8aff0 100644
--- a/include/ws2812b.h
+++ b/include/ws2812b.h
@@ -45,11 +45,23 @@ typedef struct {
uint8_t r;
uint8_t g;
uint8_t b;
+
+ /* Color alpha. 0 is perfectly opaque, 255 is perfectly transparent). */
+ uint8_t a;
};
uint32_t color;
};
} rgb_t;
+typedef struct {
+ uint8_t mat[4][4];
+} rgb_mat_t;
+
+/** Returns the new RGB as if rgb1 was overlayed on top of rgb2. */
+rgb_t blend(rgb_t rgb1, rgb_t rgb2);
+
+rgb_t mat_mul(rgb_t rgb, const rgb_mat_t* mat);
+
int write_rgb(struct ws2812b_buf* out, rgb_t color);
void start_dma(struct ws2812b_buf* buf);