aboutsummaryrefslogtreecommitdiff
path: root/src/kern/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kern/main.c')
-rw-r--r--src/kern/main.c86
1 files changed, 31 insertions, 55 deletions
diff --git a/src/kern/main.c b/src/kern/main.c
index fab2eb9..2b97197 100644
--- a/src/kern/main.c
+++ b/src/kern/main.c
@@ -2,9 +2,11 @@
#include "arch/arm/cortex-m4/mpu.h"
#include "arch/stm32l4xxx/peripherals/clock.h"
#include "arch/stm32l4xxx/peripherals/dma.h"
+#include "arch/stm32l4xxx/peripherals/exti.h"
#include "arch/stm32l4xxx/peripherals/irq.h"
#include "arch/stm32l4xxx/peripherals/rcc.h"
#include "arch/stm32l4xxx/peripherals/spi.h"
+#include "arch/stm32l4xxx/peripherals/syscfg.h"
#include "arch/stm32l4xxx/peripherals/system.h"
#include "drv/ws2812B/ws2812b.h"
#include "kern/delay.h"
@@ -82,68 +84,42 @@ static uint32_t bytescale(uint32_t n, uint32_t sc)
/* Main function. This gets executed from the interrupt vector defined above. */
int main()
{
- klogf("Entering main\n");
- gpio_reserved_pin_t sysled = get_sysled();
+ regset(RCC.apb2en_r, rcc_syscfgen, 1);
- systick_add_callback(on_systick, NULL);
- enable_systick(1000);
- configure_gpio();
+ klogf("Entering main\n");
int ec;
- ws2812b_t* drv = ws2812b_new(SPI_SELECT_SPI1, &ec);
-
- if (ec || !drv) {
- panic("Unable to create WS2812b driver :( (%d)\n", ec);
- }
-
-#define SIZE 256
- rgb_t rgb[SIZE];
- for (int i = 0; i < SIZE; ++i) {
- rgb[i].g = 0xff;
- rgb[i].r = 0xff;
- rgb[i].b = 0xff;
- }
+ gpio_reserved_pin_t sysled = get_sysled();
- uint32_t red = 0x40;
- uint32_t green = 0x40;
- uint32_t brightness = 255;
+ gpio_pin_opts_t opts = DEFAULT_GPIO_OPTS_INPUT;
+ opts.pull_dir = GPIO_PULL_DIR_NONE;
+ gpio_reserved_pin_t pb6 = reserve_gpio_pin(GPIO_PIN_PB6, &opts, &ec);
- for (int i = 0; i < 100; ++i) {
- ws2812b_write_rgb_sync(drv, 0, 0, 0);
+ if (ec) {
+ panic("Unable to reserve GPIO pin ec=%d\n", ec);
}
- ws2812b_latch(drv);
-
- for (;;) {
- set_gpio_pin_high(sysled);
- ws2812b_latch(drv);
-
- int i;
- for (i = 0; i < SIZE; ++i) {
- red = byte_sin(time / 1000 + i * 4);
- green = 255 - red;
-
- brightness = 3 * byte_sin(time / 5000) / 4 + 63;
-
- /* Add a little white flair that comes around every once in a while. */
- uint32_t white = time / 137 + i * 4;
- if ((white / 256) % 8 == 0) {
- white = amp(byte_sin(white));
- } else {
- white = 0;
- }
-
- ws2812b_write_rgb_sync(
- drv,
- bytescale(min(red + white, 255), brightness),
- bytescale(min(green + white, 255), brightness),
- bytescale(white, brightness));
- }
-
- set_gpio_pin_low(sysled);
-
- ws2812b_latch(drv);
- }
+ // while (1) {
+ // if (get_gpio_pin_input_state(pb6)) {
+ // set_gpio_pin_high(sysled);
+ // } else {
+ // set_gpio_pin_low(sysled);
+ // }
+ // // klogf("GPIO is set? %d\n", get_gpio_pin_input_state(pb6));
+ // }
+
+ regset(SYSCFG.extic_r2, syscfg_exti6, 1 /* Port B. */);
+ regset(EXTI.im_r1, exti_im_n(6), 1); /* Enable the EXTI interrupt. */
+ regset(EXTI.fts_r1, exti_ft_n(6), 1); /* Enable for falling edge. */
+ regset(EXTI.rts_r1, exti_rt_n(6), 1); /* Enable for rising edge. */
+ enable_interrupt(IRQ_EXTI9_5);
+ enable_interrupt(IRQ_EXTI0_IRQ);
+ enable_interrupt(IRQ_EXTI1_IRQ);
+ enable_interrupt(IRQ_EXTI2_IRQ);
+ enable_interrupt(IRQ_EXTI3_IRQ);
+ enable_interrupt(IRQ_EXTI4_IRQ);
+
+ for(;;);
}
#endif