]> mj.ucw.cz Git - home-hw.git/commitdiff
Test: Heat exchanger bypass control
authorMartin Mares <mj@ucw.cz>
Sat, 6 Jul 2019 22:37:55 +0000 (00:37 +0200)
committerMartin Mares <mj@ucw.cz>
Sat, 6 Jul 2019 22:37:55 +0000 (00:37 +0200)
test-opencm3/test.c

index b765805a6fff1c5cb3817b2f5f17165c6ce94df3..e49bce74eeccaeec3a6875413ed42609e8f24c01 100644 (file)
@@ -20,7 +20,17 @@ static void clock_setup(void)
 
 static void gpio_setup(void)
 {
+       // PC13 = BluePill LED
        gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
+       gpio_clear(GPIOC, GPIO13);
+
+       // PC14 = bypass LED*
+       gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO14);
+       gpio_set(GPIOC, GPIO14);
+
+       // PC15 = bypass opto-coupler
+       gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
+       gpio_clear(GPIOC, GPIO15);
 }
 
 static volatile u32 ms_ticks;
@@ -51,13 +61,15 @@ static void usart_setup(void)
        usart_set_baudrate(USART1, 115200);
        usart_set_databits(USART1, 8);
        usart_set_stopbits(USART1, USART_STOPBITS_1);
-       usart_set_mode(USART1, USART_MODE_TX);
+       usart_set_mode(USART1, USART_MODE_TX_RX);
        usart_set_parity(USART1, USART_PARITY_NONE);
        usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
 
        usart_enable(USART1);
 }
 
+static bool bypass_active;
+
 static void show_temperature(void)
 {
        debug_putc('#');
@@ -69,6 +81,8 @@ static void show_temperature(void)
                else
                        debug_printf("%3d.%03d", t / 1000, t % 1000);
        }
+       debug_putc(' ');
+       debug_putc('0' + bypass_active);
        debug_puts("\r\n");
 }
 
@@ -86,6 +100,18 @@ int main(void)
                gpio_toggle(GPIOC, GPIO13);
                delay_ms(100);
                ds_step();
+               if (usart_get_flag(USART1, USART_SR_RXNE)) {
+                       uint ch = usart_recv(USART1);
+                       if (ch == 'B') {
+                               bypass_active = 1;
+                               gpio_set(GPIOC, GPIO15);        // opto-coupler
+                               gpio_clear(GPIOC, GPIO14);      // LED
+                       } else if (ch == 'b') {
+                               bypass_active = 0;
+                               gpio_clear(GPIOC, GPIO15);      // opto-coupler
+                               gpio_set(GPIOC, GPIO14);        // LED
+                       }
+               }
                if (cycles++ >= 50) {
                        cycles = 0;
                        show_temperature();