aboutsummaryrefslogtreecommitdiff
path: root/src/kern
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2020-12-09 23:15:14 -0700
committerJosh Rahm <joshuarahm@gmail.com>2020-12-09 23:15:14 -0700
commit5f1763ec87503527583cb1a7c6deb73604db0dfc (patch)
tree0892ddf94b614db2d879f7bc993961af5ac25bb2 /src/kern
parenta5923b21e48fcfe660c1e7d586fe0c6a5b79e421 (diff)
downloadstm32l4-5f1763ec87503527583cb1a7c6deb73604db0dfc.tar.gz
stm32l4-5f1763ec87503527583cb1a7c6deb73604db0dfc.tar.bz2
stm32l4-5f1763ec87503527583cb1a7c6deb73604db0dfc.zip
Can read from the A/C remote control!test_ir
Diffstat (limited to 'src/kern')
-rw-r--r--src/kern/lib.c5
-rw-r--r--src/kern/main.c145
-rw-r--r--src/kern/stdlibrepl.c7
3 files changed, 39 insertions, 118 deletions
diff --git a/src/kern/lib.c b/src/kern/lib.c
index 24e1658..e0d3e23 100644
--- a/src/kern/lib.c
+++ b/src/kern/lib.c
@@ -37,6 +37,11 @@ void decimalify(int v, char* into)
*into = 0;
return;
} else {
+ if (v < 0) {
+ v = -v;
+ *(into++) = '-';
+ }
+
while (v > 0) {
*(into++) = 0x30 + (v % 10);
v /= 10;
diff --git a/src/kern/main.c b/src/kern/main.c
index 082d450..208f5d9 100644
--- a/src/kern/main.c
+++ b/src/kern/main.c
@@ -2,13 +2,16 @@
#include "arch/arm/cortex-m4/mpu.h"
#include "arch/stm32l4xxx/peripherals/clock.h"
#include "arch/stm32l4xxx/peripherals/dma.h"
-#include "arch/stm32l4xxx/peripherals/tim.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 "arch/stm32l4xxx/peripherals/tim.h"
+#include "drv/ir/control.h"
+#include "drv/ir/ir.h"
+#include "drv/ir/lg_remote_codes.h"
#include "drv/ws2812B/ws2812b.h"
#include "kern/delay.h"
#include "kern/dma/dma_manager.h"
@@ -23,15 +26,7 @@
#include "kern/spi/spi_manager.h"
#include "kern/systick/systick_manager.h"
#include "user/syscall.h"
-
-void on_exti9_5()
-{
- klogf("Exit Interrupt!\n");
- klogf("Pending Reg_again: %p\n", EXTI.p_r1);
- klogf("Write: %p\n", (1 << 6));
- EXTI.p_r1 |= 1 << 6;
- klogf("Pending Reg_again: %p\n", EXTI.p_r1);
-}
+#include <assert.h>
void on_hard_fault()
{
@@ -40,120 +35,34 @@ void on_hard_fault()
#ifdef ARCH_STM32L4
-void configure_gpio()
+void printit(uint32_t code, const char* str)
{
- int ec = 0;
-
- gpio_enable_alternate_function(
- GPIO_ALTERNATE_FUNCTION_SPI1_MOSI, GPIO_PIN_PA7, &ec);
- if (ec) {
- panic("Unable to set pin PA7 (ec=%d)\n", ec);
- }
- gpio_enable_alternate_function(
- GPIO_ALTERNATE_FUNCTION_SPI1_NSS, GPIO_PIN_PA4, &ec);
- if (ec) {
- panic("Unable to set pin PA4 (ec=%d)\n", ec);
- }
- gpio_enable_alternate_function(
- GPIO_ALTERNATE_FUNCTION_SPI1_SCK, GPIO_PIN_PA5, &ec);
- if (ec) {
- panic("Unable to set pin PA5 (ec=%d)\n", ec);
- }
-}
-
-static uint8_t* compiled;
-static size_t compiled_len;
-
-extern uint8_t sintable[256];
-
-static uint32_t time;
-
-static void on_systick(void* nil)
-{
- ++time;
-}
-
-#define min(a, b) (a) < (b) ? (a) : (b)
-
-static uint8_t amp(uint8_t in)
-{
- uint32_t out = in;
-
- for (int i = 0; i < 20; ++i) {
- out = (out * in) / 256;
- }
-
- return min(out, 255);
-}
-
-static uint32_t bytescale(uint32_t n, uint32_t sc)
-{
- return n * sc / 255;
-}
-
-void on_tim2()
-{
- if (regget(TIM2.s_r, tim_uif)) {
- regset(TIM2.s_r, tim_uif, 0);
- }
-
- klogf("Tim2 Update\n");
+ (void)code;
+ klogf("%s\n", str);
}
/* Main function. This gets executed from the interrupt vector defined above. */
int main()
{
- regset(RCC.apb2en_r, rcc_syscfgen, 1);
-
- klogf("Entering main\n");
-
- klogf("Enable ir\n");
- enable_interrupt(IRQ_TIM2);
- klogf("Enable clock\n");
- regset(RCC.apb1en1_r, rcc_tim2en, 1);
- klogf("psc\n");
- TIM2.psc = 39999; /* Counts every half millisecond. */
- klogf("ar_r\n");
- TIM2.ar_r = 1000;
- klogf("die_r\n");
- regset(TIM2.die_r, tim_uie, 1);
- klogf("eg_r\n");
- regset(TIM2.eg_r, tim_ug, 1);
- klogf("c_r1\n");
- regset(TIM2.c_r1, tim_cen, 1);
-
- int ec;
- gpio_reserved_pin_t sysled = get_sysled();
-
- 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);
-
- if (ec) {
- panic("Unable to reserve GPIO pin ec=%d\n", ec);
- }
-
- // 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(;;);
+ klogf("Ir begin listening\n");
+ ir_begin_listen();
+ enable_ir_control();
+
+ add_ir_code_callback(RC_HIGH, printit, "RC_HIGH");
+ add_ir_code_callback(RC_TEMP_UP, printit, "RC_TEMP_UP");
+ add_ir_code_callback(RC_DRY, printit, "RC_DRY");
+ add_ir_code_callback(RC_LOW, printit, "RC_LOW");
+ add_ir_code_callback(RC_TEMP_DOWN, printit, "RC_TEMP_DOWN");
+ add_ir_code_callback(RC_COOL, printit, "RC_COOL");
+ add_ir_code_callback(RC_CONTINUOUS, printit, "RC_CONTINUOUS");
+ add_ir_code_callback(RC_FAN, printit, "RC_FAN");
+ add_ir_code_callback(RC_SLEEP, printit, "RC_SLEEP");
+ add_ir_code_callback(RC_UNITS, printit, "RC_UNITS");
+ add_ir_code_callback(RC_TIMER, printit, "RC_TIMER");
+ add_ir_code_callback(RC_POWER, printit, "RC_POWER");
+
+ for (;;)
+ ;
}
#endif
diff --git a/src/kern/stdlibrepl.c b/src/kern/stdlibrepl.c
index 38b8477..676b820 100644
--- a/src/kern/stdlibrepl.c
+++ b/src/kern/stdlibrepl.c
@@ -1,4 +1,5 @@
#include "arch.h"
+#include "kern/panic.h"
/*
* Replacement for common stdlib functions that don't exist
* on the ARM bare-metal compilation environment.
@@ -48,4 +49,10 @@ int memcmp(const void* s1_, const void* s2_, size_t size)
return 0;
}
+void __assert_func(
+ const char* file, int line, const char* func, const char* failedexpr)
+{
+ panic("Assertion failed: %s:%d in %s at %s\n", file, line, func, failedexpr);
+}
+
#endif