diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-05-24 18:03:05 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-05-24 18:03:05 +0200 |
commit | cef95354c69745f782a95d37f4b0e7bbf02e106a (patch) | |
tree | ff3a2ce26b1785dc88eb272f41e24ee997c6b4ed /zumo/protocol.cpp | |
parent | 4568db72dc3f9694ecae3506fc3de6ffc948b24f (diff) |
uart working
Diffstat (limited to 'zumo/protocol.cpp')
-rw-r--r-- | zumo/protocol.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/zumo/protocol.cpp b/zumo/protocol.cpp index fea8a00..f11827c 100644 --- a/zumo/protocol.cpp +++ b/zumo/protocol.cpp @@ -1,4 +1,6 @@ #include <Zumo32U4Motors.h> +#include <Arduino.h> +#include <Wire.h> #include "protocol.h" @@ -34,6 +36,20 @@ void apply_state(dui_state_t *state) { // TODO: print sign on OLED screen } +inline bool rx() { return !digitalRead(DUI_PINOUT_NICLA_RX); } + unsigned char uart_read() { - return 0x00; + if (rx() == true) return 0x00; // return immediately if line is idle + + delayMicroseconds(1500); // wait out start bit + + unsigned char byte = 0x00; + for (unsigned int i = 0; i < 8; i++) { + byte = (byte << 1) | rx(); + delayMicroseconds(1000); + } + + delayMicroseconds(1000); // wait out stop bit + + return byte; } |