update
[mTask.git] / int / nucleo-f767-blinky / src / interface.c
index 96077b0..70e3326 100644 (file)
@@ -5,8 +5,18 @@
 
 #ifdef STM32F767xx
 #include "stm32f7xx_hal.h"
-#include "gpio.h"
 #include "usart.h"
+#include "gpio.h"
+
+#define SET_LED_RED GPIOB->BSRR = GPIO_PIN_14
+#define RESET_LED_RED GPIOB->BSRR = GPIO_PIN_14 << 16
+
+#define SET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7
+#define RESET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7 << 16
+
+#define SET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0
+#define RESET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0 << 16
+
 #else
 #include <stdio.h>
 #include <netdb.h>
 
 #include "interface.h"
 
-#define SET_LED_RED GPIOB->BSRR = GPIO_PIN_14
-#define RESET_LED_RED GPIOB->BSRR = GPIO_PIN_14 << 16
-
-#define SET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7
-#define RESET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7 << 16
-
-#define SET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0
-#define RESET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0 << 16
-
 //Globals
 #ifdef STM32F767xx
 volatile char uartf = 0;
@@ -79,6 +80,8 @@ long millis() {
 
 bool input_available(){
 #ifdef STM32F767xx
+       if(HAL_UART_Receive(&huart3, &bt, 1, 1) == HAL_TIMEOUT)
+               return false;
        return true;
 #else
        struct timeval tv;
@@ -89,7 +92,10 @@ bool input_available(){
        FD_SET(fd, &fds);
        if (select(fd+1, &fds, NULL, NULL, &tv) == -1)
                pdie("select");
-       return FD_ISSET(fd, &fds);
+       if(!FD_ISSET(fd, &fds))
+               return false;
+       read(fd, &bt, 1);
+       return true;
 #endif
 }
 
@@ -97,7 +103,7 @@ uint8_t read_byte()
 {
 #ifdef STM32F767xx
        HAL_UART_Receive(&huart3, &bt, 1, 1000);
-       return 0;
+       return bt;
 #else
        read(fd, &bt, 1);
        return bt;
@@ -117,8 +123,10 @@ void write_dpin(uint8_t i, bool b)
 {
 #ifdef STM32F767xx
 #else
-       debug("dwrite %d: %d\n", i, b);
+       debug("dwrite %d: %d", i, b);
 #endif
+       (void) i;
+       (void) b;
 }
 
 bool read_dpin(uint8_t i)
@@ -126,9 +134,10 @@ bool read_dpin(uint8_t i)
 #ifdef STM32F767xx
        return false;
 #else
-       debug("dread %d\n", i);
+       debug("dread %d", i);
        return false;
 #endif
+       (void) i;
 }
 
 void write_apin(uint8_t i, uint8_t a)
@@ -148,8 +157,10 @@ void write_apin(uint8_t i, uint8_t a)
                SET_LED_GREEN;
        }
 #else
-       debug("awrite %d: %d\n", i, a);
+       debug("awrite %d: %d", i, a);
 #endif
+       (void) a;
+       (void) i;
 }
 
 uint8_t read_apin(uint8_t i)
@@ -157,9 +168,10 @@ uint8_t read_apin(uint8_t i)
 #ifdef STM32F767xx
        return 0;
 #else
-       debug("aread %d\n", i);
+       debug("aread %d", i);
        return 0;
 #endif
+       (void) i;
 }
 
 void delay(long ms)
@@ -178,10 +190,10 @@ void setup()
        int port = 8123, opti = 1;
        //Register signal handler
        if(signal(SIGINT, killHandler) == SIG_ERR){
-               die("Couldn't register signal handler...\n");
+               die("Couldn't register signal handler...");
        }
        if(signal(SIGTERM, killHandler) == SIG_ERR){
-               die("Couldn't register signal handler...\n");
+               die("Couldn't register signal handler...");
        }
        //Command line arguments
        while(opti < gargc){
@@ -191,7 +203,7 @@ void setup()
                } else if(strcmp(gargv[opti], "-p") == 0 && opti+1<gargc){
                        port = atoi(gargv[++opti]);
                        if(port < 1)
-                               die("Port numbers are > 1\n");
+                               die("Port numbers are > 1");
                } else {
                        usage(stderr, gargv[0]);
                        exit(EXIT_FAILURE);